@embeddable.com/sdk-core 3.6.0 → 3.7.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.
@@ -9,12 +9,34 @@
9
9
  import { fileURLToPath, pathToFileURL } from "url";
10
10
  import { dirname, join } from "path";
11
11
  import ts from "typescript";
12
- // @ts-expect-error
13
12
  import { readDefaultTsConfig } from "@swc-node/register/read-default-tsconfig";
14
13
  import { compile } from "./custom-esm-register.cjs";
14
+ import fs from "fs";
15
15
 
16
- // @ts-expect-error
17
- const tsconfig = readDefaultTsConfig();
16
+ // Find the tsconfig.json in the customer's project directory
17
+ const tsconfigPath = ts.findConfigFile(
18
+ process.cwd(),
19
+ fs.existsSync,
20
+ "tsconfig.json",
21
+ );
22
+
23
+ let tsconfig;
24
+ if (tsconfigPath) {
25
+ // Read and parse the tsconfig.json
26
+ const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
27
+
28
+ const parsedConfig = ts.parseJsonConfigFileContent(
29
+ configFile.config,
30
+ ts.sys,
31
+ dirname(tsconfigPath),
32
+ );
33
+
34
+ tsconfig = parsedConfig.options;
35
+ } else {
36
+ tsconfig = await readDefaultTsConfig();
37
+ }
38
+
39
+ // Set necessary compiler options
18
40
  tsconfig.module = ts.ModuleKind.ESNext;
19
41
  tsconfig.moduleResolution = ts.ModuleResolutionKind.Node16;
20
42
 
@@ -23,10 +45,12 @@ const moduleResolutionCache = ts.createModuleResolutionCache(
23
45
  (x) => x,
24
46
  tsconfig,
25
47
  );
48
+
26
49
  const host = {
27
50
  fileExists: ts.sys.fileExists,
28
51
  readFile: ts.sys.readFile,
29
52
  };
53
+
30
54
  const EXTENSIONS = [ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Mts];
31
55
  const NON_JS_TS_EXTENSIONS =
32
56
  /\.(css|scss|less|sass|styl|json|svg|woff|woff2|png|jpg|jpeg|gif|webp|md|yml|yaml)$/;
@@ -50,7 +74,7 @@ export const resolve = async (specifier, context, nextResolve) => {
50
74
 
51
75
  const isTS = EXTENSIONS.some((ext) => specifier.endsWith(ext));
52
76
 
53
- // entrypoint
77
+ // Entry point
54
78
  if (!context.parentURL) {
55
79
  const processCwd = pathToFileURL(process.cwd()).href;
56
80
 
@@ -65,12 +89,13 @@ export const resolve = async (specifier, context, nextResolve) => {
65
89
  };
66
90
  }
67
91
 
68
- // define if this is a package import
92
+ // Determine if this is a package import
69
93
  const isPackageImport =
70
94
  !specifier.startsWith(".") &&
71
95
  !specifier.startsWith("/") &&
72
- !/^[A-Z]:/.test(specifier); // windows path
73
- // import/require from external library
96
+ !/^[A-Z]:/.test(specifier); // Windows path
97
+
98
+ // External library import
74
99
  if (
75
100
  (context.parentURL.includes("/node_modules/") || isPackageImport) &&
76
101
  !isTS
@@ -80,6 +105,8 @@ export const resolve = async (specifier, context, nextResolve) => {
80
105
 
81
106
  const isFileUrl = specifier.startsWith("file://");
82
107
  const isParentFileUrl = context.parentURL.startsWith("file://");
108
+
109
+ // Resolve the module using TypeScript's module resolution
83
110
  const { resolvedModule } = ts.resolveModuleName(
84
111
  isFileUrl ? fileURLToPath(specifier) : specifier,
85
112
  isParentFileUrl ? fileURLToPath(context.parentURL) : context.parentURL,
@@ -87,7 +114,8 @@ export const resolve = async (specifier, context, nextResolve) => {
87
114
  host,
88
115
  moduleResolutionCache,
89
116
  );
90
- // import from local project to local project TS file
117
+
118
+ // Local project TS file
91
119
  if (
92
120
  resolvedModule &&
93
121
  !resolvedModule.resolvedFileName.includes("/node_modules/") &&
@@ -101,10 +129,8 @@ export const resolve = async (specifier, context, nextResolve) => {
101
129
  shortCircuit: true,
102
130
  };
103
131
  }
104
- // import from local project to either:
105
- // - something TS couldn't resolve
106
- // - external library
107
- // - local project non-TS file
132
+
133
+ // Fallback for non-TS files or unresolved modules
108
134
  const specifierPathOrUrl =
109
135
  !resolvedModule?.resolvedFileName?.includes("/node_modules/") && isWindows
110
136
  ? pathToFileURL(specifier).href
@@ -112,32 +138,28 @@ export const resolve = async (specifier, context, nextResolve) => {
112
138
 
113
139
  return nextResolve(specifierPathOrUrl);
114
140
  };
115
- const tsconfigForSWCNode = {
116
- ...tsconfig,
117
- paths: undefined,
118
- baseUrl: undefined,
119
- };
120
141
 
121
142
  export const load = async (url, context, nextLoad) => {
122
143
  if (context.format === "ts") {
123
144
  const { source } = await nextLoad(url, context);
124
145
  const code =
125
146
  typeof source === "string" ? source : Buffer.from(source).toString();
126
- const compiled = await compile(
127
- code,
128
- fileURLToPath(url),
129
- tsconfigForSWCNode,
130
- true,
131
- );
147
+
148
+ // Compile the code using @swc-node with the customer's tsconfig
149
+ const compiled = await compile(code, fileURLToPath(url), tsconfig, true);
132
150
  return {
133
151
  format: "module",
134
152
  source: compiled,
135
153
  shortCircuit: true,
136
154
  };
137
155
  } else {
138
- if (isWindows && !url.startsWith("file://") && url.includes("node_modules")) {
156
+ if (
157
+ isWindows &&
158
+ !url.startsWith("file://") &&
159
+ url.includes("node_modules")
160
+ ) {
139
161
  return nextLoad(pathToFileURL(url).href, context);
140
- }
162
+ }
141
163
  return nextLoad(url, context);
142
164
  }
143
165
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddable.com/sdk-core",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "Core Embeddable SDK module responsible for web-components bundling and publishing.",
5
5
  "keywords": [
6
6
  "embeddable",
@@ -18,7 +18,8 @@
18
18
  "scripts": {
19
19
  "build": "rollup -c",
20
20
  "test": "vitest run",
21
- "test:watch": "vitest"
21
+ "test:watch": "vitest",
22
+ "license-report": "license-report --output=csv --csvHeaders --fields name --fields link --fields licenseType --fields installedVersion --fields author > license-report-sdk-core-sdk.csv"
22
23
  },
23
24
  "author": "Embeddable.com <engineering@embeddable.com>",
24
25
  "files": [
@@ -54,6 +54,7 @@ describe("defineConfig", () => {
54
54
  "componentDir": "/embeddable-sdk/packages/core-sdk",
55
55
  "errorFallbackComponent": "/embeddable-sdk/packages/core-sdk",
56
56
  "modelsSrc": "/embeddable-sdk/packages/core-sdk",
57
+ "rollupOptions": {},
57
58
  "rootDir": "/embeddable-sdk/packages/core-sdk",
58
59
  "srcDir": "/embeddable-sdk/packages/core-sdk",
59
60
  "stencilBuild": "/embeddable-sdk/packages/core-sdk",
@@ -1,5 +1,6 @@
1
1
  import * as path from "node:path";
2
2
  import { existsSync } from "node:fs";
3
+ import { RollupOptions } from "rollup";
3
4
 
4
5
  export type EmbeddableConfig = {
5
6
  plugins: (() => {
@@ -23,6 +24,7 @@ export type EmbeddableConfig = {
23
24
  alias?: Record<string, string>;
24
25
  };
25
26
  };
27
+ rollupOptions?: RollupOptions;
26
28
  };
27
29
 
28
30
  export default ({
@@ -38,6 +40,7 @@ export default ({
38
40
  modelsSrc = "src",
39
41
  componentsSrc = "src",
40
42
  viteConfig = {},
43
+ rollupOptions = {},
41
44
  }: EmbeddableConfig) => {
42
45
  const coreRoot = path.resolve(__dirname, "..");
43
46
  const clientRoot = process.cwd();
@@ -85,6 +88,7 @@ export default ({
85
88
  : undefined,
86
89
  bundleHash: undefined, // This will be set by the build process
87
90
  viteConfig,
91
+ rollupOptions,
88
92
  },
89
93
  outputOptions: {
90
94
  typesEntryPointFilename: "embeddable-types-entry-point.js",