Skip to content

Commit

Permalink
fix: resolve-workspace-deps to publish pkg versions (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Sep 15, 2023
1 parent 756aef7 commit 77be55a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 41 deletions.
9 changes: 9 additions & 0 deletions .changeset/giant-parrots-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@rocket.chat/fuselage": patch
"@rocket.chat/fuselage-hooks": patch
"@rocket.chat/logo": patch
"@rocket.chat/onboarding-ui": patch
"@rocket.chat/ui-kit": patch
---

chore: resolve-workspace-deps to publish pkg versions
17 changes: 14 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
build-and-test:
name: Build and Test
Expand Down Expand Up @@ -88,13 +90,22 @@ jobs:
- run: yarn install
if: steps.yarn-cache.outputs.cache-hit != 'true'

- uses: changesets/action@v1
with:
publish: yarn release
- name: Create Release Pull Request
id: changesets
uses: changesets/action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

if: steps.changesets.outputs.hasChangesets == 'false'
run: yarn resolve-workspace-deps

- name: Publish to npm
id: changesets-publish
uses: changesets/action@v1
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn release

publish-to-gh-pages:
name: Publish to GitHub Pages
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@rocket.chat/fuselage-root",
"name": "@rocket.chat/fuselage-monorepo",
"private": true,
"version": "0.31.25",
"workspaces": [
"packages/*",
"tools/*"
Expand Down
43 changes: 26 additions & 17 deletions tools/scripts/src/resolve-workspace-deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-unresolved
import { readFile, writeFile } from 'fs/promises';
import { join } from 'path';

Expand All @@ -11,6 +10,7 @@ type PackageList = {
};

type PackageManifest = {
name: string;
version?: string;
dependencies?: PackageList;
devDependencies?: PackageList;
Expand All @@ -19,7 +19,7 @@ type PackageManifest = {

const patchPackageList = (
packageList: PackageList | undefined,
version: string
packagesRefObj: Map<string, string | undefined>
) => {
if (!packageList) {
return;
Expand All @@ -30,22 +30,24 @@ const patchPackageList = (
continue;
}

packageList[packageName] = `^${version}`;
packageList[packageName] = `^${packagesRefObj.get(packageName)}`;
}
};

const getPackageManifest = async (packageManifestsPath: string) =>
JSON.parse(
await readFile(packageManifestsPath, { encoding: 'utf-8' })
) as PackageManifest;

const patchPackageManifest = async (
packageManifestsPath: string,
version: string
packagesRefObj: Map<string, string | undefined>
) => {
const packageManifest = JSON.parse(
await readFile(packageManifestsPath, { encoding: 'utf-8' })
) as PackageManifest;
const packageManifest = await getPackageManifest(packageManifestsPath);

packageManifest.version = version;
patchPackageList(packageManifest.dependencies, version);
patchPackageList(packageManifest.devDependencies, version);
patchPackageList(packageManifest.peerDependencies, version);
patchPackageList(packageManifest.dependencies, packagesRefObj);
patchPackageList(packageManifest.devDependencies, packagesRefObj);
patchPackageList(packageManifest.peerDependencies, packagesRefObj);

await writeFile(
packageManifestsPath,
Expand All @@ -57,19 +59,26 @@ const patchPackageManifest = async (
};

const start = async () => {
const { version } = JSON.parse(
await readFile(join(rootDir, 'lerna.json'), { encoding: 'utf-8' })
) as { version: string };

const packageManifestsPaths = await fg(
['**/package.json', '!**/node_modules/**/package.json', '!./package.json'],
{
cwd: rootDir,
}
);

for (const packageManifestsPath of packageManifestsPaths) {
patchPackageManifest(join(rootDir, packageManifestsPath), version);
const packagesRefObj = new Map(
await Promise.all(
packageManifestsPaths.map(async (packageManifestsPath) => {
const packageManifest = await getPackageManifest(
join(rootDir, packageManifestsPath)
);
return [packageManifest.name, packageManifest.version] as const;
})
)
);

for await (const packageManifestsPath of packageManifestsPaths) {
patchPackageManifest(join(rootDir, packageManifestsPath), packagesRefObj);
}
};

Expand Down
38 changes: 19 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6420,6 +6420,23 @@ __metadata:
languageName: unknown
linkType: soft

"@rocket.chat/fuselage-monorepo@workspace:.":
version: 0.0.0-use.local
resolution: "@rocket.chat/fuselage-monorepo@workspace:."
dependencies:
"@changesets/changelog-github": ~0.4.8
"@changesets/cli": ~2.26.2
bump: "workspace:~"
husky: ~7.0.4
hygen: ~6.1.5
lerna: ~4.0.0
lint-staged: ~13.2.1
turbo: ~1.1.10
update-readme: "workspace:~"
webpack: ~5.78.0
languageName: unknown
linkType: soft

"@rocket.chat/fuselage-polyfills@workspace:packages/fuselage-polyfills, @rocket.chat/fuselage-polyfills@workspace:~":
version: 0.0.0-use.local
resolution: "@rocket.chat/fuselage-polyfills@workspace:packages/fuselage-polyfills"
Expand All @@ -6440,23 +6457,6 @@ __metadata:
languageName: unknown
linkType: soft

"@rocket.chat/fuselage-root@workspace:.":
version: 0.0.0-use.local
resolution: "@rocket.chat/fuselage-root@workspace:."
dependencies:
"@changesets/changelog-github": ~0.4.8
"@changesets/cli": ~2.26.2
bump: "workspace:~"
husky: ~7.0.4
hygen: ~6.1.5
lerna: ~4.0.0
lint-staged: ~13.2.1
turbo: ~1.1.10
update-readme: "workspace:~"
webpack: ~5.78.0
languageName: unknown
linkType: soft

"@rocket.chat/fuselage-toastbar@workspace:packages/fuselage-toastbar":
version: 0.0.0-use.local
resolution: "@rocket.chat/fuselage-toastbar@workspace:packages/fuselage-toastbar"
Expand Down Expand Up @@ -8482,9 +8482,9 @@ __metadata:
languageName: node
linkType: hard

"@storybook/react-docgen-typescript-plugin@patch:@storybook/react-docgen-typescript-plugin@npm%3A1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0#./.yarn/patches/@storybook-react-docgen-typescript-plugin-npm-1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0-b31cc57c40.patch::locator=%40rocket.chat%2Ffuselage-root%40workspace%3A.":
"@storybook/react-docgen-typescript-plugin@patch:@storybook/react-docgen-typescript-plugin@npm%3A1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0#./.yarn/patches/@storybook-react-docgen-typescript-plugin-npm-1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0-b31cc57c40.patch::locator=%40rocket.chat%2Ffuselage-monorepo%40workspace%3A.":
version: 1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0
resolution: "@storybook/react-docgen-typescript-plugin@patch:@storybook/react-docgen-typescript-plugin@npm%3A1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0#./.yarn/patches/@storybook-react-docgen-typescript-plugin-npm-1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0-b31cc57c40.patch::version=1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0&hash=0878d5&locator=%40rocket.chat%2Ffuselage-root%40workspace%3A."
resolution: "@storybook/react-docgen-typescript-plugin@patch:@storybook/react-docgen-typescript-plugin@npm%3A1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0#./.yarn/patches/@storybook-react-docgen-typescript-plugin-npm-1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0-b31cc57c40.patch::version=1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0&hash=0878d5&locator=%40rocket.chat%2Ffuselage-monorepo%40workspace%3A."
dependencies:
debug: ^4.1.1
endent: ^2.0.1
Expand Down

0 comments on commit 77be55a

Please sign in to comment.