GeezerVison is showing github.com — module: simplify ts under node_modules check · nodejs/node@0794861
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js +1-11Lines changed: 1 addition & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -125,10 +125,10 @@ const { pathToFileURL, fileURLToPath, isURL } = require('internal/url'); | 125 | 125 | const { | 126 | 126 | pendingDeprecate, | 127 | 127 | emitExperimentalWarning, | 128 | | - isUnderNodeModules, | 129 | 128 | kEmptyObject, | 130 | 129 | setOwnProperty, | 131 | 130 | getLazy, | | 131 | + isUnderNodeModules, | 132 | 132 | isWindows, | 133 | 133 | } = require('internal/util'); | 134 | 134 | const { | @@ -170,7 +170,6 @@ const { | 170 | 170 | ERR_REQUIRE_CYCLE_MODULE, | 171 | 171 | ERR_REQUIRE_ESM, | 172 | 172 | ERR_UNKNOWN_BUILTIN_MODULE, | 173 | | - ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING, | 174 | 173 | }, | 175 | 174 | setArrowMessage, | 176 | 175 | } = require('internal/errors'); | @@ -1348,9 +1347,6 @@ let emittedRequireModuleWarning = false; | 1348 | 1347 | function loadESMFromCJS(mod, filename) { | 1349 | 1348 | let source = getMaybeCachedSource(mod, filename); | 1350 | 1349 | if (getOptionValue('--experimental-strip-types') && path.extname(filename) === '.mts') { | 1351 | | - if (isUnderNodeModules(filename)) { | 1352 | | - throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename); | 1353 | | - } | 1354 | 1350 | source = stripTypeScriptTypes(source, filename); | 1355 | 1351 | } | 1356 | 1352 | const cascadedLoader = require('internal/modules/esm/loader').getOrInitializeCascadedLoader(); | @@ -1587,9 +1583,6 @@ function getMaybeCachedSource(mod, filename) { | 1587 | 1583 | } | 1588 | 1584 |
| 1589 | 1585 | function loadCTS(module, filename) { | 1590 | | - if (isUnderNodeModules(filename)) { | 1591 | | - throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename); | 1592 | | - } | 1593 | 1586 | const source = getMaybeCachedSource(module, filename); | 1594 | 1587 | const code = stripTypeScriptTypes(source, filename); | 1595 | 1588 | module._compile(code, filename, 'commonjs'); | @@ -1601,9 +1594,6 @@ function loadCTS(module, filename) { | 1601 | 1594 | * @param {string} filename The file path of the module | 1602 | 1595 | */ | 1603 | 1596 | function loadTS(module, filename) { | 1604 | | - if (isUnderNodeModules(filename)) { | 1605 | | - throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename); | 1606 | | - } | 1607 | 1597 | // If already analyzed the source, then it will be cached. | 1608 | 1598 | const source = getMaybeCachedSource(module, filename); | 1609 | 1599 | const content = stripTypeScriptTypes(source, filename); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/load.js -8Lines changed: 0 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | RegExpPrototypeExec, | 5 | 5 | } = primordials; | 6 | 6 | const { | 7 | | - isUnderNodeModules, | 8 | 7 | kEmptyObject, | 9 | 8 | } = require('internal/util'); | 10 | 9 |
| @@ -23,7 +22,6 @@ const { | 23 | 22 | ERR_INVALID_URL, | 24 | 23 | ERR_UNKNOWN_MODULE_FORMAT, | 25 | 24 | ERR_UNSUPPORTED_ESM_URL_SCHEME, | 26 | | - ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING, | 27 | 25 | } = require('internal/errors').codes; | 28 | 26 |
| 29 | 27 | const { | @@ -131,12 +129,6 @@ async function defaultLoad(url, context = kEmptyObject) { | 131 | 129 |
| 132 | 130 | validateAttributes(url, format, importAttributes); | 133 | 131 |
| 134 | | - if (getOptionValue('--experimental-strip-types') && | 135 | | - (format === 'module-typescript' || format === 'commonjs-typescript') && | 136 | | - isUnderNodeModules(url)) { | 137 | | - throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(url); | 138 | | - } | 139 | | - | 140 | 132 | return { | 141 | 133 | __proto__: null, | 142 | 134 | format, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/helpers.js +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ const { | 16 | 16 | ERR_INVALID_ARG_TYPE, | 17 | 17 | ERR_INVALID_RETURN_PROPERTY_VALUE, | 18 | 18 | ERR_INVALID_TYPESCRIPT_SYNTAX, | | 19 | + ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING, | 19 | 20 | } = require('internal/errors').codes; | 20 | 21 | const { BuiltinModule } = require('internal/bootstrap/realm'); | 21 | 22 |
| @@ -28,7 +29,7 @@ const assert = require('internal/assert'); | 28 | 29 |
| 29 | 30 | const { Buffer } = require('buffer'); | 30 | 31 | const { getOptionValue } = require('internal/options'); | 31 | | -const { assertTypeScript, setOwnProperty, getLazy } = require('internal/util'); | | 32 | +const { assertTypeScript, setOwnProperty, getLazy, isUnderNodeModules } = require('internal/util'); | 32 | 33 | const { inspect } = require('internal/util/inspect'); | 33 | 34 |
| 34 | 35 | const lazyTmpdir = getLazy(() => require('os').tmpdir()); | @@ -358,6 +359,9 @@ function parseTypeScript(source, options) { | 358 | 359 | * @returns {TransformOutput} The stripped TypeScript code. | 359 | 360 | */ | 360 | 361 | function stripTypeScriptTypes(source, filename) { | | 362 | + if (isUnderNodeModules(filename)) { | | 363 | + throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename); | | 364 | + } | 361 | 365 | assert(typeof source === 'string'); | 362 | 366 | const options = { | 363 | 367 | __proto__: null, | |
|