mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-02 05:03:44 +08:00
fix(cli): fix computation of Angular version in sb init
`packageManager.getVersion` was fetching the latest version from npm registry instead of checking the version installed locally.
This commit is contained in:
parent
5de8ca626e
commit
1497a4773e
@ -33,7 +33,9 @@ const generator: Generator = async (packageManager, npmOptions, options) => {
|
||||
'Could not find a default project in your Angular workspace.\nSet a defaultProject in your angular.json and re-run the installation.'
|
||||
);
|
||||
}
|
||||
const angularVersion = semver.coerce(await packageManager.getVersion('@angular/core'))?.version;
|
||||
const angularVersion = semver.coerce(
|
||||
packageManager.retrievePackageJson().dependencies['@angular/core']
|
||||
)?.version;
|
||||
const isWebpack5 = semver.gte(angularVersion, '12.0.0');
|
||||
const updatedOptions = isWebpack5 ? { ...options, builder: CoreBuilder.Webpack5 } : options;
|
||||
|
||||
|
@ -55,6 +55,10 @@ export abstract class JsPackageManager {
|
||||
done();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the `package.json` file available in the directory the command was call from
|
||||
* If there is no `package.json` it will create one.
|
||||
*/
|
||||
public retrievePackageJson(): PackageJsonWithDepsAndDevDeps {
|
||||
let packageJson = readPackageJson();
|
||||
if (!packageJson) {
|
||||
@ -151,6 +155,15 @@ export abstract class JsPackageManager {
|
||||
return Promise.all(packageNames.map((packageName) => this.getVersion(packageName)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the latest version of the input package available on npmjs registry.
|
||||
* If constraint are provided it return the latest version matching the constraints.
|
||||
*
|
||||
* For `@storybook/*` packages the latest version is retrieved from `cli/src/versions.json` file directly
|
||||
*
|
||||
* @param packageName The name of the package
|
||||
* @param constraint A valid semver constraint, example: '1.x || >=2.5.0 || 5.0.0 - 7.2.3'
|
||||
*/
|
||||
public async getVersion(packageName: string, constraint?: string): Promise<string> {
|
||||
let current: string;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user