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.
- package/package.json +3 -4
- package/prebuilt/umo-editor/umo-editor.js +6882 -6742
- package/prebuilt/umo-editor/umo-editor.js.map +1 -1
- package/vite/nodeModulesResolve.ts +175 -0
- package/vite/tiptapUmoResolve.ts +13 -68
- package/vite/tiptapVueRendererFix.ts +5 -5
- package/vite/umoIntegration.js +167 -117
- package/vite/yjsPeerResolve.ts +19 -73
- package/vite.config.umo.ts +0 -1
package/vite/umoIntegration.js
CHANGED
|
@@ -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
|
|
27
|
-
if (!fs.existsSync(
|
|
28
|
-
const hlDir = fs.readdirSync(
|
|
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(
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
|
106
|
-
|
|
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 =
|
|
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(
|
|
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
|
|
174
|
-
if (!
|
|
175
|
-
const requireFromV3 =
|
|
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
|
|
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
|
|
300
|
+
import fs4 from "node:fs";
|
|
209
301
|
import path3 from "node:path";
|
|
210
|
-
import { createRequire as
|
|
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 (
|
|
356
|
+
if (fs4.existsSync(hoistedPkg)) {
|
|
265
357
|
try {
|
|
266
|
-
const resolved =
|
|
358
|
+
const resolved = createRequire3(hoistedPkg).resolve("@tiptap/vue-3");
|
|
267
359
|
const js = resolved.endsWith(".cjs") ? resolved.replace(/\.cjs$/, ".js") : resolved;
|
|
268
|
-
return
|
|
360
|
+
return fs4.existsSync(js) ? js : resolved;
|
|
269
361
|
} catch {
|
|
270
362
|
}
|
|
271
363
|
}
|
|
272
|
-
const
|
|
273
|
-
if (!
|
|
274
|
-
const pkgJson = path3.join(
|
|
275
|
-
if (!
|
|
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 =
|
|
369
|
+
const resolved = createRequire3(pkgJson).resolve("@tiptap/vue-3");
|
|
278
370
|
const js = resolved.endsWith(".cjs") ? resolved.replace(/\.cjs$/, ".js") : resolved;
|
|
279
|
-
return
|
|
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.
|
|
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(
|
|
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
|
-
|
|
334
|
-
|
|
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
|
|
431
|
+
import fs5 from "node:fs";
|
|
340
432
|
import path4 from "node:path";
|
|
341
|
-
import { createRequire as
|
|
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
|
|
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 (!
|
|
365
|
-
const pkgJson = JSON.parse(
|
|
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
|
|
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 (
|
|
374
|
-
const
|
|
375
|
-
if (!
|
|
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 =
|
|
469
|
+
const pkgDir = fs5.readdirSync(pnpmDir).find((name) => name.startsWith(`${pnpmPrefix}@`));
|
|
378
470
|
if (!pkgDir) return null;
|
|
379
|
-
const resolved = path4.join(
|
|
380
|
-
return
|
|
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 (
|
|
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
|
|
433
|
-
const esDir =
|
|
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(
|
|
436
|
-
if (
|
|
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(
|
|
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
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
|
617
|
+
return resolveFromHostOrCore(source);
|
|
568
618
|
}
|
|
569
619
|
};
|
|
570
620
|
}
|
package/vite/yjsPeerResolve.ts
CHANGED
|
@@ -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 {
|
|
6
|
-
|
|
7
|
-
/** prebuilt external 后,宿主须能解析 yjs 等 peer(pnpm
|
|
8
|
-
const UMO_PEER_PREFIXES = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
43
|
+
return resolveFromHostOrCore(source)
|
|
98
44
|
},
|
|
99
45
|
}
|
|
100
46
|
}
|