@checkdigit/typescript-config 5.1.0 → 5.1.1-PR.49-88af

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/bin/builder.mjs +33 -16
  2. package/package.json +1 -202
package/bin/builder.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // src/builder/index.mts
3
3
  import { strict as assert2 } 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
 
@@ -72,7 +73,7 @@ async function builder_default({
72
73
  minify: minify2 = false,
73
74
  sourceMap: sourceMap2
74
75
  }) {
75
- const messages2 = [];
76
+ const messages = [];
76
77
  assert.ok(
77
78
  entryPoint2 === void 0 && outFile2 === void 0 || entryPoint2 !== void 0 && outFile2 !== void 0,
78
79
  "entryPoint and outFile must both be provided"
@@ -122,23 +123,28 @@ async function builder_default({
122
123
  assert.ok(diagnostic.start !== void 0);
123
124
  const { line, character } = typescript.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
124
125
  const message = typescript.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
125
- messages2.push(`tsc: ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
126
+ messages.push(`tsc: ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
126
127
  } else {
127
- messages2.push(`tsc: ${typescript.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
128
+ messages.push(`tsc: ${typescript.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`);
128
129
  }
129
130
  }
130
- if (messages2.length > 0) {
131
- throw new Error(`tsc failed ${JSON.stringify(messages2)}`);
131
+ if (messages.length > 0) {
132
+ throw new Error(`tsc failed ${JSON.stringify(messages)}`);
132
133
  }
133
134
  if (type2 === "types") {
134
- return [];
135
+ return {
136
+ outputFiles: []
137
+ };
135
138
  }
136
- const buildResult = await build({
139
+ const buildResult2 = await build({
137
140
  entryPoints: productionSourceFiles,
138
141
  bundle: true,
139
142
  minify: minify2,
140
143
  platform: "node",
141
144
  format: type2 === "module" ? "esm" : "cjs",
145
+ treeShaking: type2 === "module",
146
+ write: false,
147
+ metafile: outFile2 !== void 0,
142
148
  sourcesContent: false,
143
149
  banner: type2 === "module" && outFile2 !== void 0 ? {
144
150
  js: commonJsCompatabilityBanner
@@ -167,12 +173,17 @@ async function builder_default({
167
173
  ]
168
174
  }
169
175
  });
170
- messages2.push(...buildResult.errors.map((error) => `esbuild error: ${error.text}`));
171
- messages2.push(...buildResult.warnings.map((warning) => `esbuild warning: ${warning.text}`));
172
- if (messages2.length > 0) {
173
- throw new Error(`esbuild failed ${JSON.stringify(messages2)}`);
176
+ messages.push(...buildResult2.errors.map((error) => `esbuild error: ${error.text}`));
177
+ messages.push(...buildResult2.warnings.map((warning) => `esbuild warning: ${warning.text}`));
178
+ if (messages.length > 0) {
179
+ throw new Error(`esbuild failed ${JSON.stringify(messages)}`);
174
180
  }
175
- return messages2;
181
+ return buildResult2;
182
+ }
183
+
184
+ // src/builder/analyze.mts
185
+ function analyze(metafile) {
186
+ console.log("analyze", Object.keys(metafile));
176
187
  }
177
188
 
178
189
  // src/builder/index.mts
@@ -193,7 +204,7 @@ var {
193
204
  assert2.ok(type === "module" || type === "commonjs" || type === "types", "type must be types, module or commonjs");
194
205
  assert2.ok(inDir !== void 0, "inDir is required");
195
206
  assert2.ok(outDir !== void 0, "outDir is required");
196
- var messages = await builder_default({
207
+ var buildResult = await builder_default({
197
208
  type,
198
209
  inDir: path2.join(process.cwd(), inDir),
199
210
  outDir: path2.join(process.cwd(), outDir),
@@ -203,7 +214,13 @@ var messages = await builder_default({
203
214
  minify,
204
215
  sourceMap
205
216
  });
206
- if (messages.length > 0) {
207
- console.warn(JSON.stringify(messages, void 0, 2));
208
- process.exit(1);
217
+ await Promise.all(
218
+ buildResult.outputFiles.map(async (file) => {
219
+ await fs2.mkdir(path2.join(path2.dirname(file.path)), { recursive: true });
220
+ await fs2.writeFile(file.path, file.text);
221
+ })
222
+ );
223
+ if (buildResult.metafile !== void 0) {
224
+ analyze(buildResult.metafile);
225
+ await fs2.writeFile(path2.join(outDir, "metafile.json"), JSON.stringify(buildResult.metafile, void 0, 2));
209
226
  }
package/package.json CHANGED
@@ -1,202 +1 @@
1
- {
2
- "name": "@checkdigit/typescript-config",
3
- "version": "5.1.0",
4
- "description": "Check Digit standard Typescript configuration",
5
- "prettier": "@checkdigit/prettier-config",
6
- "engines": {
7
- "node": ">=18"
8
- },
9
- "bin": {
10
- "builder": "./bin/builder.mjs"
11
- },
12
- "peerDependencies": {
13
- "@types/node": ">=18",
14
- "esbuild": "0.19.4",
15
- "typescript": ">=5.2.2 <5.3"
16
- },
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/checkdigit/typescript-config.git"
20
- },
21
- "author": "Check Digit, LLC",
22
- "license": "MIT",
23
- "bugs": {
24
- "url": "https://github.com/checkdigit/typescript-config/issues"
25
- },
26
- "homepage": "https://github.com/checkdigit/typescript-config#readme",
27
- "scripts": {
28
- "prepublishOnly": "npm run build-builder",
29
- "lint:fix": "eslint --ignore-path .gitignore . --fix",
30
- "lint": "eslint --max-warnings 0 --ignore-path .gitignore .",
31
- "prettier": "prettier --ignore-path .gitignore --list-different .",
32
- "prettier:fix": "prettier --ignore-path .gitignore --write .",
33
- "test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style",
34
- "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",
35
- "build-types": "rimraf build-types && bin/builder.mjs --type=types --outDir=build-types",
36
- "build-cjs": "rimraf build-cjs && bin/builder.mjs --type=commonjs --outDir=build-cjs",
37
- "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",
38
- "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",
39
- "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",
40
- "build-esm": "rimraf build-esm && bin/builder.mjs --type=module --outDir=build-esm",
41
- "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",
42
- "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",
43
- "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",
44
- "test-jest-esm": "NODE_OPTIONS=\"--experimental-vm-modules\" jest --coverage=false src/*.mts src/*/*.mts src/*/*/*.mts",
45
- "test-jest-cjs": "jest --coverage=false src/*.ts src/*/*.ts src/*/*/*.ts",
46
- "test-cjs": "node --test build-cjs/test/index.test.cjs",
47
- "test-cjs-bundle": "node --test build-cjs-bundle/test/index.test.cjs",
48
- "test-cjs-bundle-minify": "node --test build-cjs-bundle-minify/test/index.test.cjs",
49
- "test-cjs-bundle-no-external": "node --test build-cjs-bundle-no-external/test/index.test.cjs",
50
- "test-esm": "node --test build-esm/test/index.test.mjs",
51
- "test-esm-bundle": "node --test build-esm-bundle/test/index.test.mjs",
52
- "test-esm-bundle-minify": "node --test build-esm-bundle-minify/test/index.test.mjs",
53
- "test-esm-bundle-no-external": "node --test build-esm-bundle-no-external/test/index.test.mjs",
54
- "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",
55
- "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",
56
- "ci:lint": "npm run lint",
57
- "ci:style": "npm run prettier"
58
- },
59
- "devDependencies": {
60
- "@apidevtools/json-schema-ref-parser": "^11.1.0",
61
- "@checkdigit/prettier-config": "^4.1.0",
62
- "@types/debug": "^4.1.9",
63
- "@types/jest": "^29.5.5",
64
- "@types/uuid": "^9.0.4",
65
- "@typescript-eslint/eslint-plugin": "^6.7.4",
66
- "@typescript-eslint/parser": "^6.7.4",
67
- "debug": "^4.3.4",
68
- "eslint": "^8.50.0",
69
- "eslint-config-prettier": "^9.0.0",
70
- "get-port": "^7.0.0",
71
- "got": "^11.8.6",
72
- "jest": "^29.7.0",
73
- "node-fetch": "^3.3.2",
74
- "rimraf": "^5.0.5",
75
- "ts-jest": "^29.1.1",
76
- "uuid": "^9.0.1"
77
- },
78
- "eslintConfig": {
79
- "parser": "@typescript-eslint/parser",
80
- "plugins": [
81
- "@typescript-eslint"
82
- ],
83
- "parserOptions": {
84
- "project": "./tsconfig.json"
85
- },
86
- "extends": [
87
- "eslint:all",
88
- "plugin:@typescript-eslint/recommended",
89
- "plugin:@typescript-eslint/recommended-requiring-type-checking",
90
- "plugin:@typescript-eslint/strict",
91
- "prettier"
92
- ],
93
- "rules": {
94
- "@typescript-eslint/non-nullable-type-assertion-style": "error",
95
- "capitalized-comments": "off",
96
- "one-var": "off",
97
- "sort-keys": "off",
98
- "sort-imports": "off",
99
- "func-style": [
100
- "error",
101
- "declaration",
102
- {
103
- "allowArrowFunctions": true
104
- }
105
- ],
106
- "no-magic-numbers": [
107
- "error",
108
- {
109
- "ignore": [
110
- 0,
111
- 1,
112
- 2
113
- ]
114
- }
115
- ],
116
- "no-undefined": "off",
117
- "no-ternary": "off"
118
- },
119
- "overrides": [
120
- {
121
- "files": [
122
- "*.spec.mts",
123
- "*.test.mts",
124
- "*.spec.ts",
125
- "*.test.ts"
126
- ],
127
- "rules": {
128
- "@typescript-eslint/non-nullable-type-assertion-style": "off",
129
- "@typescript-eslint/ban-types": "off",
130
- "@typescript-eslint/require-await": "off",
131
- "@typescript-eslint/consistent-type-definitions": "off",
132
- "@typescript-eslint/ban-ts-comment": "off",
133
- "@typescript-eslint/no-unnecessary-condition": "off",
134
- "@typescript-eslint/consistent-indexed-object-style": "off",
135
- "@typescript-eslint/no-unused-vars": "off",
136
- "@typescript-eslint/no-unsafe-member-access": "off",
137
- "line-comment-position": "off",
138
- "no-inline-comments": "off",
139
- "no-param-reassign": "off",
140
- "id-length": "off",
141
- "no-magic-numbers": "off",
142
- "func-names": "off",
143
- "no-duplicate-imports": "off",
144
- "symbol-description": "off",
145
- "no-invalid-this": "off",
146
- "max-lines-per-function": "off",
147
- "max-lines": "off",
148
- "max-statements": "off",
149
- "no-await-in-loop": "off"
150
- }
151
- }
152
- ]
153
- },
154
- "jest": {
155
- "moduleFileExtensions": [
156
- "js",
157
- "mjs",
158
- "cjs",
159
- "ts",
160
- "mts",
161
- "json",
162
- "node"
163
- ],
164
- "extensionsToTreatAsEsm": [
165
- ".mts"
166
- ],
167
- "transform": {
168
- "^.+\\.mts$": [
169
- "ts-jest",
170
- {
171
- "isolatedModules": true,
172
- "diagnostics": false,
173
- "useESM": true
174
- }
175
- ],
176
- "^.+\\.ts$": [
177
- "ts-jest",
178
- {
179
- "isolatedModules": true,
180
- "diagnostics": false,
181
- "useESM": false
182
- }
183
- ]
184
- },
185
- "collectCoverageFrom": [
186
- "<rootDir>/src/**",
187
- "!<rootDir>/src/**/*.spec.mts",
188
- "!<rootDir>/src/**/*.test.mts",
189
- "!<rootDir>/src/**/*.spec.ts",
190
- "!<rootDir>/src/**/*.test.ts"
191
- ],
192
- "testMatch": [
193
- "<rootDir>/src/**/*.spec.ts",
194
- "<rootDir>/src/**/*.spec.mts"
195
- ]
196
- },
197
- "files": [
198
- "bin",
199
- "tsconfig.json",
200
- "SECURITY.md"
201
- ]
202
- }
1
+ {"name":"@checkdigit/typescript-config","version":"5.1.1-PR.49-88af","description":"Check Digit standard Typescript configuration","prettier":"@checkdigit/prettier-config","engines":{"node":">=18"},"bin":{"builder":"./bin/builder.mjs"},"peerDependencies":{"@types/node":">=18","esbuild":"0.19.4","typescript":">=5.2.2 <5.3"},"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":"^4.1.0","@types/debug":"^4.1.9","@types/jest":"^29.5.5","@types/uuid":"^9.0.4","@typescript-eslint/eslint-plugin":"^6.7.4","@typescript-eslint/parser":"^6.7.4","debug":"^4.3.4","eslint":"^8.50.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-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":["bin","tsconfig.json","SECURITY.md"]}