@bleedingdev/modern-js-builder 3.9.0-ultramodern.2 → 3.9.0-ultramodern.21
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.
- package/dist/cjs/createBuilder.js +15 -6
- package/dist/cjs/index.js +6 -2
- package/dist/cjs/plugins/environmentDefaults.js +7 -8
- package/dist/cjs/plugins/manifest.js +1 -1
- package/dist/cjs/plugins/rscConfig.js +1 -4
- package/dist/cjs/shared/parseCommonConfig.js +19 -4
- package/dist/cjs/shared/rsc/rscClientBrowserFallback.js +68 -0
- package/dist/cjs/shared/tsgo.js +274 -0
- package/dist/esm/createBuilder.mjs +16 -7
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/plugins/environmentDefaults.mjs +7 -8
- package/dist/esm/plugins/manifest.mjs +1 -1
- package/dist/esm/plugins/rscConfig.mjs +1 -4
- package/dist/esm/shared/parseCommonConfig.mjs +20 -5
- package/dist/esm/shared/rsc/rscClientBrowserFallback.mjs +20 -0
- package/dist/esm/shared/tsgo.mjs +219 -0
- package/dist/esm-node/createBuilder.mjs +16 -7
- package/dist/esm-node/index.mjs +1 -0
- package/dist/esm-node/plugins/environmentDefaults.mjs +7 -8
- package/dist/esm-node/plugins/manifest.mjs +1 -1
- package/dist/esm-node/plugins/rscConfig.mjs +1 -4
- package/dist/esm-node/shared/parseCommonConfig.mjs +20 -5
- package/dist/esm-node/shared/rsc/rscClientBrowserFallback.mjs +25 -0
- package/dist/esm-node/shared/tsgo.mjs +220 -0
- package/dist/types/css-minimizer/LICENSE +20 -0
- package/dist/types/css-minimizer/index.d.ts +154 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/sass/LICENSE +21 -0
- package/dist/types/sass/index.d.ts +36 -0
- package/dist/types/sass/loader.d.ts +957 -0
- package/dist/types/shared/rsc/rscClientBrowserFallback.d.ts +2 -0
- package/dist/types/shared/tsgo.d.ts +27 -0
- package/dist/types/types.d.ts +6 -3
- package/package.json +13 -11
- package/dist/cjs/shared/rsc/rscDisabledClientBrowserRuntime.js +0 -69
- package/dist/cjs/shared/rsc/rscDisabledClientEdgeRuntime.js +0 -61
- package/dist/cjs/shared/rsc/rscDisabledClientNodeRuntime.js +0 -65
- package/dist/cjs/shared/rsc/rscDisabledRuntime.js +0 -140
- package/dist/cjs/shared/rsc/rscDisabledRuntimeError.js +0 -42
- package/dist/cjs/shared/rsc/rscDisabledServerEdgeRuntime.js +0 -93
- package/dist/cjs/shared/rsc/rscDisabledServerNodeRuntime.js +0 -101
- package/dist/esm/shared/rsc/rscDisabledClientBrowserRuntime.mjs +0 -10
- package/dist/esm/shared/rsc/rscDisabledClientEdgeRuntime.mjs +0 -8
- package/dist/esm/shared/rsc/rscDisabledClientNodeRuntime.mjs +0 -9
- package/dist/esm/shared/rsc/rscDisabledRuntime.mjs +0 -92
- package/dist/esm/shared/rsc/rscDisabledRuntimeError.mjs +0 -4
- package/dist/esm/shared/rsc/rscDisabledServerEdgeRuntime.mjs +0 -16
- package/dist/esm/shared/rsc/rscDisabledServerNodeRuntime.mjs +0 -18
- package/dist/esm-node/shared/rsc/rscDisabledClientBrowserRuntime.mjs +0 -11
- package/dist/esm-node/shared/rsc/rscDisabledClientEdgeRuntime.mjs +0 -9
- package/dist/esm-node/shared/rsc/rscDisabledClientNodeRuntime.mjs +0 -10
- package/dist/esm-node/shared/rsc/rscDisabledRuntime.mjs +0 -97
- package/dist/esm-node/shared/rsc/rscDisabledRuntimeError.mjs +0 -5
- package/dist/esm-node/shared/rsc/rscDisabledServerEdgeRuntime.mjs +0 -17
- package/dist/esm-node/shared/rsc/rscDisabledServerNodeRuntime.mjs +0 -19
- package/dist/types/shared/rsc/rscDisabledClientBrowserRuntime.d.ts +0 -9
- package/dist/types/shared/rsc/rscDisabledClientEdgeRuntime.d.ts +0 -7
- package/dist/types/shared/rsc/rscDisabledClientNodeRuntime.d.ts +0 -8
- package/dist/types/shared/rsc/rscDisabledRuntime.d.ts +0 -2
- package/dist/types/shared/rsc/rscDisabledRuntimeError.d.ts +0 -1
- package/dist/types/shared/rsc/rscDisabledServerEdgeRuntime.d.ts +0 -15
- package/dist/types/shared/rsc/rscDisabledServerNodeRuntime.d.ts +0 -17
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
function rscClientBrowserFallbackPlugin() {
|
|
3
|
+
return {
|
|
4
|
+
name: 'builder:rsc-client-browser-fallback',
|
|
5
|
+
setup (api) {
|
|
6
|
+
let emptyModulePath;
|
|
7
|
+
try {
|
|
8
|
+
emptyModulePath = require.resolve('./rscEmptyModule');
|
|
9
|
+
} catch {
|
|
10
|
+
emptyModulePath = path.resolve(__dirname, 'rscEmptyModule');
|
|
11
|
+
}
|
|
12
|
+
api.modifyRspackConfig((config)=>{
|
|
13
|
+
config.resolve ??= {};
|
|
14
|
+
config.resolve.fallback ??= {};
|
|
15
|
+
config.resolve.fallback['react-server-dom-rspack/client.browser'] = emptyModulePath;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export { rscClientBrowserFallbackPlugin };
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import node_fs from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import node_path from "node:path";
|
|
5
|
+
import { json5 } from "@modern-js/utils";
|
|
6
|
+
const builderRequire = createRequire(import.meta.url);
|
|
7
|
+
const STABLE_TSGO_PACKAGE = "typescript/package.json";
|
|
8
|
+
const NATIVE_PREVIEW_TSGO_PACKAGE = "@typescript/native-preview/package.json";
|
|
9
|
+
const TSGO_CHECKER_DIR = node_path.join('.modern-js', 'tsgo');
|
|
10
|
+
const tryResolve = (request, rootPath)=>{
|
|
11
|
+
try {
|
|
12
|
+
return builderRequire.resolve(request, {
|
|
13
|
+
paths: [
|
|
14
|
+
rootPath
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
} catch {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const readPackageMajorVersion = (packageJsonPath)=>{
|
|
22
|
+
try {
|
|
23
|
+
const packageJson = JSON.parse(node_fs.readFileSync(packageJsonPath, 'utf8'));
|
|
24
|
+
const major = Number.parseInt(String(packageJson.version).split('.')[0], 10);
|
|
25
|
+
return Number.isFinite(major) ? major : void 0;
|
|
26
|
+
} catch {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const resolveTsgoPackagePath = (rootPath)=>{
|
|
31
|
+
const stableTypeScriptPath = tryResolve(STABLE_TSGO_PACKAGE, rootPath);
|
|
32
|
+
if (stableTypeScriptPath && (readPackageMajorVersion(stableTypeScriptPath) ?? 0) >= 7) return stableTypeScriptPath;
|
|
33
|
+
const previewFromProject = tryResolve(NATIVE_PREVIEW_TSGO_PACKAGE, rootPath);
|
|
34
|
+
if (previewFromProject) return previewFromProject;
|
|
35
|
+
try {
|
|
36
|
+
return builderRequire.resolve(NATIVE_PREVIEW_TSGO_PACKAGE);
|
|
37
|
+
} catch {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const toPosixPath = (input)=>input.replaceAll(node_path.sep, '/');
|
|
42
|
+
const asTsConfigPath = (request)=>{
|
|
43
|
+
if (node_path.extname(request)) return [
|
|
44
|
+
request
|
|
45
|
+
];
|
|
46
|
+
return [
|
|
47
|
+
request,
|
|
48
|
+
`${request}.json`
|
|
49
|
+
];
|
|
50
|
+
};
|
|
51
|
+
const resolveExtends = (request, configDirectory)=>{
|
|
52
|
+
const configRequire = createRequire(node_path.join(configDirectory, 'tsconfig.json'));
|
|
53
|
+
for (const candidate of asTsConfigPath(request)){
|
|
54
|
+
if (candidate.startsWith('.') || node_path.isAbsolute(candidate)) {
|
|
55
|
+
const resolved = node_path.resolve(configDirectory, candidate);
|
|
56
|
+
if (node_fs.existsSync(resolved)) return resolved;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return configRequire.resolve(candidate);
|
|
61
|
+
} catch {}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const PATH_COMPILER_OPTIONS = [
|
|
65
|
+
'rootDir',
|
|
66
|
+
'outDir',
|
|
67
|
+
'declarationDir'
|
|
68
|
+
];
|
|
69
|
+
const absolutiseConfigPaths = (compilerOptions, configDirectory)=>{
|
|
70
|
+
if (!compilerOptions) return {};
|
|
71
|
+
const resolved = {
|
|
72
|
+
...compilerOptions
|
|
73
|
+
};
|
|
74
|
+
for (const option of PATH_COMPILER_OPTIONS){
|
|
75
|
+
const value = resolved[option];
|
|
76
|
+
if ('string' == typeof value && !node_path.isAbsolute(value)) resolved[option] = node_path.resolve(configDirectory, value);
|
|
77
|
+
}
|
|
78
|
+
return resolved;
|
|
79
|
+
};
|
|
80
|
+
const readTsConfig = (configFile, visited = new Set())=>{
|
|
81
|
+
if (visited.has(configFile) || !node_fs.existsSync(configFile)) return {};
|
|
82
|
+
visited.add(configFile);
|
|
83
|
+
const config = json5.parse(node_fs.readFileSync(configFile, 'utf8'));
|
|
84
|
+
const configDirectory = node_path.dirname(configFile);
|
|
85
|
+
const extendsList = Array.isArray(config.extends) ? config.extends : config.extends ? [
|
|
86
|
+
config.extends
|
|
87
|
+
] : [];
|
|
88
|
+
const baseConfig = extendsList.reduce((merged, request)=>{
|
|
89
|
+
const resolved = resolveExtends(request, configDirectory);
|
|
90
|
+
if (!resolved) return merged;
|
|
91
|
+
const parentConfig = readTsConfig(resolved, visited);
|
|
92
|
+
return {
|
|
93
|
+
...merged,
|
|
94
|
+
compilerOptions: {
|
|
95
|
+
...merged.compilerOptions ?? {},
|
|
96
|
+
...parentConfig.compilerOptions ?? {}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}, {});
|
|
100
|
+
return {
|
|
101
|
+
...baseConfig,
|
|
102
|
+
compilerOptions: {
|
|
103
|
+
...baseConfig.compilerOptions ?? {},
|
|
104
|
+
...absolutiseConfigPaths(config.compilerOptions, configDirectory)
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
const readProjectReferences = (configFile)=>{
|
|
109
|
+
if (!node_fs.existsSync(configFile)) return [];
|
|
110
|
+
const config = json5.parse(node_fs.readFileSync(configFile, 'utf8'));
|
|
111
|
+
if (!Array.isArray(config.references)) return [];
|
|
112
|
+
const configDirectory = node_path.dirname(configFile);
|
|
113
|
+
return config.references.filter((reference)=>'string' == typeof reference?.path).map((reference)=>({
|
|
114
|
+
...reference,
|
|
115
|
+
path: toPosixPath(node_path.resolve(configDirectory, reference.path))
|
|
116
|
+
}));
|
|
117
|
+
};
|
|
118
|
+
const toRelativeConfigPath = (fromDirectory, target)=>{
|
|
119
|
+
const relative = toPosixPath(node_path.relative(fromDirectory, target));
|
|
120
|
+
if (relative.startsWith('.')) return relative;
|
|
121
|
+
return `./${relative}`;
|
|
122
|
+
};
|
|
123
|
+
const writeFileIfChanged = (file, content)=>{
|
|
124
|
+
if (node_fs.existsSync(file) && node_fs.readFileSync(file, 'utf8') === content) return;
|
|
125
|
+
node_fs.writeFileSync(file, content);
|
|
126
|
+
};
|
|
127
|
+
const defaultTsgoCheckerConfigFile = (configFile)=>{
|
|
128
|
+
const hash = createHash('sha1').update(configFile).digest('hex').slice(0, 10);
|
|
129
|
+
return node_path.join(node_path.dirname(configFile), TSGO_CHECKER_DIR, `tsconfig.${hash}.json`);
|
|
130
|
+
};
|
|
131
|
+
const createTsgoCheckerConfig = (configFile, checkerConfigFile = defaultTsgoCheckerConfigFile(configFile))=>{
|
|
132
|
+
const configDirectory = node_path.dirname(configFile);
|
|
133
|
+
const checkerConfigDirectory = node_path.dirname(checkerConfigFile);
|
|
134
|
+
const tsConfig = readTsConfig(configFile);
|
|
135
|
+
const compilerOptions = {
|
|
136
|
+
baseUrl: null
|
|
137
|
+
};
|
|
138
|
+
const declaredRootDir = tsConfig.compilerOptions?.rootDir;
|
|
139
|
+
if ('string' == typeof declaredRootDir) compilerOptions.rootDir = toPosixPath(declaredRootDir);
|
|
140
|
+
else if (tsConfig.compilerOptions?.composite === true) compilerOptions.rootDir = toPosixPath(configDirectory);
|
|
141
|
+
const moduleResolution = String(tsConfig.compilerOptions?.moduleResolution).toLowerCase();
|
|
142
|
+
if ([
|
|
143
|
+
'node',
|
|
144
|
+
'node10'
|
|
145
|
+
].includes(moduleResolution)) compilerOptions.moduleResolution = null;
|
|
146
|
+
const references = readProjectReferences(configFile);
|
|
147
|
+
const checkerConfig = {
|
|
148
|
+
extends: toRelativeConfigPath(checkerConfigDirectory, configFile),
|
|
149
|
+
compilerOptions,
|
|
150
|
+
...references.length > 0 ? {
|
|
151
|
+
references
|
|
152
|
+
} : {}
|
|
153
|
+
};
|
|
154
|
+
node_fs.mkdirSync(checkerConfigDirectory, {
|
|
155
|
+
recursive: true
|
|
156
|
+
});
|
|
157
|
+
writeFileIfChanged(checkerConfigFile, `${JSON.stringify(checkerConfig, null, 2)}\n`);
|
|
158
|
+
return checkerConfigFile;
|
|
159
|
+
};
|
|
160
|
+
const refreshTsgoCheckerConfig = (checkerConfigFile)=>{
|
|
161
|
+
const checkerConfigDirectory = node_path.dirname(checkerConfigFile);
|
|
162
|
+
if ('tsgo' !== node_path.basename(checkerConfigDirectory) || '.modern-js' !== node_path.basename(node_path.dirname(checkerConfigDirectory)) || !node_fs.existsSync(checkerConfigFile)) return;
|
|
163
|
+
let checkerConfig;
|
|
164
|
+
try {
|
|
165
|
+
checkerConfig = json5.parse(node_fs.readFileSync(checkerConfigFile, 'utf8'));
|
|
166
|
+
} catch {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if ('string' != typeof checkerConfig.extends) return;
|
|
170
|
+
const projectConfigFile = node_path.resolve(checkerConfigDirectory, checkerConfig.extends);
|
|
171
|
+
if (node_fs.existsSync(projectConfigFile)) try {
|
|
172
|
+
createTsgoCheckerConfig(projectConfigFile, checkerConfigFile);
|
|
173
|
+
} catch {}
|
|
174
|
+
return projectConfigFile;
|
|
175
|
+
};
|
|
176
|
+
const normalizeTsgoConfig = (config, rootPath)=>{
|
|
177
|
+
const { typescript } = config;
|
|
178
|
+
if (typescript?.tsgo === false) return config;
|
|
179
|
+
const compilerOptions = {
|
|
180
|
+
...typescript?.configOverwrite?.compilerOptions ?? {},
|
|
181
|
+
baseUrl: null
|
|
182
|
+
};
|
|
183
|
+
if ([
|
|
184
|
+
'node',
|
|
185
|
+
'node10'
|
|
186
|
+
].includes(String(compilerOptions.moduleResolution).toLowerCase())) compilerOptions.moduleResolution = null;
|
|
187
|
+
config.typescript = {
|
|
188
|
+
...typescript,
|
|
189
|
+
configOverwrite: {
|
|
190
|
+
...typescript?.configOverwrite ?? {},
|
|
191
|
+
compilerOptions
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
if (typescript?.configFile) config.typescript.configFile = createTsgoCheckerConfig(node_path.resolve(rootPath, typescript.configFile));
|
|
195
|
+
return config;
|
|
196
|
+
};
|
|
197
|
+
const withTsgoDefaults = (userOptions, rootPath)=>{
|
|
198
|
+
const tsgoPath = resolveTsgoPackagePath(rootPath);
|
|
199
|
+
const userChain = userOptions ? Array.isArray(userOptions) ? userOptions : [
|
|
200
|
+
userOptions
|
|
201
|
+
] : [];
|
|
202
|
+
return [
|
|
203
|
+
{
|
|
204
|
+
typescript: tsgoPath ? {
|
|
205
|
+
tsgo: true,
|
|
206
|
+
typescriptPath: tsgoPath
|
|
207
|
+
} : {
|
|
208
|
+
tsgo: true
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
...userChain,
|
|
212
|
+
(config)=>{
|
|
213
|
+
const { typescript } = config;
|
|
214
|
+
if (typescript?.tsgo === false && typescript.typescriptPath === tsgoPath) typescript.typescriptPath = tryResolve("typescript", rootPath);
|
|
215
|
+
return normalizeTsgoConfig(config, rootPath);
|
|
216
|
+
}
|
|
217
|
+
];
|
|
218
|
+
};
|
|
219
|
+
export { refreshTsgoCheckerConfig, withTsgoDefaults };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { createRsbuild } from "@rsbuild/core";
|
|
2
|
+
import { createRsbuild, mergeRsbuildConfig } from "@rsbuild/core";
|
|
3
3
|
import { getRscPlugins } from "./plugins/rscConfig.mjs";
|
|
4
4
|
import { parseCommonConfig } from "./shared/parseCommonConfig.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { rscClientBrowserFallbackPlugin } from "./shared/rsc/rscClientBrowserFallback.mjs";
|
|
6
6
|
async function parseConfig(builderConfig, options) {
|
|
7
7
|
builderConfig.performance ??= {};
|
|
8
8
|
builderConfig.performance.buildCache ??= true;
|
|
@@ -30,10 +30,7 @@ async function parseConfig(builderConfig, options) {
|
|
|
30
30
|
const rscEnvironments = 'object' == typeof rscConfig ? rscConfig.environments : void 0;
|
|
31
31
|
const rscPlugins = await getRscPlugins(enableRsc, options.internalDirectory, rscEnvironments);
|
|
32
32
|
rsbuildPlugins.push(...rscPlugins);
|
|
33
|
-
} else
|
|
34
|
-
...rsbuildConfig.plugins ?? [],
|
|
35
|
-
rscDisabledRuntimePlugin()
|
|
36
|
-
];
|
|
33
|
+
} else rsbuildPlugins.push(rscClientBrowserFallbackPlugin());
|
|
37
34
|
return {
|
|
38
35
|
rsbuildConfig,
|
|
39
36
|
rsbuildPlugins
|
|
@@ -51,7 +48,19 @@ async function createRspackBuilder(options) {
|
|
|
51
48
|
];
|
|
52
49
|
const rsbuild = await createRsbuild({
|
|
53
50
|
cwd,
|
|
54
|
-
rsbuildConfig
|
|
51
|
+
rsbuildConfig: mergeRsbuildConfig({
|
|
52
|
+
tools: {
|
|
53
|
+
rspack: {
|
|
54
|
+
module: {
|
|
55
|
+
parser: {
|
|
56
|
+
javascript: {
|
|
57
|
+
createRequire: true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}, rsbuildConfig)
|
|
55
64
|
});
|
|
56
65
|
return {
|
|
57
66
|
...rsbuild
|
package/dist/esm-node/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
export { createRspackBuilder as createBuilder, parseConfig as parseRspackConfig } from "./createBuilder.mjs";
|
|
3
3
|
export { logger } from "@rsbuild/core";
|
|
4
|
+
export { refreshTsgoCheckerConfig } from "./shared/tsgo.mjs";
|
|
4
5
|
export { RUNTIME_CHUNK_NAME, RUNTIME_CHUNK_REGEX, SERVICE_WORKER_ENVIRONMENT_NAME, castArray, isHtmlDisabled } from "./shared/utils.mjs";
|
|
@@ -57,14 +57,13 @@ const pluginEnvironmentDefaults = (distPath = {})=>({
|
|
|
57
57
|
});
|
|
58
58
|
api.modifyBundlerChain(async (chain, { environment })=>{
|
|
59
59
|
const isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
|
|
60
|
-
if (isServiceWorker
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
60
|
+
if (isServiceWorker) {
|
|
61
|
+
const library = chain.output.get('library');
|
|
62
|
+
chain.output.library({
|
|
63
|
+
...'object' == typeof library && !Array.isArray(library) ? library : {},
|
|
64
|
+
type: true === chain.output.get('module') ? 'module' : 'commonjs2'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
68
67
|
});
|
|
69
68
|
}
|
|
70
69
|
});
|
|
@@ -9,7 +9,7 @@ const pluginManifest = ()=>({
|
|
|
9
9
|
chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
|
|
10
10
|
{
|
|
11
11
|
fileName: 'web' === target ? 'asset-manifest.json' : `asset-manifest-${target}.json`,
|
|
12
|
-
publicPath,
|
|
12
|
+
publicPath: 'string' == typeof publicPath ? publicPath : void 0,
|
|
13
13
|
generate: generateManifest
|
|
14
14
|
}
|
|
15
15
|
]);
|
|
@@ -7,9 +7,7 @@ var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(imp
|
|
|
7
7
|
const ASYNC_STORAGE_PATTERN = /universal[/\\]async_storage/;
|
|
8
8
|
const SERVER_LOADER_ENTRY_PATTERN = /[/\\](?:server-loader-combined|route-server-loaders)\.js$/;
|
|
9
9
|
const RENDER_RSC_SOURCE_PATTERN = /render[/\\].*[/\\]server[/\\]rsc/;
|
|
10
|
-
const RENDER_RSC_RSLIB_ENTRY_PATTERN = /render[/\\]dist[/\\]esm[/\\]rsc(
|
|
11
|
-
const RENDER_RSC_RUNTIME = '@modern-js/render/rsc';
|
|
12
|
-
const RENDER_RSC_WORKER_RUNTIME = '@modern-js/render/rsc-worker';
|
|
10
|
+
const RENDER_RSC_RSLIB_ENTRY_PATTERN = /render[/\\]dist[/\\]esm[/\\]rsc(?:\.edge)?\.mjs$/;
|
|
13
11
|
const RSC_COMMON_LAYER = 'rsc-common';
|
|
14
12
|
const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
|
|
15
13
|
const ROUTE_DATA_FILE_PATTERN = /[/\\]routes[/\\](?:.*[/\\])?(?:layout|page|\$)\.(?:loader|data)\.[tj]sx?(?:\?.*)?$/;
|
|
@@ -34,7 +32,6 @@ function pluginRscConfig() {
|
|
|
34
32
|
api.modifyBundlerChain({
|
|
35
33
|
handler: (chain, { isServer })=>{
|
|
36
34
|
if (isServer) {
|
|
37
|
-
chain.resolve.alias.set(`${RENDER_RSC_RUNTIME}$`, RENDER_RSC_WORKER_RUNTIME);
|
|
38
35
|
let emptyModulePath;
|
|
39
36
|
try {
|
|
40
37
|
emptyModulePath = require.resolve('../shared/rsc/rscEmptyModule');
|
|
@@ -11,7 +11,8 @@ import { pluginGlobalVars } from "../plugins/globalVars.mjs";
|
|
|
11
11
|
import { pluginHtmlMinifierTerser } from "../plugins/htmlMinify.mjs";
|
|
12
12
|
import { pluginRuntimeChunk } from "../plugins/runtimeChunk.mjs";
|
|
13
13
|
import { transformToRsbuildServerOptions } from "./devServer.mjs";
|
|
14
|
-
import {
|
|
14
|
+
import { withTsgoDefaults } from "./tsgo.mjs";
|
|
15
|
+
import { NODE_MODULES_REGEX, SERVICE_WORKER_ENVIRONMENT_NAME } from "./utils.mjs";
|
|
15
16
|
const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
|
|
16
17
|
const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
|
|
17
18
|
const DEFAULT_CSS_MINIFIER_OPTIONS = {
|
|
@@ -136,7 +137,7 @@ async function parseCommonConfig(builderConfig, options) {
|
|
|
136
137
|
if (!disableTsChecker) {
|
|
137
138
|
const { pluginTypeCheck } = await import("@rsbuild/plugin-type-check");
|
|
138
139
|
rsbuildPlugins.push(pluginTypeCheck({
|
|
139
|
-
tsCheckerOptions: tsChecker
|
|
140
|
+
tsCheckerOptions: withTsgoDefaults(tsChecker, options?.cwd ?? process.cwd())
|
|
140
141
|
}));
|
|
141
142
|
}
|
|
142
143
|
if (convertToRem) {
|
|
@@ -152,9 +153,23 @@ async function parseCommonConfig(builderConfig, options) {
|
|
|
152
153
|
const { pluginSourceBuild } = await import("@rsbuild/plugin-source-build");
|
|
153
154
|
rsbuildPlugins.push(pluginSourceBuild(true === sourceBuild ? {} : sourceBuild));
|
|
154
155
|
}
|
|
155
|
-
rsbuildPlugins.push(pluginReact(
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
rsbuildPlugins.push(pluginReact());
|
|
157
|
+
if (!options?.disableReactCompiler && void 0 !== reactCompiler) rsbuildPlugins.push({
|
|
158
|
+
name: 'builder:react-compiler',
|
|
159
|
+
setup (api) {
|
|
160
|
+
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>'web' === config.output.target && name !== SERVICE_WORKER_ENVIRONMENT_NAME ? mergeEnvironmentConfig({
|
|
161
|
+
tools: {
|
|
162
|
+
swc: {
|
|
163
|
+
jsc: {
|
|
164
|
+
transform: {
|
|
165
|
+
reactCompiler
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}, config) : config);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
158
173
|
if (!disableSvgr) {
|
|
159
174
|
const { pluginSvgr } = await import("@rsbuild/plugin-svgr");
|
|
160
175
|
rsbuildPlugins.push(pluginSvgr({
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import __rslib_shim_module__ from "node:module";
|
|
2
|
+
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
5
|
+
import { dirname as __rspack_dirname } from "node:path";
|
|
6
|
+
var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
7
|
+
function rscClientBrowserFallbackPlugin() {
|
|
8
|
+
return {
|
|
9
|
+
name: 'builder:rsc-client-browser-fallback',
|
|
10
|
+
setup (api) {
|
|
11
|
+
let emptyModulePath;
|
|
12
|
+
try {
|
|
13
|
+
emptyModulePath = require.resolve('./rscEmptyModule');
|
|
14
|
+
} catch {
|
|
15
|
+
emptyModulePath = path.resolve(__rspack_import_meta_dirname__, 'rscEmptyModule');
|
|
16
|
+
}
|
|
17
|
+
api.modifyRspackConfig((config)=>{
|
|
18
|
+
config.resolve ??= {};
|
|
19
|
+
config.resolve.fallback ??= {};
|
|
20
|
+
config.resolve.fallback['react-server-dom-rspack/client.browser'] = emptyModulePath;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export { rscClientBrowserFallbackPlugin };
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import node_fs from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import node_path from "node:path";
|
|
6
|
+
import { json5 } from "@modern-js/utils";
|
|
7
|
+
const builderRequire = createRequire(import.meta.url);
|
|
8
|
+
const STABLE_TSGO_PACKAGE = "typescript/package.json";
|
|
9
|
+
const NATIVE_PREVIEW_TSGO_PACKAGE = "@typescript/native-preview/package.json";
|
|
10
|
+
const TSGO_CHECKER_DIR = node_path.join('.modern-js', 'tsgo');
|
|
11
|
+
const tryResolve = (request, rootPath)=>{
|
|
12
|
+
try {
|
|
13
|
+
return builderRequire.resolve(request, {
|
|
14
|
+
paths: [
|
|
15
|
+
rootPath
|
|
16
|
+
]
|
|
17
|
+
});
|
|
18
|
+
} catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const readPackageMajorVersion = (packageJsonPath)=>{
|
|
23
|
+
try {
|
|
24
|
+
const packageJson = JSON.parse(node_fs.readFileSync(packageJsonPath, 'utf8'));
|
|
25
|
+
const major = Number.parseInt(String(packageJson.version).split('.')[0], 10);
|
|
26
|
+
return Number.isFinite(major) ? major : void 0;
|
|
27
|
+
} catch {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const resolveTsgoPackagePath = (rootPath)=>{
|
|
32
|
+
const stableTypeScriptPath = tryResolve(STABLE_TSGO_PACKAGE, rootPath);
|
|
33
|
+
if (stableTypeScriptPath && (readPackageMajorVersion(stableTypeScriptPath) ?? 0) >= 7) return stableTypeScriptPath;
|
|
34
|
+
const previewFromProject = tryResolve(NATIVE_PREVIEW_TSGO_PACKAGE, rootPath);
|
|
35
|
+
if (previewFromProject) return previewFromProject;
|
|
36
|
+
try {
|
|
37
|
+
return builderRequire.resolve(NATIVE_PREVIEW_TSGO_PACKAGE);
|
|
38
|
+
} catch {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const toPosixPath = (input)=>input.replaceAll(node_path.sep, '/');
|
|
43
|
+
const asTsConfigPath = (request)=>{
|
|
44
|
+
if (node_path.extname(request)) return [
|
|
45
|
+
request
|
|
46
|
+
];
|
|
47
|
+
return [
|
|
48
|
+
request,
|
|
49
|
+
`${request}.json`
|
|
50
|
+
];
|
|
51
|
+
};
|
|
52
|
+
const resolveExtends = (request, configDirectory)=>{
|
|
53
|
+
const configRequire = createRequire(node_path.join(configDirectory, 'tsconfig.json'));
|
|
54
|
+
for (const candidate of asTsConfigPath(request)){
|
|
55
|
+
if (candidate.startsWith('.') || node_path.isAbsolute(candidate)) {
|
|
56
|
+
const resolved = node_path.resolve(configDirectory, candidate);
|
|
57
|
+
if (node_fs.existsSync(resolved)) return resolved;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
return configRequire.resolve(candidate);
|
|
62
|
+
} catch {}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const PATH_COMPILER_OPTIONS = [
|
|
66
|
+
'rootDir',
|
|
67
|
+
'outDir',
|
|
68
|
+
'declarationDir'
|
|
69
|
+
];
|
|
70
|
+
const absolutiseConfigPaths = (compilerOptions, configDirectory)=>{
|
|
71
|
+
if (!compilerOptions) return {};
|
|
72
|
+
const resolved = {
|
|
73
|
+
...compilerOptions
|
|
74
|
+
};
|
|
75
|
+
for (const option of PATH_COMPILER_OPTIONS){
|
|
76
|
+
const value = resolved[option];
|
|
77
|
+
if ('string' == typeof value && !node_path.isAbsolute(value)) resolved[option] = node_path.resolve(configDirectory, value);
|
|
78
|
+
}
|
|
79
|
+
return resolved;
|
|
80
|
+
};
|
|
81
|
+
const readTsConfig = (configFile, visited = new Set())=>{
|
|
82
|
+
if (visited.has(configFile) || !node_fs.existsSync(configFile)) return {};
|
|
83
|
+
visited.add(configFile);
|
|
84
|
+
const config = json5.parse(node_fs.readFileSync(configFile, 'utf8'));
|
|
85
|
+
const configDirectory = node_path.dirname(configFile);
|
|
86
|
+
const extendsList = Array.isArray(config.extends) ? config.extends : config.extends ? [
|
|
87
|
+
config.extends
|
|
88
|
+
] : [];
|
|
89
|
+
const baseConfig = extendsList.reduce((merged, request)=>{
|
|
90
|
+
const resolved = resolveExtends(request, configDirectory);
|
|
91
|
+
if (!resolved) return merged;
|
|
92
|
+
const parentConfig = readTsConfig(resolved, visited);
|
|
93
|
+
return {
|
|
94
|
+
...merged,
|
|
95
|
+
compilerOptions: {
|
|
96
|
+
...merged.compilerOptions ?? {},
|
|
97
|
+
...parentConfig.compilerOptions ?? {}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}, {});
|
|
101
|
+
return {
|
|
102
|
+
...baseConfig,
|
|
103
|
+
compilerOptions: {
|
|
104
|
+
...baseConfig.compilerOptions ?? {},
|
|
105
|
+
...absolutiseConfigPaths(config.compilerOptions, configDirectory)
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
const readProjectReferences = (configFile)=>{
|
|
110
|
+
if (!node_fs.existsSync(configFile)) return [];
|
|
111
|
+
const config = json5.parse(node_fs.readFileSync(configFile, 'utf8'));
|
|
112
|
+
if (!Array.isArray(config.references)) return [];
|
|
113
|
+
const configDirectory = node_path.dirname(configFile);
|
|
114
|
+
return config.references.filter((reference)=>'string' == typeof reference?.path).map((reference)=>({
|
|
115
|
+
...reference,
|
|
116
|
+
path: toPosixPath(node_path.resolve(configDirectory, reference.path))
|
|
117
|
+
}));
|
|
118
|
+
};
|
|
119
|
+
const toRelativeConfigPath = (fromDirectory, target)=>{
|
|
120
|
+
const relative = toPosixPath(node_path.relative(fromDirectory, target));
|
|
121
|
+
if (relative.startsWith('.')) return relative;
|
|
122
|
+
return `./${relative}`;
|
|
123
|
+
};
|
|
124
|
+
const writeFileIfChanged = (file, content)=>{
|
|
125
|
+
if (node_fs.existsSync(file) && node_fs.readFileSync(file, 'utf8') === content) return;
|
|
126
|
+
node_fs.writeFileSync(file, content);
|
|
127
|
+
};
|
|
128
|
+
const defaultTsgoCheckerConfigFile = (configFile)=>{
|
|
129
|
+
const hash = createHash('sha1').update(configFile).digest('hex').slice(0, 10);
|
|
130
|
+
return node_path.join(node_path.dirname(configFile), TSGO_CHECKER_DIR, `tsconfig.${hash}.json`);
|
|
131
|
+
};
|
|
132
|
+
const createTsgoCheckerConfig = (configFile, checkerConfigFile = defaultTsgoCheckerConfigFile(configFile))=>{
|
|
133
|
+
const configDirectory = node_path.dirname(configFile);
|
|
134
|
+
const checkerConfigDirectory = node_path.dirname(checkerConfigFile);
|
|
135
|
+
const tsConfig = readTsConfig(configFile);
|
|
136
|
+
const compilerOptions = {
|
|
137
|
+
baseUrl: null
|
|
138
|
+
};
|
|
139
|
+
const declaredRootDir = tsConfig.compilerOptions?.rootDir;
|
|
140
|
+
if ('string' == typeof declaredRootDir) compilerOptions.rootDir = toPosixPath(declaredRootDir);
|
|
141
|
+
else if (tsConfig.compilerOptions?.composite === true) compilerOptions.rootDir = toPosixPath(configDirectory);
|
|
142
|
+
const moduleResolution = String(tsConfig.compilerOptions?.moduleResolution).toLowerCase();
|
|
143
|
+
if ([
|
|
144
|
+
'node',
|
|
145
|
+
'node10'
|
|
146
|
+
].includes(moduleResolution)) compilerOptions.moduleResolution = null;
|
|
147
|
+
const references = readProjectReferences(configFile);
|
|
148
|
+
const checkerConfig = {
|
|
149
|
+
extends: toRelativeConfigPath(checkerConfigDirectory, configFile),
|
|
150
|
+
compilerOptions,
|
|
151
|
+
...references.length > 0 ? {
|
|
152
|
+
references
|
|
153
|
+
} : {}
|
|
154
|
+
};
|
|
155
|
+
node_fs.mkdirSync(checkerConfigDirectory, {
|
|
156
|
+
recursive: true
|
|
157
|
+
});
|
|
158
|
+
writeFileIfChanged(checkerConfigFile, `${JSON.stringify(checkerConfig, null, 2)}\n`);
|
|
159
|
+
return checkerConfigFile;
|
|
160
|
+
};
|
|
161
|
+
const refreshTsgoCheckerConfig = (checkerConfigFile)=>{
|
|
162
|
+
const checkerConfigDirectory = node_path.dirname(checkerConfigFile);
|
|
163
|
+
if ('tsgo' !== node_path.basename(checkerConfigDirectory) || '.modern-js' !== node_path.basename(node_path.dirname(checkerConfigDirectory)) || !node_fs.existsSync(checkerConfigFile)) return;
|
|
164
|
+
let checkerConfig;
|
|
165
|
+
try {
|
|
166
|
+
checkerConfig = json5.parse(node_fs.readFileSync(checkerConfigFile, 'utf8'));
|
|
167
|
+
} catch {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if ('string' != typeof checkerConfig.extends) return;
|
|
171
|
+
const projectConfigFile = node_path.resolve(checkerConfigDirectory, checkerConfig.extends);
|
|
172
|
+
if (node_fs.existsSync(projectConfigFile)) try {
|
|
173
|
+
createTsgoCheckerConfig(projectConfigFile, checkerConfigFile);
|
|
174
|
+
} catch {}
|
|
175
|
+
return projectConfigFile;
|
|
176
|
+
};
|
|
177
|
+
const normalizeTsgoConfig = (config, rootPath)=>{
|
|
178
|
+
const { typescript } = config;
|
|
179
|
+
if (typescript?.tsgo === false) return config;
|
|
180
|
+
const compilerOptions = {
|
|
181
|
+
...typescript?.configOverwrite?.compilerOptions ?? {},
|
|
182
|
+
baseUrl: null
|
|
183
|
+
};
|
|
184
|
+
if ([
|
|
185
|
+
'node',
|
|
186
|
+
'node10'
|
|
187
|
+
].includes(String(compilerOptions.moduleResolution).toLowerCase())) compilerOptions.moduleResolution = null;
|
|
188
|
+
config.typescript = {
|
|
189
|
+
...typescript,
|
|
190
|
+
configOverwrite: {
|
|
191
|
+
...typescript?.configOverwrite ?? {},
|
|
192
|
+
compilerOptions
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
if (typescript?.configFile) config.typescript.configFile = createTsgoCheckerConfig(node_path.resolve(rootPath, typescript.configFile));
|
|
196
|
+
return config;
|
|
197
|
+
};
|
|
198
|
+
const withTsgoDefaults = (userOptions, rootPath)=>{
|
|
199
|
+
const tsgoPath = resolveTsgoPackagePath(rootPath);
|
|
200
|
+
const userChain = userOptions ? Array.isArray(userOptions) ? userOptions : [
|
|
201
|
+
userOptions
|
|
202
|
+
] : [];
|
|
203
|
+
return [
|
|
204
|
+
{
|
|
205
|
+
typescript: tsgoPath ? {
|
|
206
|
+
tsgo: true,
|
|
207
|
+
typescriptPath: tsgoPath
|
|
208
|
+
} : {
|
|
209
|
+
tsgo: true
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
...userChain,
|
|
213
|
+
(config)=>{
|
|
214
|
+
const { typescript } = config;
|
|
215
|
+
if (typescript?.tsgo === false && typescript.typescriptPath === tsgoPath) typescript.typescriptPath = tryResolve("typescript", rootPath);
|
|
216
|
+
return normalizeTsgoConfig(config, rootPath);
|
|
217
|
+
}
|
|
218
|
+
];
|
|
219
|
+
};
|
|
220
|
+
export { refreshTsgoCheckerConfig, withTsgoDefaults };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright JS Foundation and other contributors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|