From 77706cb3604a6cee1e7843e636e2ead290a9af8c Mon Sep 17 00:00:00 2001 From: FrozenPandaz Date: Tue, 10 Oct 2023 18:50:39 -0400 Subject: [PATCH] feat(misc): remove additional migrations manually --- packages/linter/package.json | 1 - packages/nest/package.json | 2 - .../update-13-1-1/enable-swc.spec.ts | 203 --------- .../migrations/update-13-1-1/enable-swc.ts | 62 --- .../update-14-5-7/update-next-eslint.spec.ts | 60 --- .../update-14-5-7/update-next-eslint.ts | 28 -- packages/node/package.json | 3 +- .../remove-deprecated-options-13-0-0.spec.ts | 52 --- .../remove-deprecated-options-13-0-0.ts | 45 -- .../migrations/update-12-8-0/update-12-8-0.ts | 13 - .../webpack5-changes-utils.spec.ts | 61 --- .../update-13-0-0/webpack5-changes-utils.ts | 330 -------------- packages/storybook/package.json | 3 +- .../test-configs/custom-names-config.json | 146 ------- .../test-configs/default-config.json | 146 ------- .../test-configs/non-angular.json | 60 --- .../migrate-defaults-5-to-6.spec.ts | 165 ------- .../migrate-defaults-5-to-6.ts | 210 --------- .../migrate-stories-to-6-2.spec.ts | 171 -------- .../migrate-stories-to-6-2.ts | 406 ------------------ ...change-storybook-targets-generator.spec.ts | 63 --- .../change-storybook-targets-generator.ts | 173 -------- .../test-configs/custom-names-config.json | 154 ------- .../test-configs/default-config.json | 154 ------- .../extra-options-for-storybook.json | 222 ---------- .../no-build-storybook-target.json | 60 --- .../test-configs/no-storybook-targets.json | 34 -- .../test-configs/non-angular.json | 60 --- .../remove-deprecated-options-13-0-0.spec.ts | 54 --- .../remove-deprecated-options-13-0-0.ts | 39 -- ...lup-format-backwards-compatibility.spec.ts | 54 --- .../rollup-format-backwards-compatibility.ts | 24 -- .../update-13-9-0/update-decorate-cli.ts | 13 - 33 files changed, 2 insertions(+), 3269 deletions(-) delete mode 100644 packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts delete mode 100644 packages/next/src/migrations/update-13-1-1/enable-swc.ts delete mode 100644 packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts delete mode 100644 packages/next/src/migrations/update-14-5-7/update-next-eslint.ts delete mode 100644 packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts delete mode 100644 packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts delete mode 100644 packages/react/src/migrations/update-12-8-0/update-12-8-0.ts delete mode 100644 packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.spec.ts delete mode 100644 packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts delete mode 100644 packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json delete mode 100644 packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json delete mode 100644 packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json delete mode 100644 packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts delete mode 100644 packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts delete mode 100644 packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts delete mode 100644 packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts delete mode 100644 packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.spec.ts delete mode 100644 packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.ts delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/custom-names-config.json delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/default-config.json delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/extra-options-for-storybook.json delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/no-build-storybook-target.json delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/no-storybook-targets.json delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/non-angular.json delete mode 100644 packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts delete mode 100644 packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts delete mode 100644 packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.spec.ts delete mode 100644 packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.ts delete mode 100644 packages/workspace/src/migrations/update-13-9-0/update-decorate-cli.ts diff --git a/packages/linter/package.json b/packages/linter/package.json index 1229ee6600ec24..93341f1e5866d5 100644 --- a/packages/linter/package.json +++ b/packages/linter/package.json @@ -33,7 +33,6 @@ "eslint": "^8.0.0" }, "dependencies": { - "@phenomnomnominal/tsquery": "~5.0.1", "tslib": "^2.3.0", "@nx/devkit": "file:../devkit", "@nx/js": "file:../js", diff --git a/packages/nest/package.json b/packages/nest/package.json index fb9eeac789a24e..dc6b924ab48d59 100644 --- a/packages/nest/package.json +++ b/packages/nest/package.json @@ -31,13 +31,11 @@ }, "dependencies": { "@nestjs/schematics": "^9.1.0", - "enquirer": "~2.3.6", "@nx/devkit": "file:../devkit", "@nx/js": "file:../js", "@nx/linter": "file:../linter", "@nx/node": "file:../node", "@phenomnomnominal/tsquery": "~5.0.1", - "semver": "7.5.3", "tslib": "^2.3.0" }, "publishConfig": { diff --git a/packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts b/packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts deleted file mode 100644 index d6fa07ed81ed1d..00000000000000 --- a/packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts +++ /dev/null @@ -1,203 +0,0 @@ -import { - readProjectConfiguration, - Tree, - updateJson, - updateProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import { applicationGenerator } from '../../generators/application/application'; -import { update } from './enable-swc'; - -describe('Migration: enable SWC', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should remove .babelrc file and fix jest config', async () => { - await applicationGenerator(tree, { - style: 'none', - name: 'demo', - skipFormat: false, - swc: false, - }); - - updateJson(tree, 'apps/demo/.babelrc', (json) => { - json.presets[0] = '@nrwl/next/babel'; - - return json; - }); - - // rename jest config to js as that was standard at this version of nx - tree.delete('apps/demo/jest.config.ts'); - updateProjectConfiguration(tree, 'demo', { - ...readProjectConfiguration(tree, 'demo'), - targets: { - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/demo/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - - // Config that isn't configured properly - tree.write( - 'apps/demo/jest.config.js', - ` -module.exports = { - displayName: 'napp4', - preset: '../../jest.preset.js', - transform: { - '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest', - '^.+\\\\.[tj]sx?$': 'babel-jest', - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/apps/demo', -}; - -` - ); - - await update(tree); - - const result = tree.read('apps/demo/jest.config.js').toString(); - - expect(result).toMatch(`['babel-jest', { presets: ['@nrwl/next/babel'] }]`); - - expect(tree.exists('apps/demo/.babelrc')).toBe(false); - }); - - it('should still fix jest config when babelrc is missing', async () => { - await applicationGenerator(tree, { - style: 'none', - name: 'demo', - skipFormat: false, - swc: true, - }); - // rename jest config to js as that was standard at this version of nx - tree.delete('apps/demo/jest.config.ts'); - updateProjectConfiguration(tree, 'demo', { - ...readProjectConfiguration(tree, 'demo'), - targets: { - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/demo/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - // Config that isn't configured properly - tree.write( - 'apps/demo/jest.config.js', - ` -module.exports = { - displayName: 'napp4', - preset: '../../jest.preset.js', - transform: { - '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest', - '^.+\\\\.[tj]sx?$': 'babel-jest', - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/apps/demo', -}; - -` - ); - - await update(tree); - - const result = tree.read('apps/demo/jest.config.js').toString(); - - expect(result).toMatch(`['babel-jest', { presets: ['@nrwl/next/babel'] }]`); - }); - it('should skip migration if the babelrc has been customized', async () => { - await applicationGenerator(tree, { - style: 'none', - name: 'demo', - skipFormat: false, - swc: false, - }); - // rename jest config to js as that was standard at this version of nx - tree.rename('apps/demo/jest.config.ts', 'apps/demo/jest.config.js'); - updateProjectConfiguration(tree, 'demo', { - ...readProjectConfiguration(tree, 'demo'), - targets: { - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/demo/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - tree.write( - 'apps/demo/.babelrc', - `{ - "presets": ["@nrwl/next/babel", "something-else"], - "plugins": [] - }` - ); - - await update(tree); - - expect(tree.exists('apps/demo/.babelrc')).toBe(true); - - tree.write( - 'apps/demo/.babelrc', - `{ - "presets": ["@nrwl/next/babel"], - "plugins": ["some-plugin"] - }` - ); - - await update(tree); - - expect(tree.exists('apps/demo/.babelrc')).toBe(true); - - // No custom plugins, can migrate. - tree.write( - 'apps/demo/.babelrc', - `{ - "presets": ["@nrwl/next/babel"] - }` - ); - - await update(tree); - - expect(tree.exists('apps/demo/.babelrc')).toBe(false); - }); - - it('should skip migration if storybook configuration is detected', async () => { - await applicationGenerator(tree, { - style: 'none', - name: 'demo', - skipFormat: false, - swc: false, - }); - - tree.write( - 'apps/demo/.babelrc', - `{ - "presets": ["@nrwl/next/babel"] - }` - ); - tree.write( - 'apps/demo/.storybook/main.js', - `module.exports = { - stories: [] - }` - ); - - await update(tree); - - expect(tree.exists('apps/demo/.babelrc')).toBe(true); - }); -}); diff --git a/packages/next/src/migrations/update-13-1-1/enable-swc.ts b/packages/next/src/migrations/update-13-1-1/enable-swc.ts deleted file mode 100644 index 2b544e57416a85..00000000000000 --- a/packages/next/src/migrations/update-13-1-1/enable-swc.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { - formatFiles, - getProjects, - joinPathFragments, - logger, - readJson, - Tree, -} from '@nx/devkit'; - -export async function update(host: Tree) { - const projects = getProjects(host); - - projects.forEach((project) => { - const nextConfigPath = joinPathFragments(project.root, 'next.config.js'); - const jestConfigPath = joinPathFragments(project.root, 'jest.config.js'); - const babelConfigPath = joinPathFragments(project.root, '.babelrc'); - const storybookMainPath = joinPathFragments( - project.root, - '.storybook/main.js' - ); - - if (!host.exists(nextConfigPath) || !host.exists(jestConfigPath)) return; - - if (host.exists(babelConfigPath)) { - if (customBabelConfig(host, babelConfigPath)) { - logger.info( - `NX Custom .babelrc file detected, skipping deletion. You can delete this file yourself to enable SWC: ${babelConfigPath}` - ); - } else if (host.exists(storybookMainPath)) { - logger.info( - `NX Storybook configuration for project "${project.name}" detected, skipping deletion of .babelrc` - ); - } else { - // Deleting custom babel config enables SWC - host.delete(babelConfigPath); - } - } - - const content = host.read(jestConfigPath).toString(); - - if (content.match(/:\s+'babel-jest'/)) { - const updated = content.replace( - /:\s+'babel-jest'/, - `: ['babel-jest', { presets: ['@nrwl/next/babel'] }]` - ); - host.write(jestConfigPath, updated); - } - }); - - await formatFiles(host); -} - -function customBabelConfig(host, configPath) { - const json = readJson(host, configPath); - return !( - json.presets?.length === 1 && - json.presets?.[0] === '@nrwl/next/babel' && - (json.plugins?.length === 0 || !json.plugins) - ); -} - -export default update; diff --git a/packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts b/packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts deleted file mode 100644 index e3387e42639305..00000000000000 --- a/packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { updateNextEslint } from './update-next-eslint'; - -describe('Add next eslint 14.5.7', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'app1', { - root: 'apps/app1', - targets: { - build: { - executor: '@nrwl/next:build', - }, - }, - }); - - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - app1: {}, - }, - }) - ); - }); - - it('should update "next" config ignorePattern', async () => { - tree.write( - 'apps/app1/.eslintrc.json', - JSON.stringify({ - extends: ['../../.eslintrc.json'], - ignorePatterns: ['!**/*'], - }) - ); - - await updateNextEslint(tree); - - const result = readJson(tree, 'apps/app1/.eslintrc.json'); - expect(result.ignorePatterns).toContain('.next/**/*'); - }); - - it('should not update "next" config ignorePattern if .next pattern already exists', async () => { - tree.write( - 'apps/app1/.eslintrc.json', - JSON.stringify({ - extends: ['../../.eslintrc.json'], - ignorePatterns: ['!**/*', '.next/**/*', '/foo/bar'], - }) - ); - const before = readJson(tree, 'apps/app1/.eslintrc.json'); - - await updateNextEslint(tree); - - const result = readJson(tree, 'apps/app1/.eslintrc.json'); - expect(result.ignorePatterns).toEqual(before.ignorePatterns); - }); -}); diff --git a/packages/next/src/migrations/update-14-5-7/update-next-eslint.ts b/packages/next/src/migrations/update-14-5-7/update-next-eslint.ts deleted file mode 100644 index 3abb242c4b2105..00000000000000 --- a/packages/next/src/migrations/update-14-5-7/update-next-eslint.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { formatFiles, getProjects, Tree, updateJson } from '@nx/devkit'; - -export async function updateNextEslint(host: Tree) { - const projects = getProjects(host); - - projects.forEach((project) => { - if (project.targets?.build?.executor !== '@nrwl/next:build') return; - - const eslintPath = `${project.root}/.eslintrc.json`; - - if (!host.exists(eslintPath)) return; - - updateJson(host, eslintPath, (eslintConfig) => { - const nextIgnorePattern = '.next/**/*'; - - if (eslintConfig.ignorePatterns.indexOf(nextIgnorePattern) < 0) { - eslintConfig.ignorePatterns = [ - ...eslintConfig.ignorePatterns, - nextIgnorePattern, - ]; - } - return eslintConfig; - }); - }); - await formatFiles(host); -} - -export default updateNextEslint; diff --git a/packages/node/package.json b/packages/node/package.json index e7d94a1a382d4b..46385595acadfd 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -34,8 +34,7 @@ "@nx/devkit": "file:../devkit", "@nx/jest": "file:../jest", "@nx/js": "file:../js", - "@nx/linter": "file:../linter", - "@nx/workspace": "file:../workspace" + "@nx/linter": "file:../linter" }, "publishConfig": { "access": "public" diff --git a/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts b/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts deleted file mode 100644 index 433db02429f767..00000000000000 --- a/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import subject from './remove-deprecated-options-13-0-0'; - -describe('Migration: Remove deprecated options', () => { - it(`should remove deprecated node build options`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/node:build', - options: { - showCircularDependencies: false, - }, - configurations: { - production: { - showCircularDependencies: true, - }, - }, - }, - }, - }); - - await subject(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/node:build', - options: {}, - configurations: { - production: {}, - }, - }, - }, - }); - }); -}); diff --git a/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts b/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts deleted file mode 100644 index 0eae99eefc1b2c..00000000000000 --- a/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { - formatFiles, - getProjects, - logger, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -export default async function update(host: Tree) { - const projects = getProjects(host); - - for (const [name, config] of projects.entries()) { - if (config.targets.build.executor !== '@nrwl/node:build') return; - - let updated = false; - - if ( - typeof config.targets.build?.configurations?.production?.[ - 'showCircularDependencies' - ] !== 'undefined' - ) { - delete config.targets.build.configurations.production[ - 'showCircularDependencies' - ]; - updated = true; - } - - if ( - typeof config.targets.build?.options?.['showCircularDependencies'] !== - 'undefined' - ) { - delete config.targets.build.options['showCircularDependencies']; - updated = true; - } - - if (updated) { - updateProjectConfiguration(host, name, config); - logger.info( - `NX Removed legacy build option from "${name}": showCircularDependencies` - ); - } - } - - await formatFiles(host); -} diff --git a/packages/react/src/migrations/update-12-8-0/update-12-8-0.ts b/packages/react/src/migrations/update-12-8-0/update-12-8-0.ts deleted file mode 100644 index 03a416eef3160b..00000000000000 --- a/packages/react/src/migrations/update-12-8-0/update-12-8-0.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { addDependenciesToPackageJson, Tree } from '@nx/devkit'; - -export async function removeReactReduxTypesFromPackageJson(host: Tree) { - return addDependenciesToPackageJson( - host, - {}, - { - '@testing-library/react-hooks': '^7.0.1', - } - ); -} - -export default removeReactReduxTypesFromPackageJson; diff --git a/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.spec.ts b/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.spec.ts deleted file mode 100644 index 0a3dc242406c7b..00000000000000 --- a/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { addProjectConfiguration, Tree, updateJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { allReactProjectsWithStorybookConfiguration } from './webpack5-changes-utils'; - -describe('webpack5ChangesUtils', () => { - let tree: Tree; - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should get project name and storybook configuration for all react projects', () => { - addProjectConfiguration(tree, 'test-one', { - root: 'libs/test-one', - targets: { - storybook: { - options: { - uiFramework: '@storybook/react', - config: { - configFolder: 'libs/test-one/.storybook', - }, - }, - }, - }, - }); - addProjectConfiguration(tree, 'test-two', { - root: 'libs/test-two', - targets: { - storybook: { - options: { - uiFramework: '@storybook/react', - config: { - configFolder: 'libs/test-two/.storybook', - }, - }, - }, - }, - }); - const allReactProjects = allReactProjectsWithStorybookConfiguration(tree); - - expect(allReactProjects).toMatchSnapshot(); - }); - - it('should ignore non-react projects with storybook configuration', () => { - addProjectConfiguration(tree, 'test-one', { - root: 'libs/test-one', - targets: { - storybook: { - options: { - uiFramework: '@storybook/angular', - config: { - configFolder: 'libs/test-one/.storybook', - }, - }, - }, - }, - }); - - const allReactProjects = allReactProjectsWithStorybookConfiguration(tree); - expect(allReactProjects.length).toBe(0); - }); -}); diff --git a/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts b/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts deleted file mode 100644 index 7a644be0a334de..00000000000000 --- a/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts +++ /dev/null @@ -1,330 +0,0 @@ -import { getProjects, Tree } from '@nx/devkit'; -import { - logger, - formatFiles, - applyChangesToString, - ChangeType, -} from '@nx/devkit'; - -import ts = require('typescript'); -import { findNodes } from '@nx/js'; - -export async function migrateToWebPack5(tree: Tree) { - allReactProjectsWithStorybookConfiguration(tree).forEach((project) => { - let storybookConfigFile = `${project.storybookConfigPath}/main.js`; - if (!tree.exists(storybookConfigFile)) { - // try to see whether there's a main.ts file - storybookConfigFile = `${project.storybookConfigPath}/main.ts`; - } - - if (!tree.exists(storybookConfigFile)) { - // ok...give up - return; - } - - editProjectMainJs(tree, storybookConfigFile, project.projectName); - }); - await formatFiles(tree); -} - -export function workspaceHasStorybookForReact( - packageJson: any -): string | undefined { - return ( - packageJson.dependencies['@storybook/react'] || - packageJson.devDependencies['@storybook/react'] - ); -} - -export function allReactProjectsWithStorybookConfiguration(tree: Tree): { - projectName: string; - storybookConfigPath: string; -}[] { - const projects = getProjects(tree); - const reactProjectsThatHaveStorybookConfiguration: { - projectName: string; - storybookConfigPath: string; - }[] = [...projects.entries()] - ?.filter( - ([_, projectConfig]) => - projectConfig.targets && - projectConfig.targets.storybook && - projectConfig.targets.storybook.options - ) - ?.map(([projectName, projectConfig]) => { - if ( - projectConfig.targets && - projectConfig.targets.storybook && - projectConfig.targets.storybook.options?.config?.configFolder && - projectConfig.targets.storybook.options?.uiFramework === - '@storybook/react' - ) { - return { - projectName, - storybookConfigPath: - projectConfig.targets.storybook.options.config.configFolder, - }; - } - }) - ?.filter((entry) => !!entry); - return reactProjectsThatHaveStorybookConfiguration; -} - -export function editProjectMainJs( - tree: Tree, - projectMainJsFile: string, - projectName: string -) { - let newContents: string; - let moduleExportsIsEmptyOrNonExistentOrInvalid = false; - let alreadyHasBuilder: any; - const rootMainJsExists = tree.exists(projectMainJsFile); - let moduleExportsFull: ts.Node[] = []; - - if (rootMainJsExists) { - const file = getTsSourceFile(tree, projectMainJsFile); - const appFileContent = tree.read(projectMainJsFile, 'utf-8'); - newContents = appFileContent; - moduleExportsFull = findNodes(file, [ts.SyntaxKind.ExpressionStatement]); - - if (moduleExportsFull && moduleExportsFull[0]) { - const moduleExports = moduleExportsFull[0]; - - const listOfStatements = findNodes(moduleExports, [ - ts.SyntaxKind.SyntaxList, - ]); - - /** - * Keep the index of the stories node - * to put the core object before it - * if it does not exist already - */ - - let indexOfStoriesNode = -1; - - const hasCoreObject = listOfStatements[0]?.getChildren()?.find((node) => { - if ( - node && - node.getText().length > 0 && - indexOfStoriesNode < 0 && - node?.getText().startsWith('stories') - ) { - indexOfStoriesNode = node.getStart(); - } - return ( - node?.kind === ts.SyntaxKind.PropertyAssignment && - node?.getText().startsWith('core') - ); - }); - - if (hasCoreObject) { - const contentsOfCoreNode = hasCoreObject.getChildren().find((node) => { - return node.kind === ts.SyntaxKind.ObjectLiteralExpression; - }); - const everyAttributeInsideCoreNode = contentsOfCoreNode - .getChildren() - .find((node) => node.kind === ts.SyntaxKind.SyntaxList); - - alreadyHasBuilder = everyAttributeInsideCoreNode - .getChildren() - .find((node) => node.getText() === "builder: 'webpack5'"); - - if (!alreadyHasBuilder) { - newContents = applyChangesToString(newContents, [ - { - type: ChangeType.Insert, - index: contentsOfCoreNode.getEnd() - 1, - text: ", builder: 'webpack5'", - }, - ]); - } - } else if (indexOfStoriesNode >= 0) { - /** - * Does not have core object, - * so just write one, at the start. - */ - newContents = applyChangesToString(newContents, [ - { - type: ChangeType.Insert, - index: indexOfStoriesNode - 1, - text: "core: { ...rootMain.core, builder: 'webpack5' }, ", - }, - ]); - } else { - /** - * Module exports is empty or does not - * contain stories - most probably invalid - */ - moduleExportsIsEmptyOrNonExistentOrInvalid = true; - } - } else { - /** - * module.exports does not exist - */ - moduleExportsIsEmptyOrNonExistentOrInvalid = true; - } - } else { - moduleExportsIsEmptyOrNonExistentOrInvalid = true; - } - - if (moduleExportsIsEmptyOrNonExistentOrInvalid) { - const usesOldSyntax = checkMainJsForOldSyntax( - moduleExportsFull, - newContents - ); - if (moduleExportsFull.length > 0 && usesOldSyntax) { - newContents = usesOldSyntax; - tree.write(projectMainJsFile, newContents); - return; - } else { - logger.info( - `Please configure Storybook for project "${projectName}"", since it has not been configured properly.` - ); - return; - } - } - - if (!alreadyHasBuilder) { - tree.write(projectMainJsFile, newContents); - } -} - -export function checkMainJsForOldSyntax( - nodeList: ts.Node[], - fileContent: string -): string | undefined { - let alreadyContainsBuilder = false; - let coreNode: ts.Node | undefined; - let hasCoreNode = false; - const lastIndexOfFirstNode = nodeList[0].getEnd(); - - if (!fileContent.includes('stories.push') || nodeList.length === 0) { - return undefined; - } - - // Go through the node list and find if the core object exists - // If it does, then we need to check if it has the builder property - // If it does not, then we need to add it - for (let topNode of nodeList) { - if ( - topNode.kind === ts.SyntaxKind.ExpressionStatement && - topNode.getChildren()?.length > 0 - ) { - for (let node of topNode.getChildren()) { - if ( - node.kind === ts.SyntaxKind.BinaryExpression && - node.getChildren()?.length - ) { - for (let childNode of node.getChildren()) { - if ( - childNode.kind === ts.SyntaxKind.PropertyAccessExpression && - childNode.getChildren()?.length - ) { - for (let grandChildNode of childNode.getChildren()) { - if ( - grandChildNode.kind === ts.SyntaxKind.Identifier && - grandChildNode.getText() === 'core' - ) { - coreNode = node; - hasCoreNode = true; - break; - } - } - } - if (hasCoreNode) { - break; - } - } - } - if (hasCoreNode) { - if (coreNode.getChildren()?.length) { - for (let coreChildNode of coreNode.getChildren()) { - if ( - coreChildNode.kind === ts.SyntaxKind.ObjectLiteralExpression && - coreChildNode.getChildren()?.length - ) { - for (let coreChildNodeChild of coreChildNode.getChildren()) { - if (coreChildNodeChild.kind === ts.SyntaxKind.SyntaxList) { - for (let coreChildNodeGrandChild of coreChildNodeChild.getChildren()) { - if ( - coreChildNodeGrandChild.kind === - ts.SyntaxKind.PropertyAssignment && - coreChildNodeGrandChild.getText().startsWith('builder') - ) { - for (let coreChildNodeGrandChildChild of coreChildNodeGrandChild.getChildren()) { - if ( - coreChildNodeGrandChildChild.kind === - ts.SyntaxKind.StringLiteral && - coreChildNodeGrandChildChild.getText() === - 'webpack5' - ) { - alreadyContainsBuilder = true; - break; - } - } - } - if (alreadyContainsBuilder) { - break; - } - } - } - if (alreadyContainsBuilder) { - break; - } - } - } - if (alreadyContainsBuilder) { - break; - } - } - } - break; - } - } - } - if (hasCoreNode) { - if (alreadyContainsBuilder) { - break; - } else { - // Add builder - const indexOfCoreNodeEnd = coreNode.getEnd(); - fileContent = applyChangesToString(fileContent, [ - { - type: ChangeType.Insert, - index: indexOfCoreNodeEnd - 1, - text: ", builder: 'webpack5'", - }, - ]); - break; - } - } - } - - if (!hasCoreNode) { - fileContent = applyChangesToString(fileContent, [ - { - type: ChangeType.Insert, - index: lastIndexOfFirstNode + 1, - text: "rootMain.core = { ...rootMain.core, builder: 'webpack5' };\n", - }, - ]); - } - - return fileContent; -} - -export function getTsSourceFile(host: Tree, path: string): ts.SourceFile { - const buffer = host.read(path); - if (!buffer) { - throw new Error(`Could not read TS file (${path}).`); - } - const content = buffer.toString(); - const source = ts.createSourceFile( - path, - content, - ts.ScriptTarget.Latest, - true - ); - - return source; -} diff --git a/packages/storybook/package.json b/packages/storybook/package.json index 7828c521f8c09f..bcf6a7f76af9ce 100644 --- a/packages/storybook/package.json +++ b/packages/storybook/package.json @@ -36,8 +36,7 @@ "@nx/cypress": "file:../cypress", "@nx/devkit": "file:../devkit", "@nx/js": "file:../js", - "@nx/linter": "file:../linter", - "@nx/workspace": "file:../workspace" + "@nx/linter": "file:../linter" }, "publishConfig": { "access": "public" diff --git a/packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json b/packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json deleted file mode 100644 index 492fb8d1cd54fe..00000000000000 --- a/packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json +++ /dev/null @@ -1,146 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "trthrngb": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - } - } - }, - "asdgsdfg": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": { - "sdft": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/two/.storybook" - } - } - }, - "thjkkb": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/two", - "config": { - "configFolder": "libs/ui/two/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": { - "nmkgd": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/three/.storybook" - } - } - }, - "aaaa": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/three", - "config": { - "configFolder": "libs/ui/three/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "architect": { - "njdfvndfjnv": { - "builder": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "lmfkcn": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - }, - "odmwjbc": { - "builder": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/main-app", - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json b/packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json deleted file mode 100644 index 439d649ab46048..00000000000000 --- a/packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json +++ /dev/null @@ -1,146 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": { - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/two/.storybook" - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/two", - "config": { - "configFolder": "libs/ui/two/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": { - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/three/.storybook" - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/three", - "config": { - "configFolder": "libs/ui/three/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "architect": { - "build": { - "builder": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - }, - "build-storybook": { - "builder": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/main-app", - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json b/packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json deleted file mode 100644 index db81e6f3015269..00000000000000 --- a/packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/react", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "architect": { - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/react", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts deleted file mode 100644 index dce09acf85934d..00000000000000 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts +++ /dev/null @@ -1,165 +0,0 @@ -import { - readJson, - readProjectConfiguration, - Tree, - updateJson, - updateProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { storybookVersion } from '../../../utils/versions'; -import configurationGenerator from '../../../generators/configuration/configuration'; -import { - createTestUILibNoNgDevkit, - deleteNewConfigurationAndCreateNew, -} from '../../../utils/testing'; -import { migrateDefaultsGenerator } from './migrate-defaults-5-to-6'; - -// nested code imports graph from the repo, which might have innacurate graph version -jest.mock('nx/src/project-graph/project-graph', () => ({ - ...jest.requireActual('nx/src/project-graph/project-graph'), - createProjectGraphAsync: jest - .fn() - .mockImplementation(async () => ({ nodes: {}, dependencies: {} })), -})); - -describe('migrate-defaults-5-to-6 Generator', () => { - let appTree: Tree; - - beforeEach(async () => { - appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(appTree, 'package.json', (json) => { - return { - ...json, - devDependencies: { - ...json.devDependencies, - '@nrwl/storybook': '10.4.0', - '@nrwl/workspace': '10.4.0', - '@storybook/addon-knobs': '^5.3.8', - '@storybook/angular': '^5.3.8', - '@storybook/addon-notes': '5.3.21', - '@storybook/addon-postcss': '2.0.0', - }, - }; - }); - await createTestUILibNoNgDevkit(appTree, 'test-ui-lib1'); - await createTestUILibNoNgDevkit(appTree, 'test-ui-lib2'); - - await configurationGenerator(appTree, { - name: 'test-ui-lib1', - uiFramework: '@storybook/react' as any, - }); - - const lib1Configuration = readProjectConfiguration(appTree, 'test-ui-lib1'); - - updateProjectConfiguration(appTree, 'test-ui-lib1', { - ...lib1Configuration, - targets: { - ...lib1Configuration.targets, - storybook: { - ...lib1Configuration.targets.storybook, - options: { - ...lib1Configuration.targets.storybook.options, - config: { - configFolder: - lib1Configuration.targets.storybook.options.configDir, - }, - }, - }, - }, - }); - - appTree = deleteNewConfigurationAndCreateNew( - appTree, - 'libs/test-ui-lib1/.storybook' - ); - - await configurationGenerator(appTree, { - name: 'test-ui-lib2', - uiFramework: '@storybook/react' as any, - }); - - const lib2Configuration = readProjectConfiguration(appTree, 'test-ui-lib2'); - - updateProjectConfiguration(appTree, 'test-ui-lib2', { - ...lib2Configuration, - targets: { - ...lib2Configuration.targets, - storybook: { - ...lib2Configuration.targets.storybook, - options: { - ...lib2Configuration.targets.storybook.options, - config: { - configFolder: - lib2Configuration.targets.storybook.options.configDir, - }, - }, - }, - }, - }); - - appTree = deleteNewConfigurationAndCreateNew( - appTree, - 'libs/test-ui-lib2/.storybook' - ); - - updateJson(appTree, 'package.json', (json) => { - return { - ...json, - devDependencies: { - ...json.devDependencies, - '@storybook/addon-knobs': '^5.3.8', - '@storybook/angular': '^5.3.8', - }, - }; - }); - }); - - it('should update Storybook packages to latest version and ignore the ones to be ignored', async () => { - migrateDefaultsGenerator(appTree); - - const packageJson = readJson(appTree, 'package.json'); - expect(packageJson.devDependencies['@storybook/angular']).toEqual( - storybookVersion - ); - expect(packageJson.devDependencies['@storybook/addon-knobs']).toEqual( - storybookVersion - ); - expect(packageJson.devDependencies['@storybook/addon-notes']).toEqual( - '5.3.21' - ); - expect(packageJson.devDependencies['@storybook/addon-postcss']).toEqual( - '2.0.0' - ); - }); - - it('should update configuration of all projects', async () => { - migrateDefaultsGenerator(appTree); - - expect( - appTree.exists('libs/test-ui-lib1/.old_storybook/addons.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib2/.old_storybook/addons.js') - ).toBeTruthy(); - - expect(appTree.exists('libs/test-ui-lib1/.storybook/main.js')).toBeTruthy(); - expect(appTree.exists('libs/test-ui-lib2/.storybook/main.js')).toBeTruthy(); - }); - - it('should keep old files and put them in .old_storybook directory', async () => { - migrateDefaultsGenerator(appTree); - expect( - appTree.exists('libs/test-ui-lib1/.old_storybook/addons.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib1/.old_storybook/config.js') - ).toBeTruthy(); - - expect( - appTree.exists('libs/test-ui-lib2/.old_storybook/addons.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib2/.old_storybook/config.js') - ).toBeTruthy(); - }); -}); diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts deleted file mode 100644 index 6d20313448739f..00000000000000 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts +++ /dev/null @@ -1,210 +0,0 @@ -import { - GeneratorCallback, - getProjects, - installPackagesTask, - logger, - readProjectConfiguration, - Tree, - updateJson, - visitNotIgnoredFiles, -} from '@nx/devkit'; -import { lte } from 'semver'; -import { checkAndCleanWithSemver } from '@nx/devkit/src/utils/semver'; -import { storybookVersion } from '../../../utils/versions'; -import { createProjectStorybookDir } from '../../../generators/configuration/lib/util-functions'; -import { StorybookConfigureSchema } from '../../../generators/configuration/schema'; -import { findStorybookAndBuildTargetsAndCompiler } from '../../../utils/utilities'; - -export function migrateDefaultsGenerator(tree: Tree) { - migrateAllStorybookInstances(tree); - return upgradeStorybookPackagesInPackageJson(tree); -} - -export function migrateAllStorybookInstances(tree: Tree) { - logger.debug('adding .storybook folder to project'); - const projects = getProjects(tree); - const projectsThatHaveStorybookConfiguration: { - name: string; - uiFramework: StorybookConfigureSchema['uiFramework']; - configFolder: string; - }[] = [...projects.entries()] - .filter( - ([_, projectConfig]) => - projectConfig?.targets?.storybook && - projectConfig?.targets?.storybook?.executor !== - '@nrwl/react-native:storybook' - ) - .map(([projectName, projectConfig]) => { - return { - name: projectName, - uiFramework: projectConfig?.targets?.storybook?.options?.uiFramework, - configFolder: - projectConfig?.targets?.storybook?.options?.config?.configFolder ?? - '', - }; - }); - - for (const projectWithStorybook of projectsThatHaveStorybookConfiguration) { - migrateStorybookInstance( - tree, - projectWithStorybook.name, - projectWithStorybook.uiFramework, - projectWithStorybook.configFolder - ); - } -} - -export function migrateStorybookInstance( - tree: Tree, - projectName: string, - uiFramework: StorybookConfigureSchema['uiFramework'], - configFolder?: string -) { - migrateProjectLevelStorybookInstance( - tree, - projectName, - uiFramework, - configFolder - ); -} - -function maybeUpdateVersion(tree: Tree): GeneratorCallback { - let needsInstall = false; - updateJson(tree, 'package.json', (json) => { - const ignoredStorybookPackages = [ - '@storybook/builder-vite', - '@storybook/jest', - '@storybook/react-native', - '@storybook/storybook-deployer', - '@storybook/test-runner', - '@storybook/testing-library', - '@storybook/testing-angular', - '@storybook/testing-react', - '@storybook/testing-vue', - '@storybook/testing-vue3', - '@storybook/addon-notes', - '@storybook/addon-postcss', - ]; - - json.dependencies = json.dependencies || {}; - json.devDependencies = json.devDependencies || {}; - - const allStorybookPackagesInDependencies = Object.keys( - json.dependencies - ).filter( - (packageName: string) => - packageName.startsWith('@storybook/') && - !ignoredStorybookPackages.includes(packageName) - ); - - const allStorybookPackagesInDevDependencies = Object.keys( - json.devDependencies - ).filter( - (packageName: string) => - packageName.startsWith('@storybook/') && - !ignoredStorybookPackages.includes(packageName) - ); - - const storybookPackages = [ - ...allStorybookPackagesInDependencies, - ...allStorybookPackagesInDevDependencies, - ]; - - storybookPackages.forEach((storybookPackageName) => { - if (json.dependencies[storybookPackageName]) { - const version = checkAndCleanWithSemver( - storybookPackageName, - json.dependencies[storybookPackageName] - ); - if (lte(version, '6.0.0')) { - json.dependencies[storybookPackageName] = storybookVersion; - needsInstall = true; - } - } - if (json.devDependencies[storybookPackageName]) { - const version = checkAndCleanWithSemver( - storybookPackageName, - json.devDependencies[storybookPackageName] - ); - if (lte(version, '6.0.0')) { - json.devDependencies[storybookPackageName] = storybookVersion; - needsInstall = true; - } - } - }); - return json; - }); - - if (needsInstall) { - return () => installPackagesTask(tree); - } -} - -function upgradeStorybookPackagesInPackageJson(tree: Tree) { - /** - * Should upgrade all @storybook/* packages in package.json - */ - - return maybeUpdateVersion(tree); -} - -function moveOldFiles(tree: Tree, configFolderDir: string) { - moveDirectory( - tree, - configFolderDir, - configFolderDir.replace('.storybook', '.old_storybook') - ); -} - -function migrateProjectLevelStorybookInstance( - tree: Tree, - projectName: string, - uiFramework: StorybookConfigureSchema['uiFramework'], - configFolder: string -) { - const old_folder_exists_already = tree.exists( - configFolder?.replace('.storybook', '.old_storybook') - ); - const new_config_exists_already = tree.exists(`${configFolder}/main.js`); - - if (old_folder_exists_already || new_config_exists_already) { - return; - } - - moveOldFiles(tree, configFolder); - - if (tree.exists(configFolder)) { - return; - } - - const { projectType, targets, root } = readProjectConfiguration( - tree, - projectName - ); - const { nextBuildTarget, compiler } = - findStorybookAndBuildTargetsAndCompiler(targets); - - const mainDir = - !!nextBuildTarget && projectType === 'application' ? 'components' : 'src'; - - createProjectStorybookDir( - tree, - projectName, - uiFramework, - false, - false, - root, - projectType, - false, - false, - mainDir, - !!nextBuildTarget, - compiler === 'swc' - ); -} - -export function moveDirectory(tree: Tree, from: string, to: string) { - visitNotIgnoredFiles(tree, from, (file) => { - tree.rename(file, file.replace(from, to)); - }); -} diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts deleted file mode 100644 index 22276edc060062..00000000000000 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts +++ /dev/null @@ -1,171 +0,0 @@ -import { - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { joinPathFragments, writeJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { storybookVersion } from '../../../utils/versions'; -import { findNodes } from '@nx/js'; -import * as ts from 'typescript'; -import { SyntaxKind } from 'typescript'; -import { nxVersion } from '../../../utils/versions'; -import { migrateStoriesTo62Generator } from './migrate-stories-to-6-2'; -import { - overrideCollectionResolutionForTesting, - wrapAngularDevkitSchematic, -} from '@nx/devkit/ngcli-adapter'; -import { getTsSourceFile } from '../../../utils/utilities'; - -// nested code imports graph from the repo, which might have innacurate graph version -jest.mock('nx/src/project-graph/project-graph', () => ({ - ...jest.requireActual('nx/src/project-graph/project-graph'), - createProjectGraphAsync: jest - .fn() - .mockImplementation(async () => ({ nodes: {}, dependencies: {} })), -})); - -const componentSchematic = wrapAngularDevkitSchematic( - '@schematics/angular', - 'component' -); -const runAngularLibrarySchematic = wrapAngularDevkitSchematic( - '@schematics/angular', - 'library' -); - -const runAngularStorybookSchematic = wrapAngularDevkitSchematic( - '@nx/angular', - 'storybook-configuration' -); - -describe('migrate-stories-to-6-2 schematic', () => { - let appTree: Tree; - - describe('angular project', () => { - beforeEach(async () => { - overrideCollectionResolutionForTesting({ - '@nx/storybook': joinPathFragments( - __dirname, - '../../../../generators.json' - ), - }); - - appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - await runAngularLibrarySchematic(appTree, { - name: 'test-ui-lib', - }); - - await componentSchematic(appTree, { - name: 'test-button', - project: 'test-ui-lib', - }); - - writeJson(appTree, 'package.json', { - devDependencies: { - '@nx/storybook': nxVersion, - '@storybook/addon-knobs': storybookVersion, - '@storybook/angular': storybookVersion, - }, - }); - writeJson(appTree, 'test-ui-lib/tsconfig.json', {}); - - await runAngularStorybookSchematic(appTree, { - name: 'test-ui-lib', - configureCypress: true, - configureStaticServe: false, - }); - - appTree.write( - `test-ui-lib/src/lib/test-button/test-button.component.stories.ts`, - ` - import { text, number, boolean } from '@storybook/addon-knobs'; - import { TestButtonComponent } from './test-button.component'; - - export default { - title: 'TestButtonComponent', - }; - - export const primary = () => ({ - component: TestButtonComponent, - moduleMetadata: { - imports: [], - }, - props: { - buttonType: text('buttonType', 'button'), - style: text('style', 'default'), - age: number('age', 0), - isOn: boolean('isOn', false), - }, - }); - - export const secondary = () => ({ - component: TestButtonComponent, - moduleMetadata: { - imports: [], - }, - props: {}, - }); - ` - ); - - /** - * This needs to be updated for the following reason: - * - runAngularStorybookSchematic now generates the Storybook targets in - * the project configuration using the @storybook/angular executors - * - this means that the uiFramework property is not used any more - * - that property was used in versions before that so the migration script looks for it - * - the migrate-stories-to-6-2 migrator should have already taken effect in previous versions - * so there is no need to update the generator to look for the new executor as well - */ - const projectConfig = readProjectConfiguration(appTree, 'test-ui-lib'); - projectConfig.targets.storybook.options.uiFramework = - '@storybook/angular'; - projectConfig.targets.storybook.options.config = { - configFolder: projectConfig.targets.storybook.options.configDir, - }; - updateProjectConfiguration(appTree, 'test-ui-lib', projectConfig); - }); - - it('should move the component from the story to parameters.component', async () => { - await migrateStoriesTo62Generator(appTree); - const storyFilePath = - 'test-ui-lib/src/lib/test-button/test-button.component.stories.ts'; - const file = getTsSourceFile(appTree, storyFilePath); - const storiesExportDefault = findNodes(file, [ - ts.SyntaxKind.ExportAssignment, - ]); - const defaultExportNode = storiesExportDefault[0]; - const defaultExportObject = defaultExportNode - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.ObjectLiteralExpression; - }); - const defaultPropertiesList = defaultExportObject - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.SyntaxList; - }); - - const hasTitle = defaultPropertiesList?.getChildren()?.find((node) => { - return ( - node.kind === SyntaxKind.PropertyAssignment && - node.getText().startsWith('title') - ); - }); - const hasComponent = defaultPropertiesList - ?.getChildren() - ?.find((node) => { - return ( - node.kind === SyntaxKind.PropertyAssignment && - node.getText().startsWith('component') - ); - }); - - expect(appTree.exists(storyFilePath)).toBeTruthy(); - expect(hasTitle).toBeTruthy(); - expect(hasComponent).toBeTruthy(); - }); - }); -}); diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts deleted file mode 100644 index 912a9a90887759..00000000000000 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts +++ /dev/null @@ -1,406 +0,0 @@ -import { - applyChangesToString, - ChangeType, - formatFiles, - getProjects, - logger, - stripIndents, - Tree, - visitNotIgnoredFiles, -} from '@nx/devkit'; -import { fileExists } from '@nx/workspace/src/utilities/fileutils'; -import { findNodes } from '@nx/js'; -import { join, normalize } from 'path'; -import { SyntaxKind } from 'typescript'; -import { getTsSourceFile } from '../../../utils/utilities'; -import ts = require('typescript'); - -export async function migrateStoriesTo62Generator(tree: Tree) { - let allComponentsWithStories: { - componentName: string; - componentPath: any; - componentFileName: any; - componentStoryPath: string; - }[] = []; - const result: { - name: string; - configFolder: string; - projectRoot: string; - projectSrc: string; - }[] = findAllAngularProjectsWithStorybookConfiguration(tree); - result?.forEach( - (angularProjectWithStorybook: { - name: string; - configFolder: string; - projectRoot: string; - projectSrc: string; - }) => { - const componentResult = findAllComponentsWithStoriesForSpecificProject( - tree, - angularProjectWithStorybook.projectRoot - ); - allComponentsWithStories = [ - ...allComponentsWithStories, - ...componentResult, - ]; - } - ); - allComponentsWithStories?.forEach((componentInfo) => { - changeSyntaxOfStory(tree, componentInfo.componentStoryPath); - }); - await formatFiles(tree); -} - -export function findAllAngularProjectsWithStorybookConfiguration(tree: Tree): { - name: string; - configFolder: string; - projectRoot: string; - projectSrc: string; -}[] { - const projects = getProjects(tree); - const projectsThatHaveStorybookConfiguration: { - name: string; - configFolder: string; - projectRoot: string; - projectSrc: string; - }[] = [...projects.entries()] - ?.filter( - ([_, projectConfig]) => - projectConfig?.targets?.storybook?.options?.uiFramework === - '@storybook/angular' - ) - ?.map(([projectName, projectConfig]) => { - return { - name: projectName, - configFolder: - projectConfig.targets.storybook?.options?.config?.configFolder, - projectRoot: projectConfig.root, - projectSrc: projectConfig.sourceRoot, - }; - }); - return projectsThatHaveStorybookConfiguration; -} - -function findAllComponentsWithStoriesForSpecificProject( - tree: Tree, - projectPath: string -): { - componentName: string; - componentPath: any; - componentFileName: any; - componentStoryPath: string; -}[] { - let moduleFilePaths = [] as string[]; - visitNotIgnoredFiles(tree, projectPath, (filePath) => { - if (filePath?.endsWith('.module.ts')) { - moduleFilePaths.push(filePath); - } - }); - let componentFileInfos = []; - moduleFilePaths?.map((moduleFilePath) => { - const file = getTsSourceFile(tree, moduleFilePath); - const ngModuleDecorators = findNodes(file, ts.SyntaxKind.Decorator); - if (ngModuleDecorators.length === 0) { - return; - } - const ngModuleDecorator = ngModuleDecorators[0]; - const ngModuleNode = ngModuleDecorator?.getChildren()?.find((node) => { - return node?.getText()?.startsWith('NgModule'); - }); - const ngModulePropertiesObject = ngModuleNode - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.SyntaxList; - }); - const ngModuleProperties = ngModulePropertiesObject - ?.getChildren()[0] - ?.getChildren() - ?.find((node) => { - return node?.getText()?.includes('declarations'); - }); - - const declarationsPropertyAssignment = ngModuleProperties - ?.getChildren() - ?.find((node) => { - return node?.getText()?.startsWith('declarations'); - }); - - if (!declarationsPropertyAssignment) { - logger.warn(stripIndents`No components declared in ${moduleFilePath}.`); - } - let declarationArray = declarationsPropertyAssignment - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.ArrayLiteralExpression); - if (!declarationArray) { - // Attempt to follow a variable instead of the literal - const declarationVariable = declarationsPropertyAssignment - ?.getChildren() - ?.filter((node) => node.kind === SyntaxKind.Identifier)[1]; - const variableName = declarationVariable?.getText(); - const variableDeclaration = findNodes( - file, - SyntaxKind.VariableDeclaration - )?.find((variableDeclaration) => { - const identifier = variableDeclaration - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.Identifier); - return identifier?.getText() === variableName; - }); - if (variableDeclaration) { - declarationArray = variableDeclaration - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.ArrayLiteralExpression); - } - } - const declaredComponents = declarationArray - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.SyntaxList) - ?.getChildren() - ?.filter((node) => node.kind === SyntaxKind.Identifier) - ?.map((node) => node?.getText()) - ?.filter((name) => name?.endsWith('Component')); - const imports = file.statements?.filter( - (statement) => statement.kind === SyntaxKind.ImportDeclaration - ); - const modulePath = moduleFilePath.slice( - 0, - moduleFilePath?.lastIndexOf('/') - ); - let componentInfo = declaredComponents?.map((componentName) => { - try { - const importStatement = imports?.find((statement) => { - const namedImports = statement - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.ImportClause) - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.NamedImports); - if (namedImports === undefined) return false; - const importedIdentifiers = namedImports - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.SyntaxList) - ?.getChildren() - ?.filter((node) => node.kind === SyntaxKind.ImportSpecifier) - ?.map((node) => node?.getText()); - return importedIdentifiers?.includes(componentName); - }); - - const fullPath = importStatement - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.StringLiteral) - ?.getText() - ?.slice(1, -1); - - // if it is a directory, search recursively for the component - let fullCmpImportPath = moduleFilePath?.slice( - 0, - moduleFilePath?.lastIndexOf('/') - ); - if (fullCmpImportPath?.startsWith('/')) { - fullCmpImportPath = fullCmpImportPath?.slice( - 1, - fullCmpImportPath.length - ); - } - let componentImportPath = join(normalize(fullCmpImportPath), fullPath); - - let path = null; - let componentFileName = null; - let componentStoryPath = null; - let storyExists = false; - let componentExists = false; - /** - * Here we want to remove the .component - * part of the path, to just keep the - * apps//src/app/ - * or - * libs//src/lib/ - * part of the path - */ - componentImportPath = componentImportPath.slice( - 0, - componentImportPath.lastIndexOf('/') - ); - visitNotIgnoredFiles(tree, componentImportPath, (componentFilePath) => { - if (componentFilePath?.endsWith('.ts')) { - const content = tree.read(componentFilePath).toString('utf-8'); - - if (content?.indexOf(`class ${componentName}`) > -1) { - componentExists = true; - path = componentFilePath; - componentFileName = - componentFilePath?.slice( - componentFilePath?.lastIndexOf('/') + 1, - componentFilePath?.lastIndexOf('.') - ) + '.ts'; - } - - if (componentFilePath?.endsWith('.stories.ts')) { - componentStoryPath = componentFilePath; - storyExists = true; - } - } - }); - if (!storyExists || !componentExists) { - path = null; - componentFileName = null; - componentStoryPath = null; - } - if (path !== null) { - return { - componentName: componentName, - componentPath: path, - componentFileName, - componentStoryPath: componentStoryPath, - }; - } else { - const path = fullPath?.slice(0, fullPath?.lastIndexOf('/')); - const componentFileName = - fullPath?.slice(fullPath?.lastIndexOf('/') + 1) + '.ts'; - - componentStoryPath = fullPath + '.stories.ts'; - if (fileExists(componentStoryPath)) { - return { - componentName: componentName, - componentPath: path + componentFileName, - componentFileName, - componentStoryPath: componentStoryPath, - }; - } else { - return undefined; - } - } - } catch (e) { - logger.warn(`Could not find file for ${componentName}. Error: ${e}`); - return undefined; - } - }); - if (componentInfo) { - componentInfo = componentInfo?.filter((info) => info !== undefined); - componentFileInfos = [...componentFileInfos, ...componentInfo]; - } - }); - return componentFileInfos; -} - -async function changeSyntaxOfStory(tree: Tree, storyFilePath: string) { - const file = getTsSourceFile(tree, storyFilePath); - const appFileContent = tree.read(storyFilePath, 'utf-8'); - let newContents = appFileContent; - const storiesVariableDeclaration = findNodes(file, [ - ts.SyntaxKind.VariableDeclaration, - ]); - const storiesExportDefault = findNodes(file, [ - ts.SyntaxKind.ExportAssignment, - ]); - - const defaultExportNode = storiesExportDefault[0]; - const defaultExportObject = defaultExportNode?.getChildren()?.find((node) => { - return node.kind === SyntaxKind.ObjectLiteralExpression; - }); - const defaultPropertiesList = defaultExportObject - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.SyntaxList; - }); - const hasTitle = defaultPropertiesList?.getChildren()?.find((node) => { - return ( - node.kind === SyntaxKind.PropertyAssignment && - node.getText().startsWith('title') - ); - }); - - /** - * A component node will look like this: - * - * component: MyTestComponent - * - * And this is what we need to remove. - */ - let firstComponentNode: ts.Node; - - /** - * The result of ts.Node.getStart() will give us the index - * of that node in the whole original file. - * While we're editing that file, the getStart() will - * still reference the original file. So, during deletion, - * it would go and delete characters using the original index. - * - * We need to save the length of the characters that have been removed - * so far, so that we can substract it from the index. - * Since it's parsing the file linearly and in order, then this - * logic works. - * */ - - let lengthOfRemovalsSoFar = 0; - - storiesVariableDeclaration?.forEach((oneStory) => { - const oneExportedStoryArrowFunction = oneStory - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.ArrowFunction; - }); - const inParenthesis = oneExportedStoryArrowFunction - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.ParenthesizedExpression; - }); - const objectLiteralOfStory = inParenthesis?.getChildren()?.find((node) => { - return node.kind === SyntaxKind.ObjectLiteralExpression; - }); - const propertiesList = objectLiteralOfStory?.getChildren()?.find((node) => { - return node.kind === SyntaxKind.SyntaxList; - }); - - const hasComponentDeclared = propertiesList?.getChildren()?.find((node) => { - return ( - node.kind === SyntaxKind.PropertyAssignment && - node.getText().startsWith('component') - ); - }); - - if (hasComponentDeclared) { - /** - * Here I am saving the first component to appear - * in the case where we have multiple stories - */ - if (!firstComponentNode) { - firstComponentNode = hasComponentDeclared; - } - - /** - * Here we are performing the following check: - * If the component we will be adding in the default declaration - * which is the first component that we find - * is the same for this story as well, - * then remove it. - */ - - if (hasComponentDeclared.getText() === firstComponentNode.getText()) { - const indexOfPropertyName = hasComponentDeclared.getStart(); - const lengthOfRemoval = hasComponentDeclared?.getText()?.length + 1; - newContents = applyChangesToString(newContents, [ - { - type: ChangeType.Delete, - start: indexOfPropertyName - lengthOfRemovalsSoFar, - length: lengthOfRemoval, - }, - ]); - lengthOfRemovalsSoFar = lengthOfRemovalsSoFar + lengthOfRemoval; - } - } - }); - - if (hasTitle && firstComponentNode) { - const indexOfPropertyName = hasTitle.getEnd(); - newContents = applyChangesToString(newContents, [ - { - type: ChangeType.Insert, - index: indexOfPropertyName + 2, - text: firstComponentNode.getText() + ',', - }, - ]); - tree.write(storyFilePath, newContents); - } - - await formatFiles(tree); -} diff --git a/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.spec.ts b/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.spec.ts deleted file mode 100644 index 892d0b1579ec07..00000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.spec.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { addProjectConfiguration, readNxJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import changeStorybookTargetsGenerator from './change-storybook-targets-generator'; -import * as defaultConfig from './test-configs/default-config.json'; -import * as customNames from './test-configs/custom-names-config.json'; -import * as nonAngular from './test-configs/non-angular.json'; -import * as extraOptions from './test-configs/extra-options-for-storybook.json'; -import * as noStorybookBuildTarget from './test-configs/no-build-storybook-target.json'; -import * as noStorybook from './test-configs/no-storybook-targets.json'; - -describe('Change the Storybook targets for Angular projects to use native Storybooke executor', () => { - let tree: Tree; - - describe('for all types of angular projects - non-buildable and buildable libs/apps', () => { - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it(`should set the browserTarget correctly in the Storybook config according to the type of project`, async () => { - writeConfig(tree, defaultConfig); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - - it(`should set the browserTarget correctly even if target names are not the default`, async () => { - writeConfig(tree, customNames); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - - it(`should keep any extra options added in the target`, async () => { - writeConfig(tree, extraOptions); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - it(`should work even if build-storybook does not exist`, async () => { - writeConfig(tree, noStorybookBuildTarget); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - - it(`should not throw an error if no Storybook exists`, async () => { - writeConfig(tree, noStorybook); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - }); - - describe('for non-angular projects', () => { - it(`should not change their Storybook targets`, async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - writeConfig(tree, nonAngular); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - }); -}); - -function writeConfig(tree: Tree, config: any) { - Object.keys(config.projects).forEach((project) => { - addProjectConfiguration(tree, project, config.projects[project]); - }); -} diff --git a/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.ts b/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.ts deleted file mode 100644 index e02e94ac7e86ff..00000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.ts +++ /dev/null @@ -1,173 +0,0 @@ -import { - logger, - Tree, - formatFiles, - updateProjectConfiguration, - getProjects, - TargetConfiguration, - ProjectConfiguration, - Target, - convertNxGenerator, -} from '@nx/devkit'; -import { findStorybookAndBuildTargetsAndCompiler } from '../../utils/utilities'; - -export async function changeStorybookTargetsGenerator(tree: Tree) { - let changesMade = false; - let changesMadeToAtLeastOne = false; - const projects = getProjects(tree); - [...projects.entries()].forEach(([projectName, projectConfiguration]) => { - changesMade = false; - const { storybookBuildTarget, storybookTarget, ngBuildTarget } = - findStorybookAndBuildTargetsAndCompiler(projectConfiguration.targets); - if ( - projectName && - storybookTarget && - projectConfiguration?.targets?.[storybookTarget]?.options?.uiFramework === - '@storybook/angular' - ) { - projectConfiguration.targets[storybookTarget] = updateStorybookTarget( - projectConfiguration, - storybookTarget, - projectName, - ngBuildTarget, - storybookBuildTarget - ); - changesMade = true; - changesMadeToAtLeastOne = true; - if (storybookBuildTarget) { - projectConfiguration.targets[storybookBuildTarget] = - updateStorybookBuildTarget( - projectConfiguration, - projectName, - ngBuildTarget, - storybookBuildTarget - ); - } else { - logger.info( - `Project ${projectName} does not have a build target configured for Storybook.` - ); - } - } else { - logger.warn(`Could not find a Storybook target for ${projectName}.`); - } - if (changesMade) { - updateProjectConfiguration(tree, projectName, projectConfiguration); - } - }); - - if (changesMadeToAtLeastOne) { - await formatFiles(tree); - } -} - -function updateStorybookTarget( - projectConfiguration: ProjectConfiguration, - storybookTarget: string, - projectName: string, - buildTarget: string, - storybookBuildTarget: string -): TargetConfiguration { - const oldStorybookTargetConfig: TargetConfiguration = - projectConfiguration.targets[storybookTarget]; - - const newStorybookTargetConfig: TargetConfiguration = { - executor: '@storybook/angular:start-storybook', - options: { - port: oldStorybookTargetConfig.options.port, - configDir: oldStorybookTargetConfig.options.config?.configFolder, - browserTarget: undefined, - compodoc: false, - }, - configurations: oldStorybookTargetConfig.configurations, - }; - - const { project, target } = parseTargetStringCustom( - oldStorybookTargetConfig.options.projectBuildConfig - ); - if (project && target) { - newStorybookTargetConfig.options.browserTarget = - oldStorybookTargetConfig.options.projectBuildConfig; - } else { - newStorybookTargetConfig.options.browserTarget = `${projectName}:${ - buildTarget ? buildTarget : storybookBuildTarget - }`; - } - - const { - uiFramework, - outputPath, - config, - projectBuildConfig, - ...optionsToCopy - } = oldStorybookTargetConfig.options; - - newStorybookTargetConfig.options = { - ...optionsToCopy, - ...newStorybookTargetConfig.options, - }; - - return newStorybookTargetConfig; -} - -function updateStorybookBuildTarget( - projectConfiguration: ProjectConfiguration, - projectName: string, - buildTarget: string, - storybookBuildTarget: string -): TargetConfiguration { - const oldStorybookBuildTargetConfig: TargetConfiguration = - projectConfiguration.targets[storybookBuildTarget]; - const newStorybookBuildTargetConfig: TargetConfiguration = { - executor: '@storybook/angular:build-storybook', - outputs: oldStorybookBuildTargetConfig.outputs, - options: { - outputDir: oldStorybookBuildTargetConfig.options.outputPath, - configDir: oldStorybookBuildTargetConfig.options.config?.configFolder, - browserTarget: undefined, - compodoc: false, - }, - configurations: oldStorybookBuildTargetConfig.configurations, - }; - - const { project, target } = parseTargetStringCustom( - oldStorybookBuildTargetConfig.options.projectBuildConfig - ); - if (project && target) { - newStorybookBuildTargetConfig.options.browserTarget = - oldStorybookBuildTargetConfig.options.projectBuildConfig; - } else { - newStorybookBuildTargetConfig.options.browserTarget = `${projectName}:${ - buildTarget ? buildTarget : storybookBuildTarget - }`; - } - - const { - uiFramework, - outputPath, - config, - projectBuildConfig, - ...optionsToCopy - } = oldStorybookBuildTargetConfig.options; - - newStorybookBuildTargetConfig.options = { - ...optionsToCopy, - ...newStorybookBuildTargetConfig.options, - }; - - return newStorybookBuildTargetConfig; -} - -function parseTargetStringCustom(targetString: string): Target { - const [project, target, configuration] = targetString.split(':'); - - return { - project, - target, - configuration, - }; -} - -export default changeStorybookTargetsGenerator; -export const changeStorybookTargetsSchematic = convertNxGenerator( - changeStorybookTargetsGenerator -); diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/custom-names-config.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/custom-names-config.json deleted file mode 100644 index 87a662bc001fa6..00000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/custom-names-config.json +++ /dev/null @@ -1,154 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "trthrngb": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:asdgsdfg" - } - }, - "asdgsdfg": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:asdgsdfg" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": { - "sdft": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:thjkkb" - } - }, - "thjkkb": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/two", - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:thjkkb" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": { - "nmkgd": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:aaaa" - } - }, - "aaaa": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/three", - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:aaaa" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "njdfvndfjnv": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "lmfkcn": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - }, - "odmwjbc": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/main-app", - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/default-config.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/default-config.json deleted file mode 100644 index 19be537bd91a4c..00000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/default-config.json +++ /dev/null @@ -1,154 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:build-storybook" - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:build-storybook" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:build-storybook" - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/two", - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:build-storybook" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:build-storybook" - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/three", - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:build-storybook" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "build": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/main-app", - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/extra-options-for-storybook.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/extra-options-for-storybook.json deleted file mode 100644 index 7badb6b8e00584..00000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/extra-options-for-storybook.json +++ /dev/null @@ -1,222 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false, - "loglevel": "info" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/two", - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false, - "loglevel": "info" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/three", - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false, - "loglevel": "info" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "build": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false - }, - "configurations": { - "ci": { - "quiet": true - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/main-app", - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false, - "loglevel": "info" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/no-build-storybook-target.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/no-build-storybook-target.json deleted file mode 100644 index 921b0aba4887c0..00000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/no-build-storybook-target.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "projects": { - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "build": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "other-app": { - "projectType": "application", - "root": "apps/other-app", - "sourceRoot": "apps/other-app/src", - "prefix": "katst", - "targets": { - "build": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/other-app/.storybook" - }, - "projectBuildConfig": "other-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/no-storybook-targets.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/no-storybook-targets.json deleted file mode 100644 index 5d53bd22c3f3aa..00000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/no-storybook-targets.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": {} - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": {} - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": {} - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "build": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/non-angular.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/non-angular.json deleted file mode 100644 index edd7136372f913..00000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/non-angular.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/react", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/react", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts b/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts deleted file mode 100644 index 9e3286936b9eaa..00000000000000 --- a/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import subject from './remove-deprecated-options-13-0-0'; - -describe('Migration: Remove deprecated options', () => { - it(`should remove deprecated web build options`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:build', - options: { - showCircularDependencies: false, - budgets: [], - }, - configurations: { - production: { - showCircularDependencies: true, - budgets: [], - }, - }, - }, - }, - }); - - await subject(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:build', - options: {}, - configurations: { - production: {}, - }, - }, - }, - }); - }); -}); diff --git a/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts b/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts deleted file mode 100644 index b768690433da77..00000000000000 --- a/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { - formatFiles, - getProjects, - logger, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -const deprecatedOptions = ['showCircularDependencies', 'budgets']; - -export default async function update(host: Tree) { - const projects = getProjects(host); - - for (const [name, config] of projects.entries()) { - if (config.targets.build.executor !== '@nrwl/web:build') return; - - for (const opt of deprecatedOptions) { - let updated = false; - if ( - typeof config.targets.build?.configurations?.production?.[opt] !== - 'undefined' - ) { - delete config.targets.build.configurations.production[opt]; - updated = true; - } - if (typeof config.targets.build.options[opt] !== 'undefined') { - delete config.targets.build.options[opt]; - updated = true; - } - - if (updated) { - updateProjectConfiguration(host, name, config); - logger.info(`NX Removed legacy build option from "${name}": ${opt}`); - } - } - } - - await formatFiles(host); -} diff --git a/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.spec.ts b/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.spec.ts deleted file mode 100644 index f060c07194c2e4..00000000000000 --- a/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.spec.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { addProjectConfiguration, readJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './rollup-format-backwards-compatibility'; - -describe('rollup-format-backwards-compatibility', () => { - it('should add format options to match previous behavior if it does not exist', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'proj1', { - root: 'proj1', - targets: { - build: { - executor: '@nrwl/web:rollup', - }, - }, - }); - - await update(tree); - - expect(readJson(tree, 'proj1/project.json').targets).toEqual({ - build: { - executor: '@nrwl/web:rollup', - options: { - format: ['esm', 'cjs'], - }, - }, - }); - }); - - it('should skip update if format exists', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'proj1', { - root: 'proj1', - targets: { - build: { - executor: '@nrwl/web:rollup', - options: { - format: ['esm'], - }, - }, - }, - }); - - await update(tree); - - expect(readJson(tree, 'proj1/project.json').targets).toEqual({ - build: { - executor: '@nrwl/web:rollup', - options: { - format: ['esm'], - }, - }, - }); - }); -}); diff --git a/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.ts b/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.ts deleted file mode 100644 index 9ea5111b2e3c36..00000000000000 --- a/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -/* - * - */ -export default async function update(tree: Tree) { - for (const [name, config] of getProjects(tree)) { - if (config.targets?.build?.executor !== '@nrwl/web:rollup') continue; - if (Array.isArray(config.targets.build.options?.format)) continue; - - config.targets.build.options = { - ...config.targets.build.options, - format: ['esm', 'cjs'], - }; - - updateProjectConfiguration(tree, name, config); - } - await formatFiles(tree); -} diff --git a/packages/workspace/src/migrations/update-13-9-0/update-decorate-cli.ts b/packages/workspace/src/migrations/update-13-9-0/update-decorate-cli.ts deleted file mode 100644 index 0d2699667d1bb9..00000000000000 --- a/packages/workspace/src/migrations/update-13-9-0/update-decorate-cli.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Tree } from '@nx/devkit'; - -export function updateDecorateAngularCLI(host: Tree) { - const decorate = host.read('decorate-angular-cli.js')?.toString(); - if (decorate) { - host.write( - 'decorate-angular-cli.js', - decorate.replace('@nrwl/cli/lib/decorate-cli', 'nx/src/cli/decorate-cli') - ); - } -} - -export default updateDecorateAngularCLI;