@checkdigit/typescript-config 3.3.0-PR.30-9280 → 3.3.0-PR.30-cbc4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -0
- package/bin/builder.mjs +23 -12
- package/package.json +1 -1
- package/src/builder/builder.mts +23 -9
- package/src/builder/index.mts +3 -1
package/README.md
CHANGED
@@ -34,6 +34,7 @@ types, and `esbuild` for generating code.
|
|
34
34
|
- `--external` external modules to exclude from the bundle. Built-in `node` modules are automatically excluded.
|
35
35
|
A wildcard `*` can be used to exclude multiple external modules.
|
36
36
|
- `--minify` whether to minify the output.
|
37
|
+
- `--sourceMap` whether to include inline sourcemap.
|
37
38
|
|
38
39
|
#### Examples
|
39
40
|
|
package/bin/builder.mjs
CHANGED
@@ -22,14 +22,19 @@ async function getFiles(directory) {
|
|
22
22
|
}
|
23
23
|
function excludeSourceMaps(filter) {
|
24
24
|
return (pluginBuild) => {
|
25
|
-
pluginBuild.onLoad({ filter }, async (args) =>
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
pluginBuild.onLoad({ filter }, async (args) => {
|
26
|
+
if (args.path.endsWith(".js") || args.path.endsWith(".mjs") || args.path.endsWith(".cjs")) {
|
27
|
+
return {
|
28
|
+
contents: `${await fs.readFile(
|
29
|
+
args.path,
|
30
|
+
"utf8"
|
31
|
+
)}
|
30
32
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,
|
31
|
-
|
32
|
-
|
33
|
+
loader: "default"
|
34
|
+
};
|
35
|
+
}
|
36
|
+
return void 0;
|
37
|
+
});
|
33
38
|
};
|
34
39
|
}
|
35
40
|
function resolveTypescriptPaths(type2) {
|
@@ -58,7 +63,8 @@ async function builder_default({
|
|
58
63
|
outDir: outDir2,
|
59
64
|
outFile: outFile2,
|
60
65
|
external: external2 = [],
|
61
|
-
minify: minify2 = false
|
66
|
+
minify: minify2 = false,
|
67
|
+
sourceMap: sourceMap2
|
62
68
|
}) {
|
63
69
|
const messages2 = [];
|
64
70
|
assert.ok(
|
@@ -123,9 +129,10 @@ async function builder_default({
|
|
123
129
|
minify: minify2,
|
124
130
|
platform: "node",
|
125
131
|
format: type2 === "module" ? "esm" : "cjs",
|
126
|
-
sourcemap: "inline",
|
127
132
|
sourcesContent: false,
|
133
|
+
sourcemap: sourceMap2 ? "inline" : false,
|
128
134
|
...outFile2 === void 0 ? {
|
135
|
+
// individual files
|
129
136
|
outdir: outDir2,
|
130
137
|
outExtension: { ".js": type2 === "module" ? ".mjs" : ".cjs" },
|
131
138
|
plugins: [
|
@@ -135,7 +142,9 @@ async function builder_default({
|
|
135
142
|
}
|
136
143
|
]
|
137
144
|
} : {
|
145
|
+
// bundling
|
138
146
|
outfile: path.join(outDir2, outFile2),
|
147
|
+
legalComments: "none",
|
139
148
|
external: external2,
|
140
149
|
plugins: [
|
141
150
|
{
|
@@ -155,7 +164,7 @@ async function builder_default({
|
|
155
164
|
|
156
165
|
// src/builder/index.mts
|
157
166
|
var {
|
158
|
-
values: { type, inDir, outDir, entryPoint, outFile, external, minify }
|
167
|
+
values: { type, inDir, outDir, entryPoint, outFile, external, minify, sourceMap }
|
159
168
|
} = parseArgs({
|
160
169
|
options: {
|
161
170
|
type: { type: "string", short: "t", default: "module" },
|
@@ -164,7 +173,8 @@ var {
|
|
164
173
|
entryPoint: { type: "string", short: "e", default: void 0 },
|
165
174
|
outFile: { type: "string", short: "f", default: void 0 },
|
166
175
|
external: { type: "string", short: "x", multiple: true, default: [] },
|
167
|
-
minify: { type: "boolean", short: "m", default: false }
|
176
|
+
minify: { type: "boolean", short: "m", default: false },
|
177
|
+
sourceMap: { type: "boolean", short: "s", default: false }
|
168
178
|
}
|
169
179
|
});
|
170
180
|
assert2.ok(type === "module" || type === "commonjs", "type must be module or commonjs");
|
@@ -177,7 +187,8 @@ var messages = await builder_default({
|
|
177
187
|
entryPoint,
|
178
188
|
outFile,
|
179
189
|
external,
|
180
|
-
minify
|
190
|
+
minify,
|
191
|
+
sourceMap
|
181
192
|
});
|
182
193
|
if (messages.length > 0) {
|
183
194
|
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-
|
1
|
+
{"name":"@checkdigit/typescript-config","version":"3.3.0-PR.30-cbc4","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.19","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 --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 --minify --sourceMap","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 --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-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.1","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/"]}
|
package/src/builder/builder.mts
CHANGED
@@ -43,6 +43,11 @@ export interface BuilderOptions {
|
|
43
43
|
* whether to minify output
|
44
44
|
*/
|
45
45
|
minify?: boolean | undefined;
|
46
|
+
|
47
|
+
/**
|
48
|
+
* whether to include sourcemap
|
49
|
+
*/
|
50
|
+
sourceMap?: boolean | undefined;
|
46
51
|
}
|
47
52
|
|
48
53
|
/**
|
@@ -63,14 +68,19 @@ async function getFiles(directory: string): Promise<string[]> {
|
|
63
68
|
|
64
69
|
function excludeSourceMaps(filter: RegExp) {
|
65
70
|
return (pluginBuild: PluginBuild) => {
|
66
|
-
// ignore source maps for
|
67
|
-
pluginBuild.onLoad({ filter }, async (args) =>
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
// ignore source maps for any Javascript file that matches filter
|
72
|
+
pluginBuild.onLoad({ filter }, async (args) => {
|
73
|
+
if (args.path.endsWith('.js') || args.path.endsWith('.mjs') || args.path.endsWith('.cjs')) {
|
74
|
+
return {
|
75
|
+
contents: `${await fs.readFile(
|
76
|
+
args.path,
|
77
|
+
'utf8'
|
78
|
+
)}\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,
|
79
|
+
loader: 'default',
|
80
|
+
};
|
81
|
+
}
|
82
|
+
return undefined;
|
83
|
+
});
|
74
84
|
};
|
75
85
|
}
|
76
86
|
|
@@ -105,6 +115,7 @@ export default async function ({
|
|
105
115
|
outFile,
|
106
116
|
external = [],
|
107
117
|
minify = false,
|
118
|
+
sourceMap,
|
108
119
|
}: BuilderOptions): Promise<string[]> {
|
109
120
|
const messages: string[] = [];
|
110
121
|
|
@@ -181,10 +192,11 @@ export default async function ({
|
|
181
192
|
minify,
|
182
193
|
platform: 'node',
|
183
194
|
format: type === 'module' ? 'esm' : 'cjs',
|
184
|
-
sourcemap: 'inline',
|
185
195
|
sourcesContent: false,
|
196
|
+
sourcemap: sourceMap ? 'inline' : false,
|
186
197
|
...(outFile === undefined
|
187
198
|
? {
|
199
|
+
// individual files
|
188
200
|
outdir: outDir,
|
189
201
|
outExtension: { '.js': type === 'module' ? '.mjs' : '.cjs' },
|
190
202
|
plugins: [
|
@@ -195,7 +207,9 @@ export default async function ({
|
|
195
207
|
],
|
196
208
|
}
|
197
209
|
: {
|
210
|
+
// bundling
|
198
211
|
outfile: path.join(outDir, outFile),
|
212
|
+
legalComments: 'none',
|
199
213
|
external,
|
200
214
|
plugins: [
|
201
215
|
{
|
package/src/builder/index.mts
CHANGED
@@ -9,7 +9,7 @@ import { parseArgs } from 'node:util';
|
|
9
9
|
import builder from './builder.mts';
|
10
10
|
|
11
11
|
const {
|
12
|
-
values: { type, inDir, outDir, entryPoint, outFile, external, minify },
|
12
|
+
values: { type, inDir, outDir, entryPoint, outFile, external, minify, sourceMap },
|
13
13
|
} = parseArgs({
|
14
14
|
options: {
|
15
15
|
type: { type: 'string', short: 't', default: 'module' },
|
@@ -19,6 +19,7 @@ const {
|
|
19
19
|
outFile: { type: 'string', short: 'f', default: undefined },
|
20
20
|
external: { type: 'string', short: 'x', multiple: true, default: [] },
|
21
21
|
minify: { type: 'boolean', short: 'm', default: false },
|
22
|
+
sourceMap: { type: 'boolean', short: 's', default: false },
|
22
23
|
},
|
23
24
|
});
|
24
25
|
|
@@ -34,6 +35,7 @@ const messages = await builder({
|
|
34
35
|
outFile,
|
35
36
|
external,
|
36
37
|
minify,
|
38
|
+
sourceMap,
|
37
39
|
});
|
38
40
|
if (messages.length > 0) {
|
39
41
|
// eslint-disable-next-line no-console
|