@checkdigit/typescript-config 3.3.0-PR.30-05fd → 3.3.0-PR.30-0bbb
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.txt +1 -1
- package/package.json +1 -1
- package/src/builder/builder.mts +109 -0
- package/src/builder/builder.spec.mts +12 -0
- package/src/builder/index.mts +20 -0
- package/src/builder.mts +0 -120
- package/src/builder.spec.mts +0 -9
package/LICENSE.txt
CHANGED
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-0bbb","description":"Check Digit standard Typescript configuration","prettier":"@checkdigit/prettier-config","engines":{"node":">=16"},"peerDependencies":{"@types/node":">=16","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","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":"tsc --module nodenext --outDir build-builder src/builder/builder.mts","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 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-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","@typescript-eslint/eslint-plugin":"^5.59.2","@typescript-eslint/parser":"^5.59.2","debug":"^4.3.4","esbuild":"^0.17.18","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"},"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","func-style":["error","declaration",{"allowArrowFunctions":true}],"no-magic-numbers":["error",{"ignore":[1]}],"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","sort-imports":"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"}}]},"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/"]}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
// builder/builder.mts
|
2
|
+
|
3
|
+
import { strict as assert } from 'node:assert';
|
4
|
+
import { promises as fs } from 'node:fs';
|
5
|
+
import path from 'node:path';
|
6
|
+
import typescript from 'typescript';
|
7
|
+
import url from 'node:url';
|
8
|
+
// import { parseArgs } from 'node:util';
|
9
|
+
|
10
|
+
/*
|
11
|
+
* import { PluginBuild } from 'esbuild';
|
12
|
+
* import { build, PluginBuild } from 'esbuild';
|
13
|
+
*/
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Recursively obtains all files in a directory
|
17
|
+
* @param {string} directory
|
18
|
+
* @returns {Promise<string[]>}
|
19
|
+
*/
|
20
|
+
async function getFiles(directory: string): Promise<string[]> {
|
21
|
+
const entries = await fs.readdir(directory, { withFileTypes: true });
|
22
|
+
const files = await Promise.all(
|
23
|
+
entries.map((entry) => {
|
24
|
+
const result = path.resolve(directory, entry.name);
|
25
|
+
return entry.isDirectory() ? getFiles(result) : result;
|
26
|
+
})
|
27
|
+
);
|
28
|
+
return files.flat();
|
29
|
+
}
|
30
|
+
|
31
|
+
// function setup(pluginBuild: PluginBuild) {
|
32
|
+
// pluginBuild.onResolve({ filter: /.*/u }, async (resolved) => {
|
33
|
+
// if (resolved.kind === 'entry-point' || !resolved.path.startsWith('.') || resolved.path.endsWith('.js')) {
|
34
|
+
// return { external: resolved.kind !== 'entry-point' };
|
35
|
+
// }
|
36
|
+
// let isDirectory = false;
|
37
|
+
// try {
|
38
|
+
// const stats = await fs.lstat(path.join(resolved.resolveDir, resolved.path));
|
39
|
+
// isDirectory = stats.isDirectory();
|
40
|
+
// } catch {
|
41
|
+
// // do nothing
|
42
|
+
// }
|
43
|
+
// let newPath = resolved.path;
|
44
|
+
// newPath += isDirectory ? `/index.mjs` : `.mjs`;
|
45
|
+
// return { path: newPath, external: true };
|
46
|
+
// });
|
47
|
+
// }
|
48
|
+
|
49
|
+
// eslint-disable-next-line func-names,max-lines-per-function,max-statements
|
50
|
+
export default async function (inDir: string, outDir: string): Promise<void> {
|
51
|
+
/**
|
52
|
+
* Emit declarations using typescript compiler
|
53
|
+
*/
|
54
|
+
const sourceDirectory = path.join(path.dirname(url.fileURLToPath(import.meta.url)), inDir);
|
55
|
+
const allSourceFiles = await getFiles(sourceDirectory);
|
56
|
+
const productionSourceFiles = allSourceFiles.filter(
|
57
|
+
// && !file.endsWith('.test.ts') && !file.endsWith('.spec.ts')
|
58
|
+
(file) => file.endsWith('.ts')
|
59
|
+
);
|
60
|
+
|
61
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
62
|
+
const configFile = typescript.readConfigFile('./tsconfig.json', typescript.sys.readFile);
|
63
|
+
const compilerOptions = typescript.parseJsonConfigFileContent(configFile.config, typescript.sys, './');
|
64
|
+
|
65
|
+
const program = typescript.createProgram(productionSourceFiles, {
|
66
|
+
...compilerOptions.options,
|
67
|
+
noEmitOnError: true,
|
68
|
+
emitDeclarationOnly: true,
|
69
|
+
rootDir: inDir,
|
70
|
+
outDir,
|
71
|
+
});
|
72
|
+
const emitResult = program.emit();
|
73
|
+
const allDiagnostics = [...typescript.getPreEmitDiagnostics(program), ...emitResult.diagnostics];
|
74
|
+
for (const diagnostic of allDiagnostics) {
|
75
|
+
if (diagnostic.file) {
|
76
|
+
assert.ok(diagnostic.start !== undefined);
|
77
|
+
const { line, character } = typescript.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
78
|
+
const message = typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
79
|
+
// eslint-disable-next-line no-console
|
80
|
+
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
81
|
+
} else {
|
82
|
+
// eslint-disable-next-line no-console
|
83
|
+
console.log(typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
|
84
|
+
}
|
85
|
+
}
|
86
|
+
// if (emitResult.emitSkipped) {
|
87
|
+
// throw new Error('TypeScript compilation failed');
|
88
|
+
// }
|
89
|
+
//
|
90
|
+
// /**
|
91
|
+
// * Emit ESM javascript using esbuild
|
92
|
+
// */
|
93
|
+
// await build({
|
94
|
+
// entryPoints: productionSourceFiles,
|
95
|
+
// bundle: true,
|
96
|
+
// platform: 'node',
|
97
|
+
// format: 'esm',
|
98
|
+
// outdir: outDir as string,
|
99
|
+
// sourcemap: 'inline',
|
100
|
+
// sourcesContent: false,
|
101
|
+
// outExtension: { '.js': '.mjs' },
|
102
|
+
// plugins: [
|
103
|
+
// {
|
104
|
+
// name: 'resolve-ts',
|
105
|
+
// setup,
|
106
|
+
// },
|
107
|
+
// ],
|
108
|
+
// });
|
109
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// builder/builder.spec.mts
|
2
|
+
|
3
|
+
// @ts-expect-error
|
4
|
+
import builder from './builder';
|
5
|
+
|
6
|
+
describe('test builder', () => {
|
7
|
+
it('should build', async () => {
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
9
|
+
await builder('../test/lib', 'hello');
|
10
|
+
expect(true).toBe(true);
|
11
|
+
});
|
12
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// builder/index.mts
|
2
|
+
|
3
|
+
import { parseArgs } from 'node:util';
|
4
|
+
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
6
|
+
// @ts-expect-error
|
7
|
+
// eslint-disable-next-line sort-imports
|
8
|
+
import builder from './builder';
|
9
|
+
|
10
|
+
const {
|
11
|
+
values: { inDir, outDir },
|
12
|
+
} = parseArgs({
|
13
|
+
options: {
|
14
|
+
inDir: { type: 'string', short: 'i', default: 'src' },
|
15
|
+
outDir: { type: 'string', short: 'o', default: 'build' },
|
16
|
+
},
|
17
|
+
});
|
18
|
+
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/non-nullable-type-assertion-style
|
20
|
+
await builder(inDir as string, outDir as string);
|
package/src/builder.mts
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
// builder.mts
|
2
|
-
|
3
|
-
import { strict as assert } from 'node:assert';
|
4
|
-
import { promises as fs } from 'node:fs';
|
5
|
-
import path from 'node:path';
|
6
|
-
import typescript from 'typescript';
|
7
|
-
import url from 'node:url';
|
8
|
-
// import { parseArgs } from 'node:util';
|
9
|
-
|
10
|
-
/*
|
11
|
-
* import { PluginBuild } from 'esbuild';
|
12
|
-
* import { build, PluginBuild } from 'esbuild';
|
13
|
-
*/
|
14
|
-
|
15
|
-
/**
|
16
|
-
* Recursively obtains all files in a directory
|
17
|
-
* @param {string} directory
|
18
|
-
* @returns {Promise<string[]>}
|
19
|
-
*/
|
20
|
-
async function getFiles(directory: string): Promise<string[]> {
|
21
|
-
const entries = await fs.readdir(directory, { withFileTypes: true });
|
22
|
-
const files = await Promise.all(
|
23
|
-
entries.map((entry) => {
|
24
|
-
const result = path.resolve(directory, entry.name);
|
25
|
-
return entry.isDirectory() ? getFiles(result) : result;
|
26
|
-
})
|
27
|
-
);
|
28
|
-
return files.flat();
|
29
|
-
}
|
30
|
-
|
31
|
-
// function setup(pluginBuild: PluginBuild) {
|
32
|
-
// pluginBuild.onResolve({ filter: /.*/u }, async (resolved) => {
|
33
|
-
// if (resolved.kind === 'entry-point' || !resolved.path.startsWith('.') || resolved.path.endsWith('.js')) {
|
34
|
-
// return { external: resolved.kind !== 'entry-point' };
|
35
|
-
// }
|
36
|
-
// let isDirectory = false;
|
37
|
-
// try {
|
38
|
-
// const stats = await fs.lstat(path.join(resolved.resolveDir, resolved.path));
|
39
|
-
// isDirectory = stats.isDirectory();
|
40
|
-
// } catch {
|
41
|
-
// // do nothing
|
42
|
-
// }
|
43
|
-
// let newPath = resolved.path;
|
44
|
-
// newPath += isDirectory ? `/index.mjs` : `.mjs`;
|
45
|
-
// return { path: newPath, external: true };
|
46
|
-
// });
|
47
|
-
// }
|
48
|
-
|
49
|
-
const inDir = 'test/lib',
|
50
|
-
outDir = 'hello';
|
51
|
-
|
52
|
-
/*
|
53
|
-
* const {
|
54
|
-
* values: { inDir, outDir },
|
55
|
-
* } = parseArgs({
|
56
|
-
* options: {
|
57
|
-
* inDir: { type: 'string', short: 'i', default: 'src' },
|
58
|
-
* outDir: { type: 'string', short: 'o', default: 'build' },
|
59
|
-
* },
|
60
|
-
* });
|
61
|
-
*/
|
62
|
-
|
63
|
-
/**
|
64
|
-
* Emit declarations using typescript compiler
|
65
|
-
*/
|
66
|
-
const sourceDirectory = path.join(path.dirname(url.fileURLToPath(import.meta.url)), inDir as string);
|
67
|
-
const allSourceFiles = await getFiles(sourceDirectory);
|
68
|
-
const productionSourceFiles = allSourceFiles.filter(
|
69
|
-
// && !file.endsWith('.test.ts') && !file.endsWith('.spec.ts')
|
70
|
-
(file) => file.endsWith('.ts')
|
71
|
-
);
|
72
|
-
|
73
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
74
|
-
const configFile = typescript.readConfigFile('./tsconfig.json', typescript.sys.readFile);
|
75
|
-
const compilerOptions = typescript.parseJsonConfigFileContent(configFile.config, typescript.sys, './');
|
76
|
-
|
77
|
-
const program = typescript.createProgram(productionSourceFiles, {
|
78
|
-
...compilerOptions.options,
|
79
|
-
noEmitOnError: true,
|
80
|
-
emitDeclarationOnly: true,
|
81
|
-
rootDir: inDir as string,
|
82
|
-
outDir: outDir as string,
|
83
|
-
});
|
84
|
-
const emitResult = program.emit();
|
85
|
-
const allDiagnostics = [...typescript.getPreEmitDiagnostics(program), ...emitResult.diagnostics];
|
86
|
-
for (const diagnostic of allDiagnostics) {
|
87
|
-
if (diagnostic.file) {
|
88
|
-
assert.ok(diagnostic.start !== undefined);
|
89
|
-
const { line, character } = typescript.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
90
|
-
const message = typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
91
|
-
// eslint-disable-next-line no-console
|
92
|
-
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
93
|
-
} else {
|
94
|
-
// eslint-disable-next-line no-console
|
95
|
-
console.log(typescript.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
|
96
|
-
}
|
97
|
-
}
|
98
|
-
// if (emitResult.emitSkipped) {
|
99
|
-
// throw new Error('TypeScript compilation failed');
|
100
|
-
// }
|
101
|
-
//
|
102
|
-
// /**
|
103
|
-
// * Emit ESM javascript using esbuild
|
104
|
-
// */
|
105
|
-
// await build({
|
106
|
-
// entryPoints: productionSourceFiles,
|
107
|
-
// bundle: true,
|
108
|
-
// platform: 'node',
|
109
|
-
// format: 'esm',
|
110
|
-
// outdir: outDir as string,
|
111
|
-
// sourcemap: 'inline',
|
112
|
-
// sourcesContent: false,
|
113
|
-
// outExtension: { '.js': '.mjs' },
|
114
|
-
// plugins: [
|
115
|
-
// {
|
116
|
-
// name: 'resolve-ts',
|
117
|
-
// setup,
|
118
|
-
// },
|
119
|
-
// ],
|
120
|
-
// });
|