Skip to content

Commit

Permalink
ts-node-esm / --esm to spawn a child process; decouple config loa…
Browse files Browse the repository at this point in the history
…ding from `create()`; fix pluggable dep resolution (#1655)

* WIP

* lint-fix

* WIP

* it works!

* Update index.ts

* Move `preferTsExts` from `RegisterOptions` to `CreateOptions`

* fix

* fix

* fix tests

* fix?

* fix

* fix?

* fix?

* fix!

* fix

* fix!!

* fix

* fix...

* tweak test lib's suite delimiter to match ava's

* fix

* fix

* docs, fixes

* fix #1662 and add tests

* lint-fix

* test cleanup, remove or cleanup version checks, skip failing tsconfig "extends" tests on TS 2.7

* ensure tests are forced to install and use most recent ts-node tarball and cannot accidentally use project-root nor outdated tarball

* fix absence of fs method on old node
  • Loading branch information
cspotcode committed Mar 5, 2022
1 parent f35a120 commit 0792067
Show file tree
Hide file tree
Showing 60 changed files with 1,139 additions and 231 deletions.
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 });

0 comments on commit 0792067

Please sign in to comment.