@ariestools/toolchain 8.7.18 → 8.7.19
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/dist/actions/barrel/checkBarrelImportRestrictions.d.ts +10 -1
- package/dist/actions/barrel/checkBarrelImportRestrictions.d.ts.map +1 -1
- package/dist/actions/clean.d.ts +0 -1
- package/dist/actions/clean.d.ts.map +1 -1
- package/dist/bin/xy.mjs +81 -6
- package/dist/bin/xy.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import type { BarrelDescriptor } from '../lint-init.ts';
|
|
2
2
|
export type BarrelRestrictionIssueKind = 'incomplete' | 'missing';
|
|
3
|
+
/** One import of a barrel sub-package that should be restricted. */
|
|
4
|
+
export interface BarrelRestrictionImportSite {
|
|
5
|
+
file: string;
|
|
6
|
+
line: number;
|
|
7
|
+
subPackage: string;
|
|
8
|
+
/** Workspace package name that owns `file`, when known. */
|
|
9
|
+
workspacePackage?: string;
|
|
10
|
+
}
|
|
3
11
|
export interface BarrelRestrictionIssue {
|
|
4
12
|
descriptor: BarrelDescriptor;
|
|
13
|
+
importSites: BarrelRestrictionImportSite[];
|
|
5
14
|
kind: BarrelRestrictionIssueKind;
|
|
6
15
|
missingFromConfig: string[];
|
|
7
16
|
usedSubPackages: string[];
|
|
8
17
|
}
|
|
9
18
|
export declare function findBarrelImportRestrictionIssues(rootDir: string): Promise<BarrelRestrictionIssue[]>;
|
|
10
|
-
export declare function reportBarrelImportRestrictionIssues(issues: readonly BarrelRestrictionIssue[]): number;
|
|
19
|
+
export declare function reportBarrelImportRestrictionIssues(issues: readonly BarrelRestrictionIssue[], rootDir?: string): number;
|
|
11
20
|
export declare function checkBarrelImportRestrictions(rootDir: string): Promise<number>;
|
|
12
21
|
//# sourceMappingURL=checkBarrelImportRestrictions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkBarrelImportRestrictions.d.ts","sourceRoot":"","sources":["../../../src/actions/barrel/checkBarrelImportRestrictions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"checkBarrelImportRestrictions.d.ts","sourceRoot":"","sources":["../../../src/actions/barrel/checkBarrelImportRestrictions.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAWvD,MAAM,MAAM,0BAA0B,GAAG,YAAY,GAAG,SAAS,CAAA;AAEjE,oEAAoE;AACpE,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,2DAA2D;IAC3D,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,gBAAgB,CAAA;IAC5B,WAAW,EAAE,2BAA2B,EAAE,CAAA;IAC1C,IAAI,EAAE,0BAA0B,CAAA;IAChC,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B;AAqJD,wBAAsB,iCAAiC,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC,CA0B1G;AAmCD,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,SAAS,sBAAsB,EAAE,EACzC,OAAO,SAAgB,GACtB,MAAM,CAyBR;AAED,wBAAsB,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGpF"}
|
package/dist/actions/clean.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/actions/clean.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE3D,
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/actions/clean.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE3D,MAAM,WAAW,WAAW;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAiED,eAAO,MAAM,KAAK,GAAU,qDAEzB,WAAW,oBASb,CAAA;AAED,eAAO,MAAM,YAAY,GAAU,mBAA4B,kBAAkB,oBAoBhF,CAAA;AAaD,eAAO,MAAM,QAAQ,GAAU,gDAE5B,WAAW,oBAoCb,CAAA"}
|
package/dist/bin/xy.mjs
CHANGED
|
@@ -27063,7 +27063,53 @@ function collectDescriptorBarrelInfo(configDir, descriptors) {
|
|
|
27063
27063
|
}
|
|
27064
27064
|
return info;
|
|
27065
27065
|
}
|
|
27066
|
-
function
|
|
27066
|
+
function allReferencesForUsage(usage) {
|
|
27067
|
+
const references = [...usage.defaultReferences, ...usage.namespaceReferences];
|
|
27068
|
+
for (const named of usage.namedReferences.values()) references.push(...named);
|
|
27069
|
+
return references;
|
|
27070
|
+
}
|
|
27071
|
+
function workspacePackageForFile(file, rootDir, workspaces) {
|
|
27072
|
+
const absFile = PATH.resolve(file);
|
|
27073
|
+
let best;
|
|
27074
|
+
for (const workspace of workspaces) {
|
|
27075
|
+
const locationAbs = PATH.resolve(rootDir, workspace.location);
|
|
27076
|
+
if ((absFile === locationAbs || absFile.startsWith(locationAbs + PATH.sep)) && (best === void 0 || locationAbs.length > best.length)) best = {
|
|
27077
|
+
length: locationAbs.length,
|
|
27078
|
+
location: workspace.location,
|
|
27079
|
+
name: workspace.name
|
|
27080
|
+
};
|
|
27081
|
+
}
|
|
27082
|
+
return best?.name;
|
|
27083
|
+
}
|
|
27084
|
+
function pushUniqueImportSites(sites, seen, subPackage, usage, rootDir, workspaces) {
|
|
27085
|
+
for (const reference of allReferencesForUsage(usage)) {
|
|
27086
|
+
const key = `${reference.file}:${reference.line}:${subPackage}`;
|
|
27087
|
+
if (seen.has(key)) continue;
|
|
27088
|
+
seen.add(key);
|
|
27089
|
+
sites.push({
|
|
27090
|
+
file: reference.file,
|
|
27091
|
+
line: reference.line,
|
|
27092
|
+
subPackage,
|
|
27093
|
+
workspacePackage: workspacePackageForFile(reference.file, rootDir, workspaces)
|
|
27094
|
+
});
|
|
27095
|
+
}
|
|
27096
|
+
}
|
|
27097
|
+
function importSitesForSubPackages(subPackages, usage, rootDir, workspaces) {
|
|
27098
|
+
const sites = [];
|
|
27099
|
+
for (const subPackage of subPackages) {
|
|
27100
|
+
const entry = usage.get(subPackage);
|
|
27101
|
+
if (entry === void 0) continue;
|
|
27102
|
+
pushUniqueImportSites(sites, /* @__PURE__ */ new Set(), subPackage, entry, rootDir, workspaces);
|
|
27103
|
+
}
|
|
27104
|
+
return sites.toSorted((left, right) => {
|
|
27105
|
+
const byPkg = left.subPackage.localeCompare(right.subPackage);
|
|
27106
|
+
if (byPkg !== 0) return byPkg;
|
|
27107
|
+
const byFile = left.file.localeCompare(right.file);
|
|
27108
|
+
if (byFile !== 0) return byFile;
|
|
27109
|
+
return left.line - right.line;
|
|
27110
|
+
});
|
|
27111
|
+
}
|
|
27112
|
+
function findRestrictionIssues(barrelInfo, restrictedPaths, isRuleEnabled, usage, source, rootDir, workspaces) {
|
|
27067
27113
|
const issues = [];
|
|
27068
27114
|
for (const { descriptor, subPackages } of barrelInfo) {
|
|
27069
27115
|
const usedSubPackages = subPackages.filter((pkg) => usage.has(pkg));
|
|
@@ -27071,17 +27117,22 @@ function findRestrictionIssues(barrelInfo, restrictedPaths, isRuleEnabled, usage
|
|
|
27071
27117
|
const configured = configuredNamesForDescriptor(restrictedPaths, descriptor, source);
|
|
27072
27118
|
const configuredSet = new Set(configured);
|
|
27073
27119
|
const missingFromConfig = usedSubPackages.filter((pkg) => !configuredSet.has(pkg));
|
|
27120
|
+
const relevantSubPackages = !isRuleEnabled || configured.length === 0 ? usedSubPackages : missingFromConfig;
|
|
27121
|
+
if (relevantSubPackages.length === 0) continue;
|
|
27122
|
+
const importSites = importSitesForSubPackages(relevantSubPackages, usage, rootDir, workspaces);
|
|
27074
27123
|
if (!isRuleEnabled || configured.length === 0) {
|
|
27075
27124
|
issues.push({
|
|
27076
27125
|
descriptor,
|
|
27126
|
+
importSites,
|
|
27077
27127
|
kind: "missing",
|
|
27078
27128
|
missingFromConfig: usedSubPackages,
|
|
27079
27129
|
usedSubPackages
|
|
27080
27130
|
});
|
|
27081
27131
|
continue;
|
|
27082
27132
|
}
|
|
27083
|
-
|
|
27133
|
+
issues.push({
|
|
27084
27134
|
descriptor,
|
|
27135
|
+
importSites,
|
|
27085
27136
|
kind: "incomplete",
|
|
27086
27137
|
missingFromConfig,
|
|
27087
27138
|
usedSubPackages
|
|
@@ -27099,25 +27150,49 @@ async function findBarrelImportRestrictionIssues(rootDir) {
|
|
|
27099
27150
|
const watchSet = new Set(barrelInfo.flatMap((entry) => entry.subPackages));
|
|
27100
27151
|
const usage = collectExternalUsage(workspaces.map((workspace) => PATH.resolve(rootDir, workspace.location)), watchSet);
|
|
27101
27152
|
const source = readFileSync(resolved.eslintConfigPath, "utf8");
|
|
27102
|
-
return findRestrictionIssues(barrelInfo, resolved.restrictedPaths, resolved.ruleEnabled, usage, source);
|
|
27103
|
-
}
|
|
27104
|
-
function
|
|
27153
|
+
return findRestrictionIssues(barrelInfo, resolved.restrictedPaths, resolved.ruleEnabled, usage, source, rootDir, workspaces);
|
|
27154
|
+
}
|
|
27155
|
+
function formatImportSite(site, rootDir) {
|
|
27156
|
+
const relativeFile = PATH.relative(rootDir, site.file);
|
|
27157
|
+
const location = relativeFile.length > 0 ? relativeFile : site.file;
|
|
27158
|
+
const packageLabel = site.workspacePackage === void 0 ? "" : chalk.gray(` (${site.workspacePackage})`);
|
|
27159
|
+
return `${location}:${site.line}${packageLabel}`;
|
|
27160
|
+
}
|
|
27161
|
+
function reportImportSites(sites, rootDir) {
|
|
27162
|
+
if (sites.length === 0) return;
|
|
27163
|
+
const bySubPackage = /* @__PURE__ */ new Map();
|
|
27164
|
+
for (const site of sites) {
|
|
27165
|
+
const group = bySubPackage.get(site.subPackage) ?? [];
|
|
27166
|
+
group.push(site);
|
|
27167
|
+
bySubPackage.set(site.subPackage, group);
|
|
27168
|
+
}
|
|
27169
|
+
const sortedSubPackages = bySubPackage.keys().toArray().toSorted((left, right) => left.localeCompare(right));
|
|
27170
|
+
for (const subPackage of sortedSubPackages) {
|
|
27171
|
+
const group = bySubPackage.get(subPackage);
|
|
27172
|
+
if (group === void 0) continue;
|
|
27173
|
+
console.log(chalk.gray(` ${subPackage} imported by:`));
|
|
27174
|
+
for (const site of group) console.log(chalk.gray(` - ${formatImportSite(site, rootDir)}`));
|
|
27175
|
+
}
|
|
27176
|
+
}
|
|
27177
|
+
function reportBarrelImportRestrictionIssues(issues, rootDir = process.cwd()) {
|
|
27105
27178
|
if (issues.length === 0) return 0;
|
|
27106
27179
|
console.log(chalk.yellow("\nBarrel import restrictions"));
|
|
27107
27180
|
for (const issue of issues) {
|
|
27108
27181
|
if (issue.kind === "missing") {
|
|
27109
27182
|
console.log(chalk.yellow(` ${issue.descriptor.pkg}: sub-packages are imported but no-restricted-imports is not configured for this barrel`));
|
|
27110
27183
|
console.log(chalk.gray(` Run xy lint init to add restrictions for: ${issue.usedSubPackages.join(", ")}`));
|
|
27184
|
+
reportImportSites(issue.importSites, rootDir);
|
|
27111
27185
|
continue;
|
|
27112
27186
|
}
|
|
27113
27187
|
console.log(chalk.yellow(` ${issue.descriptor.pkg}: disallowed-imports list is missing entries for imported sub-packages`));
|
|
27114
27188
|
for (const name of issue.missingFromConfig) console.log(chalk.yellow(` - ${name}`));
|
|
27115
27189
|
console.log(chalk.gray(" Update eslint.config.ts or rerun xy lint init to include the missing entries"));
|
|
27190
|
+
reportImportSites(issue.importSites, rootDir);
|
|
27116
27191
|
}
|
|
27117
27192
|
return issues.length;
|
|
27118
27193
|
}
|
|
27119
27194
|
async function checkBarrelImportRestrictions(rootDir) {
|
|
27120
|
-
return reportBarrelImportRestrictionIssues(await findBarrelImportRestrictionIssues(rootDir));
|
|
27195
|
+
return reportBarrelImportRestrictionIssues(await findBarrelImportRestrictionIssues(rootDir), rootDir);
|
|
27121
27196
|
}
|
|
27122
27197
|
//#endregion
|
|
27123
27198
|
//#region src/actions/incremental.ts
|