@cordisjs/loader
Advanced tools
Comparing version 0.12.5 to 0.12.6
@@ -46,9 +46,7 @@ var __defProp = Object.defineProperty; | ||
} catch (e) { | ||
if (e.code !== "ERR_REQUIRE_ESM" || !this.internal) | ||
throw e; | ||
if (e.code !== "ERR_REQUIRE_ESM" || !this.internal) throw e; | ||
try { | ||
const result = this.internal.resolveSync(request, pathToFileURL(parent.filename).href, {}); | ||
const job = result?.format === "module" ? this.internal.loadCache.get(result.url) : void 0; | ||
if (job) | ||
return job?.module?.getNamespace(); | ||
if (job) return job?.module?.getNamespace(); | ||
} catch { | ||
@@ -64,4 +62,3 @@ throw e; | ||
process.send?.({ type: "shared", body }, (err) => { | ||
if (err) | ||
this.ctx.emit(this.ctx, "internal/error", "failed to send shared data"); | ||
if (err) this.ctx.emit(this.ctx, "internal/error", "failed to send shared data"); | ||
this.ctx.emit(this.ctx, "internal/info", "trigger full reload"); | ||
@@ -68,0 +65,0 @@ process.exit(code); |
@@ -6,4 +6,3 @@ var __defProp = Object.defineProperty; | ||
}) : x)(function(x) { | ||
if (typeof require !== "undefined") | ||
return require.apply(this, arguments); | ||
if (typeof require !== "undefined") return require.apply(this, arguments); | ||
throw Error('Dynamic require of "' + x + '" is not supported'); | ||
@@ -28,4 +27,3 @@ }); | ||
const entry = ctx.scope.entry; | ||
if (entry) | ||
entry.subgroup = this; | ||
if (entry) entry.subgroup = this; | ||
} | ||
@@ -47,9 +45,7 @@ static { | ||
const index = config.indexOf(options); | ||
if (index >= 0) | ||
config.splice(index, 1); | ||
if (index >= 0) config.splice(index, 1); | ||
} | ||
remove(id) { | ||
const entry = this.tree.store[id]; | ||
if (!entry) | ||
return; | ||
if (!entry) return; | ||
entry.stop(); | ||
@@ -105,4 +101,3 @@ this.unlink(entry.options); | ||
const entry = ctx.scope.entry; | ||
if (entry) | ||
entry.subtree = this; | ||
if (entry) entry.subtree = this; | ||
} | ||
@@ -123,4 +118,3 @@ static { | ||
yield entry; | ||
if (!entry.subtree) | ||
continue; | ||
if (!entry.subtree) continue; | ||
yield* entry.subtree.entries(); | ||
@@ -143,16 +137,12 @@ } | ||
tree = tree.store[part]?.subtree; | ||
if (!tree) | ||
throw new Error(`cannot resolve entry ${id}`); | ||
if (!tree) throw new Error(`cannot resolve entry ${id}`); | ||
} | ||
const entry = tree.store[final]; | ||
if (!entry) | ||
throw new Error(`cannot resolve entry ${id}`); | ||
if (!entry) throw new Error(`cannot resolve entry ${id}`); | ||
return entry; | ||
} | ||
resolveGroup(id) { | ||
if (!id) | ||
return this.root; | ||
if (!id) return this.root; | ||
const entry = this.resolve(id); | ||
if (!entry.subgroup) | ||
throw new Error(`entry ${id} is not a group`); | ||
if (!entry.subgroup) throw new Error(`entry ${id} is not a group`); | ||
return entry.subgroup; | ||
@@ -197,4 +187,3 @@ } | ||
for (const key of keys) { | ||
if (!(key in object)) | ||
continue; | ||
if (!(key in object)) continue; | ||
result.push([key, object[key]]); | ||
@@ -241,8 +230,6 @@ delete object[key]; | ||
get disabled() { | ||
if (this.options.group) | ||
return false; | ||
if (this.options.group) return false; | ||
let entry = this; | ||
do { | ||
if (entry.options.disabled) | ||
return true; | ||
if (entry.options.disabled) return true; | ||
entry = entry.parent.ctx.scope.entry; | ||
@@ -253,4 +240,3 @@ } while (entry); | ||
_check() { | ||
if (this.disabled) | ||
return false; | ||
if (this.disabled) return false; | ||
return !this.parent.ctx.bail("loader/entry-check", this); | ||
@@ -311,4 +297,3 @@ } | ||
}); | ||
if (!exports) | ||
return; | ||
if (!exports) return; | ||
const plugin = this.loader.unwrapExports(exports); | ||
@@ -349,6 +334,6 @@ this.patch(); | ||
kind: "scalar", | ||
resolve: (data) => typeof data === "string", | ||
construct: (data) => ({ __jsExpr: data }), | ||
resolve: /* @__PURE__ */ __name((data) => typeof data === "string", "resolve"), | ||
construct: /* @__PURE__ */ __name((data) => ({ __jsExpr: data }), "construct"), | ||
predicate: isJsExpr, | ||
represent: (data) => data["__jsExpr"] | ||
represent: /* @__PURE__ */ __name((data) => data["__jsExpr"], "represent") | ||
}); | ||
@@ -381,4 +366,3 @@ | ||
remove(this.trees, tree); | ||
if (this.trees.length) | ||
return; | ||
if (this.trees.length) return; | ||
clearTimeout(this._writeTask); | ||
@@ -388,4 +372,3 @@ delete this.loader.files[this.url]; | ||
async checkAccess() { | ||
if (!this.type) | ||
return; | ||
if (!this.type) return; | ||
try { | ||
@@ -496,4 +479,3 @@ await access(this.name, constants.W_OK); | ||
const dirent = dirents.find((dirent2) => dirent2.name === name3 + extension); | ||
if (!dirent) | ||
continue; | ||
if (!dirent) continue; | ||
if (!dirent.isFile()) { | ||
@@ -552,9 +534,7 @@ throw new Error(`config file "${dirent.name}" is not a file`); | ||
const checkInject = /* @__PURE__ */ __name((scope, name3) => { | ||
if (!scope.runtime.plugin) | ||
return false; | ||
if (!scope.runtime.plugin) return false; | ||
if (scope.runtime === scope) { | ||
return scope.runtime.children.every((fork) => checkInject(fork, name3)); | ||
} | ||
if (name3 in Inject.resolve(scope.entry?.options.inject)) | ||
return true; | ||
if (name3 in Inject.resolve(scope.entry?.options.inject)) return true; | ||
return checkInject(scope.parent.scope, name3); | ||
@@ -567,4 +547,3 @@ }, "checkInject"); | ||
for (const name3 in getRequired(entry)) { | ||
if (!entry.ctx.get(name3)) | ||
return true; | ||
if (!entry.ctx.get(name3)) return true; | ||
} | ||
@@ -574,4 +553,3 @@ }); | ||
for (const entry of ctx.loader.entries()) { | ||
if (!(name3 in getRequired(entry))) | ||
continue; | ||
if (!(name3 in getRequired(entry))) continue; | ||
entry.refresh(); | ||
@@ -582,4 +560,3 @@ } | ||
for (const entry of ctx.loader.entries()) { | ||
if (!(name3 in getRequired(entry))) | ||
continue; | ||
if (!(name3 in getRequired(entry))) continue; | ||
entry.refresh(); | ||
@@ -659,4 +636,3 @@ } | ||
const label = entry.options.isolate?.[key]; | ||
if (!label) | ||
return; | ||
if (!label) return; | ||
if (label === true) { | ||
@@ -684,4 +660,3 @@ realm = entry.realm ??= new LocalRealm(entry); | ||
for (const key in { ...this.newMap, ...entry.loader.delims }) { | ||
if (this.newMap[key] === oldMap[key]) | ||
continue; | ||
if (this.newMap[key] === oldMap[key]) continue; | ||
const delim = entry.loader.delims[key] ??= Symbol(`delim:${key}`); | ||
@@ -691,4 +666,3 @@ entry.ctx[delim] = Symbol(`${key}#${entry.id}`); | ||
const value = symbol && entry.ctx[symbol]; | ||
if (!(value instanceof Object)) | ||
continue; | ||
if (!(value instanceof Object)) continue; | ||
const source = Reflect.getOwnPropertyDescriptor(value, Context2.source)?.value; | ||
@@ -700,4 +674,3 @@ if (!source) { | ||
this.diff.push([key, oldMap[key], this.newMap[key], entry.ctx[delim], source[delim]]); | ||
if (entry.ctx[delim] !== source[delim]) | ||
break; | ||
if (entry.ctx[delim] !== source[delim]) break; | ||
} | ||
@@ -708,4 +681,3 @@ } | ||
self[Context2.filter] = (target) => { | ||
if (![symbol1, symbol2].includes(target[Context2.isolate][key])) | ||
return false; | ||
if (![symbol1, symbol2].includes(target[Context2.isolate][key])) return false; | ||
return flag1 === target[entry.loader.delims[key]] !== (flag1 === flag2); | ||
@@ -730,4 +702,3 @@ }; | ||
self[Context2.filter] = (target) => { | ||
if (![symbol1, symbol2].includes(target[Context2.isolate][key])) | ||
return false; | ||
if (![symbol1, symbol2].includes(target[Context2.isolate][key])) return false; | ||
return flag1 === target[entry.loader.delims[key]] !== (flag1 === flag2); | ||
@@ -745,12 +716,8 @@ }; | ||
for (const [key, label] of Object.entries(legacy.isolate ?? {})) { | ||
if (label === true) | ||
continue; | ||
if (active && entry.options.isolate?.[key] === label) | ||
continue; | ||
if (label === true) continue; | ||
if (active && entry.options.isolate?.[key] === label) continue; | ||
const realm = realms[label]; | ||
if (!realm) | ||
continue; | ||
if (!realm) continue; | ||
for (const entry2 of ctx.loader.entries()) { | ||
if (entry2.options.isolate?.[key] === realm.label) | ||
return; | ||
if (entry2.options.isolate?.[key] === realm.label) return; | ||
} | ||
@@ -774,11 +741,8 @@ realm.delete(key); | ||
ctx.on("internal/update", (fork) => { | ||
if (!fork.entry) | ||
return; | ||
if (!fork.entry) return; | ||
fork.parent.emit("loader/entry-fork", fork.entry, "reload"); | ||
}); | ||
ctx.on("internal/before-update", (fork, config2) => { | ||
if (!fork.entry) | ||
return; | ||
if (fork.entry.suspend) | ||
return fork.entry.suspend = false; | ||
if (!fork.entry) return; | ||
if (fork.entry.suspend) return fork.entry.suspend = false; | ||
const { schema: schema2 } = fork.runtime; | ||
@@ -793,12 +757,8 @@ fork.entry.options.config = schema2 ? schema2.simplify(config2) : config2; | ||
} | ||
if (fork.uid) | ||
return; | ||
if (!fork.entry) | ||
return; | ||
if (!ctx.registry.has(fork.runtime.plugin)) | ||
return; | ||
if (fork.uid) return; | ||
if (!fork.entry) return; | ||
if (!ctx.registry.has(fork.runtime.plugin)) return; | ||
fork.entry.fork = void 0; | ||
fork.parent.emit("loader/entry-fork", fork.entry, "unload"); | ||
if (!fork.entry._check()) | ||
return; | ||
if (!fork.entry._check()) return; | ||
fork.entry.options.disabled = true; | ||
@@ -833,9 +793,7 @@ fork.entry.parent.tree.write(); | ||
_locate(scope) { | ||
if (!scope.runtime.plugin) | ||
return []; | ||
if (!scope.runtime.plugin) return []; | ||
if (scope.runtime === scope) { | ||
return scope.runtime.children.flatMap((child) => this._locate(child)); | ||
} | ||
if (scope.entry) | ||
return [scope.entry]; | ||
if (scope.entry) return [scope.entry]; | ||
return this._locate(scope.parent.scope); | ||
@@ -846,7 +804,5 @@ } | ||
unwrapExports(exports) { | ||
if (isNullable2(exports)) | ||
return exports; | ||
if (isNullable2(exports)) return exports; | ||
exports = exports.default ?? exports; | ||
if (!exports.__esModule) | ||
return exports; | ||
if (!exports.__esModule) return exports; | ||
return exports.default ?? exports; | ||
@@ -853,0 +809,0 @@ } |
{ | ||
"name": "@cordisjs/loader", | ||
"description": "Loader for cordis", | ||
"version": "0.12.5", | ||
"version": "0.12.6", | ||
"type": "module", | ||
@@ -40,6 +40,6 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@cordisjs/core": "^3.17.5" | ||
"@cordisjs/core": "^3.17.6" | ||
}, | ||
"peerDependencies": { | ||
"@cordisjs/core": "^3.17.5" | ||
"@cordisjs/core": "^3.17.6" | ||
}, | ||
@@ -46,0 +46,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
88212
2059