Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
stripIndents,
readJson,
updateJson,
workspaceRoot,
installPackagesTask,
} from '@nrwl/devkit';
import childProcess from 'child_process';
Expand Down Expand Up @@ -121,15 +120,22 @@ describe('prepare-initial-release generator', () => {

sideEffects();

expect(execSyncSpy.mock.calls.flat()).toMatchInlineSnapshot(`
Array [
"yarn change --message 'feat: release preview package' --type minor --package @proj/react-one-preview",
Object {
"cwd": "${workspaceRoot}",
"stdio": "inherit",
},
]
`);
const execCalls = getExecSpyCalls(execSyncSpy);

expect(execCalls.length).toEqual(1);

expect(execCalls[0].cmd).toMatchInlineSnapshot(
`"yarn change --message 'feat: release preview package' --type minor --package @proj/react-one-preview"`,
);
expect(execCalls[0].args).toMatchInlineSnapshot(
{ cwd: expect.any(String) },
`
Object {
"cwd": Any<String>,
"stdio": "inherit",
}
`,
);
});
});

Expand Down Expand Up @@ -160,7 +166,20 @@ describe('prepare-initial-release generator', () => {
content: stripIndents`
import { One } from '@proj/react-one-preview';

export const App = () => { return <One/> };
export const Default = () => <div><One/></div>
`,
},
{
filePath: 'packages/react-one-preview/stories/index.stories.tsx',
content: stripIndents`
import { One } from '@proj/react-one-preview';

const metadata: ComponentMeta<typeof One> = {
title: 'Preview Components/One',
component: One,
}

export default metadata;
`,
},
],
Expand Down Expand Up @@ -232,11 +251,24 @@ describe('prepare-initial-release generator', () => {
"
`);
expect(tree.read('packages/react-one/stories/One.stories.tsx', 'utf-8')).toMatchInlineSnapshot(`
"import { One } from '@proj/react-one-preview';
"import { One } from '@proj/react-components';

export const Default = () => (
<div>
<One />
</div>
);
"
`);
expect(tree.read('packages/react-one/stories/index.stories.tsx', 'utf-8')).toMatchInlineSnapshot(`
"import { One } from '@proj/react-components';

export const App = () => {
return <One />;
const metadata: ComponentMeta<typeof One> = {
title: 'Components/One',
component: One,
};

export default metadata;
"
`);

Expand All @@ -258,6 +290,7 @@ describe('prepare-initial-release generator', () => {

// project updates

// v9 docsite
expect(utils.docsite.pkgJson().dependencies).not.toEqual(
expect.objectContaining({ '@proj/react-one-preview': '*' }),
);
Expand All @@ -268,8 +301,9 @@ describe('prepare-initial-release generator', () => {
`),
);

// v9 vr-tests
const vrTestDeps = utils.vrTest.pkgJson().dependencies ?? {};
expect(vrTestDeps).toEqual(expect.objectContaining({ '@proj/react-one': '*' }));
expect(vrTestDeps).toEqual(expect.objectContaining({ '@proj/react-one': '>=9.0.0-alpha' }));
expect(vrTestDeps[projectName]).toEqual(undefined);
expect(tree.read('apps/vr-tests-react-components/src/stories/One.stories.tsx', 'utf-8')).toEqual(
expect.stringContaining(stripIndents`
Expand All @@ -278,6 +312,7 @@ describe('prepare-initial-release generator', () => {
`),
);

// react-components suite
expect(utils.suite.pkgJson().dependencies).toEqual(
expect.objectContaining({ '@proj/react-one': '9.0.0-alpha.0' }),
);
Expand All @@ -290,25 +325,47 @@ describe('prepare-initial-release generator', () => {

sideEffects();

expect(execSyncSpy.mock.calls.flat()).toMatchInlineSnapshot(`
Array [
"yarn change --message 'feat: release stable' --type minor --package @proj/react-one",
Object {
"cwd": "${workspaceRoot}",
"stdio": "inherit",
},
"yarn change --message 'feat: add @proj/react-one to suite' --type minor --package @proj/react-components",
Object {
"cwd": "${workspaceRoot}",
"stdio": "inherit",
},
"yarn lage generate-api --to @proj/react-components",
Object {
"cwd": "${workspaceRoot}",
"stdio": "inherit",
},
]
`);
const execCalls = getExecSpyCalls(execSyncSpy);

expect(execCalls.length).toEqual(3);

expect(execCalls[0].cmd).toMatchInlineSnapshot(
`"yarn change --message 'feat: release stable' --type minor --package @proj/react-one"`,
);
expect(execCalls[0].args).toMatchInlineSnapshot(
{ cwd: expect.any(String) },
`
Object {
"cwd": Any<String>,
"stdio": "inherit",
}
`,
);

expect(execCalls[1].cmd).toMatchInlineSnapshot(
`"yarn change --message 'feat: add @proj/react-one to suite' --type minor --package @proj/react-components"`,
);
expect(execCalls[1].args).toMatchInlineSnapshot(
{ cwd: expect.any(String) },
`
Object {
"cwd": Any<String>,
"stdio": "inherit",
}
`,
);

expect(execCalls[2].cmd).toMatchInlineSnapshot(`"yarn lage generate-api --to @proj/react-components"`);
expect(execCalls[2].args).toMatchInlineSnapshot(
{ cwd: expect.any(String) },
`
Object {
"cwd": Any<String>,
"stdio": "inherit",
}
`,
);

expect(installPackagesTaskSpy).toHaveBeenCalled();
});

Expand Down Expand Up @@ -463,3 +520,16 @@ These are not production-ready components and **should never be used in product*
},
};
}

function getExecSpyCalls(spy: jest.SpyInstance) {
const execSyncCalls = spy.mock.calls;

const normalized = execSyncCalls.map(call => {
return {
cmd: call[0],
args: call[1],
};
});

return normalized;
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,18 @@ async function stableRelease(tree: Tree, options: NormalizedSchema) {

// update stories
visitNotIgnoredFiles(tree, options.paths.stories, filePath => {
if (filePath.indexOf('index.stories.tsx') !== -1) {
updateFileContent(tree, {
filePath,
updater: content => {
let newContent = content.replace(`'Preview Components/`, 'Components/');

newContent = contentNameUpdater(content);

return newContent;
},
});
}
updateFileContent(tree, {
filePath,
updater: content => {
let newContent = contentNameToSuiteUpdater(content);

if (filePath.indexOf('index.stories.tsx') !== -1) {
newContent = newContent.replace(`'Preview `, `'`);
}

return newContent;
},
});
});

// global updates
Expand Down Expand Up @@ -207,7 +207,10 @@ async function stableRelease(tree: Tree, options: NormalizedSchema) {
updateJson<PackageJson>(tree, reactComponentsVrTestsProject.paths.packageJson, json => {
json.dependencies = json.dependencies ?? {};
delete json.dependencies[currentPackageName];
json.dependencies[newPackage.name] = '*';
// when going from preview to stable, package version changes to `9.0.0-alpha` in order to beachball properly bump to `9.0.0` stable.
// thus dependency on the package within workspace packages cannot use `*` but `>=9.0.0-alpha`
// on CI (release,pr) this is being checked normalized via [normalize-package-dependencies generator](tools/workspace-plugin/src/generators/normalize-package-dependencies/index.ts)
json.dependencies[newPackage.name] = '>=9.0.0-alpha';
return json;
});
visitNotIgnoredFiles(
Expand Down