@next/codemod 16.5.0-canary.7 → 16.5.0-canary.71
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/bin/agents-md.js +18 -10
- package/lib/__tests__/agents-md-e2e.test.js +471 -5
- package/lib/agents-md.js +86 -17
- package/lib/cra-to-next/global-css-transform.js +4 -0
- package/lib/cra-to-next/index-to-component.js +6 -0
- package/package.json +4 -2
- package/transforms/next-lint-to-eslint-cli.js +16 -0
package/bin/agents-md.js
CHANGED
|
@@ -58,18 +58,22 @@ async function runAgentsMd(options) {
|
|
|
58
58
|
nextjsVersion = promptedOptions.nextVersion;
|
|
59
59
|
targetFile = promptedOptions.targetFile;
|
|
60
60
|
}
|
|
61
|
-
const agentsMdPath = path_1.default.
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
const agentsMdPath = path_1.default.resolve(cwd, targetFile);
|
|
62
|
+
// Agents resolve paths in the index from the directory of the output file,
|
|
63
|
+
// so every link written into it is relative to that directory, not the cwd.
|
|
64
|
+
const outputDir = path_1.default.dirname(agentsMdPath);
|
|
65
|
+
// Next.js >= 16.2.0 ships its docs inside the published package. When an
|
|
66
|
+
// installed version (from the cwd or, in a monorepo, a workspace package)
|
|
67
|
+
// matches the requested one, index the bundled docs directly instead of
|
|
68
|
+
// downloading a copy into .next-docs.
|
|
69
|
+
const bundledDocs = (0, agents_md_1.getBundledDocsInfo)(cwd, nextjsVersion);
|
|
70
|
+
const useBundledDocs = bundledDocs !== null;
|
|
67
71
|
const docsPath = useBundledDocs
|
|
68
72
|
? bundledDocs.docsPath
|
|
69
73
|
: path_1.default.join(cwd, DOCS_DIR_NAME);
|
|
70
74
|
const docsLinkPath = useBundledDocs
|
|
71
|
-
? (0, agents_md_1.getBundledDocsLinkPath)(
|
|
72
|
-
:
|
|
75
|
+
? (0, agents_md_1.getBundledDocsLinkPath)(outputDir, bundledDocs.docsPath, bundledDocs.resolvedFrom)
|
|
76
|
+
: (0, agents_md_1.getRelativeLinkPath)(outputDir, docsPath);
|
|
73
77
|
let sizeBefore = 0;
|
|
74
78
|
let isNewFile = true;
|
|
75
79
|
let existingContent = '';
|
|
@@ -79,7 +83,10 @@ async function runAgentsMd(options) {
|
|
|
79
83
|
isNewFile = false;
|
|
80
84
|
}
|
|
81
85
|
if (useBundledDocs) {
|
|
82
|
-
|
|
86
|
+
const fromWorkspacePackage = path_1.default.resolve(bundledDocs.resolvedFrom) !== path_1.default.resolve(cwd)
|
|
87
|
+
? ` from workspace package ${picocolors_1.default.cyan(path_1.default.relative(cwd, bundledDocs.resolvedFrom).replace(/\\/g, '/'))}`
|
|
88
|
+
: '';
|
|
89
|
+
console.log(`\nUsing the docs bundled with Next.js ${picocolors_1.default.cyan(nextjsVersion)}${fromWorkspacePackage} at ${picocolors_1.default.cyan(docsLinkPath)} (no download needed).`);
|
|
83
90
|
}
|
|
84
91
|
else {
|
|
85
92
|
console.log(`\nDownloading Next.js ${picocolors_1.default.cyan(nextjsVersion)} documentation to ${picocolors_1.default.cyan(DOCS_DIR_NAME)}...`);
|
|
@@ -97,7 +104,8 @@ async function runAgentsMd(options) {
|
|
|
97
104
|
const indexContent = (0, agents_md_1.generateAgentsMdIndex)({
|
|
98
105
|
docsPath: docsLinkPath,
|
|
99
106
|
sections,
|
|
100
|
-
|
|
107
|
+
// The regeneration hint is run from the output file's directory.
|
|
108
|
+
outputFile: path_1.default.relative(outputDir, agentsMdPath).replace(/\\/g, '/'),
|
|
101
109
|
});
|
|
102
110
|
const newContent = (0, agents_md_1.injectIntoAgentsMd)(existingContent, indexContent);
|
|
103
111
|
fs_1.default.writeFileSync(agentsMdPath, newContent, 'utf-8');
|
|
@@ -4,9 +4,22 @@ jest.autoMockOff()
|
|
|
4
4
|
const fs = require('fs')
|
|
5
5
|
const path = require('path')
|
|
6
6
|
const os = require('os')
|
|
7
|
+
const { execFileSync } = require('child_process')
|
|
7
8
|
const { runAgentsMd } = require('../../bin/agents-md')
|
|
8
9
|
const { getNextjsVersion } = require('../../lib/agents-md')
|
|
9
10
|
|
|
11
|
+
function execNodeWithoutNodePath(script, options = {}) {
|
|
12
|
+
// pnpm 12's Jest launcher exposes hoisted dependencies through NODE_PATH.
|
|
13
|
+
// A fresh Node process must omit it to resolve only the fixture's dependencies.
|
|
14
|
+
const env = { ...process.env, ...options.env }
|
|
15
|
+
delete env.NODE_PATH
|
|
16
|
+
return execFileSync(process.execPath, ['-e', script], {
|
|
17
|
+
...options,
|
|
18
|
+
env,
|
|
19
|
+
encoding: 'utf8',
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
/**
|
|
11
24
|
* TRUE E2E TESTS
|
|
12
25
|
* These tests invoke the actual CLI entry point (runAgentsMd),
|
|
@@ -14,6 +27,12 @@ const { getNextjsVersion } = require('../../lib/agents-md')
|
|
|
14
27
|
* npx @next/codemod agents-md --version 15.0.0 --output AGENTS.md
|
|
15
28
|
*/
|
|
16
29
|
describe('agents-md e2e (CLI invocation)', () => {
|
|
30
|
+
// A stable cwd to return to after every test. Tests chdir into their temp
|
|
31
|
+
// project, and the cleanup below deletes it. If a test times out, its body
|
|
32
|
+
// keeps running and never restores the cwd itself, so without this every
|
|
33
|
+
// later test would start in (and capture as its "original" cwd) a
|
|
34
|
+
// directory that no longer exists.
|
|
35
|
+
const suiteCwd = process.cwd()
|
|
17
36
|
let testProjectDir
|
|
18
37
|
let originalConsoleLog
|
|
19
38
|
let consoleOutput
|
|
@@ -39,6 +58,8 @@ describe('agents-md e2e (CLI invocation)', () => {
|
|
|
39
58
|
// Restore console.log
|
|
40
59
|
console.log = originalConsoleLog
|
|
41
60
|
|
|
61
|
+
process.chdir(suiteCwd)
|
|
62
|
+
|
|
42
63
|
// Clean up test directory
|
|
43
64
|
if (testProjectDir && fs.existsSync(testProjectDir)) {
|
|
44
65
|
fs.rmSync(testProjectDir, { recursive: true, force: true })
|
|
@@ -287,7 +308,7 @@ This is my project documentation.
|
|
|
287
308
|
} finally {
|
|
288
309
|
process.chdir(originalCwd)
|
|
289
310
|
}
|
|
290
|
-
}
|
|
311
|
+
})
|
|
291
312
|
|
|
292
313
|
describe('bundled docs (Next.js >= 16.2.0)', () => {
|
|
293
314
|
// Simulate an install of a Next.js version that ships docs inside the
|
|
@@ -382,12 +403,24 @@ This is my project documentation.
|
|
|
382
403
|
it('falls back to downloading when --version differs from the installed version', async () => {
|
|
383
404
|
setupBundledNext(testProjectDir, '16.2.0')
|
|
384
405
|
|
|
406
|
+
// This test is about choosing the download path, not about the download
|
|
407
|
+
// itself (covered by the tests above), so stub it to stay offline.
|
|
408
|
+
const pullDocsSpy = jest
|
|
409
|
+
.spyOn(require('../../lib/agents-md'), 'pullDocs')
|
|
410
|
+
.mockImplementation(async ({ docsDir }) => {
|
|
411
|
+
fs.mkdirSync(path.join(docsDir, '01-app'), { recursive: true })
|
|
412
|
+
fs.writeFileSync(path.join(docsDir, '01-app', 'index.md'), '# Docs')
|
|
413
|
+
return { success: true, docsPath: docsDir }
|
|
414
|
+
})
|
|
415
|
+
|
|
385
416
|
const originalCwd = process.cwd()
|
|
386
417
|
process.chdir(testProjectDir)
|
|
387
418
|
|
|
388
419
|
try {
|
|
389
420
|
await runAgentsMd({ version: '15.0.0', output: 'AGENTS.md' })
|
|
390
421
|
|
|
422
|
+
expect(pullDocsSpy).toHaveBeenCalledTimes(1)
|
|
423
|
+
expect(pullDocsSpy.mock.calls[0][0].version).toBe('15.0.0')
|
|
391
424
|
expect(fs.existsSync(path.join(testProjectDir, '.next-docs'))).toBe(
|
|
392
425
|
true
|
|
393
426
|
)
|
|
@@ -402,8 +435,435 @@ This is my project documentation.
|
|
|
402
435
|
expect(output).toContain('Downloading')
|
|
403
436
|
} finally {
|
|
404
437
|
process.chdir(originalCwd)
|
|
438
|
+
pullDocsSpy.mockRestore()
|
|
405
439
|
}
|
|
406
|
-
}
|
|
440
|
+
})
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
// The index `root` is resolved by agents from the directory of the output
|
|
444
|
+
// file, so it must be relative to that directory, not to the cwd.
|
|
445
|
+
describe('paths relative to the output file', () => {
|
|
446
|
+
const agentsMdLib = require('../../lib/agents-md')
|
|
447
|
+
let originalCwd
|
|
448
|
+
let pullDocsSpy
|
|
449
|
+
|
|
450
|
+
// Install `next` the way pnpm's isolated linker does: the real package
|
|
451
|
+
// lives in the root `node_modules/.pnpm` store and is only symlinked into
|
|
452
|
+
// the package that depends on it.
|
|
453
|
+
function installNextIsolated(projectDir, pkgDir, version) {
|
|
454
|
+
const storeDir = path.join(
|
|
455
|
+
projectDir,
|
|
456
|
+
'node_modules',
|
|
457
|
+
'.pnpm',
|
|
458
|
+
`next@${version}`,
|
|
459
|
+
'node_modules',
|
|
460
|
+
'next'
|
|
461
|
+
)
|
|
462
|
+
writeBundledNextPackage(storeDir, version)
|
|
463
|
+
const linkDir = path.join(pkgDir, 'node_modules')
|
|
464
|
+
fs.mkdirSync(linkDir, { recursive: true })
|
|
465
|
+
fs.symlinkSync(storeDir, path.join(linkDir, 'next'), 'junction')
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function writeBundledNextPackage(nextDir, version) {
|
|
469
|
+
const docsDir = path.join(nextDir, 'dist', 'docs', '01-app')
|
|
470
|
+
fs.mkdirSync(docsDir, { recursive: true })
|
|
471
|
+
fs.writeFileSync(
|
|
472
|
+
path.join(nextDir, 'package.json'),
|
|
473
|
+
JSON.stringify({ name: 'next', version })
|
|
474
|
+
)
|
|
475
|
+
fs.writeFileSync(path.join(docsDir, `docs-${version}.md`), '# Docs')
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function readIndex(agentsMdPath) {
|
|
479
|
+
const content = fs.readFileSync(agentsMdPath, 'utf-8')
|
|
480
|
+
return {
|
|
481
|
+
content,
|
|
482
|
+
root: content.match(/\|root: ([^|]+)\|/)[1],
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Returns the absolute path `root` points at, resolved the way an agent
|
|
487
|
+
// reading the output file would resolve it.
|
|
488
|
+
function resolveRoot(agentsMdPath) {
|
|
489
|
+
return path.resolve(path.dirname(agentsMdPath), readIndex(agentsMdPath).root)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
beforeEach(() => {
|
|
493
|
+
originalCwd = process.cwd()
|
|
494
|
+
// Stub the download so the `.next-docs` branch is testable offline.
|
|
495
|
+
pullDocsSpy = jest
|
|
496
|
+
.spyOn(agentsMdLib, 'pullDocs')
|
|
497
|
+
.mockImplementation(async ({ docsDir }) => {
|
|
498
|
+
const sectionDir = path.join(docsDir, '01-app')
|
|
499
|
+
fs.mkdirSync(sectionDir, { recursive: true })
|
|
500
|
+
fs.writeFileSync(path.join(sectionDir, 'downloaded.md'), '# Docs')
|
|
501
|
+
return { success: true, docsPath: docsDir }
|
|
502
|
+
})
|
|
503
|
+
})
|
|
504
|
+
|
|
505
|
+
afterEach(() => {
|
|
506
|
+
process.chdir(originalCwd)
|
|
507
|
+
pullDocsSpy.mockRestore()
|
|
508
|
+
})
|
|
509
|
+
|
|
510
|
+
it('links bundled docs relative to an output file outside the cwd', async () => {
|
|
511
|
+
const appDir = path.join(testProjectDir, 'apps', 'web')
|
|
512
|
+
installNextIsolated(testProjectDir, appDir, '16.4.0')
|
|
513
|
+
process.chdir(appDir)
|
|
514
|
+
|
|
515
|
+
await runAgentsMd({ output: '../../AGENTS.md' })
|
|
516
|
+
|
|
517
|
+
const agentsMdPath = path.join(testProjectDir, 'AGENTS.md')
|
|
518
|
+
expect(readIndex(agentsMdPath).root).toBe(
|
|
519
|
+
'./apps/web/node_modules/next/dist/docs'
|
|
520
|
+
)
|
|
521
|
+
expect(
|
|
522
|
+
fs.existsSync(path.join(resolveRoot(agentsMdPath), '01-app'))
|
|
523
|
+
).toBe(true)
|
|
524
|
+
expect(pullDocsSpy).not.toHaveBeenCalled()
|
|
525
|
+
})
|
|
526
|
+
|
|
527
|
+
it('links downloaded docs relative to an output file outside the cwd', async () => {
|
|
528
|
+
const appDir = path.join(testProjectDir, 'apps', 'web')
|
|
529
|
+
fs.mkdirSync(appDir, { recursive: true })
|
|
530
|
+
process.chdir(appDir)
|
|
531
|
+
|
|
532
|
+
await runAgentsMd({ version: '15.0.0', output: '../../AGENTS.md' })
|
|
533
|
+
|
|
534
|
+
const agentsMdPath = path.join(testProjectDir, 'AGENTS.md')
|
|
535
|
+
expect(readIndex(agentsMdPath).root).toBe('./apps/web/.next-docs')
|
|
536
|
+
expect(fs.realpathSync(resolveRoot(agentsMdPath))).toBe(
|
|
537
|
+
fs.realpathSync(path.join(appDir, '.next-docs'))
|
|
538
|
+
)
|
|
539
|
+
})
|
|
540
|
+
|
|
541
|
+
it('keeps the ./ prefix for the .next-docs dot-directory', async () => {
|
|
542
|
+
process.chdir(testProjectDir)
|
|
543
|
+
|
|
544
|
+
await runAgentsMd({ version: '15.0.0', output: 'AGENTS.md' })
|
|
545
|
+
|
|
546
|
+
expect(readIndex(path.join(testProjectDir, 'AGENTS.md')).root).toBe(
|
|
547
|
+
'./.next-docs'
|
|
548
|
+
)
|
|
549
|
+
})
|
|
550
|
+
|
|
551
|
+
it('links the indexed install when the output dir resolves a different next', async () => {
|
|
552
|
+
// Root has a hoisted next@16.3.0; the app has its own next@16.4.0.
|
|
553
|
+
writeBundledNextPackage(
|
|
554
|
+
path.join(testProjectDir, 'node_modules', 'next'),
|
|
555
|
+
'16.3.0'
|
|
556
|
+
)
|
|
557
|
+
const appDir = path.join(testProjectDir, 'apps', 'web')
|
|
558
|
+
installNextIsolated(testProjectDir, appDir, '16.4.0')
|
|
559
|
+
process.chdir(appDir)
|
|
560
|
+
|
|
561
|
+
await runAgentsMd({ output: '../../AGENTS.md' })
|
|
562
|
+
|
|
563
|
+
const agentsMdPath = path.join(testProjectDir, 'AGENTS.md')
|
|
564
|
+
const linkedPkg = JSON.parse(
|
|
565
|
+
fs.readFileSync(
|
|
566
|
+
path.join(resolveRoot(agentsMdPath), '..', '..', 'package.json'),
|
|
567
|
+
'utf-8'
|
|
568
|
+
)
|
|
569
|
+
)
|
|
570
|
+
expect(linkedPkg.version).toBe('16.4.0')
|
|
571
|
+
expect(readIndex(agentsMdPath).content).toContain('docs-16.4.0.md')
|
|
572
|
+
})
|
|
573
|
+
|
|
574
|
+
it('writes a regeneration hint that is relative to the output file', async () => {
|
|
575
|
+
const appDir = path.join(testProjectDir, 'apps', 'web')
|
|
576
|
+
installNextIsolated(testProjectDir, appDir, '16.4.0')
|
|
577
|
+
process.chdir(appDir)
|
|
578
|
+
|
|
579
|
+
await runAgentsMd({ output: '../../AGENTS.md' })
|
|
580
|
+
|
|
581
|
+
const { content } = readIndex(path.join(testProjectDir, 'AGENTS.md'))
|
|
582
|
+
expect(content).toContain(
|
|
583
|
+
"If docs missing, run this command from this file's directory: npx @next/codemod agents-md --output AGENTS.md|"
|
|
584
|
+
)
|
|
585
|
+
expect(content).not.toContain('--output ../../AGENTS.md')
|
|
586
|
+
})
|
|
587
|
+
|
|
588
|
+
it('supports an absolute --output path', async () => {
|
|
589
|
+
const appDir = path.join(testProjectDir, 'apps', 'web')
|
|
590
|
+
installNextIsolated(testProjectDir, appDir, '16.4.0')
|
|
591
|
+
const outputDir = path.join(testProjectDir, 'docs-out')
|
|
592
|
+
fs.mkdirSync(outputDir)
|
|
593
|
+
const agentsMdPath = path.join(outputDir, 'CLAUDE.md')
|
|
594
|
+
process.chdir(appDir)
|
|
595
|
+
|
|
596
|
+
await runAgentsMd({ output: agentsMdPath })
|
|
597
|
+
|
|
598
|
+
expect(fs.existsSync(agentsMdPath)).toBe(true)
|
|
599
|
+
const { root, content } = readIndex(agentsMdPath)
|
|
600
|
+
expect(root).toBe('../apps/web/node_modules/next/dist/docs')
|
|
601
|
+
expect(
|
|
602
|
+
fs.existsSync(path.join(resolveRoot(agentsMdPath), '01-app'))
|
|
603
|
+
).toBe(true)
|
|
604
|
+
expect(content).toContain('--output CLAUDE.md|')
|
|
605
|
+
})
|
|
606
|
+
|
|
607
|
+
// The cwd/output path and the path `next` resolves to can be spelled
|
|
608
|
+
// differently for the same directory: a symlinked alias, or an 8.3 short
|
|
609
|
+
// name like `C:\Users\RUNNER~1\...` on Windows, where `process.cwd()`
|
|
610
|
+
// keeps the short name while module resolution returns the long one.
|
|
611
|
+
// Links must still be computed between consistent spellings.
|
|
612
|
+
describe('when the cwd is spelled differently than the realpath', () => {
|
|
613
|
+
let aliasBase
|
|
614
|
+
let aliasDir
|
|
615
|
+
let cwdSpy
|
|
616
|
+
|
|
617
|
+
// Run from `dir` (inside the real project) while `process.cwd()`
|
|
618
|
+
// reports it through the alias, like a non-canonical cwd on Windows.
|
|
619
|
+
function chdirViaAlias(dir) {
|
|
620
|
+
process.chdir(dir)
|
|
621
|
+
const aliased = path.join(
|
|
622
|
+
aliasDir,
|
|
623
|
+
path.relative(fs.realpathSync(testProjectDir), fs.realpathSync(dir))
|
|
624
|
+
)
|
|
625
|
+
cwdSpy = jest.spyOn(process, 'cwd').mockReturnValue(aliased)
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
beforeEach(() => {
|
|
629
|
+
aliasBase = fs.mkdtempSync(path.join(os.tmpdir(), 'agents-md-alias-'))
|
|
630
|
+
aliasDir = path.join(aliasBase, 'project')
|
|
631
|
+
fs.symlinkSync(testProjectDir, aliasDir, 'junction')
|
|
632
|
+
})
|
|
633
|
+
|
|
634
|
+
afterEach(() => {
|
|
635
|
+
cwdSpy?.mockRestore()
|
|
636
|
+
cwdSpy = undefined
|
|
637
|
+
fs.rmSync(aliasBase, { recursive: true, force: true })
|
|
638
|
+
})
|
|
639
|
+
|
|
640
|
+
it('links the conventional path through a symlinked cwd', async () => {
|
|
641
|
+
writeBundledNextPackage(
|
|
642
|
+
path.join(testProjectDir, 'node_modules', 'next'),
|
|
643
|
+
'16.4.0'
|
|
644
|
+
)
|
|
645
|
+
chdirViaAlias(testProjectDir)
|
|
646
|
+
|
|
647
|
+
await runAgentsMd({ output: 'AGENTS.md' })
|
|
648
|
+
|
|
649
|
+
const agentsMdPath = path.join(testProjectDir, 'AGENTS.md')
|
|
650
|
+
expect(readIndex(agentsMdPath).root).toBe(
|
|
651
|
+
'./node_modules/next/dist/docs'
|
|
652
|
+
)
|
|
653
|
+
})
|
|
654
|
+
|
|
655
|
+
it('links a hoisted install canonically through a symlinked cwd', async () => {
|
|
656
|
+
writeBundledNextPackage(
|
|
657
|
+
path.join(testProjectDir, 'node_modules', 'next'),
|
|
658
|
+
'16.4.0'
|
|
659
|
+
)
|
|
660
|
+
const appDir = path.join(testProjectDir, 'apps', 'web')
|
|
661
|
+
fs.mkdirSync(appDir, { recursive: true })
|
|
662
|
+
chdirViaAlias(appDir)
|
|
663
|
+
|
|
664
|
+
await runAgentsMd({ output: 'AGENTS.md' })
|
|
665
|
+
|
|
666
|
+
const agentsMdPath = path.join(testProjectDir, 'apps', 'web', 'AGENTS.md')
|
|
667
|
+
expect(readIndex(agentsMdPath).root).toBe(
|
|
668
|
+
'../../node_modules/next/dist/docs'
|
|
669
|
+
)
|
|
670
|
+
expect(
|
|
671
|
+
fs.existsSync(path.join(resolveRoot(agentsMdPath), '01-app'))
|
|
672
|
+
).toBe(true)
|
|
673
|
+
})
|
|
674
|
+
|
|
675
|
+
it('detects the same install when only the native realpath canonicalizes', async () => {
|
|
676
|
+
// Simulate Windows 8.3 short names: the JS `fs.realpathSync` leaves
|
|
677
|
+
// the alias spelling as-is, while `fs.realpathSync.native` expands it.
|
|
678
|
+
writeBundledNextPackage(
|
|
679
|
+
path.join(testProjectDir, 'node_modules', 'next'),
|
|
680
|
+
'16.4.0'
|
|
681
|
+
)
|
|
682
|
+
chdirViaAlias(testProjectDir)
|
|
683
|
+
const nativeRealpath = fs.realpathSync.native
|
|
684
|
+
const realpathSpy = jest
|
|
685
|
+
.spyOn(fs, 'realpathSync')
|
|
686
|
+
.mockImplementation((p) => path.resolve(String(p)))
|
|
687
|
+
fs.realpathSync.native = nativeRealpath
|
|
688
|
+
|
|
689
|
+
try {
|
|
690
|
+
await runAgentsMd({ output: 'AGENTS.md' })
|
|
691
|
+
} finally {
|
|
692
|
+
realpathSpy.mockRestore()
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
expect(readIndex(path.join(testProjectDir, 'AGENTS.md')).root).toBe(
|
|
696
|
+
'./node_modules/next/dist/docs'
|
|
697
|
+
)
|
|
698
|
+
})
|
|
699
|
+
})
|
|
700
|
+
|
|
701
|
+
it('always prefixes relative links with ./ or ../', () => {
|
|
702
|
+
const { getRelativeLinkPath } = agentsMdLib
|
|
703
|
+
const base = path.join(testProjectDir, 'a', 'b')
|
|
704
|
+
|
|
705
|
+
expect(getRelativeLinkPath(base, base)).toBe('./')
|
|
706
|
+
expect(getRelativeLinkPath(base, path.join(testProjectDir, 'a'))).toBe(
|
|
707
|
+
'../'
|
|
708
|
+
)
|
|
709
|
+
expect(getRelativeLinkPath(base, path.join(base, '.next-docs'))).toBe(
|
|
710
|
+
'./.next-docs'
|
|
711
|
+
)
|
|
712
|
+
expect(
|
|
713
|
+
getRelativeLinkPath(base, path.join(testProjectDir, 'a', 'docs'))
|
|
714
|
+
).toBe('../docs')
|
|
715
|
+
expect(getRelativeLinkPath(base, path.join(base, '..docs'))).toBe(
|
|
716
|
+
'./..docs'
|
|
717
|
+
)
|
|
718
|
+
})
|
|
719
|
+
|
|
720
|
+
// In a pnpm monorepo `next` is usually not resolvable from the repo root,
|
|
721
|
+
// so the bundled docs have to be found through the workspace packages.
|
|
722
|
+
describe('bundled docs from workspace packages', () => {
|
|
723
|
+
function setupWorkspace(patterns, packages) {
|
|
724
|
+
fs.writeFileSync(
|
|
725
|
+
path.join(testProjectDir, 'package.json'),
|
|
726
|
+
JSON.stringify({ name: 'root', private: true })
|
|
727
|
+
)
|
|
728
|
+
fs.writeFileSync(
|
|
729
|
+
path.join(testProjectDir, 'pnpm-workspace.yaml'),
|
|
730
|
+
`packages:\n${patterns.map((p) => ` - '${p}'`).join('\n')}\n`
|
|
731
|
+
)
|
|
732
|
+
for (const [pkg, version] of Object.entries(packages)) {
|
|
733
|
+
const pkgDir = path.join(testProjectDir, pkg)
|
|
734
|
+
fs.mkdirSync(pkgDir, { recursive: true })
|
|
735
|
+
fs.writeFileSync(
|
|
736
|
+
path.join(pkgDir, 'package.json'),
|
|
737
|
+
JSON.stringify({ name: path.basename(pkg) })
|
|
738
|
+
)
|
|
739
|
+
if (version) installNextIsolated(testProjectDir, pkgDir, version)
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function output() {
|
|
744
|
+
// Package names are colored; strip ANSI so FORCE_COLOR doesn't matter.
|
|
745
|
+
return require('strip-ansi')(consoleOutput.join('\n'))
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
function runFromWorkspaceRoot() {
|
|
749
|
+
return require('strip-ansi')(
|
|
750
|
+
execNodeWithoutNodePath(
|
|
751
|
+
`const { runAgentsMd } = require(${JSON.stringify(
|
|
752
|
+
path.join(__dirname, '../../bin/agents-md.js')
|
|
753
|
+
)})
|
|
754
|
+
runAgentsMd({ output: 'AGENTS.md' }).catch((error) => {
|
|
755
|
+
console.error(error)
|
|
756
|
+
process.exitCode = 1
|
|
757
|
+
})`,
|
|
758
|
+
{ cwd: testProjectDir }
|
|
759
|
+
)
|
|
760
|
+
)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
it('uses the bundled docs of a workspace package when run from the root', () => {
|
|
764
|
+
setupWorkspace(['apps/*'], { 'apps/web': '16.4.0' })
|
|
765
|
+
|
|
766
|
+
const cliOutput = runFromWorkspaceRoot()
|
|
767
|
+
|
|
768
|
+
const agentsMdPath = path.join(testProjectDir, 'AGENTS.md')
|
|
769
|
+
expect(readIndex(agentsMdPath).root).toBe(
|
|
770
|
+
'./apps/web/node_modules/next/dist/docs'
|
|
771
|
+
)
|
|
772
|
+
expect(
|
|
773
|
+
fs.existsSync(path.join(resolveRoot(agentsMdPath), '01-app'))
|
|
774
|
+
).toBe(true)
|
|
775
|
+
expect(fs.existsSync(path.join(testProjectDir, '.next-docs'))).toBe(
|
|
776
|
+
false
|
|
777
|
+
)
|
|
778
|
+
expect(fs.existsSync(path.join(testProjectDir, '.gitignore'))).toBe(
|
|
779
|
+
false
|
|
780
|
+
)
|
|
781
|
+
expect(cliOutput).toContain('workspace package apps/web')
|
|
782
|
+
})
|
|
783
|
+
|
|
784
|
+
it('indexes the package with the highest Next.js version', () => {
|
|
785
|
+
setupWorkspace(['apps/a', 'apps/b'], {
|
|
786
|
+
'apps/a': '16.3.0',
|
|
787
|
+
'apps/b': '16.4.0',
|
|
788
|
+
})
|
|
789
|
+
|
|
790
|
+
const cliOutput = runFromWorkspaceRoot()
|
|
791
|
+
|
|
792
|
+
const { root, content } = readIndex(
|
|
793
|
+
path.join(testProjectDir, 'AGENTS.md')
|
|
794
|
+
)
|
|
795
|
+
expect(root).toBe('./apps/b/node_modules/next/dist/docs')
|
|
796
|
+
expect(content).toContain('docs-16.4.0.md')
|
|
797
|
+
expect(cliOutput).not.toContain('Downloading')
|
|
798
|
+
expect(fs.existsSync(path.join(testProjectDir, '.next-docs'))).toBe(
|
|
799
|
+
false
|
|
800
|
+
)
|
|
801
|
+
})
|
|
802
|
+
|
|
803
|
+
it('picks the first matching package in workspace order and logs it', () => {
|
|
804
|
+
// Listed b before a, so the choice follows the workspace patterns
|
|
805
|
+
// rather than alphabetical order.
|
|
806
|
+
setupWorkspace(['apps/b', 'apps/a'], {
|
|
807
|
+
'apps/a': '16.4.0',
|
|
808
|
+
'apps/b': '16.4.0',
|
|
809
|
+
})
|
|
810
|
+
|
|
811
|
+
const cliOutput = runFromWorkspaceRoot()
|
|
812
|
+
|
|
813
|
+
expect(readIndex(path.join(testProjectDir, 'AGENTS.md')).root).toBe(
|
|
814
|
+
'./apps/b/node_modules/next/dist/docs'
|
|
815
|
+
)
|
|
816
|
+
expect(cliOutput).toContain('workspace package apps/b')
|
|
817
|
+
expect(cliOutput).not.toContain('workspace package apps/a')
|
|
818
|
+
})
|
|
819
|
+
|
|
820
|
+
it('prefers a matching install resolved from the cwd', async () => {
|
|
821
|
+
setupWorkspace(['apps/*'], { 'apps/web': '16.4.0' })
|
|
822
|
+
writeBundledNextPackage(
|
|
823
|
+
path.join(testProjectDir, 'node_modules', 'next'),
|
|
824
|
+
'16.4.0'
|
|
825
|
+
)
|
|
826
|
+
process.chdir(testProjectDir)
|
|
827
|
+
|
|
828
|
+
await runAgentsMd({ output: 'AGENTS.md' })
|
|
829
|
+
|
|
830
|
+
expect(readIndex(path.join(testProjectDir, 'AGENTS.md')).root).toBe(
|
|
831
|
+
'./node_modules/next/dist/docs'
|
|
832
|
+
)
|
|
833
|
+
expect(output()).not.toContain('workspace package')
|
|
834
|
+
})
|
|
835
|
+
|
|
836
|
+
it('uses a workspace package matching --version when the cwd resolves another version', async () => {
|
|
837
|
+
setupWorkspace(['apps/*'], { 'apps/web': '16.4.0' })
|
|
838
|
+
writeBundledNextPackage(
|
|
839
|
+
path.join(testProjectDir, 'node_modules', 'next'),
|
|
840
|
+
'16.3.0'
|
|
841
|
+
)
|
|
842
|
+
process.chdir(testProjectDir)
|
|
843
|
+
|
|
844
|
+
await runAgentsMd({ version: '16.4.0', output: 'AGENTS.md' })
|
|
845
|
+
|
|
846
|
+
const { root, content } = readIndex(
|
|
847
|
+
path.join(testProjectDir, 'AGENTS.md')
|
|
848
|
+
)
|
|
849
|
+
expect(root).toBe('./apps/web/node_modules/next/dist/docs')
|
|
850
|
+
expect(content).toContain('docs-16.4.0.md')
|
|
851
|
+
expect(pullDocsSpy).not.toHaveBeenCalled()
|
|
852
|
+
})
|
|
853
|
+
|
|
854
|
+
it('still downloads when no workspace package has matching bundled docs', async () => {
|
|
855
|
+
setupWorkspace(['apps/*'], { 'apps/web': '16.4.0' })
|
|
856
|
+
process.chdir(testProjectDir)
|
|
857
|
+
|
|
858
|
+
await runAgentsMd({ version: '15.0.0', output: 'AGENTS.md' })
|
|
859
|
+
|
|
860
|
+
expect(pullDocsSpy).toHaveBeenCalled()
|
|
861
|
+
expect(readIndex(path.join(testProjectDir, 'AGENTS.md')).root).toBe(
|
|
862
|
+
'./.next-docs'
|
|
863
|
+
)
|
|
864
|
+
expect(output()).not.toContain('workspace package')
|
|
865
|
+
})
|
|
866
|
+
})
|
|
407
867
|
})
|
|
408
868
|
|
|
409
869
|
describe('getNextjsVersion', () => {
|
|
@@ -428,9 +888,15 @@ This is my project documentation.
|
|
|
428
888
|
})
|
|
429
889
|
|
|
430
890
|
it('returns error when Next.js is not installed', () => {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
891
|
+
const result = JSON.parse(
|
|
892
|
+
execNodeWithoutNodePath(
|
|
893
|
+
`const { getNextjsVersion } = require(${JSON.stringify(
|
|
894
|
+
path.join(__dirname, '../agents-md.js')
|
|
895
|
+
)})
|
|
896
|
+
console.log(JSON.stringify(getNextjsVersion(process.cwd())))`,
|
|
897
|
+
{ cwd: testProjectDir }
|
|
898
|
+
)
|
|
899
|
+
)
|
|
434
900
|
|
|
435
901
|
expect(result.version).toBeNull()
|
|
436
902
|
expect(result.error).toBe('Next.js is not installed in this project.')
|
package/lib/agents-md.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.refreshAgentRulesBlock = refreshAgentRulesBlock;
|
|
13
13
|
exports.getNextjsVersion = getNextjsVersion;
|
|
14
14
|
exports.getBundledDocsInfo = getBundledDocsInfo;
|
|
15
|
+
exports.getRelativeLinkPath = getRelativeLinkPath;
|
|
15
16
|
exports.getBundledDocsLinkPath = getBundledDocsLinkPath;
|
|
16
17
|
exports.pullDocs = pullDocs;
|
|
17
18
|
exports.collectDocFiles = collectDocFiles;
|
|
@@ -87,33 +88,98 @@ function getNextjsVersion(cwd) {
|
|
|
87
88
|
}
|
|
88
89
|
/**
|
|
89
90
|
* Next.js ships its documentation inside the published package (at
|
|
90
|
-
* `dist/docs`) since 16.2.0. When
|
|
91
|
-
* bundled docs, the index can point at them directly instead
|
|
92
|
-
* downloading a copy into `.next-docs`.
|
|
91
|
+
* `dist/docs`) since 16.2.0. When an installed `next` of the requested
|
|
92
|
+
* `version` has bundled docs, the index can point at them directly instead
|
|
93
|
+
* of downloading a copy into `.next-docs`.
|
|
94
|
+
*
|
|
95
|
+
* The install resolved from `cwd` wins; otherwise the workspace packages are
|
|
96
|
+
* searched.
|
|
93
97
|
*/
|
|
94
|
-
function getBundledDocsInfo(cwd) {
|
|
98
|
+
function getBundledDocsInfo(cwd, version) {
|
|
99
|
+
const fromCwd = getBundledDocsInfoFrom(cwd);
|
|
100
|
+
if (fromCwd?.version === version) {
|
|
101
|
+
return fromCwd;
|
|
102
|
+
}
|
|
103
|
+
// Mirror getNextjsVersion: with isolated installs (pnpm), `next` is often
|
|
104
|
+
// only resolvable from the workspace package that depends on it, not from
|
|
105
|
+
// the repo root. Use the first package, in workspace order, that ships
|
|
106
|
+
// bundled docs for the requested version.
|
|
107
|
+
const workspace = detectWorkspace(cwd);
|
|
108
|
+
if (workspace.isMonorepo) {
|
|
109
|
+
for (const pkgPath of expandWorkspacePatterns(cwd, workspace.packages)) {
|
|
110
|
+
const info = getBundledDocsInfoFrom(pkgPath);
|
|
111
|
+
if (info?.version === version) {
|
|
112
|
+
return info;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
function getBundledDocsInfoFrom(dir) {
|
|
95
119
|
try {
|
|
96
|
-
const nextPkgPath = require.resolve('next/package.json', { paths: [
|
|
120
|
+
const nextPkgPath = require.resolve('next/package.json', { paths: [dir] });
|
|
97
121
|
const pkg = JSON.parse(fs_1.default.readFileSync(nextPkgPath, 'utf-8'));
|
|
98
122
|
const docsPath = path_1.default.join(path_1.default.dirname(nextPkgPath), 'dist', 'docs');
|
|
99
123
|
if (!pkg.version || collectDocFiles(docsPath).length === 0) {
|
|
100
124
|
return null;
|
|
101
125
|
}
|
|
102
|
-
return { docsPath, version: pkg.version };
|
|
126
|
+
return { docsPath, version: pkg.version, resolvedFrom: dir };
|
|
103
127
|
}
|
|
104
128
|
catch {
|
|
105
129
|
return null;
|
|
106
130
|
}
|
|
107
131
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Returns `target` as a `./`- or `../`-prefixed, forward-slash path relative
|
|
134
|
+
* to `fromDir`. Agents resolve paths in the index from the directory of the
|
|
135
|
+
* output file, so `fromDir` must be that directory, not the cwd.
|
|
136
|
+
*/
|
|
137
|
+
function getRelativeLinkPath(fromDir, target) {
|
|
138
|
+
const relative = path_1.default.relative(fromDir, target).replace(/\\/g, '/');
|
|
139
|
+
if (relative === '')
|
|
140
|
+
return './';
|
|
141
|
+
if (relative === '..')
|
|
142
|
+
return '../';
|
|
143
|
+
// A dot-directory such as `.next-docs` still needs the `./` prefix.
|
|
144
|
+
return relative.startsWith('../') ? relative : `./${relative}`;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Canonical spelling of `p`: symlinks resolved and, on Windows, 8.3 short
|
|
148
|
+
* names (e.g. `C:\Users\RUNNER~1`) expanded. `process.cwd()` can keep a
|
|
149
|
+
* non-canonical spelling while module resolution returns the canonical one,
|
|
150
|
+
* so compare and relate paths only in this form. Falls back to the resolved
|
|
151
|
+
* path when `p` cannot be canonicalized (e.g. it does not exist).
|
|
152
|
+
*/
|
|
153
|
+
function canonicalPath(p) {
|
|
154
|
+
try {
|
|
155
|
+
return fs_1.default.realpathSync.native(p);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return path_1.default.resolve(p);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Link to the bundled docs of the install resolved from `resolvedFrom`,
|
|
163
|
+
* relative to `fromDir` (the directory of the output file).
|
|
164
|
+
*/
|
|
165
|
+
function getBundledDocsLinkPath(fromDir, docsPath, resolvedFrom) {
|
|
166
|
+
// Prefer the conventional path of the resolved install over its realpath:
|
|
167
|
+
// pnpm's `.pnpm/next@x.y.z/...` realpath changes on every upgrade, while
|
|
168
|
+
// the `node_modules/next` symlink stays stable. Check it under the
|
|
169
|
+
// directory `next` was resolved from, not under `fromDir`, which may see a
|
|
170
|
+
// different `next` install.
|
|
171
|
+
//
|
|
172
|
+
// Paths are related in canonical form (see canonicalPath) so a cwd or
|
|
173
|
+
// --output spelled differently than the resolved install still produces a
|
|
174
|
+
// clean link. Only the parent of the `node_modules/next` symlink is
|
|
175
|
+
// canonicalized, never the symlink itself, so the stable path is kept.
|
|
176
|
+
const outputDir = canonicalPath(fromDir);
|
|
177
|
+
const conventional = path_1.default.join(canonicalPath(resolvedFrom), 'node_modules', 'next', 'dist', 'docs');
|
|
178
|
+
if (fs_1.default.existsSync(conventional) &&
|
|
179
|
+
canonicalPath(conventional) === canonicalPath(docsPath)) {
|
|
180
|
+
return getRelativeLinkPath(outputDir, conventional);
|
|
181
|
+
}
|
|
182
|
+
return getRelativeLinkPath(outputDir, canonicalPath(docsPath));
|
|
117
183
|
}
|
|
118
184
|
function versionToGitHubTag(version) {
|
|
119
185
|
return version.startsWith('v') ? version : `v${version}`;
|
|
@@ -203,7 +269,10 @@ function collectDocFiles(dir) {
|
|
|
203
269
|
.filter((f) => (f.endsWith('.mdx') || f.endsWith('.md')) &&
|
|
204
270
|
!/[/\\]index\.mdx$/.test(f) &&
|
|
205
271
|
!/[/\\]index\.md$/.test(f) &&
|
|
206
|
-
!f.startsWith('index.')
|
|
272
|
+
!f.startsWith('index.') &&
|
|
273
|
+
// Error pages are opened by name from the link in a message, not
|
|
274
|
+
// browsed. Listing all of them would nearly double the index.
|
|
275
|
+
!/^messages[/\\]/.test(f))
|
|
207
276
|
.sort()
|
|
208
277
|
.map((f) => ({ relativePath: f.replace(/\\/g, '/') }));
|
|
209
278
|
}
|
|
@@ -264,7 +333,7 @@ function generateAgentsMdIndex(data) {
|
|
|
264
333
|
parts.push(`root: ${docsPath}`);
|
|
265
334
|
parts.push('STOP. What you remember about Next.js is WRONG for this project. Always search docs and read before any task.');
|
|
266
335
|
const targetFile = outputFile || 'AGENTS.md';
|
|
267
|
-
parts.push(`If docs missing, run this command
|
|
336
|
+
parts.push(`If docs missing, run this command from this file's directory: npx @next/codemod agents-md --output ${targetFile}`);
|
|
268
337
|
const allFiles = collectAllFilesFromSections(sections);
|
|
269
338
|
const grouped = groupByDirectory(allFiles);
|
|
270
339
|
for (const [dir, files] of grouped) {
|
|
@@ -27,6 +27,8 @@ function transformer(file, _api, options) {
|
|
|
27
27
|
resolvedPath = path_1.default.resolve(path_1.default.dirname(file.path), value);
|
|
28
28
|
}
|
|
29
29
|
exports.globalCssContext.cssImports.add(resolvedPath);
|
|
30
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
31
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
30
32
|
const { start, end } = path.node;
|
|
31
33
|
if (!path.parentPath.node.comments) {
|
|
32
34
|
path.parentPath.node.comments = [];
|
|
@@ -39,6 +41,8 @@ function transformer(file, _api, options) {
|
|
|
39
41
|
}
|
|
40
42
|
else if (value.endsWith('.svg')) {
|
|
41
43
|
const isComponentImport = path.node.specifiers.some((specifier) => {
|
|
44
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
45
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
42
46
|
return specifier.imported?.name === 'ReactComponent';
|
|
43
47
|
});
|
|
44
48
|
if (isComponentImport) {
|
|
@@ -34,10 +34,16 @@ function transformer(file, _api, options) {
|
|
|
34
34
|
let found = false;
|
|
35
35
|
if (defaultReactDomImport &&
|
|
36
36
|
node.callee.type === 'MemberExpression' &&
|
|
37
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
38
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
37
39
|
node.callee.object.name === defaultReactDomImport &&
|
|
40
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
41
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
38
42
|
node.callee.property.name === 'render') {
|
|
39
43
|
found = true;
|
|
40
44
|
}
|
|
45
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
46
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
41
47
|
if (hasRenderImport && node.callee.name === 'render') {
|
|
42
48
|
found = true;
|
|
43
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next/codemod",
|
|
3
|
-
"version": "16.5.0-canary.
|
|
3
|
+
"version": "16.5.0-canary.71",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"lib/**/*.js",
|
|
29
29
|
"lib/cra-to-next/gitignore"
|
|
30
30
|
],
|
|
31
|
-
"bin":
|
|
31
|
+
"bin": {
|
|
32
|
+
"codemod": "./bin/next-codemod.js"
|
|
33
|
+
},
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"@types/find-up": "4.0.0",
|
|
34
36
|
"@types/js-yaml": "4.0.9",
|
|
@@ -122,9 +122,17 @@ function replaceFlatCompatInConfig(configPath) {
|
|
|
122
122
|
const node = astPath.value;
|
|
123
123
|
// Detect compat.extends() calls and identify which configs are being used
|
|
124
124
|
if (node.callee.type === 'MemberExpression' &&
|
|
125
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
126
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
125
127
|
node.callee.object.type === 'Identifier' &&
|
|
128
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
129
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
126
130
|
node.callee.object.name === 'compat' &&
|
|
131
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
132
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
127
133
|
node.callee.property.type === 'Identifier' &&
|
|
134
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
135
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
128
136
|
node.callee.property.name === 'extends') {
|
|
129
137
|
// Check arguments for all configs
|
|
130
138
|
node.arguments.forEach((arg) => {
|
|
@@ -147,9 +155,17 @@ function replaceFlatCompatInConfig(configPath) {
|
|
|
147
155
|
}
|
|
148
156
|
// Detect compat.config({ extends: [...] }) calls and identify which configs are being used
|
|
149
157
|
if (node.callee.type === 'MemberExpression' &&
|
|
158
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
159
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
150
160
|
node.callee.object.type === 'Identifier' &&
|
|
161
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
162
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
151
163
|
node.callee.object.name === 'compat' &&
|
|
164
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
165
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
152
166
|
node.callee.property.type === 'Identifier' &&
|
|
167
|
+
// TODO(as-any): pre-existing cast, not yet reviewed
|
|
168
|
+
// eslint-disable-next-line @next/internal/no-as-any
|
|
153
169
|
node.callee.property.name === 'config') {
|
|
154
170
|
// Look for extends property in the object argument
|
|
155
171
|
node.arguments.forEach((arg) => {
|