@checkdigit/typescript-config 9.1.1 → 9.2.0-PR.76-0a46
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/README.md +1 -1
- package/bin/builder.mjs +75 -26
- package/dist-mjs/analyze.mjs +29 -15
- package/dist-mjs/builder.mjs +19 -4
- package/dist-mjs/compile.mjs +30 -10
- package/package.json +1 -91
- package/src/analyze.ts +33 -15
- package/src/builder.ts +18 -3
- package/src/compile.ts +36 -11
package/README.md
CHANGED
@@ -10,7 +10,7 @@ This module contains the standard Check Digit TypeScript configuration, along wi
|
|
10
10
|
|
11
11
|
## TypeScript Configuration
|
12
12
|
|
13
|
-
- currently requires Node 22.
|
13
|
+
- currently requires Node 22.15 or above.
|
14
14
|
- emits `esnext`, with the default libraries, to avoid down-leveling. It is intended that application spec tests pick
|
15
15
|
up any issues with using newer features unavailable in a particular environment. Browsers and Node.js are fast-moving
|
16
16
|
targets, and can add language features at any time.
|
package/bin/builder.mjs
CHANGED
@@ -8,23 +8,37 @@ import { parseArgs } from "node:util";
|
|
8
8
|
// src/analyze.ts
|
9
9
|
import { strict as assert } from "node:assert";
|
10
10
|
function analyze(metafile) {
|
11
|
-
const source = new Set(
|
12
|
-
|
11
|
+
const source = new Set(
|
12
|
+
Object.keys(metafile.inputs).filter(
|
13
|
+
(key) => !key.startsWith("node_modules")
|
14
|
+
)
|
15
|
+
);
|
16
|
+
const modules = new Set(
|
17
|
+
Object.keys(metafile.inputs).filter(
|
18
|
+
(key) => key.startsWith("node_modules")
|
19
|
+
)
|
20
|
+
);
|
13
21
|
const [output] = Object.entries(metafile.outputs);
|
14
22
|
assert.ok(output !== void 0);
|
15
23
|
const [, bundle] = output;
|
16
|
-
const sourceBytes = Object.entries(bundle.inputs).reduce(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
const sourceBytes = Object.entries(bundle.inputs).reduce(
|
25
|
+
(bytes, [file, value]) => {
|
26
|
+
if (source.has(file)) {
|
27
|
+
return bytes + value.bytesInOutput;
|
28
|
+
}
|
29
|
+
return bytes;
|
30
|
+
},
|
31
|
+
0
|
32
|
+
);
|
33
|
+
const moduleBytes = Object.entries(bundle.inputs).reduce(
|
34
|
+
(bytes, [file, value]) => {
|
35
|
+
if (modules.has(file)) {
|
36
|
+
return bytes + value.bytesInOutput;
|
37
|
+
}
|
38
|
+
return bytes;
|
39
|
+
},
|
40
|
+
0
|
41
|
+
);
|
28
42
|
return {
|
29
43
|
sourceBytes,
|
30
44
|
moduleBytes,
|
@@ -116,13 +130,15 @@ function excludeSourceMaps(filter) {
|
|
116
130
|
}
|
117
131
|
function resolveTypescriptPaths() {
|
118
132
|
return (pluginBuild) => {
|
119
|
-
pluginBuild.onResolve({ filter: /.*/
|
133
|
+
pluginBuild.onResolve({ filter: /.*/ }, async (resolved) => {
|
120
134
|
if (resolved.kind === "entry-point" || !resolved.path.startsWith(".") || resolved.path.endsWith(".js") || resolved.path.endsWith(".json")) {
|
121
135
|
return { external: resolved.kind !== "entry-point" };
|
122
136
|
}
|
123
137
|
let isDirectory = false;
|
124
138
|
try {
|
125
|
-
const stats = await fs.lstat(
|
139
|
+
const stats = await fs.lstat(
|
140
|
+
path.join(resolved.resolveDir, resolved.path)
|
141
|
+
);
|
126
142
|
isDirectory = stats.isDirectory();
|
127
143
|
} catch {
|
128
144
|
}
|
@@ -153,7 +169,11 @@ async function compile_default({
|
|
153
169
|
);
|
154
170
|
const allSourceFiles = await getFiles(inDir2);
|
155
171
|
const productionSourceFiles = entryPoint2 === void 0 ? allSourceFiles.filter((file) => file.endsWith(".ts")) : [path.join(inDir2, entryPoint2)];
|
156
|
-
const compilerOptions = typescript.parseJsonConfigFileContent(
|
172
|
+
const compilerOptions = typescript.parseJsonConfigFileContent(
|
173
|
+
tsconfig_default,
|
174
|
+
typescript.sys,
|
175
|
+
outDir2
|
176
|
+
).options;
|
157
177
|
const program = typescript.createProgram(productionSourceFiles, {
|
158
178
|
...compilerOptions,
|
159
179
|
noEmit: type2 !== "types",
|
@@ -172,11 +192,21 @@ async function compile_default({
|
|
172
192
|
for (const diagnostic of allDiagnostics) {
|
173
193
|
if (diagnostic.file) {
|
174
194
|
assert2.ok(diagnostic.start !== void 0);
|
175
|
-
const { line, character } = typescript.getLineAndCharacterOfPosition(
|
176
|
-
|
177
|
-
|
195
|
+
const { line, character } = typescript.getLineAndCharacterOfPosition(
|
196
|
+
diagnostic.file,
|
197
|
+
diagnostic.start
|
198
|
+
);
|
199
|
+
const message = typescript.flattenDiagnosticMessageText(
|
200
|
+
diagnostic.messageText,
|
201
|
+
"\n"
|
202
|
+
);
|
203
|
+
messages.push(
|
204
|
+
`tsc: ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`
|
205
|
+
);
|
178
206
|
} else {
|
179
|
-
messages.push(
|
207
|
+
messages.push(
|
208
|
+
`tsc: ${typescript.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`
|
209
|
+
);
|
180
210
|
}
|
181
211
|
}
|
182
212
|
if (messages.length > 0) {
|
@@ -221,12 +251,16 @@ async function compile_default({
|
|
221
251
|
plugins: [
|
222
252
|
{
|
223
253
|
name: "exclude-source-maps",
|
224
|
-
|
254
|
+
// Note: the /u flag cannot be used here because the underlying Go implementation does not support it
|
255
|
+
// eslint-disable-next-line require-unicode-regexp
|
256
|
+
setup: excludeSourceMaps(/node_modules/)
|
225
257
|
}
|
226
258
|
]
|
227
259
|
}
|
228
260
|
});
|
229
|
-
messages.push(
|
261
|
+
messages.push(
|
262
|
+
...buildResult.errors.map((error) => `esbuild error: ${error.text}`)
|
263
|
+
);
|
230
264
|
if (messages.length > 0) {
|
231
265
|
throw new Error(`esbuild failed ${JSON.stringify(messages)}`);
|
232
266
|
}
|
@@ -235,7 +269,16 @@ async function compile_default({
|
|
235
269
|
|
236
270
|
// src/builder.ts
|
237
271
|
var {
|
238
|
-
values: {
|
272
|
+
values: {
|
273
|
+
type,
|
274
|
+
inDir,
|
275
|
+
outDir,
|
276
|
+
entryPoint,
|
277
|
+
outFile,
|
278
|
+
external,
|
279
|
+
minify,
|
280
|
+
sourceMap
|
281
|
+
}
|
239
282
|
} = parseArgs({
|
240
283
|
options: {
|
241
284
|
type: { type: "string", short: "t", default: "module" },
|
@@ -248,7 +291,10 @@ var {
|
|
248
291
|
sourceMap: { type: "boolean", short: "s", default: false }
|
249
292
|
}
|
250
293
|
});
|
251
|
-
assert3.ok(
|
294
|
+
assert3.ok(
|
295
|
+
type === "module" || type === "types",
|
296
|
+
"type must be types or module"
|
297
|
+
);
|
252
298
|
var compileResult = await compile_default({
|
253
299
|
type,
|
254
300
|
inDir: path2.join(process.cwd(), inDir),
|
@@ -267,7 +313,10 @@ await Promise.all(
|
|
267
313
|
);
|
268
314
|
if (compileResult.metafile !== void 0) {
|
269
315
|
const analysis = analyze(compileResult.metafile);
|
270
|
-
await fs2.writeFile(
|
316
|
+
await fs2.writeFile(
|
317
|
+
path2.join(outDir, "metafile.json"),
|
318
|
+
JSON.stringify(compileResult.metafile, void 0, 2)
|
319
|
+
);
|
271
320
|
console.log(
|
272
321
|
`${outFile}: src ${analysis.sourceBytes}, node_modules ${analysis.moduleBytes}, total ${analysis.totalBytes}`
|
273
322
|
);
|
package/dist-mjs/analyze.mjs
CHANGED
@@ -1,23 +1,37 @@
|
|
1
1
|
// src/analyze.ts
|
2
2
|
import { strict as assert } from "node:assert";
|
3
3
|
function analyze(metafile) {
|
4
|
-
const source = new Set(
|
5
|
-
|
4
|
+
const source = new Set(
|
5
|
+
Object.keys(metafile.inputs).filter(
|
6
|
+
(key) => !key.startsWith("node_modules")
|
7
|
+
)
|
8
|
+
);
|
9
|
+
const modules = new Set(
|
10
|
+
Object.keys(metafile.inputs).filter(
|
11
|
+
(key) => key.startsWith("node_modules")
|
12
|
+
)
|
13
|
+
);
|
6
14
|
const [output] = Object.entries(metafile.outputs);
|
7
15
|
assert.ok(output !== void 0);
|
8
16
|
const [, bundle] = output;
|
9
|
-
const sourceBytes = Object.entries(bundle.inputs).reduce(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
const sourceBytes = Object.entries(bundle.inputs).reduce(
|
18
|
+
(bytes, [file, value]) => {
|
19
|
+
if (source.has(file)) {
|
20
|
+
return bytes + value.bytesInOutput;
|
21
|
+
}
|
22
|
+
return bytes;
|
23
|
+
},
|
24
|
+
0
|
25
|
+
);
|
26
|
+
const moduleBytes = Object.entries(bundle.inputs).reduce(
|
27
|
+
(bytes, [file, value]) => {
|
28
|
+
if (modules.has(file)) {
|
29
|
+
return bytes + value.bytesInOutput;
|
30
|
+
}
|
31
|
+
return bytes;
|
32
|
+
},
|
33
|
+
0
|
34
|
+
);
|
21
35
|
return {
|
22
36
|
sourceBytes,
|
23
37
|
moduleBytes,
|
@@ -27,4 +41,4 @@ function analyze(metafile) {
|
|
27
41
|
export {
|
28
42
|
analyze as default
|
29
43
|
};
|
30
|
-
//# sourceMappingURL=data:application/json;base64,
|
44
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2FuYWx5emUudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBRUEsU0FBUyxVQUFVLGNBQWM7QUFJbEIsU0FBUixRQUF5QixVQUk5QjtBQUNBLFFBQU0sU0FBUyxJQUFJO0FBQUEsSUFDakIsT0FBTyxLQUFLLFNBQVMsTUFBTSxFQUFFO0FBQUEsTUFDM0IsQ0FBQyxRQUFRLENBQUMsSUFBSSxXQUFXLGNBQWM7QUFBQSxJQUN6QztBQUFBLEVBQ0Y7QUFDQSxRQUFNLFVBQVUsSUFBSTtBQUFBLElBQ2xCLE9BQU8sS0FBSyxTQUFTLE1BQU0sRUFBRTtBQUFBLE1BQU8sQ0FBQyxRQUNuQyxJQUFJLFdBQVcsY0FBYztBQUFBLElBQy9CO0FBQUEsRUFDRjtBQUVBLFFBQU0sQ0FBQyxNQUFNLElBQUksT0FBTyxRQUFRLFNBQVMsT0FBTztBQUNoRCxTQUFPLEdBQUcsV0FBVyxNQUFTO0FBQzlCLFFBQU0sQ0FBQyxFQUFFLE1BQU0sSUFBSTtBQUVuQixRQUFNLGNBQWMsT0FBTyxRQUFRLE9BQU8sTUFBTSxFQUFFO0FBQUEsSUFDaEQsQ0FBQyxPQUFPLENBQUMsTUFBTSxLQUFLLE1BQU07QUFDeEIsVUFBSSxPQUFPLElBQUksSUFBSSxHQUFHO0FBQ3BCLGVBQU8sUUFBUSxNQUFNO0FBQUEsTUFDdkI7QUFDQSxhQUFPO0FBQUEsSUFDVDtBQUFBLElBQ0E7QUFBQSxFQUNGO0FBRUEsUUFBTSxjQUFjLE9BQU8sUUFBUSxPQUFPLE1BQU0sRUFBRTtBQUFBLElBQ2hELENBQUMsT0FBTyxDQUFDLE1BQU0sS0FBSyxNQUFNO0FBQ3hCLFVBQUksUUFBUSxJQUFJLElBQUksR0FBRztBQUNyQixlQUFPLFFBQVEsTUFBTTtBQUFBLE1BQ3ZCO0FBQ0EsYUFBTztBQUFBLElBQ1Q7QUFBQSxJQUNBO0FBQUEsRUFDRjtBQUVBLFNBQU87QUFBQSxJQUNMO0FBQUEsSUFDQTtBQUFBLElBQ0EsWUFBWSxPQUFPO0FBQUEsRUFDckI7QUFDRjsiLAogICJuYW1lcyI6IFtdCn0K
|
package/dist-mjs/builder.mjs
CHANGED
@@ -5,7 +5,16 @@ import path from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
6
6
|
import { analyze, compile } from "./index.mjs";
|
7
7
|
var {
|
8
|
-
values: {
|
8
|
+
values: {
|
9
|
+
type,
|
10
|
+
inDir,
|
11
|
+
outDir,
|
12
|
+
entryPoint,
|
13
|
+
outFile,
|
14
|
+
external,
|
15
|
+
minify,
|
16
|
+
sourceMap
|
17
|
+
}
|
9
18
|
} = parseArgs({
|
10
19
|
options: {
|
11
20
|
type: { type: "string", short: "t", default: "module" },
|
@@ -18,7 +27,10 @@ var {
|
|
18
27
|
sourceMap: { type: "boolean", short: "s", default: false }
|
19
28
|
}
|
20
29
|
});
|
21
|
-
assert.ok(
|
30
|
+
assert.ok(
|
31
|
+
type === "module" || type === "types",
|
32
|
+
"type must be types or module"
|
33
|
+
);
|
22
34
|
var compileResult = await compile({
|
23
35
|
type,
|
24
36
|
inDir: path.join(process.cwd(), inDir),
|
@@ -37,9 +49,12 @@ await Promise.all(
|
|
37
49
|
);
|
38
50
|
if (compileResult.metafile !== void 0) {
|
39
51
|
const analysis = analyze(compileResult.metafile);
|
40
|
-
await fs.writeFile(
|
52
|
+
await fs.writeFile(
|
53
|
+
path.join(outDir, "metafile.json"),
|
54
|
+
JSON.stringify(compileResult.metafile, void 0, 2)
|
55
|
+
);
|
41
56
|
console.log(
|
42
57
|
`${outFile}: src ${analysis.sourceBytes}, node_modules ${analysis.moduleBytes}, total ${analysis.totalBytes}`
|
43
58
|
);
|
44
59
|
}
|
45
|
-
//# sourceMappingURL=data:application/json;base64,
|
60
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2J1aWxkZXIudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBRUEsU0FBUyxVQUFVLGNBQWM7QUFDakMsU0FBUyxZQUFZLFVBQVU7QUFDL0IsT0FBTyxVQUFVO0FBQ2pCLFNBQVMsaUJBQWlCO0FBRTFCLFNBQVMsU0FBUyxlQUFlO0FBRWpDLElBQU07QUFBQSxFQUNKLFFBQVE7QUFBQSxJQUNOO0FBQUEsSUFDQTtBQUFBLElBQ0E7QUFBQSxJQUNBO0FBQUEsSUFDQTtBQUFBLElBQ0E7QUFBQSxJQUNBO0FBQUEsSUFDQTtBQUFBLEVBQ0Y7QUFDRixJQUFJLFVBQVU7QUFBQSx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xRQUFRLEtBQUssSUFBSSxDQUFDLEdBQUcsRUFBRSxXQUFXLEtBQUssQ0FBQztBQUN0RSxVQUFNLEdBQUcsVUFBVSxLQUFLLE1BQU0sS0FBSyxJQUFJO0FBQUEsRUFDekMsQ0FBQztBQUNIO0FBR0EsSUFBSSxjQUFjLGFBQWEsUUFBVztBQUN4QyxRQUFNLFdBQVcsUUFBUSxjQUFjLFFBQVE7QUFDL0MsUUFBTSxHQUFHO0FBQUEsSUFDUCxLQUFLLEtBQUssUUFBUSxlQUFlO0FBQUEsSUFDakMsS0FBSyxVQUFVLGNBQWMsVUFBVSxRQUFXLENBQUM7QUFBQSxFQUNyRDtBQUdBLFVBQVE7QUFBQSxJQUNOLEdBQUcsT0FBTyxTQUFTLFNBQVMsV0FBVyxrQkFBa0IsU0FBUyxXQUFXLFdBQVcsU0FBUyxVQUFVO0FBQUEsRUFDN0c7QUFDRjsiLAogICJuYW1lcyI6IFtdCn0K
|
package/dist-mjs/compile.mjs
CHANGED
@@ -40,13 +40,15 @@ function excludeSourceMaps(filter) {
|
|
40
40
|
}
|
41
41
|
function resolveTypescriptPaths() {
|
42
42
|
return (pluginBuild) => {
|
43
|
-
pluginBuild.onResolve({ filter: /.*/
|
43
|
+
pluginBuild.onResolve({ filter: /.*/ }, async (resolved) => {
|
44
44
|
if (resolved.kind === "entry-point" || !resolved.path.startsWith(".") || resolved.path.endsWith(".js") || resolved.path.endsWith(".json")) {
|
45
45
|
return { external: resolved.kind !== "entry-point" };
|
46
46
|
}
|
47
47
|
let isDirectory = false;
|
48
48
|
try {
|
49
|
-
const stats = await fs.lstat(
|
49
|
+
const stats = await fs.lstat(
|
50
|
+
path.join(resolved.resolveDir, resolved.path)
|
51
|
+
);
|
50
52
|
isDirectory = stats.isDirectory();
|
51
53
|
} catch {
|
52
54
|
}
|
@@ -77,7 +79,11 @@ async function compile_default({
|
|
77
79
|
);
|
78
80
|
const allSourceFiles = await getFiles(inDir);
|
79
81
|
const productionSourceFiles = entryPoint === void 0 ? allSourceFiles.filter((file) => file.endsWith(".ts")) : [path.join(inDir, entryPoint)];
|
80
|
-
const compilerOptions = typescript.parseJsonConfigFileContent(
|
82
|
+
const compilerOptions = typescript.parseJsonConfigFileContent(
|
83
|
+
tsConfigJson,
|
84
|
+
typescript.sys,
|
85
|
+
outDir
|
86
|
+
).options;
|
81
87
|
const program = typescript.createProgram(productionSourceFiles, {
|
82
88
|
...compilerOptions,
|
83
89
|
noEmit: type !== "types",
|
@@ -96,11 +102,21 @@ async function compile_default({
|
|
96
102
|
for (const diagnostic of allDiagnostics) {
|
97
103
|
if (diagnostic.file) {
|
98
104
|
assert.ok(diagnostic.start !== void 0);
|
99
|
-
const { line, character } = typescript.getLineAndCharacterOfPosition(
|
100
|
-
|
101
|
-
|
105
|
+
const { line, character } = typescript.getLineAndCharacterOfPosition(
|
106
|
+
diagnostic.file,
|
107
|
+
diagnostic.start
|
108
|
+
);
|
109
|
+
const message = typescript.flattenDiagnosticMessageText(
|
110
|
+
diagnostic.messageText,
|
111
|
+
"\n"
|
112
|
+
);
|
113
|
+
messages.push(
|
114
|
+
`tsc: ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`
|
115
|
+
);
|
102
116
|
} else {
|
103
|
-
messages.push(
|
117
|
+
messages.push(
|
118
|
+
`tsc: ${typescript.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`
|
119
|
+
);
|
104
120
|
}
|
105
121
|
}
|
106
122
|
if (messages.length > 0) {
|
@@ -145,12 +161,16 @@ async function compile_default({
|
|
145
161
|
plugins: [
|
146
162
|
{
|
147
163
|
name: "exclude-source-maps",
|
148
|
-
|
164
|
+
// Note: the /u flag cannot be used here because the underlying Go implementation does not support it
|
165
|
+
// eslint-disable-next-line require-unicode-regexp
|
166
|
+
setup: excludeSourceMaps(/node_modules/)
|
149
167
|
}
|
150
168
|
]
|
151
169
|
}
|
152
170
|
});
|
153
|
-
messages.push(
|
171
|
+
messages.push(
|
172
|
+
...buildResult.errors.map((error) => `esbuild error: ${error.text}`)
|
173
|
+
);
|
154
174
|
if (messages.length > 0) {
|
155
175
|
throw new Error(`esbuild failed ${JSON.stringify(messages)}`);
|
156
176
|
}
|
@@ -159,4 +179,4 @@ async function compile_default({
|
|
159
179
|
export {
|
160
180
|
compile_default as default
|
161
181
|
};
|
162
|
-
//# sourceMappingURL=data:application/json;base64,
|
182
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2NvbXBpbGUudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBRUEsU0FBUyxVQUFVLGNBQWM7QUFDakMsU0FBUyxZQUFZLFVBQVU7QUFDL0IsT0FBTyxVQUFVO0FBRWpCLE9BQU8sZ0JBQWdCO0FBQ3ZCLFNBQVMsYUFBK0I7QUFFeEMsT0FBTyxrQkFBa0IsbUJBQW1CLEtBQUssRUFBRSxNQUFNLE9BQU87QUFFaEUsSUFBTSw4QkFBOEI7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBb0hwQyxlQUFlLFNBQVMsV0FBc0M7QUFDNUQsUUFBTSxVQUFVLE1BQU0sR0FBRyxRQUFRLFdBQVcsRUFBRSxlQUFlLEtBQUssQ0FBQztBQUNuRSxRQUFNLFFBQVEsTUFBTSxRQUFRO0FBQUEsSUFDMUIsUUFBUSxJQUFJLENBQUMsVUFBVTtBQUNyQixZQUFNLFNBQVMsS0FBSyxRQUFRLFdBQVcsTUFBTSxJQUFJO0FBQ2pELGFBQU8sTUFBTSxZQUFZLElBQUksU0FBUyxNQUFNLElBQUk7QUFBQSxJQUNsRCxDQUFDO0FBQUEsRUFDSDtBQUNBLFNBQU8sTUFBTSxLQUFLO0FBQ3BCO0FBRUEsU0FBUyxrQkFBa0IsUUFBZ0I7QUFDekMsU0FBTyxDQUFDLGdCQUE2QjtBQUVuQyxnQkFBWSxPQUFPLEVBQUUsT0FBTyxHQUFHLE9BQU8sU0FBUztBQUM3QyxVQ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
3
|
-
"version": "9.1.1",
|
4
|
-
"description": "Check Digit standard Typescript configuration",
|
5
|
-
"homepage": "https://github.com/checkdigit/typescript-config#readme",
|
6
|
-
"bugs": {
|
7
|
-
"url": "https://github.com/checkdigit/typescript-config/issues"
|
8
|
-
},
|
9
|
-
"repository": {
|
10
|
-
"type": "git",
|
11
|
-
"url": "git+https://github.com/checkdigit/typescript-config.git"
|
12
|
-
},
|
13
|
-
"license": "MIT",
|
14
|
-
"author": "Check Digit, LLC",
|
15
|
-
"type": "module",
|
16
|
-
"exports": {
|
17
|
-
".": {
|
18
|
-
"types": "./dist-types/index.d.ts",
|
19
|
-
"import": "./dist-mjs/index.mjs",
|
20
|
-
"default": "./tsconfig.json"
|
21
|
-
}
|
22
|
-
},
|
23
|
-
"bin": {
|
24
|
-
"builder": "./bin/builder.mjs"
|
25
|
-
},
|
26
|
-
"files": [
|
27
|
-
"bin",
|
28
|
-
"tsconfig.json",
|
29
|
-
"src",
|
30
|
-
"dist-types",
|
31
|
-
"dist-mjs",
|
32
|
-
"!src/**/test/**",
|
33
|
-
"!src/**/*.test.ts",
|
34
|
-
"!src/**/*.spec.ts",
|
35
|
-
"!dist-types/**/test/**",
|
36
|
-
"!dist-types/**/*.test.d.ts",
|
37
|
-
"!dist-types/**/*.spec.d.ts",
|
38
|
-
"!dist-mjs/**/test/**",
|
39
|
-
"!dist-mjs/**/*.test.mjs",
|
40
|
-
"!dist-mjs/**/*.spec.mjs",
|
41
|
-
"SECURITY.md"
|
42
|
-
],
|
43
|
-
"scripts": {
|
44
|
-
"build": "npm run build:builder && npm run build:types && npm run build:mjs && npm run build:mjs-bundle && npm run build:mjs-bundle-minify && npm run build:mjs-bundle-no-external",
|
45
|
-
"build:builder": "esbuild src/builder.ts --bundle --platform=node --format=esm --external:typescript --external:esbuild --outfile=build-builder/builder.mjs && mkdir -p bin && { echo '#!/usr/bin/env node'; cat build-builder/builder.mjs; } > bin/builder.mjs && chmod +x bin/builder.mjs",
|
46
|
-
"build:dist-mjs": "rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs",
|
47
|
-
"build:dist-types": "rimraf dist-types && npx builder --type=types --outDir=dist-types",
|
48
|
-
"build:mjs": "rimraf build-mjs && bin/builder.mjs --type=module --outDir=build-mjs",
|
49
|
-
"build:mjs-bundle": "rimraf build-mjs-bundle && bin/builder.mjs --type=module --outDir=build-mjs-bundle --entryPoint=index.test.ts --outFile=index.test.mjs",
|
50
|
-
"build:mjs-bundle-minify": "rimraf build-mjs-bundle-minify && bin/builder.mjs --type=module --minify --outDir=build-mjs-bundle-minify --entryPoint=index.test.ts --outFile=index.test.mjs",
|
51
|
-
"build:mjs-bundle-no-external": "rimraf build-mjs-bundle-no-external && bin/builder.mjs --type=module --external=./node_modules/* --outDir=build-mjs-bundle-no-external --entryPoint=index.test.ts --outFile=index.test.mjs --minify",
|
52
|
-
"build:types": "rimraf build-types && bin/builder.mjs --type=types --outDir=build-types",
|
53
|
-
"ci:compile": "tsc --noEmit --rootDir src",
|
54
|
-
"ci:lint": "npm run lint",
|
55
|
-
"ci:style": "npm run prettier",
|
56
|
-
"ci:test": "npm run build && npm run test:node-mjs && npm run test:mjs && npm run test:mjs-bundle && npm run test:mjs-bundle-no-external",
|
57
|
-
"lint": "eslint --max-warnings 0 .",
|
58
|
-
"lint:fix": "eslint . --fix",
|
59
|
-
"prepare": "",
|
60
|
-
"prepublishOnly": "npm run build:builder && npm run build:dist-types && npm run build:dist-mjs",
|
61
|
-
"prettier": "prettier --ignore-path .gitignore --list-different .",
|
62
|
-
"prettier:fix": "prettier --ignore-path .gitignore --write .",
|
63
|
-
"test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style",
|
64
|
-
"test:mjs": "node --test build-mjs/test/index.mjs",
|
65
|
-
"test:mjs-bundle": "node --test build-mjs-bundle/index.test.mjs",
|
66
|
-
"test:mjs-bundle-minify": "node --test build-mjs-bundle-minify/index.test.mjs",
|
67
|
-
"test:mjs-bundle-no-external": "node --test build-mjs-bundle-no-external/index.test.mjs",
|
68
|
-
"test:node-mjs": "node --disable-warning ExperimentalWarning --experimental-strip-types --test-timeout 600000 --test \"src/**/*.spec.ts\""
|
69
|
-
},
|
70
|
-
"prettier": "@checkdigit/prettier-config",
|
71
|
-
"devDependencies": {
|
72
|
-
"@checkdigit/prettier-config": "^6.3.0",
|
73
|
-
"@eslint/js": "^9.22.0",
|
74
|
-
"@eslint/json": "^0.11.0",
|
75
|
-
"@eslint/markdown": "^6.3.0",
|
76
|
-
"eslint": "^9.22.0",
|
77
|
-
"eslint-config-prettier": "^10.1.1",
|
78
|
-
"eslint-plugin-yml": "^1.17.0",
|
79
|
-
"rimraf": "^6.0.1",
|
80
|
-
"typescript-eslint": "^8.26.1"
|
81
|
-
},
|
82
|
-
"peerDependencies": {
|
83
|
-
"@swc-node/register": "1.10.10",
|
84
|
-
"@types/node": ">=22",
|
85
|
-
"esbuild": "0.25.1",
|
86
|
-
"typescript": ">=5.8.2 <5.9.0"
|
87
|
-
},
|
88
|
-
"engines": {
|
89
|
-
"node": ">=22.14"
|
90
|
-
}
|
91
|
-
}
|
1
|
+
{"name":"@checkdigit/typescript-config","version":"9.2.0-PR.76-0a46","description":"Check Digit standard Typescript configuration","homepage":"https://github.com/checkdigit/typescript-config#readme","bugs":{"url":"https://github.com/checkdigit/typescript-config/issues"},"repository":{"type":"git","url":"git+https://github.com/checkdigit/typescript-config.git"},"license":"MIT","author":"Check Digit, LLC","type":"module","exports":{".":{"types":"./dist-types/index.d.ts","import":"./dist-mjs/index.mjs","default":"./tsconfig.json"}},"bin":{"builder":"./bin/builder.mjs"},"files":["bin","tsconfig.json","src","dist-types","dist-mjs","!src/**/test/**","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/test/**","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/test/**","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"build":"npm run build:builder && npm run build:types && npm run build:mjs && npm run build:mjs-bundle && npm run build:mjs-bundle-minify && npm run build:mjs-bundle-no-external","build:builder":"esbuild src/builder.ts --bundle --platform=node --format=esm --external:typescript --external:esbuild --outfile=build-builder/builder.mjs && mkdir -p bin && { echo '#!/usr/bin/env node'; cat build-builder/builder.mjs; } > bin/builder.mjs && chmod +x bin/builder.mjs","build:dist-mjs":"rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","build:dist-types":"rimraf dist-types && npx builder --type=types --outDir=dist-types","build:mjs":"rimraf build-mjs && bin/builder.mjs --type=module --outDir=build-mjs","build:mjs-bundle":"rimraf build-mjs-bundle && bin/builder.mjs --type=module --outDir=build-mjs-bundle --entryPoint=index.test.ts --outFile=index.test.mjs","build:mjs-bundle-minify":"rimraf build-mjs-bundle-minify && bin/builder.mjs --type=module --minify --outDir=build-mjs-bundle-minify --entryPoint=index.test.ts --outFile=index.test.mjs","build:mjs-bundle-no-external":"rimraf build-mjs-bundle-no-external && bin/builder.mjs --type=module --external=./node_modules/* --outDir=build-mjs-bundle-no-external --entryPoint=index.test.ts --outFile=index.test.mjs --minify","build:types":"rimraf build-types && bin/builder.mjs --type=types --outDir=build-types","ci:compile":"tsc --noEmit --rootDir src","ci:lint":"npm run lint","ci:style":"npm run prettier","ci:test":"npm run build && npm run test:node-mjs && npm run test:mjs && npm run test:mjs-bundle && npm run test:mjs-bundle-no-external","lint":"eslint --max-warnings 0 .","lint:fix":"eslint . --fix","prepare":"","prepublishOnly":"npm run build:builder && npm run build:dist-types && npm run build:dist-mjs","prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style","test:mjs":"node --test build-mjs/test/index.mjs","test:mjs-bundle":"node --test build-mjs-bundle/index.test.mjs","test:mjs-bundle-minify":"node --test build-mjs-bundle-minify/index.test.mjs","test:mjs-bundle-no-external":"node --test build-mjs-bundle-no-external/index.test.mjs","test:node-mjs":"node --disable-warning ExperimentalWarning --experimental-strip-types --test-timeout 600000 --test \"src/**/*.spec.ts\""},"prettier":"@checkdigit/prettier-config","devDependencies":{"@checkdigit/prettier-config":"^7.1.1","@eslint/js":"^9.30.0","@eslint/json":"^0.12.0","@eslint/markdown":"^6.6.0","eslint":"^9.30.0","eslint-config-prettier":"^10.1.5","eslint-plugin-yml":"^1.18.0","rimraf":"^6.0.1","typescript-eslint":"^8.35.1"},"peerDependencies":{"@swc-node/register":"1.10.10","@types/node":">=22","esbuild":"0.25.5","typescript":">=5.8.3 <5.9.0"},"engines":{"node":">=22.15"}}
|
package/src/analyze.ts
CHANGED
@@ -4,27 +4,45 @@ import { strict as assert } from 'node:assert';
|
|
4
4
|
|
5
5
|
import type { Metafile } from 'esbuild';
|
6
6
|
|
7
|
-
export default function analyze(metafile: Metafile): {
|
8
|
-
|
9
|
-
|
7
|
+
export default function analyze(metafile: Metafile): {
|
8
|
+
sourceBytes: number;
|
9
|
+
moduleBytes: number;
|
10
|
+
totalBytes: number;
|
11
|
+
} {
|
12
|
+
const source = new Set(
|
13
|
+
Object.keys(metafile.inputs).filter(
|
14
|
+
(key) => !key.startsWith('node_modules'),
|
15
|
+
),
|
16
|
+
);
|
17
|
+
const modules = new Set(
|
18
|
+
Object.keys(metafile.inputs).filter((key) =>
|
19
|
+
key.startsWith('node_modules'),
|
20
|
+
),
|
21
|
+
);
|
10
22
|
|
11
23
|
const [output] = Object.entries(metafile.outputs);
|
12
24
|
assert.ok(output !== undefined);
|
13
25
|
const [, bundle] = output;
|
14
26
|
|
15
|
-
const sourceBytes = Object.entries(bundle.inputs).reduce(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
27
|
+
const sourceBytes = Object.entries(bundle.inputs).reduce(
|
28
|
+
(bytes, [file, value]) => {
|
29
|
+
if (source.has(file)) {
|
30
|
+
return bytes + value.bytesInOutput;
|
31
|
+
}
|
32
|
+
return bytes;
|
33
|
+
},
|
34
|
+
0,
|
35
|
+
);
|
21
36
|
|
22
|
-
const moduleBytes = Object.entries(bundle.inputs).reduce(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
37
|
+
const moduleBytes = Object.entries(bundle.inputs).reduce(
|
38
|
+
(bytes, [file, value]) => {
|
39
|
+
if (modules.has(file)) {
|
40
|
+
return bytes + value.bytesInOutput;
|
41
|
+
}
|
42
|
+
return bytes;
|
43
|
+
},
|
44
|
+
0,
|
45
|
+
);
|
28
46
|
|
29
47
|
return {
|
30
48
|
sourceBytes,
|
package/src/builder.ts
CHANGED
@@ -8,7 +8,16 @@ import { parseArgs } from 'node:util';
|
|
8
8
|
import { analyze, compile } from './index.ts';
|
9
9
|
|
10
10
|
const {
|
11
|
-
values: {
|
11
|
+
values: {
|
12
|
+
type,
|
13
|
+
inDir,
|
14
|
+
outDir,
|
15
|
+
entryPoint,
|
16
|
+
outFile,
|
17
|
+
external,
|
18
|
+
minify,
|
19
|
+
sourceMap,
|
20
|
+
},
|
12
21
|
} = parseArgs({
|
13
22
|
options: {
|
14
23
|
type: { type: 'string', short: 't', default: 'module' },
|
@@ -22,7 +31,10 @@ const {
|
|
22
31
|
},
|
23
32
|
});
|
24
33
|
|
25
|
-
assert.ok(
|
34
|
+
assert.ok(
|
35
|
+
type === 'module' || type === 'types',
|
36
|
+
'type must be types or module',
|
37
|
+
);
|
26
38
|
|
27
39
|
const compileResult = await compile({
|
28
40
|
type,
|
@@ -46,7 +58,10 @@ await Promise.all(
|
|
46
58
|
// write metafile.json
|
47
59
|
if (compileResult.metafile !== undefined) {
|
48
60
|
const analysis = analyze(compileResult.metafile);
|
49
|
-
await fs.writeFile(
|
61
|
+
await fs.writeFile(
|
62
|
+
path.join(outDir, 'metafile.json'),
|
63
|
+
JSON.stringify(compileResult.metafile, undefined, 2),
|
64
|
+
);
|
50
65
|
|
51
66
|
// eslint-disable-next-line no-console
|
52
67
|
console.log(
|
package/src/compile.ts
CHANGED
@@ -157,7 +157,9 @@ function excludeSourceMaps(filter: RegExp) {
|
|
157
157
|
function resolveTypescriptPaths() {
|
158
158
|
return (pluginBuild: PluginBuild) => {
|
159
159
|
// rewrite paths based on standard node resolution
|
160
|
-
|
160
|
+
// Note: the /u flag cannot be used here because the underlying Go implementation does not support it
|
161
|
+
// eslint-disable-next-line require-unicode-regexp
|
162
|
+
pluginBuild.onResolve({ filter: /.*/ }, async (resolved) => {
|
161
163
|
if (
|
162
164
|
resolved.kind === 'entry-point' ||
|
163
165
|
!resolved.path.startsWith('.') ||
|
@@ -168,7 +170,9 @@ function resolveTypescriptPaths() {
|
|
168
170
|
}
|
169
171
|
let isDirectory = false;
|
170
172
|
try {
|
171
|
-
const stats = await fs.lstat(
|
173
|
+
const stats = await fs.lstat(
|
174
|
+
path.join(resolved.resolveDir, resolved.path),
|
175
|
+
);
|
172
176
|
isDirectory = stats.isDirectory();
|
173
177
|
} catch {
|
174
178
|
// do nothing
|
@@ -199,18 +203,25 @@ export default async function ({
|
|
199
203
|
const messages: string[] = [];
|
200
204
|
|
201
205
|
assert.ok(
|
202
|
-
(entryPoint === undefined && outFile === undefined) ||
|
206
|
+
(entryPoint === undefined && outFile === undefined) ||
|
207
|
+
(entryPoint !== undefined && outFile !== undefined),
|
203
208
|
'entryPoint and outFile must both be provided',
|
204
209
|
);
|
205
210
|
|
206
211
|
const allSourceFiles = await getFiles(inDir);
|
207
212
|
const productionSourceFiles =
|
208
|
-
entryPoint === undefined
|
213
|
+
entryPoint === undefined
|
214
|
+
? allSourceFiles.filter((file) => file.endsWith('.ts'))
|
215
|
+
: [path.join(inDir, entryPoint)];
|
209
216
|
|
210
217
|
/**
|
211
218
|
* Emit declarations using TypeScript compiler if the type is 'types'. Otherwise, compile to ensure the build is good.
|
212
219
|
*/
|
213
|
-
const compilerOptions = typescript.parseJsonConfigFileContent(
|
220
|
+
const compilerOptions = typescript.parseJsonConfigFileContent(
|
221
|
+
tsConfigJson,
|
222
|
+
typescript.sys,
|
223
|
+
outDir,
|
224
|
+
).options;
|
214
225
|
const program = typescript.createProgram(productionSourceFiles, {
|
215
226
|
...compilerOptions,
|
216
227
|
noEmit: type !== 'types',
|
@@ -229,11 +240,21 @@ export default async function ({
|
|
229
240
|
for (const diagnostic of allDiagnostics) {
|
230
241
|
if (diagnostic.file) {
|
231
242
|
assert.ok(diagnostic.start !== undefined);
|
232
|
-
const { line, character } = typescript.getLineAndCharacterOfPosition(
|
233
|
-
|
234
|
-
|
243
|
+
const { line, character } = typescript.getLineAndCharacterOfPosition(
|
244
|
+
diagnostic.file,
|
245
|
+
diagnostic.start,
|
246
|
+
);
|
247
|
+
const message = typescript.flattenDiagnosticMessageText(
|
248
|
+
diagnostic.messageText,
|
249
|
+
'\n',
|
250
|
+
);
|
251
|
+
messages.push(
|
252
|
+
`tsc: ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`,
|
253
|
+
);
|
235
254
|
} else {
|
236
|
-
messages.push(
|
255
|
+
messages.push(
|
256
|
+
`tsc: ${typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n')}`,
|
257
|
+
);
|
237
258
|
}
|
238
259
|
}
|
239
260
|
|
@@ -289,13 +310,17 @@ export default async function ({
|
|
289
310
|
plugins: [
|
290
311
|
{
|
291
312
|
name: 'exclude-source-maps',
|
292
|
-
|
313
|
+
// Note: the /u flag cannot be used here because the underlying Go implementation does not support it
|
314
|
+
// eslint-disable-next-line require-unicode-regexp
|
315
|
+
setup: excludeSourceMaps(/node_modules/),
|
293
316
|
},
|
294
317
|
],
|
295
318
|
}),
|
296
319
|
});
|
297
320
|
|
298
|
-
messages.push(
|
321
|
+
messages.push(
|
322
|
+
...buildResult.errors.map((error) => `esbuild error: ${error.text}`),
|
323
|
+
);
|
299
324
|
if (messages.length > 0) {
|
300
325
|
throw new Error(`esbuild failed ${JSON.stringify(messages)}`);
|
301
326
|
}
|