Skip to content

Commit 3269059

Browse files
committed
wip: updating build files
[ci skip]
1 parent add75c0 commit 3269059

File tree

5 files changed

+69
-52
lines changed

5 files changed

+69
-52
lines changed

.eslintrc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77
"jest": true
88
},
99
"parser": "@typescript-eslint/parser",
10-
"extends": [
11-
"eslint:recommended",
12-
"plugin:@typescript-eslint/recommended",
13-
"plugin:prettier/recommended",
14-
"prettier"
15-
],
16-
"plugins": [
17-
"import"
18-
],
1910
"parserOptions": {
2011
"project": "tsconfig.json",
2112
"sourceType": "module"
2213
},
14+
"plugins": [
15+
"import"
16+
],
17+
"extends": [
18+
"eslint:recommended",
19+
"plugin:@typescript-eslint/recommended",
20+
"plugin:prettier/recommended"
21+
],
2322
"rules": {
2423
"linebreak-style": ["error", "unix"],
2524
"no-empty": 1,
@@ -39,6 +38,7 @@
3938
"message": "Use `globalThis` instead"
4039
}
4140
],
41+
"prefer-rest-params": 0,
4242
"require-yield": 0,
4343
"eqeqeq": ["error", "smart"],
4444
"spaced-comment": [

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ npm install
106106
# build the dist
107107
npm run build
108108
# run the repl (this allows you to import from ./src)
109-
npm run ts-node
109+
npm run tsx
110110
# run the tests
111111
npm run test
112112
# lint the source code

jest.config.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
const path = require('path');
2-
const { pathsToModuleNameMapper } = require('ts-jest');
3-
const { compilerOptions } = require('./tsconfig');
1+
import path from 'node:path';
2+
import url from 'node:url';
3+
import tsconfigJSON from './tsconfig.json' assert { type: "json" };
44

5-
const moduleNameMapper = pathsToModuleNameMapper(compilerOptions.paths, {
6-
prefix: '<rootDir>/src/',
7-
});
5+
const projectPath = path.dirname(url.fileURLToPath(import.meta.url));
86

97
// Global variables that are shared across the jest worker pool
108
// These variables must be static and serializable
119
const globals = {
1210
// Absolute directory to the project root
13-
projectDir: __dirname,
11+
projectDir: projectPath,
1412
// Absolute directory to the test root
15-
testDir: path.join(__dirname, 'tests'),
13+
testDir: path.join(projectPath, 'tests'),
1614
// Default asynchronous test timeout
1715
defaultTimeout: 20000,
1816
// Timeouts rely on setTimeout which takes 32 bit numbers
@@ -24,7 +22,7 @@ const globals = {
2422
// They can however receive the process environment
2523
// Use `process.env` to set variables
2624

27-
module.exports = {
25+
const config = {
2826
testEnvironment: 'node',
2927
verbose: true,
3028
collectCoverage: false,
@@ -40,10 +38,10 @@ module.exports = {
4038
parser: {
4139
syntax: "typescript",
4240
tsx: true,
43-
decorators: compilerOptions.experimentalDecorators,
41+
decorators: tsconfigJSON.compilerOptions.experimentalDecorators,
4442
dynamicImport: true,
4543
},
46-
target: compilerOptions.target.toLowerCase(),
44+
target: tsconfigJSON.compilerOptions.target.toLowerCase(),
4745
keepClassNames: true,
4846
},
4947
}
@@ -77,5 +75,10 @@ module.exports = {
7775
'jest-extended/all',
7876
'<rootDir>/tests/setupAfterEnv.ts'
7977
],
80-
moduleNameMapper: moduleNameMapper,
78+
moduleNameMapper: {
79+
"^(\\.{1,2}/.*)\\.js$": "$1",
80+
},
81+
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
8182
};
83+
84+
export default config;

package.json

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,30 @@
88
"type": "git",
99
"url": "https://github.com/MatrixAI/js-id.git"
1010
},
11-
"main": "dist/index.js",
12-
"types": "dist/index.d.ts",
11+
"type": "module",
12+
"exports": {
13+
"./package.json": "./package.json",
14+
".": {
15+
"types": "./dist/index.d.ts",
16+
"import": "./dist/index.js"
17+
},
18+
"./*.js": {
19+
"types": "./dist/*.d.ts",
20+
"import": "./dist/*.js"
21+
},
22+
"./*": "./dist/*"
23+
},
24+
"imports": {
25+
"#*": "./dist/*"
26+
},
1327
"scripts": {
1428
"prepare": "tsc -p ./tsconfig.build.json",
1529
"build": "shx rm -rf ./dist && tsc -p ./tsconfig.build.json",
1630
"postversion": "npm install --package-lock-only --ignore-scripts --silent",
17-
"ts-node": "ts-node",
18-
"test": "jest",
19-
"lint": "eslint '{src,tests,scripts,benches}/**/*.{js,ts}'",
20-
"lintfix": "eslint '{src,tests,scripts,benches}/**/*.{js,ts}' --fix",
31+
"tsx": "tsx",
32+
"test": "node ./scripts/test.mjs",
33+
"lint": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx}'",
34+
"lintfix": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx}' --fix",
2135
"lint-shell": "find ./src ./tests ./scripts -type f -regextype posix-extended -regex '.*\\.(sh)' -exec shellcheck {} +",
2236
"docs": "shx rm -rf ./docs && typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src"
2337
},
@@ -27,24 +41,22 @@
2741
},
2842
"devDependencies": {
2943
"@swc/core": "^1.3.62",
30-
"@swc/jest": "^0.2.26",
31-
"@types/jest": "^28.1.3",
32-
"@types/node": "^18.15.0",
33-
"@typescript-eslint/eslint-plugin": "^5.45.1",
34-
"@typescript-eslint/parser": "^5.45.1",
35-
"eslint": "^8.15.0",
36-
"eslint-config-prettier": "^8.5.0",
37-
"eslint-plugin-import": "^2.26.0",
38-
"eslint-plugin-prettier": "^4.0.0",
39-
"jest": "^28.1.1",
40-
"jest-extended": "^3.0.1",
41-
"jest-junit": "^14.0.0",
42-
"prettier": "^2.6.2",
44+
"@swc/jest": "^0.2.29",
45+
"@types/jest": "^29.5.2",
46+
"@types/node": "^20.5.7",
47+
"@typescript-eslint/eslint-plugin": "^5.61.0",
48+
"@typescript-eslint/parser": "^5.61.0",
49+
"eslint": "^8.44.0",
50+
"eslint-config-prettier": "^8.8.0",
51+
"eslint-plugin-import": "^2.27.5",
52+
"eslint-plugin-prettier": "^5.0.0-alpha.2",
53+
"jest": "^29.6.2",
54+
"jest-extended": "^4.0.0",
55+
"jest-junit": "^16.0.0",
56+
"prettier": "^3.0.0",
4357
"shx": "^0.3.4",
44-
"ts-jest": "^28.0.5",
45-
"ts-node": "^10.9.1",
46-
"tsconfig-paths": "^3.9.0",
47-
"typedoc": "^0.23.21",
48-
"typescript": "^4.9.3"
58+
"tsx": "^3.12.7",
59+
"typedoc": "^0.24.8",
60+
"typescript": "^5.1.6"
4961
}
5062
}

tsconfig.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@
88
"allowJs": true,
99
"strictNullChecks": true,
1010
"noImplicitAny": false,
11+
"experimentalDecorators": true,
1112
"esModuleInterop": true,
1213
"allowSyntheticDefaultImports": true,
1314
"resolveJsonModule": true,
14-
"moduleResolution": "node",
15-
"module": "CommonJS",
15+
"isolatedModules": true,
16+
"moduleResolution": "NodeNext",
17+
"module": "ESNext",
1618
"target": "ES2022",
1719
"baseUrl": "./src",
1820
"paths": {
19-
"@": ["index"],
20-
"@/*": ["*"]
21+
"#*": ["*"]
2122
},
23+
"skipLibCheck": true,
2224
"noEmit": true
2325
},
2426
"include": [
2527
"./src/**/*",
2628
"./src/**/*.json",
2729
"./tests/**/*",
28-
"./scripts/**/*"
30+
"./scripts/**/*",
2931
],
3032
"ts-node": {
31-
"require": ["tsconfig-paths/register"],
33+
"esm": true,
3234
"transpileOnly": true,
3335
"swc": true
3436
}

0 commit comments

Comments
 (0)