From cfb6db2dc54fcd8184a726fe9f2d59bc84b0196d Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 18:35:19 +0200 Subject: [PATCH 01/14] fix(workspace-plugin): prepare-initial-release - phase:stable - update additional files and properly resolve *-stories package.json definitions --- .../prepare-initial-release/index.spec.ts | 87 ++++++++++++++++++- .../prepare-initial-release/index.ts | 29 +++++++ 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts index 6f301d8777feb..ae2ac592c920b 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts @@ -199,6 +199,10 @@ describe('prepare-initial-release generator', () => { `); expect(utils.project.stories.pkgJson()).toMatchInlineSnapshot(` Object { + "devDependencies": Object { + "@proj/react-components": "*", + "@proj/react-one-compat": "*", + }, "name": "@proj/react-one-compat-stories", "private": true, "version": "0.0.0", @@ -295,6 +299,10 @@ describe('prepare-initial-release generator', () => { `); expect(utils.project.stories.pkgJson()).toMatchInlineSnapshot(` Object { + "devDependencies": Object { + "@proj/react-components": "*", + "@proj/react-one-preview": "*", + }, "name": "@proj/react-one-preview-stories", "private": true, "version": "0.0.0", @@ -465,6 +473,7 @@ describe('prepare-initial-release generator', () => { " `); + expect(tree.exists('packages/react-one-preview')).toEqual(false); expect(tree.children('packages/react-one-preview')).toEqual([]); expect(utils.project.global.codeowners()).toEqual( @@ -714,12 +723,24 @@ describe('prepare-initial-release generator', () => { sourceRoot: 'packages/react-one/library/src', }), ); + expect(utils.project.library.pkgJson()).toEqual({ + name: '@proj/react-one', + version: '9.0.0-alpha.0', + }); + expect(utils.project.stories.projectJson()).toEqual( expect.objectContaining({ name: 'react-one-stories', sourceRoot: 'packages/react-one/stories/src', }), ); + expect(utils.project.stories.pkgJson()).toEqual({ + name: '@proj/react-one-stories', + version: expect.any(String), + devDependencies: { + '@proj/react-components': '*', + }, + }); expect(utils.project.library.bundleSize()).toMatchInlineSnapshot(` Object { @@ -733,6 +754,23 @@ describe('prepare-initial-release generator', () => { } `); + expect(utils.project.library.md.license()).toMatchInlineSnapshot(` + "# @proj/react-one + + Copyright (c) CompanyName + + All rights reserved. + + MIT License" + `); + expect(utils.project.library.md.spec()).toMatchInlineSnapshot(` + "# @proj/react-one Spec + + ## Background + + A Foo is a component that displays a set of vertically stacked Moos. + " + `); expect(utils.project.library.md.readme()).toMatchInlineSnapshot(` "# @proj/react-one @@ -831,6 +869,13 @@ function createSplitProject( const stories = createProject(tree, storiesProjectName, { ...options, + pkgJson: { + ...options.pkgJson, + devDependencies: { + [`@proj/react-components`]: '*', + [`@proj/${projectName}`]: '*', + }, + }, root: storiesProject.root, files: [ ...(options.files?.stories ?? []), @@ -878,7 +923,9 @@ function createProject( const sourceRoot = joinPathFragments(options.root, 'src'); const indexFile = joinPathFragments(sourceRoot, 'index.ts'); const jestPath = joinPathFragments(options.root, 'jest.config.js'); + const specPath = joinPathFragments(options.root, 'docs/SPEC.md'); const readmePath = joinPathFragments(options.root, 'README.md'); + const licensePath = joinPathFragments(options.root, 'LICENSE'); const apiMdPath = joinPathFragments(options.root, `etc/${projectName}.api.md`); const tsConfigBaseAllPath = 'tsconfig.base.all.json'; const tsConfigBasePath = 'tsconfig.base.json'; @@ -901,6 +948,39 @@ function createProject( `, ); + tree.write( + licensePath, + stripIndents` + # ${npmName} + +Copyright (c) CompanyName + +All rights reserved. + +MIT License + `, + ); + tree.write( + specPath, + stripIndents` +# ${npmName} Spec + +## Background + +A Foo is a component that displays a set of vertically stacked Moos. + `, + ); + tree.write( + readmePath, + stripIndents` + # ${npmName} + +**React Tags components for [Fluent UI React](https://react.fluentui.dev/)** + +These are not production-ready components and **should never be used in product**. This space is useful for testing new components whose APIs might change before final release. + + `, + ); tree.write( readmePath, stripIndents` @@ -941,7 +1021,10 @@ These are not production-ready components and **should never be used in product* return json; }); - const depKeys = [...Object.keys(options.pkgJson.dependencies ?? {})]; + const depKeys = [ + ...Object.keys(options.pkgJson.dependencies ?? {}), + ...Object.keys(options.pkgJson.devDependencies ?? {}), + ]; graphMock.dependencies[projectName] = depKeys.map(value => { return { source: projectName, target: value.replace('@proj/', ''), type: 'static' }; @@ -971,6 +1054,8 @@ These are not production-ready components and **should never be used in product* return tree.read(joinPathFragments(newRoot, 'jest.config.js'), 'utf-8'); }, md: { + license: () => tree.read(joinPathFragments(newRoot, 'LICENSE'), 'utf-8'), + spec: () => tree.read(joinPathFragments(newRoot, 'docs/SPEC.md'), 'utf-8'), readme: () => tree.read(joinPathFragments(newRoot, 'README.md'), 'utf-8'), api: () => tree.read(joinPathFragments(newRoot, `etc/${projectName.replace('-preview', '')}.api.md`), 'utf-8'), }, diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts index 2da3e1c429764..581f6e0b590b0 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts @@ -12,6 +12,7 @@ import { readJson, stripIndents, workspaceRoot, + logger, type ProjectConfiguration, type Tree, type ProjectGraph, @@ -150,11 +151,21 @@ async function stableRelease(tree: Tree, options: NormalizedSchema & { isSplitPr } const mdFilePath = { + spec: joinPathFragments(options.projectConfig.root, 'docs/SPEC.md'), readme: joinPathFragments(options.projectConfig.root, 'README.md'), api: joinPathFragments(options.projectConfig.root, 'etc', options.project + '.api.md'), apiNew: joinPathFragments(options.projectConfig.root, 'etc', newPackage.name + '.api.md'), + license: joinPathFragments(options.projectConfig.root, 'LICENSE'), }; + updateFileContent(tree, { + filePath: mdFilePath.license, + updater: contentNameUpdater, + }); + updateFileContent(tree, { + filePath: mdFilePath.spec, + updater: contentNameUpdater, + }); updateFileContent(tree, { filePath: mdFilePath.readme, updater: contentNameUpdater, @@ -222,6 +233,11 @@ async function stableRelease(tree: Tree, options: NormalizedSchema & { isSplitPr async function updateProjectsThatUsedPreviewPackage() { const graph = await createProjectGraphAsync(); const projectsToUpdate = await getProjectThatNeedsToBeUpdated(graph, options); + const ignoreProjects = [ + // we don't wanna update `*-stories` project based on Graph - stories project is updated later which doesn't uses Graph rather relies on our custom imports parser and package.json template + // TODO: re-evaluate this approach if we should not rather use Graph for everything + options.isSplitProject ? options.projectConfig.name + '-stories' : null, + ].filter(Boolean) as string[]; const knownProjectsToBeUpdated = { docsite: 'public-docsite-v9', @@ -231,6 +247,10 @@ async function stableRelease(tree: Tree, options: NormalizedSchema & { isSplitPr // update other projects that might still contain dependency to old -preview package const unknownProjectsToBeUpdated = projectsToUpdate ? projectsToUpdate.filter(projectName => { + if (ignoreProjects.includes(projectName)) { + return false; + } + const knownKeys = Object.values(knownProjectsToBeUpdated); return !knownKeys.includes(projectName); }) @@ -321,6 +341,8 @@ function stableReleaseForStoriesProject(tree: Tree, options: NormalizedSchema) { updateJson(tree, storiesProjectPaths.packageJson, json => { json.name = newStoriesProject.npmName; + delete json.devDependencies?.[options.npmPackageName]; + return json; }); @@ -365,6 +387,13 @@ function updateFileContent( }, ) { const { filePath, newFilePath, updater } = options; + + if (!tree.exists(filePath)) { + logger.warn(`attempt to update ${filePath} contents failed, because that path does not exist`); + + return tree; + } + const oldContent = tree.read(filePath, 'utf-8') as string; const newContent = updater(oldContent); From 72c5ef860c9600374bd2d268da2e40b508b50db4 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 18:43:54 +0200 Subject: [PATCH 02/14] ci: run prepare-initial-release tests to verify path integrity cross platform --- .github/workflows/check-tooling.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-tooling.yml b/.github/workflows/check-tooling.yml index df86975691840..79bc345d65388 100644 --- a/.github/workflows/check-tooling.yml +++ b/.github/workflows/check-tooling.yml @@ -31,6 +31,8 @@ jobs: - run: yarn nx run scripts-executors:test -t start + - run: yarn nx run workspace-plugin:test -t 'prepare-initial-release generator' + - run: yarn nx list @fluentui/workspace-plugin - run: yarn nx g @fluentui/workspace-plugin:react-library --name hello-world --owner '@mrWick' --kind standard --no-interactive From 898aab9abebf395d6f1e068caeb67aaff4972f0b Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 19:12:06 +0200 Subject: [PATCH 03/14] ci: test win paths --- .github/workflows/check-tooling.yml | 2 +- .../src/generators/prepare-initial-release/index.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-tooling.yml b/.github/workflows/check-tooling.yml index 79bc345d65388..1024f2a8223ea 100644 --- a/.github/workflows/check-tooling.yml +++ b/.github/workflows/check-tooling.yml @@ -31,7 +31,7 @@ jobs: - run: yarn nx run scripts-executors:test -t start - - run: yarn nx run workspace-plugin:test -t 'prepare-initial-release generator' + # - run: yarn nx run workspace-plugin:test -t 'prepare-initial-release generator' - run: yarn nx list @fluentui/workspace-plugin diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts index 581f6e0b590b0..62660468600b2 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts @@ -53,9 +53,20 @@ export default async function (tree: Tree, schema: ReleasePackageGeneratorSchema tasks.forEach(task => { task(tree); }); + + assertOutputOnCi(tree, options); }; } +function assertOutputOnCi(tree: Tree, options: NormalizedSchema) { + if (options.phase === 'stable') { + console.log( + 'bundle-size', + tree.read(joinPathFragments(options.projectConfig.root, 'bundle-size/index.fixture.js'), 'utf-8'), + ); + } +} + function normalizeOptions(tree: Tree, options: ReleasePackageGeneratorSchema) { const project = getProjectConfig(tree, { packageName: options.project }); From f7aa6d42143425b078c21d4843c485e14b8cfe48 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 19:20:47 +0200 Subject: [PATCH 04/14] fixup! ci: test win paths --- .../src/generators/prepare-initial-release/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts index 62660468600b2..b474a12857bbc 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts @@ -62,7 +62,10 @@ function assertOutputOnCi(tree: Tree, options: NormalizedSchema) { if (options.phase === 'stable') { console.log( 'bundle-size', - tree.read(joinPathFragments(options.projectConfig.root, 'bundle-size/index.fixture.js'), 'utf-8'), + tree.read( + joinPathFragments(options.projectConfig.root.replace('-preview', ''), 'bundle-size/index.fixture.js'), + 'utf-8', + ), ); } } From a0014f773d5a383bf13c3e13a88e6ae7cc078c79 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 19:33:56 +0200 Subject: [PATCH 05/14] fixup! fixup! ci: test win paths --- .github/workflows/check-tooling.yml | 2 +- .../src/generators/prepare-initial-release/index.spec.ts | 3 ++- .../src/generators/prepare-initial-release/index.ts | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-tooling.yml b/.github/workflows/check-tooling.yml index 1024f2a8223ea..79bc345d65388 100644 --- a/.github/workflows/check-tooling.yml +++ b/.github/workflows/check-tooling.yml @@ -31,7 +31,7 @@ jobs: - run: yarn nx run scripts-executors:test -t start - # - run: yarn nx run workspace-plugin:test -t 'prepare-initial-release generator' + - run: yarn nx run workspace-plugin:test -t 'prepare-initial-release generator' - run: yarn nx list @fluentui/workspace-plugin diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts index ae2ac592c920b..688a66989c27b 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts @@ -12,6 +12,7 @@ import { visitNotIgnoredFiles, } from '@nrwl/devkit'; import childProcess from 'child_process'; +import path from 'node:path'; import generator from './index'; import { PackageJson, TsConfig } from '../../types'; @@ -1064,7 +1065,7 @@ These are not production-ready components and **should never be used in product* const contents: Record = {}; visitNotIgnoredFiles(tree, root, file => { - contents[file] = stripIndents`${tree.read(file, 'utf-8')}` ?? ''; + contents[path.normalize(file)] = stripIndents`${tree.read(file, 'utf-8')}` ?? ''; }); return contents; diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts index b474a12857bbc..36775da249088 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts @@ -156,12 +156,15 @@ async function stableRelease(tree: Tree, options: NormalizedSchema & { isSplitPr const bundleSizeFixturesRoot = joinPathFragments(options.projectConfig.root, 'bundle-size'); if (tree.exists(bundleSizeFixturesRoot)) { + console.log('===BUNDLE SIZE UPDATES====', { bundleSizeFixturesRoot }); visitNotIgnoredFiles(tree, bundleSizeFixturesRoot, filePath => { updateFileContent(tree, { filePath, updater: contentNameUpdater, }); }); + } else { + console.warn('=== NO BUNDLE SIZE UPDATES! ====', { bundleSizeFixturesRoot }); } const mdFilePath = { From 1ddb403708a3ff42844607daaac0708c34e22e1d Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 20:14:10 +0200 Subject: [PATCH 06/14] fixup! fixup! fixup! ci: test win paths --- .github/workflows/check-tooling.yml | 4 ++++ .../src/generators/prepare-initial-release/index.spec.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-tooling.yml b/.github/workflows/check-tooling.yml index 79bc345d65388..cc7a4de9abf75 100644 --- a/.github/workflows/check-tooling.yml +++ b/.github/workflows/check-tooling.yml @@ -41,6 +41,10 @@ jobs: - run: yarn nx g @fluentui/workspace-plugin:bundle-size-configuration --project hello-world-preview --no-interactive - run: yarn nx g @fluentui/workspace-plugin:prepare-initial-release --project hello-world-preview --phase=preview --no-interactive - run: yarn nx g @fluentui/workspace-plugin:prepare-initial-release --project hello-world-preview --phase=stable --no-interactive + - run: cat packages/react-components/hello-world/library/bundle-size/index.fixture.js + - run: cat packages/react-components/hello-world/library/bundle-size/README.md + - run: cat packages/react-components/hello-world/library/bundle-size/docs/SPEC.md + - run: cat packages/react-components/hello-world/stories/README.md - run: yarn nx g @nx/workspace:remove --project hello-world --forceRemove --no-interactive - run: yarn nx g @nx/workspace:remove --project hello-world-stories --forceRemove --no-interactive - run: yarn nx g @fluentui/workspace-plugin:tsconfig-base-all --no-interactive diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts index 688a66989c27b..d47bbeae9f4a4 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts @@ -1065,7 +1065,7 @@ These are not production-ready components and **should never be used in product* const contents: Record = {}; visitNotIgnoredFiles(tree, root, file => { - contents[path.normalize(file)] = stripIndents`${tree.read(file, 'utf-8')}` ?? ''; + contents[path.posix.normalize(file)] = stripIndents`${tree.read(file, 'utf-8')}` ?? ''; }); return contents; From 7c3040177cef719c2d83000c9ec18ae2b79eec3f Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 21:16:55 +0200 Subject: [PATCH 07/14] fixup! fixup! fixup! fixup! ci: test win paths --- .github/workflows/check-tooling.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-tooling.yml b/.github/workflows/check-tooling.yml index cc7a4de9abf75..ff01fcb5cf525 100644 --- a/.github/workflows/check-tooling.yml +++ b/.github/workflows/check-tooling.yml @@ -42,8 +42,8 @@ jobs: - run: yarn nx g @fluentui/workspace-plugin:prepare-initial-release --project hello-world-preview --phase=preview --no-interactive - run: yarn nx g @fluentui/workspace-plugin:prepare-initial-release --project hello-world-preview --phase=stable --no-interactive - run: cat packages/react-components/hello-world/library/bundle-size/index.fixture.js - - run: cat packages/react-components/hello-world/library/bundle-size/README.md - - run: cat packages/react-components/hello-world/library/bundle-size/docs/SPEC.md + - run: cat packages/react-components/hello-world/library/README.md + - run: cat packages/react-components/hello-world/library/docs/SPEC.md - run: cat packages/react-components/hello-world/stories/README.md - run: yarn nx g @nx/workspace:remove --project hello-world --forceRemove --no-interactive - run: yarn nx g @nx/workspace:remove --project hello-world-stories --forceRemove --no-interactive From d9c03ef89f089a4b5418a7ea1b21a63893415ac2 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 21:20:58 +0200 Subject: [PATCH 08/14] fixup! fixup! fixup! fixup! ci: test win paths --- .github/workflows/check-tooling.yml | 1 + .../src/generators/prepare-initial-release/index.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/workflows/check-tooling.yml b/.github/workflows/check-tooling.yml index ff01fcb5cf525..ec0184453547e 100644 --- a/.github/workflows/check-tooling.yml +++ b/.github/workflows/check-tooling.yml @@ -45,6 +45,7 @@ jobs: - run: cat packages/react-components/hello-world/library/README.md - run: cat packages/react-components/hello-world/library/docs/SPEC.md - run: cat packages/react-components/hello-world/stories/README.md + - run: tree packages/react-components/hello-world - run: yarn nx g @nx/workspace:remove --project hello-world --forceRemove --no-interactive - run: yarn nx g @nx/workspace:remove --project hello-world-stories --forceRemove --no-interactive - run: yarn nx g @fluentui/workspace-plugin:tsconfig-base-all --no-interactive diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts index 36775da249088..89b925be88e18 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts @@ -415,6 +415,8 @@ function updateFileContent( const newContent = updater(oldContent); + console.log({ filePath, newFilePath, oldContent, newContent }); + if (newFilePath) { tree.rename(filePath, newFilePath); tree.write(newFilePath, newContent); From ba9731fef6f5f777f58b060482fdc048fad7e9d3 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 22:54:02 +0200 Subject: [PATCH 09/14] fixup! fixup! fixup! fixup! ci: test win paths --- .github/workflows/check-tooling.yml | 3 ++- .../src/generators/prepare-initial-release/index.ts | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-tooling.yml b/.github/workflows/check-tooling.yml index ec0184453547e..9b113e0a525fc 100644 --- a/.github/workflows/check-tooling.yml +++ b/.github/workflows/check-tooling.yml @@ -42,8 +42,9 @@ jobs: - run: yarn nx g @fluentui/workspace-plugin:prepare-initial-release --project hello-world-preview --phase=preview --no-interactive - run: yarn nx g @fluentui/workspace-plugin:prepare-initial-release --project hello-world-preview --phase=stable --no-interactive - run: cat packages/react-components/hello-world/library/bundle-size/index.fixture.js + - run: cat packages/react-components/hello-world/library/jest.config.js - run: cat packages/react-components/hello-world/library/README.md - - run: cat packages/react-components/hello-world/library/docs/SPEC.md + - run: cat packages/react-components/hello-world/library/docs/Spec.md - run: cat packages/react-components/hello-world/stories/README.md - run: tree packages/react-components/hello-world - run: yarn nx g @nx/workspace:remove --project hello-world --forceRemove --no-interactive diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts index 89b925be88e18..d1d52ee7a948b 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts @@ -158,6 +158,7 @@ async function stableRelease(tree: Tree, options: NormalizedSchema & { isSplitPr if (tree.exists(bundleSizeFixturesRoot)) { console.log('===BUNDLE SIZE UPDATES====', { bundleSizeFixturesRoot }); visitNotIgnoredFiles(tree, bundleSizeFixturesRoot, filePath => { + console.log('===BUNDLE SIZE UPDATES====', { filePath }); updateFileContent(tree, { filePath, updater: contentNameUpdater, @@ -415,8 +416,6 @@ function updateFileContent( const newContent = updater(oldContent); - console.log({ filePath, newFilePath, oldContent, newContent }); - if (newFilePath) { tree.rename(filePath, newFilePath); tree.write(newFilePath, newContent); From c5e5096dcedaed4e38a7d959f15ffdc428a8c218 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 22:56:39 +0200 Subject: [PATCH 10/14] chore: fix spec file typo --- .../src/generators/prepare-initial-release/index.spec.ts | 4 ++-- .../src/generators/prepare-initial-release/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts index d47bbeae9f4a4..61d7e14a00507 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts @@ -924,7 +924,7 @@ function createProject( const sourceRoot = joinPathFragments(options.root, 'src'); const indexFile = joinPathFragments(sourceRoot, 'index.ts'); const jestPath = joinPathFragments(options.root, 'jest.config.js'); - const specPath = joinPathFragments(options.root, 'docs/SPEC.md'); + const specPath = joinPathFragments(options.root, 'docs/Spec.md'); const readmePath = joinPathFragments(options.root, 'README.md'); const licensePath = joinPathFragments(options.root, 'LICENSE'); const apiMdPath = joinPathFragments(options.root, `etc/${projectName}.api.md`); @@ -1056,7 +1056,7 @@ These are not production-ready components and **should never be used in product* }, md: { license: () => tree.read(joinPathFragments(newRoot, 'LICENSE'), 'utf-8'), - spec: () => tree.read(joinPathFragments(newRoot, 'docs/SPEC.md'), 'utf-8'), + spec: () => tree.read(joinPathFragments(newRoot, 'docs/Spec.md'), 'utf-8'), readme: () => tree.read(joinPathFragments(newRoot, 'README.md'), 'utf-8'), api: () => tree.read(joinPathFragments(newRoot, `etc/${projectName.replace('-preview', '')}.api.md`), 'utf-8'), }, diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts index d1d52ee7a948b..3e723a4de6036 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts @@ -169,7 +169,7 @@ async function stableRelease(tree: Tree, options: NormalizedSchema & { isSplitPr } const mdFilePath = { - spec: joinPathFragments(options.projectConfig.root, 'docs/SPEC.md'), + spec: joinPathFragments(options.projectConfig.root, 'docs/Spec.md'), readme: joinPathFragments(options.projectConfig.root, 'README.md'), api: joinPathFragments(options.projectConfig.root, 'etc', options.project + '.api.md'), apiNew: joinPathFragments(options.projectConfig.root, 'etc', newPackage.name + '.api.md'), From 95de07d631072f4646c34f4b7f3e68018c356312 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 23:32:46 +0200 Subject: [PATCH 11/14] fix(workspace-plugin): update nxignored files during stable release migration --- .../prepare-initial-release/index.spec.ts | 22 ++++++++-- .../prepare-initial-release/index.ts | 24 +++-------- .../prepare-initial-release/lib/utils.ts | 43 +++++++++++++++++++ 3 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 tools/workspace-plugin/src/generators/prepare-initial-release/lib/utils.ts diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts index 61d7e14a00507..3132a17ca652a 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts @@ -9,13 +9,14 @@ import { readJson, updateJson, installPackagesTask, - visitNotIgnoredFiles, } from '@nrwl/devkit'; import childProcess from 'child_process'; import path from 'node:path'; +import type { PackageJson, TsConfig } from '../../types'; + import generator from './index'; -import { PackageJson, TsConfig } from '../../types'; +import { visitNotGitIgnoredFiles } from './lib/utils'; const getBlankGraphMock = () => ({ dependencies: {}, @@ -55,6 +56,21 @@ describe('prepare-initial-release generator', () => { ...getBlankGraphMock(), }; tree = createTreeWithEmptyWorkspace(); + tree.write( + '.nxignore', + stripIndents` + ; build output + **/dist/** + + ; known directories to not incorporate into the workspace graph creation + **/fixtures/** + **/__fixtures__/** + **/bundle-size/** + + ; scaffolding templates + **/generators/**/files/** + `, + ); tree.write(codeownersPath, `foo/bar @org/all\n`); writeJson(tree, 'tsconfig.base.v8.json', { compilerOptions: { paths: {} } }); writeJson(tree, 'tsconfig.base.v0.json', { compilerOptions: { paths: {} } }); @@ -1064,7 +1080,7 @@ These are not production-ready components and **should never be used in product* const root = joinPathFragments(newRoot, 'bundle-size'); const contents: Record = {}; - visitNotIgnoredFiles(tree, root, file => { + visitNotGitIgnoredFiles(tree, root, file => { contents[path.posix.normalize(file)] = stripIndents`${tree.read(file, 'utf-8')}` ?? ''; }); diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts index 3e723a4de6036..8562ebf5b642f 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts @@ -28,6 +28,7 @@ import tsConfigBaseAll from '../tsconfig-base-all'; import { assertStoriesProject, isSplitProject as isSplitProjectFn } from '../split-library-in-two/shared'; import { type ReleasePackageGeneratorSchema } from './schema'; +import { visitNotGitIgnoredFiles } from './lib/utils'; interface NormalizedSchema extends ReturnType {} @@ -53,23 +54,9 @@ export default async function (tree: Tree, schema: ReleasePackageGeneratorSchema tasks.forEach(task => { task(tree); }); - - assertOutputOnCi(tree, options); }; } -function assertOutputOnCi(tree: Tree, options: NormalizedSchema) { - if (options.phase === 'stable') { - console.log( - 'bundle-size', - tree.read( - joinPathFragments(options.projectConfig.root.replace('-preview', ''), 'bundle-size/index.fixture.js'), - 'utf-8', - ), - ); - } -} - function normalizeOptions(tree: Tree, options: ReleasePackageGeneratorSchema) { const project = getProjectConfig(tree, { packageName: options.project }); @@ -135,6 +122,9 @@ async function stableRelease(tree: Tree, options: NormalizedSchema & { isSplitPr return content.replace(regexp, 'react-components'); }; + // clean node_modules so we don't perform unnecessary RENAMES later + tree.delete(joinPathFragments(options.projectConfig.root, 'node_modules')); + // we need to update projects that might still contain dependency to old -preview package first await updateProjectsThatUsedPreviewPackage(); @@ -156,16 +146,12 @@ async function stableRelease(tree: Tree, options: NormalizedSchema & { isSplitPr const bundleSizeFixturesRoot = joinPathFragments(options.projectConfig.root, 'bundle-size'); if (tree.exists(bundleSizeFixturesRoot)) { - console.log('===BUNDLE SIZE UPDATES====', { bundleSizeFixturesRoot }); - visitNotIgnoredFiles(tree, bundleSizeFixturesRoot, filePath => { - console.log('===BUNDLE SIZE UPDATES====', { filePath }); + visitNotGitIgnoredFiles(tree, bundleSizeFixturesRoot, filePath => { updateFileContent(tree, { filePath, updater: contentNameUpdater, }); }); - } else { - console.warn('=== NO BUNDLE SIZE UPDATES! ====', { bundleSizeFixturesRoot }); } const mdFilePath = { diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/lib/utils.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/lib/utils.ts new file mode 100644 index 0000000000000..b73014dd9dfd4 --- /dev/null +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/lib/utils.ts @@ -0,0 +1,43 @@ +import type { Tree } from '@nx/devkit'; +import ignore from 'ignore'; +import { join, relative, sep } from 'node:path'; + +/** + * Utility to act on all files in a tree that are not ignored by git. + * copied from https://github.com/nrwl/nx/blob/master/packages/devkit/src/generators/visit-not-ignored-files.ts + * utility override from original in order to process files that are ignored within .nxignore + */ +export function visitNotGitIgnoredFiles(tree: Tree, dirPath = tree.root, visitor: (path: string) => void): void { + // TODO (v17): use packages/nx/src/utils/ignore.ts + let ig = ignore(); + if (tree.exists('.gitignore')) { + // ig = ignore(); + ig.add('.git'); + ig.add(tree.read('.gitignore', 'utf-8')!); + } + // if (tree.exists('.nxignore')) { + // ig ??= ignore(); + // ig.add(tree.read('.nxignore', 'utf-8')!); + // } + dirPath = normalizePathRelativeToRoot(dirPath, tree.root); + + if (dirPath !== '' && ig?.ignores(dirPath)) { + return; + } + + for (const child of tree.children(dirPath)) { + const fullPath = join(dirPath, child); + if (ig?.ignores(fullPath)) { + continue; + } + if (tree.isFile(fullPath)) { + visitor(fullPath); + } else { + visitNotGitIgnoredFiles(tree, fullPath, visitor); + } + } +} + +function normalizePathRelativeToRoot(path: string, root: string): string { + return relative(root, join(root, path)).split(sep).join('/'); +} From 4c03dcc208d960f56ba804fbd38fdefb2be9738d Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 23 Sep 2024 23:52:43 +0200 Subject: [PATCH 12/14] feat(workspace-plugin): update any self references to -preview when running stable migration --- .../prepare-initial-release/index.spec.ts | 23 ++++++++++++++++++- .../prepare-initial-release/index.ts | 10 ++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts index 3132a17ca652a..65e34a2cd5c49 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts @@ -734,6 +734,18 @@ describe('prepare-initial-release generator', () => { expect(treeStructureAfter).toEqual(treeStructureBefore); expect(tree.children('packages/react-one-preview')).toEqual([]); + expect(tree.read('packages/react-one/library/src/index.ts', 'utf-8')).toMatchInlineSnapshot(` + "export { Hello } from './hello'; + " + `); + expect(tree.read('packages/react-one/library/src/hello.ts', 'utf-8')).toMatchInlineSnapshot(` + "export function Hello() { + console.log('@proj/react-one: some debug message for user'); + return; + } + " + `); + expect(utils.project.library.projectJson()).toEqual( expect.objectContaining({ name: 'react-one', @@ -961,7 +973,16 @@ function createProject( tree.write( indexFile, stripIndents` - export {}; + export { Hello } from './hello'; + `, + ); + tree.write( + joinPathFragments(sourceRoot, 'hello.ts'), + stripIndents` + export function Hello(){ + console.log('${npmName}: some debug message for user') + return + }; `, ); diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts index 8562ebf5b642f..9dc40c66c79b1 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts @@ -144,6 +144,16 @@ async function stableRelease(tree: Tree, options: NormalizedSchema & { isSplitPr updateFileContent(tree, { filePath: options.paths.jestConfig, updater: contentNameUpdater }); + // update any references to self within source code + if (options.projectConfig.sourceRoot) { + visitNotIgnoredFiles(tree, joinPathFragments(options.projectConfig.sourceRoot), filePath => { + updateFileContent(tree, { + filePath, + updater: contentNameUpdater, + }); + }); + } + const bundleSizeFixturesRoot = joinPathFragments(options.projectConfig.root, 'bundle-size'); if (tree.exists(bundleSizeFixturesRoot)) { visitNotGitIgnoredFiles(tree, bundleSizeFixturesRoot, filePath => { From 39386ea2705fe48f20a9e8829804f1de9b12029c Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 24 Sep 2024 00:13:33 +0200 Subject: [PATCH 13/14] fix(workspace-plugin): properly update story readmes when migraging to stable --- .../src/generators/prepare-initial-release/index.spec.ts | 8 ++++---- .../src/generators/prepare-initial-release/index.ts | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts index 65e34a2cd5c49..dc898e1825676 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts @@ -811,7 +811,7 @@ describe('prepare-initial-release generator', () => { expect(utils.project.stories.md.readme()).toMatchInlineSnapshot(` "# @proj/react-one-stories - Storybook stories for packages/react-components/react-one-stories + Storybook stories for packages/react-components/react-one ## Usage @@ -819,7 +819,7 @@ describe('prepare-initial-release generator', () => { \\\\\`\\\\\`\\\\\`js module.exports = { - stories: ['../packages/react-components/react-one-stories/stories/src/**/*.stories.mdx', '../packages/react-components/react-one-stories/stories/src/**/index.stories.@(ts|tsx)'], + stories: ['../packages/react-components/react-one/stories/src/**/*.stories.mdx', '../packages/react-components/react-one/stories/src/**/index.stories.@(ts|tsx)'], } \\\\\`\\\\\`\\\\\` " @@ -913,7 +913,7 @@ function createSplitProject( content: stripIndents` # @proj/${storiesProjectName} - Storybook stories for packages/react-components/${storiesProjectName} + Storybook stories for packages/react-components/${projectName} ## Usage @@ -921,7 +921,7 @@ function createSplitProject( \`\`\`js module.exports = { - stories: ['../packages/react-components/${storiesProjectName}/stories/src/**/*.stories.mdx', '../packages/react-components/${storiesProjectName}/stories/src/**/index.stories.@(ts|tsx)'], + stories: ['../packages/react-components/${projectName}/stories/src/**/*.stories.mdx', '../packages/react-components/${projectName}/stories/src/**/index.stories.@(ts|tsx)'], } \`\`\` `, diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts index 9dc40c66c79b1..18d6ffac39939 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.ts @@ -348,8 +348,11 @@ function stableReleaseForStoriesProject(tree: Tree, options: NormalizedSchema) { }; const contentNameUpdaterStories = (content: string) => { - const regexp = new RegExp(currentStoriesPackage.name, 'g'); - return content.replace(regexp, newStoriesProject.name); + const regexpStoryProject = new RegExp(currentStoriesPackage.name, 'g'); + const regexpLibraryProject = new RegExp(options.project, 'g'); + return content + .replace(regexpStoryProject, newStoriesProject.name) + .replace(regexpLibraryProject, options.project.replace('-preview', '')); }; updateJson(tree, storiesProjectPaths.packageJson, json => { From 8794cb7a078f38db98d46a4c2afe8d7fe1405b1b Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Tue, 24 Sep 2024 00:18:00 +0200 Subject: [PATCH 14/14] test: normalize path to posix --- .../src/generators/prepare-initial-release/index.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts index dc898e1825676..9286ab14123b9 100644 --- a/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts +++ b/tools/workspace-plugin/src/generators/prepare-initial-release/index.spec.ts @@ -1102,7 +1102,8 @@ These are not production-ready components and **should never be used in product* const contents: Record = {}; visitNotGitIgnoredFiles(tree, root, file => { - contents[path.posix.normalize(file)] = stripIndents`${tree.read(file, 'utf-8')}` ?? ''; + // normalize path key to POSIX + contents[file.split(path.sep).join('/')] = stripIndents`${tree.read(file, 'utf-8')}` ?? ''; }); return contents;