diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f2265ffe..a11ed1df 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -129,7 +129,9 @@ Repository maintainers can publish a new version of all packages to npm. Here are the steps to publish (we generally use CI for releases and avoid publishing npm packages locally): -1. [Create release pull request](https://github.com/web-infra-dev/rslib/actions/workflows/release-pull-request.yml). + + +1. Run `pnpm generate-release-pr` to create a release pull request. 2. [Run the release action](https://github.com/web-infra-dev/rslib/actions/workflows/release.yml). 3. [Generate the release notes](https://github.com/web-infra-dev/rslib/releases). 4. Merge the release pull request. @@ -138,6 +140,6 @@ Here are the steps to publish (we generally use CI for releases and avoid publis The project is still in its early stages and under active development, so it possible dependents on Rsbuild or Rspack canary versions to test the latest features. The current versions are: -| Package | Link | -| ------------ | ------------------------------------------------- | -| @rspack/core | https://github.com/web-infra-dev/rspack/pull/7939 | +| Package | Link | +| ------------ | ------------------------------------------------------------ | +| @rspack/core | https://github.com/web-infra-dev/rspack/releases/tag/v1.0.10 | diff --git a/package.json b/package.json index cd53efb3..9119413b 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "changeset": "changeset", "check-dependency-version": "check-dependency-version-consistency .", "check-spell": "pnpx cspell", + "generate-release-pr": "zx scripts/generateReleasePr.mjs", "lint": "biome check . --diagnostic-level=warn && pnpm run check-spell", "prebundle": "nx run-many -t prebundle", "prepare": "pnpm run build && simple-git-hooks", @@ -54,11 +55,17 @@ "prettier-plugin-packagejson": "^2.5.3", "simple-git-hooks": "^2.11.1", "typescript": "^5.6.3", - "vitest": "^2.1.2" + "vitest": "^2.1.2", + "zx": "^8.1.9" }, - "packageManager": "pnpm@9.9.0", + "packageManager": "pnpm@9.12.1", "engines": { "node": ">=18.0.0", "pnpm": ">=9.0.0" + }, + "pnpm": { + "overrides": { + "zx>@types/node": "-" + } } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a00f07fa..b4c5692e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,9 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +overrides: + zx>@types/node: '-' + importers: .: @@ -53,6 +56,9 @@ importers: vitest: specifier: ^2.1.2 version: 2.1.2(@types/node@18.19.39)(terser@5.31.6) + zx: + specifier: ^8.1.9 + version: 8.1.9 examples/express-plugin: devDependencies: @@ -4809,6 +4815,11 @@ packages: zwitch@2.0.4: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} + zx@8.1.9: + resolution: {integrity: sha512-UHuLHphHmsBYKkAchkSrEN4nzDyagafqC9HUxtc1J7eopaScW6H9dsLJ1lmkAntnLtDTGoM8fa+jrJrXiIfKFA==} + engines: {node: '>= 12.17.0'} + hasBin: true + snapshots: '@alloc/quick-lru@5.2.0': {} @@ -9588,3 +9599,7 @@ snapshots: yocto-queue@1.1.1: {} zwitch@2.0.4: {} + + zx@8.1.9: + optionalDependencies: + '@types/fs-extra': 11.0.4 diff --git a/scripts/generateReleasePr.mjs b/scripts/generateReleasePr.mjs new file mode 100644 index 00000000..d30df290 --- /dev/null +++ b/scripts/generateReleasePr.mjs @@ -0,0 +1,106 @@ +#!/usr/bin/env zx + +import fs from 'node:fs/promises'; +import path from 'node:path'; +import { parseArgs } from 'node:util'; +import { $, chalk } from 'zx'; + +$.verbose = false; + +async function getCurrentVersion() { + const packageJsonPath = path.join( + process.cwd(), + 'packages/core/package.json', + ); + const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8')); + return packageJson.version; +} + +async function getNextVersion(currentVersion, type) { + const [major, minor, patch] = currentVersion.split('.').map(Number); + switch (type) { + case 'patch': + return `${major}.${minor}.${patch + 1}`; + case 'minor': + return `${major}.${minor + 1}.0`; + case 'major': + return `${major + 1}.0.0`; + default: + throw new Error('Invalid version type'); + } +} + +async function generateChangesetFile(bumpType, nextVersion) { + const changesetDir = path.join(process.cwd(), '.changeset'); + const timestamp = Date.now(); + const filename = `${timestamp}-${bumpType}-release.md`; + const content = `--- +"@rslib/core": ${bumpType} +--- + +Release version ${nextVersion} +`; + + await fs.mkdir(changesetDir, { recursive: true }); + await fs.writeFile(path.join(changesetDir, filename), content); + + console.log(chalk.blue(`Generated changeset file: ${filename}`)); +} + +async function main() { + try { + // 1. Read the current version + const currentVersion = await getCurrentVersion(); + console.log(chalk.blue(`Current version: ${currentVersion}`)); + + // 2. Determine bump type and next release version + const options = { + type: { + type: 'string', + short: 't', + default: 'patch', + }, + }; + const args = process.argv.slice(3); + const { values } = parseArgs({ args, options }); + + const bumpType = values.type; + + if (!['major', 'minor', 'patch'].includes(bumpType)) { + console.error('Invalid bump type. Please select major, minor, or patch.'); + process.exit(1); + } + + console.log(chalk.blue(`Bump type: ${bumpType}`)); + + const nextVersion = await getNextVersion(currentVersion, bumpType); + console.log(chalk.blue(`Next version: ${nextVersion}`)); + + // 3. Create and switch to new branch + const branchName = `release-v${nextVersion}`; + console.log(chalk.blue(`Creating branch: ${branchName}`)); + + await $`git checkout -b ${branchName}`; + + // 4. Generate changeset file + await generateChangesetFile(bumpType, nextVersion); + + // 5. Run changeset version and pnpm install + await $`pnpm run changeset version`; + await $`pnpm install --ignore-scripts`; + + // 6. Commit changes + await $`git add .`; + await $`git commit -m "Release v${nextVersion}"`; + + // 7. Push to remote repo + await $`git push -u origin ${branchName}`; + + console.log(chalk.green(`Successfully created and pushed ${branchName}`)); + } catch (error) { + console.error(chalk.red(`Error: ${error.message}`)); + process.exit(1); + } +} + +main(); diff --git a/tests/README.md b/tests/README.md index 1fbcf687..5aaaf4ec 100644 --- a/tests/README.md +++ b/tests/README.md @@ -36,7 +36,7 @@ Rslib will try to cover the common scenarios in the [integration test cases of M | sourceDir | 🟢 | | | sourceMap | 🟢 | | | splitting | ⚪️ | | -| style | ⚪️ | | +| style | 🟡 | asset svgr in CSS / css banner and footer | | target | 🟢 | | | transformImport | 🟢 | | | transformLodash | 🟢 | |