@embeddable.com/sdk-core 3.9.14 → 3.10.1
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/bin/embeddable +8 -5
- package/bin/package.json +3 -0
- package/lib/index.esm.js +30 -23
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +30 -23
- package/lib/index.js.map +1 -1
- package/loader/entryPoint.js +75 -0
- package/loader/entryPoint.test.js +122 -0
- package/loader/package.json +3 -0
- package/package.json +15 -14
- package/src/build.test.ts +0 -1
- package/src/dev.ts +20 -10
- package/src/rollbar.test.ts +0 -1
- package/src/entryPoint.js +0 -12
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import COMMANDS_MAP from "../lib/index.js";
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
|
|
6
|
+
export async function main() {
|
|
7
|
+
const command = process.argv[2];
|
|
8
|
+
const runScript = COMMANDS_MAP[command];
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
const skipTypeCheck = args.includes("--force");
|
|
11
|
+
|
|
12
|
+
if (!runScript) {
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (command === "build") {
|
|
17
|
+
await runTypeScriptCheck(skipTypeCheck);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await runScript();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function outputWarning(message) {
|
|
24
|
+
console.warn(`\x1b[33m⚠️ WARNING: ${message}\x1b[0m`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function runTypeScriptCheck(skipTypeCheck = false) {
|
|
28
|
+
const skipTypeCheckWarning =
|
|
29
|
+
"You can skip type checking by running with the --force flag, if you know what you are doing.";
|
|
30
|
+
return new Promise((resolve) => {
|
|
31
|
+
const customerProjectDir = process.cwd();
|
|
32
|
+
const tsconfigPath = path.join(customerProjectDir, "tsconfig.json");
|
|
33
|
+
|
|
34
|
+
if (skipTypeCheck) {
|
|
35
|
+
outputWarning("Type checking skipped.");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!fs.existsSync(tsconfigPath) || skipTypeCheck) {
|
|
39
|
+
resolve();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const tscPath = path.join(
|
|
44
|
+
customerProjectDir,
|
|
45
|
+
"node_modules",
|
|
46
|
+
".bin",
|
|
47
|
+
process.platform === "win32" ? "tsc.cmd" : "tsc",
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (!fs.existsSync(tscPath) && !skipTypeCheck) {
|
|
51
|
+
outputWarning(
|
|
52
|
+
"TypeScript compiler not found. Please ensure 'typescript' is installed in your project dependencies.",
|
|
53
|
+
);
|
|
54
|
+
outputWarning(skipTypeCheckWarning);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const tsc = spawn(tscPath, ["--noEmit", "--pretty"], {
|
|
59
|
+
cwd: customerProjectDir,
|
|
60
|
+
stdio: "inherit",
|
|
61
|
+
env: { ...process.env, FORCE_COLOR: "true" },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
tsc.on("exit", (code) => {
|
|
65
|
+
if (code !== 0) {
|
|
66
|
+
outputWarning(skipTypeCheckWarning);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
} else {
|
|
69
|
+
resolve();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
main();
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
// Mock the dependencies
|
|
7
|
+
vi.mock("child_process");
|
|
8
|
+
vi.mock("fs");
|
|
9
|
+
vi.mock("path");
|
|
10
|
+
vi.mock("../lib/index.js", () => ({
|
|
11
|
+
default: {
|
|
12
|
+
build: vi.fn().mockResolvedValue(undefined),
|
|
13
|
+
someOtherCommand: vi.fn().mockResolvedValue(undefined),
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
describe("entryPoint", () => {
|
|
18
|
+
let originalWarn;
|
|
19
|
+
let main;
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
// Reset all mocks before each test
|
|
22
|
+
vi.clearAllMocks();
|
|
23
|
+
originalWarn = console.warn;
|
|
24
|
+
console.warn = vi.fn();
|
|
25
|
+
|
|
26
|
+
fs.existsSync.mockReturnValue(true);
|
|
27
|
+
|
|
28
|
+
// Mock process.on to avoid actually setting up process listeners
|
|
29
|
+
vi.spyOn(process, "on").mockImplementation(() => process);
|
|
30
|
+
vi.spyOn(process, "exit").mockImplementation(() => {
|
|
31
|
+
throw new Error("Process.exit called with code 1");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Mock path.join to return predictable paths
|
|
35
|
+
path.join.mockImplementation((...args) => args.join("/"));
|
|
36
|
+
|
|
37
|
+
// Mock spawn
|
|
38
|
+
spawn.mockReturnValue({
|
|
39
|
+
on: vi.fn().mockImplementation((event, cb) => {
|
|
40
|
+
if (event === "exit") {
|
|
41
|
+
cb(0); // Success by default
|
|
42
|
+
}
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Set up process.argv for the test
|
|
47
|
+
process.argv = ["node", "script.js", "someOtherCommand"];
|
|
48
|
+
|
|
49
|
+
// Dynamically import main after mocking process.exit
|
|
50
|
+
const entryPoint = await import("./entryPoint.js");
|
|
51
|
+
main = entryPoint.main;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
afterEach(() => {
|
|
55
|
+
console.warn = originalWarn;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should run typescript check before build command", async () => {
|
|
59
|
+
process.argv = ["node", "script.js", "build"];
|
|
60
|
+
await main();
|
|
61
|
+
|
|
62
|
+
expect(spawn).toHaveBeenCalledWith(
|
|
63
|
+
expect.stringContaining("tsc"),
|
|
64
|
+
["--noEmit", "--pretty"],
|
|
65
|
+
expect.any(Object),
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should skip typescript check with --force flag", async () => {
|
|
70
|
+
process.argv = ["node", "script.js", "build", "--force"];
|
|
71
|
+
await main();
|
|
72
|
+
|
|
73
|
+
expect(spawn).not.toHaveBeenCalled();
|
|
74
|
+
expect(console.warn).toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should handle missing tsconfig.json", async () => {
|
|
78
|
+
process.argv = ["node", "script.js", "build"];
|
|
79
|
+
fs.existsSync.mockImplementation((path) => {
|
|
80
|
+
return !path.includes("tsconfig.json");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await main();
|
|
84
|
+
expect(spawn).not.toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should exit if typescript check fails", async () => {
|
|
88
|
+
process.argv = ["node", "script.js", "build"];
|
|
89
|
+
|
|
90
|
+
spawn.mockReturnValue({
|
|
91
|
+
on: vi.fn().mockImplementation((event, cb) => {
|
|
92
|
+
if (event === "exit") {
|
|
93
|
+
cb(1); // Simulate failure
|
|
94
|
+
}
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
await main();
|
|
100
|
+
} catch (error) {
|
|
101
|
+
expect(error.message).toBe("Process.exit called with code 1");
|
|
102
|
+
expect(console.warn).toHaveBeenCalled();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should handle missing typescript compiler", async () => {
|
|
107
|
+
process.argv = ["node", "script.js", "build"];
|
|
108
|
+
|
|
109
|
+
// Mock both tsconfig.json existence and tsc missing
|
|
110
|
+
fs.existsSync.mockImplementation((filePath) => {
|
|
111
|
+
if (filePath.includes("tsconfig.json")) return true;
|
|
112
|
+
if (filePath.includes("tsc")) return false;
|
|
113
|
+
return true;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
await main();
|
|
118
|
+
} catch (error) {
|
|
119
|
+
expect(error.message).toBe("Process.exit called with code 1");
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embeddable.com/sdk-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.1",
|
|
4
4
|
"description": "Core Embeddable SDK module responsible for web-components bundling and publishing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"embeddable",
|
|
@@ -39,22 +39,23 @@
|
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@embeddable.com/sdk-utils": "*",
|
|
42
|
-
"@inquirer/prompts": "^7.
|
|
43
|
-
"@stencil/core": "^4.22.
|
|
42
|
+
"@inquirer/prompts": "^7.1.0",
|
|
43
|
+
"@stencil/core": "^4.22.3",
|
|
44
44
|
"@swc-node/register": "^1.10.9",
|
|
45
|
-
"archiver": "^5.3.
|
|
46
|
-
"axios": "^1.7.
|
|
47
|
-
"chokidar": "^
|
|
48
|
-
"
|
|
45
|
+
"archiver": "^5.3.2",
|
|
46
|
+
"axios": "^1.7.8",
|
|
47
|
+
"chokidar": "^4.0.1",
|
|
48
|
+
"fast-glob": "^3.3.2",
|
|
49
|
+
"finalhandler": "^1.3.1",
|
|
49
50
|
"formdata-node": "^6.0.3",
|
|
50
51
|
"minimist": "^1.2.8",
|
|
51
52
|
"open": "^9.1.0",
|
|
52
|
-
"ora": "^8.
|
|
53
|
-
"serve-static": "^1.
|
|
54
|
-
"sorcery": "^0.11.
|
|
55
|
-
"vite": "^5.4.
|
|
56
|
-
"ws": "^8.
|
|
57
|
-
"yaml": "^2.
|
|
53
|
+
"ora": "^8.1.1",
|
|
54
|
+
"serve-static": "^1.16.2",
|
|
55
|
+
"sorcery": "^0.11.1",
|
|
56
|
+
"vite": "^5.4.11",
|
|
57
|
+
"ws": "^8.18.0",
|
|
58
|
+
"yaml": "^2.6.1"
|
|
58
59
|
},
|
|
59
60
|
"lint-staged": {
|
|
60
61
|
"*.{js,ts,json}": [
|
|
@@ -63,6 +64,6 @@
|
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"@types/archiver": "^5.3.4",
|
|
66
|
-
"@types/ws": "^8.5.
|
|
67
|
+
"@types/ws": "^8.5.13"
|
|
67
68
|
}
|
|
68
69
|
}
|
package/src/build.test.ts
CHANGED
|
@@ -5,7 +5,6 @@ import buildTypes from "./buildTypes";
|
|
|
5
5
|
import provideConfig from "./provideConfig";
|
|
6
6
|
import generate from "./generate";
|
|
7
7
|
import cleanup from "./cleanup";
|
|
8
|
-
import { initLogger, logError } from "./logger";
|
|
9
8
|
|
|
10
9
|
// @ts-ignore
|
|
11
10
|
import reportErrorToRollbar from "./rollbar.mjs";
|
package/src/dev.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
createNodeLogger,
|
|
11
11
|
createNodeSys,
|
|
12
12
|
} from "@stencil/core/sys/node";
|
|
13
|
+
import { glob } from "node:fs/promises";
|
|
13
14
|
import { RollupWatcher } from "rollup";
|
|
14
15
|
import * as http from "node:http";
|
|
15
16
|
import { IncomingMessage, Server, ServerResponse } from "http";
|
|
@@ -29,6 +30,7 @@ import { selectWorkspace } from "./workspaceUtils";
|
|
|
29
30
|
import * as fs from "fs";
|
|
30
31
|
const minimist = require("minimist");
|
|
31
32
|
import { initLogger, logError } from "./logger";
|
|
33
|
+
import fg from "fast-glob";
|
|
32
34
|
|
|
33
35
|
const oraP = import("ora");
|
|
34
36
|
let wss: WSServer;
|
|
@@ -206,8 +208,7 @@ export default async () => {
|
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
const dataModelAndSecurityContextWatch =
|
|
209
|
-
dataModelAndSecurityContextWatcher(config);
|
|
210
|
-
|
|
211
|
+
await dataModelAndSecurityContextWatcher(config);
|
|
211
212
|
const customGlobalCssWatch = globalCssWatcher(config);
|
|
212
213
|
watchers.push(dataModelAndSecurityContextWatch);
|
|
213
214
|
watchers.push(customGlobalCssWatch);
|
|
@@ -272,17 +273,26 @@ const onBundleBuildEnd = async (ctx: any) => {
|
|
|
272
273
|
}
|
|
273
274
|
};
|
|
274
275
|
|
|
275
|
-
const dataModelAndSecurityContextWatcher = (
|
|
276
|
+
const dataModelAndSecurityContextWatcher = async (
|
|
277
|
+
ctx: any,
|
|
278
|
+
): Promise<FSWatcher> => {
|
|
279
|
+
const [modelsFiles, presetsFiles] = await Promise.all([
|
|
280
|
+
fg("**/*.cube.{yaml,yml,js}", {
|
|
281
|
+
cwd: ctx.client.modelsSrc,
|
|
282
|
+
absolute: true,
|
|
283
|
+
}),
|
|
284
|
+
fg("**/*.{sc,cc}.{yaml,yml}", {
|
|
285
|
+
cwd: ctx.client.presetsSrc,
|
|
286
|
+
absolute: true,
|
|
287
|
+
}),
|
|
288
|
+
]);
|
|
289
|
+
|
|
276
290
|
const fsWatcher = chokidar.watch(
|
|
277
|
-
[
|
|
278
|
-
path.resolve(ctx.client.modelsSrc, "**/*.cube.{yaml,yml,js}"),
|
|
279
|
-
path.resolve(ctx.client.presetsSrc, "**/*.{sc,cc}.{yaml,yml}"),
|
|
280
|
-
],
|
|
291
|
+
[...modelsFiles, ...presetsFiles],
|
|
281
292
|
chokidarWatchOptions,
|
|
282
293
|
);
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
});
|
|
294
|
+
|
|
295
|
+
fsWatcher.on("all", () => sendDataModelsAndContextsChanges(ctx));
|
|
286
296
|
|
|
287
297
|
return fsWatcher;
|
|
288
298
|
};
|
package/src/rollbar.test.ts
CHANGED
package/src/entryPoint.js
DELETED