@effected/workspaces 0.42.0 → 0.43.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/SourceBoundary.js +124 -2
- package/package.json +9 -9
- package/testing.d.ts +45 -7
package/SourceBoundary.js
CHANGED
|
@@ -25,7 +25,8 @@ var Offence = class extends Schema.Class("Offence")({
|
|
|
25
25
|
"console-stdout",
|
|
26
26
|
"forbidImports",
|
|
27
27
|
"forbidTokens",
|
|
28
|
-
"forbidImportedNames"
|
|
28
|
+
"forbidImportedNames",
|
|
29
|
+
"promiseInExclusive"
|
|
29
30
|
]),
|
|
30
31
|
/**
|
|
31
32
|
* What matched: the identifier, the call, the import specifier, the token,
|
|
@@ -283,6 +284,37 @@ const tokenOccurrences = (code, token) => {
|
|
|
283
284
|
};
|
|
284
285
|
const forbids = (entry, specifier) => entry.endsWith("*") ? specifier.startsWith(entry.slice(0, -1)) : specifier === entry || specifier.startsWith(`${entry}/`);
|
|
285
286
|
const isNodeModule = (specifier, module) => [module, `node:${module}`].some((name) => specifier === name || specifier.startsWith(`${name}/`));
|
|
287
|
+
const LANE_BINDING = /(?<![\p{ID_Continue}$.#])(?:const|let|var)\s+([\p{ID_Start}$_][\p{ID_Continue}$]*)\s*=\s*(?:(?:yield\s*\*|await)\s*)?Exclusive\s*\.\s*make(?![\p{ID_Continue}$])/gu;
|
|
288
|
+
const PROMISE_CALL = /(?<![\p{ID_Continue}$.#])Effect\s*\.\s*(promise|runPromiseExit|runPromise)\s*(?:<[^()]*>\s*)?\(/gu;
|
|
289
|
+
/** Where `code` calls `<lane>.run(`, as the offsets just inside the opening paren and of the matching close (end of text when unbalanced). */
|
|
290
|
+
const runSpans = (code, lane) => {
|
|
291
|
+
const call = new RegExp(`(?<![\\p{ID_Continue}$.#])${lane.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")}\\s*(?:\\?\\.|\\.)\\s*run\\s*\\(`, "gu");
|
|
292
|
+
return [...code.matchAll(call)].map((match) => {
|
|
293
|
+
const from = (match.index ?? 0) + match[0].length;
|
|
294
|
+
let depth = 1;
|
|
295
|
+
let to = from;
|
|
296
|
+
for (; to < code.length && depth > 0; to++) if (code[to] === "(") depth++;
|
|
297
|
+
else if (code[to] === ")") depth--;
|
|
298
|
+
return {
|
|
299
|
+
from,
|
|
300
|
+
to
|
|
301
|
+
};
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
/** Every `Effect.promise(` or `Effect.runPromise(` lexically inside a `<lane>.run(` call, for each lane the file binds from `Exclusive.make` or `lanes` names. */
|
|
305
|
+
const promisesInLanes = (code, lanes) => {
|
|
306
|
+
const names = /* @__PURE__ */ new Set([...[...code.matchAll(LANE_BINDING)].map((match) => match[1] ?? ""), ...lanes]);
|
|
307
|
+
names.delete("");
|
|
308
|
+
const found = /* @__PURE__ */ new Map();
|
|
309
|
+
for (const lane of names) for (const { from, to } of runSpans(code, lane)) for (const call of code.slice(from, to).matchAll(PROMISE_CALL)) {
|
|
310
|
+
const offset = from + (call.index ?? 0);
|
|
311
|
+
if (!found.has(offset)) found.set(offset, `${lane}.run: Effect.${call[1]}`);
|
|
312
|
+
}
|
|
313
|
+
return [...found].map(([offset, detail]) => ({
|
|
314
|
+
offset,
|
|
315
|
+
detail
|
|
316
|
+
}));
|
|
317
|
+
};
|
|
286
318
|
const FIXTURES = [
|
|
287
319
|
{
|
|
288
320
|
name: "process: destructuring",
|
|
@@ -635,6 +667,72 @@ const FIXTURES = [
|
|
|
635
667
|
} },
|
|
636
668
|
flagged: false
|
|
637
669
|
},
|
|
670
|
+
{
|
|
671
|
+
name: "promiseInExclusive: Effect.promise in a lane body",
|
|
672
|
+
source: "const lane = yield* Exclusive.make;\nlane.run(Effect.promise(() => f()), { timeout: \"1s\" });",
|
|
673
|
+
rule: { promiseInExclusive: {} },
|
|
674
|
+
flagged: true
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
name: "promiseInExclusive: Effect.promise nested in Effect.gen in a lane body",
|
|
678
|
+
source: "const lane = yield* Exclusive.make;\nlane.run(Effect.gen(function* () { yield* Effect.promise(() => f()); }), { timeout: 1 });",
|
|
679
|
+
rule: { promiseInExclusive: {} },
|
|
680
|
+
flagged: true
|
|
681
|
+
},
|
|
682
|
+
{
|
|
683
|
+
name: "promiseInExclusive: Effect.runPromise in a lane body",
|
|
684
|
+
source: "const lane = yield* Exclusive.make;\nlane.run(Effect.sync(() => Effect.runPromise(g)), { timeout: 1 });",
|
|
685
|
+
rule: { promiseInExclusive: {} },
|
|
686
|
+
flagged: true
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
name: "promiseInExclusive: Effect.promise with a type argument in a lane body",
|
|
690
|
+
source: "const lane = yield* Exclusive.make;\nlane.run(Effect.promise<void>(() => f()), { timeout: 1 });",
|
|
691
|
+
rule: { promiseInExclusive: {} },
|
|
692
|
+
flagged: true
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
name: "promiseInExclusive: Effect.runPromiseExit in a lane body",
|
|
696
|
+
source: "const lane = yield* Exclusive.make;\nlane.run(Effect.sync(() => Effect.runPromiseExit(g)), { timeout: 1 });",
|
|
697
|
+
rule: { promiseInExclusive: {} },
|
|
698
|
+
flagged: true
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
name: "promiseInExclusive: a lane passed in and named in lanes",
|
|
702
|
+
source: "lane.run(Effect.promise(() => f()), { timeout: 1 });",
|
|
703
|
+
rule: { promiseInExclusive: { lanes: ["lane"] } },
|
|
704
|
+
flagged: true
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
name: "promiseInExclusive: Exclusive.promise in a lane body",
|
|
708
|
+
source: "const lane = yield* Exclusive.make;\nlane.run(Exclusive.promise(lane, (s) => f(s)), { timeout: 1 });",
|
|
709
|
+
rule: { promiseInExclusive: {} },
|
|
710
|
+
flagged: false
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
name: "promiseInExclusive: Effect.promise after the run call closes",
|
|
714
|
+
source: "const lane = yield* Exclusive.make;\nlane.run(body, { timeout: 1 });\nconst p = Effect.promise(() => f());",
|
|
715
|
+
rule: { promiseInExclusive: {} },
|
|
716
|
+
flagged: false
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
name: "promiseInExclusive: the call named in a string",
|
|
720
|
+
source: "const lane = yield* Exclusive.make;\nlane.run(Effect.succeed(\"Effect.promise(x)\"), { timeout: 1 });",
|
|
721
|
+
rule: { promiseInExclusive: {} },
|
|
722
|
+
flagged: false
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
name: "promiseInExclusive: the call named in a comment",
|
|
726
|
+
source: "const lane = yield* Exclusive.make;\nlane.run(body /* Effect.promise(x) */, { timeout: 1 });",
|
|
727
|
+
rule: { promiseInExclusive: {} },
|
|
728
|
+
flagged: false
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
name: "promiseInExclusive: a receiver nothing binds from Exclusive.make",
|
|
732
|
+
source: "other.run(Effect.promise(() => f()), { timeout: 1 });",
|
|
733
|
+
rule: { promiseInExclusive: {} },
|
|
734
|
+
flagged: false
|
|
735
|
+
},
|
|
638
736
|
{
|
|
639
737
|
name: "forbidTokens: a private field",
|
|
640
738
|
source: "const v = this.#process.env.__PACKAGE_VERSION__;",
|
|
@@ -715,8 +813,27 @@ var SourceBoundary = class SourceBoundary {
|
|
|
715
813
|
static stripComments = (text) => lex(text).withoutComments;
|
|
716
814
|
/** Whether `text` reads the global `process` in code (see {@link BoundaryRule}). */
|
|
717
815
|
static referencesProcess = (text, options) => processReads(lex(text).code, [...EXEMPT, ...options?.ignoreTokens ?? []]).length > 0;
|
|
718
|
-
/**
|
|
816
|
+
/**
|
|
817
|
+
* Every module specifier `text` imports: static, side-effect, re-export, type-only, `import(...)` with a literal, and `require(...)`.
|
|
818
|
+
*
|
|
819
|
+
* @remarks
|
|
820
|
+
* One entry per occurrence, in source order: a module imported twice appears twice. Wrap the result in
|
|
821
|
+
* `new Set(...)` for the set of modules.
|
|
822
|
+
*/
|
|
719
823
|
static importSpecifiers = (text) => specifierLiterals(lex(text)).map((literal) => literal.value);
|
|
824
|
+
/**
|
|
825
|
+
* The rule for platform-free code: every Node built-in, bare or `node:`-prefixed, and `@effect/platform*`.
|
|
826
|
+
*
|
|
827
|
+
* @remarks
|
|
828
|
+
* Pass `builtinModules` from `node:module` as `builtins`; no list ships here because it would drift with Node
|
|
829
|
+
* releases. A bare-name list also forbids npm packages that share a built-in's name (`events`, `buffer`,
|
|
830
|
+
* `punycode`).
|
|
831
|
+
*/
|
|
832
|
+
static platformFree = (builtins) => ({ forbidImports: [
|
|
833
|
+
"node:*",
|
|
834
|
+
"@effect/platform*",
|
|
835
|
+
...builtins
|
|
836
|
+
] });
|
|
720
837
|
/** Whether `text` imports the Node built-in `module`, in either its `node:` or bare form. */
|
|
721
838
|
static importsNode = (text, module) => SourceBoundary.importSpecifiers(text).some((specifier) => isNodeModule(specifier, module));
|
|
722
839
|
/**
|
|
@@ -775,6 +892,11 @@ var SourceBoundary = class SourceBoundary {
|
|
|
775
892
|
rule: "forbidImportedNames",
|
|
776
893
|
detail
|
|
777
894
|
});
|
|
895
|
+
else if ("promiseInExclusive" in rule) for (const { offset, detail } of promisesInLanes(lexed.code, rule.promiseInExclusive.lanes ?? [])) found.push({
|
|
896
|
+
offset,
|
|
897
|
+
rule: "promiseInExclusive",
|
|
898
|
+
detail
|
|
899
|
+
});
|
|
778
900
|
else if ("forbidTokens" in rule) for (const token of new Set(rule.forbidTokens)) for (const offset of tokenOccurrences(lexed.code, token)) found.push({
|
|
779
901
|
offset,
|
|
780
902
|
rule: "forbidTokens",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/workspaces",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Monorepo workspace tooling as Effect services — root discovery, package enumeration, the dependency graph, package-manager detection, pnpm catalog resolution, lockfile IO and git-based change detection.",
|
|
6
6
|
"keywords": [
|
|
@@ -53,14 +53,14 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@effected/commands": "^0.20.0",
|
|
55
55
|
"@effected/git": "^0.30.0",
|
|
56
|
-
"@effected/glob": "^0.
|
|
57
|
-
"@effected/jsonc": "^0.
|
|
58
|
-
"@effected/lockfiles": "^0.22.
|
|
59
|
-
"@effected/npm": "^0.30.
|
|
60
|
-
"@effected/package-json": "^0.
|
|
61
|
-
"@effected/semver": "^0.
|
|
62
|
-
"@effected/walker": "^0.25.
|
|
63
|
-
"@effected/yaml": "^0.
|
|
56
|
+
"@effected/glob": "^0.19.0",
|
|
57
|
+
"@effected/jsonc": "^0.24.0",
|
|
58
|
+
"@effected/lockfiles": "^0.22.1",
|
|
59
|
+
"@effected/npm": "^0.30.1",
|
|
60
|
+
"@effected/package-json": "^0.30.0",
|
|
61
|
+
"@effected/semver": "^0.22.0",
|
|
62
|
+
"@effected/walker": "^0.25.1",
|
|
63
|
+
"@effected/yaml": "^0.29.0",
|
|
64
64
|
"@pnpm/catalogs.config": "^1100.0.5",
|
|
65
65
|
"@pnpm/catalogs.protocol-parser": "^1100.0.0",
|
|
66
66
|
"@pnpm/catalogs.resolver": "^1100.0.0",
|
package/testing.d.ts
CHANGED
|
@@ -2067,8 +2067,18 @@ export declare class PackedInstall {
|
|
|
2067
2067
|
* re-export (`export { App } from ...`), an `export * from` of the module,
|
|
2068
2068
|
* and a member access on a namespace binding (`import * as m from ...` or the
|
|
2069
2069
|
* TypeScript `import m = require(...)`, then `m.App`). `from` must equal the specifier
|
|
2070
|
-
* exactly; a subpath is a different module.
|
|
2071
|
-
*
|
|
2070
|
+
* exactly; a subpath is a different module. `{ promiseInExclusive }` forbids
|
|
2071
|
+
* `Effect.promise(`, `Effect.runPromise(` and `Effect.runPromiseExit(` inside the argument span of a
|
|
2072
|
+
* `<lane>.run(` call, where `<lane>` is a name the same file binds from
|
|
2073
|
+
* `Exclusive.make` (`const lane = yield* Exclusive.make`) or one listed in
|
|
2074
|
+
* `lanes`. Core's `Effect.promise` abandons the promise when the lane's timeout
|
|
2075
|
+
* interrupts the body, so the permit is released while the work still runs;
|
|
2076
|
+
* `Exclusive.promise` aborts and waits. `Exclusive.promise` and
|
|
2077
|
+
* `Effect.tryPromise` are not flagged. The check is lexical: a helper called
|
|
2078
|
+
* from the body, a body bound to a variable before `run`, a member receiver
|
|
2079
|
+
* (`this.lane.run(`), an aliased import of `Effect`, a destructured `run` and a
|
|
2080
|
+
* call through a local alias of `Effect.promise` all pass. See
|
|
2081
|
+
* {@link SourceBoundary}'s remarks for what this lexer cannot see.
|
|
2072
2082
|
*
|
|
2073
2083
|
* To confine a token to named files rather than forbid it everywhere, forbid
|
|
2074
2084
|
* it and waive the rule for those files through
|
|
@@ -2084,7 +2094,8 @@ export declare class PackedInstall {
|
|
|
2084
2094
|
* `{ forbidImports: ["node:*", ...builtinModules] }` with `builtinModules`
|
|
2085
2095
|
* from `node:module`. That also forbids npm packages that share a built-in's
|
|
2086
2096
|
* name (`events`, `buffer`, `punycode`). No built-in list ships here: it
|
|
2087
|
-
* would drift with Node releases.
|
|
2097
|
+
* would drift with Node releases. {@link SourceBoundary.platformFree} builds
|
|
2098
|
+
* the rule from that list.
|
|
2088
2099
|
*
|
|
2089
2100
|
* @public
|
|
2090
2101
|
*/
|
|
@@ -2094,6 +2105,8 @@ type BoundaryRule = "process" | "node:process" | "stdout-write" | "console" | "c
|
|
|
2094
2105
|
readonly forbidTokens: ReadonlyArray<string>;
|
|
2095
2106
|
} | {
|
|
2096
2107
|
readonly forbidImportedNames: ForbiddenImportedNames;
|
|
2108
|
+
} | {
|
|
2109
|
+
readonly promiseInExclusive: PromiseInExclusiveOptions;
|
|
2097
2110
|
};
|
|
2098
2111
|
/**
|
|
2099
2112
|
* The names a `{ forbidImportedNames }` rule forbids, and the module they must
|
|
@@ -2107,6 +2120,15 @@ interface ForbiddenImportedNames {
|
|
|
2107
2120
|
/** The export names that must not be imported from it. `"default"` names the default export. */
|
|
2108
2121
|
readonly names: ReadonlyArray<string>;
|
|
2109
2122
|
}
|
|
2123
|
+
/**
|
|
2124
|
+
* The options of a `{ promiseInExclusive }` rule.
|
|
2125
|
+
*
|
|
2126
|
+
* @public
|
|
2127
|
+
*/
|
|
2128
|
+
interface PromiseInExclusiveOptions {
|
|
2129
|
+
/** Names of lanes this file receives rather than binds from `Exclusive.make`, such as a parameter. */
|
|
2130
|
+
readonly lanes?: ReadonlyArray<string> | undefined;
|
|
2131
|
+
}
|
|
2110
2132
|
/**
|
|
2111
2133
|
* Options for the `process` rule.
|
|
2112
2134
|
*
|
|
@@ -2145,7 +2167,7 @@ declare const Offence_base: Schema.Class<Offence, Schema.Struct<{
|
|
|
2145
2167
|
/** The 1-based column, in UTF-16 code units. */
|
|
2146
2168
|
readonly column: Schema.Number;
|
|
2147
2169
|
/** The rule broken. */
|
|
2148
|
-
readonly rule: Schema.Literals<readonly ["process", "node:process", "stdout-write", "console", "console-stdout", "forbidImports", "forbidTokens", "forbidImportedNames"]>;
|
|
2170
|
+
readonly rule: Schema.Literals<readonly ["process", "node:process", "stdout-write", "console", "console-stdout", "forbidImports", "forbidTokens", "forbidImportedNames", "promiseInExclusive"]>;
|
|
2149
2171
|
/**
|
|
2150
2172
|
* What matched: the identifier, the call, the import specifier, the token,
|
|
2151
2173
|
* or, for `forbidImportedNames`, `<name> from <specifier>` (`*` for an
|
|
@@ -2166,7 +2188,8 @@ export declare class Offence extends Offence_base {
|
|
|
2166
2188
|
* The rule an {@link Offence} names: every string {@link BoundaryRule}, plus
|
|
2167
2189
|
* `"forbidImports"` for any `{ forbidImports }` rule, `"forbidTokens"` for
|
|
2168
2190
|
* any `{ forbidTokens }` rule and `"forbidImportedNames"` for any
|
|
2169
|
-
* `{ forbidImportedNames }` rule
|
|
2191
|
+
* `{ forbidImportedNames }` rule and `"promiseInExclusive"` for any
|
|
2192
|
+
* `{ promiseInExclusive }` rule. These are the keys of
|
|
2170
2193
|
* {@link ScanOptions.allowRules}.
|
|
2171
2194
|
*
|
|
2172
2195
|
* @public
|
|
@@ -2298,8 +2321,23 @@ export declare class SourceBoundary {
|
|
|
2298
2321
|
static readonly stripComments: (text: string) => string;
|
|
2299
2322
|
/** Whether `text` reads the global `process` in code (see {@link BoundaryRule}). */
|
|
2300
2323
|
static readonly referencesProcess: (text: string, options?: ReferenceOptions) => boolean;
|
|
2301
|
-
/**
|
|
2324
|
+
/**
|
|
2325
|
+
* Every module specifier `text` imports: static, side-effect, re-export, type-only, `import(...)` with a literal, and `require(...)`.
|
|
2326
|
+
*
|
|
2327
|
+
* @remarks
|
|
2328
|
+
* One entry per occurrence, in source order: a module imported twice appears twice. Wrap the result in
|
|
2329
|
+
* `new Set(...)` for the set of modules.
|
|
2330
|
+
*/
|
|
2302
2331
|
static readonly importSpecifiers: (text: string) => ReadonlyArray<string>;
|
|
2332
|
+
/**
|
|
2333
|
+
* The rule for platform-free code: every Node built-in, bare or `node:`-prefixed, and `@effect/platform*`.
|
|
2334
|
+
*
|
|
2335
|
+
* @remarks
|
|
2336
|
+
* Pass `builtinModules` from `node:module` as `builtins`; no list ships here because it would drift with Node
|
|
2337
|
+
* releases. A bare-name list also forbids npm packages that share a built-in's name (`events`, `buffer`,
|
|
2338
|
+
* `punycode`).
|
|
2339
|
+
*/
|
|
2340
|
+
static readonly platformFree: (builtins: ReadonlyArray<string>) => BoundaryRule;
|
|
2303
2341
|
/** Whether `text` imports the Node built-in `module`, in either its `node:` or bare form. */
|
|
2304
2342
|
static readonly importsNode: (text: string, module: string) => boolean;
|
|
2305
2343
|
/**
|
|
@@ -2443,5 +2481,5 @@ export declare class WorkspaceLayering {
|
|
|
2443
2481
|
/** Discover the workspace and check it against `policy`. */
|
|
2444
2482
|
static readonly checkWorkspace: (policy: LayerPolicy) => Effect.Effect<LayeringReport, WorkspaceDiscoveryFailure, WorkspaceDiscovery>;
|
|
2445
2483
|
}
|
|
2446
|
-
export type { BinCommandOptions, BinProvenance, BoundaryFixture, BoundaryRule, DependencyDiff, FindWorkspaceRootOptions, ForbiddenImportedNames, LayeringGraph, OffenceRule, PackSource, PackedInstallBudget, PackedInstallClosureOptions, PackedInstallGate, PackedInstallOptions, PackedInstallPreflight, PackedInstallPreflightOptions, ReachabilityOptions, ReferenceOptions, RunBinOptions, ScanOptions, UndeclaredOptions, WorkspaceDiscoveryFailure, WorkspaceDiscoveryOptions, WorkspaceDiscoveryShape, WorkspaceLookupFailure, WorkspaceRootShape };
|
|
2484
|
+
export type { BinCommandOptions, BinProvenance, BoundaryFixture, BoundaryRule, DependencyDiff, FindWorkspaceRootOptions, ForbiddenImportedNames, LayeringGraph, OffenceRule, PackSource, PackedInstallBudget, PackedInstallClosureOptions, PackedInstallGate, PackedInstallOptions, PackedInstallPreflight, PackedInstallPreflightOptions, PromiseInExclusiveOptions, ReachabilityOptions, ReferenceOptions, RunBinOptions, ScanOptions, UndeclaredOptions, WorkspaceDiscoveryFailure, WorkspaceDiscoveryOptions, WorkspaceDiscoveryShape, WorkspaceLookupFailure, WorkspaceRootShape };
|
|
2447
2485
|
//# sourceMappingURL=testing.d.ts.map
|