Skip to content

Commit 8b09d49

Browse files
authored
Improve dev experience (#1854)
* WIP switch to yarn * WIP switch to yarn * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * confirm node and TS versions on CI * Fix * WIP * WIP * WIP * WIP * WIP * shrink the test matrix more * fix * fix
1 parent 6ab696c commit 8b09d49

17 files changed

+6470
-5350
lines changed

.github/workflows/continuous-integration.yml

+52-46
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@ jobs:
2020
# checkout code
2121
- uses: actions/checkout@v2
2222
# install node
23-
- name: Use Node.js 16
23+
- name: Use Node.js 18
2424
uses: actions/setup-node@v1
2525
with:
26-
node-version: 16
27-
- run: |
28-
npm config set cache "$( node -p "process.cwd()" )/temp/npm-cache"
26+
node-version: 18
27+
- name: Get cache directory
28+
id: get-cache-directory
29+
run: |
30+
yarn config get cacheFolder
31+
echo "::set-output name=path::$( yarn config get cacheFolder )"
2932
- name: Cache dependencies
3033
uses: actions/cache@v2
3134
with:
32-
path: temp/npm-cache
33-
key: npm-cache-packaging-${{ hashFiles('package-lock.json') }}
34-
restore-keys: npm-cache-packaging-
35+
path: ${{ steps.get-cache-directory.outputs.path }}
36+
key: yarn-cache-packaging-${{ hashFiles('yarn.lock') }}
37+
restore-keys: yarn-cache-packaging-
3538
# lint, build, test
36-
- run: npm ci
37-
- run: npm run lint
38-
- run: npm run build-pack
39+
- run: yarn install --immutable
40+
- run: yarn lint
41+
- run: yarn build
3942
- name: Upload package artifact
4043
uses: actions/upload-artifact@v1
4144
with:
@@ -46,20 +49,23 @@ jobs:
4649
needs: lint-build
4750
name: "Test: ${{ matrix.os }}, node ${{ matrix.node }}, TS ${{ matrix.typescript }}"
4851
runs-on: ${{ matrix.os }}-latest
52+
env:
53+
TEST_MATRIX_NODE_VERSION: ${{ matrix.node }}
54+
TEST_MATRIX_TYPESCRIPT_VERSION: ${{ matrix.typescript }}
4955
strategy:
5056
fail-fast: false
5157
matrix:
5258
os: [ubuntu, windows]
5359
# Don't forget to add all new flavors to this list!
54-
flavor: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
60+
flavor: [2, 3, 4, 6, 8, 9, 10, 11]
5561
include:
5662
# Node 14.13.0
5763
# To test ESM builtin module resolution immediately before a node behavioral change: https://github.com/TypeStrong/ts-node/issues/1130
58-
- flavor: 1
59-
node: 14.13.0
60-
nodeFlag: 14_13_0
61-
typescript: latest
62-
typescriptFlag: latest
64+
# - flavor: 1
65+
# node: 14.13.0
66+
# nodeFlag: 14_13_0
67+
# typescript: latest
68+
# typescriptFlag: latest
6369
# Node 14
6470
- flavor: 2
6571
node: 14
@@ -79,23 +85,23 @@ jobs:
7985
# Node 16
8086
# Node 16.11.1
8187
# Earliest version that supports old ESM Loader Hooks API: https://github.com/TypeStrong/ts-node/pull/1522
82-
- flavor: 5
83-
node: 16.11.1
84-
nodeFlag: 16_11_1
85-
typescript: latest
86-
typescriptFlag: latest
88+
# - flavor: 5
89+
# node: 16.11.1
90+
# nodeFlag: 16_11_1
91+
# typescript: latest
92+
# typescriptFlag: latest
8793
- flavor: 6
8894
node: 16
8995
nodeFlag: 16
9096
typescript: latest
9197
typescriptFlag: latest
9298
downgradeNpm: true
93-
- flavor: 7
94-
node: 16
95-
nodeFlag: 16
96-
typescript: 4.0
97-
typescriptFlag: 4_0
98-
downgradeNpm: true
99+
# - flavor: 7
100+
# node: 16
101+
# nodeFlag: 16
102+
# typescript: 4.0
103+
# typescriptFlag: 4_0
104+
# downgradeNpm: true
99105
- flavor: 8
100106
node: 16
101107
nodeFlag: 16
@@ -153,40 +159,40 @@ jobs:
153159
Invoke-WebRequest -Uri $url -OutFile $targetPath -UserAgent ([Microsoft.PowerShell.Commands.PSUserAgent]::Chrome)
154160
node --version
155161
# lint, build, test
156-
# Downgrade from npm 7 to 6 because 7 still seems buggy to me
157-
- if: ${{ matrix.downgradeNpm }}
158-
run: npm install -g npm@6
159-
- run: |
160-
npm config set cache "$( node -p "process.cwd()" )/temp/npm-cache"
162+
- name: Get cache directory
163+
id: get-cache-directory
164+
run: |
165+
yarn config get cacheFolder
166+
echo "::set-output name=path::$( yarn config get cacheFolder )"
161167
- name: Cache dependencies
162168
if: ${{ matrix.os != 'windows' }}
163169
uses: actions/cache@v2
164170
with:
165-
path: temp/npm-cache
166-
key: npm-cache-${{ matrix.os }}-${{ hashFiles('package-lock.json') }}
167-
restore-keys: npm-cache-${{matrix.os }}-
168-
- run: npm ci --ignore-scripts
169-
- name: Upload npm logs
171+
path: ${{ steps.get-cache-directory.outputs.path }}
172+
key: yarn-cache-${{ matrix.os }}-${{ hashFiles('yarn.lock') }}
173+
restore-keys: yarn-cache-${{matrix.os }}-
174+
- run: yarn install --immutable --mode=skip-build
175+
- name: Upload yarn logs
170176
if: ${{ failure() }}
171177
uses: actions/upload-artifact@v1
172178
with:
173-
name: npm-logs
174-
path: temp/npm-cache/_logs
175-
- run: npm run build-tsc
179+
name: yarn-logs
180+
path: yarn-error.log
181+
- run: yarn build-tsc
176182
- name: Download package artifact
177183
uses: actions/download-artifact@v1
178184
with:
179185
name: ts-node-packed.tgz
180186
path: tests/
181-
- run: npm install typescript@${{ matrix.typescript }} --force
182-
- run: npm run test-cov
183-
- name: Upload npm logs
187+
- run: yarn add -D typescript@${{ matrix.typescript }}
188+
- run: yarn test-cov
189+
- name: Upload yarn logs
184190
if: ${{ failure() }}
185191
uses: actions/upload-artifact@v1
186192
with:
187-
name: npm-logs-${{ matrix.os }}-node-${{ matrix.nodeFlag }}-typescript-${{ matrix.typescriptFlag }}
188-
path: temp/npm-cache/_logs
189-
- run: npm run coverage-report
193+
name: yarn-logs-${{ matrix.os }}-node-${{ matrix.nodeFlag }}-typescript-${{ matrix.typescriptFlag }}
194+
path: yarn-error.log
195+
- run: yarn coverage-report
190196
if: ${{ always() }}
191197
- name: Codecov
192198
if: ${{ always() }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ npm-debug.log
1313
/website/static/api
1414
/tsconfig.tsbuildinfo
1515
/temp
16+
/yarn-error.log
17+
/.yarn/install-state.gz
18+
/tests/.yarn/install-state.gz
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// No-op plugin to disable yarn's own plugin-compat, preventing any unexpected
2+
// modifications to the typescript package and others
3+
module.exports = {
4+
name: `@yarnpkg/plugin-compat`,
5+
factory: require => ({})
6+
};

.yarn/releases/yarn-3.2.2.cjs

+783
Large diffs are not rendered by default.

.yarnrc.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
enableGlobalCache: true
2+
3+
nmMode: hardlinks-global
4+
5+
nodeLinker: node-modules
6+
7+
plugins:
8+
- path: .yarn/plugins/@yarnpkg/plugin-compat.cjs
9+
spec: .yarn/plugins/@yarnpkg/plugin-compat.cjs
10+
11+
yarnPath: .yarn/releases/yarn-3.2.2.cjs
12+
13+
nmHoistingLimits: workspaces

CONTRIBUTING.md

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
*This guide is best-effort and will be improved as necessary.*
22

3+
## Dev environment
4+
5+
Tools I use:
6+
7+
- yarn 3 for package management
8+
- volta (optional, node version management)
9+
310
## Features, bugfixes, and other code
411

5-
We use npm scripts for building, testing, and linting. Read the scripts to become familiar with our build process. The big ones are:
12+
We use package.json scripts for building, testing, and linting. Read the scripts to become familiar with our build process. The big ones are:
613

714
```
8-
npm install
9-
npm run build
10-
npm run test-local
11-
npm run lint-fix
15+
yarn
16+
yarn build
17+
yarn test-local
18+
yarn fmt
1219
```
1320

14-
`npm prepare` is maintained so that anyone can install `ts-node` from git, which is useful for testing experimental branches and unreleased features.
21+
`npm prepare` / `yarn prepare` is maintained so that anyone can install `ts-node` from git, which is useful for testing experimental branches and unreleased features.
1522

1623
Source lives in `src` and is compiled to `dist`. Some shim files live outside of `src` so that they can be imported at
1724
certain paths. For example, to allow users to import `ts-node/register`, we have `register/index.js` which is a shim to
@@ -21,20 +28,20 @@ compiled code in `dist`.
2128

2229
## Tests
2330

24-
Test cases are declared in `src/test/*.spec.ts`, and test fixtures live in `./tests`. They can be run with `npm run test-local`.
31+
Test cases are declared in `src/test/*.spec.ts`, and test fixtures live in `./tests`. They can be run with `yarn test-local`.
2532

2633
To run a subset of tests:
2734

2835
```
2936
# Use ava's --match flag to match the name of a test or suite
3037
# https://github.com/avajs/ava/blob/main/docs/05-command-line.md
3138
# Don't forget the * wildcards
32-
npm run test-local -- --match '*esm loader*'
39+
yarn test-local --match '*esm loader*'
3340
```
3441

3542
Tests are run with AVA, but using a custom wrapper API to enable some TS-friendly features and grouped test suites.
3643

37-
The tests `npm pack` ts-node into a tarball and `npm install` it into `./tests/node_modules`. This makes `./tests` a better testing environment
44+
The tests `yarn pack` ts-node into a tarball and `yarn install` it into `./tests/node_modules`. This makes `./tests` a better testing environment
3845
because it more closely matches the end-user's environment. Complex `require()` / `import` / `--require` / `--loader` invocations behave
3946
the way they would in a users's project.
4047

@@ -120,7 +127,7 @@ We publish using `np`: https://npm.im/np
120127

121128
## APIExtractor
122129

123-
`npm run api-extractor` will update an API report generated by [`api-extractor`](https://api-extractor.com/pages/overview/intro/) which may be useful
130+
`yarn api-extractor` will update an API report generated by [`api-extractor`](https://api-extractor.com/pages/overview/intro/) which may be useful
124131
when generating release notes to detect (breaking) changes in our API surface.
125132

126133
I configured it for my own convenience; it is not a necessary part of our development process.

justfile

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ regenerate:
1313
const fs = require("fs");
1414
let acc = fs.readFileSync("justfile", "utf8").replace(/(# CUT\n)[\s\S]+/, "$1\n");
1515
for(const [key, value] of Object.entries(require("./package.json").scripts)) {
16-
acc += `${key} *ARGS:\n ${value.replace(/npm run /g, "just ").replace(/ --$/, "")} "$@"\n`;
16+
acc += `${key} *ARGS:\n ${value.replace(/(npm run |yarn )/g, "just ").replace(/ --$/, "")} "$@"\n`;
1717
}
1818
fs.writeFileSync("justfile", acc);
1919
'
2020

2121
install:
22-
npm install
22+
yarn
2323

2424
# EVERYTHING BELOW THIS LINE IS AUTO-GENERATED FROM PACKAGE.JSON
2525
# DO NOT MODIFY BY HAND
@@ -28,14 +28,14 @@ install:
2828

2929
lint *ARGS:
3030
dprint check "$@"
31-
lint-fix *ARGS:
31+
fmt *ARGS:
3232
dprint fmt "$@"
3333
clean *ARGS:
34-
rimraf temp dist tsconfig.schema.json tsconfig.schemastore-schema.json tsconfig.tsbuildinfo tests/ts-node-packed.tgz tests/tmp "$@"
34+
rimraf temp dist tsconfig.schema.json tsconfig.schemastore-schema.json tsconfig.tsbuildinfo tests/ts-node-packed.tgz tests/node_modules tests/tmp "$@"
3535
rebuild *ARGS:
3636
just clean && just build "$@"
3737
build *ARGS:
38-
just build-nopack && just build-pack "$@"
38+
just build-nopack && just build-pack && just build-manifest "$@"
3939
build-nopack *ARGS:
4040
just build-tsc && just build-configSchema "$@"
4141
build-tsc *ARGS:
@@ -44,23 +44,23 @@ build-configSchema *ARGS:
4444
typescript-json-schema --topRef --refs --validationKeywords allOf --out tsconfig.schema.json tsconfig.build-schema.json TsConfigSchema && node --require ./register ./scripts/create-merged-schema "$@"
4545
build-pack *ARGS:
4646
node ./scripts/build-pack.js "$@"
47+
build-manifest *ARGS:
48+
node ./scripts/build-manifest.mjs "$@"
4749
test-spec *ARGS:
4850
ava "$@"
4951
test-cov *ARGS:
5052
nyc ava "$@"
5153
test *ARGS:
5254
just build && just lint && just test-cov "$@"
5355
test-local *ARGS:
54-
just lint-fix && just build-tsc && just build-pack && just test-spec "$@"
56+
just fmt && just build-tsc && just build-pack && just test-spec "$@"
5557
pre-debug *ARGS:
5658
just build-tsc && just build-pack "$@"
5759
coverage-report *ARGS:
5860
nyc report --reporter=lcov "$@"
59-
prepare *ARGS:
61+
__prepare_template__ *ARGS:
6062
just clean && just build-nopack "$@"
63+
prepare *ARGS:
64+
rimraf temp dist tsconfig.schema.json tsconfig.schemastore-schema.json tsconfig.tsbuildinfo tests/ts-node-packed.tgz tests/node_modules tests/tmp && tsc -b ./tsconfig.build-dist.json && typescript-json-schema --topRef --refs --validationKeywords allOf --out tsconfig.schema.json tsconfig.build-schema.json TsConfigSchema && node --require ./register ./scripts/create-merged-schema "$@"
6165
api-extractor *ARGS:
6266
api-extractor run --local --verbose "$@"
63-
esm-usage-example *ARGS:
64-
just build-tsc && cd esm-usage-example && node --experimental-specifier-resolution node --loader ../esm.mjs ./index "$@"
65-
esm-usage-example2 *ARGS:
66-
just build-tsc && cd tests && TS_NODE_PROJECT=./module-types/override-to-cjs/tsconfig.json node --loader ../esm.mjs ./module-types/override-to-cjs/test.cjs "$@"

0 commit comments

Comments
 (0)