@superblocksteam/sdk 2.0.4 → 2.0.5
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/cli-replacement/automatic-upgrades.d.ts +10 -0
- package/dist/cli-replacement/automatic-upgrades.d.ts.map +1 -1
- package/dist/cli-replacement/automatic-upgrades.js +19 -12
- package/dist/cli-replacement/automatic-upgrades.js.map +1 -1
- package/dist/cli-replacement/dev.d.mts +2 -0
- package/dist/cli-replacement/dev.d.mts.map +1 -1
- package/dist/cli-replacement/dev.mjs +7 -3
- package/dist/cli-replacement/dev.mjs.map +1 -1
- package/dist/dev-utils/dev-tracer.d.ts.map +1 -1
- package/dist/dev-utils/dev-tracer.js +6 -0
- package/dist/dev-utils/dev-tracer.js.map +1 -1
- package/dist/dev-utils/vite-plugin-sb-cdn.d.mts.map +1 -1
- package/dist/dev-utils/vite-plugin-sb-cdn.mjs +6 -2
- package/dist/dev-utils/vite-plugin-sb-cdn.mjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/cli-replacement/automatic-upgrades.ts +26 -12
- package/src/cli-replacement/dev.mts +20 -2
- package/src/dev-utils/dev-tracer.ts +6 -0
- package/src/dev-utils/vite-plugin-sb-cdn.mts +10 -4
- package/src/index.ts +2 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -22,7 +22,11 @@ import { getLogger } from "../dev-utils/dev-logger.mjs";
|
|
|
22
22
|
import { createDevServer } from "../dev-utils/dev-server.mjs";
|
|
23
23
|
import tracer from "../dev-utils/dev-tracer.js";
|
|
24
24
|
import { SuperblocksSdk } from "../sdk.js";
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
checkVersionsAndUpgrade,
|
|
27
|
+
getCurrentCliVersion,
|
|
28
|
+
getCurrentLibraryVersionWithoutPM,
|
|
29
|
+
} from "./automatic-upgrades.js";
|
|
26
30
|
import type { DevLogger } from "../dev-utils/dev-logger.mjs";
|
|
27
31
|
import type { ApplicationConfig } from "../types/common.js";
|
|
28
32
|
import type { DraftInterface } from "@superblocksteam/vite-plugin-file-sync/draft-interface";
|
|
@@ -99,9 +103,15 @@ export async function dev(options: {
|
|
|
99
103
|
skipSync?: boolean;
|
|
100
104
|
|
|
101
105
|
applicationConfig?: ApplicationConfig;
|
|
106
|
+
|
|
107
|
+
/* For debugging purposes to get location of the cli */
|
|
108
|
+
superblocksPath?: string;
|
|
102
109
|
/* For redirecting output, like when running outside of the CLI */
|
|
103
110
|
logger?: (message: string) => void;
|
|
104
111
|
|
|
112
|
+
/* For a child process when restarting the dev server for automatic upgrades */
|
|
113
|
+
skipAutoUpgrade?: boolean;
|
|
114
|
+
|
|
105
115
|
/* To cancel the dev server */
|
|
106
116
|
signal?: AbortSignal;
|
|
107
117
|
}) {
|
|
@@ -115,8 +125,15 @@ export async function dev(options: {
|
|
|
115
125
|
uploadFirst,
|
|
116
126
|
skipSync,
|
|
117
127
|
applicationConfig,
|
|
128
|
+
skipAutoUpgrade,
|
|
118
129
|
} = options;
|
|
119
130
|
|
|
131
|
+
const cliVersion = await getCurrentCliVersion();
|
|
132
|
+
const libraryVersion = await getCurrentLibraryVersionWithoutPM();
|
|
133
|
+
logger.info(
|
|
134
|
+
`Running command: ${options.superblocksPath} dev${options.uploadFirst ? " --upload-first" : ""}${options.downloadFirst ? " --download-first" : ""} with baseUrl: ${applicationConfig?.superblocksBaseUrl}, cliVersion: ${cliVersion}, libraryVersion: ${libraryVersion?.alias} ${libraryVersion?.version}`,
|
|
135
|
+
);
|
|
136
|
+
|
|
120
137
|
// Add check for node_modules
|
|
121
138
|
if (!fs.existsSync(path.join(cwd, "node_modules"))) {
|
|
122
139
|
throw new Error(
|
|
@@ -175,7 +192,8 @@ export async function dev(options: {
|
|
|
175
192
|
// TODO(code-mode): package naming is preventing upgrade in ephemeral environments
|
|
176
193
|
if (
|
|
177
194
|
!process.env.PACKAGE_SUFFIX ||
|
|
178
|
-
process.env.PACKAGE_SUFFIX === ""
|
|
195
|
+
process.env.PACKAGE_SUFFIX === "" ||
|
|
196
|
+
!skipAutoUpgrade
|
|
179
197
|
) {
|
|
180
198
|
await checkVersionsAndUpgrade(lockService, applicationConfig);
|
|
181
199
|
}
|
|
@@ -14,13 +14,18 @@ import type { Span } from "@opentelemetry/api";
|
|
|
14
14
|
const ATTR_DEPLOYMENT_ENVIRONMENT = "deployment.environment";
|
|
15
15
|
// NOTE: @joeyagreco - this can be used to determine if we are using mock-csb, staging-csb, prod-csb, etc
|
|
16
16
|
const ATTR_SUPERBLOCKS_BASE_URL = "superblocks.base_url";
|
|
17
|
+
const ATTR_SUPERBLOCKS_CLI_TOKEN = "superblocks.cli_token";
|
|
17
18
|
let superblocksTracesUrl = undefined;
|
|
18
19
|
let superblocksHostname = "unknown";
|
|
20
|
+
let token = "unknown";
|
|
19
21
|
try {
|
|
20
22
|
const tokenWithUrl = await getLocalTokenWithUrl();
|
|
21
23
|
const superblocksBaseUrl = new URL(tokenWithUrl.superblocksBaseUrl);
|
|
22
24
|
superblocksTracesUrl = superblocksBaseUrl.origin + "/api/v1/traces";
|
|
23
25
|
superblocksHostname = superblocksBaseUrl.hostname;
|
|
26
|
+
if ("token" in tokenWithUrl) {
|
|
27
|
+
token = tokenWithUrl.token.substring(0, 8);
|
|
28
|
+
}
|
|
24
29
|
} catch (e) {
|
|
25
30
|
console.error("[tracing init] could not determine superblocks base url", e);
|
|
26
31
|
}
|
|
@@ -32,6 +37,7 @@ const sdk = new NodeSDK({
|
|
|
32
37
|
[ATTR_SERVICE_NAME]: "sdk-dev-server",
|
|
33
38
|
[ATTR_DEPLOYMENT_ENVIRONMENT]: process.env.SUPERBLOCKS_CLI_ENV,
|
|
34
39
|
[ATTR_SUPERBLOCKS_BASE_URL]: superblocksHostname,
|
|
40
|
+
[ATTR_SUPERBLOCKS_CLI_TOKEN]: token,
|
|
35
41
|
}),
|
|
36
42
|
),
|
|
37
43
|
traceExporter: new OTLPTraceExporter({
|
|
@@ -693,9 +693,6 @@ export async function superblocksCdnPlugin(
|
|
|
693
693
|
{
|
|
694
694
|
name: "vite-plugin-superblocks-cdn",
|
|
695
695
|
|
|
696
|
-
// run before Vite's module resolution
|
|
697
|
-
enforce: "pre",
|
|
698
|
-
|
|
699
696
|
/**
|
|
700
697
|
* Configure Vite to properly handle CDN modules
|
|
701
698
|
* - Exclude CDN modules from optimization
|
|
@@ -759,6 +756,8 @@ export async function superblocksCdnPlugin(
|
|
|
759
756
|
|
|
760
757
|
cdnDependencyChunks.set(dep, resolved);
|
|
761
758
|
}
|
|
759
|
+
|
|
760
|
+
debug("dependencies of CDN modules", cdnDependencyChunks);
|
|
762
761
|
},
|
|
763
762
|
|
|
764
763
|
resolveId(id, importer) {
|
|
@@ -786,6 +785,8 @@ export async function superblocksCdnPlugin(
|
|
|
786
785
|
* These modules will be loaded from CDN at runtime, so we return empty content
|
|
787
786
|
*/
|
|
788
787
|
async load(id: string) {
|
|
788
|
+
debug("loading module", id);
|
|
789
|
+
|
|
789
790
|
if (id.startsWith("cdn:")) {
|
|
790
791
|
debug(`Providing empty module for CDN import: ${id}`);
|
|
791
792
|
return "";
|
|
@@ -816,9 +817,13 @@ export async function superblocksCdnPlugin(
|
|
|
816
817
|
}
|
|
817
818
|
}
|
|
818
819
|
}
|
|
820
|
+
|
|
821
|
+
debug({ moduleToChunkMap, importToChunkMap });
|
|
819
822
|
},
|
|
820
823
|
|
|
821
824
|
async transformIndexHtml(html, { server }) {
|
|
825
|
+
debug("transforming index.html");
|
|
826
|
+
|
|
822
827
|
const isDevMode = !!server;
|
|
823
828
|
|
|
824
829
|
// Create the base import map with explicit ordering for proper resolution
|
|
@@ -877,7 +882,6 @@ export async function superblocksCdnPlugin(
|
|
|
877
882
|
|
|
878
883
|
// Get the asset URL as it would be served to the browser
|
|
879
884
|
// For Vite to correctly resolve this module in the browser
|
|
880
|
-
|
|
881
885
|
if (resolvedChunkUrl.startsWith("/")) {
|
|
882
886
|
// For paths starting with /, they're already root-relative
|
|
883
887
|
// Make sure we don't duplicate the base path
|
|
@@ -912,6 +916,8 @@ export async function superblocksCdnPlugin(
|
|
|
912
916
|
debug(`Resolved %s to %s`, moduleName, dependencyChunkUrl);
|
|
913
917
|
// Store in the import map scope
|
|
914
918
|
importMap.scopes[baseUrl][moduleName] = dependencyChunkUrl;
|
|
919
|
+
// Also add to main imports for external dependencies
|
|
920
|
+
importMap.imports[moduleName] = dependencyChunkUrl;
|
|
915
921
|
}
|
|
916
922
|
}
|
|
917
923
|
}
|
package/src/index.ts
CHANGED
|
@@ -114,6 +114,8 @@ export {
|
|
|
114
114
|
type ModeFlag,
|
|
115
115
|
} from "./version-control.mjs";
|
|
116
116
|
|
|
117
|
+
export { AUTO_UPGRADE_EXIT_CODE } from "./cli-replacement/automatic-upgrades.js";
|
|
118
|
+
|
|
117
119
|
export { createDevServer } from "./dev-utils/dev-server.mjs";
|
|
118
120
|
|
|
119
121
|
export { dev } from "./cli-replacement/dev.mjs";
|