Skip to content

Commit 8017184

Browse files
authored
Use src/**/*.ts when developing locally (#3944)
* add typescript exports key * Update vitest to use typescript conditions * Merge branch 'master' into run-typescript-natively * Merge remote-tracking branch 'origin/master' into run-typescript-natively * Update vm and genesis scripts/config to use typescript conditions * update tx script * update docs * one more update * update client package config * address feedback
1 parent 9ee4e87 commit 8017184

File tree

22 files changed

+154
-61
lines changed

22 files changed

+154
-61
lines changed

config/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ Use CLI commands above in your `package.json`:
132132
}
133133
```
134134

135+
### Doing cross-package development
136+
137+
All of our packages include a `typescript` entry in the `exports` map under the `esm` key. This allows `node`/`tsx`/`vitest` to use
138+
the typescript sources directly without requiring you to recompile packages when you make changes.
139+
140+
Vitest is already configured to use the `typescript` entry points so simply specify `npx vitest run-c ../../config/vitest.config.mts test/myTest.spec.ts`
141+
when running individual tests.
142+
143+
If running typescript scripts from the command line, you can use `tsx --conditions=typescript myScript.ts` to use the typescript sources.
144+
145+
When running code using a bash script, you can set an environment variable `NODE_OPTIONS='--conditions=typescript'` and this will get picked by `tsx`.
146+
135147
## Documentation
136148

137149
Add `typedoc.js` to a package that extends the generic TypeDoc configuration:

config/vitest.config.mts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { configDefaults, defineConfig, mergeConfig } from 'vitest/config'
2+
export default defineConfig({
3+
environments: {
4+
ssr: {
5+
resolve: {
6+
conditions: ['typescript'],
7+
},
8+
},
9+
},
10+
})

packages/binarytree/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
"module": "dist/esm/index.js",
2626
"exports": {
2727
".": {
28-
"import": "./dist/esm/index.js",
28+
"import": {
29+
"typescript": "./src/index.ts",
30+
"default": "./dist/esm/index.js"
31+
},
2932
"require": "./dist/cjs/index.js"
3033
}
3134
},
@@ -42,7 +45,7 @@
4245
"lint:fix": "npm run biome:fix && eslint --fix --config ./eslint.config.mjs .",
4346
"prepublishOnly": "../../config/cli/prepublish.sh",
4447
"test": "npm run test:node",
45-
"test:node": "npx vitest run",
48+
"test:node": "npx vitest run -c ../../config/vitest.config.mts",
4649
"test:browser": "npx vitest run --config=../../config/vitest.config.browser.mts",
4750
"tsc": "../../config/cli/ts-compile.sh"
4851
},

packages/block/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
"module": "dist/esm/index.js",
2020
"exports": {
2121
".": {
22-
"import": "./dist/esm/index.js",
22+
"import": {
23+
"typescript": "./src/index.ts",
24+
"default": "./dist/esm/index.js"
25+
},
2326
"require": "./dist/cjs/index.js"
2427
}
2528
},
@@ -39,7 +42,7 @@
3942
"prepublishOnly": "../../config/cli/prepublish.sh",
4043
"test": "npm run test:node && npm run test:browser",
4144
"test:browser": "npx vitest run --config=../../config/vitest.config.browser.mts",
42-
"test:node": "npx vitest run",
45+
"test:node": "npx vitest run -c ../../config/vitest.config.mts",
4346
"tsc": "../../config/cli/ts-compile.sh"
4447
},
4548
"dependencies": {

packages/blockchain/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
"module": "dist/esm/index.js",
2020
"exports": {
2121
".": {
22-
"import": "./dist/esm/index.js",
22+
"import": {
23+
"typescript": "./src/index.ts",
24+
"default": "./dist/esm/index.js"
25+
},
2326
"require": "./dist/cjs/index.js"
2427
}
2528
},
@@ -39,7 +42,7 @@
3942
"prepublishOnly": "../../config/cli/prepublish.sh",
4043
"test": "npm run test:node && npm run test:browser",
4144
"test:browser": "npx vitest run --config=./vitest.config.browser.mts",
42-
"test:node": "npx vitest run",
45+
"test:node": "npx vitest run -c ../../config/vitest.config.mts",
4346
"tsc": "../../config/cli/ts-compile.sh"
4447
},
4548
"dependencies": {

packages/client/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"build": "npm run build:common && mkdir -p ./src/trustedSetup/ && cp -Rf ./src/trustedSetups ./dist/src/",
2828
"build:common": "./scripts/ts-build.sh && ./scripts/postBuildFixes.sh",
2929
"clean": "../../config/cli/clean-package.sh",
30-
"client:start:ts": "tsx bin/cli.ts",
30+
"client:start:ts": "tsx --conditions=typescript bin/cli.ts",
3131
"client:start:js": "npm run build && node dist/esm/bin/cli.js",
3232
"client:start": "npm run client:start:js --",
3333
"client:start:dev1": "npm run client:start -- --discDns=false --discV4=false --bootnodes",
@@ -42,9 +42,9 @@
4242
"prepublishOnly": "../../config/cli/prepublish.sh",
4343
"repl": "npx tsx ./bin/repl.ts --logLevel=error",
4444
"test": "npm run test:unit && npm run test:integration",
45-
"test:cli": "npx vitest run ./test/cli/*.spec.ts",
46-
"test:integration": "npx vitest run ./test/integration/*.spec.ts",
47-
"test:unit": "npx vitest run test/* -c=./vitest.config.unit.ts",
45+
"test:cli": "npx vitest run -c ../../config/vitest.config.mts ./test/cli/*.spec.ts",
46+
"test:integration": "npx vitest run -c ../../config/vitest.config.mts ./test/integration/*.spec.ts",
47+
"test:unit": "npx vitest run -c ./vitest.config.unit.ts",
4848
"tsc": "../../config/cli/ts-compile.sh"
4949
},
5050
"dependencies": {

packages/client/vitest.config.unit.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { defineConfig } from 'vitest/config'
1+
import { defineConfig, mergeConfig } from 'vitest/config'
2+
import baseConfig from '../../config/vitest.config.mts'
23

3-
export default defineConfig({
4-
test: {
5-
silent: true,
6-
exclude: ['test/integration', 'test/sim', 'test/cli'],
7-
testTimeout: 300000,
8-
alias: { '@polkadot/util': 'false' },
9-
typecheck: {
10-
tsconfig: './tsconfig.prod.esm.json',
4+
export default mergeConfig(
5+
baseConfig,
6+
defineConfig({
7+
test: {
8+
silent: true,
9+
exclude: ['test/integration', 'test/sim', 'test/cli'],
10+
testTimeout: 300000,
11+
alias: { '@polkadot/util': 'false' },
12+
typecheck: {
13+
tsconfig: './tsconfig.prod.esm.json',
14+
},
1115
},
12-
},
13-
})
16+
}),
17+
)

packages/common/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
"module": "dist/esm/index.js",
3333
"exports": {
3434
".": {
35-
"import": "./dist/esm/index.js",
35+
"import": {
36+
"typescript": "./src/index.ts",
37+
"default": "./dist/esm/index.js"
38+
},
3639
"require": "./dist/cjs/index.js"
3740
}
3841
},
@@ -52,7 +55,7 @@
5255
"prepublishOnly": "../../config/cli/prepublish.sh",
5356
"test": "npm run test:node && npm run test:browser",
5457
"test:browser": "npx vitest run --config=../../config/vitest.config.browser.mts",
55-
"test:node": "npx vitest run",
58+
"test:node": "npx vitest run -c ../../config/vitest.config.mts",
5659
"tsc": "../../config/cli/ts-compile.sh"
5760
},
5861
"dependencies": {

packages/devp2p/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
"module": "dist/esm/index.js",
3636
"exports": {
3737
".": {
38-
"import": "./dist/esm/index.js",
38+
"import": {
39+
"typescript": "./src/index.ts",
40+
"default": "./dist/esm/index.js"
41+
},
3942
"require": "./dist/cjs/index.js"
4043
}
4144
},
@@ -53,7 +56,7 @@
5356
"lint": "npm run biome && eslint --config ./eslint.config.mjs .",
5457
"lint:fix": "npm run biome:fix && eslint --fix --config ./eslint.config.mjs .",
5558
"prepublishOnly": "../../config/cli/prepublish.sh",
56-
"test": "vitest run",
59+
"test": "vitest run -c ../../config/vitest.config.mts",
5760
"test:node": "npm run test",
5861
"tsc": "../../config/cli/ts-compile.sh"
5962
},

packages/era/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
"module": "dist/esm/index.js",
2626
"exports": {
2727
".": {
28-
"import": "./dist/esm/index.js",
28+
"import": {
29+
"typescript": "./src/index.ts",
30+
"default": "./dist/esm/index.js"
31+
},
2932
"require": "./dist/cjs/index.js"
3033
}
3134
},
@@ -44,7 +47,7 @@
4447
"lint:fix": "npm run biome:fix && eslint --fix --config ./eslint.config.mjs .",
4548
"prepublishOnly": "../../config/cli/prepublish.sh",
4649
"test": "npm run test:node",
47-
"test:node": "npx vitest run",
50+
"test:node": "npx vitest run -c ../../config/vitest.config.mts",
4851
"tsc": "../../config/cli/ts-compile.sh"
4952
},
5053
"dependencies": {

0 commit comments

Comments
 (0)