@@ -13,7 +13,7 @@ export default testSuite(({ describe }, nodePath: string) => {
13
13
} ) ,
14
14
} ) ;
15
15
16
- const pkgrollProcess = await pkgroll ( [ '--env.NODE_ENV=development' ] , {
16
+ const pkgrollProcess = await pkgroll ( [ '--env.NODE_ENV=development' , '--env.PROD=false' ] , {
17
17
cwd : fixture . path ,
18
18
nodePath,
19
19
} ) ;
@@ -25,5 +25,42 @@ export default testSuite(({ describe }, nodePath: string) => {
25
25
expect ( content ) . toMatch ( 'development' ) ;
26
26
expect ( content ) . not . toMatch ( 'production' ) ;
27
27
} ) ;
28
+
29
+ test ( 'dead code elimination via env in node_modules' , async ( ) => {
30
+ await using fixture = await createFixture ( {
31
+ 'package.json' : createPackageJson ( {
32
+ main : './dist/index.mjs' ,
33
+ } ) ,
34
+ 'src/index.mjs' : 'import "dep"' ,
35
+ 'node_modules/dep' : {
36
+ 'package.json' : createPackageJson ( {
37
+ main : 'index.js' ,
38
+ } ) ,
39
+ 'index.js' : `
40
+ if (
41
+ process.env.NODE_ENV === 'production'
42
+ || process.env['NODE_ENV'] === 'production'
43
+ || process.env['PROD'] === 'true'
44
+ ) {
45
+ console.log('production');
46
+ } else {
47
+ console.log('development');
48
+ }
49
+ ` ,
50
+ } ,
51
+ } ) ;
52
+
53
+ const pkgrollProcess = await pkgroll ( [ '--env.NODE_ENV=development' , '--env.PROD=false' ] , {
54
+ cwd : fixture . path ,
55
+ nodePath,
56
+ } ) ;
57
+
58
+ expect ( pkgrollProcess . exitCode ) . toBe ( 0 ) ;
59
+ expect ( pkgrollProcess . stderr ) . toBe ( '' ) ;
60
+
61
+ const content = await fixture . readFile ( 'dist/index.mjs' , 'utf8' ) ;
62
+ expect ( content ) . toMatch ( 'development' ) ;
63
+ expect ( content ) . not . toMatch ( 'production' ) ;
64
+ } ) ;
28
65
} ) ;
29
66
} ) ;
0 commit comments