@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.
@@ -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 = /\.(css|scss|less|sass|styl|json|svg)$/;
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: specifier,
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 (context.parentURL.includes("/node_modules/") && !isTS) {
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: pathToFileURL(resolvedModule.resolvedFileName).href,
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
- return nextResolve(specifier);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddable.com/sdk-core",
3
- "version": "3.2.0-next.0",
3
+ "version": "3.2.0-next.10",
4
4
  "description": "Core Embeddable SDK module responsible for web-components bundling and publishing.",
5
5
  "keywords": [
6
6
  "embeddable",
@@ -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<void>;
7
- cleanup: (config: EmbeddableConfig) => Promise<void>;
8
- validate: (config: EmbeddableConfig) => Promise<void>;
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;
@@ -0,0 +1,12 @@
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();
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
- import { jwtDecode } from "jwt-decode";
4
+
7
5
  // @ts-ignore
8
6
  import reportErrorToRollbar from "./rollbar.mjs";
9
7
  import { CREDENTIALS_DIR, CREDENTIALS_FILE } from "./credentials";
@@ -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("Please create a proper `embeddable.config.js` file first.");
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 configFileUrl = url.pathToFileURL(configFilePath).href;
13
- return (await import(configFileUrl)).default;
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
- const spinnerPushing = ora(
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
- console.log(error);
51
+ spinnerPushing?.fail("Publishing failed");
52
+ console.error(error.response?.data || error?.message || error);
50
53
  await reportErrorToRollbar(error);
51
- throw error;
54
+ process.exit(1);
52
55
  }
53
56
  };
54
57
 
@@ -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();