@modern-js/builder 3.0.0 → 3.0.2

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.
Files changed (59) hide show
  1. package/dist/cjs/createBuilder.js +3 -8
  2. package/dist/cjs/plugins/environmentDefaults.js +4 -4
  3. package/dist/cjs/plugins/postcss.js +8 -31
  4. package/dist/cjs/plugins/rscConfig.js +159 -0
  5. package/dist/cjs/{rsc/rsc-css-loader.js → shared/rsc/rsc-server-entry-loader.js} +6 -7
  6. package/dist/esm/createBuilder.mjs +3 -8
  7. package/dist/esm/plugins/environmentDefaults.mjs +4 -4
  8. package/dist/esm/plugins/postcss.mjs +8 -31
  9. package/dist/esm/plugins/rscConfig.mjs +112 -0
  10. package/dist/esm/shared/rsc/rsc-server-entry-loader.mjs +7 -0
  11. package/dist/esm-node/createBuilder.mjs +3 -8
  12. package/dist/esm-node/plugins/environmentDefaults.mjs +4 -4
  13. package/dist/esm-node/plugins/postcss.mjs +8 -31
  14. package/dist/esm-node/plugins/rscConfig.mjs +117 -0
  15. package/dist/esm-node/shared/rsc/rsc-server-entry-loader.mjs +8 -0
  16. package/dist/types/plugins/postcss.d.ts +1 -1
  17. package/dist/types/plugins/rscConfig.d.ts +18 -0
  18. package/dist/types/shared/rsc/rsc-server-entry-loader.d.ts +5 -0
  19. package/package.json +7 -8
  20. package/compiled/postcss-load-config/index.d.ts +0 -1
  21. package/compiled/postcss-load-config/index.js +0 -14
  22. package/compiled/postcss-load-config/license +0 -20
  23. package/compiled/postcss-load-config/package.json +0 -1
  24. package/dist/cjs/rsc/common.js +0 -157
  25. package/dist/cjs/rsc/plugins/rsbuild-rsc-plugin.js +0 -169
  26. package/dist/cjs/rsc/plugins/rspack-rsc-client-plugin.js +0 -187
  27. package/dist/cjs/rsc/plugins/rspack-rsc-server-plugin.js +0 -245
  28. package/dist/cjs/rsc/rsc-client-loader.js +0 -71
  29. package/dist/cjs/rsc/rsc-server-loader.js +0 -102
  30. package/dist/cjs/rsc/rsc-ssr-loader.js +0 -60
  31. package/dist/compiled/postcss-load-config/index.d.ts +0 -1
  32. package/dist/compiled/postcss-load-config/index.js +0 -608
  33. package/dist/compiled/postcss-load-config/index.js.LICENSE.txt +0 -13
  34. package/dist/compiled/postcss-load-config/license +0 -20
  35. package/dist/compiled/postcss-load-config/package.json +0 -1
  36. package/dist/esm/rsc/common.mjs +0 -87
  37. package/dist/esm/rsc/plugins/rsbuild-rsc-plugin.mjs +0 -124
  38. package/dist/esm/rsc/plugins/rspack-rsc-client-plugin.mjs +0 -143
  39. package/dist/esm/rsc/plugins/rspack-rsc-server-plugin.mjs +0 -211
  40. package/dist/esm/rsc/rsc-client-loader.mjs +0 -37
  41. package/dist/esm/rsc/rsc-css-loader.mjs +0 -8
  42. package/dist/esm/rsc/rsc-server-loader.mjs +0 -58
  43. package/dist/esm/rsc/rsc-ssr-loader.mjs +0 -26
  44. package/dist/esm-node/rsc/common.mjs +0 -88
  45. package/dist/esm-node/rsc/plugins/rsbuild-rsc-plugin.mjs +0 -126
  46. package/dist/esm-node/rsc/plugins/rspack-rsc-client-plugin.mjs +0 -144
  47. package/dist/esm-node/rsc/plugins/rspack-rsc-server-plugin.mjs +0 -212
  48. package/dist/esm-node/rsc/rsc-client-loader.mjs +0 -38
  49. package/dist/esm-node/rsc/rsc-css-loader.mjs +0 -9
  50. package/dist/esm-node/rsc/rsc-server-loader.mjs +0 -60
  51. package/dist/esm-node/rsc/rsc-ssr-loader.mjs +0 -27
  52. package/dist/types/rsc/common.d.ts +0 -22
  53. package/dist/types/rsc/plugins/rsbuild-rsc-plugin.d.ts +0 -7
  54. package/dist/types/rsc/plugins/rspack-rsc-client-plugin.d.ts +0 -14
  55. package/dist/types/rsc/plugins/rspack-rsc-server-plugin.d.ts +0 -32
  56. package/dist/types/rsc/rsc-client-loader.d.ts +0 -7
  57. package/dist/types/rsc/rsc-css-loader.d.ts +0 -2
  58. package/dist/types/rsc/rsc-server-loader.d.ts +0 -6
  59. package/dist/types/rsc/rsc-ssr-loader.d.ts +0 -6
@@ -0,0 +1,117 @@
1
+ import __rslib_shim_module__ from "node:module";
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
+ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
4
+ import { dirname as __rspack_dirname } from "node:path";
5
+ import path from "path";
6
+ var rscConfig_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
7
+ const ASYNC_STORAGE_PATTERN = /universal[/\\]async_storage/;
8
+ const RSC_COMMON_LAYER = 'rsc-common';
9
+ const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
10
+ const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
11
+ const isAsyncStorageExclude = (exclude)=>{
12
+ if ('string' == typeof exclude) return ASYNC_STORAGE_PATTERN.test(exclude);
13
+ if (exclude instanceof RegExp) return exclude.test('universal/async_storage') || exclude.test('universal\\async_storage');
14
+ return false;
15
+ };
16
+ function pluginRscConfig() {
17
+ return {
18
+ name: 'builder:rsc-config',
19
+ setup (api) {
20
+ let layersCache = null;
21
+ const getLayers = async ()=>{
22
+ if (!layersCache) {
23
+ const { Layers } = await import("rsbuild-plugin-rsc");
24
+ layersCache = Layers;
25
+ }
26
+ return layersCache;
27
+ };
28
+ api.modifyBundlerChain({
29
+ handler: (chain, { isServer })=>{
30
+ if (isServer) {
31
+ const routeFilePattern = /routes[/\\].*[/\\](layout|page|\$)\.[tj]sx?$/;
32
+ const appFilePattern = /[/\\]App\.[tj]sx?$/;
33
+ const combinedPattern = new RegExp(`(${routeFilePattern.source}|${appFilePattern.source})`);
34
+ let loaderPath;
35
+ try {
36
+ loaderPath = require.resolve('../shared/rsc/rsc-server-entry-loader');
37
+ } catch {
38
+ loaderPath = path.resolve(rscConfig_dirname, '../shared/rsc/rsc-server-entry-loader');
39
+ }
40
+ chain.module.rule('rsc-server-entry').test(/\.(tsx?|jsx?)$/).resource(combinedPattern).exclude.add(/node_modules/).end().use('rsc-server-entry-loader').loader(loaderPath).end();
41
+ }
42
+ },
43
+ order: 'pre'
44
+ });
45
+ api.modifyRspackConfig(async (config, utils)=>{
46
+ const isServer = 'node' === config.target || 'node' === utils.target || utils.environment?.name === 'server';
47
+ if (!isServer) return;
48
+ const Layers = await getLayers();
49
+ if (config.entry) {
50
+ const entries = config.entry;
51
+ const newEntries = {};
52
+ for (const [entryName, entryValue] of Object.entries(entries))if ('string' == typeof entryValue) newEntries[entryName] = {
53
+ import: entryValue,
54
+ layer: Layers.ssr
55
+ };
56
+ else if (Array.isArray(entryValue)) newEntries[entryName] = {
57
+ import: entryValue,
58
+ layer: Layers.ssr
59
+ };
60
+ else if ('object' == typeof entryValue && null !== entryValue) newEntries[entryName] = {
61
+ ...entryValue,
62
+ layer: Layers.ssr
63
+ };
64
+ else newEntries[entryName] = entryValue;
65
+ config.entry = newEntries;
66
+ }
67
+ if (config.module?.rules) {
68
+ const rules = config.module.rules;
69
+ for (const rule of rules)if (rule.layer === Layers.rsc) {
70
+ if (rule.exclude) {
71
+ if (!Array.isArray(rule.exclude)) rule.exclude = [
72
+ rule.exclude
73
+ ];
74
+ } else rule.exclude = [];
75
+ const hasExclude = rule.exclude.some(isAsyncStorageExclude);
76
+ if (!hasExclude) rule.exclude.push(ASYNC_STORAGE_PATTERN);
77
+ }
78
+ if (!Array.isArray(config.module.rules)) config.module.rules = [];
79
+ config.module.rules.push({
80
+ resource: ASYNC_STORAGE_PATTERN,
81
+ layer: RSC_COMMON_LAYER
82
+ });
83
+ }
84
+ });
85
+ api.modifyBundlerChain((chain, { isServer, isWebWorker })=>{
86
+ if (!isServer && !isWebWorker) {
87
+ const entries = chain.entryPoints.entries();
88
+ if (entries && 'object' == typeof entries) for (const entryName of Object.keys(entries)){
89
+ const entryPoint = chain.entry(entryName);
90
+ const code = `window.${ENTRY_NAME_VAR}="${entryName}";`;
91
+ entryPoint.add(createVirtualModule(code));
92
+ }
93
+ }
94
+ });
95
+ }
96
+ };
97
+ }
98
+ async function getRscPlugins(enableRsc, internalDirectory) {
99
+ if (enableRsc) {
100
+ const routesFileReg = new RegExp(`${internalDirectory.replace(/[/\\]/g, '[/\\\\]')}[/\\\\][^/\\\\]*[/\\\\]routes`);
101
+ const { pluginRSC } = await import("rsbuild-plugin-rsc");
102
+ return [
103
+ pluginRSC({
104
+ layers: {
105
+ rsc: [
106
+ /render[/\\].*[/\\]server[/\\]rsc/,
107
+ /AppProxy/,
108
+ routesFileReg
109
+ ]
110
+ }
111
+ }),
112
+ pluginRscConfig()
113
+ ];
114
+ }
115
+ return [];
116
+ }
117
+ export { getRscPlugins, pluginRscConfig };
@@ -0,0 +1,8 @@
1
+ import "node:module";
2
+ function rscServerEntryLoader(source) {
3
+ this.cacheable(true);
4
+ const hasServerEntryDirective = source.includes("'use server-entry'") || source.includes('"use server-entry"') || source.includes('`use server-entry`');
5
+ if (hasServerEntryDirective) return source;
6
+ return `'use server-entry';\n${source}`;
7
+ }
8
+ export { rscServerEntryLoader as default };
@@ -1,4 +1,4 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
1
+ import { type RsbuildPlugin } from '@rsbuild/core';
2
2
  import type { ToolsAutoprefixerConfig } from '../types';
3
3
  export interface PluginPostcssOptions {
4
4
  autoprefixer?: ToolsAutoprefixerConfig;
@@ -0,0 +1,18 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ /**
3
+ * Unified plugin for RSC (React Server Components) configuration
4
+ * Handles:
5
+ * 1. Adding layer configuration to server-side entries
6
+ * 2. Excluding /universal[/\\]async_storage/ from react-server-components layer
7
+ * 3. Adding rsc-common layer for /universal[/\\]async_storage/
8
+ * 4. Adding entry name virtual module for client-side entries
9
+ * 5. Adding 'use server-entry' directive to route components
10
+ */
11
+ export declare function pluginRscConfig(): RsbuildPlugin;
12
+ /**
13
+ * Get RSC plugins based on configuration
14
+ * @param enableRsc - Whether RSC is enabled
15
+ * @param internalDirectory - Internal directory path for route matching
16
+ * @returns Array of RSC-related plugins
17
+ */
18
+ export declare function getRscPlugins(enableRsc: boolean, internalDirectory: string): Promise<RsbuildPlugin[]>;
@@ -0,0 +1,5 @@
1
+ import type { Rspack } from '@rsbuild/core';
2
+ /**
3
+ * Loader to add 'use server-entry'; directive at the top of route components
4
+ */
5
+ export default function rscServerEntryLoader(this: Rspack.LoaderContext, source: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/builder",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "A builder for Modern.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  "dist"
27
27
  ],
28
28
  "dependencies": {
29
- "@rsbuild/core": "2.0.0-beta.1",
29
+ "@rsbuild/core": "2.0.0-beta.4",
30
30
  "@rsbuild/plugin-assets-retry": "1.5.1",
31
31
  "@rsbuild/plugin-check-syntax": "1.6.1",
32
32
  "@rsbuild/plugin-css-minimizer": "1.1.1",
@@ -38,7 +38,8 @@
38
38
  "@rsbuild/plugin-svgr": "1.3.0",
39
39
  "@rsbuild/plugin-type-check": "1.3.3",
40
40
  "@rsbuild/plugin-typed-css-modules": "1.2.1",
41
- "@swc/core": "1.15.10",
41
+ "@swc/core": "1.15.11",
42
+ "rsbuild-plugin-rsc": "0.0.1-beta.0",
42
43
  "@swc/helpers": "^0.5.17",
43
44
  "autoprefixer": "10.4.24",
44
45
  "browserslist": "4.28.1",
@@ -56,19 +57,17 @@
56
57
  "postcss-page-break": "3.0.4",
57
58
  "rspack-manifest-plugin": "5.2.1",
58
59
  "ts-deepmerge": "7.0.3",
59
- "jiti": "^2.6.1",
60
- "@modern-js/flight-server-transform-plugin": "3.0.0",
61
- "@modern-js/utils": "3.0.0"
60
+ "@modern-js/utils": "3.0.2"
62
61
  },
63
62
  "devDependencies": {
64
- "@rslib/core": "0.19.4",
63
+ "@rslib/core": "0.19.5",
65
64
  "@types/html-minifier-terser": "^7.0.2",
66
65
  "@types/lodash": "^4.17.23",
67
66
  "react": "^19.2.4",
68
67
  "terser": "^5.46.0",
69
68
  "typescript": "^5.3.0",
70
69
  "@modern-js/rslib": "2.68.10",
71
- "@modern-js/types": "3.0.0",
70
+ "@modern-js/types": "3.0.2",
72
71
  "@scripts/rstest-config": "2.66.0"
73
72
  },
74
73
  "publishConfig": {
@@ -1 +0,0 @@
1
- export = any;
@@ -1,14 +0,0 @@
1
- (()=>{var __webpack_modules__={920:(module,__unused_webpack_exports,__nccwpck_require__)=>{const path=__nccwpck_require__(928);const fs=__nccwpck_require__(896);const os=__nccwpck_require__(857);const url=__nccwpck_require__(16);const fsReadFileAsync=fs.promises.readFile;function getDefaultSearchPlaces(e,t){return["package.json",`.${e}rc.json`,`.${e}rc.js`,`.${e}rc.cjs`,...t?[]:[`.${e}rc.mjs`],`.config/${e}rc`,`.config/${e}rc.json`,`.config/${e}rc.js`,`.config/${e}rc.cjs`,...t?[]:[`.config/${e}rc.mjs`],`${e}.config.js`,`${e}.config.cjs`,...t?[]:[`${e}.config.mjs`]]}function parentDir(e){return path.dirname(e)||path.sep}const jsonLoader=(e,t)=>JSON.parse(t);const requireFunc=true?eval("require"):0;const defaultLoadersSync=Object.freeze({".js":requireFunc,".json":requireFunc,".cjs":requireFunc,noExt:jsonLoader});module.exports.defaultLoadersSync=defaultLoadersSync;const dynamicImport=async e=>{try{const t=url.pathToFileURL(e).href;const r=await import(t);return r.default}catch(t){try{return requireFunc(e)}catch(e){if(e.code==="ERR_REQUIRE_ESM"||e instanceof SyntaxError&&e.toString().includes("Cannot use import statement outside a module")){throw t}throw e}}};const defaultLoaders=Object.freeze({".js":dynamicImport,".mjs":dynamicImport,".cjs":dynamicImport,".json":jsonLoader,noExt:jsonLoader});module.exports.defaultLoaders=defaultLoaders;function getOptions(e,t,r){const n={stopDir:os.homedir(),searchPlaces:getDefaultSearchPlaces(e,r),ignoreEmptySearchPlaces:true,cache:true,transform:e=>e,packageProp:[e],...t,loaders:{...r?defaultLoadersSync:defaultLoaders,...t.loaders}};n.searchPlaces.forEach((e=>{const t=path.extname(e)||"noExt";const r=n.loaders[t];if(!r){throw new Error(`Missing loader for extension "${e}"`)}if(typeof r!=="function"){throw new Error(`Loader for extension "${e}" is not a function: Received ${typeof r}.`)}}));return n}function getPackageProp(e,t){if(typeof e==="string"&&e in t)return t[e];return(Array.isArray(e)?e:e.split(".")).reduce(((e,t)=>e===undefined?e:e[t]),t)||null}function validateFilePath(e){if(!e)throw new Error("load must pass a non-empty string")}function validateLoader(e,t){if(!e)throw new Error(`No loader specified for extension "${t}"`);if(typeof e!=="function")throw new Error("loader is not a function")}const makeEmplace=e=>(t,r,n)=>{if(e)t.set(r,n);return n};module.exports.lilconfig=function lilconfig(e,t){const{ignoreEmptySearchPlaces:r,loaders:n,packageProp:o,searchPlaces:a,stopDir:s,transform:c,cache:i}=getOptions(e,t??{},false);const f=new Map;const l=new Map;const u=makeEmplace(i);return{async search(e=process.cwd()){const t={config:null,filepath:""};const l=new Set;let u=e;e:while(true){if(i){const e=f.get(u);if(e!==undefined){for(const t of l)f.set(t,e);return e}l.add(u)}for(const e of a){const a=path.join(u,e);try{await fs.promises.access(a)}catch{continue}const s=String(await fsReadFileAsync(a));const c=path.extname(e)||"noExt";const i=n[c];if(e==="package.json"){const e=await i(a,s);const r=getPackageProp(o,e);if(r!=null){t.config=r;t.filepath=a;break e}continue}const f=s.trim()==="";if(f&&r)continue;if(f){t.isEmpty=true;t.config=undefined}else{validateLoader(i,c);t.config=await i(a,s)}t.filepath=a;break e}if(u===s||u===parentDir(u))break e;u=parentDir(u)}const p=t.filepath===""&&t.config===null?c(null):c(t);if(i){for(const e of l)f.set(e,p)}return p},async load(e){validateFilePath(e);const t=path.resolve(process.cwd(),e);if(i&&l.has(t)){return l.get(t)}const{base:a,ext:s}=path.parse(t);const f=s||"noExt";const p=n[f];validateLoader(p,f);const d=String(await fsReadFileAsync(t));if(a==="package.json"){const e=await p(t,d);return u(l,t,c({config:getPackageProp(o,e),filepath:t}))}const _={config:null,filepath:t};const g=d.trim()==="";if(g&&r)return u(l,t,c({config:undefined,filepath:t,isEmpty:true}));_.config=g?undefined:await p(t,d);return u(l,t,c(g?{..._,isEmpty:g,config:undefined}:_))},clearLoadCache(){if(i)l.clear()},clearSearchCache(){if(i)f.clear()},clearCaches(){if(i){l.clear();f.clear()}}}};module.exports.lilconfigSync=function lilconfigSync(e,t){const{ignoreEmptySearchPlaces:r,loaders:n,packageProp:o,searchPlaces:a,stopDir:s,transform:c,cache:i}=getOptions(e,t??{},true);const f=new Map;const l=new Map;const u=makeEmplace(i);return{search(e=process.cwd()){const t={config:null,filepath:""};const l=new Set;let u=e;e:while(true){if(i){const e=f.get(u);if(e!==undefined){for(const t of l)f.set(t,e);return e}l.add(u)}for(const e of a){const a=path.join(u,e);try{fs.accessSync(a)}catch{continue}const s=path.extname(e)||"noExt";const c=n[s];const i=String(fs.readFileSync(a));if(e==="package.json"){const e=c(a,i);const r=getPackageProp(o,e);if(r!=null){t.config=r;t.filepath=a;break e}continue}const f=i.trim()==="";if(f&&r)continue;if(f){t.isEmpty=true;t.config=undefined}else{validateLoader(c,s);t.config=c(a,i)}t.filepath=a;break e}if(u===s||u===parentDir(u))break e;u=parentDir(u)}const p=t.filepath===""&&t.config===null?c(null):c(t);if(i){for(const e of l)f.set(e,p)}return p},load(e){validateFilePath(e);const t=path.resolve(process.cwd(),e);if(i&&l.has(t)){return l.get(t)}const{base:a,ext:s}=path.parse(t);const f=s||"noExt";const p=n[f];validateLoader(p,f);const d=String(fs.readFileSync(t));if(a==="package.json"){const e=p(t,d);return c({config:getPackageProp(o,e),filepath:t})}const _={config:null,filepath:t};const g=d.trim()==="";if(g&&r)return u(l,t,c({filepath:t,config:undefined,isEmpty:true}));_.config=g?undefined:p(t,d);return u(l,t,c(g?{..._,isEmpty:g,config:undefined}:_))},clearLoadCache(){if(i)l.clear()},clearSearchCache(){if(i)f.clear()},clearCaches(){if(i){l.clear();f.clear()}}}}},109:(e,t,r)=>{const{resolve:n}=r(760);const o=r(920);const a=r(471);const s=r(697);const c=r(257);const interopRequireDefault=e=>e&&e.__esModule?e:{default:e};async function processResult(e,t){let r=t.filepath||"";let n=interopRequireDefault(t.config).default||{};if(typeof n==="function"){n=n(e)}else{n=Object.assign({},n,e)}if(!n.plugins){n.plugins=[]}let o={file:r,options:await a(n,r),plugins:await s(n,r)};delete n.plugins;return o}function createContext(e){e=Object.assign({cwd:process.cwd(),env:process.env.NODE_ENV},e);if(!e.env){process.env.NODE_ENV="development"}return e}async function loader(e){return c(e)}let i;async function yamlLoader(e,t){if(!i){try{i=await Promise.resolve().then(r.t.bind(r,160,23))}catch(e){throw new Error(`'yaml' is required for the YAML configuration files. Make sure it is installed\nError: ${e.message}`)}}return i.parse(t)}const withLoaders=(e={})=>{let t="postcss";return{...e,loaders:{...e.loaders,".cjs":loader,".cts":loader,".js":loader,".mjs":loader,".mts":loader,".ts":loader,".yaml":yamlLoader,".yml":yamlLoader},searchPlaces:[...e.searchPlaces||[],"package.json",`.${t}rc`,`.${t}rc.json`,`.${t}rc.yaml`,`.${t}rc.yml`,`.${t}rc.ts`,`.${t}rc.cts`,`.${t}rc.mts`,`.${t}rc.js`,`.${t}rc.cjs`,`.${t}rc.mjs`,`${t}.config.ts`,`${t}.config.cts`,`${t}.config.mts`,`${t}.config.js`,`${t}.config.cjs`,`${t}.config.mjs`]}};function rc(e,t,r){e=createContext(e);t=t?n(t):process.cwd();return o.lilconfig("postcss",withLoaders(r)).search(t).then((r=>{if(!r){throw new Error(`No PostCSS Config found in: ${t}`)}return processResult(e,r)}))}
2
- /**
3
- * Autoload Config for PostCSS
4
- *
5
- * @author Michael Ciniawsky @michael-ciniawsky <michael.ciniawsky@gmail.com>
6
- * @license MIT
7
- *
8
- * @module postcss-load-config
9
- * @version 2.1.0
10
- *
11
- * @requires comsiconfig
12
- * @requires ./options
13
- * @requires ./plugins
14
- */e.exports=rc},471:(e,t,r)=>{const n=r(257);async function options(e,t){if(e.parser&&typeof e.parser==="string"){try{e.parser=await n(e.parser,t)}catch(e){throw new Error(`Loading PostCSS Parser failed: ${e.message}\n\n(@${t})`)}}if(e.syntax&&typeof e.syntax==="string"){try{e.syntax=await n(e.syntax,t)}catch(e){throw new Error(`Loading PostCSS Syntax failed: ${e.message}\n\n(@${t})`)}}if(e.stringifier&&typeof e.stringifier==="string"){try{e.stringifier=await n(e.stringifier,t)}catch(e){throw new Error(`Loading PostCSS Stringifier failed: ${e.message}\n\n(@${t})`)}}return e}e.exports=options},697:(e,t,r)=>{const n=r(257);async function load(e,t,r){try{if(t===null||t===undefined||Object.keys(t).length===0){return await n(e,r)}else{return(await n(e,r))(t)}}catch(e){throw new Error(`Loading PostCSS Plugin failed: ${e.message}\n\n(@${r})`)}}async function plugins(e,t){let r=[];if(Array.isArray(e.plugins)){r=e.plugins.filter(Boolean)}else{r=Object.entries(e.plugins).filter((([,e])=>e!==false)).map((([e,r])=>load(e,r,t)));r=await Promise.all(r)}if(r.length&&r.length>0){r.forEach(((e,r)=>{if(e.default){e=e.default}if(e.postcss===true){e=e()}else if(e.postcss){e=e.postcss}if(!(typeof e==="object"&&Array.isArray(e.plugins)||typeof e==="object"&&e.postcssPlugin||typeof e==="function")){throw new TypeError(`Invalid PostCSS Plugin found at: plugins[${r}]\n\n(@${t})`)}}))}return r}e.exports=plugins},257:(e,t,r)=>{const{createRequire:n}=r(995);const{pathToFileURL:o}=r(136);const a=/\.[mc]?ts$/;let s;let c;let i=[];async function req(e,t=__filename){let r=n(t).resolve(e);try{return(await import(`${o(r)}?t=${Date.now()}`)).default}catch(e){if(!a.test(r)){throw e}}if(s===undefined){try{s=await import("tsx/cjs/api")}catch(e){i.push(e)}}if(s){let r=s.require(e,t);return r&&"__esModule"in r?r.default:r}if(c===undefined){try{c=(await import("jiti")).default}catch(e){i.push(e)}}if(c){return c(t,{interopDefault:true})(e)}throw new Error(`'tsx' or 'jiti' is required for the TypeScript configuration files. Make sure it is installed\nError: ${i.map((e=>e.message)).join("\n")}`)}e.exports=req},896:e=>{"use strict";e.exports=require("fs")},995:e=>{"use strict";e.exports=require("node:module")},760:e=>{"use strict";e.exports=require("node:path")},136:e=>{"use strict";e.exports=require("node:url")},857:e=>{"use strict";e.exports=require("os")},928:e=>{"use strict";e.exports=require("path")},16:e=>{"use strict";e.exports=require("url")},160:e=>{"use strict";e.exports=require("yaml")}};var __webpack_module_cache__={};function __nccwpck_require__(e){var t=__webpack_module_cache__[e];if(t!==undefined){return t.exports}var r=__webpack_module_cache__[e]={exports:{}};var n=true;try{__webpack_modules__[e](r,r.exports,__nccwpck_require__);n=false}finally{if(n)delete __webpack_module_cache__[e]}return r.exports}(()=>{var e=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__;var t;__nccwpck_require__.t=function(r,n){if(n&1)r=this(r);if(n&8)return r;if(typeof r==="object"&&r){if(n&4&&r.__esModule)return r;if(n&16&&typeof r.then==="function")return r}var o=Object.create(null);__nccwpck_require__.r(o);var a={};t=t||[null,e({}),e([]),e(e)];for(var s=n&2&&r;typeof s=="object"&&!~t.indexOf(s);s=e(s)){Object.getOwnPropertyNames(s).forEach((e=>a[e]=()=>r[e]))}a["default"]=()=>r;__nccwpck_require__.d(o,a);return o}})();(()=>{__nccwpck_require__.d=(e,t)=>{for(var r in t){if(__nccwpck_require__.o(t,r)&&!__nccwpck_require__.o(e,r)){Object.defineProperty(e,r,{enumerable:true,get:t[r]})}}}})();(()=>{__nccwpck_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})();(()=>{__nccwpck_require__.r=e=>{if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(e,"__esModule",{value:true})}})();if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var __webpack_exports__=__nccwpck_require__(109);module.exports=__webpack_exports__})();
@@ -1,20 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright Michael Ciniawsky <michael.ciniawsky@gmail.com>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1 +0,0 @@
1
- {"name":"postcss-load-config","author":"Michael Ciniawky <michael.ciniawsky@gmail.com>","version":"6.0.1","funding":[{"type":"opencollective","url":"https://opencollective.com/postcss/"},{"type":"github","url":"https://github.com/sponsors/ai"}],"license":"MIT","types":"index.d.ts"}
@@ -1,157 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- rspackRscLayerName: ()=>rspackRscLayerName,
28
- getExportNames: ()=>getExportNames,
29
- MODERN_RSC_INFO: ()=>MODERN_RSC_INFO,
30
- isCssModule: ()=>isCssModule,
31
- findRootIssuer: ()=>findRootIssuer,
32
- getRscBuildInfo: ()=>getRscBuildInfo,
33
- parseSource: ()=>parseSource,
34
- sharedData: ()=>sharedData,
35
- setBuildInfo: ()=>setBuildInfo,
36
- isServerModule: ()=>isServerModule,
37
- isClientModule: ()=>isClientModule,
38
- removeRscBuildInfo: ()=>removeRscBuildInfo,
39
- setRscBuildInfo: ()=>setRscBuildInfo
40
- });
41
- const utils_namespaceObject = require("@modern-js/utils");
42
- const core_namespaceObject = require("@swc/core");
43
- const rspackRscLayerName = "react-server";
44
- const MODERN_RSC_INFO = 'modernRscInfo';
45
- const sharedData = {
46
- store: new Map(),
47
- get (key) {
48
- return this.store.get(key);
49
- },
50
- set (key, value) {
51
- this.store.set(key, value);
52
- },
53
- clear () {
54
- this.store.clear();
55
- }
56
- };
57
- function setBuildInfo(mod, property) {
58
- if (!mod.buildInfo) mod.buildInfo = {};
59
- Object.assign(mod.buildInfo, property);
60
- }
61
- function setRscBuildInfo(mod, property) {
62
- if (!mod.buildInfo) mod.buildInfo = {};
63
- const rscBuildInfo = mod.buildInfo[MODERN_RSC_INFO] || {};
64
- Object.assign(rscBuildInfo, property);
65
- setBuildInfo(mod, {
66
- [MODERN_RSC_INFO]: rscBuildInfo
67
- });
68
- }
69
- function removeRscBuildInfo(mod) {
70
- delete mod.buildInfo?.[MODERN_RSC_INFO];
71
- }
72
- function getRscBuildInfo(mod) {
73
- return mod.buildInfo?.[MODERN_RSC_INFO];
74
- }
75
- function isCssModule(mod) {
76
- if (!mod) return false;
77
- return getRscBuildInfo(mod)?.isCssModule;
78
- }
79
- const parseSource = async (source)=>await (0, core_namespaceObject.parse)(source, {
80
- syntax: "typescript",
81
- tsx: true,
82
- dynamicImport: true
83
- });
84
- const getExportNames = async (ast, collectFuncOnly = false)=>{
85
- const exportNames = [];
86
- ast.body.forEach((node)=>{
87
- if ('ExportNamedDeclaration' === node.type) {
88
- const namedExport = node;
89
- namedExport.specifiers.forEach((specifier)=>{
90
- if ('ExportSpecifier' === specifier.type) exportNames.push(specifier.exported?.value || specifier.orig.value);
91
- });
92
- }
93
- if ('ExportDeclaration' === node.type) {
94
- if ('VariableDeclaration' === node.declaration.type) node.declaration.declarations.forEach((decl)=>{
95
- if ('Identifier' === decl.id.type) if (collectFuncOnly) {
96
- if (decl.init?.type === 'FunctionExpression' || decl.init?.type === 'ArrowFunctionExpression') exportNames.push(decl.id.value);
97
- } else exportNames.push(decl.id.value);
98
- });
99
- if ('ClassDeclaration' === node.declaration.type || 'FunctionDeclaration' === node.declaration.type) {
100
- if (node.declaration.identifier) exportNames.push(node.declaration.identifier.value);
101
- }
102
- }
103
- if ('ExportDefaultExpression' === node.type || 'ExportDefaultDeclaration' === node.type) exportNames.push('default');
104
- });
105
- return exportNames;
106
- };
107
- const checkDirective = async (ast, directive)=>{
108
- try {
109
- for(let i = 0; i < ast.body.length; i++){
110
- const node = ast.body[i];
111
- if ('ExpressionStatement' !== node.type) break;
112
- if ('StringLiteral' === node.expression.type && node.expression.value === directive) return true;
113
- }
114
- } catch (e) {
115
- utils_namespaceObject.logger.error(e);
116
- }
117
- return false;
118
- };
119
- const isServerModule = async (ast)=>checkDirective(ast, 'use server');
120
- const isClientModule = async (ast)=>checkDirective(ast, 'use client');
121
- function findRootIssuer(modulegraph, module) {
122
- const currentModule = module;
123
- const issuer = modulegraph.getIssuer(currentModule);
124
- if (!issuer) return currentModule;
125
- return findRootIssuer(modulegraph, issuer);
126
- }
127
- exports.MODERN_RSC_INFO = __webpack_exports__.MODERN_RSC_INFO;
128
- exports.findRootIssuer = __webpack_exports__.findRootIssuer;
129
- exports.getExportNames = __webpack_exports__.getExportNames;
130
- exports.getRscBuildInfo = __webpack_exports__.getRscBuildInfo;
131
- exports.isClientModule = __webpack_exports__.isClientModule;
132
- exports.isCssModule = __webpack_exports__.isCssModule;
133
- exports.isServerModule = __webpack_exports__.isServerModule;
134
- exports.parseSource = __webpack_exports__.parseSource;
135
- exports.removeRscBuildInfo = __webpack_exports__.removeRscBuildInfo;
136
- exports.rspackRscLayerName = __webpack_exports__.rspackRscLayerName;
137
- exports.setBuildInfo = __webpack_exports__.setBuildInfo;
138
- exports.setRscBuildInfo = __webpack_exports__.setRscBuildInfo;
139
- exports.sharedData = __webpack_exports__.sharedData;
140
- for(var __rspack_i in __webpack_exports__)if (-1 === [
141
- "MODERN_RSC_INFO",
142
- "findRootIssuer",
143
- "getExportNames",
144
- "getRscBuildInfo",
145
- "isClientModule",
146
- "isCssModule",
147
- "isServerModule",
148
- "parseSource",
149
- "removeRscBuildInfo",
150
- "rspackRscLayerName",
151
- "setBuildInfo",
152
- "setRscBuildInfo",
153
- "sharedData"
154
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
155
- Object.defineProperty(exports, '__esModule', {
156
- value: true
157
- });
@@ -1,169 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
18
- };
19
- })();
20
- (()=>{
21
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
- })();
23
- (()=>{
24
- __webpack_require__.r = (exports1)=>{
25
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
- value: 'Module'
27
- });
28
- Object.defineProperty(exports1, '__esModule', {
29
- value: true
30
- });
31
- };
32
- })();
33
- var __webpack_exports__ = {};
34
- __webpack_require__.r(__webpack_exports__);
35
- __webpack_require__.d(__webpack_exports__, {
36
- rsbuildRscPlugin: ()=>rsbuildRscPlugin
37
- });
38
- const external_node_path_namespaceObject = require("node:path");
39
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
40
- const fs_extra_namespaceObject = require("@modern-js/utils/fs-extra");
41
- var fs_extra_default = /*#__PURE__*/ __webpack_require__.n(fs_extra_namespaceObject);
42
- const core_namespaceObject = require("@rsbuild/core");
43
- const external_common_js_namespaceObject = require("../common.js");
44
- const external_rspack_rsc_client_plugin_js_namespaceObject = require("./rspack-rsc-client-plugin.js");
45
- const external_rspack_rsc_server_plugin_js_namespaceObject = require("./rspack-rsc-server-plugin.js");
46
- const CSS_RULE_NAMES = [
47
- 'less',
48
- 'css',
49
- 'scss',
50
- 'sass'
51
- ];
52
- const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
53
- const checkReactVersionAtLeast19 = async (appDir)=>{
54
- const packageJsonPath = external_node_path_default().resolve(appDir, 'package.json');
55
- const packageJson = await fs_extra_default().readJSON(packageJsonPath);
56
- if (!packageJson.dependencies) return false;
57
- const { dependencies } = packageJson;
58
- const reactVersion = dependencies.react;
59
- const reactDomVersion = dependencies['react-dom'];
60
- if (!reactVersion || !reactDomVersion) return false;
61
- const cleanVersion = (version)=>version.replace(/[\^~]/g, '');
62
- const reactVersionParts = cleanVersion(reactVersion).split('.');
63
- const reactDomVersionParts = cleanVersion(reactDomVersion).split('.');
64
- const reactMajor = parseInt(reactVersionParts[0], 10);
65
- const reactDomMajor = parseInt(reactDomVersionParts[0], 10);
66
- if (Number.isNaN(reactMajor) || Number.isNaN(reactDomMajor)) return false;
67
- return reactMajor >= 19 && reactDomMajor >= 19;
68
- };
69
- const rsbuildRscPlugin = ({ appDir, rscClientRuntimePath, rscServerRuntimePath, internalDirectory })=>({
70
- name: 'builder:rsc-rsbuild-plugin',
71
- setup (api) {
72
- api.modifyBundlerChain({
73
- handler: async (chain, { isServer, CHAIN_ID, isWebWorker })=>{
74
- if (!await checkReactVersionAtLeast19(appDir)) {
75
- core_namespaceObject.logger.error('Enable react server component, please make sure the react and react-dom versions are greater than or equal to 19.0.0');
76
- process.exit(1);
77
- }
78
- const entryPath2Name = new Map();
79
- for (const [name, entry] of Object.entries(chain.entryPoints.entries()))entry.values().forEach((value)=>{
80
- entryPath2Name.set(value, name);
81
- });
82
- const jsHandler = ()=>{
83
- const originalJsRule = chain.module.rules.get(CHAIN_ID.RULE.JS);
84
- if (!originalJsRule) throw new Error('Original JS rule not found when setup RSC plugin.');
85
- const originalJsMainRule = originalJsRule.oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN);
86
- if (!originalJsMainRule) throw new Error('Original JS main rule not found when setup RSC plugin.');
87
- const useBabel = originalJsMainRule.uses.has(CHAIN_ID.USE.BABEL);
88
- const jsLoader = useBabel ? CHAIN_ID.USE.BABEL : CHAIN_ID.USE.SWC;
89
- const jsLoaderOptions = originalJsMainRule.use(jsLoader).get('options');
90
- const jsLoaderPath = originalJsMainRule.use(jsLoader).get('loader');
91
- originalJsRule.oneOfs.delete(CHAIN_ID.ONE_OF.JS_MAIN);
92
- chain.module.rule(CHAIN_ID.RULE.JS).oneOf('rsc-server').issuerLayer(external_common_js_namespaceObject.rspackRscLayerName).exclude.add(/universal[/\\]async_storage/).end().use('rsc-server-loader').loader(require.resolve('../rsc-server-loader')).options({
93
- entryPath2Name,
94
- appDir,
95
- runtimePath: rscServerRuntimePath,
96
- internalDirectory
97
- }).end().use(jsLoader).loader(jsLoaderPath).options(jsLoaderOptions).end().end().oneOf('rsc-ssr').exclude.add(/universal[/\\]async_storage/).end().use('rsc-ssr-loader').loader(require.resolve('../rsc-ssr-loader')).options({
98
- entryPath2Name,
99
- internalDirectory
100
- }).end().use(jsLoader).loader(jsLoaderPath).options(jsLoaderOptions).end().end();
101
- };
102
- const layerHandler = ()=>{
103
- const routesFileReg = new RegExp(`${internalDirectory.replace(/[/\\]/g, '[/\\\\]')}[/\\\\][^/\\\\]*[/\\\\]routes`);
104
- chain.module.rule('server-module').resource([
105
- /render[/\\].*[/\\]server[/\\]rsc/,
106
- /AppProxy/,
107
- routesFileReg
108
- ]).layer(external_common_js_namespaceObject.rspackRscLayerName).end();
109
- chain.module.rule(external_common_js_namespaceObject.rspackRscLayerName).issuerLayer(external_common_js_namespaceObject.rspackRscLayerName).resolve.conditionNames.add(external_common_js_namespaceObject.rspackRscLayerName).add('...');
110
- chain.module.rule('rsc-common').resource([
111
- /universal[/\\]async_storage/
112
- ]).layer('rsc-common');
113
- };
114
- const flightCssHandler = ()=>{
115
- CSS_RULE_NAMES.forEach((ruleName)=>{
116
- const rule = chain.module.rules.get(ruleName);
117
- if (rule) chain.module.rule(ruleName).use('custom-loader').before('ignore-css').loader(require.resolve('../rsc-css-loader'));
118
- });
119
- };
120
- const addServerRscPlugin = ()=>{
121
- const ServerPlugin = external_rspack_rsc_server_plugin_js_namespaceObject.RscServerPlugin;
122
- chain.plugin('rsc-server-plugin').use(ServerPlugin, [
123
- {
124
- entryPath2Name
125
- }
126
- ]);
127
- };
128
- const addRscClientLoader = ()=>{
129
- chain.module.rule('js').use('rsc-client-loader').loader(require.resolve('../rsc-client-loader')).before('babel').options({
130
- callServerImport: rscClientRuntimePath,
131
- registerImport: rscClientRuntimePath
132
- }).end();
133
- };
134
- const addRscClientPlugin = ()=>{
135
- const ClientPlugin = external_rspack_rsc_client_plugin_js_namespaceObject.RspackRscClientPlugin;
136
- chain.plugin('rsc-client-plugin').use(ClientPlugin);
137
- };
138
- if (isServer) {
139
- chain.name('server');
140
- layerHandler();
141
- flightCssHandler();
142
- jsHandler();
143
- addServerRscPlugin();
144
- } else if (!isWebWorker) {
145
- chain.name('client');
146
- chain.dependencies([
147
- 'server'
148
- ]);
149
- const entries = chain.entryPoints.entries();
150
- for (const entryName of Object.keys(entries)){
151
- const entryPoint = chain.entry(entryName);
152
- const code = `window.__MODERN_JS_ENTRY_NAME="${entryName}";`;
153
- entryPoint.add(createVirtualModule(code));
154
- }
155
- addRscClientLoader();
156
- addRscClientPlugin();
157
- }
158
- },
159
- order: 'post'
160
- });
161
- }
162
- });
163
- exports.rsbuildRscPlugin = __webpack_exports__.rsbuildRscPlugin;
164
- for(var __rspack_i in __webpack_exports__)if (-1 === [
165
- "rsbuildRscPlugin"
166
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
167
- Object.defineProperty(exports, '__esModule', {
168
- value: true
169
- });