@embeddable.com/sdk-core 3.9.13 → 3.10.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.
@@ -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
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddable.com/sdk-core",
3
- "version": "3.9.13",
3
+ "version": "3.10.0",
4
4
  "description": "Core Embeddable SDK module responsible for web-components bundling and publishing.",
5
5
  "keywords": [
6
6
  "embeddable",
@@ -39,22 +39,22 @@
39
39
  "license": "MIT",
40
40
  "dependencies": {
41
41
  "@embeddable.com/sdk-utils": "*",
42
- "@inquirer/prompts": "^7.0.0",
43
- "@stencil/core": "^4.22.0",
42
+ "@inquirer/prompts": "^7.1.0",
43
+ "@stencil/core": "^4.22.2",
44
44
  "@swc-node/register": "^1.10.9",
45
- "archiver": "^5.3.1",
46
- "axios": "^1.7.2",
47
- "chokidar": "^3.6.0",
48
- "finalhandler": "^1.2.0",
45
+ "archiver": "^5.3.2",
46
+ "axios": "^1.7.7",
47
+ "chokidar": "^4.0.1",
48
+ "finalhandler": "^1.3.1",
49
49
  "formdata-node": "^6.0.3",
50
50
  "minimist": "^1.2.8",
51
51
  "open": "^9.1.0",
52
- "ora": "^8.0.1",
53
- "serve-static": "^1.15.0",
54
- "sorcery": "^0.11.0",
55
- "vite": "^5.4.8",
56
- "ws": "^8.17.0",
57
- "yaml": "^2.3.3"
52
+ "ora": "^8.1.1",
53
+ "serve-static": "^1.16.2",
54
+ "sorcery": "^0.11.1",
55
+ "vite": "^5.4.11",
56
+ "ws": "^8.18.0",
57
+ "yaml": "^2.6.0"
58
58
  },
59
59
  "lint-staged": {
60
60
  "*.{js,ts,json}": [
@@ -63,6 +63,6 @@
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/archiver": "^5.3.4",
66
- "@types/ws": "^8.5.10"
66
+ "@types/ws": "^8.5.13"
67
67
  }
68
68
  }
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/generate.ts CHANGED
@@ -135,16 +135,7 @@ async function runStencil(ctx: any): Promise<void> {
135
135
  const compiler = await createCompiler(validated.config);
136
136
  const buildResults = await compiler.build();
137
137
 
138
- if (devMode) {
139
- // Handle process exit to clean up resources
140
- const cleanUp = async () => {
141
- await compiler.destroy();
142
- process.exit(0);
143
- };
144
-
145
- process.on("SIGINT", cleanUp);
146
- process.on("SIGTERM", cleanUp);
147
- } else {
138
+ if (!devMode) {
148
139
  if (buildResults.hasError) {
149
140
  console.error("Stencil build error:", buildResults.diagnostics);
150
141
  throw new Error("Stencil build error");
@@ -5,7 +5,6 @@ import Rollbar from "rollbar";
5
5
  import * as path from "node:path";
6
6
  import * as fs from "node:fs/promises";
7
7
  import { jwtDecode } from "jwt-decode";
8
- import { readFile } from "node:fs";
9
8
 
10
9
  const config = {
11
10
  applicationEnvironment: "test",
package/src/entryPoint.js DELETED
@@ -1,12 +0,0 @@
1
- const COMMANDS_MAP = require("../lib/index.js");
2
-
3
- async function main() {
4
- const command = process.argv[2];
5
- const runScript = COMMANDS_MAP[command];
6
-
7
- if (!runScript) process.exit(1);
8
-
9
- await runScript();
10
- }
11
-
12
- main();