@effected/workspaces 0.32.0 → 0.33.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/ImportGraph.js +525 -0
- package/README.md +54 -2
- package/SourceBoundary.js +15 -40
- package/internal/importPosition.js +642 -0
- package/internal/sourceText.js +1 -1
- package/internal/sourceWalk.js +58 -0
- package/package.json +11 -11
- package/testing.d.ts +418 -104
- package/testing.js +3 -2
package/SourceBoundary.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isIdentifierChar, lex, locate, references, specifierLiterals } from "./internal/sourceText.js";
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_EXTENSIONS, walkSources } from "./internal/sourceWalk.js";
|
|
3
|
+
import { Effect, FileSystem, Schema } from "effect";
|
|
3
4
|
import { GlobSet } from "@effected/glob";
|
|
4
5
|
|
|
5
6
|
//#region src/SourceBoundary.ts
|
|
@@ -57,15 +58,6 @@ var SourceScan = class extends Schema.Class("SourceScan")({
|
|
|
57
58
|
return this.offences.map((offence) => offence.label);
|
|
58
59
|
}
|
|
59
60
|
};
|
|
60
|
-
const DEFAULT_EXTENSIONS = [
|
|
61
|
-
".ts",
|
|
62
|
-
".mts",
|
|
63
|
-
".cts",
|
|
64
|
-
".js",
|
|
65
|
-
".mjs",
|
|
66
|
-
".cjs"
|
|
67
|
-
];
|
|
68
|
-
const DECLARATION = /\.d\.[cm]?ts$/;
|
|
69
61
|
const byCodeUnit = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
70
62
|
const byPosition = (a, b) => byCodeUnit(a.file, b.file) || a.line - b.line || a.column - b.column;
|
|
71
63
|
const EXEMPT = ["process.env.__PACKAGE_VERSION__"];
|
|
@@ -548,9 +540,10 @@ var SourceBoundary = class SourceBoundary {
|
|
|
548
540
|
* Check every source file under `root` against `rules`.
|
|
549
541
|
*
|
|
550
542
|
* @remarks
|
|
551
|
-
* Walks with
|
|
543
|
+
* Walks with the shared source walker (`internal/sourceWalk.ts`, which the
|
|
544
|
+
* `ImportGraph` checks also use): each real directory is visited once (via
|
|
552
545
|
* `realPath`), so a symlink loop terminates and a linked directory is not
|
|
553
|
-
* scanned twice
|
|
546
|
+
* scanned twice, and `node_modules` is never entered. Paths come back relative
|
|
554
547
|
* and `/`-separated whatever the platform's separator, and that is also
|
|
555
548
|
* what `allow` globs match against. A missing root fails; it never scans
|
|
556
549
|
* nothing. A dangling symlink under the root is skipped, having nothing to
|
|
@@ -570,42 +563,24 @@ var SourceBoundary = class SourceBoundary {
|
|
|
570
563
|
*/
|
|
571
564
|
static scan = Effect.fn("SourceBoundary.scan")(function* (options) {
|
|
572
565
|
const fs = yield* FileSystem.FileSystem;
|
|
573
|
-
const path = yield* Path.Path;
|
|
574
566
|
const allow = yield* GlobSet.compile(options.allow ?? []);
|
|
575
567
|
const allowRules = /* @__PURE__ */ new Map();
|
|
576
568
|
for (const [rule, patterns] of Object.entries(options.allowRules ?? {})) if (patterns !== void 0) allowRules.set(rule, yield* GlobSet.compile(patterns));
|
|
577
|
-
const
|
|
578
|
-
|
|
569
|
+
const walked = yield* walkSources({
|
|
570
|
+
root: options.root,
|
|
571
|
+
extensions: options.extensions ?? DEFAULT_EXTENSIONS
|
|
572
|
+
});
|
|
579
573
|
const files = [];
|
|
580
574
|
const allowed = [];
|
|
581
575
|
const offences = [];
|
|
582
576
|
const waived = [];
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
const real = yield* fs.realPath(directory);
|
|
589
|
-
if (visited.has(real)) continue;
|
|
590
|
-
visited.add(real);
|
|
591
|
-
for (const name of yield* fs.readDirectory(directory)) {
|
|
592
|
-
const full = path.join(directory, name);
|
|
593
|
-
const found = yield* fs.stat(full).pipe(Effect.map(Option.some), Effect.catch((error) => error.reason._tag === "NotFound" ? fs.readLink(full).pipe(Effect.as(Option.none()), Effect.mapError(() => error)) : Effect.fail(error)));
|
|
594
|
-
if (Option.isNone(found)) continue;
|
|
595
|
-
const info = found.value;
|
|
596
|
-
if (info.type === "Directory") {
|
|
597
|
-
if (name !== "node_modules") pending.push(full);
|
|
598
|
-
continue;
|
|
599
|
-
}
|
|
600
|
-
if (info.type !== "File" || DECLARATION.test(name) || !extensions.some((extension) => name.endsWith(extension))) continue;
|
|
601
|
-
const file = posix(path.relative(options.root, full));
|
|
602
|
-
files.push(file);
|
|
603
|
-
if (allow.matches(file)) {
|
|
604
|
-
allowed.push(file);
|
|
605
|
-
continue;
|
|
606
|
-
}
|
|
607
|
-
for (const offence of SourceBoundary.check(file, yield* fs.readFileString(full), options.rules, options)) (allowRules.get(offence.rule)?.matches(file) === true ? waived : offences).push(offence);
|
|
577
|
+
for (const source of walked) {
|
|
578
|
+
files.push(source.file);
|
|
579
|
+
if (allow.matches(source.file)) {
|
|
580
|
+
allowed.push(source.file);
|
|
581
|
+
continue;
|
|
608
582
|
}
|
|
583
|
+
for (const offence of SourceBoundary.check(source.file, yield* fs.readFileString(source.path), options.rules, options)) (allowRules.get(offence.rule)?.matches(source.file) === true ? waived : offences).push(offence);
|
|
609
584
|
}
|
|
610
585
|
return SourceScan.make({
|
|
611
586
|
files: files.sort(byCodeUnit),
|