@superblocksteam/cli 1.9.3 → 1.12.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.
Files changed (59) hide show
  1. package/LICENSE.txt +87 -0
  2. package/README.md +6 -6
  3. package/assets/custom-components/setup/package.json +1 -1
  4. package/assets/custom-components/setup/tsconfig.json +0 -1
  5. package/assets/injectedReactShim17.jsx +15 -0
  6. package/assets/injectedReactShim18.jsx +16 -0
  7. package/assets/injectedReactShimShared.jsx +140 -0
  8. package/bin/dev +5 -7
  9. package/bin/run +1 -3
  10. package/dist/appendHotReloadEventPlugin.d.mts +2 -0
  11. package/dist/appendHotReloadEventPlugin.mjs +43 -0
  12. package/dist/commands/commits.d.mts +18 -0
  13. package/dist/commands/{commits.js → commits.mjs} +59 -67
  14. package/dist/commands/components/{create.d.ts → create.d.mts} +2 -2
  15. package/dist/commands/components/{create.js → create.mjs} +84 -93
  16. package/dist/commands/components/{register.d.ts → register.d.mts} +1 -1
  17. package/dist/commands/components/register.mjs +12 -0
  18. package/dist/commands/components/{upload.d.ts → upload.d.mts} +2 -2
  19. package/dist/commands/components/{upload.js → upload.mjs} +39 -43
  20. package/dist/commands/components/{watch.d.ts → watch.d.mts} +1 -1
  21. package/dist/commands/components/{watch.js → watch.mjs} +29 -36
  22. package/dist/commands/config/{set.d.ts → set.d.mts} +2 -2
  23. package/dist/commands/config/{set.js → set.mjs} +28 -32
  24. package/dist/commands/{init.d.ts → init.d.mts} +4 -4
  25. package/dist/commands/{init.js → init.mjs} +63 -65
  26. package/dist/commands/{login.d.ts → login.d.mts} +1 -1
  27. package/dist/commands/login.mjs +55 -0
  28. package/dist/commands/{migrate.d.ts → migrate.d.mts} +1 -1
  29. package/dist/commands/{migrate.js → migrate.mjs} +38 -46
  30. package/dist/commands/pull.d.mts +17 -0
  31. package/dist/commands/{pull.js → pull.mjs} +74 -80
  32. package/dist/commands/push.d.mts +15 -0
  33. package/dist/commands/{push.js → push.mjs} +81 -90
  34. package/dist/commands/{rm.d.ts → rm.d.mts} +2 -2
  35. package/dist/commands/{rm.js → rm.mjs} +34 -40
  36. package/dist/common/{authenticated-command.js → authenticated-command.mjs} +65 -75
  37. package/dist/common/defaults/{create-component-defaults.js → create-component-defaults.mjs} +2 -7
  38. package/dist/common/{version-control.d.ts → version-control.d.mts} +13 -6
  39. package/dist/common/version-control.mjs +1064 -0
  40. package/dist/index.js +1 -5
  41. package/dist/productionCssPlugin.d.mts +2 -0
  42. package/dist/productionCssPlugin.mjs +50 -0
  43. package/dist/reactShimPlugin.d.mts +2 -0
  44. package/dist/reactShimPlugin.mjs +127 -0
  45. package/dist/util/migrationWarningsForApplications.mjs +47 -0
  46. package/dist/util/{migrationsForDotfiles.js → migrationsForDotfiles.mjs} +10 -17
  47. package/oclif.manifest.json +274 -161
  48. package/package.json +45 -45
  49. package/dist/commands/commits.d.ts +0 -18
  50. package/dist/commands/components/register.js +0 -15
  51. package/dist/commands/login.js +0 -61
  52. package/dist/commands/pull.d.ts +0 -17
  53. package/dist/commands/push.d.ts +0 -15
  54. package/dist/common/version-control.js +0 -716
  55. package/dist/util/migrationWarningsForApplications.js +0 -52
  56. /package/dist/common/{authenticated-command.d.ts → authenticated-command.d.mts} +0 -0
  57. /package/dist/common/defaults/{create-component-defaults.d.ts → create-component-defaults.d.mts} +0 -0
  58. /package/dist/util/{migrationWarningsForApplications.d.ts → migrationWarningsForApplications.d.mts} +0 -0
  59. /package/dist/util/{migrationsForDotfiles.d.ts → migrationsForDotfiles.d.mts} +0 -0
package/dist/index.js CHANGED
@@ -1,5 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = void 0;
4
- var core_1 = require("@oclif/core");
5
- Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
1
+ export { run } from "@oclif/core";
@@ -0,0 +1,2 @@
1
+ import { Plugin } from "vite";
2
+ export declare const productionCssPlugin: () => Plugin;
@@ -0,0 +1,50 @@
1
+ import path from "node:path";
2
+ // CSS is located at a path like "assets/component-8625163d.css", so
3
+ // we need to get the full URL to it by using import.meta.url
4
+ function getInjector(path) {
5
+ return `(() => {
6
+ const link = document.createElement("link"); link.rel = "stylesheet"; link.href = new URL("${path}", import.meta.url).toString();
7
+ document.querySelector("head").appendChild(link);
8
+ })();`;
9
+ }
10
+ // Vite extracts CSS into separate files, but expects that developers will
11
+ // place them in the <head> of their HTML to avoid flash-of-unstyled-content.
12
+ // Since we're not using HTML, we need to inject the CSS into the JS bundle.
13
+ // But we want to avoid inline CSS because we can't guarantee components are
14
+ // all used on the page- so by using <link> tags, the browser does not have to
15
+ // download unused CSS
16
+ export const productionCssPlugin = () => {
17
+ return {
18
+ name: "css-reference",
19
+ enforce: "post",
20
+ apply: "build",
21
+ renderChunk(code, chunk) {
22
+ if (chunk.viteMetadata?.importedCss.size) {
23
+ const cssFiles = Array.from(chunk.viteMetadata.importedCss);
24
+ if (chunk.isEntry) {
25
+ return {
26
+ code: `${cssFiles.map(getInjector).join("\n")}
27
+ ${code}`,
28
+ // No code was moved, use existing sourcemap
29
+ map: null,
30
+ };
31
+ }
32
+ else {
33
+ return {
34
+ code: `${cssFiles
35
+ .map((p) => {
36
+ // Converts a path like "assets/component-8625163d.css" to
37
+ // a path like "component-8625163d.css", which resolves as a URL
38
+ const relativePath = path.relative(path.dirname(chunk.fileName), p);
39
+ return getInjector(relativePath);
40
+ })
41
+ .join("\n")}
42
+ ${code}`,
43
+ // No code was moved, use existing sourcemap
44
+ map: null,
45
+ };
46
+ }
47
+ }
48
+ },
49
+ };
50
+ };
@@ -0,0 +1,2 @@
1
+ import { Plugin } from "vite";
2
+ export declare const injectReactVersionsPlugin: () => Plugin;
@@ -0,0 +1,127 @@
1
+ import path from "path";
2
+ import fs from "fs-extra";
3
+ import semver from "semver";
4
+ import { searchForWorkspaceRoot, mergeConfig, normalizePath, } from "vite";
5
+ const shimIdForBuild = "injectedReactShim";
6
+ const shimFileNameDev = `${shimIdForBuild}.jsx`;
7
+ const shimFileNameBuild = `${shimIdForBuild}.js`;
8
+ const pathToInjectedReactShim17 = normalizePath(path.join(new URL(import.meta.url).pathname, `../../assets/${shimIdForBuild}17.jsx`));
9
+ const pathToInjectedReactShim18 = normalizePath(path.join(new URL(import.meta.url).pathname, `../../assets/${shimIdForBuild}18.jsx`));
10
+ // This plugin works in both dev and build mode
11
+ // In dev mode, the UI makes a request to localhost:3002/@superblocksteam/react-shim
12
+ // In build mode, the plugin injects an additional entry point for the shim
13
+ export const injectReactVersionsPlugin = () => {
14
+ const packageJson = fs.readJsonSync(path.join(searchForWorkspaceRoot(process.cwd()), "package.json"));
15
+ if (!packageJson.dependencies?.react) {
16
+ throw new Error("React is not installed");
17
+ }
18
+ const version = semver.minVersion(packageJson.dependencies.react);
19
+ if (!version)
20
+ throw new Error("React is not installed");
21
+ const isReact17 = semver.satisfies(version, "^17");
22
+ const isReact18 = semver.satisfies(version, "^18");
23
+ return {
24
+ name: "react-versions-plugin",
25
+ enforce: "pre",
26
+ config(config) {
27
+ config.server = mergeConfig(config.server ?? {}, {
28
+ fs: {
29
+ allow: [
30
+ searchForWorkspaceRoot(process.cwd()),
31
+ pathToInjectedReactShim17,
32
+ pathToInjectedReactShim18,
33
+ ],
34
+ },
35
+ });
36
+ if (isReact18) {
37
+ // This fixes an issue in vite-plugin-react, from their source they say:
38
+ //
39
+ // We can't add `react-dom` because the dependency is `react-dom/client`
40
+ // for React 18 while it's `react-dom` for React 17. We'd need to detect
41
+ // what React version the user has installed.
42
+ config.optimizeDeps = mergeConfig(config.optimizeDeps ?? {}, {
43
+ include: ["react", "react-dom", "react-dom/client"],
44
+ });
45
+ config.resolve = mergeConfig(config.resolve ?? {}, {
46
+ dedupe: ["react", "react-dom", "react-dom/client"],
47
+ });
48
+ }
49
+ else if (isReact17) {
50
+ config.optimizeDeps = mergeConfig(config.optimizeDeps ?? {}, {
51
+ include: ["react", "react-dom"],
52
+ });
53
+ }
54
+ // Since the React plugin is part of both the dev and build modes, it's a good place
55
+ // to put other build settings
56
+ config.css = {
57
+ modules: {
58
+ // CSS modules will rewrite hyphens but keep both names in the output object
59
+ localsConvention: "camelCase",
60
+ },
61
+ };
62
+ return config;
63
+ },
64
+ resolveId(id) {
65
+ if (id === shimIdForBuild) {
66
+ return `/${shimFileNameBuild}`;
67
+ }
68
+ },
69
+ load(id) {
70
+ // We are modifying just the injectedReactShim code because import.meta.hot is a global handler,
71
+ // and we only need to handle the events in one place
72
+ const setupHotReloadingOneTime = (code) => {
73
+ if (!this.meta.watchMode)
74
+ return code;
75
+ return `import RefreshRuntime2 from "/@react-refresh";
76
+ RefreshRuntime2.injectIntoGlobalHook(window);
77
+ ${code}
78
+
79
+ if (import.meta.hot) {
80
+ import.meta.hot.on('vite:beforeUpdate', (data) => {
81
+ window.parent.postMessage(
82
+ { type: "hot-reloaded" },
83
+ "*"
84
+ );
85
+ });
86
+
87
+ import.meta.hot.on('config-reloaded', () => {
88
+ window.parent.postMessage(
89
+ { type: "reload-configs" },
90
+ "*"
91
+ );
92
+ });
93
+ }
94
+ `;
95
+ };
96
+ if (id === `/${shimFileNameDev}` || id === `/${shimFileNameBuild}`) {
97
+ if (isReact18) {
98
+ return {
99
+ code: setupHotReloadingOneTime(`export { loadReact } from "/@fs${pathToInjectedReactShim18.startsWith("/") ? "" : "/"}${pathToInjectedReactShim18}";`),
100
+ meta: { superblocks: true },
101
+ map: null,
102
+ };
103
+ }
104
+ else if (isReact17) {
105
+ return {
106
+ code: setupHotReloadingOneTime(`export { loadReact } from "/@fs${pathToInjectedReactShim18.startsWith("/") ? "" : "/"}${pathToInjectedReactShim17}";`),
107
+ meta: { superblocks: true },
108
+ map: null,
109
+ };
110
+ }
111
+ else {
112
+ throw new Error(`React version ${version.major} is not supported`);
113
+ }
114
+ }
115
+ },
116
+ buildStart() {
117
+ if (this.meta.watchMode)
118
+ return; // Don't inject in dev mode
119
+ // Inject the shim as an entry point file, which will be processed using the usual Vite pipeline
120
+ this.emitFile({
121
+ type: "chunk",
122
+ id: shimIdForBuild,
123
+ fileName: shimFileNameBuild,
124
+ });
125
+ },
126
+ };
127
+ };
@@ -0,0 +1,47 @@
1
+ import { bold, magenta, red } from "colorette";
2
+ import semver from "semver";
3
+ // If you are changing how application files work on disk, for example changing the directory layout,
4
+ // you need to tell the user how to upgrade manually.
5
+ const BREAKING_APPLICATION_VERSIONS = [
6
+ {
7
+ version: "0.0.20",
8
+ // This is an example message because 0.0.20 does not have a docs page for any migrations. This will be added
9
+ // in a future release
10
+ message: `${red("Warning")}: Your code must be updated due to a breaking change in custom component definitions. See docs.`,
11
+ },
12
+ {
13
+ version: "0.0.21",
14
+ // This is an example message because 0.0.21 does not have a docs page for any migrations. This will be added
15
+ // in a future release
16
+ message: `${red("Error")}: This version of the CLI is incompatible with any Custom Components you've previously used,
17
+ due to breaking changes introduced in the config.ts format and Custom Components React API.
18
+
19
+ ${bold("Your existing components are safe.")}
20
+
21
+ To manually migrate:
22
+
23
+ 1. Rename "eventHandlers" to "events".
24
+ 2. Update your properties to use the new format: ${magenta("https://docs.superblocks.com/applications/custom-components/development-lifecycle#configts")}
25
+ `,
26
+ },
27
+ {
28
+ version: "0.0.23",
29
+ message: `${red("Warning")}: Type definitions for custom components have changed to include null values,
30
+ which were missing from previous types. The previous types were not accurate.
31
+ Superblocks represents missing/undefined properties as null.
32
+
33
+ To manually update, you should follow Typescript errors in your IDE and update your code
34
+ to handle null values.
35
+
36
+ ${bold("Your existing components are safe.")}
37
+
38
+ See changelog: ${magenta("https://github.com/superblocksteam/superblocks-cli/blob/main/CHANGELOG.md")}
39
+ `,
40
+ },
41
+ ];
42
+ export function getWarningsForApplicationMigration(previousVersion, newVersion) {
43
+ const firstBreakingChange = BREAKING_APPLICATION_VERSIONS.find(({ version }) => {
44
+ return (semver.lt(previousVersion, version) && semver.lte(version, newVersion));
45
+ });
46
+ return firstBreakingChange?.message;
47
+ }
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDotfileMigrationNeeded = exports.migrateSuperblocksEntityConfig = exports.migrateSuperblocksMonorepoConfig = void 0;
4
- const tslib_1 = require("tslib");
5
- const semver_1 = tslib_1.__importDefault(require("semver"));
1
+ import semver from "semver";
6
2
  // These migrations are used to upgrade the Superblocks config files as needed.
7
3
  // For example if we add a new required field
8
4
  const MonorepoMigratorsFromOldVersion = [
@@ -12,10 +8,9 @@ const MonorepoMigratorsFromOldVersion = [
12
8
  },
13
9
  ];
14
10
  // Recursively migrate configs to the latest version
15
- async function migrateSuperblocksMonorepoConfig(config, options) {
11
+ export async function migrateSuperblocksMonorepoConfig(config, options) {
16
12
  return await sharedMigrator(MonorepoMigratorsFromOldVersion, config, options);
17
13
  }
18
- exports.migrateSuperblocksMonorepoConfig = migrateSuperblocksMonorepoConfig;
19
14
  // These migrations are used to upgrade the Superblocks config files as needed.
20
15
  // For example if we add a new required field
21
16
  const EntityMigratorsFromOldVersion = [
@@ -24,23 +19,21 @@ const EntityMigratorsFromOldVersion = [
24
19
  migrator: (config) => config,
25
20
  },
26
21
  ];
27
- async function migrateSuperblocksEntityConfig(config, options) {
22
+ export async function migrateSuperblocksEntityConfig(config, options) {
28
23
  return await sharedMigrator(EntityMigratorsFromOldVersion, config, options);
29
24
  }
30
- exports.migrateSuperblocksEntityConfig = migrateSuperblocksEntityConfig;
31
- function isDotfileMigrationNeeded(previousVersion, currentVersion) {
25
+ export function isDotfileMigrationNeeded(previousVersion, currentVersion) {
32
26
  return (previousVersion !== currentVersion &&
33
- (MonorepoMigratorsFromOldVersion.some(({ migrateWhenUpgradingTo }) => semver_1.default.gt(migrateWhenUpgradingTo, previousVersion) &&
34
- semver_1.default.lte(migrateWhenUpgradingTo, currentVersion)) ||
35
- EntityMigratorsFromOldVersion.some(({ migrateWhenUpgradingTo }) => semver_1.default.gt(migrateWhenUpgradingTo, previousVersion) &&
36
- semver_1.default.lte(migrateWhenUpgradingTo, currentVersion))));
27
+ (MonorepoMigratorsFromOldVersion.some(({ migrateWhenUpgradingTo }) => semver.gt(migrateWhenUpgradingTo, previousVersion) &&
28
+ semver.lte(migrateWhenUpgradingTo, currentVersion)) ||
29
+ EntityMigratorsFromOldVersion.some(({ migrateWhenUpgradingTo }) => semver.gt(migrateWhenUpgradingTo, previousVersion) &&
30
+ semver.lte(migrateWhenUpgradingTo, currentVersion))));
37
31
  }
38
- exports.isDotfileMigrationNeeded = isDotfileMigrationNeeded;
39
32
  async function sharedMigrator(migratorObject, config, { previousVersion, currentVersion, }) {
40
33
  let newConfig = JSON.parse(JSON.stringify(config));
41
34
  // Find all migrators in the range between previousVersion and currentVersion
42
- const migratorFns = migratorObject.filter(({ migrateWhenUpgradingTo }) => semver_1.default.gt(migrateWhenUpgradingTo, previousVersion) &&
43
- semver_1.default.lte(migrateWhenUpgradingTo, currentVersion));
35
+ const migratorFns = migratorObject.filter(({ migrateWhenUpgradingTo }) => semver.gt(migrateWhenUpgradingTo, previousVersion) &&
36
+ semver.lte(migrateWhenUpgradingTo, currentVersion));
44
37
  migratorFns.forEach(({ migrator, migrateWhenUpgradingTo }) => {
45
38
  try {
46
39
  newConfig = migrator(newConfig);