Skip to content

Commit ddd5a2b

Browse files
authored
Merge pull request #381 from MatrixAI/feature-eng-556-polykey-cli-migration-to-esm
ESM migration
2 parents f325ede + 0ea0a1b commit ddd5a2b

File tree

188 files changed

+3898
-2503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+3898
-2503
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
"jest": true
88
},
99
"parser": "@typescript-eslint/parser",
10+
"parserOptions": {
11+
"project": "tsconfig.json",
12+
"sourceType": "module"
13+
},
14+
"plugins": [
15+
"import"
16+
],
1017
"extends": [
1118
"eslint:recommended",
1219
"plugin:@typescript-eslint/recommended",
1320
"plugin:prettier/recommended"
1421
],
15-
"plugins": [
16-
"import"
17-
],
18-
"parserOptions": {
19-
"project": "tsconfig.json",
20-
"sourceType": "module"
21-
},
2222
"rules": {
2323
"linebreak-style": ["error", "unix"],
2424
"no-empty": 1,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ npm install
9696
# build the dist
9797
npm run build
9898
# run the repl (this allows you to import from ./src)
99-
npm run ts-node
99+
npm run tsx
100100
# run the tests
101101
npm run test
102102
# lint the source code

jest.config.js renamed to jest.config.mjs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
const os = require('os');
2-
const path = require('path');
3-
const fs = require('fs');
4-
const process = require('process');
5-
const { pathsToModuleNameMapper } = require('ts-jest');
6-
const { compilerOptions } = require('./tsconfig');
1+
import path from 'node:path';
2+
import url from 'node:url';
3+
import os from 'node:os';
4+
import process from 'node:process';
5+
import tsconfigJSON from './tsconfig.json' assert { type: "json" };
76

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

129
// Global variables that are shared across the jest worker pool
1310
// These variables must be static and serializable
14-
if ((process.env.PK_TEST_PLATFORM != null) !== (process.env.PK_TEST_COMMAND != null)) throw Error('Both PK_TEST_PLATFORM and PK_TEST_COMMAND must be set together.')
1511
const globals = {
1612
// Absolute directory to the project root
17-
projectDir: __dirname,
13+
projectDir: projectPath,
1814
// Absolute directory to the test root
19-
testDir: path.join(__dirname, 'tests'),
20-
// Default global data directory
21-
dataDir: fs.mkdtempSync(
22-
path.join(os.tmpdir(), 'polykey-test-global-'),
23-
),
15+
testDir: path.join(projectPath, 'tests'),
2416
// Default asynchronous test timeout
2517
defaultTimeout: 20000,
2618
failedConnectionTimeout: 50000,
@@ -31,10 +23,11 @@ const globals = {
3123

3224
// The `globalSetup` and `globalTeardown` cannot access the `globals`
3325
// They run in their own process context
34-
// They can receive process environment
26+
// They can however receive the process environment
27+
// Use `process.env` to set variables
3528
process.env['GLOBAL_DATA_DIR'] = globals.dataDir;
3629

37-
module.exports = {
30+
const config = {
3831
testEnvironment: 'node',
3932
verbose: true,
4033
collectCoverage: false,
@@ -46,15 +39,15 @@ module.exports = {
4639
"^.+\\.(t|j)sx?$": [
4740
"@swc/jest",
4841
{
49-
"jsc": {
50-
"parser": {
51-
"syntax": "typescript",
52-
"dynamicImport": true,
53-
"tsx": true,
54-
"decorators": compilerOptions.experimentalDecorators,
42+
jsc: {
43+
parser: {
44+
syntax: "typescript",
45+
tsx: true,
46+
decorators: tsconfigJSON.compilerOptions.experimentalDecorators,
47+
dynamicImport: true,
5548
},
56-
"target": compilerOptions.target.toLowerCase(),
57-
"keepClassNames": true,
49+
target: tsconfigJSON.compilerOptions.target.toLowerCase(),
50+
keepClassNames: true,
5851
},
5952
}
6053
],
@@ -87,5 +80,10 @@ module.exports = {
8780
'jest-extended/all',
8881
'<rootDir>/tests/setupAfterEnv.ts'
8982
],
90-
moduleNameMapper: moduleNameMapper,
83+
moduleNameMapper: {
84+
"^(\\.{1,2}/.*)\\.js$": "$1",
85+
},
86+
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
9187
};
88+
89+
export default config;

npmDepsHash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sha256-LHQ8nB8ewWjKMgdkS1oguQKaFk1IsAroYdZ21Z7bnME=
1+
sha256-HhXB5SIRl0Z8RUGozF7NHcaOQsvMmUG90iZlUBcbyng=

0 commit comments

Comments
 (0)