@ariestools/toolchain 8.7.1 → 8.7.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/README.md +44 -0
- package/dist/actions/deplint/deplint.d.ts +3 -1
- package/dist/actions/deplint/deplint.d.ts.map +1 -1
- package/dist/actions/deplint/engine.d.ts +2 -2
- package/dist/actions/deplint/engine.d.ts.map +1 -1
- package/dist/actions/deplint/findFiles.d.ts.map +1 -1
- package/dist/actions/deplint/getCliReferencedPackagesFromFiles.d.ts.map +1 -1
- package/dist/actions/deplint/getImportsFromFile.d.ts.map +1 -1
- package/dist/actions/deplint/getStorybookConfigImports.d.ts.map +1 -1
- package/dist/actions/deplint/index.d.ts +2 -0
- package/dist/actions/deplint/index.d.ts.map +1 -1
- package/dist/actions/deplint/reporters.d.ts +6 -1
- package/dist/actions/deplint/reporters.d.ts.map +1 -1
- package/dist/actions/deplint/runDeplint.d.ts +4 -0
- package/dist/actions/deplint/runDeplint.d.ts.map +1 -0
- package/dist/actions/deplint/snapshot.d.ts +7 -0
- package/dist/actions/deplint/snapshot.d.ts.map +1 -1
- package/dist/actions/deplint/sourceFileCache.d.ts +11 -0
- package/dist/actions/deplint/sourceFileCache.d.ts.map +1 -0
- package/dist/actions/deplint/types.d.ts +31 -0
- package/dist/actions/deplint/types.d.ts.map +1 -1
- package/dist/actions/package/compile/MonolithConfig.d.ts +10 -0
- package/dist/actions/package/compile/MonolithConfig.d.ts.map +1 -1
- package/dist/actions/package/compile/index.d.ts +1 -0
- package/dist/actions/package/compile/index.d.ts.map +1 -1
- package/dist/actions/package/compile/monolithCopyEntries.d.ts +14 -0
- package/dist/actions/package/compile/monolithCopyEntries.d.ts.map +1 -0
- package/dist/actions/package/compile/packageCompileMonolith.d.ts.map +1 -1
- package/dist/actions/package/expectedCompileOutputs.d.ts +1 -0
- package/dist/actions/package/expectedCompileOutputs.d.ts.map +1 -1
- package/dist/actions/package/exportMapPublint.d.ts.map +1 -1
- package/dist/bin/package/build.mjs +118 -14
- package/dist/bin/package/build.mjs.map +1 -1
- package/dist/bin/package/compile.mjs +84 -6
- package/dist/bin/package/compile.mjs.map +1 -1
- package/dist/bin/package/publint.mjs +95 -14
- package/dist/bin/package/publint.mjs.map +1 -1
- package/dist/bin/package/recompile.mjs +84 -6
- package/dist/bin/package/recompile.mjs.map +1 -1
- package/dist/bin/package/sync-layout.mjs +23 -6
- package/dist/bin/package/sync-layout.mjs.map +1 -1
- package/dist/bin/xy.mjs +1881 -1687
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/lib/loadConfig.d.ts.map +1 -1
- package/dist/xy/lint/deplintCommand.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/bin/xy.mjs
CHANGED
|
@@ -11939,22 +11939,33 @@ function ruleConfigPath(configKey, ruleId) {
|
|
|
11939
11939
|
var import_dist$1 = require_dist$1();
|
|
11940
11940
|
const configState = {
|
|
11941
11941
|
config: void 0,
|
|
11942
|
+
/** In-flight root load so concurrent callers share one cosmiconfig search. */
|
|
11943
|
+
loadPromise: void 0,
|
|
11942
11944
|
rootConfigPath: void 0
|
|
11943
11945
|
};
|
|
11944
11946
|
const workspaceConfigCache = /* @__PURE__ */ new Map();
|
|
11947
|
+
/** In-flight workspace loads — concurrent jobs for the same dir share one search. */
|
|
11948
|
+
const workspaceConfigLoadPromises = /* @__PURE__ */ new Map();
|
|
11945
11949
|
const deprecationWarned = /* @__PURE__ */ new Set();
|
|
11946
11950
|
function isRecord$6(value) {
|
|
11947
11951
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11948
11952
|
}
|
|
11949
|
-
|
|
11950
|
-
|
|
11953
|
+
const explorerState = {};
|
|
11954
|
+
function getExplorer() {
|
|
11955
|
+
explorerState.current ??= (0, import_dist$1.cosmiconfig)("xy", {
|
|
11951
11956
|
cache: true,
|
|
11952
11957
|
loaders: { ".ts": TypeScriptLoader() }
|
|
11953
11958
|
});
|
|
11959
|
+
return explorerState.current;
|
|
11954
11960
|
}
|
|
11955
|
-
|
|
11956
|
-
if (configState.config
|
|
11957
|
-
|
|
11961
|
+
async function ensureRootConfigLoaded() {
|
|
11962
|
+
if (configState.config !== void 0) return;
|
|
11963
|
+
if (configState.loadPromise !== void 0) {
|
|
11964
|
+
await configState.loadPromise;
|
|
11965
|
+
return;
|
|
11966
|
+
}
|
|
11967
|
+
configState.loadPromise = (async () => {
|
|
11968
|
+
const cosmicConfigResult = await getExplorer().search();
|
|
11958
11969
|
configState.config = cosmicConfigResult?.config ?? {};
|
|
11959
11970
|
configState.rootConfigPath = cosmicConfigResult?.filepath;
|
|
11960
11971
|
const configFilePath = cosmicConfigResult?.filepath;
|
|
@@ -11962,8 +11973,16 @@ const loadConfig = async (params) => {
|
|
|
11962
11973
|
console.log(chalk.green(`Loaded config from ${configFilePath}`));
|
|
11963
11974
|
if (Boolean(configState.config.verbose)) console.log(chalk.gray(JSON.stringify(configState.config, null, 2)));
|
|
11964
11975
|
}
|
|
11976
|
+
})();
|
|
11977
|
+
try {
|
|
11978
|
+
await configState.loadPromise;
|
|
11979
|
+
} finally {
|
|
11980
|
+
configState.loadPromise = void 0;
|
|
11965
11981
|
}
|
|
11966
|
-
|
|
11982
|
+
}
|
|
11983
|
+
const loadConfig = async (params) => {
|
|
11984
|
+
await ensureRootConfigLoaded();
|
|
11985
|
+
return deepMerge(configState.config ?? {}, params ?? {});
|
|
11967
11986
|
};
|
|
11968
11987
|
/**
|
|
11969
11988
|
* Loads the xy.config from a specific workspace directory.
|
|
@@ -11973,14 +11992,25 @@ const loadConfig = async (params) => {
|
|
|
11973
11992
|
async function loadWorkspaceConfig(workspaceDir) {
|
|
11974
11993
|
const cached = workspaceConfigCache.get(workspaceDir);
|
|
11975
11994
|
if (cached !== void 0) return cached;
|
|
11976
|
-
const
|
|
11977
|
-
if (
|
|
11978
|
-
|
|
11979
|
-
|
|
11995
|
+
const inFlight = workspaceConfigLoadPromises.get(workspaceDir);
|
|
11996
|
+
if (inFlight !== void 0) return inFlight;
|
|
11997
|
+
const loadPromise = (async () => {
|
|
11998
|
+
await ensureRootConfigLoaded();
|
|
11999
|
+
const result = await getExplorer().search(workspaceDir);
|
|
12000
|
+
if (!result || result.filepath === configState.rootConfigPath) {
|
|
12001
|
+
workspaceConfigCache.set(workspaceDir, {});
|
|
12002
|
+
return {};
|
|
12003
|
+
}
|
|
12004
|
+
const wsConfig = result.config ?? {};
|
|
12005
|
+
workspaceConfigCache.set(workspaceDir, wsConfig);
|
|
12006
|
+
return wsConfig;
|
|
12007
|
+
})();
|
|
12008
|
+
workspaceConfigLoadPromises.set(workspaceDir, loadPromise);
|
|
12009
|
+
try {
|
|
12010
|
+
return await loadPromise;
|
|
12011
|
+
} finally {
|
|
12012
|
+
workspaceConfigLoadPromises.delete(workspaceDir);
|
|
11980
12013
|
}
|
|
11981
|
-
const wsConfig = result.config ?? {};
|
|
11982
|
-
workspaceConfigCache.set(workspaceDir, wsConfig);
|
|
11983
|
-
return wsConfig;
|
|
11984
12014
|
}
|
|
11985
12015
|
/** Deprecated top-level fields that should be under `commands`. */
|
|
11986
12016
|
const DEPRECATED_COMMAND_FIELDS = /* @__PURE__ */ new Set(["deplint", "publint"]);
|
|
@@ -13556,7 +13586,7 @@ function isMatch(input, pattern, options = {}) {
|
|
|
13556
13586
|
//#endregion
|
|
13557
13587
|
//#region src/lib/npmLatestVersion.ts
|
|
13558
13588
|
const REGISTRY_BASE$3 = "https://registry.npmjs.org";
|
|
13559
|
-
const cache$
|
|
13589
|
+
const cache$3 = /* @__PURE__ */ new Map();
|
|
13560
13590
|
async function fetchUncached$1(packageName) {
|
|
13561
13591
|
try {
|
|
13562
13592
|
const url = `${REGISTRY_BASE$3}/${encodeURIComponent(packageName)}/latest`;
|
|
@@ -13568,10 +13598,10 @@ async function fetchUncached$1(packageName) {
|
|
|
13568
13598
|
}
|
|
13569
13599
|
}
|
|
13570
13600
|
function fetchLatestPackageVersion(packageName) {
|
|
13571
|
-
const existing = cache$
|
|
13601
|
+
const existing = cache$3.get(packageName);
|
|
13572
13602
|
if (existing) return existing;
|
|
13573
13603
|
const pending = fetchUncached$1(packageName);
|
|
13574
|
-
cache$
|
|
13604
|
+
cache$3.set(packageName, pending);
|
|
13575
13605
|
return pending;
|
|
13576
13606
|
}
|
|
13577
13607
|
//#endregion
|
|
@@ -24955,6 +24985,38 @@ function analyzeBarrel(barrelPkg, fromDir, scopePrefix) {
|
|
|
24955
24985
|
return [...collected].toSorted((a, b) => a.localeCompare(b));
|
|
24956
24986
|
}
|
|
24957
24987
|
//#endregion
|
|
24988
|
+
//#region src/actions/deplint/sourceFileCache.ts
|
|
24989
|
+
const cache$2 = /* @__PURE__ */ new Map();
|
|
24990
|
+
function scriptKindForPath(filePath) {
|
|
24991
|
+
if (/\.(?:mjs|cjs|js)$/i.test(filePath)) return ts.ScriptKind.JS;
|
|
24992
|
+
if (/\.tsx$/i.test(filePath)) return ts.ScriptKind.TSX;
|
|
24993
|
+
if (/\.jsx$/i.test(filePath)) return ts.ScriptKind.JSX;
|
|
24994
|
+
}
|
|
24995
|
+
function getCachedSourceFile(filePath) {
|
|
24996
|
+
const cached = cache$2.get(filePath);
|
|
24997
|
+
if (cached !== void 0) return cached;
|
|
24998
|
+
const sourceCode = fs.readFileSync(filePath, "utf8");
|
|
24999
|
+
const entry = {
|
|
25000
|
+
sourceCode,
|
|
25001
|
+
sourceFile: ts.createSourceFile(PATH.basename(filePath), sourceCode, ts.ScriptTarget.Latest, true, scriptKindForPath(filePath))
|
|
25002
|
+
};
|
|
25003
|
+
cache$2.set(filePath, entry);
|
|
25004
|
+
return entry;
|
|
25005
|
+
}
|
|
25006
|
+
/** Like getCachedSourceFile, but returns undefined when the file cannot be read. */
|
|
25007
|
+
function tryGetCachedSourceFile(filePath) {
|
|
25008
|
+
const cached = cache$2.get(filePath);
|
|
25009
|
+
if (cached !== void 0) return cached;
|
|
25010
|
+
try {
|
|
25011
|
+
return getCachedSourceFile(filePath);
|
|
25012
|
+
} catch {
|
|
25013
|
+
return;
|
|
25014
|
+
}
|
|
25015
|
+
}
|
|
25016
|
+
function clearSourceFileCache() {
|
|
25017
|
+
cache$2.clear();
|
|
25018
|
+
}
|
|
25019
|
+
//#endregion
|
|
24958
25020
|
//#region src/actions/deplint/findFiles.ts
|
|
24959
25021
|
const codeExtensions$1 = "*.{ts,tsx,mts,cts,js,mjs,cjs}";
|
|
24960
25022
|
const codeExtensionRe = /\.(?:ts|tsx|mts|cts|js|mjs|cjs)$/i;
|
|
@@ -25083,9 +25145,7 @@ function resolveRuntimeEntry(location, entry) {
|
|
|
25083
25145
|
return resolved != null && resolved.length > 0 ? [resolved] : [];
|
|
25084
25146
|
}
|
|
25085
25147
|
function collectLocalImportSpecifiers(filePath) {
|
|
25086
|
-
const
|
|
25087
|
-
const isJsFile = /\.(?:js|mjs|cjs)$/i.test(filePath);
|
|
25088
|
-
const sourceFile = ts.createSourceFile(PATH.basename(filePath), sourceCode, ts.ScriptTarget.Latest, true, isJsFile ? ts.ScriptKind.JS : void 0);
|
|
25148
|
+
const { sourceFile } = getCachedSourceFile(filePath);
|
|
25089
25149
|
const imports = [];
|
|
25090
25150
|
function addModuleSpecifier(moduleSpecifier) {
|
|
25091
25151
|
if (moduleSpecifier && ts.isStringLiteral(moduleSpecifier) && moduleSpecifier.text.startsWith(".")) imports.push(moduleSpecifier.text);
|
|
@@ -26886,354 +26946,996 @@ const compileAll = ({ shouldExitOnFail, jobs, isVerbose, incremental, incrementa
|
|
|
26886
26946
|
return shouldExitOnFail === void 0 ? safeExitAsync(action) : safeExitAsync(action, shouldExitOnFail);
|
|
26887
26947
|
};
|
|
26888
26948
|
//#endregion
|
|
26889
|
-
//#region
|
|
26890
|
-
|
|
26891
|
-
|
|
26892
|
-
let keys, sortFn, key;
|
|
26893
|
-
if (typeof sortWith === "function") sortFn = sortWith;
|
|
26894
|
-
else keys = sortWith;
|
|
26895
|
-
const total = {};
|
|
26896
|
-
for (key of [...keys ?? [], ...Object.keys(object).sort(sortFn)]) if (has(object, key)) total[key] = object[key];
|
|
26897
|
-
return total;
|
|
26949
|
+
//#region src/actions/deplint/reporters.ts
|
|
26950
|
+
function pluralize(word, count) {
|
|
26951
|
+
return `${word}${count === 1 ? "" : "s"}`;
|
|
26898
26952
|
}
|
|
26899
|
-
|
|
26900
|
-
|
|
26901
|
-
|
|
26902
|
-
|
|
26903
|
-
const INDENT_TYPE_TAB = "tab";
|
|
26904
|
-
function shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, value) {
|
|
26905
|
-
return ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && value === 1;
|
|
26953
|
+
function formatDuration$2(ms) {
|
|
26954
|
+
if (ms < 10) return `${ms.toFixed(1)}ms`;
|
|
26955
|
+
if (ms < 1e3) return `${Math.round(ms)}ms`;
|
|
26956
|
+
return `${(ms / 1e3).toFixed(2)}s`;
|
|
26906
26957
|
}
|
|
26907
|
-
|
|
26908
|
-
|
|
26909
|
-
|
|
26910
|
-
|
|
26911
|
-
|
|
26912
|
-
```
|
|
26913
|
-
indents = {
|
|
26914
|
-
t3: [1, 0],
|
|
26915
|
-
t4: [1, 5],
|
|
26916
|
-
s5: [1, 0],
|
|
26917
|
-
s12: [1, 0],
|
|
26958
|
+
function formatWorkspaceList(workspaces) {
|
|
26959
|
+
const names = workspaces.map((workspace) => workspace.name);
|
|
26960
|
+
if (names.length <= 5) return names.join(", ");
|
|
26961
|
+
return `${names.slice(0, 5).join(", ")} +${names.length - 5} more`;
|
|
26918
26962
|
}
|
|
26919
|
-
|
|
26920
|
-
*/
|
|
26921
|
-
|
|
26922
|
-
|
|
26923
|
-
|
|
26924
|
-
|
|
26925
|
-
|
|
26926
|
-
|
|
26927
|
-
|
|
26928
|
-
|
|
26929
|
-
|
|
26930
|
-
|
|
26931
|
-
previousIndentType = "";
|
|
26932
|
-
} else {
|
|
26933
|
-
const indent = matches[0].length;
|
|
26934
|
-
const indentType = matches[1] ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
|
|
26935
|
-
if (shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, indent)) continue;
|
|
26936
|
-
if (indentType !== previousIndentType) previousSize = 0;
|
|
26937
|
-
previousIndentType = indentType;
|
|
26938
|
-
let use = 1;
|
|
26939
|
-
let weight = 0;
|
|
26940
|
-
const indentDifference = indent - previousSize;
|
|
26941
|
-
previousSize = indent;
|
|
26942
|
-
if (indentDifference === 0) {
|
|
26943
|
-
use = 0;
|
|
26944
|
-
weight = 1;
|
|
26945
|
-
} else {
|
|
26946
|
-
const absoluteIndentDifference = Math.abs(indentDifference);
|
|
26947
|
-
if (shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, absoluteIndentDifference)) continue;
|
|
26948
|
-
key = encodeIndentsKey(indentType, absoluteIndentDifference);
|
|
26949
|
-
}
|
|
26950
|
-
const entry = indents.get(key);
|
|
26951
|
-
indents.set(key, entry === void 0 ? [1, 0] : [entry[0] + use, entry[1] + weight]);
|
|
26963
|
+
function groupedDiagnostics(diagnostics) {
|
|
26964
|
+
const workspaces = /* @__PURE__ */ new Map();
|
|
26965
|
+
for (const diagnostic of diagnostics) {
|
|
26966
|
+
const key = diagnostic.workspace.location;
|
|
26967
|
+
let workspaceGroup = workspaces.get(key);
|
|
26968
|
+
if (!workspaceGroup) {
|
|
26969
|
+
workspaceGroup = {
|
|
26970
|
+
diagnostics: 0,
|
|
26971
|
+
rules: /* @__PURE__ */ new Map(),
|
|
26972
|
+
workspace: diagnostic.workspace
|
|
26973
|
+
};
|
|
26974
|
+
workspaces.set(key, workspaceGroup);
|
|
26952
26975
|
}
|
|
26976
|
+
workspaceGroup.diagnostics += 1;
|
|
26977
|
+
const rules = workspaceGroup.rules;
|
|
26978
|
+
const ruleDiagnostics = rules.get(diagnostic.id) ?? [];
|
|
26979
|
+
ruleDiagnostics.push(diagnostic);
|
|
26980
|
+
rules.set(diagnostic.id, ruleDiagnostics);
|
|
26953
26981
|
}
|
|
26954
|
-
return
|
|
26955
|
-
}
|
|
26956
|
-
function encodeIndentsKey(indentType, indentAmount) {
|
|
26957
|
-
return (indentType === INDENT_TYPE_SPACE ? "s" : "t") + String(indentAmount);
|
|
26982
|
+
return workspaces.values().toArray();
|
|
26958
26983
|
}
|
|
26959
|
-
function
|
|
26960
|
-
return
|
|
26961
|
-
type: indentsKey[0] === "s" ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB,
|
|
26962
|
-
amount: Number(indentsKey.slice(1))
|
|
26963
|
-
};
|
|
26984
|
+
function createHumanDeplintProgressReporter({ isVerbose = false } = {}) {
|
|
26985
|
+
return (event) => renderHumanDeplintProgressEvent(event, isVerbose);
|
|
26964
26986
|
}
|
|
26965
|
-
function
|
|
26966
|
-
|
|
26967
|
-
|
|
26968
|
-
|
|
26969
|
-
|
|
26970
|
-
|
|
26971
|
-
|
|
26972
|
-
|
|
26987
|
+
function renderHumanDeplintProgressEvent(event, isVerbose) {
|
|
26988
|
+
switch (event.type) {
|
|
26989
|
+
case "run-start":
|
|
26990
|
+
renderRunStart(event);
|
|
26991
|
+
break;
|
|
26992
|
+
case "workspace-start":
|
|
26993
|
+
renderWorkspaceHeader(event);
|
|
26994
|
+
if (isVerbose) renderVerboseWorkspaceDetails(event);
|
|
26995
|
+
break;
|
|
26996
|
+
case "fix-start":
|
|
26997
|
+
renderFixStart(event);
|
|
26998
|
+
break;
|
|
26999
|
+
case "fix-end":
|
|
27000
|
+
renderFixEnd(event);
|
|
27001
|
+
break;
|
|
27002
|
+
default: if (isVerbose) renderVerboseProgressEvent(event);
|
|
26973
27003
|
}
|
|
26974
|
-
return result;
|
|
26975
27004
|
}
|
|
26976
|
-
function
|
|
26977
|
-
|
|
27005
|
+
function renderRunStart(event) {
|
|
27006
|
+
const categories = event.activeCategories.join(", ");
|
|
27007
|
+
const fixDetail = event.fix ? ` with --fix (max ${event.maxFixPasses} fix ${pluralize("pass", event.maxFixPasses)})` : "";
|
|
27008
|
+
console.info(`Deplint: checking ${event.workspaces.length} ${pluralize("workspace", event.workspaces.length)} [${categories}]${fixDetail}`);
|
|
27009
|
+
console.info(`Workspaces: ${formatWorkspaceList(event.workspaces)}`);
|
|
26978
27010
|
}
|
|
26979
|
-
function
|
|
26980
|
-
|
|
26981
|
-
|
|
26982
|
-
|
|
26983
|
-
|
|
26984
|
-
|
|
26985
|
-
|
|
26986
|
-
|
|
26987
|
-
|
|
26988
|
-
|
|
26989
|
-
|
|
27011
|
+
function renderFixStart(event) {
|
|
27012
|
+
console.info(`Deplint: fix pass ${event.fixPass} resolving ${event.diagnostics} ${pluralize("diagnostic", event.diagnostics)}`);
|
|
27013
|
+
}
|
|
27014
|
+
function renderFixEnd(event) {
|
|
27015
|
+
console.info(`Deplint: fix pass ${event.fixPass} applied ${event.appliedFixes} ${pluralize("fix", event.appliedFixes)}`);
|
|
27016
|
+
}
|
|
27017
|
+
function renderVerboseProgressEvent(event) {
|
|
27018
|
+
switch (event.type) {
|
|
27019
|
+
case "pass-start":
|
|
27020
|
+
console.info(chalk.dim(`Deplint pass ${event.pass}: evaluating ${event.workspaces.length} ${pluralize("workspace", event.workspaces.length)}`));
|
|
27021
|
+
break;
|
|
27022
|
+
case "pass-end":
|
|
27023
|
+
console.info(chalk.dim(`Deplint pass ${event.pass}: ${event.diagnostics} ${pluralize("diagnostic", event.diagnostics)}, ${event.rulesEvaluated} ${pluralize("rule", event.rulesEvaluated)} evaluated, ${event.rulesSkipped} skipped`));
|
|
27024
|
+
break;
|
|
27025
|
+
case "workspace-end":
|
|
27026
|
+
console.info(chalk.dim(`[${event.workspace.name}] pass ${event.pass}: ${event.diagnostics} ${pluralize("diagnostic", event.diagnostics)}`));
|
|
27027
|
+
break;
|
|
27028
|
+
case "rule-start":
|
|
27029
|
+
console.info(chalk.dim(` rule ${event.ruleIndex}/${event.ruleTotal}: ${event.rule.id}`));
|
|
27030
|
+
break;
|
|
27031
|
+
case "rule-end":
|
|
27032
|
+
console.info(chalk.dim(` ${event.diagnostics} ${pluralize("finding", event.diagnostics)} in ${event.elapsedMs}ms`));
|
|
27033
|
+
break;
|
|
27034
|
+
case "rule-skip":
|
|
27035
|
+
console.info(chalk.dim(` skip ${event.ruleIndex}/${event.ruleTotal}: ${event.rule.id} (${event.reason})`));
|
|
27036
|
+
break;
|
|
26990
27037
|
}
|
|
26991
|
-
return {
|
|
26992
|
-
amount,
|
|
26993
|
-
type,
|
|
26994
|
-
indent
|
|
26995
|
-
};
|
|
26996
27038
|
}
|
|
26997
|
-
|
|
26998
|
-
|
|
26999
|
-
function detectNewline(string) {
|
|
27000
|
-
if (typeof string !== "string") throw new TypeError("Expected a string");
|
|
27001
|
-
const newlines = string.match(/(?:\r?\n)/g) || [];
|
|
27002
|
-
if (newlines.length === 0) return;
|
|
27003
|
-
const crlf = newlines.filter((newline) => newline === "\r\n").length;
|
|
27004
|
-
return crlf > newlines.length - crlf ? "\r\n" : "\n";
|
|
27039
|
+
function renderWorkspaceHeader(event) {
|
|
27040
|
+
console.info(`[${chalk.blue(event.workspace.name)}] package ${event.workspaceIndex}/${event.workspaceTotal}: ${event.workspace.location} (${event.context.packageKind})`);
|
|
27005
27041
|
}
|
|
27006
|
-
function
|
|
27007
|
-
|
|
27042
|
+
function renderVerboseWorkspaceDetails(event) {
|
|
27043
|
+
const forcedRefs = event.context.forceDeps + event.context.forceDevs + event.context.forcePeers + event.context.forcePeerOptional;
|
|
27044
|
+
console.info(chalk.dim(` files: ${event.context.allFiles} all, ${event.context.distFiles} dist; deps: ${event.context.dependencies}, dev: ${event.context.devDependencies}, peer: ${event.context.peerDependencies}; exclude: ${event.context.excludeCount}, forced refs: ${forcedRefs}`));
|
|
27008
27045
|
}
|
|
27009
|
-
|
|
27010
|
-
|
|
27011
|
-
|
|
27012
|
-
|
|
27013
|
-
|
|
27014
|
-
|
|
27015
|
-
|
|
27016
|
-
|
|
27017
|
-
|
|
27018
|
-
|
|
27019
|
-
|
|
27020
|
-
|
|
27021
|
-
|
|
27022
|
-
|
|
27023
|
-
|
|
27024
|
-
|
|
27025
|
-
|
|
27026
|
-
|
|
27027
|
-
|
|
27028
|
-
|
|
27029
|
-
|
|
27030
|
-
|
|
27031
|
-
|
|
27032
|
-
|
|
27033
|
-
|
|
27034
|
-
|
|
27035
|
-
|
|
27036
|
-
|
|
27037
|
-
|
|
27038
|
-
|
|
27039
|
-
|
|
27040
|
-
|
|
27041
|
-
|
|
27042
|
-
|
|
27043
|
-
|
|
27044
|
-
|
|
27045
|
-
|
|
27046
|
-
|
|
27046
|
+
const humanDeplintReporter = { render(result) {
|
|
27047
|
+
for (const fix of result.appliedFixes) console.log(`[${chalk.blue(fix.workspace.name)}] Fixed: ${fix.detail} ${chalk.green(fix.dependency)}`);
|
|
27048
|
+
for (const workspaceGroup of groupedDiagnostics(result.diagnostics)) {
|
|
27049
|
+
console.log(`[${chalk.blue(workspaceGroup.workspace.name)}] ${workspaceGroup.diagnostics} ${pluralize("problem", workspaceGroup.diagnostics)}`);
|
|
27050
|
+
for (const [ruleId, diagnostics] of workspaceGroup.rules) {
|
|
27051
|
+
console.log(` ${chalk.cyan(ruleId)} (${diagnostics.length})`);
|
|
27052
|
+
for (const diagnostic of diagnostics) {
|
|
27053
|
+
console.log(` ${diagnostic.message}`);
|
|
27054
|
+
if (diagnostic.fixable) console.log(` ${chalk.dim("fixable with `--fix`")}`);
|
|
27055
|
+
const evidence = diagnostic.evidence ?? [];
|
|
27056
|
+
for (const line of evidence) console.log(` ${line}`);
|
|
27057
|
+
console.log(` ${chalk.yellow(diagnostic.file)}`);
|
|
27058
|
+
}
|
|
27059
|
+
}
|
|
27060
|
+
console.log("");
|
|
27061
|
+
}
|
|
27062
|
+
if (result.summary.problemCount > 0) {
|
|
27063
|
+
const summaryMessage = [
|
|
27064
|
+
`✖ ${result.summary.problemCount} ${pluralize("problem", result.summary.problemCount)}`,
|
|
27065
|
+
`(${result.summary.errorCount} ${pluralize("error", result.summary.errorCount)},`,
|
|
27066
|
+
`${result.summary.warningCount} ${pluralize("warning", result.summary.warningCount)})`
|
|
27067
|
+
].join(" ");
|
|
27068
|
+
const colorizeSummary = (message) => {
|
|
27069
|
+
if (result.summary.errorCount > 0) return chalk.red(message);
|
|
27070
|
+
return chalk.yellow(message);
|
|
27071
|
+
};
|
|
27072
|
+
console.warn(colorizeSummary(summaryMessage));
|
|
27073
|
+
if (result.summary.fixableErrorCount > 0 || result.summary.fixableWarningCount > 0) {
|
|
27074
|
+
const fixableMessage = [
|
|
27075
|
+
` ${result.summary.fixableErrorCount} ${pluralize("error", result.summary.fixableErrorCount)}`,
|
|
27076
|
+
`and ${result.summary.fixableWarningCount} ${pluralize("warning", result.summary.fixableWarningCount)}`,
|
|
27077
|
+
"potentially fixable with the `--fix` option."
|
|
27078
|
+
].join(" ");
|
|
27079
|
+
console.warn(colorizeSummary(fixableMessage));
|
|
27080
|
+
}
|
|
27081
|
+
if (result.summary.diagnosticsByRule !== void 0) {
|
|
27082
|
+
const byRule = Object.entries(result.summary.diagnosticsByRule).map(([rule, count]) => `${rule}: ${count}`).join(", ");
|
|
27083
|
+
if (byRule.length > 0) console.warn(colorizeSummary(` By rule: ${byRule}`));
|
|
27084
|
+
}
|
|
27085
|
+
if (result.summary.passesRun !== void 0 && result.summary.rulesEvaluated !== void 0) console.warn(chalk.dim(` Checked ${result.summary.workspacesChecked} ${pluralize("workspace", result.summary.workspacesChecked)} across ${result.summary.passesRun} ${pluralize("pass", result.summary.passesRun)}; ${result.summary.rulesEvaluated} ${pluralize("rule", result.summary.rulesEvaluated)} evaluated, ${result.summary.rulesSkipped ?? 0} skipped.`));
|
|
27086
|
+
return;
|
|
27087
|
+
}
|
|
27088
|
+
const detail = result.summary.passesRun === void 0 ? "" : chalk.dim(` Checked ${result.summary.workspacesChecked} ${pluralize("workspace", result.summary.workspacesChecked)} across ${result.summary.passesRun} ${pluralize("pass", result.summary.passesRun)}.`);
|
|
27089
|
+
const summaryMessage = `(${result.summary.errorCount} ${pluralize("error", result.summary.errorCount)}, ${result.summary.warningCount} ${pluralize("warning", result.summary.warningCount)})`;
|
|
27090
|
+
console.info(`Deplint: Found no dependency problems. ${chalk.green("✔")} ${summaryMessage}${detail}`);
|
|
27091
|
+
} };
|
|
27092
|
+
const jsonDeplintReporter = { render(result) {
|
|
27093
|
+
console.log(JSON.stringify(result, null, 2));
|
|
27094
|
+
} };
|
|
27095
|
+
function getDeplintReporter(format) {
|
|
27096
|
+
return format === "json" ? jsonDeplintReporter : humanDeplintReporter;
|
|
27047
27097
|
}
|
|
27048
|
-
|
|
27049
|
-
|
|
27050
|
-
|
|
27051
|
-
|
|
27052
|
-
const
|
|
27053
|
-
|
|
27054
|
-
const onStringArray = (fn) => (x) => Array.isArray(x) && x.every((item) => typeof item === "string") ? fn(x) : x;
|
|
27055
|
-
const uniq = onStringArray((xs) => [...new Set(xs)]);
|
|
27056
|
-
const uniqAndSortArray = pipe([uniq, onStringArray((array) => array.toSorted())]);
|
|
27057
|
-
const onObject = (fn) => (x, ...args) => isPlainObject(x) ? fn(x, ...args) : x;
|
|
27058
|
-
const sortObjectBy = (comparator, deep) => {
|
|
27059
|
-
const over = onObject((object) => {
|
|
27060
|
-
if (deep) object = Object.fromEntries(Object.entries(object).map(([key, value]) => [key, over(value)]));
|
|
27061
|
-
return sortObjectByKeyNameList(object, comparator);
|
|
27062
|
-
});
|
|
27063
|
-
return over;
|
|
27064
|
-
};
|
|
27065
|
-
const sortObject = sortObjectBy();
|
|
27066
|
-
const sortURLObject = sortObjectBy(["type", "url"]);
|
|
27067
|
-
const sortPeopleObject = sortObjectBy([
|
|
27068
|
-
"name",
|
|
27069
|
-
"email",
|
|
27070
|
-
"url"
|
|
27071
|
-
]);
|
|
27072
|
-
const sortDirectories = sortObjectBy([
|
|
27073
|
-
"lib",
|
|
27074
|
-
"bin",
|
|
27075
|
-
"man",
|
|
27076
|
-
"doc",
|
|
27077
|
-
"example",
|
|
27078
|
-
"test"
|
|
27079
|
-
]);
|
|
27080
|
-
const overProperty = (property, over) => onObject((object, ...args) => Object.hasOwn(object, property) ? {
|
|
27081
|
-
...object,
|
|
27082
|
-
[property]: over(object[property], ...args)
|
|
27083
|
-
} : object);
|
|
27084
|
-
const sortGitHooks = sortObjectBy(git_hooks_list_default);
|
|
27085
|
-
const parseNameAndVersionRange = (specifier) => {
|
|
27086
|
-
const [nameAndVersion] = specifier.split(">");
|
|
27087
|
-
const atMatches = [...nameAndVersion.matchAll("@")];
|
|
27088
|
-
if (!atMatches.length || atMatches.length === 1 && atMatches[0].index === 0) return { name: specifier };
|
|
27089
|
-
const splitIndex = atMatches.pop().index;
|
|
27090
|
-
return {
|
|
27091
|
-
name: nameAndVersion.substring(0, splitIndex),
|
|
27092
|
-
range: nameAndVersion.substring(splitIndex + 1)
|
|
27093
|
-
};
|
|
27094
|
-
};
|
|
27095
|
-
const sortObjectBySemver = sortObjectBy((a, b) => {
|
|
27096
|
-
const { name: aName, range: aRange } = parseNameAndVersionRange(a);
|
|
27097
|
-
const { name: bName, range: bRange } = parseNameAndVersionRange(b);
|
|
27098
|
-
if (aName !== bName) return aName.localeCompare(bName, "en");
|
|
27099
|
-
if (!aRange) return -1;
|
|
27100
|
-
if (!bRange) return 1;
|
|
27101
|
-
return (0, import_compare.default)((0, import_min_version.default)(aRange), (0, import_min_version.default)(bRange));
|
|
27102
|
-
});
|
|
27103
|
-
const getPackageName = (ident) => {
|
|
27104
|
-
const index = ident.indexOf("@", ident.startsWith("@") ? 1 : 0);
|
|
27105
|
-
return index === -1 ? ident : ident.slice(0, index);
|
|
27106
|
-
};
|
|
27107
|
-
const sortObjectByIdent = (a, b) => {
|
|
27108
|
-
const packageNameA = getPackageName(a);
|
|
27109
|
-
const packageNameB = getPackageName(b);
|
|
27110
|
-
if (packageNameA < packageNameB) return -1;
|
|
27111
|
-
if (packageNameA > packageNameB) return 1;
|
|
27112
|
-
return 0;
|
|
27113
|
-
};
|
|
27114
|
-
const cache$1 = /* @__PURE__ */ new Map();
|
|
27115
|
-
const hasYarnOrPnpmFiles = () => {
|
|
27116
|
-
const cwd = process.cwd();
|
|
27117
|
-
if (!cache$1.has(cwd)) cache$1.set(cwd, fs.existsSync("yarn.lock") || fs.existsSync(".yarn/") || fs.existsSync(".yarnrc.yml") || fs.existsSync("pnpm-lock.yaml") || fs.existsSync("pnpm-workspace.yaml"));
|
|
27118
|
-
return cache$1.get(cwd);
|
|
27119
|
-
};
|
|
27120
|
-
/**
|
|
27121
|
-
* Detects the package manager from package.json and lock files
|
|
27122
|
-
* @param {object} packageJson - The parsed package.json object
|
|
27123
|
-
* @returns {boolean} - The detected package manager. Default to npm if not detected.
|
|
27124
|
-
*/
|
|
27125
|
-
function shouldSortDependenciesLikeNpm(packageJson) {
|
|
27126
|
-
if (typeof packageJson.packageManager === "string") return packageJson.packageManager.startsWith("npm@");
|
|
27127
|
-
if (packageJson.devEngines?.packageManager?.name) return packageJson.devEngines.packageManager.name === "npm";
|
|
27128
|
-
if (packageJson.pnpm) return false;
|
|
27129
|
-
if (packageJson.engines?.npm) return true;
|
|
27130
|
-
if (hasYarnOrPnpmFiles()) return false;
|
|
27131
|
-
return true;
|
|
27098
|
+
function sumWorkspacePhase(profiles, key) {
|
|
27099
|
+
return profiles.reduce((sum, profile) => sum + profile[key], 0);
|
|
27100
|
+
}
|
|
27101
|
+
function formatWorkspaceProfileLine(profile) {
|
|
27102
|
+
const slowRules = profile.slowRules.length === 0 ? "" : chalk.dim(` slow: ${profile.slowRules.map((rule) => `${rule.id} ${formatDuration$2(rule.elapsedMs)}`).join(", ")}`);
|
|
27103
|
+
return ` [${profile.workspace}] config ${formatDuration$2(profile.configMs)} · files ${formatDuration$2(profile.findFilesMs)} · imports ${formatDuration$2(profile.importsMs)} · meta ${formatDuration$2(profile.packageMetaMs)} · rules ${formatDuration$2(profile.rulesMs)} · total ${formatDuration$2(profile.totalMs)}` + chalk.dim(` (${profile.allFiles} src, ${profile.distFiles} runtime)`) + slowRules;
|
|
27132
27104
|
}
|
|
27133
27105
|
/**
|
|
27134
|
-
*
|
|
27135
|
-
* appropriate comparison. npm uses locale-aware comparison, yarn and pnpm use
|
|
27136
|
-
* simple string comparison
|
|
27137
|
-
*/
|
|
27138
|
-
const sortDependencies = onObject((dependencies, packageJson) => {
|
|
27139
|
-
if (Object.keys(dependencies).length < 2) return dependencies;
|
|
27140
|
-
if (shouldSortDependenciesLikeNpm(packageJson)) return sortObjectByKeyNameList(dependencies, (a, b) => a.localeCompare(b, "en"));
|
|
27141
|
-
return sortObjectByKeyNameList(dependencies);
|
|
27142
|
-
});
|
|
27143
|
-
/**
|
|
27144
|
-
* "workspaces" can be an array (npm or yarn classic) or an object (pnpm/bun).
|
|
27145
|
-
* In the case of an array, we do not want to alphabetically sort it in case
|
|
27146
|
-
* scripts need to run in a specific order.
|
|
27147
|
-
*
|
|
27148
|
-
* @see https://docs.npmjs.com/cli/v7/using-npm/workspaces?v=true#running-commands-in-the-context-of-workspaces
|
|
27106
|
+
* Prints a human-readable timing breakdown collected when `--profile` is set.
|
|
27149
27107
|
*/
|
|
27150
|
-
|
|
27151
|
-
|
|
27152
|
-
|
|
27153
|
-
|
|
27154
|
-
|
|
27155
|
-
|
|
27156
|
-
|
|
27157
|
-
|
|
27158
|
-
|
|
27159
|
-
|
|
27160
|
-
|
|
27161
|
-
|
|
27162
|
-
|
|
27163
|
-
|
|
27164
|
-
|
|
27165
|
-
|
|
27166
|
-
|
|
27167
|
-
|
|
27168
|
-
"processor",
|
|
27169
|
-
"noInlineConfig",
|
|
27170
|
-
"reportUnusedDisableDirectives"
|
|
27171
|
-
]),
|
|
27172
|
-
overProperty("env", sortObject),
|
|
27173
|
-
overProperty("globals", sortObject),
|
|
27174
|
-
overProperty("overrides", onArray((overrides) => overrides.map(sortEslintConfig))),
|
|
27175
|
-
overProperty("parserOptions", sortObject),
|
|
27176
|
-
overProperty("rules", sortObjectBy((rule1, rule2) => rule1.split("/").length - rule2.split("/").length || rule1.localeCompare(rule2))),
|
|
27177
|
-
overProperty("settings", sortObject)
|
|
27108
|
+
function printDeplintProfile(profile) {
|
|
27109
|
+
if (profile.workspaces.length === 0) return;
|
|
27110
|
+
const sorted = profile.workspaces.toSorted((a, b) => b.totalMs - a.totalMs);
|
|
27111
|
+
console.log(chalk.cyan("Deplint profile"));
|
|
27112
|
+
console.log(chalk.gray(` packages: ${sorted.length} · wall ${formatDuration$2(profile.wallMs)} · cpu Σ ${formatDuration$2(profile.cpuMs)} · config Σ ${formatDuration$2(sorted.reduce((sum, workspaceProfile) => sum + workspaceProfile.configMs, 0))} · files Σ ${formatDuration$2(sumWorkspacePhase(sorted, "findFilesMs"))} · imports Σ ${formatDuration$2(sumWorkspacePhase(sorted, "importsMs"))} · rules Σ ${formatDuration$2(sumWorkspacePhase(sorted, "rulesMs"))}`));
|
|
27113
|
+
console.log(chalk.gray(" (config = xy config + rules load; files = glob + runtime reachability AST; imports = external import AST scan; meta = package.json / transitive peers; cpu Σ can exceed wall when --jobs > 1)"));
|
|
27114
|
+
for (const workspaceProfile of sorted) console.log(chalk.gray(formatWorkspaceProfileLine(workspaceProfile)));
|
|
27115
|
+
}
|
|
27116
|
+
function printDeplintProfileFromResult(result) {
|
|
27117
|
+
if (result.profile === void 0) return;
|
|
27118
|
+
printDeplintProfile(result.profile);
|
|
27119
|
+
}
|
|
27120
|
+
//#endregion
|
|
27121
|
+
//#region src/actions/deplint/ruleConfig.ts
|
|
27122
|
+
const VALID_RULE_LEVELS$1 = /* @__PURE__ */ new Set([
|
|
27123
|
+
"off",
|
|
27124
|
+
"warn",
|
|
27125
|
+
"error"
|
|
27178
27126
|
]);
|
|
27179
|
-
const
|
|
27180
|
-
"
|
|
27181
|
-
"
|
|
27182
|
-
"
|
|
27127
|
+
const VALID_RANGE_BOUNDS = /* @__PURE__ */ new Set([
|
|
27128
|
+
"infer",
|
|
27129
|
+
"major",
|
|
27130
|
+
"minor"
|
|
27183
27131
|
]);
|
|
27184
|
-
const
|
|
27185
|
-
const
|
|
27186
|
-
"
|
|
27187
|
-
"
|
|
27188
|
-
"
|
|
27132
|
+
const VALID_RANGE_FORMS = /* @__PURE__ */ new Set(["broad", "shorthand"]);
|
|
27133
|
+
const VALID_WORKSPACE_PROTOCOLS = /* @__PURE__ */ new Set([
|
|
27134
|
+
"workspace:~",
|
|
27135
|
+
"workspace:^",
|
|
27136
|
+
"workspace:*"
|
|
27189
27137
|
]);
|
|
27190
|
-
const
|
|
27191
|
-
|
|
27192
|
-
|
|
27193
|
-
|
|
27194
|
-
|
|
27195
|
-
"
|
|
27138
|
+
const deprecatedDeplintRuleWarnings = /* @__PURE__ */ new Set();
|
|
27139
|
+
const BUILT_IN_RULE_OPTION_KEYS = {
|
|
27140
|
+
"dep.dependencies.range-style": /* @__PURE__ */ new Set(["ignore"]),
|
|
27141
|
+
"dep.devDependencies.range-style": /* @__PURE__ */ new Set(["ignore"]),
|
|
27142
|
+
"dep.peerDependencies.range-style": /* @__PURE__ */ new Set([
|
|
27143
|
+
"bound",
|
|
27144
|
+
"form",
|
|
27145
|
+
"ignore"
|
|
27196
27146
|
]),
|
|
27197
|
-
|
|
27198
|
-
|
|
27199
|
-
|
|
27200
|
-
|
|
27201
|
-
|
|
27202
|
-
|
|
27203
|
-
"
|
|
27204
|
-
|
|
27205
|
-
|
|
27206
|
-
|
|
27207
|
-
|
|
27208
|
-
|
|
27209
|
-
"
|
|
27210
|
-
|
|
27211
|
-
|
|
27212
|
-
"
|
|
27213
|
-
|
|
27214
|
-
|
|
27215
|
-
"
|
|
27216
|
-
|
|
27217
|
-
|
|
27218
|
-
|
|
27219
|
-
|
|
27220
|
-
|
|
27221
|
-
]
|
|
27222
|
-
|
|
27223
|
-
|
|
27224
|
-
"
|
|
27225
|
-
|
|
27226
|
-
|
|
27227
|
-
|
|
27228
|
-
|
|
27229
|
-
|
|
27230
|
-
|
|
27231
|
-
|
|
27232
|
-
|
|
27233
|
-
|
|
27234
|
-
|
|
27235
|
-
const
|
|
27236
|
-
|
|
27147
|
+
"dep.workspace.protocol": /* @__PURE__ */ new Set(["ignore", "protocol"])
|
|
27148
|
+
};
|
|
27149
|
+
function isRecord$4(value) {
|
|
27150
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27151
|
+
}
|
|
27152
|
+
function isRuleLevel$3(value) {
|
|
27153
|
+
return typeof value === "string" && VALID_RULE_LEVELS$1.has(value);
|
|
27154
|
+
}
|
|
27155
|
+
function severityFromLevel$1(level) {
|
|
27156
|
+
return level === "warn" ? "warning" : "error";
|
|
27157
|
+
}
|
|
27158
|
+
function formatRuleConfigLocation$1(ruleId) {
|
|
27159
|
+
return `commands.deplint.rules["${ruleId}"]`;
|
|
27160
|
+
}
|
|
27161
|
+
function deprecatedDeplintRuleAlias(ruleId) {
|
|
27162
|
+
return ruleId.startsWith("dep.") ? `deplint.${ruleId.slice(4)}` : void 0;
|
|
27163
|
+
}
|
|
27164
|
+
function canonicalDeplintRuleId(ruleId) {
|
|
27165
|
+
return ruleId.startsWith("deplint.") ? `dep.${ruleId.slice(8)}` : ruleId;
|
|
27166
|
+
}
|
|
27167
|
+
function warnDeprecatedDeplintRuleId(ruleId, canonicalRuleId) {
|
|
27168
|
+
const key = `${ruleId}:${canonicalRuleId}`;
|
|
27169
|
+
if (deprecatedDeplintRuleWarnings.has(key)) return;
|
|
27170
|
+
deprecatedDeplintRuleWarnings.add(key);
|
|
27171
|
+
console.warn(`Deprecated: commands.deplint.rules["${ruleId}"] is deprecated; use commands.deplint.rules["${canonicalRuleId}"] instead.`);
|
|
27172
|
+
}
|
|
27173
|
+
function parseRuleConfig$1(ruleId, value) {
|
|
27174
|
+
if (typeof value === "string") {
|
|
27175
|
+
if (!isRuleLevel$3(value)) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} must be one of "off", "warn", or "error"`);
|
|
27176
|
+
return {
|
|
27177
|
+
level: value,
|
|
27178
|
+
options: {}
|
|
27179
|
+
};
|
|
27180
|
+
}
|
|
27181
|
+
if (Array.isArray(value)) {
|
|
27182
|
+
if (value.length !== 2) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} tuple must be [level, options]`);
|
|
27183
|
+
const level = value[0];
|
|
27184
|
+
if (!isRuleLevel$3(level)) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} level must be one of "off", "warn", or "error"`);
|
|
27185
|
+
const options = value[1];
|
|
27186
|
+
if (!isRecord$4(options)) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} options must be an object`);
|
|
27187
|
+
return {
|
|
27188
|
+
level,
|
|
27189
|
+
options: { ...options }
|
|
27190
|
+
};
|
|
27191
|
+
}
|
|
27192
|
+
throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} must be a level or [level, options] tuple`);
|
|
27193
|
+
}
|
|
27194
|
+
function validateIgnore$1(ruleId, options) {
|
|
27195
|
+
if (options.ignore === void 0) return;
|
|
27196
|
+
if (!Array.isArray(options.ignore) || options.ignore.some((pattern) => typeof pattern !== "string")) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)}.ignore must be an array of strings`);
|
|
27197
|
+
}
|
|
27198
|
+
function validateBuiltInOptions(ruleId, options, builtInRuleIds) {
|
|
27199
|
+
validateIgnore$1(ruleId, options);
|
|
27200
|
+
if (!builtInRuleIds.has(ruleId)) return;
|
|
27201
|
+
const allowedKeys = BUILT_IN_RULE_OPTION_KEYS[ruleId] ?? /* @__PURE__ */ new Set(["ignore"]);
|
|
27202
|
+
for (const key of Object.keys(options)) if (!allowedKeys.has(key)) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} has unknown option "${key}"`);
|
|
27203
|
+
if (ruleId === "dep.peerDependencies.range-style" && options.bound !== void 0 && (typeof options.bound !== "string" || !VALID_RANGE_BOUNDS.has(options.bound))) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)}.bound must be "infer", "major", or "minor"`);
|
|
27204
|
+
if (ruleId === "dep.peerDependencies.range-style" && options.form !== void 0 && (typeof options.form !== "string" || !VALID_RANGE_FORMS.has(options.form))) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)}.form must be "broad" or "shorthand"`);
|
|
27205
|
+
if (ruleId === "dep.workspace.protocol" && options.protocol !== void 0 && (typeof options.protocol !== "string" || !VALID_WORKSPACE_PROTOCOLS.has(options.protocol))) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)}.protocol must be "workspace:~", "workspace:^", or "workspace:*"`);
|
|
27206
|
+
}
|
|
27207
|
+
function normalizeRuleConfigs(ruleConfigs, ruleIds) {
|
|
27208
|
+
const normalized = {};
|
|
27209
|
+
for (const [ruleId, config] of Object.entries(ruleConfigs)) {
|
|
27210
|
+
const canonicalId = canonicalDeplintRuleId(ruleId);
|
|
27211
|
+
if (!ruleIds.has(canonicalId)) {
|
|
27212
|
+
normalized[ruleId] = config;
|
|
27213
|
+
continue;
|
|
27214
|
+
}
|
|
27215
|
+
if (canonicalId !== ruleId && ruleConfigs[canonicalId] !== void 0) continue;
|
|
27216
|
+
if (canonicalId !== ruleId) warnDeprecatedDeplintRuleId(ruleId, canonicalId);
|
|
27217
|
+
normalized[canonicalId] = config;
|
|
27218
|
+
}
|
|
27219
|
+
return normalized;
|
|
27220
|
+
}
|
|
27221
|
+
function normalizeDeplintRules(rules, config, builtInRuleIds) {
|
|
27222
|
+
const ruleIds = new Set(rules.map((rule) => rule.id));
|
|
27223
|
+
const ruleConfigs = normalizeRuleConfigs(config?.rules ?? {}, ruleIds);
|
|
27224
|
+
const unknownRuleIds = Object.keys(ruleConfigs).filter((ruleId) => !ruleIds.has(ruleId));
|
|
27225
|
+
if (unknownRuleIds.length > 0) throw new TypeError(`Unknown deplint rule ${unknownRuleIds.map((ruleId) => `"${ruleId}"`).join(", ")} in commands.deplint.rules`);
|
|
27226
|
+
return rules.map((rule) => {
|
|
27227
|
+
const legacyRuleId = deprecatedDeplintRuleAlias(rule.id);
|
|
27228
|
+
const ruleConfig = ruleConfigs[rule.id] ?? (legacyRuleId === void 0 ? void 0 : ruleConfigs[legacyRuleId]);
|
|
27229
|
+
if (ruleConfig === void 0) return {
|
|
27230
|
+
...rule,
|
|
27231
|
+
enabled: true,
|
|
27232
|
+
meta: {
|
|
27233
|
+
...rule.meta,
|
|
27234
|
+
severity: "warning"
|
|
27235
|
+
},
|
|
27236
|
+
options: {}
|
|
27237
|
+
};
|
|
27238
|
+
const { level, options } = parseRuleConfig$1(rule.id, ruleConfig);
|
|
27239
|
+
validateBuiltInOptions(rule.id, options, builtInRuleIds);
|
|
27240
|
+
return {
|
|
27241
|
+
...rule,
|
|
27242
|
+
enabled: level !== "off",
|
|
27243
|
+
meta: level === "off" ? { ...rule.meta } : {
|
|
27244
|
+
...rule.meta,
|
|
27245
|
+
severity: severityFromLevel$1(level)
|
|
27246
|
+
},
|
|
27247
|
+
options
|
|
27248
|
+
};
|
|
27249
|
+
});
|
|
27250
|
+
}
|
|
27251
|
+
function isDependencyIgnoredByRule(dependency, options) {
|
|
27252
|
+
if (dependency == null || dependency.length === 0) return false;
|
|
27253
|
+
return options?.ignore?.some((pattern) => pattern === dependency || isMatch(dependency, pattern)) ?? false;
|
|
27254
|
+
}
|
|
27255
|
+
//#endregion
|
|
27256
|
+
//#region src/actions/deplint/getExtendsFromTsconfigs.ts
|
|
27257
|
+
init_index_min();
|
|
27258
|
+
const isExternalReference = (ref) => !ref.startsWith(".") && !ref.startsWith("/");
|
|
27259
|
+
function parseExtendsField(value) {
|
|
27260
|
+
if (typeof value === "string") return [value];
|
|
27261
|
+
if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
|
|
27262
|
+
return [];
|
|
27263
|
+
}
|
|
27264
|
+
function parseTypesField(value) {
|
|
27265
|
+
if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
|
|
27266
|
+
return [];
|
|
27267
|
+
}
|
|
27268
|
+
function parsePathsField(value) {
|
|
27269
|
+
if (typeof value !== "object" || value === null) return [];
|
|
27270
|
+
return Object.keys(value);
|
|
27271
|
+
}
|
|
27272
|
+
function enqueueResolvedTsconfigExtend(file, ref, discovered, queue) {
|
|
27273
|
+
if (isExternalReference(ref)) return;
|
|
27274
|
+
const resolved = PATH.resolve(PATH.dirname(file), ref);
|
|
27275
|
+
if (fs.existsSync(resolved) && !discovered.has(resolved)) queue.push(resolved);
|
|
27276
|
+
}
|
|
27277
|
+
function collectTsconfigFiles(location) {
|
|
27278
|
+
const discovered = /* @__PURE__ */ new Set();
|
|
27279
|
+
const queue = ts$1("./tsconfig*.json", {
|
|
27280
|
+
cwd: location,
|
|
27281
|
+
absolute: true
|
|
27282
|
+
});
|
|
27283
|
+
while (queue.length > 0) {
|
|
27284
|
+
const file = queue.pop();
|
|
27285
|
+
if (file === void 0 || discovered.has(file)) continue;
|
|
27286
|
+
discovered.add(file);
|
|
27287
|
+
try {
|
|
27288
|
+
const parsed = parseTsconfig(file);
|
|
27289
|
+
for (const ref of parseExtendsField(parsed.extends)) enqueueResolvedTsconfigExtend(file, ref, discovered, queue);
|
|
27290
|
+
} catch {}
|
|
27291
|
+
}
|
|
27292
|
+
return [...discovered];
|
|
27293
|
+
}
|
|
27294
|
+
/**
|
|
27295
|
+
* Returns true when `importPath` matches a TypeScript `compilerOptions.paths` key.
|
|
27296
|
+
* Wildcard `*` matches one or more trailing path segments.
|
|
27297
|
+
*/
|
|
27298
|
+
function isMatchingTsconfigPathPattern(pattern, importPath) {
|
|
27299
|
+
const patternParts = pattern.split("/");
|
|
27300
|
+
const importParts = importPath.split("/");
|
|
27301
|
+
let patternIndex = 0;
|
|
27302
|
+
let importIndex = 0;
|
|
27303
|
+
while (patternIndex < patternParts.length && importIndex < importParts.length) {
|
|
27304
|
+
const patternPart = patternParts[patternIndex];
|
|
27305
|
+
if (patternPart === "*") {
|
|
27306
|
+
if (patternIndex === patternParts.length - 1) return true;
|
|
27307
|
+
patternIndex++;
|
|
27308
|
+
importIndex++;
|
|
27309
|
+
continue;
|
|
27310
|
+
}
|
|
27311
|
+
if (patternPart !== importParts[importIndex]) return false;
|
|
27312
|
+
patternIndex++;
|
|
27313
|
+
importIndex++;
|
|
27314
|
+
}
|
|
27315
|
+
if (patternIndex === patternParts.length - 1 && patternParts[patternIndex] === "*") return true;
|
|
27316
|
+
return patternIndex === patternParts.length && importIndex === importParts.length;
|
|
27317
|
+
}
|
|
27318
|
+
function isTsconfigPathAlias(importPath, pathPatterns) {
|
|
27319
|
+
return pathPatterns.some((pattern) => isMatchingTsconfigPathPattern(pattern, importPath));
|
|
27320
|
+
}
|
|
27321
|
+
function parseTsconfig(file) {
|
|
27322
|
+
const cleaned = fs.readFileSync(file, "utf8").replaceAll(/\/\/.*/g, "").replaceAll(/,\s*([}\]])/g, "$1");
|
|
27323
|
+
return JSON.parse(cleaned);
|
|
27324
|
+
}
|
|
27325
|
+
function getPathsFromTsconfigs(location) {
|
|
27326
|
+
const patterns = /* @__PURE__ */ new Set();
|
|
27327
|
+
for (const file of collectTsconfigFiles(location)) try {
|
|
27328
|
+
const compilerOptions = parseTsconfig(file).compilerOptions;
|
|
27329
|
+
const pathPatterns = parsePathsField(compilerOptions?.paths);
|
|
27330
|
+
for (const pattern of pathPatterns) patterns.add(pattern);
|
|
27331
|
+
} catch {}
|
|
27332
|
+
return [...patterns];
|
|
27333
|
+
}
|
|
27334
|
+
function getExtendsFromTsconfigs(location) {
|
|
27335
|
+
const packages = /* @__PURE__ */ new Set();
|
|
27336
|
+
for (const file of collectTsconfigFiles(location)) try {
|
|
27337
|
+
const refs = parseExtendsField(parseTsconfig(file).extends);
|
|
27338
|
+
for (const ref of refs) if (isExternalReference(ref)) packages.add(getBasePackageName(ref));
|
|
27339
|
+
} catch {}
|
|
27340
|
+
return [...packages];
|
|
27341
|
+
}
|
|
27342
|
+
function getTypesFromTsconfigs(location) {
|
|
27343
|
+
const packages = /* @__PURE__ */ new Set();
|
|
27344
|
+
for (const file of collectTsconfigFiles(location)) try {
|
|
27345
|
+
const compilerOptions = parseTsconfig(file).compilerOptions;
|
|
27346
|
+
const refs = parseTypesField(compilerOptions?.types);
|
|
27347
|
+
for (const ref of refs) packages.add(getBasePackageName(ref));
|
|
27348
|
+
} catch {}
|
|
27349
|
+
return [...packages];
|
|
27350
|
+
}
|
|
27351
|
+
//#endregion
|
|
27352
|
+
//#region src/actions/deplint/getImportsFromFile.ts
|
|
27353
|
+
function isTypeOnlyImportClause(clause) {
|
|
27354
|
+
if (clause === void 0) return false;
|
|
27355
|
+
if ("phaseModifier" in clause) {
|
|
27356
|
+
const mod = clause.phaseModifier;
|
|
27357
|
+
return (typeof mod === "number" ? mod : mod?.kind) === ts.SyntaxKind.TypeKeyword;
|
|
27358
|
+
}
|
|
27359
|
+
return clause.isTypeOnly ?? false;
|
|
27360
|
+
}
|
|
27361
|
+
function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
27362
|
+
const { sourceFile } = getCachedSourceFile(filePath);
|
|
27363
|
+
const imports = [];
|
|
27364
|
+
const typeImports = [];
|
|
27365
|
+
const isDeclarationFile = filePath.endsWith(".d.ts") || filePath.endsWith(".d.mts") || filePath.endsWith(".d.cts");
|
|
27366
|
+
function visit(node) {
|
|
27367
|
+
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
27368
|
+
const moduleSpecifier = node.moduleSpecifier?.getFullText();
|
|
27369
|
+
const isTypeImport = ts.isImportDeclaration(node) ? isTypeOnlyImportClause(node.importClause) : false;
|
|
27370
|
+
if (typeof moduleSpecifier === "string") {
|
|
27371
|
+
const trimmed = moduleSpecifier.replaceAll(/['"]/g, "").trim();
|
|
27372
|
+
if (isTypeImport || isDeclarationFile) typeImports.push(trimmed);
|
|
27373
|
+
else imports.push(trimmed);
|
|
27374
|
+
}
|
|
27375
|
+
} else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
27376
|
+
const [arg] = node.arguments;
|
|
27377
|
+
if (ts.isStringLiteral(arg)) imports.push(arg.text);
|
|
27378
|
+
} else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "require" && node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0])) imports.push(node.arguments[0].text);
|
|
27379
|
+
ts.forEachChild(node, visit);
|
|
27380
|
+
}
|
|
27381
|
+
visit(sourceFile);
|
|
27382
|
+
for (const ref of sourceFile.typeReferenceDirectives) typeImports.push(ref.fileName);
|
|
27383
|
+
const importsStartsWithExcludes = [
|
|
27384
|
+
".",
|
|
27385
|
+
"#",
|
|
27386
|
+
"node:"
|
|
27387
|
+
];
|
|
27388
|
+
const isValidImport = (imp) => importsStartsWithExcludes.every((exc) => !imp.startsWith(exc)) && !imp.includes("*") && !imp.includes("!");
|
|
27389
|
+
const cleanedImports = imports.filter(isValidImport).map(getBasePackageName);
|
|
27390
|
+
const cleanedTypeImports = typeImports.filter(isValidImport).map(getBasePackageName);
|
|
27391
|
+
for (const imp of cleanedImports) {
|
|
27392
|
+
importPaths[imp] ??= [];
|
|
27393
|
+
importPaths[imp].push(filePath);
|
|
27394
|
+
}
|
|
27395
|
+
for (const imp of cleanedTypeImports) {
|
|
27396
|
+
typeImportPaths[imp] ??= [];
|
|
27397
|
+
typeImportPaths[imp].push(filePath);
|
|
27398
|
+
}
|
|
27399
|
+
return [cleanedImports, cleanedTypeImports];
|
|
27400
|
+
}
|
|
27401
|
+
//#endregion
|
|
27402
|
+
//#region src/actions/deplint/getStorybookConfigImports.ts
|
|
27403
|
+
const storybookMainPattern = /(?:^|[\\/])\.storybook[\\/]main\.[cm]?[jt]sx?$/;
|
|
27404
|
+
const npmPackageNamePattern = /^@?[a-z0-9][\w./-]*$/i;
|
|
27405
|
+
function isStorybookMainFile(filePath) {
|
|
27406
|
+
return storybookMainPattern.test(filePath);
|
|
27407
|
+
}
|
|
27408
|
+
function getPropertyName$1(prop) {
|
|
27409
|
+
if (ts.isIdentifier(prop.name)) return prop.name.text;
|
|
27410
|
+
if (ts.isStringLiteral(prop.name) || ts.isNoSubstitutionTemplateLiteral(prop.name)) return prop.name.text;
|
|
27411
|
+
}
|
|
27412
|
+
function pushIfPackage(text, collected) {
|
|
27413
|
+
const trimmed = text.trim();
|
|
27414
|
+
if (trimmed.length === 0) return;
|
|
27415
|
+
if (trimmed.startsWith(".") || trimmed.startsWith("/") || trimmed.startsWith("node:")) return;
|
|
27416
|
+
if (!npmPackageNamePattern.test(trimmed)) return;
|
|
27417
|
+
collected.push(trimmed);
|
|
27418
|
+
}
|
|
27419
|
+
function extractFromEntry(node, collected) {
|
|
27420
|
+
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
27421
|
+
pushIfPackage(node.text, collected);
|
|
27422
|
+
return;
|
|
27423
|
+
}
|
|
27424
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
27425
|
+
for (const prop of node.properties) if (ts.isPropertyAssignment(prop) && getPropertyName$1(prop) === "name") extractFromEntry(prop.initializer, collected);
|
|
27426
|
+
return;
|
|
27427
|
+
}
|
|
27428
|
+
if (ts.isCallExpression(node)) {
|
|
27429
|
+
for (const arg of node.arguments) if (ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg)) pushIfPackage(arg.text, collected);
|
|
27430
|
+
return;
|
|
27431
|
+
}
|
|
27432
|
+
if (ts.isArrayLiteralExpression(node)) for (const element of node.elements) extractFromEntry(element, collected);
|
|
27433
|
+
}
|
|
27434
|
+
function getStorybookConfigImports(filePath, importPaths) {
|
|
27435
|
+
if (!isStorybookMainFile(filePath)) return [];
|
|
27436
|
+
const cached = tryGetCachedSourceFile(filePath);
|
|
27437
|
+
if (cached === void 0) return [];
|
|
27438
|
+
const { sourceFile } = cached;
|
|
27439
|
+
const collected = [];
|
|
27440
|
+
function visit(node) {
|
|
27441
|
+
if (ts.isPropertyAssignment(node)) {
|
|
27442
|
+
const name = getPropertyName$1(node);
|
|
27443
|
+
if (name === "addons") {
|
|
27444
|
+
if (ts.isArrayLiteralExpression(node.initializer)) for (const element of node.initializer.elements) extractFromEntry(element, collected);
|
|
27445
|
+
} else if (name === "framework" || name === "builder") extractFromEntry(node.initializer, collected);
|
|
27446
|
+
}
|
|
27447
|
+
ts.forEachChild(node, visit);
|
|
27448
|
+
}
|
|
27449
|
+
visit(sourceFile);
|
|
27450
|
+
const cleaned = [...new Set(collected.map(getBasePackageName))];
|
|
27451
|
+
for (const imp of cleaned) {
|
|
27452
|
+
importPaths[imp] ??= [];
|
|
27453
|
+
if (!importPaths[imp].includes(filePath)) importPaths[imp].push(filePath);
|
|
27454
|
+
}
|
|
27455
|
+
return cleaned;
|
|
27456
|
+
}
|
|
27457
|
+
//#endregion
|
|
27458
|
+
//#region src/actions/deplint/getExternalImportsFromFiles.ts
|
|
27459
|
+
const internalImportPrefixes = [
|
|
27460
|
+
".",
|
|
27461
|
+
"#",
|
|
27462
|
+
"node:"
|
|
27463
|
+
];
|
|
27464
|
+
const removeInternalImports = (imports) => {
|
|
27465
|
+
return imports.filter((imp) => internalImportPrefixes.every((prefix) => !imp.startsWith(prefix)));
|
|
27466
|
+
};
|
|
27467
|
+
const removeTsconfigPathAliases = (imports, pathPatterns) => {
|
|
27468
|
+
if (pathPatterns.length === 0) return imports;
|
|
27469
|
+
return imports.filter((imp) => !isTsconfigPathAlias(imp, pathPatterns));
|
|
27470
|
+
};
|
|
27471
|
+
const isDeclarationFile$1 = (file) => file.endsWith(".d.ts") || file.endsWith(".d.cts") || file.endsWith(".d.mts");
|
|
27472
|
+
const toolingConfigFilePattern = /(?:^|[\\/])xy\.config\.[cm]?[jt]sx?$/;
|
|
27473
|
+
const isToolingConfigFile = (file) => toolingConfigFilePattern.test(file);
|
|
27474
|
+
function excludeToolingConfigImports(paths) {
|
|
27475
|
+
const filtered = {};
|
|
27476
|
+
for (const [imp, files] of Object.entries(paths)) {
|
|
27477
|
+
const kept = files.filter((file) => !isToolingConfigFile(file));
|
|
27478
|
+
if (kept.length > 0) filtered[imp] = kept;
|
|
27479
|
+
}
|
|
27480
|
+
return filtered;
|
|
27481
|
+
}
|
|
27482
|
+
function formatExportPath$2(pathParts) {
|
|
27483
|
+
return pathParts.map((part, index) => {
|
|
27484
|
+
if (index === 0) return part;
|
|
27485
|
+
if (part.startsWith("[")) return part;
|
|
27486
|
+
return /^[a-zA-Z_$][\w$]*$/.test(part) ? `.${part}` : `[${JSON.stringify(part)}]`;
|
|
27487
|
+
}).join("");
|
|
27488
|
+
}
|
|
27489
|
+
function collectExportTargets$1(value, pathParts = ["exports"]) {
|
|
27490
|
+
if (typeof value === "string") {
|
|
27491
|
+
if (!value.startsWith("./")) return [];
|
|
27492
|
+
return [{
|
|
27493
|
+
path: formatExportPath$2(pathParts),
|
|
27494
|
+
target: value
|
|
27495
|
+
}];
|
|
27496
|
+
}
|
|
27497
|
+
if (Array.isArray(value)) return value.flatMap((entry, index) => collectExportTargets$1(entry, [...pathParts, `[${index}]`]));
|
|
27498
|
+
if (typeof value !== "object" || value === null) return [];
|
|
27499
|
+
return Object.entries(value).flatMap(([key, nested]) => collectExportTargets$1(nested, [...pathParts, key]));
|
|
27500
|
+
}
|
|
27501
|
+
function hasExportTarget(location, target) {
|
|
27502
|
+
if (target.includes("*")) return findFilesByGlob(location, target).length > 0;
|
|
27503
|
+
return fs.existsSync(PATH.resolve(location, target));
|
|
27504
|
+
}
|
|
27505
|
+
function readPackageJson$5(location) {
|
|
27506
|
+
try {
|
|
27507
|
+
return JSON.parse(fs.readFileSync(`${location}/package.json`, "utf8"));
|
|
27508
|
+
} catch {
|
|
27509
|
+
return;
|
|
27510
|
+
}
|
|
27511
|
+
}
|
|
27512
|
+
function warnMissingExportTargets(name, location) {
|
|
27513
|
+
const targets = collectExportTargets$1(readPackageJson$5(location)?.exports);
|
|
27514
|
+
const warnedTargets = /* @__PURE__ */ new Set();
|
|
27515
|
+
const prefix = name != null && name.length > 0 ? `[${chalk.blue(name)}] ` : "";
|
|
27516
|
+
for (const { path: exportPath, target } of targets) {
|
|
27517
|
+
if (warnedTargets.has(target)) continue;
|
|
27518
|
+
warnedTargets.add(target);
|
|
27519
|
+
if (hasExportTarget(location, target)) continue;
|
|
27520
|
+
const description = target.includes("*") ? "pattern matched no files" : "file missing";
|
|
27521
|
+
console.warn(`${prefix}${chalk.yellow(`deplint: package.json export ${description}: ${target} (${exportPath})`)}`);
|
|
27522
|
+
}
|
|
27523
|
+
}
|
|
27524
|
+
function hasShippedTsconfig(location) {
|
|
27525
|
+
return (readPackageJson$5(location)?.files)?.some((f) => f === "tsconfig.json" || f.includes("tsconfig")) ?? false;
|
|
27526
|
+
}
|
|
27527
|
+
function getEffectiveRuntimeImportPaths({ distImportPaths, distTypeImportPaths, hasDist, hasRuntimeRoots, srcImportPaths, srcTypeImportPaths }) {
|
|
27528
|
+
if (hasDist) return {
|
|
27529
|
+
importPaths: distImportPaths,
|
|
27530
|
+
typeImportPaths: distTypeImportPaths
|
|
27531
|
+
};
|
|
27532
|
+
if (!hasRuntimeRoots) return {
|
|
27533
|
+
importPaths: {},
|
|
27534
|
+
typeImportPaths: {}
|
|
27535
|
+
};
|
|
27536
|
+
return {
|
|
27537
|
+
importPaths: excludeToolingConfigImports(srcImportPaths),
|
|
27538
|
+
typeImportPaths: excludeToolingConfigImports(srcTypeImportPaths)
|
|
27539
|
+
};
|
|
27540
|
+
}
|
|
27541
|
+
function getExternalImportsFromFiles({ allFiles, distFiles, hasRuntimeRoots = true, location, name, tsconfigExtends = [], tsconfigPaths = [], tsconfigTypes = [] }) {
|
|
27542
|
+
const srcImportPaths = {};
|
|
27543
|
+
const srcTypeImportPaths = {};
|
|
27544
|
+
for (const path of allFiles) {
|
|
27545
|
+
getImportsFromFile(path, srcImportPaths, srcTypeImportPaths);
|
|
27546
|
+
getStorybookConfigImports(path, srcImportPaths);
|
|
27547
|
+
}
|
|
27548
|
+
const allImportPaths = { ...srcImportPaths };
|
|
27549
|
+
for (const [key, paths] of Object.entries(srcTypeImportPaths)) allImportPaths[key] = [...allImportPaths[key] ?? [], ...paths];
|
|
27550
|
+
const distImportPaths = {};
|
|
27551
|
+
const distTypeImportPaths = {};
|
|
27552
|
+
const hasDist = distFiles.length > 0;
|
|
27553
|
+
if (hasDist) {
|
|
27554
|
+
const distTypeFiles = distFiles.filter(isDeclarationFile$1);
|
|
27555
|
+
const distCodeFiles = distFiles.filter((file) => !isDeclarationFile$1(file));
|
|
27556
|
+
for (const path of distCodeFiles) getImportsFromFile(path, distImportPaths, distImportPaths);
|
|
27557
|
+
for (const path of distTypeFiles) getImportsFromFile(path, distTypeImportPaths, distTypeImportPaths);
|
|
27558
|
+
}
|
|
27559
|
+
warnMissingExportTargets(name, location);
|
|
27560
|
+
const { importPaths: effectiveDistImportPaths, typeImportPaths: effectiveDistTypeImportPaths } = getEffectiveRuntimeImportPaths({
|
|
27561
|
+
distImportPaths,
|
|
27562
|
+
distTypeImportPaths,
|
|
27563
|
+
hasDist,
|
|
27564
|
+
hasRuntimeRoots,
|
|
27565
|
+
srcImportPaths,
|
|
27566
|
+
srcTypeImportPaths
|
|
27567
|
+
});
|
|
27568
|
+
const allImports = Object.keys(allImportPaths);
|
|
27569
|
+
const distImports = Object.keys(effectiveDistImportPaths);
|
|
27570
|
+
const externalAllImports = removeTsconfigPathAliases(removeInternalImports(allImports), tsconfigPaths);
|
|
27571
|
+
const externalDistImports = removeTsconfigPathAliases(removeInternalImports(distImports), tsconfigPaths);
|
|
27572
|
+
const externalDistTypeImports = removeTsconfigPathAliases(removeInternalImports(Object.keys(effectiveDistTypeImportPaths)), tsconfigPaths);
|
|
27573
|
+
const isDistTsconfig = hasShippedTsconfig(location);
|
|
27574
|
+
for (const ext of tsconfigExtends) {
|
|
27575
|
+
if (!externalAllImports.includes(ext)) externalAllImports.push(ext);
|
|
27576
|
+
if (isDistTsconfig && !externalDistImports.includes(ext)) externalDistImports.push(ext);
|
|
27577
|
+
}
|
|
27578
|
+
for (const typ of tsconfigTypes) if (!externalAllImports.includes(typ)) externalAllImports.push(typ);
|
|
27579
|
+
return {
|
|
27580
|
+
allImportPaths,
|
|
27581
|
+
allImports,
|
|
27582
|
+
distImportPaths: effectiveDistImportPaths,
|
|
27583
|
+
distImports,
|
|
27584
|
+
externalAllImports,
|
|
27585
|
+
externalDistImports,
|
|
27586
|
+
externalDistTypeImports,
|
|
27587
|
+
tsconfigExtends: [...tsconfigExtends]
|
|
27588
|
+
};
|
|
27589
|
+
}
|
|
27590
|
+
//#endregion
|
|
27591
|
+
//#region ../../node_modules/.pnpm/sort-object-keys@2.1.0/node_modules/sort-object-keys/index.js
|
|
27592
|
+
const has = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
27593
|
+
function sortObjectByKeyNameList(object, sortWith) {
|
|
27594
|
+
let keys, sortFn, key;
|
|
27595
|
+
if (typeof sortWith === "function") sortFn = sortWith;
|
|
27596
|
+
else keys = sortWith;
|
|
27597
|
+
const total = {};
|
|
27598
|
+
for (key of [...keys ?? [], ...Object.keys(object).sort(sortFn)]) if (has(object, key)) total[key] = object[key];
|
|
27599
|
+
return total;
|
|
27600
|
+
}
|
|
27601
|
+
//#endregion
|
|
27602
|
+
//#region ../../node_modules/.pnpm/detect-indent@7.0.2/node_modules/detect-indent/index.js
|
|
27603
|
+
const INDENT_REGEX = /^(?:( )+|\t+)/;
|
|
27604
|
+
const INDENT_TYPE_SPACE = "space";
|
|
27605
|
+
const INDENT_TYPE_TAB = "tab";
|
|
27606
|
+
function shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, value) {
|
|
27607
|
+
return ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && value === 1;
|
|
27608
|
+
}
|
|
27609
|
+
/**
|
|
27610
|
+
Make a Map that counts how many indents/unindents have occurred for a given size and how many lines follow a given indentation.
|
|
27611
|
+
|
|
27612
|
+
The key is a concatenation of the indentation type (s = space and t = tab) and the size of the indents/unindents.
|
|
27613
|
+
|
|
27614
|
+
```
|
|
27615
|
+
indents = {
|
|
27616
|
+
t3: [1, 0],
|
|
27617
|
+
t4: [1, 5],
|
|
27618
|
+
s5: [1, 0],
|
|
27619
|
+
s12: [1, 0],
|
|
27620
|
+
}
|
|
27621
|
+
```
|
|
27622
|
+
*/
|
|
27623
|
+
function makeIndentsMap(string, ignoreSingleSpaces) {
|
|
27624
|
+
const indents = /* @__PURE__ */ new Map();
|
|
27625
|
+
let previousSize = 0;
|
|
27626
|
+
let previousIndentType;
|
|
27627
|
+
let key;
|
|
27628
|
+
for (const line of string.split(/\n/g)) {
|
|
27629
|
+
if (!line) continue;
|
|
27630
|
+
const matches = line.match(INDENT_REGEX);
|
|
27631
|
+
if (matches === null) {
|
|
27632
|
+
previousSize = 0;
|
|
27633
|
+
previousIndentType = "";
|
|
27634
|
+
} else {
|
|
27635
|
+
const indent = matches[0].length;
|
|
27636
|
+
const indentType = matches[1] ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
|
|
27637
|
+
if (shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, indent)) continue;
|
|
27638
|
+
if (indentType !== previousIndentType) previousSize = 0;
|
|
27639
|
+
previousIndentType = indentType;
|
|
27640
|
+
let use = 1;
|
|
27641
|
+
let weight = 0;
|
|
27642
|
+
const indentDifference = indent - previousSize;
|
|
27643
|
+
previousSize = indent;
|
|
27644
|
+
if (indentDifference === 0) {
|
|
27645
|
+
use = 0;
|
|
27646
|
+
weight = 1;
|
|
27647
|
+
} else {
|
|
27648
|
+
const absoluteIndentDifference = Math.abs(indentDifference);
|
|
27649
|
+
if (shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, absoluteIndentDifference)) continue;
|
|
27650
|
+
key = encodeIndentsKey(indentType, absoluteIndentDifference);
|
|
27651
|
+
}
|
|
27652
|
+
const entry = indents.get(key);
|
|
27653
|
+
indents.set(key, entry === void 0 ? [1, 0] : [entry[0] + use, entry[1] + weight]);
|
|
27654
|
+
}
|
|
27655
|
+
}
|
|
27656
|
+
return indents;
|
|
27657
|
+
}
|
|
27658
|
+
function encodeIndentsKey(indentType, indentAmount) {
|
|
27659
|
+
return (indentType === INDENT_TYPE_SPACE ? "s" : "t") + String(indentAmount);
|
|
27660
|
+
}
|
|
27661
|
+
function decodeIndentsKey(indentsKey) {
|
|
27662
|
+
return {
|
|
27663
|
+
type: indentsKey[0] === "s" ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB,
|
|
27664
|
+
amount: Number(indentsKey.slice(1))
|
|
27665
|
+
};
|
|
27666
|
+
}
|
|
27667
|
+
function getMostUsedKey(indents) {
|
|
27668
|
+
let result;
|
|
27669
|
+
let maxUsed = 0;
|
|
27670
|
+
let maxWeight = 0;
|
|
27671
|
+
for (const [key, [usedCount, weight]] of indents) if (usedCount > maxUsed || usedCount === maxUsed && weight > maxWeight) {
|
|
27672
|
+
maxUsed = usedCount;
|
|
27673
|
+
maxWeight = weight;
|
|
27674
|
+
result = key;
|
|
27675
|
+
}
|
|
27676
|
+
return result;
|
|
27677
|
+
}
|
|
27678
|
+
function makeIndentString(type, amount) {
|
|
27679
|
+
return (type === INDENT_TYPE_SPACE ? " " : " ").repeat(amount);
|
|
27680
|
+
}
|
|
27681
|
+
function detectIndent(string) {
|
|
27682
|
+
if (typeof string !== "string") throw new TypeError("Expected a string");
|
|
27683
|
+
let indents = makeIndentsMap(string, true);
|
|
27684
|
+
if (indents.size === 0) indents = makeIndentsMap(string, false);
|
|
27685
|
+
const keyOfMostUsedIndent = getMostUsedKey(indents);
|
|
27686
|
+
let type;
|
|
27687
|
+
let amount = 0;
|
|
27688
|
+
let indent = "";
|
|
27689
|
+
if (keyOfMostUsedIndent !== void 0) {
|
|
27690
|
+
({type, amount} = decodeIndentsKey(keyOfMostUsedIndent));
|
|
27691
|
+
indent = makeIndentString(type, amount);
|
|
27692
|
+
}
|
|
27693
|
+
return {
|
|
27694
|
+
amount,
|
|
27695
|
+
type,
|
|
27696
|
+
indent
|
|
27697
|
+
};
|
|
27698
|
+
}
|
|
27699
|
+
//#endregion
|
|
27700
|
+
//#region ../../node_modules/.pnpm/detect-newline@4.0.1/node_modules/detect-newline/index.js
|
|
27701
|
+
function detectNewline(string) {
|
|
27702
|
+
if (typeof string !== "string") throw new TypeError("Expected a string");
|
|
27703
|
+
const newlines = string.match(/(?:\r?\n)/g) || [];
|
|
27704
|
+
if (newlines.length === 0) return;
|
|
27705
|
+
const crlf = newlines.filter((newline) => newline === "\r\n").length;
|
|
27706
|
+
return crlf > newlines.length - crlf ? "\r\n" : "\n";
|
|
27707
|
+
}
|
|
27708
|
+
function detectNewlineGraceful(string) {
|
|
27709
|
+
return typeof string === "string" && detectNewline(string) || "\n";
|
|
27710
|
+
}
|
|
27711
|
+
//#endregion
|
|
27712
|
+
//#region ../../node_modules/.pnpm/git-hooks-list@4.2.1/node_modules/git-hooks-list/index.json
|
|
27713
|
+
var git_hooks_list_default = [
|
|
27714
|
+
"applypatch-msg",
|
|
27715
|
+
"pre-applypatch",
|
|
27716
|
+
"post-applypatch",
|
|
27717
|
+
"pre-commit",
|
|
27718
|
+
"pre-merge-commit",
|
|
27719
|
+
"prepare-commit-msg",
|
|
27720
|
+
"commit-msg",
|
|
27721
|
+
"post-commit",
|
|
27722
|
+
"pre-rebase",
|
|
27723
|
+
"post-checkout",
|
|
27724
|
+
"post-merge",
|
|
27725
|
+
"pre-push",
|
|
27726
|
+
"pre-receive",
|
|
27727
|
+
"update",
|
|
27728
|
+
"proc-receive",
|
|
27729
|
+
"post-receive",
|
|
27730
|
+
"post-update",
|
|
27731
|
+
"reference-transaction",
|
|
27732
|
+
"push-to-checkout",
|
|
27733
|
+
"pre-auto-gc",
|
|
27734
|
+
"post-rewrite",
|
|
27735
|
+
"sendemail-validate",
|
|
27736
|
+
"fsmonitor-watchman",
|
|
27737
|
+
"p4-changelist",
|
|
27738
|
+
"p4-prepare-changelist",
|
|
27739
|
+
"p4-post-changelist",
|
|
27740
|
+
"p4-pre-submit",
|
|
27741
|
+
"post-index-change"
|
|
27742
|
+
];
|
|
27743
|
+
//#endregion
|
|
27744
|
+
//#region ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
|
|
27745
|
+
function isPlainObject(value) {
|
|
27746
|
+
if (typeof value !== "object" || value === null) return false;
|
|
27747
|
+
const prototype = Object.getPrototypeOf(value);
|
|
27748
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
27749
|
+
}
|
|
27750
|
+
//#endregion
|
|
27751
|
+
//#region ../../node_modules/.pnpm/sort-package-json@4.0.0/node_modules/sort-package-json/index.js
|
|
27752
|
+
var import_compare = /* @__PURE__ */ __toESM(require_compare(), 1);
|
|
27753
|
+
var import_min_version = /* @__PURE__ */ __toESM(require_min_version(), 1);
|
|
27754
|
+
const pipe = (fns) => (x, ...args) => fns.reduce((result, fn) => fn(result, ...args), x);
|
|
27755
|
+
const onArray = (fn) => (x) => Array.isArray(x) ? fn(x) : x;
|
|
27756
|
+
const onStringArray = (fn) => (x) => Array.isArray(x) && x.every((item) => typeof item === "string") ? fn(x) : x;
|
|
27757
|
+
const uniq = onStringArray((xs) => [...new Set(xs)]);
|
|
27758
|
+
const uniqAndSortArray = pipe([uniq, onStringArray((array) => array.toSorted())]);
|
|
27759
|
+
const onObject = (fn) => (x, ...args) => isPlainObject(x) ? fn(x, ...args) : x;
|
|
27760
|
+
const sortObjectBy = (comparator, deep) => {
|
|
27761
|
+
const over = onObject((object) => {
|
|
27762
|
+
if (deep) object = Object.fromEntries(Object.entries(object).map(([key, value]) => [key, over(value)]));
|
|
27763
|
+
return sortObjectByKeyNameList(object, comparator);
|
|
27764
|
+
});
|
|
27765
|
+
return over;
|
|
27766
|
+
};
|
|
27767
|
+
const sortObject = sortObjectBy();
|
|
27768
|
+
const sortURLObject = sortObjectBy(["type", "url"]);
|
|
27769
|
+
const sortPeopleObject = sortObjectBy([
|
|
27770
|
+
"name",
|
|
27771
|
+
"email",
|
|
27772
|
+
"url"
|
|
27773
|
+
]);
|
|
27774
|
+
const sortDirectories = sortObjectBy([
|
|
27775
|
+
"lib",
|
|
27776
|
+
"bin",
|
|
27777
|
+
"man",
|
|
27778
|
+
"doc",
|
|
27779
|
+
"example",
|
|
27780
|
+
"test"
|
|
27781
|
+
]);
|
|
27782
|
+
const overProperty = (property, over) => onObject((object, ...args) => Object.hasOwn(object, property) ? {
|
|
27783
|
+
...object,
|
|
27784
|
+
[property]: over(object[property], ...args)
|
|
27785
|
+
} : object);
|
|
27786
|
+
const sortGitHooks = sortObjectBy(git_hooks_list_default);
|
|
27787
|
+
const parseNameAndVersionRange = (specifier) => {
|
|
27788
|
+
const [nameAndVersion] = specifier.split(">");
|
|
27789
|
+
const atMatches = [...nameAndVersion.matchAll("@")];
|
|
27790
|
+
if (!atMatches.length || atMatches.length === 1 && atMatches[0].index === 0) return { name: specifier };
|
|
27791
|
+
const splitIndex = atMatches.pop().index;
|
|
27792
|
+
return {
|
|
27793
|
+
name: nameAndVersion.substring(0, splitIndex),
|
|
27794
|
+
range: nameAndVersion.substring(splitIndex + 1)
|
|
27795
|
+
};
|
|
27796
|
+
};
|
|
27797
|
+
const sortObjectBySemver = sortObjectBy((a, b) => {
|
|
27798
|
+
const { name: aName, range: aRange } = parseNameAndVersionRange(a);
|
|
27799
|
+
const { name: bName, range: bRange } = parseNameAndVersionRange(b);
|
|
27800
|
+
if (aName !== bName) return aName.localeCompare(bName, "en");
|
|
27801
|
+
if (!aRange) return -1;
|
|
27802
|
+
if (!bRange) return 1;
|
|
27803
|
+
return (0, import_compare.default)((0, import_min_version.default)(aRange), (0, import_min_version.default)(bRange));
|
|
27804
|
+
});
|
|
27805
|
+
const getPackageName = (ident) => {
|
|
27806
|
+
const index = ident.indexOf("@", ident.startsWith("@") ? 1 : 0);
|
|
27807
|
+
return index === -1 ? ident : ident.slice(0, index);
|
|
27808
|
+
};
|
|
27809
|
+
const sortObjectByIdent = (a, b) => {
|
|
27810
|
+
const packageNameA = getPackageName(a);
|
|
27811
|
+
const packageNameB = getPackageName(b);
|
|
27812
|
+
if (packageNameA < packageNameB) return -1;
|
|
27813
|
+
if (packageNameA > packageNameB) return 1;
|
|
27814
|
+
return 0;
|
|
27815
|
+
};
|
|
27816
|
+
const cache$1 = /* @__PURE__ */ new Map();
|
|
27817
|
+
const hasYarnOrPnpmFiles = () => {
|
|
27818
|
+
const cwd = process.cwd();
|
|
27819
|
+
if (!cache$1.has(cwd)) cache$1.set(cwd, fs.existsSync("yarn.lock") || fs.existsSync(".yarn/") || fs.existsSync(".yarnrc.yml") || fs.existsSync("pnpm-lock.yaml") || fs.existsSync("pnpm-workspace.yaml"));
|
|
27820
|
+
return cache$1.get(cwd);
|
|
27821
|
+
};
|
|
27822
|
+
/**
|
|
27823
|
+
* Detects the package manager from package.json and lock files
|
|
27824
|
+
* @param {object} packageJson - The parsed package.json object
|
|
27825
|
+
* @returns {boolean} - The detected package manager. Default to npm if not detected.
|
|
27826
|
+
*/
|
|
27827
|
+
function shouldSortDependenciesLikeNpm(packageJson) {
|
|
27828
|
+
if (typeof packageJson.packageManager === "string") return packageJson.packageManager.startsWith("npm@");
|
|
27829
|
+
if (packageJson.devEngines?.packageManager?.name) return packageJson.devEngines.packageManager.name === "npm";
|
|
27830
|
+
if (packageJson.pnpm) return false;
|
|
27831
|
+
if (packageJson.engines?.npm) return true;
|
|
27832
|
+
if (hasYarnOrPnpmFiles()) return false;
|
|
27833
|
+
return true;
|
|
27834
|
+
}
|
|
27835
|
+
/**
|
|
27836
|
+
* Sort dependencies alphabetically, detecting package manager to use the
|
|
27837
|
+
* appropriate comparison. npm uses locale-aware comparison, yarn and pnpm use
|
|
27838
|
+
* simple string comparison
|
|
27839
|
+
*/
|
|
27840
|
+
const sortDependencies = onObject((dependencies, packageJson) => {
|
|
27841
|
+
if (Object.keys(dependencies).length < 2) return dependencies;
|
|
27842
|
+
if (shouldSortDependenciesLikeNpm(packageJson)) return sortObjectByKeyNameList(dependencies, (a, b) => a.localeCompare(b, "en"));
|
|
27843
|
+
return sortObjectByKeyNameList(dependencies);
|
|
27844
|
+
});
|
|
27845
|
+
/**
|
|
27846
|
+
* "workspaces" can be an array (npm or yarn classic) or an object (pnpm/bun).
|
|
27847
|
+
* In the case of an array, we do not want to alphabetically sort it in case
|
|
27848
|
+
* scripts need to run in a specific order.
|
|
27849
|
+
*
|
|
27850
|
+
* @see https://docs.npmjs.com/cli/v7/using-npm/workspaces?v=true#running-commands-in-the-context-of-workspaces
|
|
27851
|
+
*/
|
|
27852
|
+
const sortWorkspaces = pipe([
|
|
27853
|
+
sortObjectBy(["packages", "catalog"]),
|
|
27854
|
+
overProperty("packages", uniqAndSortArray),
|
|
27855
|
+
overProperty("catalog", sortDependencies)
|
|
27856
|
+
]);
|
|
27857
|
+
const sortEslintConfig = pipe([
|
|
27858
|
+
sortObjectBy([
|
|
27859
|
+
"files",
|
|
27860
|
+
"excludedFiles",
|
|
27861
|
+
"env",
|
|
27862
|
+
"parser",
|
|
27863
|
+
"parserOptions",
|
|
27864
|
+
"settings",
|
|
27865
|
+
"plugins",
|
|
27866
|
+
"extends",
|
|
27867
|
+
"rules",
|
|
27868
|
+
"overrides",
|
|
27869
|
+
"globals",
|
|
27870
|
+
"processor",
|
|
27871
|
+
"noInlineConfig",
|
|
27872
|
+
"reportUnusedDisableDirectives"
|
|
27873
|
+
]),
|
|
27874
|
+
overProperty("env", sortObject),
|
|
27875
|
+
overProperty("globals", sortObject),
|
|
27876
|
+
overProperty("overrides", onArray((overrides) => overrides.map(sortEslintConfig))),
|
|
27877
|
+
overProperty("parserOptions", sortObject),
|
|
27878
|
+
overProperty("rules", sortObjectBy((rule1, rule2) => rule1.split("/").length - rule2.split("/").length || rule1.localeCompare(rule2))),
|
|
27879
|
+
overProperty("settings", sortObject)
|
|
27880
|
+
]);
|
|
27881
|
+
const sortVSCodeBadgeObject = sortObjectBy([
|
|
27882
|
+
"description",
|
|
27883
|
+
"url",
|
|
27884
|
+
"href"
|
|
27885
|
+
]);
|
|
27886
|
+
const sortPrettierConfig = pipe([onObject((config) => sortObjectByKeyNameList(config, [...Object.keys(config).filter((key) => key !== "overrides").sort(), "overrides"])), overProperty("overrides", onArray((overrides) => overrides.map(pipe([sortObject, overProperty("options", sortObject)]))))]);
|
|
27887
|
+
const sortVolta = sortObjectBy([
|
|
27888
|
+
"node",
|
|
27889
|
+
"npm",
|
|
27890
|
+
"yarn"
|
|
27891
|
+
]);
|
|
27892
|
+
const sortWireitScript = pipe([
|
|
27893
|
+
sortObjectBy([
|
|
27894
|
+
"command",
|
|
27895
|
+
"dependencies",
|
|
27896
|
+
"files",
|
|
27897
|
+
"output"
|
|
27898
|
+
]),
|
|
27899
|
+
overProperty("dependencies", onArray((deps) => deps.map(sortObjectBy(["script", "cascade"])))),
|
|
27900
|
+
overProperty("env", onObject((env) => sortObjectByKeyNameList(Object.fromEntries(Object.entries(env).map(([key, value]) => [key, sortObjectBy(["external", "default"])(value)]))))),
|
|
27901
|
+
overProperty("service", pipe([sortObjectBy(["readyWhen"]), overProperty("readyWhen", sortObject)]))
|
|
27902
|
+
]);
|
|
27903
|
+
const sortWireit = onObject((wireit) => sortObjectByKeyNameList(Object.fromEntries(Object.entries(wireit).map(([name, config]) => [name, sortWireitScript(config)]))));
|
|
27904
|
+
const sortDevEngines = overProperty("packageManager", sortObjectBy([
|
|
27905
|
+
"name",
|
|
27906
|
+
"version",
|
|
27907
|
+
"onFail"
|
|
27908
|
+
]));
|
|
27909
|
+
const sortPnpmConfig = pipe([sortObjectBy([
|
|
27910
|
+
"peerDependencyRules",
|
|
27911
|
+
"neverBuiltDependencies",
|
|
27912
|
+
"onlyBuiltDependencies",
|
|
27913
|
+
"onlyBuiltDependenciesFile",
|
|
27914
|
+
"allowedDeprecatedVersions",
|
|
27915
|
+
"allowNonAppliedPatches",
|
|
27916
|
+
"updateConfig",
|
|
27917
|
+
"auditConfig",
|
|
27918
|
+
"requiredScripts",
|
|
27919
|
+
"supportedArchitectures",
|
|
27920
|
+
"overrides",
|
|
27921
|
+
"patchedDependencies",
|
|
27922
|
+
"packageExtensions"
|
|
27923
|
+
], true), overProperty("overrides", sortObjectBySemver)]);
|
|
27924
|
+
const defaultNpmScripts = /* @__PURE__ */ new Set([
|
|
27925
|
+
"install",
|
|
27926
|
+
"pack",
|
|
27927
|
+
"prepare",
|
|
27928
|
+
"publish",
|
|
27929
|
+
"restart",
|
|
27930
|
+
"shrinkwrap",
|
|
27931
|
+
"start",
|
|
27932
|
+
"stop",
|
|
27933
|
+
"test",
|
|
27934
|
+
"uninstall",
|
|
27935
|
+
"version"
|
|
27936
|
+
]);
|
|
27937
|
+
const hasDevDependency = (dependency, packageJson) => {
|
|
27938
|
+
return Object.hasOwn(packageJson, "devDependencies") && Object.hasOwn(packageJson.devDependencies, dependency);
|
|
27237
27939
|
};
|
|
27238
27940
|
const runSRegExp = /(?<=^|[\s&;<>|(])(?:run-s|npm-run-all2? .*(?:--sequential|--serial|-s))(?=$|[\s&;<>|)])/;
|
|
27239
27941
|
const isSequentialScript = (command) => command.includes("*") && runSRegExp.test(command);
|
|
@@ -27591,803 +28293,263 @@ const fields = [
|
|
|
27591
28293
|
{
|
|
27592
28294
|
key: "publishConfig",
|
|
27593
28295
|
over: sortObject
|
|
27594
|
-
},
|
|
27595
|
-
{ key: "icon" },
|
|
27596
|
-
{
|
|
27597
|
-
key: "badges",
|
|
27598
|
-
over: onArray((badge) => badge.map(sortVSCodeBadgeObject))
|
|
27599
|
-
},
|
|
27600
|
-
{
|
|
27601
|
-
key: "galleryBanner",
|
|
27602
|
-
over: sortObject
|
|
27603
|
-
},
|
|
27604
|
-
{ key: "preview" },
|
|
27605
|
-
{ key: "markdown" },
|
|
27606
|
-
{
|
|
27607
|
-
key: "pnpm",
|
|
27608
|
-
over: sortPnpmConfig
|
|
27609
|
-
}
|
|
27610
|
-
];
|
|
27611
|
-
const defaultSortOrder = fields.map(({ key }) => key);
|
|
27612
|
-
const overFields = pipe(fields.map(({ key, over }) => over ? overProperty(key, over) : void 0).filter(Boolean));
|
|
27613
|
-
function editStringJSON(json, over) {
|
|
27614
|
-
if (typeof json === "string") {
|
|
27615
|
-
const { indent, type } = detectIndent(json);
|
|
27616
|
-
const endCharacters = json.slice(-1) === "\n" ? "\n" : "";
|
|
27617
|
-
const newline = detectNewlineGraceful(json);
|
|
27618
|
-
json = JSON.parse(json);
|
|
27619
|
-
let result = JSON.stringify(over(json), null, type === "tab" ? " " : indent) + endCharacters;
|
|
27620
|
-
if (newline === "\r\n") result = result.replace(/\n/g, newline);
|
|
27621
|
-
return result;
|
|
27622
|
-
}
|
|
27623
|
-
return over(json);
|
|
27624
|
-
}
|
|
27625
|
-
function sortPackageJson(jsonIsh, options = {}) {
|
|
27626
|
-
return editStringJSON(jsonIsh, onObject((json) => {
|
|
27627
|
-
let sortOrder = options.sortOrder || defaultSortOrder;
|
|
27628
|
-
if (Array.isArray(sortOrder)) {
|
|
27629
|
-
const keys = Object.keys(json);
|
|
27630
|
-
const { privateKeys = [], publicKeys = [] } = Object.groupBy(keys, (key) => key[0] === "_" ? "privateKeys" : "publicKeys");
|
|
27631
|
-
sortOrder = [
|
|
27632
|
-
...sortOrder,
|
|
27633
|
-
...defaultSortOrder,
|
|
27634
|
-
...publicKeys.sort(),
|
|
27635
|
-
...privateKeys.sort()
|
|
27636
|
-
];
|
|
27637
|
-
}
|
|
27638
|
-
return overFields(sortObjectByKeyNameList(json, sortOrder), json);
|
|
27639
|
-
}));
|
|
27640
|
-
}
|
|
27641
|
-
//#endregion
|
|
27642
|
-
//#region src/actions/deplint/packageJsonEditor.ts
|
|
27643
|
-
function readPackageJson$5(location) {
|
|
27644
|
-
return JSON.parse(fs.readFileSync(`${location}/package.json`, "utf8"));
|
|
27645
|
-
}
|
|
27646
|
-
function writePackageJson$2(location, pkg) {
|
|
27647
|
-
const sorted = sortPackageJson(JSON.stringify(pkg, null, 2));
|
|
27648
|
-
fs.writeFileSync(`${location}/package.json`, `${sorted}\n`);
|
|
27649
|
-
}
|
|
27650
|
-
/**
|
|
27651
|
-
* Move a dependency from one section to another (e.g. dependencies → devDependencies).
|
|
27652
|
-
* When moving out of `peerDependencies`, the corresponding
|
|
27653
|
-
* `peerDependenciesMeta` entry is cleared so it does not dangle.
|
|
27654
|
-
*/
|
|
27655
|
-
function moveDep(pkg, dep, from, to) {
|
|
27656
|
-
const fromSection = pkg[from];
|
|
27657
|
-
if (!fromSection || !Object.hasOwn(fromSection, dep)) return;
|
|
27658
|
-
const version = fromSection[dep];
|
|
27659
|
-
delete fromSection[dep];
|
|
27660
|
-
if (Object.keys(fromSection).length === 0) delete pkg[from];
|
|
27661
|
-
const toSection = pkg[to] ?? {};
|
|
27662
|
-
toSection[dep] = version;
|
|
27663
|
-
pkg[to] = toSection;
|
|
27664
|
-
if (from === "peerDependencies" && to !== "peerDependencies") removePeerMeta(pkg, dep);
|
|
27665
|
-
}
|
|
27666
|
-
/**
|
|
27667
|
-
* Remove a dependency from a section. When the section is `peerDependencies`,
|
|
27668
|
-
* also strip any matching `peerDependenciesMeta` entry so meta does not
|
|
27669
|
-
* dangle for a peer that is no longer declared.
|
|
27670
|
-
*/
|
|
27671
|
-
function removeDep(pkg, dep, section) {
|
|
27672
|
-
const sectionObj = pkg[section];
|
|
27673
|
-
if (!sectionObj || !Object.hasOwn(sectionObj, dep)) return;
|
|
27674
|
-
delete sectionObj[dep];
|
|
27675
|
-
if (Object.keys(sectionObj).length === 0) delete pkg[section];
|
|
27676
|
-
if (section === "peerDependencies") removePeerMeta(pkg, dep);
|
|
27677
|
-
}
|
|
27678
|
-
/**
|
|
27679
|
-
* Add a dependency to a section with a resolved version.
|
|
27680
|
-
*/
|
|
27681
|
-
function addDep(pkg, dep, version, section) {
|
|
27682
|
-
const sectionObj = pkg[section] ?? {};
|
|
27683
|
-
sectionObj[dep] = version;
|
|
27684
|
-
pkg[section] = sectionObj;
|
|
27685
|
-
}
|
|
27686
|
-
/**
|
|
27687
|
-
* Set or clear `peerDependenciesMeta[dep].optional`. Only meaningful for
|
|
27688
|
-
* peers declared in `peerDependencies`.
|
|
27689
|
-
*
|
|
27690
|
-
* - `optional === true` → ensure `{ optional: true }` is set.
|
|
27691
|
-
* - `optional === false` → clear any optional flag (and the entry itself if
|
|
27692
|
-
* it would otherwise be `{}`).
|
|
27693
|
-
* - `optional === undefined` → no-op; existing meta is preserved.
|
|
27694
|
-
*/
|
|
27695
|
-
function setPeerOptional(pkg, dep, optional) {
|
|
27696
|
-
if (optional === void 0) return;
|
|
27697
|
-
if (optional) {
|
|
27698
|
-
const meta = pkg.peerDependenciesMeta ?? {};
|
|
27699
|
-
const entry = meta[dep] ?? {};
|
|
27700
|
-
entry.optional = true;
|
|
27701
|
-
meta[dep] = entry;
|
|
27702
|
-
pkg.peerDependenciesMeta = meta;
|
|
27703
|
-
return;
|
|
27704
|
-
}
|
|
27705
|
-
const meta = pkg.peerDependenciesMeta;
|
|
27706
|
-
if (!meta || !Object.hasOwn(meta, dep)) return;
|
|
27707
|
-
delete meta[dep].optional;
|
|
27708
|
-
if (Object.keys(meta[dep]).length === 0) delete meta[dep];
|
|
27709
|
-
if (Object.keys(meta).length === 0) delete pkg.peerDependenciesMeta;
|
|
27710
|
-
}
|
|
27711
|
-
function removePeerMeta(pkg, dep) {
|
|
27712
|
-
const meta = pkg.peerDependenciesMeta;
|
|
27713
|
-
if (!meta || !Object.hasOwn(meta, dep)) return;
|
|
27714
|
-
delete meta[dep];
|
|
27715
|
-
if (Object.keys(meta).length === 0) delete pkg.peerDependenciesMeta;
|
|
27716
|
-
}
|
|
27717
|
-
const OPAQUE_VERSION_PREFIXES = [
|
|
27718
|
-
"catalog:",
|
|
27719
|
-
"file:",
|
|
27720
|
-
"link:",
|
|
27721
|
-
"npm:",
|
|
27722
|
-
"patch:",
|
|
27723
|
-
"portal:",
|
|
27724
|
-
"workspace:"
|
|
27725
|
-
];
|
|
27726
|
-
function normalizedVersionSpec(version) {
|
|
27727
|
-
const normalized = version?.trim();
|
|
27728
|
-
return normalized != null && normalized.length > 0 ? normalized : void 0;
|
|
27729
|
-
}
|
|
27730
|
-
function isOpaqueVersionSpec(version) {
|
|
27731
|
-
const spec = normalizedVersionSpec(version);
|
|
27732
|
-
if (spec === void 0) return true;
|
|
27733
|
-
if (OPAQUE_VERSION_PREFIXES.some((prefix) => spec.startsWith(prefix))) return true;
|
|
27734
|
-
if (spec.includes("://")) return true;
|
|
27735
|
-
if (/^(?:git\+|git:|github:|gitlab:|bitbucket:|ssh:)/.test(spec)) return true;
|
|
27736
|
-
return /^[\w.-]+\/[\w./-]+(?:#.+)?$/.test(spec);
|
|
27737
|
-
}
|
|
27738
|
-
function resolveRangeLowerBound(version) {
|
|
27739
|
-
const spec = normalizedVersionSpec(version);
|
|
27740
|
-
if (spec === void 0 || spec === "*" || isOpaqueVersionSpec(spec)) return void 0;
|
|
27741
|
-
try {
|
|
27742
|
-
return import_semver.default.minVersion(spec)?.version;
|
|
27743
|
-
} catch {
|
|
27744
|
-
return;
|
|
27745
|
-
}
|
|
27746
|
-
}
|
|
27747
|
-
function formatFullVersion(version) {
|
|
27748
|
-
if (version == null || version.length === 0) return void 0;
|
|
27749
|
-
return import_semver.default.parse(version)?.version;
|
|
27750
|
-
}
|
|
27751
|
-
/**
|
|
27752
|
-
* Format an installed version as a broad peerDependency range. The upper
|
|
27753
|
-
* bound is the next major (`'major'`, default) or next minor (`'minor'`):
|
|
27754
|
-
* 5.5.1, 'major' -> '>=5.5.1 <6'
|
|
27755
|
-
* 0.5.1, 'major' -> '>=0.5.1 <1'
|
|
27756
|
-
* 7.11.5, 'minor' -> '>=7.11.5 <7.12'
|
|
27757
|
-
* 5.5.1-beta.0, 'major' -> '>=5.5.1-beta.0 <6'
|
|
27758
|
-
* Falls back to `~<version>` if the version cannot be parsed.
|
|
27759
|
-
*/
|
|
27760
|
-
function formatPeerRange(version, boundType = "major") {
|
|
27761
|
-
const parsed = import_semver.default.parse(version);
|
|
27762
|
-
if (!parsed) return `~${version}`;
|
|
27763
|
-
if (boundType === "minor") return `>=${parsed.version} <${parsed.major}.${parsed.minor + 1}`;
|
|
27764
|
-
return `>=${parsed.version} <${parsed.major + 1}`;
|
|
27765
|
-
}
|
|
27766
|
-
/**
|
|
27767
|
-
* Pick the peer-range upper-bound style based on the devDependency's range
|
|
27768
|
-
* prefix. `~` devDeps narrow to the next minor; everything else (including
|
|
27769
|
-
* `^`, exact pins, and absent ranges) defaults to the next major.
|
|
27770
|
-
*/
|
|
27771
|
-
function inferPeerBoundType(devRange) {
|
|
27772
|
-
return devRange?.startsWith("~") ?? false ? "minor" : "major";
|
|
27773
|
-
}
|
|
27774
|
-
function readInstalledVersion(location, dep) {
|
|
27775
|
-
const depPkgPath = findDepPackageJson(location, dep);
|
|
27776
|
-
if (depPkgPath == null || depPkgPath.length === 0) return void 0;
|
|
27777
|
-
try {
|
|
27778
|
-
return JSON.parse(fs.readFileSync(depPkgPath, "utf8")).version;
|
|
27779
|
-
} catch {
|
|
27780
|
-
return;
|
|
28296
|
+
},
|
|
28297
|
+
{ key: "icon" },
|
|
28298
|
+
{
|
|
28299
|
+
key: "badges",
|
|
28300
|
+
over: onArray((badge) => badge.map(sortVSCodeBadgeObject))
|
|
28301
|
+
},
|
|
28302
|
+
{
|
|
28303
|
+
key: "galleryBanner",
|
|
28304
|
+
over: sortObject
|
|
28305
|
+
},
|
|
28306
|
+
{ key: "preview" },
|
|
28307
|
+
{ key: "markdown" },
|
|
28308
|
+
{
|
|
28309
|
+
key: "pnpm",
|
|
28310
|
+
over: sortPnpmConfig
|
|
27781
28311
|
}
|
|
28312
|
+
];
|
|
28313
|
+
const defaultSortOrder = fields.map(({ key }) => key);
|
|
28314
|
+
const overFields = pipe(fields.map(({ key, over }) => over ? overProperty(key, over) : void 0).filter(Boolean));
|
|
28315
|
+
function editStringJSON(json, over) {
|
|
28316
|
+
if (typeof json === "string") {
|
|
28317
|
+
const { indent, type } = detectIndent(json);
|
|
28318
|
+
const endCharacters = json.slice(-1) === "\n" ? "\n" : "";
|
|
28319
|
+
const newline = detectNewlineGraceful(json);
|
|
28320
|
+
json = JSON.parse(json);
|
|
28321
|
+
let result = JSON.stringify(over(json), null, type === "tab" ? " " : indent) + endCharacters;
|
|
28322
|
+
if (newline === "\r\n") result = result.replace(/\n/g, newline);
|
|
28323
|
+
return result;
|
|
28324
|
+
}
|
|
28325
|
+
return over(json);
|
|
27782
28326
|
}
|
|
27783
|
-
|
|
27784
|
-
|
|
27785
|
-
|
|
27786
|
-
|
|
27787
|
-
|
|
27788
|
-
|
|
27789
|
-
|
|
27790
|
-
|
|
27791
|
-
|
|
27792
|
-
|
|
27793
|
-
|
|
27794
|
-
|
|
27795
|
-
|
|
27796
|
-
|
|
27797
|
-
|
|
27798
|
-
* Compute the expected dependency/devDependency range. External package
|
|
27799
|
-
* entries use a tilde range pinned to a full three-part lower bound.
|
|
27800
|
-
*/
|
|
27801
|
-
function resolveExpectedDependencyVersion(location, dep, range) {
|
|
27802
|
-
const version = formatFullVersion(resolveRangeLowerBound(range) ?? readInstalledVersion(location, dep));
|
|
27803
|
-
return version ? `~${version}` : "*";
|
|
28327
|
+
function sortPackageJson(jsonIsh, options = {}) {
|
|
28328
|
+
return editStringJSON(jsonIsh, onObject((json) => {
|
|
28329
|
+
let sortOrder = options.sortOrder || defaultSortOrder;
|
|
28330
|
+
if (Array.isArray(sortOrder)) {
|
|
28331
|
+
const keys = Object.keys(json);
|
|
28332
|
+
const { privateKeys = [], publicKeys = [] } = Object.groupBy(keys, (key) => key[0] === "_" ? "privateKeys" : "publicKeys");
|
|
28333
|
+
sortOrder = [
|
|
28334
|
+
...sortOrder,
|
|
28335
|
+
...defaultSortOrder,
|
|
28336
|
+
...publicKeys.sort(),
|
|
28337
|
+
...privateKeys.sort()
|
|
28338
|
+
];
|
|
28339
|
+
}
|
|
28340
|
+
return overFields(sortObjectByKeyNameList(json, sortOrder), json);
|
|
28341
|
+
}));
|
|
27804
28342
|
}
|
|
27805
|
-
|
|
27806
|
-
|
|
27807
|
-
|
|
27808
|
-
|
|
27809
|
-
function resolveDepVersion(location, dep) {
|
|
27810
|
-
return resolveExpectedDependencyVersion(location, dep);
|
|
28343
|
+
//#endregion
|
|
28344
|
+
//#region src/actions/deplint/packageJsonEditor.ts
|
|
28345
|
+
function readPackageJson$4(location) {
|
|
28346
|
+
return JSON.parse(fs.readFileSync(`${location}/package.json`, "utf8"));
|
|
27811
28347
|
}
|
|
27812
|
-
|
|
27813
|
-
|
|
27814
|
-
|
|
27815
|
-
* superset of devDep), otherwise the installed version. Produces
|
|
27816
|
-
* `>=<lowerBound> <<major+1>`; falls back to '*' if nothing is known.
|
|
27817
|
-
*/
|
|
27818
|
-
function resolveExpectedPeerVersion(location, dep, devRange, boundType) {
|
|
27819
|
-
const lower = resolvePeerLowerBound(location, dep, devRange);
|
|
27820
|
-
return lower != null && lower.length > 0 ? formatPeerRange(lower, boundType ?? inferPeerBoundType(devRange)) : "*";
|
|
28348
|
+
function writePackageJson$2(location, pkg) {
|
|
28349
|
+
const sorted = sortPackageJson(JSON.stringify(pkg, null, 2));
|
|
28350
|
+
fs.writeFileSync(`${location}/package.json`, `${sorted}\n`);
|
|
27821
28351
|
}
|
|
27822
28352
|
/**
|
|
27823
|
-
*
|
|
27824
|
-
*
|
|
27825
|
-
*
|
|
27826
|
-
* installed version.
|
|
28353
|
+
* Move a dependency from one section to another (e.g. dependencies → devDependencies).
|
|
28354
|
+
* When moving out of `peerDependencies`, the corresponding
|
|
28355
|
+
* `peerDependenciesMeta` entry is cleared so it does not dangle.
|
|
27827
28356
|
*/
|
|
27828
|
-
function
|
|
27829
|
-
const
|
|
27830
|
-
if (
|
|
27831
|
-
const version =
|
|
27832
|
-
|
|
28357
|
+
function moveDep(pkg, dep, from, to) {
|
|
28358
|
+
const fromSection = pkg[from];
|
|
28359
|
+
if (!fromSection || !Object.hasOwn(fromSection, dep)) return;
|
|
28360
|
+
const version = fromSection[dep];
|
|
28361
|
+
delete fromSection[dep];
|
|
28362
|
+
if (Object.keys(fromSection).length === 0) delete pkg[from];
|
|
28363
|
+
const toSection = pkg[to] ?? {};
|
|
28364
|
+
toSection[dep] = version;
|
|
28365
|
+
pkg[to] = toSection;
|
|
28366
|
+
if (from === "peerDependencies" && to !== "peerDependencies") removePeerMeta(pkg, dep);
|
|
27833
28367
|
}
|
|
27834
28368
|
/**
|
|
27835
|
-
*
|
|
27836
|
-
*
|
|
27837
|
-
*
|
|
27838
|
-
* fix in a second pass. That removes the 2-pass cascade that could oscillate
|
|
27839
|
-
* when an upstream rule re-fired on every pass.
|
|
28369
|
+
* Remove a dependency from a section. When the section is `peerDependencies`,
|
|
28370
|
+
* also strip any matching `peerDependenciesMeta` entry so meta does not
|
|
28371
|
+
* dangle for a peer that is no longer declared.
|
|
27840
28372
|
*/
|
|
27841
|
-
function
|
|
27842
|
-
|
|
28373
|
+
function removeDep(pkg, dep, section) {
|
|
28374
|
+
const sectionObj = pkg[section];
|
|
28375
|
+
if (!sectionObj || !Object.hasOwn(sectionObj, dep)) return;
|
|
28376
|
+
delete sectionObj[dep];
|
|
28377
|
+
if (Object.keys(sectionObj).length === 0) delete pkg[section];
|
|
28378
|
+
if (section === "peerDependencies") removePeerMeta(pkg, dep);
|
|
27843
28379
|
}
|
|
27844
28380
|
/**
|
|
27845
|
-
*
|
|
27846
|
-
* the installed peer. Returns `~<major>.<minor>` (e.g. `~7.6`); falls back to
|
|
27847
|
-
* `~<version>` if parsing fails or '*' if no installed version is found.
|
|
28381
|
+
* Add a dependency to a section with a resolved version.
|
|
27848
28382
|
*/
|
|
27849
|
-
function
|
|
27850
|
-
|
|
27851
|
-
|
|
27852
|
-
|
|
27853
|
-
//#region src/actions/deplint/packageEditor.ts
|
|
27854
|
-
var DeplintPackageEditor = class {
|
|
27855
|
-
dirty = false;
|
|
27856
|
-
pkg;
|
|
27857
|
-
workspace;
|
|
27858
|
-
constructor(workspace) {
|
|
27859
|
-
this.workspace = workspace;
|
|
27860
|
-
this.pkg = readPackageJson$5(workspace.location);
|
|
27861
|
-
}
|
|
27862
|
-
applyFix(fix) {
|
|
27863
|
-
const before = JSON.stringify(this.pkg);
|
|
27864
|
-
switch (fix.action) {
|
|
27865
|
-
case "add":
|
|
27866
|
-
addDep(this.pkg, fix.dependency, fix.version, fix.section);
|
|
27867
|
-
if (fix.section === "peerDependencies") setPeerOptional(this.pkg, fix.dependency, fix.optional);
|
|
27868
|
-
break;
|
|
27869
|
-
case "move":
|
|
27870
|
-
moveDep(this.pkg, fix.dependency, fix.fromSection, fix.toSection);
|
|
27871
|
-
if (fix.version !== void 0 && this.pkg[fix.toSection]?.[fix.dependency] !== void 0) this.pkg[fix.toSection][fix.dependency] = fix.version;
|
|
27872
|
-
if (fix.toSection === "peerDependencies") setPeerOptional(this.pkg, fix.dependency, fix.optional);
|
|
27873
|
-
break;
|
|
27874
|
-
case "remove":
|
|
27875
|
-
removeDep(this.pkg, fix.dependency, fix.section);
|
|
27876
|
-
break;
|
|
27877
|
-
case "set-version":
|
|
27878
|
-
if (this.pkg[fix.section]?.[fix.dependency] !== void 0) addDep(this.pkg, fix.dependency, fix.version, fix.section);
|
|
27879
|
-
break;
|
|
27880
|
-
case "resolve-peer-bump": break;
|
|
27881
|
-
}
|
|
27882
|
-
if (JSON.stringify(this.pkg) === before) return void 0;
|
|
27883
|
-
this.dirty = true;
|
|
27884
|
-
return {
|
|
27885
|
-
dependency: fix.dependency,
|
|
27886
|
-
detail: fix.detail,
|
|
27887
|
-
workspace: this.workspace
|
|
27888
|
-
};
|
|
27889
|
-
}
|
|
27890
|
-
save() {
|
|
27891
|
-
if (!this.dirty) return;
|
|
27892
|
-
writePackageJson$2(this.workspace.location, this.pkg);
|
|
27893
|
-
}
|
|
27894
|
-
};
|
|
27895
|
-
//#endregion
|
|
27896
|
-
//#region src/actions/deplint/fixer.ts
|
|
27897
|
-
function applyDeplintFixes(diagnostics) {
|
|
27898
|
-
const editors = /* @__PURE__ */ new Map();
|
|
27899
|
-
const applied = [];
|
|
27900
|
-
for (const diagnostic of diagnostics) {
|
|
27901
|
-
const fixes = diagnostic.fixes ?? [];
|
|
27902
|
-
for (const fix of fixes) {
|
|
27903
|
-
const workspaceKey = diagnostic.workspace.location;
|
|
27904
|
-
let editor = editors.get(workspaceKey);
|
|
27905
|
-
if (!editor) {
|
|
27906
|
-
editor = new DeplintPackageEditor(diagnostic.workspace);
|
|
27907
|
-
editors.set(workspaceKey, editor);
|
|
27908
|
-
}
|
|
27909
|
-
const appliedFix = editor.applyFix(fix);
|
|
27910
|
-
if (appliedFix) applied.push(appliedFix);
|
|
27911
|
-
}
|
|
27912
|
-
}
|
|
27913
|
-
for (const editor of editors.values()) editor.save();
|
|
27914
|
-
return applied;
|
|
27915
|
-
}
|
|
27916
|
-
//#endregion
|
|
27917
|
-
//#region src/actions/deplint/ruleConfig.ts
|
|
27918
|
-
const VALID_RULE_LEVELS$1 = /* @__PURE__ */ new Set([
|
|
27919
|
-
"off",
|
|
27920
|
-
"warn",
|
|
27921
|
-
"error"
|
|
27922
|
-
]);
|
|
27923
|
-
const VALID_RANGE_BOUNDS = /* @__PURE__ */ new Set([
|
|
27924
|
-
"infer",
|
|
27925
|
-
"major",
|
|
27926
|
-
"minor"
|
|
27927
|
-
]);
|
|
27928
|
-
const VALID_RANGE_FORMS = /* @__PURE__ */ new Set(["broad", "shorthand"]);
|
|
27929
|
-
const VALID_WORKSPACE_PROTOCOLS = /* @__PURE__ */ new Set([
|
|
27930
|
-
"workspace:~",
|
|
27931
|
-
"workspace:^",
|
|
27932
|
-
"workspace:*"
|
|
27933
|
-
]);
|
|
27934
|
-
const deprecatedDeplintRuleWarnings = /* @__PURE__ */ new Set();
|
|
27935
|
-
const BUILT_IN_RULE_OPTION_KEYS = {
|
|
27936
|
-
"dep.dependencies.range-style": /* @__PURE__ */ new Set(["ignore"]),
|
|
27937
|
-
"dep.devDependencies.range-style": /* @__PURE__ */ new Set(["ignore"]),
|
|
27938
|
-
"dep.peerDependencies.range-style": /* @__PURE__ */ new Set([
|
|
27939
|
-
"bound",
|
|
27940
|
-
"form",
|
|
27941
|
-
"ignore"
|
|
27942
|
-
]),
|
|
27943
|
-
"dep.workspace.protocol": /* @__PURE__ */ new Set(["ignore", "protocol"])
|
|
27944
|
-
};
|
|
27945
|
-
function isRecord$4(value) {
|
|
27946
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27947
|
-
}
|
|
27948
|
-
function isRuleLevel$3(value) {
|
|
27949
|
-
return typeof value === "string" && VALID_RULE_LEVELS$1.has(value);
|
|
27950
|
-
}
|
|
27951
|
-
function severityFromLevel$1(level) {
|
|
27952
|
-
return level === "warn" ? "warning" : "error";
|
|
27953
|
-
}
|
|
27954
|
-
function formatRuleConfigLocation$1(ruleId) {
|
|
27955
|
-
return `commands.deplint.rules["${ruleId}"]`;
|
|
27956
|
-
}
|
|
27957
|
-
function deprecatedDeplintRuleAlias(ruleId) {
|
|
27958
|
-
return ruleId.startsWith("dep.") ? `deplint.${ruleId.slice(4)}` : void 0;
|
|
27959
|
-
}
|
|
27960
|
-
function canonicalDeplintRuleId(ruleId) {
|
|
27961
|
-
return ruleId.startsWith("deplint.") ? `dep.${ruleId.slice(8)}` : ruleId;
|
|
27962
|
-
}
|
|
27963
|
-
function warnDeprecatedDeplintRuleId(ruleId, canonicalRuleId) {
|
|
27964
|
-
const key = `${ruleId}:${canonicalRuleId}`;
|
|
27965
|
-
if (deprecatedDeplintRuleWarnings.has(key)) return;
|
|
27966
|
-
deprecatedDeplintRuleWarnings.add(key);
|
|
27967
|
-
console.warn(`Deprecated: commands.deplint.rules["${ruleId}"] is deprecated; use commands.deplint.rules["${canonicalRuleId}"] instead.`);
|
|
27968
|
-
}
|
|
27969
|
-
function parseRuleConfig$1(ruleId, value) {
|
|
27970
|
-
if (typeof value === "string") {
|
|
27971
|
-
if (!isRuleLevel$3(value)) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} must be one of "off", "warn", or "error"`);
|
|
27972
|
-
return {
|
|
27973
|
-
level: value,
|
|
27974
|
-
options: {}
|
|
27975
|
-
};
|
|
27976
|
-
}
|
|
27977
|
-
if (Array.isArray(value)) {
|
|
27978
|
-
if (value.length !== 2) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} tuple must be [level, options]`);
|
|
27979
|
-
const level = value[0];
|
|
27980
|
-
if (!isRuleLevel$3(level)) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} level must be one of "off", "warn", or "error"`);
|
|
27981
|
-
const options = value[1];
|
|
27982
|
-
if (!isRecord$4(options)) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} options must be an object`);
|
|
27983
|
-
return {
|
|
27984
|
-
level,
|
|
27985
|
-
options: { ...options }
|
|
27986
|
-
};
|
|
27987
|
-
}
|
|
27988
|
-
throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} must be a level or [level, options] tuple`);
|
|
27989
|
-
}
|
|
27990
|
-
function validateIgnore$1(ruleId, options) {
|
|
27991
|
-
if (options.ignore === void 0) return;
|
|
27992
|
-
if (!Array.isArray(options.ignore) || options.ignore.some((pattern) => typeof pattern !== "string")) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)}.ignore must be an array of strings`);
|
|
27993
|
-
}
|
|
27994
|
-
function validateBuiltInOptions(ruleId, options, builtInRuleIds) {
|
|
27995
|
-
validateIgnore$1(ruleId, options);
|
|
27996
|
-
if (!builtInRuleIds.has(ruleId)) return;
|
|
27997
|
-
const allowedKeys = BUILT_IN_RULE_OPTION_KEYS[ruleId] ?? /* @__PURE__ */ new Set(["ignore"]);
|
|
27998
|
-
for (const key of Object.keys(options)) if (!allowedKeys.has(key)) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)} has unknown option "${key}"`);
|
|
27999
|
-
if (ruleId === "dep.peerDependencies.range-style" && options.bound !== void 0 && (typeof options.bound !== "string" || !VALID_RANGE_BOUNDS.has(options.bound))) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)}.bound must be "infer", "major", or "minor"`);
|
|
28000
|
-
if (ruleId === "dep.peerDependencies.range-style" && options.form !== void 0 && (typeof options.form !== "string" || !VALID_RANGE_FORMS.has(options.form))) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)}.form must be "broad" or "shorthand"`);
|
|
28001
|
-
if (ruleId === "dep.workspace.protocol" && options.protocol !== void 0 && (typeof options.protocol !== "string" || !VALID_WORKSPACE_PROTOCOLS.has(options.protocol))) throw new TypeError(`${formatRuleConfigLocation$1(ruleId)}.protocol must be "workspace:~", "workspace:^", or "workspace:*"`);
|
|
28002
|
-
}
|
|
28003
|
-
function normalizeRuleConfigs(ruleConfigs, ruleIds) {
|
|
28004
|
-
const normalized = {};
|
|
28005
|
-
for (const [ruleId, config] of Object.entries(ruleConfigs)) {
|
|
28006
|
-
const canonicalId = canonicalDeplintRuleId(ruleId);
|
|
28007
|
-
if (!ruleIds.has(canonicalId)) {
|
|
28008
|
-
normalized[ruleId] = config;
|
|
28009
|
-
continue;
|
|
28010
|
-
}
|
|
28011
|
-
if (canonicalId !== ruleId && ruleConfigs[canonicalId] !== void 0) continue;
|
|
28012
|
-
if (canonicalId !== ruleId) warnDeprecatedDeplintRuleId(ruleId, canonicalId);
|
|
28013
|
-
normalized[canonicalId] = config;
|
|
28014
|
-
}
|
|
28015
|
-
return normalized;
|
|
28016
|
-
}
|
|
28017
|
-
function normalizeDeplintRules(rules, config, builtInRuleIds) {
|
|
28018
|
-
const ruleIds = new Set(rules.map((rule) => rule.id));
|
|
28019
|
-
const ruleConfigs = normalizeRuleConfigs(config?.rules ?? {}, ruleIds);
|
|
28020
|
-
const unknownRuleIds = Object.keys(ruleConfigs).filter((ruleId) => !ruleIds.has(ruleId));
|
|
28021
|
-
if (unknownRuleIds.length > 0) throw new TypeError(`Unknown deplint rule ${unknownRuleIds.map((ruleId) => `"${ruleId}"`).join(", ")} in commands.deplint.rules`);
|
|
28022
|
-
return rules.map((rule) => {
|
|
28023
|
-
const legacyRuleId = deprecatedDeplintRuleAlias(rule.id);
|
|
28024
|
-
const ruleConfig = ruleConfigs[rule.id] ?? (legacyRuleId === void 0 ? void 0 : ruleConfigs[legacyRuleId]);
|
|
28025
|
-
if (ruleConfig === void 0) return {
|
|
28026
|
-
...rule,
|
|
28027
|
-
enabled: true,
|
|
28028
|
-
meta: {
|
|
28029
|
-
...rule.meta,
|
|
28030
|
-
severity: "warning"
|
|
28031
|
-
},
|
|
28032
|
-
options: {}
|
|
28033
|
-
};
|
|
28034
|
-
const { level, options } = parseRuleConfig$1(rule.id, ruleConfig);
|
|
28035
|
-
validateBuiltInOptions(rule.id, options, builtInRuleIds);
|
|
28036
|
-
return {
|
|
28037
|
-
...rule,
|
|
28038
|
-
enabled: level !== "off",
|
|
28039
|
-
meta: level === "off" ? { ...rule.meta } : {
|
|
28040
|
-
...rule.meta,
|
|
28041
|
-
severity: severityFromLevel$1(level)
|
|
28042
|
-
},
|
|
28043
|
-
options
|
|
28044
|
-
};
|
|
28045
|
-
});
|
|
28046
|
-
}
|
|
28047
|
-
function isDependencyIgnoredByRule(dependency, options) {
|
|
28048
|
-
if (dependency == null || dependency.length === 0) return false;
|
|
28049
|
-
return options?.ignore?.some((pattern) => pattern === dependency || isMatch(dependency, pattern)) ?? false;
|
|
28050
|
-
}
|
|
28051
|
-
//#endregion
|
|
28052
|
-
//#region src/actions/deplint/getExtendsFromTsconfigs.ts
|
|
28053
|
-
init_index_min();
|
|
28054
|
-
const isExternalReference = (ref) => !ref.startsWith(".") && !ref.startsWith("/");
|
|
28055
|
-
function parseExtendsField(value) {
|
|
28056
|
-
if (typeof value === "string") return [value];
|
|
28057
|
-
if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
|
|
28058
|
-
return [];
|
|
28059
|
-
}
|
|
28060
|
-
function parseTypesField(value) {
|
|
28061
|
-
if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
|
|
28062
|
-
return [];
|
|
28063
|
-
}
|
|
28064
|
-
function parsePathsField(value) {
|
|
28065
|
-
if (typeof value !== "object" || value === null) return [];
|
|
28066
|
-
return Object.keys(value);
|
|
28067
|
-
}
|
|
28068
|
-
function enqueueResolvedTsconfigExtend(file, ref, discovered, queue) {
|
|
28069
|
-
if (isExternalReference(ref)) return;
|
|
28070
|
-
const resolved = PATH.resolve(PATH.dirname(file), ref);
|
|
28071
|
-
if (fs.existsSync(resolved) && !discovered.has(resolved)) queue.push(resolved);
|
|
28072
|
-
}
|
|
28073
|
-
function collectTsconfigFiles(location) {
|
|
28074
|
-
const discovered = /* @__PURE__ */ new Set();
|
|
28075
|
-
const queue = ts$1("./tsconfig*.json", {
|
|
28076
|
-
cwd: location,
|
|
28077
|
-
absolute: true
|
|
28078
|
-
});
|
|
28079
|
-
while (queue.length > 0) {
|
|
28080
|
-
const file = queue.pop();
|
|
28081
|
-
if (file === void 0 || discovered.has(file)) continue;
|
|
28082
|
-
discovered.add(file);
|
|
28083
|
-
try {
|
|
28084
|
-
const parsed = parseTsconfig(file);
|
|
28085
|
-
for (const ref of parseExtendsField(parsed.extends)) enqueueResolvedTsconfigExtend(file, ref, discovered, queue);
|
|
28086
|
-
} catch {}
|
|
28087
|
-
}
|
|
28088
|
-
return [...discovered];
|
|
28383
|
+
function addDep(pkg, dep, version, section) {
|
|
28384
|
+
const sectionObj = pkg[section] ?? {};
|
|
28385
|
+
sectionObj[dep] = version;
|
|
28386
|
+
pkg[section] = sectionObj;
|
|
28089
28387
|
}
|
|
28090
28388
|
/**
|
|
28091
|
-
*
|
|
28092
|
-
*
|
|
28093
|
-
|
|
28094
|
-
|
|
28095
|
-
|
|
28096
|
-
|
|
28097
|
-
|
|
28098
|
-
|
|
28099
|
-
|
|
28100
|
-
|
|
28101
|
-
|
|
28102
|
-
|
|
28103
|
-
|
|
28104
|
-
|
|
28105
|
-
|
|
28106
|
-
|
|
28107
|
-
if (patternPart !== importParts[importIndex]) return false;
|
|
28108
|
-
patternIndex++;
|
|
28109
|
-
importIndex++;
|
|
28110
|
-
}
|
|
28111
|
-
if (patternIndex === patternParts.length - 1 && patternParts[patternIndex] === "*") return true;
|
|
28112
|
-
return patternIndex === patternParts.length && importIndex === importParts.length;
|
|
28113
|
-
}
|
|
28114
|
-
function isTsconfigPathAlias(importPath, pathPatterns) {
|
|
28115
|
-
return pathPatterns.some((pattern) => isMatchingTsconfigPathPattern(pattern, importPath));
|
|
28116
|
-
}
|
|
28117
|
-
function parseTsconfig(file) {
|
|
28118
|
-
const cleaned = fs.readFileSync(file, "utf8").replaceAll(/\/\/.*/g, "").replaceAll(/,\s*([}\]])/g, "$1");
|
|
28119
|
-
return JSON.parse(cleaned);
|
|
28120
|
-
}
|
|
28121
|
-
function getPathsFromTsconfigs(location) {
|
|
28122
|
-
const patterns = /* @__PURE__ */ new Set();
|
|
28123
|
-
for (const file of collectTsconfigFiles(location)) try {
|
|
28124
|
-
const compilerOptions = parseTsconfig(file).compilerOptions;
|
|
28125
|
-
const pathPatterns = parsePathsField(compilerOptions?.paths);
|
|
28126
|
-
for (const pattern of pathPatterns) patterns.add(pattern);
|
|
28127
|
-
} catch {}
|
|
28128
|
-
return [...patterns];
|
|
28129
|
-
}
|
|
28130
|
-
function getExtendsFromTsconfigs(location) {
|
|
28131
|
-
const packages = /* @__PURE__ */ new Set();
|
|
28132
|
-
for (const file of collectTsconfigFiles(location)) try {
|
|
28133
|
-
const refs = parseExtendsField(parseTsconfig(file).extends);
|
|
28134
|
-
for (const ref of refs) if (isExternalReference(ref)) packages.add(getBasePackageName(ref));
|
|
28135
|
-
} catch {}
|
|
28136
|
-
return [...packages];
|
|
28137
|
-
}
|
|
28138
|
-
function getTypesFromTsconfigs(location) {
|
|
28139
|
-
const packages = /* @__PURE__ */ new Set();
|
|
28140
|
-
for (const file of collectTsconfigFiles(location)) try {
|
|
28141
|
-
const compilerOptions = parseTsconfig(file).compilerOptions;
|
|
28142
|
-
const refs = parseTypesField(compilerOptions?.types);
|
|
28143
|
-
for (const ref of refs) packages.add(getBasePackageName(ref));
|
|
28144
|
-
} catch {}
|
|
28145
|
-
return [...packages];
|
|
28146
|
-
}
|
|
28147
|
-
//#endregion
|
|
28148
|
-
//#region src/actions/deplint/getImportsFromFile.ts
|
|
28149
|
-
function isTypeOnlyImportClause(clause) {
|
|
28150
|
-
if (clause === void 0) return false;
|
|
28151
|
-
if ("phaseModifier" in clause) {
|
|
28152
|
-
const mod = clause.phaseModifier;
|
|
28153
|
-
return (typeof mod === "number" ? mod : mod?.kind) === ts.SyntaxKind.TypeKeyword;
|
|
28154
|
-
}
|
|
28155
|
-
return clause.isTypeOnly ?? false;
|
|
28156
|
-
}
|
|
28157
|
-
function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
28158
|
-
const sourceCode = fs.readFileSync(filePath, "utf8");
|
|
28159
|
-
const isJsFile = filePath.endsWith(".mjs") || filePath.endsWith(".cjs");
|
|
28160
|
-
const sourceFile = ts.createSourceFile(PATH.basename(filePath), sourceCode, ts.ScriptTarget.Latest, true, isJsFile ? ts.ScriptKind.JS : void 0);
|
|
28161
|
-
const imports = [];
|
|
28162
|
-
const typeImports = [];
|
|
28163
|
-
const isDeclarationFile = filePath.endsWith(".d.ts") || filePath.endsWith(".d.mts") || filePath.endsWith(".d.cts");
|
|
28164
|
-
function visit(node) {
|
|
28165
|
-
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
28166
|
-
const moduleSpecifier = node.moduleSpecifier?.getFullText();
|
|
28167
|
-
const isTypeImport = ts.isImportDeclaration(node) ? isTypeOnlyImportClause(node.importClause) : false;
|
|
28168
|
-
if (typeof moduleSpecifier === "string") {
|
|
28169
|
-
const trimmed = moduleSpecifier.replaceAll(/['"]/g, "").trim();
|
|
28170
|
-
if (isTypeImport || isDeclarationFile) typeImports.push(trimmed);
|
|
28171
|
-
else imports.push(trimmed);
|
|
28172
|
-
}
|
|
28173
|
-
} else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
28174
|
-
const [arg] = node.arguments;
|
|
28175
|
-
if (ts.isStringLiteral(arg)) imports.push(arg.text);
|
|
28176
|
-
} else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "require" && node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0])) imports.push(node.arguments[0].text);
|
|
28177
|
-
ts.forEachChild(node, visit);
|
|
28178
|
-
}
|
|
28179
|
-
visit(sourceFile);
|
|
28180
|
-
for (const ref of sourceFile.typeReferenceDirectives) typeImports.push(ref.fileName);
|
|
28181
|
-
const importsStartsWithExcludes = [
|
|
28182
|
-
".",
|
|
28183
|
-
"#",
|
|
28184
|
-
"node:"
|
|
28185
|
-
];
|
|
28186
|
-
const isValidImport = (imp) => importsStartsWithExcludes.every((exc) => !imp.startsWith(exc)) && !imp.includes("*") && !imp.includes("!");
|
|
28187
|
-
const cleanedImports = imports.filter(isValidImport).map(getBasePackageName);
|
|
28188
|
-
const cleanedTypeImports = typeImports.filter(isValidImport).map(getBasePackageName);
|
|
28189
|
-
for (const imp of cleanedImports) {
|
|
28190
|
-
importPaths[imp] ??= [];
|
|
28191
|
-
importPaths[imp].push(filePath);
|
|
28192
|
-
}
|
|
28193
|
-
for (const imp of cleanedTypeImports) {
|
|
28194
|
-
typeImportPaths[imp] ??= [];
|
|
28195
|
-
typeImportPaths[imp].push(filePath);
|
|
28196
|
-
}
|
|
28197
|
-
return [cleanedImports, cleanedTypeImports];
|
|
28198
|
-
}
|
|
28199
|
-
//#endregion
|
|
28200
|
-
//#region src/actions/deplint/getStorybookConfigImports.ts
|
|
28201
|
-
const storybookMainPattern = /(?:^|[\\/])\.storybook[\\/]main\.[cm]?[jt]sx?$/;
|
|
28202
|
-
const npmPackageNamePattern = /^@?[a-z0-9][\w./-]*$/i;
|
|
28203
|
-
function isStorybookMainFile(filePath) {
|
|
28204
|
-
return storybookMainPattern.test(filePath);
|
|
28205
|
-
}
|
|
28206
|
-
function getPropertyName$1(prop) {
|
|
28207
|
-
if (ts.isIdentifier(prop.name)) return prop.name.text;
|
|
28208
|
-
if (ts.isStringLiteral(prop.name) || ts.isNoSubstitutionTemplateLiteral(prop.name)) return prop.name.text;
|
|
28209
|
-
}
|
|
28210
|
-
function pushIfPackage(text, collected) {
|
|
28211
|
-
const trimmed = text.trim();
|
|
28212
|
-
if (trimmed.length === 0) return;
|
|
28213
|
-
if (trimmed.startsWith(".") || trimmed.startsWith("/") || trimmed.startsWith("node:")) return;
|
|
28214
|
-
if (!npmPackageNamePattern.test(trimmed)) return;
|
|
28215
|
-
collected.push(trimmed);
|
|
28216
|
-
}
|
|
28217
|
-
function extractFromEntry(node, collected) {
|
|
28218
|
-
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
28219
|
-
pushIfPackage(node.text, collected);
|
|
28220
|
-
return;
|
|
28221
|
-
}
|
|
28222
|
-
if (ts.isObjectLiteralExpression(node)) {
|
|
28223
|
-
for (const prop of node.properties) if (ts.isPropertyAssignment(prop) && getPropertyName$1(prop) === "name") extractFromEntry(prop.initializer, collected);
|
|
28224
|
-
return;
|
|
28225
|
-
}
|
|
28226
|
-
if (ts.isCallExpression(node)) {
|
|
28227
|
-
for (const arg of node.arguments) if (ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg)) pushIfPackage(arg.text, collected);
|
|
28389
|
+
* Set or clear `peerDependenciesMeta[dep].optional`. Only meaningful for
|
|
28390
|
+
* peers declared in `peerDependencies`.
|
|
28391
|
+
*
|
|
28392
|
+
* - `optional === true` → ensure `{ optional: true }` is set.
|
|
28393
|
+
* - `optional === false` → clear any optional flag (and the entry itself if
|
|
28394
|
+
* it would otherwise be `{}`).
|
|
28395
|
+
* - `optional === undefined` → no-op; existing meta is preserved.
|
|
28396
|
+
*/
|
|
28397
|
+
function setPeerOptional(pkg, dep, optional) {
|
|
28398
|
+
if (optional === void 0) return;
|
|
28399
|
+
if (optional) {
|
|
28400
|
+
const meta = pkg.peerDependenciesMeta ?? {};
|
|
28401
|
+
const entry = meta[dep] ?? {};
|
|
28402
|
+
entry.optional = true;
|
|
28403
|
+
meta[dep] = entry;
|
|
28404
|
+
pkg.peerDependenciesMeta = meta;
|
|
28228
28405
|
return;
|
|
28229
28406
|
}
|
|
28230
|
-
|
|
28407
|
+
const meta = pkg.peerDependenciesMeta;
|
|
28408
|
+
if (!meta || !Object.hasOwn(meta, dep)) return;
|
|
28409
|
+
delete meta[dep].optional;
|
|
28410
|
+
if (Object.keys(meta[dep]).length === 0) delete meta[dep];
|
|
28411
|
+
if (Object.keys(meta).length === 0) delete pkg.peerDependenciesMeta;
|
|
28231
28412
|
}
|
|
28232
|
-
function
|
|
28233
|
-
|
|
28234
|
-
|
|
28235
|
-
|
|
28236
|
-
|
|
28237
|
-
} catch {
|
|
28238
|
-
return [];
|
|
28239
|
-
}
|
|
28240
|
-
const sourceFile = ts.createSourceFile(PATH.basename(filePath), sourceCode, ts.ScriptTarget.Latest, true);
|
|
28241
|
-
const collected = [];
|
|
28242
|
-
function visit(node) {
|
|
28243
|
-
if (ts.isPropertyAssignment(node)) {
|
|
28244
|
-
const name = getPropertyName$1(node);
|
|
28245
|
-
if (name === "addons") {
|
|
28246
|
-
if (ts.isArrayLiteralExpression(node.initializer)) for (const element of node.initializer.elements) extractFromEntry(element, collected);
|
|
28247
|
-
} else if (name === "framework" || name === "builder") extractFromEntry(node.initializer, collected);
|
|
28248
|
-
}
|
|
28249
|
-
ts.forEachChild(node, visit);
|
|
28250
|
-
}
|
|
28251
|
-
visit(sourceFile);
|
|
28252
|
-
const cleaned = [...new Set(collected.map(getBasePackageName))];
|
|
28253
|
-
for (const imp of cleaned) {
|
|
28254
|
-
importPaths[imp] ??= [];
|
|
28255
|
-
if (!importPaths[imp].includes(filePath)) importPaths[imp].push(filePath);
|
|
28256
|
-
}
|
|
28257
|
-
return cleaned;
|
|
28413
|
+
function removePeerMeta(pkg, dep) {
|
|
28414
|
+
const meta = pkg.peerDependenciesMeta;
|
|
28415
|
+
if (!meta || !Object.hasOwn(meta, dep)) return;
|
|
28416
|
+
delete meta[dep];
|
|
28417
|
+
if (Object.keys(meta).length === 0) delete pkg.peerDependenciesMeta;
|
|
28258
28418
|
}
|
|
28259
|
-
|
|
28260
|
-
|
|
28261
|
-
|
|
28262
|
-
"
|
|
28263
|
-
"
|
|
28264
|
-
"
|
|
28419
|
+
const OPAQUE_VERSION_PREFIXES = [
|
|
28420
|
+
"catalog:",
|
|
28421
|
+
"file:",
|
|
28422
|
+
"link:",
|
|
28423
|
+
"npm:",
|
|
28424
|
+
"patch:",
|
|
28425
|
+
"portal:",
|
|
28426
|
+
"workspace:"
|
|
28265
28427
|
];
|
|
28266
|
-
|
|
28267
|
-
|
|
28268
|
-
|
|
28269
|
-
const removeTsconfigPathAliases = (imports, pathPatterns) => {
|
|
28270
|
-
if (pathPatterns.length === 0) return imports;
|
|
28271
|
-
return imports.filter((imp) => !isTsconfigPathAlias(imp, pathPatterns));
|
|
28272
|
-
};
|
|
28273
|
-
const isDeclarationFile$1 = (file) => file.endsWith(".d.ts") || file.endsWith(".d.cts") || file.endsWith(".d.mts");
|
|
28274
|
-
const toolingConfigFilePattern = /(?:^|[\\/])xy\.config\.[cm]?[jt]sx?$/;
|
|
28275
|
-
const isToolingConfigFile = (file) => toolingConfigFilePattern.test(file);
|
|
28276
|
-
function excludeToolingConfigImports(paths) {
|
|
28277
|
-
const filtered = {};
|
|
28278
|
-
for (const [imp, files] of Object.entries(paths)) {
|
|
28279
|
-
const kept = files.filter((file) => !isToolingConfigFile(file));
|
|
28280
|
-
if (kept.length > 0) filtered[imp] = kept;
|
|
28281
|
-
}
|
|
28282
|
-
return filtered;
|
|
28428
|
+
function normalizedVersionSpec(version) {
|
|
28429
|
+
const normalized = version?.trim();
|
|
28430
|
+
return normalized != null && normalized.length > 0 ? normalized : void 0;
|
|
28283
28431
|
}
|
|
28284
|
-
function
|
|
28285
|
-
|
|
28286
|
-
|
|
28287
|
-
|
|
28288
|
-
|
|
28289
|
-
|
|
28432
|
+
function isOpaqueVersionSpec(version) {
|
|
28433
|
+
const spec = normalizedVersionSpec(version);
|
|
28434
|
+
if (spec === void 0) return true;
|
|
28435
|
+
if (OPAQUE_VERSION_PREFIXES.some((prefix) => spec.startsWith(prefix))) return true;
|
|
28436
|
+
if (spec.includes("://")) return true;
|
|
28437
|
+
if (/^(?:git\+|git:|github:|gitlab:|bitbucket:|ssh:)/.test(spec)) return true;
|
|
28438
|
+
return /^[\w.-]+\/[\w./-]+(?:#.+)?$/.test(spec);
|
|
28290
28439
|
}
|
|
28291
|
-
function
|
|
28292
|
-
|
|
28293
|
-
|
|
28294
|
-
|
|
28295
|
-
|
|
28296
|
-
|
|
28297
|
-
|
|
28440
|
+
function resolveRangeLowerBound(version) {
|
|
28441
|
+
const spec = normalizedVersionSpec(version);
|
|
28442
|
+
if (spec === void 0 || spec === "*" || isOpaqueVersionSpec(spec)) return void 0;
|
|
28443
|
+
try {
|
|
28444
|
+
return import_semver.default.minVersion(spec)?.version;
|
|
28445
|
+
} catch {
|
|
28446
|
+
return;
|
|
28298
28447
|
}
|
|
28299
|
-
if (Array.isArray(value)) return value.flatMap((entry, index) => collectExportTargets$1(entry, [...pathParts, `[${index}]`]));
|
|
28300
|
-
if (typeof value !== "object" || value === null) return [];
|
|
28301
|
-
return Object.entries(value).flatMap(([key, nested]) => collectExportTargets$1(nested, [...pathParts, key]));
|
|
28302
28448
|
}
|
|
28303
|
-
function
|
|
28304
|
-
if (
|
|
28305
|
-
return
|
|
28449
|
+
function formatFullVersion(version) {
|
|
28450
|
+
if (version == null || version.length === 0) return void 0;
|
|
28451
|
+
return import_semver.default.parse(version)?.version;
|
|
28306
28452
|
}
|
|
28307
|
-
|
|
28453
|
+
/**
|
|
28454
|
+
* Format an installed version as a broad peerDependency range. The upper
|
|
28455
|
+
* bound is the next major (`'major'`, default) or next minor (`'minor'`):
|
|
28456
|
+
* 5.5.1, 'major' -> '>=5.5.1 <6'
|
|
28457
|
+
* 0.5.1, 'major' -> '>=0.5.1 <1'
|
|
28458
|
+
* 7.11.5, 'minor' -> '>=7.11.5 <7.12'
|
|
28459
|
+
* 5.5.1-beta.0, 'major' -> '>=5.5.1-beta.0 <6'
|
|
28460
|
+
* Falls back to `~<version>` if the version cannot be parsed.
|
|
28461
|
+
*/
|
|
28462
|
+
function formatPeerRange(version, boundType = "major") {
|
|
28463
|
+
const parsed = import_semver.default.parse(version);
|
|
28464
|
+
if (!parsed) return `~${version}`;
|
|
28465
|
+
if (boundType === "minor") return `>=${parsed.version} <${parsed.major}.${parsed.minor + 1}`;
|
|
28466
|
+
return `>=${parsed.version} <${parsed.major + 1}`;
|
|
28467
|
+
}
|
|
28468
|
+
/**
|
|
28469
|
+
* Pick the peer-range upper-bound style based on the devDependency's range
|
|
28470
|
+
* prefix. `~` devDeps narrow to the next minor; everything else (including
|
|
28471
|
+
* `^`, exact pins, and absent ranges) defaults to the next major.
|
|
28472
|
+
*/
|
|
28473
|
+
function inferPeerBoundType(devRange) {
|
|
28474
|
+
return devRange?.startsWith("~") ?? false ? "minor" : "major";
|
|
28475
|
+
}
|
|
28476
|
+
function readInstalledVersion(location, dep) {
|
|
28477
|
+
const depPkgPath = findDepPackageJson(location, dep);
|
|
28478
|
+
if (depPkgPath == null || depPkgPath.length === 0) return void 0;
|
|
28308
28479
|
try {
|
|
28309
|
-
return JSON.parse(fs.readFileSync(
|
|
28480
|
+
return JSON.parse(fs.readFileSync(depPkgPath, "utf8")).version;
|
|
28310
28481
|
} catch {
|
|
28311
28482
|
return;
|
|
28312
28483
|
}
|
|
28313
28484
|
}
|
|
28314
|
-
|
|
28315
|
-
|
|
28316
|
-
|
|
28317
|
-
|
|
28318
|
-
|
|
28319
|
-
|
|
28320
|
-
|
|
28321
|
-
|
|
28322
|
-
|
|
28323
|
-
|
|
28324
|
-
|
|
28485
|
+
/**
|
|
28486
|
+
* Pick the lower bound to anchor a peerDependency range to. Prefers the
|
|
28487
|
+
* `minVersion` of the sibling devDependency range (so the peer covers the
|
|
28488
|
+
* full range the library has been tested against), falling back to the
|
|
28489
|
+
* current peer range and then the installed version when no usable devRange
|
|
28490
|
+
* is available.
|
|
28491
|
+
*/
|
|
28492
|
+
function resolvePeerLowerBound(location, dep, devRange, peerRange) {
|
|
28493
|
+
const devLower = resolveRangeLowerBound(devRange);
|
|
28494
|
+
if (devLower) return devLower;
|
|
28495
|
+
const peerLower = resolveRangeLowerBound(peerRange);
|
|
28496
|
+
if (peerLower) return peerLower;
|
|
28497
|
+
return readInstalledVersion(location, dep);
|
|
28325
28498
|
}
|
|
28326
|
-
|
|
28327
|
-
|
|
28499
|
+
/**
|
|
28500
|
+
* Compute the expected dependency/devDependency range. External package
|
|
28501
|
+
* entries use a tilde range pinned to a full three-part lower bound.
|
|
28502
|
+
*/
|
|
28503
|
+
function resolveExpectedDependencyVersion(location, dep, range) {
|
|
28504
|
+
const version = formatFullVersion(resolveRangeLowerBound(range) ?? readInstalledVersion(location, dep));
|
|
28505
|
+
return version ? `~${version}` : "*";
|
|
28328
28506
|
}
|
|
28329
|
-
|
|
28330
|
-
|
|
28331
|
-
|
|
28332
|
-
|
|
28333
|
-
|
|
28334
|
-
|
|
28335
|
-
importPaths: {},
|
|
28336
|
-
typeImportPaths: {}
|
|
28337
|
-
};
|
|
28338
|
-
return {
|
|
28339
|
-
importPaths: excludeToolingConfigImports(srcImportPaths),
|
|
28340
|
-
typeImportPaths: excludeToolingConfigImports(srcTypeImportPaths)
|
|
28341
|
-
};
|
|
28507
|
+
/**
|
|
28508
|
+
* Resolve the version for a missing devDependency or dependency.
|
|
28509
|
+
* Looks in node_modules first, then falls back to '*'.
|
|
28510
|
+
*/
|
|
28511
|
+
function resolveDepVersion(location, dep) {
|
|
28512
|
+
return resolveExpectedDependencyVersion(location, dep);
|
|
28342
28513
|
}
|
|
28343
|
-
|
|
28344
|
-
|
|
28345
|
-
|
|
28346
|
-
|
|
28347
|
-
|
|
28348
|
-
|
|
28349
|
-
|
|
28350
|
-
const
|
|
28351
|
-
|
|
28352
|
-
|
|
28353
|
-
|
|
28354
|
-
|
|
28355
|
-
|
|
28356
|
-
|
|
28357
|
-
|
|
28358
|
-
|
|
28359
|
-
|
|
28360
|
-
|
|
28361
|
-
|
|
28362
|
-
const
|
|
28363
|
-
|
|
28364
|
-
|
|
28365
|
-
|
|
28366
|
-
|
|
28367
|
-
|
|
28368
|
-
|
|
28369
|
-
|
|
28370
|
-
|
|
28371
|
-
|
|
28372
|
-
|
|
28373
|
-
|
|
28374
|
-
|
|
28375
|
-
|
|
28376
|
-
|
|
28377
|
-
|
|
28378
|
-
|
|
28379
|
-
|
|
28380
|
-
|
|
28381
|
-
return
|
|
28382
|
-
allImportPaths,
|
|
28383
|
-
allImports,
|
|
28384
|
-
distImportPaths: effectiveDistImportPaths,
|
|
28385
|
-
distImports,
|
|
28386
|
-
externalAllImports,
|
|
28387
|
-
externalDistImports,
|
|
28388
|
-
externalDistTypeImports,
|
|
28389
|
-
tsconfigExtends: [...tsconfigExtends]
|
|
28390
|
-
};
|
|
28514
|
+
/**
|
|
28515
|
+
* Compute the expected peerDependency range for a dep. Anchored at the
|
|
28516
|
+
* devDependency's `minVersion` when available (so the peer range is a
|
|
28517
|
+
* superset of devDep), otherwise the installed version. Produces
|
|
28518
|
+
* `>=<lowerBound> <<major+1>`; falls back to '*' if nothing is known.
|
|
28519
|
+
*/
|
|
28520
|
+
function resolveExpectedPeerVersion(location, dep, devRange, boundType) {
|
|
28521
|
+
const lower = resolvePeerLowerBound(location, dep, devRange);
|
|
28522
|
+
return lower != null && lower.length > 0 ? formatPeerRange(lower, boundType ?? inferPeerBoundType(devRange)) : "*";
|
|
28523
|
+
}
|
|
28524
|
+
/**
|
|
28525
|
+
* Compute the non-broad peerDependency range for a dep. The result is a
|
|
28526
|
+
* caret range anchored at a full three-part lower bound. Prefer the sibling
|
|
28527
|
+
* devDependency floor; fall back to the current peer range and then the
|
|
28528
|
+
* installed version.
|
|
28529
|
+
*/
|
|
28530
|
+
function resolveExpectedPeerShorthandVersion(location, dep, devRange, peerRange) {
|
|
28531
|
+
const lower = resolvePeerLowerBound(location, dep, devRange, peerRange);
|
|
28532
|
+
if (lower == null || lower.length === 0) return "*";
|
|
28533
|
+
const version = formatFullVersion(lower);
|
|
28534
|
+
return version ? `^${version}` : "*";
|
|
28535
|
+
}
|
|
28536
|
+
/**
|
|
28537
|
+
* Single entry-point used by every rule that writes a peerDependency range.
|
|
28538
|
+
* Produces the form configured for `dep.peerDependencies.range-style`
|
|
28539
|
+
* directly, so the range-style rule never has to follow up another rule's
|
|
28540
|
+
* fix in a second pass. That removes the 2-pass cascade that could oscillate
|
|
28541
|
+
* when an upstream rule re-fired on every pass.
|
|
28542
|
+
*/
|
|
28543
|
+
function resolvePeerVersionForFix(location, dep, devRange, form, boundType) {
|
|
28544
|
+
return form === "broad" ? resolveExpectedPeerVersion(location, dep, devRange, boundType) : resolveExpectedPeerShorthandVersion(location, dep, devRange);
|
|
28545
|
+
}
|
|
28546
|
+
/**
|
|
28547
|
+
* Compute the expected devDependency range for a dep when bumping to match
|
|
28548
|
+
* the installed peer. Returns `~<major>.<minor>` (e.g. `~7.6`); falls back to
|
|
28549
|
+
* `~<version>` if parsing fails or '*' if no installed version is found.
|
|
28550
|
+
*/
|
|
28551
|
+
function resolveExpectedDevVersion(location, dep) {
|
|
28552
|
+
return resolveExpectedDependencyVersion(location, dep);
|
|
28391
28553
|
}
|
|
28392
28554
|
//#endregion
|
|
28393
28555
|
//#region src/actions/deplint/checkPackage/getMismatchedPeerDevVersions.ts
|
|
@@ -28660,14 +28822,9 @@ const allExecFunctions = shellCommandFunctions.union(directExecFunctions);
|
|
|
28660
28822
|
*/
|
|
28661
28823
|
function getCommandTokensFromFile(filePath) {
|
|
28662
28824
|
const tokens = /* @__PURE__ */ new Set();
|
|
28663
|
-
|
|
28664
|
-
|
|
28665
|
-
|
|
28666
|
-
} catch {
|
|
28667
|
-
return tokens;
|
|
28668
|
-
}
|
|
28669
|
-
const isMjsFile = filePath.endsWith(".mjs");
|
|
28670
|
-
const sourceFile = ts.createSourceFile(PATH.basename(filePath), sourceCode, ts.ScriptTarget.Latest, true, isMjsFile ? ts.ScriptKind.JS : void 0);
|
|
28825
|
+
const cached = tryGetCachedSourceFile(filePath);
|
|
28826
|
+
if (cached === void 0) return tokens;
|
|
28827
|
+
const { sourceFile } = cached;
|
|
28671
28828
|
function visit(node) {
|
|
28672
28829
|
if (ts.isCallExpression(node) && node.arguments.length > 0) {
|
|
28673
28830
|
const fnName = getFunctionName(node.expression);
|
|
@@ -29627,277 +29784,96 @@ const workspaceVersionProblemsRule = {
|
|
|
29627
29784
|
data: {
|
|
29628
29785
|
...finding,
|
|
29629
29786
|
expectedVersion
|
|
29630
|
-
},
|
|
29631
|
-
dependency: finding.dep,
|
|
29632
|
-
message: `Workspace dependency ${finding.dep} in ${finding.section} should use ${configuredProtocol} — found ${finding.version}`
|
|
29633
|
-
});
|
|
29634
|
-
}
|
|
29635
|
-
},
|
|
29636
|
-
resolveFixes(diagnostic) {
|
|
29637
|
-
const data = diagnostic.data;
|
|
29638
|
-
return data ? [{
|
|
29639
|
-
action: "set-version",
|
|
29640
|
-
dependency: data.dep,
|
|
29641
|
-
detail: `set ${data.expectedVersion ?? "workspace:~"} for ${data.section}`,
|
|
29642
|
-
section: data.section,
|
|
29643
|
-
version: data.expectedVersion ?? "workspace:~"
|
|
29644
|
-
}] : [];
|
|
29645
|
-
}
|
|
29646
|
-
};
|
|
29647
|
-
function shouldSkipExternalRangeStyle(context, dep, current) {
|
|
29648
|
-
return current === void 0 || isOpaqueVersionSpec(current) || (context.workspaceNames?.has(dep) ?? false);
|
|
29649
|
-
}
|
|
29650
|
-
function shouldSkipPeerRangeStyle(context, dep, current) {
|
|
29651
|
-
return (context.exclude?.has(dep) ?? false) || current === void 0 || isOpaqueVersionSpec(current) || (context.workspaceNames?.has(dep) ?? false);
|
|
29652
|
-
}
|
|
29653
|
-
function expectedPeerRangeStyle(context, dep, devRange, peerRange, form, boundType) {
|
|
29654
|
-
return form === "broad" ? resolveExpectedPeerVersion(context.workspace.location, dep, devRange, boundType) : resolveExpectedPeerShorthandVersion(context.workspace.location, dep, devRange, peerRange);
|
|
29655
|
-
}
|
|
29656
|
-
const builtInDeplintPlugin = {
|
|
29657
|
-
name: "builtin",
|
|
29658
|
-
rules: [
|
|
29659
|
-
unlistedDependenciesRule,
|
|
29660
|
-
unusedDependenciesRule,
|
|
29661
|
-
misplacedDependenciesRule,
|
|
29662
|
-
{
|
|
29663
|
-
category: "dependencies",
|
|
29664
|
-
id: "dep.dependencies.aei-review",
|
|
29665
|
-
meta: {
|
|
29666
|
-
description: "Dependencies whose API Exposure Index score is borderline — placement needs manual review",
|
|
29667
|
-
fixable: [],
|
|
29668
|
-
severity: "warning"
|
|
29669
|
-
},
|
|
29670
|
-
evaluate(context) {
|
|
29671
|
-
if (context.classifierMode !== "aei" || context.isTerminalPackage) return;
|
|
29672
|
-
const candidates = /* @__PURE__ */ new Set([...context.packageParams.dependencies, ...context.packageParams.peerDependencies]);
|
|
29673
|
-
for (const dep of candidates) {
|
|
29674
|
-
if (context.forceDeps.has(dep) || context.forceDevs.has(dep) || context.forcePeers.has(dep)) continue;
|
|
29675
|
-
if (context.packageParams.dependencyVersions[dep]?.startsWith("workspace:")) continue;
|
|
29676
|
-
if (context.workspaceNames?.has(dep) ?? false) continue;
|
|
29677
|
-
if (dep.startsWith("@types/")) continue;
|
|
29678
|
-
if (context.classifyDependency(dep) !== "review") continue;
|
|
29679
|
-
context.report({
|
|
29680
|
-
dependency: dep,
|
|
29681
|
-
message: `AEI score for ${dep} is borderline — review whether it belongs in dependencies or peerDependencies (run \`xy api-exposure --dep ${dep}\` for the evidence)`
|
|
29682
|
-
});
|
|
29683
|
-
}
|
|
29684
|
-
}
|
|
29685
|
-
},
|
|
29686
|
-
dependencyRangeStyleRule,
|
|
29687
|
-
unlistedDevDependenciesRule,
|
|
29688
|
-
unusedDevDependenciesRule,
|
|
29689
|
-
redundantDevDependenciesRule,
|
|
29690
|
-
devDependencyRangeStyleRule,
|
|
29691
|
-
unsatisfiedPeersRule,
|
|
29692
|
-
unusedPeerDependenciesRule,
|
|
29693
|
-
unrequestedPeerDependenciesRule,
|
|
29694
|
-
misplacedPeerDependenciesRule,
|
|
29695
|
-
redundantPeerDependenciesRule,
|
|
29696
|
-
mismatchedPeerDevVersionsRule,
|
|
29697
|
-
peerDependencyRangeStyleRule,
|
|
29698
|
-
workspaceVersionProblemsRule
|
|
29699
|
-
]
|
|
29700
|
-
};
|
|
29701
|
-
//#endregion
|
|
29702
|
-
//#region src/actions/deplint/loader.ts
|
|
29703
|
-
function resolvePluginSpecifier(specifier) {
|
|
29704
|
-
if (specifier.startsWith(".") || PATH.isAbsolute(specifier)) return pathToFileURL(PATH.resolve(specifier)).href;
|
|
29705
|
-
return specifier;
|
|
29706
|
-
}
|
|
29707
|
-
function isPlugin(value) {
|
|
29708
|
-
return typeof value === "object" && value !== null && "name" in value && "rules" in value && Array.isArray(value.rules);
|
|
29709
|
-
}
|
|
29710
|
-
async function loadDeplintRules(config) {
|
|
29711
|
-
const plugins = [builtInDeplintPlugin];
|
|
29712
|
-
const pluginSpecifiers = config?.plugins ?? [];
|
|
29713
|
-
for (const specifier of pluginSpecifiers) {
|
|
29714
|
-
const pluginModule = await import(resolvePluginSpecifier(specifier));
|
|
29715
|
-
const plugin = pluginModule.default ?? pluginModule.plugin;
|
|
29716
|
-
if (!isPlugin(plugin)) throw new TypeError(`Invalid deplint plugin "${specifier}" - expected a plugin with a name and rules array`);
|
|
29717
|
-
plugins.push(plugin);
|
|
29718
|
-
}
|
|
29719
|
-
return normalizeDeplintRules(plugins.flatMap((plugin) => plugin.rules), config, new Set(builtInDeplintPlugin.rules.map((rule) => rule.id)));
|
|
29720
|
-
}
|
|
29721
|
-
//#endregion
|
|
29722
|
-
//#region src/actions/deplint/fetchPackageManifest.ts
|
|
29723
|
-
/**
|
|
29724
|
-
* Fetches npm registry manifests for deplint's peer-dependency resolution.
|
|
29725
|
-
*
|
|
29726
|
-
* Unlike `lib/updo/fetchRegistryInfo`, which returns only version strings
|
|
29727
|
-
* and dist-tags, this helper preserves each version's `peerDependencies`
|
|
29728
|
-
* block. That's what we need to answer the question: "what's the latest
|
|
29729
|
-
* version of package X whose peer range accepts peer Y at version Z?"
|
|
29730
|
-
*
|
|
29731
|
-
* Results are cached per-process so repeated lookups within a single
|
|
29732
|
-
* deplint run hit the registry at most once per package.
|
|
29733
|
-
*/
|
|
29734
|
-
const REGISTRY_BASE = "https://registry.npmjs.org";
|
|
29735
|
-
const cache = /* @__PURE__ */ new Map();
|
|
29736
|
-
async function fetchUncached(packageName) {
|
|
29737
|
-
try {
|
|
29738
|
-
const url = `${REGISTRY_BASE}/${encodeURIComponent(packageName)}`;
|
|
29739
|
-
const res = await fetch(url, { headers: { Accept: "application/vnd.npm.install-v1+json" } });
|
|
29740
|
-
if (!res.ok) return void 0;
|
|
29741
|
-
const data = await res.json();
|
|
29742
|
-
const versionsMap = data.versions ?? {};
|
|
29743
|
-
const versions = Object.entries(versionsMap).map(([version, manifest]) => ({
|
|
29744
|
-
peerDependencies: manifest.peerDependencies ?? {},
|
|
29745
|
-
version
|
|
29746
|
-
}));
|
|
29747
|
-
return {
|
|
29748
|
-
distTags: data["dist-tags"] ?? {},
|
|
29749
|
-
versions
|
|
29750
|
-
};
|
|
29751
|
-
} catch {
|
|
29752
|
-
return;
|
|
29753
|
-
}
|
|
29754
|
-
}
|
|
29755
|
-
function fetchPackageManifest(packageName) {
|
|
29756
|
-
const existing = cache.get(packageName);
|
|
29757
|
-
if (existing) return existing;
|
|
29758
|
-
const pending = fetchUncached(packageName);
|
|
29759
|
-
cache.set(packageName, pending);
|
|
29760
|
-
return pending;
|
|
29761
|
-
}
|
|
29762
|
-
async function fetchPackageManifests(packageNames, concurrency = 16) {
|
|
29763
|
-
const unique = [...new Set(packageNames)];
|
|
29764
|
-
const results = /* @__PURE__ */ new Map();
|
|
29765
|
-
await runWithConcurrency(unique, concurrency, async (name) => {
|
|
29766
|
-
results.set(name, await fetchPackageManifest(name));
|
|
29767
|
-
});
|
|
29768
|
-
return results;
|
|
29769
|
-
}
|
|
29770
|
-
//#endregion
|
|
29771
|
-
//#region src/actions/deplint/resolvePeerBumpFixes.ts
|
|
29772
|
-
/**
|
|
29773
|
-
* Resolves `resolve-peer-bump` fixes by consulting the npm registry.
|
|
29774
|
-
*
|
|
29775
|
-
* A `resolve-peer-bump` fix says "the installed peer X@v doesn't satisfy the
|
|
29776
|
-
* range that the currently installed version of the requiring dep D declares —
|
|
29777
|
-
* bump our declared range for D." To pick a concrete target range, we fetch
|
|
29778
|
-
* D's registry manifest and find the highest published version whose
|
|
29779
|
-
* `peerDependencies[X]` range accepts v. We then express our new declared
|
|
29780
|
-
* range using D's actual version numbers (not the peer's — that was the old
|
|
29781
|
-
* bug).
|
|
29782
|
-
*
|
|
29783
|
-
* If no published version of D accepts the installed peer, the fix is dropped
|
|
29784
|
-
* and the mismatch remains visible in the next deplint pass as a warning.
|
|
29785
|
-
*/
|
|
29786
|
-
function keyOf(k) {
|
|
29787
|
-
return `${k.dependency}|${k.peer}|${k.installedPeerVersion}|${k.currentRange}`;
|
|
29788
|
-
}
|
|
29789
|
-
function collectPeerBumpFixes(diagnostics) {
|
|
29790
|
-
const fixes = [];
|
|
29791
|
-
const packageNames = /* @__PURE__ */ new Set();
|
|
29792
|
-
for (const diagnostic of diagnostics) {
|
|
29793
|
-
const peerBumpFixes = (diagnostic.fixes ?? []).filter((candidate) => candidate.action === "resolve-peer-bump");
|
|
29794
|
-
for (const fix of peerBumpFixes) {
|
|
29795
|
-
fixes.push(fix);
|
|
29796
|
-
packageNames.add(fix.dependency);
|
|
29797
|
-
}
|
|
29798
|
-
}
|
|
29799
|
-
return {
|
|
29800
|
-
fixes,
|
|
29801
|
-
packageNames: [...packageNames]
|
|
29802
|
-
};
|
|
29803
|
-
}
|
|
29804
|
-
function canAcceptPeer(version, peer, installedPeerVersion) {
|
|
29805
|
-
const range = version.peerDependencies[peer];
|
|
29806
|
-
if (!range || range === "*") return true;
|
|
29807
|
-
if (range.startsWith("workspace:")) return true;
|
|
29808
|
-
try {
|
|
29809
|
-
return import_semver.default.satisfies(installedPeerVersion, range, { includePrerelease: true });
|
|
29810
|
-
} catch {
|
|
29811
|
-
return false;
|
|
29812
|
-
}
|
|
29813
|
-
}
|
|
29814
|
-
function pickHighest(versions) {
|
|
29815
|
-
if (versions.length === 0) return void 0;
|
|
29816
|
-
const stable = versions.filter((v) => import_semver.default.prerelease(v) === null);
|
|
29817
|
-
return (stable.length > 0 ? stable : versions).toSorted(import_semver.default.rcompare)[0];
|
|
29818
|
-
}
|
|
29819
|
-
/**
|
|
29820
|
-
* Returns a version to bump to ONLY if doing so would meaningfully change what
|
|
29821
|
-
* `pnpm install` resolves — i.e., a newer version of the requiring dep exists
|
|
29822
|
-
* whose peer range accepts the installed peer. If the best peer-compatible
|
|
29823
|
-
* version is older than (or equal to) what the current range already resolves
|
|
29824
|
-
* to, we emit nothing: "downgrade to fix a peer warning" is a user decision,
|
|
29825
|
-
* not an automatic one.
|
|
29826
|
-
*/
|
|
29827
|
-
function pickUpgradeTarget(manifest, peer, installedPeerVersion, currentRange) {
|
|
29828
|
-
const valid = manifest.versions.filter((v) => import_semver.default.valid(v.version) !== null);
|
|
29829
|
-
const currentBest = pickHighest(valid.filter((v) => import_semver.default.satisfies(v.version, currentRange, { includePrerelease: true })).filter((v) => canAcceptPeer(v, peer, installedPeerVersion)).map((v) => v.version));
|
|
29830
|
-
const absoluteBest = pickHighest(valid.filter((v) => canAcceptPeer(v, peer, installedPeerVersion)).map((v) => v.version));
|
|
29831
|
-
if (absoluteBest == null || absoluteBest.length === 0) return void 0;
|
|
29832
|
-
if (currentBest != null && currentBest.length > 0 && import_semver.default.gte(currentBest, absoluteBest)) return void 0;
|
|
29833
|
-
let currentMin;
|
|
29834
|
-
try {
|
|
29835
|
-
currentMin = import_semver.default.minVersion(currentRange)?.version;
|
|
29836
|
-
} catch {}
|
|
29837
|
-
if (currentMin != null && currentMin.length > 0 && import_semver.default.lt(absoluteBest, currentMin)) return void 0;
|
|
29838
|
-
return absoluteBest;
|
|
29839
|
-
}
|
|
29840
|
-
function buildBumpedRange(resolvedVersion, section) {
|
|
29841
|
-
return section === "peerDependencies" ? `^${resolvedVersion}` : `~${resolvedVersion}`;
|
|
29842
|
-
}
|
|
29843
|
-
function resolveOneFix(fix, manifest, resolutionCache, loggedKeys) {
|
|
29844
|
-
const cacheKey = keyOf(fix);
|
|
29845
|
-
const isFirstSeen = !resolutionCache.has(cacheKey);
|
|
29846
|
-
let resolvedVersion;
|
|
29847
|
-
if (isFirstSeen) {
|
|
29848
|
-
resolvedVersion = manifest ? pickUpgradeTarget(manifest, fix.peer, fix.installedPeerVersion, fix.currentRange) : void 0;
|
|
29849
|
-
resolutionCache.set(cacheKey, resolvedVersion);
|
|
29850
|
-
} else resolvedVersion = resolutionCache.get(cacheKey);
|
|
29851
|
-
if (resolvedVersion == null || resolvedVersion.length === 0) {
|
|
29852
|
-
if (!loggedKeys.has(cacheKey)) {
|
|
29853
|
-
loggedKeys.add(cacheKey);
|
|
29854
|
-
console.log(` ${chalk.dim(`No newer version of ${fix.dependency} accepts peer ${fix.peer}@${fix.installedPeerVersion} beyond current range ${fix.currentRange} — skipping bump (fix peer manually)`)}`);
|
|
29787
|
+
},
|
|
29788
|
+
dependency: finding.dep,
|
|
29789
|
+
message: `Workspace dependency ${finding.dep} in ${finding.section} should use ${configuredProtocol} — found ${finding.version}`
|
|
29790
|
+
});
|
|
29855
29791
|
}
|
|
29856
|
-
|
|
29792
|
+
},
|
|
29793
|
+
resolveFixes(diagnostic) {
|
|
29794
|
+
const data = diagnostic.data;
|
|
29795
|
+
return data ? [{
|
|
29796
|
+
action: "set-version",
|
|
29797
|
+
dependency: data.dep,
|
|
29798
|
+
detail: `set ${data.expectedVersion ?? "workspace:~"} for ${data.section}`,
|
|
29799
|
+
section: data.section,
|
|
29800
|
+
version: data.expectedVersion ?? "workspace:~"
|
|
29801
|
+
}] : [];
|
|
29857
29802
|
}
|
|
29858
|
-
|
|
29859
|
-
|
|
29860
|
-
return
|
|
29861
|
-
action: "set-version",
|
|
29862
|
-
dependency: fix.dependency,
|
|
29863
|
-
detail: `bumped ${fix.section} range to ${bumped} so ${fix.dependency}@${resolvedVersion} is installed (accepts peer ${fix.peer}@${fix.installedPeerVersion})`,
|
|
29864
|
-
section: fix.section,
|
|
29865
|
-
version: bumped
|
|
29866
|
-
};
|
|
29803
|
+
};
|
|
29804
|
+
function shouldSkipExternalRangeStyle(context, dep, current) {
|
|
29805
|
+
return current === void 0 || isOpaqueVersionSpec(current) || (context.workspaceNames?.has(dep) ?? false);
|
|
29867
29806
|
}
|
|
29868
|
-
|
|
29869
|
-
|
|
29870
|
-
* fix-loop's re-passes don't re-log "skipping bump" for the same unresolved
|
|
29871
|
-
* lookups each time. Cleared between CLI runs via `clearPeerBumpCache` (only
|
|
29872
|
-
* wired up in tests; a fresh process starts empty).
|
|
29873
|
-
*/
|
|
29874
|
-
const resolutionCache = /* @__PURE__ */ new Map();
|
|
29875
|
-
const loggedKeys = /* @__PURE__ */ new Set();
|
|
29876
|
-
function replacePeerBumpFixes(fixes, manifests, resolutionCache, loggedKeys) {
|
|
29877
|
-
const replacement = [];
|
|
29878
|
-
for (const fix of fixes) {
|
|
29879
|
-
if (fix.action !== "resolve-peer-bump") {
|
|
29880
|
-
replacement.push(fix);
|
|
29881
|
-
continue;
|
|
29882
|
-
}
|
|
29883
|
-
const resolved = resolveOneFix(fix, manifests.get(fix.dependency), resolutionCache, loggedKeys);
|
|
29884
|
-
if (resolved) replacement.push(resolved);
|
|
29885
|
-
}
|
|
29886
|
-
return replacement;
|
|
29807
|
+
function shouldSkipPeerRangeStyle(context, dep, current) {
|
|
29808
|
+
return (context.exclude?.has(dep) ?? false) || current === void 0 || isOpaqueVersionSpec(current) || (context.workspaceNames?.has(dep) ?? false);
|
|
29887
29809
|
}
|
|
29888
|
-
|
|
29889
|
-
|
|
29890
|
-
|
|
29891
|
-
|
|
29892
|
-
|
|
29893
|
-
|
|
29894
|
-
|
|
29895
|
-
|
|
29896
|
-
|
|
29897
|
-
|
|
29898
|
-
|
|
29899
|
-
|
|
29810
|
+
function expectedPeerRangeStyle(context, dep, devRange, peerRange, form, boundType) {
|
|
29811
|
+
return form === "broad" ? resolveExpectedPeerVersion(context.workspace.location, dep, devRange, boundType) : resolveExpectedPeerShorthandVersion(context.workspace.location, dep, devRange, peerRange);
|
|
29812
|
+
}
|
|
29813
|
+
const builtInDeplintPlugin = {
|
|
29814
|
+
name: "builtin",
|
|
29815
|
+
rules: [
|
|
29816
|
+
unlistedDependenciesRule,
|
|
29817
|
+
unusedDependenciesRule,
|
|
29818
|
+
misplacedDependenciesRule,
|
|
29819
|
+
{
|
|
29820
|
+
category: "dependencies",
|
|
29821
|
+
id: "dep.dependencies.aei-review",
|
|
29822
|
+
meta: {
|
|
29823
|
+
description: "Dependencies whose API Exposure Index score is borderline — placement needs manual review",
|
|
29824
|
+
fixable: [],
|
|
29825
|
+
severity: "warning"
|
|
29826
|
+
},
|
|
29827
|
+
evaluate(context) {
|
|
29828
|
+
if (context.classifierMode !== "aei" || context.isTerminalPackage) return;
|
|
29829
|
+
const candidates = /* @__PURE__ */ new Set([...context.packageParams.dependencies, ...context.packageParams.peerDependencies]);
|
|
29830
|
+
for (const dep of candidates) {
|
|
29831
|
+
if (context.forceDeps.has(dep) || context.forceDevs.has(dep) || context.forcePeers.has(dep)) continue;
|
|
29832
|
+
if (context.packageParams.dependencyVersions[dep]?.startsWith("workspace:")) continue;
|
|
29833
|
+
if (context.workspaceNames?.has(dep) ?? false) continue;
|
|
29834
|
+
if (dep.startsWith("@types/")) continue;
|
|
29835
|
+
if (context.classifyDependency(dep) !== "review") continue;
|
|
29836
|
+
context.report({
|
|
29837
|
+
dependency: dep,
|
|
29838
|
+
message: `AEI score for ${dep} is borderline — review whether it belongs in dependencies or peerDependencies (run \`xy api-exposure --dep ${dep}\` for the evidence)`
|
|
29839
|
+
});
|
|
29840
|
+
}
|
|
29841
|
+
}
|
|
29842
|
+
},
|
|
29843
|
+
dependencyRangeStyleRule,
|
|
29844
|
+
unlistedDevDependenciesRule,
|
|
29845
|
+
unusedDevDependenciesRule,
|
|
29846
|
+
redundantDevDependenciesRule,
|
|
29847
|
+
devDependencyRangeStyleRule,
|
|
29848
|
+
unsatisfiedPeersRule,
|
|
29849
|
+
unusedPeerDependenciesRule,
|
|
29850
|
+
unrequestedPeerDependenciesRule,
|
|
29851
|
+
misplacedPeerDependenciesRule,
|
|
29852
|
+
redundantPeerDependenciesRule,
|
|
29853
|
+
mismatchedPeerDevVersionsRule,
|
|
29854
|
+
peerDependencyRangeStyleRule,
|
|
29855
|
+
workspaceVersionProblemsRule
|
|
29856
|
+
]
|
|
29857
|
+
};
|
|
29858
|
+
//#endregion
|
|
29859
|
+
//#region src/actions/deplint/loader.ts
|
|
29860
|
+
function resolvePluginSpecifier(specifier) {
|
|
29861
|
+
if (specifier.startsWith(".") || PATH.isAbsolute(specifier)) return pathToFileURL(PATH.resolve(specifier)).href;
|
|
29862
|
+
return specifier;
|
|
29863
|
+
}
|
|
29864
|
+
function isPlugin(value) {
|
|
29865
|
+
return typeof value === "object" && value !== null && "name" in value && "rules" in value && Array.isArray(value.rules);
|
|
29866
|
+
}
|
|
29867
|
+
async function loadDeplintRules(config) {
|
|
29868
|
+
const plugins = [builtInDeplintPlugin];
|
|
29869
|
+
const pluginSpecifiers = config?.plugins ?? [];
|
|
29870
|
+
for (const specifier of pluginSpecifiers) {
|
|
29871
|
+
const pluginModule = await import(resolvePluginSpecifier(specifier));
|
|
29872
|
+
const plugin = pluginModule.default ?? pluginModule.plugin;
|
|
29873
|
+
if (!isPlugin(plugin)) throw new TypeError(`Invalid deplint plugin "${specifier}" - expected a plugin with a name and rules array`);
|
|
29874
|
+
plugins.push(plugin);
|
|
29900
29875
|
}
|
|
29876
|
+
return normalizeDeplintRules(plugins.flatMap((plugin) => plugin.rules), config, new Set(builtInDeplintPlugin.rules.map((rule) => rule.id)));
|
|
29901
29877
|
}
|
|
29902
29878
|
//#endregion
|
|
29903
29879
|
//#region src/actions/deplint/snapshot.ts
|
|
@@ -29954,8 +29930,11 @@ function buildDependencyClassifier(workspace, options, isTerminal, peerDependenc
|
|
|
29954
29930
|
};
|
|
29955
29931
|
}
|
|
29956
29932
|
function buildWorkspaceContext(workspace, options = {}) {
|
|
29957
|
-
const { sourceExclude, terminalOverride } = options;
|
|
29933
|
+
const { sourceExclude, terminalOverride, phases } = options;
|
|
29934
|
+
const findFilesStarted = performance.now();
|
|
29958
29935
|
const { allFiles, distFiles, runtimeRoots } = findFiles(workspace.location, sourceExclude);
|
|
29936
|
+
if (phases !== void 0) phases.findFilesMs = performance.now() - findFilesStarted;
|
|
29937
|
+
const importsStarted = performance.now();
|
|
29959
29938
|
const tsconfigExtends = getExtendsFromTsconfigs(workspace.location);
|
|
29960
29939
|
const tsconfigPaths = getPathsFromTsconfigs(workspace.location);
|
|
29961
29940
|
const tsconfigTypes = getTypesFromTsconfigs(workspace.location);
|
|
@@ -29969,11 +29948,14 @@ function buildWorkspaceContext(workspace, options = {}) {
|
|
|
29969
29948
|
tsconfigPaths,
|
|
29970
29949
|
tsconfigTypes
|
|
29971
29950
|
});
|
|
29951
|
+
if (phases !== void 0) phases.importsMs = performance.now() - importsStarted;
|
|
29952
|
+
const packageMetaStarted = performance.now();
|
|
29972
29953
|
const packageJsonPath = `${workspace.location}/package.json`;
|
|
29973
29954
|
const packageParams = getDependenciesFromPackageJson(packageJsonPath);
|
|
29974
29955
|
const requiredTransitivePeers = getRequiredNonOptionalTransitivePeers(workspace.location, packageParams);
|
|
29975
29956
|
const runtimeRootedRequired = getRuntimeRootedNonOptionalTransitivePeers(workspace.location, packageParams);
|
|
29976
29957
|
const packageClassification = classifyDeplintPackage(workspace.location, terminalOverride);
|
|
29958
|
+
if (phases !== void 0) phases.packageMetaMs = performance.now() - packageMetaStarted;
|
|
29977
29959
|
return {
|
|
29978
29960
|
classifierMode: options.classifier ?? "legacy",
|
|
29979
29961
|
classifyDependency: buildDependencyClassifier(workspace, options, packageClassification.isTerminalPackage, packageParams.peerDependencies, sourceParams.externalDistImports),
|
|
@@ -30003,7 +29985,7 @@ function buildWorkspaceContext(workspace, options = {}) {
|
|
|
30003
29985
|
}
|
|
30004
29986
|
//#endregion
|
|
30005
29987
|
//#region src/actions/deplint/engine.ts
|
|
30006
|
-
const
|
|
29988
|
+
const PROFILE_SLOW_RULE_LIMIT = 5;
|
|
30007
29989
|
function resolveDeplintCheckFlags({ deps = false, devDeps = false, peerDeps = false } = {}) {
|
|
30008
29990
|
const isNoneExplicit = !(deps || devDeps || peerDeps);
|
|
30009
29991
|
const isCheckDependencies = deps || isNoneExplicit;
|
|
@@ -30060,6 +30042,7 @@ function normalizeConfigList(values) {
|
|
|
30060
30042
|
return values.filter((value) => typeof value === "string").map((value) => value.trim()).filter(Boolean);
|
|
30061
30043
|
}
|
|
30062
30044
|
async function loadWorkspaceEvaluationContext(workspace, options, workspaceNames) {
|
|
30045
|
+
const configStarted = performance.now();
|
|
30063
30046
|
const wsConfig = await loadWorkspaceCommandConfig(workspace.location, "deplint");
|
|
30064
30047
|
const rules = await loadDeplintRules(wsConfig);
|
|
30065
30048
|
const classifier = options.classifier ?? wsConfig.classifier ?? "legacy";
|
|
@@ -30075,7 +30058,15 @@ async function loadWorkspaceEvaluationContext(workspace, options, workspaceNames
|
|
|
30075
30058
|
for (const [name, cfg] of packageEntries) if (typeof cfg.peerOptional === "boolean") forcePeerOptional.set(name, cfg.peerOptional);
|
|
30076
30059
|
const rangeStyleOptions = rules.find((rule) => rule.id === "dep.peerDependencies.range-style")?.options ?? {};
|
|
30077
30060
|
const peerRangeForm = resolvePeerRangeFormOption(rangeStyleOptions);
|
|
30061
|
+
const peerRangeBound = resolvePeerRangeBoundOption(rangeStyleOptions);
|
|
30062
|
+
const configMs = performance.now() - configStarted;
|
|
30063
|
+
const contextPhases = {
|
|
30064
|
+
findFilesMs: 0,
|
|
30065
|
+
importsMs: 0,
|
|
30066
|
+
packageMetaMs: 0
|
|
30067
|
+
};
|
|
30078
30068
|
return {
|
|
30069
|
+
configMs,
|
|
30079
30070
|
context: buildWorkspaceContext(workspace, {
|
|
30080
30071
|
apiExposureConfig,
|
|
30081
30072
|
classifier,
|
|
@@ -30083,15 +30074,429 @@ async function loadWorkspaceEvaluationContext(workspace, options, workspaceNames
|
|
|
30083
30074
|
forceDevs,
|
|
30084
30075
|
forcePeerOptional,
|
|
30085
30076
|
forcePeers,
|
|
30086
|
-
peerRangeBound
|
|
30077
|
+
peerRangeBound,
|
|
30087
30078
|
peerRangeForm,
|
|
30079
|
+
phases: options.profile === true ? contextPhases : void 0,
|
|
30088
30080
|
sourceExclude,
|
|
30089
30081
|
terminalOverride: wsConfig.terminal,
|
|
30090
30082
|
workspaceNames
|
|
30091
30083
|
}),
|
|
30084
|
+
contextPhases,
|
|
30092
30085
|
rules
|
|
30093
30086
|
};
|
|
30094
30087
|
}
|
|
30088
|
+
async function evaluateWorkspace(workspace, workspaceIndex, workspaceTotal, options, workspaceNames, pass, emitProgress) {
|
|
30089
|
+
const workspaceStarted = performance.now();
|
|
30090
|
+
const diagnostics = [];
|
|
30091
|
+
const progressEvents = [];
|
|
30092
|
+
const progress = (event) => {
|
|
30093
|
+
progressEvents.push(event);
|
|
30094
|
+
emitProgress(event);
|
|
30095
|
+
};
|
|
30096
|
+
let rulesEvaluated = 0;
|
|
30097
|
+
let rulesSkipped = 0;
|
|
30098
|
+
const ruleTimings = [];
|
|
30099
|
+
const { configMs, context, contextPhases, rules } = await loadWorkspaceEvaluationContext(workspace, options, workspaceNames);
|
|
30100
|
+
const workspaceDiagnosticStart = diagnostics.length;
|
|
30101
|
+
progress({
|
|
30102
|
+
context: buildWorkspaceProgressContext(context),
|
|
30103
|
+
pass,
|
|
30104
|
+
type: "workspace-start",
|
|
30105
|
+
workspace,
|
|
30106
|
+
workspaceIndex: workspaceIndex + 1,
|
|
30107
|
+
workspaceTotal
|
|
30108
|
+
});
|
|
30109
|
+
for (const [ruleIndex, rule] of rules.entries()) {
|
|
30110
|
+
const ruleProgress = buildRuleProgress(rule);
|
|
30111
|
+
if (rule.enabled === false) {
|
|
30112
|
+
rulesSkipped += 1;
|
|
30113
|
+
progress({
|
|
30114
|
+
pass,
|
|
30115
|
+
reason: "rule disabled",
|
|
30116
|
+
rule: ruleProgress,
|
|
30117
|
+
ruleIndex: ruleIndex + 1,
|
|
30118
|
+
ruleTotal: rules.length,
|
|
30119
|
+
type: "rule-skip",
|
|
30120
|
+
workspace
|
|
30121
|
+
});
|
|
30122
|
+
} else if (shouldRunDeplintRule(rule.category, rule.id, options)) {
|
|
30123
|
+
rulesEvaluated += 1;
|
|
30124
|
+
progress({
|
|
30125
|
+
pass,
|
|
30126
|
+
rule: ruleProgress,
|
|
30127
|
+
ruleIndex: ruleIndex + 1,
|
|
30128
|
+
ruleTotal: rules.length,
|
|
30129
|
+
type: "rule-start",
|
|
30130
|
+
workspace
|
|
30131
|
+
});
|
|
30132
|
+
const startedAt = performance.now();
|
|
30133
|
+
const diagnosticStart = diagnostics.length;
|
|
30134
|
+
await rule.evaluate({
|
|
30135
|
+
...context,
|
|
30136
|
+
options: rule.options ?? {},
|
|
30137
|
+
report: ({ data, dependency, evidence, file, message }) => {
|
|
30138
|
+
if (isDependencyIgnoredByRule(dependency, rule.options)) return;
|
|
30139
|
+
diagnostics.push({
|
|
30140
|
+
data,
|
|
30141
|
+
dependency,
|
|
30142
|
+
evidence,
|
|
30143
|
+
file: file ?? context.packageJsonPath,
|
|
30144
|
+
fixable: isRuleFixable(rule),
|
|
30145
|
+
id: rule.id,
|
|
30146
|
+
message,
|
|
30147
|
+
severity: rule.meta.severity,
|
|
30148
|
+
workspace: context.workspace
|
|
30149
|
+
});
|
|
30150
|
+
}
|
|
30151
|
+
});
|
|
30152
|
+
const elapsedMs = performance.now() - startedAt;
|
|
30153
|
+
if (options.profile === true) ruleTimings.push({
|
|
30154
|
+
elapsedMs,
|
|
30155
|
+
id: rule.id
|
|
30156
|
+
});
|
|
30157
|
+
progress({
|
|
30158
|
+
diagnostics: diagnostics.length - diagnosticStart,
|
|
30159
|
+
elapsedMs: Math.round(elapsedMs),
|
|
30160
|
+
pass,
|
|
30161
|
+
rule: ruleProgress,
|
|
30162
|
+
ruleIndex: ruleIndex + 1,
|
|
30163
|
+
ruleTotal: rules.length,
|
|
30164
|
+
type: "rule-end",
|
|
30165
|
+
workspace
|
|
30166
|
+
});
|
|
30167
|
+
} else {
|
|
30168
|
+
rulesSkipped += 1;
|
|
30169
|
+
progress({
|
|
30170
|
+
pass,
|
|
30171
|
+
reason: "section filter",
|
|
30172
|
+
rule: ruleProgress,
|
|
30173
|
+
ruleIndex: ruleIndex + 1,
|
|
30174
|
+
ruleTotal: rules.length,
|
|
30175
|
+
type: "rule-skip",
|
|
30176
|
+
workspace
|
|
30177
|
+
});
|
|
30178
|
+
}
|
|
30179
|
+
}
|
|
30180
|
+
progress({
|
|
30181
|
+
diagnostics: diagnostics.length - workspaceDiagnosticStart,
|
|
30182
|
+
pass,
|
|
30183
|
+
type: "workspace-end",
|
|
30184
|
+
workspace
|
|
30185
|
+
});
|
|
30186
|
+
const rulesMs = ruleTimings.reduce((sum, rule) => sum + rule.elapsedMs, 0);
|
|
30187
|
+
return {
|
|
30188
|
+
context,
|
|
30189
|
+
diagnostics,
|
|
30190
|
+
profile: options.profile === true ? {
|
|
30191
|
+
allFiles: context.fileContext.allFiles.length,
|
|
30192
|
+
configMs,
|
|
30193
|
+
distFiles: context.fileContext.distFiles.length,
|
|
30194
|
+
findFilesMs: contextPhases.findFilesMs,
|
|
30195
|
+
importsMs: contextPhases.importsMs,
|
|
30196
|
+
packageMetaMs: contextPhases.packageMetaMs,
|
|
30197
|
+
rulesMs,
|
|
30198
|
+
slowRules: ruleTimings.toSorted((a, b) => b.elapsedMs - a.elapsedMs).slice(0, PROFILE_SLOW_RULE_LIMIT).filter((rule) => rule.elapsedMs >= 1),
|
|
30199
|
+
totalMs: performance.now() - workspaceStarted,
|
|
30200
|
+
workspace: workspace.name,
|
|
30201
|
+
workspaceLocation: workspace.location
|
|
30202
|
+
} : void 0,
|
|
30203
|
+
progressEvents,
|
|
30204
|
+
rules,
|
|
30205
|
+
rulesEvaluated,
|
|
30206
|
+
rulesSkipped
|
|
30207
|
+
};
|
|
30208
|
+
}
|
|
30209
|
+
async function evaluateWorkspaces(workspaces, options, workspaceNames, pass = 1, progress) {
|
|
30210
|
+
const diagnostics = [];
|
|
30211
|
+
const contextsByWorkspace = /* @__PURE__ */ new Map();
|
|
30212
|
+
const rulesById = /* @__PURE__ */ new Map();
|
|
30213
|
+
const profiles = [];
|
|
30214
|
+
const results = Array.from({ length: workspaces.length }, () => ({
|
|
30215
|
+
context: void 0,
|
|
30216
|
+
diagnostics: [],
|
|
30217
|
+
progressEvents: [],
|
|
30218
|
+
rules: [],
|
|
30219
|
+
rulesEvaluated: 0,
|
|
30220
|
+
rulesSkipped: 0
|
|
30221
|
+
}));
|
|
30222
|
+
let rulesEvaluated = 0;
|
|
30223
|
+
let rulesSkipped = 0;
|
|
30224
|
+
const concurrency = Math.max(1, options.jobs ?? 1);
|
|
30225
|
+
const isEmitProgressImmediately = concurrency === 1;
|
|
30226
|
+
const noopProgress = (_event) => void 0;
|
|
30227
|
+
await runWithConcurrency(workspaces.map((workspace, workspaceIndex) => ({
|
|
30228
|
+
workspace,
|
|
30229
|
+
workspaceIndex
|
|
30230
|
+
})), concurrency, async ({ workspace, workspaceIndex }) => {
|
|
30231
|
+
results[workspaceIndex] = await evaluateWorkspace(workspace, workspaceIndex, workspaces.length, options, workspaceNames, pass, isEmitProgressImmediately ? progress ?? noopProgress : noopProgress);
|
|
30232
|
+
});
|
|
30233
|
+
for (const result of results) {
|
|
30234
|
+
if (!isEmitProgressImmediately) for (const event of result.progressEvents) progress?.(event);
|
|
30235
|
+
const { context, rules } = result;
|
|
30236
|
+
contextsByWorkspace.set(context.workspace.location, context);
|
|
30237
|
+
diagnostics.push(...result.diagnostics);
|
|
30238
|
+
rulesEvaluated += result.rulesEvaluated;
|
|
30239
|
+
rulesSkipped += result.rulesSkipped;
|
|
30240
|
+
if (result.profile !== void 0) profiles.push(result.profile);
|
|
30241
|
+
for (const rule of rules) rulesById.set(rule.id, rule);
|
|
30242
|
+
}
|
|
30243
|
+
return {
|
|
30244
|
+
contextsByWorkspace,
|
|
30245
|
+
diagnostics,
|
|
30246
|
+
profiles,
|
|
30247
|
+
rulesById,
|
|
30248
|
+
rulesEvaluated,
|
|
30249
|
+
rulesSkipped
|
|
30250
|
+
};
|
|
30251
|
+
}
|
|
30252
|
+
//#endregion
|
|
30253
|
+
//#region src/actions/deplint/packageEditor.ts
|
|
30254
|
+
var DeplintPackageEditor = class {
|
|
30255
|
+
dirty = false;
|
|
30256
|
+
pkg;
|
|
30257
|
+
workspace;
|
|
30258
|
+
constructor(workspace) {
|
|
30259
|
+
this.workspace = workspace;
|
|
30260
|
+
this.pkg = readPackageJson$4(workspace.location);
|
|
30261
|
+
}
|
|
30262
|
+
applyFix(fix) {
|
|
30263
|
+
const before = JSON.stringify(this.pkg);
|
|
30264
|
+
switch (fix.action) {
|
|
30265
|
+
case "add":
|
|
30266
|
+
addDep(this.pkg, fix.dependency, fix.version, fix.section);
|
|
30267
|
+
if (fix.section === "peerDependencies") setPeerOptional(this.pkg, fix.dependency, fix.optional);
|
|
30268
|
+
break;
|
|
30269
|
+
case "move":
|
|
30270
|
+
moveDep(this.pkg, fix.dependency, fix.fromSection, fix.toSection);
|
|
30271
|
+
if (fix.version !== void 0 && this.pkg[fix.toSection]?.[fix.dependency] !== void 0) this.pkg[fix.toSection][fix.dependency] = fix.version;
|
|
30272
|
+
if (fix.toSection === "peerDependencies") setPeerOptional(this.pkg, fix.dependency, fix.optional);
|
|
30273
|
+
break;
|
|
30274
|
+
case "remove":
|
|
30275
|
+
removeDep(this.pkg, fix.dependency, fix.section);
|
|
30276
|
+
break;
|
|
30277
|
+
case "set-version":
|
|
30278
|
+
if (this.pkg[fix.section]?.[fix.dependency] !== void 0) addDep(this.pkg, fix.dependency, fix.version, fix.section);
|
|
30279
|
+
break;
|
|
30280
|
+
case "resolve-peer-bump": break;
|
|
30281
|
+
}
|
|
30282
|
+
if (JSON.stringify(this.pkg) === before) return void 0;
|
|
30283
|
+
this.dirty = true;
|
|
30284
|
+
return {
|
|
30285
|
+
dependency: fix.dependency,
|
|
30286
|
+
detail: fix.detail,
|
|
30287
|
+
workspace: this.workspace
|
|
30288
|
+
};
|
|
30289
|
+
}
|
|
30290
|
+
save() {
|
|
30291
|
+
if (!this.dirty) return;
|
|
30292
|
+
writePackageJson$2(this.workspace.location, this.pkg);
|
|
30293
|
+
}
|
|
30294
|
+
};
|
|
30295
|
+
//#endregion
|
|
30296
|
+
//#region src/actions/deplint/fixer.ts
|
|
30297
|
+
function applyDeplintFixes(diagnostics) {
|
|
30298
|
+
const editors = /* @__PURE__ */ new Map();
|
|
30299
|
+
const applied = [];
|
|
30300
|
+
for (const diagnostic of diagnostics) {
|
|
30301
|
+
const fixes = diagnostic.fixes ?? [];
|
|
30302
|
+
for (const fix of fixes) {
|
|
30303
|
+
const workspaceKey = diagnostic.workspace.location;
|
|
30304
|
+
let editor = editors.get(workspaceKey);
|
|
30305
|
+
if (!editor) {
|
|
30306
|
+
editor = new DeplintPackageEditor(diagnostic.workspace);
|
|
30307
|
+
editors.set(workspaceKey, editor);
|
|
30308
|
+
}
|
|
30309
|
+
const appliedFix = editor.applyFix(fix);
|
|
30310
|
+
if (appliedFix) applied.push(appliedFix);
|
|
30311
|
+
}
|
|
30312
|
+
}
|
|
30313
|
+
for (const editor of editors.values()) editor.save();
|
|
30314
|
+
return applied;
|
|
30315
|
+
}
|
|
30316
|
+
//#endregion
|
|
30317
|
+
//#region src/actions/deplint/fetchPackageManifest.ts
|
|
30318
|
+
/**
|
|
30319
|
+
* Fetches npm registry manifests for deplint's peer-dependency resolution.
|
|
30320
|
+
*
|
|
30321
|
+
* Unlike `lib/updo/fetchRegistryInfo`, which returns only version strings
|
|
30322
|
+
* and dist-tags, this helper preserves each version's `peerDependencies`
|
|
30323
|
+
* block. That's what we need to answer the question: "what's the latest
|
|
30324
|
+
* version of package X whose peer range accepts peer Y at version Z?"
|
|
30325
|
+
*
|
|
30326
|
+
* Results are cached per-process so repeated lookups within a single
|
|
30327
|
+
* deplint run hit the registry at most once per package.
|
|
30328
|
+
*/
|
|
30329
|
+
const REGISTRY_BASE = "https://registry.npmjs.org";
|
|
30330
|
+
const cache = /* @__PURE__ */ new Map();
|
|
30331
|
+
async function fetchUncached(packageName) {
|
|
30332
|
+
try {
|
|
30333
|
+
const url = `${REGISTRY_BASE}/${encodeURIComponent(packageName)}`;
|
|
30334
|
+
const res = await fetch(url, { headers: { Accept: "application/vnd.npm.install-v1+json" } });
|
|
30335
|
+
if (!res.ok) return void 0;
|
|
30336
|
+
const data = await res.json();
|
|
30337
|
+
const versionsMap = data.versions ?? {};
|
|
30338
|
+
const versions = Object.entries(versionsMap).map(([version, manifest]) => ({
|
|
30339
|
+
peerDependencies: manifest.peerDependencies ?? {},
|
|
30340
|
+
version
|
|
30341
|
+
}));
|
|
30342
|
+
return {
|
|
30343
|
+
distTags: data["dist-tags"] ?? {},
|
|
30344
|
+
versions
|
|
30345
|
+
};
|
|
30346
|
+
} catch {
|
|
30347
|
+
return;
|
|
30348
|
+
}
|
|
30349
|
+
}
|
|
30350
|
+
function fetchPackageManifest(packageName) {
|
|
30351
|
+
const existing = cache.get(packageName);
|
|
30352
|
+
if (existing) return existing;
|
|
30353
|
+
const pending = fetchUncached(packageName);
|
|
30354
|
+
cache.set(packageName, pending);
|
|
30355
|
+
return pending;
|
|
30356
|
+
}
|
|
30357
|
+
async function fetchPackageManifests(packageNames, concurrency = 16) {
|
|
30358
|
+
const unique = [...new Set(packageNames)];
|
|
30359
|
+
const results = /* @__PURE__ */ new Map();
|
|
30360
|
+
await runWithConcurrency(unique, concurrency, async (name) => {
|
|
30361
|
+
results.set(name, await fetchPackageManifest(name));
|
|
30362
|
+
});
|
|
30363
|
+
return results;
|
|
30364
|
+
}
|
|
30365
|
+
//#endregion
|
|
30366
|
+
//#region src/actions/deplint/resolvePeerBumpFixes.ts
|
|
30367
|
+
/**
|
|
30368
|
+
* Resolves `resolve-peer-bump` fixes by consulting the npm registry.
|
|
30369
|
+
*
|
|
30370
|
+
* A `resolve-peer-bump` fix says "the installed peer X@v doesn't satisfy the
|
|
30371
|
+
* range that the currently installed version of the requiring dep D declares —
|
|
30372
|
+
* bump our declared range for D." To pick a concrete target range, we fetch
|
|
30373
|
+
* D's registry manifest and find the highest published version whose
|
|
30374
|
+
* `peerDependencies[X]` range accepts v. We then express our new declared
|
|
30375
|
+
* range using D's actual version numbers (not the peer's — that was the old
|
|
30376
|
+
* bug).
|
|
30377
|
+
*
|
|
30378
|
+
* If no published version of D accepts the installed peer, the fix is dropped
|
|
30379
|
+
* and the mismatch remains visible in the next deplint pass as a warning.
|
|
30380
|
+
*/
|
|
30381
|
+
function keyOf(k) {
|
|
30382
|
+
return `${k.dependency}|${k.peer}|${k.installedPeerVersion}|${k.currentRange}`;
|
|
30383
|
+
}
|
|
30384
|
+
function collectPeerBumpFixes(diagnostics) {
|
|
30385
|
+
const fixes = [];
|
|
30386
|
+
const packageNames = /* @__PURE__ */ new Set();
|
|
30387
|
+
for (const diagnostic of diagnostics) {
|
|
30388
|
+
const peerBumpFixes = (diagnostic.fixes ?? []).filter((candidate) => candidate.action === "resolve-peer-bump");
|
|
30389
|
+
for (const fix of peerBumpFixes) {
|
|
30390
|
+
fixes.push(fix);
|
|
30391
|
+
packageNames.add(fix.dependency);
|
|
30392
|
+
}
|
|
30393
|
+
}
|
|
30394
|
+
return {
|
|
30395
|
+
fixes,
|
|
30396
|
+
packageNames: [...packageNames]
|
|
30397
|
+
};
|
|
30398
|
+
}
|
|
30399
|
+
function canAcceptPeer(version, peer, installedPeerVersion) {
|
|
30400
|
+
const range = version.peerDependencies[peer];
|
|
30401
|
+
if (!range || range === "*") return true;
|
|
30402
|
+
if (range.startsWith("workspace:")) return true;
|
|
30403
|
+
try {
|
|
30404
|
+
return import_semver.default.satisfies(installedPeerVersion, range, { includePrerelease: true });
|
|
30405
|
+
} catch {
|
|
30406
|
+
return false;
|
|
30407
|
+
}
|
|
30408
|
+
}
|
|
30409
|
+
function pickHighest(versions) {
|
|
30410
|
+
if (versions.length === 0) return void 0;
|
|
30411
|
+
const stable = versions.filter((v) => import_semver.default.prerelease(v) === null);
|
|
30412
|
+
return (stable.length > 0 ? stable : versions).toSorted(import_semver.default.rcompare)[0];
|
|
30413
|
+
}
|
|
30414
|
+
/**
|
|
30415
|
+
* Returns a version to bump to ONLY if doing so would meaningfully change what
|
|
30416
|
+
* `pnpm install` resolves — i.e., a newer version of the requiring dep exists
|
|
30417
|
+
* whose peer range accepts the installed peer. If the best peer-compatible
|
|
30418
|
+
* version is older than (or equal to) what the current range already resolves
|
|
30419
|
+
* to, we emit nothing: "downgrade to fix a peer warning" is a user decision,
|
|
30420
|
+
* not an automatic one.
|
|
30421
|
+
*/
|
|
30422
|
+
function pickUpgradeTarget(manifest, peer, installedPeerVersion, currentRange) {
|
|
30423
|
+
const valid = manifest.versions.filter((v) => import_semver.default.valid(v.version) !== null);
|
|
30424
|
+
const currentBest = pickHighest(valid.filter((v) => import_semver.default.satisfies(v.version, currentRange, { includePrerelease: true })).filter((v) => canAcceptPeer(v, peer, installedPeerVersion)).map((v) => v.version));
|
|
30425
|
+
const absoluteBest = pickHighest(valid.filter((v) => canAcceptPeer(v, peer, installedPeerVersion)).map((v) => v.version));
|
|
30426
|
+
if (absoluteBest == null || absoluteBest.length === 0) return void 0;
|
|
30427
|
+
if (currentBest != null && currentBest.length > 0 && import_semver.default.gte(currentBest, absoluteBest)) return void 0;
|
|
30428
|
+
let currentMin;
|
|
30429
|
+
try {
|
|
30430
|
+
currentMin = import_semver.default.minVersion(currentRange)?.version;
|
|
30431
|
+
} catch {}
|
|
30432
|
+
if (currentMin != null && currentMin.length > 0 && import_semver.default.lt(absoluteBest, currentMin)) return void 0;
|
|
30433
|
+
return absoluteBest;
|
|
30434
|
+
}
|
|
30435
|
+
function buildBumpedRange(resolvedVersion, section) {
|
|
30436
|
+
return section === "peerDependencies" ? `^${resolvedVersion}` : `~${resolvedVersion}`;
|
|
30437
|
+
}
|
|
30438
|
+
function resolveOneFix(fix, manifest, resolutionCache, loggedKeys) {
|
|
30439
|
+
const cacheKey = keyOf(fix);
|
|
30440
|
+
const isFirstSeen = !resolutionCache.has(cacheKey);
|
|
30441
|
+
let resolvedVersion;
|
|
30442
|
+
if (isFirstSeen) {
|
|
30443
|
+
resolvedVersion = manifest ? pickUpgradeTarget(manifest, fix.peer, fix.installedPeerVersion, fix.currentRange) : void 0;
|
|
30444
|
+
resolutionCache.set(cacheKey, resolvedVersion);
|
|
30445
|
+
} else resolvedVersion = resolutionCache.get(cacheKey);
|
|
30446
|
+
if (resolvedVersion == null || resolvedVersion.length === 0) {
|
|
30447
|
+
if (!loggedKeys.has(cacheKey)) {
|
|
30448
|
+
loggedKeys.add(cacheKey);
|
|
30449
|
+
console.log(` ${chalk.dim(`No newer version of ${fix.dependency} accepts peer ${fix.peer}@${fix.installedPeerVersion} beyond current range ${fix.currentRange} — skipping bump (fix peer manually)`)}`);
|
|
30450
|
+
}
|
|
30451
|
+
return;
|
|
30452
|
+
}
|
|
30453
|
+
const bumped = buildBumpedRange(resolvedVersion, fix.section);
|
|
30454
|
+
if (bumped === fix.currentRange) return void 0;
|
|
30455
|
+
return {
|
|
30456
|
+
action: "set-version",
|
|
30457
|
+
dependency: fix.dependency,
|
|
30458
|
+
detail: `bumped ${fix.section} range to ${bumped} so ${fix.dependency}@${resolvedVersion} is installed (accepts peer ${fix.peer}@${fix.installedPeerVersion})`,
|
|
30459
|
+
section: fix.section,
|
|
30460
|
+
version: bumped
|
|
30461
|
+
};
|
|
30462
|
+
}
|
|
30463
|
+
/**
|
|
30464
|
+
* Caches survive across multiple calls in one `deplint` invocation so the
|
|
30465
|
+
* fix-loop's re-passes don't re-log "skipping bump" for the same unresolved
|
|
30466
|
+
* lookups each time. Cleared between CLI runs via `clearPeerBumpCache` (only
|
|
30467
|
+
* wired up in tests; a fresh process starts empty).
|
|
30468
|
+
*/
|
|
30469
|
+
const resolutionCache = /* @__PURE__ */ new Map();
|
|
30470
|
+
const loggedKeys = /* @__PURE__ */ new Set();
|
|
30471
|
+
function replacePeerBumpFixes(fixes, manifests, resolutionCache, loggedKeys) {
|
|
30472
|
+
const replacement = [];
|
|
30473
|
+
for (const fix of fixes) {
|
|
30474
|
+
if (fix.action !== "resolve-peer-bump") {
|
|
30475
|
+
replacement.push(fix);
|
|
30476
|
+
continue;
|
|
30477
|
+
}
|
|
30478
|
+
const resolved = resolveOneFix(fix, manifests.get(fix.dependency), resolutionCache, loggedKeys);
|
|
30479
|
+
if (resolved) replacement.push(resolved);
|
|
30480
|
+
}
|
|
30481
|
+
return replacement;
|
|
30482
|
+
}
|
|
30483
|
+
/**
|
|
30484
|
+
* Mutates `diagnostics` in place: every `resolve-peer-bump` fix is replaced
|
|
30485
|
+
* with either a concrete `set-version` fix or removed entirely if no
|
|
30486
|
+
* published version of the requiring dep accepts the installed peer.
|
|
30487
|
+
*/
|
|
30488
|
+
async function resolvePeerBumpFixes(diagnostics) {
|
|
30489
|
+
const { fixes, packageNames } = collectPeerBumpFixes(diagnostics);
|
|
30490
|
+
if (fixes.length === 0) return;
|
|
30491
|
+
const manifests = await fetchPackageManifests(packageNames);
|
|
30492
|
+
for (const diagnostic of diagnostics) {
|
|
30493
|
+
if (!diagnostic.fixes) continue;
|
|
30494
|
+
diagnostic.fixes = replacePeerBumpFixes(diagnostic.fixes, manifests, resolutionCache, loggedKeys);
|
|
30495
|
+
}
|
|
30496
|
+
}
|
|
30497
|
+
//#endregion
|
|
30498
|
+
//#region src/actions/deplint/runDeplint.ts
|
|
30499
|
+
const MAX_FIX_PASSES = 5;
|
|
30095
30500
|
async function resolveDiagnosticFixes(diagnostics, rulesById, contextsByWorkspace) {
|
|
30096
30501
|
const resolvedDiagnostics = await Promise.all(diagnostics.map(async (diagnostic) => {
|
|
30097
30502
|
const rule = rulesById.get(diagnostic.id);
|
|
@@ -30122,151 +30527,37 @@ async function resolveDiagnosticFixes(diagnostics, rulesById, contextsByWorkspac
|
|
|
30122
30527
|
fixable: (diagnostic.fixes?.length ?? 0) > 0
|
|
30123
30528
|
}));
|
|
30124
30529
|
}
|
|
30125
|
-
|
|
30126
|
-
const
|
|
30127
|
-
const
|
|
30128
|
-
const progress = (event) => {
|
|
30129
|
-
progressEvents.push(event);
|
|
30130
|
-
emitProgress(event);
|
|
30131
|
-
};
|
|
30132
|
-
let rulesEvaluated = 0;
|
|
30133
|
-
let rulesSkipped = 0;
|
|
30134
|
-
const { context, rules } = await loadWorkspaceEvaluationContext(workspace, options, workspaceNames);
|
|
30135
|
-
const workspaceDiagnosticStart = diagnostics.length;
|
|
30136
|
-
progress({
|
|
30137
|
-
context: buildWorkspaceProgressContext(context),
|
|
30138
|
-
pass,
|
|
30139
|
-
type: "workspace-start",
|
|
30140
|
-
workspace,
|
|
30141
|
-
workspaceIndex: workspaceIndex + 1,
|
|
30142
|
-
workspaceTotal
|
|
30143
|
-
});
|
|
30144
|
-
for (const [ruleIndex, rule] of rules.entries()) {
|
|
30145
|
-
const ruleProgress = buildRuleProgress(rule);
|
|
30146
|
-
if (rule.enabled === false) {
|
|
30147
|
-
rulesSkipped += 1;
|
|
30148
|
-
progress({
|
|
30149
|
-
pass,
|
|
30150
|
-
reason: "rule disabled",
|
|
30151
|
-
rule: ruleProgress,
|
|
30152
|
-
ruleIndex: ruleIndex + 1,
|
|
30153
|
-
ruleTotal: rules.length,
|
|
30154
|
-
type: "rule-skip",
|
|
30155
|
-
workspace
|
|
30156
|
-
});
|
|
30157
|
-
} else if (shouldRunDeplintRule(rule.category, rule.id, options)) {
|
|
30158
|
-
rulesEvaluated += 1;
|
|
30159
|
-
progress({
|
|
30160
|
-
pass,
|
|
30161
|
-
rule: ruleProgress,
|
|
30162
|
-
ruleIndex: ruleIndex + 1,
|
|
30163
|
-
ruleTotal: rules.length,
|
|
30164
|
-
type: "rule-start",
|
|
30165
|
-
workspace
|
|
30166
|
-
});
|
|
30167
|
-
const startedAt = Date.now();
|
|
30168
|
-
const diagnosticStart = diagnostics.length;
|
|
30169
|
-
await rule.evaluate({
|
|
30170
|
-
...context,
|
|
30171
|
-
options: rule.options ?? {},
|
|
30172
|
-
report: ({ data, dependency, evidence, file, message }) => {
|
|
30173
|
-
if (isDependencyIgnoredByRule(dependency, rule.options)) return;
|
|
30174
|
-
diagnostics.push({
|
|
30175
|
-
data,
|
|
30176
|
-
dependency,
|
|
30177
|
-
evidence,
|
|
30178
|
-
file: file ?? context.packageJsonPath,
|
|
30179
|
-
fixable: isRuleFixable(rule),
|
|
30180
|
-
id: rule.id,
|
|
30181
|
-
message,
|
|
30182
|
-
severity: rule.meta.severity,
|
|
30183
|
-
workspace: context.workspace
|
|
30184
|
-
});
|
|
30185
|
-
}
|
|
30186
|
-
});
|
|
30187
|
-
progress({
|
|
30188
|
-
diagnostics: diagnostics.length - diagnosticStart,
|
|
30189
|
-
elapsedMs: Date.now() - startedAt,
|
|
30190
|
-
pass,
|
|
30191
|
-
rule: ruleProgress,
|
|
30192
|
-
ruleIndex: ruleIndex + 1,
|
|
30193
|
-
ruleTotal: rules.length,
|
|
30194
|
-
type: "rule-end",
|
|
30195
|
-
workspace
|
|
30196
|
-
});
|
|
30197
|
-
} else {
|
|
30198
|
-
rulesSkipped += 1;
|
|
30199
|
-
progress({
|
|
30200
|
-
pass,
|
|
30201
|
-
reason: "section filter",
|
|
30202
|
-
rule: ruleProgress,
|
|
30203
|
-
ruleIndex: ruleIndex + 1,
|
|
30204
|
-
ruleTotal: rules.length,
|
|
30205
|
-
type: "rule-skip",
|
|
30206
|
-
workspace
|
|
30207
|
-
});
|
|
30208
|
-
}
|
|
30209
|
-
}
|
|
30210
|
-
progress({
|
|
30211
|
-
diagnostics: diagnostics.length - workspaceDiagnosticStart,
|
|
30212
|
-
pass,
|
|
30213
|
-
type: "workspace-end",
|
|
30214
|
-
workspace
|
|
30215
|
-
});
|
|
30530
|
+
function buildSummary({ appliedFixes, diagnostics, fixPassesRun, passesRun, rulesEvaluated, rulesSkipped, workspacesChecked }) {
|
|
30531
|
+
const diagnosticsByRule = {};
|
|
30532
|
+
for (const diagnostic of diagnostics) diagnosticsByRule[diagnostic.id] = (diagnosticsByRule[diagnostic.id] ?? 0) + 1;
|
|
30216
30533
|
return {
|
|
30217
|
-
|
|
30218
|
-
|
|
30219
|
-
|
|
30220
|
-
|
|
30534
|
+
appliedFixes: appliedFixes.length,
|
|
30535
|
+
diagnosticsByRule,
|
|
30536
|
+
errorCount: diagnostics.filter((diagnostic) => diagnostic.severity === "error").length,
|
|
30537
|
+
fixableErrorCount: diagnostics.filter((diagnostic) => diagnostic.severity === "error" && diagnostic.fixable).length,
|
|
30538
|
+
fixableWarningCount: diagnostics.filter((diagnostic) => diagnostic.severity === "warning" && diagnostic.fixable).length,
|
|
30539
|
+
fixPassesRun,
|
|
30540
|
+
passesRun,
|
|
30541
|
+
problemCount: diagnostics.length,
|
|
30221
30542
|
rulesEvaluated,
|
|
30222
|
-
rulesSkipped
|
|
30543
|
+
rulesSkipped,
|
|
30544
|
+
warningCount: diagnostics.filter((diagnostic) => diagnostic.severity === "warning").length,
|
|
30545
|
+
workspacesChecked
|
|
30223
30546
|
};
|
|
30224
30547
|
}
|
|
30225
|
-
|
|
30226
|
-
|
|
30227
|
-
const contextsByWorkspace = /* @__PURE__ */ new Map();
|
|
30228
|
-
const rulesById = /* @__PURE__ */ new Map();
|
|
30229
|
-
const results = Array.from({ length: workspaces.length }, () => ({
|
|
30230
|
-
context: void 0,
|
|
30231
|
-
diagnostics: [],
|
|
30232
|
-
progressEvents: [],
|
|
30233
|
-
rules: [],
|
|
30234
|
-
rulesEvaluated: 0,
|
|
30235
|
-
rulesSkipped: 0
|
|
30236
|
-
}));
|
|
30237
|
-
let rulesEvaluated = 0;
|
|
30238
|
-
let rulesSkipped = 0;
|
|
30239
|
-
const concurrency = Math.max(1, options.jobs ?? 1);
|
|
30240
|
-
const isEmitProgressImmediately = concurrency === 1;
|
|
30241
|
-
const noopProgress = (_event) => void 0;
|
|
30242
|
-
await runWithConcurrency(workspaces.map((workspace, workspaceIndex) => ({
|
|
30243
|
-
workspace,
|
|
30244
|
-
workspaceIndex
|
|
30245
|
-
})), concurrency, async ({ workspace, workspaceIndex }) => {
|
|
30246
|
-
results[workspaceIndex] = await evaluateWorkspace(workspace, workspaceIndex, workspaces.length, options, workspaceNames, pass, isEmitProgressImmediately ? progress ?? noopProgress : noopProgress);
|
|
30247
|
-
});
|
|
30248
|
-
for (const result of results) {
|
|
30249
|
-
if (!isEmitProgressImmediately) for (const event of result.progressEvents) progress?.(event);
|
|
30250
|
-
const { context, rules } = result;
|
|
30251
|
-
contextsByWorkspace.set(context.workspace.location, context);
|
|
30252
|
-
diagnostics.push(...result.diagnostics);
|
|
30253
|
-
rulesEvaluated += result.rulesEvaluated;
|
|
30254
|
-
rulesSkipped += result.rulesSkipped;
|
|
30255
|
-
for (const rule of rules) rulesById.set(rule.id, rule);
|
|
30256
|
-
}
|
|
30548
|
+
function buildRunProfile(options, firstPassProfiles, wallMs) {
|
|
30549
|
+
if (options.profile !== true) return void 0;
|
|
30257
30550
|
return {
|
|
30258
|
-
|
|
30259
|
-
|
|
30260
|
-
|
|
30261
|
-
rulesEvaluated,
|
|
30262
|
-
rulesSkipped
|
|
30551
|
+
cpuMs: firstPassProfiles.reduce((sum, workspaceProfile) => sum + workspaceProfile.totalMs, 0),
|
|
30552
|
+
wallMs,
|
|
30553
|
+
workspaces: firstPassProfiles
|
|
30263
30554
|
};
|
|
30264
30555
|
}
|
|
30265
30556
|
async function runDeplint(workspaces, options, workspaceNames) {
|
|
30557
|
+
const runStarted = performance.now();
|
|
30266
30558
|
const progress = options.progress;
|
|
30267
|
-
const flags = resolveDeplintCheckFlags(options);
|
|
30268
30559
|
progress?.({
|
|
30269
|
-
activeCategories: getActiveDeplintCategories(
|
|
30560
|
+
activeCategories: getActiveDeplintCategories(resolveDeplintCheckFlags(options)),
|
|
30270
30561
|
fix: options.fix === true,
|
|
30271
30562
|
maxFixPasses: MAX_FIX_PASSES,
|
|
30272
30563
|
type: "run-start",
|
|
@@ -30294,7 +30585,9 @@ async function runDeplint(workspaces, options, workspaceNames) {
|
|
|
30294
30585
|
});
|
|
30295
30586
|
return evaluation;
|
|
30296
30587
|
}
|
|
30297
|
-
|
|
30588
|
+
const firstPass = await evaluatePass(1);
|
|
30589
|
+
const firstPassProfiles = firstPass.profiles;
|
|
30590
|
+
let { contextsByWorkspace, diagnostics, rulesById } = firstPass;
|
|
30298
30591
|
const appliedFixes = [];
|
|
30299
30592
|
let fixPassesRun = 0;
|
|
30300
30593
|
for (let fixPass = 1; (options.fix ?? false) && diagnostics.length > 0 && fixPass <= MAX_FIX_PASSES; fixPass++) {
|
|
@@ -30319,178 +30612,23 @@ async function runDeplint(workspaces, options, workspaceNames) {
|
|
|
30319
30612
|
}
|
|
30320
30613
|
({contextsByWorkspace, diagnostics, rulesById} = await evaluatePass(fixPass + 1));
|
|
30321
30614
|
}
|
|
30322
|
-
|
|
30323
|
-
const fixableErrorCount = diagnostics.filter((diagnostic) => diagnostic.severity === "error" && diagnostic.fixable).length;
|
|
30324
|
-
const fixableWarningCount = diagnostics.filter((diagnostic) => diagnostic.severity === "warning" && diagnostic.fixable).length;
|
|
30325
|
-
const problemCount = diagnostics.length;
|
|
30326
|
-
const warningCount = diagnostics.filter((diagnostic) => diagnostic.severity === "warning").length;
|
|
30327
|
-
const diagnosticsByRule = {};
|
|
30328
|
-
for (const diagnostic of diagnostics) diagnosticsByRule[diagnostic.id] = (diagnosticsByRule[diagnostic.id] ?? 0) + 1;
|
|
30615
|
+
clearSourceFileCache();
|
|
30329
30616
|
return {
|
|
30330
30617
|
appliedFixes,
|
|
30331
30618
|
diagnostics,
|
|
30332
|
-
|
|
30333
|
-
|
|
30334
|
-
|
|
30335
|
-
|
|
30336
|
-
fixableErrorCount,
|
|
30337
|
-
fixableWarningCount,
|
|
30619
|
+
profile: buildRunProfile(options, firstPassProfiles, performance.now() - runStarted),
|
|
30620
|
+
summary: buildSummary({
|
|
30621
|
+
appliedFixes,
|
|
30622
|
+
diagnostics,
|
|
30338
30623
|
fixPassesRun,
|
|
30339
30624
|
passesRun,
|
|
30340
|
-
problemCount,
|
|
30341
30625
|
rulesEvaluated,
|
|
30342
30626
|
rulesSkipped,
|
|
30343
|
-
warningCount,
|
|
30344
30627
|
workspacesChecked: workspaces.length
|
|
30345
|
-
}
|
|
30628
|
+
})
|
|
30346
30629
|
};
|
|
30347
30630
|
}
|
|
30348
30631
|
//#endregion
|
|
30349
|
-
//#region src/actions/deplint/reporters.ts
|
|
30350
|
-
function pluralize(word, count) {
|
|
30351
|
-
return `${word}${count === 1 ? "" : "s"}`;
|
|
30352
|
-
}
|
|
30353
|
-
function formatWorkspaceList(workspaces) {
|
|
30354
|
-
const names = workspaces.map((workspace) => workspace.name);
|
|
30355
|
-
if (names.length <= 5) return names.join(", ");
|
|
30356
|
-
return `${names.slice(0, 5).join(", ")} +${names.length - 5} more`;
|
|
30357
|
-
}
|
|
30358
|
-
function groupedDiagnostics(diagnostics) {
|
|
30359
|
-
const workspaces = /* @__PURE__ */ new Map();
|
|
30360
|
-
for (const diagnostic of diagnostics) {
|
|
30361
|
-
const key = diagnostic.workspace.location;
|
|
30362
|
-
let workspaceGroup = workspaces.get(key);
|
|
30363
|
-
if (!workspaceGroup) {
|
|
30364
|
-
workspaceGroup = {
|
|
30365
|
-
diagnostics: 0,
|
|
30366
|
-
rules: /* @__PURE__ */ new Map(),
|
|
30367
|
-
workspace: diagnostic.workspace
|
|
30368
|
-
};
|
|
30369
|
-
workspaces.set(key, workspaceGroup);
|
|
30370
|
-
}
|
|
30371
|
-
workspaceGroup.diagnostics += 1;
|
|
30372
|
-
const rules = workspaceGroup.rules;
|
|
30373
|
-
const ruleDiagnostics = rules.get(diagnostic.id) ?? [];
|
|
30374
|
-
ruleDiagnostics.push(diagnostic);
|
|
30375
|
-
rules.set(diagnostic.id, ruleDiagnostics);
|
|
30376
|
-
}
|
|
30377
|
-
return workspaces.values().toArray();
|
|
30378
|
-
}
|
|
30379
|
-
function createHumanDeplintProgressReporter({ isVerbose = false } = {}) {
|
|
30380
|
-
return (event) => renderHumanDeplintProgressEvent(event, isVerbose);
|
|
30381
|
-
}
|
|
30382
|
-
function renderHumanDeplintProgressEvent(event, isVerbose) {
|
|
30383
|
-
switch (event.type) {
|
|
30384
|
-
case "run-start":
|
|
30385
|
-
renderRunStart(event);
|
|
30386
|
-
break;
|
|
30387
|
-
case "workspace-start":
|
|
30388
|
-
renderWorkspaceHeader(event);
|
|
30389
|
-
if (isVerbose) renderVerboseWorkspaceDetails(event);
|
|
30390
|
-
break;
|
|
30391
|
-
case "fix-start":
|
|
30392
|
-
renderFixStart(event);
|
|
30393
|
-
break;
|
|
30394
|
-
case "fix-end":
|
|
30395
|
-
renderFixEnd(event);
|
|
30396
|
-
break;
|
|
30397
|
-
default: if (isVerbose) renderVerboseProgressEvent(event);
|
|
30398
|
-
}
|
|
30399
|
-
}
|
|
30400
|
-
function renderRunStart(event) {
|
|
30401
|
-
const categories = event.activeCategories.join(", ");
|
|
30402
|
-
const fixDetail = event.fix ? ` with --fix (max ${event.maxFixPasses} fix ${pluralize("pass", event.maxFixPasses)})` : "";
|
|
30403
|
-
console.info(`Deplint: checking ${event.workspaces.length} ${pluralize("workspace", event.workspaces.length)} [${categories}]${fixDetail}`);
|
|
30404
|
-
console.info(`Workspaces: ${formatWorkspaceList(event.workspaces)}`);
|
|
30405
|
-
}
|
|
30406
|
-
function renderFixStart(event) {
|
|
30407
|
-
console.info(`Deplint: fix pass ${event.fixPass} resolving ${event.diagnostics} ${pluralize("diagnostic", event.diagnostics)}`);
|
|
30408
|
-
}
|
|
30409
|
-
function renderFixEnd(event) {
|
|
30410
|
-
console.info(`Deplint: fix pass ${event.fixPass} applied ${event.appliedFixes} ${pluralize("fix", event.appliedFixes)}`);
|
|
30411
|
-
}
|
|
30412
|
-
function renderVerboseProgressEvent(event) {
|
|
30413
|
-
switch (event.type) {
|
|
30414
|
-
case "pass-start":
|
|
30415
|
-
console.info(chalk.dim(`Deplint pass ${event.pass}: evaluating ${event.workspaces.length} ${pluralize("workspace", event.workspaces.length)}`));
|
|
30416
|
-
break;
|
|
30417
|
-
case "pass-end":
|
|
30418
|
-
console.info(chalk.dim(`Deplint pass ${event.pass}: ${event.diagnostics} ${pluralize("diagnostic", event.diagnostics)}, ${event.rulesEvaluated} ${pluralize("rule", event.rulesEvaluated)} evaluated, ${event.rulesSkipped} skipped`));
|
|
30419
|
-
break;
|
|
30420
|
-
case "workspace-end":
|
|
30421
|
-
console.info(chalk.dim(`[${event.workspace.name}] pass ${event.pass}: ${event.diagnostics} ${pluralize("diagnostic", event.diagnostics)}`));
|
|
30422
|
-
break;
|
|
30423
|
-
case "rule-start":
|
|
30424
|
-
console.info(chalk.dim(` rule ${event.ruleIndex}/${event.ruleTotal}: ${event.rule.id}`));
|
|
30425
|
-
break;
|
|
30426
|
-
case "rule-end":
|
|
30427
|
-
console.info(chalk.dim(` ${event.diagnostics} ${pluralize("finding", event.diagnostics)} in ${event.elapsedMs}ms`));
|
|
30428
|
-
break;
|
|
30429
|
-
case "rule-skip":
|
|
30430
|
-
console.info(chalk.dim(` skip ${event.ruleIndex}/${event.ruleTotal}: ${event.rule.id} (${event.reason})`));
|
|
30431
|
-
break;
|
|
30432
|
-
}
|
|
30433
|
-
}
|
|
30434
|
-
function renderWorkspaceHeader(event) {
|
|
30435
|
-
console.info(`[${chalk.blue(event.workspace.name)}] package ${event.workspaceIndex}/${event.workspaceTotal}: ${event.workspace.location} (${event.context.packageKind})`);
|
|
30436
|
-
}
|
|
30437
|
-
function renderVerboseWorkspaceDetails(event) {
|
|
30438
|
-
const forcedRefs = event.context.forceDeps + event.context.forceDevs + event.context.forcePeers + event.context.forcePeerOptional;
|
|
30439
|
-
console.info(chalk.dim(` files: ${event.context.allFiles} all, ${event.context.distFiles} dist; deps: ${event.context.dependencies}, dev: ${event.context.devDependencies}, peer: ${event.context.peerDependencies}; exclude: ${event.context.excludeCount}, forced refs: ${forcedRefs}`));
|
|
30440
|
-
}
|
|
30441
|
-
const humanDeplintReporter = { render(result) {
|
|
30442
|
-
for (const fix of result.appliedFixes) console.log(`[${chalk.blue(fix.workspace.name)}] Fixed: ${fix.detail} ${chalk.green(fix.dependency)}`);
|
|
30443
|
-
for (const workspaceGroup of groupedDiagnostics(result.diagnostics)) {
|
|
30444
|
-
console.log(`[${chalk.blue(workspaceGroup.workspace.name)}] ${workspaceGroup.diagnostics} ${pluralize("problem", workspaceGroup.diagnostics)}`);
|
|
30445
|
-
for (const [ruleId, diagnostics] of workspaceGroup.rules) {
|
|
30446
|
-
console.log(` ${chalk.cyan(ruleId)} (${diagnostics.length})`);
|
|
30447
|
-
for (const diagnostic of diagnostics) {
|
|
30448
|
-
console.log(` ${diagnostic.message}`);
|
|
30449
|
-
if (diagnostic.fixable) console.log(` ${chalk.dim("fixable with `--fix`")}`);
|
|
30450
|
-
const evidence = diagnostic.evidence ?? [];
|
|
30451
|
-
for (const line of evidence) console.log(` ${line}`);
|
|
30452
|
-
console.log(` ${chalk.yellow(diagnostic.file)}`);
|
|
30453
|
-
}
|
|
30454
|
-
}
|
|
30455
|
-
console.log("");
|
|
30456
|
-
}
|
|
30457
|
-
if (result.summary.problemCount > 0) {
|
|
30458
|
-
const summaryMessage = [
|
|
30459
|
-
`✖ ${result.summary.problemCount} ${pluralize("problem", result.summary.problemCount)}`,
|
|
30460
|
-
`(${result.summary.errorCount} ${pluralize("error", result.summary.errorCount)},`,
|
|
30461
|
-
`${result.summary.warningCount} ${pluralize("warning", result.summary.warningCount)})`
|
|
30462
|
-
].join(" ");
|
|
30463
|
-
const colorizeSummary = (message) => {
|
|
30464
|
-
if (result.summary.errorCount > 0) return chalk.red(message);
|
|
30465
|
-
return chalk.yellow(message);
|
|
30466
|
-
};
|
|
30467
|
-
console.warn(colorizeSummary(summaryMessage));
|
|
30468
|
-
if (result.summary.fixableErrorCount > 0 || result.summary.fixableWarningCount > 0) {
|
|
30469
|
-
const fixableMessage = [
|
|
30470
|
-
` ${result.summary.fixableErrorCount} ${pluralize("error", result.summary.fixableErrorCount)}`,
|
|
30471
|
-
`and ${result.summary.fixableWarningCount} ${pluralize("warning", result.summary.fixableWarningCount)}`,
|
|
30472
|
-
"potentially fixable with the `--fix` option."
|
|
30473
|
-
].join(" ");
|
|
30474
|
-
console.warn(colorizeSummary(fixableMessage));
|
|
30475
|
-
}
|
|
30476
|
-
if (result.summary.diagnosticsByRule !== void 0) {
|
|
30477
|
-
const byRule = Object.entries(result.summary.diagnosticsByRule).map(([rule, count]) => `${rule}: ${count}`).join(", ");
|
|
30478
|
-
if (byRule.length > 0) console.warn(colorizeSummary(` By rule: ${byRule}`));
|
|
30479
|
-
}
|
|
30480
|
-
if (result.summary.passesRun !== void 0 && result.summary.rulesEvaluated !== void 0) console.warn(chalk.dim(` Checked ${result.summary.workspacesChecked} ${pluralize("workspace", result.summary.workspacesChecked)} across ${result.summary.passesRun} ${pluralize("pass", result.summary.passesRun)}; ${result.summary.rulesEvaluated} ${pluralize("rule", result.summary.rulesEvaluated)} evaluated, ${result.summary.rulesSkipped ?? 0} skipped.`));
|
|
30481
|
-
return;
|
|
30482
|
-
}
|
|
30483
|
-
const detail = result.summary.passesRun === void 0 ? "" : chalk.dim(` Checked ${result.summary.workspacesChecked} ${pluralize("workspace", result.summary.workspacesChecked)} across ${result.summary.passesRun} ${pluralize("pass", result.summary.passesRun)}.`);
|
|
30484
|
-
const summaryMessage = `(${result.summary.errorCount} ${pluralize("error", result.summary.errorCount)}, ${result.summary.warningCount} ${pluralize("warning", result.summary.warningCount)})`;
|
|
30485
|
-
console.info(`Deplint: Found no dependency problems. ${chalk.green("✔")} ${summaryMessage}${detail}`);
|
|
30486
|
-
} };
|
|
30487
|
-
const jsonDeplintReporter = { render(result) {
|
|
30488
|
-
console.log(JSON.stringify(result, null, 2));
|
|
30489
|
-
} };
|
|
30490
|
-
function getDeplintReporter(format) {
|
|
30491
|
-
return format === "json" ? jsonDeplintReporter : humanDeplintReporter;
|
|
30492
|
-
}
|
|
30493
|
-
//#endregion
|
|
30494
30632
|
//#region src/actions/deplint/deplint.ts
|
|
30495
30633
|
function emptyResult$7() {
|
|
30496
30634
|
return {
|
|
@@ -30518,7 +30656,7 @@ function resolveTargetWorkspaces(targetPackage, inputWorkspaces) {
|
|
|
30518
30656
|
workspaceNames
|
|
30519
30657
|
};
|
|
30520
30658
|
}
|
|
30521
|
-
const deplint = async ({ pkg, classifier, deps, devDeps, fix, peerDeps, verbose, cliExclude, format, jobs, workspaces: inputWorkspaces }) => {
|
|
30659
|
+
const deplint = async ({ pkg, classifier, deps, devDeps, fix, peerDeps, profile, verbose, cliExclude, format, jobs, workspaces: inputWorkspaces }) => {
|
|
30522
30660
|
const effectiveFormat = format ?? (isJsonMode() ? "json" : "human");
|
|
30523
30661
|
const targetPackage = typeof pkg === "string" && pkg.length > 0 && pkg !== "undefined" ? pkg : void 0;
|
|
30524
30662
|
const { targetWorkspaces, workspaceNames } = resolveTargetWorkspaces(targetPackage, inputWorkspaces);
|
|
@@ -30532,11 +30670,15 @@ const deplint = async ({ pkg, classifier, deps, devDeps, fix, peerDeps, verbose,
|
|
|
30532
30670
|
fix,
|
|
30533
30671
|
jobs,
|
|
30534
30672
|
peerDeps,
|
|
30673
|
+
profile,
|
|
30535
30674
|
progress: effectiveFormat === "human" ? createHumanDeplintProgressReporter({ isVerbose: verbose }) : void 0,
|
|
30536
30675
|
reporter: effectiveFormat,
|
|
30537
30676
|
verbose
|
|
30538
30677
|
}, workspaceNames);
|
|
30539
|
-
if (!isJsonMode())
|
|
30678
|
+
if (!isJsonMode()) {
|
|
30679
|
+
getDeplintReporter(effectiveFormat).render(result);
|
|
30680
|
+
if (profile === true && effectiveFormat === "human") printDeplintProfileFromResult(result);
|
|
30681
|
+
}
|
|
30540
30682
|
if ((fix ?? false) && result.summary.appliedFixes > 0) shouldRunInstall();
|
|
30541
30683
|
const exitCode = result.summary.errorCount + (isStrictMode() ? result.summary.warningCount : 0);
|
|
30542
30684
|
return {
|
|
@@ -31952,6 +32094,44 @@ const resolveCompilePlatforms = (compile) => {
|
|
|
31952
32094
|
};
|
|
31953
32095
|
};
|
|
31954
32096
|
//#endregion
|
|
32097
|
+
//#region src/actions/package/compile/monolithCopyEntries.ts
|
|
32098
|
+
const copyPlatforms = /* @__PURE__ */ new Set([
|
|
32099
|
+
"browser",
|
|
32100
|
+
"neutral",
|
|
32101
|
+
"node"
|
|
32102
|
+
]);
|
|
32103
|
+
function isPathInside(parent, candidate) {
|
|
32104
|
+
const relative = PATH.relative(parent, candidate);
|
|
32105
|
+
return relative.length > 0 && relative !== ".." && !relative.startsWith(`..${PATH.sep}`) && !PATH.isAbsolute(relative);
|
|
32106
|
+
}
|
|
32107
|
+
/** Resolves configured copy destinations without requiring their sources to exist. */
|
|
32108
|
+
function listMonolithCopyEntries(packageDir, config) {
|
|
32109
|
+
const distDir = PATH.resolve(packageDir, "dist");
|
|
32110
|
+
const entries = [];
|
|
32111
|
+
const configuredCopyEntries = Object.entries(config.copyEntries ?? {});
|
|
32112
|
+
for (const [platformName, configuredEntries] of configuredCopyEntries) {
|
|
32113
|
+
if (!copyPlatforms.has(platformName)) throw new Error(`Unsupported monolith copy entry platform "${platformName}"`);
|
|
32114
|
+
const platform = platformName;
|
|
32115
|
+
const platformDir = PATH.join(distDir, platform);
|
|
32116
|
+
for (const [output, source] of Object.entries(configuredEntries)) {
|
|
32117
|
+
if (output.length === 0) throw new Error(`Monolith copy entry for ${platform} has an empty output path`);
|
|
32118
|
+
if (source.length === 0) throw new Error(`Monolith copy entry "${output}" has an empty source`);
|
|
32119
|
+
if (PATH.isAbsolute(output)) throw new Error(`Monolith copy entry output must be relative: "${output}"`);
|
|
32120
|
+
const destination = PATH.resolve(platformDir, output);
|
|
32121
|
+
if (!isPathInside(platformDir, destination)) throw new Error(`Monolith copy entry output escapes dist/${platform}: "${output}"`);
|
|
32122
|
+
const normalizedOutput = PATH.relative(platformDir, destination).split(PATH.sep).join("/");
|
|
32123
|
+
entries.push({
|
|
32124
|
+
destination,
|
|
32125
|
+
output: normalizedOutput,
|
|
32126
|
+
platform,
|
|
32127
|
+
source,
|
|
32128
|
+
subpath: `./${normalizedOutput}`
|
|
32129
|
+
});
|
|
32130
|
+
}
|
|
32131
|
+
}
|
|
32132
|
+
return entries;
|
|
32133
|
+
}
|
|
32134
|
+
//#endregion
|
|
31955
32135
|
//#region src/actions/package/compile/PublintConfig.ts
|
|
31956
32136
|
const ALL_PUBLINT_CHECKS = [
|
|
31957
32137
|
"compileTargets",
|
|
@@ -32286,10 +32466,22 @@ async function collectExpectedCompileOutputs(pkgDir) {
|
|
|
32286
32466
|
const compile = (await loadMergedWorkspaceConfig(pkgDir)).compile;
|
|
32287
32467
|
if (compile === void 0) return [];
|
|
32288
32468
|
const platforms = resolveCompilePlatforms(compile);
|
|
32469
|
+
const copiedOutputs = compile.mode === "monolith" && compile.monolith !== void 0 ? listMonolithCopyEntries(pkgDir, compile.monolith).filter((entry) => fs.existsSync(entry.destination) && fs.statSync(entry.destination).isFile()).map((entry) => {
|
|
32470
|
+
const declarationFile = pairedDeclarationFile(entry.destination);
|
|
32471
|
+
return {
|
|
32472
|
+
entry: entry.output,
|
|
32473
|
+
isPrimaryIndex: false,
|
|
32474
|
+
platform: entry.platform,
|
|
32475
|
+
runtime: relativeExportsTarget(pkgDir, entry.destination),
|
|
32476
|
+
suggestedSubpath: entry.subpath,
|
|
32477
|
+
types: declarationFile === void 0 ? void 0 : relativeExportsTarget(pkgDir, declarationFile)
|
|
32478
|
+
};
|
|
32479
|
+
}) : [];
|
|
32289
32480
|
return [
|
|
32290
32481
|
...collectOutputsForPlatform(pkgDir, "node", platforms.node, compile),
|
|
32291
32482
|
...collectOutputsForPlatform(pkgDir, "browser", platforms.browser, compile),
|
|
32292
|
-
...collectOutputsForPlatform(pkgDir, "neutral", platforms.neutral, compile)
|
|
32483
|
+
...collectOutputsForPlatform(pkgDir, "neutral", platforms.neutral, compile),
|
|
32484
|
+
...copiedOutputs
|
|
32293
32485
|
];
|
|
32294
32486
|
}
|
|
32295
32487
|
//#endregion
|
|
@@ -32492,6 +32684,7 @@ function setConditionExport(subpathExport, platform, kind, target) {
|
|
|
32492
32684
|
if (conditionExport[kind] === void 0) conditionExport[kind] = target;
|
|
32493
32685
|
}
|
|
32494
32686
|
function preferredSubpath(expected) {
|
|
32687
|
+
if (expected.suggestedSubpath !== void 0) return expected.suggestedSubpath;
|
|
32495
32688
|
if (expected.isPrimaryIndex) return ".";
|
|
32496
32689
|
return `./${PATH.posix.parse(expected.runtime).name}`;
|
|
32497
32690
|
}
|
|
@@ -50472,6 +50665,7 @@ const deplintCommand = {
|
|
|
50472
50665
|
jobs: argv.jobs,
|
|
50473
50666
|
peerDeps: !!Boolean(argv.peerDeps),
|
|
50474
50667
|
pkg,
|
|
50668
|
+
profile: !!Boolean(argv.profile),
|
|
50475
50669
|
verbose: !!Boolean(argv.verbose)
|
|
50476
50670
|
}));
|
|
50477
50671
|
}
|
|
@@ -56153,7 +56347,7 @@ const xyParseOptions = () => {
|
|
|
56153
56347
|
}).option("profile", {
|
|
56154
56348
|
alias: "p",
|
|
56155
56349
|
default: false,
|
|
56156
|
-
description: "Emit per-package timing profile (lint:
|
|
56350
|
+
description: "Emit per-package timing profile (lint phases; deplint: files / imports / rules)",
|
|
56157
56351
|
type: "boolean"
|
|
56158
56352
|
}).option("json", {
|
|
56159
56353
|
default: false,
|