svelte-vitals 0.21.0 → 0.22.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/dist/bin.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  readCoreVersion,
8
8
  readPackageVersion,
9
9
  run
10
- } from "./chunk-B3RVLTZY.js";
10
+ } from "./chunk-KSJZLF5U.js";
11
11
 
12
12
  // src/bin.ts
13
13
  import mri3 from "mri";
@@ -849,9 +849,9 @@ function planWorkflowWrite(existing, force) {
849
849
  return { status: "updated" };
850
850
  }
851
851
  function buildWorkflowYaml(opts) {
852
- const v = opts.version;
852
+ const { actionSha, actionVersion } = opts;
853
853
  return [
854
- `# Generated by \`svelte-vitals ci install\` (svelte-vitals ${v}).`,
854
+ "# Generated by `svelte-vitals ci install`.",
855
855
  "# Re-run with --force to regenerate.",
856
856
  "name: svelte-vitals",
857
857
  "",
@@ -869,60 +869,27 @@ function buildWorkflowYaml(opts) {
869
869
  " - uses: actions/checkout@v4",
870
870
  " with:",
871
871
  " fetch-depth: 0",
872
- " - uses: actions/setup-node@v4",
872
+ ` - uses: oekazuma/svelte-vitals/packages/action@${actionSha} # @svelte-vitals/action@${actionVersion}`,
873
873
  " with:",
874
- " node-version: 24",
875
- " - name: Scan (inline annotations + gate)",
876
- " id: scan",
877
- " continue-on-error: true",
878
- " run: >",
879
- ` npx -y svelte-vitals@${v} .`,
880
- " --diff origin/${{ github.base_ref }}",
881
- " --baseline origin/${{ github.base_ref }}",
882
- " --reporter github",
883
- " - name: Markdown summary",
884
- " run: >",
885
- ` npx -y svelte-vitals@${v} .`,
886
- " --diff origin/${{ github.base_ref }}",
887
- " --baseline origin/${{ github.base_ref }}",
888
- " --reporter md > svelte-vitals-report.md || true",
889
- " - name: Job summary",
890
- ' run: cat svelte-vitals-report.md >> "$GITHUB_STEP_SUMMARY"',
891
- " - name: PR comment (sticky)",
892
- " if: github.event.pull_request.head.repo.full_name == github.repository",
893
- " continue-on-error: true",
894
- " uses: actions/github-script@v7",
895
- " with:",
896
- " script: |",
897
- " const fs = require('fs');",
898
- " const marker = '<!-- svelte-vitals-report -->';",
899
- " const body = marker + '\\n' + fs.readFileSync('svelte-vitals-report.md', 'utf8');",
900
- " const { data: comments } = await github.rest.issues.listComments({",
901
- " ...context.repo, issue_number: context.issue.number, per_page: 100",
902
- " });",
903
- " const mine = comments.find(c => c.body && c.body.startsWith(marker));",
904
- " if (mine) {",
905
- " await github.rest.issues.updateComment({ ...context.repo, comment_id: mine.id, body });",
906
- " } else {",
907
- " await github.rest.issues.createComment({ ...context.repo, issue_number: context.issue.number, body });",
908
- " }",
909
- " - name: Gate",
910
- " if: steps.scan.outcome == 'failure'",
911
- " run: |",
912
- ' echo "svelte-vitals found blocking issues (see annotations above)."',
913
- " exit 1",
874
+ " diff: origin/${{ github.base_ref }}",
875
+ " baseline: origin/${{ github.base_ref }}",
914
876
  ""
915
877
  ].join("\n");
916
878
  }
917
879
 
880
+ // src/ci/action-pin.generated.ts
881
+ var ACTION_SHA = "86e84073bddea99530d2d6831378a68836443ee4";
882
+ var ACTION_VERSION = "0.2.0";
883
+
918
884
  // src/ci/cli.ts
919
885
  var CI_HELP = `svelte-vitals ci \u2014 scaffold CI integration
920
886
 
921
887
  Usage:
922
888
  svelte-vitals ci install [options]
923
889
 
924
- Adds a GitHub Actions workflow (${WORKFLOW_PATH}) that scans pull requests, posts inline
925
- annotations + a job summary, and maintains a sticky PR comment with the findings.
890
+ Adds a GitHub Actions workflow (${WORKFLOW_PATH}) that calls the \`@svelte-vitals/action\`
891
+ GitHub Action on pull requests: inline annotations, a job summary, and a sticky PR
892
+ comment with the findings.
926
893
 
927
894
  Options:
928
895
  --force Overwrite an existing workflow file
@@ -958,9 +925,8 @@ async function runCiCli(args, io = realIO()) {
958
925
  if (plan.status === "exists") {
959
926
  io.log(`= already installed (${WORKFLOW_PATH}) \u2014 use --force to regenerate.`);
960
927
  } else {
961
- const version = readPackageVersion();
962
928
  try {
963
- io.writeFile(path, buildWorkflowYaml({ version }));
929
+ io.writeFile(path, buildWorkflowYaml({ actionSha: ACTION_SHA, actionVersion: ACTION_VERSION }));
964
930
  io.log(`\u2713 ${plan.status} ${WORKFLOW_PATH}`);
965
931
  } catch (err) {
966
932
  io.errorLog(
@@ -994,6 +994,38 @@ async function analyzeProject(opts = {}) {
994
994
  );
995
995
  return { results, config, version: readPackageVersion(), warnings };
996
996
  }
997
+ async function applyScope(results, opts) {
998
+ const errorLog = opts.errorLog ?? ((line) => console.error(line));
999
+ let scoped = results;
1000
+ if (opts.staged || opts.diffBase !== void 0) {
1001
+ const changed = opts.staged ? getChangedFiles(opts.cwd, { staged: true }) : getChangedFiles(opts.cwd, { base: opts.diffBase });
1002
+ if (changed === void 0) {
1003
+ errorLog(
1004
+ "svelte-vitals: could not determine changed files (not a git repo, git unavailable, or bad ref); analyzing all."
1005
+ );
1006
+ } else {
1007
+ scoped = filterToChangedFiles(scoped, changed);
1008
+ }
1009
+ }
1010
+ if (opts.baseline !== void 0) {
1011
+ const checkout = checkoutBaseline(opts.cwd, opts.baseline);
1012
+ if (checkout === void 0) {
1013
+ errorLog(
1014
+ `svelte-vitals: could not analyze baseline '${opts.baseline}' (not a git repo, git unavailable, or bad ref); reporting all findings.`
1015
+ );
1016
+ } else {
1017
+ try {
1018
+ const base = await analyzeProject({ ...opts.analyzeOpts, cwd: checkout.analyzeCwd });
1019
+ scoped = filterToNewFindings(scoped, base.results);
1020
+ } catch {
1021
+ errorLog(`svelte-vitals: baseline analysis of '${opts.baseline}' failed; reporting all findings.`);
1022
+ } finally {
1023
+ checkout.cleanup();
1024
+ }
1025
+ }
1026
+ }
1027
+ return scoped;
1028
+ }
997
1029
  async function run(opts = {}) {
998
1030
  const log = opts.log ?? ((line) => console.log(line));
999
1031
  const errorLog = opts.errorLog ?? ((line) => console.error(line));
@@ -1086,43 +1118,22 @@ async function run(opts = {}) {
1086
1118
  for (const w of analysis.warnings) errorLog(`svelte-vitals: ${w}`);
1087
1119
  try {
1088
1120
  const { config, version } = analysis;
1089
- let results = analysis.results;
1090
- if (opts.staged || opts.diffBase !== void 0) {
1091
- const changed = opts.staged ? getChangedFiles(cwd, { staged: true }) : getChangedFiles(cwd, { base: opts.diffBase });
1092
- if (changed === void 0) {
1093
- errorLog(
1094
- "svelte-vitals: could not determine changed files (not a git repo, git unavailable, or bad ref); analyzing all."
1095
- );
1096
- } else {
1097
- results = filterToChangedFiles(results, changed);
1098
- }
1099
- }
1100
- if (opts.baseline !== void 0) {
1101
- const checkout = checkoutBaseline(cwd, opts.baseline);
1102
- if (checkout === void 0) {
1103
- errorLog(
1104
- `svelte-vitals: could not analyze baseline '${opts.baseline}' (not a git repo, git unavailable, or bad ref); reporting all findings.`
1105
- );
1106
- } else {
1107
- try {
1108
- const base = await analyzeProject({
1109
- cwd: checkout.analyzeCwd,
1110
- metaComponents: opts.metaComponents,
1111
- treatDynamicAs: opts.treatDynamicAs,
1112
- route: opts.route,
1113
- failOn: opts.failOn,
1114
- rules: opts.rules,
1115
- weights: opts.weights,
1116
- categories: opts.categories
1117
- });
1118
- results = filterToNewFindings(results, base.results);
1119
- } catch {
1120
- errorLog(`svelte-vitals: baseline analysis of '${opts.baseline}' failed; reporting all findings.`);
1121
- } finally {
1122
- checkout.cleanup();
1123
- }
1121
+ const results = await applyScope(analysis.results, {
1122
+ cwd,
1123
+ staged: opts.staged,
1124
+ diffBase: opts.diffBase,
1125
+ baseline: opts.baseline,
1126
+ errorLog,
1127
+ analyzeOpts: {
1128
+ metaComponents: opts.metaComponents,
1129
+ treatDynamicAs: opts.treatDynamicAs,
1130
+ route: opts.route,
1131
+ failOn: opts.failOn,
1132
+ rules: opts.rules,
1133
+ weights: opts.weights,
1134
+ categories: opts.categories
1124
1135
  }
1125
- }
1136
+ });
1126
1137
  if (opts.score) {
1127
1138
  log(String(computeHealth(results, config).health));
1128
1139
  } else {
@@ -1192,6 +1203,7 @@ export {
1192
1203
  spinnerEnabled,
1193
1204
  routeMatcher,
1194
1205
  analyzeProject,
1206
+ applyScope,
1195
1207
  run,
1196
1208
  defineConfig2 as defineConfig
1197
1209
  };
package/dist/index.d.ts CHANGED
@@ -137,10 +137,25 @@ interface AnalyzeResult {
137
137
  * 2026-07-05-config-file-design.md §3).
138
138
  */
139
139
  declare function analyzeProject(opts?: AnalyzeOptions): Promise<AnalyzeResult>;
140
+ interface ApplyScopeOptions {
141
+ cwd: string;
142
+ staged?: boolean;
143
+ diffBase?: string;
144
+ baseline?: string;
145
+ errorLog?: (line: string) => void;
146
+ analyzeOpts?: AnalyzeOptions;
147
+ }
148
+ /**
149
+ * Narrow `results` to what a PR gate cares about: `--staged`/`--diff` restrict to
150
+ * changed files, `--baseline` drops findings that already existed at that ref. Shared
151
+ * by `run()` and `@svelte-vitals/action` (issue #154) so the git-diff/baseline
152
+ * orchestration lives in exactly one place.
153
+ */
154
+ declare function applyScope(results: Result[], opts: ApplyScopeOptions): Promise<Result[]>;
140
155
  /**
141
156
  * Run static-mode analysis once and return the process exit code (design §6):
142
157
  * 0 = no failing findings, 1 = critical finding present, 2 = execution error.
143
158
  */
144
159
  declare function run(opts?: RunOptions): Promise<number>;
145
160
 
146
- export { type AnalyzeOptions, type AnalyzeResult, type LoadedConfigFile, ProjectError, type RunOptions, analyzeProject, buildRulesConfig, findUnknownRuleIds, knownRuleIds, loadConfigFile, routeMatcher, run, spinnerEnabled };
161
+ export { type AnalyzeOptions, type AnalyzeResult, type ApplyScopeOptions, type LoadedConfigFile, ProjectError, type RunOptions, analyzeProject, applyScope, buildRulesConfig, findUnknownRuleIds, knownRuleIds, loadConfigFile, routeMatcher, run, spinnerEnabled };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  ProjectError,
3
3
  analyzeProject,
4
+ applyScope,
4
5
  buildRulesConfig,
5
6
  defineConfig,
6
7
  findUnknownRuleIds,
@@ -9,10 +10,11 @@ import {
9
10
  routeMatcher,
10
11
  run,
11
12
  spinnerEnabled
12
- } from "./chunk-B3RVLTZY.js";
13
+ } from "./chunk-KSJZLF5U.js";
13
14
  export {
14
15
  ProjectError,
15
16
  analyzeProject,
17
+ applyScope,
16
18
  buildRulesConfig,
17
19
  defineConfig,
18
20
  findUnknownRuleIds,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-vitals",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "A SvelteKit SEO checker — not a runtime Web Vitals reporter. Static analysis of your routes' head metadata.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -51,8 +51,8 @@
51
51
  "@types/node": "^24.13.2"
52
52
  },
53
53
  "scripts": {
54
- "build": "tsup",
55
- "typecheck": "tsc --noEmit",
56
- "test": "vitest run"
54
+ "build": "node scripts/gen-action-pin.mjs && tsup",
55
+ "typecheck": "node scripts/gen-action-pin.mjs && tsc --noEmit",
56
+ "test": "node scripts/gen-action-pin.mjs && vitest run"
57
57
  }
58
58
  }