react-server-dom-webpack 0.0.1 → 18.3.0-next-d925a8d0b-20221024

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.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license React
3
+ * react-server-dom-webpack-client.production.min.js
4
+ *
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';var h=require("react"),k={stream:!0};function m(a,b){return a?(a=a[b.id][b.name],b.async?{id:a.id,chunks:a.chunks,name:a.name,async:!0}:a):b}var n=new Map,p=new Map;function q(){}
11
+ function r(a){for(var b=a.chunks,c=[],d=0;d<b.length;d++){var e=b[d],f=n.get(e);if(void 0===f){f=__webpack_chunk_load__(e);c.push(f);var l=n.set.bind(n,e,null);f.then(l,q);n.set(e,f)}else null!==f&&c.push(f)}if(a.async){if(b=p.get(a.id))return"fulfilled"===b.status?null:b;var g=Promise.all(c).then(function(){return __webpack_require__(a.id)});g.then(function(a){g.status="fulfilled";g.value=a},function(a){g.status="rejected";g.reason=a});p.set(a.id,g);return g}return 0<c.length?Promise.all(c):null}
12
+ var t=Symbol.for("react.element"),u=Symbol.for("react.lazy"),v=Symbol.for("react.default_value"),w=h.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ContextRegistry;function x(a){w[a]||(w[a]=h.createServerContext(a,v));return w[a]}function y(a,b,c,d){this.status=a;this.value=b;this.reason=c;this._response=d}y.prototype=Object.create(Promise.prototype);
13
+ y.prototype.then=function(a,b){switch(this.status){case "resolved_model":z(this);break;case "resolved_module":B(this)}switch(this.status){case "fulfilled":a(this.value);break;case "pending":case "blocked":a&&(null===this.value&&(this.value=[]),this.value.push(a));b&&(null===this.reason&&(this.reason=[]),this.reason.push(b));break;default:b(this.reason)}};
14
+ function C(a){switch(a.status){case "resolved_model":z(a);break;case "resolved_module":B(a)}switch(a.status){case "fulfilled":return a.value;case "pending":case "blocked":throw a;default:throw a.reason;}}function D(a,b){return new y("fulfilled",b,null,a)}function E(a,b){for(var c=0;c<a.length;c++)(0,a[c])(b)}function F(a,b,c){switch(a.status){case "fulfilled":E(b,a.value);break;case "pending":case "blocked":a.value=b;a.reason=c;break;case "rejected":c&&E(c,a.reason)}}
15
+ function G(a,b){if("pending"===a.status||"blocked"===a.status){var c=a.reason;a.status="rejected";a.reason=b;null!==c&&E(c,b)}}function H(a,b){if("pending"===a.status||"blocked"===a.status){var c=a.value,d=a.reason;a.status="resolved_module";a.value=b;null!==c&&(B(a),F(a,c,d))}}var I=null,J=null;
16
+ function z(a){var b=I,c=J;I=a;J=null;try{var d=JSON.parse(a.value,a._response._fromJSON);null!==J&&0<J.deps?(J.value=d,a.status="blocked",a.value=null,a.reason=null):(a.status="fulfilled",a.value=d)}catch(e){a.status="rejected",a.reason=e}finally{I=b,J=c}}
17
+ function B(a){try{var b=a.value;if(b.async){var c=p.get(b.id);if("fulfilled"===c.status)var d=c.value;else throw c.reason;}else d=__webpack_require__(b.id);var e="*"===b.name?d:""===b.name?d.__esModule?d.default:d:d[b.name];a.status="fulfilled";a.value=e}catch(f){a.status="rejected",a.reason=f}}function K(a,b){a._chunks.forEach(function(a){"pending"===a.status&&G(a,b)})}function L(a,b){var c=a._chunks,d=c.get(b);d||(d=new y("pending",null,null,a),c.set(b,d));return d}
18
+ function N(a,b,c){if(J){var d=J;d.deps++}else d=J={deps:1,value:null};return function(e){b[c]=e;d.deps--;0===d.deps&&"blocked"===a.status&&(e=a.value,a.status="fulfilled",a.value=d.value,null!==e&&E(e,d.value))}}function O(a){return function(b){return G(a,b)}}
19
+ function P(a,b,c,d){switch(d[0]){case "$":if("$"===d)return t;if("$"===d[1]||"@"===d[1])return d.substring(1);d=parseInt(d.substring(1),16);a=L(a,d);switch(a.status){case "resolved_model":z(a);break;case "resolved_module":B(a)}switch(a.status){case "fulfilled":return a.value;case "pending":case "blocked":return d=I,a.then(N(d,b,c),O(d)),null;default:throw a.reason;}case "@":return b=parseInt(d.substring(1),16),b=L(a,b),{$$typeof:u,_payload:b,_init:C}}return d}
20
+ function Q(a,b,c){var d=a._chunks,e=d.get(b);c=JSON.parse(c,a._fromJSON);var f=m(a._bundlerConfig,c);if(c=r(f)){if(e){var l=e;l.status="blocked"}else l=new y("blocked",null,null,a),d.set(b,l);c.then(function(){return H(l,f)},function(a){return G(l,a)})}else e?H(e,f):d.set(b,new y("resolved_module",f,null,a))}function R(a){K(a,Error("Connection closed."))}
21
+ function S(a,b){if(""!==b){var c=b[0],d=b.indexOf(":",1),e=parseInt(b.substring(1,d),16);b=b.substring(d+1);switch(c){case "J":d=a._chunks;(c=d.get(e))?"pending"===c.status&&(a=c.value,e=c.reason,c.status="resolved_model",c.value=b,null!==a&&(z(c),F(c,a,e))):d.set(e,new y("resolved_model",b,null,a));break;case "M":Q(a,e,b);break;case "P":a._chunks.set(e,D(a,x(b).Provider));break;case "S":b=JSON.parse(b);a._chunks.set(e,D(a,Symbol.for(b)));break;case "E":c=JSON.parse(b).digest;b=Error("An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.");
22
+ b.stack="Error: "+b.message;b.digest=c;c=a._chunks;(d=c.get(e))?G(d,b):c.set(e,new y("rejected",null,b,a));break;default:throw Error("Error parsing the data. It's probably an error code or network corruption.");}}}function T(a){return function(b,c){return"string"===typeof c?P(a,this,b,c):"object"===typeof c&&null!==c?(b=c[0]===t?{$$typeof:t,type:c[1],key:c[2],ref:null,props:c[3],_owner:null}:c,b):c}}
23
+ function U(a){var b=new TextDecoder,c=new Map;a={_bundlerConfig:a,_chunks:c,_partialRow:"",_stringDecoder:b};a._fromJSON=T(a);return a}function V(a,b){function c(b){var f=b.value;if(b.done)R(a);else{b=f;f=a._stringDecoder;for(var g=b.indexOf(10);-1<g;){var M=a._partialRow;var A=b.subarray(0,g);A=f.decode(A);S(a,M+A);a._partialRow="";b=b.subarray(g+1);g=b.indexOf(10)}a._partialRow+=f.decode(b,k);return e.read().then(c).catch(d)}}function d(b){K(a,b)}var e=b.getReader();e.read().then(c).catch(d)}
24
+ exports.createFromFetch=function(a,b){var c=U(b&&b.moduleMap?b.moduleMap:null);a.then(function(a){V(c,a.body)},function(a){K(c,a)});return L(c,0)};exports.createFromReadableStream=function(a,b){b=U(b&&b.moduleMap?b.moduleMap:null);V(b,a);return L(b,0)};
25
+ exports.createFromXHR=function(a,b){function c(){for(var b=a.responseText,c=f,d=b.indexOf("\n",c);-1<d;)c=e._partialRow+b.substring(c,d),S(e,c),e._partialRow="",c=d+1,d=b.indexOf("\n",c);e._partialRow+=b.substring(c);f=b.length}function d(){K(e,new TypeError("Network error"))}var e=U(b&&b.moduleMap?b.moduleMap:null),f=0;a.addEventListener("progress",c);a.addEventListener("load",function(){c();R(e)});a.addEventListener("error",d);a.addEventListener("abort",d);a.addEventListener("timeout",d);return L(e,
26
+ 0)};
@@ -0,0 +1,143 @@
1
+ /**
2
+ * @license React
3
+ * react-server-dom-webpack-node-register.js
4
+ *
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ 'use strict';
14
+
15
+ var url = require('url');
16
+
17
+ var Module = require('module');
18
+
19
+ module.exports = function register() {
20
+ var MODULE_REFERENCE = Symbol.for('react.module.reference');
21
+ var PROMISE_PROTOTYPE = Promise.prototype;
22
+ var proxyHandlers = {
23
+ get: function (target, name, receiver) {
24
+ switch (name) {
25
+ // These names are read by the Flight runtime if you end up using the exports object.
26
+ case '$$typeof':
27
+ // These names are a little too common. We should probably have a way to
28
+ // have the Flight runtime extract the inner target instead.
29
+ return target.$$typeof;
30
+
31
+ case 'filepath':
32
+ return target.filepath;
33
+
34
+ case 'name':
35
+ return target.name;
36
+
37
+ case 'async':
38
+ return target.async;
39
+ // We need to special case this because createElement reads it if we pass this
40
+ // reference.
41
+
42
+ case 'defaultProps':
43
+ return undefined;
44
+
45
+ case '__esModule':
46
+ // Something is conditionally checking which export to use. We'll pretend to be
47
+ // an ESM compat module but then we'll check again on the client.
48
+ target.default = {
49
+ $$typeof: MODULE_REFERENCE,
50
+ filepath: target.filepath,
51
+ // This a placeholder value that tells the client to conditionally use the
52
+ // whole object or just the default export.
53
+ name: '',
54
+ async: target.async
55
+ };
56
+ return true;
57
+
58
+ case 'then':
59
+ if (!target.async) {
60
+ // If this module is expected to return a Promise (such as an AsyncModule) then
61
+ // we should resolve that with a client reference that unwraps the Promise on
62
+ // the client.
63
+ var then = function then(resolve, reject) {
64
+ var moduleReference = {
65
+ $$typeof: MODULE_REFERENCE,
66
+ filepath: target.filepath,
67
+ name: '*',
68
+ // Represents the whole object instead of a particular import.
69
+ async: true
70
+ };
71
+ return Promise.resolve( // $FlowFixMe[incompatible-call] found when upgrading Flow
72
+ resolve(new Proxy(moduleReference, proxyHandlers)));
73
+ }; // If this is not used as a Promise but is treated as a reference to a `.then`
74
+ // export then we should treat it as a reference to that name.
75
+
76
+
77
+ then.$$typeof = MODULE_REFERENCE;
78
+ then.filepath = target.filepath; // then.name is conveniently already "then" which is the export name we need.
79
+ // This will break if it's minified though.
80
+
81
+ return then;
82
+ }
83
+
84
+ }
85
+
86
+ var cachedReference = target[name];
87
+
88
+ if (!cachedReference) {
89
+ cachedReference = target[name] = {
90
+ $$typeof: MODULE_REFERENCE,
91
+ filepath: target.filepath,
92
+ name: name,
93
+ async: target.async
94
+ };
95
+ }
96
+
97
+ return cachedReference;
98
+ },
99
+ getPrototypeOf: function (target) {
100
+ // Pretend to be a Promise in case anyone asks.
101
+ return PROMISE_PROTOTYPE;
102
+ },
103
+ set: function () {
104
+ throw new Error('Cannot assign to a client module from a server module.');
105
+ }
106
+ }; // $FlowFixMe[prop-missing] found when upgrading Flow
107
+
108
+ Module._extensions['.client.js'] = function (module, path) {
109
+ var moduleId = url.pathToFileURL(path).href;
110
+ var moduleReference = {
111
+ $$typeof: MODULE_REFERENCE,
112
+ filepath: moduleId,
113
+ name: '*',
114
+ // Represents the whole object instead of a particular import.
115
+ async: false
116
+ }; // $FlowFixMe[incompatible-call] found when upgrading Flow
117
+
118
+ module.exports = new Proxy(moduleReference, proxyHandlers);
119
+ }; // $FlowFixMe[prop-missing] found when upgrading Flow
120
+
121
+
122
+ var originalResolveFilename = Module._resolveFilename; // $FlowFixMe[prop-missing] found when upgrading Flow
123
+
124
+ Module._resolveFilename = function (request, parent, isMain, options) {
125
+ var resolved = originalResolveFilename.apply(this, arguments);
126
+
127
+ if (resolved.endsWith('.server.js')) {
128
+ if (parent && parent.filename && !parent.filename.endsWith('.server.js')) {
129
+ var reason;
130
+
131
+ if (request.endsWith('.server.js')) {
132
+ reason = "\"" + request + "\"";
133
+ } else {
134
+ reason = "\"" + request + "\" (which expands to \"" + resolved + "\")";
135
+ }
136
+
137
+ throw new Error("Cannot import " + reason + " from \"" + parent.filename + "\". " + 'By react-server convention, .server.js files can only be imported from other .server.js files. ' + 'That way nobody accidentally sends these to the client by indirectly importing it.');
138
+ }
139
+ }
140
+
141
+ return resolved;
142
+ };
143
+ };
@@ -0,0 +1,255 @@
1
+ /**
2
+ * @license React
3
+ * react-server-dom-webpack-plugin.js
4
+ *
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ 'use strict';
14
+
15
+ var path = require('path');
16
+ var url = require('url');
17
+ var asyncLib = require('neo-async');
18
+ var ModuleDependency = require('webpack/lib/dependencies/ModuleDependency');
19
+ var NullDependency = require('webpack/lib/dependencies/NullDependency');
20
+ var Template = require('webpack/lib/Template');
21
+ var webpack = require('webpack');
22
+
23
+ var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
24
+
25
+ function isArray(a) {
26
+ return isArrayImpl(a);
27
+ }
28
+
29
+ class ClientReferenceDependency extends ModuleDependency {
30
+ constructor(request) {
31
+ super(request);
32
+ }
33
+
34
+ get type() {
35
+ return 'client-reference';
36
+ }
37
+
38
+ } // This is the module that will be used to anchor all client references to.
39
+ // I.e. it will have all the client files as async deps from this point on.
40
+ // We use the Flight client implementation because you can't get to these
41
+ // without the client runtime so it's the first time in the loading sequence
42
+ // you might want them.
43
+
44
+
45
+ var clientImportName = 'react-server-dom-webpack/client';
46
+
47
+ var clientFileName = require.resolve('../client');
48
+
49
+ var PLUGIN_NAME = 'React Server Plugin';
50
+ class ReactFlightWebpackPlugin {
51
+ constructor(options) {
52
+ if (!options || typeof options.isServer !== 'boolean') {
53
+ throw new Error(PLUGIN_NAME + ': You must specify the isServer option as a boolean.');
54
+ }
55
+
56
+ if (options.isServer) {
57
+ throw new Error('TODO: Implement the server compiler.');
58
+ }
59
+
60
+ if (!options.clientReferences) {
61
+ this.clientReferences = [{
62
+ directory: '.',
63
+ recursive: true,
64
+ include: /\.client\.(js|ts|jsx|tsx)$/
65
+ }];
66
+ } else if (typeof options.clientReferences === 'string' || !isArray(options.clientReferences)) {
67
+ this.clientReferences = [options.clientReferences];
68
+ } else {
69
+ // $FlowFixMe[incompatible-type] found when upgrading Flow
70
+ this.clientReferences = options.clientReferences;
71
+ }
72
+
73
+ if (typeof options.chunkName === 'string') {
74
+ this.chunkName = options.chunkName;
75
+
76
+ if (!/\[(index|request)\]/.test(this.chunkName)) {
77
+ this.chunkName += '[index]';
78
+ }
79
+ } else {
80
+ this.chunkName = 'client[index]';
81
+ }
82
+
83
+ this.manifestFilename = options.manifestFilename || 'react-client-manifest.json';
84
+ }
85
+
86
+ apply(compiler) {
87
+ var _this = this;
88
+
89
+ var resolvedClientReferences;
90
+ var clientFileNameFound = false; // Find all client files on the file system
91
+
92
+ compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, function (_ref, callback) {
93
+ var contextModuleFactory = _ref.contextModuleFactory;
94
+ var contextResolver = compiler.resolverFactory.get('context', {});
95
+
96
+ _this.resolveAllClientFiles(compiler.context, contextResolver, compiler.inputFileSystem, contextModuleFactory, function (err, resolvedClientRefs) {
97
+ if (err) {
98
+ callback(err);
99
+ return;
100
+ }
101
+
102
+ resolvedClientReferences = resolvedClientRefs;
103
+ callback();
104
+ });
105
+ });
106
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function (compilation, _ref2) {
107
+ var normalModuleFactory = _ref2.normalModuleFactory;
108
+ compilation.dependencyFactories.set(ClientReferenceDependency, normalModuleFactory);
109
+ compilation.dependencyTemplates.set(ClientReferenceDependency, new NullDependency.Template());
110
+
111
+ var handler = function (parser) {
112
+ // We need to add all client references as dependency of something in the graph so
113
+ // Webpack knows which entries need to know about the relevant chunks and include the
114
+ // map in their runtime. The things that actually resolves the dependency is the Flight
115
+ // client runtime. So we add them as a dependency of the Flight client runtime.
116
+ // Anything that imports the runtime will be made aware of these chunks.
117
+ parser.hooks.program.tap(PLUGIN_NAME, function () {
118
+ var module = parser.state.module;
119
+
120
+ if (module.resource !== clientFileName) {
121
+ return;
122
+ }
123
+
124
+ clientFileNameFound = true;
125
+
126
+ if (resolvedClientReferences) {
127
+ // $FlowFixMe[incompatible-use] found when upgrading Flow
128
+ for (var i = 0; i < resolvedClientReferences.length; i++) {
129
+ // $FlowFixMe[incompatible-use] found when upgrading Flow
130
+ var dep = resolvedClientReferences[i];
131
+
132
+ var chunkName = _this.chunkName.replace(/\[index\]/g, '' + i).replace(/\[request\]/g, Template.toPath(dep.userRequest));
133
+
134
+ var block = new webpack.AsyncDependenciesBlock({
135
+ name: chunkName
136
+ }, null, dep.request);
137
+ block.addDependency(dep);
138
+ module.addBlock(block);
139
+ }
140
+ }
141
+ });
142
+ };
143
+
144
+ normalModuleFactory.hooks.parser.for('javascript/auto').tap('HarmonyModulesPlugin', handler);
145
+ normalModuleFactory.hooks.parser.for('javascript/esm').tap('HarmonyModulesPlugin', handler);
146
+ normalModuleFactory.hooks.parser.for('javascript/dynamic').tap('HarmonyModulesPlugin', handler);
147
+ });
148
+ compiler.hooks.make.tap(PLUGIN_NAME, function (compilation) {
149
+ compilation.hooks.processAssets.tap({
150
+ name: PLUGIN_NAME,
151
+ stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
152
+ }, function () {
153
+ if (clientFileNameFound === false) {
154
+ compilation.warnings.push(new webpack.WebpackError("Client runtime at " + clientImportName + " was not found. React Server Components module map file " + _this.manifestFilename + " was not created."));
155
+ return;
156
+ }
157
+
158
+ var json = {};
159
+ compilation.chunkGroups.forEach(function (chunkGroup) {
160
+ var chunkIds = chunkGroup.chunks.map(function (c) {
161
+ return c.id;
162
+ });
163
+
164
+ function recordModule(id, module) {
165
+ // TODO: Hook into deps instead of the target module.
166
+ // That way we know by the type of dep whether to include.
167
+ // It also resolves conflicts when the same module is in multiple chunks.
168
+ if (!/\.client\.(js|ts)x?$/.test(module.resource)) {
169
+ return;
170
+ }
171
+
172
+ var moduleProvidedExports = compilation.moduleGraph.getExportsInfo(module).getProvidedExports();
173
+ var moduleExports = {};
174
+ ['', '*'].concat(Array.isArray(moduleProvidedExports) ? moduleProvidedExports : []).forEach(function (name) {
175
+ moduleExports[name] = {
176
+ id: id,
177
+ chunks: chunkIds,
178
+ name: name
179
+ };
180
+ });
181
+ var href = url.pathToFileURL(module.resource).href;
182
+
183
+ if (href !== undefined) {
184
+ json[href] = moduleExports;
185
+ }
186
+ }
187
+
188
+ chunkGroup.chunks.forEach(function (chunk) {
189
+ var chunkModules = compilation.chunkGraph.getChunkModulesIterable(chunk);
190
+ Array.from(chunkModules).forEach(function (module) {
191
+ var moduleId = compilation.chunkGraph.getModuleId(module);
192
+ recordModule(moduleId, module); // If this is a concatenation, register each child to the parent ID.
193
+
194
+ if (module.modules) {
195
+ module.modules.forEach(function (concatenatedMod) {
196
+ recordModule(moduleId, concatenatedMod);
197
+ });
198
+ }
199
+ });
200
+ });
201
+ });
202
+ var output = JSON.stringify(json, null, 2);
203
+ compilation.emitAsset(_this.manifestFilename, new webpack.sources.RawSource(output, false));
204
+ });
205
+ });
206
+ } // This attempts to replicate the dynamic file path resolution used for other wildcard
207
+ // resolution in Webpack is using.
208
+
209
+
210
+ resolveAllClientFiles(context, contextResolver, fs, contextModuleFactory, callback) {
211
+ asyncLib.map(this.clientReferences, function (clientReferencePath, cb) {
212
+ if (typeof clientReferencePath === 'string') {
213
+ cb(null, [new ClientReferenceDependency(clientReferencePath)]);
214
+ return;
215
+ }
216
+
217
+ var clientReferenceSearch = clientReferencePath;
218
+ contextResolver.resolve({}, context, clientReferencePath.directory, {}, function (err, resolvedDirectory) {
219
+ if (err) return cb(err);
220
+ var options = {
221
+ resource: resolvedDirectory,
222
+ resourceQuery: '',
223
+ recursive: clientReferenceSearch.recursive === undefined ? true : clientReferenceSearch.recursive,
224
+ regExp: clientReferenceSearch.include,
225
+ include: undefined,
226
+ exclude: clientReferenceSearch.exclude
227
+ };
228
+ contextModuleFactory.resolveDependencies(fs, options, function (err2, deps) {
229
+ if (err2) return cb(err2);
230
+ var clientRefDeps = deps.map(function (dep) {
231
+ // use userRequest instead of request. request always end with undefined which is wrong
232
+ var request = path.join(resolvedDirectory, dep.userRequest);
233
+ var clientRefDep = new ClientReferenceDependency(request);
234
+ clientRefDep.userRequest = dep.userRequest;
235
+ return clientRefDep;
236
+ });
237
+ cb(null, clientRefDeps);
238
+ });
239
+ });
240
+ }, function (err, result) {
241
+ if (err) return callback(err);
242
+ var flat = [];
243
+
244
+ for (var i = 0; i < result.length; i++) {
245
+ // $FlowFixMe[method-unbinding]
246
+ flat.push.apply(flat, result[i]);
247
+ }
248
+
249
+ callback(null, flat);
250
+ });
251
+ }
252
+
253
+ }
254
+
255
+ module.exports = ReactFlightWebpackPlugin;