@qvac/sdk 0.14.0 → 0.14.1

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.
@@ -1,2 +1,2 @@
1
- export declare function generateWorkerEntry(pluginSpecifiers: string[], sdkName: string): string;
1
+ export declare function generateWorkerEntry(pluginSpecifiers: string[], sdkName: string, resolveImport?: (specifier: string) => string): string;
2
2
  //# sourceMappingURL=entry-gen.d.ts.map
@@ -1,17 +1,17 @@
1
1
  import { parseBuiltinSpecifier } from "./plugins.js";
2
- export function generateWorkerEntry(pluginSpecifiers, sdkName) {
2
+ export function generateWorkerEntry(pluginSpecifiers, sdkName, resolveImport = (specifier) => specifier) {
3
3
  const imports = [];
4
4
  const registrations = [];
5
5
  let varIndex = 0;
6
6
  for (const specifier of pluginSpecifiers) {
7
7
  const builtin = parseBuiltinSpecifier(specifier, sdkName);
8
8
  if (builtin) {
9
- imports.push(`import { ${builtin.exportName} } from "${sdkName}/${builtin.suffix}/plugin";`);
9
+ imports.push(`import { ${builtin.exportName} } from "${resolveImport(`${sdkName}/${builtin.suffix}/plugin`)}";`);
10
10
  registrations.push(`registerPlugin(${builtin.exportName});`);
11
11
  }
12
12
  else {
13
13
  const varName = `customPlugin${varIndex++}`;
14
- imports.push(`import ${varName} from "${specifier}";`);
14
+ imports.push(`import ${varName} from "${resolveImport(specifier)}";`);
15
15
  registrations.push(`registerPlugin(${varName});`);
16
16
  }
17
17
  }
@@ -26,9 +26,9 @@ export function generateWorkerEntry(pluginSpecifiers, sdkName) {
26
26
  ${pluginsList}
27
27
  */
28
28
 
29
- import { initializeWorkerCore, ensureRPCSetup } from "${sdkName}/worker-core";
30
- import { registerPlugin } from "${sdkName}/plugins";
31
- import { getServerLogger } from "${sdkName}/logging";
29
+ import { initializeWorkerCore, ensureRPCSetup } from "${resolveImport(`${sdkName}/worker-core`)}";
30
+ import { registerPlugin } from "${resolveImport(`${sdkName}/plugins`)}";
31
+ import { getServerLogger } from "${resolveImport(`${sdkName}/logging`)}";
32
32
 
33
33
  ${importsStr}
34
34
 
@@ -9,6 +9,7 @@ import { resolvePluginSpecifiers, parseBuiltinSpecifier, } from "./plugins.js";
9
9
  import { generateWorkerEntry } from "./entry-gen.js";
10
10
  import { runBarePack } from "./bare-pack.js";
11
11
  import { generateAddonsManifest } from "./manifest.js";
12
+ import { createSdkImportResolver } from "./resolve-sdk-import.js";
12
13
  const require = createRequire(import.meta.url);
13
14
  function resolveSdkPath(projectRoot, explicitSdkPath) {
14
15
  if (explicitSdkPath) {
@@ -93,7 +94,8 @@ export async function bundleSdk(options = {}) {
93
94
  const deferModules = options.defer ?? [];
94
95
  await fsp.mkdir(outputDir, { recursive: true });
95
96
  logger.info("\nšŸ“ Generating worker entry...");
96
- const workerEntry = generateWorkerEntry(pluginSpecifiers, sdkName);
97
+ const resolveSdkImport = createSdkImportResolver(sdkPath, sdkName);
98
+ const workerEntry = generateWorkerEntry(pluginSpecifiers, sdkName, resolveSdkImport);
97
99
  await fsp.writeFile(entryPath, workerEntry, "utf8");
98
100
  logger.info(` Created: ${path.relative(projectRoot, entryPath)}`);
99
101
  logger.info(` Using: ${path.relative(projectRoot, importsMapPath)}`);
@@ -0,0 +1,6 @@
1
+ export type SdkExportEntry = string | {
2
+ [condition: string]: SdkExportEntry;
3
+ };
4
+ export declare function selectExportTarget(entry: SdkExportEntry | undefined): string | null;
5
+ export declare function createSdkImportResolver(sdkPath: string, sdkName: string): (specifier: string) => string;
6
+ //# sourceMappingURL=resolve-sdk-import.d.ts.map
@@ -0,0 +1,60 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ const SDK_EXPORT_CONDITIONS = [
5
+ "bare",
6
+ "import",
7
+ "module",
8
+ "default",
9
+ "node",
10
+ "require",
11
+ ];
12
+ export function selectExportTarget(entry) {
13
+ if (entry == null)
14
+ return null;
15
+ if (typeof entry === "string")
16
+ return entry;
17
+ for (const condition of SDK_EXPORT_CONDITIONS) {
18
+ const resolved = selectExportTarget(entry[condition]);
19
+ if (resolved)
20
+ return resolved;
21
+ }
22
+ return null;
23
+ }
24
+ function readSdkExports(sdkPath) {
25
+ try {
26
+ const raw = fs.readFileSync(path.join(sdkPath, "package.json"), "utf8");
27
+ const pkg = JSON.parse(raw);
28
+ return pkg.exports ?? {};
29
+ }
30
+ catch {
31
+ return {};
32
+ }
33
+ }
34
+ // bare-pack rewrites the worker's Node builtins to their bare-* equivalents
35
+ // (os -> bare-os, fs -> bare-fs, ...) and resolves them relative to wherever
36
+ // the generated entry imports the SDK from. A bare specifier resolves against
37
+ // the consumer project, so a hoisted/symlinked SDK (pnpm, workspaces) whose
38
+ // bare-* deps live in a parent node_modules becomes unreachable. Importing each
39
+ // SDK subpath via its resolved file under the SDK's realpath anchors that
40
+ // resolution next to the bare-* deps instead.
41
+ export function createSdkImportResolver(sdkPath, sdkName) {
42
+ let resolvedSdkPath = sdkPath;
43
+ try {
44
+ resolvedSdkPath = fs.realpathSync(sdkPath);
45
+ }
46
+ catch {
47
+ // Keep sdkPath as-is if it cannot be canonicalized.
48
+ }
49
+ const exportsMap = readSdkExports(resolvedSdkPath);
50
+ const prefix = `${sdkName}/`;
51
+ return (specifier) => {
52
+ if (!specifier.startsWith(prefix))
53
+ return specifier;
54
+ const subpath = `./${specifier.slice(prefix.length)}`;
55
+ const target = selectExportTarget(exportsMap[subpath]);
56
+ if (!target)
57
+ return specifier;
58
+ return pathToFileURL(path.join(resolvedSdkPath, target)).href;
59
+ };
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qvac/sdk",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",