@superblocksteam/sdk 2.0.6-next.79 → 2.0.6-next.8

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 (57) hide show
  1. package/dist/application-build.mjs +2 -6
  2. package/dist/application-build.mjs.map +1 -1
  3. package/dist/cli-replacement/automatic-upgrades.d.ts +2 -5
  4. package/dist/cli-replacement/automatic-upgrades.d.ts.map +1 -1
  5. package/dist/cli-replacement/automatic-upgrades.js +93 -221
  6. package/dist/cli-replacement/automatic-upgrades.js.map +1 -1
  7. package/dist/cli-replacement/dev.d.mts +2 -1
  8. package/dist/cli-replacement/dev.d.mts.map +1 -1
  9. package/dist/cli-replacement/dev.mjs +32 -57
  10. package/dist/cli-replacement/dev.mjs.map +1 -1
  11. package/dist/client.d.ts +0 -34
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/client.js +1 -92
  14. package/dist/client.js.map +1 -1
  15. package/dist/dev-utils/dev-logger.d.mts +7 -17
  16. package/dist/dev-utils/dev-logger.d.mts.map +1 -1
  17. package/dist/dev-utils/dev-logger.mjs +9 -50
  18. package/dist/dev-utils/dev-logger.mjs.map +1 -1
  19. package/dist/dev-utils/dev-server.d.mts.map +1 -1
  20. package/dist/dev-utils/dev-server.mjs +12 -8
  21. package/dist/dev-utils/dev-server.mjs.map +1 -1
  22. package/dist/dev-utils/dev-tracer.d.ts +0 -2
  23. package/dist/dev-utils/dev-tracer.d.ts.map +1 -1
  24. package/dist/dev-utils/dev-tracer.js +35 -42
  25. package/dist/dev-utils/dev-tracer.js.map +1 -1
  26. package/dist/dev-utils/vite-plugin-sb-cdn.d.mts.map +1 -1
  27. package/dist/dev-utils/vite-plugin-sb-cdn.mjs +3 -13
  28. package/dist/dev-utils/vite-plugin-sb-cdn.mjs.map +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/vite-plugin-inject-sb-ids-transform.mjs +1 -1
  34. package/dist/vite-plugin-inject-sb-ids-transform.mjs.map +1 -1
  35. package/package.json +4 -6
  36. package/src/application-build.mts +3 -6
  37. package/src/cli-replacement/automatic-upgrades.ts +113 -278
  38. package/src/cli-replacement/dev.mts +43 -77
  39. package/src/client.ts +0 -115
  40. package/src/dev-utils/dev-logger.mts +20 -94
  41. package/src/dev-utils/dev-server.mts +12 -10
  42. package/src/dev-utils/dev-tracer.ts +37 -48
  43. package/src/dev-utils/vite-plugin-sb-cdn.mts +3 -14
  44. package/src/index.ts +0 -4
  45. package/src/vite-plugin-inject-sb-ids-transform.mts +1 -1
  46. package/tsconfig.tsbuildinfo +1 -1
  47. package/dist/dev-utils/vite-plugin-build-manifest-stub.d.mts +0 -10
  48. package/dist/dev-utils/vite-plugin-build-manifest-stub.d.mts.map +0 -1
  49. package/dist/dev-utils/vite-plugin-build-manifest-stub.mjs +0 -27
  50. package/dist/dev-utils/vite-plugin-build-manifest-stub.mjs.map +0 -1
  51. package/dist/vite-plugin-generate-build-manifest.d.mts +0 -21
  52. package/dist/vite-plugin-generate-build-manifest.d.mts.map +0 -1
  53. package/dist/vite-plugin-generate-build-manifest.mjs +0 -131
  54. package/dist/vite-plugin-generate-build-manifest.mjs.map +0 -1
  55. package/src/dev-utils/vite-plugin-build-manifest-stub.mts +0 -30
  56. package/src/vite-plugin-generate-build-manifest.mts +0 -193
  57. package/test/clients.test.mts +0 -120
@@ -1,10 +0,0 @@
1
- import type { Plugin } from "vite";
2
- /**
3
- * This plugin is used to stub the build manifest module. It creates a virtual module
4
- * for the build manifest module and returns an empty object.
5
- *
6
- * This is meant to be used to avoid errors when the build manifest module is not found.
7
- * This plugin only runs in dev server mode.
8
- */
9
- export declare const buildManifestStubPlugin: () => Plugin;
10
- //# sourceMappingURL=vite-plugin-build-manifest-stub.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-plugin-build-manifest-stub.d.mts","sourceRoot":"","sources":["../../src/dev-utils/vite-plugin-build-manifest-stub.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAKnC;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,QAAO,MAiB1C,CAAC"}
@@ -1,27 +0,0 @@
1
- const BUILD_MANIFEST_MODULE_PATH = "./user-facing/build-manifest.js";
2
- const VIRTUAL_MODULE_ID = "\0virtual:build-manifest.js";
3
- /**
4
- * This plugin is used to stub the build manifest module. It creates a virtual module
5
- * for the build manifest module and returns an empty object.
6
- *
7
- * This is meant to be used to avoid errors when the build manifest module is not found.
8
- * This plugin only runs in dev server mode.
9
- */
10
- export const buildManifestStubPlugin = () => {
11
- return {
12
- name: "build-manifest-stub",
13
- enforce: "pre",
14
- apply: "serve",
15
- resolveId(source) {
16
- if (source === BUILD_MANIFEST_MODULE_PATH) {
17
- return VIRTUAL_MODULE_ID;
18
- }
19
- },
20
- load(id) {
21
- if (id === VIRTUAL_MODULE_ID) {
22
- return "export default {}";
23
- }
24
- },
25
- };
26
- };
27
- //# sourceMappingURL=vite-plugin-build-manifest-stub.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-plugin-build-manifest-stub.mjs","sourceRoot":"","sources":["../../src/dev-utils/vite-plugin-build-manifest-stub.mts"],"names":[],"mappings":"AAEA,MAAM,0BAA0B,GAAG,iCAAiC,CAAC;AACrE,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAW,EAAE;IAClD,OAAO;QACL,IAAI,EAAE,qBAAqB;QAC3B,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,OAAO;QAEd,SAAS,CAAC,MAAM;YACd,IAAI,MAAM,KAAK,0BAA0B,EAAE,CAAC;gBAC1C,OAAO,iBAAiB,CAAC;YAC3B,CAAC;QACH,CAAC;QACD,IAAI,CAAC,EAAE;YACL,IAAI,EAAE,KAAK,iBAAiB,EAAE,CAAC;gBAC7B,OAAO,mBAAmB,CAAC;YAC7B,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,21 +0,0 @@
1
- import type { Plugin } from "vite";
2
- export declare const scopeFileBaseName = "scope.ts";
3
- export declare const apiFileBaseName = "api.yaml";
4
- /**
5
- * Vite plugin that generates a build manifest for the application.
6
- *
7
- * This plugin will:
8
- * 1. Read all api.yaml and api.yml files in the application
9
- * 2. Read all scope.ts files in the application
10
- * 3. Generate a build manifest for the application
11
- * 4. Write the build manifest to a file in the build output directory
12
- *
13
- * The build manifest is a JSON object with the following properties:
14
- * - apis: a map of all apis in the application keyed by their file path
15
- * - apiDependencies: an array where each item represents an api and its dependencies
16
- *
17
- * @param root - The root directory of the application
18
- * @returns A Vite plugin that generates a build manifest for the application
19
- */
20
- export declare function generateBuildManifestPlugin(root: string): Plugin;
21
- //# sourceMappingURL=vite-plugin-generate-build-manifest.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-plugin-generate-build-manifest.d.mts","sourceRoot":"","sources":["../src/vite-plugin-generate-build-manifest.mts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAC5C,eAAO,MAAM,eAAe,aAAa,CAAC;AAQ1C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAwGjD,MAAM,CACZ"}
@@ -1,131 +0,0 @@
1
- import path from "node:path";
2
- import { parse } from "@babel/parser";
3
- import { getClientApiId } from "@superblocksteam/library-shared";
4
- import { resolveLanguageSpecificStepContentFromBlocks } from "@superblocksteam/util";
5
- import { getPageName } from "@superblocksteam/vite-plugin-file-sync";
6
- import { extractIdentifierPathsFromApi, extractApiDependencies, } from "@superblocksteam/vite-plugin-file-sync/binding-extraction";
7
- import { getScope, extractImportsFromAst, } from "@superblocksteam/vite-plugin-file-sync/parsing";
8
- import { yellow, red } from "colorette";
9
- import fg from "fast-glob";
10
- import fs from "fs-extra";
11
- import { createLogger } from "vite";
12
- import yaml from "yaml";
13
- import { getLogger } from "./dev-utils/dev-logger.mjs";
14
- export const scopeFileBaseName = "scope.ts";
15
- export const apiFileBaseName = "api.yaml";
16
- /**
17
- * Vite plugin that generates a build manifest for the application.
18
- *
19
- * This plugin will:
20
- * 1. Read all api.yaml and api.yml files in the application
21
- * 2. Read all scope.ts files in the application
22
- * 3. Generate a build manifest for the application
23
- * 4. Write the build manifest to a file in the build output directory
24
- *
25
- * The build manifest is a JSON object with the following properties:
26
- * - apis: a map of all apis in the application keyed by their file path
27
- * - apiDependencies: an array where each item represents an api and its dependencies
28
- *
29
- * @param root - The root directory of the application
30
- * @returns A Vite plugin that generates a build manifest for the application
31
- */
32
- export function generateBuildManifestPlugin(root) {
33
- const viteLogger = createLogger();
34
- const logger = getLogger();
35
- viteLogger.info = (msg) => logger.info(msg);
36
- viteLogger.warn = (msg) => {
37
- logger.warn(yellow(msg));
38
- };
39
- viteLogger.warnOnce = (msg) => {
40
- logger.warn(yellow(msg));
41
- };
42
- viteLogger.error = (msg) => {
43
- logger.error(red(msg));
44
- };
45
- viteLogger.clearScreen = () => { };
46
- const scopesByPage = {};
47
- const apiFiles = {};
48
- let buildManifest = { apis: {}, apiDependencies: [] };
49
- return {
50
- name: "sb-generate-build-manifest",
51
- apply: "build",
52
- enforce: "pre",
53
- async buildStart() {
54
- const apiDocuments = await fg(["**/api.yaml", "**/api.yml"], {
55
- cwd: root,
56
- });
57
- for (const apiFilePath of apiDocuments) {
58
- const absoluteApiFilePath = path.join(root, apiFilePath);
59
- const document = await fs.readFile(absoluteApiFilePath, "utf-8");
60
- const apiPb = yaml.parse(document);
61
- await resolveLanguageSpecificStepContentFromBlocks(path.dirname(absoluteApiFilePath), apiPb.blocks ?? [], {});
62
- const pageName = getPageName(apiFilePath);
63
- apiPb.metadata.id = getClientApiId(apiPb.metadata.name, pageName);
64
- apiFiles[apiFilePath] = { apiPb, pageName };
65
- }
66
- },
67
- transform(code, id) {
68
- if (id.endsWith(scopeFileBaseName)) {
69
- const ast = parse(code, {
70
- sourceType: "module",
71
- sourceFilename: id,
72
- plugins: [["typescript", {}]],
73
- });
74
- const scopeFileMeta = {
75
- code,
76
- ast,
77
- imports: extractImportsFromAst(ast),
78
- };
79
- const scope = getScope(id, scopeFileMeta);
80
- scopesByPage[getPageName(id)] = scope;
81
- }
82
- return code;
83
- },
84
- async generateBundle() {
85
- const allApiNames = getAllUniqueApiNames(apiFiles);
86
- const allApis = Object.entries(apiFiles).reduce((acc, [id, api]) => {
87
- acc[id] = {
88
- api,
89
- scopeId: scopesByPage[api.pageName]?.scopeId ?? "",
90
- };
91
- return acc;
92
- }, {});
93
- const deps = await getApiDependencies(allApiNames, apiFiles);
94
- buildManifest = {
95
- apis: allApis,
96
- apiDependencies: deps,
97
- };
98
- this.emitFile({
99
- type: "prebuilt-chunk",
100
- fileName: "assets/build-manifest.js",
101
- code: `export default ${JSON.stringify(buildManifest)}`,
102
- exports: ["default"],
103
- });
104
- },
105
- };
106
- }
107
- function getAllUniqueApiNames(apiFiles) {
108
- const allApiNamesSet = new Set(Object.values(apiFiles).map((api) => api.apiPb.metadata.name));
109
- return Array.from(allApiNamesSet);
110
- }
111
- async function getApiDependencies(apiNames, apiFiles) {
112
- const deps = [];
113
- // TODO: This logic is a copy of the extractApiParamsAndDependencies function in the
114
- // fileSyncVitePlugin (https://github.com/superblocksteam/superblocks/blob/474c0b11d79a1d6988864fb20d5ec26f92931fde/packages/vite-plugin-file-sync/src/file-sync-vite-plugin.ts#L261-L280).
115
- //
116
- // This logic should be refactored so that it can be shared between the two plugins.
117
- await Promise.all([
118
- ...Object.values(apiFiles).map(async (api) => {
119
- const bindings = await extractIdentifierPathsFromApi(api);
120
- const allIdentifiers = bindings.flatMap((binding) => binding.bindings);
121
- const apiDependencies = extractApiDependencies(apiNames, bindings);
122
- deps.push({
123
- apiName: api.apiPb.metadata.name,
124
- params: allIdentifiers,
125
- dependencies: apiDependencies,
126
- });
127
- }),
128
- ]);
129
- return deps;
130
- }
131
- //# sourceMappingURL=vite-plugin-generate-build-manifest.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-plugin-generate-build-manifest.mjs","sourceRoot":"","sources":["../src/vite-plugin-generate-build-manifest.mts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,4CAA4C,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,2DAA2D,CAAC;AACnE,OAAO,EACL,QAAQ,EACR,qBAAqB,GACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,MAAM,WAAW,CAAC;AAC3B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AASvD,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAC5C,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC;AAQ1C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,2BAA2B,CAAC,IAAY;IACtD,MAAM,UAAU,GAAG,YAAY,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,UAAU,CAAC,IAAI,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG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AAQ,CAAC,CAAC;YACvE,MAAM,eAAe,GAAG,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACnE,IAAI,CAAC,IAAI,CAAC;gBACR,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI;gBAChC,MAAM,EAAE,cAAc;gBACtB,YAAY,EAAE,eAAe;aAC9B,CAAC,CAAC;QACL,CAAC,CAAC;KACH,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,30 +0,0 @@
1
- import type { Plugin } from "vite";
2
-
3
- const BUILD_MANIFEST_MODULE_PATH = "./user-facing/build-manifest.js";
4
- const VIRTUAL_MODULE_ID = "\0virtual:build-manifest.js";
5
-
6
- /**
7
- * This plugin is used to stub the build manifest module. It creates a virtual module
8
- * for the build manifest module and returns an empty object.
9
- *
10
- * This is meant to be used to avoid errors when the build manifest module is not found.
11
- * This plugin only runs in dev server mode.
12
- */
13
- export const buildManifestStubPlugin = (): Plugin => {
14
- return {
15
- name: "build-manifest-stub",
16
- enforce: "pre",
17
- apply: "serve",
18
-
19
- resolveId(source) {
20
- if (source === BUILD_MANIFEST_MODULE_PATH) {
21
- return VIRTUAL_MODULE_ID;
22
- }
23
- },
24
- load(id) {
25
- if (id === VIRTUAL_MODULE_ID) {
26
- return "export default {}";
27
- }
28
- },
29
- };
30
- };
@@ -1,193 +0,0 @@
1
- import path from "node:path";
2
- import { parse } from "@babel/parser";
3
- import { getClientApiId } from "@superblocksteam/library-shared";
4
- import { resolveLanguageSpecificStepContentFromBlocks } from "@superblocksteam/util";
5
- import { getPageName } from "@superblocksteam/vite-plugin-file-sync";
6
- import {
7
- extractIdentifierPathsFromApi,
8
- extractApiDependencies,
9
- } from "@superblocksteam/vite-plugin-file-sync/binding-extraction";
10
- import {
11
- getScope,
12
- extractImportsFromAst,
13
- } from "@superblocksteam/vite-plugin-file-sync/parsing";
14
- import { yellow, red } from "colorette";
15
- import fg from "fast-glob";
16
- import fs from "fs-extra";
17
- import { createLogger } from "vite";
18
- import yaml from "yaml";
19
- import { getLogger } from "./dev-utils/dev-logger.mjs";
20
- import type { ParseResult } from "@babel/parser";
21
- import type { File } from "@babel/types";
22
- import type {
23
- DeleteMeLibraryApi,
24
- StaticScope,
25
- } from "@superblocksteam/library-shared/types";
26
- import type { Plugin } from "vite";
27
-
28
- export const scopeFileBaseName = "scope.ts";
29
- export const apiFileBaseName = "api.yaml";
30
-
31
- type ApiDependency = {
32
- apiName: string;
33
- params: string[];
34
- dependencies: string[];
35
- };
36
-
37
- /**
38
- * Vite plugin that generates a build manifest for the application.
39
- *
40
- * This plugin will:
41
- * 1. Read all api.yaml and api.yml files in the application
42
- * 2. Read all scope.ts files in the application
43
- * 3. Generate a build manifest for the application
44
- * 4. Write the build manifest to a file in the build output directory
45
- *
46
- * The build manifest is a JSON object with the following properties:
47
- * - apis: a map of all apis in the application keyed by their file path
48
- * - apiDependencies: an array where each item represents an api and its dependencies
49
- *
50
- * @param root - The root directory of the application
51
- * @returns A Vite plugin that generates a build manifest for the application
52
- */
53
- export function generateBuildManifestPlugin(root: string) {
54
- const viteLogger = createLogger();
55
- const logger = getLogger();
56
- viteLogger.info = (msg: string) => logger.info(msg);
57
- viteLogger.warn = (msg: string) => {
58
- logger.warn(yellow(msg));
59
- };
60
- viteLogger.warnOnce = (msg: string) => {
61
- logger.warn(yellow(msg));
62
- };
63
- viteLogger.error = (msg: string) => {
64
- logger.error(red(msg));
65
- };
66
-
67
- viteLogger.clearScreen = () => {};
68
-
69
- const scopesByPage: Record<string, StaticScope | null> = {};
70
- const apiFiles: Record<string, DeleteMeLibraryApi> = {};
71
- let buildManifest: {
72
- apis: Record<string, { api: DeleteMeLibraryApi; scopeId: string }>;
73
- apiDependencies: ApiDependency[];
74
- } = { apis: {}, apiDependencies: [] };
75
-
76
- return {
77
- name: "sb-generate-build-manifest",
78
- apply: "build",
79
- enforce: "pre",
80
-
81
- async buildStart() {
82
- const apiDocuments = await fg(["**/api.yaml", "**/api.yml"], {
83
- cwd: root,
84
- });
85
-
86
- for (const apiFilePath of apiDocuments) {
87
- const absoluteApiFilePath = path.join(root, apiFilePath);
88
-
89
- const document = await fs.readFile(absoluteApiFilePath, "utf-8");
90
- const apiPb = yaml.parse(document);
91
-
92
- await resolveLanguageSpecificStepContentFromBlocks(
93
- path.dirname(absoluteApiFilePath),
94
- apiPb.blocks ?? [],
95
- {},
96
- );
97
-
98
- const pageName = getPageName(apiFilePath);
99
- apiPb.metadata.id = getClientApiId(apiPb.metadata.name, pageName);
100
- apiFiles[apiFilePath] = { apiPb, pageName };
101
- }
102
- },
103
-
104
- transform(code: string, id: string) {
105
- if (id.endsWith(scopeFileBaseName)) {
106
- const ast = parse(code, {
107
- sourceType: "module",
108
- sourceFilename: id,
109
- plugins: [["typescript", {}]],
110
- });
111
-
112
- const scopeFileMeta: {
113
- code: string;
114
- ast: ParseResult<File>;
115
- imports: Record<string, boolean>;
116
- } = {
117
- code,
118
- ast,
119
- imports: extractImportsFromAst(ast),
120
- };
121
- const scope = getScope(id, scopeFileMeta);
122
-
123
- scopesByPage[getPageName(id)] = scope;
124
- }
125
-
126
- return code;
127
- },
128
-
129
- async generateBundle() {
130
- const allApiNames = getAllUniqueApiNames(apiFiles);
131
-
132
- const allApis = Object.entries(apiFiles).reduce(
133
- (acc, [id, api]) => {
134
- acc[id] = {
135
- api,
136
- scopeId: scopesByPage[api.pageName]?.scopeId ?? "",
137
- };
138
- return acc;
139
- },
140
- {} as Record<string, { api: DeleteMeLibraryApi; scopeId: string }>,
141
- );
142
-
143
- const deps = await getApiDependencies(allApiNames, apiFiles);
144
-
145
- buildManifest = {
146
- apis: allApis,
147
- apiDependencies: deps,
148
- };
149
-
150
- this.emitFile({
151
- type: "prebuilt-chunk",
152
- fileName: "assets/build-manifest.js",
153
- code: `export default ${JSON.stringify(buildManifest)}`,
154
- exports: ["default"],
155
- });
156
- },
157
- } as Plugin;
158
- }
159
-
160
- function getAllUniqueApiNames(
161
- apiFiles: Record<string, DeleteMeLibraryApi>,
162
- ): string[] {
163
- const allApiNamesSet = new Set<string>(
164
- Object.values(apiFiles).map((api) => api.apiPb.metadata.name),
165
- );
166
- return Array.from(allApiNamesSet);
167
- }
168
-
169
- async function getApiDependencies(
170
- apiNames: string[],
171
- apiFiles: Record<string, DeleteMeLibraryApi>,
172
- ): Promise<ApiDependency[]> {
173
- const deps: ApiDependency[] = [];
174
-
175
- // TODO: This logic is a copy of the extractApiParamsAndDependencies function in the
176
- // fileSyncVitePlugin (https://github.com/superblocksteam/superblocks/blob/474c0b11d79a1d6988864fb20d5ec26f92931fde/packages/vite-plugin-file-sync/src/file-sync-vite-plugin.ts#L261-L280).
177
- //
178
- // This logic should be refactored so that it can be shared between the two plugins.
179
- await Promise.all([
180
- ...Object.values(apiFiles).map(async (api) => {
181
- const bindings = await extractIdentifierPathsFromApi(api);
182
- const allIdentifiers = bindings.flatMap((binding) => binding.bindings);
183
- const apiDependencies = extractApiDependencies(apiNames, bindings);
184
- deps.push({
185
- apiName: api.apiPb.metadata.name,
186
- params: allIdentifiers,
187
- dependencies: apiDependencies,
188
- });
189
- }),
190
- ]);
191
-
192
- return deps;
193
- }
@@ -1,120 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { expect } from "chai";
4
- import { describe, it } from "mocha";
5
- import { BranchSource, getCurrentBranchInfo } from "../src/client.js";
6
- import { getCurrentGitBranch } from "../src/version-control.mjs";
7
- import type { SuperblocksDevEnvironmentConfig } from "@superblocksteam/util";
8
-
9
- // The .superblocks folder is located in the 'test' directory, so we need to prefix the path in order to find it.
10
- const testPathPrefix = "test";
11
- const superblocksTestFolder = path.join(
12
- process.cwd(),
13
- testPathPrefix,
14
- ".superblocks",
15
- );
16
- const devEnvBranch = "dev-branch";
17
- const currentGitBranch = await getCurrentGitBranch();
18
-
19
- describe("get current branch info", () => {
20
- let createdSuperblocksFolder = false;
21
-
22
- before(async function () {
23
- // Make the .superblocks folder in the test directory, if it is missing. It should be git-ignored.
24
- if (!fs.existsSync(superblocksTestFolder)) {
25
- fs.mkdirSync(superblocksTestFolder, { recursive: true });
26
- createdSuperblocksFolder = true;
27
- }
28
- // Create a dev-environment.json file in the .superblocks folder.
29
- const devEnvironmentJson = path.join(
30
- superblocksTestFolder,
31
- "dev-environment.json",
32
- );
33
- fs.writeFileSync(
34
- devEnvironmentJson,
35
- JSON.stringify({
36
- branch: devEnvBranch,
37
- configType: "DEV_ENVIRONMENT",
38
- } as SuperblocksDevEnvironmentConfig),
39
- );
40
- });
41
-
42
- after(async function () {
43
- // Delete the .superblocks folder in the test directory.
44
- if (createdSuperblocksFolder && fs.existsSync(superblocksTestFolder)) {
45
- fs.rmSync(superblocksTestFolder, { recursive: true });
46
- }
47
- });
48
-
49
- it("should find the dev environment config and return a valid branch info object", async () => {
50
- const branchInfo = await getCurrentBranchInfo(undefined, testPathPrefix);
51
-
52
- expect(branchInfo.branchName).to.equal(devEnvBranch);
53
- expect(branchInfo.source).to.equal(BranchSource.DEV_ENVIRONMENT);
54
- expect(branchInfo.userSpecifiedBranch).to.be.undefined;
55
- expect(branchInfo.isDefinedInDevEnvironmentConfig()).to.be.true;
56
- expect(branchInfo.isDevEnvironmentWithUserSpecifiedBranch()).to.be.false;
57
- expect(branchInfo.isDefaultBranch()).to.be.false;
58
-
59
- // Call it again to make sure it has the same properties
60
- const branchInfo2 = await getCurrentBranchInfo(undefined, testPathPrefix);
61
- expect(branchInfo).to.deep.equal(branchInfo2);
62
- });
63
-
64
- it("should find the dev environment config and include the user-specified branch parameter", async () => {
65
- const userBranch = "test-user-branch";
66
- const branchInfo = await getCurrentBranchInfo(userBranch, testPathPrefix);
67
-
68
- expect(branchInfo.branchName).to.equal(devEnvBranch);
69
- expect(branchInfo.source).to.equal(BranchSource.DEV_ENVIRONMENT);
70
- expect(branchInfo.userSpecifiedBranch).to.equal(userBranch);
71
- expect(branchInfo.isDefinedInDevEnvironmentConfig()).to.be.true;
72
- expect(branchInfo.isDevEnvironmentWithUserSpecifiedBranch()).to.be.true;
73
- expect(branchInfo.isDefaultBranch()).to.be.false;
74
-
75
- // Call it again to make sure it's the same object
76
- const branchInfo2 = await getCurrentBranchInfo(userBranch, testPathPrefix);
77
- expect(branchInfo).to.deep.equal(branchInfo2);
78
-
79
- // Call it again without the test path will find the user supplied branch
80
- const branchInfo3 = await getCurrentBranchInfo(userBranch);
81
- expect(branchInfo3.branchName).to.equal(userBranch);
82
- expect(branchInfo3.source).to.equal(BranchSource.COMMAND_LINE);
83
- expect(branchInfo3.userSpecifiedBranch).to.equal(userBranch);
84
- expect(branchInfo3.isDefinedInDevEnvironmentConfig()).to.be.false;
85
- expect(branchInfo3.isDevEnvironmentWithUserSpecifiedBranch()).to.be.false;
86
- expect(branchInfo3.isDefaultBranch()).to.be.false;
87
- });
88
-
89
- it("should not find a dev environment config and return an info with our git branch", async () => {
90
- const branchInfo = await getCurrentBranchInfo();
91
- expect(branchInfo.branchName).to.equal(currentGitBranch);
92
- expect(branchInfo.source).to.equal(BranchSource.GIT_REPO);
93
- expect(branchInfo.userSpecifiedBranch).to.be.undefined;
94
- expect(branchInfo.isDefinedInDevEnvironmentConfig()).to.be.false;
95
- expect(branchInfo.isDevEnvironmentWithUserSpecifiedBranch()).to.be.false;
96
- expect(branchInfo.isDefaultBranch()).to.be.false;
97
-
98
- // Call it again to make sure it's the same object
99
- const branchInfo2 = await getCurrentBranchInfo();
100
- expect(branchInfo).to.deep.equal(branchInfo2);
101
- });
102
-
103
- it("should not find a dev environment config and return an info with the user-specified branch", async () => {
104
- const userBranch = "test-user-branch";
105
- expect(userBranch).to.not.equal(devEnvBranch);
106
- expect(userBranch).to.not.equal(currentGitBranch);
107
-
108
- const branchInfo = await getCurrentBranchInfo(userBranch);
109
- expect(branchInfo.branchName).to.equal(userBranch);
110
- expect(branchInfo.source).to.equal(BranchSource.COMMAND_LINE);
111
- expect(branchInfo.userSpecifiedBranch).to.equal(userBranch);
112
- expect(branchInfo.isDefinedInDevEnvironmentConfig()).to.be.false;
113
- expect(branchInfo.isDevEnvironmentWithUserSpecifiedBranch()).to.be.false;
114
- expect(branchInfo.isDefaultBranch()).to.be.false;
115
-
116
- // Call it again to make sure it's the same object
117
- const branchInfo2 = await getCurrentBranchInfo(userBranch);
118
- expect(branchInfo).to.deep.equal(branchInfo2);
119
- });
120
- });