@@ -17,6 +17,7 @@ import {
17
17
} from '@parcel/test-utils' ;
18
18
import { makeDeferredWithPromise , normalizePath } from '@parcel/utils' ;
19
19
import vm from 'vm' ;
20
+ import Logger from '@parcel/logger' ;
20
21
21
22
describe ( 'javascript' , function ( ) {
22
23
beforeEach ( async ( ) => {
@@ -2703,15 +2704,15 @@ describe('javascript', function() {
2703
2704
let b = await bundle (
2704
2705
path . join ( __dirname , '/integration/env-computed/index.js' ) ,
2705
2706
{
2706
- env : { name : 'abc' } ,
2707
+ env : { ABC : 'abc' } ,
2707
2708
} ,
2708
2709
) ;
2709
2710
2710
2711
let contents = await outputFS . readFile ( b . getBundles ( ) [ 0 ] . filePath , 'utf8' ) ;
2711
2712
assert ( contents . includes ( 'process.env' ) ) ;
2712
2713
2713
2714
let output = await run ( b ) ;
2714
- assert . strictEqual ( output , 'abc' ) ;
2715
+ assert . strictEqual ( output , undefined ) ;
2715
2716
} ) ;
2716
2717
2717
2718
it ( 'should inline computed accesses with string literals to process.env' , async function ( ) {
@@ -2807,6 +2808,210 @@ describe('javascript', function() {
2807
2808
assert . equal ( output , 'productiontest' ) ;
2808
2809
} ) ;
2809
2810
2811
+ it ( 'should error on process.env mutations' , async function ( ) {
2812
+ let filePath = path . join ( __dirname , '/integration/env-mutate/index.js' ) ;
2813
+ await assert . rejects ( bundle ( filePath ) , {
2814
+ diagnostics : [
2815
+ {
2816
+ origin : '@parcel/transformer-js' ,
2817
+ message : 'Mutating process.env is not supported' ,
2818
+ hints : null ,
2819
+ codeFrames : [
2820
+ {
2821
+ filePath,
2822
+ codeHighlights : [
2823
+ {
2824
+ message : null ,
2825
+ start : {
2826
+ line : 1 ,
2827
+ column : 1 ,
2828
+ } ,
2829
+ end : {
2830
+ line : 1 ,
2831
+ column : 29 ,
2832
+ } ,
2833
+ } ,
2834
+ ] ,
2835
+ } ,
2836
+ ] ,
2837
+ } ,
2838
+ {
2839
+ origin : '@parcel/transformer-js' ,
2840
+ message : 'Mutating process.env is not supported' ,
2841
+ hints : null ,
2842
+ codeFrames : [
2843
+ {
2844
+ filePath,
2845
+ codeHighlights : [
2846
+ {
2847
+ message : null ,
2848
+ start : {
2849
+ line : 2 ,
2850
+ column : 1 ,
2851
+ } ,
2852
+ end : {
2853
+ line : 2 ,
2854
+ column : 30 ,
2855
+ } ,
2856
+ } ,
2857
+ ] ,
2858
+ } ,
2859
+ ] ,
2860
+ } ,
2861
+ {
2862
+ origin : '@parcel/transformer-js' ,
2863
+ message : 'Mutating process.env is not supported' ,
2864
+ hints : null ,
2865
+ codeFrames : [
2866
+ {
2867
+ filePath,
2868
+ codeHighlights : [
2869
+ {
2870
+ message : null ,
2871
+ start : {
2872
+ line : 3 ,
2873
+ column : 1 ,
2874
+ } ,
2875
+ end : {
2876
+ line : 3 ,
2877
+ column : 28 ,
2878
+ } ,
2879
+ } ,
2880
+ ] ,
2881
+ } ,
2882
+ ] ,
2883
+ } ,
2884
+ {
2885
+ origin : '@parcel/transformer-js' ,
2886
+ message : 'Mutating process.env is not supported' ,
2887
+ hints : null ,
2888
+ codeFrames : [
2889
+ {
2890
+ filePath,
2891
+ codeHighlights : [
2892
+ {
2893
+ message : null ,
2894
+ start : {
2895
+ line : 4 ,
2896
+ column : 1 ,
2897
+ } ,
2898
+ end : {
2899
+ line : 4 ,
2900
+ column : 23 ,
2901
+ } ,
2902
+ } ,
2903
+ ] ,
2904
+ } ,
2905
+ ] ,
2906
+ } ,
2907
+ ] ,
2908
+ } ) ;
2909
+ } ) ;
2910
+
2911
+ it ( 'should warn on process.env mutations in node_modules' , async function ( ) {
2912
+ let logs = [ ] ;
2913
+ let disposable = Logger . onLog ( d => logs . push ( d ) ) ;
2914
+ let b = await bundle (
2915
+ path . join ( __dirname , '/integration/env-mutate/warn.js' ) ,
2916
+ ) ;
2917
+ disposable . dispose ( ) ;
2918
+
2919
+ assert . deepEqual ( logs , [
2920
+ {
2921
+ type : 'log' ,
2922
+ level : 'warn' ,
2923
+ diagnostics : [
2924
+ {
2925
+ origin : '@parcel/transformer-js' ,
2926
+ message : 'Mutating process.env is not supported' ,
2927
+ hints : null ,
2928
+ codeFrames : [
2929
+ {
2930
+ filePath : path . join (
2931
+ __dirname ,
2932
+ '/integration/env-mutate/node_modules/foo/index.js' ,
2933
+ ) ,
2934
+ codeHighlights : [
2935
+ {
2936
+ message : null ,
2937
+ start : {
2938
+ line : 1 ,
2939
+ column : 8 ,
2940
+ } ,
2941
+ end : {
2942
+ line : 1 ,
2943
+ column : 36 ,
2944
+ } ,
2945
+ } ,
2946
+ ] ,
2947
+ } ,
2948
+ ] ,
2949
+ } ,
2950
+ {
2951
+ origin : '@parcel/transformer-js' ,
2952
+ message : 'Mutating process.env is not supported' ,
2953
+ hints : null ,
2954
+ codeFrames : [
2955
+ {
2956
+ filePath : path . join (
2957
+ __dirname ,
2958
+ '/integration/env-mutate/node_modules/foo/index.js' ,
2959
+ ) ,
2960
+ codeHighlights : [
2961
+ {
2962
+ message : null ,
2963
+ start : {
2964
+ line : 2 ,
2965
+ column : 8 ,
2966
+ } ,
2967
+ end : {
2968
+ line : 2 ,
2969
+ column : 35 ,
2970
+ } ,
2971
+ } ,
2972
+ ] ,
2973
+ } ,
2974
+ ] ,
2975
+ } ,
2976
+ {
2977
+ origin : '@parcel/transformer-js' ,
2978
+ message : 'Mutating process.env is not supported' ,
2979
+ hints : null ,
2980
+ codeFrames : [
2981
+ {
2982
+ filePath : path . join (
2983
+ __dirname ,
2984
+ '/integration/env-mutate/node_modules/foo/index.js' ,
2985
+ ) ,
2986
+ codeHighlights : [
2987
+ {
2988
+ message : null ,
2989
+ start : {
2990
+ line : 3 ,
2991
+ column : 8 ,
2992
+ } ,
2993
+ end : {
2994
+ line : 3 ,
2995
+ column : 30 ,
2996
+ } ,
2997
+ } ,
2998
+ ] ,
2999
+ } ,
3000
+ ] ,
3001
+ } ,
3002
+ ] ,
3003
+ } ,
3004
+ ] ) ;
3005
+
3006
+ let output = [ ] ;
3007
+ await run ( b , {
3008
+ output ( o ) {
3009
+ output . push ( o ) ;
3010
+ } ,
3011
+ } ) ;
3012
+ assert . deepEqual ( output , [ 'foo' , true , undefined ] ) ;
3013
+ } ) ;
3014
+
2810
3015
it ( 'should replace process.browser for target browser' , async function ( ) {
2811
3016
let b = await bundle (
2812
3017
path . join ( __dirname , '/integration/process/index.js' ) ,
0 commit comments