Files and paths (IAWL ideas 12, 13, 36): resolved --dest, starter refuses links and escaping paths, Office ZIP entries with trailing dots, proxy matcher ends api/admin/_next at /
- iapl-skills: --dest is compared with the project root after resolving links; a folder that is the root or holds it (.., /) is refused - starter: collectBundle refuses symbolic links (their target would ship in the published bundle); writeFiles refuses absolute or escaping paths - form files: a program inside a DOCX/XLSX is found with trailing dots or spaces (Windows drops them) - proxy matcher: (?!(?:api|admin|_next)(?:/|$)|...) so /administracja, /apis get the proxy; doctor rule proxy-matcher reports the old literal - pnpm: @swc/core in ignoredBuiltDependencies (its postinstall only checks the native binary, already installed) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e821d52d19
commit
498b3dbf38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* The documented proxy matcher, compiled by Next's own code (the function `next build` uses for `config.matcher`):
|
||||
* `api`, `admin` and `_next` are skipped only as a whole first segment. Before 1.17.1 `/administracja`, `/admin-guide`
|
||||
* or `/apis` skipped the proxy as well (IAWL idea 36: a deny rule by name must end at "/").
|
||||
*/
|
||||
import { readFileSync, realpathSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import path from 'node:path'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
import { DEFAULT_PROXY_MATCHER } from '../src/modules/i18n/createProxy.js'
|
||||
|
||||
const root = path.resolve(import.meta.dirname, '..')
|
||||
const next = realpathSync(path.join(root, 'node_modules/next'))
|
||||
const { getMiddlewareMatchers } = createRequire(import.meta.url)(path.join(next, 'dist/build/analysis/get-page-static-info.js')) as {
|
||||
getMiddlewareMatchers: (matchers: string[], nextConfig: object) => { regexp: string }[]
|
||||
}
|
||||
const runs = (matcher: string) => {
|
||||
const re = new RegExp(getMiddlewareMatchers([matcher], {})[0]!.regexp)
|
||||
return (pathname: string) => re.test(pathname)
|
||||
}
|
||||
|
||||
describe('the proxy matcher', () => {
|
||||
test('skips /api, /admin and /_next as whole segments and files; runs on pages that only START with those letters', () => {
|
||||
const proxy = runs(DEFAULT_PROXY_MATCHER[0]!)
|
||||
for (const skipped of ['/api', '/api/users', '/api/ipal/hit', '/admin', '/admin/', '/admin/collections/users', '/_next/static/chunk.js', '/robots.txt', '/sitemap.xml']) {
|
||||
expect([skipped, proxy(skipped)]).toEqual([skipped, false])
|
||||
}
|
||||
for (const page of ['/', '/o-nas', '/pl/o-nas', '/administracja', '/admin-guide', '/apis', '/api-docs', '/_nextish', '/md/pl/o-nas']) {
|
||||
expect([page, proxy(page)]).toEqual([page, true])
|
||||
}
|
||||
})
|
||||
|
||||
test('the reference site uses the same literal (Next reads it statically, it cannot be imported)', () => {
|
||||
const proxyFile = readFileSync(path.join(root, 'reference/src/proxy.ts'), 'utf8')
|
||||
expect(proxyFile).toContain(`matcher: ['${DEFAULT_PROXY_MATCHER[0]!.replace(/\\/g, '\\\\')}']`)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user