@systemfsoftware/oxlint-plugin-effect-platform 2.1.8 → 2.2.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 CHANGED
@@ -1,7 +1,5 @@
1
1
  # @systemfsoftware/oxlint-plugin-effect-platform
2
2
 
3
- # @systemfsoftware/oxlint-plugin-effect-platform@2.1.8
3
+ # @systemfsoftware/oxlint-plugin-effect-platform@2.2.0
4
4
 
5
- Dev dependency bump (@types/node) only; the packed tarball is unchanged.
6
-
7
- Rebuilt with tsdown 0.23.7 against the updated dev dependencies: the bundled `dist/` files carry a different hashed runtime chunk name and comment markers, and the declared devDependency ranges move. The public API and runtime behaviour are unchanged.
5
+ `runtime-construction-placement` reports a factory that builds a fresh `ManagedRuntime` per call even when its returned closures capture it, and no longer reports `Layer.provide`, which composes a Layer graph and builds no runtime. Its fix message names `Layer.build` in the owner's scope for wiring that belongs to an object with its own lifetime.
package/README.md CHANGED
@@ -59,19 +59,20 @@ All six rules are in the recommended set, so the spread enables them at `error`.
59
59
 
60
60
  ## Rules
61
61
 
62
- | Rule | Reports |
63
- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
64
- | `entrypoint-interprets-once` | A `main.ts` with zero or more than one interpretation edge — `runMain` under any namespace, `Effect.run*`, `ManagedRuntime.make`, `Layer.toRuntime` |
65
- | `entrypoint-no-exports` | Any export from `main.ts`: named, default, `export *`, re-export, or type-only |
66
- | `entrypoint-not-imported` | Any static import, re-export, or dynamic `import()` of a `main` module, reported in the importing file — production, barrel, or test |
67
- | `entrypoint-no-promise-wrapper` | `runMain(Effect.tryPromise(...))` or `runMain(Effect.promise(...))`: the outer edge awaits a promise while the real fibers run in a runtime it cannot interrupt |
68
- | `runtime-construction-placement` | `ManagedRuntime.make` or `Layer.provide` inside a function body — wiring rebuilt per call — and `ManagedRuntime.make` at module scope, where importing the module starts fibers nothing can interrupt. It judges runtime code: a file under a `src/` directory segment, or a `*.test.ts` file; a package-root hook, config, or setup file is outside its subject |
69
- | `no-unported-time-source` | A direct `Date.now`, `performance.now`, `process.hrtime`, `Math.random`, `crypto.getRandomValues`, `crypto.randomUUID`, `setTimeout`, `setInterval`, or `setImmediate` call, an argument-less `new Date()`, or a static or dynamic import of `node:timers` in production source outside a file listed in the rule's `ports` option |
62
+ | Rule | Reports |
63
+ | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
64
+ | `entrypoint-interprets-once` | A `main.ts` with zero or more than one interpretation edge — `runMain` under any namespace, `Effect.run*`, `ManagedRuntime.make`, `Layer.toRuntime` |
65
+ | `entrypoint-no-exports` | Any export from `main.ts`: named, default, `export *`, re-export, or type-only |
66
+ | `entrypoint-not-imported` | Any static import, re-export, or dynamic `import()` of a `main` module, reported in the importing file — production, barrel, or test |
67
+ | `entrypoint-no-promise-wrapper` | `runMain(Effect.tryPromise(...))` or `runMain(Effect.promise(...))`: the outer edge awaits a promise while the real fibers run in a runtime it cannot interrupt |
68
+ | `runtime-construction-placement` | `ManagedRuntime.make` inside a function body — a runtime built per call that nothing finalizes — and `ManagedRuntime.make` at module scope, where importing the module starts fibers nothing can interrupt. It judges runtime code: a file under a `src/` directory segment, or a `*.test.ts` file; a package-root hook, config, or setup file is outside its subject |
69
+ | `no-unported-time-source` | A direct `Date.now`, `performance.now`, `process.hrtime`, `Math.random`, `crypto.getRandomValues`, `crypto.randomUUID`, `setTimeout`, `setInterval`, or `setImmediate` call, an argument-less `new Date()`, or a static or dynamic import of `node:timers` in production source outside a file listed in the rule's `ports` option |
70
70
 
71
71
  What the placement rule leaves alone, each a shape the rule's own fixtures pin:
72
72
 
73
- - A module-scope closure that memoizes the construction — written into a cache binding (`??=`, `||=`, plain assignment) or into a declarator whose binding a nested closure captures.
74
- - Module-scope layer composition: `Layer.provide` at module scope builds a graph, not a runtime. `Cell.provideContext(context)` is silent everywhere — binding a context built once constructs no runtime.
73
+ - A module-scope closure that memoizes the construction — written into a cache binding (`??=`, `||=`, plain assignment), or made in a closure that runs once because a module-scope binding holds the call that invokes it (an invoked factory, a `then` on a module-scope promise). A local that the returned closures capture is not a memo: each call of the factory builds another runtime.
74
+ - No `ManagedRuntime` where the wiring belongs to an object with its own lifetime (one per instance, as a Durable Object is): run `Layer.build` (an Effect that needs a `Scope`) once in a `Scope` the object owns, close that scope when the host tears the object down, and provide the built `Context` to each call with `Effect.provide` before running it. Each call still runs its Effect; what it skips is a per-instance `ManagedRuntime`. A scope the host never closes keeps the layer's resources for the object's whole life, which is that object's lifetime, not a leak per call.
75
+ - Layer composition at any depth: `Layer.provide`, `Layer.provideMerge` and `Layer.merge` build a graph, not a runtime. `Cell.provideContext(context)` is silent everywhere — binding a context built once constructs no runtime.
75
76
  - `cell.run(input)` at any depth, in any file.
76
77
  - `main.ts`, the interpretation edge: exempt from the module-scope verdict, because the process entry is where building the runtime is the point. Wiring built inside one of its functions still reports.
77
78
  - A package-root hook, config, or setup file: outside the rule's subject by location, which is why a test runner's hook module may compose at module scope.
package/dist/index.mjs CHANGED
@@ -862,15 +862,10 @@ const resolveIdentifierOrigin = (identifier, getScope, depth) => {
862
862
  // src/rules/runtime-construction-placement.config.ts
863
863
  const isRuntimeCodeFile = (filename) => /(?:^|[\\/])src[\\/]/u.test(filename) || filename.endsWith(".test.ts");
864
864
  const isInterpretationEdge = (filename) => /(?:^|[\\/])main\.ts$/u.test(filename);
865
- const EFFECT_MODULE = "effect";
866
865
  const TRACKED_WIRING_CALLS = [{
867
- source: EFFECT_MODULE,
866
+ source: "effect",
868
867
  namespace: "ManagedRuntime",
869
868
  member: "make"
870
- }, {
871
- source: EFFECT_MODULE,
872
- namespace: "Layer",
873
- member: "provide"
874
869
  }];
875
870
  const MEMOIZING_ASSIGNMENT_OPERATORS = [
876
871
  "=",
@@ -879,14 +874,14 @@ const MEMOIZING_ASSIGNMENT_OPERATORS = [
879
874
  ];
880
875
  const WIRING_PER_CALL_EXPECTED = "wiring built once per process and deferred to first use in a module-scope lazy memoized closure";
881
876
  const WIRING_PER_CALL_ACTUAL = "the wiring is constructed inside a function body, so every call builds its own runtime";
882
- const WIRING_PER_CALL_FIX = "build the wiring in one module-scope lazy memoized closure and read that runtime where it is needed; a runtime constructed per call is never finalized and the fibers it starts outlive the caller - delete the construction if this module already reads a process-scope runtime";
877
+ const WIRING_PER_CALL_FIX = "build the wiring in one module-scope lazy memoized closure and read that runtime where it is needed, or, when the wiring belongs to an object with its own lifetime, run `Layer.build` once in a `Scope` that object owns and provide the built `Context` to each call with `Effect.provide` before running it, so no `ManagedRuntime` is constructed; a runtime constructed per call is never finalized and the fibers it starts outlive the caller - delete the construction if this module already reads a process-scope runtime";
883
878
  const EAGER_CONSTRUCTION_EXPECTED = "runtime construction deferred to first use, inside a module-scope memoizing closure";
884
879
  const EAGER_CONSTRUCTION_ACTUAL = "the runtime is constructed while the module is imported";
885
880
  const EAGER_CONSTRUCTION_FIX = "wrap the construction in a module-scope memoizing closure and call it where the runtime is needed, so importing the module starts nothing; delete the runtime if this module already reads a process-scope one";
886
881
  const PLACEMENT_MESSAGE = "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}.";
887
882
  const meta = {
888
883
  type: "problem",
889
- docs: { description: "`ManagedRuntime.make` or `Layer.provide` inside a function body rebuilds wiring per call; `ManagedRuntime.make` evaluated at module scope constructs the runtime at import time. The rule judges runtime code: files under a `src/` directory segment and `*.test.ts` files; a package-root hook, config, or setup file is outside its subject, `.tst.ts` type-test files run nowhere, and `main.ts` is exempt from the module-scope verdict as the interpretation edge. Lawful and silent in scope: a memoized module-scope closure, module-scope graph composition, `cell.run(input)` at any depth. Shapes, bounds, and examples: the README." },
884
+ docs: { description: "`ManagedRuntime.make` inside a function body builds a runtime per call that nothing finalizes; `ManagedRuntime.make` evaluated at module scope constructs the runtime at import time. The rule judges runtime code: files under a `src/` directory segment and `*.test.ts` files; a package-root hook, config, or setup file is outside its subject, `.tst.ts` type-test files run nowhere, and `main.ts` is exempt from the module-scope verdict as the interpretation edge. Lawful and silent in scope: a memoized module-scope closure, Layer composition (`Layer.provide`, `Layer.provideMerge`, `Layer.merge`) at any depth, `cell.run(input)` at any depth. Shapes, bounds, and examples: the README." },
890
885
  schema: [],
891
886
  messages: {
892
887
  wiringPerCall: PLACEMENT_MESSAGE,
@@ -1016,44 +1011,22 @@ const isBoundByAModuleScopeBinding = (node) => {
1016
1011
  }
1017
1012
  return false;
1018
1013
  };
1019
- const MAX_WALK_DEPTH = 32;
1020
- const isNode = (value) => value !== null && typeof value === "object" && "type" in value;
1021
- const mentionsName = (value, name, depth) => {
1022
- if (depth > MAX_WALK_DEPTH) return false;
1023
- if (Array.isArray(value)) return value.some((item) => mentionsName(item, name, depth + 1));
1024
- if (!isNode(value)) return false;
1025
- if (value.type === "Identifier") return value.name === name;
1026
- for (const [key, child] of Object.entries(value)) {
1027
- if (key === "parent") continue;
1028
- if (mentionsName(child, name, depth + 1)) return true;
1029
- }
1030
- return false;
1031
- };
1032
- const isReadInsideANestedFunction = (value, enclosing, name, depth) => {
1033
- if (depth > MAX_WALK_DEPTH) return false;
1034
- if (Array.isArray(value)) return value.some((item) => isReadInsideANestedFunction(item, enclosing, name, depth + 1));
1035
- if (!isNode(value)) return false;
1036
- if (value !== enclosing && isFunctionNode(value)) return mentionsName(value, name, depth + 1);
1037
- for (const [key, child] of Object.entries(value)) {
1038
- if (key === "parent") continue;
1039
- if (isReadInsideANestedFunction(child, enclosing, name, depth + 1)) return true;
1040
- }
1041
- return false;
1042
- };
1043
- const isCapturedDeclaratorBinding = (declarator, enclosing) => {
1044
- if (declarator.id.type !== "Identifier") return false;
1045
- return isReadInsideANestedFunction(enclosing, enclosing, declarator.id.name, 0);
1014
+ /**
1015
+ * A closure that runs once: invoked by a call whose result a module-scope binding holds
1016
+ * (an invoked factory, a `then` on a module-scope promise). A cache write inside any
1017
+ * other closure is the only memo; a local the closure captures is rebuilt per call.
1018
+ */
1019
+ const runsOnceAtModuleScope = (enclosing) => {
1020
+ const consumer = enclosing.parent;
1021
+ return consumer !== null && consumer.type === "CallExpression" && isBoundByAModuleScopeBinding(consumer);
1046
1022
  };
1047
1023
  const isMemoizedConstruction = (call, enclosing) => {
1048
1024
  let current = call.parent;
1049
1025
  while (current !== null && current !== enclosing) {
1050
1026
  if (isCacheWrite(current)) return true;
1051
- if (current.type === "VariableDeclarator" && isCapturedDeclaratorBinding(current, enclosing)) return true;
1052
1027
  current = current.parent;
1053
1028
  }
1054
- const consumer = enclosing.parent;
1055
- if (consumer === null || consumer.type !== "CallExpression") return false;
1056
- return isBoundByAModuleScopeBinding(consumer);
1029
+ return runsOnceAtModuleScope(enclosing);
1057
1030
  };
1058
1031
  const runtimeConstructionPlacement = defineRule({
1059
1032
  meta,
@@ -1100,7 +1073,6 @@ const runtimeConstructionPlacement = defineRule({
1100
1073
  });
1101
1074
  return;
1102
1075
  }
1103
- if (tracked.namespace !== "ManagedRuntime") return;
1104
1076
  if (isInterpretationEdge(context.filename)) return;
1105
1077
  context.report({
1106
1078
  node: callee,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@systemfsoftware/oxlint-plugin-effect-platform",
3
3
  "license": "Apache-2.0",
4
- "version": "2.1.8",
4
+ "version": "2.2.0",
5
5
  "author": "Ryan Lee <drdgvhbh@gmail.com>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -72,7 +72,7 @@
72
72
  "clean": "rimraf dist",
73
73
  "typecheck": "tsc -b",
74
74
  "test": "vitest run",
75
- "lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
75
+ "lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; effect-tsgo oxlint . --format=${f:-default}",
76
76
  "attw": "attw --pack .",
77
77
  "api:check": "api-extractor-quiet run",
78
78
  "api:update": "api-extractor run --local"