Skip to content

Commit

Permalink
fix(ci): fixed invalid potentialWorkspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
DuCanhGH committed Apr 4, 2024
1 parent 3532d76 commit a517c13
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 85 deletions.
8 changes: 2 additions & 6 deletions docs/src/components/GitLabLogo.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { SVGProps } from "react";

export const GitLabLogo = (props : Omit<SVGProps<SVGElement>, "ref" | "viewBox" | "xmlns">) => (
<svg
viewBox="-.1 .5 960.1 923.7"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
export const GitLabLogo = (props: Omit<SVGProps<SVGElement>, "ref" | "viewBox" | "xmlns">) => (
<svg viewBox="-.1 .5 960.1 923.7" xmlns="http://www.w3.org/2000/svg" {...props}>
<title>GitLab</title>
<path
d="m958.9 442.4c1.1 26.1-2 52.1-9.2 77.2-7.1 25.1-18.3 48.8-33.1 70.3a240.43 240.43 0 0 1 -53.6 56.2l-.5.4-199.9 149.8-98.3 74.5-59.9 45.2c-3.5 2.7-7.4 4.7-11.5 6.1s-8.5 2.1-12.9 2.1c-4.3 0-8.7-.7-12.8-2.1s-8-3.4-11.5-6.1l-59.9-45.2-98.3-74.5-198.7-148.9-1.2-.8-.4-.4c-20.9-15.7-39-34.7-53.8-56.2s-26-45.3-33.2-70.4c-7.2-25.1-10.3-51.2-9.2-77.3 1.2-26.1 6.5-51.8 15.8-76.2l1.3-3.5 130.7-340.5q1-2.5 2.4-4.8 1.3-2.3 3.1-4.3 1.7-2.1 3.7-3.9 2-1.7 4.2-3.2c3.1-1.9 6.3-3.3 9.8-4.1 3.4-.9 7-1.3 10.5-1.1 3.6.2 7.1.9 10.4 2.2 3.3 1.2 6.5 3 9.3 5.2q2 1.7 3.9 3.6 1.8 2 3.2 4.3 1.5 2.2 2.6 4.7 1.1 2.4 1.8 5l88.1 269.7h356.6l88.1-269.7q.7-2.6 1.9-5 1.1-2.4 2.6-4.7 1.4-2.2 3.2-4.2 1.8-2 3.9-3.7c2.8-2.2 5.9-3.9 9.2-5.2 3.4-1.2 6.9-1.9 10.4-2.1 3.6-.2 7.1.1 10.6 1 3.4.9 6.7 2.3 9.7 4.2q2.3 1.4 4.3 3.2 2 1.7 3.7 3.8 1.7 2.1 3.1 4.4 1.3 2.3 2.3 4.8l130.5 340.6 1.3 3.5c9.3 24.3 14.6 50 15.7 76.1z"
Expand Down
8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
"license": "MIT",
"private": true,
"packageManager": "pnpm@8.15.4",
"workspaces": [
"docs",
"packages/**",
"examples/**",
"!**/.next",
"next-pwa-e2e-test"
],
"workspaces": ["docs", "packages/**", "examples/**", "!**/.next", "next-pwa-e2e-test"],
"scripts": {
"build": "cross-env FORCE_COLOR=1 turbo run build --filter=./packages/*",
"code-check": "biome check --max-diagnostics=150 --log-kind=compact .",
Expand Down
2 changes: 1 addition & 1 deletion packages/configs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "MIT",
"repository": "https://gitlab.com/serwist/next-pwa",
"bugs": "https://gitlab.com/serwist/next-pwa/issues",
"homepage": "https://ducanh2912-next-pwa.vercel.app",
"homepage": "https://ducanh-next-pwa.vercel.app",
"exports": {
"./rollup": {
"types": "./src/rollup.d.ts",
Expand Down
19 changes: 4 additions & 15 deletions packages/next-pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@
"type": "module",
"private": false,
"description": "PWA for Next.js, powered by Workbox.",
"keywords": [
"nextjs",
"pwa",
"workbox",
"web",
"service-worker"
],
"keywords": ["nextjs", "pwa", "workbox", "web", "service-worker"],
"author": "ShadowWalker <w@weiw.io>, 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"
Expand Down Expand Up @@ -49,9 +40,7 @@
"types": "./dist/index.d.ts",
"typesVersions": {
"*": {
"workbox": [
"./dist/sw-entry.d.ts"
]
"workbox": ["./dist/sw-entry.d.ts"]
}
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
15 changes: 3 additions & 12 deletions packages/release/src/lib/get-changed-packages.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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,
})),
Expand Down
7 changes: 0 additions & 7 deletions packages/release/src/lib/get-packages.ts

This file was deleted.

15 changes: 15 additions & 0 deletions packages/release/src/lib/package-names.ts
Original file line number Diff line number Diff line change
@@ -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(",")}}`);
6 changes: 3 additions & 3 deletions packages/release/src/lib/read-changeset-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export interface ChangesetState {
filteredChangesets: NewChangeset[];
}

export const readChangesetState = async (cwd: string = process.cwd()): Promise<ChangesetState> => {
const preState = await readPreState(cwd);
export const readChangesetState = async (): Promise<ChangesetState> => {
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<string> | null = null;

Expand Down
28 changes: 8 additions & 20 deletions packages/release/src/lib/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand Down Expand Up @@ -64,14 +63,9 @@ export const runPublish = async (api: Gitlab): Promise<PublishResult> => {
} = 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) {
Expand All @@ -83,13 +77,7 @@ export const runPublish = async (api: Gitlab): Promise<PublishResult> => {

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,
Expand Down Expand Up @@ -139,21 +127,21 @@ 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}"`, {
stdio: "inherit",
});
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) => {
Expand Down
18 changes: 5 additions & 13 deletions packages/release/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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<string, 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).map((pkg) => {
export const getBumpedPackages = async (previousVersions: Map<string, string>) => {
const packages = packageNames.map((pkg) => {
return {
packageJson: getPackageJson(pkg),
dir: pkg,
Expand Down

0 comments on commit a517c13

Please sign in to comment.