@isomorph.ai/app-sdk 1.3.0 → 1.3.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.
- package/dist/runtime-hooks.d.ts +13 -0
- package/dist/runtime-hooks.js +33 -0
- package/dist/runtime.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type ResolveContext = {
|
|
2
|
+
parentURL?: string;
|
|
3
|
+
conditions: string[];
|
|
4
|
+
importAttributes: Record<string, string>;
|
|
5
|
+
};
|
|
6
|
+
type ResolveResult = {
|
|
7
|
+
url: string;
|
|
8
|
+
format?: string | null;
|
|
9
|
+
shortCircuit?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type NextResolve = (specifier: string, context: ResolveContext) => Promise<ResolveResult> | ResolveResult;
|
|
12
|
+
export declare function resolve(specifier: string, context: ResolveContext, nextResolve: NextResolve): Promise<ResolveResult>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Module resolution for the kit runtime (registered by runtime.ts through
|
|
2
|
+
// node:module's register, so it runs on Node's loader thread). Node's type
|
|
3
|
+
// stripping loads a `.ts` file but resolves nothing for it: a relative import
|
|
4
|
+
// written the way the browser code writes it — `../src/isomorph.client`, no
|
|
5
|
+
// extension — fails with "Cannot find module". The first hosted job that
|
|
6
|
+
// imported the app's client died exactly there (fourier smoke app, preview
|
|
7
|
+
// 000006, 2026-09-21). An extensionless relative specifier is tried as the
|
|
8
|
+
// `.ts` file, then as a folder's `index.ts`; anything else, and anything with
|
|
9
|
+
// an extension, is left to Node.
|
|
10
|
+
import { access } from 'node:fs/promises';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
const candidates = ['.ts', '.mts', '/index.ts'];
|
|
13
|
+
async function exists(url) {
|
|
14
|
+
try {
|
|
15
|
+
await access(fileURLToPath(url));
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
23
|
+
const relative = specifier.startsWith('./') || specifier.startsWith('../');
|
|
24
|
+
const extensionless = !/\.[A-Za-z0-9]+$/.test(specifier);
|
|
25
|
+
if (relative && extensionless && context.parentURL?.startsWith('file:')) {
|
|
26
|
+
const base = new URL(specifier, context.parentURL).href;
|
|
27
|
+
for (const suffix of candidates) {
|
|
28
|
+
if (await exists(base + suffix))
|
|
29
|
+
return nextResolve(base + suffix, context);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return nextResolve(specifier, context);
|
|
33
|
+
}
|
package/dist/runtime.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
// ISOMORPH_APP_ROOT the app root (default: the working directory)
|
|
21
21
|
import { createServer } from 'node:http';
|
|
22
22
|
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
23
|
+
import { register } from 'node:module';
|
|
23
24
|
import { join, resolve } from 'node:path';
|
|
24
25
|
import { pathToFileURL } from 'node:url';
|
|
25
26
|
import { createClient, IsomorphError } from './index.js';
|
|
@@ -399,6 +400,10 @@ export function optionsFromEnvironment(env = process.env) {
|
|
|
399
400
|
}
|
|
400
401
|
const entry = process.argv[1] ? pathToFileURL(process.argv[1]).href : '';
|
|
401
402
|
if (import.meta.url === entry) {
|
|
403
|
+
// Extensionless relative imports in the app's server code resolve to
|
|
404
|
+
// their .ts files (runtime-hooks.ts); registered before any app module
|
|
405
|
+
// is imported.
|
|
406
|
+
register('./runtime-hooks.js', import.meta.url);
|
|
402
407
|
const options = optionsFromEnvironment();
|
|
403
408
|
if (options.gatewayUrl && !process.env.ISOMORPH_GATEWAY_URL)
|
|
404
409
|
process.env.ISOMORPH_GATEWAY_URL = options.gatewayUrl;
|