react-cosmos-plugin-rspack 1.0.2 → 2.0.0
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/client/errorOverlay/reactErrorOverlay.js +1311 -1203
- package/dist/client/index.js +1415 -1639
- package/dist/client/userImports.js +2 -1
- package/dist/server/rspackServerPlugin.js +72 -72
- package/dist/server/userImportsLoader.cjs +7 -6
- package/package.json +12 -12
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
// src/server/rspackConfigPlugin.ts
|
|
2
|
-
import * as path from "
|
|
2
|
+
import * as path from "path";
|
|
3
3
|
|
|
4
4
|
// src/server/rspackConfig/constants.ts
|
|
5
5
|
var RENDERER_FILENAME = "renderer.html";
|
|
6
6
|
|
|
7
7
|
// src/server/rspackConfigPlugin.ts
|
|
8
8
|
async function rspackConfigPlugin({
|
|
9
|
-
|
|
9
|
+
config
|
|
10
10
|
}) {
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
11
|
+
if (config.rendererUrl) {
|
|
12
|
+
return config;
|
|
13
13
|
}
|
|
14
14
|
return {
|
|
15
|
-
...
|
|
16
|
-
rendererUrl: path.join(
|
|
15
|
+
...config,
|
|
16
|
+
rendererUrl: path.join(config.publicUrl, RENDERER_FILENAME)
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// src/server/rspackDevServerPlugin.ts
|
|
21
|
-
import * as path8 from "
|
|
21
|
+
import * as path8 from "path";
|
|
22
22
|
import { serveStaticDir } from "react-cosmos";
|
|
23
23
|
import webpackHotMiddleware from "webpack-hot-middleware";
|
|
24
24
|
|
|
25
25
|
// src/server/cosmosConfig/createRspackCosmosConfig.ts
|
|
26
|
-
import * as path3 from "
|
|
26
|
+
import * as path3 from "path";
|
|
27
27
|
import { fileExists } from "react-cosmos";
|
|
28
28
|
|
|
29
29
|
// src/server/utils/resolveLoose.ts
|
|
30
|
-
import * as path2 from "
|
|
30
|
+
import * as path2 from "path";
|
|
31
31
|
|
|
32
32
|
// src/server/utils/isNodeError.ts
|
|
33
33
|
function isNodeError(err) {
|
|
@@ -35,7 +35,7 @@ function isNodeError(err) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// src/server/utils/resolve.ts
|
|
38
|
-
import { createRequire } from "
|
|
38
|
+
import { createRequire } from "module";
|
|
39
39
|
function resolve(moduleId) {
|
|
40
40
|
const require2 = createRequire(import.meta.url);
|
|
41
41
|
return require2.resolve(moduleId);
|
|
@@ -116,8 +116,8 @@ function getReloadOnFail({ reloadOnFail = false }) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
// src/server/utils/requireModule.ts
|
|
119
|
-
import { createRequire as createRequire2 } from "
|
|
120
|
-
import * as path4 from "
|
|
119
|
+
import { createRequire as createRequire2 } from "module";
|
|
120
|
+
import * as path4 from "path";
|
|
121
121
|
function requireFrom(fromDirectory, moduleId) {
|
|
122
122
|
const require2 = createRequire2(path4.resolve(fromDirectory, "noop.js"));
|
|
123
123
|
return require2(moduleId);
|
|
@@ -151,10 +151,10 @@ function getRspack(rootDir) {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
// src/server/rspackConfig/getDevRspackConfig.ts
|
|
154
|
-
import * as path7 from "
|
|
154
|
+
import * as path7 from "path";
|
|
155
155
|
|
|
156
156
|
// src/server/rspackConfig/getUserRspackConfig.ts
|
|
157
|
-
import * as path5 from "
|
|
157
|
+
import * as path5 from "path";
|
|
158
158
|
import {
|
|
159
159
|
getCliArgs,
|
|
160
160
|
importModule,
|
|
@@ -255,9 +255,9 @@ function getDefaultRspackConfig(rootDir) {
|
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
// src/server/rspackConfig/getUserRspackConfig.ts
|
|
258
|
-
async function getUserRspackConfig(
|
|
259
|
-
const baseRspackConfig = await getBaseRspackConfig(
|
|
260
|
-
const { overridePath } = createRspackCosmosConfig(
|
|
258
|
+
async function getUserRspackConfig(config) {
|
|
259
|
+
const baseRspackConfig = await getBaseRspackConfig(config);
|
|
260
|
+
const { overridePath } = createRspackCosmosConfig(config);
|
|
261
261
|
if (!overridePath || !moduleExists(overridePath)) {
|
|
262
262
|
console.log(
|
|
263
263
|
`[Cosmos] Learn how to override rspack config for cosmos: https://github.com/react-cosmos/react-cosmos/tree/main/docs#webpack-config-override`
|
|
@@ -270,9 +270,9 @@ async function getUserRspackConfig(cosmosConfig) {
|
|
|
270
270
|
const rspackOverride = module.default;
|
|
271
271
|
return rspackOverride(baseRspackConfig, getRspackNodeEnv());
|
|
272
272
|
}
|
|
273
|
-
async function getBaseRspackConfig(
|
|
274
|
-
const { rootDir } =
|
|
275
|
-
const { configPath } = createRspackCosmosConfig(
|
|
273
|
+
async function getBaseRspackConfig(confg) {
|
|
274
|
+
const { rootDir } = confg;
|
|
275
|
+
const { configPath } = createRspackCosmosConfig(confg);
|
|
276
276
|
if (!configPath || !moduleExists(configPath)) {
|
|
277
277
|
console.log("[Cosmos] Using default rspack config");
|
|
278
278
|
return getDefaultRspackConfig(rootDir);
|
|
@@ -293,47 +293,47 @@ async function getBaseRspackConfig(cosmosConfig) {
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
// src/server/rspackConfig/resolveRspackClientPath.ts
|
|
296
|
-
import { createRequire as createRequire3 } from "
|
|
296
|
+
import { createRequire as createRequire3 } from "module";
|
|
297
297
|
function resolveRspackClientPath(relPath) {
|
|
298
298
|
const require2 = createRequire3(import.meta.url);
|
|
299
299
|
return require2.resolve(`../client/${relPath}`);
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
// src/server/rspackConfig/resolveRspackLoaderPath.ts
|
|
303
|
-
import { createRequire as createRequire4 } from "
|
|
303
|
+
import { createRequire as createRequire4 } from "module";
|
|
304
304
|
function resolveRspackLoaderPath() {
|
|
305
305
|
const require2 = createRequire4(import.meta.url);
|
|
306
306
|
return require2.resolve("./userImportsLoader.cjs");
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
// src/server/rspackConfig/getRspackConfigModule.ts
|
|
310
|
-
function getRspackConfigModule(
|
|
310
|
+
function getRspackConfigModule(config, rspackConfig, mode) {
|
|
311
311
|
return {
|
|
312
312
|
...rspackConfig.module,
|
|
313
|
-
rules: getRules(
|
|
313
|
+
rules: getRules(config, rspackConfig, mode)
|
|
314
314
|
};
|
|
315
315
|
}
|
|
316
|
-
function getRules(
|
|
316
|
+
function getRules(config, { module }, mode) {
|
|
317
317
|
const existingRules = module && module.rules || [];
|
|
318
|
-
return [...existingRules, getUserImportsLoaderRule(
|
|
318
|
+
return [...existingRules, getUserImportsLoaderRule(config, mode)];
|
|
319
319
|
}
|
|
320
|
-
function getUserImportsLoaderRule(
|
|
320
|
+
function getUserImportsLoaderRule(config, mode) {
|
|
321
321
|
return {
|
|
322
322
|
include: resolveRspackClientPath("userImports"),
|
|
323
323
|
use: {
|
|
324
324
|
loader: resolveRspackLoaderPath(),
|
|
325
|
-
options: {
|
|
325
|
+
options: { config, mode }
|
|
326
326
|
}
|
|
327
327
|
};
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
// src/server/rspackConfig/getRspackConfigResolve.ts
|
|
331
|
-
import * as path6 from "
|
|
332
|
-
function getRspackConfigResolve(
|
|
333
|
-
return resolveLocalReactDeps(
|
|
331
|
+
import * as path6 from "path";
|
|
332
|
+
function getRspackConfigResolve(config, rspackConfig) {
|
|
333
|
+
return resolveLocalReactDeps(config, rspackConfig.resolve);
|
|
334
334
|
}
|
|
335
|
-
function resolveLocalReactDeps(
|
|
336
|
-
const { rootDir } =
|
|
335
|
+
function resolveLocalReactDeps(config, resolve6 = {}) {
|
|
336
|
+
const { rootDir } = config;
|
|
337
337
|
let alias = resolve6.alias || {};
|
|
338
338
|
let reactAlias = hasAlias(alias, "react");
|
|
339
339
|
let reactDomAlias = hasAlias(alias, "react-dom");
|
|
@@ -463,15 +463,15 @@ function ensureRspackConfigTopLevelAwait(baseWebpackConfig) {
|
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
// src/server/rspackConfig/getDevRspackConfig.ts
|
|
466
|
-
async function getDevRspackConfig(
|
|
467
|
-
const baseRspackConfig = await getUserRspackConfig(
|
|
466
|
+
async function getDevRspackConfig(config, userRspack) {
|
|
467
|
+
const baseRspackConfig = await getUserRspackConfig(config);
|
|
468
468
|
const rspackConfig = {
|
|
469
469
|
...baseRspackConfig,
|
|
470
|
-
entry: getEntry(
|
|
471
|
-
output: getOutput(
|
|
472
|
-
module: getRspackConfigModule(
|
|
473
|
-
resolve: getRspackConfigResolve(
|
|
474
|
-
plugins: getPlugins(
|
|
470
|
+
entry: getEntry(config),
|
|
471
|
+
output: getOutput(config),
|
|
472
|
+
module: getRspackConfigModule(config, baseRspackConfig, "dev"),
|
|
473
|
+
resolve: getRspackConfigResolve(config, baseRspackConfig),
|
|
474
|
+
plugins: getPlugins(config, baseRspackConfig, userRspack),
|
|
475
475
|
experiments: getExperiments(baseRspackConfig)
|
|
476
476
|
};
|
|
477
477
|
if (rspackConfig.optimization?.splitChunks) {
|
|
@@ -480,8 +480,8 @@ async function getDevRspackConfig(cosmosConfig, userRspack) {
|
|
|
480
480
|
}
|
|
481
481
|
return rspackConfig;
|
|
482
482
|
}
|
|
483
|
-
function getEntry(
|
|
484
|
-
const { hotReload, reloadOnFail } = createRspackCosmosConfig(
|
|
483
|
+
function getEntry(config) {
|
|
484
|
+
const { hotReload, reloadOnFail } = createRspackCosmosConfig(config);
|
|
485
485
|
const devtoolsHook = resolveRspackClientPath("reactDevtoolsHook");
|
|
486
486
|
const clientIndex = resolveRspackClientPath("index");
|
|
487
487
|
return hotReload ? [devtoolsHook, getHotMiddlewareEntry(reloadOnFail), clientIndex] : [devtoolsHook, clientIndex];
|
|
@@ -495,12 +495,12 @@ function getOutput({ publicUrl }) {
|
|
|
495
495
|
devtoolModuleFilenameTemplate: (info) => path7.resolve(info.absoluteResourcePath).replace(/\\/g, "/")
|
|
496
496
|
};
|
|
497
497
|
}
|
|
498
|
-
function getPlugins(
|
|
498
|
+
function getPlugins(config, baseRspackConfig, userRspack) {
|
|
499
499
|
const existingPlugins = ignoreEmptyRspackPlugins(baseRspackConfig.plugins);
|
|
500
|
-
const globalsPlugin = getGlobalsPlugin(
|
|
500
|
+
const globalsPlugin = getGlobalsPlugin(config, userRspack, true);
|
|
501
501
|
const noEmitErrorsPlugin = new userRspack.NoEmitOnErrorsPlugin();
|
|
502
502
|
let plugins = [...existingPlugins, globalsPlugin, noEmitErrorsPlugin];
|
|
503
|
-
const { hotReload } = createRspackCosmosConfig(
|
|
503
|
+
const { hotReload } = createRspackCosmosConfig(config);
|
|
504
504
|
if (hotReload && !hasPlugin(plugins, "HotModuleReplacementPlugin")) {
|
|
505
505
|
const hmrPlugin = new userRspack.HotModuleReplacementPlugin();
|
|
506
506
|
plugins = [...plugins, hmrPlugin];
|
|
@@ -517,29 +517,29 @@ function getExperiments(baseWebpackConfig) {
|
|
|
517
517
|
|
|
518
518
|
// src/server/rspackDevServerPlugin.ts
|
|
519
519
|
async function rspackDevServerPlugin({
|
|
520
|
-
|
|
520
|
+
config,
|
|
521
521
|
platform,
|
|
522
|
-
|
|
522
|
+
app,
|
|
523
523
|
sendMessage
|
|
524
524
|
}) {
|
|
525
525
|
if (platform !== "web") {
|
|
526
526
|
return;
|
|
527
527
|
}
|
|
528
|
-
const userRspack = getRspack(
|
|
528
|
+
const userRspack = getRspack(config.rootDir);
|
|
529
529
|
if (!userRspack) {
|
|
530
530
|
return;
|
|
531
531
|
}
|
|
532
532
|
const rspackConfig = await getDevRspackConfig(
|
|
533
|
-
|
|
533
|
+
config,
|
|
534
534
|
userRspack
|
|
535
535
|
);
|
|
536
|
-
if (
|
|
536
|
+
if (config.staticPath === null) {
|
|
537
537
|
const rspackDerivedStaticPath = getRspackStaticPath(rspackConfig);
|
|
538
538
|
if (rspackDerivedStaticPath !== null) {
|
|
539
539
|
serveStaticDir(
|
|
540
|
-
|
|
541
|
-
path8.resolve(
|
|
542
|
-
|
|
540
|
+
app,
|
|
541
|
+
path8.resolve(config.rootDir, rspackDerivedStaticPath),
|
|
542
|
+
config.publicUrl
|
|
543
543
|
);
|
|
544
544
|
}
|
|
545
545
|
}
|
|
@@ -580,13 +580,13 @@ async function rspackDevServerPlugin({
|
|
|
580
580
|
{
|
|
581
581
|
// publicPath is the base path for the rspack assets and has to match
|
|
582
582
|
// rspack.output.publicPath
|
|
583
|
-
publicPath:
|
|
583
|
+
publicPath: config.publicUrl
|
|
584
584
|
}
|
|
585
585
|
);
|
|
586
|
-
|
|
587
|
-
const { hotReload } = createRspackCosmosConfig(
|
|
586
|
+
app.use(wdmInst);
|
|
587
|
+
const { hotReload } = createRspackCosmosConfig(config);
|
|
588
588
|
if (hotReload) {
|
|
589
|
-
|
|
589
|
+
app.use(
|
|
590
590
|
webpackHotMiddleware(
|
|
591
591
|
// As above, rspack's Compiler type is pretty close to webpack's
|
|
592
592
|
// Compiler type so this should be fine.
|
|
@@ -604,16 +604,16 @@ function getRspackStaticPath({ devServer }) {
|
|
|
604
604
|
}
|
|
605
605
|
|
|
606
606
|
// src/server/rspackConfig/getExportRspackConfig.ts
|
|
607
|
-
import * as path9 from "
|
|
608
|
-
async function getExportRspackConfig(
|
|
609
|
-
const baseRspackConfig = await getUserRspackConfig(
|
|
607
|
+
import * as path9 from "path";
|
|
608
|
+
async function getExportRspackConfig(config, userRspack) {
|
|
609
|
+
const baseRspackConfig = await getUserRspackConfig(config);
|
|
610
610
|
return {
|
|
611
611
|
...baseRspackConfig,
|
|
612
612
|
entry: getEntry2(),
|
|
613
|
-
output: getOutput2(
|
|
614
|
-
module: getRspackConfigModule(
|
|
615
|
-
resolve: getRspackConfigResolve(
|
|
616
|
-
plugins: getPlugins2(
|
|
613
|
+
output: getOutput2(config),
|
|
614
|
+
module: getRspackConfigModule(config, baseRspackConfig, "export"),
|
|
615
|
+
resolve: getRspackConfigResolve(config, baseRspackConfig),
|
|
616
|
+
plugins: getPlugins2(config, baseRspackConfig, userRspack),
|
|
617
617
|
experiments: getExperiments2(baseRspackConfig)
|
|
618
618
|
};
|
|
619
619
|
}
|
|
@@ -622,18 +622,18 @@ function getEntry2() {
|
|
|
622
622
|
const clientIndex = resolveRspackClientPath("index");
|
|
623
623
|
return [devtoolsHook, clientIndex];
|
|
624
624
|
}
|
|
625
|
-
function getOutput2(
|
|
626
|
-
const { exportPath, publicUrl } =
|
|
627
|
-
const { includeHashInOutputFilename } = createRspackCosmosConfig(
|
|
625
|
+
function getOutput2(config) {
|
|
626
|
+
const { exportPath, publicUrl } = config;
|
|
627
|
+
const { includeHashInOutputFilename } = createRspackCosmosConfig(config);
|
|
628
628
|
return {
|
|
629
629
|
path: path9.join(exportPath, publicUrl),
|
|
630
630
|
filename: includeHashInOutputFilename ? "[name].[contenthash].js" : "[name].js",
|
|
631
631
|
publicPath: publicUrl
|
|
632
632
|
};
|
|
633
633
|
}
|
|
634
|
-
function getPlugins2(
|
|
634
|
+
function getPlugins2(config, baseRspackConfig, userRspack) {
|
|
635
635
|
const existingPlugins = ignoreEmptyRspackPlugins(baseRspackConfig.plugins);
|
|
636
|
-
const globalsPlugin = getGlobalsPlugin(
|
|
636
|
+
const globalsPlugin = getGlobalsPlugin(config, userRspack, false);
|
|
637
637
|
const noEmitErrorsPlugin = new userRspack.NoEmitOnErrorsPlugin();
|
|
638
638
|
return ensureHtmlPlugin([
|
|
639
639
|
...existingPlugins,
|
|
@@ -646,12 +646,12 @@ function getExperiments2(baseWebpackConfig) {
|
|
|
646
646
|
}
|
|
647
647
|
|
|
648
648
|
// src/server/rspackExportPlugin.ts
|
|
649
|
-
async function rspackExportPlugin({
|
|
650
|
-
const userRspack = getRspack(
|
|
649
|
+
async function rspackExportPlugin({ config }) {
|
|
650
|
+
const userRspack = getRspack(config.rootDir);
|
|
651
651
|
if (!userRspack) {
|
|
652
652
|
return;
|
|
653
653
|
}
|
|
654
|
-
const rspackConfig = await getExportRspackConfig(
|
|
654
|
+
const rspackConfig = await getExportRspackConfig(config, userRspack);
|
|
655
655
|
try {
|
|
656
656
|
await runRspackCompiler(userRspack, rspackConfig);
|
|
657
657
|
} catch (err) {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// dist folder as part of the build process
|
|
5
5
|
module.exports = async function injectUserImports() {
|
|
6
6
|
const cosmos = await import('react-cosmos');
|
|
7
|
-
const {
|
|
7
|
+
const { config, mode } = this.getOptions();
|
|
8
8
|
|
|
9
9
|
// This ensures this loader is invalidated whenever a new file is added to or
|
|
10
10
|
// removed from user's project, which in turn triggers findUserModulePaths
|
|
@@ -13,17 +13,18 @@ module.exports = async function injectUserImports() {
|
|
|
13
13
|
// of require.context, which not only watches for file changes but also
|
|
14
14
|
// automatically bundles new files that match the watcher's query.
|
|
15
15
|
// https://github.com/webpack/webpack/issues/222#issuecomment-40691546
|
|
16
|
-
const watchDirs =
|
|
16
|
+
const watchDirs = config.watchDirs;
|
|
17
17
|
watchDirs.forEach((watchDir) => this.addContextDependency(watchDir));
|
|
18
18
|
|
|
19
|
-
const { containerQuerySelector } =
|
|
20
|
-
const modulePaths = await cosmos.findUserModulePaths(
|
|
19
|
+
const { containerQuerySelector } = config.dom;
|
|
20
|
+
const modulePaths = await cosmos.findUserModulePaths(config);
|
|
21
21
|
const rendererConfig = {
|
|
22
|
-
|
|
22
|
+
webSocketUrl: mode === 'dev' ? cosmos.getWebSocketUrl(config) : null,
|
|
23
|
+
rendererUrl: null,
|
|
23
24
|
containerQuerySelector,
|
|
24
25
|
};
|
|
25
26
|
return cosmos.generateUserImports({
|
|
26
|
-
|
|
27
|
+
config,
|
|
27
28
|
modulePaths,
|
|
28
29
|
rendererConfig,
|
|
29
30
|
relativeToDir: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-plugin-rspack",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "rspack plugin for React Cosmos",
|
|
5
5
|
"repository": "https://github.com/birchill/react-cosmos-plugin-rspack/",
|
|
6
6
|
"author": "Birchill, Inc.",
|
|
@@ -12,26 +12,26 @@
|
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"react-cosmos-dom": ">=
|
|
15
|
+
"react-cosmos-dom": ">=7.0.0",
|
|
16
16
|
"webpack-dev-middleware": "7.4.2",
|
|
17
17
|
"webpack-hot-middleware": "2.26.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@release-it/conventional-changelog": "10.0.1",
|
|
21
|
-
"@rspack/core": "1.3.
|
|
22
|
-
"@types/node": "22.15.
|
|
21
|
+
"@rspack/core": "1.3.15",
|
|
22
|
+
"@types/node": "22.15.30",
|
|
23
23
|
"@types/webpack-hot-middleware": "2.25.9",
|
|
24
|
-
"esbuild": "0.25.
|
|
24
|
+
"esbuild": "0.25.5",
|
|
25
25
|
"husky": "9.1.7",
|
|
26
|
-
"knip": "5.
|
|
27
|
-
"lint-staged": "
|
|
26
|
+
"knip": "5.60.2",
|
|
27
|
+
"lint-staged": "16.1.0",
|
|
28
28
|
"prettier": "3.5.3",
|
|
29
|
-
"react-cosmos": "
|
|
30
|
-
"react-cosmos-core": "
|
|
31
|
-
"react-error-overlay": "6.
|
|
29
|
+
"react-cosmos": "7.0.0",
|
|
30
|
+
"react-cosmos-core": "7.0.0",
|
|
31
|
+
"react-error-overlay": "6.0.9",
|
|
32
32
|
"react-plugin": "3.0.0-alpha.4",
|
|
33
|
-
"release-it": "19.0.
|
|
34
|
-
"tsup": "8.
|
|
33
|
+
"release-it": "19.0.3",
|
|
34
|
+
"tsup": "8.5.0",
|
|
35
35
|
"typescript": "5.8.3"
|
|
36
36
|
},
|
|
37
37
|
"prettier": {
|