Skip to content

Commit 45f77c0

Browse files
chore: correct .gitignore
1 parent 32686e6 commit 45f77c0

File tree

5 files changed

+268
-6
lines changed

5 files changed

+268
-6
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
cases/
1+
cases/files-*
22
node_modules/
33
package-lock.json

knip.json

-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/knip@latest/schema.json",
33
"entry": ["./src/*.ts"],
4-
"ignore": [
5-
"src/creators/files/createESLintConfigFile.ts",
6-
"src/creators/files/createStandardTSConfigFile.ts",
7-
"src/creators/utils.ts"
8-
],
94
"ignoreExportsUsedInFile": { "interface": true, "type": true },
105
"ignoreWorkspaces": ["cases/**"]
116
}
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { CaseData } from "../../data.js";
2+
import { Structure } from "../../writing/writeStructure.js";
3+
import { createESLintConfigFile } from "../files/createESLintConfigFile.js";
4+
import { createStandardTSConfigFile } from "../files/createStandardTSConfigFile.js";
5+
import { range } from "../utils.js";
6+
7+
function createExampleFile(index: number) {
8+
return [
9+
index > 1 &&
10+
range(1, index)
11+
.map((i) => `export * as nested${i} from "./nested${i}/index.js";`)
12+
.join("\n\t\t"),
13+
`
14+
export async function example${index}(prefix: string) {
15+
await Promise.resolve();
16+
return prefix + "" + ${index};
17+
}
18+
`,
19+
]
20+
.filter(Boolean)
21+
.join("\n\n");
22+
}
23+
24+
function createExampleDirectory(index: number): Structure {
25+
return {
26+
"index.ts": [createExampleFile(index), "typescript"],
27+
...(index > 2 &&
28+
Object.fromEntries(
29+
range(1, index).map((i) => [
30+
`nested${i}`,
31+
createExampleDirectory(i - 1),
32+
]),
33+
)),
34+
};
35+
}
36+
37+
function createIndexFile(count: number) {
38+
const indices = range(0, count);
39+
40+
return `
41+
import { example0 } from "./example0/index.js";
42+
43+
export async function root() {
44+
// Lint report: no-floating-promises
45+
example0("");
46+
47+
// No lint report
48+
await example0("");
49+
}
50+
51+
${indices.map((index) => `export { example${index} } from "./example${index}/index.js";`).join("\n\t\t")}
52+
`;
53+
}
54+
55+
export function writeEvenCaseFiles(data: CaseData): Structure {
56+
const topLevelWidth = Math.floor(Math.log(data.files) * 1.7);
57+
58+
return {
59+
"eslint.config.js": [
60+
createESLintConfigFile({
61+
singleRun: data.singleRun,
62+
types:
63+
data.types === "service"
64+
? "projectService"
65+
: data.layout === "references"
66+
? "tsconfig.eslint.json"
67+
: true,
68+
}),
69+
"typescript",
70+
],
71+
src: {
72+
"index.ts": [createIndexFile(topLevelWidth), "typescript"],
73+
...Object.fromEntries(
74+
new Array(topLevelWidth)
75+
.fill(undefined)
76+
.map((_, index) => [
77+
`example${index}`,
78+
createExampleDirectory(index),
79+
]),
80+
),
81+
},
82+
"tsconfig.json": [createStandardTSConfigFile(), "json"],
83+
};
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { CaseData } from "../../data.js";
2+
import { Structure } from "../../writing/writeStructure.js";
3+
import { createESLintConfigFile } from "../files/createESLintConfigFile.js";
4+
import { createStandardTSConfigFile } from "../files/createStandardTSConfigFile.js";
5+
import { range } from "../utils.js";
6+
7+
function createExampleFile(index: number) {
8+
return [
9+
index > 2 &&
10+
range(1, index)
11+
.map((i) => `export * as nested${i} from "./nested${i}/index.js";`)
12+
.join("\n\t\t"),
13+
`
14+
export async function example${index}(prefix: string) {
15+
await Promise.resolve();
16+
return prefix + "" + ${index};
17+
}
18+
`,
19+
]
20+
.filter(Boolean)
21+
.join("\n\n");
22+
}
23+
24+
function createIndexFile(count: number) {
25+
const indices = count > 1 ? range(0, count - 1) : [];
26+
27+
return `
28+
import { example0 } from "./nested0/index.js";
29+
30+
export async function root() {
31+
// Lint report: no-floating-promises
32+
example0("");
33+
34+
// No lint report
35+
await example0("");
36+
}
37+
38+
${indices.map((index) => `export * as nested${index} from "./nested${index}/index.js";`).join("\n\t\t")}
39+
`;
40+
}
41+
42+
function createNestedDirectory(index: number): Structure {
43+
return {
44+
"index.ts": [createExampleFile(index), "typescript"],
45+
...(index > 2 &&
46+
Object.fromEntries(
47+
range(1, index).map((i) => [
48+
`nested${i}`,
49+
createNestedDirectory(i - 1),
50+
]),
51+
)),
52+
};
53+
}
54+
55+
function createProjectDirectory(index: number): Structure {
56+
return {
57+
src: {
58+
"index.ts": [createIndexFile(index), "typescript"],
59+
...(index > 2 &&
60+
Object.fromEntries(
61+
range(0, index - 1).map((i) => [
62+
`nested${i}`,
63+
createNestedDirectory(i),
64+
]),
65+
)),
66+
},
67+
"tsconfig.json": [
68+
{
69+
extends: "../../tsconfig.build.json",
70+
include: ["src"],
71+
},
72+
"json",
73+
],
74+
};
75+
}
76+
77+
export function createReferencesCaseFiles(data: CaseData): Structure {
78+
const topLevelWidth = Math.ceil(
79+
Math.log(data.files) * (data.files > 1000 ? 1.6 : 1.7),
80+
);
81+
const projectNames = range(0, topLevelWidth).map((i) => `project-${i}`);
82+
83+
return {
84+
"eslint.config.js": [
85+
createESLintConfigFile({
86+
singleRun: data.singleRun,
87+
types:
88+
data.types === "service"
89+
? "projectService"
90+
: data.layout === "references"
91+
? "tsconfig.eslint.json"
92+
: true,
93+
}),
94+
"typescript",
95+
],
96+
"tsconfig.build.json": [
97+
{ ...createStandardTSConfigFile(), include: undefined },
98+
"json",
99+
],
100+
...(data.types === "service"
101+
? {
102+
"tsconfig.json": [
103+
{
104+
include: [],
105+
references: projectNames.map((projectName) => ({
106+
path: `./src/${projectName}`,
107+
})),
108+
},
109+
"json",
110+
],
111+
}
112+
: {
113+
"tsconfig.eslint.json": [createStandardTSConfigFile(), "json"],
114+
"tsconfig.json": [createStandardTSConfigFile(), "json"],
115+
}),
116+
src: {
117+
...Object.fromEntries(
118+
projectNames.map((projectName, index) => [
119+
projectName,
120+
createProjectDirectory(index),
121+
]),
122+
),
123+
},
124+
};
125+
}
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { CaseData } from "../../data.js";
2+
import { Structure } from "../../writing/writeStructure.js";
3+
import { createESLintConfigFile } from "../files/createESLintConfigFile.js";
4+
import { createStandardTSConfigFile } from "../files/createStandardTSConfigFile.js";
5+
6+
function createExampleFile(index: number) {
7+
return `
8+
export async function example${index}(prefix: string) {
9+
await Promise.resolve();
10+
return prefix + "" + ${index};
11+
}
12+
`;
13+
}
14+
15+
function createIndexFile(count: number) {
16+
const indices = new Array(count - 1).fill(undefined).map((_, index) => index);
17+
18+
return `
19+
${indices.map((index) => `import { example${index} } from "./example${index}.js";`).join("\n\t\t")}
20+
21+
export async function root() {
22+
// Lint report: no-floating-promises
23+
example0("");
24+
25+
// No lint reports
26+
${indices.map((index) => `await example${index}("");`).join("\n\t\t\t")}
27+
}
28+
`;
29+
}
30+
31+
export function writeWideCaseFiles(data: CaseData): Structure {
32+
return {
33+
"eslint.config.js": [
34+
createESLintConfigFile({
35+
singleRun: data.singleRun,
36+
types:
37+
data.types === "service"
38+
? "projectService"
39+
: data.layout === "references"
40+
? "tsconfig.eslint.json"
41+
: true,
42+
}),
43+
"typescript",
44+
],
45+
src: {
46+
"index.ts": [createIndexFile(data.files), "typescript"],
47+
...Object.fromEntries(
48+
new Array(data.files - 1)
49+
.fill(undefined)
50+
.map((_, index) => [
51+
`example${index}.ts`,
52+
[createExampleFile(index), "typescript"],
53+
]),
54+
),
55+
},
56+
"tsconfig.json": [createStandardTSConfigFile(), "json"],
57+
};
58+
}

0 commit comments

Comments
 (0)