forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix relative import path for type plugin in NX workspaces
Refs: vercel#44363, nrwl/nx#14558
- Loading branch information
Ian Serpa
committed
Apr 3, 2023
1 parent
0715118
commit 490c00a
Showing
2 changed files
with
96 additions
and
11 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
packages/next/src/build/webpack/plugins/next-types-plugin.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { NextTypesPlugin } from './next-types-plugin' | ||
|
||
describe('next-types-plugin', () => { | ||
it('should generate correct base import path', () => { | ||
const plugin = new NextTypesPlugin({ | ||
dir: '/Users/myself/myproject', | ||
distDir: '.next', | ||
appDir: '/Users/myself/myproject/app', | ||
dev: false, | ||
isEdgeServer: false, | ||
pageExtensions: ['tsx', 'ts', 'jsx', 'js'], | ||
typedRoutes: false, | ||
originalRewrites: undefined, | ||
originalRedirects: undefined, | ||
}) | ||
expect(plugin.getRelativePathFromAppTypesDir('page.tsx')).toEqual( | ||
'../../../app/page.tsx' | ||
) | ||
expect(plugin.getRelativePathFromAppTypesDir('layout.tsx')).toEqual( | ||
'../../../app/layout.tsx' | ||
) | ||
expect(plugin.getRelativePathFromAppTypesDir('test/page.tsx')).toEqual( | ||
'../../../../app/test/page.tsx' | ||
) | ||
expect( | ||
plugin.getRelativePathFromAppTypesDir('deeply/nested/page.tsx') | ||
).toEqual('../../../../../app/deeply/nested/page.tsx') | ||
}) | ||
|
||
it('should generate correct base import path for nx monorepos', () => { | ||
const plugin = new NextTypesPlugin({ | ||
dir: '/Users/myself/code/nx-monorepo/apps/myproject', | ||
distDir: '../../dist/apps/myproject/.next', | ||
appDir: '/Users/myself/code/nx-monorepo/apps/myproject/app', | ||
dev: false, | ||
isEdgeServer: false, | ||
pageExtensions: ['tsx', 'ts', 'jsx', 'js'], | ||
typedRoutes: false, | ||
originalRewrites: undefined, | ||
originalRedirects: undefined, | ||
}) | ||
expect(plugin.getRelativePathFromAppTypesDir('layout.tsx')).toEqual( | ||
'../../../../../../apps/myproject/app/layout.tsx' | ||
) | ||
expect(plugin.getRelativePathFromAppTypesDir('test/page.tsx')).toEqual( | ||
'../../../../../../../apps/myproject/app/test/page.tsx' | ||
) | ||
}) | ||
|
||
it('should generate correct base import path for custom projects', () => { | ||
const plugin = new NextTypesPlugin({ | ||
dir: '/Users/myself/code/custom-project/frontend/ui', | ||
distDir: '../dist/ui/.next', | ||
appDir: '/Users/myself/code/custom-project/frontend/ui/app', | ||
dev: false, | ||
isEdgeServer: false, | ||
pageExtensions: ['tsx', 'ts', 'jsx', 'js'], | ||
typedRoutes: false, | ||
originalRewrites: undefined, | ||
originalRedirects: undefined, | ||
}) | ||
expect(plugin.getRelativePathFromAppTypesDir('layout.tsx')).toEqual( | ||
'../../../../../ui/app/layout.tsx' | ||
) | ||
expect(plugin.getRelativePathFromAppTypesDir('test/page.tsx')).toEqual( | ||
'../../../../../../ui/app/test/page.tsx' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters