@open-mercato/ai-assistant 0.9.1-develop.7475.1.28ca93ed97 → 0.9.1-develop.7477.1.64ba865101

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
- [build:ai-assistant] found 238 entry points
1
+ [build:ai-assistant] found 237 entry points
2
2
  [build:ai-assistant] built successfully
@@ -1,58 +1,9 @@
1
- import * as nodeModule from "node:module";
2
- const NEXT_BARE_SUBPATH = /^next\/[A-Za-z0-9_-]+$/;
3
- let installed = false;
4
- function isModuleNotFound(error) {
5
- return Boolean(error) && typeof error === "object" && error.code === "ERR_MODULE_NOT_FOUND";
6
- }
7
- function resolveNextSubpath(specifier, context, nextResolve) {
8
- if (!NEXT_BARE_SUBPATH.test(specifier)) return nextResolve(specifier, context);
9
- try {
10
- return nextResolve(specifier, context);
11
- } catch (error) {
12
- if (!isModuleNotFound(error)) throw error;
13
- try {
14
- return nextResolve(`${specifier}.js`, context);
15
- } catch {
16
- throw error;
17
- }
18
- }
19
- }
20
- async function resolveNextSubpathAsync(specifier, context, nextResolve) {
21
- if (!NEXT_BARE_SUBPATH.test(specifier)) return nextResolve(specifier, context);
22
- try {
23
- return await nextResolve(specifier, context);
24
- } catch (error) {
25
- if (!isModuleNotFound(error)) throw error;
26
- try {
27
- return await nextResolve(`${specifier}.js`, context);
28
- } catch {
29
- throw error;
30
- }
31
- }
32
- }
33
- function runtimeRegisterHooks() {
34
- const candidate = nodeModule.registerHooks;
35
- return typeof candidate === "function" ? candidate : void 0;
36
- }
37
- function runtimeRegisterHookModule() {
38
- const candidate = nodeModule.register;
39
- return typeof candidate === "function" ? candidate : void 0;
40
- }
41
- function installNextSubpathResolveHook(registerHooks = runtimeRegisterHooks(), registerHookModule = runtimeRegisterHookModule()) {
42
- if (installed) return false;
43
- if (typeof registerHooks === "function") {
44
- registerHooks({ resolve: resolveNextSubpath });
45
- } else if (typeof registerHookModule === "function") {
46
- registerHookModule(new URL("./next-subpath-resolve-hook-worker.js", import.meta.url), import.meta.url);
47
- } else {
48
- return false;
49
- }
50
- installed = true;
51
- return true;
52
- }
53
- function resetNextSubpathResolveHookForTests() {
54
- installed = false;
55
- }
1
+ import {
2
+ installNextSubpathResolveHook,
3
+ resetNextSubpathResolveHookForTests,
4
+ resolveNextSubpath,
5
+ resolveNextSubpathAsync
6
+ } from "@open-mercato/shared/lib/bootstrap/next-subpath-resolve-hook";
56
7
  export {
57
8
  installNextSubpathResolveHook,
58
9
  resetNextSubpathResolveHookForTests,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/ai_assistant/lib/next-subpath-resolve-hook.ts"],
4
- "sourcesContent": ["/**\n * Node ESM resolution for `next/<subpath>` in the standalone MCP processes (#6118).\n *\n * `mercato ai_assistant mcp:serve-http` (and `mcp:serve`, `mcp:dev`,\n * `mcp:list-tools`) run in plain Node, and the AI API operation runner loads\n * API route modules with a runtime `import()`. Those modules import\n * `NextResponse` from `'next/server'`: a bare package subpath that only a\n * bundler resolves, because `next` ships no `exports` map and Node's ESM\n * resolver does no extension guessing. Every route with that import (287 of\n * them on the 0.7.0 packages) therefore fails to load with\n * `ERR_MODULE_NOT_FOUND \u2026 node_modules/next/server`, and every tool backed by\n * such a route returns \"Failed to load route module\".\n *\n * `next/server.js`, `next/headers.js`, `next/navigation.js` \u2026 do exist as files,\n * which is why `@open-mercato/shared` imports `'next/headers.js'`. Rather than\n * rewriting several hundred imports across every package (and every\n * third-party module), this hook retries a failed bare `next/<subpath>` with\n * the `.js` suffix. It only runs in the processes that install it, only for\n * `next/*` specifiers, and only after the normal resolution failed, so it\n * becomes a no-op the day `next` publishes an `exports` map.\n */\nimport * as nodeModule from 'node:module'\n\ntype ResolveContext = Record<string, unknown>\ntype ResolveResult = { url: string; format?: string | null | undefined; shortCircuit?: boolean }\ntype NextResolve = (specifier: string, context?: ResolveContext) => ResolveResult\ntype AsyncNextResolve = (specifier: string, context?: ResolveContext) => ResolveResult | Promise<ResolveResult>\n\n/** Bare `next/<one segment>` specifiers, e.g. `next/server`, `next/headers`. */\nconst NEXT_BARE_SUBPATH = /^next\\/[A-Za-z0-9_-]+$/\n\nlet installed = false\n\nfunction isModuleNotFound(error: unknown): boolean {\n return Boolean(error) && typeof error === 'object' && (error as { code?: unknown }).code === 'ERR_MODULE_NOT_FOUND'\n}\n\n/**\n * The resolve hook itself. Exported so it can be tested without touching the\n * process-global hook chain.\n */\nexport function resolveNextSubpath(\n specifier: string,\n context: ResolveContext,\n nextResolve: NextResolve,\n): ResolveResult {\n if (!NEXT_BARE_SUBPATH.test(specifier)) return nextResolve(specifier, context)\n try {\n return nextResolve(specifier, context)\n } catch (error) {\n if (!isModuleNotFound(error)) throw error\n try {\n return nextResolve(`${specifier}.js`, context)\n } catch {\n // Neither form resolves (Next is not installed at all): surface the\n // original error, which names the specifier the caller wrote.\n throw error\n }\n }\n}\n\nexport async function resolveNextSubpathAsync(\n specifier: string,\n context: ResolveContext,\n nextResolve: AsyncNextResolve,\n): Promise<ResolveResult> {\n if (!NEXT_BARE_SUBPATH.test(specifier)) return nextResolve(specifier, context)\n try {\n return await nextResolve(specifier, context)\n } catch (error) {\n if (!isModuleNotFound(error)) throw error\n try {\n return await nextResolve(`${specifier}.js`, context)\n } catch {\n throw error\n }\n }\n}\n\ntype RegisterHooks = (hooks: { resolve: typeof resolveNextSubpath }) => unknown\ntype RegisterHookModule = (specifier: string | URL, parentURL?: string | URL) => unknown\n\n/**\n * `module.registerHooks` exists from Node 22.15. It is read off the namespace\n * rather than imported by name: in the published ESM build a named import of an\n * export the running Node lacks fails while the module links, before the check\n * in `installNextSubpathResolveHook` can run, and the package still declares\n * `node >= 22.0.0`.\n */\nfunction runtimeRegisterHooks(): RegisterHooks | undefined {\n const candidate = (nodeModule as unknown as { registerHooks?: unknown }).registerHooks\n return typeof candidate === 'function' ? (candidate as RegisterHooks) : undefined\n}\n\nfunction runtimeRegisterHookModule(): RegisterHookModule | undefined {\n const candidate = (nodeModule as unknown as { register?: unknown }).register\n return typeof candidate === 'function' ? (candidate as RegisterHookModule) : undefined\n}\n\n/**\n * Install the hook once per process. Returns `true` when it was installed by\n * this call, `false` when it already was or when the runtime has neither\n * registration API. Node 22.15+ uses the synchronous hook API; earlier\n * supported Node 22 releases use the asynchronous hook API.\n */\nexport function installNextSubpathResolveHook(\n registerHooks: RegisterHooks | null | undefined = runtimeRegisterHooks(),\n registerHookModule: RegisterHookModule | null | undefined = runtimeRegisterHookModule(),\n): boolean {\n if (installed) return false\n if (typeof registerHooks === 'function') {\n registerHooks({ resolve: resolveNextSubpath })\n } else if (typeof registerHookModule === 'function') {\n registerHookModule(new URL('./next-subpath-resolve-hook-worker.js', import.meta.url), import.meta.url)\n } else {\n return false\n }\n installed = true\n return true\n}\n\n/** Test seam: forget that the hook was installed. */\nexport function resetNextSubpathResolveHookForTests(): void {\n installed = false\n}\n"],
5
- "mappings": "AAqBA,YAAY,gBAAgB;AAQ5B,MAAM,oBAAoB;AAE1B,IAAI,YAAY;AAEhB,SAAS,iBAAiB,OAAyB;AACjD,SAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAa,MAA6B,SAAS;AAC/F;AAMO,SAAS,mBACd,WACA,SACA,aACe;AACf,MAAI,CAAC,kBAAkB,KAAK,SAAS,EAAG,QAAO,YAAY,WAAW,OAAO;AAC7E,MAAI;AACF,WAAO,YAAY,WAAW,OAAO;AAAA,EACvC,SAAS,OAAO;AACd,QAAI,CAAC,iBAAiB,KAAK,EAAG,OAAM;AACpC,QAAI;AACF,aAAO,YAAY,GAAG,SAAS,OAAO,OAAO;AAAA,IAC/C,QAAQ;AAGN,YAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,eAAsB,wBACpB,WACA,SACA,aACwB;AACxB,MAAI,CAAC,kBAAkB,KAAK,SAAS,EAAG,QAAO,YAAY,WAAW,OAAO;AAC7E,MAAI;AACF,WAAO,MAAM,YAAY,WAAW,OAAO;AAAA,EAC7C,SAAS,OAAO;AACd,QAAI,CAAC,iBAAiB,KAAK,EAAG,OAAM;AACpC,QAAI;AACF,aAAO,MAAM,YAAY,GAAG,SAAS,OAAO,OAAO;AAAA,IACrD,QAAQ;AACN,YAAM;AAAA,IACR;AAAA,EACF;AACF;AAYA,SAAS,uBAAkD;AACzD,QAAM,YAAa,WAAsD;AACzE,SAAO,OAAO,cAAc,aAAc,YAA8B;AAC1E;AAEA,SAAS,4BAA4D;AACnE,QAAM,YAAa,WAAiD;AACpE,SAAO,OAAO,cAAc,aAAc,YAAmC;AAC/E;AAQO,SAAS,8BACd,gBAAkD,qBAAqB,GACvE,qBAA4D,0BAA0B,GAC7E;AACT,MAAI,UAAW,QAAO;AACtB,MAAI,OAAO,kBAAkB,YAAY;AACvC,kBAAc,EAAE,SAAS,mBAAmB,CAAC;AAAA,EAC/C,WAAW,OAAO,uBAAuB,YAAY;AACnD,uBAAmB,IAAI,IAAI,yCAAyC,YAAY,GAAG,GAAG,YAAY,GAAG;AAAA,EACvG,OAAO;AACL,WAAO;AAAA,EACT;AACA,cAAY;AACZ,SAAO;AACT;AAGO,SAAS,sCAA4C;AAC1D,cAAY;AACd;",
4
+ "sourcesContent": ["export {\n installNextSubpathResolveHook,\n resetNextSubpathResolveHookForTests,\n resolveNextSubpath,\n resolveNextSubpathAsync,\n} from '@open-mercato/shared/lib/bootstrap/next-subpath-resolve-hook'\n"],
5
+ "mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/ai-assistant",
3
- "version": "0.9.1-develop.7475.1.28ca93ed97",
3
+ "version": "0.9.1-develop.7477.1.64ba865101",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -100,16 +100,16 @@
100
100
  "zod-to-json-schema": "^3.25.2"
101
101
  },
102
102
  "peerDependencies": {
103
- "@open-mercato/shared": "0.9.1-develop.7475.1.28ca93ed97",
104
- "@open-mercato/ui": "0.9.1-develop.7475.1.28ca93ed97",
103
+ "@open-mercato/shared": "0.9.1-develop.7477.1.64ba865101",
104
+ "@open-mercato/ui": "0.9.1-develop.7477.1.64ba865101",
105
105
  "react": "^19.0.0",
106
106
  "react-dom": "^19.0.0",
107
107
  "zod": ">=3.23.0"
108
108
  },
109
109
  "devDependencies": {
110
- "@open-mercato/cli": "0.9.1-develop.7475.1.28ca93ed97",
111
- "@open-mercato/shared": "0.9.1-develop.7475.1.28ca93ed97",
112
- "@open-mercato/ui": "0.9.1-develop.7475.1.28ca93ed97",
110
+ "@open-mercato/cli": "0.9.1-develop.7477.1.64ba865101",
111
+ "@open-mercato/shared": "0.9.1-develop.7477.1.64ba865101",
112
+ "@open-mercato/ui": "0.9.1-develop.7477.1.64ba865101",
113
113
  "@types/react": "^19.2.18",
114
114
  "@types/react-dom": "^19.2.5",
115
115
  "react": "19.2.8",
@@ -1,125 +1,6 @@
1
- /**
2
- * Node ESM resolution for `next/<subpath>` in the standalone MCP processes (#6118).
3
- *
4
- * `mercato ai_assistant mcp:serve-http` (and `mcp:serve`, `mcp:dev`,
5
- * `mcp:list-tools`) run in plain Node, and the AI API operation runner loads
6
- * API route modules with a runtime `import()`. Those modules import
7
- * `NextResponse` from `'next/server'`: a bare package subpath that only a
8
- * bundler resolves, because `next` ships no `exports` map and Node's ESM
9
- * resolver does no extension guessing. Every route with that import (287 of
10
- * them on the 0.7.0 packages) therefore fails to load with
11
- * `ERR_MODULE_NOT_FOUND … node_modules/next/server`, and every tool backed by
12
- * such a route returns "Failed to load route module".
13
- *
14
- * `next/server.js`, `next/headers.js`, `next/navigation.js` … do exist as files,
15
- * which is why `@open-mercato/shared` imports `'next/headers.js'`. Rather than
16
- * rewriting several hundred imports across every package (and every
17
- * third-party module), this hook retries a failed bare `next/<subpath>` with
18
- * the `.js` suffix. It only runs in the processes that install it, only for
19
- * `next/*` specifiers, and only after the normal resolution failed, so it
20
- * becomes a no-op the day `next` publishes an `exports` map.
21
- */
22
- import * as nodeModule from 'node:module'
23
-
24
- type ResolveContext = Record<string, unknown>
25
- type ResolveResult = { url: string; format?: string | null | undefined; shortCircuit?: boolean }
26
- type NextResolve = (specifier: string, context?: ResolveContext) => ResolveResult
27
- type AsyncNextResolve = (specifier: string, context?: ResolveContext) => ResolveResult | Promise<ResolveResult>
28
-
29
- /** Bare `next/<one segment>` specifiers, e.g. `next/server`, `next/headers`. */
30
- const NEXT_BARE_SUBPATH = /^next\/[A-Za-z0-9_-]+$/
31
-
32
- let installed = false
33
-
34
- function isModuleNotFound(error: unknown): boolean {
35
- return Boolean(error) && typeof error === 'object' && (error as { code?: unknown }).code === 'ERR_MODULE_NOT_FOUND'
36
- }
37
-
38
- /**
39
- * The resolve hook itself. Exported so it can be tested without touching the
40
- * process-global hook chain.
41
- */
42
- export function resolveNextSubpath(
43
- specifier: string,
44
- context: ResolveContext,
45
- nextResolve: NextResolve,
46
- ): ResolveResult {
47
- if (!NEXT_BARE_SUBPATH.test(specifier)) return nextResolve(specifier, context)
48
- try {
49
- return nextResolve(specifier, context)
50
- } catch (error) {
51
- if (!isModuleNotFound(error)) throw error
52
- try {
53
- return nextResolve(`${specifier}.js`, context)
54
- } catch {
55
- // Neither form resolves (Next is not installed at all): surface the
56
- // original error, which names the specifier the caller wrote.
57
- throw error
58
- }
59
- }
60
- }
61
-
62
- export async function resolveNextSubpathAsync(
63
- specifier: string,
64
- context: ResolveContext,
65
- nextResolve: AsyncNextResolve,
66
- ): Promise<ResolveResult> {
67
- if (!NEXT_BARE_SUBPATH.test(specifier)) return nextResolve(specifier, context)
68
- try {
69
- return await nextResolve(specifier, context)
70
- } catch (error) {
71
- if (!isModuleNotFound(error)) throw error
72
- try {
73
- return await nextResolve(`${specifier}.js`, context)
74
- } catch {
75
- throw error
76
- }
77
- }
78
- }
79
-
80
- type RegisterHooks = (hooks: { resolve: typeof resolveNextSubpath }) => unknown
81
- type RegisterHookModule = (specifier: string | URL, parentURL?: string | URL) => unknown
82
-
83
- /**
84
- * `module.registerHooks` exists from Node 22.15. It is read off the namespace
85
- * rather than imported by name: in the published ESM build a named import of an
86
- * export the running Node lacks fails while the module links, before the check
87
- * in `installNextSubpathResolveHook` can run, and the package still declares
88
- * `node >= 22.0.0`.
89
- */
90
- function runtimeRegisterHooks(): RegisterHooks | undefined {
91
- const candidate = (nodeModule as unknown as { registerHooks?: unknown }).registerHooks
92
- return typeof candidate === 'function' ? (candidate as RegisterHooks) : undefined
93
- }
94
-
95
- function runtimeRegisterHookModule(): RegisterHookModule | undefined {
96
- const candidate = (nodeModule as unknown as { register?: unknown }).register
97
- return typeof candidate === 'function' ? (candidate as RegisterHookModule) : undefined
98
- }
99
-
100
- /**
101
- * Install the hook once per process. Returns `true` when it was installed by
102
- * this call, `false` when it already was or when the runtime has neither
103
- * registration API. Node 22.15+ uses the synchronous hook API; earlier
104
- * supported Node 22 releases use the asynchronous hook API.
105
- */
106
- export function installNextSubpathResolveHook(
107
- registerHooks: RegisterHooks | null | undefined = runtimeRegisterHooks(),
108
- registerHookModule: RegisterHookModule | null | undefined = runtimeRegisterHookModule(),
109
- ): boolean {
110
- if (installed) return false
111
- if (typeof registerHooks === 'function') {
112
- registerHooks({ resolve: resolveNextSubpath })
113
- } else if (typeof registerHookModule === 'function') {
114
- registerHookModule(new URL('./next-subpath-resolve-hook-worker.js', import.meta.url), import.meta.url)
115
- } else {
116
- return false
117
- }
118
- installed = true
119
- return true
120
- }
121
-
122
- /** Test seam: forget that the hook was installed. */
123
- export function resetNextSubpathResolveHookForTests(): void {
124
- installed = false
125
- }
1
+ export {
2
+ installNextSubpathResolveHook,
3
+ resetNextSubpathResolveHookForTests,
4
+ resolveNextSubpath,
5
+ resolveNextSubpathAsync,
6
+ } from '@open-mercato/shared/lib/bootstrap/next-subpath-resolve-hook'
@@ -1,6 +0,0 @@
1
- import { resolveNextSubpathAsync } from "./next-subpath-resolve-hook.js";
2
- const resolve = resolveNextSubpathAsync;
3
- export {
4
- resolve
5
- };
6
- //# sourceMappingURL=next-subpath-resolve-hook-worker.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/modules/ai_assistant/lib/next-subpath-resolve-hook-worker.ts"],
4
- "sourcesContent": ["import { resolveNextSubpathAsync } from './next-subpath-resolve-hook'\n\nexport const resolve = resolveNextSubpathAsync\n"],
5
- "mappings": "AAAA,SAAS,+BAA+B;AAEjC,MAAM,UAAU;",
6
- "names": []
7
- }
@@ -1,174 +0,0 @@
1
- import {
2
- installNextSubpathResolveHook,
3
- resetNextSubpathResolveHookForTests,
4
- resolveNextSubpath,
5
- resolveNextSubpathAsync,
6
- } from '../next-subpath-resolve-hook'
7
-
8
- function notFound(specifier: string): Error & { code: string } {
9
- return Object.assign(new Error(`Cannot find module '${specifier}'`), { code: 'ERR_MODULE_NOT_FOUND' })
10
- }
11
-
12
- describe('resolveNextSubpath (#6118)', () => {
13
- const context = { parentURL: 'file:///app/route.js' }
14
-
15
- it('leaves specifiers other than next/<subpath> to the default resolver', () => {
16
- const nextResolve = jest.fn(() => ({ url: 'file:///app/node_modules/zod/index.js' }))
17
-
18
- const result = resolveNextSubpath('zod', context, nextResolve)
19
-
20
- expect(result.url).toBe('file:///app/node_modules/zod/index.js')
21
- expect(nextResolve).toHaveBeenCalledTimes(1)
22
- expect(nextResolve).toHaveBeenCalledWith('zod', context)
23
- })
24
-
25
- it('does not touch a next/<subpath> that resolves on its own', () => {
26
- // The day `next` ships an exports map the hook must step aside.
27
- const nextResolve = jest.fn(() => ({ url: 'file:///app/node_modules/next/server.js' }))
28
-
29
- resolveNextSubpath('next/server', context, nextResolve)
30
-
31
- expect(nextResolve).toHaveBeenCalledTimes(1)
32
- })
33
-
34
- it('retries a bare next/<subpath> with the .js suffix when Node cannot resolve it', () => {
35
- // `next` has no exports map and Node ESM does no extension guessing, so
36
- // `next/server` fails while `next/server.js` is a real file.
37
- const nextResolve = jest
38
- .fn()
39
- .mockImplementationOnce(() => { throw notFound('/app/node_modules/next/server') })
40
- .mockImplementationOnce(() => ({ url: 'file:///app/node_modules/next/server.js' }))
41
-
42
- const result = resolveNextSubpath('next/server', context, nextResolve)
43
-
44
- expect(result.url).toBe('file:///app/node_modules/next/server.js')
45
- expect(nextResolve).toHaveBeenNthCalledWith(1, 'next/server', context)
46
- expect(nextResolve).toHaveBeenNthCalledWith(2, 'next/server.js', context)
47
- })
48
-
49
- it('covers the other subpaths route modules import', () => {
50
- for (const subpath of ['next/headers', 'next/navigation', 'next/cache']) {
51
- const nextResolve = jest
52
- .fn()
53
- .mockImplementationOnce(() => { throw notFound(subpath) })
54
- .mockImplementationOnce((resolvedSpecifier: string) => ({
55
- url: `file:///app/node_modules/${resolvedSpecifier}`,
56
- }))
57
- expect(resolveNextSubpath(subpath, context, nextResolve).url).toBe(`file:///app/node_modules/${subpath}.js`)
58
- }
59
- })
60
-
61
- it('does not retry deeper or already-suffixed specifiers', () => {
62
- for (const specifier of ['next/server.js', 'next/dist/server/web/spec-extension/response', 'next']) {
63
- const nextResolve = jest.fn(() => { throw notFound(specifier) })
64
- expect(() => resolveNextSubpath(specifier, context, nextResolve)).toThrow(/Cannot find module/)
65
- expect(nextResolve).toHaveBeenCalledTimes(1)
66
- }
67
- })
68
-
69
- it('rethrows the original error when the .js form is missing too', () => {
70
- const original = notFound('/app/node_modules/next/server')
71
- const nextResolve = jest
72
- .fn()
73
- .mockImplementationOnce(() => { throw original })
74
- .mockImplementationOnce(() => { throw notFound('/app/node_modules/next/server.js') })
75
-
76
- expect(() => resolveNextSubpath('next/server', context, nextResolve)).toThrow(original)
77
- })
78
-
79
- it('rethrows errors that are not ERR_MODULE_NOT_FOUND without retrying', () => {
80
- const syntaxError = Object.assign(new Error('bad package.json'), { code: 'ERR_INVALID_PACKAGE_CONFIG' })
81
- const nextResolve = jest.fn(() => { throw syntaxError })
82
-
83
- expect(() => resolveNextSubpath('next/server', context, nextResolve)).toThrow(syntaxError)
84
- expect(nextResolve).toHaveBeenCalledTimes(1)
85
- })
86
- })
87
-
88
- describe('installNextSubpathResolveHook', () => {
89
- beforeEach(() => {
90
- resetNextSubpathResolveHookForTests()
91
- })
92
-
93
- it('registers the resolve hook once per process', () => {
94
- const register = jest.fn()
95
-
96
- expect(installNextSubpathResolveHook(register, null)).toBe(true)
97
- expect(installNextSubpathResolveHook(register, null)).toBe(false)
98
-
99
- expect(register).toHaveBeenCalledTimes(1)
100
- expect(register).toHaveBeenCalledWith({ resolve: resolveNextSubpath })
101
- })
102
-
103
- it('registers an asynchronous hook on Node 22.0-22.14', () => {
104
- const registerHookModule = jest.fn()
105
-
106
- expect(installNextSubpathResolveHook(null, registerHookModule)).toBe(true)
107
- expect(registerHookModule).toHaveBeenCalledWith(
108
- expect.objectContaining({ href: expect.stringMatching(/next-subpath-resolve-hook-worker\.js$/) }),
109
- expect.stringMatching(/^file:/),
110
- )
111
- })
112
-
113
- it('is a no-op on a runtime without either registration API', () => {
114
- expect(installNextSubpathResolveHook(null, null)).toBe(false)
115
- })
116
- })
117
-
118
- describe('resolveNextSubpathAsync', () => {
119
- const context = { parentURL: 'file:///app/route.js' }
120
-
121
- it('retries a bare next/<subpath> with the .js suffix', async () => {
122
- const nextResolve = jest
123
- .fn()
124
- .mockRejectedValueOnce(notFound('/app/node_modules/next/server'))
125
- .mockResolvedValueOnce({ url: 'file:///app/node_modules/next/server.js' })
126
-
127
- const result = await resolveNextSubpathAsync('next/server', context, nextResolve)
128
-
129
- expect(result.url).toBe('file:///app/node_modules/next/server.js')
130
- expect(nextResolve).toHaveBeenNthCalledWith(1, 'next/server', context)
131
- expect(nextResolve).toHaveBeenNthCalledWith(2, 'next/server.js', context)
132
- })
133
- })
134
-
135
- describe('installNextSubpathResolveHook against the runtime node:module', () => {
136
- afterEach(() => {
137
- jest.dontMock('node:module')
138
- jest.resetModules()
139
- })
140
-
141
- it('installs through node:module.register on Node 22.0-22.14', () => {
142
- // A named import of `registerHooks` would throw while the module loads on
143
- // such a runtime; the helper must load and use the older registration API.
144
- jest.resetModules()
145
- const register = jest.fn()
146
- jest.doMock('node:module', () => ({ register }))
147
- let installed: boolean | undefined
148
- jest.isolateModules(() => {
149
- // eslint-disable-next-line @typescript-eslint/no-require-imports
150
- const hookModule = require('../next-subpath-resolve-hook') as typeof import('../next-subpath-resolve-hook')
151
- installed = hookModule.installNextSubpathResolveHook()
152
- })
153
- expect(installed).toBe(true)
154
- expect(register).toHaveBeenCalledTimes(1)
155
- expect(register.mock.calls[0][0]).toEqual(
156
- expect.objectContaining({ href: expect.stringMatching(/next-subpath-resolve-hook-worker\.js$/) }),
157
- )
158
- })
159
-
160
- it('installs through node:module.registerHooks when the runtime has it', () => {
161
- jest.resetModules()
162
- const register = jest.fn()
163
- jest.doMock('node:module', () => ({ registerHooks: register }))
164
- let installed: boolean | undefined
165
- jest.isolateModules(() => {
166
- // eslint-disable-next-line @typescript-eslint/no-require-imports
167
- const hookModule = require('../next-subpath-resolve-hook') as typeof import('../next-subpath-resolve-hook')
168
- installed = hookModule.installNextSubpathResolveHook()
169
- })
170
- expect(installed).toBe(true)
171
- expect(register).toHaveBeenCalledTimes(1)
172
- expect(register.mock.calls[0][0]).toEqual({ resolve: expect.any(Function) })
173
- })
174
- })
@@ -1,3 +0,0 @@
1
- import { resolveNextSubpathAsync } from './next-subpath-resolve-hook'
2
-
3
- export const resolve = resolveNextSubpathAsync