@sshkeda/check 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +156 -2
- package/docs/how-to-make-check-pass.md +71 -0
- package/package.json +51 -4
- package/src/index.ts +8 -0
- package/src/internal/ban-abbreviated-words-in-declared-names.ts +165 -0
- package/src/internal/ban-checked-members-outside-calls.ts +151 -0
- package/src/internal/ban-comments.ts +23 -0
- package/src/internal/ban-comparing-or-switching-on-tag.ts +114 -0
- package/src/internal/ban-deadlines-inside-tests.ts +41 -0
- package/src/internal/ban-declared-values.ts +70 -0
- package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +67 -0
- package/src/internal/ban-failures-collected-as-results.ts +57 -0
- package/src/internal/ban-fallbacks-of-named-recoveries.ts +118 -0
- package/src/internal/ban-function-overloads.ts +107 -0
- package/src/internal/ban-global-error-in-failure-types.ts +146 -0
- package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +63 -0
- package/src/internal/ban-let-and-effect-mutable-ref.ts +79 -0
- package/src/internal/ban-logic-in-index-files.ts +178 -0
- package/src/internal/ban-namespaces-used-without-a-member.ts +176 -0
- package/src/internal/ban-node-builtins-that-effect-replaces.ts +42 -0
- package/src/internal/ban-parsing-outside-data-without-a-schema.ts +299 -0
- package/src/internal/ban-re-exports.ts +172 -0
- package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +239 -0
- package/src/internal/ban-retired-words-in-names.ts +49 -0
- package/src/internal/ban-scanning-directories-with-bun-glob.ts +79 -0
- package/src/internal/ban-shebang-lines.ts +26 -0
- package/src/internal/ban-timer-globals-and-the-global-object.ts +34 -0
- package/src/internal/ban-timer-schedules-without-deadlines.ts +240 -0
- package/src/internal/ban-type-and-interface-declarations.ts +48 -0
- package/src/internal/ban-type-predicates.ts +82 -0
- package/src/internal/ban-unknown-in-function-signatures.ts +143 -0
- package/src/internal/ban-vague-error-class-names.ts +28 -0
- package/src/internal/ban-vague-file-names.ts +51 -0
- package/src/internal/ban-what-a-file-is-not-granted.ts +512 -0
- package/src/internal/ban-while-do-while-and-for-loops.ts +27 -0
- package/src/internal/confine-service-declarations-to-granted-files.ts +116 -0
- package/src/internal/confine-the-stdio-service-to-terminal-output.ts +190 -0
- package/src/internal/define-the-lint-plugin-and-configs.ts +361 -0
- package/src/internal/describe-and-decode-rule-options.ts +22 -0
- package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +128 -0
- package/src/internal/keep-effect-testing-helpers-in-test-files.ts +157 -0
- package/src/internal/match-banned-modules-and-globals.ts +71 -0
- package/src/internal/match-effect-service-factories.ts +20 -0
- package/src/internal/require-a-named-const-for-compound-conditions.ts +44 -0
- package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +141 -0
- package/src/internal/require-service-keys-to-end-with-their-class-name.ts +64 -0
- package/src/internal/resolve-what-an-expression-imports.ts +295 -0
- package/src/internal/sort-type-constituents.ts +82 -0
- package/src/internal/split-names-into-words.ts +12 -0
- package/src/internal/visit-every-declared-name.ts +264 -0
- package/src/lib/tasks/index.ts +1 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +29 -0
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +41 -0
- package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +25 -0
- package/src/lib/tasks/internal/run-checks-over-one-typescript-project.ts +68 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +15 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +211 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +39 -0
- package/src/lib/tasks/lib/check-import-boundaries/index.ts +1 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +415 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-subpath-import-targets.ts +117 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-what-hides-an-import.ts +65 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/import-boundary-errors.ts +176 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/index.ts +1 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/declared-use-errors.ts +32 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-declared-use-violations.ts +38 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-sync-calls.ts +23 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-type-only-schemas.ts +375 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/index.ts +1 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +648 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +27 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +262 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/index.ts +1 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/find-ungranted-stdio-uses.ts +219 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/stdio-use-errors.ts +31 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/index.ts +1 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +357 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/inferrable-annotation-errors.ts +33 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/index.ts +1 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/internal/find-repeated-service-yields.ts +162 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/internal/repeated-service-yield-errors.ts +25 -0
- package/src/lib/tasks/lib/enforce-file-layout/index.ts +5 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +9 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +417 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +83 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +827 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +82 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +178 -0
- package/src/lib/tasks/lib/enforce-file-types/index.ts +5 -0
- package/src/lib/tasks/lib/enforce-file-types/internal/file-type-errors.ts +21 -0
- package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +78 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/index.ts +1 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +157 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +66 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-config-violations.ts +16 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-input-violations.ts +74 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-symbolic-links.ts +14 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/unformatted-file-errors.ts +12 -0
- package/src/lib/tasks/lib/judge-index-re-exports/index.ts +1 -0
- package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +353 -0
- package/src/lib/tasks/lib/judge-index-re-exports/internal/index-re-export-errors.ts +21 -0
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +15 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +123 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-unsafe-enum-assignments.ts +152 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/find-tsgolint-executable.ts +21 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +82 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-tsgolint-rule-messages.ts +68 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/index.ts +1 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +135 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +507 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-misplaced-files.ts +116 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-subdivided-directories.ts +29 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +451 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/list-binding-names.ts +49 -0
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +15 -0
- package/src/lib/tasks/lib/refuse-disable-directives/internal/disable-directive-errors.ts +45 -0
- package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +66 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/index.ts +1 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/error-mapping-errors.ts +21 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +135 -0
- package/src/lib/tasks/lib/require-separate-service-layers/index.ts +1 -0
- package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +170 -0
- package/src/lib/tasks/lib/require-separate-service-layers/internal/service-layer-errors.ts +21 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +14 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +117 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/linted-file-errors.ts +51 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +11 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/check-types-with-bun-check.ts +54 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/read-bun-check-output.ts +73 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/type-check-errors.ts +10 -0
- package/src/lib/tasks/shared/check-each-nested-package.ts +79 -0
- package/src/lib/tasks/shared/classify-files-by-role.ts +115 -0
- package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +2 -0
- package/src/lib/tasks/shared/create-the-module-resolver.ts +38 -0
- package/src/lib/tasks/shared/declare-lint-config-task.ts +13 -0
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +18 -0
- package/src/lib/tasks/shared/encode-compact-json.ts +5 -0
- package/src/lib/tasks/shared/find-installed-package-binaries.ts +62 -0
- package/src/lib/tasks/shared/find-module-requests.ts +482 -0
- package/src/lib/tasks/shared/find-named-package-manifests.ts +94 -0
- package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +60 -0
- package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +79 -0
- package/src/lib/tasks/shared/list-linted-files.ts +28 -0
- package/src/lib/tasks/shared/list-owned-files.ts +13 -0
- package/src/lib/tasks/shared/list-package-files.ts +66 -0
- package/src/lib/tasks/shared/load-the-lint-config.ts +176 -0
- package/src/lib/tasks/shared/match-granted-patch-files.ts +88 -0
- package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +310 -0
- package/src/lib/tasks/shared/print-failures-and-keep-detail-in-the-trace.ts +99 -0
- package/src/lib/tasks/shared/project-config-and-tool-errors.ts +485 -0
- package/src/lib/tasks/shared/query-the-typescript-project.ts +635 -0
- package/src/lib/tasks/shared/read-named-package-manifests.ts +53 -0
- package/src/lib/tasks/shared/read-package-manifest-object.ts +28 -0
- package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -0
- package/src/lib/tasks/shared/resolve-module-requests.ts +121 -0
- package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +98 -0
- package/src/lib/tasks/shared/tool-file-locations.ts +38 -0
- package/src/shared/bans-each-permission-lifts.ts +454 -0
- package/src/shared/config-file-names.ts +3 -0
- package/src/shared/find-retired-words.ts +17 -0
- package/src/shared/format-reported-failures.ts +31 -0
- package/src/shared/lint-rule-messages-and-patterns.ts +104 -0
- package/src/shared/match-file-names-and-path-prefixes.ts +18 -0
- package/src/shared/permission-grant-errors.ts +42 -0
- package/src/shared/record-and-grant-permissions-by-path.ts +419 -0
- package/src/shared/test-home-directories.ts +4 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ReportedErrors } from "@sshkeda/task/errors";
|
|
2
|
+
import type { PrintableError } from "@sshkeda/task/errors";
|
|
3
|
+
import { Array as Arrays, Effect, Path } from "effect";
|
|
4
|
+
import type { PlatformError } from "effect";
|
|
5
|
+
|
|
6
|
+
import { listedPackageFiles } from "./list-package-files.ts";
|
|
7
|
+
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
8
|
+
|
|
9
|
+
const CHECKED_PACKAGE = ".";
|
|
10
|
+
|
|
11
|
+
const INSTALLED_PACKAGES_DIRECTORY = "node_modules";
|
|
12
|
+
|
|
13
|
+
const isInstalledPackage = (packageDirectory: string) =>
|
|
14
|
+
packageDirectory.split("/").includes(INSTALLED_PACKAGES_DIRECTORY);
|
|
15
|
+
|
|
16
|
+
const locationInPackage = (
|
|
17
|
+
pathModule: Path.Path,
|
|
18
|
+
packageDirectory: string,
|
|
19
|
+
location: string | undefined,
|
|
20
|
+
) => {
|
|
21
|
+
if (location === undefined) {
|
|
22
|
+
return packageDirectory;
|
|
23
|
+
}
|
|
24
|
+
const isLocatedFromTheCheckedPackage =
|
|
25
|
+
pathModule.isAbsolute(location) || location.startsWith(`${packageDirectory}/`);
|
|
26
|
+
return isLocatedFromTheCheckedPackage ? location : pathModule.join(packageDirectory, location);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const locatedInPackage = (
|
|
30
|
+
pathModule: Path.Path,
|
|
31
|
+
packageDirectory: string,
|
|
32
|
+
printable: PrintableError,
|
|
33
|
+
): PrintableError =>
|
|
34
|
+
packageDirectory === CHECKED_PACKAGE
|
|
35
|
+
? printable
|
|
36
|
+
: {
|
|
37
|
+
tag: printable.tag,
|
|
38
|
+
location: locationInPackage(pathModule, packageDirectory, printable.location),
|
|
39
|
+
message: printable.message,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const packageDirectoriesIn = (directory: string) =>
|
|
43
|
+
listedPackageFiles(directory, []).pipe(
|
|
44
|
+
Effect.map(({ nestedPackageDirectories }) => [
|
|
45
|
+
CHECKED_PACKAGE,
|
|
46
|
+
...nestedPackageDirectories.filter((nested) => !isInstalledPackage(nested)),
|
|
47
|
+
]),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const inEachPackage = <Requirements>(
|
|
51
|
+
tool: string,
|
|
52
|
+
directory: string,
|
|
53
|
+
checkPackage: (
|
|
54
|
+
packageDirectory: string,
|
|
55
|
+
) => Effect.Effect<void, PlatformError.PlatformError | ReportedErrors, Requirements>,
|
|
56
|
+
) =>
|
|
57
|
+
Effect.gen(function* () {
|
|
58
|
+
const pathModule = yield* Path.Path;
|
|
59
|
+
const packageDirectories = yield* packageDirectoriesIn(directory).pipe(quietViolations(tool));
|
|
60
|
+
const reportedByPackage = yield* Effect.forEach(
|
|
61
|
+
packageDirectories,
|
|
62
|
+
(packageDirectory) =>
|
|
63
|
+
checkPackage(pathModule.join(directory, packageDirectory)).pipe(
|
|
64
|
+
Effect.as([]),
|
|
65
|
+
Effect.catchTag("ReportedErrors", ({ reportedErrors }) =>
|
|
66
|
+
Effect.succeed(
|
|
67
|
+
reportedErrors.map((printable) =>
|
|
68
|
+
locatedInPackage(pathModule, packageDirectory, printable),
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
{ concurrency: "unbounded" },
|
|
74
|
+
);
|
|
75
|
+
const reportedErrors = reportedByPackage.flat();
|
|
76
|
+
if (Arrays.isArrayNonEmpty(reportedErrors)) {
|
|
77
|
+
return yield* new ReportedErrors({ reportedErrors });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Path } from "effect";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
fileNameOf,
|
|
5
|
+
isEntryFileName,
|
|
6
|
+
isWithin,
|
|
7
|
+
LAYOUT_DIRECTORY_NAMES,
|
|
8
|
+
} from "../../../shared/match-file-names-and-path-prefixes.ts";
|
|
9
|
+
import {
|
|
10
|
+
SCRIPTS_DIRECTORY,
|
|
11
|
+
SOURCE_DIRECTORY,
|
|
12
|
+
TEST_DIRECTORY,
|
|
13
|
+
} from "../../../shared/test-home-directories.ts";
|
|
14
|
+
import { PACKAGE_MANIFEST_FILE } from "./find-named-package-manifests.ts";
|
|
15
|
+
import { toolFileIsPlaced } from "./tool-file-locations.ts";
|
|
16
|
+
|
|
17
|
+
export const SCRIPT_EXTENSIONS = [
|
|
18
|
+
".ts",
|
|
19
|
+
".tsx",
|
|
20
|
+
".mts",
|
|
21
|
+
".cts",
|
|
22
|
+
".js",
|
|
23
|
+
".jsx",
|
|
24
|
+
".mjs",
|
|
25
|
+
".cjs",
|
|
26
|
+
] as const;
|
|
27
|
+
|
|
28
|
+
export const joinedWithAnd = (items: readonly string[]) =>
|
|
29
|
+
new Intl.ListFormat("en", { type: "conjunction" }).format(items);
|
|
30
|
+
|
|
31
|
+
export const hasExtension = (path: string, extensions: readonly string[]) =>
|
|
32
|
+
extensions.some((extension) => path.endsWith(extension));
|
|
33
|
+
|
|
34
|
+
export const isScript = (path: string) => hasExtension(path, SCRIPT_EXTENSIONS);
|
|
35
|
+
|
|
36
|
+
const DECLARATION_FILE = /\.d\.[cm]?ts$/u;
|
|
37
|
+
|
|
38
|
+
export const isDeclarationFile = (path: string) => DECLARATION_FILE.test(path);
|
|
39
|
+
|
|
40
|
+
export const isPackageManifest = (path: string) => fileNameOf(path) === PACKAGE_MANIFEST_FILE;
|
|
41
|
+
|
|
42
|
+
export const directoryOf = (path: string) => path.split("/").slice(0, -1).join("/");
|
|
43
|
+
|
|
44
|
+
export const isTopLevelScript = (path: string) => {
|
|
45
|
+
const [directory, fileName, ...nested] = path.split("/");
|
|
46
|
+
return (
|
|
47
|
+
directory === SCRIPTS_DIRECTORY &&
|
|
48
|
+
fileName !== undefined &&
|
|
49
|
+
nested.length === 0 &&
|
|
50
|
+
isScript(fileName)
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const isUnderTestDirectory = (path: string) => isWithin(path, TEST_DIRECTORY);
|
|
55
|
+
|
|
56
|
+
export const isTestEntryFile = (path: string) =>
|
|
57
|
+
isUnderTestDirectory(path) && isScript(path) && !isDeclarationFile(path);
|
|
58
|
+
|
|
59
|
+
export const isRootSupportFile = (path: string) => !path.includes("/") && toolFileIsPlaced(path);
|
|
60
|
+
|
|
61
|
+
export const isSpecialContainer = (directory: string) =>
|
|
62
|
+
directory === "" || directory === SCRIPTS_DIRECTORY;
|
|
63
|
+
|
|
64
|
+
export const isStrictlyUnder = (directory: string, scope: string) =>
|
|
65
|
+
directory !== scope && (scope === "" || directory.startsWith(`${scope}/`));
|
|
66
|
+
|
|
67
|
+
export const enclosingDirectoriesOf = (path: string) => {
|
|
68
|
+
const segments = directoryOf(path)
|
|
69
|
+
.split("/")
|
|
70
|
+
.filter((segment) => segment !== "");
|
|
71
|
+
return segments.map((_segment, index) => segments.slice(0, index + 1).join("/"));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const SOURCE_NEVER_IMPORTS_SCRIPTS = {
|
|
75
|
+
path: SOURCE_DIRECTORY,
|
|
76
|
+
cannotImport: [SCRIPTS_DIRECTORY],
|
|
77
|
+
} as const;
|
|
78
|
+
|
|
79
|
+
export const repeatsSourceNeverImportsScripts = (grantPath: string, target: string) =>
|
|
80
|
+
isWithin(grantPath, SOURCE_NEVER_IMPORTS_SCRIPTS.path) &&
|
|
81
|
+
SOURCE_NEVER_IMPORTS_SCRIPTS.cannotImport.some((banned) => isWithin(target, banned));
|
|
82
|
+
|
|
83
|
+
const isLayoutDirectory = (directory: string) => LAYOUT_DIRECTORY_NAMES.has(fileNameOf(directory));
|
|
84
|
+
|
|
85
|
+
export const moduleDirectoriesAmong = (paths: readonly string[]) =>
|
|
86
|
+
new Set(
|
|
87
|
+
paths
|
|
88
|
+
.filter((path) => isEntryFileName(fileNameOf(path)))
|
|
89
|
+
.map((path) => directoryOf(path))
|
|
90
|
+
.filter(
|
|
91
|
+
(directory) =>
|
|
92
|
+
directory !== "" &&
|
|
93
|
+
!enclosingDirectoriesOf(`${directory}/`).some((enclosing) =>
|
|
94
|
+
isLayoutDirectory(enclosing),
|
|
95
|
+
),
|
|
96
|
+
),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
export const directoriesNestedInLayoutDirectoriesOf = (path: string) =>
|
|
100
|
+
enclosingDirectoriesOf(path).filter((directory) => isLayoutDirectory(directoryOf(directory)));
|
|
101
|
+
|
|
102
|
+
export const placementScopeOf = (directory: string) => {
|
|
103
|
+
const layoutDirectory = enclosingDirectoriesOf(`${directory}/`).findLast((enclosing) =>
|
|
104
|
+
isLayoutDirectory(enclosing),
|
|
105
|
+
);
|
|
106
|
+
return layoutDirectory === undefined ? directory : directoryOf(layoutDirectory);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const RELATIVE_SPECIFIER = /^\.{1,2}\//u;
|
|
110
|
+
|
|
111
|
+
export const isFileSpecifier = (specifier: string) =>
|
|
112
|
+
RELATIVE_SPECIFIER.test(specifier) || specifier.startsWith("/");
|
|
113
|
+
|
|
114
|
+
export const packagePathOf = (path: Path.Path, packageDirectory: string, file: string) =>
|
|
115
|
+
path.relative(packageDirectory, file).split(path.sep).join("/");
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ResolverFactory } from "oxc-resolver";
|
|
2
|
+
|
|
3
|
+
const RUNTIME_CONDITION_NAMES = ["bun", "import", "node", "default"] as const;
|
|
4
|
+
|
|
5
|
+
const TYPES_CONDITION_NAME = "types";
|
|
6
|
+
|
|
7
|
+
const resolversByConditions = new Map<string, ResolverFactory>();
|
|
8
|
+
|
|
9
|
+
const moduleResolverWith = (conditionNames: readonly string[]) => {
|
|
10
|
+
const key = conditionNames.join("\0");
|
|
11
|
+
const resolver =
|
|
12
|
+
resolversByConditions.get(key) ??
|
|
13
|
+
new ResolverFactory({
|
|
14
|
+
extensions: [".ts", ".tsx", ".mts", ".cts", ".d.ts", ".js", ".jsx", ".mjs", ".cjs", ".json"],
|
|
15
|
+
extensionAlias: {
|
|
16
|
+
".js": [".ts", ".tsx", ".js"],
|
|
17
|
+
".jsx": [".tsx", ".jsx"],
|
|
18
|
+
".mjs": [".mts", ".mjs"],
|
|
19
|
+
".cjs": [".cts", ".cjs"],
|
|
20
|
+
},
|
|
21
|
+
tsconfig: "auto",
|
|
22
|
+
builtinModules: true,
|
|
23
|
+
conditionNames: [...conditionNames],
|
|
24
|
+
});
|
|
25
|
+
resolversByConditions.set(key, resolver);
|
|
26
|
+
return resolver;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const conditionNamesWith = (customConditions: readonly string[]) => [
|
|
30
|
+
...customConditions,
|
|
31
|
+
TYPES_CONDITION_NAME,
|
|
32
|
+
...RUNTIME_CONDITION_NAMES,
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
export const moduleResolverFor = (customConditions: readonly string[]) =>
|
|
36
|
+
moduleResolverWith(conditionNamesWith(customConditions));
|
|
37
|
+
|
|
38
|
+
export const runtimeModuleResolver = () => moduleResolverWith(RUNTIME_CONDITION_NAMES);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Task } from "@sshkeda/task";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
|
|
4
|
+
import { inEachPackage } from "./check-each-nested-package.ts";
|
|
5
|
+
import { loadedLintConfigIn } from "./load-the-lint-config.ts";
|
|
6
|
+
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
7
|
+
|
|
8
|
+
export const lintConfigFile = Task.make(
|
|
9
|
+
"lint-config",
|
|
10
|
+
inEachPackage("lint-config", ".", (packageDirectory) =>
|
|
11
|
+
loadedLintConfigIn(packageDirectory).pipe(Effect.asVoid, quietViolations("lint-config")),
|
|
12
|
+
),
|
|
13
|
+
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Task } from "@sshkeda/task";
|
|
2
|
+
import { Path } from "effect";
|
|
3
|
+
|
|
4
|
+
import { inEachPackage } from "./check-each-nested-package.ts";
|
|
5
|
+
import { findTypeScriptConfigViolations } from "./find-unmet-typescript-config-requirements.ts";
|
|
6
|
+
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
7
|
+
import { TYPESCRIPT_PROJECT_FILE } from "./query-the-typescript-project.ts";
|
|
8
|
+
|
|
9
|
+
export const typeScriptConfig = Task.make(
|
|
10
|
+
"typescript-config",
|
|
11
|
+
inEachPackage("typescript-config", ".", (packageDirectory) =>
|
|
12
|
+
Path.Path.use((path) =>
|
|
13
|
+
findTypeScriptConfigViolations(path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE)).pipe(
|
|
14
|
+
quietViolations("typescript-config"),
|
|
15
|
+
),
|
|
16
|
+
),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Effect, FileSystem, Path, Predicate, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { PACKAGE_MANIFEST_FILE } from "./find-named-package-manifests.ts";
|
|
4
|
+
import {
|
|
5
|
+
InstalledPackageHasNoBinary,
|
|
6
|
+
PackageManifestFieldInvalid,
|
|
7
|
+
PackageNotInstalled,
|
|
8
|
+
} from "./project-config-and-tool-errors.ts";
|
|
9
|
+
import { packageManifestObject } from "./read-package-manifest-object.ts";
|
|
10
|
+
|
|
11
|
+
const MANIFEST_BINARIES = Schema.Struct({
|
|
12
|
+
bin: Schema.optionalKey(
|
|
13
|
+
Schema.Union([Schema.String, Schema.Record(Schema.String, Schema.String)]),
|
|
14
|
+
),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const unscopedName = (packageName: string) => packageName.split("/").at(-1) ?? packageName;
|
|
18
|
+
|
|
19
|
+
const declaredBinary = (
|
|
20
|
+
bin: (typeof MANIFEST_BINARIES.Type)["bin"],
|
|
21
|
+
packageName: string,
|
|
22
|
+
binaryName: string,
|
|
23
|
+
) => {
|
|
24
|
+
if (Predicate.isString(bin)) {
|
|
25
|
+
return binaryName === unscopedName(packageName) ? bin : undefined;
|
|
26
|
+
}
|
|
27
|
+
return bin?.[binaryName];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const installedBinary = (
|
|
31
|
+
packageDirectory: string,
|
|
32
|
+
packageName: string,
|
|
33
|
+
binaryName: string,
|
|
34
|
+
) =>
|
|
35
|
+
Effect.gen(function* () {
|
|
36
|
+
const path = yield* Path.Path;
|
|
37
|
+
const manifestFile = yield* Effect.tryPromise({
|
|
38
|
+
try: () => Bun.resolve(`${packageName}/${PACKAGE_MANIFEST_FILE}`, packageDirectory),
|
|
39
|
+
catch: (cause) =>
|
|
40
|
+
new PackageNotInstalled({
|
|
41
|
+
packageName,
|
|
42
|
+
packageDirectory,
|
|
43
|
+
reason: String(cause),
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
const manifestText = yield* FileSystem.FileSystem.pipe(
|
|
47
|
+
Effect.flatMap((fileSystem) => fileSystem.readFileString(manifestFile)),
|
|
48
|
+
);
|
|
49
|
+
const manifestObject = yield* Effect.fromResult(
|
|
50
|
+
packageManifestObject(manifestFile, manifestText),
|
|
51
|
+
);
|
|
52
|
+
const { bin } = yield* Schema.decodeEffect(MANIFEST_BINARIES)(manifestObject).pipe(
|
|
53
|
+
Effect.mapError(
|
|
54
|
+
(error) => new PackageManifestFieldInvalid({ path: manifestFile, reason: error.message }),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
const binary = declaredBinary(bin, packageName, binaryName);
|
|
58
|
+
if (binary === undefined) {
|
|
59
|
+
return yield* new InstalledPackageHasNoBinary({ packageName, binaryName });
|
|
60
|
+
}
|
|
61
|
+
return path.join(path.dirname(manifestFile), binary);
|
|
62
|
+
});
|