@deepseek-ai/cordis-plugin-loader 1.1.0 → 1.2.0-alpha.2

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 +1 @@
1
- {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../../src/config/tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAiB,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAChE,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGvC;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,UAAU,CAAA;IACjB,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,MAAM,CAAC,EAAE,YAAY,CAAA;CACtB;AAeD,6EAA6E;AAC7E,8BAAsB,SAAS;IAC7B,MAAM,CAAC,QAAQ,CAAC,GAAG,OAAM;IAElB,GAAG,EAAE,OAAO,CAAA;IACZ,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,IAAI,EAAE,UAAU,CAAA;IAChB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAsB;gBAEnC,GAAG,EAAE,OAAO;IAOxB,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,4DAA4D;IAC1D,OAAO,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC;IAQzC,oEAAoE;IACpE,QAAQ;IAMR,qEAAqE;IAC/D,KAAK;IAQX;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC;IASvC,iFAAiF;IACjF,OAAO,CAAC,EAAE,EAAE,MAAM;IAalB,YAAY,CA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Q,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAE1C;;;;;;OAMG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,cAAc,GAAG,SAAS;CAG3E"}
@@ -8,4 +8,62 @@ export declare function isJsExpr(value: any): value is JsExpr;
8
8
  export interface JsExpr {
9
9
  __jsExpr: string;
10
10
  }
11
+ /** Source position of a config value: 1-based, with columns in UTF-16 code units. */
12
+ export interface SourceLocation {
13
+ /** Path of the config file that writes the value. */
14
+ filename: string;
15
+ line: number;
16
+ column: number;
17
+ }
18
+ /**
19
+ * Format a source position as `file:line:column`.
20
+ * @param location - Position to format.
21
+ * @returns The formatted position.
22
+ */
23
+ export declare function formatLocation(location: SourceLocation): string;
24
+ /**
25
+ * Format one validation issue as an indented list item.
26
+ * @param message - Issue description.
27
+ * @param location - Source position of the value, when known.
28
+ * @param path - Dotted option path of the value, when not the root.
29
+ * @returns The list item, with its path and position in parentheses.
30
+ */
31
+ export declare function formatIssue(message: string, location?: SourceLocation, path?: string): string;
32
+ /** One rejected entry option. */
33
+ export interface Issue {
34
+ message: string;
35
+ /** Path from the entry options to the rejected value; empty for the entry itself. */
36
+ path: PropertyKey[];
37
+ }
38
+ /** Map an option path to the source position that writes it. */
39
+ export type Locate = (path: PropertyKey[]) => SourceLocation | undefined;
40
+ /**
41
+ * Format a titled list of validation issues.
42
+ * @param title - First line of the message.
43
+ * @param issues - Issues to list in order.
44
+ * @param locate - Resolves each issue path to a source position.
45
+ * @returns The multi-line message.
46
+ */
47
+ export declare function formatIssues(title: string, issues: readonly Issue[], locate?: Locate): string;
48
+ /**
49
+ * Replace an error's message and stack frames, so the error points at the config source instead of the loader internals.
50
+ * @param error - Error to rewrite in place.
51
+ * @param message - New message.
52
+ * @param frames - Stack frames listed after the message line.
53
+ */
54
+ export declare function relocate(error: Error, message: string, frames: string[]): void;
55
+ /** Entry options rejected by `validateOptions()`; `issues` lists every rejected option. */
56
+ export declare class EntryValidationError extends TypeError {
57
+ issues: Issue[];
58
+ name: string;
59
+ constructor(issues: Issue[]);
60
+ }
61
+ /**
62
+ * Check entry options before an entry is created or updated. Explicit ids may contain `sep`.
63
+ * @param options - Candidate entry options.
64
+ * @param sep - Tree id separator; kept for the upstream signature.
65
+ * @param deep - Also check the entries of a group's `config`.
66
+ * @returns Every issue found; empty when the options are valid.
67
+ */
68
+ export declare function validateOptions(options: unknown, sep: string, deep?: boolean): Issue[];
11
69
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/config/utils.ts"],"names":[],"mappings":"AAGA,uEAAuE;AACvE,eAAO,MAAM,QAAQ,EAIf,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC,CAAA;AAE1C,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAUlD;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAEpD;AAED,yEAAyE;AACzE,MAAM,WAAW,MAAM;IACrB,QAAQ,EAAE,MAAM,CAAA;CACjB"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/config/utils.ts"],"names":[],"mappings":"AAGA,uEAAuE;AACvE,eAAO,MAAM,QAAQ,EAIf,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC,CAAA;AAE1C,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAUlD;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAEpD;AAED,yEAAyE;AACzE,MAAM,WAAW,MAAM;IACrB,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type Awaitable, type Dict } from '@deepseek-ai/cosmokit';
3
3
  import { ModuleLoader } from './internal.ts';
4
4
  import { Entry, type EntryOptions } from './config/entry.ts';
@@ -65,7 +65,7 @@ export declare namespace Loader {
65
65
  */
66
66
  export declare class Loader extends EntryTree {
67
67
  config: Loader.Config;
68
- [Service.config]: Loader.Intercept;
68
+ [Service.metadata]: Loader.Intercept;
69
69
  envData: any;
70
70
  name: string;
71
71
  internal: ModuleLoader | undefined;
@@ -75,7 +75,7 @@ export declare class Loader extends EntryTree {
75
75
  [Service.check](): boolean;
76
76
  showLog(entry: Entry, type: string): void;
77
77
  /** Return the loader entry id that owns `fiber`, if any. */
78
- locate(fiber?: import("@deepseek-ai/cordis").Fiber): string | undefined;
78
+ locate(fiber?: Fiber): string | undefined;
79
79
  /** Hook for hosts that can restart the process on full-reload requests. */
80
80
  exit(): void;
81
81
  /** Normalize ESM/CJS/default export shapes before applying a plugin. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsB,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAA8B,KAAK,SAAS,EAAE,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAG5D,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9D,iCAAiC;AACjC,cAAc,mBAAmB,CAAA;AACjC,yCAAyC;AACzC,cAAc,mBAAmB,CAAA;AACjC,2CAA2C;AAC3C,cAAc,qBAAqB,CAAA;AACnC,6CAA6C;AAC7C,cAAc,kBAAkB,CAAA;AAChC,kDAAkD;AAClD,cAAc,mBAAmB,CAAA;AACjC,iEAAiE;AACjE,cAAc,eAAe,CAAA;A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AAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM;IAKlC,4DAA4D;IAC5D,MAAM,CAAC,KAAK,QAAiB;IAS7B,2EAA2E;IAC3E,IAAI;IAGJ,wEAAwE;IACxE,aAAa,CAAC,OAAO,EAAE,GAAG;CAQ3B;AAED,eAAe,MAAM,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/resolve.ts"],"names":[],"mappings":"AAMA,mEAAmE;AACnE,MAAM,MAAM,OAAO,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;AA0DnD;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,gCAI9D"}
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/resolve.ts"],"names":[],"mappings":"AAOA,mEAAmE;AACnE,MAAM,MAAM,OAAO,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;AAoFnD;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,gCAO9D"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/cordis-plugin-loader",
3
3
  "description": "Plugin loader for cordis",
4
- "version": "1.1.0",
4
+ "version": "1.2.0-alpha.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -30,8 +30,8 @@
30
30
  "author": "Shigma <shigma10826@gmail.com>",
31
31
  "license": "MIT",
32
32
  "peerDependencies": {
33
- "@deepseek-ai/cordis": "~4.1.0",
34
- "node-addon-require-builtin": "^0.1.9"
33
+ "@deepseek-ai/cordis": "~4.2.0-alpha.2",
34
+ "node-addon-require-builtin": "^0.1.10"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "node-addon-require-builtin": {
@@ -39,7 +39,7 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@deepseek-ai/cosmokit": "~1.9.0",
43
- "@deepseek-ai/schemastery": "~3.19.0"
42
+ "@deepseek-ai/cosmokit": "~1.10.0-alpha.2",
43
+ "@deepseek-ai/schemastery": "~3.20.0-alpha.2"
44
44
  }
45
45
  }
@@ -1,9 +1,9 @@
1
- import { Context, Fiber, FiberState, Inject } from '@deepseek-ai/cordis'
1
+ import { Context, Fiber, FiberState, Inject, ValidationError } from '@deepseek-ai/cordis'
2
2
  import { deepEqual, isNullable, updateVolatile, volatileEntries, type Volatile } from '@deepseek-ai/cosmokit'
3
3
  import { Loader } from '../index.ts'
4
4
  import { EntryGroup } from './group.ts'
5
- import { EntryTree } from './tree.ts'
6
- import { evaluate, isJsExpr } from './utils.ts'
5
+ import { EntryTree, ModuleNotFoundError } from './tree.ts'
6
+ import { evaluate, formatIssues, formatLocation, isJsExpr, relocate } from './utils.ts'
7
7
  import { equalExceptVolatile } from './diff.ts'
8
8
 
9
9
  /** Serialized plugin entry options stored in loader config files. */
@@ -60,6 +60,23 @@ export class Entry {
60
60
  this.context.emit('loader/entry-init', this)
61
61
  }
62
62
 
63
+ /**
64
+ * Merge partial options into `target`; a nullish value deletes its key.
65
+ * @param target - Options to modify in place.
66
+ * @param options - Changes to apply.
67
+ * @returns `target`.
68
+ */
69
+ static merge(target: Partial<EntryOptions>, options: Partial<EntryOptions>) {
70
+ for (const [key, value] of Object.entries(options)) {
71
+ if (isNullable(value)) {
72
+ delete target[key]
73
+ } else {
74
+ target[key] = value
75
+ }
76
+ }
77
+ return target
78
+ }
79
+
63
80
  get context(): Context {
64
81
  return this.ctx
65
82
  }
@@ -125,13 +142,7 @@ export class Entry {
125
142
  if (create) {
126
143
  this.options = options as EntryOptions
127
144
  } else {
128
- for (const [key, value] of Object.entries(options)) {
129
- if (isNullable(value)) {
130
- delete this.options[key]
131
- } else {
132
- this.options[key] = value
133
- }
134
- }
145
+ Entry.merge(this.options, options)
135
146
  }
136
147
  sortKeys(this.options)
137
148
 
@@ -199,14 +210,41 @@ export class Entry {
199
210
  return true
200
211
  }
201
212
 
202
- getOuterStack = () => {
203
- let entry: Entry | undefined = this
204
- const result: string[] = []
205
- do {
206
- result.push(` at ${entry.parent.tree.ctx.baseUrl}#${entry.options.id}`)
207
- entry = entry.parent.ctx.fiber.entry
208
- } while (entry)
209
- return result
213
+ /**
214
+ * Where a value of this entry's options is written.
215
+ * @param path - Path inside the entry options; empty for the entry itself.
216
+ * @returns The source position, or undefined when the tree has no source.
217
+ */
218
+ getLocation(path: PropertyKey[] = []) {
219
+ return this.parent.tree.getLocation(this.options.id, path)
220
+ }
221
+
222
+ /** Stack frames from this entry out through its owning entries, each with its source position when known. */
223
+ getOuterStack = () => this.parent.getOuterStack(this.options.id)
224
+
225
+ /**
226
+ * Rewrite a config validation error to list each issue with its source position, when this entry has a source.
227
+ * @param error - Error to rewrite in place.
228
+ */
229
+ traceValidation(error: ValidationError) {
230
+ const frames = this.getOuterStack()
231
+ // an entry outside any source has nothing to point to
232
+ if (!frames.length) return
233
+ const issues = error.issues.map(({ message, path }) => ({ message, path: ValidationError.normalizePath(path) }))
234
+ const locate = (path: PropertyKey[]) => this.getLocation(['config', ...path])
235
+ relocate(error, formatIssues('invalid config', issues, locate), frames)
236
+ }
237
+
238
+ private _reportImport(error: unknown) {
239
+ if (error instanceof ModuleNotFoundError) {
240
+ const location = this.getLocation(['name'])
241
+ if (location) {
242
+ // before Node's hints
243
+ const [first, ...hints] = error.message.split('\n')
244
+ relocate(error, [`${first} (at name, ${formatLocation(location)})`, ...hints].join('\n'), this.getOuterStack())
245
+ }
246
+ }
247
+ this.ctx.logger.error(error)
210
248
  }
211
249
 
212
250
  /** Import and start the configured plugin if it is not already running. */
@@ -227,7 +265,7 @@ export class Entry {
227
265
  try {
228
266
  moduleNamespace = await this.parent.tree.import(this.options.name, this.getOuterStack)
229
267
  } catch (error) {
230
- this.ctx.logger.error(error)
268
+ this._reportImport(error)
231
269
  return
232
270
  }
233
271
  const plugin = this.loader.unwrapExports(moduleNamespace)
@@ -1,6 +1,8 @@
1
1
  import { Context, Service } from '@deepseek-ai/cordis'
2
+ import { isNullable } from '@deepseek-ai/cosmokit'
2
3
  import { Entry, type EntryOptions } from './entry.ts'
3
4
  import { EntryTree } from './tree.ts'
5
+ import { EntryValidationError, formatIssues, formatLocation, relocate, validateOptions, type Issue } from './utils.ts'
4
6
 
5
7
  /** Runtime owner for a list of child loader entries. */
6
8
  export class EntryGroup {
@@ -17,7 +19,13 @@ export class EntryGroup {
17
19
  return this.ctx
18
20
  }
19
21
 
22
+ /**
23
+ * Create or replace the entry for `options`. Invalid options reject with `EntryValidationError` and dispose any entry already registered under their id.
24
+ * @returns The full entry id.
25
+ */
20
26
  async create(options: Omit<EntryOptions, 'id'>) {
27
+ const issues = validateOptions(options, EntryTree.sep)
28
+ if (issues.length) throw this._reject(options as EntryOptions, issues)
21
29
  const id = this.tree.ensureId(options)
22
30
  const entry: Entry = this.tree.store[id] ??= new Entry(this.ctx.loader)
23
31
  // Entry may be moved from another group,
@@ -28,6 +36,35 @@ export class EntryGroup {
28
36
  return entry.id
29
37
  }
30
38
 
39
+ /**
40
+ * Stack frames for an entry of this group, followed by those of the owning entries.
41
+ * @param id - Tree-local entry id.
42
+ * @returns Frames that point at the entries' source positions.
43
+ */
44
+ getOuterStack(id: string): string[] {
45
+ const location = this.tree.getLocation(id, [])
46
+ const frames = location ? [` at ${id} (${formatLocation(location)})`] : []
47
+ return [...frames, ...this.ctx.fiber.entry?.getOuterStack() ?? []]
48
+ }
49
+
50
+ private _reject(options: EntryOptions, issues: Issue[]) {
51
+ const error = new EntryValidationError(issues)
52
+ const id = options?.id
53
+ if (isNullable(id)) return error
54
+ // unregistered first, so the disposal is not taken for a self-dispose
55
+ const entry = this.tree.store[id]
56
+ if (entry) {
57
+ delete this.tree.store[id]
58
+ entry.fiber?.dispose()
59
+ this.context.emit('loader/partial-dispose', entry, entry.options, false)
60
+ }
61
+ const frames = this.getOuterStack(id)
62
+ if (!frames.length) return error
63
+ const locate = (path: PropertyKey[]) => this.tree.getLocation(id, path)
64
+ relocate(error, formatIssues('invalid entry options', issues, locate), frames)
65
+ return error
66
+ }
67
+
31
68
  unlink(options: EntryOptions) {
32
69
  const config = this.data
33
70
  const index = config.indexOf(options)
@@ -49,8 +86,9 @@ export class EntryGroup {
49
86
  async update(config: EntryOptions[]) {
50
87
  const oldConfig = this.data as EntryOptions[]
51
88
  this.data = config
52
- const oldMap = Object.fromEntries(oldConfig.map(options => [options.id, options]))
53
- const newMap = Object.fromEntries(config.map(options => [options.id ?? Symbol('anonymous'), options]))
89
+ const oldMap = Object.fromEntries(oldConfig.map(options => [options?.id, options]))
90
+ // non-objects are rejected by `create`
91
+ const newMap = Object.fromEntries(config.map(options => [options?.id ?? Symbol('anonymous'), options]))
54
92
 
55
93
  // update inner plugins
56
94
  const ids = Reflect.ownKeys({ ...oldMap, ...newMap }) as string[]
@@ -1,9 +1,46 @@
1
1
  import { composeError, Context } from '@deepseek-ai/cordis'
2
2
  import { isNonNullable, type Dict } from '@deepseek-ai/cosmokit'
3
+ import url from 'node:url'
3
4
  import { Entry, type EntryOptions } from './entry.ts'
4
5
  import { EntryGroup } from './group.ts'
6
+ import { EntryValidationError, validateOptions, type SourceLocation } from './utils.ts'
5
7
  import { createResolve } from '../resolve.ts'
6
8
 
9
+ // A Windows drive-letter path, e.g. `C:\app\plugin.js` or `C:/app/plugin.js`.
10
+ const driveLetter = /^[A-Za-z]:[\\/]/
11
+
12
+ // Node names the modules only in the message:
13
+ // `Cannot find (module|package) '<target>' imported from <parent>`
14
+ function parseNotFound(error: any) {
15
+ if (error?.code !== 'ERR_MODULE_NOT_FOUND' || typeof error.message !== 'string') return
16
+ // later lines are hints, e.g. `Did you mean to import ...?`
17
+ const [first, ...hints] = error.message.split('\n') as string[]
18
+ const match = first.match(/^(Cannot find (?:module|package) '.*') imported from (.*)$/)
19
+ if (match) return { description: match[1], parent: match[2], hints }
20
+ }
21
+
22
+ function toPath(href: string) {
23
+ try {
24
+ return href.startsWith('file:') ? url.fileURLToPath(href) : href
25
+ } catch {
26
+ return href
27
+ }
28
+ }
29
+
30
+ /** A configured plugin module that cannot be found, as opposed to a missing module imported by that plugin. */
31
+ export class ModuleNotFoundError extends Error {
32
+ name = 'ModuleNotFoundError'
33
+ code = 'ERR_MODULE_NOT_FOUND'
34
+
35
+ /**
36
+ * @param specifier - Entry `name` that failed to resolve.
37
+ * @param message - Node's description and hints, without its importer.
38
+ */
39
+ constructor(public specifier: string, message: string) {
40
+ super(message)
41
+ }
42
+ }
43
+
7
44
  /**
8
45
  * One tree-side mutation, reported to `EntryTree.commit()` synchronously after
9
46
  * it has been applied to `entry.options` / `group.data`.
@@ -125,6 +162,8 @@ export abstract class EntryTree {
125
162
  /** Create an entry in the root group or a nested group. */
126
163
  async create(options: Omit<EntryOptions, 'id'>, parent: string | null = null, position = Infinity) {
127
164
  const group = this.resolveGroup(parent)
165
+ const issues = validateOptions(options, EntryTree.sep, true)
166
+ if (issues.length) throw new EntryValidationError(issues)
128
167
  const id = group.tree.ensureId(options)
129
168
  group.data.splice(position, 0, options as EntryOptions)
130
169
  group.tree.commit({ id, group, options: options as EntryOptions })
@@ -145,6 +184,8 @@ export abstract class EntryTree {
145
184
  const entry = this.resolve(id)
146
185
  const source = entry.parent
147
186
  const legacy = { ...entry.options }
187
+ const issues = validateOptions(Entry.merge({ ...legacy }, options), EntryTree.sep, true)
188
+ if (issues.length) throw new EntryValidationError(issues)
148
189
  if (parent !== undefined) {
149
190
  const target = this.resolveGroup(parent)
150
191
  const moved = target.tree === source.tree ? [] : members(entry)
@@ -178,28 +219,70 @@ export abstract class EntryTree {
178
219
  return task
179
220
  }
180
221
 
181
- /** Import a plugin module from a specifier or `cordis:` builtin. */
222
+ /**
223
+ * Import a plugin module from a specifier or `cordis:` builtin. On Windows a drive-letter path is imported as a file URL.
224
+ * Rejects with `ModuleNotFoundError` when the specifier itself cannot be found; other import errors propagate unchanged.
225
+ */
182
226
  import(name: string, getOuterStack?: () => string[]) {
183
227
  if (name.startsWith('cordis:')) {
184
228
  return this.ctx.loader.builtins[name.slice(7)]
185
229
  }
230
+ // On Windows, a drive-letter path is converted with `pathToFileURL`.
231
+ if (process.platform === 'win32' && driveLetter.test(name)) {
232
+ name = url.pathToFileURL(name).href
233
+ }
234
+ // to tell `name` apart from a module it imports
235
+ let parent: string | undefined
236
+ // the helper resolves `name` only
237
+ let unresolved: unknown
186
238
  return composeError(async (info) => {
187
239
  // ModuleJob.run
188
240
  // onImport.tracePromise.__proto__
189
241
  // internal.import
190
242
  info.offset += 3
191
243
  if (this.ctx.loader.internal) {
192
- return await this.ctx.loader.internal.import(name, this.ctx.baseUrl!, {})
244
+ parent = this.ctx.baseUrl!
245
+ return await this.ctx.loader.internal.import(name, parent, {})
193
246
  } else if (name.startsWith('.')) {
247
+ parent = import.meta.url
194
248
  return await import(/* @vite-ignore */new URL(name, this.ctx.baseUrl).href)
195
249
  } else {
196
250
  const resolve = await createResolve(this.ctx.baseUrl)
197
- const url = resolve ? resolve(name) : name
251
+ let url = name
252
+ if (resolve) {
253
+ try {
254
+ url = resolve(name)
255
+ } catch (error) {
256
+ unresolved = error
257
+ throw error
258
+ }
259
+ }
260
+ parent = import.meta.url
198
261
  return await import(/* @vite-ignore */ url)
199
262
  }
200
- }, getOuterStack)
263
+ }, getOuterStack).catch((error: unknown) => {
264
+ const notFound = parseNotFound(error)
265
+ if (!notFound) throw error
266
+ if (error !== unresolved && (!parent || notFound.parent !== toPath(parent))) throw error
267
+ const result = new ModuleNotFoundError(name, [notFound.description, ...notFound.hints].join('\n'))
268
+ const frames = getOuterStack?.() ?? []
269
+ // Node's frames are those of its resolver
270
+ if (frames.length) result.stack = [`${result.name}: ${result.message}`, ...frames].join('\n')
271
+ throw result
272
+ })
201
273
  }
202
274
 
203
275
  /** Report an applied mutation synchronously. In-memory trees may use a no-op. */
204
276
  abstract commit(change: EntryChange): void
277
+
278
+ /**
279
+ * Where a value of the entry options is written. A path that leaves the
280
+ * source falls back to its deepest written ancestor.
281
+ * @param _id - Tree-local entry id.
282
+ * @param _path - Path inside the entry options.
283
+ * @returns The source position, or undefined for trees without a source file.
284
+ */
285
+ getLocation(_id: string, _path: PropertyKey[]): SourceLocation | undefined {
286
+ return undefined
287
+ }
205
288
  }
@@ -23,10 +23,140 @@ export function interpolate(ctx: object, value: any) {
23
23
 
24
24
  /** Return true when a value is a serialized loader JavaScript expression. */
25
25
  export function isJsExpr(value: any): value is JsExpr {
26
- return value instanceof Object && '__jsExpr' in value
26
+ return value instanceof Object && typeof value.__jsExpr === 'string'
27
27
  }
28
28
 
29
29
  /** Serialized JavaScript expression produced by the include YAML tag. */
30
30
  export interface JsExpr {
31
31
  __jsExpr: string
32
32
  }
33
+
34
+ /** Source position of a config value: 1-based, with columns in UTF-16 code units. */
35
+ export interface SourceLocation {
36
+ /** Path of the config file that writes the value. */
37
+ filename: string
38
+ line: number
39
+ column: number
40
+ }
41
+
42
+ /**
43
+ * Format a source position as `file:line:column`.
44
+ * @param location - Position to format.
45
+ * @returns The formatted position.
46
+ */
47
+ export function formatLocation(location: SourceLocation) {
48
+ return `${location.filename}:${location.line}:${location.column}`
49
+ }
50
+
51
+ /**
52
+ * Format one validation issue as an indented list item.
53
+ * @param message - Issue description.
54
+ * @param location - Source position of the value, when known.
55
+ * @param path - Dotted option path of the value, when not the root.
56
+ * @returns The list item, with its path and position in parentheses.
57
+ */
58
+ export function formatIssue(message: string, location?: SourceLocation, path?: string) {
59
+ const where = [path, location && formatLocation(location)].filter(Boolean).join(', ')
60
+ return where ? ` - ${message} (at ${where})` : ` - ${message}`
61
+ }
62
+
63
+ /** One rejected entry option. */
64
+ export interface Issue {
65
+ message: string
66
+ /** Path from the entry options to the rejected value; empty for the entry itself. */
67
+ path: PropertyKey[]
68
+ }
69
+
70
+ /** Map an option path to the source position that writes it. */
71
+ export type Locate = (path: PropertyKey[]) => SourceLocation | undefined
72
+
73
+ /**
74
+ * Format a titled list of validation issues.
75
+ * @param title - First line of the message.
76
+ * @param issues - Issues to list in order.
77
+ * @param locate - Resolves each issue path to a source position.
78
+ * @returns The multi-line message.
79
+ */
80
+ export function formatIssues(title: string, issues: readonly Issue[], locate?: Locate) {
81
+ const lines = issues.map(({ message, path }) => {
82
+ return formatIssue(message, locate?.(path), path.length ? path.map(String).join('.') : undefined)
83
+ })
84
+ return `${title}:\n${lines.join('\n')}`
85
+ }
86
+
87
+ /**
88
+ * Replace an error's message and stack frames, so the error points at the config source instead of the loader internals.
89
+ * @param error - Error to rewrite in place.
90
+ * @param message - New message.
91
+ * @param frames - Stack frames listed after the message line.
92
+ */
93
+ export function relocate(error: Error, message: string, frames: string[]) {
94
+ error.message = message
95
+ error.stack = [`${error.name}: ${message}`, ...frames].join('\n')
96
+ }
97
+
98
+ /** Entry options rejected by `validateOptions()`; `issues` lists every rejected option. */
99
+ export class EntryValidationError extends TypeError {
100
+ name = 'EntryValidationError'
101
+
102
+ constructor(public issues: Issue[]) {
103
+ super(formatIssues('invalid entry options', issues))
104
+ }
105
+ }
106
+
107
+ // only `disabled` takes an expression
108
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
109
+ return !!value && typeof value === 'object' && !Array.isArray(value) && !isJsExpr(value)
110
+ }
111
+
112
+ /**
113
+ * Check entry options before an entry is created or updated. Explicit ids may contain `sep`.
114
+ * @param options - Candidate entry options.
115
+ * @param sep - Tree id separator; kept for the upstream signature.
116
+ * @param deep - Also check the entries of a group's `config`.
117
+ * @returns Every issue found; empty when the options are valid.
118
+ */
119
+ export function validateOptions(options: unknown, sep: string, deep = false): Issue[] {
120
+ if (!isPlainObject(options)) return [{ message: 'entry must be an object', path: [] }]
121
+ const issues: Issue[] = []
122
+ const check = (key: string, expected: string, valid: (value: any) => boolean, required = false) => {
123
+ const value = options[key]
124
+ if (value === undefined || value === null) {
125
+ if (required) issues.push({ message: `${key} is required`, path: [key] })
126
+ } else if (!valid(value)) {
127
+ issues.push({ message: `${key} must be ${expected}`, path: [key] })
128
+ }
129
+ }
130
+
131
+ check('id', 'a string', value => typeof value === 'string')
132
+ check('name', 'a string', value => typeof value === 'string', true)
133
+ check('group', 'a boolean', value => typeof value === 'boolean')
134
+ check('disabled', 'a boolean', value => typeof value === 'boolean' || isJsExpr(value))
135
+ // a group's config is its entry list
136
+ if (options.group === true) check('config', 'an array', Array.isArray, true)
137
+
138
+ check('inject', 'an array or an object', value => Array.isArray(value) || isPlainObject(value))
139
+ if (Array.isArray(options.inject)) {
140
+ options.inject.forEach((name, index) => {
141
+ if (typeof name === 'string') return
142
+ issues.push({ message: `inject.${index} must be a string`, path: ['inject', index] })
143
+ })
144
+ }
145
+ check('intercept', 'an object', isPlainObject)
146
+ check('isolate', 'an object', isPlainObject)
147
+ if (isPlainObject(options.isolate)) {
148
+ for (const [name, label] of Object.entries(options.isolate)) {
149
+ if (label === true || typeof label === 'string') continue
150
+ issues.push({ message: `isolate.${name} must be true or a string`, path: ['isolate', name] })
151
+ }
152
+ }
153
+ // from a source, each entry is checked as its group creates it
154
+ if (deep && options.group === true && Array.isArray(options.config)) {
155
+ options.config.forEach((child, index) => {
156
+ for (const { message, path } of validateOptions(child, sep, true)) {
157
+ issues.push({ message, path: ['config', index, ...path] })
158
+ }
159
+ })
160
+ }
161
+ return issues
162
+ }