-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
182 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 18 additions & 3 deletions
21
packages/rspack/src/container/ModuleFederationRuntimePlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
import { Compiler } from "../Compiler"; | ||
import { BuiltinPluginName, create } from "../builtin-plugin/base"; | ||
import { EntryPlugin } from "../builtin-plugin/EntryPlugin"; | ||
|
||
const ModuleFederationRuntimePlugin2 = create( | ||
BuiltinPluginName.ModuleFederationRuntimePlugin, | ||
() => undefined | ||
); | ||
|
||
export class ModuleFederationRuntimePlugin { | ||
plugins: string[] = []; | ||
|
||
apply(compiler: Compiler) { | ||
// TODO: a hack to make sure this runtime is added after ContainerReferencePlugin | ||
// remove afterPlugin once we make rust side runtime_requirements_in_tree "tapable" | ||
compiler.hooks.afterPlugins.tap("ModuleFederationRuntimePlugin", () => { | ||
new ModuleFederationRuntimePlugin2().apply(compiler); | ||
}); | ||
compiler.hooks.afterPlugins.tap( | ||
{ name: ModuleFederationRuntimePlugin.name, stage: 10 }, | ||
() => { | ||
// TODO: move to rust side so don't depend on dataUrl | ||
const entry = this.plugins.map(p => `import "${p}";`).join("\n"); | ||
new EntryPlugin(compiler.context, `data:text/javascript,${entry}`, { | ||
name: undefined | ||
}).apply(compiler); | ||
new ModuleFederationRuntimePlugin2().apply(compiler); | ||
} | ||
); | ||
} | ||
|
||
addPlugin(dep: string) { | ||
this.plugins.push(dep); | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
packages/rspack/src/container/RemoteRuntimeSingletonPlugin.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,75 @@ | ||
// @ts-nocheck | ||
|
||
__webpack_require__.MF.remotes = function (data) { | ||
var chunkId = data.chunkId, | ||
promises = data.promises, | ||
chunkMapping = data.chunkMapping, | ||
idToExternalAndNameMapping = data.idToExternalAndNameMapping; | ||
if (__webpack_require__.o(chunkMapping, chunkId)) { | ||
chunkMapping[chunkId].forEach(function (id) { | ||
var getScope = __webpack_require__.R; | ||
if (!getScope) getScope = []; | ||
var data = idToExternalAndNameMapping[id]; | ||
if (getScope.indexOf(data) >= 0) return; | ||
getScope.push(data); | ||
if (data.p) return promises.push(data.p); | ||
var onError = function (error) { | ||
if (!error) error = new Error("Container missing"); | ||
if (typeof error.message === "string") | ||
error.message += '\nwhile loading "' + data[1] + '" from ' + data[2]; | ||
__webpack_require__.m[id] = function () { | ||
throw error; | ||
if (__webpack_require__.MF) { | ||
__webpack_require__.MF.remotes = function (data) { | ||
var chunkId = data.chunkId, | ||
promises = data.promises, | ||
chunkMapping = data.chunkMapping, | ||
idToExternalAndNameMapping = data.idToExternalAndNameMapping; | ||
if (__webpack_require__.o(chunkMapping, chunkId)) { | ||
chunkMapping[chunkId].forEach(function (id) { | ||
var getScope = __webpack_require__.R; | ||
if (!getScope) getScope = []; | ||
var data = idToExternalAndNameMapping[id]; | ||
if (getScope.indexOf(data) >= 0) return; | ||
getScope.push(data); | ||
if (data.p) return promises.push(data.p); | ||
var onError = function (error) { | ||
if (!error) error = new Error("Container missing"); | ||
if (typeof error.message === "string") | ||
error.message += | ||
'\nwhile loading "' + data[1] + '" from ' + data[2]; | ||
__webpack_require__.m[id] = function () { | ||
throw error; | ||
}; | ||
data.p = 0; | ||
}; | ||
data.p = 0; | ||
}; | ||
var handleFunction = function (fn, arg1, arg2, d, next, first) { | ||
try { | ||
var promise = fn(arg1, arg2); | ||
if (promise && promise.then) { | ||
var p = promise.then(function (result) { | ||
return next(result, d); | ||
}, onError); | ||
if (first) promises.push((data.p = p)); | ||
else return p; | ||
} else { | ||
return next(promise, d, first); | ||
var handleFunction = function (fn, arg1, arg2, d, next, first) { | ||
try { | ||
var promise = fn(arg1, arg2); | ||
if (promise && promise.then) { | ||
var p = promise.then(function (result) { | ||
return next(result, d); | ||
}, onError); | ||
if (first) promises.push((data.p = p)); | ||
else return p; | ||
} else { | ||
return next(promise, d, first); | ||
} | ||
} catch (error) { | ||
onError(error); | ||
} | ||
} catch (error) { | ||
onError(error); | ||
} | ||
}; | ||
var onExternal = function (external, _, first) { | ||
return external | ||
? handleFunction( | ||
__webpack_require__.I, | ||
data[0], | ||
0, | ||
external, | ||
onInitialized, | ||
first | ||
) | ||
: onError(); | ||
}; | ||
var onInitialized = function (_, external, first) { | ||
return handleFunction( | ||
external.get, | ||
data[1], | ||
getScope, | ||
0, | ||
onFactory, | ||
first | ||
); | ||
}; | ||
var onFactory = function (factory) { | ||
data.p = 1; | ||
__webpack_require__.m[id] = function (module) { | ||
module.exports = factory(); | ||
}; | ||
}; | ||
handleFunction(__webpack_require__, data[2], 0, 0, onExternal, 1); | ||
}); | ||
} | ||
}; | ||
var onExternal = function (external, _, first) { | ||
return external | ||
? handleFunction( | ||
__webpack_require__.I, | ||
data[0], | ||
0, | ||
external, | ||
onInitialized, | ||
first | ||
) | ||
: onError(); | ||
}; | ||
var onInitialized = function (_, external, first) { | ||
return handleFunction( | ||
external.get, | ||
data[1], | ||
getScope, | ||
0, | ||
onFactory, | ||
first | ||
); | ||
}; | ||
var onFactory = function (factory) { | ||
data.p = 1; | ||
__webpack_require__.m[id] = function (module) { | ||
module.exports = factory(); | ||
}; | ||
}; | ||
handleFunction(__webpack_require__, data[2], 0, 0, onExternal, 1); | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
packages/rspack/src/sharing/ShareRuntimeSingletonPlugin.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.