react-cosmos-plugin-rspack 0.0.1

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.
@@ -0,0 +1,32 @@
1
+ // Webpack (and therefore probably rspack) doesn't support ESM loaders:
2
+ // https://github.com/webpack/webpack/issues/13233
3
+ // To circumvent this we use this CJS source file that's manually copied in the
4
+ // dist folder as part of the build process
5
+ module.exports = async function injectUserImports() {
6
+ const cosmos = await import('react-cosmos');
7
+ const { cosmosConfig } = this.getOptions();
8
+
9
+ // This ensures this loader is invalidated whenever a new file is added to or
10
+ // removed from user's project, which in turn triggers findUserModulePaths
11
+ // to detect fixture files and finally update fixture list inside Playground.
12
+ // Note that while this may not be very performant, it's not the equivalent
13
+ // of require.context, which not only watches for file changes but also
14
+ // automatically bundles new files that match the watcher's query.
15
+ // https://github.com/webpack/webpack/issues/222#issuecomment-40691546
16
+ const watchDirs = cosmosConfig.watchDirs;
17
+ watchDirs.forEach((watchDir) => this.addContextDependency(watchDir));
18
+
19
+ const { containerQuerySelector } = cosmosConfig.dom;
20
+ const modulePaths = cosmos.findUserModulePaths(cosmosConfig);
21
+ const rendererConfig = {
22
+ playgroundUrl: cosmos.getPlaygroundUrl(cosmosConfig),
23
+ containerQuerySelector,
24
+ };
25
+ return cosmos.generateUserImports({
26
+ cosmosConfig,
27
+ modulePaths,
28
+ rendererConfig,
29
+ relativeToDir: null,
30
+ typeScript: false,
31
+ });
32
+ };
@@ -0,0 +1,55 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // external-global:react
28
+ var require_react = __commonJS({
29
+ "external-global:react"(exports, module) {
30
+ module.exports = React;
31
+ }
32
+ });
33
+
34
+ // external-global:react-plugin
35
+ var require_react_plugin = __commonJS({
36
+ "external-global:react-plugin"(exports, module) {
37
+ module.exports = ReactPlugin;
38
+ }
39
+ });
40
+
41
+ // src/ui/WebpackRendererError.tsx
42
+ var import_react = __toESM(require_react(), 1);
43
+ var import_react_plugin = __toESM(require_react_plugin(), 1);
44
+ var { register, plug } = (0, import_react_plugin.createPlugin)({
45
+ name: "webpackRendererError"
46
+ });
47
+ plug("rendererError", () => {
48
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, "If you use a custom webpack config,", " ", /* @__PURE__ */ import_react.default.createElement("strong", null, "make sure", /* @__PURE__ */ import_react.default.createElement("br", null), "your build is generating an index.html page."));
49
+ });
50
+ if (true) {
51
+ register();
52
+ }
53
+ export {
54
+ register
55
+ };
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "react-cosmos-plugin-rspack",
3
+ "version": "0.0.1",
4
+ "description": "rspack plugin for React Cosmos",
5
+ "repository": "https://github.com/birchill/react-cosmos-plugin-rspack/",
6
+ "author": "Birchill, Inc.",
7
+ "license": "MIT",
8
+ "main": "./cosmos.plugin.json",
9
+ "files": [
10
+ "dist/**",
11
+ "cosmos.plugin.json"
12
+ ],
13
+ "type": "module",
14
+ "dependencies": {
15
+ "webpack-dev-middleware": "7.2.1",
16
+ "webpack-hot-middleware": "2.26.1"
17
+ },
18
+ "devDependencies": {
19
+ "@release-it/conventional-changelog": "8.0.1",
20
+ "@rspack/core": "0.7.5",
21
+ "@types/node": "20.14.9",
22
+ "@types/webpack-hot-middleware": "2.25.9",
23
+ "html-webpack-plugin": "5.6.0",
24
+ "husky": "9.0.11",
25
+ "knip": "5.23.3",
26
+ "lint-staged": "15.2.7",
27
+ "prettier": "3.3.2",
28
+ "react-cosmos": "6.1.1",
29
+ "react-cosmos-core": "6.1.1",
30
+ "react-error-overlay": "6.0.9",
31
+ "react-plugin": "3.0.0-alpha.4",
32
+ "release-it": "17.4.1",
33
+ "tsup": "8.1.0",
34
+ "typescript": "5.5.3"
35
+ },
36
+ "prettier": {
37
+ "singleQuote": true,
38
+ "trailingComma": "es5"
39
+ },
40
+ "publishConfig": {
41
+ "registry": "https://registry.npmjs.org"
42
+ },
43
+ "peerDependencies": {
44
+ "@rspack/core": "^0.6.0",
45
+ "react-cosmos": "^6.0.0",
46
+ "react-cosmos-dom": "^6.0.0"
47
+ },
48
+ "lint-staged": {
49
+ "*.{ts,json,md}": [
50
+ "prettier --write"
51
+ ]
52
+ },
53
+ "scripts": {
54
+ "build": "tsup && tsup --config tsup.ui.config.ts && cp src/server/rspackConfig/userImportsLoader.cjs dist/server",
55
+ "release": "release-it"
56
+ }
57
+ }