@embeddable.com/sdk-core 3.2.0-next.0 → 3.2.0-next.10
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 +15 -3
- package/configs/tsconfig.json +4 -11
- package/lib/defineConfig.d.ts +6 -6
- package/lib/index.esm.js +20 -10
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +21 -11
- package/lib/index.js.map +1 -1
- package/loader/custom-esm-loader.mjs +40 -7
- package/package.json +1 -1
- package/src/defineConfig.ts +3 -3
- package/src/entryPoint.js +12 -0
- package/src/generate.ts +3 -0
- package/src/login.ts +1 -3
- package/src/provideConfig.ts +13 -4
- package/src/push.ts +6 -3
- package/lib/entryPoint.d.ts +0 -1
- package/src/entryPoint.ts +0 -16
|
@@ -28,10 +28,13 @@ const host = {
|
|
|
28
28
|
readFile: ts.sys.readFile,
|
|
29
29
|
};
|
|
30
30
|
const EXTENSIONS = [ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Mts];
|
|
31
|
-
const NON_JS_TS_EXTENSIONS =
|
|
31
|
+
const NON_JS_TS_EXTENSIONS =
|
|
32
|
+
/\.(css|scss|less|sass|styl|json|svg|woff|woff2|png|jpg|jpeg|gif|webp|md|yml|yaml)$/;
|
|
32
33
|
|
|
33
34
|
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
34
35
|
|
|
36
|
+
const isWindows = process.platform === "win32";
|
|
37
|
+
|
|
35
38
|
export const resolve = async (specifier, context, nextResolve) => {
|
|
36
39
|
if (NON_JS_TS_EXTENSIONS.test(specifier)) {
|
|
37
40
|
const mockModulePath = pathToFileURL(
|
|
@@ -44,22 +47,42 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
44
47
|
shortCircuit: true,
|
|
45
48
|
};
|
|
46
49
|
}
|
|
50
|
+
|
|
47
51
|
const isTS = EXTENSIONS.some((ext) => specifier.endsWith(ext));
|
|
52
|
+
|
|
48
53
|
// entrypoint
|
|
49
54
|
if (!context.parentURL) {
|
|
55
|
+
const processCwd = pathToFileURL(process.cwd()).href;
|
|
56
|
+
|
|
57
|
+
const entryPointPath = isWindows
|
|
58
|
+
? pathToFileURL(specifier.replace(`${processCwd}/file:/`, "")).href
|
|
59
|
+
: specifier;
|
|
60
|
+
|
|
50
61
|
return {
|
|
51
62
|
format: isTS ? "ts" : undefined,
|
|
52
|
-
url:
|
|
63
|
+
url: entryPointPath,
|
|
53
64
|
shortCircuit: true,
|
|
54
65
|
};
|
|
55
66
|
}
|
|
67
|
+
|
|
68
|
+
// define if this is a package import
|
|
69
|
+
const isPackageImport =
|
|
70
|
+
!specifier.startsWith(".") &&
|
|
71
|
+
!specifier.startsWith("/") &&
|
|
72
|
+
!specifier.startsWith("C:");
|
|
56
73
|
// import/require from external library
|
|
57
|
-
if (
|
|
74
|
+
if (
|
|
75
|
+
(context.parentURL.includes("/node_modules/") || isPackageImport) &&
|
|
76
|
+
!isTS
|
|
77
|
+
) {
|
|
58
78
|
return nextResolve(specifier);
|
|
59
79
|
}
|
|
80
|
+
|
|
81
|
+
const isFileUrl = specifier.startsWith("file://");
|
|
82
|
+
const isParentFileUrl = context.parentURL.startsWith("file://");
|
|
60
83
|
const { resolvedModule } = ts.resolveModuleName(
|
|
61
|
-
specifier,
|
|
62
|
-
fileURLToPath(context.parentURL),
|
|
84
|
+
isFileUrl ? fileURLToPath(specifier) : specifier,
|
|
85
|
+
isParentFileUrl ? fileURLToPath(context.parentURL) : context.parentURL,
|
|
63
86
|
tsconfig,
|
|
64
87
|
host,
|
|
65
88
|
moduleResolutionCache,
|
|
@@ -72,7 +95,9 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
72
95
|
) {
|
|
73
96
|
return {
|
|
74
97
|
format: "ts",
|
|
75
|
-
url:
|
|
98
|
+
url:
|
|
99
|
+
pathToFileURL(resolvedModule.resolvedFileName).href +
|
|
100
|
+
`?update=${Date.now()}`,
|
|
76
101
|
shortCircuit: true,
|
|
77
102
|
};
|
|
78
103
|
}
|
|
@@ -80,7 +105,12 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
80
105
|
// - something TS couldn't resolve
|
|
81
106
|
// - external library
|
|
82
107
|
// - local project non-TS file
|
|
83
|
-
|
|
108
|
+
const specifierPathOrUrl =
|
|
109
|
+
!resolvedModule?.resolvedFileName?.includes("/node_modules/") && isWindows
|
|
110
|
+
? pathToFileURL(specifier).href
|
|
111
|
+
: specifier;
|
|
112
|
+
|
|
113
|
+
return nextResolve(specifierPathOrUrl);
|
|
84
114
|
};
|
|
85
115
|
const tsconfigForSWCNode = {
|
|
86
116
|
...tsconfig,
|
|
@@ -105,6 +135,9 @@ export const load = async (url, context, nextLoad) => {
|
|
|
105
135
|
shortCircuit: true,
|
|
106
136
|
};
|
|
107
137
|
} else {
|
|
138
|
+
if (isWindows && !url.startsWith("file://") && url.includes("node_modules")) {
|
|
139
|
+
return nextLoad(pathToFileURL(url).href, context);
|
|
140
|
+
}
|
|
108
141
|
return nextLoad(url, context);
|
|
109
142
|
}
|
|
110
143
|
};
|
package/package.json
CHANGED
package/src/defineConfig.ts
CHANGED
|
@@ -3,9 +3,9 @@ import * as path from "node:path";
|
|
|
3
3
|
export type EmbeddableConfig = {
|
|
4
4
|
plugins: (() => {
|
|
5
5
|
pluginName: string;
|
|
6
|
-
build: (config: EmbeddableConfig) => Promise<
|
|
7
|
-
cleanup: (config: EmbeddableConfig) => Promise<
|
|
8
|
-
validate: (config: EmbeddableConfig) => Promise<
|
|
6
|
+
build: (config: EmbeddableConfig) => Promise<unknown>;
|
|
7
|
+
cleanup: (config: EmbeddableConfig) => Promise<unknown>;
|
|
8
|
+
validate: (config: EmbeddableConfig) => Promise<unknown>;
|
|
9
9
|
})[];
|
|
10
10
|
pushBaseUrl?: string;
|
|
11
11
|
audienceUrl?: string;
|
package/src/generate.ts
CHANGED
|
@@ -63,12 +63,15 @@ async function runStencil(ctx: any) {
|
|
|
63
63
|
const sys = ctx.dev?.sys || createNodeSys({ process });
|
|
64
64
|
const devMode = !!ctx.dev;
|
|
65
65
|
|
|
66
|
+
const isWindows = process.platform === "win32";
|
|
67
|
+
|
|
66
68
|
const validated = await loadConfig({
|
|
67
69
|
initTsConfig: true,
|
|
68
70
|
logger,
|
|
69
71
|
sys,
|
|
70
72
|
config: {
|
|
71
73
|
devMode,
|
|
74
|
+
maxConcurrentWorkers: isWindows ? 0 : 8, // workers break on windows
|
|
72
75
|
rootDir: ctx.client.buildDir,
|
|
73
76
|
configPath: path.resolve(ctx.client.buildDir, "stencil.config.ts"),
|
|
74
77
|
tsconfig: path.resolve(ctx.client.buildDir, "tsconfig.json"),
|
package/src/login.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
|
-
import * as os from "node:os";
|
|
3
1
|
import * as fs from "node:fs/promises";
|
|
4
2
|
import axios from "axios";
|
|
5
3
|
import provideConfig from "./provideConfig";
|
|
6
|
-
|
|
4
|
+
|
|
7
5
|
// @ts-ignore
|
|
8
6
|
import reportErrorToRollbar from "./rollbar.mjs";
|
|
9
7
|
import { CREDENTIALS_DIR, CREDENTIALS_FILE } from "./credentials";
|
package/src/provideConfig.ts
CHANGED
|
@@ -3,12 +3,21 @@ import * as url from "node:url";
|
|
|
3
3
|
|
|
4
4
|
export default async () => {
|
|
5
5
|
const configFilePath = `${process.cwd()}/embeddable.config.js`;
|
|
6
|
+
const tsConfigFilePath = `${process.cwd()}/embeddable.config.ts`;
|
|
6
7
|
|
|
7
|
-
if (!fs.existsSync(configFilePath)) {
|
|
8
|
-
console.log(
|
|
8
|
+
if (!fs.existsSync(configFilePath) && !fs.existsSync(tsConfigFilePath)) {
|
|
9
|
+
console.log(
|
|
10
|
+
"Please create a proper `embeddable.config.js` or `embeddable.config.ts` file in the root of your project.",
|
|
11
|
+
);
|
|
9
12
|
process.exit(1);
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
const
|
|
13
|
-
|
|
15
|
+
const isWindows = process.platform === "win32";
|
|
16
|
+
const configPath = fs.existsSync(tsConfigFilePath)
|
|
17
|
+
? tsConfigFilePath
|
|
18
|
+
: configFilePath;
|
|
19
|
+
|
|
20
|
+
const pathOrUrl = isWindows ? url.pathToFileURL(configPath).href : configPath;
|
|
21
|
+
|
|
22
|
+
return (await import(pathOrUrl)).default;
|
|
14
23
|
};
|
package/src/push.ts
CHANGED
|
@@ -17,6 +17,8 @@ export const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
|
|
|
17
17
|
|
|
18
18
|
let ora: any;
|
|
19
19
|
export default async () => {
|
|
20
|
+
let spinnerPushing;
|
|
21
|
+
|
|
20
22
|
try {
|
|
21
23
|
checkNodeVersion();
|
|
22
24
|
ora = (await oraP).default;
|
|
@@ -37,7 +39,7 @@ export default async () => {
|
|
|
37
39
|
await archive(config, filesList);
|
|
38
40
|
spinnerArchive.succeed("Bundling completed");
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
spinnerPushing = ora(
|
|
41
43
|
`Publishing to ${workspaceName} using ${config.pushBaseUrl}...`,
|
|
42
44
|
).start();
|
|
43
45
|
|
|
@@ -46,9 +48,10 @@ export default async () => {
|
|
|
46
48
|
`Published to ${workspaceName} using ${config.pushBaseUrl}`,
|
|
47
49
|
);
|
|
48
50
|
} catch (error: any) {
|
|
49
|
-
|
|
51
|
+
spinnerPushing?.fail("Publishing failed");
|
|
52
|
+
console.error(error.response?.data || error?.message || error);
|
|
50
53
|
await reportErrorToRollbar(error);
|
|
51
|
-
|
|
54
|
+
process.exit(1);
|
|
52
55
|
}
|
|
53
56
|
};
|
|
54
57
|
|
package/lib/entryPoint.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/entryPoint.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { fileURLToPath } from "url";
|
|
3
|
-
|
|
4
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
-
const COMMANDS_MAP = await import(path.join(__dirname, "../lib/index.js"));
|
|
6
|
-
|
|
7
|
-
async function main() {
|
|
8
|
-
const command = process.argv[2];
|
|
9
|
-
const runScript = COMMANDS_MAP[command];
|
|
10
|
-
|
|
11
|
-
if (!runScript) process.exit(1);
|
|
12
|
-
|
|
13
|
-
await runScript();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
main();
|