Skip to content

Commit 1a12d66

Browse files
authored
Suppress prepack in test workflow (#2014)
* Rename `test-local` to `test` Suppress `prepack` when building tarball for installation into fixture directory Update contributing.md * try e2es * turn off e2es; they worked
1 parent 590f873 commit 1a12d66

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

.github/workflows/e2e-git-installs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
# nightly
55
schedule:
66
- cron: '0 0 * * *'
7+
# To temporarily enable on your branch for verification
8+
# push: {}
79
concurrency:
810
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
911
permissions:

CONTRIBUTING.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ We use package.json scripts for building, testing, and linting. Read the script
1414
```
1515
yarn
1616
yarn build
17-
yarn test-local
17+
yarn test
1818
yarn fmt
1919
```
2020

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.
21+
`yarn prepack` / `pnpm prepack`/ `npm prepare` are maintained so that anyone can install `ts-node` from git, which is useful for testing experimental branches and unreleased features.
2222

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

2929
## Tests
3030

31-
Test cases are declared in `src/test/*.spec.ts`, and test fixtures live in `./tests`. They can be run with `yarn 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`.
3232

3333
To run a subset of tests:
3434

3535
```
3636
# Use ava's --match flag to match the name of a test or suite
3737
# https://github.com/avajs/ava/blob/main/docs/05-command-line.md
3838
# Don't forget the * wildcards
39-
yarn test-local --match '*esm loader*'
39+
yarn test --match '*esm loader*'
40+
41+
# Or pass a filename as it exists in the compiled output
42+
# To run the tests in ./src/test/diagnostics.spec.ts
43+
yarn test ./dist/test/diagnostics.spec.js
4044
```
4145

4246
Tests are run with AVA, but using a custom wrapper API to enable some TS-friendly features and grouped test suites.
@@ -83,7 +87,7 @@ By convention, if a macro function is meant to be imported and reused in multipl
8387

8488
Macros can also be declared to require a certain "context," thanks to the namespace types described in "Test Context" above.
8589

86-
See examples in `helpers.ts`.
90+
See examples in `helpers/*.ts`.
8791

8892
## Documentation
8993

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@
7070
"build-manifest": "node ./scripts/build-manifest.mjs",
7171
"test-spec": "ava",
7272
"test-cov": "nyc ava",
73-
"test": "yarn build && yarn lint && yarn test-cov",
74-
"test-local": "yarn fmt && yarn build-tsc && yarn build-pack && yarn test-spec",
73+
"test": "yarn fmt && yarn build-tsc && yarn build-pack && yarn test-spec",
74+
"test-full": "yarn build && yarn lint && yarn test-cov",
7575
"pre-debug": "yarn build-tsc && yarn build-pack",
7676
"coverage-report": "nyc report --reporter=lcov",
7777
"__prepack_template__": "yarn clean && yarn build-nopack",
78-
"prepack": "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",
78+
"prepack": "node ./scripts/prepack.mjs",
79+
"prepack-worker": "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",
7980
"prepare": "workaround-broken-npm-prepack-behavior prepack",
8081
"api-extractor": "api-extractor run --local --verbose"
8182
},

scripts/build-manifest.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ const manifestPath = resolve(fileURLToPath(import.meta.url), '../../package.json
88
const pkg = JSON.parse(readFileSync(manifestPath, 'utf8'));
99

1010
// Fully splat the "prepack" script so that it does not contain references to a package manager, neither `yarn` nor `npm`
11-
pkg.scripts.prepack = pkg.scripts.__prepack_template__;
12-
while (true) {
13-
let before = pkg.scripts.prepack;
14-
pkg.scripts.prepack = pkg.scripts.prepack.replace(/yarn (\S+)/g, ($0, $1) => pkg.scripts[$1]);
15-
if (pkg.scripts.prepack === before) break;
11+
let before;
12+
let prepack = pkg.scripts.__prepack_template__;
13+
while (before !== prepack) {
14+
before = prepack;
15+
prepack = prepack.replace(/yarn (\S+)/g, ($0, $1) => pkg.scripts[$1]);
1616
}
17+
pkg.scripts['prepack-worker'] = prepack;
1718

1819
writeFileSync(manifestPath, JSON.stringify(pkg, null, 2) + '\n');

scripts/build-pack.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ const { join } = require('path');
77
const rootDir = join(__dirname, '..');
88
const testDir = join(__dirname, '../tests');
99
const tarballPath = join(testDir, 'ts-node-packed.tgz');
10-
exec(`yarn pack --out "${tarballPath}"`, { cwd: rootDir }, (err, stdout) => {
10+
11+
const env = {
12+
...process.env,
13+
TS_NODE_SKIP_PREPACK: 'true',
14+
};
15+
16+
exec(`yarn pack --out "${tarballPath}"`, { cwd: rootDir, env }, (err, stdout) => {
1117
if (err) {
1218
console.error(err);
1319
process.exit(1);

scripts/prepack.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { spawnSync } from 'child_process';
2+
const { npm_node_execpath, npm_execpath } = process.env;
3+
import { readFileSync } from 'fs';
4+
5+
// prepack is executed by user's package manager when they install from git
6+
// So cannot assume yarn
7+
8+
if (process.env.TS_NODE_SKIP_PREPACK == null) {
9+
if (readFileSync(npm_execpath, 'utf8').match(/^#!.*sh/)) {
10+
spawnSync(npm_execpath, ['run', 'prepack-worker'], {
11+
stdio: 'inherit',
12+
});
13+
} else {
14+
spawnSync(npm_node_execpath, [npm_execpath, 'run', 'prepack-worker'], {
15+
stdio: 'inherit',
16+
});
17+
}
18+
}

0 commit comments

Comments
 (0)