@mininglamp-oss/octo-runtime 1.1.0 → 1.1.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 (127) hide show
  1. package/README.md +4 -2
  2. package/apps/cli/README.md +3 -1
  3. package/apps/cli/dist/build-info.json +2 -2
  4. package/apps/cli/dist/extras.d.ts +4 -2
  5. package/apps/cli/dist/extras.js +20 -21
  6. package/apps/cli/dist/help.js +3 -0
  7. package/apps/cli/dist/logs.d.ts +10 -0
  8. package/apps/cli/dist/logs.js +186 -0
  9. package/apps/cli/dist/main.d.ts +1 -0
  10. package/apps/cli/dist/main.js +94 -19
  11. package/apps/cli/dist/{default_adapters.json → manifest.json} +5 -0
  12. package/apps/cli/dist/module-manifest.d.ts +3 -0
  13. package/apps/cli/dist/module-manifest.js +11 -0
  14. package/apps/cli/dist/openclaw.js +30 -6
  15. package/apps/cli/dist/output.js +3 -0
  16. package/apps/cli/dist/playboard.js +10 -8
  17. package/apps/cli/dist/status-output.d.ts +10 -0
  18. package/apps/cli/dist/status-output.js +65 -0
  19. package/apps/cli/dist/worker.d.ts +1 -0
  20. package/apps/cli/dist/worker.js +18 -0
  21. package/dist/public/host.d.ts +1 -0
  22. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  23. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  24. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  25. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  26. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  27. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  28. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  29. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  30. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  31. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  32. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  33. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  34. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  35. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +1 -0
  36. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +1 -0
  37. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.d.ts +33 -0
  38. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.js +118 -0
  39. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log-worker.js +7 -5
  40. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.d.ts +3 -0
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +45 -10
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.d.ts +11 -0
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.js +70 -0
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +5 -3
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
  46. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  47. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.d.ts +4 -2
  48. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +20 -21
  49. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +3 -0
  50. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/logs.d.ts +10 -0
  51. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/logs.js +186 -0
  52. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.d.ts +1 -0
  53. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +94 -19
  54. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/{default_adapters.json → manifest.json} +5 -0
  55. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.d.ts +3 -0
  56. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +11 -0
  57. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/openclaw.js +30 -6
  58. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +3 -0
  59. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +10 -8
  60. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/status-output.d.ts +10 -0
  61. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/status-output.js +65 -0
  62. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/worker.d.ts +1 -0
  63. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/worker.js +18 -0
  64. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +22 -9
  65. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +2 -2
  66. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-input.d.ts +1 -1
  67. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-input.js +5 -5
  68. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  69. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/heartbeat.d.ts +16 -0
  70. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/heartbeat.js +59 -0
  71. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +1 -0
  72. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +4 -1
  73. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/manifest-adapters.d.ts +6 -0
  74. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/manifest-adapters.js +88 -0
  75. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/module-specifier.d.ts +1 -2
  76. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/module-specifier.js +2 -9
  77. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/process.d.ts +7 -2
  78. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/process.js +138 -9
  79. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runner.js +3 -92
  80. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +36 -12
  81. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.d.ts +4 -1
  82. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +14 -6
  83. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.js +2 -1
  84. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/supervisor.d.ts +2 -2
  85. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/supervisor.js +57 -34
  86. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +8 -16
  87. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +2 -2
  88. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +16 -17
  89. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
  90. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/config-schema.json +2 -2
  91. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
  92. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/config-schema.json +2 -2
  93. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/index.js +1 -1
  94. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/store.d.ts +4 -1
  95. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/store.js +54 -4
  96. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
  97. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.d.ts +8 -1
  98. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +27 -12
  99. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-service.js +39 -2
  100. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +1 -0
  101. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
  102. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  103. package/node_modules/import-meta-resolve/index.d.ts +19 -0
  104. package/node_modules/import-meta-resolve/index.d.ts.map +1 -0
  105. package/node_modules/import-meta-resolve/index.js +47 -0
  106. package/node_modules/import-meta-resolve/lib/errors.d.ts +24 -0
  107. package/node_modules/import-meta-resolve/lib/errors.d.ts.map +1 -0
  108. package/node_modules/import-meta-resolve/lib/errors.js +504 -0
  109. package/node_modules/import-meta-resolve/lib/get-format.d.ts +13 -0
  110. package/node_modules/import-meta-resolve/lib/get-format.d.ts.map +1 -0
  111. package/node_modules/import-meta-resolve/lib/get-format.js +159 -0
  112. package/node_modules/import-meta-resolve/lib/package-json-reader.d.ts +31 -0
  113. package/node_modules/import-meta-resolve/lib/package-json-reader.d.ts.map +1 -0
  114. package/node_modules/import-meta-resolve/lib/package-json-reader.js +177 -0
  115. package/node_modules/import-meta-resolve/lib/resolve.d.ts +29 -0
  116. package/node_modules/import-meta-resolve/lib/resolve.d.ts.map +1 -0
  117. package/node_modules/import-meta-resolve/lib/resolve.js +1301 -0
  118. package/node_modules/import-meta-resolve/lib/utils.d.ts +6 -0
  119. package/node_modules/import-meta-resolve/lib/utils.d.ts.map +1 -0
  120. package/node_modules/import-meta-resolve/lib/utils.js +47 -0
  121. package/node_modules/import-meta-resolve/license +74 -0
  122. package/node_modules/import-meta-resolve/package.json +78 -0
  123. package/node_modules/import-meta-resolve/readme.md +252 -0
  124. package/package.json +28 -26
  125. package/packages/octo-runtime-extra-channel-gateway/config-schema.json +2 -2
  126. package/packages/octo-runtime-extra-channel-wecom/config-schema.json +2 -2
  127. package/packages/octo-runtime-extra-webui/config-schema.json +2 -2
@@ -0,0 +1,504 @@
1
+ /**
2
+ * @typedef ErrnoExceptionFields
3
+ * @property {number | undefined} [errnode]
4
+ * @property {string | undefined} [code]
5
+ * @property {string | undefined} [path]
6
+ * @property {string | undefined} [syscall]
7
+ * @property {string | undefined} [url]
8
+ *
9
+ * @typedef {Error & ErrnoExceptionFields} ErrnoException
10
+ */
11
+
12
+ /**
13
+ * @typedef {(...parameters: Array<any>) => string} MessageFunction
14
+ */
15
+
16
+ // Manually “tree shaken” from:
17
+ // <https://github.com/nodejs/node/blob/45f5c9b/lib/internal/errors.js>
18
+ // Last checked on: Apr 29, 2024.
19
+ import v8 from 'node:v8'
20
+ import assert from 'node:assert'
21
+ import {format, inspect} from 'node:util'
22
+
23
+ const own = {}.hasOwnProperty
24
+
25
+ const classRegExp = /^([A-Z][a-z\d]*)+$/
26
+ // Sorted by a rough estimate on most frequently used entries.
27
+ const kTypes = new Set([
28
+ 'string',
29
+ 'function',
30
+ 'number',
31
+ 'object',
32
+ // Accept 'Function' and 'Object' as alternative to the lower cased version.
33
+ 'Function',
34
+ 'Object',
35
+ 'boolean',
36
+ 'bigint',
37
+ 'symbol'
38
+ ])
39
+
40
+ export const codes = {}
41
+
42
+ /**
43
+ * Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.
44
+ * We cannot use Intl.ListFormat because it's not available in
45
+ * --without-intl builds.
46
+ *
47
+ * @param {Array<string>} array
48
+ * An array of strings.
49
+ * @param {string} [type]
50
+ * The list type to be inserted before the last element.
51
+ * @returns {string}
52
+ */
53
+ function formatList(array, type = 'and') {
54
+ return array.length < 3
55
+ ? array.join(` ${type} `)
56
+ : `${array.slice(0, -1).join(', ')}, ${type} ${array[array.length - 1]}`
57
+ }
58
+
59
+ /** @type {Map<string, MessageFunction | string>} */
60
+ const messages = new Map()
61
+ const nodeInternalPrefix = '__node_internal_'
62
+ /** @type {number} */
63
+ let userStackTraceLimit
64
+
65
+ codes.ERR_INVALID_ARG_TYPE = createError(
66
+ 'ERR_INVALID_ARG_TYPE',
67
+ /**
68
+ * @param {string} name
69
+ * @param {Array<string> | string} expected
70
+ * @param {unknown} actual
71
+ */
72
+ (name, expected, actual) => {
73
+ assert.ok(typeof name === 'string', "'name' must be a string")
74
+ if (!Array.isArray(expected)) {
75
+ expected = [expected]
76
+ }
77
+
78
+ let message = 'The '
79
+ if (name.endsWith(' argument')) {
80
+ // For cases like 'first argument'
81
+ message += `${name} `
82
+ } else {
83
+ const type = name.includes('.') ? 'property' : 'argument'
84
+ message += `"${name}" ${type} `
85
+ }
86
+
87
+ message += 'must be '
88
+
89
+ /** @type {Array<string>} */
90
+ const types = []
91
+ /** @type {Array<string>} */
92
+ const instances = []
93
+ /** @type {Array<string>} */
94
+ const other = []
95
+
96
+ for (const value of expected) {
97
+ assert.ok(
98
+ typeof value === 'string',
99
+ 'All expected entries have to be of type string'
100
+ )
101
+
102
+ if (kTypes.has(value)) {
103
+ types.push(value.toLowerCase())
104
+ } else if (classRegExp.exec(value) === null) {
105
+ assert.ok(
106
+ value !== 'object',
107
+ 'The value "object" should be written as "Object"'
108
+ )
109
+ other.push(value)
110
+ } else {
111
+ instances.push(value)
112
+ }
113
+ }
114
+
115
+ // Special handle `object` in case other instances are allowed to outline
116
+ // the differences between each other.
117
+ if (instances.length > 0) {
118
+ const pos = types.indexOf('object')
119
+ if (pos !== -1) {
120
+ types.slice(pos, 1)
121
+ instances.push('Object')
122
+ }
123
+ }
124
+
125
+ if (types.length > 0) {
126
+ message += `${types.length > 1 ? 'one of type' : 'of type'} ${formatList(
127
+ types,
128
+ 'or'
129
+ )}`
130
+ if (instances.length > 0 || other.length > 0) message += ' or '
131
+ }
132
+
133
+ if (instances.length > 0) {
134
+ message += `an instance of ${formatList(instances, 'or')}`
135
+ if (other.length > 0) message += ' or '
136
+ }
137
+
138
+ if (other.length > 0) {
139
+ if (other.length > 1) {
140
+ message += `one of ${formatList(other, 'or')}`
141
+ } else {
142
+ if (other[0].toLowerCase() !== other[0]) message += 'an '
143
+ message += `${other[0]}`
144
+ }
145
+ }
146
+
147
+ message += `. Received ${determineSpecificType(actual)}`
148
+
149
+ return message
150
+ },
151
+ TypeError
152
+ )
153
+
154
+ codes.ERR_INVALID_MODULE_SPECIFIER = createError(
155
+ 'ERR_INVALID_MODULE_SPECIFIER',
156
+ /**
157
+ * @param {string} request
158
+ * @param {string} reason
159
+ * @param {string} [base]
160
+ */
161
+ (request, reason, base = undefined) => {
162
+ return `Invalid module "${request}" ${reason}${
163
+ base ? ` imported from ${base}` : ''
164
+ }`
165
+ },
166
+ TypeError
167
+ )
168
+
169
+ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
170
+ 'ERR_INVALID_PACKAGE_CONFIG',
171
+ /**
172
+ * @param {string} path
173
+ * @param {string} [base]
174
+ * @param {string} [message]
175
+ */
176
+ (path, base, message) => {
177
+ return `Invalid package config ${path}${
178
+ base ? ` while importing ${base}` : ''
179
+ }${message ? `. ${message}` : ''}`
180
+ },
181
+ Error
182
+ )
183
+
184
+ codes.ERR_INVALID_PACKAGE_TARGET = createError(
185
+ 'ERR_INVALID_PACKAGE_TARGET',
186
+ /**
187
+ * @param {string} packagePath
188
+ * @param {string} key
189
+ * @param {unknown} target
190
+ * @param {boolean} [isImport=false]
191
+ * @param {string} [base]
192
+ */
193
+ (packagePath, key, target, isImport = false, base = undefined) => {
194
+ const relatedError =
195
+ typeof target === 'string' &&
196
+ !isImport &&
197
+ target.length > 0 &&
198
+ !target.startsWith('./')
199
+ if (key === '.') {
200
+ assert.ok(isImport === false)
201
+ return (
202
+ `Invalid "exports" main target ${JSON.stringify(target)} defined ` +
203
+ `in the package config ${packagePath}package.json${
204
+ base ? ` imported from ${base}` : ''
205
+ }${relatedError ? '; targets must start with "./"' : ''}`
206
+ )
207
+ }
208
+
209
+ return `Invalid "${
210
+ isImport ? 'imports' : 'exports'
211
+ }" target ${JSON.stringify(
212
+ target
213
+ )} defined for '${key}' in the package config ${packagePath}package.json${
214
+ base ? ` imported from ${base}` : ''
215
+ }${relatedError ? '; targets must start with "./"' : ''}`
216
+ },
217
+ Error
218
+ )
219
+
220
+ codes.ERR_MODULE_NOT_FOUND = createError(
221
+ 'ERR_MODULE_NOT_FOUND',
222
+ /**
223
+ * @param {string} path
224
+ * @param {string} base
225
+ * @param {boolean} [exactUrl]
226
+ */
227
+ (path, base, exactUrl = false) => {
228
+ return `Cannot find ${
229
+ exactUrl ? 'module' : 'package'
230
+ } '${path}' imported from ${base}`
231
+ },
232
+ Error
233
+ )
234
+
235
+ codes.ERR_NETWORK_IMPORT_DISALLOWED = createError(
236
+ 'ERR_NETWORK_IMPORT_DISALLOWED',
237
+ "import of '%s' by %s is not supported: %s",
238
+ Error
239
+ )
240
+
241
+ codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
242
+ 'ERR_PACKAGE_IMPORT_NOT_DEFINED',
243
+ /**
244
+ * @param {string} specifier
245
+ * @param {string} packagePath
246
+ * @param {string} base
247
+ */
248
+ (specifier, packagePath, base) => {
249
+ return `Package import specifier "${specifier}" is not defined${
250
+ packagePath ? ` in package ${packagePath}package.json` : ''
251
+ } imported from ${base}`
252
+ },
253
+ TypeError
254
+ )
255
+
256
+ codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
257
+ 'ERR_PACKAGE_PATH_NOT_EXPORTED',
258
+ /**
259
+ * @param {string} packagePath
260
+ * @param {string} subpath
261
+ * @param {string} [base]
262
+ */
263
+ (packagePath, subpath, base = undefined) => {
264
+ if (subpath === '.')
265
+ return `No "exports" main defined in ${packagePath}package.json${
266
+ base ? ` imported from ${base}` : ''
267
+ }`
268
+ return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${
269
+ base ? ` imported from ${base}` : ''
270
+ }`
271
+ },
272
+ Error
273
+ )
274
+
275
+ codes.ERR_UNSUPPORTED_DIR_IMPORT = createError(
276
+ 'ERR_UNSUPPORTED_DIR_IMPORT',
277
+ "Directory import '%s' is not supported " +
278
+ 'resolving ES modules imported from %s',
279
+ Error
280
+ )
281
+
282
+ codes.ERR_UNSUPPORTED_RESOLVE_REQUEST = createError(
283
+ 'ERR_UNSUPPORTED_RESOLVE_REQUEST',
284
+ 'Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.',
285
+ TypeError
286
+ )
287
+
288
+ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
289
+ 'ERR_UNKNOWN_FILE_EXTENSION',
290
+ /**
291
+ * @param {string} extension
292
+ * @param {string} path
293
+ */
294
+ (extension, path) => {
295
+ return `Unknown file extension "${extension}" for ${path}`
296
+ },
297
+ TypeError
298
+ )
299
+
300
+ codes.ERR_INVALID_ARG_VALUE = createError(
301
+ 'ERR_INVALID_ARG_VALUE',
302
+ /**
303
+ * @param {string} name
304
+ * @param {unknown} value
305
+ * @param {string} [reason='is invalid']
306
+ */
307
+ (name, value, reason = 'is invalid') => {
308
+ let inspected = inspect(value)
309
+
310
+ if (inspected.length > 128) {
311
+ inspected = `${inspected.slice(0, 128)}...`
312
+ }
313
+
314
+ const type = name.includes('.') ? 'property' : 'argument'
315
+
316
+ return `The ${type} '${name}' ${reason}. Received ${inspected}`
317
+ },
318
+ TypeError
319
+ // Note: extra classes have been shaken out.
320
+ // , RangeError
321
+ )
322
+
323
+ /**
324
+ * Utility function for registering the error codes. Only used here. Exported
325
+ * *only* to allow for testing.
326
+ * @param {string} sym
327
+ * @param {MessageFunction | string} value
328
+ * @param {ErrorConstructor} constructor
329
+ * @returns {new (...parameters: Array<any>) => Error}
330
+ */
331
+ function createError(sym, value, constructor) {
332
+ // Special case for SystemError that formats the error message differently
333
+ // The SystemErrors only have SystemError as their base classes.
334
+ messages.set(sym, value)
335
+
336
+ return makeNodeErrorWithCode(constructor, sym)
337
+ }
338
+
339
+ /**
340
+ * @param {ErrorConstructor} Base
341
+ * @param {string} key
342
+ * @returns {ErrorConstructor}
343
+ */
344
+ function makeNodeErrorWithCode(Base, key) {
345
+ // @ts-expect-error It’s a Node error.
346
+ return NodeError
347
+ /**
348
+ * @param {Array<unknown>} parameters
349
+ */
350
+ function NodeError(...parameters) {
351
+ const limit = Error.stackTraceLimit
352
+ if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0
353
+ const error = new Base()
354
+ // Reset the limit and setting the name property.
355
+ if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit
356
+ const message = getMessage(key, parameters, error)
357
+ Object.defineProperties(error, {
358
+ // Note: no need to implement `kIsNodeError` symbol, would be hard,
359
+ // probably.
360
+ message: {
361
+ value: message,
362
+ enumerable: false,
363
+ writable: true,
364
+ configurable: true
365
+ },
366
+ toString: {
367
+ /** @this {Error} */
368
+ value() {
369
+ return `${this.name} [${key}]: ${this.message}`
370
+ },
371
+ enumerable: false,
372
+ writable: true,
373
+ configurable: true
374
+ }
375
+ })
376
+
377
+ captureLargerStackTrace(error)
378
+ // @ts-expect-error It’s a Node error.
379
+ error.code = key
380
+ return error
381
+ }
382
+ }
383
+
384
+ /**
385
+ * @returns {boolean}
386
+ */
387
+ function isErrorStackTraceLimitWritable() {
388
+ // Do no touch Error.stackTraceLimit as V8 would attempt to install
389
+ // it again during deserialization.
390
+ try {
391
+ if (v8.startupSnapshot.isBuildingSnapshot()) {
392
+ return false
393
+ }
394
+ } catch {}
395
+
396
+ const desc = Object.getOwnPropertyDescriptor(Error, 'stackTraceLimit')
397
+ if (desc === undefined) {
398
+ return Object.isExtensible(Error)
399
+ }
400
+
401
+ return own.call(desc, 'writable') && desc.writable !== undefined
402
+ ? desc.writable
403
+ : desc.set !== undefined
404
+ }
405
+
406
+ /**
407
+ * This function removes unnecessary frames from Node.js core errors.
408
+ * @template {(...parameters: unknown[]) => unknown} T
409
+ * @param {T} wrappedFunction
410
+ * @returns {T}
411
+ */
412
+ function hideStackFrames(wrappedFunction) {
413
+ // We rename the functions that will be hidden to cut off the stacktrace
414
+ // at the outermost one
415
+ const hidden = nodeInternalPrefix + wrappedFunction.name
416
+ Object.defineProperty(wrappedFunction, 'name', {value: hidden})
417
+ return wrappedFunction
418
+ }
419
+
420
+ const captureLargerStackTrace = hideStackFrames(
421
+ /**
422
+ * @param {Error} error
423
+ * @returns {Error}
424
+ */
425
+ // @ts-expect-error: fine
426
+ function (error) {
427
+ const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable()
428
+ if (stackTraceLimitIsWritable) {
429
+ userStackTraceLimit = Error.stackTraceLimit
430
+ Error.stackTraceLimit = Number.POSITIVE_INFINITY
431
+ }
432
+
433
+ Error.captureStackTrace(error)
434
+
435
+ // Reset the limit
436
+ if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit
437
+
438
+ return error
439
+ }
440
+ )
441
+
442
+ /**
443
+ * @param {string} key
444
+ * @param {Array<unknown>} parameters
445
+ * @param {Error} self
446
+ * @returns {string}
447
+ */
448
+ function getMessage(key, parameters, self) {
449
+ const message = messages.get(key)
450
+ assert.ok(message !== undefined, 'expected `message` to be found')
451
+
452
+ if (typeof message === 'function') {
453
+ assert.ok(
454
+ message.length <= parameters.length, // Default options do not count.
455
+ `Code: ${key}; The provided arguments length (${parameters.length}) does not ` +
456
+ `match the required ones (${message.length}).`
457
+ )
458
+ return Reflect.apply(message, self, parameters)
459
+ }
460
+
461
+ const regex = /%[dfijoOs]/g
462
+ let expectedLength = 0
463
+ while (regex.exec(message) !== null) expectedLength++
464
+ assert.ok(
465
+ expectedLength === parameters.length,
466
+ `Code: ${key}; The provided arguments length (${parameters.length}) does not ` +
467
+ `match the required ones (${expectedLength}).`
468
+ )
469
+ if (parameters.length === 0) return message
470
+
471
+ parameters.unshift(message)
472
+ return Reflect.apply(format, null, parameters)
473
+ }
474
+
475
+ /**
476
+ * Determine the specific type of a value for type-mismatch errors.
477
+ * @param {unknown} value
478
+ * @returns {string}
479
+ */
480
+ function determineSpecificType(value) {
481
+ if (value === null || value === undefined) {
482
+ return String(value)
483
+ }
484
+
485
+ if (typeof value === 'function' && value.name) {
486
+ return `function ${value.name}`
487
+ }
488
+
489
+ if (typeof value === 'object') {
490
+ if (value.constructor && value.constructor.name) {
491
+ return `an instance of ${value.constructor.name}`
492
+ }
493
+
494
+ return `${inspect(value, {depth: -1})}`
495
+ }
496
+
497
+ let inspected = inspect(value, {colors: false})
498
+
499
+ if (inspected.length > 28) {
500
+ inspected = `${inspected.slice(0, 25)}...`
501
+ }
502
+
503
+ return `type ${typeof value} (${inspected})`
504
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @param {URL} url
3
+ * @param {{parentURL: string}} context
4
+ * @returns {string | null}
5
+ */
6
+ export function defaultGetFormatWithoutErrors(url: URL, context: {
7
+ parentURL: string;
8
+ }): string | null;
9
+ export type ProtocolHandler = (parsed: URL, context: {
10
+ parentURL: string;
11
+ source?: Buffer;
12
+ }, ignoreErrors: boolean) => string | null | void;
13
+ //# sourceMappingURL=get-format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-format.d.ts","sourceRoot":"","sources":["get-format.js"],"names":[],"mappings":"AAiJA;;;;GAIG;AACH,mDAJW,GAAG,WACH;IAAC,SAAS,EAAE,MAAM,CAAA;CAAC,GACjB,MAAM,GAAG,IAAI,CAUzB;uCAxHU,GAAG,WACH;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,gBACpC,OAAO,KACL,MAAM,GAAG,IAAI,GAAG,IAAI"}
@@ -0,0 +1,159 @@
1
+ // Manually “tree shaken” from:
2
+ // <https://github.com/nodejs/node/blob/7c3dce0/lib/internal/modules/esm/get_format.js>
3
+ // Last checked on: Apr 29, 2024.
4
+
5
+ import {fileURLToPath} from 'node:url'
6
+ import {getPackageType} from './package-json-reader.js'
7
+ import {codes} from './errors.js'
8
+
9
+ const {ERR_UNKNOWN_FILE_EXTENSION} = codes
10
+
11
+ const hasOwnProperty = {}.hasOwnProperty
12
+
13
+ /** @type {Record<string, string>} */
14
+ const extensionFormatMap = {
15
+ // @ts-expect-error: hush.
16
+ __proto__: null,
17
+ '.cjs': 'commonjs',
18
+ '.js': 'module',
19
+ '.json': 'json',
20
+ '.mjs': 'module'
21
+ }
22
+
23
+ /**
24
+ * @param {string | null} mime
25
+ * @returns {string | null}
26
+ */
27
+ function mimeToFormat(mime) {
28
+ if (
29
+ mime &&
30
+ /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime)
31
+ )
32
+ return 'module'
33
+ if (mime === 'application/json') return 'json'
34
+ return null
35
+ }
36
+
37
+ /**
38
+ * @callback ProtocolHandler
39
+ * @param {URL} parsed
40
+ * @param {{parentURL: string, source?: Buffer}} context
41
+ * @param {boolean} ignoreErrors
42
+ * @returns {string | null | void}
43
+ */
44
+
45
+ /**
46
+ * @type {Record<string, ProtocolHandler>}
47
+ */
48
+ const protocolHandlers = {
49
+ // @ts-expect-error: hush.
50
+ __proto__: null,
51
+ 'data:': getDataProtocolModuleFormat,
52
+ 'file:': getFileProtocolModuleFormat,
53
+ 'http:': getHttpProtocolModuleFormat,
54
+ 'https:': getHttpProtocolModuleFormat,
55
+ 'node:'() {
56
+ return 'builtin'
57
+ }
58
+ }
59
+
60
+ /**
61
+ * @param {URL} parsed
62
+ */
63
+ function getDataProtocolModuleFormat(parsed) {
64
+ const {1: mime} = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(
65
+ parsed.pathname
66
+ ) || [null, null, null]
67
+ return mimeToFormat(mime)
68
+ }
69
+
70
+ /**
71
+ * Returns the file extension from a URL.
72
+ *
73
+ * Should give similar result to
74
+ * `require('node:path').extname(require('node:url').fileURLToPath(url))`
75
+ * when used with a `file:` URL.
76
+ *
77
+ * @param {URL} url
78
+ * @returns {string}
79
+ */
80
+ function extname(url) {
81
+ const pathname = url.pathname
82
+ let index = pathname.length
83
+
84
+ while (index--) {
85
+ const code = pathname.codePointAt(index)
86
+
87
+ if (code === 47 /* `/` */) {
88
+ return ''
89
+ }
90
+
91
+ if (code === 46 /* `.` */) {
92
+ return pathname.codePointAt(index - 1) === 47 /* `/` */
93
+ ? ''
94
+ : pathname.slice(index)
95
+ }
96
+ }
97
+
98
+ return ''
99
+ }
100
+
101
+ /**
102
+ * @type {ProtocolHandler}
103
+ */
104
+ function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
105
+ const value = extname(url)
106
+
107
+ if (value === '.js') {
108
+ const packageType = getPackageType(url)
109
+
110
+ if (packageType !== 'none') {
111
+ return packageType
112
+ }
113
+
114
+ return 'commonjs'
115
+ }
116
+
117
+ if (value === '') {
118
+ const packageType = getPackageType(url)
119
+
120
+ // Legacy behavior
121
+ if (packageType === 'none' || packageType === 'commonjs') {
122
+ return 'commonjs'
123
+ }
124
+
125
+ // Note: we don’t implement WASM, so we don’t need
126
+ // `getFormatOfExtensionlessFile` from `formats`.
127
+ return 'module'
128
+ }
129
+
130
+ const format = extensionFormatMap[value]
131
+ if (format) return format
132
+
133
+ // Explicit undefined return indicates load hook should rerun format check
134
+ if (ignoreErrors) {
135
+ return undefined
136
+ }
137
+
138
+ const filepath = fileURLToPath(url)
139
+ throw new ERR_UNKNOWN_FILE_EXTENSION(value, filepath)
140
+ }
141
+
142
+ function getHttpProtocolModuleFormat() {
143
+ // To do: HTTPS imports.
144
+ }
145
+
146
+ /**
147
+ * @param {URL} url
148
+ * @param {{parentURL: string}} context
149
+ * @returns {string | null}
150
+ */
151
+ export function defaultGetFormatWithoutErrors(url, context) {
152
+ const protocol = url.protocol
153
+
154
+ if (!hasOwnProperty.call(protocolHandlers, protocol)) {
155
+ return null
156
+ }
157
+
158
+ return protocolHandlers[protocol](url, context, true) || null
159
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @param {string} jsonPath
3
+ * @param {{specifier: URL | string, base?: URL}} options
4
+ * @returns {PackageConfig}
5
+ */
6
+ export function read(jsonPath: string, { base, specifier }: {
7
+ specifier: URL | string;
8
+ base?: URL;
9
+ }): PackageConfig;
10
+ /**
11
+ * @param {URL | string} resolved
12
+ * @returns {PackageConfig}
13
+ */
14
+ export function getPackageScopeConfig(resolved: URL | string): PackageConfig;
15
+ /**
16
+ * Returns the package type for a given URL.
17
+ * @param {URL} url - The URL to get the package type for.
18
+ * @returns {PackageType}
19
+ */
20
+ export function getPackageType(url: URL): PackageType;
21
+ export type PackageType = "commonjs" | "module" | "none";
22
+ export type PackageConfig = {
23
+ pjsonPath: string;
24
+ exists: boolean;
25
+ main?: string | undefined;
26
+ name?: string | undefined;
27
+ type: PackageType;
28
+ exports?: Record<string, unknown> | undefined;
29
+ imports?: Record<string, unknown> | undefined;
30
+ };
31
+ //# sourceMappingURL=package-json-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-json-reader.d.ts","sourceRoot":"","sources":["package-json-reader.js"],"names":[],"mappings":"AAiCA;;;;GAIG;AACH,+BAJW,MAAM,uBACN;IAAC,SAAS,EAAE,GAAG,GAAG,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,GAAG,CAAA;CAAC,GACnC,aAAa,CAwFzB;AAED;;;GAGG;AACH,gDAHW,GAAG,GAAG,MAAM,GACV,aAAa,CAsCzB;AAED;;;;GAIG;AACH,oCAHW,GAAG,GACD,WAAW,CAKvB;0BAvKY,UAAU,GAAG,QAAQ,GAAG,MAAM;;eAG7B,MAAM;YACN,OAAO;WACP,MAAM,GAAG,SAAS;WAClB,MAAM,GAAG,SAAS;UAClB,WAAW;cACX,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;cACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS"}