@checkdigit/typescript-config 5.2.0-PR.47-e8bc → 6.0.0-PR.47-da40
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/bin/builder.mjs +69 -22
- package/package.json +1 -1
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
|
13
|
+
- currently requires Node 20 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 NodeJS are fast moving
|
16
16
|
targets, and can add language features at any time.
|
package/bin/builder.mjs
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
// src/builder/index.mts
|
3
|
-
import { strict as
|
3
|
+
import { strict as assert3 } from "node:assert";
|
4
|
+
import { promises as fs2 } from "node:fs";
|
4
5
|
import path2 from "node:path";
|
5
6
|
import { parseArgs } from "node:util";
|
6
7
|
|
@@ -70,9 +71,10 @@ async function builder_default({
|
|
70
71
|
outFile: outFile2,
|
71
72
|
external: external2 = [],
|
72
73
|
minify: minify2 = false,
|
73
|
-
sourceMap: sourceMap2
|
74
|
+
sourceMap: sourceMap2,
|
75
|
+
workingDirectory = process.cwd()
|
74
76
|
}) {
|
75
|
-
const
|
77
|
+
const messages = [];
|
76
78
|
assert.ok(
|
77
79
|
entryPoint2 === void 0 && outFile2 === void 0 || entryPoint2 !== void 0 && outFile2 !== void 0,
|
78
80
|
"entryPoint and outFile must both be provided"
|
@@ -111,7 +113,10 @@ async function builder_default({
|
|
111
113
|
useUnknownInCatchVariables: true,
|
112
114
|
exactOptionalPropertyTypes: true
|
113
115
|
});
|
114
|
-
const
|
116
|
+
const declarationFiles = [];
|
117
|
+
const emitResult = program.emit(void 0, (fileName, data) => {
|
118
|
+
declarationFiles.push({ path: fileName, text: data });
|
119
|
+
});
|
115
120
|
const allDiagnostics = typescript.sortAndDeduplicateDiagnostics([
|
116
121
|
...typescript.getPreEmitDiagnostics(program),
|
117
122
|
...emitResult.diagnostics
|
@@ -121,23 +126,29 @@ async function builder_default({
|
|
121
126
|
assert.ok(diagnostic.start !== void 0);
|
122
127
|
const { line, character } = typescript.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
123
128
|
const message = typescript.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
124
|
-
|
129
|
+
messages.push(`tsc: ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
125
130
|
} else {
|
126
|
-
|
131
|
+
messages.push(`tsc: ${typescript.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
|
127
132
|
}
|
128
133
|
}
|
129
|
-
if (
|
130
|
-
throw new Error(`tsc failed ${JSON.stringify(
|
134
|
+
if (messages.length > 0) {
|
135
|
+
throw new Error(`tsc failed ${JSON.stringify(messages)}`);
|
131
136
|
}
|
132
137
|
if (type2 === "types") {
|
133
|
-
return
|
138
|
+
return {
|
139
|
+
outputFiles: declarationFiles
|
140
|
+
};
|
134
141
|
}
|
135
|
-
const
|
142
|
+
const buildResult2 = await build({
|
136
143
|
entryPoints: productionSourceFiles,
|
137
144
|
bundle: true,
|
138
145
|
minify: minify2,
|
146
|
+
absWorkingDir: workingDirectory,
|
139
147
|
platform: "node",
|
140
148
|
format: type2 === "module" ? "esm" : "cjs",
|
149
|
+
treeShaking: type2 === "module",
|
150
|
+
write: false,
|
151
|
+
metafile: outFile2 !== void 0,
|
141
152
|
sourcesContent: false,
|
142
153
|
banner: type2 === "module" && outFile2 !== void 0 ? {
|
143
154
|
js: commonJsCompatabilityBanner
|
@@ -166,12 +177,39 @@ async function builder_default({
|
|
166
177
|
]
|
167
178
|
}
|
168
179
|
});
|
169
|
-
|
170
|
-
|
171
|
-
if (
|
172
|
-
throw new Error(`esbuild failed ${JSON.stringify(
|
180
|
+
messages.push(...buildResult2.errors.map((error) => `esbuild error: ${error.text}`));
|
181
|
+
messages.push(...buildResult2.warnings.map((warning) => `esbuild warning: ${warning.text}`));
|
182
|
+
if (messages.length > 0) {
|
183
|
+
throw new Error(`esbuild failed ${JSON.stringify(messages)}`);
|
173
184
|
}
|
174
|
-
return
|
185
|
+
return buildResult2;
|
186
|
+
}
|
187
|
+
|
188
|
+
// src/builder/analyze.mts
|
189
|
+
import { strict as assert2 } from "node:assert";
|
190
|
+
function analyze(metafile) {
|
191
|
+
const source = new Set(Object.keys(metafile.inputs).filter((key) => !key.startsWith("node_modules")));
|
192
|
+
const modules = new Set(Object.keys(metafile.inputs).filter((key) => key.startsWith("node_modules")));
|
193
|
+
const [output] = Object.entries(metafile.outputs);
|
194
|
+
assert2.ok(output !== void 0);
|
195
|
+
const [, bundle] = output;
|
196
|
+
const sourceBytes = Object.entries(bundle.inputs).reduce((bytes, [file, value]) => {
|
197
|
+
if (source.has(file)) {
|
198
|
+
return bytes + value.bytesInOutput;
|
199
|
+
}
|
200
|
+
return bytes;
|
201
|
+
}, 0);
|
202
|
+
const moduleBytes = Object.entries(bundle.inputs).reduce((bytes, [file, value]) => {
|
203
|
+
if (modules.has(file)) {
|
204
|
+
return bytes + value.bytesInOutput;
|
205
|
+
}
|
206
|
+
return bytes;
|
207
|
+
}, 0);
|
208
|
+
return {
|
209
|
+
sourceBytes,
|
210
|
+
moduleBytes,
|
211
|
+
totalBytes: bundle.bytes
|
212
|
+
};
|
175
213
|
}
|
176
214
|
|
177
215
|
// src/builder/index.mts
|
@@ -189,10 +227,10 @@ var {
|
|
189
227
|
sourceMap: { type: "boolean", short: "s", default: false }
|
190
228
|
}
|
191
229
|
});
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
var
|
230
|
+
assert3.ok(type === "module" || type === "commonjs" || type === "types", "type must be types, module or commonjs");
|
231
|
+
assert3.ok(inDir !== void 0, "inDir is required");
|
232
|
+
assert3.ok(outDir !== void 0, "outDir is required");
|
233
|
+
var buildResult = await builder_default({
|
196
234
|
type,
|
197
235
|
inDir: path2.join(process.cwd(), inDir),
|
198
236
|
outDir: path2.join(process.cwd(), outDir),
|
@@ -202,7 +240,16 @@ var messages = await builder_default({
|
|
202
240
|
minify,
|
203
241
|
sourceMap
|
204
242
|
});
|
205
|
-
|
206
|
-
|
207
|
-
|
243
|
+
await Promise.all(
|
244
|
+
buildResult.outputFiles.map(async (file) => {
|
245
|
+
await fs2.mkdir(path2.join(path2.dirname(file.path)), { recursive: true });
|
246
|
+
await fs2.writeFile(file.path, file.text);
|
247
|
+
})
|
248
|
+
);
|
249
|
+
if (buildResult.metafile !== void 0) {
|
250
|
+
const analysis = analyze(buildResult.metafile);
|
251
|
+
await fs2.writeFile(path2.join(outDir, "metafile.json"), JSON.stringify(buildResult.metafile, void 0, 2));
|
252
|
+
console.log(
|
253
|
+
`${outFile}: src ${analysis.sourceBytes}, node_modules ${analysis.moduleBytes}, total ${analysis.totalBytes}`
|
254
|
+
);
|
208
255
|
}
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@checkdigit/typescript-config","version":"
|
1
|
+
{"name":"@checkdigit/typescript-config","version":"6.0.0-PR.47-da40","description":"Check Digit standard Typescript configuration","prettier":"@checkdigit/prettier-config","engines":{"node":">=20.9"},"bin":{"builder":"./bin/builder.mjs"},"peerDependencies":{"@types/node":">=20.9","esbuild":"0.19.5","typescript":"5.3.1-rc"},"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/index.mts --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-cjs":"rimraf build-cjs && bin/builder.mjs --type=commonjs --outDir=build-cjs","build-cjs-bundle":"rimraf build-cjs-bundle && bin/builder.mjs --type=commonjs --entryPoint=test/index.test.ts --outDir=build-cjs-bundle --outFile=test/index.test.cjs --sourceMap","build-cjs-bundle-minify":"rimraf build-cjs-bundle-minify && bin/builder.mjs --type=commonjs --entryPoint=test/index.test.ts --outDir=build-cjs-bundle-minify --outFile=test/index.test.cjs --minify --sourceMap","build-cjs-bundle-no-external":"rimraf build-cjs-bundle-no-external && bin/builder.mjs --type=commonjs --external=./node_modules/* --entryPoint=test/index.test.ts --outDir=build-cjs-bundle-no-external --outFile=test/index.test.cjs","build-esm":"rimraf build-esm && bin/builder.mjs --type=module --outDir=build-esm","build-esm-bundle":"rimraf build-esm-bundle && bin/builder.mjs --type=module --outDir=build-esm-bundle --entryPoint=test/index.test.ts --outFile=test/index.test.mjs","build-esm-bundle-minify":"rimraf build-esm-bundle-minify && bin/builder.mjs --type=module --minify --outDir=build-esm-bundle-minify --entryPoint=test/index.test.ts --outFile=test/index.test.mjs","build-esm-bundle-no-external":"rimraf build-esm-bundle-no-external && bin/builder.mjs --type=module --external=./node_modules/* --outDir=build-esm-bundle-no-external --entryPoint=test/index.test.ts --outFile=test/index.test.mjs --minify","test-jest-esm":"NODE_OPTIONS=\"--experimental-vm-modules\" jest --coverage=false src/*.mts src/*/*.mts src/*/*/*.mts","test-jest-cjs":"jest --coverage=false src/*.ts src/*/*.ts src/*/*/*.ts","test-cjs":"node --test build-cjs/test/index.test.cjs","test-cjs-bundle":"node --test build-cjs-bundle/test/index.test.cjs","test-cjs-bundle-minify":"node --test build-cjs-bundle-minify/test/index.test.cjs","test-cjs-bundle-no-external":"node --test build-cjs-bundle-no-external/test/index.test.cjs","test-esm":"node --test build-esm/test/index.test.mjs","test-esm-bundle":"node --test build-esm-bundle/test/index.test.mjs","test-esm-bundle-minify":"node --test build-esm-bundle-minify/test/index.test.mjs","test-esm-bundle-no-external":"node --test build-esm-bundle-no-external/test/index.test.mjs","ci:test":"npm run test-jest-cjs && npm run test-jest-esm && npm run test-cjs && npm run test-cjs-bundle && npm run test-cjs-bundle-no-external && npm run test-esm && npm run test-esm-bundle && npm run test-esm-bundle-no-external","ci:compile":"tsc --noEmit && npm run build-builder && npm run build-types && npm run build-cjs && npm run build-cjs-bundle && npm run build-cjs-bundle-minify && npm run build-cjs-bundle-no-external && npm run build-esm && npm run build-esm-bundle && npm run build-esm-bundle-minify && npm run build-esm-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.0.0-PR.29-ad02","@types/debug":"^4.1.12","@types/jest":"^29.5.8","@types/uuid":"^9.0.7","@typescript-eslint/eslint-plugin":"^6.11.0","@typescript-eslint/parser":"^6.11.0","debug":"^4.3.4","eslint":"^8.53.0","eslint-config-prettier":"^9.0.0","get-port":"^7.0.0","got":"^11.8.6","jest":"^29.7.0","node-fetch":"^3.3.2","rimraf":"^5.0.5","ts-jest":"^29.1.1","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.mts","*.test.mts","*.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","mts","json","node"],"extensionsToTreatAsEsm":[".mts"],"transform":{"^.+\\.mts$":["ts-jest",{"isolatedModules":true,"diagnostics":false,"useESM":true}],"^.+\\.ts$":["ts-jest",{"isolatedModules":true,"diagnostics":false,"useESM":false}]},"collectCoverageFrom":["<rootDir>/src/**"],"testMatch":["<rootDir>/src/**/*.spec.ts","<rootDir>/src/**/*.spec.mts"]},"files":["bin","tsconfig.json","SECURITY.md"],"overrides":{"typescript":"5.3.1-rc"}}
|