-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into tom/sb-415-return-cleanup-function-from-rend…
…ertodom
- Loading branch information
Showing
5 changed files
with
127 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { NPMProxy } from '../../js-package-manager/NPMProxy'; | ||
import { npm7 } from './npm7'; | ||
|
||
const mockExecuteCommand = jest.fn(); | ||
class MockedNPMProxy extends NPMProxy { | ||
executeCommand(...args) { | ||
return mockExecuteCommand(...args); | ||
} | ||
} | ||
|
||
function mockExecuteResults(map: Record<string, string>) { | ||
mockExecuteCommand.mockImplementation((command, args) => { | ||
const commandString = `${command} ${args.join(' ')}`; | ||
if (map[commandString]) return map[commandString]; | ||
|
||
throw new Error(`Unexpected execution of '${commandString}'`); | ||
}); | ||
} | ||
|
||
describe('npm7 fix', () => { | ||
describe('npm < 7', () => { | ||
it('does not match', async () => { | ||
mockExecuteResults({ 'npm --version': '6.0.0' }); | ||
expect(await npm7.check({ packageManager: new MockedNPMProxy() })).toEqual(null); | ||
}); | ||
}); | ||
|
||
describe('npm 7+', () => { | ||
it('matches if config is not installed', async () => { | ||
mockExecuteResults({ | ||
'npm --version': '7.0.0', | ||
'npm config get legacy-peer-deps --location=project': 'false', | ||
}); | ||
expect(await npm7.check({ packageManager: new MockedNPMProxy() })).toEqual({ | ||
npmVersion: '7.0.0', | ||
}); | ||
}); | ||
|
||
it('does not match if config is installed', async () => { | ||
mockExecuteResults({ | ||
'npm --version': '7.0.0', | ||
'npm config get legacy-peer-deps --location=project': 'true', | ||
}); | ||
expect(await npm7.check({ packageManager: new MockedNPMProxy() })).toEqual(null); | ||
}); | ||
}); | ||
}); |
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,41 @@ | ||
import chalk from 'chalk'; | ||
import dedent from 'ts-dedent'; | ||
import { Fix } from '../types'; | ||
import { NPMProxy } from '../../js-package-manager/NPMProxy'; | ||
|
||
interface Npm7RunOptions { | ||
npmVersion: string; | ||
} | ||
|
||
/** | ||
* Is the user using npm7+? If so create a .npmrc with legacy-peer-deps=true | ||
*/ | ||
export const npm7: Fix<Npm7RunOptions> = { | ||
id: 'npm7', | ||
|
||
async check({ packageManager }) { | ||
if (packageManager.type !== 'npm') return null; | ||
|
||
const npmVersion = (packageManager as NPMProxy).getNpmVersion(); | ||
if ((packageManager as NPMProxy).needsLegacyPeerDeps(npmVersion)) { | ||
return { npmVersion }; | ||
} | ||
return null; | ||
}, | ||
|
||
prompt({ npmVersion }) { | ||
const npmFormatted = chalk.cyan(`npm ${npmVersion}`); | ||
return dedent` | ||
We've detected you are running ${npmFormatted} which has peer dependency semantics which Storybook is incompatible with. | ||
In order to work with Storybook's package structure, you'll need to run \`npm\` with the | ||
\`--legacy-peer-deps=true\` flag. We can generate an \`.npmrc\` which will do that automatically. | ||
More info: ${chalk.yellow('https://github.com/storybookjs/storybook/issues/18298')} | ||
`; | ||
}, | ||
|
||
async run({ packageManager }) { | ||
(packageManager as NPMProxy).setLegacyPeerDeps(); | ||
}, | ||
}; |
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