Skip to content

Commit 7f9aed6

Browse files
committed
Enable requiring the package.json
1 parent fcf890d commit 7f9aed6

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"scripts": "dist/lib/workers/worker.js"
2222
},
2323
"scripts": {
24-
"build": "tsc -p ./tsconfig.build.json",
24+
"build": "rm -r ./dist || true; tsc -p ./tsconfig.build.json",
2525
"ts-node": "ts-node -r tsconfig-paths/register",
2626
"test": "jest",
2727
"lint": "eslint '{src,tests}/**/*.{js,ts}'",

src/bin/typescript-demo-lib.ts

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import NumPair from '../lib/NumPair';
88
import testLevel from '../lib/test-level';
99
import testUtpNative from '../lib/test-utp-native';
1010
import testWorkers from '../lib/workers/test-workers';
11+
import { version } from '../utils';
1112

1213
async function main(argv = process.argv): Promise<number> {
1314
// Print out command-line arguments
@@ -34,6 +35,8 @@ async function main(argv = process.argv): Promise<number> {
3435
await testWorkers();
3536
await testUtpNative();
3637

38+
process.stdout.write(version);
39+
3740
process.exitCode = 0;
3841
return process.exitCode;
3942
}

src/utils.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"test": true
3+
}

src/utils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import { test } from './utils.json';
2+
// @ts-ignore package.json is outside rootDir
3+
import { version } from '../package.json';
4+
15
async function sleep(ms: number) {
26
return await new Promise((r) => setTimeout(r, ms));
37
}
48

5-
export { sleep };
9+
export { sleep, version, test };

tsconfig.json

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"rootDir": "./src",
34
"outDir": "./dist",
45
"sourceMap": true,
56
"declaration": true,
@@ -8,6 +9,7 @@
89
"noImplicitAny": false,
910
"esModuleInterop": true,
1011
"allowSyntheticDefaultImports": true,
12+
"resolveJsonModule": true,
1113
"moduleResolution": "node",
1214
"module": "CommonJS",
1315
"target": "ES2020",

0 commit comments

Comments
 (0)