-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32686e6
commit 45f77c0
Showing
5 changed files
with
268 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
cases/ | ||
cases/files-* | ||
node_modules/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
{ | ||
"$schema": "https://unpkg.com/knip@latest/schema.json", | ||
"entry": ["./src/*.ts"], | ||
"ignore": [ | ||
"src/creators/files/createESLintConfigFile.ts", | ||
"src/creators/files/createStandardTSConfigFile.ts", | ||
"src/creators/utils.ts" | ||
], | ||
"ignoreExportsUsedInFile": { "interface": true, "type": true }, | ||
"ignoreWorkspaces": ["cases/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { CaseData } from "../../data.js"; | ||
import { Structure } from "../../writing/writeStructure.js"; | ||
import { createESLintConfigFile } from "../files/createESLintConfigFile.js"; | ||
import { createStandardTSConfigFile } from "../files/createStandardTSConfigFile.js"; | ||
import { range } from "../utils.js"; | ||
|
||
function createExampleFile(index: number) { | ||
return [ | ||
index > 1 && | ||
range(1, index) | ||
.map((i) => `export * as nested${i} from "./nested${i}/index.js";`) | ||
.join("\n\t\t"), | ||
` | ||
export async function example${index}(prefix: string) { | ||
await Promise.resolve(); | ||
return prefix + "" + ${index}; | ||
} | ||
`, | ||
] | ||
.filter(Boolean) | ||
.join("\n\n"); | ||
} | ||
|
||
function createExampleDirectory(index: number): Structure { | ||
return { | ||
"index.ts": [createExampleFile(index), "typescript"], | ||
...(index > 2 && | ||
Object.fromEntries( | ||
range(1, index).map((i) => [ | ||
`nested${i}`, | ||
createExampleDirectory(i - 1), | ||
]), | ||
)), | ||
}; | ||
} | ||
|
||
function createIndexFile(count: number) { | ||
const indices = range(0, count); | ||
|
||
return ` | ||
import { example0 } from "./example0/index.js"; | ||
export async function root() { | ||
// Lint report: no-floating-promises | ||
example0(""); | ||
// No lint report | ||
await example0(""); | ||
} | ||
${indices.map((index) => `export { example${index} } from "./example${index}/index.js";`).join("\n\t\t")} | ||
`; | ||
} | ||
|
||
export function writeEvenCaseFiles(data: CaseData): Structure { | ||
const topLevelWidth = Math.floor(Math.log(data.files) * 1.7); | ||
|
||
return { | ||
"eslint.config.js": [ | ||
createESLintConfigFile({ | ||
singleRun: data.singleRun, | ||
types: | ||
data.types === "service" | ||
? "projectService" | ||
: data.layout === "references" | ||
? "tsconfig.eslint.json" | ||
: true, | ||
}), | ||
"typescript", | ||
], | ||
src: { | ||
"index.ts": [createIndexFile(topLevelWidth), "typescript"], | ||
...Object.fromEntries( | ||
new Array(topLevelWidth) | ||
.fill(undefined) | ||
.map((_, index) => [ | ||
`example${index}`, | ||
createExampleDirectory(index), | ||
]), | ||
), | ||
}, | ||
"tsconfig.json": [createStandardTSConfigFile(), "json"], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { CaseData } from "../../data.js"; | ||
import { Structure } from "../../writing/writeStructure.js"; | ||
import { createESLintConfigFile } from "../files/createESLintConfigFile.js"; | ||
import { createStandardTSConfigFile } from "../files/createStandardTSConfigFile.js"; | ||
import { range } from "../utils.js"; | ||
|
||
function createExampleFile(index: number) { | ||
return [ | ||
index > 2 && | ||
range(1, index) | ||
.map((i) => `export * as nested${i} from "./nested${i}/index.js";`) | ||
.join("\n\t\t"), | ||
` | ||
export async function example${index}(prefix: string) { | ||
await Promise.resolve(); | ||
return prefix + "" + ${index}; | ||
} | ||
`, | ||
] | ||
.filter(Boolean) | ||
.join("\n\n"); | ||
} | ||
|
||
function createIndexFile(count: number) { | ||
const indices = count > 1 ? range(0, count - 1) : []; | ||
|
||
return ` | ||
import { example0 } from "./nested0/index.js"; | ||
export async function root() { | ||
// Lint report: no-floating-promises | ||
example0(""); | ||
// No lint report | ||
await example0(""); | ||
} | ||
${indices.map((index) => `export * as nested${index} from "./nested${index}/index.js";`).join("\n\t\t")} | ||
`; | ||
} | ||
|
||
function createNestedDirectory(index: number): Structure { | ||
return { | ||
"index.ts": [createExampleFile(index), "typescript"], | ||
...(index > 2 && | ||
Object.fromEntries( | ||
range(1, index).map((i) => [ | ||
`nested${i}`, | ||
createNestedDirectory(i - 1), | ||
]), | ||
)), | ||
}; | ||
} | ||
|
||
function createProjectDirectory(index: number): Structure { | ||
return { | ||
src: { | ||
"index.ts": [createIndexFile(index), "typescript"], | ||
...(index > 2 && | ||
Object.fromEntries( | ||
range(0, index - 1).map((i) => [ | ||
`nested${i}`, | ||
createNestedDirectory(i), | ||
]), | ||
)), | ||
}, | ||
"tsconfig.json": [ | ||
{ | ||
extends: "../../tsconfig.build.json", | ||
include: ["src"], | ||
}, | ||
"json", | ||
], | ||
}; | ||
} | ||
|
||
export function createReferencesCaseFiles(data: CaseData): Structure { | ||
const topLevelWidth = Math.ceil( | ||
Math.log(data.files) * (data.files > 1000 ? 1.6 : 1.7), | ||
); | ||
const projectNames = range(0, topLevelWidth).map((i) => `project-${i}`); | ||
|
||
return { | ||
"eslint.config.js": [ | ||
createESLintConfigFile({ | ||
singleRun: data.singleRun, | ||
types: | ||
data.types === "service" | ||
? "projectService" | ||
: data.layout === "references" | ||
? "tsconfig.eslint.json" | ||
: true, | ||
}), | ||
"typescript", | ||
], | ||
"tsconfig.build.json": [ | ||
{ ...createStandardTSConfigFile(), include: undefined }, | ||
"json", | ||
], | ||
...(data.types === "service" | ||
? { | ||
"tsconfig.json": [ | ||
{ | ||
include: [], | ||
references: projectNames.map((projectName) => ({ | ||
path: `./src/${projectName}`, | ||
})), | ||
}, | ||
"json", | ||
], | ||
} | ||
: { | ||
"tsconfig.eslint.json": [createStandardTSConfigFile(), "json"], | ||
"tsconfig.json": [createStandardTSConfigFile(), "json"], | ||
}), | ||
src: { | ||
...Object.fromEntries( | ||
projectNames.map((projectName, index) => [ | ||
projectName, | ||
createProjectDirectory(index), | ||
]), | ||
), | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { CaseData } from "../../data.js"; | ||
import { Structure } from "../../writing/writeStructure.js"; | ||
import { createESLintConfigFile } from "../files/createESLintConfigFile.js"; | ||
import { createStandardTSConfigFile } from "../files/createStandardTSConfigFile.js"; | ||
|
||
function createExampleFile(index: number) { | ||
return ` | ||
export async function example${index}(prefix: string) { | ||
await Promise.resolve(); | ||
return prefix + "" + ${index}; | ||
} | ||
`; | ||
} | ||
|
||
function createIndexFile(count: number) { | ||
const indices = new Array(count - 1).fill(undefined).map((_, index) => index); | ||
|
||
return ` | ||
${indices.map((index) => `import { example${index} } from "./example${index}.js";`).join("\n\t\t")} | ||
export async function root() { | ||
// Lint report: no-floating-promises | ||
example0(""); | ||
// No lint reports | ||
${indices.map((index) => `await example${index}("");`).join("\n\t\t\t")} | ||
} | ||
`; | ||
} | ||
|
||
export function writeWideCaseFiles(data: CaseData): Structure { | ||
return { | ||
"eslint.config.js": [ | ||
createESLintConfigFile({ | ||
singleRun: data.singleRun, | ||
types: | ||
data.types === "service" | ||
? "projectService" | ||
: data.layout === "references" | ||
? "tsconfig.eslint.json" | ||
: true, | ||
}), | ||
"typescript", | ||
], | ||
src: { | ||
"index.ts": [createIndexFile(data.files), "typescript"], | ||
...Object.fromEntries( | ||
new Array(data.files - 1) | ||
.fill(undefined) | ||
.map((_, index) => [ | ||
`example${index}.ts`, | ||
[createExampleFile(index), "typescript"], | ||
]), | ||
), | ||
}, | ||
"tsconfig.json": [createStandardTSConfigFile(), "json"], | ||
}; | ||
} |