@svelte-vitals/core 0.41.0 → 0.42.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +76 -24
  2. package/dist/index.js +280 -1352
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -612,6 +612,29 @@ interface KitModuleFacts {
612
612
  parseFailed?: true;
613
613
  }
614
614
 
615
+ /**
616
+ * Resolve an import specifier to a path relative to the analyzed project's root (the
617
+ * cwd svelte-vitals runs from — not necessarily a repo root; in a monorepo the project
618
+ * may live at e.g. `apps/web/`) against the importing file, or undefined when it cannot
619
+ * be a project-local module: the caller's `aliases` list decides which non-relative
620
+ * specifiers resolve, defaulting to `$lib` → `src/lib`; `./`/`../` resolve against the
621
+ * importing file's directory; bare packages and other aliases are skipped (they can't
622
+ * be resolved to a project-local path at all). Also undefined when a relative
623
+ * specifier's `..` segments escape the project root (see `normalizePosix`), or when a
624
+ * matched alias's value is itself absolute (e.g. `/opt/shared/src`, or a posixified Windows
625
+ * drive-letter path like `C:/shared/src`): an absolute target is outside the analyzed project by
626
+ * definition, and without this check `normalizePosix` would quietly drop the leading empty
627
+ * segment and hand back a project-relative-LOOKING path that actually names a different file.
628
+ *
629
+ * Exported from the package's public barrel because `architecture/private-scope-import`
630
+ * and `architecture/route-component-import` (inside `packages/core`) both need resolution
631
+ * that is not restricted to runes modules, unlike `resolveRunesModuleSpecifier` — and
632
+ * because `resolveComponentPath` (`packages/cli/src/providers/source/resolve.ts`), which
633
+ * drives transitive `<head>`/heading resolution, delegates its alias/`$lib`/relative
634
+ * mapping here too, rather than duplicating it. This is the single site for every
635
+ * repo-local specifier resolution in the repo.
636
+ */
637
+ declare function resolveRepoLocalPath(spec: string, importerFile: string, aliases?: readonly KitAlias[]): string | undefined;
615
638
  /**
616
639
  * Resolve an import specifier to a repo-relative `.svelte.ts`/`.svelte.js` path, or
617
640
  * undefined when it cannot be a runes module: delegates to `resolveRepoLocalPath` with
@@ -739,13 +762,6 @@ type TextOrExpr = AST.Text | AST.ExpressionTag;
739
762
  * the standard fragment, nodes, consequent, alternate, and body keys.
740
763
  */
741
764
  declare const CHILD_NODE_KEYS: string[];
742
- /**
743
- * Determine a value's kind from a list of child/text nodes (design §4, §11):
744
- * - any ExpressionTag present → 'dynamic' (e.g. {data.title}); we do NOT
745
- * follow the expression — that would turn this into runtime analysis.
746
- * - non-whitespace Text only → 'static'
747
- * - empty / whitespace only → 'absent'
748
- */
749
765
  declare function valueFromNodes(nodes: TextOrExpr[]): Value;
750
766
  /** The literal text of a node list when fully static (no ExpressionTag), else undefined. */
751
767
  declare function textFromNodes(nodes: TextOrExpr[]): string | undefined;
@@ -780,6 +796,19 @@ declare function settingSeverity(setting: RuleSetting | undefined): Severity | '
780
796
  declare function settingOptions(setting: RuleSetting | undefined): RuleOptions | undefined;
781
797
  /** Drop rules disabled via config (design §6). */
782
798
  declare function selectRules(rules: Rule[], config: Config): Rule[];
799
+ /**
800
+ * `config` with `failedRuleIds` (from `runRules`' `failedRules`) forced `'off'`: a rule that threw
801
+ * examined nothing, so leaving it in the inventory would score it as if it had run clean, silently
802
+ * inflating Health. Reuses the exact mechanism a `rules: { id: 'off' }` config entry already gets —
803
+ * `selectRules`/`buildInventory` both drop an `'off'` id from the denominator — rather than adding a
804
+ * second, parallel notion of "not counted" for callers to keep in sync.
805
+ */
806
+ declare function withFailedRulesOff(config: Config, failedRuleIds: readonly string[]): Config;
807
+ /** One-line "rule failed and was skipped" warning; capped to the message's first line so a stack trace can't flood a terminal. */
808
+ declare function formatFailedRuleWarning(f: {
809
+ id: string;
810
+ message: string;
811
+ }): string;
783
812
  /** Apply per-rule severity overrides to results (design §6). */
784
813
  declare function applyRuleSeverities(results: Result[], config: Config): Result[];
785
814
  /** An override entry with its globs compiled once. Build with `compileOverrides`. */
@@ -1009,14 +1038,21 @@ declare function docsUrlFor(id: string): string;
1009
1038
  */
1010
1039
  declare function isPenalized(detection: Detection, treatDynamicAs: TreatDynamicAs): boolean;
1011
1040
 
1041
+ interface FailedRule {
1042
+ id: string;
1043
+ message: string;
1044
+ }
1012
1045
  /**
1013
1046
  * Run a set of rules against a shared context and collect their findings.
1014
1047
  * Rules are independent, so they run concurrently; results are flattened in
1015
- * rule order for stable output.
1048
+ * rule order for stable output. A rule that throws (sync or async) contributes
1049
+ * no results instead of taking the whole run down with it — dev tooling must
1050
+ * never throw — and is reported in `failedRules` instead.
1016
1051
  */
1017
1052
  declare function runRules(rules: Rule[], ctx: RuleContext): Promise<{
1018
1053
  results: Result[];
1019
1054
  examined: Record<string, Record<string, number>>;
1055
+ failedRules: FailedRule[];
1020
1056
  }>;
1021
1057
 
1022
1058
  /**
@@ -1501,6 +1537,23 @@ interface ConsoleReportOptions {
1501
1537
  */
1502
1538
  declare function formatConsoleReport(results: Result[], config: Config, options?: ConsoleReportOptions): string;
1503
1539
 
1540
+ /**
1541
+ * Strip ANSI/OSC escape sequences and C0 control characters (except `\n`/`\t`) from a
1542
+ * string before it reaches a terminal. POSIX file/route names can contain almost any
1543
+ * byte, so a hostile repo can smuggle a terminal-title rewrite, cursor move, or other
1544
+ * escape-sequence trick into what looks like plain report text.
1545
+ *
1546
+ * Only OSC and CSI sequences are pattern-matched and removed whole (payload included) —
1547
+ * those cover title-bar writes and cursor/screen control, the two classes with a real
1548
+ * blast radius. Any other `ESC` byte (rarer single/two-byte forms like reset or
1549
+ * save-cursor) falls through to the final C0 sweep below, which drops the lone `ESC`
1550
+ * but — deliberately, not swallowing an adjacent legitimate character — leaves whatever
1551
+ * printable byte follows it as stray text.
1552
+ * ponytail: doesn't special-case every Fe escape form; broaden the CSI/OSC patterns if a
1553
+ * concrete non-CSI/OSC sequence turns out to matter.
1554
+ */
1555
+ declare function terminalSafe(text: string): string;
1556
+
1504
1557
  interface ScoreModel {
1505
1558
  routeAverage: number;
1506
1559
  sitePenalty: number;
@@ -1632,6 +1685,20 @@ declare function formatMarkdownReport(results: Result[], config: Config, meta: {
1632
1685
  version: string;
1633
1686
  }): string;
1634
1687
 
1688
+ type Band = 'good' | 'warn' | 'poor';
1689
+ declare const BAND_COLOR: Record<Band, string>;
1690
+ declare function scoreBand(score: number): Band;
1691
+ declare function escapeHtml(s: string): string;
1692
+ /**
1693
+ * Return the URL only when it uses a safe http/https scheme, else null.
1694
+ * Guards a finding's `docsUrl` against `javascript:`/`data:` hrefs — escapeHtml
1695
+ * neutralizes attribute breakout but not a malicious scheme. Browsers strip
1696
+ * ASCII whitespace (tab/newline/CR) from a URL before resolving its scheme (so
1697
+ * `java\tscript:` runs as `javascript:`), so strip whitespace first; anything not
1698
+ * plainly http(s):// afterward is rejected. Pure string work — no `URL` global,
1699
+ * keeping core runtime-agnostic and lib-minimal.
1700
+ */
1701
+ declare function safeHref(url: string): string | null;
1635
1702
  /** Provenance of a route's findings: real rendered page vs. source-only analysis. */
1636
1703
  type RouteBadge = 'measured' | 'static';
1637
1704
  interface AppSnapshot {
@@ -1681,19 +1748,4 @@ declare function formatHtmlReport(results: Result[], config: Config, meta: {
1681
1748
  coreVersion?: string;
1682
1749
  }): string;
1683
1750
 
1684
- type Band = 'good' | 'warn' | 'poor';
1685
- declare const BAND_COLOR: Record<Band, string>;
1686
- declare function scoreBand(score: number): Band;
1687
- declare function escapeHtml(s: string): string;
1688
- /**
1689
- * Return the URL only when it uses a safe http/https scheme, else null.
1690
- * Guards a finding's `docsUrl` against `javascript:`/`data:` hrefs — escapeHtml
1691
- * neutralizes attribute breakout but not a malicious scheme. Browsers strip
1692
- * ASCII whitespace (tab/newline/CR) from a URL before resolving its scheme (so
1693
- * `java\tscript:` runs as `javascript:`), so strip whitespace first; anything not
1694
- * plainly http(s):// afterward is rejected. Pure string work — no `URL` global,
1695
- * keeping core runtime-agnostic and lib-minimal.
1696
- */
1697
- declare function safeHref(url: string): string | null;
1698
-
1699
- export { APP_SCRIPT, APP_STYLE, type AppSnapshot, BAND_COLOR, CATEGORIES, CHILD_NODE_KEYS, type Category, type Classification, type CompiledOverride, type ComponentFacts, type Config, type ConsoleReportOptions, type Detection, type EachBlockFact, type EffectFact, type Fix, type HeadProvider, type HeadTag, type HeadingInfo, type HealthResult, type ImageInfo, type JsonReport, type KitAlias, type KitModuleFacts, type OrphanEffectFact, type Palette, type Presence, type Project, ROBOTS_SOURCE_PATHS, type RawKitAliases, type ResolvedHead, type ResolvedHeadings, type ResolvedImages, type Result, type RouteBadge, type Rule, type RuleContext, type RuleEvidence, type RuleInfo, type RuleOptionInfo, type RuleOptionSpec, type RuleOptions, type RuleOptionsSpec, type RuleOverride, type RuleSetting, type RuleSettingObject, type Runtime, SITEMAP_SOURCE_PATHS, SVELTE_CONFIG_FILES, type Scope, type ScoreModel, type ScoreOptions, type ScoreResult, type Severity, type SourceSpan, type Summary, type SuppressionDirective, type TreatDynamicAs, VITE_CONFIG_FILES, type Value, type ViteKitConfigResult, allRules, applyOverrides, applyRuleSeverities, architectureComponentSize, architectureDirectoryNaming, architectureDocLinkTarget, architecturePrivateScopeImport, architecturePropCount, architectureReservedDirectoryNames, architectureReservedNamePlacement, architectureRouteComponentImport, architectureUnitEntryFile, attrText, attrTextOf, attrValue, attrValueOf, buildHtmlDocument, buildJsonReport, classify, collectComponentFacts, collectKitModuleFacts, collectSourceFiles, compileOverrides, computeHealth, computeScore, correctnessBasePathNavigation, correctnessCheckableBindValue, correctnessEachIndexKey, correctnessEachKey, correctnessEffectAsDerived, correctnessEffectAsOnMount, correctnessInstanceBrowserGlobal, correctnessNonreactiveBuiltinState, correctnessOrphanEffect, correctnessOrphanLifecycle, correctnessPropMutation, correctnessServerBrowserGlobal, correctnessStalePropDerivation, correctnessUnmutatedState, defaultConfig, defaultProject, defineConfig, docsUrlFor, effectiveSeverity, emptyComponentFacts, emptyKitModuleFacts, escapeHtml, explainRule, findAttr, findKitAliasesInSvelteConfig, findKitPathsBaseInSvelteConfig, findKitPathsBaseInViteConfig, findMinifyDisabled, formatAgentReport, formatConsoleReport, formatGithubReport, formatHtmlReport, formatJsonReport, formatMarkdownReport, formatSarifReport, hasFailureAtOrAbove, headTagRule, imageRule, intOption, isMentionedAnywhere, isPenalized, lineOf, linkRule, listOption, mapOption, noColorPalette, overrideMatches, parseComponentFacts, parseKitModuleFacts, performanceFontPreloadCrossorigin, performanceHeavyImport, performanceImageDimensions, performanceImageLoadingHint, performanceLcpImage, performanceLoadWaterfall, performanceMinifyDisabled, performanceNamespaceImport, performancePreconnect, performancePreloadMissingAs, performanceRenderBlockingScript, performanceResponsiveImage, performanceSequentialAwaits, performanceStateRaw, renderAppShell, resolveKitAliases, resolveKitPathsBase, resolveRuleOptions, resolveRunesModuleSpecifier, runRules, safeHref, scoreBand, scoreColor, scoresByCategory, securityHandlerStateWrite, securityJavascriptUrl, securityRawHtml, securityServerModuleState, securitySharedStateImport, selectRules, seoCanonicalUrl, seoCharset, seoDescriptionLength, seoDescriptionPresence, seoDuplicateDescription, seoDuplicateTitle, seoHeadingLevelSkip, seoHreflang, seoHtmlLang, seoImageAlt, seoIndexability, seoJsonLd, seoJsonLdDateFormat, seoJsonLdDeprecatedType, seoJsonLdPlaceholder, seoJsonLdRelativeUrl, seoJsonLdRequiredProps, seoJsonLdValidity, seoOgDescription, seoOgImage, seoOgTitle, seoOgUrl, seoRobotsTxt, seoSingleH1, seoSitemapInRobots, seoSitemapXml, seoSsrDisabled, seoTitleLength, seoTitlePresence, seoTwitterCard, seoViewport, settingOptions, settingSeverity, shouldSkipRangeCheck, summarize, textFromNodes, validateRuleOptions, validateRuleSetting, valueFromNodes };
1751
+ export { APP_SCRIPT, APP_STYLE, type AppSnapshot, BAND_COLOR, CATEGORIES, CHILD_NODE_KEYS, type Category, type Classification, type CompiledOverride, type ComponentFacts, type Config, type ConsoleReportOptions, type Detection, type EachBlockFact, type EffectFact, type FailedRule, type Fix, type HeadProvider, type HeadTag, type HeadingInfo, type HealthResult, type ImageInfo, type JsonReport, type KitAlias, type KitModuleFacts, type OrphanEffectFact, type Palette, type Presence, type Project, ROBOTS_SOURCE_PATHS, type RawKitAliases, type ResolvedHead, type ResolvedHeadings, type ResolvedImages, type Result, type RouteBadge, type Rule, type RuleContext, type RuleEvidence, type RuleInfo, type RuleOptionInfo, type RuleOptionSpec, type RuleOptions, type RuleOptionsSpec, type RuleOverride, type RuleSetting, type RuleSettingObject, type Runtime, SITEMAP_SOURCE_PATHS, SVELTE_CONFIG_FILES, type Scope, type ScoreModel, type ScoreOptions, type ScoreResult, type Severity, type SourceSpan, type Summary, type SuppressionDirective, type TreatDynamicAs, VITE_CONFIG_FILES, type Value, type ViteKitConfigResult, allRules, applyOverrides, applyRuleSeverities, architectureComponentSize, architectureDirectoryNaming, architectureDocLinkTarget, architecturePrivateScopeImport, architecturePropCount, architectureReservedDirectoryNames, architectureReservedNamePlacement, architectureRouteComponentImport, architectureUnitEntryFile, attrText, attrTextOf, attrValue, attrValueOf, buildHtmlDocument, buildJsonReport, classify, collectComponentFacts, collectKitModuleFacts, collectSourceFiles, compileOverrides, computeHealth, computeScore, correctnessBasePathNavigation, correctnessCheckableBindValue, correctnessEachIndexKey, correctnessEachKey, correctnessEffectAsDerived, correctnessEffectAsOnMount, correctnessInstanceBrowserGlobal, correctnessNonreactiveBuiltinState, correctnessOrphanEffect, correctnessOrphanLifecycle, correctnessPropMutation, correctnessServerBrowserGlobal, correctnessStalePropDerivation, correctnessUnmutatedState, defaultConfig, defaultProject, defineConfig, docsUrlFor, effectiveSeverity, emptyComponentFacts, emptyKitModuleFacts, escapeHtml, explainRule, findAttr, findKitAliasesInSvelteConfig, findKitPathsBaseInSvelteConfig, findKitPathsBaseInViteConfig, findMinifyDisabled, formatAgentReport, formatConsoleReport, formatFailedRuleWarning, formatGithubReport, formatHtmlReport, formatJsonReport, formatMarkdownReport, formatSarifReport, hasFailureAtOrAbove, headTagRule, imageRule, intOption, isMentionedAnywhere, isPenalized, lineOf, linkRule, listOption, mapOption, noColorPalette, overrideMatches, parseComponentFacts, parseKitModuleFacts, performanceFontPreloadCrossorigin, performanceHeavyImport, performanceImageDimensions, performanceImageLoadingHint, performanceLcpImage, performanceLoadWaterfall, performanceMinifyDisabled, performanceNamespaceImport, performancePreconnect, performancePreloadMissingAs, performanceRenderBlockingScript, performanceResponsiveImage, performanceSequentialAwaits, performanceStateRaw, renderAppShell, resolveKitAliases, resolveKitPathsBase, resolveRepoLocalPath, resolveRuleOptions, resolveRunesModuleSpecifier, runRules, safeHref, scoreBand, scoreColor, scoresByCategory, securityHandlerStateWrite, securityJavascriptUrl, securityRawHtml, securityServerModuleState, securitySharedStateImport, selectRules, seoCanonicalUrl, seoCharset, seoDescriptionLength, seoDescriptionPresence, seoDuplicateDescription, seoDuplicateTitle, seoHeadingLevelSkip, seoHreflang, seoHtmlLang, seoImageAlt, seoIndexability, seoJsonLd, seoJsonLdDateFormat, seoJsonLdDeprecatedType, seoJsonLdPlaceholder, seoJsonLdRelativeUrl, seoJsonLdRequiredProps, seoJsonLdValidity, seoOgDescription, seoOgImage, seoOgTitle, seoOgUrl, seoRobotsTxt, seoSingleH1, seoSitemapInRobots, seoSitemapXml, seoSsrDisabled, seoTitleLength, seoTitlePresence, seoTwitterCard, seoViewport, settingOptions, settingSeverity, shouldSkipRangeCheck, summarize, terminalSafe, textFromNodes, validateRuleOptions, validateRuleSetting, valueFromNodes, withFailedRulesOff };