@nifrajs/cli 5.1.0 → 5.3.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 +3313 -0
- package/README.md +3 -0
- package/dist/agent-files.d.ts +19 -11
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +26 -18
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +7 -2
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +14 -1
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +131 -45
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +5 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +5 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +9 -3
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +61 -21
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +55 -15
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +37 -18
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +9 -5
- package/dist/command-catalog.js.map +1 -1
- package/dist/db-tool.d.ts.map +1 -1
- package/dist/db-tool.js +2 -1
- package/dist/db-tool.js.map +1 -1
- package/dist/dev-bun-config.d.ts +6 -3
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +13 -10
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/dev-feed-tool.d.ts +3 -2
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +26 -5
- package/dist/dev-feed-tool.js.map +1 -1
- package/dist/doctor.d.ts +15 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +79 -61
- package/dist/doctor.js.map +1 -1
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +41 -8
- package/dist/env-file.js.map +1 -1
- package/dist/i18n-check.d.ts +11 -1
- package/dist/i18n-check.d.ts.map +1 -1
- package/dist/i18n-check.js +170 -17
- package/dist/i18n-check.js.map +1 -1
- package/dist/init-agents.d.ts +46 -6
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +193 -31
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +9 -1
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/source-facts.d.ts +22 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +322 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/workspace-packages.d.ts +22 -0
- package/dist/internal/workspace-packages.d.ts.map +1 -0
- package/dist/internal/workspace-packages.js +215 -0
- package/dist/internal/workspace-packages.js.map +1 -0
- package/dist/load.d.ts +7 -2
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +11 -2
- package/dist/load.js.map +1 -1
- package/dist/lock-links.d.ts +42 -0
- package/dist/lock-links.d.ts.map +1 -0
- package/dist/lock-links.js +144 -0
- package/dist/lock-links.js.map +1 -0
- package/dist/mcp-exec.d.ts +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +16 -5
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +23 -3
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +59 -12
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts.map +1 -1
- package/dist/mcp-isolate.js +2 -1
- package/dist/mcp-isolate.js.map +1 -1
- package/dist/mcp-root.d.ts +6 -4
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +12 -8
- package/dist/mcp-root.js.map +1 -1
- package/dist/migrate-layout.d.ts +2 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +435 -29
- package/dist/migrate-layout.js.map +1 -1
- package/dist/project-site.d.ts +7 -0
- package/dist/project-site.d.ts.map +1 -0
- package/dist/project-site.js +19 -0
- package/dist/project-site.js.map +1 -0
- package/dist/recipes/4.0.0.d.ts.map +1 -1
- package/dist/recipes/4.0.0.js +2 -0
- package/dist/recipes/4.0.0.js.map +1 -1
- package/dist/recipes/5.1.0.d.ts +9 -0
- package/dist/recipes/5.1.0.d.ts.map +1 -0
- package/dist/recipes/5.1.0.js +22 -0
- package/dist/recipes/5.1.0.js.map +1 -0
- package/dist/recipes/5.2.0.d.ts +10 -0
- package/dist/recipes/5.2.0.d.ts.map +1 -0
- package/dist/recipes/5.2.0.js +32 -0
- package/dist/recipes/5.2.0.js.map +1 -0
- package/dist/recipes/5.3.0.d.ts +11 -0
- package/dist/recipes/5.3.0.d.ts.map +1 -0
- package/dist/recipes/5.3.0.js +35 -0
- package/dist/recipes/5.3.0.js.map +1 -0
- package/dist/recipes/index.d.ts +3 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +9 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +4 -0
- package/dist/review.js.map +1 -1
- package/dist/rule-explain.d.ts +26 -0
- package/dist/rule-explain.d.ts.map +1 -0
- package/dist/rule-explain.js +49 -0
- package/dist/rule-explain.js.map +1 -0
- package/dist/rules/codes.d.ts +4 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +4 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +93 -21
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/explanations.d.ts +14 -0
- package/dist/rules/explanations.d.ts.map +1 -0
- package/dist/rules/explanations.js +326 -0
- package/dist/rules/explanations.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +24 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/merge-auth.d.ts +12 -0
- package/dist/rules/merge-auth.d.ts.map +1 -0
- package/dist/rules/merge-auth.js +52 -0
- package/dist/rules/merge-auth.js.map +1 -0
- package/dist/rules/pages.d.ts +51 -0
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +293 -2
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/route-statement.d.ts +10 -0
- package/dist/rules/route-statement.d.ts.map +1 -0
- package/dist/rules/route-statement.js +150 -0
- package/dist/rules/route-statement.js.map +1 -0
- package/dist/rules/routes.d.ts +3 -2
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +4 -3
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +3 -2
- package/dist/rules/zones.js.map +1 -1
- package/dist/typecheck-coverage.d.ts +11 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +50 -7
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +80 -11
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +332 -65
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +2 -0
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts.map +1 -1
- package/dist/version-drift.js +12 -1
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +19 -1
- package/docs/llms-full.txt +716 -138
- package/docs/types.json +516 -74
- package/package.json +13 -12
- package/src/agent-files.ts +27 -17
- package/src/assure-hydration.ts +8 -1
- package/src/assure.ts +11 -1
- package/src/capabilities-tool.ts +159 -50
- package/src/check-diagnostics.ts +10 -0
- package/src/check-scan.ts +64 -19
- package/src/check.ts +75 -15
- package/src/cli.ts +38 -17
- package/src/command-catalog.ts +16 -8
- package/src/db-tool.ts +2 -0
- package/src/dev-bun-config.ts +13 -9
- package/src/dev-feed-tool.ts +40 -6
- package/src/doctor.ts +102 -66
- package/src/env-file.ts +42 -7
- package/src/i18n-check.ts +254 -18
- package/src/init-agents.ts +221 -41
- package/src/internal/project-specifiers.ts +9 -1
- package/src/internal/source-facts.ts +397 -0
- package/src/internal/workspace-packages.ts +218 -0
- package/src/load.ts +19 -3
- package/src/lock-links.ts +173 -0
- package/src/mcp-exec.ts +18 -4
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +72 -12
- package/src/mcp-isolate.ts +2 -0
- package/src/mcp-root.ts +14 -8
- package/src/migrate-layout.ts +496 -31
- package/src/project-site.ts +18 -0
- package/src/recipes/4.0.0.ts +2 -0
- package/src/recipes/5.1.0.ts +23 -0
- package/src/recipes/5.2.0.ts +33 -0
- package/src/recipes/5.3.0.ts +36 -0
- package/src/recipes/index.ts +9 -0
- package/src/review.ts +4 -0
- package/src/rule-explain.ts +75 -0
- package/src/rules/codes.ts +4 -0
- package/src/rules/contract-visibility.ts +118 -20
- package/src/rules/explanations.ts +339 -0
- package/src/rules/legacy.ts +24 -1
- package/src/rules/merge-auth.ts +55 -0
- package/src/rules/pages.ts +381 -2
- package/src/rules/route-statement.ts +170 -0
- package/src/rules/routes.ts +4 -3
- package/src/rules/zones.ts +3 -2
- package/src/typecheck-coverage.ts +51 -6
- package/src/upgrade.ts +430 -70
- package/src/verification-plan.ts +6 -0
- package/src/version-drift.ts +15 -0
- package/src/web-app-options.ts +9 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isAbsolute, relative, sep } from "node:path"
|
|
2
|
+
import { fileURLToPath } from "node:url"
|
|
3
|
+
|
|
4
|
+
/** A recorded `file:line:col` as a project-relative POSIX path and line, when it is inside the project
|
|
5
|
+
* and not under a `node_modules`. */
|
|
6
|
+
export function projectSite(
|
|
7
|
+
root: string,
|
|
8
|
+
site: string | undefined,
|
|
9
|
+
): { readonly file: string; readonly line: number } | undefined {
|
|
10
|
+
const [, raw, line] = site?.match(/^(.*):(\d+):\d+$/) ?? []
|
|
11
|
+
if (raw === undefined || line === undefined) return undefined
|
|
12
|
+
const path = raw.startsWith("file://") ? fileURLToPath(raw) : raw
|
|
13
|
+
if (!isAbsolute(path)) return undefined
|
|
14
|
+
const rel = relative(root, path)
|
|
15
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) return undefined
|
|
16
|
+
if (rel.split(sep).includes("node_modules")) return undefined
|
|
17
|
+
return { file: rel.split(sep).join("/"), line: Number(line) }
|
|
18
|
+
}
|
package/src/recipes/4.0.0.ts
CHANGED
|
@@ -20,6 +20,8 @@ export const recipe: UpgradeRecipe = {
|
|
|
20
20
|
"A loader or action that returns data needs `loaderOutput` / `actionOutput` in its backend half, or the request fails; the data is projected through the schema, so undeclared keys never reach the page. A deferred value is declared with `t.deferred(schema)`. `nifra check` reports a loader without one (NF-C030).",
|
|
21
21
|
"Builds fail on what looks like a credential in a client bundle, a `public/` file or a prerendered page; exempt a reviewed false positive with `secretExemptions` in `nifra.config.ts`.",
|
|
22
22
|
"The Cloudflare Pages target is `cloudflare` (`cf-pages` is refused), and `export const target` in `nifra.config.ts` sets what `nifra build` emits.",
|
|
23
|
+
'Page data reaches the browser in one inert `<script type="application/json" id="__nifra-handover">` instead of a script that assigned `window.__NIFRA_DATA__` and its siblings; the client entry assigns the same globals before anything reads them. A test or tool that read `window.__NIFRA_DATA__=` out of the HTML parses that element\'s JSON (`HANDOVER_ID` from `@nifrajs/web`), and an inline script that read the globals before the client entry must run after it.',
|
|
24
|
+
"`x-nifra-isr-revalidate` and `x-nifra-isr-tags`, which carry a route's `revalidate` and `revalidateTags`, are set only once a cache wrapper such as `withISR` attaches, and `withISR` removes them from every response it returns. A test or proxy that read a page's TTL from those headers on an unwrapped app reads nothing; assert on the wrapper's cache behavior, or on the route's `revalidate` export.",
|
|
23
25
|
'`withISR` no longer caches a page per query string by default: a request with any query parameter renders fresh and is not stored. Pass `query: ["page", ...]` to cache those parameters, or `query: "all"` to both `withISR` and `revalidateEndpoint` to keep the old keys.',
|
|
24
26
|
"A page file under the backend's API prefix or any other mount (`routes/api/*.tsx` with a backend) now fails at startup, at build and in `nifra check` (NF-C027), instead of answering 404. Move the page, change `apiPrefix` in `backend/framework.ts`, or serve that path from the backend.",
|
|
25
27
|
'Two page routes of one shape that share a path, such as `users/[id].tsx` beside `users/[slug].tsx`, fail dev, build and `nifra check` with "overlapping routes", because one could never be served. A static page beside a dynamic one (`users/me.tsx` beside `users/[id].tsx`) is fine: the more specific route serves the path they share. In a backend file, `nifra check` reports two same-method registrations that accept a shared path (NF-C024); make them disjoint (`/users/:id{[0-9]+}`) or mark the intended pair with a `// nifra-expect route-overlap` comment.',
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { UpgradeRecipe } from "./index.ts"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Upgrade recipe for Nifra 5.1.
|
|
5
|
+
*
|
|
6
|
+
* No import or dependency moves. Three changes can alter what a 5.0 app serves, so each note says what
|
|
7
|
+
* changes and the one edit that keeps or restores the old answer.
|
|
8
|
+
*/
|
|
9
|
+
export const recipe: UpgradeRecipe = {
|
|
10
|
+
version: "5.1.0",
|
|
11
|
+
pins: [
|
|
12
|
+
{ match: "@nifrajs/", to: "5.1.0" },
|
|
13
|
+
{ match: "create-nifra", to: "5.1.0" },
|
|
14
|
+
{ match: "nifra", to: "5.1.0" },
|
|
15
|
+
],
|
|
16
|
+
importMoves: [],
|
|
17
|
+
notes: [
|
|
18
|
+
'`merge()` now recompiles a merged route under the `responseContract()` and `effectLedger()` the server it is merged into installed before the merge, when the route declares a response (or capabilities) and its own server installed neither, as a `group()` route already was. Under `responseContract("enforce")`, a merged route whose payload carries a field its closed `t.object` does not declare now answers 500; declare the field, or install `responseContract("enforce", { extra: "strip" })` to drop it. After installing, `nifra routes --hooks --since .nifra/hooks-before-upgrade.json` lists each route that gained the contract.',
|
|
19
|
+
"A route with a `body` schema refuses a urlencoded, multipart or `text/plain` body whose `Origin` names another site with `403 forbidden_origin`, before reading it. A frontend on another origin that posts forms or `FormData` to the API, or an identity provider's `form_post` callback, needs that origin in the `formOrigins` server option (`@nifrajs/edge` takes it too). JSON bodies are unchanged.",
|
|
20
|
+
"`clientIp: { trustedHops: n }` reads the same `X-Forwarded-For` entry whether or not the adapter saw a socket peer. With no peer (Workers, edge handlers, a unix socket) it used to take the entry one place further left, which the client wrote; with no peer, `trustedHops: 0` is now `undefined`.",
|
|
21
|
+
'New and optional: a route assurance `baseline` rule `{ name: "response-contract", match: { hasResponse: true }, require: [NIFRA_ASSURANCE.RESPONSE_CONTRACT] }` makes `nifra assure` fail a route that declares a response no contract enforces.',
|
|
22
|
+
],
|
|
23
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { UpgradeRecipe } from "./index.ts"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Upgrade recipe for Nifra 5.2.
|
|
5
|
+
*
|
|
6
|
+
* No import or dependency moves. Six changes alter what a 5.1 app serves or builds, and the development audit,
|
|
7
|
+
* `nifra check`, `nifra i18n check` and the upgrade itself report more; each note says what changes and
|
|
8
|
+
* what keeps the old answer.
|
|
9
|
+
*/
|
|
10
|
+
export const recipe: UpgradeRecipe = {
|
|
11
|
+
version: "5.2.0",
|
|
12
|
+
pins: [
|
|
13
|
+
{ match: "@nifrajs/", to: "5.2.0" },
|
|
14
|
+
{ match: "create-nifra", to: "5.2.0" },
|
|
15
|
+
{ match: "nifra", to: "5.2.0" },
|
|
16
|
+
],
|
|
17
|
+
importMoves: [],
|
|
18
|
+
notes: [
|
|
19
|
+
"A closed request-header schema (`headers: t.object({...})`) validates only the header names it declares, read case-insensitively. It used to see every header a client sends (`host`, `user-agent`), so such a route answered real requests with 422; those requests are now served. Use `t.headers({...})` for an open header slot.",
|
|
20
|
+
'`responseContract("enforce", { extra: "strip" })` projects a union whose object branches all require one key holding literals no two branches share (`ok: true` / `ok: false`). When those branches are closed `t.object`s, a payload that carried undeclared fields used to answer 500; it is now sent without them.',
|
|
21
|
+
"An `authenticate()` stage that throws, or returns a malformed decision, still answers 503 `auth_unavailable`, but its cause now goes to `onError` (a response it returns replaces the 503) and, when no hook answers, to the logger as `unhandled request error`. A stage that throws a `Response` or `status(...)`, such as `requirePrincipal`'s 401 or redirect, now has it sent as thrown instead of a 503, and `authed()` from `@nifrajs/better-auth` no longer catches provider failures itself. An `onError` hook that answers every error now answers these too; return nothing for them to keep the 503.",
|
|
22
|
+
'The development `unusedScopedHooks` audit also reports a hook only `merge()`d routes follow (a merged route keeps its own server\'s chain), an `authenticate()` after the last route, and a `responseContract()` or `effectLedger()` installed after routes it would have covered. With `unusedScopedHooks: "error"` each now throws at startup outside production: move the call before the routes, or wire the hook on the merged server.',
|
|
23
|
+
"`nifra check` adds NF-C043 (warning): a parent's `authenticate()` or authenticated scope precedes a `merge()` of a server that authenticates none of its routes. Wire the auth on that server, or mark the merge `// nifra-expect NF-C043: <reason>`.",
|
|
24
|
+
"`nifra check`'s capability walk also starts from the module that registered each route, recorded while `nifra.assurance.ts` loads the app, so a route it could not see before (a computed path, a helper-built server) is now checked and may report an undeclared capability.",
|
|
25
|
+
"`nifra check`'s NF-C035 also reads app modules that call `createWebApp` themselves: a call that mounts `api` with no `apiPrefix`, or with one other than the framework config's, is reported. Import the `apiPrefix` from `backend/framework.ts` so both read one value.",
|
|
26
|
+
'`nifra i18n check` and `checkCatalogs()` report two new errors: `latin-share`, a message in a locale that does not write in Latin whose words are mostly Latin script, and `volume`, a long default message translated to under a third of its length. List kept brand names in `latinWords`, raise `maxLatinShare` or lower `minVolumeRatio`, or list the keys under `ignore` (`"*"` for every key) to keep the old answer.',
|
|
27
|
+
"`alternates()` from `@nifrajs/i18n/routing` given `locales` of a single locale returns no links, where it returned one self-reference.",
|
|
28
|
+
'`nifra check` typechecks every project `tsconfig.json` references, each as its own program, where it ran `tsc -p tsconfig.json` alone: a solution-style tsconfig (`"files": []` plus `references`) used to pass having read nothing, and its projects\' errors now fail the check. Name other configs to typecheck in `nifra.check.json` as `"tsconfigs": [...]`.',
|
|
29
|
+
"The Bun build (`nifra build` without `--vite`, `buildClient`, `buildServer`, `nifra dev --bun`) expands `import.meta.glob` as Vite does. A glob it used to bundle as a call that loads nothing now ships its files, and one it cannot read (a computed pattern, an alias, the `query` option) fails the build naming the file and line: write it as a literal, or build with `--vite`.",
|
|
30
|
+
"With both `nifra.config.ts` and `backend/framework.ts`, `nifra dev` and `nifra build` take `publicEnvPrefix` from `backend/framework.ts` when `nifra.config.ts` leaves it unset, so browser code reads the variables under that prefix there too, and `nifra check` (NF-C029) reads `nifra.config.ts` first. Set the prefix in one file to keep a single value.",
|
|
31
|
+
"In a project that declares `@nifrajs/cli`, `nifra upgrade --write` drops the version pin from the MCP launch (`bunx @nifrajs/cli mcp`) so it runs the installed CLI from then on; restart the agent afterwards. `nifra upgrade --write` now refuses while a `link:` or `file:` dependency installs another nifra version, naming the commands for that repository; `--allow-linked-skew` proceeds anyway.",
|
|
32
|
+
],
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { UpgradeRecipe } from "./index.ts"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Upgrade recipe for Nifra 5.3.
|
|
5
|
+
*
|
|
6
|
+
* No import or dependency moves. The typed client reads two route return shapes differently,
|
|
7
|
+
* `nifra check` and `nifra upgrade` report more, and a build, a GraphQL endpoint, a session store and
|
|
8
|
+
* a few constructors refuse inputs they used to take; each note says what changes and what keeps the
|
|
9
|
+
* old answer.
|
|
10
|
+
*/
|
|
11
|
+
export const recipe: UpgradeRecipe = {
|
|
12
|
+
version: "5.3.0",
|
|
13
|
+
pins: [
|
|
14
|
+
{ match: "@nifrajs/", to: "5.3.0" },
|
|
15
|
+
{ match: "create-nifra", to: "5.3.0" },
|
|
16
|
+
{ match: "nifra", to: "5.3.0" },
|
|
17
|
+
],
|
|
18
|
+
importMoves: [],
|
|
19
|
+
notes: [
|
|
20
|
+
"A route answering `status(code, body)` with a code typed as plain `number` types the client's `data` as that body, where it was `unknown`; a cast that recovered the type can go. A plain return beside `status(200, body)` types the 200 arm as either body, where the two were intersected, so client code that read a field only one of them has must narrow first.",
|
|
21
|
+
"`nifra check` adds NF-C045 (warning): a route added to a server as a statement of its own (`app.get(...)` with its result unused) when that server is exported or read by `typeof`. The route is served, but the typed client never sees it. Chain the registration onto the server's declaration, or declare the routes on their own `server()` and `merge()` it; `// nifra-expect NF-C045: <reason>` above the statement keeps a route off the type on purpose.",
|
|
22
|
+
"`nifra check` adds NF-C044 (warning): a `createWebApp` call that passes a `clientEntry` and no `copyChunks` in an app with copy tables (`@nifrajs/i18n/copy`), which fails in production on the first page that renders copy. Pass the `copyChunks` the generated server manifest exports; `// nifra-expect NF-C044: <reason>` on the call accepts a server that never serves those pages.",
|
|
23
|
+
"`nifra check`'s raw-`Response` advisory (NF-C007) also reads routes chained onto `createWebApp(...)`, a `Response` held in a local before it is returned, a handler's `c.json()`/`c.text()`, and a call to a function imported from a relative module that returns one, reported at each route that returns it. Return plain data to keep the route typed, or mark an intended `Response` with `// nifra-expect NF-C007: <reason>`.",
|
|
24
|
+
"`nifra upgrade` leaves a `peerDependencies` range alone when it already admits the target, and starts from the versions dependencies, devDependencies and overrides pin rather than from a peer floor, so a library workspace no longer replays older recipes. `nifra check` (NF-D002) and `nifra doctor` no longer count a peer floor as a second nifra version.",
|
|
25
|
+
"A build no longer copies hidden files from `public/` - any path segment starting with `.` other than `.well-known` - so `.env`, `.git/` or `.DS_Store` there is no longer deployed or served, matching development. A host marker a static deploy relies on, such as GitHub Pages' `.nojekyll`, now has to be written into the build output after the build.",
|
|
26
|
+
"`@nifrajs/graphql` refuses with a 400 before validation a document whose fragments, named and inline, expand past `maxFragmentExpansion` (default 20,000 selections summed over its selection sets), or whose fragment comparisons pass `maxFragmentComparisons` (default 100,000, which admits a binary tree of 255 fragments). Pass a higher limit to `respondGraphql`, `graphqlWebSocket` or `mountGraphql` if a legitimate client document is refused. A spread of an unknown fragment and a fragment cycle, which validation already refused, are refused before it too, with graphql-js's message and no `locations`.",
|
|
27
|
+
"A store-mode `@nifrajs/auth` session now writes a revocation marker under `<id>.revoked` on logout and rotation, and every load reads it beside the record. A custom `SessionStore` must accept that key like any other; one that validates keys against the session-id shape has to allow the suffix. `destroy(c, session)` also empties the session object it is passed, in both modes, so read anything you need from it before the call; committing it afterwards starts a new session holding only what was set since.",
|
|
28
|
+
"A raw request target holding a character a URL parser percent-encodes in a path (`\"`, `<`, `>`, `^`, `` ` ``, `{`, `}`, a space or non-ASCII) now routes as its encoded path on Node, Deno and Bun's native route table, as it already did on workerd and Bun's parsed URL: `GET /vault<tag>` reaches a route registered as `/vault%3Ctag%3E`, and `c.req.url` on Node and Deno carries the encoded form. Params are decoded as before.",
|
|
29
|
+
"`rangeResponse()` and `servePublicDir` ignore `Range` on a HEAD request (RFC 9110 section 14.2): HEAD answers 200 with the full `content-length`, where it used to answer 206 or 416.",
|
|
30
|
+
"Invalid numbers are refused where they used to disable a limit or strand work: `@nifrajs/edge` `server({ maxBodyBytes })` throws a `RangeError` for anything but a non-negative safe integer; `@nifrajs/jobs` `enqueue` throws for a `NaN` or infinite `delayMs` or `runAt`, `fixedBackoff`/`exponentialBackoff` throw for a non-finite or negative delay or a `jitter` outside [0, 1], and a backoff returning a non-finite delay dead-letters the job; `@nifrajs/mock` throws `UnsupportedMockSchemaError` for an `anyOf` whose every alternative contradicts the keywords beside it.",
|
|
31
|
+
"`RenderAdapter.renderToString` may return `undefined` for a render that suspended; the page is then streamed. A custom adapter keeps working unchanged; code that calls an adapter's `renderToString` itself has to handle `undefined`. Under `createCspPolicy`, a buffered page whose render writes a script of its own (a Solid `ErrorBoundary` that caught a server error) now carries a nonce and `cache-control: private, no-store`, like a deferred page.",
|
|
32
|
+
"A `@nifrajs/pi` turn whose provider refused Pi's sign-in or API key (an expired OAuth login, an incorrect key) now fails with code `PI_AUTH_REQUIRED` rather than `PI_MODEL_FAILED`, as `@nifrajs/acp` reports `ACP_AUTH_REQUIRED`. Code that matches `PI_MODEL_FAILED` to catch every failed model call has to match both.",
|
|
33
|
+
"A tool call through `executeTool` (`@nifrajs/core/tool-contract`) or an adapter built on it (the agent, MCP, WebMCP and HTTP tool adapters) whose executor throws or rejects keeps its idempotency key: a retry with the same key answers `idempotency_duplicate` rather than running the executor again, since the first attempt may have committed its effect. To retry a failure known to have committed nothing, call again with a new key.",
|
|
34
|
+
"`FileStorage` resolves the directory holding its root once and checks it before every operation: renaming an ancestor of the root now fails each operation with `StorageKeyError`, and a root reached through a symbolic link that is later repointed keeps the first tree until restart. Restart the process after moving a storage root.",
|
|
35
|
+
],
|
|
36
|
+
}
|
package/src/recipes/index.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Per-release upgrade recipes, as data. Each recipe declares the mechanical edits a target version
|
|
3
3
|
* needs - dependency pins and exact import-specifier moves - so `nifra upgrade <version>` can apply
|
|
4
4
|
* them deterministically. Recipes are static imports (they bundle) and keyed by target version.
|
|
5
|
+
*
|
|
6
|
+
* Every minor and major release has one, even with no edits: its notes are where a change an app can
|
|
7
|
+
* observe is announced to `nifra upgrade` and `--list`. `check:publish` fails a release without it.
|
|
5
8
|
*/
|
|
6
9
|
|
|
7
10
|
import { recipe as v1_8_0 } from "./1.8.0.ts"
|
|
@@ -9,6 +12,9 @@ import { recipe as v2_0_0 } from "./2.0.0.ts"
|
|
|
9
12
|
import { recipe as v3_0_0 } from "./3.0.0.ts"
|
|
10
13
|
import { recipe as v4_0_0 } from "./4.0.0.ts"
|
|
11
14
|
import { recipe as v5_0_0 } from "./5.0.0.ts"
|
|
15
|
+
import { recipe as v5_1_0 } from "./5.1.0.ts"
|
|
16
|
+
import { recipe as v5_2_0 } from "./5.2.0.ts"
|
|
17
|
+
import { recipe as v5_3_0 } from "./5.3.0.ts"
|
|
12
18
|
|
|
13
19
|
/** A pin rule: every dependency whose name starts with `match` is set to version `to`. */
|
|
14
20
|
export interface PinRule {
|
|
@@ -54,6 +60,9 @@ const RECIPES: Record<string, UpgradeRecipe> = {
|
|
|
54
60
|
[v3_0_0.version]: v3_0_0,
|
|
55
61
|
[v4_0_0.version]: v4_0_0,
|
|
56
62
|
[v5_0_0.version]: v5_0_0,
|
|
63
|
+
[v5_1_0.version]: v5_1_0,
|
|
64
|
+
[v5_2_0.version]: v5_2_0,
|
|
65
|
+
[v5_3_0.version]: v5_3_0,
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
export function getRecipe(version: string): UpgradeRecipe | undefined {
|
package/src/review.ts
CHANGED
|
@@ -154,8 +154,12 @@ export const CHECK_CODES: Readonly<Record<string, ReviewCheckId>> = {
|
|
|
154
154
|
"NF-C040": "route-boundary",
|
|
155
155
|
"NF-C041": "route-boundary",
|
|
156
156
|
"NF-C042": "route-boundary",
|
|
157
|
+
"NF-C043": "security",
|
|
158
|
+
"NF-C044": "route-boundary",
|
|
159
|
+
"NF-C045": "typed-client",
|
|
157
160
|
"NF-D001": "dependency",
|
|
158
161
|
"NF-D002": "dependency",
|
|
162
|
+
"NF-D003": "dependency",
|
|
159
163
|
"NF-A001": "route-assurance",
|
|
160
164
|
"NF-H001": "hydration",
|
|
161
165
|
"NF-H002": "hydration",
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `nifra explain NF-xxxx`: a rule code answered from the catalog, with no project read. The catalog
|
|
3
|
+
* loads only when a code is asked for, so the explain command's other paths never pay for it.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** The shape of a built-in rule code. A positional that matches it is a code, not an error message. */
|
|
7
|
+
export const RULE_CODE_SHAPE = /^NF-[A-Z]\d{3}$/
|
|
8
|
+
|
|
9
|
+
const DOCS_ORIGIN = "https://nifra.dev"
|
|
10
|
+
|
|
11
|
+
export interface RuleExplainOutput {
|
|
12
|
+
readonly kind: "rule"
|
|
13
|
+
readonly code: string
|
|
14
|
+
readonly title: string
|
|
15
|
+
/** The `nifra review` check it reports under. */
|
|
16
|
+
readonly category: string
|
|
17
|
+
/** What the rule reports and why it matters. */
|
|
18
|
+
readonly message: string
|
|
19
|
+
readonly fix: string
|
|
20
|
+
readonly command?: string
|
|
21
|
+
readonly docs: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface UnknownRuleOutput {
|
|
25
|
+
readonly code: "NIFRA_UNKNOWN_RULE"
|
|
26
|
+
readonly message: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function explainRule(code: string): Promise<RuleExplainOutput | UnknownRuleOutput> {
|
|
30
|
+
const [{ isBuiltInCode, RETIRED_CODES, RULE_CODES }, { RULE_EXPLANATIONS }, { CHECK_CODES }] =
|
|
31
|
+
await Promise.all([
|
|
32
|
+
import("./rules/codes.ts"),
|
|
33
|
+
import("./rules/explanations.ts"),
|
|
34
|
+
import("./review.ts"),
|
|
35
|
+
])
|
|
36
|
+
if (RETIRED_CODES.has(code))
|
|
37
|
+
return {
|
|
38
|
+
code: "NIFRA_UNKNOWN_RULE",
|
|
39
|
+
message: `${code} is retired: no rule reports it any more, and the code is never reused.`,
|
|
40
|
+
}
|
|
41
|
+
if (!isBuiltInCode(code) || !Object.hasOwn(RULE_CODES, code))
|
|
42
|
+
return {
|
|
43
|
+
code: "NIFRA_UNKNOWN_RULE",
|
|
44
|
+
message: `${code} is not a nifra rule code. \`nifra check --json\` lists each finding's code; \`nifra explain "<message>"\` explains an error instead.`,
|
|
45
|
+
}
|
|
46
|
+
const explanation = RULE_EXPLANATIONS[code]
|
|
47
|
+
const out: RuleExplainOutput = {
|
|
48
|
+
kind: "rule",
|
|
49
|
+
code,
|
|
50
|
+
title: RULE_CODES[code],
|
|
51
|
+
category: CHECK_CODES[code] ?? "configuration",
|
|
52
|
+
message: explanation.why,
|
|
53
|
+
fix: explanation.fix,
|
|
54
|
+
docs: `${DOCS_ORIGIN}${explanation.docs}`,
|
|
55
|
+
}
|
|
56
|
+
return explanation.command === undefined ? out : { ...out, command: explanation.command }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const isRuleExplanation = (value: unknown): value is RuleExplainOutput =>
|
|
60
|
+
typeof value === "object" &&
|
|
61
|
+
value !== null &&
|
|
62
|
+
Reflect.get(value, "kind") === "rule" &&
|
|
63
|
+
["code", "title", "category", "message", "fix", "docs"].every(
|
|
64
|
+
(key) => typeof Reflect.get(value, key) === "string",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
export function renderRuleExplanation(out: RuleExplainOutput): string[] {
|
|
68
|
+
return [
|
|
69
|
+
`${out.code} ${out.title} (${out.category})`,
|
|
70
|
+
` ${out.message}`,
|
|
71
|
+
` fix: ${out.fix}`,
|
|
72
|
+
...(out.command === undefined ? [] : [` run: ${out.command}`]),
|
|
73
|
+
` docs: ${out.docs}`,
|
|
74
|
+
]
|
|
75
|
+
}
|
package/src/rules/codes.ts
CHANGED
|
@@ -39,12 +39,16 @@ export const RULE_CODES = Object.freeze({
|
|
|
39
39
|
"NF-C040": "Layout meta reads data its layout never loads",
|
|
40
40
|
"NF-C041": "Server-only export in a route frontend file",
|
|
41
41
|
"NF-C042": "Layout loader refuses access without a gate",
|
|
42
|
+
"NF-C043": "Merged routes skip the parent's authentication",
|
|
43
|
+
"NF-C044": "createWebApp passes no copy chunks",
|
|
44
|
+
"NF-C045": "Route registered outside the typed chain",
|
|
42
45
|
"NF-C020": "Island enhancer cleanup check",
|
|
43
46
|
"NF-C021": "nano binding cleanup check",
|
|
44
47
|
"NF-C022": "nano bindList key check",
|
|
45
48
|
"NF-C023": "nano computed deps check",
|
|
46
49
|
"NF-D001": "Doctor check",
|
|
47
50
|
"NF-D002": "Mixed nifra versions",
|
|
51
|
+
"NF-D003": "Stale file: dependencies in bun.lock",
|
|
48
52
|
"NF-A001": "Assurance bundle check",
|
|
49
53
|
"NF-H001": "Hydration mismatch",
|
|
50
54
|
"NF-H002": "Duplicate framework runtime",
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* The served routes come from the backend the contract-lock check already loaded; this rule runs no
|
|
7
7
|
* project code of its own. Without a lock the backend is not loaded and the comparison is skipped.
|
|
8
|
+
* A contract imported from a workspace package is read through that package's `exports`.
|
|
9
|
+
* Re-exports on the way to a contract, and `...operations` spreads inside one, are followed.
|
|
8
10
|
*/
|
|
9
11
|
import { existsSync, readFileSync, realpathSync } from "node:fs"
|
|
10
12
|
import { join, relative } from "node:path"
|
|
@@ -13,6 +15,7 @@ import { BACKEND_APP_FILE } from "../app-files.ts"
|
|
|
13
15
|
import { type Diagnostic, diagnostic } from "../diagnostics.ts"
|
|
14
16
|
import { createSpecifierResolver, type SpecifierResolver } from "../internal/project-specifiers.ts"
|
|
15
17
|
import { scriptKindOf } from "../internal/script-kind.ts"
|
|
18
|
+
import { createExportedFileResolver } from "../internal/workspace-packages.ts"
|
|
16
19
|
import type { CheckRule } from "./index.ts"
|
|
17
20
|
import { loadRuleTypeScript } from "./typescript.ts"
|
|
18
21
|
|
|
@@ -126,14 +129,31 @@ function calls(
|
|
|
126
129
|
)
|
|
127
130
|
}
|
|
128
131
|
|
|
129
|
-
|
|
132
|
+
interface OperationsRead {
|
|
133
|
+
readonly operations: readonly Operation[]
|
|
134
|
+
readonly unreadable: readonly string[]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The operations an object literal of a contract declares, and what could not be read. `spreadOf`
|
|
138
|
+
* reads a `...name` spread of another operations object. */
|
|
130
139
|
function operationsOf(
|
|
131
140
|
ts: typeof TSApi,
|
|
132
141
|
literal: TSApi.ObjectLiteralExpression,
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
spreadOf: (name: string) => OperationsRead | undefined,
|
|
143
|
+
): OperationsRead {
|
|
144
|
+
// A later key replaces an earlier one, as in the object the page builds at runtime.
|
|
145
|
+
const operations = new Map<string, Operation>()
|
|
135
146
|
const unreadable: string[] = []
|
|
136
147
|
for (const property of literal.properties) {
|
|
148
|
+
if (ts.isSpreadAssignment(property)) {
|
|
149
|
+
const spread = unwrap(ts, property.expression)
|
|
150
|
+
const read = ts.isIdentifier(spread) ? spreadOf(spread.text) : undefined
|
|
151
|
+
if (read !== undefined) {
|
|
152
|
+
for (const op of read.operations) operations.set(op.name, op)
|
|
153
|
+
unreadable.push(...read.unreadable)
|
|
154
|
+
continue
|
|
155
|
+
}
|
|
156
|
+
}
|
|
137
157
|
if (!ts.isPropertyAssignment(property)) {
|
|
138
158
|
unreadable.push("an operation spread or written as a method")
|
|
139
159
|
continue
|
|
@@ -156,9 +176,9 @@ function operationsOf(
|
|
|
156
176
|
const path = field("path")
|
|
157
177
|
if (method === undefined || path === undefined)
|
|
158
178
|
unreadable.push(`operation "${name}" has a method or path that is not a string literal`)
|
|
159
|
-
else operations.
|
|
179
|
+
else operations.set(name, { name, method: method.toUpperCase(), path })
|
|
160
180
|
}
|
|
161
|
-
return { operations, unreadable }
|
|
181
|
+
return { operations: [...operations.values()], unreadable }
|
|
162
182
|
}
|
|
163
183
|
|
|
164
184
|
interface Parsed {
|
|
@@ -166,6 +186,13 @@ interface Parsed {
|
|
|
166
186
|
readonly bound: Bindings
|
|
167
187
|
}
|
|
168
188
|
|
|
189
|
+
/** An operations object literal and the file it is written in, which its spreads resolve against. */
|
|
190
|
+
interface Located {
|
|
191
|
+
readonly literal: TSApi.ObjectLiteralExpression
|
|
192
|
+
readonly file: string
|
|
193
|
+
readonly parsed: Parsed
|
|
194
|
+
}
|
|
195
|
+
|
|
169
196
|
export const contractVisibilityRule: CheckRule = {
|
|
170
197
|
code: "NF-C039",
|
|
171
198
|
title: "Implemented contract operation the backend does not serve",
|
|
@@ -192,7 +219,19 @@ export const contractVisibilityRule: CheckRule = {
|
|
|
192
219
|
const loaded = await loadRuleTypeScript(ctx)
|
|
193
220
|
const ts = loaded.compiler
|
|
194
221
|
if (ts === undefined) return []
|
|
195
|
-
const
|
|
222
|
+
const projectResolve = createSpecifierResolver()
|
|
223
|
+
const packageEntry = await createExportedFileResolver(ctx.root)
|
|
224
|
+
/** Why a package specifier could not be read, by importing file and specifier. */
|
|
225
|
+
const packageReasons = new Map<string, string>()
|
|
226
|
+
const resolve: SpecifierResolver = (from, specifier) => {
|
|
227
|
+
const local = projectResolve(from, specifier)
|
|
228
|
+
if (local !== undefined) return local
|
|
229
|
+
const entry = packageEntry(from, specifier)
|
|
230
|
+
if (entry === undefined) return undefined
|
|
231
|
+
if ("path" in entry) return entry.path
|
|
232
|
+
packageReasons.set(`${from}\0${specifier}`, entry.reason)
|
|
233
|
+
return undefined
|
|
234
|
+
}
|
|
196
235
|
// The resolver answers with real paths, so the root is read as one to name files project-relative.
|
|
197
236
|
const realRoot = (() => {
|
|
198
237
|
try {
|
|
@@ -217,20 +256,21 @@ export const contractVisibilityRule: CheckRule = {
|
|
|
217
256
|
return parsed
|
|
218
257
|
}
|
|
219
258
|
/** The object literal `defineContract({...})` gives the const `name` in `file`, followed one hop
|
|
220
|
-
* into a project module it is imported from. */
|
|
259
|
+
* into a project module it is imported from, and through any re-exports on the way. */
|
|
221
260
|
const contractLiteral = (
|
|
222
261
|
file: string,
|
|
223
262
|
parsed: Parsed,
|
|
224
263
|
name: string,
|
|
225
264
|
hops = 0,
|
|
226
|
-
|
|
265
|
+
seen = new Set<string>(),
|
|
266
|
+
): Located | undefined => {
|
|
227
267
|
for (const statement of parsed.tree.statements) {
|
|
228
268
|
if (!ts.isVariableStatement(statement)) continue
|
|
229
269
|
for (const declaration of statement.declarationList.declarations) {
|
|
230
270
|
if (!ts.isIdentifier(declaration.name) || declaration.name.text !== name) continue
|
|
231
271
|
if (declaration.initializer === undefined) return undefined
|
|
232
272
|
const init = unwrap(ts, declaration.initializer)
|
|
233
|
-
if (ts.isObjectLiteralExpression(init)) return init
|
|
273
|
+
if (ts.isObjectLiteralExpression(init)) return { literal: init, file, parsed }
|
|
234
274
|
if (
|
|
235
275
|
!ts.isCallExpression(init) ||
|
|
236
276
|
!calls(ts, init.expression, parsed.bound, "defineContract")
|
|
@@ -239,19 +279,66 @@ export const contractVisibilityRule: CheckRule = {
|
|
|
239
279
|
const arg = init.arguments[0]
|
|
240
280
|
const literal = arg === undefined ? undefined : unwrap(ts, arg)
|
|
241
281
|
return literal !== undefined && ts.isObjectLiteralExpression(literal)
|
|
242
|
-
? literal
|
|
282
|
+
? { literal, file, parsed }
|
|
243
283
|
: undefined
|
|
244
284
|
}
|
|
245
285
|
}
|
|
246
286
|
const from = parsed.bound.imported.get(name)
|
|
247
|
-
if (from
|
|
248
|
-
|
|
287
|
+
if (from !== undefined)
|
|
288
|
+
return hops > 0 ? undefined : follow(file, from.specifier, from.name, hops + 1, seen)
|
|
289
|
+
// A re-export declares nothing, so passing through one does not spend the hop.
|
|
290
|
+
for (const statement of parsed.tree.statements) {
|
|
291
|
+
if (
|
|
292
|
+
!ts.isExportDeclaration(statement) ||
|
|
293
|
+
statement.isTypeOnly ||
|
|
294
|
+
statement.moduleSpecifier === undefined ||
|
|
295
|
+
!ts.isStringLiteral(statement.moduleSpecifier)
|
|
296
|
+
)
|
|
297
|
+
continue
|
|
298
|
+
const clause = statement.exportClause
|
|
299
|
+
if (clause === undefined) {
|
|
300
|
+
const found = follow(file, statement.moduleSpecifier.text, name, hops, seen)
|
|
301
|
+
if (found !== undefined) return found
|
|
302
|
+
continue
|
|
303
|
+
}
|
|
304
|
+
if (!ts.isNamedExports(clause)) continue
|
|
305
|
+
const element = clause.elements.find((e) => !e.isTypeOnly && e.name.text === name)
|
|
306
|
+
if (element !== undefined)
|
|
307
|
+
return follow(
|
|
308
|
+
file,
|
|
309
|
+
statement.moduleSpecifier.text,
|
|
310
|
+
(element.propertyName ?? element.name).text,
|
|
311
|
+
hops,
|
|
312
|
+
seen,
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
return undefined
|
|
316
|
+
}
|
|
317
|
+
const follow = (
|
|
318
|
+
file: string,
|
|
319
|
+
specifier: string,
|
|
320
|
+
name: string,
|
|
321
|
+
hops: number,
|
|
322
|
+
seen: Set<string>,
|
|
323
|
+
): Located | undefined => {
|
|
324
|
+
const target = resolve(join(ctx.root, file), specifier)
|
|
249
325
|
if (target === undefined) return undefined
|
|
250
326
|
const rel = relative(realRoot, target).replaceAll("\\", "/")
|
|
327
|
+
const key = `${rel}\0${name}`
|
|
328
|
+
if (seen.has(key)) return undefined
|
|
329
|
+
seen.add(key)
|
|
251
330
|
const next = parse(rel, readText(target))
|
|
252
|
-
return next === undefined ? undefined : contractLiteral(rel, next,
|
|
331
|
+
return next === undefined ? undefined : contractLiteral(rel, next, name, hops, seen)
|
|
253
332
|
}
|
|
254
333
|
|
|
334
|
+
// Each spread is looked up afresh from the file it is written in; the depth only stops a cycle.
|
|
335
|
+
const readOperations = (found: Located, depth = 0): OperationsRead =>
|
|
336
|
+
operationsOf(ts, found.literal, (name) => {
|
|
337
|
+
if (depth >= 8) return undefined
|
|
338
|
+
const inner = contractLiteral(found.file, found.parsed, name)
|
|
339
|
+
return inner === undefined ? undefined : readOperations(inner, depth + 1)
|
|
340
|
+
})
|
|
341
|
+
|
|
255
342
|
const implementations: Implementation[] = []
|
|
256
343
|
for (const file of candidates) {
|
|
257
344
|
const parsed = parse(file, ctx.sources.read(file))
|
|
@@ -264,12 +351,12 @@ export const contractVisibilityRule: CheckRule = {
|
|
|
264
351
|
if (ts.isCallExpression(node) && calls(ts, node.expression, parsed.bound, "implement")) {
|
|
265
352
|
const line = parsed.tree.getLineAndCharacterOfPosition(node.getStart()).line + 1
|
|
266
353
|
const arg = node.arguments[0] === undefined ? undefined : unwrap(ts, node.arguments[0])
|
|
267
|
-
let
|
|
354
|
+
let located: Located | undefined
|
|
268
355
|
let contract = arg?.getText() ?? "(none)"
|
|
269
356
|
if (arg !== undefined && ts.isIdentifier(arg))
|
|
270
|
-
|
|
357
|
+
located = contractLiteral(file, parsed, arg.text)
|
|
271
358
|
else if (arg !== undefined && ts.isObjectLiteralExpression(arg)) {
|
|
272
|
-
|
|
359
|
+
located = { literal: arg, file, parsed }
|
|
273
360
|
contract = "an inline contract"
|
|
274
361
|
} else if (
|
|
275
362
|
arg !== undefined &&
|
|
@@ -277,20 +364,31 @@ export const contractVisibilityRule: CheckRule = {
|
|
|
277
364
|
calls(ts, arg.expression, parsed.bound, "defineContract")
|
|
278
365
|
) {
|
|
279
366
|
const inner = arg.arguments[0] === undefined ? undefined : unwrap(ts, arg.arguments[0])
|
|
280
|
-
if (inner !== undefined && ts.isObjectLiteralExpression(inner))
|
|
367
|
+
if (inner !== undefined && ts.isObjectLiteralExpression(inner))
|
|
368
|
+
located = { literal: inner, file, parsed }
|
|
281
369
|
contract = "an inline contract"
|
|
282
370
|
}
|
|
283
|
-
if (
|
|
371
|
+
if (located === undefined) {
|
|
372
|
+
const from =
|
|
373
|
+
arg !== undefined && ts.isIdentifier(arg)
|
|
374
|
+
? parsed.bound.imported.get(arg.text)?.specifier
|
|
375
|
+
: undefined
|
|
376
|
+
const reason =
|
|
377
|
+
from === undefined
|
|
378
|
+
? undefined
|
|
379
|
+
: packageReasons.get(`${join(ctx.root, file)}\0${from}`)
|
|
284
380
|
implementations.push({
|
|
285
381
|
file,
|
|
286
382
|
line,
|
|
287
383
|
contract,
|
|
288
384
|
operations: [],
|
|
289
385
|
unreadable: [
|
|
290
|
-
|
|
386
|
+
reason === undefined
|
|
387
|
+
? `the contract ${contract} is not a defineContract({...}) the scan can read`
|
|
388
|
+
: `the contract ${contract} is imported from "${from}", which the scan cannot read: ${reason}`,
|
|
291
389
|
],
|
|
292
390
|
})
|
|
293
|
-
} else implementations.push({ file, line, contract, ...
|
|
391
|
+
} else implementations.push({ file, line, contract, ...readOperations(located) })
|
|
294
392
|
}
|
|
295
393
|
ts.forEachChild(node, visit)
|
|
296
394
|
}
|