@happyvertical/smrt-core 0.56.0 → 0.56.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.
Files changed (70) hide show
  1. package/agents/generators.md +37 -0
  2. package/dist/browser.d.ts +1 -0
  3. package/dist/browser.d.ts.map +1 -1
  4. package/dist/browser.js +2 -1
  5. package/dist/cookbook/engine/commands.d.ts.map +1 -1
  6. package/dist/cookbook/engine/commands.js +12 -0
  7. package/dist/cookbook/engine/commands.js.map +1 -1
  8. package/dist/cookbook/engine/defaults.d.ts.map +1 -1
  9. package/dist/cookbook/engine/defaults.js +8 -0
  10. package/dist/cookbook/engine/defaults.js.map +1 -1
  11. package/dist/cookbook/engine/document.d.ts +4 -0
  12. package/dist/cookbook/engine/document.d.ts.map +1 -1
  13. package/dist/cookbook/engine/document.js +11 -3
  14. package/dist/cookbook/engine/document.js.map +1 -1
  15. package/dist/cookbook/engine/engine.d.ts.map +1 -1
  16. package/dist/cookbook/engine/engine.js +3 -1
  17. package/dist/cookbook/engine/engine.js.map +1 -1
  18. package/dist/cookbook/engine/schemas.d.ts.map +1 -1
  19. package/dist/cookbook/engine/schemas.js +8 -0
  20. package/dist/cookbook/engine/schemas.js.map +1 -1
  21. package/dist/cookbook/engine/types.d.ts +5 -1
  22. package/dist/cookbook/engine/types.d.ts.map +1 -1
  23. package/dist/cookbook/engine/types.js.map +1 -1
  24. package/dist/generators/index.d.ts +1 -0
  25. package/dist/generators/index.d.ts.map +1 -1
  26. package/dist/generators/index.js +2 -1
  27. package/dist/generators/mcp-runtime-template.d.ts +3 -0
  28. package/dist/generators/mcp-runtime-template.d.ts.map +1 -1
  29. package/dist/generators/mcp-runtime-template.js +30 -4
  30. package/dist/generators/mcp-runtime-template.js.map +1 -1
  31. package/dist/generators/mcp.d.ts +5 -0
  32. package/dist/generators/mcp.d.ts.map +1 -1
  33. package/dist/generators/mcp.js +78 -7
  34. package/dist/generators/mcp.js.map +1 -1
  35. package/dist/generators.js +2 -1
  36. package/dist/index.js +2 -1
  37. package/dist/manifest/browser-capability.generated.js +34 -5
  38. package/dist/manifest/browser-capability.generated.js.map +1 -1
  39. package/dist/manifest/index.js +1 -1
  40. package/dist/manifest/static-manifest.js +1 -1
  41. package/dist/manifest/static-manifest.js.map +1 -1
  42. package/dist/manifest/store.js +1 -1
  43. package/dist/manifest.json +1 -1
  44. package/dist/mcp-serializer.d.ts +38 -0
  45. package/dist/mcp-serializer.d.ts.map +1 -0
  46. package/dist/mcp-serializer.js +60 -0
  47. package/dist/mcp-serializer.js.map +1 -0
  48. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/index.js +34 -0
  49. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/index.js.map +1 -0
  50. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/errors.js +343 -0
  51. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/errors.js.map +1 -0
  52. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/get-format.js +109 -0
  53. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/get-format.js.map +1 -0
  54. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/package-json-reader.js +102 -0
  55. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/package-json-reader.js.map +1 -0
  56. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/resolve.js +673 -0
  57. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/resolve.js.map +1 -0
  58. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/utils.js +32 -0
  59. package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/utils.js.map +1 -0
  60. package/dist/registry/types.d.ts +13 -0
  61. package/dist/registry/types.d.ts.map +1 -1
  62. package/dist/smrt-knowledge.json +7 -5
  63. package/dist/utils/import-project-vite.js +1 -1
  64. package/dist/utils/import-workspace-module.js +1 -1
  65. package/dist/vite-plugin/dev-plane-route.js +1 -1
  66. package/dist/vite-plugin/import-build-aware.js +1 -1
  67. package/dist/vite-plugin/index.js +1 -1
  68. package/dist/vite-plugin/resources-route.js +1 -1
  69. package/dist/vite-plugin/sveltekit-generator.js +1 -1
  70. package/package.json +16 -10
@@ -2,7 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "timestamp": 0,
4
4
  "packageName": "@happyvertical/smrt-core",
5
- "packageVersion": "0.56.0",
5
+ "packageVersion": "0.56.1",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-core:SmrtClass": {
8
8
  "name": "smrtclass",
@@ -0,0 +1,38 @@
1
+ import type { PublicJsonOptions, SmrtObject } from './object.js';
2
+ /** A named module export that projects an admitted MCP `get` result. */
3
+ export type McpGetSerializer = (item: SmrtObject, options: PublicJsonOptions) => unknown | Promise<unknown>;
4
+ /** Package-owned location of an MCP `get` result serializer. */
5
+ export interface McpGetSerializerReference {
6
+ importPath: string;
7
+ exportName: string;
8
+ }
9
+ export interface McpGetSerializerResolveOptions {
10
+ /**
11
+ * Module URL that owns a relative serializer reference. Omit only when the
12
+ * resolver itself owns that relative reference.
13
+ */
14
+ parentUrl?: string;
15
+ /**
16
+ * Qualified registry key of the model that declared the serializer. Its
17
+ * loaded module is the default anchor for resolving a bare package.
18
+ */
19
+ ownerRegistryKey?: string;
20
+ /**
21
+ * Explicit application module URL for a host that resolves a serializer
22
+ * outside a registered MCP model.
23
+ */
24
+ consumerAnchorUrl?: string;
25
+ }
26
+ /**
27
+ * Resolve a serializer package from the running application's module graph.
28
+ *
29
+ * Model packages own serializer implementations but do not become dependencies
30
+ * of core or generic consumers such as Chat. Bare specifiers first use the
31
+ * active runtime module graph so workspace aliases keep one constructor
32
+ * identity. When the package is absent from Core's dependency graph, resolution
33
+ * continues from the module that registered the owning model (or an explicit
34
+ * host anchor), with ESM export conditions. Relative and URL references keep
35
+ * their declaring module's ordinary dynamic-import behavior.
36
+ */
37
+ export declare function resolveMcpGetSerializer(reference: McpGetSerializerReference, options?: McpGetSerializerResolveOptions): Promise<McpGetSerializer>;
38
+ //# sourceMappingURL=mcp-serializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-serializer.d.ts","sourceRoot":"","sources":["../src/mcp-serializer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGjE,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,GAAG,CAC7B,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,iBAAiB,KACvB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,gEAAgE;AAChE,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAqCD;;;;;;;;;;GAUG;AACH,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,yBAAyB,EACpC,OAAO,GAAE,8BAAmC,GAC3C,OAAO,CAAC,gBAAgB,CAAC,CA+C3B"}
@@ -0,0 +1,60 @@
1
+ import { ObjectRegistry } from "./registry.js";
2
+ import { resolve as resolve$1 } from "./node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/index.js";
3
+ import { isAbsolute } from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ //#region src/mcp-serializer.ts
6
+ function resolvesFromConsumer(importPath) {
7
+ return !importPath.startsWith(".") && !isAbsolute(importPath) && !importPath.startsWith("file:") && !importPath.startsWith("data:") && !importPath.startsWith("node:");
8
+ }
9
+ function isUnresolvedPackage(error, importPath) {
10
+ if (!(error instanceof Error) || error.code !== "ERR_MODULE_NOT_FOUND") return false;
11
+ const packageName = importPath.startsWith("@") ? importPath.split("/").slice(0, 2).join("/") : importPath.split("/")[0];
12
+ return error.message.includes(`'${packageName}'`);
13
+ }
14
+ function registeredModuleUrl(ownerRegistryKey) {
15
+ if (!ownerRegistryKey) return void 0;
16
+ const sourceFilePath = ObjectRegistry.getClass(ownerRegistryKey)?.sourceFilePath;
17
+ if (!sourceFilePath) return void 0;
18
+ if (sourceFilePath.startsWith("file:")) return sourceFilePath;
19
+ return isAbsolute(sourceFilePath) ? pathToFileURL(sourceFilePath).href : void 0;
20
+ }
21
+ /**
22
+ * Resolve a serializer package from the running application's module graph.
23
+ *
24
+ * Model packages own serializer implementations but do not become dependencies
25
+ * of core or generic consumers such as Chat. Bare specifiers first use the
26
+ * active runtime module graph so workspace aliases keep one constructor
27
+ * identity. When the package is absent from Core's dependency graph, resolution
28
+ * continues from the module that registered the owning model (or an explicit
29
+ * host anchor), with ESM export conditions. Relative and URL references keep
30
+ * their declaring module's ordinary dynamic-import behavior.
31
+ */
32
+ async function resolveMcpGetSerializer(reference, options = {}) {
33
+ let module;
34
+ let missingPackageError;
35
+ if (resolvesFromConsumer(reference.importPath)) try {
36
+ module = await import(reference.importPath);
37
+ } catch (error) {
38
+ if (!isUnresolvedPackage(error, reference.importPath)) throw error;
39
+ missingPackageError = error;
40
+ }
41
+ if (!module) {
42
+ const consumerAnchorUrl = options.consumerAnchorUrl ?? registeredModuleUrl(options.ownerRegistryKey);
43
+ let resolvedImportPath;
44
+ if (resolvesFromConsumer(reference.importPath)) {
45
+ if (!consumerAnchorUrl) throw missingPackageError ?? /* @__PURE__ */ new Error(`MCP get serializer '${reference.importPath}' requires a registered model or host module anchor`);
46
+ resolvedImportPath = resolve$1(reference.importPath, consumerAnchorUrl);
47
+ } else resolvedImportPath = resolve$1(reference.importPath, options.parentUrl ?? import.meta.url);
48
+ module = await import(
49
+ /* @vite-ignore */
50
+ resolvedImportPath
51
+ );
52
+ }
53
+ const serializer = module[reference.exportName];
54
+ if (typeof serializer !== "function") throw new Error(`MCP get serializer '${reference.exportName}' was not exported by '${reference.importPath}'`);
55
+ return serializer;
56
+ }
57
+ //#endregion
58
+ export { resolveMcpGetSerializer };
59
+
60
+ //# sourceMappingURL=mcp-serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-serializer.js","names":[],"sources":["../src/mcp-serializer.ts"],"sourcesContent":["import { isAbsolute } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { resolve as resolveImport } from 'import-meta-resolve';\nimport type { PublicJsonOptions, SmrtObject } from './object.js';\nimport { ObjectRegistry } from './registry.js';\n\n/** A named module export that projects an admitted MCP `get` result. */\nexport type McpGetSerializer = (\n item: SmrtObject,\n options: PublicJsonOptions,\n) => unknown | Promise<unknown>;\n\n/** Package-owned location of an MCP `get` result serializer. */\nexport interface McpGetSerializerReference {\n importPath: string;\n exportName: string;\n}\n\nexport interface McpGetSerializerResolveOptions {\n /**\n * Module URL that owns a relative serializer reference. Omit only when the\n * resolver itself owns that relative reference.\n */\n parentUrl?: string;\n\n /**\n * Qualified registry key of the model that declared the serializer. Its\n * loaded module is the default anchor for resolving a bare package.\n */\n ownerRegistryKey?: string;\n\n /**\n * Explicit application module URL for a host that resolves a serializer\n * outside a registered MCP model.\n */\n consumerAnchorUrl?: string;\n}\n\nfunction resolvesFromConsumer(importPath: string): boolean {\n return (\n !importPath.startsWith('.') &&\n !isAbsolute(importPath) &&\n !importPath.startsWith('file:') &&\n !importPath.startsWith('data:') &&\n !importPath.startsWith('node:')\n );\n}\n\nfunction isUnresolvedPackage(error: unknown, importPath: string): boolean {\n if (\n !(error instanceof Error) ||\n (error as Error & { code?: string }).code !== 'ERR_MODULE_NOT_FOUND'\n )\n return false;\n const packageName = importPath.startsWith('@')\n ? importPath.split('/').slice(0, 2).join('/')\n : importPath.split('/')[0];\n return error.message.includes(`'${packageName}'`);\n}\n\nfunction registeredModuleUrl(\n ownerRegistryKey: string | undefined,\n): string | undefined {\n if (!ownerRegistryKey) return undefined;\n const sourceFilePath =\n ObjectRegistry.getClass(ownerRegistryKey)?.sourceFilePath;\n if (!sourceFilePath) return undefined;\n if (sourceFilePath.startsWith('file:')) return sourceFilePath;\n return isAbsolute(sourceFilePath)\n ? pathToFileURL(sourceFilePath).href\n : undefined;\n}\n\n/**\n * Resolve a serializer package from the running application's module graph.\n *\n * Model packages own serializer implementations but do not become dependencies\n * of core or generic consumers such as Chat. Bare specifiers first use the\n * active runtime module graph so workspace aliases keep one constructor\n * identity. When the package is absent from Core's dependency graph, resolution\n * continues from the module that registered the owning model (or an explicit\n * host anchor), with ESM export conditions. Relative and URL references keep\n * their declaring module's ordinary dynamic-import behavior.\n */\nexport async function resolveMcpGetSerializer(\n reference: McpGetSerializerReference,\n options: McpGetSerializerResolveOptions = {},\n): Promise<McpGetSerializer> {\n let module: Record<string, unknown> | undefined;\n let missingPackageError: unknown;\n if (resolvesFromConsumer(reference.importPath)) {\n try {\n module = (await import(reference.importPath)) as Record<string, unknown>;\n } catch (error) {\n if (!isUnresolvedPackage(error, reference.importPath)) throw error;\n missingPackageError = error;\n }\n }\n if (!module) {\n const consumerAnchorUrl =\n options.consumerAnchorUrl ??\n registeredModuleUrl(options.ownerRegistryKey);\n let resolvedImportPath: string;\n if (resolvesFromConsumer(reference.importPath)) {\n if (!consumerAnchorUrl) {\n throw (\n missingPackageError ??\n new Error(\n `MCP get serializer '${reference.importPath}' requires a registered model or host module anchor`,\n )\n );\n }\n resolvedImportPath = resolveImport(\n reference.importPath,\n consumerAnchorUrl,\n );\n } else {\n resolvedImportPath = resolveImport(\n reference.importPath,\n options.parentUrl ?? import.meta.url,\n );\n }\n module = (await import(/* @vite-ignore */ resolvedImportPath)) as Record<\n string,\n unknown\n >;\n }\n const serializer = module[reference.exportName];\n if (typeof serializer !== 'function') {\n throw new Error(\n `MCP get serializer '${reference.exportName}' was not exported by '${reference.importPath}'`,\n );\n }\n return serializer as McpGetSerializer;\n}\n"],"mappings":";;;;;AAsCA,SAAS,qBAAqB,YAA6B;CACzD,OACE,CAAC,WAAW,WAAW,GAAG,KAC1B,CAAC,WAAW,UAAU,KACtB,CAAC,WAAW,WAAW,OAAO,KAC9B,CAAC,WAAW,WAAW,OAAO,KAC9B,CAAC,WAAW,WAAW,OAAO;AAElC;AAEA,SAAS,oBAAoB,OAAgB,YAA6B;CACxE,IACE,EAAE,iBAAiB,UAClB,MAAoC,SAAS,wBAE9C,OAAO;CACT,MAAM,cAAc,WAAW,WAAW,GAAG,IACzC,WAAW,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAC1C,WAAW,MAAM,GAAG,CAAC,CAAC;CAC1B,OAAO,MAAM,QAAQ,SAAS,IAAI,YAAY,EAAE;AAClD;AAEA,SAAS,oBACP,kBACoB;CACpB,IAAI,CAAC,kBAAkB,OAAO,KAAA;CAC9B,MAAM,iBACJ,eAAe,SAAS,gBAAgB,CAAC,EAAE;CAC7C,IAAI,CAAC,gBAAgB,OAAO,KAAA;CAC5B,IAAI,eAAe,WAAW,OAAO,GAAG,OAAO;CAC/C,OAAO,WAAW,cAAc,IAC5B,cAAc,cAAc,CAAC,CAAC,OAC9B,KAAA;AACN;;;;;;;;;;;;AAaA,eAAsB,wBACpB,WACA,UAA0C,CAAC,GAChB;CAC3B,IAAI;CACJ,IAAI;CACJ,IAAI,qBAAqB,UAAU,UAAU,GAC3C,IAAI;EACF,SAAU,MAAM,OAAO,UAAU;CACnC,SAAS,OAAO;EACd,IAAI,CAAC,oBAAoB,OAAO,UAAU,UAAU,GAAG,MAAM;EAC7D,sBAAsB;CACxB;CAEF,IAAI,CAAC,QAAQ;EACX,MAAM,oBACJ,QAAQ,qBACR,oBAAoB,QAAQ,gBAAgB;EAC9C,IAAI;EACJ,IAAI,qBAAqB,UAAU,UAAU,GAAG;GAC9C,IAAI,CAAC,mBACH,MACE,uCACA,IAAI,MACF,uBAAuB,UAAU,WAAW,oDAC9C;GAGJ,qBAAqB,UACnB,UAAU,YACV,iBACF;EACF,OACE,qBAAqB,UACnB,UAAU,YACV,QAAQ,aAAa,OAAO,KAAK,GACnC;EAEF,SAAU,MAAM;;GAA0B;;CAI5C;CACA,MAAM,aAAa,OAAO,UAAU;CACpC,IAAI,OAAO,eAAe,YACxB,MAAM,IAAI,MACR,uBAAuB,UAAU,WAAW,yBAAyB,UAAU,WAAW,EAC5F;CAEF,OAAO;AACT"}
@@ -0,0 +1,34 @@
1
+ import { defaultResolve } from "./lib/resolve.js";
2
+ //#region ../../node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/index.js
3
+ /**
4
+ * @typedef {import('./lib/errors.js').ErrnoException} ErrnoException
5
+ */
6
+ /**
7
+ * Match `import.meta.resolve` except that `parent` is required (you can pass
8
+ * `import.meta.url`).
9
+ *
10
+ * @param {string} specifier
11
+ * The module specifier to resolve relative to parent
12
+ * (`/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`,
13
+ * etc).
14
+ * @param {string} parent
15
+ * The absolute parent module URL to resolve from.
16
+ * You must pass `import.meta.url` or something else.
17
+ * @returns {string}
18
+ * Returns a string to a full `file:`, `data:`, or `node:` URL
19
+ * to the found thing.
20
+ */
21
+ function resolve(specifier, parent) {
22
+ if (!parent) throw new Error("Please pass `parent`: `import-meta-resolve` cannot ponyfill that");
23
+ try {
24
+ return defaultResolve(specifier, { parentURL: parent }).url;
25
+ } catch (error) {
26
+ const exception = error;
27
+ if ((exception.code === "ERR_UNSUPPORTED_DIR_IMPORT" || exception.code === "ERR_MODULE_NOT_FOUND") && typeof exception.url === "string") return exception.url;
28
+ throw error;
29
+ }
30
+ }
31
+ //#endregion
32
+ export { resolve };
33
+
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../../../node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/index.js"],"sourcesContent":["/**\n * @typedef {import('./lib/errors.js').ErrnoException} ErrnoException\n */\n\nimport {defaultResolve} from './lib/resolve.js'\n\nexport {moduleResolve} from './lib/resolve.js'\n\n/**\n * Match `import.meta.resolve` except that `parent` is required (you can pass\n * `import.meta.url`).\n *\n * @param {string} specifier\n * The module specifier to resolve relative to parent\n * (`/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`,\n * etc).\n * @param {string} parent\n * The absolute parent module URL to resolve from.\n * You must pass `import.meta.url` or something else.\n * @returns {string}\n * Returns a string to a full `file:`, `data:`, or `node:` URL\n * to the found thing.\n */\nexport function resolve(specifier, parent) {\n if (!parent) {\n throw new Error(\n 'Please pass `parent`: `import-meta-resolve` cannot ponyfill that'\n )\n }\n\n try {\n return defaultResolve(specifier, {parentURL: parent}).url\n } catch (error) {\n // See: <https://github.com/nodejs/node/blob/45f5c9b/lib/internal/modules/esm/initialize_import_meta.js#L34>\n const exception = /** @type {ErrnoException} */ (error)\n\n if (\n (exception.code === 'ERR_UNSUPPORTED_DIR_IMPORT' ||\n exception.code === 'ERR_MODULE_NOT_FOUND') &&\n typeof exception.url === 'string'\n ) {\n return exception.url\n }\n\n throw error\n }\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,QAAQ,WAAW,QAAQ;CACzC,IAAI,CAAC,QACH,MAAM,IAAI,MACR,kEACF;CAGF,IAAI;EACF,OAAO,eAAe,WAAW,EAAC,WAAW,OAAM,CAAC,CAAC,CAAC;CACxD,SAAS,OAAO;EAEd,MAAM,YAA2C;EAEjD,KACG,UAAU,SAAS,gCAClB,UAAU,SAAS,2BACrB,OAAO,UAAU,QAAQ,UAEzB,OAAO,UAAU;EAGnB,MAAM;CACR;AACF"}
@@ -0,0 +1,343 @@
1
+ import assert from "node:assert";
2
+ import v8 from "node:v8";
3
+ import { format, inspect } from "node:util";
4
+ //#region ../../node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/errors.js
5
+ /**
6
+ * @typedef ErrnoExceptionFields
7
+ * @property {number | undefined} [errnode]
8
+ * @property {string | undefined} [code]
9
+ * @property {string | undefined} [path]
10
+ * @property {string | undefined} [syscall]
11
+ * @property {string | undefined} [url]
12
+ *
13
+ * @typedef {Error & ErrnoExceptionFields} ErrnoException
14
+ */
15
+ /**
16
+ * @typedef {(...parameters: Array<any>) => string} MessageFunction
17
+ */
18
+ var own = {}.hasOwnProperty;
19
+ var classRegExp = /^([A-Z][a-z\d]*)+$/;
20
+ var kTypes = /* @__PURE__ */ new Set([
21
+ "string",
22
+ "function",
23
+ "number",
24
+ "object",
25
+ "Function",
26
+ "Object",
27
+ "boolean",
28
+ "bigint",
29
+ "symbol"
30
+ ]);
31
+ var codes = {};
32
+ /**
33
+ * Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.
34
+ * We cannot use Intl.ListFormat because it's not available in
35
+ * --without-intl builds.
36
+ *
37
+ * @param {Array<string>} array
38
+ * An array of strings.
39
+ * @param {string} [type]
40
+ * The list type to be inserted before the last element.
41
+ * @returns {string}
42
+ */
43
+ function formatList(array, type = "and") {
44
+ return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(", ")}, ${type} ${array[array.length - 1]}`;
45
+ }
46
+ /** @type {Map<string, MessageFunction | string>} */
47
+ var messages = /* @__PURE__ */ new Map();
48
+ var nodeInternalPrefix = "__node_internal_";
49
+ /** @type {number} */
50
+ var userStackTraceLimit;
51
+ codes.ERR_INVALID_ARG_TYPE = createError(
52
+ "ERR_INVALID_ARG_TYPE",
53
+ /**
54
+ * @param {string} name
55
+ * @param {Array<string> | string} expected
56
+ * @param {unknown} actual
57
+ */
58
+ (name, expected, actual) => {
59
+ assert.ok(typeof name === "string", "'name' must be a string");
60
+ if (!Array.isArray(expected)) expected = [expected];
61
+ let message = "The ";
62
+ if (name.endsWith(" argument")) message += `${name} `;
63
+ else {
64
+ const type = name.includes(".") ? "property" : "argument";
65
+ message += `"${name}" ${type} `;
66
+ }
67
+ message += "must be ";
68
+ /** @type {Array<string>} */
69
+ const types = [];
70
+ /** @type {Array<string>} */
71
+ const instances = [];
72
+ /** @type {Array<string>} */
73
+ const other = [];
74
+ for (const value of expected) {
75
+ assert.ok(typeof value === "string", "All expected entries have to be of type string");
76
+ if (kTypes.has(value)) types.push(value.toLowerCase());
77
+ else if (classRegExp.exec(value) === null) {
78
+ assert.ok(value !== "object", "The value \"object\" should be written as \"Object\"");
79
+ other.push(value);
80
+ } else instances.push(value);
81
+ }
82
+ if (instances.length > 0) {
83
+ const pos = types.indexOf("object");
84
+ if (pos !== -1) {
85
+ types.slice(pos, 1);
86
+ instances.push("Object");
87
+ }
88
+ }
89
+ if (types.length > 0) {
90
+ message += `${types.length > 1 ? "one of type" : "of type"} ${formatList(types, "or")}`;
91
+ if (instances.length > 0 || other.length > 0) message += " or ";
92
+ }
93
+ if (instances.length > 0) {
94
+ message += `an instance of ${formatList(instances, "or")}`;
95
+ if (other.length > 0) message += " or ";
96
+ }
97
+ if (other.length > 0) if (other.length > 1) message += `one of ${formatList(other, "or")}`;
98
+ else {
99
+ if (other[0].toLowerCase() !== other[0]) message += "an ";
100
+ message += `${other[0]}`;
101
+ }
102
+ message += `. Received ${determineSpecificType(actual)}`;
103
+ return message;
104
+ },
105
+ TypeError
106
+ );
107
+ codes.ERR_INVALID_MODULE_SPECIFIER = createError(
108
+ "ERR_INVALID_MODULE_SPECIFIER",
109
+ /**
110
+ * @param {string} request
111
+ * @param {string} reason
112
+ * @param {string} [base]
113
+ */
114
+ (request, reason, base = void 0) => {
115
+ return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
116
+ },
117
+ TypeError
118
+ );
119
+ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
120
+ "ERR_INVALID_PACKAGE_CONFIG",
121
+ /**
122
+ * @param {string} path
123
+ * @param {string} [base]
124
+ * @param {string} [message]
125
+ */
126
+ (path, base, message) => {
127
+ return `Invalid package config ${path}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
128
+ },
129
+ Error
130
+ );
131
+ codes.ERR_INVALID_PACKAGE_TARGET = createError(
132
+ "ERR_INVALID_PACKAGE_TARGET",
133
+ /**
134
+ * @param {string} packagePath
135
+ * @param {string} key
136
+ * @param {unknown} target
137
+ * @param {boolean} [isImport=false]
138
+ * @param {string} [base]
139
+ */
140
+ (packagePath, key, target, isImport = false, base = void 0) => {
141
+ const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
142
+ if (key === ".") {
143
+ assert.ok(isImport === false);
144
+ return `Invalid "exports" main target ${JSON.stringify(target)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? "; targets must start with \"./\"" : ""}`;
145
+ }
146
+ return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(target)} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? "; targets must start with \"./\"" : ""}`;
147
+ },
148
+ Error
149
+ );
150
+ codes.ERR_MODULE_NOT_FOUND = createError(
151
+ "ERR_MODULE_NOT_FOUND",
152
+ /**
153
+ * @param {string} path
154
+ * @param {string} base
155
+ * @param {boolean} [exactUrl]
156
+ */
157
+ (path, base, exactUrl = false) => {
158
+ return `Cannot find ${exactUrl ? "module" : "package"} '${path}' imported from ${base}`;
159
+ },
160
+ Error
161
+ );
162
+ codes.ERR_NETWORK_IMPORT_DISALLOWED = createError("ERR_NETWORK_IMPORT_DISALLOWED", "import of '%s' by %s is not supported: %s", Error);
163
+ codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
164
+ "ERR_PACKAGE_IMPORT_NOT_DEFINED",
165
+ /**
166
+ * @param {string} specifier
167
+ * @param {string} packagePath
168
+ * @param {string} base
169
+ */
170
+ (specifier, packagePath, base) => {
171
+ return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ""} imported from ${base}`;
172
+ },
173
+ TypeError
174
+ );
175
+ codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
176
+ "ERR_PACKAGE_PATH_NOT_EXPORTED",
177
+ /**
178
+ * @param {string} packagePath
179
+ * @param {string} subpath
180
+ * @param {string} [base]
181
+ */
182
+ (packagePath, subpath, base = void 0) => {
183
+ if (subpath === ".") return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
184
+ return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
185
+ },
186
+ Error
187
+ );
188
+ codes.ERR_UNSUPPORTED_DIR_IMPORT = createError("ERR_UNSUPPORTED_DIR_IMPORT", "Directory import '%s' is not supported resolving ES modules imported from %s", Error);
189
+ codes.ERR_UNSUPPORTED_RESOLVE_REQUEST = createError("ERR_UNSUPPORTED_RESOLVE_REQUEST", "Failed to resolve module specifier \"%s\" from \"%s\": Invalid relative URL or base scheme is not hierarchical.", TypeError);
190
+ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
191
+ "ERR_UNKNOWN_FILE_EXTENSION",
192
+ /**
193
+ * @param {string} extension
194
+ * @param {string} path
195
+ */
196
+ (extension, path) => {
197
+ return `Unknown file extension "${extension}" for ${path}`;
198
+ },
199
+ TypeError
200
+ );
201
+ codes.ERR_INVALID_ARG_VALUE = createError(
202
+ "ERR_INVALID_ARG_VALUE",
203
+ /**
204
+ * @param {string} name
205
+ * @param {unknown} value
206
+ * @param {string} [reason='is invalid']
207
+ */
208
+ (name, value, reason = "is invalid") => {
209
+ let inspected = inspect(value);
210
+ if (inspected.length > 128) inspected = `${inspected.slice(0, 128)}...`;
211
+ return `The ${name.includes(".") ? "property" : "argument"} '${name}' ${reason}. Received ${inspected}`;
212
+ },
213
+ TypeError
214
+ );
215
+ /**
216
+ * Utility function for registering the error codes. Only used here. Exported
217
+ * *only* to allow for testing.
218
+ * @param {string} sym
219
+ * @param {MessageFunction | string} value
220
+ * @param {ErrorConstructor} constructor
221
+ * @returns {new (...parameters: Array<any>) => Error}
222
+ */
223
+ function createError(sym, value, constructor) {
224
+ messages.set(sym, value);
225
+ return makeNodeErrorWithCode(constructor, sym);
226
+ }
227
+ /**
228
+ * @param {ErrorConstructor} Base
229
+ * @param {string} key
230
+ * @returns {ErrorConstructor}
231
+ */
232
+ function makeNodeErrorWithCode(Base, key) {
233
+ return NodeError;
234
+ /**
235
+ * @param {Array<unknown>} parameters
236
+ */
237
+ function NodeError(...parameters) {
238
+ const limit = Error.stackTraceLimit;
239
+ if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
240
+ const error = new Base();
241
+ if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
242
+ const message = getMessage(key, parameters, error);
243
+ Object.defineProperties(error, {
244
+ message: {
245
+ value: message,
246
+ enumerable: false,
247
+ writable: true,
248
+ configurable: true
249
+ },
250
+ toString: {
251
+ /** @this {Error} */
252
+ value() {
253
+ return `${this.name} [${key}]: ${this.message}`;
254
+ },
255
+ enumerable: false,
256
+ writable: true,
257
+ configurable: true
258
+ }
259
+ });
260
+ captureLargerStackTrace(error);
261
+ error.code = key;
262
+ return error;
263
+ }
264
+ }
265
+ /**
266
+ * @returns {boolean}
267
+ */
268
+ function isErrorStackTraceLimitWritable() {
269
+ try {
270
+ if (v8.startupSnapshot.isBuildingSnapshot()) return false;
271
+ } catch {}
272
+ const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
273
+ if (desc === void 0) return Object.isExtensible(Error);
274
+ return own.call(desc, "writable") && desc.writable !== void 0 ? desc.writable : desc.set !== void 0;
275
+ }
276
+ /**
277
+ * This function removes unnecessary frames from Node.js core errors.
278
+ * @template {(...parameters: unknown[]) => unknown} T
279
+ * @param {T} wrappedFunction
280
+ * @returns {T}
281
+ */
282
+ function hideStackFrames(wrappedFunction) {
283
+ const hidden = nodeInternalPrefix + wrappedFunction.name;
284
+ Object.defineProperty(wrappedFunction, "name", { value: hidden });
285
+ return wrappedFunction;
286
+ }
287
+ var captureLargerStackTrace = hideStackFrames(
288
+ /**
289
+ * @param {Error} error
290
+ * @returns {Error}
291
+ */
292
+ function(error) {
293
+ const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
294
+ if (stackTraceLimitIsWritable) {
295
+ userStackTraceLimit = Error.stackTraceLimit;
296
+ Error.stackTraceLimit = Number.POSITIVE_INFINITY;
297
+ }
298
+ Error.captureStackTrace(error);
299
+ if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
300
+ return error;
301
+ }
302
+ );
303
+ /**
304
+ * @param {string} key
305
+ * @param {Array<unknown>} parameters
306
+ * @param {Error} self
307
+ * @returns {string}
308
+ */
309
+ function getMessage(key, parameters, self) {
310
+ const message = messages.get(key);
311
+ assert.ok(message !== void 0, "expected `message` to be found");
312
+ if (typeof message === "function") {
313
+ assert.ok(message.length <= parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`);
314
+ return Reflect.apply(message, self, parameters);
315
+ }
316
+ const regex = /%[dfijoOs]/g;
317
+ let expectedLength = 0;
318
+ while (regex.exec(message) !== null) expectedLength++;
319
+ assert.ok(expectedLength === parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`);
320
+ if (parameters.length === 0) return message;
321
+ parameters.unshift(message);
322
+ return Reflect.apply(format, null, parameters);
323
+ }
324
+ /**
325
+ * Determine the specific type of a value for type-mismatch errors.
326
+ * @param {unknown} value
327
+ * @returns {string}
328
+ */
329
+ function determineSpecificType(value) {
330
+ if (value === null || value === void 0) return String(value);
331
+ if (typeof value === "function" && value.name) return `function ${value.name}`;
332
+ if (typeof value === "object") {
333
+ if (value.constructor && value.constructor.name) return `an instance of ${value.constructor.name}`;
334
+ return `${inspect(value, { depth: -1 })}`;
335
+ }
336
+ let inspected = inspect(value, { colors: false });
337
+ if (inspected.length > 28) inspected = `${inspected.slice(0, 25)}...`;
338
+ return `type ${typeof value} (${inspected})`;
339
+ }
340
+ //#endregion
341
+ export { codes };
342
+
343
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../../../../../../../../../node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/errors.js"],"sourcesContent":["/**\n * @typedef ErrnoExceptionFields\n * @property {number | undefined} [errnode]\n * @property {string | undefined} [code]\n * @property {string | undefined} [path]\n * @property {string | undefined} [syscall]\n * @property {string | undefined} [url]\n *\n * @typedef {Error & ErrnoExceptionFields} ErrnoException\n */\n\n/**\n * @typedef {(...parameters: Array<any>) => string} MessageFunction\n */\n\n// Manually “tree shaken” from:\n// <https://github.com/nodejs/node/blob/45f5c9b/lib/internal/errors.js>\n// Last checked on: Apr 29, 2024.\nimport v8 from 'node:v8'\nimport assert from 'node:assert'\nimport {format, inspect} from 'node:util'\n\nconst own = {}.hasOwnProperty\n\nconst classRegExp = /^([A-Z][a-z\\d]*)+$/\n// Sorted by a rough estimate on most frequently used entries.\nconst kTypes = new Set([\n 'string',\n 'function',\n 'number',\n 'object',\n // Accept 'Function' and 'Object' as alternative to the lower cased version.\n 'Function',\n 'Object',\n 'boolean',\n 'bigint',\n 'symbol'\n])\n\nexport const codes = {}\n\n/**\n * Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.\n * We cannot use Intl.ListFormat because it's not available in\n * --without-intl builds.\n *\n * @param {Array<string>} array\n * An array of strings.\n * @param {string} [type]\n * The list type to be inserted before the last element.\n * @returns {string}\n */\nfunction formatList(array, type = 'and') {\n return array.length < 3\n ? array.join(` ${type} `)\n : `${array.slice(0, -1).join(', ')}, ${type} ${array[array.length - 1]}`\n}\n\n/** @type {Map<string, MessageFunction | string>} */\nconst messages = new Map()\nconst nodeInternalPrefix = '__node_internal_'\n/** @type {number} */\nlet userStackTraceLimit\n\ncodes.ERR_INVALID_ARG_TYPE = createError(\n 'ERR_INVALID_ARG_TYPE',\n /**\n * @param {string} name\n * @param {Array<string> | string} expected\n * @param {unknown} actual\n */\n (name, expected, actual) => {\n assert.ok(typeof name === 'string', \"'name' must be a string\")\n if (!Array.isArray(expected)) {\n expected = [expected]\n }\n\n let message = 'The '\n if (name.endsWith(' argument')) {\n // For cases like 'first argument'\n message += `${name} `\n } else {\n const type = name.includes('.') ? 'property' : 'argument'\n message += `\"${name}\" ${type} `\n }\n\n message += 'must be '\n\n /** @type {Array<string>} */\n const types = []\n /** @type {Array<string>} */\n const instances = []\n /** @type {Array<string>} */\n const other = []\n\n for (const value of expected) {\n assert.ok(\n typeof value === 'string',\n 'All expected entries have to be of type string'\n )\n\n if (kTypes.has(value)) {\n types.push(value.toLowerCase())\n } else if (classRegExp.exec(value) === null) {\n assert.ok(\n value !== 'object',\n 'The value \"object\" should be written as \"Object\"'\n )\n other.push(value)\n } else {\n instances.push(value)\n }\n }\n\n // Special handle `object` in case other instances are allowed to outline\n // the differences between each other.\n if (instances.length > 0) {\n const pos = types.indexOf('object')\n if (pos !== -1) {\n types.slice(pos, 1)\n instances.push('Object')\n }\n }\n\n if (types.length > 0) {\n message += `${types.length > 1 ? 'one of type' : 'of type'} ${formatList(\n types,\n 'or'\n )}`\n if (instances.length > 0 || other.length > 0) message += ' or '\n }\n\n if (instances.length > 0) {\n message += `an instance of ${formatList(instances, 'or')}`\n if (other.length > 0) message += ' or '\n }\n\n if (other.length > 0) {\n if (other.length > 1) {\n message += `one of ${formatList(other, 'or')}`\n } else {\n if (other[0].toLowerCase() !== other[0]) message += 'an '\n message += `${other[0]}`\n }\n }\n\n message += `. Received ${determineSpecificType(actual)}`\n\n return message\n },\n TypeError\n)\n\ncodes.ERR_INVALID_MODULE_SPECIFIER = createError(\n 'ERR_INVALID_MODULE_SPECIFIER',\n /**\n * @param {string} request\n * @param {string} reason\n * @param {string} [base]\n */\n (request, reason, base = undefined) => {\n return `Invalid module \"${request}\" ${reason}${\n base ? ` imported from ${base}` : ''\n }`\n },\n TypeError\n)\n\ncodes.ERR_INVALID_PACKAGE_CONFIG = createError(\n 'ERR_INVALID_PACKAGE_CONFIG',\n /**\n * @param {string} path\n * @param {string} [base]\n * @param {string} [message]\n */\n (path, base, message) => {\n return `Invalid package config ${path}${\n base ? ` while importing ${base}` : ''\n }${message ? `. ${message}` : ''}`\n },\n Error\n)\n\ncodes.ERR_INVALID_PACKAGE_TARGET = createError(\n 'ERR_INVALID_PACKAGE_TARGET',\n /**\n * @param {string} packagePath\n * @param {string} key\n * @param {unknown} target\n * @param {boolean} [isImport=false]\n * @param {string} [base]\n */\n (packagePath, key, target, isImport = false, base = undefined) => {\n const relatedError =\n typeof target === 'string' &&\n !isImport &&\n target.length > 0 &&\n !target.startsWith('./')\n if (key === '.') {\n assert.ok(isImport === false)\n return (\n `Invalid \"exports\" main target ${JSON.stringify(target)} defined ` +\n `in the package config ${packagePath}package.json${\n base ? ` imported from ${base}` : ''\n }${relatedError ? '; targets must start with \"./\"' : ''}`\n )\n }\n\n return `Invalid \"${\n isImport ? 'imports' : 'exports'\n }\" target ${JSON.stringify(\n target\n )} defined for '${key}' in the package config ${packagePath}package.json${\n base ? ` imported from ${base}` : ''\n }${relatedError ? '; targets must start with \"./\"' : ''}`\n },\n Error\n)\n\ncodes.ERR_MODULE_NOT_FOUND = createError(\n 'ERR_MODULE_NOT_FOUND',\n /**\n * @param {string} path\n * @param {string} base\n * @param {boolean} [exactUrl]\n */\n (path, base, exactUrl = false) => {\n return `Cannot find ${\n exactUrl ? 'module' : 'package'\n } '${path}' imported from ${base}`\n },\n Error\n)\n\ncodes.ERR_NETWORK_IMPORT_DISALLOWED = createError(\n 'ERR_NETWORK_IMPORT_DISALLOWED',\n \"import of '%s' by %s is not supported: %s\",\n Error\n)\n\ncodes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(\n 'ERR_PACKAGE_IMPORT_NOT_DEFINED',\n /**\n * @param {string} specifier\n * @param {string} packagePath\n * @param {string} base\n */\n (specifier, packagePath, base) => {\n return `Package import specifier \"${specifier}\" is not defined${\n packagePath ? ` in package ${packagePath}package.json` : ''\n } imported from ${base}`\n },\n TypeError\n)\n\ncodes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(\n 'ERR_PACKAGE_PATH_NOT_EXPORTED',\n /**\n * @param {string} packagePath\n * @param {string} subpath\n * @param {string} [base]\n */\n (packagePath, subpath, base = undefined) => {\n if (subpath === '.')\n return `No \"exports\" main defined in ${packagePath}package.json${\n base ? ` imported from ${base}` : ''\n }`\n return `Package subpath '${subpath}' is not defined by \"exports\" in ${packagePath}package.json${\n base ? ` imported from ${base}` : ''\n }`\n },\n Error\n)\n\ncodes.ERR_UNSUPPORTED_DIR_IMPORT = createError(\n 'ERR_UNSUPPORTED_DIR_IMPORT',\n \"Directory import '%s' is not supported \" +\n 'resolving ES modules imported from %s',\n Error\n)\n\ncodes.ERR_UNSUPPORTED_RESOLVE_REQUEST = createError(\n 'ERR_UNSUPPORTED_RESOLVE_REQUEST',\n 'Failed to resolve module specifier \"%s\" from \"%s\": Invalid relative URL or base scheme is not hierarchical.',\n TypeError\n)\n\ncodes.ERR_UNKNOWN_FILE_EXTENSION = createError(\n 'ERR_UNKNOWN_FILE_EXTENSION',\n /**\n * @param {string} extension\n * @param {string} path\n */\n (extension, path) => {\n return `Unknown file extension \"${extension}\" for ${path}`\n },\n TypeError\n)\n\ncodes.ERR_INVALID_ARG_VALUE = createError(\n 'ERR_INVALID_ARG_VALUE',\n /**\n * @param {string} name\n * @param {unknown} value\n * @param {string} [reason='is invalid']\n */\n (name, value, reason = 'is invalid') => {\n let inspected = inspect(value)\n\n if (inspected.length > 128) {\n inspected = `${inspected.slice(0, 128)}...`\n }\n\n const type = name.includes('.') ? 'property' : 'argument'\n\n return `The ${type} '${name}' ${reason}. Received ${inspected}`\n },\n TypeError\n // Note: extra classes have been shaken out.\n // , RangeError\n)\n\n/**\n * Utility function for registering the error codes. Only used here. Exported\n * *only* to allow for testing.\n * @param {string} sym\n * @param {MessageFunction | string} value\n * @param {ErrorConstructor} constructor\n * @returns {new (...parameters: Array<any>) => Error}\n */\nfunction createError(sym, value, constructor) {\n // Special case for SystemError that formats the error message differently\n // The SystemErrors only have SystemError as their base classes.\n messages.set(sym, value)\n\n return makeNodeErrorWithCode(constructor, sym)\n}\n\n/**\n * @param {ErrorConstructor} Base\n * @param {string} key\n * @returns {ErrorConstructor}\n */\nfunction makeNodeErrorWithCode(Base, key) {\n // @ts-expect-error It’s a Node error.\n return NodeError\n /**\n * @param {Array<unknown>} parameters\n */\n function NodeError(...parameters) {\n const limit = Error.stackTraceLimit\n if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0\n const error = new Base()\n // Reset the limit and setting the name property.\n if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit\n const message = getMessage(key, parameters, error)\n Object.defineProperties(error, {\n // Note: no need to implement `kIsNodeError` symbol, would be hard,\n // probably.\n message: {\n value: message,\n enumerable: false,\n writable: true,\n configurable: true\n },\n toString: {\n /** @this {Error} */\n value() {\n return `${this.name} [${key}]: ${this.message}`\n },\n enumerable: false,\n writable: true,\n configurable: true\n }\n })\n\n captureLargerStackTrace(error)\n // @ts-expect-error It’s a Node error.\n error.code = key\n return error\n }\n}\n\n/**\n * @returns {boolean}\n */\nfunction isErrorStackTraceLimitWritable() {\n // Do no touch Error.stackTraceLimit as V8 would attempt to install\n // it again during deserialization.\n try {\n if (v8.startupSnapshot.isBuildingSnapshot()) {\n return false\n }\n } catch {}\n\n const desc = Object.getOwnPropertyDescriptor(Error, 'stackTraceLimit')\n if (desc === undefined) {\n return Object.isExtensible(Error)\n }\n\n return own.call(desc, 'writable') && desc.writable !== undefined\n ? desc.writable\n : desc.set !== undefined\n}\n\n/**\n * This function removes unnecessary frames from Node.js core errors.\n * @template {(...parameters: unknown[]) => unknown} T\n * @param {T} wrappedFunction\n * @returns {T}\n */\nfunction hideStackFrames(wrappedFunction) {\n // We rename the functions that will be hidden to cut off the stacktrace\n // at the outermost one\n const hidden = nodeInternalPrefix + wrappedFunction.name\n Object.defineProperty(wrappedFunction, 'name', {value: hidden})\n return wrappedFunction\n}\n\nconst captureLargerStackTrace = hideStackFrames(\n /**\n * @param {Error} error\n * @returns {Error}\n */\n // @ts-expect-error: fine\n function (error) {\n const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable()\n if (stackTraceLimitIsWritable) {\n userStackTraceLimit = Error.stackTraceLimit\n Error.stackTraceLimit = Number.POSITIVE_INFINITY\n }\n\n Error.captureStackTrace(error)\n\n // Reset the limit\n if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit\n\n return error\n }\n)\n\n/**\n * @param {string} key\n * @param {Array<unknown>} parameters\n * @param {Error} self\n * @returns {string}\n */\nfunction getMessage(key, parameters, self) {\n const message = messages.get(key)\n assert.ok(message !== undefined, 'expected `message` to be found')\n\n if (typeof message === 'function') {\n assert.ok(\n message.length <= parameters.length, // Default options do not count.\n `Code: ${key}; The provided arguments length (${parameters.length}) does not ` +\n `match the required ones (${message.length}).`\n )\n return Reflect.apply(message, self, parameters)\n }\n\n const regex = /%[dfijoOs]/g\n let expectedLength = 0\n while (regex.exec(message) !== null) expectedLength++\n assert.ok(\n expectedLength === parameters.length,\n `Code: ${key}; The provided arguments length (${parameters.length}) does not ` +\n `match the required ones (${expectedLength}).`\n )\n if (parameters.length === 0) return message\n\n parameters.unshift(message)\n return Reflect.apply(format, null, parameters)\n}\n\n/**\n * Determine the specific type of a value for type-mismatch errors.\n * @param {unknown} value\n * @returns {string}\n */\nfunction determineSpecificType(value) {\n if (value === null || value === undefined) {\n return String(value)\n }\n\n if (typeof value === 'function' && value.name) {\n return `function ${value.name}`\n }\n\n if (typeof value === 'object') {\n if (value.constructor && value.constructor.name) {\n return `an instance of ${value.constructor.name}`\n }\n\n return `${inspect(value, {depth: -1})}`\n }\n\n let inspected = inspect(value, {colors: false})\n\n if (inspected.length > 28) {\n inspected = `${inspected.slice(0, 25)}...`\n }\n\n return `type ${typeof value} (${inspected})`\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;;;;;;AAsBA,IAAM,MAAM,CAAC,EAAE;AAEf,IAAM,cAAc;AAEpB,IAAM,yBAAS,IAAI,IAAI;CACrB;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,IAAa,QAAQ,CAAC;;;;;;;;;;;;AAatB,SAAS,WAAW,OAAO,OAAO,OAAO;CACvC,OAAO,MAAM,SAAS,IAClB,MAAM,KAAK,IAAI,KAAK,EAAE,IACtB,GAAG,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,IAAI,KAAK,GAAG,MAAM,MAAM,SAAS;AACxE;;AAGA,IAAM,2BAAW,IAAI,IAAI;AACzB,IAAM,qBAAqB;;AAE3B,IAAI;AAEJ,MAAM,uBAAuB;CAC3B;;;;;;EAMC,MAAM,UAAU,WAAW;EAC1B,OAAO,GAAG,OAAO,SAAS,UAAU,yBAAyB;EAC7D,IAAI,CAAC,MAAM,QAAQ,QAAQ,GACzB,WAAW,CAAC,QAAQ;EAGtB,IAAI,UAAU;EACd,IAAI,KAAK,SAAS,WAAW,GAE3B,WAAW,GAAG,KAAK;OACd;GACL,MAAM,OAAO,KAAK,SAAS,GAAG,IAAI,aAAa;GAC/C,WAAW,IAAI,KAAK,IAAI,KAAK;EAC/B;EAEA,WAAW;;EAGX,MAAM,QAAQ,CAAC;;EAEf,MAAM,YAAY,CAAC;;EAEnB,MAAM,QAAQ,CAAC;EAEf,KAAK,MAAM,SAAS,UAAU;GAC5B,OAAO,GACL,OAAO,UAAU,UACjB,gDACF;GAEA,IAAI,OAAO,IAAI,KAAK,GAClB,MAAM,KAAK,MAAM,YAAY,CAAC;QACzB,IAAI,YAAY,KAAK,KAAK,MAAM,MAAM;IAC3C,OAAO,GACL,UAAU,UACV,sDAC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AE,EAAE;CAGxC,OAAO,QAAQ,OAAO,MAAM,IAAI,UAAU;AAC5C"}
@@ -0,0 +1,109 @@
1
+ import { codes } from "./errors.js";
2
+ import { getPackageType } from "./package-json-reader.js";
3
+ import { fileURLToPath } from "node:url";
4
+ //#region ../../node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/get-format.js
5
+ var { ERR_UNKNOWN_FILE_EXTENSION } = codes;
6
+ var hasOwnProperty = {}.hasOwnProperty;
7
+ /** @type {Record<string, string>} */
8
+ var extensionFormatMap = {
9
+ __proto__: null,
10
+ ".cjs": "commonjs",
11
+ ".js": "module",
12
+ ".json": "json",
13
+ ".mjs": "module"
14
+ };
15
+ /**
16
+ * @param {string | null} mime
17
+ * @returns {string | null}
18
+ */
19
+ function mimeToFormat(mime) {
20
+ if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime)) return "module";
21
+ if (mime === "application/json") return "json";
22
+ return null;
23
+ }
24
+ /**
25
+ * @callback ProtocolHandler
26
+ * @param {URL} parsed
27
+ * @param {{parentURL: string, source?: Buffer}} context
28
+ * @param {boolean} ignoreErrors
29
+ * @returns {string | null | void}
30
+ */
31
+ /**
32
+ * @type {Record<string, ProtocolHandler>}
33
+ */
34
+ var protocolHandlers = {
35
+ __proto__: null,
36
+ "data:": getDataProtocolModuleFormat,
37
+ "file:": getFileProtocolModuleFormat,
38
+ "http:": getHttpProtocolModuleFormat,
39
+ "https:": getHttpProtocolModuleFormat,
40
+ "node:"() {
41
+ return "builtin";
42
+ }
43
+ };
44
+ /**
45
+ * @param {URL} parsed
46
+ */
47
+ function getDataProtocolModuleFormat(parsed) {
48
+ const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(parsed.pathname) || [
49
+ null,
50
+ null,
51
+ null
52
+ ];
53
+ return mimeToFormat(mime);
54
+ }
55
+ /**
56
+ * Returns the file extension from a URL.
57
+ *
58
+ * Should give similar result to
59
+ * `require('node:path').extname(require('node:url').fileURLToPath(url))`
60
+ * when used with a `file:` URL.
61
+ *
62
+ * @param {URL} url
63
+ * @returns {string}
64
+ */
65
+ function extname(url) {
66
+ const pathname = url.pathname;
67
+ let index = pathname.length;
68
+ while (index--) {
69
+ const code = pathname.codePointAt(index);
70
+ if (code === 47) return "";
71
+ if (code === 46) return pathname.codePointAt(index - 1) === 47 ? "" : pathname.slice(index);
72
+ }
73
+ return "";
74
+ }
75
+ /**
76
+ * @type {ProtocolHandler}
77
+ */
78
+ function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
79
+ const value = extname(url);
80
+ if (value === ".js") {
81
+ const packageType = getPackageType(url);
82
+ if (packageType !== "none") return packageType;
83
+ return "commonjs";
84
+ }
85
+ if (value === "") {
86
+ const packageType = getPackageType(url);
87
+ if (packageType === "none" || packageType === "commonjs") return "commonjs";
88
+ return "module";
89
+ }
90
+ const format = extensionFormatMap[value];
91
+ if (format) return format;
92
+ if (ignoreErrors) return;
93
+ throw new ERR_UNKNOWN_FILE_EXTENSION(value, fileURLToPath(url));
94
+ }
95
+ function getHttpProtocolModuleFormat() {}
96
+ /**
97
+ * @param {URL} url
98
+ * @param {{parentURL: string}} context
99
+ * @returns {string | null}
100
+ */
101
+ function defaultGetFormatWithoutErrors(url, context) {
102
+ const protocol = url.protocol;
103
+ if (!hasOwnProperty.call(protocolHandlers, protocol)) return null;
104
+ return protocolHandlers[protocol](url, context, true) || null;
105
+ }
106
+ //#endregion
107
+ export { defaultGetFormatWithoutErrors };
108
+
109
+ //# sourceMappingURL=get-format.js.map