@embeddable.com/sdk-core 3.12.4 → 3.12.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/lib/index.esm.js +43 -15
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +43 -15
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/dev.ts +21 -8
- package/src/generate.test.ts +1 -1
- package/src/logger.test.ts +5 -1
- package/src/login.test.ts +17 -4
- package/src/provideConfig.test.ts +17 -6
- package/src/push.test.ts +1 -0
- package/src/push.ts +7 -4
- package/src/workspaceUtils.test.ts +1 -1
- package/src/workspaceUtils.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embeddable.com/sdk-core",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.5",
|
|
4
4
|
"description": "Core Embeddable SDK module responsible for web-components bundling and publishing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"embeddable",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@embeddable.com/sdk-utils": "0.6.
|
|
41
|
+
"@embeddable.com/sdk-utils": "0.6.2",
|
|
42
42
|
"@inquirer/prompts": "^7.2.1",
|
|
43
43
|
"@stencil/core": "^4.23.0",
|
|
44
44
|
"@swc-node/register": "^1.10.9",
|
package/src/dev.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
createNodeLogger,
|
|
11
11
|
createNodeSys,
|
|
12
12
|
} from "@stencil/core/sys/node";
|
|
13
|
-
import { glob } from "node:fs/promises";
|
|
14
13
|
import { RollupWatcher } from "rollup";
|
|
15
14
|
import * as http from "node:http";
|
|
16
15
|
import { IncomingMessage, Server, ServerResponse } from "http";
|
|
@@ -32,6 +31,7 @@ const minimist = require("minimist");
|
|
|
32
31
|
import { initLogger, logError } from "./logger";
|
|
33
32
|
import fg from "fast-glob";
|
|
34
33
|
import * as dotenv from "dotenv";
|
|
34
|
+
import { pathToFileURL } from "node:url";
|
|
35
35
|
|
|
36
36
|
dotenv.config();
|
|
37
37
|
|
|
@@ -121,7 +121,7 @@ export default async () => {
|
|
|
121
121
|
|
|
122
122
|
const serve = serveStatic(config.client.buildDir);
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
let workspacePreparation = ora("Preparing workspace...").start();
|
|
125
125
|
|
|
126
126
|
breadcrumbs.push("get preview workspace");
|
|
127
127
|
try {
|
|
@@ -130,10 +130,20 @@ export default async () => {
|
|
|
130
130
|
config,
|
|
131
131
|
);
|
|
132
132
|
} catch (e: any) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
if (e.response?.status === 401) {
|
|
134
|
+
// login and retry
|
|
135
|
+
await login();
|
|
136
|
+
workspacePreparation = ora("Preparing workspace...").start();
|
|
137
|
+
previewWorkspace = await getPreviewWorkspace(
|
|
138
|
+
workspacePreparation,
|
|
139
|
+
config,
|
|
140
|
+
);
|
|
141
|
+
} else {
|
|
142
|
+
workspacePreparation.fail(
|
|
143
|
+
e.response?.data?.errorMessage || "Unknown error: " + e.message,
|
|
144
|
+
);
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
137
147
|
}
|
|
138
148
|
|
|
139
149
|
workspacePreparation.succeed("Workspace is ready");
|
|
@@ -325,11 +335,14 @@ const sendDataModelsAndContextsChanges = async (ctx: any) => {
|
|
|
325
335
|
PRESET_FILES,
|
|
326
336
|
);
|
|
327
337
|
|
|
328
|
-
|
|
338
|
+
// Map the files to include their full filenames
|
|
339
|
+
const filesList = [...cubeFilesList, ...contextFilesList].map(
|
|
340
|
+
(entry): [string, string] => [path.basename(entry[1]), entry[1]],
|
|
341
|
+
);
|
|
329
342
|
|
|
330
343
|
// add manifest to the archive
|
|
331
344
|
filesList.push([
|
|
332
|
-
"embeddable-manifest",
|
|
345
|
+
"embeddable-manifest.json",
|
|
333
346
|
path.resolve(ctx.client.buildDir, "embeddable-manifest.json"),
|
|
334
347
|
]);
|
|
335
348
|
|
package/src/generate.test.ts
CHANGED
|
@@ -140,7 +140,7 @@ describe("generate", () => {
|
|
|
140
140
|
config: {
|
|
141
141
|
configPath: "buildDir/stencil.config.ts",
|
|
142
142
|
devMode: true,
|
|
143
|
-
maxConcurrentWorkers: 8,
|
|
143
|
+
maxConcurrentWorkers: process.platform === "win32" ? 0 : 8,
|
|
144
144
|
minifyCss: false,
|
|
145
145
|
minifyJs: false,
|
|
146
146
|
namespace: "embeddable-wrapper",
|
package/src/logger.test.ts
CHANGED
|
@@ -14,7 +14,11 @@ describe("Logger", () => {
|
|
|
14
14
|
it("should create log directory if it does not exist", async () => {
|
|
15
15
|
await initLogger("test");
|
|
16
16
|
expect(fs.mkdir).toHaveBeenCalledWith(
|
|
17
|
-
expect.stringContaining(
|
|
17
|
+
expect.stringContaining(
|
|
18
|
+
process.platform === "win32"
|
|
19
|
+
? ".embeddable\\logs"
|
|
20
|
+
: ".embeddable/logs",
|
|
21
|
+
),
|
|
18
22
|
{ recursive: true },
|
|
19
23
|
);
|
|
20
24
|
});
|
package/src/login.test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import login, { resolveFiles, getToken } from "./login";
|
|
|
3
3
|
import { vi } from "vitest";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
|
+
import { PathLike } from "node:fs";
|
|
6
7
|
import { mkdir, access, writeFile, readFile } from "fs/promises";
|
|
7
8
|
import { CREDENTIALS_DIR, CREDENTIALS_FILE } from "./credentials";
|
|
8
9
|
import { http, HttpResponse } from "msw";
|
|
@@ -48,14 +49,21 @@ vi.mock("node:url", () => ({
|
|
|
48
49
|
pathToFileURL: vi.fn(),
|
|
49
50
|
}));
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
// Create a mock module factory
|
|
53
|
+
const mockConfigModule = {
|
|
52
54
|
default: {
|
|
53
55
|
authDomain: "test-domain.com",
|
|
54
56
|
},
|
|
55
|
-
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Mock both possible config paths
|
|
60
|
+
vi.mock(`${process.cwd()}/embeddable.config.js`, () => mockConfigModule);
|
|
61
|
+
vi.mock(`${process.cwd()}/embeddable.config.ts`, () => mockConfigModule);
|
|
56
62
|
|
|
57
63
|
describe("login", () => {
|
|
58
64
|
beforeEach(async () => {
|
|
65
|
+
vi.resetModules();
|
|
66
|
+
|
|
59
67
|
vi.mocked(readFile).mockImplementation(async () =>
|
|
60
68
|
Buffer.from(`{"access_token":"mocked-token"}`),
|
|
61
69
|
);
|
|
@@ -68,9 +76,14 @@ describe("login", () => {
|
|
|
68
76
|
|
|
69
77
|
vi.mocked(writeFile).mockImplementation(async () => undefined);
|
|
70
78
|
|
|
71
|
-
|
|
79
|
+
// Mock that only the TS config exists
|
|
80
|
+
vi.mocked(existsSync).mockImplementation((path: PathLike) =>
|
|
81
|
+
path.toString().endsWith("embeddable.config.ts"),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// Mock URL creation
|
|
72
85
|
vi.mocked(pathToFileURL).mockImplementation(
|
|
73
|
-
() => new URL(
|
|
86
|
+
(path) => new URL(`file://${path}`),
|
|
74
87
|
);
|
|
75
88
|
});
|
|
76
89
|
|
|
@@ -1,32 +1,43 @@
|
|
|
1
1
|
import { pathToFileURL } from "node:url";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
+
import { PathLike } from "node:fs";
|
|
3
4
|
import provideConfig from "./provideConfig";
|
|
4
5
|
import { vi } from "vitest";
|
|
5
6
|
|
|
7
|
+
// Mock fs module
|
|
6
8
|
vi.mock("node:fs", () => ({
|
|
7
9
|
existsSync: vi.fn(),
|
|
8
10
|
}));
|
|
9
11
|
|
|
12
|
+
// Mock url module
|
|
10
13
|
vi.mock("node:url", () => ({
|
|
11
14
|
pathToFileURL: vi.fn(),
|
|
12
15
|
}));
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
// Create a mock module factory
|
|
18
|
+
const mockConfigModule = {
|
|
15
19
|
default: "mocked-config",
|
|
16
|
-
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Mock both possible config paths
|
|
23
|
+
vi.mock(`${process.cwd()}/embeddable.config.js`, () => mockConfigModule);
|
|
24
|
+
vi.mock(`${process.cwd()}/embeddable.config.ts`, () => mockConfigModule);
|
|
17
25
|
|
|
18
26
|
describe("provideConfig", () => {
|
|
19
27
|
beforeEach(() => {
|
|
20
|
-
vi.
|
|
28
|
+
vi.resetModules();
|
|
29
|
+
// Mock that only the TS config exists
|
|
30
|
+
vi.mocked(existsSync).mockImplementation((path: PathLike) =>
|
|
31
|
+
path.toString().endsWith("embeddable.config.ts"),
|
|
32
|
+
);
|
|
33
|
+
// Mock URL creation
|
|
21
34
|
vi.mocked(pathToFileURL).mockImplementation(
|
|
22
|
-
() => new URL(
|
|
35
|
+
(path) => new URL(`file://${path}`),
|
|
23
36
|
);
|
|
24
37
|
});
|
|
25
38
|
|
|
26
39
|
it("should return the default config when the config file exists", async () => {
|
|
27
40
|
const result = await provideConfig();
|
|
28
|
-
|
|
29
|
-
// Assert the result
|
|
30
41
|
expect(result).toEqual("mocked-config");
|
|
31
42
|
});
|
|
32
43
|
});
|
package/src/push.test.ts
CHANGED
package/src/push.ts
CHANGED
|
@@ -148,7 +148,12 @@ async function buildArchive(config: any) {
|
|
|
148
148
|
PRESET_FILES,
|
|
149
149
|
);
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
// Map the files to include their full filenames
|
|
152
|
+
const filesList = [...cubeFilesList, ...contextFilesList].map(
|
|
153
|
+
(entry): [string, string] => [path.basename(entry[1]), entry[1]],
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
await archive(config, filesList);
|
|
152
157
|
return spinnerArchive.succeed("Bundling completed");
|
|
153
158
|
}
|
|
154
159
|
|
|
@@ -172,10 +177,8 @@ export async function archive(
|
|
|
172
177
|
}
|
|
173
178
|
|
|
174
179
|
for (const fileData of yamlFiles) {
|
|
175
|
-
const fileName = fileData[1].split("/").pop();
|
|
176
|
-
|
|
177
180
|
_archiver.file(fileData[1], {
|
|
178
|
-
name:
|
|
181
|
+
name: fileData[0],
|
|
179
182
|
});
|
|
180
183
|
}
|
|
181
184
|
|
package/src/workspaceUtils.ts
CHANGED
|
@@ -15,6 +15,10 @@ export async function getWorkspaces(
|
|
|
15
15
|
|
|
16
16
|
return response.data?.filter((w: any) => !w.devWorkspace);
|
|
17
17
|
} catch (e: any) {
|
|
18
|
+
if (ctx.dev?.watch) {
|
|
19
|
+
workspaceSpinner.stop();
|
|
20
|
+
throw e;
|
|
21
|
+
}
|
|
18
22
|
if (e.response?.status === 401) {
|
|
19
23
|
workspaceSpinner.fail(
|
|
20
24
|
'Unauthorized. Please login using "embeddable login" command.',
|