@checkdigit/typescript-config 11.0.0-PR.82-1629 → 11.0.0-PR.82-fd65
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 +51 -42
- package/bin/builder.mjs +19 -24
- package/dist-mjs/compile.mjs +20 -25
- package/package.json +1 -1
- package/src/compile.ts +25 -33
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# checkdigit/typescript-config
|
|
2
2
|
|
|
3
|
-
[](https://github.com/checkdigit/typescript-config/blob/
|
|
3
|
+
[](https://github.com/checkdigit/typescript-config/blob/main/LICENSE.txt)
|
|
4
4
|
|
|
5
5
|
Copyright © 2021–2026 [Check Digit, LLC](https://checkdigit.com)
|
|
6
6
|
|
|
@@ -10,39 +10,46 @@ This module contains the standard Check Digit TypeScript configuration, along wi
|
|
|
10
10
|
|
|
11
11
|
## TypeScript Configuration
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
-
|
|
13
|
+
- Requires Node.js 26.13 or later and `@types/node` 26 or later.
|
|
14
|
+
- Targets `esnext`, with the default libraries. Application tests should check that the features used are available
|
|
15
|
+
in the deployment runtime.
|
|
16
|
+
- Uses `moduleResolution: "bundler"` and `verbatimModuleSyntax`.
|
|
17
|
+
- Enables `strict` mode and additional checks, including `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`,
|
|
18
|
+
and unused local and parameter checks.
|
|
19
|
+
- Enables `isolatedDeclarations`, `allowImportingTsExtensions`, and `erasableSyntaxOnly`.
|
|
20
|
+
- Sets `noEmit: true`; use `builder` to generate JavaScript and declarations.
|
|
20
21
|
|
|
21
22
|
## Builder
|
|
22
23
|
|
|
23
|
-
`builder` is a command line tool that generates ESM modules
|
|
24
|
-
It is intended to be used when publishing a package to
|
|
25
|
-
It
|
|
24
|
+
`builder` is a command line tool that generates ESM `.mjs` modules or TypeScript `.d.ts` declarations.
|
|
25
|
+
It is intended to be used when publishing a package to npm, or to bundle a package for deployment to Node.js.
|
|
26
|
+
It type-checks the source with the native TypeScript compiler before generating output, using the compiler's async API
|
|
27
|
+
for declarations and `esbuild` for JavaScript.
|
|
26
28
|
|
|
27
|
-
The compiler
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
The compiler peer dependency is TypeScript `7.1.0`, installed under the `@typescript/native` npm alias.
|
|
30
|
+
This repository's lint tooling separately uses the TypeScript 6 compatibility package (`@typescript/typescript6`,
|
|
31
|
+
installed as `typescript`) for `typescript-eslint`.
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
The builder uses this package's compiler configuration directly; it does not read the consuming project's `tsconfig.json`.
|
|
34
|
+
Without an entry point, it processes all `.ts` files under the input directory recursively, including test files,
|
|
35
|
+
and rewrites relative TypeScript imports for the generated `.mjs` files.
|
|
36
|
+
|
|
37
|
+
Single-file bundles include Node.js compatibility bindings for `require`, `__filename`, and `__dirname` to support
|
|
38
|
+
bundled CommonJS dependencies. These bindings are local to the bundle, and the output is intended for Node.js.
|
|
39
|
+
Bundle builds also write `metafile.json` in the output directory and print a size summary.
|
|
33
40
|
|
|
34
41
|
### Options
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
| Option | Short form | Description |
|
|
44
|
+
| -------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
45
|
+
| `--type` | `-t` | Output type: `module` (ESM, the default) or `types` (declarations). |
|
|
46
|
+
| `--inDir` | `-i` | Input source directory, relative to the current directory. Defaults to `src`. |
|
|
47
|
+
| `--outDir` | `-o` | Output directory, relative to the current directory. Defaults to `build`. |
|
|
48
|
+
| `--entryPoint` | `-e` | Entry point relative to `--inDir`. For module output, enables a single-file bundle. Requires `--outFile`. |
|
|
49
|
+
| `--outFile` | `-f` | Bundle filename relative to `--outDir`. Requires `--entryPoint`. Does not combine declaration files. |
|
|
50
|
+
| `--external` | `-x` | Modules to exclude from a bundle. Repeat for multiple patterns; quote wildcard `*` patterns. Node.js built-ins are always external. |
|
|
51
|
+
| `--minify` | `-m` | Minify JavaScript output. Defaults to `false`. |
|
|
52
|
+
| `--sourceMap` | `-s` | Include inline JavaScript source maps. Defaults to `false`. |
|
|
46
53
|
|
|
47
54
|
### Examples
|
|
48
55
|
|
|
@@ -52,20 +59,25 @@ npx builder --type=module --outDir=build-esm
|
|
|
52
59
|
|
|
53
60
|
# build single-file ESM .mjs bundle from TypeScript source
|
|
54
61
|
npx builder --type=module --outDir=build-esm-bundle --entryPoint=index.ts --outFile=index.mjs
|
|
62
|
+
|
|
63
|
+
# generate declarations alongside the JavaScript build
|
|
64
|
+
npx builder --type=types --outDir=build-types
|
|
65
|
+
|
|
66
|
+
# bundle with source maps while leaving selected dependencies external
|
|
67
|
+
npx builder --entryPoint=index.ts --outFile=index.mjs --sourceMap --external='@example/*' --external=another-package
|
|
55
68
|
```
|
|
56
69
|
|
|
57
70
|
## Tests
|
|
58
71
|
|
|
59
|
-
This module includes
|
|
60
|
-
|
|
61
|
-
with `builder`, in addition to runtimes, libraries and frameworks used by Check Digit:
|
|
72
|
+
This module includes compiler, builder, and runtime tests to check interoperability with the tools and
|
|
73
|
+
language features used by Check Digit:
|
|
62
74
|
|
|
63
75
|
- Recent TC39 proposals
|
|
64
|
-
- Node
|
|
65
|
-
- ESLint and
|
|
76
|
+
- Node.js APIs, with version-specific tests
|
|
77
|
+
- ESLint and `typescript-eslint`
|
|
66
78
|
- Built-in `node:test` runner
|
|
67
79
|
- `prettier`
|
|
68
|
-
-
|
|
80
|
+
- The native TypeScript compiler, and features introduced in TypeScript 5.x, 6.0, and 7.1
|
|
69
81
|
- `esbuild`
|
|
70
82
|
- Wallaby.js (supports `node:test` by relying on native Node type-stripping support)
|
|
71
83
|
|
|
@@ -81,12 +93,10 @@ the new version of TypeScript, and/or without emitting warnings during these tes
|
|
|
81
93
|
|
|
82
94
|
Strict semver is a little complicated, as TypeScript itself does not adhere to semver. So our "best effort" policy is:
|
|
83
95
|
|
|
84
|
-
- Each update to the minimum Node
|
|
96
|
+
- Each update to the minimum supported Node.js version, or a change to a major compiler output option
|
|
85
97
|
(e.g. `module`, `target` or `moduleResolution`) will result in a new major version of this module.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
- Each new "major" version of TypeScript (e.g. `5.7.x` to `5.8.x`) will result in a new minor version of this module.
|
|
89
|
-
- A new minor update of TypeScript (e.g. `5.7.2` to `5.7.3`) or a key dependency (e.g., Node `22.11` to Node `22.14`) _may_ result in a patch.
|
|
98
|
+
- Each new TypeScript feature release (e.g. `7.0.x` to `7.1.x`) will result in a new minor version of this module.
|
|
99
|
+
- A TypeScript patch release or a key dependency update _may_ result in a patch version of this module.
|
|
90
100
|
|
|
91
101
|
Bear in mind, any update of TypeScript can potentially break your build. But hopefully in a way that's useful.
|
|
92
102
|
|
|
@@ -96,8 +106,8 @@ Bear in mind, any update of TypeScript can potentially break your build. But hop
|
|
|
96
106
|
npm add -D @checkdigit/typescript-config
|
|
97
107
|
```
|
|
98
108
|
|
|
99
|
-
|
|
100
|
-
|
|
109
|
+
The required compiler (`@typescript/native`), `@types/node`, and `esbuild` are peer dependencies, which npm installs
|
|
110
|
+
automatically by default. A separate `typescript` installation is not required to use the builder.
|
|
101
111
|
|
|
102
112
|
Make sure your project's `tsconfig.json` extends `@checkdigit/typescript-config`.
|
|
103
113
|
|
|
@@ -109,9 +119,8 @@ Make sure your project's `tsconfig.json` extends `@checkdigit/typescript-config`
|
|
|
109
119
|
}
|
|
110
120
|
```
|
|
111
121
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
to produce working code for deployment.
|
|
122
|
+
This configuration checks types without emitting files and uses `moduleResolution: "bundler"`.
|
|
123
|
+
Use `builder` to produce deployable Node.js code, or another build tool that handles these module resolution rules.
|
|
115
124
|
|
|
116
125
|
## License
|
|
117
126
|
|
package/bin/builder.mjs
CHANGED
|
@@ -51,7 +51,7 @@ import { strict as assert2 } from "node:assert";
|
|
|
51
51
|
import { promises as fs } from "node:fs";
|
|
52
52
|
import path from "node:path";
|
|
53
53
|
import { fileURLToPath } from "node:url";
|
|
54
|
-
import { API } from "@typescript/native/
|
|
54
|
+
import { API } from "@typescript/native/async";
|
|
55
55
|
import { build } from "esbuild";
|
|
56
56
|
|
|
57
57
|
// tsconfig.json
|
|
@@ -94,11 +94,9 @@ var tsconfig_default = {
|
|
|
94
94
|
|
|
95
95
|
// src/compile.ts
|
|
96
96
|
var commonJsCompatabilityBanner = `import { createRequire as __createRequire } from "node:module";
|
|
97
|
-
|
|
98
|
-
const __filename = __fileURLToPath(import.meta.url);
|
|
97
|
+
const __filename = import.meta.filename;
|
|
99
98
|
const require = __createRequire(import.meta.url);`;
|
|
100
|
-
var dirNameJsCompatibilityInjection = `
|
|
101
|
-
export const __dirname = path.dirname(__filename);`;
|
|
99
|
+
var dirNameJsCompatibilityInjection = `export const __dirname = import.meta.dirname;`;
|
|
102
100
|
var dirNameJsCompatibilityInjectionURL = `data:text/javascript,${encodeURIComponent(dirNameJsCompatibilityInjection)}`;
|
|
103
101
|
async function getFiles(directory) {
|
|
104
102
|
const entries = await fs.readdir(directory, { withFileTypes: true });
|
|
@@ -176,25 +174,29 @@ async function compile_default({
|
|
|
176
174
|
);
|
|
177
175
|
const allSourceFiles = await getFiles(inDir2);
|
|
178
176
|
const productionSourceFiles = entryPoint2 === void 0 ? allSourceFiles.filter((file) => file.endsWith(".ts")) : [path.join(inDir2, entryPoint2)];
|
|
179
|
-
using api = new API();
|
|
180
|
-
const compilerOptions = api.parseJsonConfigFileContent(tsconfig_default, {
|
|
177
|
+
await using api = new API();
|
|
178
|
+
const compilerOptions = (await api.parseJsonConfigFileContent(tsconfig_default, {
|
|
181
179
|
// @checkdigit/typescript-config package root:
|
|
182
|
-
configDirectory: path.dirname(
|
|
183
|
-
|
|
184
|
-
|
|
180
|
+
configDirectory: path.dirname(
|
|
181
|
+
path.dirname(fileURLToPath(import.meta.url))
|
|
182
|
+
)
|
|
183
|
+
})).options;
|
|
184
|
+
await using program = await api.createProgram(productionSourceFiles, {
|
|
185
185
|
...compilerOptions,
|
|
186
186
|
noEmit: type2 !== "types",
|
|
187
187
|
emitDeclarationOnly: type2 === "types",
|
|
188
188
|
rootDir: inDir2,
|
|
189
189
|
outDir: outDir2
|
|
190
190
|
});
|
|
191
|
-
const emitResult = program.emitToString();
|
|
191
|
+
const emitResult = await program.emitToString();
|
|
192
192
|
const allDiagnostics = [
|
|
193
|
-
...
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
...(await Promise.all([
|
|
194
|
+
program.getGlobalDiagnostics(),
|
|
195
|
+
program.getProgramDiagnostics(),
|
|
196
|
+
program.getSyntacticDiagnostics(),
|
|
197
|
+
program.getSemanticDiagnostics(),
|
|
198
|
+
program.getDeclarationDiagnostics()
|
|
199
|
+
])).flat(),
|
|
198
200
|
...emitResult.diagnostics
|
|
199
201
|
];
|
|
200
202
|
for (const diagnostic of allDiagnostics) {
|
|
@@ -220,7 +222,7 @@ async function compile_default({
|
|
|
220
222
|
}))
|
|
221
223
|
};
|
|
222
224
|
}
|
|
223
|
-
|
|
225
|
+
return await build({
|
|
224
226
|
entryPoints: productionSourceFiles,
|
|
225
227
|
bundle: true,
|
|
226
228
|
minify: minify2,
|
|
@@ -262,13 +264,6 @@ async function compile_default({
|
|
|
262
264
|
]
|
|
263
265
|
}
|
|
264
266
|
});
|
|
265
|
-
messages.push(
|
|
266
|
-
...buildResult.errors.map((error) => `esbuild error: ${error.text}`)
|
|
267
|
-
);
|
|
268
|
-
if (messages.length > 0) {
|
|
269
|
-
throw new Error(`esbuild failed ${JSON.stringify(messages)}`);
|
|
270
|
-
}
|
|
271
|
-
return buildResult;
|
|
272
267
|
}
|
|
273
268
|
|
|
274
269
|
// src/builder.ts
|
package/dist-mjs/compile.mjs
CHANGED
|
@@ -3,15 +3,13 @@ import { strict as assert } from "node:assert";
|
|
|
3
3
|
import { promises as fs } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { API } from "@typescript/native/
|
|
6
|
+
import { API } from "@typescript/native/async";
|
|
7
7
|
import { build } from "esbuild";
|
|
8
8
|
import tsConfigJson from "../tsconfig.json" with { type: "json" };
|
|
9
9
|
var commonJsCompatabilityBanner = `import { createRequire as __createRequire } from "node:module";
|
|
10
|
-
|
|
11
|
-
const __filename = __fileURLToPath(import.meta.url);
|
|
10
|
+
const __filename = import.meta.filename;
|
|
12
11
|
const require = __createRequire(import.meta.url);`;
|
|
13
|
-
var dirNameJsCompatibilityInjection = `
|
|
14
|
-
export const __dirname = path.dirname(__filename);`;
|
|
12
|
+
var dirNameJsCompatibilityInjection = `export const __dirname = import.meta.dirname;`;
|
|
15
13
|
var dirNameJsCompatibilityInjectionURL = `data:text/javascript,${encodeURIComponent(dirNameJsCompatibilityInjection)}`;
|
|
16
14
|
async function getFiles(directory) {
|
|
17
15
|
const entries = await fs.readdir(directory, { withFileTypes: true });
|
|
@@ -89,25 +87,29 @@ async function compile_default({
|
|
|
89
87
|
);
|
|
90
88
|
const allSourceFiles = await getFiles(inDir);
|
|
91
89
|
const productionSourceFiles = entryPoint === void 0 ? allSourceFiles.filter((file) => file.endsWith(".ts")) : [path.join(inDir, entryPoint)];
|
|
92
|
-
using api = new API();
|
|
93
|
-
const compilerOptions = api.parseJsonConfigFileContent(tsConfigJson, {
|
|
90
|
+
await using api = new API();
|
|
91
|
+
const compilerOptions = (await api.parseJsonConfigFileContent(tsConfigJson, {
|
|
94
92
|
// @checkdigit/typescript-config package root:
|
|
95
|
-
configDirectory: path.dirname(
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
configDirectory: path.dirname(
|
|
94
|
+
path.dirname(fileURLToPath(import.meta.url))
|
|
95
|
+
)
|
|
96
|
+
})).options;
|
|
97
|
+
await using program = await api.createProgram(productionSourceFiles, {
|
|
98
98
|
...compilerOptions,
|
|
99
99
|
noEmit: type !== "types",
|
|
100
100
|
emitDeclarationOnly: type === "types",
|
|
101
101
|
rootDir: inDir,
|
|
102
102
|
outDir
|
|
103
103
|
});
|
|
104
|
-
const emitResult = program.emitToString();
|
|
104
|
+
const emitResult = await program.emitToString();
|
|
105
105
|
const allDiagnostics = [
|
|
106
|
-
...
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
...(await Promise.all([
|
|
107
|
+
program.getGlobalDiagnostics(),
|
|
108
|
+
program.getProgramDiagnostics(),
|
|
109
|
+
program.getSyntacticDiagnostics(),
|
|
110
|
+
program.getSemanticDiagnostics(),
|
|
111
|
+
program.getDeclarationDiagnostics()
|
|
112
|
+
])).flat(),
|
|
111
113
|
...emitResult.diagnostics
|
|
112
114
|
];
|
|
113
115
|
for (const diagnostic of allDiagnostics) {
|
|
@@ -133,7 +135,7 @@ async function compile_default({
|
|
|
133
135
|
}))
|
|
134
136
|
};
|
|
135
137
|
}
|
|
136
|
-
|
|
138
|
+
return await build({
|
|
137
139
|
entryPoints: productionSourceFiles,
|
|
138
140
|
bundle: true,
|
|
139
141
|
minify,
|
|
@@ -175,15 +177,8 @@ async function compile_default({
|
|
|
175
177
|
]
|
|
176
178
|
}
|
|
177
179
|
});
|
|
178
|
-
messages.push(
|
|
179
|
-
...buildResult.errors.map((error) => `esbuild error: ${error.text}`)
|
|
180
|
-
);
|
|
181
|
-
if (messages.length > 0) {
|
|
182
|
-
throw new Error(`esbuild failed ${JSON.stringify(messages)}`);
|
|
183
|
-
}
|
|
184
|
-
return buildResult;
|
|
185
180
|
}
|
|
186
181
|
export {
|
|
187
182
|
compile_default as default
|
|
188
183
|
};
|
|
189
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
184
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2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6QztBQUFBLE1BQ0Y7QUFBQSxJQUNGO0FBQUEsRUFDTixDQUFDO0FBQ0g7IiwKICAibmFtZXMiOiBbXQp9Cg==
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@checkdigit/typescript-config","version":"11.0.0-PR.82-
|
|
1
|
+
{"name":"@checkdigit/typescript-config","version":"11.0.0-PR.82-fd65","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/native --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":"node -e \"require('node:fs').rmSync('dist-mjs', { recursive: true, force: true })\" && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","build:dist-types":"node -e \"require('node:fs').rmSync('dist-types', { recursive: true, force: true })\" && npx builder --type=types --outDir=dist-types","build:mjs":"node -e \"require('node:fs').rmSync('build-mjs', { recursive: true, force: true })\" && bin/builder.mjs --type=module --outDir=build-mjs","build:mjs-bundle":"node -e \"require('node:fs').rmSync('build-mjs-bundle', { recursive: true, force: true })\" && bin/builder.mjs --type=module --outDir=build-mjs-bundle --entryPoint=index.test.ts --outFile=index.test.mjs","build:mjs-bundle-minify":"node -e \"require('node:fs').rmSync('build-mjs-bundle-minify', { recursive: true, force: true })\" && bin/builder.mjs --type=module --minify --outDir=build-mjs-bundle-minify --entryPoint=index.test.ts --outFile=index.test.mjs","build:mjs-bundle-no-external":"node -e \"require('node:fs').rmSync('build-mjs-bundle-no-external', { recursive: true, force: true })\" && 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":"node -e \"require('node:fs').rmSync('build-types', { recursive: true, force: true })\" && bin/builder.mjs --type=types --outDir=build-types","ci:compile":"tsc","ci:coverage":"node -e \"process.argv.slice(1).forEach((path) => require('node:fs').rmSync(path, { recursive: true, force: true }))\" -- coverage && mkdir coverage && node --test-timeout 600000 --experimental-test-coverage --test-coverage-include-all --test-coverage-include=\"src/**/*.ts\" --test-coverage-exclude=\"src/test/**\" --test-coverage-exclude=\"src/**/*.test.ts\" --test-coverage-exclude=\"src/**/*.spec.ts\" --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test \"src/**/*.spec.ts\"","ci:lint":"npm run lint","ci:style":"npm run prettier","ci:test":"npm run build && npm run test:node && npm run test:mjs && npm run test:mjs-bundle && npm run test:mjs-bundle-no-external","coverage":"node --test-timeout 600000 --experimental-test-coverage --test-coverage-include-all --test-coverage-include=\"src/**/*.ts\" --test-coverage-exclude=\"src/test/**\" --test-coverage-exclude=\"src/**/*.test.ts\" --test-coverage-exclude=\"src/**/*.spec.ts\" --test \"src/**/*.spec.ts\"","lint":"eslint . --max-warnings=0 --concurrency=auto --flag unstable_native_nodejs_ts_config","lint:fix":"eslint . --fix --concurrency=auto --flag unstable_native_nodejs_ts_config","prepublishOnly":"npm run build:builder && npm run build:dist-types && npm run build:dist-mjs","prettier":"prettier . --check","prettier:fix":"prettier . --write","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style","test:mjs":"node --throw-deprecation --pending-deprecation --test build-mjs/test/index.mjs","test:mjs-bundle":"node --throw-deprecation --pending-deprecation --test build-mjs-bundle/index.test.mjs","test:mjs-bundle-minify":"node --throw-deprecation --pending-deprecation --test build-mjs-bundle-minify/index.test.mjs","test:mjs-bundle-no-external":"node --throw-deprecation --pending-deprecation --test build-mjs-bundle-no-external/index.test.mjs","test:node":"node --throw-deprecation --pending-deprecation --test-timeout 600000 --test \"src/**/*.spec.ts\""},"prettier":"@checkdigit/prettier-config","devDependencies":{"@checkdigit/prettier-config":"^8.3.0","@eslint/js":"^10.0.1","@eslint/json":"^2.1.1","@eslint/markdown":"^8.0.3","eslint":"^10.14.0","eslint-config-prettier":"^10.1.8","eslint-plugin-yml":"^3.10.0","typescript":"npm:@typescript/typescript6@^6.0.2","typescript-eslint":"^8.72.2"},"peerDependencies":{"@types/node":">=26","@typescript/native":"npm:typescript@7.1.0-beta","esbuild":"0.28.2"},"engines":{"node":">=26.13"}}
|
package/src/compile.ts
CHANGED
|
@@ -5,18 +5,16 @@ import { promises as fs } from 'node:fs';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
|
-
import { API, type Diagnostic } from '@typescript/native/
|
|
8
|
+
import { API, type Diagnostic } from '@typescript/native/async';
|
|
9
9
|
import { build, type PluginBuild } from 'esbuild';
|
|
10
10
|
|
|
11
11
|
import tsConfigJson from '../tsconfig.json' with { type: 'json' };
|
|
12
12
|
|
|
13
13
|
const commonJsCompatabilityBanner = `import { createRequire as __createRequire } from "node:module";
|
|
14
|
-
|
|
15
|
-
const __filename = __fileURLToPath(import.meta.url);
|
|
14
|
+
const __filename = import.meta.filename;
|
|
16
15
|
const require = __createRequire(import.meta.url);`;
|
|
17
16
|
|
|
18
|
-
const dirNameJsCompatibilityInjection = `
|
|
19
|
-
export const __dirname = path.dirname(__filename);`; // relies on __filename from commonJsCompatabilityBanner
|
|
17
|
+
const dirNameJsCompatibilityInjection = `export const __dirname = import.meta.dirname;`;
|
|
20
18
|
const dirNameJsCompatibilityInjectionURL = `data:text/javascript,${encodeURIComponent(dirNameJsCompatibilityInjection)}`;
|
|
21
19
|
|
|
22
20
|
export type ImportKind =
|
|
@@ -125,8 +123,6 @@ export interface CompileOptions {
|
|
|
125
123
|
|
|
126
124
|
/**
|
|
127
125
|
* Recursively obtains all files in a directory
|
|
128
|
-
* @param {string} directory
|
|
129
|
-
* @returns {Promise<string[]>}
|
|
130
126
|
*/
|
|
131
127
|
async function getFiles(directory: string): Promise<string[]> {
|
|
132
128
|
const entries = await fs.readdir(directory, { withFileTypes: true });
|
|
@@ -150,7 +146,7 @@ function flattenDiagnosticMessage(diagnostic: Diagnostic, indent = 0): string {
|
|
|
150
146
|
|
|
151
147
|
function excludeSourceMaps(filter: RegExp) {
|
|
152
148
|
return (pluginBuild: PluginBuild) => {
|
|
153
|
-
// ignore source maps for any
|
|
149
|
+
// ignore source maps for any JavaScript file that matches filter
|
|
154
150
|
pluginBuild.onLoad({ filter }, async (args) => {
|
|
155
151
|
if (args.path.endsWith('.js') || args.path.endsWith('.mjs')) {
|
|
156
152
|
return {
|
|
@@ -229,25 +225,33 @@ export default async function ({
|
|
|
229
225
|
/**
|
|
230
226
|
* Emit declarations using TypeScript compiler if the type is 'types'. Otherwise, compile to ensure the build is good.
|
|
231
227
|
*/
|
|
232
|
-
using api = new API();
|
|
233
|
-
const compilerOptions =
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
228
|
+
await using api = new API();
|
|
229
|
+
const compilerOptions = (
|
|
230
|
+
await api.parseJsonConfigFileContent(tsConfigJson, {
|
|
231
|
+
// @checkdigit/typescript-config package root:
|
|
232
|
+
configDirectory: path.dirname(
|
|
233
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
234
|
+
),
|
|
235
|
+
})
|
|
236
|
+
).options;
|
|
237
|
+
await using program = await api.createProgram(productionSourceFiles, {
|
|
238
238
|
...compilerOptions,
|
|
239
239
|
noEmit: type !== 'types',
|
|
240
240
|
emitDeclarationOnly: type === 'types',
|
|
241
241
|
rootDir: inDir,
|
|
242
242
|
outDir,
|
|
243
243
|
});
|
|
244
|
-
const emitResult = program.emitToString();
|
|
244
|
+
const emitResult = await program.emitToString();
|
|
245
245
|
const allDiagnostics = [
|
|
246
|
-
...
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
246
|
+
...(
|
|
247
|
+
await Promise.all([
|
|
248
|
+
program.getGlobalDiagnostics(),
|
|
249
|
+
program.getProgramDiagnostics(),
|
|
250
|
+
program.getSyntacticDiagnostics(),
|
|
251
|
+
program.getSemanticDiagnostics(),
|
|
252
|
+
program.getDeclarationDiagnostics(),
|
|
253
|
+
])
|
|
254
|
+
).flat(),
|
|
251
255
|
...emitResult.diagnostics,
|
|
252
256
|
];
|
|
253
257
|
for (const diagnostic of allDiagnostics) {
|
|
@@ -276,10 +280,7 @@ export default async function ({
|
|
|
276
280
|
};
|
|
277
281
|
}
|
|
278
282
|
|
|
279
|
-
|
|
280
|
-
* Emit ESM javascript using esbuild
|
|
281
|
-
*/
|
|
282
|
-
const buildResult = await build({
|
|
283
|
+
return await build({
|
|
283
284
|
entryPoints: productionSourceFiles,
|
|
284
285
|
bundle: true,
|
|
285
286
|
minify,
|
|
@@ -326,13 +327,4 @@ export default async function ({
|
|
|
326
327
|
],
|
|
327
328
|
}),
|
|
328
329
|
});
|
|
329
|
-
|
|
330
|
-
messages.push(
|
|
331
|
-
...buildResult.errors.map((error) => `esbuild error: ${error.text}`),
|
|
332
|
-
);
|
|
333
|
-
if (messages.length > 0) {
|
|
334
|
-
throw new Error(`esbuild failed ${JSON.stringify(messages)}`);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return buildResult;
|
|
338
330
|
}
|