diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 5ffccfbea..6735af97a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -40,7 +40,7 @@ jobs: matrix: os: [ubuntu, windows] # Don't forget to add all new flavors to this list! - flavor: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] + flavor: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] include: # Node 10 - flavor: 1 @@ -94,20 +94,27 @@ jobs: nodeFlag: 14 typescript: next typescriptFlag: next - # Node 15 + # Node 14.13.0 + # To test ESM builtin module resolution immediately before a node behavioral change: https://github.com/TypeStrong/ts-node/issues/1130 - flavor: 10 + node: 14.13.0 + nodeFlag: 14_13_0 + typescript: latest + typescriptFlag: latest + # Node 15 + - flavor: 11 node: 15 nodeFlag: 15 typescript: latest typescriptFlag: latest downgradeNpm: true - - flavor: 11 + - flavor: 12 node: 15 nodeFlag: 15 typescript: 2.7 typescriptFlag: 2_7 downgradeNpm: true - - flavor: 12 + - flavor: 13 node: 15 nodeFlag: 15 typescript: next diff --git a/dist-raw/node-esm-resolve-implementation.js b/dist-raw/node-esm-resolve-implementation.js index a3da2f9a0..ef9cd106e 100644 --- a/dist-raw/node-esm-resolve-implementation.js +++ b/dist-raw/node-esm-resolve-implementation.js @@ -4,6 +4,18 @@ // upstream changes and understand our modifications. 'use strict'; +const [nodeMajor, nodeMinor, nodePatch] = process.versions.node.split('.').map(s => parseInt(s, 10)) +// Test for 14.13.1 or higher +const builtinModuleProtocol = nodeMajor > 14 || ( + nodeMajor === 14 && ( + nodeMinor > 13 || ( + nodeMinor === 13 && nodePatch > 0 + ) + ) + ) + ? 'node:' + : 'nodejs:'; + const { ArrayIsArray, JSONParse, @@ -688,13 +700,13 @@ function defaultResolve(specifier, { parentURL } = {}, defaultResolveUnused) { }; } } catch {} - if (parsed && parsed.protocol === 'nodejs:') + if (parsed && parsed.protocol === builtinModuleProtocol) return { url: specifier }; if (parsed && parsed.protocol !== 'file:' && parsed.protocol !== 'data:') throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(); if (NativeModule.canBeRequiredByUsers(specifier)) { return { - url: 'nodejs:' + specifier + url: builtinModuleProtocol + specifier }; } if (parentURL && StringPrototypeStartsWith(parentURL, 'data:')) { diff --git a/tests/esm/index.ts b/tests/esm/index.ts index 3b955e28b..9f7091dcf 100644 --- a/tests/esm/index.ts +++ b/tests/esm/index.ts @@ -3,6 +3,10 @@ import {bar} from './bar.js' import {baz} from './baz.js' import {biff} from './biff.js' +// Test import builtin modules +import {readFileSync} from 'fs'; +if(typeof readFileSync !== 'function') throw new Error('failed to import builtin module') + if(typeof module !== 'undefined') throw new Error('module should not exist in ESM') console.log(`${foo} ${bar} ${baz} ${biff}`)