@fulgurjs/federation 6.14.2 → 6.14.4
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/CHANGELOG.md +10 -0
- package/dist/cli.js +294 -130
- package/dist/index.cjs +288 -126
- package/dist/index.js +288 -126
- package/dist/runtime.js +1 -1
- package/docs/en/reference/api.md +4 -0
- package/docs/zh/reference/api.md +4 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1380,17 +1380,17 @@ function validateHostPages(value) {
|
|
|
1380
1380
|
}
|
|
1381
1381
|
return hp;
|
|
1382
1382
|
}
|
|
1383
|
-
function validatePathsInsideApp(options, appRoot, fs12,
|
|
1383
|
+
function validatePathsInsideApp(options, appRoot, fs12, path13) {
|
|
1384
1384
|
const checkModule = (field, value) => {
|
|
1385
1385
|
if (typeof value !== "string" || value.trim() === "") return;
|
|
1386
|
-
if (/^(https?:)?\/\//.test(value) ||
|
|
1386
|
+
if (/^(https?:)?\/\//.test(value) || path13.isAbsolute(value)) {
|
|
1387
1387
|
appConfigError(
|
|
1388
1388
|
`${field} "${value}" \u4E0D\u662F\u672C\u9879\u76EE\u5185\u7684\u6A21\u5757\u8DEF\u5F84`,
|
|
1389
1389
|
"exposes/setup \u7684\u503C\u662F\u76F8\u5BF9\u672C\u5E94\u7528\u6839\u76EE\u5F55\u7684\u6E90\u6587\u4EF6\u8DEF\u5F84\uFF08URL/\u7EDD\u5BF9\u8DEF\u5F84\u65E0\u6CD5\u5728\u72EC\u7ACB\u4ED3\u5E93\u95F4\u79FB\u690D\uFF09",
|
|
1390
1390
|
`\u6539\u4E3A\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u5982 './src/views/Home.vue'\uFF08\u914D\u7F6E\u6587\u4EF6\u76EE\u5F55 = \u5E94\u7528\u6839 ${appRoot}\uFF09`
|
|
1391
1391
|
);
|
|
1392
1392
|
}
|
|
1393
|
-
const abs =
|
|
1393
|
+
const abs = path13.resolve(appRoot, value);
|
|
1394
1394
|
if (!fs12.existsSync(abs)) {
|
|
1395
1395
|
appConfigError(
|
|
1396
1396
|
`${field} \u6307\u5411\u7684\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${value}`,
|
|
@@ -1462,8 +1462,8 @@ function resolveEsbuild(configPath) {
|
|
|
1462
1462
|
async function loadAppConfig(configPath) {
|
|
1463
1463
|
const fs12 = await import("node:fs");
|
|
1464
1464
|
const os = await import("node:os");
|
|
1465
|
-
const
|
|
1466
|
-
const abs =
|
|
1465
|
+
const path13 = await import("node:path");
|
|
1466
|
+
const abs = path13.resolve(configPath);
|
|
1467
1467
|
if (!fs12.existsSync(abs)) {
|
|
1468
1468
|
appConfigError(
|
|
1469
1469
|
`\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${abs}`,
|
|
@@ -1474,7 +1474,7 @@ async function loadAppConfig(configPath) {
|
|
|
1474
1474
|
if (abs.endsWith(".json")) {
|
|
1475
1475
|
const parsed = JSON.parse(fs12.readFileSync(abs, "utf8"));
|
|
1476
1476
|
if (isAggregateShape(parsed)) aggregateMigrationError();
|
|
1477
|
-
return finishAppShape(parsed, {}, abs,
|
|
1477
|
+
return finishAppShape(parsed, {}, abs, path13.dirname(abs), fs12, path13);
|
|
1478
1478
|
}
|
|
1479
1479
|
const rawSource = fs12.readFileSync(abs, "utf8");
|
|
1480
1480
|
if (/@fulgurjs\/federation\/config/.test(rawSource)) {
|
|
@@ -1507,21 +1507,21 @@ async function loadAppConfig(configPath) {
|
|
|
1507
1507
|
plugins: [selfRedirect],
|
|
1508
1508
|
logLevel: "silent"
|
|
1509
1509
|
});
|
|
1510
|
-
const tmpDir = fs12.mkdtempSync(
|
|
1510
|
+
const tmpDir = fs12.mkdtempSync(path13.join(os.tmpdir(), "fulgurjs-appcfg-"));
|
|
1511
1511
|
try {
|
|
1512
|
-
const bundleFile =
|
|
1512
|
+
const bundleFile = path13.join(tmpDir, "fulgurjs.config.bundle.mjs");
|
|
1513
1513
|
fs12.writeFileSync(bundleFile, out.outputFiles[0].text);
|
|
1514
1514
|
const mod = await import(
|
|
1515
1515
|
/* @vite-ignore */
|
|
1516
1516
|
`${pathToFileURL(bundleFile).href}?t=${Date.now()}`
|
|
1517
1517
|
);
|
|
1518
1518
|
if (isAggregateShape(mod.default)) aggregateMigrationError();
|
|
1519
|
-
return finishAppShape(mod.default, { hostPages: mod.hostPages }, abs,
|
|
1519
|
+
return finishAppShape(mod.default, { hostPages: mod.hostPages }, abs, path13.dirname(abs), fs12, path13);
|
|
1520
1520
|
} finally {
|
|
1521
1521
|
fs12.rmSync(tmpDir, { recursive: true, force: true });
|
|
1522
1522
|
}
|
|
1523
1523
|
}
|
|
1524
|
-
function finishAppShape(def, named, configPath, appRoot, fs12,
|
|
1524
|
+
function finishAppShape(def, named, configPath, appRoot, fs12, path13) {
|
|
1525
1525
|
if (def === void 0 || def === null) {
|
|
1526
1526
|
appConfigError(
|
|
1527
1527
|
"fulgurjs.config.ts \u6CA1\u6709\u53EF\u7528\u7684\u9ED8\u8BA4\u5BFC\u51FA",
|
|
@@ -1534,7 +1534,7 @@ function finishAppShape(def, named, configPath, appRoot, fs12, path12) {
|
|
|
1534
1534
|
}
|
|
1535
1535
|
const options = def;
|
|
1536
1536
|
validateAppOptions(options);
|
|
1537
|
-
validatePathsInsideApp(options, appRoot, fs12,
|
|
1537
|
+
validatePathsInsideApp(options, appRoot, fs12, path13);
|
|
1538
1538
|
const hostPages = named.hostPages !== void 0 ? validateHostPages(named.hostPages) : void 0;
|
|
1539
1539
|
return {
|
|
1540
1540
|
kind: "app",
|
|
@@ -3187,7 +3187,7 @@ var RUNTIME_VERSION;
|
|
|
3187
3187
|
var init_version = __esm({
|
|
3188
3188
|
"src/version.ts"() {
|
|
3189
3189
|
"use strict";
|
|
3190
|
-
RUNTIME_VERSION = "6.14.
|
|
3190
|
+
RUNTIME_VERSION = "6.14.4";
|
|
3191
3191
|
}
|
|
3192
3192
|
});
|
|
3193
3193
|
|
|
@@ -3892,14 +3892,171 @@ var init_dts_vue_display = __esm({
|
|
|
3892
3892
|
}
|
|
3893
3893
|
});
|
|
3894
3894
|
|
|
3895
|
+
// src/dts-type-display.ts
|
|
3896
|
+
import path6 from "node:path";
|
|
3897
|
+
function displayPublicDataTypes(ts, files, entries, root, compilerOptions = {}) {
|
|
3898
|
+
const base = path6.join(root, ".fulgurjs-types-display");
|
|
3899
|
+
const paths = new Map([...files].map(([rel, text]) => [path6.resolve(base, rel), text]));
|
|
3900
|
+
const entryPaths = [...new Set(entries)].map((rel) => path6.resolve(base, rel));
|
|
3901
|
+
const needsDisplay = entryPaths.filter((file) => {
|
|
3902
|
+
const source = ts.createSourceFile(file, paths.get(file), ts.ScriptTarget.Latest, true);
|
|
3903
|
+
return source.statements.some((s) => ts.isExportDeclaration(s) && (!s.exportClause || ts.isNamedExports(s.exportClause) && s.exportClause.elements.length > 0) || (ts.isInterfaceDeclaration(s) || ts.isTypeAliasDeclaration(s)) && s.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword));
|
|
3904
|
+
});
|
|
3905
|
+
if (needsDisplay.length === 0) return;
|
|
3906
|
+
const options = {
|
|
3907
|
+
...compilerOptions,
|
|
3908
|
+
noEmit: true,
|
|
3909
|
+
target: compilerOptions.target ?? ts.ScriptTarget.ESNext,
|
|
3910
|
+
module: compilerOptions.module ?? ts.ModuleKind.ESNext,
|
|
3911
|
+
moduleResolution: compilerOptions.moduleResolution ?? ts.ModuleResolutionKind.Bundler ?? ts.ModuleResolutionKind.NodeJs,
|
|
3912
|
+
skipLibCheck: true,
|
|
3913
|
+
types: [],
|
|
3914
|
+
allowArbitraryExtensions: true
|
|
3915
|
+
};
|
|
3916
|
+
const directories = /* @__PURE__ */ new Set();
|
|
3917
|
+
for (const file of paths.keys()) {
|
|
3918
|
+
for (let dir = path6.dirname(file); dir.startsWith(base); dir = path6.dirname(dir)) directories.add(dir);
|
|
3919
|
+
}
|
|
3920
|
+
const host = ts.createCompilerHost(options, true);
|
|
3921
|
+
const readFile = (file) => paths.get(path6.resolve(file)) ?? ts.sys.readFile(file);
|
|
3922
|
+
host.readFile = readFile;
|
|
3923
|
+
host.fileExists = (file) => paths.has(path6.resolve(file)) || ts.sys.fileExists(file);
|
|
3924
|
+
host.directoryExists = (dir) => directories.has(path6.resolve(dir)) || (ts.sys.directoryExists?.(dir) ?? false);
|
|
3925
|
+
host.realpath = (file) => paths.has(path6.resolve(file)) ? file : ts.sys.realpath?.(file) ?? file;
|
|
3926
|
+
host.getCurrentDirectory = () => root;
|
|
3927
|
+
host.getSourceFile = (file, languageVersion) => {
|
|
3928
|
+
const text = readFile(file);
|
|
3929
|
+
return text === void 0 ? void 0 : ts.createSourceFile(file, text, languageVersion, true);
|
|
3930
|
+
};
|
|
3931
|
+
const program = ts.createProgram(needsDisplay, options, host);
|
|
3932
|
+
const checker = program.getTypeChecker();
|
|
3933
|
+
const plainData = (symbol) => {
|
|
3934
|
+
if (!(symbol.flags & (ts.SymbolFlags.Interface | ts.SymbolFlags.TypeAlias)) || symbol.flags & (ts.SymbolFlags.Value | ts.SymbolFlags.Namespace)) return false;
|
|
3935
|
+
if (symbol.declarations?.some((d) => (ts.isInterfaceDeclaration(d) || ts.isTypeAliasDeclaration(d)) && d.typeParameters?.length)) return false;
|
|
3936
|
+
const type = checker.getDeclaredTypeOfSymbol(symbol);
|
|
3937
|
+
if (!(type.flags & ts.TypeFlags.Object) || type.getCallSignatures().length || type.getConstructSignatures().length || checker.isArrayType(type) || checker.isTupleType(type)) return false;
|
|
3938
|
+
const hasThis = (node) => ts.isThisTypeNode(node) || (ts.forEachChild(node, hasThis) ?? false);
|
|
3939
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3940
|
+
const specialBase = (value) => {
|
|
3941
|
+
if (visited.has(value)) return false;
|
|
3942
|
+
visited.add(value);
|
|
3943
|
+
if (!(value.flags & ts.TypeFlags.Object)) return true;
|
|
3944
|
+
const object = value;
|
|
3945
|
+
const target = object.target ?? object;
|
|
3946
|
+
if ((object.objectFlags | target.objectFlags) & ts.ObjectFlags.Class) return true;
|
|
3947
|
+
if (value.symbol?.declarations?.some(hasThis)) return true;
|
|
3948
|
+
if (value.symbol?.declarations?.some((d) => ts.isInterfaceDeclaration(d) && d.heritageClauses?.some((clause) => clause.types.some((base2) => checker.getTypeAtLocation(base2).flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.TypeParameter))))) return true;
|
|
3949
|
+
return !!(object.objectFlags & ts.ObjectFlags.Interface && checker.getBaseTypes(object)?.some(specialBase));
|
|
3950
|
+
};
|
|
3951
|
+
if (specialBase(type)) return false;
|
|
3952
|
+
const properties = type.getProperties();
|
|
3953
|
+
if (properties.length === 0) return false;
|
|
3954
|
+
return properties.every((property) => !property.name.startsWith("__@") && property.declarations?.every((d) => !hasThis(d) && !ts.isMethodSignature(d) && !ts.isMethodDeclaration(d) && !ts.isGetAccessorDeclaration(d) && !ts.isSetAccessorDeclaration(d) && !(ts.getCombinedModifierFlags(d) & (ts.ModifierFlags.Private | ts.ModifierFlags.Protected)) && !("name" in d && d.name && ts.isPrivateIdentifier(d.name))));
|
|
3955
|
+
};
|
|
3956
|
+
for (const file of needsDisplay) {
|
|
3957
|
+
const source = program.getSourceFile(file);
|
|
3958
|
+
const moduleSymbol = source && checker.getSymbolAtLocation(source);
|
|
3959
|
+
if (!source || !moduleSymbol) continue;
|
|
3960
|
+
const original = paths.get(file);
|
|
3961
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
3962
|
+
const collect = (node) => {
|
|
3963
|
+
if (ts.isIdentifier(node)) identifiers.add(node.text);
|
|
3964
|
+
ts.forEachChild(node, collect);
|
|
3965
|
+
};
|
|
3966
|
+
collect(source);
|
|
3967
|
+
const unique = (stem) => {
|
|
3968
|
+
let name = stem;
|
|
3969
|
+
for (let n2 = 2; identifiers.has(name); n2++) name = `${stem}${n2}`;
|
|
3970
|
+
identifiers.add(name);
|
|
3971
|
+
return name;
|
|
3972
|
+
};
|
|
3973
|
+
const views = [];
|
|
3974
|
+
for (const exported of checker.getExportsOfModule(moduleSymbol)) {
|
|
3975
|
+
const name = exported.name;
|
|
3976
|
+
if (name === "default" || !/^[$_\p{ID_Start}][$_\p{ID_Continue}]*$/u.test(name)) continue;
|
|
3977
|
+
const target = exported.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(exported) : exported;
|
|
3978
|
+
if (!plainData(target)) continue;
|
|
3979
|
+
let expression;
|
|
3980
|
+
for (const statement of source.statements) {
|
|
3981
|
+
if ((ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement)) && statement.name.text === name && checker.getSymbolAtLocation(statement.name) === target) {
|
|
3982
|
+
expression = name;
|
|
3983
|
+
break;
|
|
3984
|
+
}
|
|
3985
|
+
if (!ts.isExportDeclaration(statement)) continue;
|
|
3986
|
+
if (statement.attributes || statement.assertClause) continue;
|
|
3987
|
+
if (statement.exportClause && ts.isNamedExports(statement.exportClause)) {
|
|
3988
|
+
const member = statement.exportClause.elements.find((e) => e.name.text === name);
|
|
3989
|
+
if (member) {
|
|
3990
|
+
const local = member.propertyName ?? member.name;
|
|
3991
|
+
if (!ts.isIdentifier(local)) break;
|
|
3992
|
+
expression = statement.moduleSpecifier ? `import(${statement.moduleSpecifier.getText(source)}).${local.text}` : local.text;
|
|
3993
|
+
break;
|
|
3994
|
+
}
|
|
3995
|
+
} else if (!statement.exportClause && statement.moduleSpecifier) {
|
|
3996
|
+
const from = checker.getSymbolAtLocation(statement.moduleSpecifier);
|
|
3997
|
+
if (from && checker.getExportsOfModule(from).some((e) => e.name === name)) {
|
|
3998
|
+
expression = `import(${statement.moduleSpecifier.getText(source)}).${name}`;
|
|
3999
|
+
break;
|
|
4000
|
+
}
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
4003
|
+
if (!expression) continue;
|
|
4004
|
+
const docs = exported.getDocumentationComment(checker);
|
|
4005
|
+
const description = ts.displayPartsToString(docs.length ? docs : target.getDocumentationComment(checker));
|
|
4006
|
+
const tags = target.getJsDocTags(checker).map((tag) => `@${tag.name}${tag.text ? ` ${ts.displayPartsToString(tag.text)}` : ""}`);
|
|
4007
|
+
views.push({ name, expression, doc: [description, ...tags].filter(Boolean).join("\n").replace(/\*\//g, "* /") });
|
|
4008
|
+
}
|
|
4009
|
+
if (views.length === 0) continue;
|
|
4010
|
+
const names = new Set(views.map((view) => view.name));
|
|
4011
|
+
const edits = [];
|
|
4012
|
+
for (const statement of source.statements) {
|
|
4013
|
+
if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {
|
|
4014
|
+
const remaining = statement.exportClause.elements.filter((e) => !names.has(e.name.text));
|
|
4015
|
+
if (remaining.length === statement.exportClause.elements.length) continue;
|
|
4016
|
+
edits.push(remaining.length ? {
|
|
4017
|
+
start: statement.exportClause.getStart(source),
|
|
4018
|
+
end: statement.exportClause.end,
|
|
4019
|
+
text: `{ ${remaining.map((e) => e.getText(source)).join(", ")} }`
|
|
4020
|
+
} : { start: statement.getStart(source), end: statement.end, text: "" });
|
|
4021
|
+
} else if ((ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement)) && names.has(statement.name.text) && !statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword)) {
|
|
4022
|
+
const modifier = statement.modifiers?.find((m) => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
4023
|
+
if (modifier) edits.push({ start: modifier.getStart(source), end: modifier.end, text: "" });
|
|
4024
|
+
}
|
|
4025
|
+
}
|
|
4026
|
+
let output = original;
|
|
4027
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);
|
|
4028
|
+
const display = unique("__FgDataView");
|
|
4029
|
+
output += `
|
|
4030
|
+
// \u81EA\u52A8\u751F\u6210\u7684\u5B57\u6BB5\u89C6\u56FE\uFF1B\u539F\u5408\u540C\u53CA\u7EC4\u4EF6\u7B7E\u540D\u4FDD\u7559\uFF0C\u6D88\u8D39\u65B9\u65E0\u9700\u81EA\u884C\u6620\u5C04\u3002
|
|
4031
|
+
type ${display}<T> = { [K in keyof T]: T[K] } & {};
|
|
4032
|
+
`;
|
|
4033
|
+
for (const view of views.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
|
|
4034
|
+
const alias = unique(`__FgData_${view.name}`);
|
|
4035
|
+
if (view.doc) output += `/**
|
|
4036
|
+
${view.doc.split("\n").map((line) => ` * ${line}`).join("\n")}
|
|
4037
|
+
*/
|
|
4038
|
+
`;
|
|
4039
|
+
output += `type ${alias} = ${display}<${view.expression}>;
|
|
4040
|
+
export type { ${alias} as ${view.name} };
|
|
4041
|
+
`;
|
|
4042
|
+
}
|
|
4043
|
+
files.set(path6.relative(base, file).split(path6.sep).join("/"), output);
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
var init_dts_type_display = __esm({
|
|
4047
|
+
"src/dts-type-display.ts"() {
|
|
4048
|
+
"use strict";
|
|
4049
|
+
}
|
|
4050
|
+
});
|
|
4051
|
+
|
|
3895
4052
|
// src/dts-generate.ts
|
|
3896
4053
|
import fs6 from "node:fs";
|
|
3897
|
-
import
|
|
4054
|
+
import path7 from "node:path";
|
|
3898
4055
|
import crypto from "node:crypto";
|
|
3899
4056
|
import { createRequire as createRequire4 } from "node:module";
|
|
3900
4057
|
import { execFile } from "node:child_process";
|
|
3901
4058
|
function resolveFromRoot(root, pkg) {
|
|
3902
|
-
const req = createRequire4(
|
|
4059
|
+
const req = createRequire4(path7.join(root, "package.json"));
|
|
3903
4060
|
let resolved = null;
|
|
3904
4061
|
for (const spec of [`${pkg}/package.json`, pkg]) {
|
|
3905
4062
|
try {
|
|
@@ -3909,18 +4066,18 @@ function resolveFromRoot(root, pkg) {
|
|
|
3909
4066
|
}
|
|
3910
4067
|
}
|
|
3911
4068
|
if (!resolved) return null;
|
|
3912
|
-
let dir =
|
|
3913
|
-
for (let i = 0; i < 5 && !fs6.existsSync(
|
|
3914
|
-
const parent =
|
|
4069
|
+
let dir = path7.dirname(resolved);
|
|
4070
|
+
for (let i = 0; i < 5 && !fs6.existsSync(path7.join(dir, "package.json")); i++) {
|
|
4071
|
+
const parent = path7.dirname(dir);
|
|
3915
4072
|
if (parent === dir) return null;
|
|
3916
4073
|
dir = parent;
|
|
3917
4074
|
}
|
|
3918
|
-
return fs6.existsSync(
|
|
4075
|
+
return fs6.existsSync(path7.join(dir, "package.json")) ? dir : null;
|
|
3919
4076
|
}
|
|
3920
4077
|
function installHint(root, pkg) {
|
|
3921
4078
|
const pkgManager = (() => {
|
|
3922
|
-
if (fs6.existsSync(
|
|
3923
|
-
if (fs6.existsSync(
|
|
4079
|
+
if (fs6.existsSync(path7.join(root, "pnpm-lock.yaml"))) return "pnpm";
|
|
4080
|
+
if (fs6.existsSync(path7.join(root, "yarn.lock"))) return "yarn";
|
|
3924
4081
|
return "npm";
|
|
3925
4082
|
})();
|
|
3926
4083
|
const devFlag = pkgManager === "pnpm" ? "-D" : "--save-dev";
|
|
@@ -3950,7 +4107,7 @@ function computeStaticClosure(ts, entryFiles, resolver, root) {
|
|
|
3950
4107
|
continue;
|
|
3951
4108
|
}
|
|
3952
4109
|
if (file.endsWith(".vue")) {
|
|
3953
|
-
const req = createRequire4(
|
|
4110
|
+
const req = createRequire4(path7.join(root, "package.json"));
|
|
3954
4111
|
const { parse: parse2 } = req("vue/compiler-sfc");
|
|
3955
4112
|
const { descriptor } = parse2(text);
|
|
3956
4113
|
text = [descriptor.script?.content, descriptor.scriptSetup?.content].filter(Boolean).join("\n");
|
|
@@ -3972,16 +4129,16 @@ import ${JSON.stringify(descriptor.script.src)}`;
|
|
|
3972
4129
|
const r = resolver(spec, file);
|
|
3973
4130
|
let resolved = r && !r.fromNodeModules ? r.resolved : null;
|
|
3974
4131
|
if (!resolved) {
|
|
3975
|
-
const base =
|
|
3976
|
-
for (const c of [base, `${base}.vue`, `${base}.ts`, `${base}.tsx`,
|
|
4132
|
+
const base = path7.resolve(path7.dirname(file), spec);
|
|
4133
|
+
for (const c of [base, `${base}.vue`, `${base}.ts`, `${base}.tsx`, path7.join(base, "index.ts")]) {
|
|
3977
4134
|
if (fs6.existsSync(c)) {
|
|
3978
4135
|
resolved = c;
|
|
3979
4136
|
break;
|
|
3980
4137
|
}
|
|
3981
4138
|
}
|
|
3982
4139
|
}
|
|
3983
|
-
if (resolved && !resolved.includes(`${
|
|
3984
|
-
queue.push(
|
|
4140
|
+
if (resolved && !resolved.includes(`${path7.sep}node_modules${path7.sep}`)) {
|
|
4141
|
+
queue.push(path7.resolve(resolved));
|
|
3985
4142
|
}
|
|
3986
4143
|
}
|
|
3987
4144
|
}
|
|
@@ -3992,7 +4149,7 @@ function parseErrorFiles(stdout, root) {
|
|
|
3992
4149
|
const out = /* @__PURE__ */ new Set();
|
|
3993
4150
|
for (const line of stdout.split("\n")) {
|
|
3994
4151
|
const m = line.match(/^([^)(]+)\((\d+),(\d+)\): error TS/);
|
|
3995
|
-
if (m) out.add(
|
|
4152
|
+
if (m) out.add(path7.resolve(root, m[1].trim()));
|
|
3996
4153
|
}
|
|
3997
4154
|
return out;
|
|
3998
4155
|
}
|
|
@@ -4001,13 +4158,13 @@ function resolveTypesEntries(root, baseCo, diagnostics) {
|
|
|
4001
4158
|
if (raw === void 0) return [];
|
|
4002
4159
|
baseCo.types = [];
|
|
4003
4160
|
if (!Array.isArray(raw)) return [];
|
|
4004
|
-
const req = createRequire4(
|
|
4161
|
+
const req = createRequire4(path7.join(root, "package.json"));
|
|
4005
4162
|
const out = [];
|
|
4006
4163
|
for (const entry of raw) {
|
|
4007
4164
|
if (typeof entry !== "string" || entry.length === 0) continue;
|
|
4008
|
-
const direct = [
|
|
4165
|
+
const direct = [path7.resolve(root, `${entry}.d.ts`), path7.resolve(root, entry, "index.d.ts"), path7.resolve(root, "node_modules", `${entry}.d.ts`), path7.resolve(root, "node_modules", entry, "index.d.ts"), path7.resolve(root, "node_modules/@types", entry, "index.d.ts")];
|
|
4009
4166
|
let hit = direct.find((c) => fs6.existsSync(c));
|
|
4010
|
-
if (!hit && !entry.startsWith(".") && !
|
|
4167
|
+
if (!hit && !entry.startsWith(".") && !path7.isAbsolute(entry)) {
|
|
4011
4168
|
try {
|
|
4012
4169
|
const r = req.resolve(entry);
|
|
4013
4170
|
for (const c of [r.replace(/\.js$/, ".d.ts"), `${r}.d.ts`, r]) {
|
|
@@ -4035,27 +4192,27 @@ function hasVueFilesUnderSources(root) {
|
|
|
4035
4192
|
}
|
|
4036
4193
|
for (const e of entries) {
|
|
4037
4194
|
if (e.name === "node_modules" || e.name === ".git" || e.name === "dist") continue;
|
|
4038
|
-
const p =
|
|
4195
|
+
const p = path7.join(dir, e.name);
|
|
4039
4196
|
budget.left -= 1;
|
|
4040
4197
|
if (e.isFile() && e.name.endsWith(".vue")) return true;
|
|
4041
4198
|
if (e.isDirectory() && scan(p, budget)) return true;
|
|
4042
4199
|
}
|
|
4043
4200
|
return false;
|
|
4044
4201
|
};
|
|
4045
|
-
const srcDir =
|
|
4202
|
+
const srcDir = path7.join(root, "src");
|
|
4046
4203
|
return scan(fs6.existsSync(srcDir) ? srcDir : root, { left: 2e3 });
|
|
4047
4204
|
}
|
|
4048
4205
|
function commonDirOf(files) {
|
|
4049
4206
|
if (files.length === 0) return "";
|
|
4050
|
-
let dir =
|
|
4207
|
+
let dir = path7.dirname(files[0]);
|
|
4051
4208
|
for (const f of files) {
|
|
4052
|
-
const rel =
|
|
4209
|
+
const rel = path7.relative(dir, f);
|
|
4053
4210
|
if (rel.startsWith("..")) {
|
|
4054
|
-
const parts =
|
|
4055
|
-
const cur = dir.split(
|
|
4211
|
+
const parts = path7.dirname(f).split(path7.sep);
|
|
4212
|
+
const cur = dir.split(path7.sep);
|
|
4056
4213
|
let i = 0;
|
|
4057
4214
|
while (i < parts.length && i < cur.length && parts[i] === cur[i]) i++;
|
|
4058
|
-
dir = parts.slice(0, i).join(
|
|
4215
|
+
dir = parts.slice(0, i).join(path7.sep) || path7.sep;
|
|
4059
4216
|
}
|
|
4060
4217
|
}
|
|
4061
4218
|
return dir;
|
|
@@ -4096,12 +4253,12 @@ function loadTsContext(root, ts, diagnostics) {
|
|
|
4096
4253
|
diagnostics.push(`tsconfig \u89E3\u6790\u5931\u8D25\uFF08${tsconfigFile}\uFF09\uFF1A${ts.flattenDiagnosticMessageText(raw.error.messageText, " ")}`);
|
|
4097
4254
|
return null;
|
|
4098
4255
|
}
|
|
4099
|
-
const parsed = ts.parseJsonConfigFileContent(raw.config, ts.sys,
|
|
4256
|
+
const parsed = ts.parseJsonConfigFileContent(raw.config, ts.sys, path7.dirname(tsconfigFile), void 0, void 0, void 0, [
|
|
4100
4257
|
{ extension: ".vue", isMixedContent: true, scriptKind: ts.ScriptKind.Deferred }
|
|
4101
4258
|
]);
|
|
4102
4259
|
const co = { ...parsed.options };
|
|
4103
|
-
if (typeof co.baseUrl === "string" && !
|
|
4104
|
-
co.baseUrl =
|
|
4260
|
+
if (typeof co.baseUrl === "string" && !path7.isAbsolute(co.baseUrl)) {
|
|
4261
|
+
co.baseUrl = path7.resolve(path7.dirname(tsconfigFile), co.baseUrl);
|
|
4105
4262
|
}
|
|
4106
4263
|
if (parsed.errors.length > 0) {
|
|
4107
4264
|
const fatal = parsed.errors.filter((e) => e.category === ts.DiagnosticCategory.Error);
|
|
@@ -4117,7 +4274,7 @@ function loadTsContext(root, ts, diagnostics) {
|
|
|
4117
4274
|
compilerOptions: co,
|
|
4118
4275
|
rawOptions: raw.config.compilerOptions ?? {},
|
|
4119
4276
|
projectFiles: parsed.fileNames.filter((f) => !f.endsWith(".d.ts")),
|
|
4120
|
-
ambientInputs: parsed.fileNames.filter((f) => f.endsWith(".d.ts") && !f.includes(`${
|
|
4277
|
+
ambientInputs: parsed.fileNames.filter((f) => f.endsWith(".d.ts") && !f.includes(`${path7.sep}node_modules${path7.sep}`)),
|
|
4121
4278
|
tsconfigFile
|
|
4122
4279
|
};
|
|
4123
4280
|
}
|
|
@@ -4128,7 +4285,7 @@ function makeResolver(ts, co) {
|
|
|
4128
4285
|
let resolved = r.resolvedModule?.resolvedFileName;
|
|
4129
4286
|
if (resolved?.endsWith(".vue.ts") && ts.sys.fileExists(resolved.slice(0, -3))) resolved = resolved.slice(0, -3);
|
|
4130
4287
|
if (!resolved) return null;
|
|
4131
|
-
return { resolved, fromNodeModules: resolved.includes(`${
|
|
4288
|
+
return { resolved, fromNodeModules: resolved.includes(`${path7.sep}node_modules${path7.sep}`) };
|
|
4132
4289
|
};
|
|
4133
4290
|
}
|
|
4134
4291
|
async function generateTypesBundle(input) {
|
|
@@ -4141,7 +4298,7 @@ async function generateTypesBundle(input) {
|
|
|
4141
4298
|
if (!tsPkgDir) {
|
|
4142
4299
|
return { ok: false, diagnostics: [`\u63D0\u4F9B\u65B9\u5DE5\u7A0B\u672A\u5B89\u88C5 typescript\uFF08\u58F0\u660E\u751F\u6210\u5FC5\u9700\uFF09\u3002${installHint(root, "typescript")}`] };
|
|
4143
4300
|
}
|
|
4144
|
-
const tsReq = createRequire4(
|
|
4301
|
+
const tsReq = createRequire4(path7.join(tsPkgDir, "package.json"));
|
|
4145
4302
|
const ts = tsReq("typescript");
|
|
4146
4303
|
const ctx = loadTsContext(root, ts, diagnostics);
|
|
4147
4304
|
if (!ctx) return { ok: false, diagnostics };
|
|
@@ -4149,9 +4306,9 @@ async function generateTypesBundle(input) {
|
|
|
4149
4306
|
const entryMap = /* @__PURE__ */ new Map();
|
|
4150
4307
|
for (const expose of exposes) {
|
|
4151
4308
|
const raw = expose.import.replace(/^\.?\//, "");
|
|
4152
|
-
let abs =
|
|
4309
|
+
let abs = path7.resolve(root, raw);
|
|
4153
4310
|
if (!fs6.existsSync(abs)) {
|
|
4154
|
-
const viaResolver = resolver(expose.import,
|
|
4311
|
+
const viaResolver = resolver(expose.import, path7.join(root, "package.json"));
|
|
4155
4312
|
if (viaResolver && !viaResolver.fromNodeModules) abs = viaResolver.resolved;
|
|
4156
4313
|
}
|
|
4157
4314
|
abs = abs.replace(/\.js$/, ".ts");
|
|
@@ -4183,17 +4340,17 @@ async function generateTypesBundle(input) {
|
|
|
4183
4340
|
};
|
|
4184
4341
|
}
|
|
4185
4342
|
tool = "vue-tsc";
|
|
4186
|
-
const vueTscPkg = JSON.parse(fs6.readFileSync(
|
|
4343
|
+
const vueTscPkg = JSON.parse(fs6.readFileSync(path7.join(vueTscDir, "package.json"), "utf8"));
|
|
4187
4344
|
const binRel = vueTscPkg.bin?.["vue-tsc"] ?? vueTscPkg.bin?.["vue-tsc.js"] ?? "bin/vue-tsc.js";
|
|
4188
|
-
const binPath =
|
|
4345
|
+
const binPath = path7.resolve(vueTscDir, binRel);
|
|
4189
4346
|
const scopedVueProgram = /^1\./.test(vueTscPkg.version);
|
|
4190
4347
|
if (!fs6.existsSync(binPath)) {
|
|
4191
4348
|
return { ok: false, diagnostics: [`vue-tsc \u5165\u53E3\u4E0D\u5B58\u5728\uFF08${binPath}\uFF09\u3002\u8BF7\u91CD\u65B0\u5B89\u88C5 vue-tsc\u3002`] };
|
|
4192
4349
|
}
|
|
4193
4350
|
const cacheDir = input.incrementalDir;
|
|
4194
4351
|
if (cacheDir) fs6.mkdirSync(cacheDir, { recursive: true });
|
|
4195
|
-
const tmpCfg =
|
|
4196
|
-
const outDir = cacheDir ?
|
|
4352
|
+
const tmpCfg = path7.join(root, `.fulgurjs-types-tsconfig-${cacheDir ? path7.basename(cacheDir) : `${process.pid}-${crypto.randomUUID()}`}.json`);
|
|
4353
|
+
const outDir = cacheDir ? path7.join(cacheDir, "emit") : fs6.mkdtempSync(path7.join(root, "node_modules", ".fulgurjs-types-emit-"));
|
|
4197
4354
|
const clearOutput = () => {
|
|
4198
4355
|
if (!cacheDir) fs6.rmSync(outDir, { recursive: true, force: true });
|
|
4199
4356
|
};
|
|
@@ -4220,14 +4377,14 @@ async function generateTypesBundle(input) {
|
|
|
4220
4377
|
sourceMap: false,
|
|
4221
4378
|
outDir,
|
|
4222
4379
|
rootDir,
|
|
4223
|
-
...cacheDir && !scopedVueProgram ? { incremental: true, tsBuildInfoFile:
|
|
4380
|
+
...cacheDir && !scopedVueProgram ? { incremental: true, tsBuildInfoFile: path7.join(cacheDir, "state.tsbuildinfo") } : {}
|
|
4224
4381
|
},
|
|
4225
4382
|
// 显式 types 是声明程序的根文件,不能再受工程 exclude: ["node_modules"] 过滤。
|
|
4226
4383
|
// include 仍受继承的 exclude 约束;files 保留 vite/client 等已解析的全局声明。
|
|
4227
|
-
files: resolvedTypeFiles.map((f) =>
|
|
4384
|
+
files: resolvedTypeFiles.map((f) => path7.relative(root, f)),
|
|
4228
4385
|
include: [
|
|
4229
|
-
...entryFiles.map((f) =>
|
|
4230
|
-
...ctx.ambientInputs.map((f) =>
|
|
4386
|
+
...entryFiles.map((f) => path7.relative(root, f)),
|
|
4387
|
+
...ctx.ambientInputs.map((f) => path7.relative(root, f))
|
|
4231
4388
|
]
|
|
4232
4389
|
}));
|
|
4233
4390
|
if (process.env.FG_DUMP_TSCFG) fs6.writeFileSync(process.env.FG_DUMP_TSCFG, fs6.readFileSync(tmpCfg, "utf8"));
|
|
@@ -4260,7 +4417,7 @@ async function generateTypesBundle(input) {
|
|
|
4260
4417
|
signal?.addEventListener("abort", abort, { once: true });
|
|
4261
4418
|
if (signal?.aborted) abort();
|
|
4262
4419
|
});
|
|
4263
|
-
const heapMarker = cacheDir ?
|
|
4420
|
+
const heapMarker = cacheDir ? path7.join(cacheDir, "raised-heap") : void 0;
|
|
4264
4421
|
const raisedArgs = [`--max-old-space-size=${process.env.FG_DTS_MAX_OLD_SPACE ?? "8192"}`];
|
|
4265
4422
|
const initialArgs = heapMarker && fs6.existsSync(heapMarker) ? raisedArgs : [];
|
|
4266
4423
|
let { err, stdout, stderr } = await attempt(initialArgs);
|
|
@@ -4337,7 +4494,7 @@ ${tail}`);
|
|
|
4337
4494
|
collectEmitted(ts, outDir, rootDir, emitted, closure);
|
|
4338
4495
|
clearOutput();
|
|
4339
4496
|
} else {
|
|
4340
|
-
const outDir = fs6.mkdtempSync(
|
|
4497
|
+
const outDir = fs6.mkdtempSync(path7.join(root, "node_modules", ".fulgurjs-types-emit-"));
|
|
4341
4498
|
const program = ts.createProgram([...entryFiles, ...ctx.ambientInputs, ...resolveTypesEntries(root, ctx.rawOptions, [])], {
|
|
4342
4499
|
...ctx.compilerOptions,
|
|
4343
4500
|
noEmit: false,
|
|
@@ -4355,13 +4512,13 @@ ${tail}`);
|
|
|
4355
4512
|
...program.getOptionsDiagnostics(),
|
|
4356
4513
|
...program.getSemanticDiagnostics(),
|
|
4357
4514
|
...program.getDeclarationDiagnostics()
|
|
4358
|
-
].filter((d) => d.category === ts.DiagnosticCategory.Error).filter((d) => !d.file || closure.has(
|
|
4515
|
+
].filter((d) => d.category === ts.DiagnosticCategory.Error).filter((d) => !d.file || closure.has(path7.resolve(d.file.fileName)));
|
|
4359
4516
|
if (errs.length > 0) {
|
|
4360
4517
|
fs6.rmSync(outDir, { recursive: true, force: true });
|
|
4361
4518
|
diagnostics.push(
|
|
4362
4519
|
`\u58F0\u660E\u751F\u6210\u5931\u8D25\uFF1A\u66B4\u9732\u95ED\u5305\u5185\u5B58\u5728 ${errs.length} \u4E2A\u7F16\u8BD1\u9519\u8BEF\u2014\u2014\u7C7B\u578B\u8D44\u6E90\u672A\u4EA7\u51FA\uFF08\u4FEE\u590D\u540E\u91CD\u65B0\u6784\u5EFA/\u91CD\u542F dev\uFF09\u3002\u524D\u82E5\u5E72\u6761\uFF1A`,
|
|
4363
4520
|
...errs.slice(0, 20).map((d) => {
|
|
4364
|
-
const f = d.file ?
|
|
4521
|
+
const f = d.file ? path7.relative(root, d.file.fileName) : "?";
|
|
4365
4522
|
const pos = d.file ? d.file.getLineAndCharacterOfPosition(d.start ?? 0) : { line: 0 };
|
|
4366
4523
|
return ` ${f}:${pos.line + 1} TS${d.code}: ${ts.flattenDiagnosticMessageText(d.messageText, " ")}`;
|
|
4367
4524
|
})
|
|
@@ -4369,11 +4526,11 @@ ${tail}`);
|
|
|
4369
4526
|
return { ok: false, diagnostics };
|
|
4370
4527
|
}
|
|
4371
4528
|
for (const source of program.getSourceFiles()) {
|
|
4372
|
-
if (source.isDeclarationFile || source.fileName.endsWith(".json") || !closure.has(
|
|
4529
|
+
if (source.isDeclarationFile || source.fileName.endsWith(".json") || !closure.has(path7.resolve(source.fileName))) continue;
|
|
4373
4530
|
const emitResult = program.emit(source, void 0, void 0, true);
|
|
4374
4531
|
if (emitResult.emitSkipped) {
|
|
4375
4532
|
fs6.rmSync(outDir, { recursive: true, force: true });
|
|
4376
|
-
return { ok: false, diagnostics: [`TypeScript \u58F0\u660E emit \u5931\u8D25\uFF08emitSkipped\uFF09\uFF1A${
|
|
4533
|
+
return { ok: false, diagnostics: [`TypeScript \u58F0\u660E emit \u5931\u8D25\uFF08emitSkipped\uFF09\uFF1A${path7.relative(root, source.fileName)}\u3002\u8BF7\u68C0\u67E5 tsconfig \u7F16\u8BD1\u9009\u9879\u3002`] };
|
|
4377
4534
|
}
|
|
4378
4535
|
}
|
|
4379
4536
|
collectEmitted(ts, outDir, rootDir, emitted, closure);
|
|
@@ -4419,7 +4576,7 @@ export default value;
|
|
|
4419
4576
|
const externals = /* @__PURE__ */ new Set();
|
|
4420
4577
|
const srcToRel = /* @__PURE__ */ new Map();
|
|
4421
4578
|
for (const srcAbs of emitted.keys()) {
|
|
4422
|
-
const rel =
|
|
4579
|
+
const rel = path7.relative(rootDir, srcAbs).split(path7.sep).join("/");
|
|
4423
4580
|
const declRel = rel.endsWith(".d.ts") ? `files/${rel}` : rel.endsWith(".vue") ? `files/${rel}.d.ts` : `files/${rel.replace(/\.(mts|cts|ts|tsx|jsx|js)$/, "")}.d.ts`;
|
|
4424
4581
|
srcToRel.set(srcAbs, declRel);
|
|
4425
4582
|
}
|
|
@@ -4431,7 +4588,7 @@ export default value;
|
|
|
4431
4588
|
if (reachable.has(srcAbs)) continue;
|
|
4432
4589
|
const text = emitted.get(srcAbs);
|
|
4433
4590
|
if (text === void 0) {
|
|
4434
|
-
diagnostics.push(`\u516C\u5F00\u58F0\u660E\u4F9D\u8D56\u672A\u4EA7\u51FA\uFF1A${
|
|
4591
|
+
diagnostics.push(`\u516C\u5F00\u58F0\u660E\u4F9D\u8D56\u672A\u4EA7\u51FA\uFF1A${path7.relative(root, srcAbs)}\u3002`);
|
|
4435
4592
|
return { ok: false, diagnostics };
|
|
4436
4593
|
}
|
|
4437
4594
|
const rewritten = rewriteSpecifiers(
|
|
@@ -4456,11 +4613,10 @@ export default value;
|
|
|
4456
4613
|
for (const [srcAbs, text] of reachable) {
|
|
4457
4614
|
const rel = srcToRel.get(srcAbs);
|
|
4458
4615
|
if (text.includes(root)) {
|
|
4459
|
-
diagnostics.push(`\u58F0\u660E\u6587\u4EF6\u5305\u542B\u672C\u673A\u7EDD\u5BF9\u8DEF\u5F84\uFF08${
|
|
4616
|
+
diagnostics.push(`\u58F0\u660E\u6587\u4EF6\u5305\u542B\u672C\u673A\u7EDD\u5BF9\u8DEF\u5F84\uFF08${path7.relative(root, srcAbs)}\uFF09\uFF0C\u5DF2\u62D2\u7EDD\u4EA7\u51FA\u3002\u8BF7\u68C0\u67E5\u8BE5\u6587\u4EF6\u7684\u7C7B\u578B\u662F\u5426\u5F15\u7528\u4E86\u5B57\u9762\u8DEF\u5F84\u3002`);
|
|
4460
4617
|
leaked = true;
|
|
4461
4618
|
}
|
|
4462
4619
|
files.set(rel, text);
|
|
4463
|
-
filesDigest[rel] = crypto.createHash("sha256").update(text, "utf8").digest("hex");
|
|
4464
4620
|
}
|
|
4465
4621
|
if (leaked) return { ok: false, diagnostics };
|
|
4466
4622
|
const exposesMap = {};
|
|
@@ -4472,6 +4628,13 @@ export default value;
|
|
|
4472
4628
|
}
|
|
4473
4629
|
exposesMap[name] = { declaration: declRel };
|
|
4474
4630
|
}
|
|
4631
|
+
displayPublicDataTypes(ts, files, Object.values(exposesMap).map((entry) => entry.declaration), root, ctx.compilerOptions);
|
|
4632
|
+
for (const [rel, text] of files) {
|
|
4633
|
+
if (text.includes(root)) {
|
|
4634
|
+
return { ok: false, diagnostics: [...diagnostics, `\u58F0\u660E\u6587\u4EF6\u5305\u542B\u672C\u673A\u7EDD\u5BF9\u8DEF\u5F84\uFF08${rel}\uFF09\uFF0C\u5DF2\u62D2\u7EDD\u4EA7\u51FA\u3002`] };
|
|
4635
|
+
}
|
|
4636
|
+
filesDigest[rel] = crypto.createHash("sha256").update(text, "utf8").digest("hex");
|
|
4637
|
+
}
|
|
4475
4638
|
const index = {
|
|
4476
4639
|
schemaVersion: TYPES_SCHEMA_VERSION,
|
|
4477
4640
|
generator: "@fulgurjs/federation",
|
|
@@ -4488,18 +4651,18 @@ export default value;
|
|
|
4488
4651
|
}
|
|
4489
4652
|
function collectEmitted(ts, outDir, rootDir, out, closure) {
|
|
4490
4653
|
const walk = (dir) => fs6.readdirSync(dir, { withFileTypes: true }).flatMap((d) => {
|
|
4491
|
-
const p =
|
|
4654
|
+
const p = path7.join(dir, d.name);
|
|
4492
4655
|
return d.isDirectory() ? walk(p) : [p];
|
|
4493
4656
|
});
|
|
4494
4657
|
if (!fs6.existsSync(outDir)) return;
|
|
4495
4658
|
for (const file of walk(outDir)) {
|
|
4496
4659
|
if (!file.endsWith(".d.ts")) continue;
|
|
4497
|
-
const rel =
|
|
4660
|
+
const rel = path7.relative(outDir, file);
|
|
4498
4661
|
const srcRel = rel.endsWith(".vue.d.ts") ? rel.replace(/\.d\.ts$/, "") : rel.replace(/\.d\.ts$/, ".ts");
|
|
4499
|
-
let srcAbs =
|
|
4662
|
+
let srcAbs = path7.join(rootDir, srcRel);
|
|
4500
4663
|
if (!out.has(srcAbs) && !fs6.existsSync(srcAbs)) {
|
|
4501
4664
|
for (const ext of [".tsx", ".jsx", ".mts", ".cts", ".js"]) {
|
|
4502
|
-
const candidate =
|
|
4665
|
+
const candidate = path7.join(rootDir, rel.replace(/\.d\.ts$/, ext));
|
|
4503
4666
|
if (fs6.existsSync(candidate)) {
|
|
4504
4667
|
srcAbs = candidate;
|
|
4505
4668
|
break;
|
|
@@ -4517,7 +4680,7 @@ function rewriteSpecifiers(ts, text, srcAbs, srcToRel, resolver, externals, root
|
|
|
4517
4680
|
const fail = (spec) => {
|
|
4518
4681
|
failed = true;
|
|
4519
4682
|
diagnostics.push(
|
|
4520
|
-
`\u58F0\u660E\u4F9D\u8D56\u4E0D\u5B8C\u6574\uFF1A${
|
|
4683
|
+
`\u58F0\u660E\u4F9D\u8D56\u4E0D\u5B8C\u6574\uFF1A${path7.relative(root, srcAbs)} \u7684\u5BFC\u5165 "${spec}" \u65E0\u6CD5\u89E3\u6790\u5230\u5DE5\u7A0B\u5185\u6587\u4EF6\u3002\u8BF7\u68C0\u67E5 tsconfig paths/include \u662F\u5426\u8986\u76D6\u8BE5\u4F9D\u8D56\u3002`
|
|
4521
4684
|
);
|
|
4522
4685
|
return null;
|
|
4523
4686
|
};
|
|
@@ -4548,9 +4711,9 @@ function rewriteSpecifiers(ts, text, srcAbs, srcToRel, resolver, externals, root
|
|
|
4548
4711
|
return target;
|
|
4549
4712
|
};
|
|
4550
4713
|
const rewriteTo = (targetRel) => {
|
|
4551
|
-
const fromDir =
|
|
4714
|
+
const fromDir = path7.posix.dirname(declRel);
|
|
4552
4715
|
const toNoExt = targetRel.replace(/\.d\.ts$/, "");
|
|
4553
|
-
let rel =
|
|
4716
|
+
let rel = path7.posix.relative(fromDir, toNoExt);
|
|
4554
4717
|
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
4555
4718
|
return rel;
|
|
4556
4719
|
};
|
|
@@ -4641,6 +4804,7 @@ var init_dts_generate = __esm({
|
|
|
4641
4804
|
init_dts_vue_program();
|
|
4642
4805
|
init_dts_shared();
|
|
4643
4806
|
init_dts_vue_display();
|
|
4807
|
+
init_dts_type_display();
|
|
4644
4808
|
INHERITABLE_KEYS = [
|
|
4645
4809
|
"paths",
|
|
4646
4810
|
"baseUrl",
|
|
@@ -4832,7 +4996,7 @@ var init_dts_ambient = __esm({
|
|
|
4832
4996
|
|
|
4833
4997
|
// src/dts-discovery.ts
|
|
4834
4998
|
import fs7 from "node:fs";
|
|
4835
|
-
import
|
|
4999
|
+
import path8 from "node:path";
|
|
4836
5000
|
function stripJsoncForConfig(text) {
|
|
4837
5001
|
let out = "";
|
|
4838
5002
|
let i = 0;
|
|
@@ -4896,24 +5060,24 @@ function effectiveCfg(cfg, depth = 0) {
|
|
|
4896
5060
|
const parentFile = resolveConfigFile(parent, cfg.file);
|
|
4897
5061
|
if (!parentFile) continue;
|
|
4898
5062
|
const parentCfg = effectiveCfg(readCfg(parentFile) ?? { file: parentFile }, depth + 1);
|
|
4899
|
-
const dirOf = (f, base) =>
|
|
5063
|
+
const dirOf = (f, base) => path8.resolve(path8.dirname(base), f);
|
|
4900
5064
|
if (parentCfg.include && !cfg.include) {
|
|
4901
|
-
merged.include = parentCfg.include.map((p) =>
|
|
5065
|
+
merged.include = parentCfg.include.map((p) => path8.relative(path8.dirname(cfg.file), dirOf(p, parentFile)) || ".");
|
|
4902
5066
|
}
|
|
4903
5067
|
if (parentCfg.files && !cfg.files) {
|
|
4904
|
-
merged.files = parentCfg.files.map((p) =>
|
|
5068
|
+
merged.files = parentCfg.files.map((p) => path8.relative(path8.dirname(cfg.file), dirOf(p, parentFile)));
|
|
4905
5069
|
}
|
|
4906
5070
|
if (parentCfg.exclude && !cfg.exclude) {
|
|
4907
|
-
merged.exclude = parentCfg.exclude.map((p) =>
|
|
5071
|
+
merged.exclude = parentCfg.exclude.map((p) => path8.relative(path8.dirname(cfg.file), dirOf(p, parentFile)));
|
|
4908
5072
|
}
|
|
4909
5073
|
}
|
|
4910
5074
|
return merged;
|
|
4911
5075
|
}
|
|
4912
5076
|
function resolveConfigFile(value, declaringFile) {
|
|
4913
|
-
let candidate =
|
|
5077
|
+
let candidate = path8.resolve(path8.dirname(declaringFile), value);
|
|
4914
5078
|
if (!candidate.endsWith(".json")) candidate += ".json";
|
|
4915
5079
|
if (fs7.existsSync(candidate)) return candidate;
|
|
4916
|
-
const asDir =
|
|
5080
|
+
const asDir = path8.join(candidate, "tsconfig.json");
|
|
4917
5081
|
return fs7.existsSync(asDir) ? asDir : null;
|
|
4918
5082
|
}
|
|
4919
5083
|
function patternCoversDir(pattern, target, cfgDir) {
|
|
@@ -4924,15 +5088,15 @@ function patternCoversDir(pattern, target, cfgDir) {
|
|
|
4924
5088
|
if (norm.includes("**")) base = norm.slice(0, norm.indexOf("**")).replace(/\/+$/, "");
|
|
4925
5089
|
else if (norm.endsWith("/*")) base = norm.slice(0, -2);
|
|
4926
5090
|
else base = norm.replace(/\/+$/, "");
|
|
4927
|
-
const abs = base === "" || base === "." ? cfgDir :
|
|
4928
|
-
return target === abs || target.startsWith(abs +
|
|
5091
|
+
const abs = base === "" || base === "." ? cfgDir : path8.resolve(cfgDir, base);
|
|
5092
|
+
return target === abs || target.startsWith(abs + path8.sep);
|
|
4929
5093
|
}
|
|
4930
5094
|
function checkTypesDiscovery(root, typesRoot) {
|
|
4931
|
-
const relTypes =
|
|
5095
|
+
const relTypes = path8.relative(root, typesRoot) || ".";
|
|
4932
5096
|
const configs = [];
|
|
4933
|
-
let primary =
|
|
5097
|
+
let primary = path8.join(root, "tsconfig.json");
|
|
4934
5098
|
if (!fs7.existsSync(primary)) {
|
|
4935
|
-
const candidates = fs7.existsSync(root) ? fs7.readdirSync(root).filter((f) => /^tsconfig[\w.-]*\.json$/i.test(f)).map((f) =>
|
|
5099
|
+
const candidates = fs7.existsSync(root) ? fs7.readdirSync(root).filter((f) => /^tsconfig[\w.-]*\.json$/i.test(f)).map((f) => path8.join(root, f)) : [];
|
|
4936
5100
|
if (candidates.length === 0) {
|
|
4937
5101
|
return {
|
|
4938
5102
|
covered: false,
|
|
@@ -4944,7 +5108,7 @@ function checkTypesDiscovery(root, typesRoot) {
|
|
|
4944
5108
|
if (candidates.length > 1) {
|
|
4945
5109
|
let covered = false;
|
|
4946
5110
|
for (const file of candidates) {
|
|
4947
|
-
configs.push(
|
|
5111
|
+
configs.push(path8.relative(root, file));
|
|
4948
5112
|
if (configCovers(file, typesRoot)) covered = true;
|
|
4949
5113
|
}
|
|
4950
5114
|
if (covered) return { covered: true, configs, fixHint: null };
|
|
@@ -4955,34 +5119,34 @@ function checkTypesDiscovery(root, typesRoot) {
|
|
|
4955
5119
|
};
|
|
4956
5120
|
}
|
|
4957
5121
|
}
|
|
4958
|
-
configs.push(
|
|
5122
|
+
configs.push(path8.relative(root, primary));
|
|
4959
5123
|
if (configCovers(primary, typesRoot)) return { covered: true, configs, fixHint: null };
|
|
4960
5124
|
return {
|
|
4961
5125
|
covered: false,
|
|
4962
5126
|
configs,
|
|
4963
|
-
fixHint: `TYP-006 \u7C7B\u578B\u76EE\u5F55 ${relTypes} \u672A\u88AB ${
|
|
5127
|
+
fixHint: `TYP-006 \u7C7B\u578B\u76EE\u5F55 ${relTypes} \u672A\u88AB ${path8.relative(root, primary)} \u7684 include/files \u8986\u76D6\uFF08exclude \u6216\u4E25\u683C files \u767D\u540D\u5355\u90FD\u4F1A\u8BA9\u751F\u6210\u58F0\u660E\u5BF9 IDE/tsc \u4E0D\u53EF\u89C1\uFF09\u3002\u6700\u5C0F\u4FEE\u6CD5\uFF1Ainclude \u52A0\u5165 "${relTypes}/**/*.d.ts"\uFF0C\u6216\u79FB\u9664\u5BF9\u5B83\u7684 exclude/files \u9650\u5236\u3002`
|
|
4964
5128
|
};
|
|
4965
5129
|
}
|
|
4966
5130
|
function configCovers(cfgFile, typesRoot) {
|
|
4967
5131
|
const raw = readCfg(cfgFile);
|
|
4968
5132
|
if (!raw) return false;
|
|
4969
5133
|
const cfg = effectiveCfg(raw);
|
|
4970
|
-
const cfgDir =
|
|
5134
|
+
const cfgDir = path8.dirname(cfgFile);
|
|
4971
5135
|
const isSolution = Array.isArray(cfg.files) && cfg.files.length === 0 && !cfg.include;
|
|
4972
5136
|
if (isSolution && cfg.references && cfg.references.length > 0) {
|
|
4973
5137
|
return cfg.references.some((ref) => {
|
|
4974
|
-
const refFile = resolveConfigFile(ref.startsWith(".") ||
|
|
5138
|
+
const refFile = resolveConfigFile(ref.startsWith(".") || path8.isAbsolute(ref) ? ref : `./${ref}`, cfgFile);
|
|
4975
5139
|
return refFile !== null && configCovers(refFile, typesRoot);
|
|
4976
5140
|
});
|
|
4977
5141
|
}
|
|
4978
5142
|
if (Array.isArray(cfg.files) && cfg.files.length > 0) {
|
|
4979
5143
|
return cfg.files.some((f) => {
|
|
4980
|
-
const abs =
|
|
4981
|
-
return abs === typesRoot || abs.startsWith(typesRoot +
|
|
5144
|
+
const abs = path8.resolve(cfgDir, f);
|
|
5145
|
+
return abs === typesRoot || abs.startsWith(typesRoot + path8.sep);
|
|
4982
5146
|
});
|
|
4983
5147
|
}
|
|
4984
5148
|
const includes = cfg.include;
|
|
4985
|
-
if (!includes) return typesRoot === cfgDir || typesRoot.startsWith(cfgDir +
|
|
5149
|
+
if (!includes) return typesRoot === cfgDir || typesRoot.startsWith(cfgDir + path8.sep);
|
|
4986
5150
|
const included = includes.some((p) => patternCoversDir(p, typesRoot, cfgDir));
|
|
4987
5151
|
if (!included) return false;
|
|
4988
5152
|
if (cfg.exclude && cfg.exclude.some((p) => patternCoversDir(p, typesRoot, cfgDir))) return false;
|
|
@@ -4996,7 +5160,7 @@ var init_dts_discovery = __esm({
|
|
|
4996
5160
|
|
|
4997
5161
|
// src/dts-sync.ts
|
|
4998
5162
|
import fs8 from "node:fs";
|
|
4999
|
-
import
|
|
5163
|
+
import path9 from "node:path";
|
|
5000
5164
|
import crypto2 from "node:crypto";
|
|
5001
5165
|
function readManifestTypes(m) {
|
|
5002
5166
|
const t = m.types;
|
|
@@ -5032,7 +5196,7 @@ async function fetchText(url, timeoutMs) {
|
|
|
5032
5196
|
}
|
|
5033
5197
|
function readMetadata(dir) {
|
|
5034
5198
|
try {
|
|
5035
|
-
const raw = JSON.parse(fs8.readFileSync(
|
|
5199
|
+
const raw = JSON.parse(fs8.readFileSync(path9.join(dir, METADATA_FILE), "utf8"));
|
|
5036
5200
|
if (raw.generator !== "@fulgurjs/federation" || typeof raw.revision !== "string" || !Array.isArray(raw.files)) return null;
|
|
5037
5201
|
return raw;
|
|
5038
5202
|
} catch {
|
|
@@ -5042,9 +5206,9 @@ function readMetadata(dir) {
|
|
|
5042
5206
|
function cleanupOwnFiles(dir, meta) {
|
|
5043
5207
|
for (const f of meta.files) {
|
|
5044
5208
|
if (!isSafeBundlePath(f)) continue;
|
|
5045
|
-
fs8.rmSync(
|
|
5209
|
+
fs8.rmSync(path9.join(dir, f), { force: true });
|
|
5046
5210
|
}
|
|
5047
|
-
fs8.rmSync(
|
|
5211
|
+
fs8.rmSync(path9.join(dir, METADATA_FILE), { force: true });
|
|
5048
5212
|
try {
|
|
5049
5213
|
if (fs8.readdirSync(dir).length === 0) fs8.rmdirSync(dir);
|
|
5050
5214
|
} catch {
|
|
@@ -5054,7 +5218,7 @@ function sweepStaleStaging(typesRoot, alias) {
|
|
|
5054
5218
|
if (!fs8.existsSync(typesRoot)) return;
|
|
5055
5219
|
for (const name of fs8.readdirSync(typesRoot)) {
|
|
5056
5220
|
if (name.startsWith(`.fg-staging-${alias}-`) || name.startsWith(`.fg-trash-${alias}-`)) {
|
|
5057
|
-
fs8.rmSync(
|
|
5221
|
+
fs8.rmSync(path9.join(typesRoot, name), { recursive: true, force: true });
|
|
5058
5222
|
}
|
|
5059
5223
|
}
|
|
5060
5224
|
}
|
|
@@ -5063,7 +5227,7 @@ async function syncRemoteTypes(input) {
|
|
|
5063
5227
|
const fetchJsonFn = input.fetchJsonImpl ?? fetchJson;
|
|
5064
5228
|
const fetchTextFn = input.fetchTextImpl ?? fetchText;
|
|
5065
5229
|
const timeoutMs = input.timeoutMs ?? 15e3;
|
|
5066
|
-
const dir =
|
|
5230
|
+
const dir = path9.join(typesRoot, alias);
|
|
5067
5231
|
let manifest;
|
|
5068
5232
|
try {
|
|
5069
5233
|
const parsed = parseManifest(await fetchJsonFn(manifestUrl, timeoutMs));
|
|
@@ -5164,14 +5328,14 @@ async function syncRemoteTypes(input) {
|
|
|
5164
5328
|
}
|
|
5165
5329
|
const ambient = buildAmbientDeclarations({ alias, index, readFile: (rel) => indexRaw[rel] ?? "", source });
|
|
5166
5330
|
sweepStaleStaging(typesRoot, alias);
|
|
5167
|
-
const staging =
|
|
5331
|
+
const staging = path9.join(typesRoot, `.fg-staging-${alias}-${process.pid}-${Date.now()}`);
|
|
5168
5332
|
fs8.rmSync(staging, { recursive: true, force: true });
|
|
5169
5333
|
fs8.mkdirSync(staging, { recursive: true });
|
|
5170
5334
|
const written = [];
|
|
5171
5335
|
try {
|
|
5172
5336
|
for (const [name, content] of ambient.files) {
|
|
5173
|
-
const dest =
|
|
5174
|
-
fs8.mkdirSync(
|
|
5337
|
+
const dest = path9.join(staging, name);
|
|
5338
|
+
fs8.mkdirSync(path9.dirname(dest), { recursive: true });
|
|
5175
5339
|
fs8.writeFileSync(dest, content);
|
|
5176
5340
|
written.push(name);
|
|
5177
5341
|
}
|
|
@@ -5185,8 +5349,8 @@ async function syncRemoteTypes(input) {
|
|
|
5185
5349
|
externals: index.externals,
|
|
5186
5350
|
syncedAt: Date.now()
|
|
5187
5351
|
};
|
|
5188
|
-
fs8.writeFileSync(
|
|
5189
|
-
const trash =
|
|
5352
|
+
fs8.writeFileSync(path9.join(staging, METADATA_FILE), JSON.stringify(meta, null, 2));
|
|
5353
|
+
const trash = path9.join(typesRoot, `.fg-trash-${alias}-${Date.now()}`);
|
|
5190
5354
|
let swapped = false;
|
|
5191
5355
|
if (fs8.existsSync(dir)) {
|
|
5192
5356
|
fs8.renameSync(dir, trash);
|
|
@@ -5231,15 +5395,15 @@ __export(dts_cli_exports, {
|
|
|
5231
5395
|
runTypesCommand: () => runTypesCommand
|
|
5232
5396
|
});
|
|
5233
5397
|
import fs9 from "node:fs";
|
|
5234
|
-
import
|
|
5398
|
+
import path10 from "node:path";
|
|
5235
5399
|
import { createRequire as createRequire5 } from "node:module";
|
|
5236
5400
|
function hostTypesRoot(root, dtsDirOverride) {
|
|
5237
|
-
if (dtsDirOverride) return
|
|
5238
|
-
return
|
|
5401
|
+
if (dtsDirOverride) return path10.resolve(root, dtsDirOverride);
|
|
5402
|
+
return path10.join(root, fs9.existsSync(path10.join(root, "src")) ? "src/fulgurjs/types" : ".fulgurjs/types");
|
|
5239
5403
|
}
|
|
5240
5404
|
async function runTypesCommand(opts) {
|
|
5241
5405
|
const cwd = opts.cwd ?? process.cwd();
|
|
5242
|
-
const configPath =
|
|
5406
|
+
const configPath = path10.resolve(cwd, opts.configPath ?? "fulgurjs.config.ts");
|
|
5243
5407
|
const lines = [];
|
|
5244
5408
|
let failed = false;
|
|
5245
5409
|
let cfg;
|
|
@@ -5248,7 +5412,7 @@ async function runTypesCommand(opts) {
|
|
|
5248
5412
|
} catch (e) {
|
|
5249
5413
|
return { exitCode: 2, lines: [String(e.message ?? e)] };
|
|
5250
5414
|
}
|
|
5251
|
-
const root =
|
|
5415
|
+
const root = path10.dirname(configPath);
|
|
5252
5416
|
const mode = opts.mode ?? "dev";
|
|
5253
5417
|
const n2 = normalizeOptions(cfg.options, root, mode === "dev" ? "serve" : "build");
|
|
5254
5418
|
const dtsEnabled = n2.dts !== false;
|
|
@@ -5277,7 +5441,7 @@ async function runTypesCommand(opts) {
|
|
|
5277
5441
|
const syncable = n2.remotes.filter((r) => !r.promise && (mode === "dev" ? r.devEntry : r.prodEntry));
|
|
5278
5442
|
if (opts.check) {
|
|
5279
5443
|
for (const remote of n2.remotes) {
|
|
5280
|
-
const meta = readMetadata(
|
|
5444
|
+
const meta = readMetadata(path10.join(typesRoot, remote.key));
|
|
5281
5445
|
if (!meta) {
|
|
5282
5446
|
failed = true;
|
|
5283
5447
|
lines.push(`[check] \u8FDC\u7A0B ${remote.key}\uFF1A\u672C\u5730\u65E0\u5DF2\u540C\u6B65\u7C7B\u578B\uFF08\u5148\u8FD0\u884C fulgurjs types\uFF09\u3002`);
|
|
@@ -5288,7 +5452,7 @@ async function runTypesCommand(opts) {
|
|
|
5288
5452
|
return { exitCode: failed ? 1 : 0, lines };
|
|
5289
5453
|
}
|
|
5290
5454
|
if (syncable.length > 0) {
|
|
5291
|
-
lines.push(`[consumer] \u5F00\u59CB\u540C\u6B65 ${syncable.length} \u4E2A\u8FDC\u7A0B\u7684\u7C7B\u578B\uFF08--mode ${mode}\uFF0C\u76EE\u5F55 ${
|
|
5455
|
+
lines.push(`[consumer] \u5F00\u59CB\u540C\u6B65 ${syncable.length} \u4E2A\u8FDC\u7A0B\u7684\u7C7B\u578B\uFF08--mode ${mode}\uFF0C\u76EE\u5F55 ${path10.relative(root, typesRoot) || typesRoot}\uFF09\u2026\u2026`);
|
|
5292
5456
|
const externalsMissing = /* @__PURE__ */ new Map();
|
|
5293
5457
|
let virtualTypes;
|
|
5294
5458
|
for (const remote of syncable) {
|
|
@@ -5312,7 +5476,7 @@ async function runTypesCommand(opts) {
|
|
|
5312
5476
|
if (result.status === "absent") {
|
|
5313
5477
|
failed = true;
|
|
5314
5478
|
}
|
|
5315
|
-
const meta = readMetadata(
|
|
5479
|
+
const meta = readMetadata(path10.join(typesRoot, remote.key));
|
|
5316
5480
|
if (meta) {
|
|
5317
5481
|
for (const ext of meta.externals) {
|
|
5318
5482
|
if (ext === "*.vue") continue;
|
|
@@ -5360,14 +5524,14 @@ async function runTypesCommand(opts) {
|
|
|
5360
5524
|
function resolveVirtualTypes(root) {
|
|
5361
5525
|
const modules = /* @__PURE__ */ new Set();
|
|
5362
5526
|
try {
|
|
5363
|
-
const ts = createRequire5(
|
|
5527
|
+
const ts = createRequire5(path10.join(root, "package.json"))("typescript");
|
|
5364
5528
|
const visited = /* @__PURE__ */ new Set();
|
|
5365
5529
|
const visit = (configPath2) => {
|
|
5366
5530
|
if (visited.has(configPath2)) return;
|
|
5367
5531
|
visited.add(configPath2);
|
|
5368
5532
|
const config = ts.readConfigFile(configPath2, ts.sys.readFile);
|
|
5369
5533
|
if (config.error) return;
|
|
5370
|
-
const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys,
|
|
5534
|
+
const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, path10.dirname(configPath2), void 0, configPath2);
|
|
5371
5535
|
const roots = parsed.fileNames.filter((file) => /\.d\.[cm]?ts$/.test(file));
|
|
5372
5536
|
const program = ts.createProgram({ rootNames: roots, options: { ...parsed.options, noEmit: true } });
|
|
5373
5537
|
for (const symbol of program.getTypeChecker().getAmbientModules()) {
|
|
@@ -5384,11 +5548,11 @@ function resolveVirtualTypes(root) {
|
|
|
5384
5548
|
}
|
|
5385
5549
|
function resolvePackage(root, pkg) {
|
|
5386
5550
|
try {
|
|
5387
|
-
createRequire5(
|
|
5551
|
+
createRequire5(path10.join(root, "package.json")).resolve(`${pkg}/package.json`);
|
|
5388
5552
|
return true;
|
|
5389
5553
|
} catch {
|
|
5390
5554
|
try {
|
|
5391
|
-
createRequire5(
|
|
5555
|
+
createRequire5(path10.join(root, "package.json")).resolve(pkg);
|
|
5392
5556
|
return true;
|
|
5393
5557
|
} catch {
|
|
5394
5558
|
return false;
|
|
@@ -5415,9 +5579,9 @@ __export(port_exports, {
|
|
|
5415
5579
|
planPortChange: () => planPortChange
|
|
5416
5580
|
});
|
|
5417
5581
|
import fs10 from "node:fs";
|
|
5418
|
-
import
|
|
5582
|
+
import path11 from "node:path";
|
|
5419
5583
|
function readDevConfig2(root) {
|
|
5420
|
-
const file =
|
|
5584
|
+
const file = path11.join(root, "scripts", "dev.config.json");
|
|
5421
5585
|
if (!fs10.existsSync(file)) {
|
|
5422
5586
|
throw new Error(
|
|
5423
5587
|
"[fulgurjs:port] \u672A\u627E\u5230 scripts/dev.config.json\u2014\u2014\u672C\u547D\u4EE4\u7528\u4E8E\u6A21\u677F\u5DE5\u7A0B\uFF08create \u751F\u6210\uFF09\u3002\n \u4FEE\u6CD5\uFF1A\u5728\u6A21\u677F\u5DE5\u7A0B\u6839\u76EE\u5F55\u8FD0\u884C\uFF1B\u81EA\u5EFA\u5DE5\u7A0B\u8BF7\u6309\u6587\u6863\u56DB\u5904\u6E05\u5355\u624B\u5DE5\u6539\u7AEF\u53E3"
|
|
@@ -5448,14 +5612,14 @@ function planPortChange(root, app, to) {
|
|
|
5448
5612
|
}
|
|
5449
5613
|
const notes = [];
|
|
5450
5614
|
const candidates = [
|
|
5451
|
-
{ file:
|
|
5452
|
-
{ file:
|
|
5453
|
-
{ file:
|
|
5454
|
-
{ file:
|
|
5615
|
+
{ file: path11.join(root, target.dir, "package.json"), required: true },
|
|
5616
|
+
{ file: path11.join(root, "scripts", "dev.config.json"), required: true },
|
|
5617
|
+
{ file: path11.join(root, "fulgurjs.config.ts"), required: false },
|
|
5618
|
+
{ file: path11.join(root, "README.md"), required: false }
|
|
5455
5619
|
];
|
|
5456
5620
|
for (const a of cfg.apps) {
|
|
5457
5621
|
if (a.host && a.dir !== target.dir) {
|
|
5458
|
-
candidates.push({ file:
|
|
5622
|
+
candidates.push({ file: path11.join(root, a.dir, "fulgurjs.config.ts"), required: false });
|
|
5459
5623
|
}
|
|
5460
5624
|
}
|
|
5461
5625
|
const plans = [];
|
|
@@ -5475,7 +5639,7 @@ function planPortChange(root, app, to) {
|
|
|
5475
5639
|
}
|
|
5476
5640
|
const notFound = plans.filter((p) => p.status === "not-found" || p.status === "missing-file");
|
|
5477
5641
|
if (notFound.length) {
|
|
5478
|
-
notes.push(`\u4EE5\u4E0B\u6587\u4EF6\u672A\u53D1\u73B0\u65E7\u7AEF\u53E3 ${from}\uFF08\u53EF\u80FD\u5DF2\u6539\u6216\u5F62\u6001\u4E0D\u540C\uFF0C\u8BF7\u4EBA\u5DE5\u786E\u8BA4\uFF09\uFF1A${notFound.map((p) =>
|
|
5642
|
+
notes.push(`\u4EE5\u4E0B\u6587\u4EF6\u672A\u53D1\u73B0\u65E7\u7AEF\u53E3 ${from}\uFF08\u53EF\u80FD\u5DF2\u6539\u6216\u5F62\u6001\u4E0D\u540C\uFF0C\u8BF7\u4EBA\u5DE5\u786E\u8BA4\uFF09\uFF1A${notFound.map((p) => path11.relative(root, p.file)).join("\u3001")}`);
|
|
5479
5643
|
}
|
|
5480
5644
|
return { app: target.name, dir: target.dir, from, to, plans, notes };
|
|
5481
5645
|
}
|
|
@@ -5496,7 +5660,7 @@ function formatPortPlan(root, plan) {
|
|
|
5496
5660
|
const lines = [];
|
|
5497
5661
|
lines.push(`[fulgurjs:port] \u8BA1\u5212\uFF1A${plan.app}\uFF08\u76EE\u5F55 ${plan.dir}\uFF09\u7AEF\u53E3 ${plan.from} \u2192 ${plan.to}`);
|
|
5498
5662
|
for (const p of plan.plans) {
|
|
5499
|
-
const rel =
|
|
5663
|
+
const rel = path11.relative(root, p.file);
|
|
5500
5664
|
if (p.status === "planned") lines.push(` \u6539\u5199 ${rel}\uFF08${p.hits} \u5904\uFF09`);
|
|
5501
5665
|
else if (p.status === "not-found") lines.push(` \u8DF3\u8FC7 ${rel}\uFF08\u672A\u53D1\u73B0\u65E7\u7AEF\u53E3 ${plan.from}\uFF09`);
|
|
5502
5666
|
else lines.push(` \u8DF3\u8FC7 ${rel}\uFF08\u6587\u4EF6\u4E0D\u5B58\u5728\uFF09`);
|
|
@@ -5517,7 +5681,7 @@ __export(doctor_source_exports, {
|
|
|
5517
5681
|
runSourceDoctor: () => runSourceDoctor
|
|
5518
5682
|
});
|
|
5519
5683
|
import fs11 from "node:fs";
|
|
5520
|
-
import
|
|
5684
|
+
import path12 from "node:path";
|
|
5521
5685
|
import { createRequire as createRequire6 } from "node:module";
|
|
5522
5686
|
async function runSourceDoctor(configPath) {
|
|
5523
5687
|
let loaded;
|
|
@@ -5551,14 +5715,14 @@ async function runSourceDoctor(configPath) {
|
|
|
5551
5715
|
const imports = /* @__PURE__ */ new Set();
|
|
5552
5716
|
const sources = /* @__PURE__ */ new Map();
|
|
5553
5717
|
let complete = true;
|
|
5554
|
-
const relative = (file) =>
|
|
5555
|
-
const within = (file) => file === root || file.startsWith(root +
|
|
5718
|
+
const relative = (file) => path12.relative(root, file).split(path12.sep).join("/");
|
|
5719
|
+
const within = (file) => file === root || file.startsWith(root + path12.sep);
|
|
5556
5720
|
const add = (item, level, symptom, cause, fix) => {
|
|
5557
5721
|
checks.push({ app, item, level, symptom, cause, fix });
|
|
5558
5722
|
};
|
|
5559
5723
|
const resolveSource = (value, parent = root) => {
|
|
5560
5724
|
const clean = value.split(/[?#]/)[0];
|
|
5561
|
-
const file = /^(?:\/?@\/|~\/)/.test(clean) ?
|
|
5725
|
+
const file = /^(?:\/?@\/|~\/)/.test(clean) ? path12.join(root, "src", clean.replace(/^(?:\/?@\/|~\/)/, "")) : path12.resolve(parent, clean);
|
|
5562
5726
|
for (const ext of extensions) {
|
|
5563
5727
|
const candidate = file + ext;
|
|
5564
5728
|
if (!fs11.existsSync(candidate) || !fs11.statSync(candidate).isFile()) continue;
|
|
@@ -5568,10 +5732,10 @@ async function runSourceDoctor(configPath) {
|
|
|
5568
5732
|
return void 0;
|
|
5569
5733
|
};
|
|
5570
5734
|
const required = [relative(loaded.configPath)];
|
|
5571
|
-
const viteFiles = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"].filter((file) => fs11.existsSync(
|
|
5735
|
+
const viteFiles = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"].filter((file) => fs11.existsSync(path12.join(root, file)));
|
|
5572
5736
|
if (viteFiles.length !== 1) add("Vite \u63D2\u4EF6\u63A5\u7EBF", "WARN", "\u672A\u627E\u5230\u552F\u4E00\u5E38\u89C4 Vite \u914D\u7F6E\uFF0C\u65E0\u6CD5\u786E\u8BA4\u63D2\u4EF6\u6CE8\u518C\u3002", "\u53EF\u80FD\u4F7F\u7528\u81EA\u5B9A\u4E49 --config \u6216\u591A\u4EFD\u73AF\u5883\u914D\u7F6E\u3002", "\u5728\u5B9E\u9645 Vite plugins \u4E2D\u6CE8\u518C federation(fulgurjsConfig)\uFF1Binit --plan \u53EF\u9884\u89C8\u53D7\u652F\u6301\u914D\u7F6E\u7684\u63A5\u7EBF\u3002");
|
|
5573
5737
|
else {
|
|
5574
|
-
const code = fs11.readFileSync(
|
|
5738
|
+
const code = fs11.readFileSync(path12.join(root, viteFiles[0]), "utf8");
|
|
5575
5739
|
add(
|
|
5576
5740
|
viteFiles[0],
|
|
5577
5741
|
"WARN",
|
|
@@ -5580,7 +5744,7 @@ async function runSourceDoctor(configPath) {
|
|
|
5580
5744
|
code.includes("@fulgurjs/federation") ? "\u8FD0\u884C\u771F\u5B9E dev/build\uFF1B\u786E\u8BA4\u5F53\u524D\u914D\u7F6E\u8C03\u7528 federation\uFF0C\u751F\u4EA7 base/\u8FDC\u7A0B prod \u524D\u7F00\u4E0E\u670D\u52A1\u5668\u6620\u5C04\u4E00\u81F4\u3002" : "\u68C0\u67E5\u63D2\u4EF6\u662F\u5426\u7531\u8F85\u52A9\u51FD\u6570\u6CE8\u518C\uFF1B\u5426\u5219\u7528 init --plan \u9884\u89C8\u63A5\u7EBF\uFF0C\u4E0D\u8981\u4EC5\u521B\u5EFA fulgurjs.config.ts\u3002"
|
|
5581
5745
|
);
|
|
5582
5746
|
}
|
|
5583
|
-
if (fs11.existsSync(
|
|
5747
|
+
if (fs11.existsSync(path12.join(root, ".fulgurjs-init-pending.json"))) add("\u63A5\u5165\u5199\u5165\u6062\u590D", "FAIL", "\u5B58\u5728\u88AB\u4E2D\u65AD\u7684 init \u5199\u5165\u8BB0\u5F55\u3002", "\u6B64\u524D\u5199\u5165\u5C1A\u672A\u5B8C\u6210\u6216\u56DE\u9000\u9047\u5230\u624B\u5DE5\u7F16\u8F91\u3002", "\u8FD0\u884C fulgurjs init --rollback\uFF1B\u82E5\u63D0\u793A\u6587\u4EF6\u88AB\u7F16\u8F91\uFF0C\u6309\u6062\u590D\u8BB0\u5F55\u4EBA\u5DE5\u5408\u5E76\u540E\u518D\u6267\u884C\u3002");
|
|
5584
5748
|
for (const [key, expose] of Object.entries(options.exposes ?? {})) {
|
|
5585
5749
|
const file = resolveSource(typeof expose === "string" ? expose : expose.import);
|
|
5586
5750
|
if (file) {
|
|
@@ -5606,7 +5770,7 @@ async function runSourceDoctor(configPath) {
|
|
|
5606
5770
|
add("setup", "FAIL", "setup \u6E90\u6587\u4EF6\u4E0D\u5B58\u5728\u6216\u65E0\u6CD5\u89E3\u6790\u3002", "\u521D\u59CB\u5316\u5165\u53E3\u4E0D\u80FD\u5728\u52A0\u8F7D\u65F6\u624D\u53D1\u73B0\u7F3A\u5931\u3002", "\u4FEE\u6B63 setup \u8DEF\u5F84\uFF1B\u6CA1\u6709\u521D\u59CB\u5316\u9700\u6C42\u5219\u5220\u9664 setup \u914D\u7F6E\u3002");
|
|
5607
5771
|
}
|
|
5608
5772
|
}
|
|
5609
|
-
const html =
|
|
5773
|
+
const html = path12.join(root, "index.html");
|
|
5610
5774
|
let hasEntry = false;
|
|
5611
5775
|
if (fs11.existsSync(html)) for (const tag of fs11.readFileSync(html, "utf8").matchAll(/<script\b[^>]*>/gi)) {
|
|
5612
5776
|
const entry = tag[0].match(/\bsrc=["']([^"']+)["']/i)?.[1];
|
|
@@ -5653,7 +5817,7 @@ async function runSourceDoctor(configPath) {
|
|
|
5653
5817
|
}
|
|
5654
5818
|
if (item.n.startsWith(".") || /^(?:\/?@\/|~\/)/.test(item.n)) {
|
|
5655
5819
|
if (/\.(?:[cm]?js|jsx|ts|tsx|vue)$/.test(item.n.split(/[?#]/)[0]) || !/\.[a-z0-9]+$/i.test(item.n.split(/[?#]/)[0])) {
|
|
5656
|
-
const next = resolveSource(item.n,
|
|
5820
|
+
const next = resolveSource(item.n, path12.dirname(file));
|
|
5657
5821
|
if (next) pending.push(next);
|
|
5658
5822
|
else {
|
|
5659
5823
|
complete = false;
|