@next/codemod 16.5.0-canary.10 → 16.5.0-canary.12

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.
@@ -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),
@@ -711,11 +724,25 @@ This is my project documentation.
711
724
  return require('strip-ansi')(consoleOutput.join('\n'))
712
725
  }
713
726
 
714
- it('uses the bundled docs of a workspace package when run from the root', async () => {
727
+ function runFromWorkspaceRoot() {
728
+ return require('strip-ansi')(
729
+ execNodeWithoutNodePath(
730
+ `const { runAgentsMd } = require(${JSON.stringify(
731
+ path.join(__dirname, '../../bin/agents-md.js')
732
+ )})
733
+ runAgentsMd({ output: 'AGENTS.md' }).catch((error) => {
734
+ console.error(error)
735
+ process.exitCode = 1
736
+ })`,
737
+ { cwd: testProjectDir }
738
+ )
739
+ )
740
+ }
741
+
742
+ it('uses the bundled docs of a workspace package when run from the root', () => {
715
743
  setupWorkspace(['apps/*'], { 'apps/web': '16.4.0' })
716
- process.chdir(testProjectDir)
717
744
 
718
- await runAgentsMd({ output: 'AGENTS.md' })
745
+ const cliOutput = runFromWorkspaceRoot()
719
746
 
720
747
  const agentsMdPath = path.join(testProjectDir, 'AGENTS.md')
721
748
  expect(readIndex(agentsMdPath).root).toBe(
@@ -724,49 +751,49 @@ This is my project documentation.
724
751
  expect(
725
752
  fs.existsSync(path.join(resolveRoot(agentsMdPath), '01-app'))
726
753
  ).toBe(true)
727
- expect(pullDocsSpy).not.toHaveBeenCalled()
728
754
  expect(fs.existsSync(path.join(testProjectDir, '.next-docs'))).toBe(
729
755
  false
730
756
  )
731
757
  expect(fs.existsSync(path.join(testProjectDir, '.gitignore'))).toBe(
732
758
  false
733
759
  )
734
- expect(output()).toContain('workspace package apps/web')
760
+ expect(cliOutput).toContain('workspace package apps/web')
735
761
  })
736
762
 
737
- it('indexes the package with the highest Next.js version', async () => {
763
+ it('indexes the package with the highest Next.js version', () => {
738
764
  setupWorkspace(['apps/a', 'apps/b'], {
739
765
  'apps/a': '16.3.0',
740
766
  'apps/b': '16.4.0',
741
767
  })
742
- process.chdir(testProjectDir)
743
768
 
744
- await runAgentsMd({ output: 'AGENTS.md' })
769
+ const cliOutput = runFromWorkspaceRoot()
745
770
 
746
771
  const { root, content } = readIndex(
747
772
  path.join(testProjectDir, 'AGENTS.md')
748
773
  )
749
774
  expect(root).toBe('./apps/b/node_modules/next/dist/docs')
750
775
  expect(content).toContain('docs-16.4.0.md')
751
- expect(pullDocsSpy).not.toHaveBeenCalled()
776
+ expect(cliOutput).not.toContain('Downloading')
777
+ expect(fs.existsSync(path.join(testProjectDir, '.next-docs'))).toBe(
778
+ false
779
+ )
752
780
  })
753
781
 
754
- it('picks the first matching package in workspace order and logs it', async () => {
782
+ it('picks the first matching package in workspace order and logs it', () => {
755
783
  // Listed b before a, so the choice follows the workspace patterns
756
784
  // rather than alphabetical order.
757
785
  setupWorkspace(['apps/b', 'apps/a'], {
758
786
  'apps/a': '16.4.0',
759
787
  'apps/b': '16.4.0',
760
788
  })
761
- process.chdir(testProjectDir)
762
789
 
763
- await runAgentsMd({ output: 'AGENTS.md' })
790
+ const cliOutput = runFromWorkspaceRoot()
764
791
 
765
792
  expect(readIndex(path.join(testProjectDir, 'AGENTS.md')).root).toBe(
766
793
  './apps/b/node_modules/next/dist/docs'
767
794
  )
768
- expect(output()).toContain('workspace package apps/b')
769
- expect(output()).not.toContain('workspace package apps/a')
795
+ expect(cliOutput).toContain('workspace package apps/b')
796
+ expect(cliOutput).not.toContain('workspace package apps/a')
770
797
  })
771
798
 
772
799
  it('prefers a matching install resolved from the cwd', async () => {
@@ -840,9 +867,15 @@ This is my project documentation.
840
867
  })
841
868
 
842
869
  it('returns error when Next.js is not installed', () => {
843
- // Use a directory where next is not installed
844
- const nonNextDir = '/tmp'
845
- const result = getNextjsVersion(nonNextDir)
870
+ const result = JSON.parse(
871
+ execNodeWithoutNodePath(
872
+ `const { getNextjsVersion } = require(${JSON.stringify(
873
+ path.join(__dirname, '../agents-md.js')
874
+ )})
875
+ console.log(JSON.stringify(getNextjsVersion(process.cwd())))`,
876
+ { cwd: testProjectDir }
877
+ )
878
+ )
846
879
 
847
880
  expect(result.version).toBeNull()
848
881
  expect(result.error).toBe('Next.js is not installed in this project.')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/codemod",
3
- "version": "16.5.0-canary.10",
3
+ "version": "16.5.0-canary.12",
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": "./bin/next-codemod.js",
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",