react-server-dom-webpack
Advanced tools
Comparing version 0.0.0-experimental-de516ca5a-20220321 to 0.0.0-experimental-de68d2f4-20241204
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -12,95 +12,60 @@ * This source code is licensed under the MIT license found in the | ||
'use strict'; | ||
'use strict'; | ||
var url = require('url'); // $FlowFixMe | ||
var Module = require('module'); | ||
module.exports = function register() { | ||
var MODULE_REFERENCE = Symbol.for('react.module.reference'); | ||
var proxyHandlers = { | ||
get: function (target, name, receiver) { | ||
switch (name) { | ||
// These names are read by the Flight runtime if you end up using the exports object. | ||
case '$$typeof': | ||
// These names are a little too common. We should probably have a way to | ||
// have the Flight runtime extract the inner target instead. | ||
return target.$$typeof; | ||
case 'filepath': | ||
return target.filepath; | ||
case 'name': | ||
return target.name; | ||
// We need to special case this because createElement reads it if we pass this | ||
// reference. | ||
case 'defaultProps': | ||
return undefined; | ||
case '__esModule': | ||
// Something is conditionally checking which export to use. We'll pretend to be | ||
// an ESM compat module but then we'll check again on the client. | ||
target.default = { | ||
$$typeof: MODULE_REFERENCE, | ||
filepath: target.filepath, | ||
// This a placeholder value that tells the client to conditionally use the | ||
// whole object or just the default export. | ||
name: '' | ||
}; | ||
return true; | ||
} | ||
var cachedReference = target[name]; | ||
if (!cachedReference) { | ||
cachedReference = target[name] = { | ||
$$typeof: MODULE_REFERENCE, | ||
filepath: target.filepath, | ||
name: name | ||
}; | ||
} | ||
return cachedReference; | ||
}, | ||
set: function () { | ||
throw new Error('Cannot assign to a client module from a server module.'); | ||
"use strict"; | ||
const acorn = require("acorn-loose"), | ||
url = require("url"), | ||
Module = require("module"); | ||
module.exports = function () { | ||
const Server = require("react-server-dom-webpack/server"), | ||
registerServerReference = Server.registerServerReference, | ||
createClientModuleProxy = Server.createClientModuleProxy, | ||
originalCompile = Module.prototype._compile; | ||
Module.prototype._compile = function (content, filename) { | ||
if ( | ||
-1 === content.indexOf("use client") && | ||
-1 === content.indexOf("use server") | ||
) | ||
return originalCompile.apply(this, arguments); | ||
try { | ||
var body = acorn.parse(content, { | ||
ecmaVersion: "2024", | ||
sourceType: "source" | ||
}).body; | ||
} catch (x) { | ||
return ( | ||
console.error("Error parsing %s %s", url, x.message), | ||
originalCompile.apply(this, arguments) | ||
); | ||
} | ||
}; | ||
require.extensions['.client.js'] = function (module, path) { | ||
var moduleId = url.pathToFileURL(path).href; | ||
var moduleReference = { | ||
$$typeof: MODULE_REFERENCE, | ||
filepath: moduleId, | ||
name: '*' // Represents the whole object instead of a particular import. | ||
}; | ||
module.exports = new Proxy(moduleReference, proxyHandlers); | ||
}; | ||
var originalResolveFilename = Module._resolveFilename; | ||
Module._resolveFilename = function (request, parent, isMain, options) { | ||
var resolved = originalResolveFilename.apply(this, arguments); | ||
if (resolved.endsWith('.server.js')) { | ||
if (parent && parent.filename && !parent.filename.endsWith('.server.js')) { | ||
var reason; | ||
if (request.endsWith('.server.js')) { | ||
reason = "\"" + request + "\""; | ||
} else { | ||
reason = "\"" + request + "\" (which expands to \"" + resolved + "\")"; | ||
var useClient = !1, | ||
useServer = !1; | ||
for (var i = 0; i < body.length; i++) { | ||
var node = body[i]; | ||
if ("ExpressionStatement" !== node.type || !node.directive) break; | ||
"use client" === node.directive && (useClient = !0); | ||
"use server" === node.directive && (useServer = !0); | ||
} | ||
if (!useClient && !useServer) return originalCompile.apply(this, arguments); | ||
if (useClient && useServer) | ||
throw Error( | ||
'Cannot have both "use client" and "use server" directives in the same file.' | ||
); | ||
useClient && | ||
((body = url.pathToFileURL(filename).href), | ||
(this.exports = createClientModuleProxy(body))); | ||
if (useServer) | ||
if ( | ||
(originalCompile.apply(this, arguments), | ||
(useServer = url.pathToFileURL(filename).href), | ||
(body = this.exports), | ||
"function" === typeof body) | ||
) | ||
registerServerReference(body, useServer, null); | ||
else | ||
for (useClient = Object.keys(body), i = 0; i < useClient.length; i++) { | ||
node = useClient[i]; | ||
const value = body[useClient[i]]; | ||
"function" === typeof value && | ||
registerServerReference(value, useServer, node); | ||
} | ||
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.'); | ||
} | ||
} | ||
return resolved; | ||
}; | ||
}; |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -12,20 +12,78 @@ * This source code is licensed under the MIT license found in the | ||
'use strict'; | ||
'use strict'; | ||
var path = require('path'); | ||
var url = require('url'); | ||
var asyncLib = require('neo-async'); | ||
var ModuleDependency = require('webpack/lib/dependencies/ModuleDependency'); | ||
var NullDependency = require('webpack/lib/dependencies/NullDependency'); | ||
var Template = require('webpack/lib/Template'); | ||
var webpack = require('webpack'); | ||
var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare | ||
function isArray(a) { | ||
return isArrayImpl(a); | ||
"use strict"; | ||
var path = require("path"), | ||
url = require("url"), | ||
asyncLib = require("neo-async"), | ||
acorn = require("acorn-loose"), | ||
ModuleDependency = require("webpack/lib/dependencies/ModuleDependency"), | ||
NullDependency = require("webpack/lib/dependencies/NullDependency"), | ||
Template = require("webpack/lib/Template"), | ||
webpack = require("webpack"); | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (o) { | ||
if ("string" === typeof o) return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
"Object" === n && o.constructor && (n = o.constructor.name); | ||
if ("Map" === n || "Set" === n) return Array.from(o); | ||
if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) | ||
return _arrayLikeToArray(o, minLen); | ||
} | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (null == len || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it; | ||
if ("undefined" === typeof Symbol || null == o[Symbol.iterator]) { | ||
if ( | ||
Array.isArray(o) || | ||
(it = _unsupportedIterableToArray(o)) || | ||
(allowArrayLike && o && "number" === typeof o.length) | ||
) { | ||
it && (o = it); | ||
var i = 0; | ||
allowArrayLike = function () {}; | ||
return { | ||
s: allowArrayLike, | ||
n: function () { | ||
return i >= o.length ? { done: !0 } : { done: !1, value: o[i++] }; | ||
}, | ||
e: function (e) { | ||
throw e; | ||
}, | ||
f: allowArrayLike | ||
}; | ||
} | ||
throw new TypeError( | ||
"Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method." | ||
); | ||
} | ||
var normalCompletion = !0, | ||
didErr = !1, | ||
err; | ||
return { | ||
s: function () { | ||
it = o[Symbol.iterator](); | ||
}, | ||
n: function () { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
}, | ||
e: function (e) { | ||
didErr = !0; | ||
err = e; | ||
}, | ||
f: function () { | ||
try { | ||
normalCompletion || null == it.return || it.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
} | ||
} | ||
}; | ||
} | ||
const isArrayImpl = Array.isArray; | ||
class ClientReferenceDependency extends ModuleDependency { | ||
@@ -35,220 +93,310 @@ constructor(request) { | ||
} | ||
get type() { | ||
return 'client-reference'; | ||
return "client-reference"; | ||
} | ||
} // This is the module that will be used to anchor all client references to. | ||
// I.e. it will have all the client files as async deps from this point on. | ||
// We use the Flight client implementation because you can't get to these | ||
// without the client runtime so it's the first time in the loading sequence | ||
// you might want them. | ||
var clientImportName = 'react-server-dom-webpack'; | ||
var clientFileName = require.resolve('../'); | ||
var PLUGIN_NAME = 'React Server Plugin'; | ||
} | ||
const clientFileName = require.resolve("../client.browser.js"); | ||
class ReactFlightWebpackPlugin { | ||
constructor(options) { | ||
if (!options || typeof options.isServer !== 'boolean') { | ||
throw new Error(PLUGIN_NAME + ': You must specify the isServer option as a boolean.'); | ||
} | ||
if (options.isServer) { | ||
throw new Error('TODO: Implement the server compiler.'); | ||
} | ||
if (!options.clientReferences) { | ||
this.clientReferences = [{ | ||
directory: '.', | ||
recursive: true, | ||
include: /\.client\.(js|ts|jsx|tsx)$/ | ||
}]; | ||
} else if (typeof options.clientReferences === 'string' || !isArray(options.clientReferences)) { | ||
this.clientReferences = [options.clientReferences]; | ||
} else { | ||
this.clientReferences = options.clientReferences; | ||
} | ||
if (typeof options.chunkName === 'string') { | ||
this.chunkName = options.chunkName; | ||
if (!/\[(index|request)\]/.test(this.chunkName)) { | ||
this.chunkName += '[index]'; | ||
} | ||
} else { | ||
this.chunkName = 'client[index]'; | ||
} | ||
this.manifestFilename = options.manifestFilename || 'react-client-manifest.json'; | ||
this.serverConsumerManifestFilename = | ||
this.clientManifestFilename = | ||
this.chunkName = | ||
this.clientReferences = | ||
void 0; | ||
if (!options || "boolean" !== typeof options.isServer) | ||
throw Error( | ||
"React Server Plugin: You must specify the isServer option as a boolean." | ||
); | ||
if (options.isServer) throw Error("TODO: Implement the server compiler."); | ||
options.clientReferences | ||
? "string" !== typeof options.clientReferences && | ||
isArrayImpl(options.clientReferences) | ||
? (this.clientReferences = options.clientReferences) | ||
: (this.clientReferences = [options.clientReferences]) | ||
: (this.clientReferences = [ | ||
{ directory: ".", recursive: !0, include: /\.(js|ts|jsx|tsx)$/ } | ||
]); | ||
"string" === typeof options.chunkName | ||
? ((this.chunkName = options.chunkName), | ||
/\[(index|request)\]/.test(this.chunkName) || | ||
(this.chunkName += "[index]")) | ||
: (this.chunkName = "client[index]"); | ||
this.clientManifestFilename = | ||
options.clientManifestFilename || "react-client-manifest.json"; | ||
this.serverConsumerManifestFilename = | ||
options.serverConsumerManifestFilename || "react-ssr-manifest.json"; | ||
} | ||
apply(compiler) { | ||
var _this = this; | ||
var resolvedClientReferences; | ||
var clientFileNameFound = false; // Find all client files on the file system | ||
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, function (_ref, callback) { | ||
var contextModuleFactory = _ref.contextModuleFactory; | ||
var contextResolver = compiler.resolverFactory.get('context', {}); | ||
_this.resolveAllClientFiles(compiler.context, contextResolver, compiler.inputFileSystem, contextModuleFactory, function (err, resolvedClientRefs) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
resolvedClientReferences = resolvedClientRefs; | ||
callback(); | ||
}); | ||
}); | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function (compilation, _ref2) { | ||
var normalModuleFactory = _ref2.normalModuleFactory; | ||
compilation.dependencyFactories.set(ClientReferenceDependency, normalModuleFactory); | ||
compilation.dependencyTemplates.set(ClientReferenceDependency, new NullDependency.Template()); | ||
var handler = function (parser) { | ||
// We need to add all client references as dependency of something in the graph so | ||
// Webpack knows which entries need to know about the relevant chunks and include the | ||
// map in their runtime. The things that actually resolves the dependency is the Flight | ||
// client runtime. So we add them as a dependency of the Flight client runtime. | ||
// Anything that imports the runtime will be made aware of these chunks. | ||
parser.hooks.program.tap(PLUGIN_NAME, function () { | ||
var module = parser.state.module; | ||
if (module.resource !== clientFileName) { | ||
return; | ||
const _this = this; | ||
let resolvedClientReferences, | ||
clientFileNameFound = !1; | ||
compiler.hooks.beforeCompile.tapAsync( | ||
"React Server Plugin", | ||
(_ref, callback) => { | ||
_ref = _ref.contextModuleFactory; | ||
const contextResolver = compiler.resolverFactory.get("context", {}), | ||
normalResolver = compiler.resolverFactory.get("normal"); | ||
_this.resolveAllClientFiles( | ||
compiler.context, | ||
contextResolver, | ||
normalResolver, | ||
compiler.inputFileSystem, | ||
_ref, | ||
function (err, resolvedClientRefs) { | ||
err | ||
? callback(err) | ||
: ((resolvedClientReferences = resolvedClientRefs), callback()); | ||
} | ||
clientFileNameFound = true; | ||
if (resolvedClientReferences) { | ||
for (var i = 0; i < resolvedClientReferences.length; i++) { | ||
var dep = resolvedClientReferences[i]; | ||
var chunkName = _this.chunkName.replace(/\[index\]/g, '' + i).replace(/\[request\]/g, Template.toPath(dep.userRequest)); | ||
var block = new webpack.AsyncDependenciesBlock({ | ||
name: chunkName | ||
}, null, dep.request); | ||
block.addDependency(dep); | ||
module.addBlock(block); | ||
} | ||
} | ||
}); | ||
}; | ||
normalModuleFactory.hooks.parser.for('javascript/auto').tap('HarmonyModulesPlugin', handler); | ||
normalModuleFactory.hooks.parser.for('javascript/esm').tap('HarmonyModulesPlugin', handler); | ||
normalModuleFactory.hooks.parser.for('javascript/dynamic').tap('HarmonyModulesPlugin', handler); | ||
}); | ||
compiler.hooks.make.tap(PLUGIN_NAME, function (compilation) { | ||
compilation.hooks.processAssets.tap({ | ||
name: PLUGIN_NAME, | ||
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT | ||
}, function () { | ||
if (clientFileNameFound === false) { | ||
compilation.warnings.push(new webpack.WebpackError("Client runtime at " + clientImportName + " was not found. React Server Components module map file " + _this.manifestFilename + " was not created.")); | ||
return; | ||
} | ||
var json = {}; | ||
compilation.chunkGroups.forEach(function (chunkGroup) { | ||
var chunkIds = chunkGroup.chunks.map(function (c) { | ||
return c.id; | ||
); | ||
} | ||
); | ||
compiler.hooks.thisCompilation.tap( | ||
"React Server Plugin", | ||
(compilation, _ref2) => { | ||
_ref2 = _ref2.normalModuleFactory; | ||
compilation.dependencyFactories.set(ClientReferenceDependency, _ref2); | ||
compilation.dependencyTemplates.set( | ||
ClientReferenceDependency, | ||
new NullDependency.Template() | ||
); | ||
compilation = (parser) => { | ||
parser.hooks.program.tap("React Server Plugin", () => { | ||
const module = parser.state.module; | ||
if ( | ||
module.resource === clientFileName && | ||
((clientFileNameFound = !0), resolvedClientReferences) | ||
) | ||
for (let i = 0; i < resolvedClientReferences.length; i++) { | ||
const dep = resolvedClientReferences[i]; | ||
var chunkName = _this.chunkName | ||
.replace(/\[index\]/g, "" + i) | ||
.replace(/\[request\]/g, Template.toPath(dep.userRequest)); | ||
chunkName = new webpack.AsyncDependenciesBlock( | ||
{ name: chunkName }, | ||
null, | ||
dep.request | ||
); | ||
chunkName.addDependency(dep); | ||
module.addBlock(chunkName); | ||
} | ||
}); | ||
function recordModule(id, module) { | ||
// TODO: Hook into deps instead of the target module. | ||
// That way we know by the type of dep whether to include. | ||
// It also resolves conflicts when the same module is in multiple chunks. | ||
if (!/\.client\.(js|ts)x?$/.test(module.resource)) { | ||
return; | ||
} | ||
var moduleProvidedExports = compilation.moduleGraph.getExportsInfo(module).getProvidedExports(); | ||
var moduleExports = {}; | ||
['', '*'].concat(Array.isArray(moduleProvidedExports) ? moduleProvidedExports : []).forEach(function (name) { | ||
moduleExports[name] = { | ||
id: id, | ||
chunks: chunkIds, | ||
name: name | ||
}; | ||
}; | ||
_ref2.hooks.parser | ||
.for("javascript/auto") | ||
.tap("HarmonyModulesPlugin", compilation); | ||
_ref2.hooks.parser | ||
.for("javascript/esm") | ||
.tap("HarmonyModulesPlugin", compilation); | ||
_ref2.hooks.parser | ||
.for("javascript/dynamic") | ||
.tap("HarmonyModulesPlugin", compilation); | ||
} | ||
); | ||
compiler.hooks.make.tap("React Server Plugin", (compilation) => { | ||
compilation.hooks.processAssets.tap( | ||
{ | ||
name: "React Server Plugin", | ||
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT | ||
}, | ||
function () { | ||
if (!1 === clientFileNameFound) | ||
compilation.warnings.push( | ||
new webpack.WebpackError( | ||
"Client runtime at react-server-dom-webpack/client was not found. React Server Components module map file " + | ||
_this.clientManifestFilename + | ||
" was not created." | ||
) | ||
); | ||
else { | ||
var configuredCrossOriginLoading = | ||
compilation.outputOptions.crossOriginLoading; | ||
configuredCrossOriginLoading = | ||
"string" === typeof configuredCrossOriginLoading | ||
? "use-credentials" === configuredCrossOriginLoading | ||
? configuredCrossOriginLoading | ||
: "anonymous" | ||
: null; | ||
var resolvedClientFiles = new Set( | ||
(resolvedClientReferences || []).map((ref) => ref.request) | ||
), | ||
clientManifest = {}, | ||
moduleMap = {}; | ||
configuredCrossOriginLoading = { | ||
moduleLoading: { | ||
prefix: compilation.outputOptions.publicPath || "", | ||
crossOrigin: configuredCrossOriginLoading | ||
}, | ||
moduleMap | ||
}; | ||
var runtimeChunkFiles = new Set(); | ||
compilation.entrypoints.forEach((entrypoint) => { | ||
(entrypoint = entrypoint.getRuntimeChunk()) && | ||
entrypoint.files.forEach((runtimeFile) => { | ||
runtimeChunkFiles.add(runtimeFile); | ||
}); | ||
}); | ||
var href = url.pathToFileURL(module.resource).href; | ||
if (href !== undefined) { | ||
json[href] = moduleExports; | ||
} | ||
} | ||
chunkGroup.chunks.forEach(function (chunk) { | ||
var chunkModules = compilation.chunkGraph.getChunkModulesIterable(chunk); | ||
Array.from(chunkModules).forEach(function (module) { | ||
var moduleId = compilation.chunkGraph.getModuleId(module); | ||
recordModule(moduleId, module); // If this is a concatenation, register each child to the parent ID. | ||
if (module.modules) { | ||
module.modules.forEach(function (concatenatedMod) { | ||
recordModule(moduleId, concatenatedMod); | ||
compilation.chunkGroups.forEach(function (chunkGroup) { | ||
function recordModule(id, module) { | ||
if ( | ||
resolvedClientFiles.has(module.resource) && | ||
((module = url.pathToFileURL(module.resource).href), | ||
void 0 !== module) | ||
) { | ||
const ssrExports = {}; | ||
clientManifest[module] = { id, chunks, name: "*" }; | ||
ssrExports["*"] = { specifier: module, name: "*" }; | ||
moduleMap[id] = ssrExports; | ||
} | ||
} | ||
const chunks = []; | ||
chunkGroup.chunks.forEach(function (c) { | ||
var _iterator = _createForOfIteratorHelper(c.files), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done; ) { | ||
const file = _step.value; | ||
if (!file.endsWith(".js")) break; | ||
if (file.endsWith(".hot-update.js")) break; | ||
chunks.push(c.id, file); | ||
break; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
}); | ||
chunkGroup.chunks.forEach(function (chunk) { | ||
chunk = compilation.chunkGraph.getChunkModulesIterable(chunk); | ||
Array.from(chunk).forEach(function (module) { | ||
const moduleId = compilation.chunkGraph.getModuleId(module); | ||
recordModule(moduleId, module); | ||
module.modules && | ||
module.modules.forEach((concatenatedMod) => { | ||
recordModule(moduleId, concatenatedMod); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
var output = JSON.stringify(json, null, 2); | ||
compilation.emitAsset(_this.manifestFilename, new webpack.sources.RawSource(output, false)); | ||
}); | ||
var clientOutput = JSON.stringify(clientManifest, null, 2); | ||
compilation.emitAsset( | ||
_this.clientManifestFilename, | ||
new webpack.sources.RawSource(clientOutput, !1) | ||
); | ||
configuredCrossOriginLoading = JSON.stringify( | ||
configuredCrossOriginLoading, | ||
null, | ||
2 | ||
); | ||
compilation.emitAsset( | ||
_this.serverConsumerManifestFilename, | ||
new webpack.sources.RawSource(configuredCrossOriginLoading, !1) | ||
); | ||
} | ||
} | ||
); | ||
}); | ||
} // This attempts to replicate the dynamic file path resolution used for other wildcard | ||
// resolution in Webpack is using. | ||
resolveAllClientFiles(context, contextResolver, fs, contextModuleFactory, callback) { | ||
asyncLib.map(this.clientReferences, function (clientReferencePath, cb) { | ||
if (typeof clientReferencePath === 'string') { | ||
cb(null, [new ClientReferenceDependency(clientReferencePath)]); | ||
return; | ||
} | ||
resolveAllClientFiles( | ||
context, | ||
contextResolver, | ||
normalResolver, | ||
fs, | ||
contextModuleFactory, | ||
callback | ||
) { | ||
function hasUseClientDirective(source) { | ||
if (-1 === source.indexOf("use client")) return !1; | ||
let body; | ||
try { | ||
body = acorn.parse(source, { | ||
ecmaVersion: "2024", | ||
sourceType: "module" | ||
}).body; | ||
} catch (x) { | ||
return !1; | ||
} | ||
var clientReferenceSearch = clientReferencePath; | ||
contextResolver.resolve({}, context, clientReferencePath.directory, {}, function (err, resolvedDirectory) { | ||
if (err) return cb(err); | ||
var options = { | ||
resource: resolvedDirectory, | ||
resourceQuery: '', | ||
recursive: clientReferenceSearch.recursive === undefined ? true : clientReferenceSearch.recursive, | ||
regExp: clientReferenceSearch.include, | ||
include: undefined, | ||
exclude: clientReferenceSearch.exclude | ||
}; | ||
contextModuleFactory.resolveDependencies(fs, options, function (err2, deps) { | ||
if (err2) return cb(err2); | ||
var clientRefDeps = deps.map(function (dep) { | ||
// use userRequest instead of request. request always end with undefined which is wrong | ||
var request = path.join(resolvedDirectory, dep.userRequest); | ||
var clientRefDep = new ClientReferenceDependency(request); | ||
clientRefDep.userRequest = dep.userRequest; | ||
return clientRefDep; | ||
}); | ||
cb(null, clientRefDeps); | ||
}); | ||
}); | ||
}, function (err, result) { | ||
if (err) return callback(err); | ||
var flat = []; | ||
for (var i = 0; i < result.length; i++) { | ||
flat.push.apply(flat, result[i]); | ||
for (source = 0; source < body.length; source++) { | ||
const node = body[source]; | ||
if ("ExpressionStatement" !== node.type || !node.directive) break; | ||
if ("use client" === node.directive) return !0; | ||
} | ||
callback(null, flat); | ||
}); | ||
return !1; | ||
} | ||
asyncLib.map( | ||
this.clientReferences, | ||
(clientReferencePath, cb) => { | ||
"string" === typeof clientReferencePath | ||
? cb(null, [new ClientReferenceDependency(clientReferencePath)]) | ||
: contextResolver.resolve( | ||
{}, | ||
context, | ||
clientReferencePath.directory, | ||
{}, | ||
(err, resolvedDirectory) => { | ||
if (err) return cb(err); | ||
contextModuleFactory.resolveDependencies( | ||
fs, | ||
{ | ||
resource: resolvedDirectory, | ||
resourceQuery: "", | ||
recursive: | ||
void 0 === clientReferencePath.recursive | ||
? !0 | ||
: clientReferencePath.recursive, | ||
regExp: clientReferencePath.include, | ||
include: void 0, | ||
exclude: clientReferencePath.exclude | ||
}, | ||
(err2, deps) => { | ||
if (err2) return cb(err2); | ||
err2 = deps.map((dep) => { | ||
var request = path.join( | ||
resolvedDirectory, | ||
dep.userRequest | ||
); | ||
request = new ClientReferenceDependency(request); | ||
request.userRequest = dep.userRequest; | ||
return request; | ||
}); | ||
asyncLib.filter( | ||
err2, | ||
(clientRefDep, filterCb) => { | ||
normalResolver.resolve( | ||
{}, | ||
context, | ||
clientRefDep.request, | ||
{}, | ||
(err3, resolvedPath) => { | ||
if (err3 || "string" !== typeof resolvedPath) | ||
return filterCb(null, !1); | ||
fs.readFile( | ||
resolvedPath, | ||
"utf-8", | ||
(err4, content) => { | ||
if (err4 || "string" !== typeof content) | ||
return filterCb(null, !1); | ||
err4 = hasUseClientDirective(content); | ||
filterCb(null, err4); | ||
} | ||
); | ||
} | ||
); | ||
}, | ||
cb | ||
); | ||
} | ||
); | ||
} | ||
); | ||
}, | ||
(err, result) => { | ||
if (err) return callback(err); | ||
err = []; | ||
for (let i = 0; i < result.length; i++) err.push.apply(err, result[i]); | ||
callback(null, err); | ||
} | ||
); | ||
} | ||
} | ||
module.exports = ReactFlightWebpackPlugin; |
15
index.js
@@ -0,7 +1,12 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-server-dom-webpack.production.min.js'); | ||
} else { | ||
module.exports = require('./cjs/react-server-dom-webpack.development.js'); | ||
} | ||
throw new Error('Use react-server-dom-webpack/client instead.'); |
{ | ||
"name": "react-server-dom-webpack", | ||
"description": "React Server Components bindings for DOM using Webpack. This is intended to be integrated into meta-frameworks. It is not intended to be imported directly.", | ||
"version": "0.0.0-experimental-de516ca5a-20220321", | ||
"version": "0.0.0-experimental-de68d2f4-20241204", | ||
"keywords": [ | ||
"react" | ||
], | ||
"homepage": "https://reactjs.org/", | ||
"homepage": "https://react.dev/", | ||
"bugs": "https://github.com/facebook/react/issues", | ||
@@ -16,8 +16,19 @@ "license": "MIT", | ||
"plugin.js", | ||
"writer.js", | ||
"writer.browser.server.js", | ||
"writer.node.server.js", | ||
"client.js", | ||
"client.browser.js", | ||
"client.edge.js", | ||
"client.node.js", | ||
"client.node.unbundled.js", | ||
"server.js", | ||
"server.browser.js", | ||
"server.edge.js", | ||
"server.node.js", | ||
"server.node.unbundled.js", | ||
"static.js", | ||
"static.browser.js", | ||
"static.edge.js", | ||
"static.node.js", | ||
"static.node.unbundled.js", | ||
"node-register.js", | ||
"cjs/", | ||
"umd/", | ||
"esm/" | ||
@@ -28,12 +39,53 @@ ], | ||
"./plugin": "./plugin.js", | ||
"./writer": { | ||
"./client": { | ||
"workerd": "./client.edge.js", | ||
"deno": "./client.edge.js", | ||
"worker": "./client.edge.js", | ||
"node": { | ||
"webpack": "./client.node.js", | ||
"default": "./client.node.unbundled.js" | ||
}, | ||
"edge-light": "./client.edge.js", | ||
"browser": "./client.browser.js", | ||
"default": "./client.browser.js" | ||
}, | ||
"./client.browser": "./client.browser.js", | ||
"./client.edge": "./client.edge.js", | ||
"./client.node": "./client.node.js", | ||
"./client.node.unbundled": "./client.node.unbundled.js", | ||
"./server": { | ||
"react-server": { | ||
"node": "./writer.node.server.js", | ||
"browser": "./writer.browser.server.js" | ||
"workerd": "./server.edge.js", | ||
"deno": "./server.browser.js", | ||
"node": { | ||
"webpack": "./server.node.js", | ||
"default": "./server.node.unbundled.js" | ||
}, | ||
"edge-light": "./server.edge.js", | ||
"browser": "./server.browser.js" | ||
}, | ||
"default": "./writer.js" | ||
"default": "./server.js" | ||
}, | ||
"./writer.node.server": "./writer.node.server.js", | ||
"./writer.browser.server": "./writer.browser.server.js", | ||
"./node-loader": "./esm/react-server-dom-webpack-node-loader.js", | ||
"./server.browser": "./server.browser.js", | ||
"./server.edge": "./server.edge.js", | ||
"./server.node": "./server.node.js", | ||
"./server.node.unbundled": "./server.node.unbundled.js", | ||
"./static": { | ||
"react-server": { | ||
"workerd": "./static.edge.js", | ||
"deno": "./static.browser.js", | ||
"node": { | ||
"webpack": "./static.node.js", | ||
"default": "./static.node.unbundled.js" | ||
}, | ||
"edge-light": "./static.edge.js", | ||
"browser": "./static.browser.js" | ||
}, | ||
"default": "./static.js" | ||
}, | ||
"./static.browser": "./static.browser.js", | ||
"./static.edge": "./static.edge.js", | ||
"./static.node": "./static.node.js", | ||
"./static.node.unbundled": "./static.node.unbundled.js", | ||
"./node-loader": "./esm/react-server-dom-webpack-node-loader.production.js", | ||
"./node-register": "./node-register.js", | ||
@@ -52,15 +104,11 @@ "./package.json": "./package.json" | ||
"peerDependencies": { | ||
"react": "0.0.0-experimental-de516ca5a-20220321", | ||
"react": "0.0.0-experimental-de68d2f4-20241204", | ||
"react-dom": "0.0.0-experimental-de68d2f4-20241204", | ||
"webpack": "^5.59.0" | ||
}, | ||
"dependencies": { | ||
"acorn": "^6.2.1", | ||
"acorn-loose": "^8.3.0", | ||
"neo-async": "^2.6.1", | ||
"loose-envify": "^1.1.0" | ||
}, | ||
"browserify": { | ||
"transform": [ | ||
"loose-envify" | ||
] | ||
"webpack-sources": "^3.2.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1729188
41
49174
1
6
25
13
+ Addedacorn-loose@^8.3.0
+ Addedwebpack-sources@^3.2.0
+ Addedacorn-loose@8.4.0(transitive)
+ Addedreact@0.0.0-experimental-de68d2f4-20241204(transitive)
+ Addedreact-dom@0.0.0-experimental-de68d2f4-20241204(transitive)
+ Addedscheduler@0.0.0-experimental-de68d2f4-20241204(transitive)
- Removedacorn@^6.2.1
- Removedloose-envify@^1.1.0
- Removedacorn@6.4.2(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedreact@0.0.0-experimental-de516ca5a-20220321(transitive)