create-typescript-app 2.61.2 → 2.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/blocks/blockKnip.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getPackageDependencies
|
|
1
|
+
import { getPackageDependencies } from "../data/packageData.js";
|
|
2
2
|
import { base } from "../base.js";
|
|
3
3
|
import { blockRemoveFiles } from "./blockRemoveFiles.js";
|
|
4
4
|
import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
|
|
@@ -6,6 +6,7 @@ import { blockPackageJson } from "./blockPackageJson.js";
|
|
|
6
6
|
import { blockDevelopmentDocs } from "./blockDevelopmentDocs.js";
|
|
7
7
|
import { blockRemoveWorkflows } from "./blockRemoveWorkflows.js";
|
|
8
8
|
import { intakeFileAsJson } from "./intake/intakeFileAsJson.js";
|
|
9
|
+
import { intakeFileExportObject } from "./intake/intakeFileExportObject.js";
|
|
9
10
|
import { z } from "zod";
|
|
10
11
|
import removeUndefinedObjects from "remove-undefined-objects";
|
|
11
12
|
|
|
@@ -19,7 +20,7 @@ const blockKnip = base.createBlock({
|
|
|
19
20
|
project: zStringArray.optional()
|
|
20
21
|
},
|
|
21
22
|
intake({ files }) {
|
|
22
|
-
const knipJson = intakeFileAsJson(files, ["knip.json"]);
|
|
23
|
+
const knipJson = intakeFileExportObject(files, ["knip.config.ts"]) ?? intakeFileAsJson(files, ["knip.json"]);
|
|
23
24
|
if (!knipJson) return;
|
|
24
25
|
return removeUndefinedObjects({
|
|
25
26
|
entry: zStringArray.safeParse(knipJson.entry).data,
|
|
@@ -42,8 +43,9 @@ const blockKnip = base.createBlock({
|
|
|
42
43
|
} }),
|
|
43
44
|
blockRemoveFiles({ files: [".ts-prunerc*"] })
|
|
44
45
|
],
|
|
45
|
-
files: { "knip.
|
|
46
|
-
|
|
46
|
+
files: { "knip.config.ts": `import type { KnipConfig } from "knip";
|
|
47
|
+
|
|
48
|
+
export default ${JSON.stringify({
|
|
47
49
|
entry: entry?.sort(),
|
|
48
50
|
ignoreDependencies,
|
|
49
51
|
ignoreExportsUsedInFile: {
|
|
@@ -52,15 +54,14 @@ const blockKnip = base.createBlock({
|
|
|
52
54
|
},
|
|
53
55
|
project: project?.sort(),
|
|
54
56
|
treatConfigHintsAsErrors: true
|
|
55
|
-
}) }
|
|
57
|
+
})} satisfies KnipConfig;` }
|
|
56
58
|
};
|
|
57
59
|
},
|
|
58
60
|
transition() {
|
|
59
61
|
return { addons: [blockRemoveFiles({ files: [
|
|
60
62
|
".knip*",
|
|
61
|
-
"knip.{c,m
|
|
62
|
-
"knip.
|
|
63
|
-
"knip.jsonc"
|
|
63
|
+
"knip.{c,j,m}*",
|
|
64
|
+
"knip.json*"
|
|
64
65
|
] }), blockRemoveWorkflows({ workflows: ["knip", "lint-knip"] })] };
|
|
65
66
|
}
|
|
66
67
|
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { intakeFile } from "./intakeFile.js";
|
|
2
|
+
import JSON5 from "json5";
|
|
3
|
+
|
|
4
|
+
//#region src/blocks/intake/intakeFileExportObject.ts
|
|
5
|
+
function intakeFileExportObject(files, filePath) {
|
|
6
|
+
const file = intakeFile(files, filePath);
|
|
7
|
+
if (!file) return;
|
|
8
|
+
const normalized = file[0].replaceAll(/[\n\r]/g, "");
|
|
9
|
+
const matched = /export\s+default\s*\{(.+)\}/u.exec(normalized);
|
|
10
|
+
if (!matched) return;
|
|
11
|
+
const rawData = tryParseJSON5(`{${matched[1]}}`);
|
|
12
|
+
if (!rawData || typeof rawData !== "object") return;
|
|
13
|
+
return rawData;
|
|
14
|
+
}
|
|
15
|
+
function tryParseJSON5(text) {
|
|
16
|
+
try {
|
|
17
|
+
return JSON5.parse(text);
|
|
18
|
+
} catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { intakeFileExportObject };
|