adtec-core-package 3.0.1 → 3.0.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.
@@ -23,11 +23,11 @@ function findHighlightJsRoot() {
23
23
  const projectRoot2 = getProjectRoot();
24
24
  const hoisted = path.join(projectRoot2, "node_modules/highlight.js");
25
25
  if (fs.existsSync(path.join(hoisted, "lib/core.js"))) return hoisted;
26
- const pnpmDir2 = path.join(projectRoot2, "node_modules/.pnpm");
27
- if (!fs.existsSync(pnpmDir2)) return null;
28
- const hlDir = fs.readdirSync(pnpmDir2).find((name) => name.startsWith("highlight.js@11."));
26
+ const pnpmDir = path.join(projectRoot2, "node_modules/.pnpm");
27
+ if (!fs.existsSync(pnpmDir)) return null;
28
+ const hlDir = fs.readdirSync(pnpmDir).find((name) => name.startsWith("highlight.js@11."));
29
29
  if (!hlDir) return null;
30
- const hlRoot = path.join(pnpmDir2, hlDir, "node_modules/highlight.js");
30
+ const hlRoot = path.join(pnpmDir, hlDir, "node_modules/highlight.js");
31
31
  return fs.existsSync(path.join(hlRoot, "lib/core.js")) ? hlRoot : null;
32
32
  }
33
33
  function isHighlightJsLibCore(source, importer) {
@@ -94,16 +94,65 @@ function highlightJsLibVirtual() {
94
94
  }
95
95
 
96
96
  // vite/tiptapUmoResolve.ts
97
+ import { createRequire as createRequire2 } from "node:module";
98
+ import fs3 from "node:fs";
99
+
100
+ // vite/nodeModulesResolve.ts
97
101
  import { createRequire } from "node:module";
98
102
  import fs2 from "node:fs";
99
103
  import path2 from "node:path";
100
- var AIEDITOR_MARKERS = ["aieditor", "@tiptap+core@2", "@tiptap+pm@2", "@tiptap+vue-3@2"];
101
- var OPTIMIZE_DEPS_EXCLUDE = ["@tiptap/core", "@tiptap/pm", "@tiptap/vue-3"];
102
- function pnpmDir() {
103
- return path2.join(getProjectRoot(), "node_modules/.pnpm");
104
+ function preferEsmEntry(resolved) {
105
+ if (resolved.endsWith(".cjs")) {
106
+ const js = resolved.replace(/\.cjs$/, ".js");
107
+ const mjs = resolved.replace(/\.cjs$/, ".mjs");
108
+ if (fs2.existsSync(mjs)) return mjs;
109
+ if (fs2.existsSync(js)) return js;
110
+ }
111
+ return resolved;
104
112
  }
105
- function findTiptapV3Root() {
106
- const dir = pnpmDir();
113
+ function readPkgVersion(pkgJsonPath) {
114
+ try {
115
+ const pkg = JSON.parse(fs2.readFileSync(pkgJsonPath, "utf-8"));
116
+ return pkg.version ?? null;
117
+ } catch {
118
+ return null;
119
+ }
120
+ }
121
+ function isTiptapV3(version) {
122
+ return version != null && version.startsWith("3.");
123
+ }
124
+ function findCorePackageRoot() {
125
+ const root = getProjectRoot();
126
+ const linked = path2.join(root, "node_modules/adtec-core-package");
127
+ if (fs2.existsSync(path2.join(linked, "package.json"))) {
128
+ try {
129
+ return fs2.realpathSync(linked);
130
+ } catch {
131
+ return linked;
132
+ }
133
+ }
134
+ const sibling = path2.join(root, "../\u524D\u7AEF\u6838\u5FC3\u5305");
135
+ if (fs2.existsSync(path2.join(sibling, "package.json"))) {
136
+ return sibling;
137
+ }
138
+ const selfPkg = path2.join(root, "package.json");
139
+ if (fs2.existsSync(selfPkg)) {
140
+ try {
141
+ const pkg = JSON.parse(fs2.readFileSync(selfPkg, "utf-8"));
142
+ if (pkg.name === "adtec-core-package") return root;
143
+ } catch {
144
+ }
145
+ }
146
+ return null;
147
+ }
148
+ function hostNodeModules() {
149
+ return path2.join(getProjectRoot(), "node_modules");
150
+ }
151
+ function pnpmStoreDir() {
152
+ return path2.join(hostNodeModules(), ".pnpm");
153
+ }
154
+ function findTiptapV3RootFromPnpm() {
155
+ const dir = pnpmStoreDir();
107
156
  if (!fs2.existsSync(dir)) return null;
108
157
  const entries = fs2.readdirSync(dir);
109
158
  const coreDir = entries.find(
@@ -114,8 +163,31 @@ function findTiptapV3Root() {
114
163
  if (!fs2.existsSync(path2.join(tiptapRoot, "@tiptap/core/package.json"))) return null;
115
164
  return tiptapRoot;
116
165
  }
166
+ function findTiptapV3RootFromHoisted(baseNodeModules) {
167
+ const corePkg = path2.join(baseNodeModules, "@tiptap/core/package.json");
168
+ if (!fs2.existsSync(corePkg) || !isTiptapV3(readPkgVersion(corePkg))) return null;
169
+ return baseNodeModules;
170
+ }
171
+ function findTiptapV3Root() {
172
+ const fromPnpm = findTiptapV3RootFromPnpm();
173
+ if (fromPnpm) return fromPnpm;
174
+ const fromHost = findTiptapV3RootFromHoisted(hostNodeModules());
175
+ if (fromHost) return fromHost;
176
+ const coreRoot = findCorePackageRoot();
177
+ if (coreRoot) {
178
+ const fromCore = findTiptapV3RootFromHoisted(path2.join(coreRoot, "node_modules"));
179
+ if (fromCore) return fromCore;
180
+ }
181
+ return null;
182
+ }
183
+ function findTiptapCorePkgJson() {
184
+ const tiptapRoot = findTiptapV3Root();
185
+ if (!tiptapRoot) return null;
186
+ const corePkg = path2.join(tiptapRoot, "@tiptap/core/package.json");
187
+ return fs2.existsSync(corePkg) ? corePkg : null;
188
+ }
117
189
  function findTiptapPmPackageJson() {
118
- const dir = pnpmDir();
190
+ const dir = pnpmStoreDir();
119
191
  const exact = path2.join(dir, "@tiptap+pm@3.20.0", "node_modules", "@tiptap/pm", "package.json");
120
192
  if (fs2.existsSync(exact)) return exact;
121
193
  if (fs2.existsSync(dir)) {
@@ -128,17 +200,10 @@ function findTiptapPmPackageJson() {
128
200
  const tiptapRoot = findTiptapV3Root();
129
201
  if (tiptapRoot) {
130
202
  const inTree = path2.join(tiptapRoot, "@tiptap/pm/package.json");
131
- if (fs2.existsSync(inTree)) return inTree;
203
+ if (fs2.existsSync(inTree) && isTiptapV3(readPkgVersion(inTree))) return inTree;
132
204
  }
133
205
  return null;
134
206
  }
135
- function preferEsmEntry(resolved) {
136
- if (resolved.endsWith(".cjs")) {
137
- const js = resolved.replace(/\.cjs$/, ".js");
138
- if (fs2.existsSync(js)) return js;
139
- }
140
- return resolved;
141
- }
142
207
  function resolveFromContext(source, contextPkgJson) {
143
208
  try {
144
209
  return preferEsmEntry(createRequire(contextPkgJson).resolve(source));
@@ -146,6 +211,35 @@ function resolveFromContext(source, contextPkgJson) {
146
211
  return null;
147
212
  }
148
213
  }
214
+ function resolveFromHostOrCore(source) {
215
+ const root = getProjectRoot();
216
+ const hostPkg = path2.join(root, "package.json");
217
+ if (fs2.existsSync(hostPkg)) {
218
+ const resolved = resolveFromContext(source, hostPkg);
219
+ if (resolved) return resolved;
220
+ }
221
+ const coreRoot = findCorePackageRoot();
222
+ if (coreRoot) {
223
+ const corePkg = path2.join(coreRoot, "package.json");
224
+ const resolved = resolveFromContext(source, corePkg);
225
+ if (resolved) return resolved;
226
+ }
227
+ return null;
228
+ }
229
+ function buildPeerAliases(packages) {
230
+ const aliases = [];
231
+ for (const pkg of packages) {
232
+ const resolved = resolveFromHostOrCore(pkg);
233
+ if (resolved) {
234
+ aliases.push({ find: pkg, replacement: resolved });
235
+ }
236
+ }
237
+ return aliases;
238
+ }
239
+
240
+ // vite/tiptapUmoResolve.ts
241
+ var AIEDITOR_MARKERS = ["aieditor", "@tiptap+core@2", "@tiptap+pm@2", "@tiptap+vue-3@2"];
242
+ var OPTIMIZE_DEPS_EXCLUDE = ["@tiptap/core", "@tiptap/pm", "@tiptap/vue-3"];
149
243
  function buildVue3Aliases(requireFromV3) {
150
244
  const aliases = [];
151
245
  try {
@@ -158,7 +252,7 @@ function buildVue3Aliases(requireFromV3) {
158
252
  function buildProsemirrorAliases() {
159
253
  const pmPkgJson = findTiptapPmPackageJson();
160
254
  if (!pmPkgJson) return [];
161
- const pkg = JSON.parse(fs2.readFileSync(pmPkgJson, "utf-8"));
255
+ const pkg = JSON.parse(fs3.readFileSync(pmPkgJson, "utf-8"));
162
256
  const aliases = [];
163
257
  for (const dep of Object.keys(pkg.dependencies ?? {})) {
164
258
  if (!dep.startsWith("prosemirror-")) continue;
@@ -170,10 +264,9 @@ function buildProsemirrorAliases() {
170
264
  return aliases;
171
265
  }
172
266
  function buildTiptapV3Aliases() {
173
- const tiptapV3Root = findTiptapV3Root();
174
- if (!tiptapV3Root) return buildProsemirrorAliases();
175
- const requireFromV3 = createRequire(path2.join(tiptapV3Root, "@tiptap/core/package.json"));
176
- void requireFromV3;
267
+ const corePkgJson = findTiptapCorePkgJson();
268
+ if (!corePkgJson) return buildProsemirrorAliases();
269
+ const requireFromV3 = createRequire2(corePkgJson);
177
270
  return [...buildProsemirrorAliases(), ...buildVue3Aliases(requireFromV3)];
178
271
  }
179
272
  function tiptapUmoResolve() {
@@ -190,8 +283,7 @@ function tiptapUmoResolve() {
190
283
  resolveId(source, importer) {
191
284
  if (importer && AIEDITOR_MARKERS.some((marker) => importer.includes(marker))) return null;
192
285
  if (source === "@tiptap/vue-3") return null;
193
- const tiptapV3Root = findTiptapV3Root();
194
- const corePkgJson = tiptapV3Root ? path2.join(tiptapV3Root, "@tiptap/core/package.json") : null;
286
+ const corePkgJson = findTiptapCorePkgJson();
195
287
  const pmPkgJson = findTiptapPmPackageJson();
196
288
  if (corePkgJson && source.startsWith("@tiptap/")) {
197
289
  return resolveFromContext(source, corePkgJson);
@@ -205,9 +297,9 @@ function tiptapUmoResolve() {
205
297
  }
206
298
 
207
299
  // vite/tiptapVueRendererFix.ts
208
- import fs3 from "node:fs";
300
+ import fs4 from "node:fs";
209
301
  import path3 from "node:path";
210
- import { createRequire as createRequire2 } from "node:module";
302
+ import { createRequire as createRequire3 } from "node:module";
211
303
  var VIRTUAL_TIPTAP_VUE3 = "\0virtual:patched-tiptap-vue-3";
212
304
  var RAW_PROP_KEYS = [
213
305
  "editor",
@@ -261,22 +353,22 @@ function patchTiptapVueRendererCode(code) {
261
353
  function findCanonicalTiptapVue3Entry() {
262
354
  const projectRoot2 = getProjectRoot();
263
355
  const hoistedPkg = path3.join(projectRoot2, "node_modules/@tiptap/vue-3/package.json");
264
- if (fs3.existsSync(hoistedPkg)) {
356
+ if (fs4.existsSync(hoistedPkg)) {
265
357
  try {
266
- const resolved = createRequire2(hoistedPkg).resolve("@tiptap/vue-3");
358
+ const resolved = createRequire3(hoistedPkg).resolve("@tiptap/vue-3");
267
359
  const js = resolved.endsWith(".cjs") ? resolved.replace(/\.cjs$/, ".js") : resolved;
268
- return fs3.existsSync(js) ? js : resolved;
360
+ return fs4.existsSync(js) ? js : resolved;
269
361
  } catch {
270
362
  }
271
363
  }
272
- const tiptapRoot = findTiptapV3Root();
273
- if (!tiptapRoot) return null;
274
- const pkgJson = path3.join(tiptapRoot, "@tiptap/vue-3/package.json");
275
- if (!fs3.existsSync(pkgJson)) return null;
364
+ const corePkgJson = findTiptapCorePkgJson();
365
+ if (!corePkgJson) return null;
366
+ const pkgJson = path3.join(path3.dirname(path3.dirname(corePkgJson)), "@tiptap/vue-3/package.json");
367
+ if (!fs4.existsSync(pkgJson)) return null;
276
368
  try {
277
- const resolved = createRequire2(pkgJson).resolve("@tiptap/vue-3");
369
+ const resolved = createRequire3(pkgJson).resolve("@tiptap/vue-3");
278
370
  const js = resolved.endsWith(".cjs") ? resolved.replace(/\.cjs$/, ".js") : resolved;
279
- return fs3.existsSync(js) ? js : resolved;
371
+ return fs4.existsSync(js) ? js : resolved;
280
372
  } catch {
281
373
  return null;
282
374
  }
@@ -286,9 +378,9 @@ function loadPatchedTiptapVue3Code() {
286
378
  if (cachedPatchedCode) return cachedPatchedCode;
287
379
  const entry = findCanonicalTiptapVue3Entry();
288
380
  if (!entry) {
289
- throw new Error("[tiptap-vue-renderer-fix] \u672A\u627E\u5230 @tiptap/vue-3@3.20\uFF0C\u8BF7\u5148 pnpm install");
381
+ throw new Error("[tiptap-vue-renderer-fix] \u672A\u627E\u5230 @tiptap/vue-3@3.x\uFF0C\u8BF7\u5148 npm/pnpm install");
290
382
  }
291
- const patched = patchTiptapVueRendererCode(fs3.readFileSync(entry, "utf-8"));
383
+ const patched = patchTiptapVueRendererCode(fs4.readFileSync(entry, "utf-8"));
292
384
  if (patched.includes(REACTIVE_PROPS_BUG)) {
293
385
  throw new Error(`[tiptap-vue-renderer-fix] patch \u5931\u8D25: ${entry}`);
294
386
  }
@@ -330,15 +422,15 @@ function tiptapVueRendererFix() {
330
422
  }
331
423
  function writePatchedTiptapVue3ToDisk(targetPath) {
332
424
  const out = targetPath ?? path3.join(getProjectRoot(), "node_modules/.cache/patched-tiptap-vue-3-index.js");
333
- fs3.mkdirSync(path3.dirname(out), { recursive: true });
334
- fs3.writeFileSync(out, loadPatchedTiptapVue3Code(), "utf-8");
425
+ fs4.mkdirSync(path3.dirname(out), { recursive: true });
426
+ fs4.writeFileSync(out, loadPatchedTiptapVue3Code(), "utf-8");
335
427
  return out;
336
428
  }
337
429
 
338
430
  // vite/umoCjsVirtual.ts
339
- import fs4 from "node:fs";
431
+ import fs5 from "node:fs";
340
432
  import path4 from "node:path";
341
- import { createRequire as createRequire3 } from "node:module";
433
+ import { createRequire as createRequire4 } from "node:module";
342
434
  import { pathToFileURL } from "node:url";
343
435
  import { transformWithEsbuild as transformWithEsbuild2 } from "vite";
344
436
  var UMO_CJS_SPECS = [
@@ -357,27 +449,27 @@ var UMO_CJS_NAMED_EXPORTS = {
357
449
  };
358
450
  var VIRTUAL_UMO_CJS_PREFIX = "\0virtual:umo-cjs:";
359
451
  function requireFromProjectRoot() {
360
- return createRequire3(path4.join(getProjectRoot(), "package.json"));
452
+ return createRequire4(path4.join(getProjectRoot(), "package.json"));
361
453
  }
362
454
  function resolvePackageMain(pkgDir) {
363
455
  const pkgJsonPath = path4.join(pkgDir, "package.json");
364
- if (!fs4.existsSync(pkgJsonPath)) return null;
365
- const pkgJson = JSON.parse(fs4.readFileSync(pkgJsonPath, "utf-8"));
456
+ if (!fs5.existsSync(pkgJsonPath)) return null;
457
+ const pkgJson = JSON.parse(fs5.readFileSync(pkgJsonPath, "utf-8"));
366
458
  const main = pkgJson.module || pkgJson.main || "index.js";
367
459
  const entry = path4.join(pkgDir, main);
368
- return fs4.existsSync(entry) ? entry : null;
460
+ return fs5.existsSync(entry) ? entry : null;
369
461
  }
370
462
  function findUmoPackageDir(pkgName) {
371
463
  const projectRoot2 = getProjectRoot();
372
464
  const hoisted = path4.join(projectRoot2, "node_modules", pkgName);
373
- if (fs4.existsSync(path4.join(hoisted, "package.json"))) return hoisted;
374
- const pnpmDir2 = path4.join(projectRoot2, "node_modules/.pnpm");
375
- if (!fs4.existsSync(pnpmDir2)) return null;
465
+ if (fs5.existsSync(path4.join(hoisted, "package.json"))) return hoisted;
466
+ const pnpmDir = path4.join(projectRoot2, "node_modules/.pnpm");
467
+ if (!fs5.existsSync(pnpmDir)) return null;
376
468
  const pnpmPrefix = pkgName.replace("/", "+");
377
- const pkgDir = fs4.readdirSync(pnpmDir2).find((name) => name.startsWith(`${pnpmPrefix}@`));
469
+ const pkgDir = fs5.readdirSync(pnpmDir).find((name) => name.startsWith(`${pnpmPrefix}@`));
378
470
  if (!pkgDir) return null;
379
- const resolved = path4.join(pnpmDir2, pkgDir, "node_modules", pkgName);
380
- return fs4.existsSync(path4.join(resolved, "package.json")) ? resolved : null;
471
+ const resolved = path4.join(pnpmDir, pkgDir, "node_modules", pkgName);
472
+ return fs5.existsSync(path4.join(resolved, "package.json")) ? resolved : null;
381
473
  }
382
474
  function findUmoPackageEntryForSpec(spec) {
383
475
  const [pkgName, ...subParts] = spec.split("/");
@@ -393,7 +485,7 @@ function findUmoPackageEntryForSpec(spec) {
393
485
  path4.join(pkgDir, sub)
394
486
  ];
395
487
  for (const candidate of candidates) {
396
- if (fs4.existsSync(candidate) && fs4.statSync(candidate).isFile()) return candidate;
488
+ if (fs5.existsSync(candidate) && fs5.statSync(candidate).isFile()) return candidate;
397
489
  }
398
490
  return null;
399
491
  }
@@ -429,11 +521,11 @@ async function getEsbuild() {
429
521
  return cachedEsbuild;
430
522
  } catch {
431
523
  }
432
- const pnpmDir2 = path4.join(getProjectRoot(), "node_modules/.pnpm");
433
- const esDir = fs4.existsSync(pnpmDir2) ? fs4.readdirSync(pnpmDir2).find((name) => name.startsWith("esbuild@")) : void 0;
524
+ const pnpmDir = path4.join(getProjectRoot(), "node_modules/.pnpm");
525
+ const esDir = fs5.existsSync(pnpmDir) ? fs5.readdirSync(pnpmDir).find((name) => name.startsWith("esbuild@")) : void 0;
434
526
  if (esDir) {
435
- const esMain = path4.join(pnpmDir2, esDir, "node_modules/esbuild/lib/main.js");
436
- if (fs4.existsSync(esMain)) {
527
+ const esMain = path4.join(pnpmDir, esDir, "node_modules/esbuild/lib/main.js");
528
+ if (fs5.existsSync(esMain)) {
437
529
  const mod = await import(pathToFileURL(esMain).href);
438
530
  cachedEsbuild = mod.default ?? mod;
439
531
  return cachedEsbuild;
@@ -453,7 +545,7 @@ async function bundleUmoCjsToEsm(entry) {
453
545
  });
454
546
  const code = result.outputFiles[0]?.text ?? "";
455
547
  if (code) return code;
456
- const fallback = await transformWithEsbuild2(fs4.readFileSync(entry, "utf-8"), entry, {
548
+ const fallback = await transformWithEsbuild2(fs5.readFileSync(entry, "utf-8"), entry, {
457
549
  loader: "js",
458
550
  format: "esm",
459
551
  platform: "browser"
@@ -487,69 +579,27 @@ function umoCjsVirtual() {
487
579
  }
488
580
 
489
581
  // vite/yjsPeerResolve.ts
490
- import { createRequire as createRequire4 } from "node:module";
491
- import fs5 from "node:fs";
492
- import path5 from "node:path";
493
- var UMO_PEER_PREFIXES = ["yjs", "y-protocols", "y-prosemirror", "lib0/", "@tiptap/y-tiptap", "@tiptap/extension-collaboration"];
494
- function preferEsmEntry2(resolved) {
495
- if (resolved.endsWith(".cjs")) {
496
- const js = resolved.replace(/\.cjs$/, ".js");
497
- const mjs = resolved.replace(/\.cjs$/, ".mjs");
498
- if (fs5.existsSync(mjs)) return mjs;
499
- if (fs5.existsSync(js)) return js;
500
- }
501
- return resolved;
502
- }
582
+ var UMO_PEER_PREFIXES = [
583
+ "yjs",
584
+ "y-protocols",
585
+ "y-prosemirror",
586
+ "lib0/",
587
+ "@tiptap/y-tiptap",
588
+ "@tiptap/extension-collaboration"
589
+ ];
503
590
  function isUmoPeerImport(source) {
504
591
  return UMO_PEER_PREFIXES.some(
505
592
  (prefix) => source === prefix.replace(/\/$/, "") || source.startsWith(prefix)
506
593
  );
507
594
  }
508
- function findCorePackageRoot() {
509
- const root = getProjectRoot();
510
- const linked = path5.join(root, "node_modules/adtec-core-package");
511
- if (fs5.existsSync(path5.join(linked, "package.json"))) {
512
- try {
513
- return fs5.realpathSync(linked);
514
- } catch {
515
- return linked;
516
- }
517
- }
518
- const sibling = path5.join(root, "../\u524D\u7AEF\u6838\u5FC3\u5305");
519
- if (fs5.existsSync(path5.join(sibling, "package.json"))) {
520
- return sibling;
521
- }
522
- const selfPkg = path5.join(root, "package.json");
523
- if (fs5.existsSync(selfPkg)) {
524
- try {
525
- const pkg = JSON.parse(fs5.readFileSync(selfPkg, "utf-8"));
526
- if (pkg.name === "adtec-core-package") return root;
527
- } catch {
528
- }
529
- }
530
- return null;
531
- }
532
- function resolvePeerFromCore(source) {
533
- const coreRoot = findCorePackageRoot();
534
- if (!coreRoot) return null;
535
- const pkgJson = path5.join(coreRoot, "package.json");
536
- if (!fs5.existsSync(pkgJson)) return null;
537
- try {
538
- return preferEsmEntry2(createRequire4(pkgJson).resolve(source));
539
- } catch {
540
- return null;
541
- }
542
- }
543
595
  function buildYjsPeerAliases() {
544
- const roots = ["yjs", "y-protocols", "y-prosemirror", "@tiptap/y-tiptap", "@tiptap/extension-collaboration"];
545
- const aliases = [];
546
- for (const pkg of roots) {
547
- const resolved = resolvePeerFromCore(pkg);
548
- if (resolved) {
549
- aliases.push({ find: pkg, replacement: resolved });
550
- }
551
- }
552
- return aliases;
596
+ return buildPeerAliases([
597
+ "yjs",
598
+ "y-protocols",
599
+ "y-prosemirror",
600
+ "@tiptap/y-tiptap",
601
+ "@tiptap/extension-collaboration"
602
+ ]);
553
603
  }
554
604
  function yjsPeerResolve() {
555
605
  return {
@@ -564,7 +614,7 @@ function yjsPeerResolve() {
564
614
  },
565
615
  resolveId(source) {
566
616
  if (!isUmoPeerImport(source)) return null;
567
- return resolvePeerFromCore(source);
617
+ return resolveFromHostOrCore(source);
568
618
  }
569
619
  };
570
620
  }
@@ -1,21 +1,15 @@
1
- import { createRequire } from 'node:module'
2
- import fs from 'node:fs'
3
- import path from 'node:path'
4
1
  import type { Alias, Plugin } from 'vite'
5
- import { getProjectRoot } from './projectRoot'
6
-
7
- /** prebuilt external 后,宿主须能解析 yjs 等 peer(pnpm 常未 hoist 到根 node_modules) */
8
- const UMO_PEER_PREFIXES = ['yjs', 'y-protocols', 'y-prosemirror', 'lib0/', '@tiptap/y-tiptap', '@tiptap/extension-collaboration']
9
-
10
- function preferEsmEntry(resolved: string): string {
11
- if (resolved.endsWith('.cjs')) {
12
- const js = resolved.replace(/\.cjs$/, '.js')
13
- const mjs = resolved.replace(/\.cjs$/, '.mjs')
14
- if (fs.existsSync(mjs)) return mjs
15
- if (fs.existsSync(js)) return js
16
- }
17
- return resolved
18
- }
2
+ import { buildPeerAliases, resolveFromHostOrCore } from './nodeModulesResolve'
3
+
4
+ /** prebuilt external 后,宿主须能解析 yjs 等 peer(npm / pnpm 均可能未 hoist 到根 node_modules) */
5
+ const UMO_PEER_PREFIXES = [
6
+ 'yjs',
7
+ 'y-protocols',
8
+ 'y-prosemirror',
9
+ 'lib0/',
10
+ '@tiptap/y-tiptap',
11
+ '@tiptap/extension-collaboration',
12
+ ]
19
13
 
20
14
  function isUmoPeerImport(source: string): boolean {
21
15
  return UMO_PEER_PREFIXES.some(
@@ -23,62 +17,14 @@ function isUmoPeerImport(source: string): boolean {
23
17
  )
24
18
  }
25
19
 
26
- /** 宿主 node_modules/adtec-core-package(pnpm file: 链接真实路径) */
27
- export function findCorePackageRoot(): string | null {
28
- const root = getProjectRoot()
29
- const linked = path.join(root, 'node_modules/adtec-core-package')
30
- if (fs.existsSync(path.join(linked, 'package.json'))) {
31
- try {
32
- return fs.realpathSync(linked)
33
- } catch {
34
- return linked
35
- }
36
- }
37
-
38
- const sibling = path.join(root, '../前端核心包')
39
- if (fs.existsSync(path.join(sibling, 'package.json'))) {
40
- return sibling
41
- }
42
-
43
- const selfPkg = path.join(root, 'package.json')
44
- if (fs.existsSync(selfPkg)) {
45
- try {
46
- const pkg = JSON.parse(fs.readFileSync(selfPkg, 'utf-8')) as { name?: string }
47
- if (pkg.name === 'adtec-core-package') return root
48
- } catch {
49
- // ignore
50
- }
51
- }
52
-
53
- return null
54
- }
55
-
56
- function resolvePeerFromCore(source: string): string | null {
57
- const coreRoot = findCorePackageRoot()
58
- if (!coreRoot) return null
59
-
60
- const pkgJson = path.join(coreRoot, 'package.json')
61
- if (!fs.existsSync(pkgJson)) return null
62
-
63
- try {
64
- return preferEsmEntry(createRequire(pkgJson).resolve(source))
65
- } catch {
66
- return null
67
- }
68
- }
69
-
70
20
  export function buildYjsPeerAliases(): Alias[] {
71
- const roots = ['yjs', 'y-protocols', 'y-prosemirror', '@tiptap/y-tiptap', '@tiptap/extension-collaboration']
72
- const aliases: Alias[] = []
73
-
74
- for (const pkg of roots) {
75
- const resolved = resolvePeerFromCore(pkg)
76
- if (resolved) {
77
- aliases.push({ find: pkg, replacement: resolved })
78
- }
79
- }
80
-
81
- return aliases
21
+ return buildPeerAliases([
22
+ 'yjs',
23
+ 'y-protocols',
24
+ 'y-prosemirror',
25
+ '@tiptap/y-tiptap',
26
+ '@tiptap/extension-collaboration',
27
+ ])
82
28
  }
83
29
 
84
30
  export function yjsPeerResolve(): Plugin {
@@ -94,7 +40,7 @@ export function yjsPeerResolve(): Plugin {
94
40
  },
95
41
  resolveId(source) {
96
42
  if (!isUmoPeerImport(source)) return null
97
- return resolvePeerFromCore(source)
43
+ return resolveFromHostOrCore(source)
98
44
  },
99
45
  }
100
46
  }
@@ -20,7 +20,6 @@ const UMO_PEER_EXTERNAL = [
20
20
  'y-protocols',
21
21
  'y-prosemirror',
22
22
  '@tiptap/y-tiptap',
23
- '@tiptap/extension-collaboration',
24
23
  ]
25
24
 
26
25
  function isUmoPeerExternal(id: string) {