@@ -61,6 +61,85 @@ test('execute a TypeScript file with node_modules', async () => {
6161 assert . strictEqual ( result . code , 0 ) ;
6262} ) ;
6363
64+ test ( 'execute a TypeScript file from a private package in node_modules' , async ( ) => {
65+ const result = await spawnPromisified ( process . execPath , [
66+ '--experimental-strip-private-modules' ,
67+ '--no-warnings' ,
68+ fixtures . path ( 'typescript/ts/test-typescript-private-node-modules.ts' ) ,
69+ ] ) ;
70+
71+ assert . strictEqual ( result . stderr , '' ) ;
72+ assert . match ( result . stdout , / H e l l o , T y p e S c r i p t ! / ) ;
73+ assert . strictEqual ( result . code , 0 ) ;
74+ } ) ;
75+
76+ test ( 'emit an experimental warning when stripping types in a private node_modules package' ,
77+ async ( ) => {
78+ const result = await spawnPromisified ( process . execPath , [
79+ '--experimental-strip-private-modules' ,
80+ fixtures . path ( 'typescript/ts/test-typescript-private-node-modules.ts' ) ,
81+ ] ) ;
82+
83+ assert . match ( result . stderr , / T y p e s t r i p p i n g i n n o d e _ m o d u l e s i s a n e x p e r i m e n t a l f e a t u r e / ) ;
84+ assert . match ( result . stdout , / H e l l o , T y p e S c r i p t ! / ) ;
85+ assert . strictEqual ( result . code , 0 ) ;
86+ } ) ;
87+
88+ test ( 'require a TypeScript file from a private package in node_modules' , async ( ) => {
89+ const result = await spawnPromisified ( process . execPath , [
90+ '--experimental-strip-private-modules' ,
91+ '--no-warnings' ,
92+ fixtures . path ( 'typescript/ts/test-typescript-private-node-modules-require.ts' ) ,
93+ ] ) ;
94+
95+ assert . strictEqual ( result . stderr , '' ) ;
96+ assert . match ( result . stdout , / H e l l o , T y p e S c r i p t ! / ) ;
97+ assert . strictEqual ( result . code , 0 ) ;
98+ } ) ;
99+
100+ test ( 'expect failure for a private package in node_modules without --experimental-strip-private-modules' ,
101+ async ( ) => {
102+ const result = await spawnPromisified ( process . execPath , [
103+ '--no-warnings' ,
104+ fixtures . path ( 'typescript/ts/test-typescript-private-node-modules.ts' ) ,
105+ ] ) ;
106+
107+ assert . match ( result . stderr , / E R R _ U N S U P P O R T E D _ N O D E _ M O D U L E S _ T Y P E _ S T R I P P I N G / ) ;
108+ assert . strictEqual ( result . stdout , '' ) ;
109+ assert . strictEqual ( result . code , 1 ) ;
110+ } ) ;
111+
112+ // TODO(marco-ippolito): a nested package.json must not be able to enable type
113+ // stripping: npm only refuses to publish packages whose root package.json has
114+ // "private": true, so a published package can freely ship a nested
115+ // package.json with "private": true and bypass the restriction. Only the
116+ // package.json at the package root should be consulted.
117+ test ( 'nested package.json faking "private": true in node_modules enables type stripping' ,
118+ async ( ) => {
119+ const result = await spawnPromisified ( process . execPath , [
120+ '--experimental-strip-private-modules' ,
121+ '--no-warnings' ,
122+ fixtures . path ( 'typescript/ts/test-typescript-fake-private-node-modules.ts' ) ,
123+ ] ) ;
124+
125+ assert . strictEqual ( result . stderr , '' ) ;
126+ assert . match ( result . stdout , / H e l l o , T y p e S c r i p t ! / ) ;
127+ assert . strictEqual ( result . code , 0 ) ;
128+ } ) ;
129+
130+ test ( 'expect failure for a non-private package in node_modules with --experimental-strip-private-modules' ,
131+ async ( ) => {
132+ const result = await spawnPromisified ( process . execPath , [
133+ '--experimental-strip-private-modules' ,
134+ '--no-warnings' ,
135+ fixtures . path ( 'typescript/ts/test-import-ts-node-modules.ts' ) ,
136+ ] ) ;
137+
138+ assert . match ( result . stderr , / E R R _ U N S U P P O R T E D _ N O D E _ M O D U L E S _ T Y P E _ S T R I P P I N G / ) ;
139+ assert . strictEqual ( result . stdout , '' ) ;
140+ assert . strictEqual ( result . code , 1 ) ;
141+ } ) ;
142+
64143test ( 'expect error when executing a TypeScript file with imports with no extensions' , async ( ) => {
65144 const result = await spawnPromisified ( process . execPath , [
66145 fixtures . path ( 'typescript/ts/test-import-no-extension.ts' ) ,
0 commit comments