Skip to content

Commit 047de66

Browse files
fixup! module: add --experimental-strip-private-modules
1 parent 2a983c1 commit 047de66

8 files changed

Lines changed: 37 additions & 4 deletions

File tree

β€Ždoc/api/packages.mdβ€Ž

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,9 +1371,12 @@ By default, Node.js refuses to strip types from TypeScript files inside
13711371
`node_modules`. When [`--experimental-strip-private-modules`][] is enabled,
13721372
Node.js allows type stripping for:
13731373

1374-
* files that are not descendant of a `node_modules` directory.
1375-
* files that are descendant of a directory whose parent is a `node_modules` directory
1376-
and that contains a `package.json` file that sets `"private": true`.
1374+
* files that are not inside a `node_modules` directory.
1375+
* files inside `node_modules`, but only when the package that contains the
1376+
file sets `"private": true`. Only the `package.json` at each package boundary
1377+
is considered: the package's root directory, which is the directory directly
1378+
under `node_modules` (or under `node_modules/<@scope>` for scoped packages).
1379+
Nested `package.json` files are ignored.
13771380

13781381
[CommonJS]: modules.md
13791382
[Conditional exports]: #conditional-exports

β€Žtest/es-module/test-typescript.mjsβ€Ž

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ test('execute a TypeScript file from a private package in node_modules', async (
7373
assert.strictEqual(result.code, 0);
7474
});
7575

76+
test('execute a TypeScript file from a private package with a non-private nested package.json',
77+
async () => {
78+
const result = await spawnPromisified(process.execPath, [
79+
'--experimental-strip-private-modules',
80+
'--no-warnings',
81+
fixtures.path('typescript/ts/test-typescript-nested-nonprivate-node-modules.ts'),
82+
]);
83+
84+
assert.strictEqual(result.stderr, '');
85+
assert.match(result.stdout, /Hello, TypeScript!/);
86+
assert.strictEqual(result.code, 0);
87+
});
88+
7689
test('emit an experimental warning when stripping types in a private node_modules package',
7790
async () => {
7891
const result = await spawnPromisified(process.execPath, [

β€Žtest/fixtures/typescript/ts/node_modules/nested-nonprivate-pkg/lib/index.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žtest/fixtures/typescript/ts/node_modules/nested-nonprivate-pkg/lib/package.jsonβ€Ž

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žtest/fixtures/typescript/ts/node_modules/nested-nonprivate-pkg/package.jsonβ€Ž

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žtest/fixtures/typescript/ts/node_modules/private-pkg/greeting.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žtest/fixtures/typescript/ts/node_modules/private-pkg/private-pkg.tsβ€Ž

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { baz } from 'nested-nonprivate-pkg';
2+
3+
console.log(baz);

0 commit comments

Comments
Β (0)