@superblocksteam/cli 1.9.3 → 1.10.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.
@@ -0,0 +1,2 @@
1
+ import { Plugin } from "vite";
2
+ export declare const productionCssPlugin: () => Plugin;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.productionCssPlugin = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
6
+ // CSS is located at a path like "assets/component-8625163d.css", so
7
+ // we need to get the full URL to it by using import.meta.url
8
+ function getInjector(path) {
9
+ return `(() => {
10
+ const link = document.createElement("link"); link.rel = "stylesheet"; link.href = new URL("${path}", import.meta.url).toString();
11
+ document.querySelector("head").appendChild(link);
12
+ })();`;
13
+ }
14
+ // Vite extracts CSS into separate files, but expects that developers will
15
+ // place them in the <head> of their HTML to avoid flash-of-unstyled-content.
16
+ // Since we're not using HTML, we need to inject the CSS into the JS bundle.
17
+ // But we want to avoid inline CSS because we can't guarantee components are
18
+ // all used on the page- so by using <link> tags, the browser does not have to
19
+ // download unused CSS
20
+ const productionCssPlugin = () => {
21
+ return {
22
+ name: "css-reference",
23
+ enforce: "post",
24
+ apply: "build",
25
+ renderChunk(code, chunk) {
26
+ var _a;
27
+ if ((_a = chunk.viteMetadata) === null || _a === void 0 ? void 0 : _a.importedCss.size) {
28
+ const cssFiles = Array.from(chunk.viteMetadata.importedCss);
29
+ if (chunk.isEntry) {
30
+ return {
31
+ code: `${cssFiles.map(getInjector).join("\n")}
32
+ ${code}`,
33
+ // No code was moved, use existing sourcemap
34
+ map: null,
35
+ };
36
+ }
37
+ else {
38
+ return {
39
+ code: `${cssFiles
40
+ .map((p) => {
41
+ // Converts a path like "assets/component-8625163d.css" to
42
+ // a path like "component-8625163d.css", which resolves as a URL
43
+ const relativePath = node_path_1.default.relative(node_path_1.default.dirname(chunk.fileName), p);
44
+ return getInjector(relativePath);
45
+ })
46
+ .join("\n")}
47
+ ${code}`,
48
+ // No code was moved, use existing sourcemap
49
+ map: null,
50
+ };
51
+ }
52
+ }
53
+ },
54
+ };
55
+ };
56
+ exports.productionCssPlugin = productionCssPlugin;
@@ -0,0 +1,2 @@
1
+ import { Plugin } from "vite";
2
+ export declare const injectReactVersionsPlugin: () => Plugin;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.injectReactVersionsPlugin = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
7
+ const semver_1 = tslib_1.__importDefault(require("semver"));
8
+ const vite_1 = require("vite");
9
+ const shimIdForBuild = "injectedReactShim";
10
+ const shimFileNameDev = `${shimIdForBuild}.jsx`;
11
+ const shimFileNameBuild = `${shimIdForBuild}.js`;
12
+ const pathToInjectedReactShim17 = (0, vite_1.normalizePath)(path_1.default.join(__dirname, `../assets/${shimIdForBuild}17.jsx`));
13
+ const pathToInjectedReactShim18 = (0, vite_1.normalizePath)(path_1.default.join(__dirname, `../assets/${shimIdForBuild}18.jsx`));
14
+ // This plugin works in both dev and build mode
15
+ // In dev mode, the UI makes a request to localhost:3002/@superblocksteam/react-shim
16
+ // In build mode, the plugin injects an additional entry point for the shim
17
+ const injectReactVersionsPlugin = () => {
18
+ var _a;
19
+ const packageJson = fs_extra_1.default.readJsonSync(path_1.default.join((0, vite_1.searchForWorkspaceRoot)(process.cwd()), "package.json"));
20
+ if (!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a.react)) {
21
+ throw new Error("React is not installed");
22
+ }
23
+ const version = semver_1.default.minVersion(packageJson.dependencies.react);
24
+ if (!version)
25
+ throw new Error("React is not installed");
26
+ const isReact17 = semver_1.default.satisfies(version, "^17");
27
+ const isReact18 = semver_1.default.satisfies(version, "^18");
28
+ return {
29
+ name: "react-versions-plugin",
30
+ enforce: "pre",
31
+ config(config) {
32
+ var _a, _b, _c, _d;
33
+ config.server = (0, vite_1.mergeConfig)((_a = config.server) !== null && _a !== void 0 ? _a : {}, {
34
+ fs: {
35
+ allow: [
36
+ (0, vite_1.searchForWorkspaceRoot)(process.cwd()),
37
+ pathToInjectedReactShim17,
38
+ pathToInjectedReactShim18,
39
+ ],
40
+ },
41
+ });
42
+ if (isReact18) {
43
+ // This fixes an issue in vite-plugin-react, from their source they say:
44
+ //
45
+ // We can't add `react-dom` because the dependency is `react-dom/client`
46
+ // for React 18 while it's `react-dom` for React 17. We'd need to detect
47
+ // what React version the user has installed.
48
+ config.optimizeDeps = (0, vite_1.mergeConfig)((_b = config.optimizeDeps) !== null && _b !== void 0 ? _b : {}, {
49
+ include: ["react", "react-dom", "react-dom/client"],
50
+ });
51
+ config.resolve = (0, vite_1.mergeConfig)((_c = config.resolve) !== null && _c !== void 0 ? _c : {}, {
52
+ dedupe: ["react", "react-dom", "react-dom/client"],
53
+ });
54
+ }
55
+ else if (isReact17) {
56
+ config.optimizeDeps = (0, vite_1.mergeConfig)((_d = config.optimizeDeps) !== null && _d !== void 0 ? _d : {}, {
57
+ include: ["react", "react-dom"],
58
+ });
59
+ }
60
+ // Since the React plugin is part of both the dev and build modes, it's a good place
61
+ // to put other build settings
62
+ config.css = {
63
+ modules: {
64
+ // CSS modules will rewrite hyphens but keep both names in the output object
65
+ localsConvention: "camelCase",
66
+ },
67
+ };
68
+ return config;
69
+ },
70
+ resolveId(id) {
71
+ if (id === shimIdForBuild) {
72
+ return `/${shimFileNameBuild}`;
73
+ }
74
+ },
75
+ load(id) {
76
+ // We are modifying just the injectedReactShim code because import.meta.hot is a global handler,
77
+ // and we only need to handle the events in one place
78
+ const setupHotReloadingOneTime = (code) => {
79
+ if (!this.meta.watchMode)
80
+ return code;
81
+ return `import RefreshRuntime2 from "/@react-refresh";
82
+ RefreshRuntime2.injectIntoGlobalHook(window);
83
+ ${code}
84
+
85
+ if (import.meta.hot) {
86
+ import.meta.hot.on('vite:beforeUpdate', (data) => {
87
+ window.parent.postMessage(
88
+ { type: "hot-reloaded" },
89
+ "*"
90
+ );
91
+ });
92
+
93
+ import.meta.hot.on('config-reloaded', () => {
94
+ window.parent.postMessage(
95
+ { type: "reload-configs" },
96
+ "*"
97
+ );
98
+ });
99
+ }
100
+ `;
101
+ };
102
+ if (id === `/${shimFileNameDev}` || id === `/${shimFileNameBuild}`) {
103
+ if (isReact18) {
104
+ return {
105
+ code: setupHotReloadingOneTime(`export { loadReact } from "/@fs${pathToInjectedReactShim18.startsWith("/") ? "" : "/"}${pathToInjectedReactShim18}";`),
106
+ meta: { superblocks: true },
107
+ map: null,
108
+ };
109
+ }
110
+ else if (isReact17) {
111
+ return {
112
+ code: setupHotReloadingOneTime(`export { loadReact } from "/@fs${pathToInjectedReactShim18.startsWith("/") ? "" : "/"}${pathToInjectedReactShim17}";`),
113
+ meta: { superblocks: true },
114
+ map: null,
115
+ };
116
+ }
117
+ else {
118
+ throw new Error(`React version ${version.major} is not supported`);
119
+ }
120
+ }
121
+ },
122
+ buildStart() {
123
+ if (this.meta.watchMode)
124
+ return; // Don't inject in dev mode
125
+ // Inject the shim as an entry point file, which will be processed using the usual Vite pipeline
126
+ this.emitFile({
127
+ type: "chunk",
128
+ id: shimIdForBuild,
129
+ fileName: shimFileNameBuild,
130
+ });
131
+ },
132
+ };
133
+ };
134
+ exports.injectReactVersionsPlugin = injectReactVersionsPlugin;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.9.3",
2
+ "version": "1.10.0",
3
3
  "commands": {
4
4
  "commits": {
5
5
  "id": "commits",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/cli",
3
- "version": "1.9.3",
3
+ "version": "1.10.0",
4
4
  "description": "Official Superblocks CLI",
5
5
  "bin": {
6
6
  "superblocks": "bin/run"
@@ -15,17 +15,15 @@
15
15
  "/oclif.manifest.json"
16
16
  ],
17
17
  "dependencies": {
18
+ "axios": "^1.4.0",
18
19
  "@oclif/core": "^2.11.7",
19
20
  "@oclif/plugin-help": "^5.2.16",
20
21
  "@oclif/plugin-plugins": "^3.1.10",
21
- "@superblocksteam/css-plugin": "1.9.3",
22
- "@superblocksteam/react-shim": "1.9.3",
23
- "@superblocksteam/sdk": "1.9.3",
24
- "@superblocksteam/util": "1.9.3",
25
- "@superblocksteam/vite-custom-component-reload-plugin": "1.9.3",
22
+ "@superblocksteam/sdk": "1.10.0",
23
+ "@superblocksteam/util": "1.10.0",
26
24
  "@vitejs/plugin-react": "^4.1.0",
27
25
  "colorette": "^2.0.19",
28
- "enquirer": "^2.3.6",
26
+ "enquirer": "^2.4.1",
29
27
  "fs-extra": "^11.1.1",
30
28
  "listr2": "6.6.0",
31
29
  "lodash": "^4.17.21",