Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts-node-esm / --esm to spawn a child process; decouple config loading from create() #1655

Merged
merged 32 commits into from Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1e5e666
WIP
cspotcode Feb 22, 2022
a28a3be
Merge remote-tracking branch 'origin/main' into esm-child-process
cspotcode Feb 22, 2022
a35462b
lint-fix
cspotcode Feb 22, 2022
9ecd29c
Merge remote-tracking branch 'origin/main' into esm-child-process
cspotcode Feb 23, 2022
48f7e3f
WIP
cspotcode Feb 23, 2022
d042c15
Merge remote-tracking branch 'origin/main' into esm-child-process
cspotcode Feb 23, 2022
fbb496c
it works!
cspotcode Feb 24, 2022
2ab1af3
Update index.ts
cspotcode Feb 24, 2022
3ea54b6
Move `preferTsExts` from `RegisterOptions` to `CreateOptions`
cspotcode Feb 24, 2022
490078a
fix
cspotcode Feb 24, 2022
58a9e24
fix
cspotcode Feb 24, 2022
b1520d8
fix tests
cspotcode Feb 25, 2022
f654960
fix?
cspotcode Feb 25, 2022
fd7fb55
fix
cspotcode Feb 25, 2022
7074b1c
fix?
cspotcode Feb 25, 2022
e0a1e90
fix?
cspotcode Feb 25, 2022
6db4fac
fix!
cspotcode Feb 25, 2022
d02927f
fix
cspotcode Feb 25, 2022
ece1952
fix!!
cspotcode Feb 25, 2022
5cc5f42
fix
cspotcode Feb 25, 2022
2446c08
fix...
cspotcode Feb 25, 2022
5bbffd6
tweak test lib's suite delimiter to match ava's
cspotcode Feb 25, 2022
b652088
fix
cspotcode Feb 25, 2022
7fe0166
fix
cspotcode Feb 25, 2022
51186f9
Merge remote-tracking branch 'origin/main' into esm-child-process
cspotcode Mar 3, 2022
2ebc55c
docs, fixes
cspotcode Mar 4, 2022
7862f47
Merge remote-tracking branch 'origin/esm-child-process' into esm-chil…
cspotcode Mar 4, 2022
4cdf1a5
fix #1662 and add tests
cspotcode Mar 5, 2022
0b5a47b
lint-fix
cspotcode Mar 5, 2022
3f21c31
test cleanup, remove or cleanup version checks, skip failing tsconfig…
cspotcode Mar 5, 2022
611adc2
ensure tests are forced to install and use most recent ts-node tarbal…
cspotcode Mar 5, 2022
f1326e2
fix absence of fs method on old node
cspotcode Mar 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions ava.config.cjs
@@ -0,0 +1,40 @@
const expect = require('expect');
const { createRequire } = require('module');

module.exports = {
files: ['dist/test/**/*.spec.js'],
failWithoutAssertions: false,
environmentVariables: {
ts_node_install_lock: `id-${Math.floor(Math.random() * 10e9)}`,
// Force jest expect() errors to generate colorized strings, makes output more readable.
// Delete the env var within ava processes via `require` option below.
// This avoids passing it to spawned processes under test, which would negatively affect
// their behavior.
FORCE_COLOR: '3',
},
require: ['./src/test/remove-env-var-force-color.js'],
timeout: '300s',
concurrency: 1,
};

{
/*
* Tests *must* install and use our most recent ts-node tarball.
* We must prevent them from accidentally require-ing a different version of
* ts-node, from either node_modules or tests/node_modules
*/

const { existsSync } = require('fs');
const rimraf = require('rimraf');
const { resolve } = require('path');

remove(resolve(__dirname, 'node_modules/ts-node'));
remove(resolve(__dirname, 'tests/node_modules/ts-node'));

// Prove that we did it correctly
expect(() => {createRequire(resolve(__dirname, 'tests/foo.js')).resolve('ts-node')}).toThrow();

function remove(p) {
if(existsSync(p)) rimraf.sync(p, {recursive: true})
}
}
14 changes: 0 additions & 14 deletions ava.config.js

This file was deleted.

7 changes: 7 additions & 0 deletions child-loader.mjs
@@ -0,0 +1,7 @@
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
const require = createRequire(fileURLToPath(import.meta.url));

/** @type {import('./dist/child-loader')} */
const childLoader = require('./dist/child/child-loader');
export const { resolve, load, getFormat, transformSource } = childLoader;
1 change: 0 additions & 1 deletion dist-raw/node-primordials.js
@@ -1,7 +1,6 @@
module.exports = {
ArrayFrom: Array.from,
ArrayIsArray: Array.isArray,
ArrayPrototypeJoin: (obj, separator) => Array.prototype.join.call(obj, separator),
ArrayPrototypeShift: (obj) => Array.prototype.shift.call(obj),
ArrayPrototypeForEach: (arr, ...rest) => Array.prototype.forEach.apply(arr, rest),
ArrayPrototypeIncludes: (arr, ...rest) => Array.prototype.includes.apply(arr, rest),
Expand Down
11 changes: 8 additions & 3 deletions package.json
Expand Up @@ -15,6 +15,8 @@
"./dist/bin-script.js": "./dist/bin-script.js",
"./dist/bin-cwd": "./dist/bin-cwd.js",
"./dist/bin-cwd.js": "./dist/bin-cwd.js",
"./dist/bin-esm": "./dist/bin-esm.js",
"./dist/bin-esm.js": "./dist/bin-esm.js",
"./register": "./register/index.js",
"./register/files": "./register/files.js",
"./register/transpile-only": "./register/transpile-only.js",
Expand All @@ -23,6 +25,7 @@
"./esm.mjs": "./esm.mjs",
"./esm/transpile-only": "./esm/transpile-only.mjs",
"./esm/transpile-only.mjs": "./esm/transpile-only.mjs",
"./child-loader.mjs": "./child-loader.mjs",
"./transpilers/swc": "./transpilers/swc.js",
"./transpilers/swc-experimental": "./transpilers/swc-experimental.js",
"./node10/tsconfig.json": "./node10/tsconfig.json",
Expand All @@ -33,10 +36,11 @@
"types": "dist/index.d.ts",
"bin": {
"ts-node": "dist/bin.js",
"ts-script": "dist/bin-script-deprecated.js",
"ts-node-script": "dist/bin-script.js",
"ts-node-cwd": "dist/bin-cwd.js",
"ts-node-transpile-only": "dist/bin-transpile.js"
"ts-node-esm": "dist/bin-esm.js",
"ts-node-script": "dist/bin-script.js",
"ts-node-transpile-only": "dist/bin-transpile.js",
"ts-script": "dist/bin-script-deprecated.js"
},
"files": [
"/transpilers/",
Expand All @@ -46,6 +50,7 @@
"/register/",
"/esm/",
"/esm.mjs",
"/child-loader.mjs",
"/LICENSE",
"/tsconfig.schema.json",
"/tsconfig.schemastore-schema.json",
Expand Down
5 changes: 5 additions & 0 deletions src/bin-esm.ts
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import { main } from './bin';

main(undefined, { '--esm': true });