@parcel/packager-react-static 2.15.3-canary.3473 → 2.15.3

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.
@@ -118,11 +118,40 @@ var _default = exports.default = new (_plugin().Packager)({
118
118
  parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4)
119
119
  };
120
120
  },
121
+ loadBundleConfig({
122
+ bundle,
123
+ bundleGraph
124
+ }) {
125
+ let pages = [];
126
+ for (let b of bundleGraph.getEntryBundles()) {
127
+ let main = b.getMainEntry();
128
+ if (main && b.type === 'js' && b.needsStableName) {
129
+ let meta = pageMeta(main.meta);
130
+ pages.push({
131
+ url: (0, _utils().urlJoin)(b.target.publicUrl, b.name),
132
+ name: b.name,
133
+ ...meta
134
+ });
135
+ }
136
+ }
137
+ let referencedBundles = [];
138
+ for (let b of bundleGraph.getReferencedBundles(bundle, {
139
+ includeInline: false,
140
+ includeIsolated: false
141
+ })) {
142
+ referencedBundles.push(b.getContentHash());
143
+ }
144
+ return {
145
+ pages,
146
+ referencedBundles
147
+ };
148
+ },
121
149
  async package({
122
150
  bundle,
123
151
  bundleGraph,
124
152
  getInlineBundleContents,
125
- config
153
+ config,
154
+ bundleConfig
126
155
  }) {
127
156
  if (bundle.env.shouldScopeHoist) {
128
157
  throw new Error('Scope hoisting is not supported with SSG');
@@ -145,18 +174,7 @@ var _default = exports.default = new (_plugin().Packager)({
145
174
  let {
146
175
  injectRSCPayload
147
176
  } = await import('rsc-html-stream/server');
148
- let pages = [];
149
- for (let b of bundleGraph.getEntryBundles()) {
150
- let main = b.getMainEntry();
151
- if (main && b.type === 'js' && b.needsStableName) {
152
- let meta = pageMeta(main.meta);
153
- pages.push({
154
- url: (0, _utils().urlJoin)(b.target.publicUrl, b.name),
155
- name: b.name,
156
- ...meta
157
- });
158
- }
159
- }
177
+ let pages = bundleConfig.pages;
160
178
  let meta = pageMeta((0, _nullthrows().default)(bundle.getMainEntry()).meta);
161
179
  let props = {
162
180
  key: 'page',
@@ -216,7 +234,28 @@ var _default = exports.default = new (_plugin().Packager)({
216
234
  } = await prerender(React.createElement(Content), {
217
235
  bootstrapScriptContent
218
236
  });
219
- let response = prelude.pipeThrough(injectRSCPayload(injectStream));
237
+
238
+ // Buffer into a single chunk so hash reference replacement works correctly.
239
+ // There could potentially be a more optimal way of doing this in the future.
240
+ let buffers = [];
241
+ let len = 0;
242
+ // $FlowFixMe
243
+ let bufferedStream = new TransformStream({
244
+ transform(chunk) {
245
+ len += chunk.length;
246
+ buffers.push(chunk);
247
+ },
248
+ flush(controller) {
249
+ let concated = new Uint8Array(len);
250
+ let offset = 0;
251
+ for (let buf of buffers) {
252
+ concated.set(buf, offset);
253
+ offset += buf.length;
254
+ }
255
+ controller.enqueue(concated);
256
+ }
257
+ });
258
+ let response = prelude.pipeThrough(injectRSCPayload(injectStream.pipeThrough(bufferedStream)));
220
259
  return [{
221
260
  type: 'html',
222
261
  contents: _stream().Readable.from(response)
@@ -349,9 +388,13 @@ async function loadBundleUncached(bundle, bundleGraph, getInlineBundleContents)
349
388
  return loadAsset((0, _nullthrows().default)(assetsByPublicId.get(publicId)));
350
389
  };
351
390
  parcelRequire.root = parcelRequire;
391
+ let publicUrl = bundle.target.publicUrl;
392
+ if (!publicUrl.endsWith('/')) {
393
+ publicUrl += '/';
394
+ }
352
395
  parcelRequire.meta = {
353
396
  distDir: bundle.target.distDir,
354
- publicUrl: bundle.target.publicUrl
397
+ publicUrl
355
398
  };
356
399
  parcelRequire.load = async filePath => {
357
400
  let bundle = bundleGraph.getBundles().find(b => b.publicId === filePath || b.name === filePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/packager-react-static",
3
- "version": "2.15.3-canary.3473+a6945b6ed",
3
+ "version": "2.15.3",
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.1848+a6945b6ed"
20
+ "parcel": "^2.15.3"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/node-resolver-core": "3.6.3-canary.3473+a6945b6ed",
24
- "@parcel/plugin": "2.0.0-canary.1850+a6945b6ed",
25
- "@parcel/rust": "2.15.3-canary.3473+a6945b6ed",
26
- "@parcel/types": "2.0.0-canary.1850+a6945b6ed",
27
- "@parcel/utils": "2.0.0-canary.1850+a6945b6ed",
23
+ "@parcel/node-resolver-core": "3.6.3",
24
+ "@parcel/plugin": "2.15.3",
25
+ "@parcel/rust": "2.15.3",
26
+ "@parcel/types": "2.15.3",
27
+ "@parcel/utils": "2.15.3",
28
28
  "nullthrows": "^1.1.1",
29
29
  "rsc-html-stream": "^0.0.6"
30
30
  },
31
- "gitHead": "a6945b6ed6cb73c8dde72e9ebc7c25420fe84cdd"
31
+ "gitHead": "75aa6319c8037ecfbe3dab4ea9b35d10a9a696e3"
32
32
  }
@@ -78,7 +78,37 @@ export default (new Packager({
78
78
  parcelRequireName: 'parcelRequire' + hashString(name).slice(-4),
79
79
  };
80
80
  },
81
- async package({bundle, bundleGraph, getInlineBundleContents, config}) {
81
+ loadBundleConfig({bundle, bundleGraph}) {
82
+ let pages: Page[] = [];
83
+ for (let b of bundleGraph.getEntryBundles()) {
84
+ let main = b.getMainEntry();
85
+ if (main && b.type === 'js' && b.needsStableName) {
86
+ let meta = pageMeta(main.meta);
87
+ pages.push({
88
+ url: urlJoin(b.target.publicUrl, b.name),
89
+ name: b.name,
90
+ ...meta,
91
+ });
92
+ }
93
+ }
94
+
95
+ let referencedBundles = [];
96
+ for (let b of bundleGraph.getReferencedBundles(bundle, {
97
+ includeInline: false,
98
+ includeIsolated: false,
99
+ })) {
100
+ referencedBundles.push(b.getContentHash());
101
+ }
102
+
103
+ return {pages, referencedBundles};
104
+ },
105
+ async package({
106
+ bundle,
107
+ bundleGraph,
108
+ getInlineBundleContents,
109
+ config,
110
+ bundleConfig,
111
+ }) {
82
112
  if (bundle.env.shouldScopeHoist) {
83
113
  throw new Error('Scope hoisting is not supported with SSG');
84
114
  }
@@ -108,19 +138,7 @@ export default (new Packager({
108
138
  );
109
139
  let {injectRSCPayload} = await import('rsc-html-stream/server');
110
140
 
111
- let pages: Page[] = [];
112
- for (let b of bundleGraph.getEntryBundles()) {
113
- let main = b.getMainEntry();
114
- if (main && b.type === 'js' && b.needsStableName) {
115
- let meta = pageMeta(main.meta);
116
- pages.push({
117
- url: urlJoin(b.target.publicUrl, b.name),
118
- name: b.name,
119
- ...meta,
120
- });
121
- }
122
- }
123
-
141
+ let pages: Page[] = bundleConfig.pages;
124
142
  let meta = pageMeta(nullthrows(bundle.getMainEntry()).meta);
125
143
  let props: PageProps = {
126
144
  key: 'page',
@@ -197,7 +215,31 @@ export default (new Packager({
197
215
  let {prelude} = await prerender(React.createElement(Content), {
198
216
  bootstrapScriptContent,
199
217
  });
200
- let response = prelude.pipeThrough(injectRSCPayload(injectStream));
218
+
219
+ // Buffer into a single chunk so hash reference replacement works correctly.
220
+ // There could potentially be a more optimal way of doing this in the future.
221
+ let buffers = [];
222
+ let len = 0;
223
+ // $FlowFixMe
224
+ let bufferedStream = new TransformStream({
225
+ transform(chunk) {
226
+ len += chunk.length;
227
+ buffers.push(chunk);
228
+ },
229
+ flush(controller) {
230
+ let concated = new Uint8Array(len);
231
+ let offset = 0;
232
+ for (let buf of buffers) {
233
+ concated.set(buf, offset);
234
+ offset += buf.length;
235
+ }
236
+ controller.enqueue(concated);
237
+ },
238
+ });
239
+
240
+ let response = prelude.pipeThrough(
241
+ injectRSCPayload(injectStream.pipeThrough(bufferedStream)),
242
+ );
201
243
 
202
244
  return [
203
245
  {
@@ -374,9 +416,13 @@ async function loadBundleUncached(
374
416
 
375
417
  parcelRequire.root = parcelRequire;
376
418
 
419
+ let publicUrl = bundle.target.publicUrl;
420
+ if (!publicUrl.endsWith('/')) {
421
+ publicUrl += '/';
422
+ }
377
423
  parcelRequire.meta = {
378
424
  distDir: bundle.target.distDir,
379
- publicUrl: bundle.target.publicUrl,
425
+ publicUrl,
380
426
  };
381
427
 
382
428
  parcelRequire.load = async (filePath: string) => {