Skip to content

Commit

Permalink
fix(storybook): update storybook to 6.1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Dec 17, 2020
1 parent fcfc858 commit 399ceba
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/storybook/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"version": "10.3.1-beta.1",
"description": "Add missing storybook config to lint target",
"factory": "./src/migrations/update-10-3-0/update-10-3-0"
},
"update-11-0-12": {
"version": "11.0.12",
"description": "Update storybook if installed and above 6",
"factory": "./src/migrations/update-11-0-12/update-storybook"
}
},
"packageJsonUpdates": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Tree } from '@angular-devkit/schematics';
import { readJsonInTree, readWorkspace } from '@nrwl/workspace';
import { getFileContent } from '@nrwl/workspace/testing';

import { runMigration } from '../../utils/testing';

describe('Update 11-0-12', () => {
let tree: Tree;

beforeEach(async () => {
tree = Tree.empty();
});

it('should update storybook versions if storybook is already above 6', async () => {
tree.create(
'package.json',
JSON.stringify({
devDependencies: {
'@storybook/angular': '^6.0.0',
'@storybook/react': '^6.0.0',
'@storybook/addon-knobs': '^6.0.0',
},
})
);
const result = await runMigration('update-11-0-12', {}, tree);
expect(
readJsonInTree(result, 'package.json').devDependencies[
'@storybook/angular'
]
).toBe('^6.1.11');
});

it('should not update storybook versions if storybook is below 6', async () => {
tree.create(
'package.json',
JSON.stringify({
devDependencies: {
'@storybook/angular': '^5.0.0',
'@storybook/react': '^5.0.0',
'@storybook/addon-knobs': '^5.0.0',
},
})
);
const result = await runMigration('update-11-0-12', {}, tree);
expect(
readJsonInTree(result, 'package.json').devDependencies[
'@storybook/angular'
]
).toBe('^5.0.0');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { chain, SchematicContext, Tree } from '@angular-devkit/schematics';
import {
addInstallTask,
checkAndCleanWithSemver,
formatFiles,
updateJsonInTree,
} from '@nrwl/workspace';

import { gte } from 'semver';
let needsInstall = false;

const maybeUpdateVersion = updateJsonInTree('package.json', (json) => {
json.dependencies = json.dependencies || {};
json.devDependencies = json.devDependencies || {};

const storybookPackages = [
'@storybook/angular',
'@storybook/react',
'@storybook/addon-knobs',
];
storybookPackages.forEach((storybookPackageName) => {
if (json.dependencies[storybookPackageName]) {
const version = checkAndCleanWithSemver(
storybookPackageName,
json.dependencies[storybookPackageName]
);
if (gte(version, '6.0.0')) {
json.dependencies[storybookPackageName] = '^6.1.11';
needsInstall = true;
}
}
if (json.devDependencies[storybookPackageName]) {
const version = checkAndCleanWithSemver(
storybookPackageName,
json.devDependencies[storybookPackageName]
);
if (gte(version, '6.0.0')) {
json.devDependencies[storybookPackageName] = '^6.1.11';
needsInstall = true;
}
}
});

return json;
});

export default function (tree: Tree, context: SchematicContext) {
return chain([
maybeUpdateVersion,
formatFiles(),
addInstallTask({ skipInstall: !needsInstall }),
]);
}
2 changes: 1 addition & 1 deletion packages/storybook/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const nxVersion = '*';
export const storybookVersion = '^6.0.21';
export const storybookVersion = '^6.1.11';
export const babelCoreVersion = '7.9.6';
export const babelLoaderVersion = '8.1.0';
export const babelPresetTypescriptVersion = '7.9.0';
Expand Down

0 comments on commit 399ceba

Please sign in to comment.