-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): update package-manager utils to normalize yarn-path when m…
…igrating (#17088)
- Loading branch information
1 parent
d030a21
commit c9ec7d0
Showing
3 changed files
with
195 additions
and
72 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,43 +1,87 @@ | ||
jest.mock('fs'); | ||
import * as fs from 'fs'; | ||
import * as configModule from '../config/configuration'; | ||
import { detectPackageManager } from './package-manager'; | ||
import { | ||
detectPackageManager, | ||
modifyYarnRcToFitNewDirectory, | ||
modifyYarnRcYmlToFitNewDirectory, | ||
} from './package-manager'; | ||
|
||
describe('package-manager', () => { | ||
it('should detect package manager in nxJson', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({ | ||
cli: { | ||
packageManager: 'pnpm', | ||
}, | ||
}); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('pnpm'); | ||
expect(fs.existsSync).not.toHaveBeenCalled(); | ||
}); | ||
describe('detectPackageManager', () => { | ||
it('should detect package manager in nxJson', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({ | ||
cli: { | ||
packageManager: 'pnpm', | ||
}, | ||
}); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('pnpm'); | ||
expect(fs.existsSync).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should detect yarn package manager from yarn.lock', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); | ||
(fs.existsSync as jest.Mock).mockReturnValueOnce(true); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('yarn'); | ||
expect(fs.existsSync).toHaveBeenNthCalledWith(1, 'yarn.lock'); | ||
}); | ||
|
||
it('should detect pnpm package manager from pnpm-lock.yaml', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); | ||
(fs.existsSync as jest.Mock).mockImplementation((path) => { | ||
return path === 'pnpm-lock.yaml'; | ||
}); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('pnpm'); | ||
expect(fs.existsSync).toHaveBeenCalledTimes(3); | ||
}); | ||
|
||
it('should detect yarn package manager from yarn.lock', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); | ||
(fs.existsSync as jest.Mock).mockReturnValueOnce(true); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('yarn'); | ||
expect(fs.existsSync).toHaveBeenNthCalledWith(1, 'yarn.lock'); | ||
it('should use npm package manager as default', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); | ||
(fs.existsSync as jest.Mock).mockReturnValue(false); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('npm'); | ||
expect(fs.existsSync).toHaveBeenCalledTimes(5); | ||
}); | ||
}); | ||
|
||
it('should detect pnpm package manager from pnpm-lock.yaml', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); | ||
(fs.existsSync as jest.Mock).mockImplementation((path) => { | ||
return path === 'pnpm-lock.yaml'; | ||
describe('modifyYarnRcYmlToFitNewDirectory', () => { | ||
it('should update paths properly', () => { | ||
expect( | ||
modifyYarnRcYmlToFitNewDirectory('yarnPath: ./bin/yarn.js') | ||
).toEqual(''); | ||
}); | ||
|
||
it('should update plugins appropriately', () => { | ||
expect( | ||
modifyYarnRcYmlToFitNewDirectory( | ||
[ | ||
'enableProgressBars: false', | ||
'plugins:', | ||
' - ./scripts/yarn-plugin.js', | ||
' - path: .yarn/plugins/imported-plugin.js', | ||
' spec: imported-plugin', | ||
].join('\n') | ||
) | ||
).toEqual('enableProgressBars: false\n'); | ||
}); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('pnpm'); | ||
expect(fs.existsSync).toHaveBeenCalledTimes(3); | ||
}); | ||
|
||
it('should use npm package manager as default', () => { | ||
jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); | ||
(fs.existsSync as jest.Mock).mockReturnValue(false); | ||
const packageManager = detectPackageManager(); | ||
expect(packageManager).toEqual('npm'); | ||
expect(fs.existsSync).toHaveBeenCalledTimes(5); | ||
describe('modifyYarnRcToFitNewDirectory', () => { | ||
it('should update paths properly', () => { | ||
expect(modifyYarnRcToFitNewDirectory('yarn-path ./bin/yarn.js')).toEqual( | ||
'' | ||
); | ||
}); | ||
|
||
it('should not update other options', () => { | ||
expect( | ||
modifyYarnRcToFitNewDirectory( | ||
['yarn-path ./bin/yarn.js', 'enableProgressBars false'].join('\n') | ||
) | ||
).toEqual('enableProgressBars false'); | ||
}); | ||
}); | ||
}); |
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
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
c9ec7d0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev