From a517c1393905b0dfb71754c9c599552f8a48cac7 Mon Sep 17 00:00:00 2001 From: DuCanhGH Date: Thu, 4 Apr 2024 22:17:20 +0700 Subject: [PATCH] fix(ci): fixed invalid `potentialWorkspaces` --- docs/src/components/GitLabLogo.tsx | 8 ++---- package.json | 8 +----- packages/configs/package.json | 2 +- packages/next-pwa/package.json | 19 +++---------- packages/release/package.json | 2 +- .../release/src/lib/get-changed-packages.ts | 15 ++-------- packages/release/src/lib/get-packages.ts | 7 ----- packages/release/src/lib/package-names.ts | 15 ++++++++++ .../release/src/lib/read-changeset-state.ts | 6 ++-- packages/release/src/lib/run.ts | 28 ++++++------------- packages/release/src/lib/utils.ts | 18 ++++-------- 11 files changed, 43 insertions(+), 85 deletions(-) delete mode 100644 packages/release/src/lib/get-packages.ts create mode 100644 packages/release/src/lib/package-names.ts diff --git a/docs/src/components/GitLabLogo.tsx b/docs/src/components/GitLabLogo.tsx index 001b5c0a..6b423e98 100644 --- a/docs/src/components/GitLabLogo.tsx +++ b/docs/src/components/GitLabLogo.tsx @@ -1,11 +1,7 @@ import type { SVGProps } from "react"; -export const GitLabLogo = (props : Omit, "ref" | "viewBox" | "xmlns">) => ( - +export const GitLabLogo = (props: Omit, "ref" | "viewBox" | "xmlns">) => ( + GitLab , DuCanhGH", "license": "MIT", "repository": "https://gitlab.com/serwist/next-pwa", "bugs": "https://gitlab.com/serwist/next-pwa/issues", - "homepage": "https://ducanh2912-next-pwa.vercel.app", - "files": [ - "dist", - "!dist/dts" - ], + "homepage": "https://ducanh-next-pwa.vercel.app", + "files": ["dist", "!dist/dts"], "source": "./src/index.ts", "imports": { "#utils/*.js": "./src/utils/*.ts" @@ -49,9 +40,7 @@ "types": "./dist/index.d.ts", "typesVersions": { "*": { - "workbox": [ - "./dist/sw-entry.d.ts" - ] + "workbox": ["./dist/sw-entry.d.ts"] } }, "scripts": { diff --git a/packages/release/package.json b/packages/release/package.json index 09cb67ee..54aaa9c1 100644 --- a/packages/release/package.json +++ b/packages/release/package.json @@ -10,7 +10,7 @@ "license": "MIT", "repository": "https://gitlab.com/next-pwa/serwist", "bugs": "https://gitlab.com/serwist/next-pwa/issues", - "homepage": "https://ducanh2912-next-pwa.vercel.app", + "homepage": "https://ducanh-next-pwa.vercel.app", "bin": { "serwist-release": "cli.js" }, diff --git a/packages/release/src/lib/get-changed-packages.ts b/packages/release/src/lib/get-changed-packages.ts index 3375d6d4..54ea24e4 100644 --- a/packages/release/src/lib/get-changed-packages.ts +++ b/packages/release/src/lib/get-changed-packages.ts @@ -1,10 +1,8 @@ import fs from "node:fs"; -import path from "node:path"; import assembleReleasePlan from "@changesets/assemble-release-plan"; import { parse as parseConfig } from "@changesets/config"; import type { PackageJSON, WrittenConfig } from "@changesets/types"; -import { glob } from "glob"; -import { getPackages } from "./get-packages.js"; +import { packageNames } from "./package-names.js"; import { readChangesetState } from "./read-changeset-state.js"; import { getPackageJson } from "./utils.js"; @@ -15,18 +13,11 @@ export const getChangedPackages = async ({ }) => { const rootPackageJson = JSON.parse(fs.readFileSync("package.json", "utf-8")) as PackageJSON; - const [potentialWorkspaces, changesetState] = await Promise.all([ - glob("**/package.json", { absolute: false, ignore: ["node_modules/**"], nodir: true }).then((workspaces) => - workspaces.map((e) => path.dirname(e)), - ), - readChangesetState(), - ]); - - const matches = getPackages(potentialWorkspaces); + const changesetState = await readChangesetState(); const packages = { tool: "pnpm", - packages: matches.map((m) => ({ + packages: packageNames.map((m) => ({ packageJson: getPackageJson(m), dir: m, })), diff --git a/packages/release/src/lib/get-packages.ts b/packages/release/src/lib/get-packages.ts deleted file mode 100644 index 189db890..00000000 --- a/packages/release/src/lib/get-packages.ts +++ /dev/null @@ -1,7 +0,0 @@ -import fs from "node:fs"; -import { load } from "js-yaml"; -import { minimatch } from "minimatch"; - -const workspaces = (load(fs.readFileSync("pnpm-workspace.yaml", "utf-8")) as { packages: string[] }).packages; - -export const getPackages = (potentialWorkspaces: string[]) => minimatch.match(potentialWorkspaces, `{${workspaces.join(",")}}`); diff --git a/packages/release/src/lib/package-names.ts b/packages/release/src/lib/package-names.ts new file mode 100644 index 00000000..b79a90e4 --- /dev/null +++ b/packages/release/src/lib/package-names.ts @@ -0,0 +1,15 @@ +import fs from "node:fs"; +import path from "node:path"; +import { globSync } from "glob"; +import { load } from "js-yaml"; +import { minimatch } from "minimatch"; + +const potentialWorkspaces = globSync("**/package.json", { + absolute: false, + ignore: ["node_modules/**"], + nodir: true, +}).map((e) => path.dirname(e)); + +const workspacesGlob = (load(fs.readFileSync("pnpm-workspace.yaml", "utf-8")) as { packages: string[] }).packages; + +export const packageNames = minimatch.match(potentialWorkspaces, `{${workspacesGlob.join(",")}}`); diff --git a/packages/release/src/lib/read-changeset-state.ts b/packages/release/src/lib/read-changeset-state.ts index d64f2efc..74a29f7b 100644 --- a/packages/release/src/lib/read-changeset-state.ts +++ b/packages/release/src/lib/read-changeset-state.ts @@ -12,10 +12,10 @@ export interface ChangesetState { filteredChangesets: NewChangeset[]; } -export const readChangesetState = async (cwd: string = process.cwd()): Promise => { - const preState = await readPreState(cwd); +export const readChangesetState = async (): Promise => { + const preState = await readPreState(process.cwd()); const isInPreMode = preState !== undefined && preState.mode === "pre"; - const changesets = await readChangesets(cwd); + const changesets = await readChangesets(process.cwd()); let changesetsToFilter: Set | null = null; diff --git a/packages/release/src/lib/run.ts b/packages/release/src/lib/run.ts index a6ff7dd6..484634d7 100644 --- a/packages/release/src/lib/run.ts +++ b/packages/release/src/lib/run.ts @@ -2,8 +2,6 @@ import { execSync, spawnSync } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import type { Gitlab } from "@gitbeaker/core"; -import { glob } from "glob"; -import { getPackages } from "./get-packages.js"; import { checkClean as gitCheckClean, commitAll as gitCommitAll, @@ -12,6 +10,7 @@ import { reset as gitReset, switchBranch as gitSwitchBranch, } from "./git-utils.js"; +import { packageNames } from "./package-names.js"; import { readChangesetState } from "./read-changeset-state.js"; import type { Package } from "./types.js"; import { getBumpedPackages, getChangelogEntry, getPackageJson, getVersionsByDirectory } from "./utils.js"; @@ -64,14 +63,9 @@ export const runPublish = async (api: Gitlab): Promise => { } = spawnSync("pnpm", ["changeset", "publish"], { encoding: "utf-8" }); console.log( - "Ran publish script. Status:", - publishStatus ?? "N/A", - ", signal:", - publishSignal ?? "N/A", - ", stdio:", - publishStdout || "N/A", - ", stderr:", - publishStderr || "N/A", + `Ran publish script. Status: ${publishStatus ?? "N/A"}, signal: ${publishSignal ?? "N/A"}, stdio:\n${publishStdout || "N/A"}, stderr:\n${ + publishStderr || "N/A" + }.`, ); if (publishStatus || publishSignal || publishError) { @@ -83,13 +77,7 @@ export const runPublish = async (api: Gitlab): Promise => { gitPushTags(); - const potentialWorkspaces = await glob("**/package.json", { - absolute: true, - ignore: ["node_modules/**"], - nodir: true, - }).then((workspaces) => workspaces.map((e) => path.dirname(e))); - - const packages = getPackages(potentialWorkspaces).map((packageDirectory) => { + const packages = packageNames.map((packageDirectory) => { return { packageJson: getPackageJson(packageDirectory), dir: packageDirectory, @@ -139,7 +127,7 @@ export const runVersion = async (api: Gitlab) => { const currentBranch = ref; const versionBranch = `changeset-release/${currentBranch}`; - const { preState } = await readChangesetState(process.cwd()); + const { preState } = await readChangesetState(); gitSwitchBranch(versionBranch); execSync(`git fetch origin "${currentBranch}"`, { @@ -147,13 +135,13 @@ export const runVersion = async (api: Gitlab) => { }); gitReset(`origin/${currentBranch}`); - const versionsByDirectory = await getVersionsByDirectory(process.cwd()); + const versionsByDirectory = await getVersionsByDirectory(); execSync("pnpm changeset version", { stdio: "inherit", }); - const bumpedPackages = await getBumpedPackages(process.cwd(), versionsByDirectory); + const bumpedPackages = await getBumpedPackages(versionsByDirectory); const packagesToRelease = bumpedPackages .map((pkg) => { diff --git a/packages/release/src/lib/utils.ts b/packages/release/src/lib/utils.ts index a6b3928d..7eeabc44 100644 --- a/packages/release/src/lib/utils.ts +++ b/packages/release/src/lib/utils.ts @@ -2,12 +2,11 @@ import fs from "node:fs"; import path from "node:path"; import type { PackageJSON } from "@changesets/types"; import type { Gitlab } from "@gitbeaker/core"; -import { glob } from "glob"; import { toString as mdastToString } from "mdast-util-to-string"; import remarkParse from "remark-parse"; import remarkStringify from "remark-stringify"; import { unified } from "unified"; -import { getPackages } from "./get-packages.js"; +import { packageNames } from "./package-names.js"; import type { Package } from "./types.js"; export const BumpLevels = { @@ -17,19 +16,12 @@ export const BumpLevels = { major: 3, } as const; -export const getVersionsByDirectory = async (cwd: string) => { - const potentialWorkspaces = await glob("**/package.json", { absolute: false, cwd, ignore: ["node_modules/**"], nodir: true }).then((workspaces) => - workspaces.map((e) => path.dirname(e)), - ); - const packages = getPackages(potentialWorkspaces); - return new Map(packages.map((x) => [x, getPackageJson(x).version])); +export const getVersionsByDirectory = async () => { + return new Map(packageNames.map((x) => [x, getPackageJson(x).version])); }; -export const getBumpedPackages = async (cwd: string, previousVersions: Map) => { - const potentialWorkspaces = await glob("**/package.json", { absolute: false, cwd, ignore: ["node_modules/**"], nodir: true }).then((workspaces) => - workspaces.map((e) => path.dirname(e)), - ); - const packages = getPackages(potentialWorkspaces).map((pkg) => { +export const getBumpedPackages = async (previousVersions: Map) => { + const packages = packageNames.map((pkg) => { return { packageJson: getPackageJson(pkg), dir: pkg,