@embeddable.com/sdk-core 3.12.0-next.1 → 3.12.0-next.2
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/lib/index.esm.js +1 -1
- package/lib/index.js +1 -1
- package/loader/custom-esm-loader.mjs +53 -10
- package/loader/entryPoint.js +37 -13
- package/loader/entryPoint.test.js +6 -5
- package/package.json +1 -1
package/bin/embeddable
CHANGED
|
@@ -14,17 +14,20 @@ if (!process.env.LOADER_APPLIED) {
|
|
|
14
14
|
VITE_CJS_IGNORE_WARNING: "true", // see https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
const isWindows = process.platform === "win32";
|
|
18
|
+
|
|
17
19
|
const dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
20
|
+
const normalizedDirname = isWindows
|
|
21
|
+
? dirname.slice(1) // Remove leading slash on Windows
|
|
22
|
+
: dirname;
|
|
18
23
|
|
|
19
|
-
const entryPointPath = path.join(
|
|
24
|
+
const entryPointPath = path.join(normalizedDirname, "../loader/entryPoint.js");
|
|
20
25
|
const customLoaderPath = path.join(
|
|
21
|
-
|
|
26
|
+
normalizedDirname,
|
|
22
27
|
"../loader/custom-esm-loader.mjs",
|
|
23
28
|
);
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const entryPointPathOrUrl = isWindows
|
|
30
|
+
const entryPointPathOrUrl = isWindows
|
|
28
31
|
? pathToFileURL(entryPointPath).href
|
|
29
32
|
: entryPointPath;
|
|
30
33
|
|
package/lib/index.esm.js
CHANGED
|
@@ -21995,7 +21995,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
|
|
|
21995
21995
|
};
|
|
21996
21996
|
|
|
21997
21997
|
var name = "@embeddable.com/sdk-core";
|
|
21998
|
-
var version = "3.12.0-next.
|
|
21998
|
+
var version = "3.12.0-next.2";
|
|
21999
21999
|
var description = "Core Embeddable SDK module responsible for web-components bundling and publishing.";
|
|
22000
22000
|
var keywords = [
|
|
22001
22001
|
"embeddable",
|
package/lib/index.js
CHANGED
|
@@ -22023,7 +22023,7 @@ var defineConfig = ({ plugins, pushBaseUrl, audienceUrl, authDomain, authClientI
|
|
|
22023
22023
|
};
|
|
22024
22024
|
|
|
22025
22025
|
var name = "@embeddable.com/sdk-core";
|
|
22026
|
-
var version = "3.12.0-next.
|
|
22026
|
+
var version = "3.12.0-next.2";
|
|
22027
22027
|
var description = "Core Embeddable SDK module responsible for web-components bundling and publishing.";
|
|
22028
22028
|
var keywords = [
|
|
22029
22029
|
"embeddable",
|
|
@@ -12,6 +12,7 @@ import ts from "typescript";
|
|
|
12
12
|
import { readDefaultTsConfig } from "@swc-node/register/read-default-tsconfig";
|
|
13
13
|
import { compile } from "./custom-esm-register.cjs";
|
|
14
14
|
import fs from "fs";
|
|
15
|
+
import path from "path";
|
|
15
16
|
|
|
16
17
|
// Find the tsconfig.json in the customer's project directory
|
|
17
18
|
const tsconfigPath = ts.findConfigFile(
|
|
@@ -59,6 +60,13 @@ const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
|
59
60
|
|
|
60
61
|
const isWindows = process.platform === "win32";
|
|
61
62
|
|
|
63
|
+
function cleanWindowsFileURL(url) {
|
|
64
|
+
// Remove any duplicate file:/ prefixes and normalize slashes
|
|
65
|
+
return url.replace(/file:\/+/g, 'file:///')
|
|
66
|
+
.replace(/\\/g, '/')
|
|
67
|
+
.replace(/file:\/+([A-Za-z]:)/, 'file:///$1');
|
|
68
|
+
}
|
|
69
|
+
|
|
62
70
|
export const resolve = async (specifier, context, nextResolve) => {
|
|
63
71
|
if (NON_JS_TS_EXTENSIONS.test(specifier)) {
|
|
64
72
|
const mockModulePath = pathToFileURL(
|
|
@@ -76,19 +84,54 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
76
84
|
|
|
77
85
|
// Entry point
|
|
78
86
|
if (!context.parentURL) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
if (isWindows) {
|
|
88
|
+
// Handle the case where the specifier contains both the cwd and the actual path
|
|
89
|
+
const parts = specifier.split('file:/');
|
|
90
|
+
const lastPart = parts[parts.length - 1];
|
|
91
|
+
|
|
92
|
+
// Convert the path to a proper file URL
|
|
93
|
+
const cleanPath = lastPart.replace(/^\/+/, '');
|
|
94
|
+
const entryPointPath = pathToFileURL(cleanPath).href;
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
format: isTS ? "ts" : undefined,
|
|
98
|
+
url: cleanWindowsFileURL(entryPointPath),
|
|
99
|
+
shortCircuit: true,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
84
102
|
|
|
85
|
-
|
|
103
|
+
return {
|
|
86
104
|
format: isTS ? "ts" : undefined,
|
|
87
|
-
url:
|
|
105
|
+
url: specifier,
|
|
88
106
|
shortCircuit: true,
|
|
89
107
|
};
|
|
108
|
+
}
|
|
90
109
|
|
|
91
|
-
|
|
110
|
+
// Handle SDK relative imports
|
|
111
|
+
if (isWindows && specifier.startsWith('.') && context.parentURL?.includes('embeddable-sdk')) {
|
|
112
|
+
const parentPath = fileURLToPath(context.parentURL);
|
|
113
|
+
const parentDir = dirname(parentPath);
|
|
114
|
+
let resolvedPath = join(parentDir, specifier);
|
|
115
|
+
|
|
116
|
+
// If no extension is provided, try common extensions
|
|
117
|
+
if (!path.extname(resolvedPath)) {
|
|
118
|
+
const extensions = ['.js', '.mjs', '.cjs', '.ts', '.mts'];
|
|
119
|
+
for (const ext of extensions) {
|
|
120
|
+
const pathWithExt = resolvedPath + ext;
|
|
121
|
+
if (fs.existsSync(pathWithExt) && fs.statSync(pathWithExt).isFile()) {
|
|
122
|
+
resolvedPath = pathWithExt;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Check if the resolved path exists and is a file
|
|
129
|
+
if (fs.existsSync(resolvedPath) && fs.statSync(resolvedPath).isFile()) {
|
|
130
|
+
return {
|
|
131
|
+
url: pathToFileURL(resolvedPath).href,
|
|
132
|
+
shortCircuit: true
|
|
133
|
+
};
|
|
134
|
+
}
|
|
92
135
|
}
|
|
93
136
|
|
|
94
137
|
// Determine if this is a package import
|
|
@@ -99,14 +142,14 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
99
142
|
|
|
100
143
|
// External library import
|
|
101
144
|
if (
|
|
102
|
-
(context.parentURL
|
|
145
|
+
(context.parentURL?.includes("/node_modules/") || isPackageImport) &&
|
|
103
146
|
!isTS
|
|
104
147
|
) {
|
|
105
148
|
return nextResolve(specifier);
|
|
106
149
|
}
|
|
107
150
|
|
|
108
151
|
const isFileUrl = specifier.startsWith("file://");
|
|
109
|
-
const isParentFileUrl = context.parentURL
|
|
152
|
+
const isParentFileUrl = context.parentURL?.startsWith("file://");
|
|
110
153
|
|
|
111
154
|
// Resolve the module using TypeScript's module resolution
|
|
112
155
|
const { resolvedModule } = ts.resolveModuleName(
|
package/loader/entryPoint.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { build, defineConfig, dev, login, push } from "../lib/index.js";
|
|
2
2
|
import { spawn } from "child_process";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
|
|
6
|
+
const COMMANDS_MAP = {
|
|
7
|
+
build,
|
|
8
|
+
login,
|
|
9
|
+
push,
|
|
10
|
+
dev,
|
|
11
|
+
defineConfig,
|
|
12
|
+
};
|
|
13
|
+
|
|
6
14
|
export async function main() {
|
|
7
15
|
const command = process.argv[2];
|
|
8
16
|
const runScript = COMMANDS_MAP[command];
|
|
@@ -40,11 +48,13 @@ async function runTypeScriptCheck(skipTypeCheck = false) {
|
|
|
40
48
|
return;
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
const isWindows = process.platform === "win32";
|
|
52
|
+
const tscBinary = isWindows ? "tsc.cmd" : "tsc";
|
|
43
53
|
const tscPath = path.join(
|
|
44
54
|
customerProjectDir,
|
|
45
55
|
"node_modules",
|
|
46
56
|
".bin",
|
|
47
|
-
|
|
57
|
+
tscBinary,
|
|
48
58
|
);
|
|
49
59
|
|
|
50
60
|
if (!fs.existsSync(tscPath) && !skipTypeCheck) {
|
|
@@ -55,20 +65,34 @@ async function runTypeScriptCheck(skipTypeCheck = false) {
|
|
|
55
65
|
process.exit(1);
|
|
56
66
|
}
|
|
57
67
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
try {
|
|
69
|
+
const tsc = spawn(tscPath, ["--noEmit", "--pretty"], {
|
|
70
|
+
cwd: customerProjectDir,
|
|
71
|
+
stdio: "inherit",
|
|
72
|
+
env: { ...process.env, FORCE_COLOR: "true" },
|
|
73
|
+
shell: isWindows, // Use shell on Windows
|
|
74
|
+
windowsVerbatimArguments: isWindows, // Preserve argument quoting on Windows
|
|
75
|
+
});
|
|
63
76
|
|
|
64
|
-
|
|
65
|
-
|
|
77
|
+
tsc.on("error", (err) => {
|
|
78
|
+
outputWarning(`Failed to start TypeScript compiler: ${err.message}`);
|
|
66
79
|
outputWarning(skipTypeCheckWarning);
|
|
67
80
|
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
tsc.on("exit", (code) => {
|
|
84
|
+
if (code !== 0) {
|
|
85
|
+
outputWarning(skipTypeCheckWarning);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
} else {
|
|
88
|
+
resolve();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
} catch (err) {
|
|
92
|
+
outputWarning(`Failed to start TypeScript compiler: ${err.message}`);
|
|
93
|
+
outputWarning(skipTypeCheckWarning);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
72
96
|
});
|
|
73
97
|
}
|
|
74
98
|
|
|
@@ -8,10 +8,11 @@ vi.mock("child_process");
|
|
|
8
8
|
vi.mock("fs");
|
|
9
9
|
vi.mock("path");
|
|
10
10
|
vi.mock("../lib/index.js", () => ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
build: vi.fn().mockResolvedValue(undefined),
|
|
12
|
+
login: vi.fn().mockResolvedValue(undefined),
|
|
13
|
+
push: vi.fn().mockResolvedValue(undefined),
|
|
14
|
+
dev: vi.fn().mockResolvedValue(undefined),
|
|
15
|
+
defineConfig: vi.fn().mockResolvedValue(undefined),
|
|
15
16
|
}));
|
|
16
17
|
|
|
17
18
|
describe("entryPoint", () => {
|
|
@@ -44,7 +45,7 @@ describe("entryPoint", () => {
|
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
// Set up process.argv for the test
|
|
47
|
-
process.argv = ["node", "script.js", "
|
|
48
|
+
process.argv = ["node", "script.js", "defineConfig"];
|
|
48
49
|
|
|
49
50
|
// Dynamically import main after mocking process.exit
|
|
50
51
|
const entryPoint = await import("./entryPoint.js");
|