@luckylillia-dev/luckylillia 9.0.4 → 9.0.6

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.
package/llbot-core.js CHANGED
@@ -1,9 +1,9 @@
1
- import { $ as Hono, A as Registries, At as require_dist, B as installHostLifecycle, Bt as getPluginDirs, C as scanPluginRoots, Ct as normalizeScope, D as removeScannedPackage, Dt as deepMerge, E as cleanupRemovedPackages, Et as platform_exports, F as parseSpec, G as GATEWAY_SECRET_HEADER, Gt as LOG_DIR, Ht as isDockerEnvironment, I as pickVersion, J as isManaged, Jt as globalVars_exports, L as lockInstance, M as isExactVersion, Mt as configPaths_exports, N as isPackageName, Nt as currentInstance, O as scannedPackagePath, Ot as mergeNewProperties, P as matches, Pt as instance_exports, Q as version_exports, Qt as __toESM, S as resolveMain, St as acceptsScope, T as sdkRangeOf, Tt as normalizePlatformId, Ut as isPluginHmr, Vt as isDevMode, W as GATEWAY_SECRET_ENV, Wt as DATA_DIR, X as protocol_exports, Xt as __exportAll, Y as isManagerMessage, Yt as __commonJSMin, Z as version$10, Zt as __require, _ as manifest_exports, _t as templateSection, at as migrateRenamedPackages, b as parsePluginDependencies, bt as newEntryId, c as marketSettings, ct as renameNativeQQSettings, d as extractPackage, dt as renamed_exports, et as HtmlEscapedCallbackPhase, f as readTarStream, ft as withCurrentNames, g as isInside, gt as templateConfig, h as isImagePath, ht as DEPRECATED_KEYS, it as migrateNTQQMessaging, j as RegistryError, jt as configPaths, k as require_semver, kt as JsonFile, l as registriesOf, lt as RENAMED_PACKAGES, m as SDK_PACKAGE, mt as ADAPTER_KEYS, nt as liftBuiltinSettings, ot as migrateToInstances, p as PLUGIN_CATEGORIES, pt as ADAPTER_ENTRIES, qt as TEMP_DIR, r as coreUpdate_exports, rt as migrateExtractedPlugins, s as MarketSchema, st as migrateWebuiToken, tt as resolveCallback, u as Catalog, ut as currentPackageName, v as matchesPluginVersion, vt as upgradeConfig, w as sdkIncompatibility, wt as normalizePlatform, x as readPluginPackage, xt as normalizeUi, y as normalizeService, yt as PluginStore, zt as environment_exports } from "./chunks/coreUpdate-CZs1GqPc.js";
1
+ import { $ as Hono, A as Registries, At as require_dist, B as installHostLifecycle, Bt as getPluginDirs, C as scanPluginRoots, Ct as normalizeScope, D as removeScannedPackage, Dt as deepMerge, E as cleanupRemovedPackages, Et as platform_exports, F as parseSpec, G as GATEWAY_SECRET_HEADER, Gt as LOG_DIR, Ht as isDockerEnvironment, I as pickVersion, J as isManaged, Jt as globalVars_exports, L as lockInstance, M as isExactVersion, Mt as configPaths_exports, N as isPackageName, Nt as currentInstance, O as scannedPackagePath, Ot as mergeNewProperties, P as matches, Pt as instance_exports, Q as version_exports, Qt as __toESM, S as resolveMain, St as acceptsScope, T as sdkRangeOf, Tt as normalizePlatformId, Ut as isPluginHmr, Vt as isDevMode, W as GATEWAY_SECRET_ENV, Wt as DATA_DIR, X as protocol_exports, Xt as __exportAll, Y as isManagerMessage, Yt as __commonJSMin, Z as version$10, Zt as __require, _ as manifest_exports, _t as templateSection, at as migrateRenamedPackages, b as parsePluginDependencies, bt as newEntryId, c as marketSettings, ct as renameNativeQQSettings, d as extractPackage, dt as renamed_exports, et as HtmlEscapedCallbackPhase, f as readTarStream, ft as withCurrentNames, g as isInside, gt as templateConfig, h as isImagePath, ht as DEPRECATED_KEYS, it as migrateNTQQMessaging, j as RegistryError, jt as configPaths, k as require_semver, kt as JsonFile, l as registriesOf, lt as RENAMED_PACKAGES, m as SDK_PACKAGE, mt as ADAPTER_KEYS, nt as liftBuiltinSettings, ot as migrateToInstances, p as PLUGIN_CATEGORIES, pt as ADAPTER_ENTRIES, qt as TEMP_DIR, r as coreUpdate_exports, rt as migrateExtractedPlugins, s as MarketSchema, st as migrateWebuiToken, tt as resolveCallback, u as Catalog, ut as currentPackageName, v as matchesPluginVersion, vt as upgradeConfig, w as sdkIncompatibility, wt as normalizePlatform, x as readPluginPackage, xt as normalizeUi, y as normalizeService, yt as PluginStore, zt as environment_exports } from "./chunks/coreUpdate-CEtHqh6r.js";
2
2
  import { p as compareVersions } from "./chunks/restart-TVy8kurW.js";
3
3
  import { t as __vitePreload } from "./chunks/preload-helper-DxWiKyOd.js";
4
4
  import * as nodeModule from "node:module";
5
5
  import { createRequire } from "node:module";
6
- import fs, { appendFile, appendFileSync, createReadStream, createWriteStream, existsSync, mkdirSync, realpathSync, stat, statSync, watch } from "node:fs";
6
+ import fs, { appendFile, appendFileSync, createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, realpathSync, stat, statSync, watch } from "node:fs";
7
7
  import path, { dirname, join } from "node:path";
8
8
  import { fileURLToPath, pathToFileURL } from "node:url";
9
9
  import { execFile } from "node:child_process";
@@ -707,6 +707,8 @@ var resolve_hook_exports = /* @__PURE__ */ __exportAll({
707
707
  LEGACY_SPECIFIERS: () => LEGACY_SPECIFIERS,
708
708
  SHARED_SPECIFIERS: () => SHARED_SPECIFIERS,
709
709
  installPluginResolver: () => installPluginResolver,
710
+ isCommonJS: () => isCommonJS,
711
+ isModulePackage: () => isModulePackage,
710
712
  resolvePluginSpecifier: () => resolvePluginSpecifier,
711
713
  sharedSpecifierMap: () => sharedSpecifierMap
712
714
  });
@@ -735,10 +737,13 @@ function sharedSpecifierMap() {
735
737
  }
736
738
  /**
737
739
  * Two jobs: pin shared packages to the host copy, and copy the `?v=` reload epoch from a plugin module
738
- * to the modules it imports inside the same package. Without the latter only the entry would be
739
- * re-evaluated on reload and every relative import would come back from the ESM cache.
740
+ * to the ES modules it imports inside the same package. Without the latter only the entry would be
741
+ * re-evaluated on reload and every relative import would come back from the ESM cache. CommonJS files keep
742
+ * their plain URL: imported with a query, Node evaluates them apart from require() and their exports come out
743
+ * wrong (a reload of the NTQQ plugin failed on `debug`, imported by an ES module in its node_modules). The host
744
+ * clears them from require.cache for a reload instead.
740
745
  */
741
- function resolvePluginSpecifier(state, specifier, context, nextResolve) {
746
+ function resolvePluginSpecifier(state, specifier, context, nextResolve, moduleType = isModulePackage) {
742
747
  const internal = builtinRuntimeModule(specifier);
743
748
  if (internal) return {
744
749
  url: internal,
@@ -755,7 +760,7 @@ function resolvePluginSpecifier(state, specifier, context, nextResolve) {
755
760
  const epoch = new URL(parent).searchParams.get("v");
756
761
  if (!epoch) return result;
757
762
  const root = packageRootOf(state.roots, parent);
758
- if (!root || !stripQuery(result.url).startsWith(root)) return result;
763
+ if (!root || !stripQuery(result.url).startsWith(root) || isCommonJS(result.url, moduleType)) return result;
759
764
  const url = new URL(result.url);
760
765
  url.searchParams.set("v", epoch);
761
766
  return {
@@ -776,6 +781,40 @@ function packageRootOf(roots, url) {
776
781
  for (const root of roots) if (bare.startsWith(root) && (!best || root.length > best.length)) best = root;
777
782
  return best;
778
783
  }
784
+ var packageTypes = /* @__PURE__ */ new Map();
785
+ /**
786
+ * Whether the nearest package.json of a directory (a file URL) says "type": "module". Read once per directory:
787
+ * a reload does not change it.
788
+ */
789
+ function isModulePackage(dirUrl) {
790
+ let dir;
791
+ try {
792
+ dir = fileURLToPath(dirUrl);
793
+ } catch {
794
+ return false;
795
+ }
796
+ return moduleIn(path.resolve(dir));
797
+ }
798
+ function moduleIn(dir) {
799
+ const known = packageTypes.get(dir);
800
+ if (known !== void 0) return known;
801
+ let module;
802
+ try {
803
+ module = JSON.parse(readFileSync(path.join(dir, "package.json"), "utf8")).type === "module";
804
+ } catch {
805
+ const parent = path.dirname(dir);
806
+ module = parent !== dir && moduleIn(parent);
807
+ }
808
+ packageTypes.set(dir, module);
809
+ return module;
810
+ }
811
+ /** How Node decides it: .cjs, or .js without "type": "module" in the nearest package.json. */
812
+ function isCommonJS(url, moduleType) {
813
+ const bare = stripQuery(url);
814
+ if (bare.endsWith(".cjs")) return true;
815
+ if (!bare.endsWith(".js")) return false;
816
+ return !moduleType(new URL(".", bare).href);
817
+ }
779
818
  function stripQuery(url) {
780
819
  const index = url.search(/[?#]/);
781
820
  return index < 0 ? url : url.slice(0, index);
@@ -2932,7 +2971,7 @@ var Installer = class Installer {
2932
2971
  const packument = (name) => {
2933
2972
  let document = documents.get(name);
2934
2973
  if (!document) {
2935
- document = this.registry.packument(name);
2974
+ document = this.registry.packument(name, false, void 0, "install");
2936
2975
  document.catch(() => {});
2937
2976
  documents.set(name, document);
2938
2977
  }
@@ -2964,7 +3003,7 @@ var Installer = class Installer {
2964
3003
  }
2965
3004
  const existing = lookup(node, dep.alias);
2966
3005
  if (existing && existing.source.manifest.name === spec.name && matches(existing.source.manifest.version, spec.range)) continue;
2967
- const version = await packument(spec.name).then((document) => pickVersion(document, spec.range) ?? this.registry.packument(spec.name, false, (document) => !!pickVersion(document, spec.range)).then((document) => pickVersion(document, spec.range))).catch((e) => {
3006
+ const version = await packument(spec.name).then((document) => pickVersion(document, spec.range) ?? this.registry.packument(spec.name, false, (document) => !!pickVersion(document, spec.range), "install").then((document) => pickVersion(document, spec.range))).catch((e) => {
2968
3007
  if (dep.optional) return void 0;
2969
3008
  throw e;
2970
3009
  });
@@ -6793,7 +6832,7 @@ var Market = class {
6793
6832
  const documents = /* @__PURE__ */ new Map();
6794
6833
  const packument = (name) => {
6795
6834
  let document = documents.get(name);
6796
- if (!document) documents.set(name, document = this.registry.packument(name, true));
6835
+ if (!document) documents.set(name, document = this.registry.packument(name, true, void 0, "install"));
6797
6836
  return document;
6798
6837
  };
6799
6838
  await Promise.all(installed.map(async (pkg) => {
@@ -6991,7 +7030,7 @@ var Market = class {
6991
7030
  }
6992
7031
  async catalogVersion(entry, document) {
6993
7032
  const pinned = (document) => Object.hasOwn(document.versions ?? {}, entry.version);
6994
- if (!document || !pinned(document)) document = await this.registry.packument(entry.name, true, pinned);
7033
+ if (!document || !pinned(document)) document = await this.registry.packument(entry.name, true, pinned, "install");
6995
7034
  const version = pinned(document) ? document.versions[entry.version] : void 0;
6996
7035
  if (!version) throw new MarketError(`${entry.name}: catalog version ${entry.version} is unavailable from the npm registry`, 404);
6997
7036
  if (document.name !== entry.name || version.name !== entry.name || version.version !== entry.version) throw new MarketError(`the registry returned a different package or version for ${entry.name}@${entry.version}`);
@@ -7013,7 +7052,7 @@ var Market = class {
7013
7052
  }
7014
7053
  }
7015
7054
  /** Resolve the complete plugin graph before writing anything. npm library dependencies stay with Installer. */
7016
- async planPlugins(main, catalog, packument = (name) => this.registry.packument(name, true), requestedVersion) {
7055
+ async planPlugins(main, catalog, packument = (name) => this.registry.packument(name, true, void 0, "install"), requestedVersion) {
7017
7056
  const installed = new Map(this.installedPackages().map((pkg) => [pkg.name, pkg]));
7018
7057
  const installedRequirements = /* @__PURE__ */ new Map();
7019
7058
  for (const pkg of installed.values()) {