File tree Expand file tree Collapse file tree 6 files changed +75
-2
lines changed
configCases/container-1-5/runtime-entry-data-uri-encoded Expand file tree Collapse file tree 6 files changed +75
-2
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ const DELTA_A_TO_Z = 'z'.charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1;
1414const NUMBER_OF_IDENTIFIER_START_CHARS = DELTA_A_TO_Z * 2 + 2 ; // a-z A-Z _ $
1515const NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS =
1616 NUMBER_OF_IDENTIFIER_START_CHARS + 10 ; // a-z A-Z _ $ 0-9
17- const FUNCTION_CONTENT_REGEX = / ^ f u n c t i o n \s ? \( \) \s ? \{ \r ? \n ? | \r ? \n ? \} $ / g;
17+ const FUNCTION_CONTENT_REGEX =
18+ / ^ f u n c t i o n (?: \s + [ \w $ ] + ) ? \s ? \( \) \s ? \{ \r ? \n ? | \r ? \n ? \} $ / g;
1819const INDENT_MULTILINE_REGEX = / ^ \t / gm;
1920const LINE_SEPARATOR_REGEX = / \r ? \n / g;
2021const IDENTIFIER_NAME_REPLACE_REGEX = / ^ ( [ ^ a - z A - Z $ _ ] ) / ;
Original file line number Diff line number Diff line change @@ -346,5 +346,5 @@ function getDefaultEntryRuntime(
346346 require ( './moduleFederationDefaultRuntime.js' ) . default ,
347347 ) ,
348348 ] . join ( ';' ) ;
349- return `@module-federation/runtime/rspack.js!=!data:text/javascript,${ content } ` ;
349+ return `@module-federation/runtime/rspack.js!=!data:text/javascript,${ encodeURIComponent ( content ) } ` ;
350350}
Original file line number Diff line number Diff line change 1+ const { Template } = require ( "@rspack/core" ) ;
2+
3+ describe ( "Template.getFunctionContent" , ( ) => {
4+ it ( "should strip named function wrappers" , ( ) => {
5+ const content = Template . getFunctionContent ( function moduleFederationDefaultRuntime_default ( ) {
6+ return "ok" ;
7+ } ) ;
8+
9+ expect ( content ) . toContain ( 'return "ok";' ) ;
10+ expect ( content ) . not . toContain ( "function moduleFederationDefaultRuntime_default" ) ;
11+ } ) ;
12+
13+ it ( "should strip anonymous function wrappers" , ( ) => {
14+ const content = Template . getFunctionContent ( function ( ) {
15+ return "ok" ;
16+ } ) ;
17+
18+ expect ( content ) . toContain ( 'return "ok";' ) ;
19+ expect ( content ) . not . toContain ( "function ()" ) ;
20+ } ) ;
21+ } ) ;
Original file line number Diff line number Diff line change 1+ it ( "should expose module with encoded mf runtime data uri entry" , async ( ) => {
2+ await __webpack_init_sharing__ ( "default" ) ;
3+ const container = __non_webpack_require__ ( "./container.js" ) ;
4+ container . init ( __webpack_share_scopes__ . default ) ;
5+ const moduleFactory = await container . get ( "./module" ) ;
6+ expect ( moduleFactory ( ) . ok ) . toBe ( true ) ;
7+ } ) ;
Original file line number Diff line number Diff line change 1+ export const ok = true ;
Original file line number Diff line number Diff line change 1+ const { ModuleFederationPlugin } = require ( "@rspack/core" ) . container ;
2+
3+ class AssertEncodedMFRuntimeDataUriPlugin {
4+ apply ( compiler ) {
5+ compiler . hooks . compilation . tap (
6+ "AssertEncodedMFRuntimeDataUriPlugin" ,
7+ ( _ , { normalModuleFactory } ) => {
8+ normalModuleFactory . hooks . beforeResolve . tap (
9+ "AssertEncodedMFRuntimeDataUriPlugin" ,
10+ ( resolveData ) => {
11+ const request = resolveData ?. request ;
12+ const prefix =
13+ "@module-federation/runtime/rspack.js!=!data:text/javascript," ;
14+
15+ if ( ! request || ! request . startsWith ( prefix ) ) {
16+ return ;
17+ }
18+
19+ const dataUriContent = request . slice ( prefix . length ) ;
20+
21+ expect ( dataUriContent ) . toMatch ( / % [ 0 - 9 A - F a - f ] { 2 } / ) ;
22+ expect ( dataUriContent ) . not . toContain (
23+ "import __module_federation_bundler_runtime__ from" ,
24+ ) ;
25+ } ,
26+ ) ;
27+ } ,
28+ ) ;
29+ }
30+ }
31+
32+ /** @type {import("@rspack/core").Configuration } */
33+ module . exports = {
34+ plugins : [
35+ new ModuleFederationPlugin ( {
36+ name : "container" ,
37+ filename : "container.js" ,
38+ library : { type : "commonjs-module" } ,
39+ exposes : [ "./module" ] ,
40+ } ) ,
41+ new AssertEncodedMFRuntimeDataUriPlugin ( ) ,
42+ ] ,
43+ } ;
You can’t perform that action at this time.
0 commit comments