@checkdigit/typescript-config 3.3.0-PR.30-f38e → 3.3.0-PR.30-c398

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 CHANGED
@@ -39,14 +39,21 @@ function setup(type2) {
39
39
  });
40
40
  };
41
41
  }
42
- async function builder_default({ type: type2, entryPoint, inDir: inDir2, outDir: outDir2, outFile }) {
42
+ async function builder_default({
43
+ type: type2,
44
+ entryPoint: entryPoint2,
45
+ inDir: inDir2,
46
+ outDir: outDir2,
47
+ outFile: outFile2,
48
+ external: external2 = []
49
+ }) {
43
50
  const messages2 = [];
44
51
  assert.ok(
45
- entryPoint === void 0 && outFile === void 0 || entryPoint !== void 0 && outFile !== void 0,
52
+ entryPoint2 === void 0 && outFile2 === void 0 || entryPoint2 !== void 0 && outFile2 !== void 0,
46
53
  "entryPoint and outFile must both be provided"
47
54
  );
48
55
  const allSourceFiles = await getFiles(inDir2);
49
- const productionSourceFiles = entryPoint === void 0 ? allSourceFiles.filter((file) => file.endsWith(".ts")) : [path.join(inDir2, entryPoint)];
56
+ const productionSourceFiles = entryPoint2 === void 0 ? allSourceFiles.filter((file) => file.endsWith(".ts")) : [path.join(inDir2, entryPoint2)];
50
57
  const program = typescript.createProgram(productionSourceFiles, {
51
58
  module: typescript.ModuleKind.ESNext,
52
59
  moduleResolution: typescript.ModuleResolutionKind.Bundler,
@@ -104,7 +111,7 @@ async function builder_default({ type: type2, entryPoint, inDir: inDir2, outDir:
104
111
  format: type2 === "module" ? "esm" : "cjs",
105
112
  sourcemap: "inline",
106
113
  sourcesContent: false,
107
- ...outFile === void 0 ? {
114
+ ...outFile2 === void 0 ? {
108
115
  outdir: outDir2,
109
116
  outExtension: { ".js": type2 === "module" ? ".mjs" : ".cjs" },
110
117
  plugins: [
@@ -113,7 +120,7 @@ async function builder_default({ type: type2, entryPoint, inDir: inDir2, outDir:
113
120
  setup: setup(type2)
114
121
  }
115
122
  ]
116
- } : { outfile: path.join(outDir2, outFile) }
123
+ } : { outfile: path.join(outDir2, outFile2), external: external2 }
117
124
  });
118
125
  messages2.push(...buildResult.errors.map((error) => `esbuild error: ${error.text}`));
119
126
  messages2.push(...buildResult.warnings.map((warning) => `esbuild warning: ${warning.text}`));
@@ -125,12 +132,15 @@ async function builder_default({ type: type2, entryPoint, inDir: inDir2, outDir:
125
132
 
126
133
  // src/builder/index.mts
127
134
  var {
128
- values: { type, inDir, outDir }
135
+ values: { type, inDir, outDir, entryPoint, outFile, external }
129
136
  } = parseArgs({
130
137
  options: {
131
138
  type: { type: "string", short: "t", default: "module" },
132
139
  inDir: { type: "string", short: "i", default: "src" },
133
- outDir: { type: "string", short: "o", default: "build" }
140
+ outDir: { type: "string", short: "o", default: "build" },
141
+ entryPoint: { type: "string", short: "e", default: void 0 },
142
+ outFile: { type: "string", short: "f", default: void 0 },
143
+ external: { type: "string", short: "x", multiple: true, default: [] }
134
144
  }
135
145
  });
136
146
  assert2.ok(type === "module" || type === "commonjs", "type must be module or commonjs");
@@ -139,7 +149,10 @@ assert2.ok(outDir !== void 0, "outDir is required");
139
149
  var messages = await builder_default({
140
150
  type,
141
151
  inDir: path2.join(process.cwd(), inDir),
142
- outDir: path2.join(process.cwd(), outDir)
152
+ outDir: path2.join(process.cwd(), outDir),
153
+ entryPoint,
154
+ outFile,
155
+ external
143
156
  });
144
157
  if (messages.length > 0) {
145
158
  console.warn(JSON.stringify(messages, void 0, 2));
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@checkdigit/typescript-config","version":"3.3.0-PR.30-f38e","description":"Check Digit standard Typescript configuration","prettier":"@checkdigit/prettier-config","engines":{"node":">=16"},"bin":{"builder":"./bin/builder.mjs"},"peerDependencies":{"@types/node":">=16","esbuild":"0.17.18","typescript":">=5.0.4 <5.1"},"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":{"preversion":"npm test","postversion":"git push && git push --tags","prepare":"npm run build-builder","lint:fix":"eslint -f unix --ext .ts,.mts src --fix","lint":"eslint -f unix --ext .ts,.mts src","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-tsc-cjs":"rimraf build-tsc-cjs && tsc --outDir build-tsc-cjs","build-esbuild-cjs":"rimraf build-esbuild-cjs && esbuild ./src/*.ts ./src/*/*.ts --platform=node --bundle --format=cjs --sourcemap=inline --sources-content=false --outdir=build-esbuild-cjs","build-esbuild-cjs-bundle":"rimraf build-esbuild-cjs-bundle && esbuild src/test/index.test.ts --bundle --platform=node --format=cjs --sourcemap=inline --sources-content=false --outfile=build-esbuild-cjs-bundle/test/index.test.cjs","build-esbuild-esm":"rimraf build-esbuild-esm && node bin/builder.mjs --outDir=build-esbuild-esm","build-esbuild-esm-bundle":"rimraf build-esbuild-esm-bundle && esbuild src/test/index.test.ts --bundle --platform=node --format=esm --sourcemap=inline --sources-content=false --outfile=build-esbuild-esm-bundle/test/index.test.mjs","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-tsc-cjs":"node --test build-tsc-cjs/test/index.test.js","test-esbuild-cjs":"node --test build-esbuild-cjs/test/index.test.js","test-esbuild-cjs-bundle":"node --test build-esbuild-cjs-bundle/test/index.test.cjs","test-esbuild-esm":"node --test build-esbuild-esm/test/index.test.mjs","test-esbuild-esm-bundle":"echo 'node -test build-esbuild-esm-bundle/test/index.test.mjs'","ci:test":"npm run test-jest-cjs && npm run test-jest-esm &&npm run test-tsc-cjs && npm run test-esbuild-cjs && npm run test-esbuild-cjs-bundle && npm run test-esbuild-esm && npm run test-esbuild-esm-bundle","ci:compile":"npm run build-builder && npm run build-tsc-cjs && npm run build-esbuild-cjs && npm run build-esbuild-cjs-bundle && npm run build-esbuild-esm && npm run build-esbuild-esm-bundle","ci:lint":"npm run lint","ci:style":"npm run prettier"},"devDependencies":{"@checkdigit/prettier-config":"^3.4.0","@types/debug":"^4.1.7","@types/jest":"^29.5.1","@types/uuid":"^9.0.1","@typescript-eslint/eslint-plugin":"^5.59.6","@typescript-eslint/parser":"^5.59.6","debug":"^4.3.4","eslint":"^8.40.0","eslint-config-prettier":"^8.8.0","get-port":"^6.1.2","got":"^11.8.6","jest":"^29.5.0","rimraf":"^5.0.0","ts-jest":"^29.1.0","uuid":"^9.0.0"},"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","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-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/**","!<rootDir>/src/**/*.spec.mts","!<rootDir>/src/**/*.test.mts","!<rootDir>/src/**/*.spec.ts","!<rootDir>/src/**/*.test.ts"],"testMatch":["<rootDir>/src/**/*.spec.ts","<rootDir>/src/**/*.spec.mts"]},"files":["tsconfig.json","SECURITY.md","/src/"]}
1
+ {"name":"@checkdigit/typescript-config","version":"3.3.0-PR.30-c398","description":"Check Digit standard Typescript configuration","prettier":"@checkdigit/prettier-config","engines":{"node":">=16"},"bin":{"builder":"./bin/builder.mjs"},"peerDependencies":{"@types/node":">=16","esbuild":"0.17.18","typescript":">=5.0.4 <5.1"},"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":{"preversion":"npm test","postversion":"git push && git push --tags","prepare":"npm run build-builder","lint:fix":"eslint -f unix --ext .ts,.mts src --fix","lint":"eslint -f unix --ext .ts,.mts src","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-cjs":"rimraf build-cjs && npx builder --outDir=build-cjs --type=commonjs --outDir=build-cjs","build-cjs-bundle":"rimraf build-cjs-bundle && npx builder --type=commonjs --entryPoint=test/index.test.ts --outDir=build-cjs-bundle --outFile=test/index.test.cjs","build-cjs-bundle-no-external":"rimraf build-cjs-bundle-no-external && npx builder --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 && npx builder --type=module --outDir=build-esm","build-esm-bundle":"rimraf build-esm-bundle && npx builder --type=module --outDir=build-esm-bundle --entryPoint=test/index.test.ts --outFile=test/index.test.mjs","build-esm-bundle-no-external":"rimraf build-esm-bundle-no-external && npx builder --type=module --external=./node_modules/* --outDir=build-esm-bundle-no-external --entryPoint=test/index.test.ts --outFile=test/index.test.mjs","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-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":"echo \"node --test build-esm-bundle/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":"npm run build-builder && npm run build-cjs && npm run build-cjs-bundle && npm run build-cjs-bundle-no-external && npm run build-esm && npm run build-esm-bundle && npm run build-esm-bundle-no-external","ci:lint":"npm run lint","ci:style":"npm run prettier"},"devDependencies":{"@checkdigit/prettier-config":"^3.4.0","@types/debug":"^4.1.7","@types/jest":"^29.5.1","@types/uuid":"^9.0.1","@typescript-eslint/eslint-plugin":"^5.59.6","@typescript-eslint/parser":"^5.59.6","debug":"^4.3.4","eslint":"^8.40.0","eslint-config-prettier":"^8.8.0","get-port":"^6.1.2","got":"^11.8.6","jest":"^29.5.0","rimraf":"^5.0.0","ts-jest":"^29.1.0","uuid":"^9.0.0"},"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","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-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/**","!<rootDir>/src/**/*.spec.mts","!<rootDir>/src/**/*.test.mts","!<rootDir>/src/**/*.spec.ts","!<rootDir>/src/**/*.test.ts"],"testMatch":["<rootDir>/src/**/*.spec.ts","<rootDir>/src/**/*.spec.mts"]},"files":["tsconfig.json","SECURITY.md","/src/"]}
@@ -17,7 +17,7 @@ export interface BuilderOptions {
17
17
  * the entry point for the bundle, relative to the inDir. if not provided, the files in the inDir will be processed
18
18
  * as individual unbundled files
19
19
  */
20
- entryPoint?: string;
20
+ entryPoint?: string | undefined;
21
21
 
22
22
  /**
23
23
  * source code
@@ -32,7 +32,12 @@ export interface BuilderOptions {
32
32
  /**
33
33
  * build file, relative to the outDir
34
34
  */
35
- outFile?: string;
35
+ outFile?: string | undefined;
36
+
37
+ /**
38
+ * external modules to exclude from the bundle
39
+ */
40
+ external?: string[] | undefined;
36
41
  }
37
42
 
38
43
  /**
@@ -73,7 +78,14 @@ function setup(type: 'module' | 'commonjs') {
73
78
  }
74
79
 
75
80
  // eslint-disable-next-line func-names,max-lines-per-function,max-statements
76
- export default async function ({ type, entryPoint, inDir, outDir, outFile }: BuilderOptions): Promise<string[]> {
81
+ export default async function ({
82
+ type,
83
+ entryPoint,
84
+ inDir,
85
+ outDir,
86
+ outFile,
87
+ external = [],
88
+ }: BuilderOptions): Promise<string[]> {
77
89
  const messages: string[] = [];
78
90
 
79
91
  assert.ok(
@@ -161,7 +173,7 @@ export default async function ({ type, entryPoint, inDir, outDir, outFile }: Bui
161
173
  },
162
174
  ],
163
175
  }
164
- : { outfile: path.join(outDir, outFile) }),
176
+ : { outfile: path.join(outDir, outFile), external }),
165
177
  });
166
178
 
167
179
  messages.push(...buildResult.errors.map((error) => `esbuild error: ${error.text}`));
@@ -410,4 +410,59 @@ describe('test builder', () => {
410
410
  test: 'world',
411
411
  });
412
412
  });
413
+
414
+ it('should bundle an ESM module that imports external modules, but excludes them', async () => {
415
+ const id = uuid();
416
+ const moduleDir = path.join(os.tmpdir(), `in-dir-${id}`);
417
+ const inDir = path.join(moduleDir, 'src');
418
+ const outDir = path.join(os.tmpdir(), `out-dir-${id}`, 'build');
419
+ await write(inDir, importExternalModule);
420
+ await writeNodeModules(moduleDir, testNodeModules);
421
+ assert.deepEqual(
422
+ await builder({
423
+ type: 'module',
424
+ entryPoint: 'index.ts',
425
+ outFile: 'index.mjs',
426
+ inDir,
427
+ outDir,
428
+ external: ['*'],
429
+ }),
430
+ []
431
+ );
432
+ assert.deepEqual(await read(outDir), {
433
+ 'index.d.ts': 'export declare const hello: {\n test: string;\n message: string;\n};\n',
434
+ 'index.mjs':
435
+ 'import { hello as test } from "test-esm-module";\n' +
436
+ 'import util from "node:util";\n' +
437
+ 'var hello = { test, message: util.format("hello %s", "world") };\n' +
438
+ 'export {\n' +
439
+ ' hello\n' +
440
+ '};\n',
441
+ });
442
+ });
443
+
444
+ it('should bundle a commonjs module that imports external ESM modules', async () => {
445
+ const id = uuid();
446
+ const moduleDir = path.join(os.tmpdir(), `in-dir-${id}`);
447
+ const inDir = path.join(moduleDir, 'src');
448
+ const outDir = path.join(os.tmpdir(), `out-dir-${id}`, 'build');
449
+ await write(inDir, importExternalModule);
450
+ await writeNodeModules(moduleDir, testNodeModules);
451
+ assert.deepEqual(
452
+ await builder({
453
+ type: 'commonjs',
454
+ entryPoint: 'index.ts',
455
+ outFile: 'index.cjs',
456
+ inDir,
457
+ outDir,
458
+ }),
459
+ []
460
+ );
461
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
462
+ const output = require(path.join(outDir, 'index.cjs'));
463
+ assert.deepEqual(output.hello, {
464
+ message: 'hello world',
465
+ test: 'world',
466
+ });
467
+ });
413
468
  });
@@ -9,12 +9,15 @@ import { parseArgs } from 'node:util';
9
9
  import builder from './builder.mts';
10
10
 
11
11
  const {
12
- values: { type, inDir, outDir },
12
+ values: { type, inDir, outDir, entryPoint, outFile, external },
13
13
  } = parseArgs({
14
14
  options: {
15
15
  type: { type: 'string', short: 't', default: 'module' },
16
16
  inDir: { type: 'string', short: 'i', default: 'src' },
17
17
  outDir: { type: 'string', short: 'o', default: 'build' },
18
+ entryPoint: { type: 'string', short: 'e', default: undefined },
19
+ outFile: { type: 'string', short: 'f', default: undefined },
20
+ external: { type: 'string', short: 'x', multiple: true, default: [] },
18
21
  },
19
22
  });
20
23
 
@@ -26,6 +29,9 @@ const messages = await builder({
26
29
  type,
27
30
  inDir: path.join(process.cwd(), inDir),
28
31
  outDir: path.join(process.cwd(), outDir),
32
+ entryPoint,
33
+ outFile,
34
+ external,
29
35
  });
30
36
  if (messages.length > 0) {
31
37
  // eslint-disable-next-line no-console