@boringparts/verule 0.1.0 → 0.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.
@@ -9,5 +9,5 @@ export declare function validateAdditionalInputPaths(paths: readonly string[] |
9
9
  export declare function createAdditionalInputRegistry(options: {
10
10
  readonly cwd: string;
11
11
  }): AdditionalInputRegistry;
12
- /** Binds an `AdditionalInputRegistrar` to a fixed rule or adapter source tag. */
12
+ /** Binds an `AdditionalInputRegistrar` to a fixed rule or summary source tag. */
13
13
  export declare function createScopedAdditionalInputRegistrar(registrar: AdditionalInputRegistrar, source: AdditionalInputSource): ScopedAdditionalInputRegistrar;
@@ -57,7 +57,7 @@ export function createAdditionalInputRegistry(options) {
57
57
  },
58
58
  };
59
59
  }
60
- /** Binds an `AdditionalInputRegistrar` to a fixed rule or adapter source tag. */
60
+ /** Binds an `AdditionalInputRegistrar` to a fixed rule or summary source tag. */
61
61
  export function createScopedAdditionalInputRegistrar(registrar, source) {
62
62
  try {
63
63
  return createTssaeScopedAdditionalInputRegistrar(registrar, source);
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { fstatSync } from "node:fs";
3
3
  import { createRequire } from "node:module";
4
- import { nodeCliOutput } from "@ykdz/cli-contract/node";
4
+ import { nodeCliOutput } from "@boringparts/cli-contract/node";
5
5
  import { cliCommandIdentity } from "./cli-command-identity.js";
6
6
  import { runCli } from "./main.js";
7
7
  const require = createRequire(import.meta.url);
@@ -6,7 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
6
6
  }
7
7
  return path;
8
8
  };
9
- import { existsSync } from "node:fs";
9
+ import { existsSync, realpathSync } from "node:fs";
10
10
  import { registerHooks } from "node:module";
11
11
  import { resolve } from "node:path";
12
12
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -17,7 +17,38 @@ const DEFAULT_CONFIG_CANDIDATES = [
17
17
  "verule.config.mjs",
18
18
  "verule.config.js",
19
19
  ];
20
+ // Property-typed view avoids `unbound-method` while preserving the exact function
21
+ // reference for restoration (whereas `.bind(process)` would allocate a wrapper).
22
+ const processEmitWarningHost = process;
20
23
  let nextReloadGeneration = 1;
24
+ let activeConfigImports = 0;
25
+ let savedEmitWarning;
26
+ function isTypeStrippingWarning(warning, typeOrOptions) {
27
+ const warningName = typeof typeOrOptions === "string"
28
+ ? typeOrOptions
29
+ : typeof typeOrOptions === "object" &&
30
+ typeOrOptions !== null &&
31
+ "type" in typeOrOptions
32
+ ? typeOrOptions.type
33
+ : typeof warning === "object"
34
+ ? warning.name
35
+ : undefined;
36
+ const warningMessage = typeof warning === "string" ? warning : warning.message;
37
+ return (warningName === "ExperimentalWarning" &&
38
+ warningMessage.includes("Type Stripping"));
39
+ }
40
+ // Node 24.0.0 emits `ExperimentalWarning: Type Stripping` to stderr on the first
41
+ // `.ts` import, which corrupts CLI JSON envelopes and NDJSON streams. We suppress
42
+ // only that warning across dynamic config imports using an active-import refcount
43
+ // so overlapping loads share one hook and restore the exact original handler on exit.
44
+ const suppressTypeStrippingWarning = function (warning, ...args) {
45
+ if (isTypeStrippingWarning(warning, args[0])) {
46
+ return;
47
+ }
48
+ if (savedEmitWarning !== undefined) {
49
+ Reflect.apply(savedEmitWarning, process, [warning, ...args]);
50
+ }
51
+ };
21
52
  export function resolveConfigPath(cwd, explicitConfig) {
22
53
  if (explicitConfig !== undefined) {
23
54
  const resolved = resolve(cwd, explicitConfig);
@@ -40,6 +71,36 @@ function isLocalImportSpecifier(specifier) {
40
71
  specifier.startsWith("/") ||
41
72
  specifier.startsWith("file://"));
42
73
  }
74
+ function hasPreserveSymlinksFlag() {
75
+ if (process.execArgv.includes("--preserve-symlinks")) {
76
+ return true;
77
+ }
78
+ const nodeOptions = process.env.NODE_OPTIONS?.trim();
79
+ if (!nodeOptions) {
80
+ return false;
81
+ }
82
+ return nodeOptions.split(/\s+/u).includes("--preserve-symlinks");
83
+ }
84
+ function stripUrlQuery(url) {
85
+ const queryIndex = url.indexOf("?");
86
+ return queryIndex === -1
87
+ ? { baseUrl: url, query: "" }
88
+ : { baseUrl: url.slice(0, queryIndex), query: url.slice(queryIndex) };
89
+ }
90
+ function trackNonNodeModulesFileUrl(trackedFiles, fileUrl, requireExisting = false) {
91
+ if (!fileUrl.startsWith("file://") || fileUrl.includes("/node_modules/")) {
92
+ return;
93
+ }
94
+ try {
95
+ const filePath = fileURLToPath(fileUrl);
96
+ if (!requireExisting || existsSync(filePath)) {
97
+ trackedFiles.add(filePath);
98
+ }
99
+ }
100
+ catch {
101
+ // Ignore non-file paths.
102
+ }
103
+ }
43
104
  /**
44
105
  * Dynamically imports a Verule configuration file with ESM cache-busting for the config
45
106
  * and its local relative module graph, returning the validated config and dependency paths.
@@ -50,31 +111,61 @@ export async function loadProjectConfigWithDependencies(cwd, explicitConfig) {
50
111
  const reloadToken = String(nextReloadGeneration++);
51
112
  const reloadMarker = `verule-reload=${reloadToken}`;
52
113
  const trackedFiles = new Set([configPath]);
114
+ const preserveSymlinks = hasPreserveSymlinksFlag();
53
115
  const hook = registerHooks({
54
116
  resolve(specifier, context, nextResolve) {
55
117
  const resolved = nextResolve(specifier, context);
118
+ if (!resolved.url.startsWith("file://")) {
119
+ return resolved;
120
+ }
121
+ const { baseUrl: rawUrl, query: existingQuery } = stripUrlQuery(resolved.url);
122
+ // In Node 24.0.0, `nextResolve` from a symlinked `cli.js` entry can return
123
+ // an unresolved symlink path, preventing pnpm's isolated `node_modules` from
124
+ // resolving transitive dependencies such as `tssae`. Canonicalize `file://`
125
+ // URLs via `realpathSync` unless `--preserve-symlinks` is explicitly active.
126
+ let canonicalUrl = rawUrl;
127
+ if (!preserveSymlinks) {
128
+ try {
129
+ canonicalUrl = pathToFileURL(realpathSync(fileURLToPath(rawUrl))).href;
130
+ }
131
+ catch {
132
+ // Keep original URL if the target cannot be realpathed.
133
+ }
134
+ }
56
135
  const fromReloadedGraph = typeof context.parentURL === "string" &&
57
136
  context.parentURL.includes(reloadMarker);
58
- if (fromReloadedGraph &&
59
- isLocalImportSpecifier(specifier) &&
60
- resolved.url.startsWith("file://") &&
61
- !resolved.url.includes("/node_modules/")) {
62
- const cleanUrl = resolved.url.split("?")[0];
137
+ if (fromReloadedGraph && isLocalImportSpecifier(specifier)) {
138
+ // Track both the unresolved local path (for symlink retargeting) and
139
+ // canonical realpath (for target edits) outside `node_modules` so
140
+ // `verule watch` reloads on either change.
63
141
  try {
64
- trackedFiles.add(fileURLToPath(cleanUrl));
142
+ const { baseUrl: unresolvedUrl } = stripUrlQuery(new URL(specifier, context.parentURL).href);
143
+ trackNonNodeModulesFileUrl(trackedFiles, unresolvedUrl, true);
65
144
  }
66
145
  catch {
67
- // Ignore non-file paths.
146
+ // Ignore malformed specifiers.
147
+ }
148
+ trackNonNodeModulesFileUrl(trackedFiles, rawUrl);
149
+ if (!canonicalUrl.includes("/node_modules/")) {
150
+ trackNonNodeModulesFileUrl(trackedFiles, canonicalUrl);
151
+ return {
152
+ ...resolved,
153
+ url: `${canonicalUrl}?${reloadMarker}`,
154
+ };
68
155
  }
69
- return {
70
- ...resolved,
71
- url: `${cleanUrl}?${reloadMarker}`,
72
- };
73
156
  }
74
- return resolved;
157
+ const restoredUrl = `${canonicalUrl}${existingQuery}`;
158
+ return restoredUrl === resolved.url
159
+ ? resolved
160
+ : { ...resolved, url: restoredUrl };
75
161
  },
76
162
  });
77
163
  let loaded;
164
+ if (activeConfigImports === 0) {
165
+ savedEmitWarning = processEmitWarningHost.emitWarning;
166
+ processEmitWarningHost.emitWarning = suppressTypeStrippingWarning;
167
+ }
168
+ activeConfigImports += 1;
78
169
  try {
79
170
  loaded = await import(__rewriteRelativeImportExtension(`${configUrl}?${reloadMarker}`));
80
171
  }
@@ -83,6 +174,13 @@ export async function loadProjectConfigWithDependencies(cwd, explicitConfig) {
83
174
  throw new VeruleExecutionError("INVALID_CONFIG", `Failed to load Verule configuration "${configPath}": ${message}`, { cause: err });
84
175
  }
85
176
  finally {
177
+ activeConfigImports -= 1;
178
+ if (activeConfigImports === 0 &&
179
+ savedEmitWarning !== undefined &&
180
+ processEmitWarningHost.emitWarning === suppressTypeStrippingWarning) {
181
+ processEmitWarningHost.emitWarning = savedEmitWarning;
182
+ savedEmitWarning = undefined;
183
+ }
86
184
  hook.deregister();
87
185
  }
88
186
  if (typeof loaded !== "object" || loaded === null || !("default" in loaded)) {
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { createAdditionalInputRegistry, createScopedAdditionalInputRegistrar, type AdditionalInputEntry, type AdditionalInputRegistrar, type AdditionalInputRegistry, type AdditionalInputSource, type ScopedAdditionalInputRegistrar, } from "./additional-inputs.ts";
2
2
  export { INLINE_IGNORE_RULE_ID } from "./inline-ignore.ts";
3
3
  export { parseObserveLimit, parseTargetSpec } from "./observation.ts";
4
- export { defineConfig, defineModel, defineRule, openSession, runCheck, } from "./session.ts";
4
+ export { defineConfig, defineRule, openSession, runCheck } from "./session.ts";
5
5
  export { requestSharedReport, startSharedSession } from "./shared-session.ts";
6
6
  export { watchProject } from "./watch.ts";
7
- export { defineAdapter, defineFactProvider, defineFactType, getEngineVersion, isSameInstance, resolveRetainedObjectFields, type AdapterContext, type AssignabilityPair, type AssignabilityResult, type BranchCoverageItem, type BranchCoverageOptions, type BranchCoverageStatus, type BranchDirection, type BranchEdgeInfo, type BranchKind, type BranchRef, type CallEffectsOptions, type CallEffectsResult, type CallEffectsTargetRef, type CallbackInvocationInfo, type CallProjectionSelection, type CallRef, type CallSiteParameterBinding, type CallTargetInfo, type CallTargetsResult, type CleanupCoverageStatus, type CleanupModelOperation, type CleanupModelOperationKind, type CleanupModelTarget, type CleanupScopeRef, type CleanupSiteInfo, type CompilerOptionsSummary, type ConfiguredAdapter, type DeclarationCallersResult, type DeclarationProjectionSelection, type DeclarationRef, type DiagnosticBasis, type DiagnosticLocation, type DirectCallInfo, type EngineFactExtractionOptions, type EngineProviderExtractionStats, type Evidence, type ExplainCleanupPath, type ExplainGapResolution, type ExplainGapResolutionStatus, type ExplainLocalGap, type ExplainProviderEvaluation, type ExplainProviderEvaluationStatus, type FactConflictDetails, type FactConflictParty, type FactContribution, type FactExplainTrace, type FactExtractionRequest, type FactMergeOutcome, type FactProvider, type FactProviderContribution, type FactQueryOptions, type FactResult, type FactType, type FactTypeSpec, type FieldEffect, type FieldEffectKind, type FieldWriteOperator, type FindSyntaxOptions, type FullCallProjectionFields, type FullDeclarationProjectionFields, type FullInstanceProjectionFields, type FullSignatureProjectionFields, type FullSyntaxLookupFields, type FullTypeProjectionFields, type FunctionBranchesResult, type Gap, type GuardConditionInfo, type ImplementationResolutionResult, type ImplementationStatus, type ImplementationTargetRef, type InstanceCleanupOptions, type InstanceCleanupScopeResult, type InstanceModelBehavior, type InstanceModelMatch, type InstanceOriginKind, type InstanceProjectionSelection, type InstanceRef, type InstanceResolutionResult, type InstanceTargetRef, type InstantiatedParameterType, type LibraryAdapter, type LifecycleEventBehavior, type LookupFilesOptions, type MemoryStats, type Model, type NativeAdapterObservation, type ObjectFieldShape, type ObserveLimit, type ObserveLimitInput, type ObserveMode, type ObserveOptions, type PackageResolutionMode, type ProgramObjectKind, type ProgramRef, type ProjectedCallResolutionRow, type ProjectedCallRow, type ProjectedDeclarationRow, type ProjectedInstanceRow, type ProjectedSignatureRow, type ProjectedSyntaxLookupRow, type ProjectedTypeRow, type ProjectSummary, type RecomputationScope, type ResolvedImplementationTarget, type ResolvedInstanceInfo, type RetainedObjectFields, type SelectableQueryResult, type SelectedKeys, type SignatureParameterInfo, type SignatureProjectionSelection, type SignatureRef, type SourceFileOrigin, type SourceFileProjectOrigin, type SourceRange, type SourceTarget, type SyntaxKind, type SyntaxLookupSelection, type SyntaxNodeResult, type SyntaxRef, type TargetInstanceCleanupResult, type TypeAtResult, type TypeProjectionSelection, type TypePropertyInfo, type TypeRef, type TypeSummary, type ValueEndpoint, type ValuePropagationMode, type ValuePropagationOptions, type ValuePropagationPath, type ValuePropagationResult, type ValuePropagationStep, type ValuePropagationStepKind, type ValuePropagationTargetResult, } from "tssae";
8
- export { REPORT_SCHEMA_VERSION, VeruleExecutionError, type AnalysisSession, type CheckReport, type CheckpointOutcome, type CheckpointTarget, type Diagnostic, type DiagnosticInput, type ExplainCheckpointTrace, type ExplainQueryStep, type ExplainReport, type ExplainResult, type ExplainStatus, type InlineIgnoreEntry, type InlineIgnoreStatus, type ModelIdentitySummary, type NormalizedVeruleConfig, type ObservationDetailEntry, type ObservationOverhead, type ObservationPhases, type ObservationReport, type ObservationRpcMetrics, type OpenSessionOptions, type ReportIdentity, type RequestSharedReportOptions, type Rule, type RuleContext, type RuleIdentitySummary, type RunCheckOptions, type SessionCheckOptions, type SessionUpdateOptions, type SessionUpdateResult, type SharedSession, type SharedSessionOptions, type VeruleConfig, type VeruleErrorCode, type WatchConfigLoadResult, type WatchEvent, type WatchFailureEvent, type WatchProjectOptions, type WatchReportEvent, type WatchTrigger, } from "./types.ts";
7
+ export { dedupeEvidence, evidenceOf, extractBasisEvidence, getEngineVersion, isSameInstance, normalizeEvidence, normalizeEvidenceItem, normalizeLocation, registerProvenance, resolveRetainedObjectFields, syntaxLocationOf, type AssignabilityPair, type AssignabilityResult, type BranchBypassPath, type BranchCoverageItem, type BranchCoverageOptions, type BranchCoverageStatus, type BranchDirection, type BranchEdgeInfo, type BranchKind, type BranchRef, type CallEffectsOptions, type CallEffectsResult, type CallEffectsTargetRef, type CallbackInvocationInfo, type CallProjectionSelection, type CallRef, type CallSiteParameterBinding, type CallTargetInfo, type CallTargetsResult, type CleanupCoverageStatus, type CleanupScopeRef, type CleanupSiteInfo, type CompilerOptionsSummary, type ControlFlowPathStep, type DeclarationCallersResult, type DeclarationProjectionSelection, type DeclarationRef, type DiagnosticBasis, type DiagnosticLocation, type DirectCallInfo, type EngineCallIoMetrics, type EngineIrCacheMetrics, type EngineLoweringMetrics, type EngineRpcMetrics, type EngineStepMetrics, type EngineSummaryLookupMetrics, type Evidence, type ExplainCleanupPath, type FieldEffect, type FieldEffectKind, type FieldWriteOperator, type FindSyntaxOptions, type FirstPartyResolutionSource, type FullCallProjectionFields, type FullDeclarationProjectionFields, type FullInstanceProjectionFields, type FullSignatureProjectionFields, type FullSyntaxLookupFields, type FullTypeProjectionFields, type FunctionBranchesResult, type Gap, type GuardConditionInfo, type ImplementationResolutionResult, type ImplementationTargetRef, type ImplicitExceptionCleanupOutcome, type ImplicitExceptionCoverageOutcome, type InstanceCleanupOptions, type InstanceCleanupScopeResult, type InstanceOriginKind, type InstanceProjectionSelection, type InstanceRef, type InstanceResolutionResult, type InstanceTargetRef, type InstantiatedParameterType, type LookupFilesOptions, type MemoryStats, type ObjectFieldShape, type ObserveLimit, type ObserveLimitInput, type ObserveMode, type ObserveOptions, type ProgramObjectKind, type ProgramRef, type ProjectedCallResolutionRow, type ProjectedCallRow, type ProjectedDeclarationRow, type ProjectedInstanceRow, type ProjectedSignatureRow, type ProjectedSyntaxLookupRow, type ProjectedTypeRow, type ProjectSummary, type ProvenanceCarrier, type RecomputationScope, type ResolvedImplementationTarget, type ResolvedInstanceInfo, type RetainedObjectFields, type SelectableQueryResult, type SelectedKeys, type SignatureParameterInfo, type SignatureProjectionSelection, type SignatureRef, type SourceFileOrigin, type SourceFileProjectOrigin, type SourceRange, type SourceTarget, type SummaryConflictDetails, type SummaryConflictParty, type SummaryDiscoverySource, type SyntaxKind, type SyntaxLookupSelection, type SyntaxNodeResult, type SyntaxRef, type TargetInstanceCleanupResult, type TypeAtResult, type TypeProjectionSelection, type TypePropertyInfo, type TypeRef, type TypeSummary, type ValueEndpoint, type ValuePropagationMode, type ValuePropagationOptions, type ValuePropagationPath, type ValuePropagationResult, type ValuePropagationStep, type ValuePropagationStepKind, type ValuePropagationTargetResult, } from "tssae";
8
+ export { REPORT_SCHEMA_VERSION, VeruleExecutionError, type AnalysisSession, type CheckReport, type CheckpointOutcome, type CheckpointTarget, type Diagnostic, type DiagnosticInput, type ExplainCheckpointTrace, type ExplainQueryStep, type ExplainReport, type ExplainResult, type ExplainStatus, type InlineIgnoreEntry, type InlineIgnoreStatus, type NormalizedVeruleConfig, type ObservationDetailEntry, type ObservationOverhead, type ObservationPhases, type ObservationReport, type ObservationRpcMetrics, type OpenSessionOptions, type ReportIdentity, type RequestSharedReportOptions, type Rule, type RuleContext, type RuleIdentitySummary, type RunCheckOptions, type SessionCheckOptions, type SessionUpdateOptions, type SessionUpdateResult, type SharedSession, type SharedSessionOptions, type VeruleConfig, type VeruleErrorCode, type WatchConfigLoadResult, type WatchEvent, type WatchFailureEvent, type WatchProjectOptions, type WatchReportEvent, type WatchTrigger, } from "./types.ts";
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export { createAdditionalInputRegistry, createScopedAdditionalInputRegistrar, } from "./additional-inputs.js";
2
2
  export { INLINE_IGNORE_RULE_ID } from "./inline-ignore.js";
3
3
  export { parseObserveLimit, parseTargetSpec } from "./observation.js";
4
- export { defineConfig, defineModel, defineRule, openSession, runCheck, } from "./session.js";
4
+ export { defineConfig, defineRule, openSession, runCheck } from "./session.js";
5
5
  export { requestSharedReport, startSharedSession } from "./shared-session.js";
6
6
  export { watchProject } from "./watch.js";
7
- export { defineAdapter, defineFactProvider, defineFactType, getEngineVersion, isSameInstance, resolveRetainedObjectFields, } from "tssae";
7
+ export { dedupeEvidence, evidenceOf, extractBasisEvidence, getEngineVersion, isSameInstance, normalizeEvidence, normalizeEvidenceItem, normalizeLocation, registerProvenance, resolveRetainedObjectFields, syntaxLocationOf, } from "tssae";
8
8
  export { REPORT_SCHEMA_VERSION, VeruleExecutionError, } from "./types.js";