@nifrajs/cli 5.12.0 → 5.13.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 +61 -0
- package/dist/cli.d.ts +9 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +140 -19
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +29 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +102 -4
- package/dist/command-catalog.js.map +1 -1
- package/dist/deployment-adapters.d.ts +12 -0
- package/dist/deployment-adapters.d.ts.map +1 -0
- package/dist/deployment-adapters.js +92 -0
- package/dist/deployment-adapters.js.map +1 -0
- package/dist/dev-bun-config.d.ts +4 -3
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +14 -4
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/init-agents.d.ts +5 -0
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +1 -1
- package/dist/init-agents.js.map +1 -1
- package/dist/load.d.ts +12 -3
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +19 -0
- package/dist/load.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +21 -3
- package/dist/mcp-root.js.map +1 -1
- package/dist/port.d.ts +6 -3
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +19 -7
- package/dist/port.js.map +1 -1
- package/dist/recipes/5.13.0.d.ts +9 -0
- package/dist/recipes/5.13.0.d.ts.map +1 -0
- package/dist/recipes/5.13.0.js +40 -0
- package/dist/recipes/5.13.0.js.map +1 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +2 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/rules/routes.js +2 -2
- package/dist/shell-files.d.ts +44 -0
- package/dist/shell-files.d.ts.map +1 -0
- package/dist/shell-files.js +201 -0
- package/dist/shell-files.js.map +1 -0
- package/dist/shell-init.d.ts +33 -0
- package/dist/shell-init.d.ts.map +1 -0
- package/dist/shell-init.js +99 -0
- package/dist/shell-init.js.map +1 -0
- package/docs/examples.json +97 -1
- package/docs/llms-full.txt +989 -40
- package/docs/types.json +606 -36
- package/package.json +11 -11
- package/src/cli.ts +185 -35
- package/src/command-catalog.ts +144 -7
- package/src/deployment-adapters.ts +107 -0
- package/src/dev-bun-config.ts +21 -2
- package/src/init-agents.ts +1 -1
- package/src/load.ts +36 -3
- package/src/mcp-http.ts +1 -1
- package/src/mcp-root.ts +21 -3
- package/src/port.ts +25 -8
- package/src/recipes/5.13.0.ts +41 -0
- package/src/recipes/index.ts +2 -0
- package/src/rules/routes.ts +2 -2
- package/src/shell-files.ts +225 -0
- package/src/shell-init.ts +139 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
2
|
+
import { dirname, resolve } from "node:path"
|
|
3
|
+
|
|
4
|
+
const BASE_TARGETS = new Set(["bun", "node", "deno", "cloudflare", "vercel", "static"])
|
|
5
|
+
const PACKAGE_NAME = /^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/i
|
|
6
|
+
|
|
7
|
+
const DEPENDENCY_FIELDS = [
|
|
8
|
+
"dependencies",
|
|
9
|
+
"devDependencies",
|
|
10
|
+
"optionalDependencies",
|
|
11
|
+
"peerDependencies",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
const isBaseTarget = (value: unknown): value is DeploymentAdapterMetadata["baseTarget"] =>
|
|
15
|
+
typeof value === "string" && BASE_TARGETS.has(value)
|
|
16
|
+
|
|
17
|
+
export interface DeploymentAdapterMetadata {
|
|
18
|
+
readonly apiVersion: 1
|
|
19
|
+
readonly id: string
|
|
20
|
+
readonly baseTarget: "bun" | "node" | "deno" | "cloudflare" | "vercel" | "static"
|
|
21
|
+
readonly packageName: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Parse package JSON as a record and treat unreadable or malformed manifests as absent. */
|
|
25
|
+
function readRecord(path: string): Record<string, unknown> | undefined {
|
|
26
|
+
try {
|
|
27
|
+
const value: unknown = JSON.parse(readFileSync(path, "utf8"))
|
|
28
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
29
|
+
? // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: JSON.parse is assigned to unknown and the object/null/array checks above establish the record shape.
|
|
30
|
+
(value as Record<string, unknown>)
|
|
31
|
+
: undefined
|
|
32
|
+
} catch {
|
|
33
|
+
return undefined
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Read only package metadata, never importing app config or adapter code. `nifra port` uses this to
|
|
39
|
+
* map a custom target id to the built-in runtime its adapter wraps.
|
|
40
|
+
*/
|
|
41
|
+
export function readDeploymentAdapterMetadata(
|
|
42
|
+
appRoot: string,
|
|
43
|
+
id: string,
|
|
44
|
+
): DeploymentAdapterMetadata | undefined {
|
|
45
|
+
const packageRoots: string[] = []
|
|
46
|
+
let directory = resolve(appRoot)
|
|
47
|
+
for (;;) {
|
|
48
|
+
packageRoots.push(directory)
|
|
49
|
+
const parent = dirname(directory)
|
|
50
|
+
if (parent === directory) break
|
|
51
|
+
directory = parent
|
|
52
|
+
}
|
|
53
|
+
// A workspace root can declare the adapter for an app package that does not repeat it.
|
|
54
|
+
const dependencyNames = new Set<string>()
|
|
55
|
+
for (const packageRoot of packageRoots) {
|
|
56
|
+
const manifest = readRecord(resolve(packageRoot, "package.json"))
|
|
57
|
+
if (manifest === undefined) continue
|
|
58
|
+
for (const field of DEPENDENCY_FIELDS) {
|
|
59
|
+
const dependencies = manifest[field]
|
|
60
|
+
if (typeof dependencies !== "object" || dependencies === null || Array.isArray(dependencies))
|
|
61
|
+
continue
|
|
62
|
+
for (const name of Object.keys(dependencies))
|
|
63
|
+
if (PACKAGE_NAME.test(name)) dependencyNames.add(name)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const matches: DeploymentAdapterMetadata[] = []
|
|
67
|
+
for (const packageName of dependencyNames) {
|
|
68
|
+
for (const packageRoot of packageRoots) {
|
|
69
|
+
const manifestPath = resolve(packageRoot, "node_modules", packageName, "package.json")
|
|
70
|
+
if (!existsSync(manifestPath)) continue
|
|
71
|
+
const manifest = readRecord(manifestPath)
|
|
72
|
+
const nifra = manifest?.nifra
|
|
73
|
+
const declaration =
|
|
74
|
+
typeof nifra === "object" && nifra !== null && !Array.isArray(nifra)
|
|
75
|
+
? Reflect.get(nifra, "deploymentAdapter")
|
|
76
|
+
: undefined
|
|
77
|
+
if (typeof declaration !== "object" || declaration === null || Array.isArray(declaration))
|
|
78
|
+
break
|
|
79
|
+
const apiVersion: unknown = Reflect.get(declaration, "apiVersion")
|
|
80
|
+
const adapterId: unknown = Reflect.get(declaration, "id")
|
|
81
|
+
const baseTarget: unknown = Reflect.get(declaration, "baseTarget")
|
|
82
|
+
if (
|
|
83
|
+
apiVersion === 1 &&
|
|
84
|
+
adapterId === id &&
|
|
85
|
+
typeof adapterId === "string" &&
|
|
86
|
+
/^[a-z][a-z0-9-]{1,62}$/.test(adapterId) &&
|
|
87
|
+
isBaseTarget(baseTarget)
|
|
88
|
+
) {
|
|
89
|
+
matches.push({
|
|
90
|
+
apiVersion,
|
|
91
|
+
id: adapterId,
|
|
92
|
+
baseTarget,
|
|
93
|
+
packageName,
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
break
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (matches.length > 1) {
|
|
100
|
+
const targets = new Set(matches.map((match) => match.baseTarget))
|
|
101
|
+
if (targets.size > 1)
|
|
102
|
+
throw new Error(
|
|
103
|
+
`[nifra] multiple installed adapters declare target "${id}" with different base targets`,
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
return matches[0]
|
|
107
|
+
}
|
package/src/dev-bun-config.ts
CHANGED
|
@@ -154,6 +154,7 @@ export function renderDevBunfig(
|
|
|
154
154
|
user: BunfigData,
|
|
155
155
|
appRoot: string,
|
|
156
156
|
define: Readonly<Record<string, string>> = {},
|
|
157
|
+
clientDefine: Readonly<Record<string, string>> = {},
|
|
157
158
|
): string {
|
|
158
159
|
const data: BunfigData = structuredClone(user)
|
|
159
160
|
if (data.preload !== undefined) {
|
|
@@ -165,6 +166,22 @@ export function renderDevBunfig(
|
|
|
165
166
|
const serveStatic = isTable(serve.static) ? serve.static : {}
|
|
166
167
|
serve.static = serveStatic
|
|
167
168
|
serveStatic.plugins = [boundaryPluginPath]
|
|
169
|
+
if (Object.keys(clientDefine).length > 0) {
|
|
170
|
+
// Client only, as `nifra build` bakes the public environment into the client bundle alone. The
|
|
171
|
+
// app's own bunfig defines beat it, the top-level one too (SSR reads it, so the client must agree),
|
|
172
|
+
// and the config's `define` below beats both.
|
|
173
|
+
const own = isTable(data.define) ? data.define : {}
|
|
174
|
+
const fromEnv = Object.fromEntries(
|
|
175
|
+
Object.entries(clientDefine).filter(([key]) => !(key in own)),
|
|
176
|
+
)
|
|
177
|
+
const shared = Object.fromEntries(Object.entries(own).filter(([key]) => key in clientDefine))
|
|
178
|
+
serveStatic.define = Object.assign(
|
|
179
|
+
{},
|
|
180
|
+
fromEnv,
|
|
181
|
+
shared,
|
|
182
|
+
isTable(serveStatic.define) ? serveStatic.define : {},
|
|
183
|
+
)
|
|
184
|
+
}
|
|
168
185
|
if (Object.keys(define).length > 0) {
|
|
169
186
|
for (const [key, value] of Object.entries(define)) {
|
|
170
187
|
if (typeof value !== "string") {
|
|
@@ -310,12 +327,14 @@ const TOKEN_FILE = "launch-token"
|
|
|
310
327
|
/** Write the generated config for an app; returns the bunfig path to re-exec with and the fresh
|
|
311
328
|
* launch token to pass in the child's environment. `configPath` (the app's `nifra.config.ts` /
|
|
312
329
|
* `backend/framework.ts`) is what lets the app's own `clientPlugins` reach Bun's dev-server
|
|
313
|
-
* bundler; `define` and `publicEnvPrefix` are the loaded config's own.
|
|
330
|
+
* bundler; `define` and `publicEnvPrefix` are the loaded config's own. `clientDefine` is what only the
|
|
331
|
+
* client bundle gets: the public environment, which `nifra build` inlines and Bun's dev bundler does not. */
|
|
314
332
|
export async function writeBunDevConfig(
|
|
315
333
|
appRoot: string,
|
|
316
334
|
configPath?: string,
|
|
317
335
|
define?: Readonly<Record<string, string>>,
|
|
318
336
|
publicEnvPrefix?: string,
|
|
337
|
+
clientDefine?: Readonly<Record<string, string>>,
|
|
319
338
|
): Promise<BunDevConfig> {
|
|
320
339
|
const dir = resolve(appRoot, ".nifra", "dev-bun")
|
|
321
340
|
mkdirSync(dir, { recursive: true })
|
|
@@ -335,7 +354,7 @@ export async function writeBunDevConfig(
|
|
|
335
354
|
),
|
|
336
355
|
)
|
|
337
356
|
const bunfigPath = resolve(dir, "bunfig.toml")
|
|
338
|
-
writeFileSync(bunfigPath, renderDevBunfig(pluginPath, user, appRoot, define))
|
|
357
|
+
writeFileSync(bunfigPath, renderDevBunfig(pluginPath, user, appRoot, define, clientDefine))
|
|
339
358
|
const launchToken = crypto.randomUUID()
|
|
340
359
|
writeFileSync(resolve(dir, TOKEN_FILE), launchToken)
|
|
341
360
|
return { bunfigPath, launchToken }
|
package/src/init-agents.ts
CHANGED
|
@@ -141,7 +141,7 @@ async function nonRegularTarget(
|
|
|
141
141
|
* Write a whole-file generator's output to `path` unless it already exists and `force` is false.
|
|
142
142
|
* Returns the per-file result for the report.
|
|
143
143
|
*/
|
|
144
|
-
async function writeOwned(
|
|
144
|
+
export async function writeOwned(
|
|
145
145
|
cwd: string,
|
|
146
146
|
rel: string,
|
|
147
147
|
content: string,
|
package/src/load.ts
CHANGED
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
import { existsSync } from "node:fs"
|
|
17
17
|
import { isAbsolute, resolve } from "node:path"
|
|
18
18
|
import type { CreateWebAppOptions, CssLoadingMode } from "@nifrajs/web"
|
|
19
|
-
import type {
|
|
19
|
+
import type {
|
|
20
|
+
DeploymentTargetAdapter,
|
|
21
|
+
SecretExemption,
|
|
22
|
+
ServerEntrySelfHost,
|
|
23
|
+
} from "@nifrajs/web/build"
|
|
20
24
|
import { assertCurrentLayout, BACKEND_APP_FILE, CONFIG_FILE, FRAMEWORK_FILE } from "./app-files.ts"
|
|
21
25
|
import { checkPipelineSeparation } from "./pipeline-guard.ts"
|
|
22
26
|
|
|
@@ -68,9 +72,14 @@ export interface NifraFramework {
|
|
|
68
72
|
readonly conditions?: readonly string[]
|
|
69
73
|
/** Compile-time `define` replacements, e.g. Vue's `__VUE_*` flags. */
|
|
70
74
|
readonly define?: Readonly<Record<string, string>>
|
|
71
|
-
/** The
|
|
72
|
-
* rewrites it. */
|
|
75
|
+
/** The built-in target or configured adapter id `nifra build` emits without `--target` (default `"bun"`);
|
|
76
|
+
* `nifra target <t>` rewrites it. */
|
|
73
77
|
readonly target?: string
|
|
78
|
+
/** Optional public build-time host adapter. Its code runs in this CLI process during builds. */
|
|
79
|
+
readonly deploymentAdapter?: {
|
|
80
|
+
readonly adapter: DeploymentTargetAdapter
|
|
81
|
+
readonly options?: unknown
|
|
82
|
+
}
|
|
74
83
|
/** Ordinary Vercel SSR: Edge by default, or opt into a Node.js 22 serverless handler. */
|
|
75
84
|
readonly vercelRuntime?: "edge" | "node"
|
|
76
85
|
/** `"platform"` makes a `cloudflare` / `vercel` build read `c.clientIp` from the header that
|
|
@@ -98,6 +107,10 @@ export interface NifraFramework {
|
|
|
98
107
|
/** Reviewed false positives of `nifra build`'s secret scan. A `file` scope applies throughout that
|
|
99
108
|
* file; for `private-env-value`, an `env` scope applies to every finding from that variable. */
|
|
100
109
|
readonly secretExemptions?: readonly SecretExemption[]
|
|
110
|
+
/** A module, relative to the app, whose default export is the `fetch` the client reaches its server
|
|
111
|
+
* through, such as `serverFetch({ origin })` from `@nifrajs/web/client`. For a build that ships
|
|
112
|
+
* inside a native shell while the server lives elsewhere. */
|
|
113
|
+
readonly transport?: string
|
|
101
114
|
/** Vite production CSS output policy. `false` emits one aggregate stylesheet for the whole client. */
|
|
102
115
|
readonly cssCodeSplit?: boolean
|
|
103
116
|
/** Framework-owned SSR stylesheet activation. Deferred mode is intended for aggregate CSS. */
|
|
@@ -232,9 +245,29 @@ function assertFrameworkWebOptions(fw: Partial<NifraFramework>, configFile: stri
|
|
|
232
245
|
'an array of { rule, file, reason } entries (or { rule: "private-env-value", env, reason })',
|
|
233
246
|
)
|
|
234
247
|
}
|
|
248
|
+
if (fw.transport !== undefined && (typeof fw.transport !== "string" || fw.transport === "")) {
|
|
249
|
+
wrong("transport", 'a module path such as "./shell/transport.ts"')
|
|
250
|
+
}
|
|
235
251
|
if (fw.target !== undefined && typeof fw.target !== "string") {
|
|
236
252
|
wrong("target", 'a deploy target name such as "bun"')
|
|
237
253
|
}
|
|
254
|
+
if (fw.deploymentAdapter !== undefined) {
|
|
255
|
+
const configured: unknown = fw.deploymentAdapter
|
|
256
|
+
if (typeof configured !== "object" || configured === null) {
|
|
257
|
+
wrong("deploymentAdapter", "an object with { adapter, options? }")
|
|
258
|
+
} else {
|
|
259
|
+
const adapter: unknown = Reflect.get(configured, "adapter")
|
|
260
|
+
if (
|
|
261
|
+
typeof adapter !== "object" ||
|
|
262
|
+
adapter === null ||
|
|
263
|
+
typeof Reflect.get(adapter, "id") !== "string" ||
|
|
264
|
+
typeof Reflect.get(adapter, "baseTarget") !== "string" ||
|
|
265
|
+
typeof Reflect.get(adapter, "validateOptions") !== "function" ||
|
|
266
|
+
typeof Reflect.get(adapter, "emit") !== "function"
|
|
267
|
+
)
|
|
268
|
+
wrong("deploymentAdapter.adapter", "a public deployment adapter from @nifrajs/web/build")
|
|
269
|
+
}
|
|
270
|
+
}
|
|
238
271
|
if (
|
|
239
272
|
fw.vercelRuntime !== undefined &&
|
|
240
273
|
fw.vercelRuntime !== "edge" &&
|
package/src/mcp-http.ts
CHANGED
|
@@ -30,7 +30,7 @@ export { docsTools } from "./mcp-docs-tools.ts"
|
|
|
30
30
|
export type { TypeEntry } from "./types-search.ts"
|
|
31
31
|
|
|
32
32
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
33
|
-
const VERSION = "5.
|
|
33
|
+
const VERSION = "5.13.0"
|
|
34
34
|
const SERVER_INFO = { name: "nifra-docs", version: VERSION }
|
|
35
35
|
// Derive the GET/health tool list from the tools actually served, so the line can never drift from them.
|
|
36
36
|
const docsHealth = (tools: McpTool[]): string =>
|
package/src/mcp-root.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* Everything here is pure state + fs probes; the I/O wiring lives in `./mcp.ts`.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import { readdir, readFile, stat } from "node:fs/promises"
|
|
20
|
+
import { readdir, readFile, realpath, stat } from "node:fs/promises"
|
|
21
21
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path"
|
|
22
22
|
import { fileURLToPath } from "node:url"
|
|
23
23
|
|
|
@@ -100,10 +100,27 @@ async function workspacePatterns(dir: string): Promise<readonly string[] | null>
|
|
|
100
100
|
if (!Array.isArray(list)) return null
|
|
101
101
|
return list.filter(
|
|
102
102
|
(pattern): pattern is string =>
|
|
103
|
-
typeof pattern === "string" &&
|
|
103
|
+
typeof pattern === "string" &&
|
|
104
|
+
pattern !== "" &&
|
|
105
|
+
!pattern.startsWith("!") &&
|
|
106
|
+
!patternLeavesRoot(pattern),
|
|
104
107
|
)
|
|
105
108
|
}
|
|
106
109
|
|
|
110
|
+
/** An absolute pattern or one with a `..` segment names a directory outside the workspace root, so
|
|
111
|
+
* a manifest could otherwise make the server adopt a neighbouring project. */
|
|
112
|
+
function patternLeavesRoot(pattern: string): boolean {
|
|
113
|
+
return isAbsolute(pattern) || pattern.split(/[\\/]/).includes("..")
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Whether `member` resolves, symlinks followed, to somewhere inside `rootReal`. */
|
|
117
|
+
async function insideRoot(rootReal: string, member: string): Promise<boolean> {
|
|
118
|
+
const real = await realpath(member).catch(() => null)
|
|
119
|
+
if (real === null) return false
|
|
120
|
+
const rel = relative(rootReal, real)
|
|
121
|
+
return rel !== "" && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)
|
|
122
|
+
}
|
|
123
|
+
|
|
107
124
|
/**
|
|
108
125
|
* The directories under `dir` that `pattern` matches and that hold a `package.json`, in name order. A
|
|
109
126
|
* walk rather than a glob scan: a `**` pattern would otherwise descend every `node_modules` below it,
|
|
@@ -165,10 +182,11 @@ export async function workspaceMemberDirs(dir: string): Promise<string[] | null>
|
|
|
165
182
|
if (patterns === null) return null
|
|
166
183
|
const members = new Set<string>()
|
|
167
184
|
const budget = { directories: MAX_WORKSPACE_DIRECTORIES }
|
|
185
|
+
const rootReal = await realpath(dir).catch(() => dir)
|
|
168
186
|
for (const pattern of patterns) {
|
|
169
187
|
for (const member of await workspaceMatches(dir, pattern, budget)) {
|
|
170
188
|
if (members.size === MAX_WORKSPACE_MEMBERS) break
|
|
171
|
-
members.add(join(dir, member))
|
|
189
|
+
if (await insideRoot(rootReal, join(dir, member))) members.add(join(dir, member))
|
|
172
190
|
}
|
|
173
191
|
}
|
|
174
192
|
return [...members]
|
package/src/port.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { join } from "node:path"
|
|
|
18
18
|
import { Glob } from "bun"
|
|
19
19
|
import { stripComments } from "./check.ts"
|
|
20
20
|
import { readConfigTarget } from "./config-target.ts"
|
|
21
|
+
import { readDeploymentAdapterMetadata } from "./deployment-adapters.ts"
|
|
21
22
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
22
23
|
import { lineAt } from "./internal/line-at.ts"
|
|
23
24
|
|
|
@@ -357,10 +358,13 @@ export async function detectFeatures(cwd: string): Promise<DetectedFeature[]> {
|
|
|
357
358
|
|
|
358
359
|
export interface ResolvedTarget {
|
|
359
360
|
readonly target: Target
|
|
361
|
+
/** The custom deployment key when its package declares the wrapped runtime statically. */
|
|
362
|
+
readonly adapterId?: string
|
|
360
363
|
/** How the target was determined - surfaced so the report explains itself. */
|
|
361
364
|
readonly source:
|
|
362
365
|
| "flag"
|
|
363
366
|
| "config"
|
|
367
|
+
| "adapter"
|
|
364
368
|
| "package-json-build"
|
|
365
369
|
| "package-json-deploy"
|
|
366
370
|
| "wrangler"
|
|
@@ -390,25 +394,32 @@ interface PackageJsonScripts {
|
|
|
390
394
|
* Resolve the app's deploy target. `--target` (validated) always wins, then the `target` that
|
|
391
395
|
* `nifra.config.ts` exports. Otherwise infer it, in priority order, from: the canonical `build` script
|
|
392
396
|
* (an older create-nifra's `build-<target>.ts`), the `deploy` script
|
|
393
|
-
* (the vendor CLI it shells out to), a `wrangler.toml` (Cloudflare Pages),
|
|
394
|
-
* `undefined` when nothing signals a target (the matrix still prints; CI
|
|
397
|
+
* (the vendor CLI it shells out to), a `wrangler.toml` (Cloudflare Pages), a `vercel.json`, or installed
|
|
398
|
+
* adapter metadata. Returns `undefined` when nothing signals a target (the matrix still prints; CI
|
|
399
|
+
* gating needs an explicit one).
|
|
395
400
|
*/
|
|
396
401
|
export async function resolveTarget(
|
|
397
402
|
cwd: string,
|
|
398
403
|
override?: string,
|
|
399
404
|
): Promise<ResolvedTarget | undefined> {
|
|
400
|
-
|
|
401
|
-
|
|
405
|
+
/** Map a built-in target directly or a custom adapter ID to its declared runtime. */
|
|
406
|
+
const checked = (value: string, label: string): ResolvedTarget => {
|
|
407
|
+
if (isTarget(value)) return { target: value, source: label === "--target" ? "flag" : "config" }
|
|
408
|
+
const metadata = readDeploymentAdapterMetadata(cwd, value)
|
|
409
|
+
if (metadata !== undefined && metadata.baseTarget !== "static")
|
|
410
|
+
return { target: metadata.baseTarget, source: "adapter", adapterId: metadata.id }
|
|
402
411
|
throw new Error(
|
|
403
412
|
value === "cf-pages"
|
|
404
413
|
? `[nifra] the ${label} "cf-pages" is now "cloudflare"`
|
|
405
|
-
:
|
|
414
|
+
: metadata?.baseTarget === "static"
|
|
415
|
+
? `[nifra] ${label} "${value}" is a static adapter; nifra port checks runtime targets (${TARGETS.join(", ")})`
|
|
416
|
+
: `[nifra] invalid ${label} "${value}". options: ${TARGETS.join(", ")} or an installed deployment adapter with Nifra metadata`,
|
|
406
417
|
)
|
|
407
418
|
}
|
|
408
|
-
if (override !== undefined) return
|
|
419
|
+
if (override !== undefined) return checked(override, "--target")
|
|
409
420
|
const configured = readConfigTarget(cwd)
|
|
410
421
|
if (configured !== undefined && configured !== "static") {
|
|
411
|
-
return
|
|
422
|
+
return checked(configured, "target in nifra.config.ts")
|
|
412
423
|
}
|
|
413
424
|
|
|
414
425
|
const pkg = await readJson<PackageJsonScripts>(join(cwd, "package.json"))
|
|
@@ -546,7 +557,11 @@ export function renderReport(result: PortResult, opts: { readonly strict?: boole
|
|
|
546
557
|
const out: string[] = ["nifra port - portability matrix", ""]
|
|
547
558
|
|
|
548
559
|
if (resolved !== undefined) {
|
|
549
|
-
out.push(
|
|
560
|
+
out.push(
|
|
561
|
+
resolved.adapterId === undefined
|
|
562
|
+
? `target: ${resolved.target} (detected from ${describeSource(resolved.source)})`
|
|
563
|
+
: `target: ${resolved.adapterId} (base runtime ${resolved.target}; detected from ${describeSource(resolved.source)})`,
|
|
564
|
+
)
|
|
550
565
|
} else {
|
|
551
566
|
out.push(
|
|
552
567
|
"target: not detected - pass --target <bun|node|deno|cloudflare|vercel> to gate against one",
|
|
@@ -631,6 +646,8 @@ function describeSource(source: ResolvedTarget["source"]): string {
|
|
|
631
646
|
return "--target"
|
|
632
647
|
case "config":
|
|
633
648
|
return "nifra.config.ts"
|
|
649
|
+
case "adapter":
|
|
650
|
+
return "installed adapter package metadata"
|
|
634
651
|
case "package-json-build":
|
|
635
652
|
return "the package.json build script"
|
|
636
653
|
case "package-json-deploy":
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { UpgradeRecipe } from "./index.ts"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Upgrade recipe for Nifra 5.13.
|
|
5
|
+
*
|
|
6
|
+
* This release has no import or dependency moves. Its notes cover the stricter cross-site form
|
|
7
|
+
* policy, the native-shell transport, and the handle and idempotency changes.
|
|
8
|
+
*/
|
|
9
|
+
export const recipe: UpgradeRecipe = {
|
|
10
|
+
version: "5.13.0",
|
|
11
|
+
pins: [
|
|
12
|
+
{ match: "@nifrajs/", to: "5.13.0" },
|
|
13
|
+
{ match: "create-nifra", to: "5.13.0" },
|
|
14
|
+
{ match: "nifra", to: "5.13.0" },
|
|
15
|
+
],
|
|
16
|
+
importMoves: [],
|
|
17
|
+
affects: [
|
|
18
|
+
"@nifrajs/cli",
|
|
19
|
+
"@nifrajs/client",
|
|
20
|
+
"@nifrajs/core",
|
|
21
|
+
"@nifrajs/cron",
|
|
22
|
+
"@nifrajs/deno",
|
|
23
|
+
"@nifrajs/edge",
|
|
24
|
+
"@nifrajs/image",
|
|
25
|
+
"@nifrajs/jobs",
|
|
26
|
+
"@nifrajs/middleware",
|
|
27
|
+
"@nifrajs/node",
|
|
28
|
+
"@nifrajs/web",
|
|
29
|
+
"create-nifra",
|
|
30
|
+
],
|
|
31
|
+
notes: [
|
|
32
|
+
"A route without a body schema now refuses a cross-site HTML form post, and an unsafe request with no content type from an untrusted site, with `403 forbidden_origin` before the handler runs, on every lane including Bun's native route table and `@nifrajs/edge`. An app that handles CORS outside Nifra, such as a reverse proxy adding the headers, and takes bodyless cross-origin `POST`, `PUT`, `PATCH` or `DELETE` calls without an `Authorization` header needs that frontend's origin in `formOrigins`.",
|
|
33
|
+
"The origins a `cors()` list or predicate and a `csrf({ origins })` list name are now trusted for form posts, so those frontends need no second copy in `formOrigins`. Audit those origins: a named origin may now also post a form to the routes of the server that installs the middleware.",
|
|
34
|
+
"A route's `allowedOrigins` function receives, as its second argument, whether the default same-origin check would admit the request.",
|
|
35
|
+
"`createClientRouter` takes a `fetch` option and a build takes a `transport` module, so a page inside a native shell can reach its server on another origin. `nifra shell tauri` and `create-nifra --shell tauri` scaffold a Tauri 2 shell; `nifra build --target static --prerender <paths>` prerenders the pages a shell build opens on.",
|
|
36
|
+
"Standalone idempotency response serialization and replay, and in-process client response decoding, are bounded to 1 MB by default. Set `maxBytes` or a route's `maxResponseBytes` to change the limit.",
|
|
37
|
+
"Bun `listen()` handles, Node and Deno `serve()` handles, jobs workers, cron schedulers, client subscriptions and client WebSockets can be held with `await using` or `using`.",
|
|
38
|
+
"Native query URL parsing and remote image body handling are stricter, and the web query cache does less repeated hashing, invalidation and eviction work.",
|
|
39
|
+
"The generated client entry sets `data-nifra-hydrated` on a timer while the view is hidden, so a window created hidden no longer waits for an animation frame.",
|
|
40
|
+
],
|
|
41
|
+
}
|
package/src/recipes/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { recipe as v5_9_0 } from "./5.9.0.ts"
|
|
|
24
24
|
import { recipe as v5_10_0 } from "./5.10.0.ts"
|
|
25
25
|
import { recipe as v5_11_0 } from "./5.11.0.ts"
|
|
26
26
|
import { recipe as v5_12_0 } from "./5.12.0.ts"
|
|
27
|
+
import { recipe as v5_13_0 } from "./5.13.0.ts"
|
|
27
28
|
|
|
28
29
|
/** A pin rule: every dependency whose name starts with `match` is set to version `to`. */
|
|
29
30
|
export interface PinRule {
|
|
@@ -107,6 +108,7 @@ const RECIPES: Record<string, UpgradeRecipe> = {
|
|
|
107
108
|
[v5_10_0.version]: v5_10_0,
|
|
108
109
|
[v5_11_0.version]: v5_11_0,
|
|
109
110
|
[v5_12_0.version]: v5_12_0,
|
|
111
|
+
[v5_13_0.version]: v5_13_0,
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
export function getRecipe(version: string): UpgradeRecipe | undefined {
|
package/src/rules/routes.ts
CHANGED
|
@@ -12,8 +12,8 @@ import type { CheckRule, RuleContext } from "./index.ts"
|
|
|
12
12
|
* NF-C018 exists because the typed client's proxy intercepts a fixed set of property names before
|
|
13
13
|
* path resolution (`resolveSegment` + the thenable guard in @nifrajs/client). A route whose path
|
|
14
14
|
* contains a static segment spelling one of these cannot be reached by DOT ACCESS -
|
|
15
|
-
* `api.delete
|
|
16
|
-
* parent node (`api.api("delete").post()`, treaty.ts `SegmentCall`), and the client type rejects
|
|
15
|
+
* `api.delete()` invokes the DELETE verb and `api.delete.post` is undefined. The typed spelling is a
|
|
16
|
+
* call on the parent node (`api.api("delete").post()`, treaty.ts `SegmentCall`), and the client type rejects
|
|
17
17
|
* the dot access with the same guidance - so the collision is a warning that teaches the call
|
|
18
18
|
* spelling, not a blocking error: the route IS reachable, just not by the spelling its name
|
|
19
19
|
* suggests.
|