@checkdigit/typescript-config 7.0.0-PR.54-665c → 7.0.0-PR.54-eb75
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/bin/builder.mjs +42 -42
- package/package.json +1 -1
package/bin/builder.mjs
CHANGED
@@ -1,12 +1,39 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
// src/builder
|
2
|
+
// src/builder.ts
|
3
3
|
import { strict as assert3 } from "node:assert";
|
4
4
|
import { promises as fs2 } from "node:fs";
|
5
5
|
import path2 from "node:path";
|
6
6
|
import { parseArgs } from "node:util";
|
7
7
|
|
8
|
-
// src/
|
8
|
+
// src/analyze.ts
|
9
9
|
import { strict as assert } from "node:assert";
|
10
|
+
function analyze(metafile) {
|
11
|
+
const source = new Set(Object.keys(metafile.inputs).filter((key) => !key.startsWith("node_modules")));
|
12
|
+
const modules = new Set(Object.keys(metafile.inputs).filter((key) => key.startsWith("node_modules")));
|
13
|
+
const [output] = Object.entries(metafile.outputs);
|
14
|
+
assert.ok(output !== void 0);
|
15
|
+
const [, bundle] = output;
|
16
|
+
const sourceBytes = Object.entries(bundle.inputs).reduce((bytes, [file, value]) => {
|
17
|
+
if (source.has(file)) {
|
18
|
+
return bytes + value.bytesInOutput;
|
19
|
+
}
|
20
|
+
return bytes;
|
21
|
+
}, 0);
|
22
|
+
const moduleBytes = Object.entries(bundle.inputs).reduce((bytes, [file, value]) => {
|
23
|
+
if (modules.has(file)) {
|
24
|
+
return bytes + value.bytesInOutput;
|
25
|
+
}
|
26
|
+
return bytes;
|
27
|
+
}, 0);
|
28
|
+
return {
|
29
|
+
sourceBytes,
|
30
|
+
moduleBytes,
|
31
|
+
totalBytes: bundle.bytes
|
32
|
+
};
|
33
|
+
}
|
34
|
+
|
35
|
+
// src/compile.ts
|
36
|
+
import { strict as assert2 } from "node:assert";
|
10
37
|
import { promises as fs } from "node:fs";
|
11
38
|
import path from "node:path";
|
12
39
|
import typescript from "typescript";
|
@@ -62,7 +89,7 @@ function resolveTypescriptPaths() {
|
|
62
89
|
});
|
63
90
|
};
|
64
91
|
}
|
65
|
-
async function
|
92
|
+
async function compile_default({
|
66
93
|
type: type2,
|
67
94
|
entryPoint: entryPoint2,
|
68
95
|
inDir: inDir2,
|
@@ -74,7 +101,7 @@ async function builder_default({
|
|
74
101
|
workingDirectory = process.cwd()
|
75
102
|
}) {
|
76
103
|
const messages = [];
|
77
|
-
|
104
|
+
assert2.ok(
|
78
105
|
entryPoint2 === void 0 && outFile2 === void 0 || entryPoint2 !== void 0 && outFile2 !== void 0,
|
79
106
|
"entryPoint and outFile must both be provided"
|
80
107
|
);
|
@@ -122,7 +149,7 @@ async function builder_default({
|
|
122
149
|
]);
|
123
150
|
for (const diagnostic of allDiagnostics) {
|
124
151
|
if (diagnostic.file) {
|
125
|
-
|
152
|
+
assert2.ok(diagnostic.start !== void 0);
|
126
153
|
const { line, character } = typescript.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
127
154
|
const message = typescript.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
128
155
|
messages.push(`tsc: ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
@@ -138,7 +165,7 @@ async function builder_default({
|
|
138
165
|
outputFiles: declarationFiles
|
139
166
|
};
|
140
167
|
}
|
141
|
-
const
|
168
|
+
const buildResult = await build({
|
142
169
|
entryPoints: productionSourceFiles,
|
143
170
|
bundle: true,
|
144
171
|
minify: minify2,
|
@@ -176,42 +203,15 @@ async function builder_default({
|
|
176
203
|
]
|
177
204
|
}
|
178
205
|
});
|
179
|
-
messages.push(...
|
180
|
-
messages.push(...
|
206
|
+
messages.push(...buildResult.errors.map((error) => `esbuild error: ${error.text}`));
|
207
|
+
messages.push(...buildResult.warnings.map((warning) => `esbuild warning: ${warning.text}`));
|
181
208
|
if (messages.length > 0) {
|
182
209
|
throw new Error(`esbuild failed ${JSON.stringify(messages)}`);
|
183
210
|
}
|
184
|
-
return
|
185
|
-
}
|
186
|
-
|
187
|
-
// src/builder/analyze.ts
|
188
|
-
import { strict as assert2 } from "node:assert";
|
189
|
-
function analyze(metafile) {
|
190
|
-
const source = new Set(Object.keys(metafile.inputs).filter((key) => !key.startsWith("node_modules")));
|
191
|
-
const modules = new Set(Object.keys(metafile.inputs).filter((key) => key.startsWith("node_modules")));
|
192
|
-
const [output] = Object.entries(metafile.outputs);
|
193
|
-
assert2.ok(output !== void 0);
|
194
|
-
const [, bundle] = output;
|
195
|
-
const sourceBytes = Object.entries(bundle.inputs).reduce((bytes, [file, value]) => {
|
196
|
-
if (source.has(file)) {
|
197
|
-
return bytes + value.bytesInOutput;
|
198
|
-
}
|
199
|
-
return bytes;
|
200
|
-
}, 0);
|
201
|
-
const moduleBytes = Object.entries(bundle.inputs).reduce((bytes, [file, value]) => {
|
202
|
-
if (modules.has(file)) {
|
203
|
-
return bytes + value.bytesInOutput;
|
204
|
-
}
|
205
|
-
return bytes;
|
206
|
-
}, 0);
|
207
|
-
return {
|
208
|
-
sourceBytes,
|
209
|
-
moduleBytes,
|
210
|
-
totalBytes: bundle.bytes
|
211
|
-
};
|
211
|
+
return buildResult;
|
212
212
|
}
|
213
213
|
|
214
|
-
// src/builder
|
214
|
+
// src/builder.ts
|
215
215
|
var {
|
216
216
|
values: { type, inDir, outDir, entryPoint, outFile, external, minify, sourceMap }
|
217
217
|
} = parseArgs({
|
@@ -229,7 +229,7 @@ var {
|
|
229
229
|
assert3.ok(type === "module" || type === "types", "type must be types or module");
|
230
230
|
assert3.ok(inDir !== void 0, "inDir is required");
|
231
231
|
assert3.ok(outDir !== void 0, "outDir is required");
|
232
|
-
var
|
232
|
+
var compileResult = await compile_default({
|
233
233
|
type,
|
234
234
|
inDir: path2.join(process.cwd(), inDir),
|
235
235
|
outDir: path2.join(process.cwd(), outDir),
|
@@ -240,14 +240,14 @@ var buildResult = await builder_default({
|
|
240
240
|
sourceMap
|
241
241
|
});
|
242
242
|
await Promise.all(
|
243
|
-
|
243
|
+
compileResult.outputFiles.map(async (file) => {
|
244
244
|
await fs2.mkdir(path2.join(path2.dirname(file.path)), { recursive: true });
|
245
245
|
await fs2.writeFile(file.path, file.text);
|
246
246
|
})
|
247
247
|
);
|
248
|
-
if (
|
249
|
-
const analysis = analyze(
|
250
|
-
await fs2.writeFile(path2.join(outDir, "metafile.json"), JSON.stringify(
|
248
|
+
if (compileResult.metafile !== void 0) {
|
249
|
+
const analysis = analyze(compileResult.metafile);
|
250
|
+
await fs2.writeFile(path2.join(outDir, "metafile.json"), JSON.stringify(compileResult.metafile, void 0, 2));
|
251
251
|
console.log(
|
252
252
|
`${outFile}: src ${analysis.sourceBytes}, node_modules ${analysis.moduleBytes}, total ${analysis.totalBytes}`
|
253
253
|
);
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@checkdigit/typescript-config","version":"7.0.0-PR.54-
|
1
|
+
{"name":"@checkdigit/typescript-config","version":"7.0.0-PR.54-eb75","description":"Check Digit standard Typescript configuration","prettier":"@checkdigit/prettier-config","engines":{"node":">=20.11"},"type":"module","bin":{"builder":"./bin/builder.mjs"},"peerDependencies":{"@types/node":">=20.11","esbuild":"0.20.0","typescript":"5.4.0-beta"},"repository":{"type":"git","url":"git+https://github.com/checkdigit/typescript-config.git"},"author":"Check Digit, LLC","license":"MIT","bugs":{"url":"https://github.com/checkdigit/typescript-config/issues"},"homepage":"https://github.com/checkdigit/typescript-config#readme","scripts":{"prepublishOnly":"npm run build-builder","lint:fix":"eslint --ignore-path .gitignore . --fix","lint":"eslint --max-warnings 0 --ignore-path .gitignore .","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","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-types":"rimraf build-types && bin/builder.mjs --type=types --outDir=build-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=test/index.test.ts --outFile=test/index.test.mjs","build-mjs-bundle-minify":"rimraf build-mjs-bundle-minify && bin/builder.mjs --type=module --minify --outDir=build-mjs-bundle-minify --entryPoint=test/index.test.ts --outFile=test/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=test/index.test.ts --outFile=test/index.test.mjs --minify","test-jest-mjs":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false","test-mjs":"node --test build-mjs/test/index.test.mjs","test-mjs-bundle":"node --test build-mjs-bundle/test/index.test.mjs","test-mjs-bundle-minify":"node --test build-mjs-bundle-minify/test/index.test.mjs","test-mjs-bundle-no-external":"node --test build-mjs-bundle-no-external/test/index.test.mjs","ci:test":"npm run test-jest-mjs && npm run test-mjs && npm run test-mjs-bundle && npm run test-mjs-bundle-no-external","ci:compile":"tsc --noEmit && 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","ci:lint":"npm run lint","ci:style":"npm run prettier"},"devDependencies":{"@apidevtools/json-schema-ref-parser":"^11.1.0","@checkdigit/prettier-config":"^5.2.0","@types/debug":"^4.1.12","@types/jest":"^29.5.11","@types/uuid":"^9.0.8","@typescript-eslint/eslint-plugin":"^6.20.0","@typescript-eslint/parser":"^6.20.0","debug":"^4.3.4","eslint":"^8.56.0","eslint-config-prettier":"^9.1.0","jest":"^29.7.0","node-fetch":"^3.3.2","rimraf":"^5.0.5","ts-jest":"^29.1.2","uuid":"^9.0.1"},"eslintConfig":{"parser":"@typescript-eslint/parser","plugins":["@typescript-eslint"],"parserOptions":{"project":"./tsconfig.json"},"extends":["eslint:all","plugin:@typescript-eslint/recommended","plugin:@typescript-eslint/recommended-requiring-type-checking","plugin:@typescript-eslint/strict","prettier"],"rules":{"@typescript-eslint/non-nullable-type-assertion-style":"error","capitalized-comments":"off","one-var":"off","sort-keys":"off","sort-imports":"off","max-lines":["error",{"max":500,"skipBlankLines":true,"skipComments":true}],"func-style":["error","declaration",{"allowArrowFunctions":true}],"no-magic-numbers":["error",{"ignore":[0,1,2]}],"no-undefined":"off","no-ternary":"off"},"overrides":[{"files":["*.spec.ts","*.test.ts"],"rules":{"@typescript-eslint/non-nullable-type-assertion-style":"off","@typescript-eslint/ban-types":"off","@typescript-eslint/require-await":"off","@typescript-eslint/consistent-type-definitions":"off","@typescript-eslint/ban-ts-comment":"off","@typescript-eslint/no-unnecessary-condition":"off","@typescript-eslint/consistent-indexed-object-style":"off","@typescript-eslint/no-unused-vars":"off","@typescript-eslint/no-unsafe-member-access":"off","line-comment-position":"off","no-fallthrough":"off","no-inline-comments":"off","no-param-reassign":"off","id-length":"off","no-magic-numbers":"off","func-names":"off","no-duplicate-imports":"off","symbol-description":"off","no-invalid-this":"off","max-lines-per-function":"off","max-lines":"off","max-statements":"off","no-await-in-loop":"off"}}]},"jest":{"moduleFileExtensions":["js","mjs","cjs","ts","json","node"],"extensionsToTreatAsEsm":[".ts"],"transform":{"^.+\\.ts$":["ts-jest",{"isolatedModules":true,"diagnostics":false,"useESM":true}]},"collectCoverageFrom":["<rootDir>/src/**"],"testMatch":["<rootDir>/src/**/*.spec.ts"]},"files":["bin","tsconfig.json","SECURITY.md"],"overrides":{"typescript":"5.4.0-beta"}}
|