@codefast/cli 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/README.md +152 -56
- package/dist/arrange/command.js +24 -25
- package/dist/arrange/domain/ast/collectors-cn.d.ts +2 -2
- package/dist/arrange/domain/ast/collectors-cn.js +2 -2
- package/dist/arrange/domain/ast/collectors-jsx.d.ts +2 -2
- package/dist/arrange/domain/ast/collectors-jsx.js +1 -1
- package/dist/arrange/domain/ast/collectors-tv.d.ts +2 -2
- package/dist/arrange/domain/ast/collectors-tv.js +5 -5
- package/dist/arrange/domain/ast/helpers.d.ts +2 -2
- package/dist/arrange/domain/ast/helpers.js +3 -4
- package/dist/arrange/domain/ast/simplify-targets.d.ts +1 -1
- package/dist/arrange/domain/ast/simplify-targets.js +5 -5
- package/dist/arrange/domain/ast/targets.d.ts +2 -2
- package/dist/arrange/domain/ast/targets.js +9 -9
- package/dist/arrange/domain/ast/translator.d.ts +1 -1
- package/dist/arrange/domain/ast/translator.js +43 -29
- package/dist/arrange/domain/constants.d.ts +1 -1
- package/dist/arrange/domain/grouping-service.d.ts +2 -2
- package/dist/arrange/domain/grouping-service.js +3 -3
- package/dist/arrange/domain/grouping.js +3 -3
- package/dist/arrange/domain/imports.d.ts +1 -1
- package/dist/arrange/domain/imports.js +2 -2
- package/dist/arrange/domain/source-text-formatters.js +1 -1
- package/dist/arrange/domain/tailwind-token.js +1 -1
- package/dist/arrange/domain/token-classifier.d.ts +1 -1
- package/dist/arrange/domain/token-classifier.js +2 -2
- package/dist/arrange/domain/types.d.ts +3 -3
- package/dist/arrange/group/cli-result.d.ts +1 -1
- package/dist/arrange/group/output.d.ts +1 -1
- package/dist/arrange/group/output.js +1 -1
- package/dist/arrange/group/suggest.d.ts +2 -2
- package/dist/arrange/group/suggest.js +2 -2
- package/dist/arrange/inspect/cli-result.d.ts +1 -1
- package/dist/arrange/inspect/domain/analyze-service.d.ts +2 -2
- package/dist/arrange/inspect/domain/analyze-service.js +7 -7
- package/dist/arrange/inspect/output.d.ts +1 -1
- package/dist/arrange/inspect/output.js +2 -2
- package/dist/arrange/inspect/run.d.ts +4 -4
- package/dist/arrange/inspect/run.js +6 -6
- package/dist/arrange/prepare.d.ts +4 -4
- package/dist/arrange/prepare.js +5 -5
- package/dist/arrange/regroup/cli-result.d.ts +1 -1
- package/dist/arrange/regroup/cli-result.js +1 -1
- package/dist/arrange/regroup/output.d.ts +2 -2
- package/dist/arrange/regroup/output.js +2 -2
- package/dist/arrange/regroup/process-file.d.ts +2 -2
- package/dist/arrange/regroup/process-file.js +3 -3
- package/dist/arrange/regroup/run.d.ts +5 -5
- package/dist/arrange/regroup/run.js +4 -4
- package/dist/arrange/resolve-target.d.ts +1 -1
- package/dist/arrange/resolve-target.js +2 -2
- package/dist/arrange/scan-target.d.ts +1 -1
- package/dist/arrange/scan-target.js +3 -3
- package/dist/arrange/simplify/cli-result.d.ts +1 -1
- package/dist/arrange/simplify/fold-targets.d.ts +3 -3
- package/dist/arrange/simplify/fold-targets.js +3 -3
- package/dist/arrange/simplify/output.d.ts +1 -1
- package/dist/arrange/simplify/output.js +1 -1
- package/dist/arrange/simplify/process-file.d.ts +4 -4
- package/dist/arrange/simplify/process-file.js +5 -5
- package/dist/arrange/simplify/run.d.ts +4 -4
- package/dist/arrange/simplify/run.js +4 -4
- package/dist/arrange/simplify/variant-classname-probe.js +1 -1
- package/dist/arrange/source-parse.d.ts +1 -1
- package/dist/arrange/source-parse.js +3 -3
- package/dist/audit/assertions/cli-result.d.ts +13 -0
- package/dist/audit/assertions/cli-result.js +22 -0
- package/dist/audit/assertions/cli-schema.d.ts +18 -0
- package/dist/audit/assertions/cli-schema.js +12 -0
- package/dist/audit/assertions/domain/double-assertion.d.ts +20 -0
- package/dist/audit/assertions/domain/double-assertion.js +122 -0
- package/dist/audit/assertions/output.d.ts +7 -0
- package/dist/audit/assertions/output.js +21 -0
- package/dist/audit/assertions/prepare.d.ts +16 -0
- package/dist/audit/assertions/prepare.js +12 -0
- package/dist/audit/assertions/run.d.ts +14 -0
- package/dist/audit/assertions/run.js +40 -0
- package/dist/audit/command.js +89 -28
- package/dist/audit/comments/cli-result.d.ts +1 -1
- package/dist/audit/comments/cli-result.js +1 -1
- package/dist/audit/comments/output.d.ts +1 -1
- package/dist/audit/comments/output.js +1 -1
- package/dist/audit/comments/prepare.d.ts +4 -4
- package/dist/audit/comments/prepare.js +1 -1
- package/dist/audit/comments/run.d.ts +4 -4
- package/dist/audit/comments/run.js +9 -9
- package/dist/audit/constants/cli-result.d.ts +13 -0
- package/dist/audit/constants/cli-result.js +22 -0
- package/dist/audit/constants/cli-schema.d.ts +18 -0
- package/dist/audit/constants/cli-schema.js +12 -0
- package/dist/audit/constants/domain/constants.d.ts +8 -0
- package/dist/audit/constants/domain/constants.js +66 -0
- package/dist/audit/constants/output.d.ts +7 -0
- package/dist/audit/constants/output.js +21 -0
- package/dist/audit/constants/prepare.d.ts +16 -0
- package/dist/audit/constants/prepare.js +37 -0
- package/dist/audit/constants/run.d.ts +14 -0
- package/dist/audit/constants/run.js +64 -0
- package/dist/audit/display-names/cli-result.d.ts +1 -1
- package/dist/audit/display-names/cli-result.js +1 -1
- package/dist/audit/display-names/domain/display-names.d.ts +1 -1
- package/dist/audit/display-names/domain/display-names.js +1 -9
- package/dist/audit/display-names/output.d.ts +1 -1
- package/dist/audit/display-names/output.js +1 -1
- package/dist/audit/display-names/prepare.d.ts +4 -4
- package/dist/audit/display-names/prepare.js +1 -1
- package/dist/audit/display-names/run.d.ts +4 -4
- package/dist/audit/display-names/run.js +5 -5
- package/dist/audit/domain/types.d.ts +128 -0
- package/dist/audit/imports/cli-result.d.ts +1 -1
- package/dist/audit/imports/cli-result.js +1 -1
- package/dist/audit/imports/domain/import-policy.d.ts +1 -1
- package/dist/audit/imports/domain/import-policy.js +4 -18
- package/dist/audit/imports/output.d.ts +1 -1
- package/dist/audit/imports/output.js +1 -1
- package/dist/audit/imports/prepare.d.ts +4 -4
- package/dist/audit/imports/prepare.js +1 -1
- package/dist/audit/imports/run.d.ts +4 -4
- package/dist/audit/imports/run.js +6 -6
- package/dist/audit/links/cli-result.d.ts +1 -1
- package/dist/audit/links/cli-result.js +1 -1
- package/dist/audit/links/domain/markdown-links.d.ts +3 -3
- package/dist/audit/links/domain/markdown-links.js +22 -8
- package/dist/audit/links/output.d.ts +1 -1
- package/dist/audit/links/output.js +1 -1
- package/dist/audit/links/prepare.d.ts +4 -4
- package/dist/audit/links/prepare.js +1 -1
- package/dist/audit/links/run.d.ts +4 -4
- package/dist/audit/links/run.js +4 -4
- package/dist/audit/prepare.d.ts +4 -4
- package/dist/audit/prepare.js +4 -4
- package/dist/audit/publish/cli-result.d.ts +13 -0
- package/dist/audit/publish/cli-result.js +25 -0
- package/dist/audit/publish/cli-schema.d.ts +18 -0
- package/dist/audit/publish/cli-schema.js +12 -0
- package/dist/audit/publish/domain/legacy-subpath.d.ts +8 -0
- package/dist/audit/publish/domain/legacy-subpath.js +22 -0
- package/dist/audit/publish/domain/stylesheet-sources.d.ts +22 -0
- package/dist/audit/publish/domain/stylesheet-sources.js +64 -0
- package/dist/audit/publish/output.d.ts +7 -0
- package/dist/audit/publish/output.js +33 -0
- package/dist/audit/publish/prepare.d.ts +16 -0
- package/dist/audit/publish/prepare.js +12 -0
- package/dist/audit/publish/run.d.ts +15 -0
- package/dist/audit/publish/run.js +91 -0
- package/dist/audit/publish/shipped-files.d.ts +21 -0
- package/dist/audit/publish/shipped-files.js +36 -0
- package/dist/audit/rtl/cli-result.d.ts +1 -1
- package/dist/audit/rtl/cli-result.js +1 -1
- package/dist/audit/rtl/domain/audit-file.d.ts +1 -1
- package/dist/audit/rtl/domain/audit-file.js +2 -2
- package/dist/audit/rtl/domain/tokenize.d.ts +1 -1
- package/dist/audit/rtl/output.d.ts +1 -1
- package/dist/audit/rtl/output.js +1 -1
- package/dist/audit/rtl/prepare.d.ts +4 -4
- package/dist/audit/rtl/prepare.js +5 -5
- package/dist/audit/rtl/run.d.ts +4 -4
- package/dist/audit/rtl/run.js +4 -4
- package/dist/bin.js +1 -1
- package/dist/cli.js +5 -5
- package/dist/core/cli/command-pipeline.d.ts +4 -5
- package/dist/core/cli/command-pipeline.js +7 -7
- package/dist/core/cli/format-error.d.ts +1 -1
- package/dist/core/cli/resolve-root.d.ts +3 -3
- package/dist/core/cli/resolve-root.js +3 -3
- package/dist/core/cli/result-handle.d.ts +2 -2
- package/dist/core/cli/result-handle.js +4 -4
- package/dist/core/config/define-config.d.ts +1 -1
- package/dist/core/config/loader.d.ts +2 -2
- package/dist/core/config/loader.js +2 -2
- package/dist/core/config/schema.d.ts +5 -0
- package/dist/core/config/schema.js +2 -0
- package/dist/core/config/warnings.js +1 -1
- package/dist/core/config.d.ts +4 -4
- package/dist/core/config.js +4 -4
- package/dist/core/filesystem/filesystem.d.ts +3 -4
- package/dist/core/filesystem/node.d.ts +1 -1
- package/dist/core/filesystem/node.js +1 -7
- package/dist/core/oxc-node.d.ts +32 -0
- package/dist/core/oxc-node.js +25 -0
- package/dist/core/schema-parse.d.ts +2 -2
- package/dist/core/schema-parse.js +2 -2
- package/dist/core/source-position.d.ts +15 -0
- package/dist/core/source-position.js +26 -0
- package/dist/core/workspace/markdown-walk.d.ts +1 -1
- package/dist/core/workspace/markdown-walk.js +1 -1
- package/dist/core/workspace/package-version.d.ts +1 -1
- package/dist/core/workspace/package-version.js +2 -2
- package/dist/core/workspace/resolver.d.ts +1 -1
- package/dist/core/workspace/resolver.js +5 -5
- package/dist/core/workspace/source-walk.d.ts +1 -1
- package/dist/core/workspace/source-walk.js +1 -1
- package/dist/core/workspace/typescript-walk.d.ts +1 -1
- package/dist/core/workspace/typescript-walk.js +1 -1
- package/dist/core/workspace/walk-files.d.ts +1 -1
- package/dist/core/workspace/walk-files.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/mirror/cli-result.d.ts +1 -1
- package/dist/mirror/cli-result.js +1 -1
- package/dist/mirror/cli-schema.d.ts +1 -1
- package/dist/mirror/command.js +7 -7
- package/dist/mirror/dist-filesystem-node.d.ts +2 -2
- package/dist/mirror/dist-filesystem-node.js +5 -15
- package/dist/mirror/domain/exports.d.ts +2 -2
- package/dist/mirror/domain/exports.js +1 -1
- package/dist/mirror/domain/types.d.ts +2 -2
- package/dist/mirror/output.d.ts +1 -1
- package/dist/mirror/output.js +2 -2
- package/dist/mirror/package-path.d.ts +3 -3
- package/dist/mirror/package-path.js +3 -3
- package/dist/mirror/prepare.d.ts +5 -5
- package/dist/mirror/prepare.js +4 -4
- package/dist/mirror/run.d.ts +6 -6
- package/dist/mirror/run.js +7 -7
- package/dist/mirror/supplement-exports.d.ts +1 -1
- package/dist/mirror/supplement-exports.js +2 -2
- package/dist/mirror/sync-workspace-package.d.ts +3 -3
- package/dist/mirror/sync-workspace-package.js +11 -14
- package/dist/mirror/write-exports.d.ts +2 -2
- package/dist/mirror/write-exports.js +3 -3
- package/dist/pack-slim/cli-result.d.ts +1 -1
- package/dist/pack-slim/cli-result.js +1 -1
- package/dist/pack-slim/command.js +9 -9
- package/dist/pack-slim/domain/transform.d.ts +22 -1
- package/dist/pack-slim/domain/transform.js +65 -8
- package/dist/pack-slim/output.d.ts +1 -1
- package/dist/pack-slim/output.js +1 -1
- package/dist/pack-slim/prepare.d.ts +3 -3
- package/dist/pack-slim/prepare.js +2 -2
- package/dist/pack-slim/run.d.ts +5 -5
- package/dist/pack-slim/run.js +6 -6
- package/dist/pack-slim/working-tree.d.ts +2 -2
- package/dist/pack-slim/working-tree.js +2 -2
- package/dist/tag/cli-result.d.ts +1 -1
- package/dist/tag/cli-result.js +1 -1
- package/dist/tag/cli-schema.d.ts +1 -1
- package/dist/tag/command.js +7 -7
- package/dist/tag/domain/skip-filter.d.ts +1 -1
- package/dist/tag/domain/skip-filter.js +1 -1
- package/dist/tag/domain/types.d.ts +1 -1
- package/dist/tag/domain/version-summary.d.ts +5 -2
- package/dist/tag/output.d.ts +1 -1
- package/dist/tag/output.js +1 -1
- package/dist/tag/prepare.d.ts +4 -4
- package/dist/tag/prepare.js +4 -4
- package/dist/tag/run.d.ts +4 -4
- package/dist/tag/run.js +7 -7
- package/dist/tag/target/candidates.d.ts +2 -2
- package/dist/tag/target/candidates.js +2 -2
- package/dist/tag/target/resolve-path.d.ts +1 -1
- package/dist/tag/target/runner.d.ts +2 -2
- package/dist/tag/target/runner.js +3 -3
- package/dist/tag/writer/since-writer.d.ts +2 -2
- package/dist/tag/writer/since-writer.js +3 -5
- package/dist/tag/writer/version-resolver.d.ts +1 -1
- package/dist/tag/writer/version-resolver.js +1 -1
- package/package.json +7 -7
- package/dist/mirror/domain/dirent-guard.d.ts +0 -10
- package/dist/mirror/domain/dirent-guard.js +0 -15
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { scanLegacySubpathImports } from "#audit/publish/domain/legacy-subpath";
|
|
3
|
+
import { missesShippedFiles, scanStylesheetSources } from "#audit/publish/domain/stylesheet-sources";
|
|
4
|
+
import { listShippedFiles } from "#audit/publish/shipped-files";
|
|
5
|
+
import { AppError, messageFrom } from "#core/errors";
|
|
6
|
+
import { err, ok } from "#core/result";
|
|
7
|
+
import { listWorkspacePackageDirectories } from "#core/workspace/resolver";
|
|
8
|
+
import { sourceCommentLanguage, walkSourceFiles } from "#core/workspace/source-walk";
|
|
9
|
+
import { packageJsonFileName } from "#core/workspace/well-known-files";
|
|
10
|
+
import { unshippedPublishTargets } from "#pack-slim/domain/transform";
|
|
11
|
+
/**
|
|
12
|
+
* Reports what would break a consumer's install: a `#/`-prefixed import Node's ESM resolver rejects on
|
|
13
|
+
* the floor, an `exports`/`imports` target the slimmed publish manifest does not ship, and a shipped
|
|
14
|
+
* stylesheet whose `@source` paths reach none of the files that do ship.
|
|
15
|
+
*
|
|
16
|
+
* @since 0.12.0
|
|
17
|
+
*/
|
|
18
|
+
export async function runPublishAudit(fs, args) {
|
|
19
|
+
try {
|
|
20
|
+
const { rootDir, targetPath } = args;
|
|
21
|
+
const legacyImportFiles = [];
|
|
22
|
+
let legacyImportCount = 0;
|
|
23
|
+
// Tests are not published and may hold `#/` fixtures on purpose, so the specifier scan skips them.
|
|
24
|
+
const sourceFiles = walkSourceFiles(targetPath, fs).filter((filePath) => sourceCommentLanguage(filePath) === "js" && !filePath.split(path.sep).includes("tests"));
|
|
25
|
+
for (const absolutePath of sourceFiles) {
|
|
26
|
+
const imports = scanLegacySubpathImports(fs.readFileSync(absolutePath, "utf8"));
|
|
27
|
+
if (imports.length === 0) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
legacyImportCount += imports.length;
|
|
31
|
+
legacyImportFiles.push({ relativePath: toPosixPath(path.relative(rootDir, absolutePath)), imports });
|
|
32
|
+
}
|
|
33
|
+
const layout = await listWorkspacePackageDirectories(rootDir, fs, true);
|
|
34
|
+
const unshipped = [];
|
|
35
|
+
const unreachableStylesheets = [];
|
|
36
|
+
let packageCount = 0;
|
|
37
|
+
for (const packageDir of layout.packageDirectoryPathsAbsolute) {
|
|
38
|
+
const manifestPath = path.join(packageDir, packageJsonFileName);
|
|
39
|
+
if (!fs.existsSync(manifestPath)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
43
|
+
if (manifest.private === true) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
packageCount++;
|
|
47
|
+
const packageName = typeof manifest.name === "string" ? manifest.name : toPosixPath(path.relative(rootDir, packageDir));
|
|
48
|
+
for (const target of unshippedPublishTargets(manifest)) {
|
|
49
|
+
unshipped.push({ packageName, field: target.field, subpath: target.subpath, target: target.target });
|
|
50
|
+
}
|
|
51
|
+
for (const violation of unreachableStylesheetsOf(fs, { rootDir, packageDir, manifest })) {
|
|
52
|
+
unreachableStylesheets.push({ packageName, ...violation });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return ok({
|
|
56
|
+
legacyImportFiles,
|
|
57
|
+
unshipped,
|
|
58
|
+
unreachableStylesheets,
|
|
59
|
+
legacyImportCount,
|
|
60
|
+
scannedFileCount: sourceFiles.length,
|
|
61
|
+
packageCount,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (caughtError) {
|
|
65
|
+
return err(new AppError("INFRA_FAILURE", messageFrom(caughtError), caughtError));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// The shipped stylesheets whose `@source` paths register nothing the tarball ships — what a consumer's Tailwind scans.
|
|
69
|
+
function unreachableStylesheetsOf(fs, args) {
|
|
70
|
+
const { rootDir, packageDir, manifest } = args;
|
|
71
|
+
const shipped = listShippedFiles(fs, packageDir, manifest);
|
|
72
|
+
if (shipped === null) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
const violations = [];
|
|
76
|
+
for (const stylesheet of shipped.files.filter((file) => file.endsWith(".css"))) {
|
|
77
|
+
const stylesheetPath = path.join(packageDir, stylesheet);
|
|
78
|
+
const sources = scanStylesheetSources(fs.readFileSync(stylesheetPath, "utf8"));
|
|
79
|
+
if (sources.length > 0 && missesShippedFiles(stylesheet, sources, shipped.files)) {
|
|
80
|
+
violations.push({
|
|
81
|
+
stylesheet: toPosixPath(path.relative(rootDir, stylesheetPath)),
|
|
82
|
+
sources,
|
|
83
|
+
missingFilesEntries: shipped.missingEntries,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return violations;
|
|
88
|
+
}
|
|
89
|
+
function toPosixPath(filePath) {
|
|
90
|
+
return filePath.split(path.sep).join("/");
|
|
91
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Lists the files a package's slimmed tarball ships, read from disk. */
|
|
2
|
+
import type { Filesystem } from "#core/filesystem/filesystem";
|
|
3
|
+
/**
|
|
4
|
+
* What a package's tarball ships, plus the `files` entries that match nothing on disk.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.13.0
|
|
7
|
+
*/
|
|
8
|
+
export interface ShippedFiles {
|
|
9
|
+
/** Package-relative POSIX paths, sorted. */
|
|
10
|
+
readonly files: Array<string>;
|
|
11
|
+
readonly missingEntries: Array<string>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Lists the files a package ships once the publish step has slimmed it, or `null` with no `files` field to go by.
|
|
15
|
+
*
|
|
16
|
+
* @remarks Applies the same slim as `pack-slim`, so a subtree it drops is absent here too, and leaves out source maps,
|
|
17
|
+
* which the publish step deletes. Without a `files` field npm ships the whole directory, which leaves nothing to judge.
|
|
18
|
+
*
|
|
19
|
+
* @since 0.13.0
|
|
20
|
+
*/
|
|
21
|
+
export declare function listShippedFiles(fs: Filesystem, packageDir: string, manifest: Record<string, unknown>): ShippedFiles | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Lists the files a package's slimmed tarball ships, read from disk. */
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isSourceMapFile, slimPublishManifest } from "#pack-slim/domain/transform";
|
|
4
|
+
/**
|
|
5
|
+
* Lists the files a package ships once the publish step has slimmed it, or `null` with no `files` field to go by.
|
|
6
|
+
*
|
|
7
|
+
* @remarks Applies the same slim as `pack-slim`, so a subtree it drops is absent here too, and leaves out source maps,
|
|
8
|
+
* which the publish step deletes. Without a `files` field npm ships the whole directory, which leaves nothing to judge.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.13.0
|
|
11
|
+
*/
|
|
12
|
+
export function listShippedFiles(fs, packageDir, manifest) {
|
|
13
|
+
const { manifest: slimmed } = slimPublishManifest(manifest);
|
|
14
|
+
if (!Array.isArray(slimmed.files)) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const files = new Set();
|
|
18
|
+
const missingEntries = [];
|
|
19
|
+
for (const entry of slimmed.files) {
|
|
20
|
+
if (typeof entry !== "string" || entry.startsWith("!")) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
// An entry names a file, a directory whose whole subtree ships, or a glob.
|
|
24
|
+
const matches = [...fs.globSync(entry, { cwd: packageDir }), ...fs.globSync(`${entry}/**`, { cwd: packageDir })];
|
|
25
|
+
if (matches.length === 0) {
|
|
26
|
+
missingEntries.push(entry);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
for (const match of matches) {
|
|
30
|
+
if (fs.statSync(path.join(packageDir, match)).isFile()) {
|
|
31
|
+
files.add(match.split(path.sep).join("/"));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { files: [...files].filter((file) => !isSourceMapFile(file)).sort(), missingEntries };
|
|
36
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DIRECTION_RESOLVED_VARIANT, PHYSICAL_SIDE_VARIANT, RTL_MAPPINGS, RTL_REVERSE_MAPPINGS, RTL_SWAP_MAPPINGS, RTL_TRANSLATE_X_MAPPINGS, SLIDE_PREFIXES, } from "
|
|
2
|
-
import { collectTokens } from "
|
|
1
|
+
import { DIRECTION_RESOLVED_VARIANT, PHYSICAL_SIDE_VARIANT, RTL_MAPPINGS, RTL_REVERSE_MAPPINGS, RTL_SWAP_MAPPINGS, RTL_TRANSLATE_X_MAPPINGS, SLIDE_PREFIXES, } from "#audit/rtl/domain/mappings";
|
|
2
|
+
import { collectTokens } from "#audit/rtl/domain/tokenize";
|
|
3
3
|
/**
|
|
4
4
|
* A token satisfies an "rtl companion" requirement when the same file has a
|
|
5
5
|
* token whose variants include `rtl` and whose value matches. Variant order
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RtlClassToken } from "
|
|
1
|
+
import type { RtlClassToken } from "#audit/domain/types";
|
|
2
2
|
/**
|
|
3
3
|
* Splits a class token into [variant, value, modifier], colon/slash-aware of
|
|
4
4
|
* brackets and parens (arbitrary values like data-[side=left] or calc(...)).
|
package/dist/audit/rtl/output.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AuditCommandPrelude } from "
|
|
2
|
-
import { AppError } from "
|
|
3
|
-
import type { Filesystem } from "
|
|
4
|
-
import type { Result } from "
|
|
1
|
+
import type { AuditCommandPrelude } from "#audit/prepare";
|
|
2
|
+
import { AppError } from "#core/errors";
|
|
3
|
+
import type { Filesystem } from "#core/filesystem/filesystem";
|
|
4
|
+
import type { Result } from "#core/result";
|
|
5
5
|
/**
|
|
6
6
|
* Loads config and resolves the scan target for `audit rtl`.
|
|
7
7
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { resolveRepoRelativePath } from "
|
|
2
|
-
import { loadCodefastConfig } from "
|
|
3
|
-
import { AppError, messageFrom } from "
|
|
4
|
-
import { err, ok } from "
|
|
5
|
-
import { resolveProjectRoot } from "
|
|
1
|
+
import { resolveRepoRelativePath } from "#audit/prepare";
|
|
2
|
+
import { loadCodefastConfig } from "#core/config";
|
|
3
|
+
import { AppError, messageFrom } from "#core/errors";
|
|
4
|
+
import { err, ok } from "#core/result";
|
|
5
|
+
import { resolveProjectRoot } from "#core/workspace/resolver";
|
|
6
6
|
/**
|
|
7
7
|
* Loads config and resolves the scan target for `audit rtl`.
|
|
8
8
|
*
|
package/dist/audit/rtl/run.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RtlAuditResult } from "
|
|
2
|
-
import { AppError } from "
|
|
3
|
-
import type { Filesystem } from "
|
|
4
|
-
import type { Result } from "
|
|
1
|
+
import type { RtlAuditResult } from "#audit/domain/types";
|
|
2
|
+
import { AppError } from "#core/errors";
|
|
3
|
+
import type { Filesystem } from "#core/filesystem/filesystem";
|
|
4
|
+
import type { Result } from "#core/result";
|
|
5
5
|
/**
|
|
6
6
|
* Scans a target path for physical-direction Tailwind class violations.
|
|
7
7
|
*
|
package/dist/audit/rtl/run.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { auditFileContent } from "
|
|
3
|
-
import { AppError, messageFrom } from "
|
|
4
|
-
import { err, ok } from "
|
|
5
|
-
import { walkTsxFiles } from "
|
|
2
|
+
import { auditFileContent } from "#audit/rtl/domain/audit-file";
|
|
3
|
+
import { AppError, messageFrom } from "#core/errors";
|
|
4
|
+
import { err, ok } from "#core/result";
|
|
5
|
+
import { walkTsxFiles } from "#core/workspace/typescript-walk";
|
|
6
6
|
/**
|
|
7
7
|
* Scans a target path for physical-direction Tailwind class violations.
|
|
8
8
|
*
|
package/dist/bin.js
CHANGED
package/dist/cli.js
CHANGED
|
@@ -3,11 +3,11 @@ import path from "node:path";
|
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { Command } from "commander";
|
|
6
|
-
import { createArrangeCommand } from "
|
|
7
|
-
import { createAuditCommand } from "
|
|
8
|
-
import { createMirrorCommand } from "
|
|
9
|
-
import { createPackSlimCommand } from "
|
|
10
|
-
import { createTagCommand } from "
|
|
6
|
+
import { createArrangeCommand } from "#arrange/command";
|
|
7
|
+
import { createAuditCommand } from "#audit/command";
|
|
8
|
+
import { createMirrorCommand } from "#mirror/command";
|
|
9
|
+
import { createPackSlimCommand } from "#pack-slim/command";
|
|
10
|
+
import { createTagCommand } from "#tag/command";
|
|
11
11
|
function readVersion() {
|
|
12
12
|
try {
|
|
13
13
|
const dir = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
2
|
import type { ZodType } from "zod";
|
|
3
|
-
import type { GlobalCliOptions } from "
|
|
4
|
-
import type { AppError } from "
|
|
5
|
-
import type { Filesystem } from "
|
|
6
|
-
import type { Result } from "
|
|
3
|
+
import type { GlobalCliOptions } from "#core/cli/global-options";
|
|
4
|
+
import type { AppError } from "#core/errors";
|
|
5
|
+
import type { Filesystem } from "#core/filesystem/filesystem";
|
|
6
|
+
import type { Result } from "#core/result";
|
|
7
7
|
/**
|
|
8
8
|
* The options every command shares: the `--json` machine-output flag. Per-command option shapes extend this.
|
|
9
9
|
*
|
|
@@ -52,7 +52,6 @@ export interface CommandPipeline<Prelude, Request, RunResult, Presenter = never,
|
|
|
52
52
|
readonly name: string;
|
|
53
53
|
readonly help: string;
|
|
54
54
|
} | undefined;
|
|
55
|
-
readonly jsonHelp?: string | undefined;
|
|
56
55
|
readonly configureArgv?: ((command: Command) => void) | undefined;
|
|
57
56
|
readonly prepare: CommandPrepare<Prelude>;
|
|
58
57
|
readonly guard?: ((input: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import { globalCliCommanderOptionsSchema } from "
|
|
3
|
-
import { readOptionalPositionalArg } from "
|
|
4
|
-
import { consumeCliAppError } from "
|
|
5
|
-
import { logger } from "
|
|
6
|
-
import { parseWithSchema } from "
|
|
7
|
-
const DEFAULT_JSON_HELP = "Print one JSON
|
|
2
|
+
import { globalCliCommanderOptionsSchema } from "#core/cli/global-options";
|
|
3
|
+
import { readOptionalPositionalArg } from "#core/cli/positional";
|
|
4
|
+
import { consumeCliAppError } from "#core/cli/result-handle";
|
|
5
|
+
import { logger } from "#core/logger";
|
|
6
|
+
import { parseWithSchema } from "#core/schema-parse";
|
|
7
|
+
const DEFAULT_JSON_HELP = "Print one JSON object on stdout instead of the human-readable output";
|
|
8
8
|
function readGlobalOptions(command) {
|
|
9
9
|
return (command.optsWithGlobals?.() ?? command.opts());
|
|
10
10
|
}
|
|
@@ -68,7 +68,7 @@ export function applyCommandPipeline(command, fs, pipeline) {
|
|
|
68
68
|
if (pipeline.positional) {
|
|
69
69
|
command.argument(pipeline.positional.name, pipeline.positional.help);
|
|
70
70
|
}
|
|
71
|
-
command.option("--json",
|
|
71
|
+
command.option("--json", DEFAULT_JSON_HELP, false);
|
|
72
72
|
pipeline.configureArgv?.(command);
|
|
73
73
|
command.action(makeAction(fs, pipeline));
|
|
74
74
|
return command;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AppError } from "
|
|
2
|
-
import type { Filesystem } from "
|
|
3
|
-
import type { Result } from "
|
|
1
|
+
import { AppError } from "#core/errors";
|
|
2
|
+
import type { Filesystem } from "#core/filesystem/filesystem";
|
|
3
|
+
import type { Result } from "#core/result";
|
|
4
4
|
/**
|
|
5
5
|
* Resolves the project root as a `Result`, mapping a resolution failure to an `INFRA_FAILURE` error.
|
|
6
6
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AppError, messageFrom } from "
|
|
2
|
-
import { err, ok } from "
|
|
3
|
-
import { resolveProjectRoot } from "
|
|
1
|
+
import { AppError, messageFrom } from "#core/errors";
|
|
2
|
+
import { err, ok } from "#core/result";
|
|
3
|
+
import { resolveProjectRoot } from "#core/workspace/resolver";
|
|
4
4
|
/**
|
|
5
5
|
* Resolves the project root as a `Result`, mapping a resolution failure to an `INFRA_FAILURE` error.
|
|
6
6
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AppError } from "
|
|
2
|
-
import type { Result } from "
|
|
1
|
+
import type { AppError } from "#core/errors";
|
|
2
|
+
import type { Result } from "#core/result";
|
|
3
3
|
/**
|
|
4
4
|
* Narrows a `Result`, reporting a failure and setting the exit code, or logging an optional success message.
|
|
5
5
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import { formatAppError } from "
|
|
3
|
-
import { CLI_EXIT_GENERAL_ERROR, CLI_EXIT_USAGE } from "
|
|
4
|
-
import { logger } from "
|
|
5
|
-
import { isVerboseCliDiagnostics } from "
|
|
2
|
+
import { formatAppError } from "#core/cli/format-error";
|
|
3
|
+
import { CLI_EXIT_GENERAL_ERROR, CLI_EXIT_USAGE } from "#core/exit-codes";
|
|
4
|
+
import { logger } from "#core/logger";
|
|
5
|
+
import { isVerboseCliDiagnostics } from "#core/verbose-diagnostics";
|
|
6
6
|
function exitCodeForAppError(error) {
|
|
7
7
|
switch (error.code) {
|
|
8
8
|
case "NOT_FOUND":
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CodefastConfig } from "
|
|
2
|
-
import type { Filesystem } from "
|
|
1
|
+
import type { CodefastConfig } from "#core/config/schema";
|
|
2
|
+
import type { Filesystem } from "#core/filesystem/filesystem";
|
|
3
3
|
/**
|
|
4
4
|
* A loaded config together with its schema warnings and the path it was read from.
|
|
5
5
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import jiti from "jiti";
|
|
3
|
-
import { codefastConfigRootSchema } from "
|
|
4
|
-
import { ancestorDirectories } from "
|
|
3
|
+
import { codefastConfigRootSchema } from "#core/config/schema";
|
|
4
|
+
import { ancestorDirectories } from "#core/workspace/ancestor-directories";
|
|
5
5
|
function formatZodError(error, filePath) {
|
|
6
6
|
const formatted = error.issues
|
|
7
7
|
.map((issue) => {
|
|
@@ -71,7 +71,12 @@ interface CodefastAuditConfig {
|
|
|
71
71
|
links?: CodefastAuditAllowlistConfig | undefined;
|
|
72
72
|
comments?: CodefastAuditAllowlistConfig | undefined;
|
|
73
73
|
imports?: CodefastAuditAllowlistConfig | undefined;
|
|
74
|
+
assertions?: CodefastAuditAllowlistConfig | undefined;
|
|
74
75
|
displayNames?: CodefastAuditAllowlistConfig | undefined;
|
|
76
|
+
constants?: {
|
|
77
|
+
target?: string | undefined;
|
|
78
|
+
allowlist?: Array<string> | undefined;
|
|
79
|
+
} | undefined;
|
|
75
80
|
}
|
|
76
81
|
/**
|
|
77
82
|
* The validated root `codefast.config` shape.
|
|
@@ -58,7 +58,9 @@ const codefastAuditConfigSchema = z
|
|
|
58
58
|
links: codefastAuditAllowlistConfigSchema.optional(),
|
|
59
59
|
comments: codefastAuditAllowlistConfigSchema.optional(),
|
|
60
60
|
imports: codefastAuditAllowlistConfigSchema.optional(),
|
|
61
|
+
assertions: codefastAuditAllowlistConfigSchema.optional(),
|
|
61
62
|
displayNames: codefastAuditAllowlistConfigSchema.optional(),
|
|
63
|
+
constants: codefastAuditRtlConfigSchema.optional(),
|
|
62
64
|
})
|
|
63
65
|
.strict();
|
|
64
66
|
/**
|
package/dist/core/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { CodefastConfig } from "
|
|
2
|
-
import { AppError } from "
|
|
3
|
-
import type { Filesystem } from "
|
|
4
|
-
import type { Result } from "
|
|
1
|
+
import type { CodefastConfig } from "#core/config/schema";
|
|
2
|
+
import { AppError } from "#core/errors";
|
|
3
|
+
import type { Filesystem } from "#core/filesystem/filesystem";
|
|
4
|
+
import type { Result } from "#core/result";
|
|
5
5
|
/**
|
|
6
6
|
* Loads the `codefast.config.js` for a workspace root, reporting schema warnings along the way.
|
|
7
7
|
*
|
package/dist/core/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { loadConfigPayload } from "
|
|
2
|
-
import { reportSchemaWarnings } from "
|
|
3
|
-
import { AppError, messageFrom } from "
|
|
4
|
-
import { err, ok } from "
|
|
1
|
+
import { loadConfigPayload } from "#core/config/loader";
|
|
2
|
+
import { reportSchemaWarnings } from "#core/config/warnings";
|
|
3
|
+
import { AppError, messageFrom } from "#core/errors";
|
|
4
|
+
import { err, ok } from "#core/result";
|
|
5
5
|
/**
|
|
6
6
|
* Loads the `codefast.config.js` for a workspace root, reporting schema warnings along the way.
|
|
7
7
|
*
|
|
@@ -32,10 +32,9 @@ export interface Filesystem {
|
|
|
32
32
|
readdirSync(filePath: string): Array<string>;
|
|
33
33
|
readFile(filePath: string, encoding: CliFileEncoding): Promise<string>;
|
|
34
34
|
writeFile(filePath: string, data: string, encoding: CliFileEncoding): Promise<void>;
|
|
35
|
-
|
|
36
|
-
recursive?: boolean;
|
|
37
|
-
|
|
38
|
-
}): Promise<Array<string> | Array<DirectoryEntry>>;
|
|
35
|
+
readdirEntries(filePath: string, options?: {
|
|
36
|
+
readonly recursive?: boolean | undefined;
|
|
37
|
+
}): Promise<Array<DirectoryEntry>>;
|
|
39
38
|
globSync(pattern: string, options: {
|
|
40
39
|
readonly cwd: string;
|
|
41
40
|
}): Array<string>;
|
|
@@ -22,13 +22,7 @@ export const nodeFilesystem = {
|
|
|
22
22
|
},
|
|
23
23
|
readFile: (filePath, enc) => fsPromises.readFile(filePath, enc),
|
|
24
24
|
writeFile: (filePath, data, enc) => fsPromises.writeFile(filePath, data, enc),
|
|
25
|
-
|
|
26
|
-
const raw = await fsPromises.readdir(filePath, opts);
|
|
27
|
-
if (!opts?.withFileTypes) {
|
|
28
|
-
return raw;
|
|
29
|
-
}
|
|
30
|
-
return raw;
|
|
31
|
-
},
|
|
25
|
+
readdirEntries: (filePath, options) => fsPromises.readdir(filePath, { recursive: options?.recursive ?? false, withFileTypes: true }),
|
|
32
26
|
globSync: (pattern, options) => fsSync.globSync(pattern, options),
|
|
33
27
|
rename: (oldPath, newPath) => fsPromises.rename(oldPath, newPath),
|
|
34
28
|
unlink: (filePath) => fsPromises.unlink(filePath),
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The structural view every module that walks `oxc-parser`'s ESTree output reads nodes through.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* An oxc ESTree node: a `type` discriminant, UTF-16 `start`/`end` offsets, and fields read by name.
|
|
6
|
+
*
|
|
7
|
+
* @remarks Structural on purpose: the walkers match node shapes by `type` and read the few fields
|
|
8
|
+
* they need, so the parser's full node union never has to be spelled out.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.13.0
|
|
11
|
+
*/
|
|
12
|
+
export interface OxcNode {
|
|
13
|
+
readonly type: string;
|
|
14
|
+
readonly start: number;
|
|
15
|
+
readonly end: number;
|
|
16
|
+
readonly [key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns whether a value is an ESTree node rather than a scalar, a list or a location record.
|
|
20
|
+
*
|
|
21
|
+
* @since 0.13.0
|
|
22
|
+
*/
|
|
23
|
+
export declare function isOxcNode(value: unknown): value is OxcNode;
|
|
24
|
+
/**
|
|
25
|
+
* Returns a parsed program's top-level statements.
|
|
26
|
+
*
|
|
27
|
+
* @remarks Takes `parseSync(...).program` as it comes, so no caller asserts the parser's type onto
|
|
28
|
+
* the structural view.
|
|
29
|
+
*
|
|
30
|
+
* @since 0.13.0
|
|
31
|
+
*/
|
|
32
|
+
export declare function programStatements(program: unknown): ReadonlyArray<OxcNode>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The structural view every module that walks `oxc-parser`'s ESTree output reads nodes through.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Returns whether a value is an ESTree node rather than a scalar, a list or a location record.
|
|
6
|
+
*
|
|
7
|
+
* @since 0.13.0
|
|
8
|
+
*/
|
|
9
|
+
export function isOxcNode(value) {
|
|
10
|
+
return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Returns a parsed program's top-level statements.
|
|
14
|
+
*
|
|
15
|
+
* @remarks Takes `parseSync(...).program` as it comes, so no caller asserts the parser's type onto
|
|
16
|
+
* the structural view.
|
|
17
|
+
*
|
|
18
|
+
* @since 0.13.0
|
|
19
|
+
*/
|
|
20
|
+
export function programStatements(program) {
|
|
21
|
+
if (!isOxcNode(program) || !Array.isArray(program.body)) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
return program.body.filter(isOxcNode);
|
|
25
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ZodType } from "zod";
|
|
2
|
-
import { AppError } from "
|
|
3
|
-
import type { Result } from "
|
|
2
|
+
import { AppError } from "#core/errors";
|
|
3
|
+
import type { Result } from "#core/result";
|
|
4
4
|
/**
|
|
5
5
|
* Parses an input against a Zod schema and returns a `Result` with the value or a validation `AppError`.
|
|
6
6
|
*
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an offset sits in a source text, as the audits report it.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Returns the one-based line an offset falls on.
|
|
6
|
+
*
|
|
7
|
+
* @since 0.13.0
|
|
8
|
+
*/
|
|
9
|
+
export declare function lineOfOffset(sourceText: string, offset: number): number;
|
|
10
|
+
/**
|
|
11
|
+
* Returns a text up to its first line break, so a multi-line node reports as one line.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.13.0
|
|
14
|
+
*/
|
|
15
|
+
export declare function firstLineOf(text: string): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an offset sits in a source text, as the audits report it.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Returns the one-based line an offset falls on.
|
|
6
|
+
*
|
|
7
|
+
* @since 0.13.0
|
|
8
|
+
*/
|
|
9
|
+
export function lineOfOffset(sourceText, offset) {
|
|
10
|
+
let line = 1;
|
|
11
|
+
for (let index = 0; index < offset; index++) {
|
|
12
|
+
if (sourceText.charCodeAt(index) === 10) {
|
|
13
|
+
line++;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return line;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns a text up to its first line break, so a multi-line node reports as one line.
|
|
20
|
+
*
|
|
21
|
+
* @since 0.13.0
|
|
22
|
+
*/
|
|
23
|
+
export function firstLineOf(text) {
|
|
24
|
+
const newlineIndex = text.indexOf("\n");
|
|
25
|
+
return newlineIndex === -1 ? text : text.slice(0, newlineIndex);
|
|
26
|
+
}
|