Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Oct 10, 2021
1 parent e79e8e7 commit c34588e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,15 @@ export function create(rawOptions: CreateOptions = {}): Service {
});
}

/**
* True if require() hooks should interop with experimental ESM loader.
* Enabled explicitly via a flag since it is a breaking change.
*/
let experimentalEsmLoader = false;
function enableExperimentalEsmLoaderInterop() {
experimentalEsmLoader = true;
}

// Install source map support and read from memory cache.
installSourceMapSupport();
function installSourceMapSupport() {
Expand Down Expand Up @@ -1254,15 +1263,6 @@ export function create(rawOptions: CreateOptions = {}): Service {
});
}

/**
* True if require() hooks should interop with experimental ESM loader.
* Enabled explicitly via a flag since it is a breaking change.
*/
let experimentalEsmLoader = false;
function enableExperimentalEsmLoaderInterop() {
experimentalEsmLoader = true;
}

return {
[TS_NODE_SERVICE_BRAND]: true,
ts,
Expand Down
5 changes: 1 addition & 4 deletions src/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,7 @@ export function createRepl(options: CreateReplOptions = {}) {
!name.includes('/') &&
!['console', 'module', 'process'].includes(name)
)
.map(
(name) =>
`declare const ${name}: typeof import('${name}');declare import ${name} = require('${name}')`
)
.map((name) => `declare import ${name} = require('${name}')`)
.join(';')}\n`;
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const CMD_ESM_LOADER_WITHOUT_PROJECT = `node ${EXPERIMENTAL_MODULES_FLAG}
// `createRequire` does not exist on older node versions
export const testsDirRequire = createRequire(join(TEST_DIR, 'index.js'));

export const ts = testsDirRequire('typescript');

export const xfs = new NodeFS(fs);

/** Pass to `test.context()` to get access to the ts-node API under test */
Expand Down
2 changes: 1 addition & 1 deletion src/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as expect from 'expect';
import { join, resolve, sep as pathSep } from 'path';
import { tmpdir } from 'os';
import semver = require('semver');
import ts = require('typescript');
import { ts } from './helpers';
import { lstatSync, mkdtempSync } from 'fs';
import { npath } from '@yarnpkg/fslib';
import type _createRequire from 'create-require';
Expand Down
2 changes: 1 addition & 1 deletion src/test/repl/node-repl-tla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import type { Key } from 'readline';
import { Stream } from 'stream';
import semver = require('semver');
import ts = require('typescript');
import { ts } from '../helpers';
import type { ContextWithTsNodeUnderTest } from './helpers';

interface SharedObjects extends ContextWithTsNodeUnderTest {
Expand Down
4 changes: 2 additions & 2 deletions src/test/repl/repl.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts = require('typescript');
import { ts } from '../helpers';
import semver = require('semver');
import * as expect from 'expect';
import {
Expand Down Expand Up @@ -414,7 +414,7 @@ test.suite(

test.serial('REPL declares types for node built-ins within REPL', async (t) => {
const { stdout, stderr } = await t.context.executeInRepl(
`util.promisify(setTimeout)("should not be a string")
`util.promisify(setTimeout)("should not be a string" as string)
type Duplex = stream.Duplex
const s = stream
'done'`,
Expand Down

0 comments on commit c34588e

Please sign in to comment.