@parcel/packager-react-static 2.15.2-canary.3460 → 2.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -88,6 +88,7 @@ let serverResolver;
88
88
  let packagingBundles = new Map();
89
89
  let moduleCache = new Map();
90
90
  let loadedBundles = new Map();
91
+ let context = _vm().default.createContext();
91
92
  var _default = exports.default = new (_plugin().Packager)({
92
93
  async loadConfig({
93
94
  options,
@@ -97,6 +98,7 @@ var _default = exports.default = new (_plugin().Packager)({
97
98
  packagingBundles.clear();
98
99
  moduleCache.clear();
99
100
  loadedBundles.clear();
101
+ context = createContext(options);
100
102
  clientResolver = new (_nodeResolverCore().ResolverBase)(options.projectRoot, {
101
103
  mode: 2,
102
104
  packageExports: true
@@ -120,21 +122,15 @@ var _default = exports.default = new (_plugin().Packager)({
120
122
  bundle,
121
123
  bundleGraph,
122
124
  getInlineBundleContents,
123
- config,
124
- options
125
+ config
125
126
  }) {
126
127
  if (bundle.env.shouldScopeHoist) {
127
128
  throw new Error('Scope hoisting is not supported with SSG');
128
129
  }
129
-
130
- // $FlowFixMe
131
- globalThis.AsyncLocalStorage ??= _nodeAsync_hooks().AsyncLocalStorage;
132
130
  let {
133
131
  load,
134
132
  loadModule
135
133
  } = await loadBundle(bundle, bundleGraph, getInlineBundleContents);
136
- let env = process.env.NODE_ENV;
137
- process.env.NODE_ENV = options.env.NODE_ENV;
138
134
  let Component = load((0, _nullthrows().default)(bundle.getMainEntry()).id).default;
139
135
  let {
140
136
  renderToReadableStream
@@ -146,7 +142,6 @@ var _default = exports.default = new (_plugin().Packager)({
146
142
  let {
147
143
  createFromReadableStream
148
144
  } = loadModule('react-server-dom-parcel/client.edge', __filename, 'react-client');
149
- process.env.NODE_ENV = env;
150
145
  let {
151
146
  injectRSCPayload
152
147
  } = await import('rsc-html-stream/server');
@@ -433,9 +428,36 @@ async function loadBundleUncached(bundle, bundleGraph, getInlineBundleContents)
433
428
  assets
434
429
  };
435
430
  }
431
+ function createContext(options) {
432
+ // Create a fresh global context to execute code in on each build to avoid memory leaks.
433
+ // $FlowFixMe
434
+ let context = _vm().default.createContext(_vm().default.constants.DONT_CONTEXTIFY);
435
+ context.global = context;
436
+ context.AsyncLocalStorage = _nodeAsync_hooks().AsyncLocalStorage;
437
+ context.process = new Proxy(process, {
438
+ get(target, prop, receiver) {
439
+ // Expose the provided environment variables from Parcel instead of the global ones.
440
+ if (prop === 'env') {
441
+ return options.env;
442
+ }
443
+ return Reflect.get(target, prop, receiver);
444
+ }
445
+ });
446
+
447
+ // $FlowFixMe
448
+ for (let key of Object.getOwnPropertyNames(globalThis)) {
449
+ if (!context.hasOwnProperty(key)) {
450
+ Object.defineProperty(context, key,
451
+ // $FlowFixMe
452
+ Object.getOwnPropertyDescriptor(globalThis, key));
453
+ }
454
+ }
455
+ return context;
456
+ }
436
457
  function runModule(code, filename, id, require, parcelRequire) {
437
458
  let moduleFunction = _vm().default.compileFunction(code, ['exports', 'require', 'module', '__dirname', '__filename', 'parcelRequire'], {
438
- filename
459
+ filename,
460
+ parsingContext: context
439
461
  });
440
462
  let dirname = _path().default.dirname(filename);
441
463
  let module = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/packager-react-static",
3
- "version": "2.15.2-canary.3460+5b71920db",
3
+ "version": "2.15.2",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,16 +17,16 @@
17
17
  "source": "src/ReactStaticPackager.js",
18
18
  "engines": {
19
19
  "node": ">= 16.0.0",
20
- "parcel": "^2.0.0-canary.1835+5b71920db"
20
+ "parcel": "^2.15.2"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/node-resolver-core": "3.6.2-canary.3460+5b71920db",
24
- "@parcel/plugin": "2.0.0-canary.1837+5b71920db",
25
- "@parcel/rust": "2.15.2-canary.3460+5b71920db",
26
- "@parcel/types": "2.0.0-canary.1837+5b71920db",
27
- "@parcel/utils": "2.0.0-canary.1837+5b71920db",
23
+ "@parcel/node-resolver-core": "3.6.2",
24
+ "@parcel/plugin": "2.15.2",
25
+ "@parcel/rust": "2.15.2",
26
+ "@parcel/types": "2.15.2",
27
+ "@parcel/utils": "2.15.2",
28
28
  "nullthrows": "^1.1.1",
29
29
  "rsc-html-stream": "^0.0.6"
30
30
  },
31
- "gitHead": "5b71920db7b10f9e0dbbf9beca70d3aee7acd3b9"
31
+ "gitHead": "b66f37168d0e830c030d0427bceac90117674cae"
32
32
  }
@@ -44,6 +44,7 @@ let serverResolver: ResolverBase;
44
44
  let packagingBundles = new Map<NamedBundle, Async<{|contents: Blob|}>>();
45
45
  let moduleCache = new Map<string, ParcelModule>();
46
46
  let loadedBundles = new Map<NamedBundle, any>();
47
+ let context: any = vm.createContext();
47
48
 
48
49
  export default (new Packager({
49
50
  async loadConfig({options, config}) {
@@ -51,6 +52,7 @@ export default (new Packager({
51
52
  packagingBundles.clear();
52
53
  moduleCache.clear();
53
54
  loadedBundles.clear();
55
+ context = createContext(options);
54
56
  clientResolver = new ResolverBase(options.projectRoot, {
55
57
  mode: 2,
56
58
  packageExports: true,
@@ -76,28 +78,17 @@ export default (new Packager({
76
78
  parcelRequireName: 'parcelRequire' + hashString(name).slice(-4),
77
79
  };
78
80
  },
79
- async package({
80
- bundle,
81
- bundleGraph,
82
- getInlineBundleContents,
83
- config,
84
- options,
85
- }) {
81
+ async package({bundle, bundleGraph, getInlineBundleContents, config}) {
86
82
  if (bundle.env.shouldScopeHoist) {
87
83
  throw new Error('Scope hoisting is not supported with SSG');
88
84
  }
89
85
 
90
- // $FlowFixMe
91
- globalThis.AsyncLocalStorage ??= AsyncLocalStorage;
92
-
93
86
  let {load, loadModule} = await loadBundle(
94
87
  bundle,
95
88
  bundleGraph,
96
89
  getInlineBundleContents,
97
90
  );
98
91
 
99
- let env = process.env.NODE_ENV;
100
- process.env.NODE_ENV = options.env.NODE_ENV;
101
92
  let Component = load(nullthrows(bundle.getMainEntry()).id).default;
102
93
  let {renderToReadableStream} = loadModule(
103
94
  'react-server-dom-parcel/server.edge',
@@ -115,7 +106,6 @@ export default (new Packager({
115
106
  __filename,
116
107
  'react-client',
117
108
  );
118
- process.env.NODE_ENV = env;
119
109
  let {injectRSCPayload} = await import('rsc-html-stream/server');
120
110
 
121
111
  let pages: Page[] = [];
@@ -474,6 +464,38 @@ async function loadBundleUncached(
474
464
  return {load: loadAsset, loadModule, assets};
475
465
  }
476
466
 
467
+ function createContext(options) {
468
+ // Create a fresh global context to execute code in on each build to avoid memory leaks.
469
+ // $FlowFixMe
470
+ let context: any = vm.createContext(vm.constants.DONT_CONTEXTIFY);
471
+ context.global = context;
472
+ context.AsyncLocalStorage = AsyncLocalStorage;
473
+ context.process = new Proxy(process, {
474
+ get(target, prop, receiver) {
475
+ // Expose the provided environment variables from Parcel instead of the global ones.
476
+ if (prop === 'env') {
477
+ return options.env;
478
+ }
479
+
480
+ return Reflect.get(target, prop, receiver);
481
+ },
482
+ });
483
+
484
+ // $FlowFixMe
485
+ for (let key of Object.getOwnPropertyNames(globalThis)) {
486
+ if (!context.hasOwnProperty(key)) {
487
+ Object.defineProperty(
488
+ context,
489
+ key,
490
+ // $FlowFixMe
491
+ Object.getOwnPropertyDescriptor(globalThis, key),
492
+ );
493
+ }
494
+ }
495
+
496
+ return context;
497
+ }
498
+
477
499
  function runModule(
478
500
  code: string,
479
501
  filename: string,
@@ -493,6 +515,7 @@ function runModule(
493
515
  ],
494
516
  {
495
517
  filename,
518
+ parsingContext: context,
496
519
  },
497
520
  );
498
521