From e16a8cd3e246910bca13351db370258a6a65ae26 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 17:33:25 +0800 Subject: [PATCH 1/9] workflow: separate version bumping and publishing on release --- .github/workflows/publish.yml | 37 ++++ .github/workflows/release.yml | 79 --------- package.json | 2 + packages/plugin-legacy/package.json | 2 +- packages/plugin-react/package.json | 2 +- packages/plugin-vue-jsx/package.json | 2 +- packages/plugin-vue/package.json | 2 +- packages/vite/package.json | 2 +- scripts/publishCI.ts | 33 ++++ scripts/release.ts | 248 ++++++--------------------- scripts/releaseUtils.ts | 135 +++++++++++++++ 11 files changed, 268 insertions(+), 276 deletions(-) create mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/release.yml create mode 100644 scripts/publishCI.ts create mode 100644 scripts/releaseUtils.ts diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000000000..6493fa01665b51 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,37 @@ +name: Publish Package + +on: + push: + tags: + - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10 + - "plugin-*" # Push events to matching plugin-*, i.e. plugin-(vue|vue-jsx|react|legacy)@1.0.0 + - "create-vite*" # # Push events to matching create-vite*, i.e. create-vite@1.0.0 + +jobs: + publish: + # prevents this action from running on forks + if: github.repository == 'vitejs/vite' + runs-on: ubuntu-latest + environment: Release + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: 6 + + - name: Set node version to 16.x + uses: actions/setup-node@v2 + with: + node-version: 16.x + cache: "pnpm" + + - name: Install deps + run: pnpm install + + - name: Publish package + run: pnpm run ci-publish -- ${{ github.ref_name }} --dry + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index b059c0bfa35bc0..00000000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: Release - -on: - workflow_dispatch: - inputs: - branch: - description: "branch" - required: true - type: string - default: "main" - package: - description: "package" - required: true - type: choice - options: - - vite - - plugin-legacy - - plugin-vue - - plugin-vue-jsx - - plugin-react - - create-vite - type: - description: "type" - required: true - type: choice - options: - - next - - stable - - minor-beta - - major-beta - - minor - - major - -jobs: - release: - # prevents this action from running on forks - if: github.repository == 'vitejs/vite' - name: Release - runs-on: ${{ matrix.os }} - environment: Release - strategy: - matrix: - # pseudo-matrix for convenience, NEVER use more than a single combination - node: [16] - os: [ubuntu-latest] - steps: - - name: checkout - uses: actions/checkout@v2 - with: - # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits - ref: ${{ github.event.inputs.branch }} - fetch-depth: 0 - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - - run: git config user.name vitebot - - run: git config user.email vitejs.bot@gmail.com - - run: npm i -g pnpm@6 - - run: npm i -g yarn # even if the repo is using pnpm, Vite still uses yarn v1 for publishing - - run: yarn config set registry https://registry.npmjs.org # Yarn's default registry proxy doesn't work in CI - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - cache: "pnpm" - cache-dependency-path: "**/pnpm-lock.yaml" - - name: install - run: pnpm install --frozen-lockfile --prefer-offline - - name: Creating .npmrc - run: | - cat << EOF > "$HOME/.npmrc" - //registry.npmjs.org/:_authToken=$NPM_TOKEN - EOF - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - name: Release - run: pnpm --dir packages/${{ github.event.inputs.package }} release -- --quiet --type ${{ github.event.inputs.type }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index 63c7e38d0d0652..72b7076ee65d01 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,8 @@ "docs": "vitepress dev docs", "build-docs": "vitepress build docs", "serve-docs": "vitepress serve docs", + "release": "ts-node scripts/release.ts", + "ci-publish": "ts-node scripts/publishCI.ts", "build": "run-s build-vite build-plugin-vue build-plugin-react", "build-vite": "cd packages/vite && npm run build", "build-plugin-vue": "cd packages/plugin-vue && npm run build", diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json index 45c09f607fdfab..b5f7139dca20f4 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -11,7 +11,7 @@ "types": "index.d.ts", "scripts": { "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-legacy", - "release": "ts-node ../../scripts/release.ts --skipBuild" + "release": "ts-node ../../scripts/release.ts" }, "engines": { "node": ">=12.0.0" diff --git a/packages/plugin-react/package.json b/packages/plugin-react/package.json index 1047a390865f4f..fe4f8071924548 100644 --- a/packages/plugin-react/package.json +++ b/packages/plugin-react/package.json @@ -19,7 +19,7 @@ "patch-dist": "ts-node ../../scripts/patchEsbuildDist.ts dist/index.js viteReact", "build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-react", - "release": "ts-node ../../scripts/release.ts" + "prepublishOnly": "npm run build" }, "engines": { "node": ">=12.0.0" diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index c26a343c9c4227..1580b25f0a38c3 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -11,7 +11,7 @@ "types": "index.d.ts", "scripts": { "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue-jsx", - "release": "ts-node ../../scripts/release.ts --skipBuild" + "release": "ts-node ../../scripts/release.ts" }, "engines": { "node": ">=12.0.0" diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index f54042da5bf948..81518766384206 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -17,7 +17,7 @@ "patch-dist": "ts-node ../../scripts/patchEsbuildDist.ts dist/index.js vuePlugin", "build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue", - "release": "ts-node ../../scripts/release.ts" + "prepublishOnly": "npm run build" }, "engines": { "node": ">=12.0.0" diff --git a/packages/vite/package.json b/packages/vite/package.json index 2f57fb3f59164d..e1360808c321d6 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -40,7 +40,7 @@ "lint": "eslint --ext .ts src/**", "format": "prettier --write --parser typescript \"src/**/*.ts\"", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .", - "release": "ts-node ../../scripts/release.ts" + "prepublishOnly": "npm run build" }, "//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!", "dependencies": { diff --git a/scripts/publishCI.ts b/scripts/publishCI.ts new file mode 100644 index 00000000000000..a698e9a06feaaf --- /dev/null +++ b/scripts/publishCI.ts @@ -0,0 +1,33 @@ +import { args, getPackageInfo, publishPackage, step } from './releaseUtils' + +async function main() { + const tag = args._[0] + + if (!tag) { + throw new Error('No tag specified') + } + + let pkgName = 'vite' + let version + + if (tag.includes('@')) [pkgName, version] = tag.split('@') + else version = tag + + if (!version.startsWith('v')) throw new Error('Invalid tag ' + tag) + + version = version.slice(1) + + const { currentVersion, pkgPath } = getPackageInfo(pkgName) + if (currentVersion !== version) + throw new Error( + `Package version from tag "${version}" mismatches with current version "${currentVersion}"` + ) + + step('Publishing package...') + await publishPackage(pkgPath, version.includes('beta') ? 'beta' : undefined) +} + +main().catch((err) => { + console.error(err) + process.exit(1) +}) diff --git a/scripts/release.ts b/scripts/release.ts index e24f539547f014..d9d2d7c1c2135c 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -1,134 +1,52 @@ -/** - * modified from https://github.com/vuejs/core/blob/master/scripts/release.js - */ -import colors from 'picocolors' -import type { ExecaChildProcess, Options as ExecaOptions } from 'execa' -import execa from 'execa' -import { readFileSync, writeFileSync } from 'fs' -import path from 'path' import prompts from 'prompts' -import type { ReleaseType } from 'semver' import semver from 'semver' +import colors from 'picocolors' +import { + args, + getPackageInfo, + getVersionChoices, + isDryRun, + packages, + run, + runIfNotDry, + step, + updateVersion +} from './releaseUtils' -const args = require('minimist')(process.argv.slice(2)) - -// For GitHub Actions use -// Regular release : release --type next --quiet -// Start beta : release --type (minor-beta|major-beta) --quiet -// Release from beta : release --type stable --quiet - -const pkgDir = process.cwd() -const pkgPath = path.resolve(pkgDir, 'package.json') -const pkg: { name: string; version: string } = require(pkgPath) -const pkgName = pkg.name.replace(/^@vitejs\//, '') -const currentVersion = pkg.version -const isDryRun: boolean = args.dry -const skipBuild: boolean = args.skipBuild - -const versionIncrements: ReleaseType[] = [ - 'patch', - 'minor', - 'major', - 'prepatch', - 'preminor', - 'premajor', - 'prerelease' -] - -const inc: (i: ReleaseType) => string = (i) => - semver.inc(currentVersion, i, 'beta')! - -type RunFn = ( - bin: string, - args: string[], - opts?: ExecaOptions -) => ExecaChildProcess - -const run: RunFn = (bin, args, opts = {}) => - execa(bin, args, { stdio: 'inherit', ...opts }) +async function main(): Promise { + if (isDryRun) console.log('DRY RUN') -type DryRunFn = (bin: string, args: string[], opts?: any) => void + let targetVersion: string | undefined -const dryRun: DryRunFn = (bin, args, opts: any) => - console.log(colors.blue(`[dryrun] ${bin} ${args.join(' ')}`), opts) + const { pkg }: { pkg: string } = await prompts({ + type: 'select', + name: 'pkg', + message: 'Select package', + choices: packages.map((i) => ({ value: i, title: i })) + }) -const runIfNotDry = isDryRun ? dryRun : run + if (!pkg) return -const step: (msg: string) => void = (msg) => console.log(colors.cyan(msg)) - -async function main(): Promise { - let targetVersion: string | undefined = args._[0] + const { currentVersion, pkgName, pkgPath } = getPackageInfo(pkg) if (!targetVersion) { - const type: string | undefined = args.type - if (type) { - const currentBeta = currentVersion.includes('beta') - if (type === 'next') { - targetVersion = inc(currentBeta ? 'prerelease' : 'patch') - } else if (type === 'stable') { - // Out of beta - if (!currentBeta) { - throw new Error( - `Current version: ${currentVersion} isn't a beta, stable can't be used` - ) - } - targetVersion = inc('patch') - } else if (type === 'minor-beta') { - if (currentBeta) { - throw new Error( - `Current version: ${currentVersion} is already a beta, minor-beta can't be used` - ) - } - targetVersion = inc('preminor') - } else if (type === 'major-beta') { - if (currentBeta) { - throw new Error( - `Current version: ${currentVersion} is already a beta, major-beta can't be used` - ) - } - targetVersion = inc('premajor') - } else if (type === 'minor') { - if (currentBeta) { - throw new Error( - `Current version: ${currentVersion} is a beta, use stable to release it first` - ) - } - targetVersion = inc('minor') - } else if (type === 'major') { - if (currentBeta) { - throw new Error( - `Current version: ${currentVersion} is a beta, use stable to release it first` - ) - } - targetVersion = inc('major') - } else { - throw new Error( - `type: ${type} isn't a valid type. Use stable, minor-beta, major-beta, or next` - ) - } - } else { - // no explicit version or type, offer suggestions - const { release }: { release: string } = await prompts({ - type: 'select', - name: 'release', - message: 'Select release type', - choices: versionIncrements - .map((i) => `${i} (${inc(i)})`) - .concat(['custom']) - .map((i) => ({ value: i, title: i })) - }) + const { release }: { release: string } = await prompts({ + type: 'select', + name: 'release', + message: 'Select release type', + choices: getVersionChoices(currentVersion) + }) - if (release === 'custom') { - const res: { version: string } = await prompts({ - type: 'text', - name: 'version', - message: 'Input custom version', - initial: currentVersion - }) - targetVersion = res.version - } else { - targetVersion = release.match(/\((.*)\)/)![1] - } + if (release === 'custom') { + const res: { version: string } = await prompts({ + type: 'text', + name: 'version', + message: 'Input custom version', + initial: currentVersion + }) + targetVersion = res.version + } else { + targetVersion = release } } @@ -139,44 +57,25 @@ async function main(): Promise { const tag = pkgName === 'vite' ? `v${targetVersion}` : `${pkgName}@${targetVersion}` - if (!args.quiet) { - if (targetVersion.includes('beta') && !args.tag) { - const { tagBeta }: { tagBeta: boolean } = await prompts({ - type: 'confirm', - name: 'tagBeta', - message: `Publish under dist-tag "beta"?` - }) - - if (tagBeta) args.tag = 'beta' - } + if (targetVersion.includes('beta') && !args.tag) { + args.tag = 'beta' + } - const { yes }: { yes: boolean } = await prompts({ - type: 'confirm', - name: 'yes', - message: `Releasing ${tag}. Confirm?` - }) + const { yes }: { yes: boolean } = await prompts({ + type: 'confirm', + name: 'yes', + message: `Releasing ${colors.yellow(tag)} Confirm?` + }) - if (!yes) { - return - } - } else { - if (targetVersion.includes('beta') && !args.tag) { - args.tag = 'beta' - } + if (!yes) { + return } step('\nUpdating package version...') - updateVersion(targetVersion) - - step('\nBuilding package...') - if (!skipBuild && !isDryRun) { - await run('pnpm', ['run', 'build']) - } else { - console.log(`(skipped)`) - } + if (!isDryRun) updateVersion(pkgPath, targetVersion) step('\nGenerating changelog...') - await run('pnpm', ['run', 'changelog']) + await runIfNotDry('pnpm', ['run', 'changelog']) const { stdout } = await run('git', ['diff'], { stdio: 'pipe' }) if (stdout) { @@ -188,9 +87,6 @@ async function main(): Promise { console.log('No changes to commit.') } - step('\nPublishing package...') - await publishPackage(targetVersion, runIfNotDry) - step('\nPushing to GitHub...') await runIfNotDry('git', ['push', 'origin', `refs/tags/${tag}`]) await runIfNotDry('git', ['push']) @@ -199,46 +95,14 @@ async function main(): Promise { console.log(`\nDry run finished - run git diff to see package changes.`) } - console.log() -} - -function updateVersion(version: string): void { - const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) - pkg.version = version - writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') -} + step( + '\nTag pushed, publishing should starts shortly on CI.\nhttps://github.com/vitejs/vite/actions/workflows/publish.yml' + ) -async function publishPackage( - version: string, - runIfNotDry: RunFn | DryRunFn -): Promise { - const publicArgs = [ - 'publish', - '--no-git-tag-version', - '--new-version', - version, - '--access', - 'public' - ] - if (args.tag) { - publicArgs.push(`--tag`, args.tag) - } - try { - // important: we still use Yarn 1 to publish since we rely on its specific - // behavior - await runIfNotDry('yarn', publicArgs, { - stdio: 'pipe' - }) - console.log(colors.green(`Successfully published ${pkgName}@${version}`)) - } catch (e: any) { - if (e.stderr.match(/previously published/)) { - console.log(colors.red(`Skipping already published: ${pkgName}`)) - } else { - throw e - } - } + console.log() } main().catch((err) => { console.error(err) + process.exit(1) }) diff --git a/scripts/releaseUtils.ts b/scripts/releaseUtils.ts new file mode 100644 index 00000000000000..5650784c6845ac --- /dev/null +++ b/scripts/releaseUtils.ts @@ -0,0 +1,135 @@ +/** + * modified from https://github.com/vuejs/core/blob/master/scripts/release.js + */ +import colors from 'picocolors' +import type { Options as ExecaOptions } from 'execa' +import execa from 'execa' +import { readFileSync, writeFileSync, existsSync } from 'fs' +import path from 'path' +import type { ReleaseType } from 'semver' +import semver from 'semver' + +export const args = require('minimist')(process.argv.slice(2)) + +export const isDryRun = !!args.dry + +export const packages = [ + 'vite', + 'create-vite', + 'plugin-legacy', + 'plugin-react', + 'plugin-vue', + 'plugin-vue-jsx' +] + +export const versionIncrements: ReleaseType[] = [ + 'patch', + 'minor', + 'major' + // 'prepatch', + // 'preminor', + // 'premajor', + // 'prerelease' +] + +export function getPackageInfo(pkgName: string) { + const pkgDir = path.resolve(__dirname, '../packages/' + pkgName) + + if (!existsSync(pkgDir)) { + throw new Error(`Package ${pkgName} not found`) + } + + const pkgPath = path.resolve(pkgDir, 'package.json') + const pkg: { + name: string + version: string + private?: boolean + } = require(pkgPath) + const currentVersion = pkg.version + + if (pkg.private) { + throw new Error(`Package ${pkgName} is private`) + } + + return { + pkgName, + pkg, + pkgPath, + currentVersion + } +} + +export async function run( + bin: string, + args: string[], + opts: ExecaOptions = {} +) { + return execa(bin, args, { stdio: 'inherit', ...opts }) +} + +export async function dryRun( + bin: string, + args: string[], + opts?: ExecaOptions +) { + return console.log(colors.blue(`[dryrun] ${bin} ${args.join(' ')}`)) +} + +export const runIfNotDry = isDryRun ? dryRun : run + +export function step(msg: string) { + return console.log(colors.cyan(msg)) +} + +export function getVersionChoices(currentVersion: string) { + const currentBeta = currentVersion.includes('beta') + + const inc: (i: ReleaseType) => string = (i) => + semver.inc(currentVersion, i, 'beta')! + + const versionChoices = [ + { + title: 'next', + value: inc(currentBeta ? 'prerelease' : 'patch') + }, + currentBeta + ? { + title: 'stable', + value: inc('patch') + } + : { + title: 'beta', + value: inc('prerelease') + }, + ...versionIncrements.map((i) => ({ + value: inc(i), + title: i + })), + { value: 'custom', title: 'custom' } + ].map((i) => { + i.title = `${i.title} (${i.value})` + return i + }) + + return versionChoices +} + +export function updateVersion(pkgPath: string, version: string): void { + const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) + pkg.version = version + writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') +} + +export async function publishPackage( + pkgPath: string, + tag?: string +): Promise { + const publicArgs = ['publish', '--access', 'public'] + if (tag) { + publicArgs.push(`--tag`, tag) + } + await runIfNotDry('npm', publicArgs, { + stdio: 'pipe', + cwd: pkgPath + }) +} From 68a26848fd68f836d5295b716c8ea6f747749a68 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 17:48:13 +0800 Subject: [PATCH 2/9] chore: update create-vite templates version --- packages/create-vite/package.json | 3 +-- packages/create-vite/updateVersions.ts | 23 ----------------------- packages/plugin-legacy/package.json | 3 +-- packages/plugin-vue-jsx/package.json | 3 +-- scripts/release.ts | 6 +++++- scripts/releaseUtils.ts | 22 +++++++++++++++++++++- 6 files changed, 29 insertions(+), 31 deletions(-) delete mode 100644 packages/create-vite/updateVersions.ts diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index 6ff118b7793840..e7fd1f800fe3fd 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -13,8 +13,7 @@ ], "main": "index.js", "scripts": { - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package create-vite", - "release": "ts-node updateVersions && ts-node ../../scripts/release.ts --skipBuild" + "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package create-vite" }, "engines": { "node": ">=12.0.0" diff --git a/packages/create-vite/updateVersions.ts b/packages/create-vite/updateVersions.ts deleted file mode 100644 index 7125fce9119f07..00000000000000 --- a/packages/create-vite/updateVersions.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { readdirSync, writeFileSync } from 'fs' -import { join } from 'path' - -const latestVersion = require('../vite/package.json').version -const isLatestPreRelease = /beta|alpha|rc/.test(latestVersion) - -;(async () => { - const templates = readdirSync(__dirname).filter((dir) => - dir.startsWith('template-') - ) - for (const template of templates) { - const pkgPath = join(__dirname, template, `package.json`) - const pkg = require(pkgPath) - if (!isLatestPreRelease) { - pkg.devDependencies.vite = `^` + latestVersion - } - if (template.startsWith('template-vue')) { - pkg.devDependencies['@vitejs/plugin-vue'] = - `^` + require('../plugin-vue/package.json').version - } - writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') - } -})() diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json index b5f7139dca20f4..f715926dd8b929 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -10,8 +10,7 @@ "main": "index.js", "types": "index.d.ts", "scripts": { - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-legacy", - "release": "ts-node ../../scripts/release.ts" + "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-legacy" }, "engines": { "node": ">=12.0.0" diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 1580b25f0a38c3..32cd2550451f62 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -10,8 +10,7 @@ "main": "index.js", "types": "index.d.ts", "scripts": { - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue-jsx", - "release": "ts-node ../../scripts/release.ts" + "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue-jsx" }, "engines": { "node": ">=12.0.0" diff --git a/scripts/release.ts b/scripts/release.ts index d9d2d7c1c2135c..4658bed2683b6f 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -10,6 +10,7 @@ import { run, runIfNotDry, step, + updateTemplateVersions, updateVersion } from './releaseUtils' @@ -72,7 +73,10 @@ async function main(): Promise { } step('\nUpdating package version...') - if (!isDryRun) updateVersion(pkgPath, targetVersion) + if (!isDryRun) { + updateVersion(pkgPath, targetVersion) + if (pkgName === 'create-vite') updateTemplateVersions(targetVersion) + } step('\nGenerating changelog...') await runIfNotDry('pnpm', ['run', 'changelog']) diff --git a/scripts/releaseUtils.ts b/scripts/releaseUtils.ts index 5650784c6845ac..c427df53435cfe 100644 --- a/scripts/releaseUtils.ts +++ b/scripts/releaseUtils.ts @@ -4,7 +4,7 @@ import colors from 'picocolors' import type { Options as ExecaOptions } from 'execa' import execa from 'execa' -import { readFileSync, writeFileSync, existsSync } from 'fs' +import { readFileSync, writeFileSync, existsSync, readdirSync } from 'fs' import path from 'path' import type { ReleaseType } from 'semver' import semver from 'semver' @@ -133,3 +133,23 @@ export async function publishPackage( cwd: pkgPath }) } + +export async function updateTemplateVersions(version: string) { + if (/beta|alpha|rc/.test(version)) return + + const dir = path.resolve(__dirname, '../packages/create-vite') + + const templates = readdirSync(dir).filter((dir) => + dir.startsWith('template-') + ) + for (const template of templates) { + const pkgPath = path.join(dir, template, `package.json`) + const pkg = require(pkgPath) + pkg.devDependencies.vite = `^` + version + if (template.startsWith('template-vue')) { + pkg.devDependencies['@vitejs/plugin-vue'] = + `^` + require('../packages/plugin-vue/package.json').version + } + writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') + } +} From cf54ab2a103b4dc1375a0b9b28dad6ef31aac65c Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 17:54:00 +0800 Subject: [PATCH 3/9] chore: inline changelog script --- packages/create-vite/package.json | 3 --- packages/plugin-legacy/package.json | 3 --- packages/plugin-react/package.json | 1 - packages/plugin-vue-jsx/package.json | 3 --- packages/plugin-vue/package.json | 1 - packages/vite/package.json | 1 - scripts/release.ts | 13 ++++++++++++- scripts/releaseUtils.ts | 5 ++++- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index e7fd1f800fe3fd..5d873b83fe515b 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -12,9 +12,6 @@ "template-*" ], "main": "index.js", - "scripts": { - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package create-vite" - }, "engines": { "node": ">=12.0.0" }, diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json index f715926dd8b929..e464c18b4dca1d 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -9,9 +9,6 @@ ], "main": "index.js", "types": "index.d.ts", - "scripts": { - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-legacy" - }, "engines": { "node": ">=12.0.0" }, diff --git a/packages/plugin-react/package.json b/packages/plugin-react/package.json index fe4f8071924548..67df1d30b89b0c 100644 --- a/packages/plugin-react/package.json +++ b/packages/plugin-react/package.json @@ -18,7 +18,6 @@ "build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@babel/* --external:@rollup/* --external:resolve --external:react-refresh/* --outfile=dist/index.js && npm run patch-dist", "patch-dist": "ts-node ../../scripts/patchEsbuildDist.ts dist/index.js viteReact", "build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp", - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-react", "prepublishOnly": "npm run build" }, "engines": { diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 32cd2550451f62..dff19a227804d1 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -9,9 +9,6 @@ ], "main": "index.js", "types": "index.d.ts", - "scripts": { - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue-jsx" - }, "engines": { "node": ">=12.0.0" }, diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index 81518766384206..ca8836d8e81d36 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -16,7 +16,6 @@ "build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@vue/compiler-sfc --external:vue/compiler-sfc --external:vite --outfile=dist/index.js & npm run patch-dist", "patch-dist": "ts-node ../../scripts/patchEsbuildDist.ts dist/index.js vuePlugin", "build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp", - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue", "prepublishOnly": "npm run build" }, "engines": { diff --git a/packages/vite/package.json b/packages/vite/package.json index e1360808c321d6..9bd14ca89a4d16 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -39,7 +39,6 @@ "roll-types": "api-extractor run && rimraf temp", "lint": "eslint --ext .ts src/**", "format": "prettier --write --parser typescript \"src/**/*.ts\"", - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .", "prepublishOnly": "npm run build" }, "//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!", diff --git a/scripts/release.ts b/scripts/release.ts index 4658bed2683b6f..0b37ee814d466c 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -79,7 +79,18 @@ async function main(): Promise { } step('\nGenerating changelog...') - await runIfNotDry('pnpm', ['run', 'changelog']) + const changelogArgs = [ + 'conventional-changelog', + '-p', + 'angular', + '-i', + 'CHANGELOG.md', + '-s', + '--commit-path', + '.' + ] + if (pkgName !== 'vite') changelogArgs.push('--lerna-package', 'plugin-vue') + await runIfNotDry('npx', changelogArgs, { cwd: pkgPath }) const { stdout } = await run('git', ['diff'], { stdio: 'pipe' }) if (stdout) { diff --git a/scripts/releaseUtils.ts b/scripts/releaseUtils.ts index c427df53435cfe..64f7ee75d55961 100644 --- a/scripts/releaseUtils.ts +++ b/scripts/releaseUtils.ts @@ -72,7 +72,10 @@ export async function dryRun( args: string[], opts?: ExecaOptions ) { - return console.log(colors.blue(`[dryrun] ${bin} ${args.join(' ')}`)) + return console.log( + colors.blue(`[dryrun] ${bin} ${args.join(' ')}`), + opts || '' + ) } export const runIfNotDry = isDryRun ? dryRun : run From 65910643aa0adf376be31c456f0dc5ccd6dbc308 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 17:56:35 +0800 Subject: [PATCH 4/9] chore: update action --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6493fa01665b51..f4df5af00cc23c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -34,4 +34,4 @@ jobs: - name: Publish package run: pnpm run ci-publish -- ${{ github.ref_name }} --dry env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From 3024e5622586324729c9220fc3369256461d8a37 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 18:16:39 +0800 Subject: [PATCH 5/9] chore: update version choices --- scripts/releaseUtils.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/scripts/releaseUtils.ts b/scripts/releaseUtils.ts index 64f7ee75d55961..4fb9f5bfe0703f 100644 --- a/scripts/releaseUtils.ts +++ b/scripts/releaseUtils.ts @@ -95,15 +95,23 @@ export function getVersionChoices(currentVersion: string) { title: 'next', value: inc(currentBeta ? 'prerelease' : 'patch') }, - currentBeta - ? { - title: 'stable', - value: inc('patch') - } - : { - title: 'beta', - value: inc('prerelease') - }, + ...(currentBeta + ? [ + { + title: 'stable', + value: inc('patch') + } + ] + : [ + { + title: 'beta-minor', + value: inc('preminor') + }, + { + title: 'beta-major', + value: inc('premajor') + } + ]), ...versionIncrements.map((i) => ({ value: inc(i), title: i From 6923bc9768833cd52f41e450f935502c19be2658 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 18:30:56 +0800 Subject: [PATCH 6/9] chore: show commit diff on release --- scripts/publishCI.ts | 4 +--- scripts/release.ts | 5 +++-- scripts/releaseUtils.ts | 44 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/scripts/publishCI.ts b/scripts/publishCI.ts index a698e9a06feaaf..ac93abcc920eb3 100644 --- a/scripts/publishCI.ts +++ b/scripts/publishCI.ts @@ -13,9 +13,7 @@ async function main() { if (tag.includes('@')) [pkgName, version] = tag.split('@') else version = tag - if (!version.startsWith('v')) throw new Error('Invalid tag ' + tag) - - version = version.slice(1) + if (version.startsWith('v')) version = version.slice(1) const { currentVersion, pkgPath } = getPackageInfo(pkgName) if (currentVersion !== version) diff --git a/scripts/release.ts b/scripts/release.ts index 0b37ee814d466c..4ef47749bfcae9 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -6,6 +6,7 @@ import { getPackageInfo, getVersionChoices, isDryRun, + logRecentCommits, packages, run, runIfNotDry, @@ -15,8 +16,6 @@ import { } from './releaseUtils' async function main(): Promise { - if (isDryRun) console.log('DRY RUN') - let targetVersion: string | undefined const { pkg }: { pkg: string } = await prompts({ @@ -28,6 +27,8 @@ async function main(): Promise { if (!pkg) return + await logRecentCommits(pkg) + const { currentVersion, pkgName, pkgPath } = getPackageInfo(pkg) if (!targetVersion) { diff --git a/scripts/releaseUtils.ts b/scripts/releaseUtils.ts index 4fb9f5bfe0703f..b39968a2a859b5 100644 --- a/scripts/releaseUtils.ts +++ b/scripts/releaseUtils.ts @@ -13,6 +13,11 @@ export const args = require('minimist')(process.argv.slice(2)) export const isDryRun = !!args.dry +if (isDryRun) { + console.log(colors.inverse(colors.yellow(' DRY RUN '))) + console.log() +} + export const packages = [ 'vite', 'create-vite', @@ -145,6 +150,45 @@ export async function publishPackage( }) } +export async function getLatestTag(pkgName: string) { + const tags = (await run('git', ['tag'], { stdio: 'pipe' })).stdout + .split(/\n/) + .filter(Boolean) + const prefix = pkgName === 'vite' ? 'v' : `${pkgName}@` + return tags + .filter((tag) => tag.startsWith(prefix)) + .sort() + .reverse()[0] +} + +export async function logRecentCommits(pkgName: string) { + const tag = await getLatestTag(pkgName) + if (!tag) return + const sha = await run('git', ['rev-list', '-n', '1', tag], { + stdio: 'pipe' + }).then((res) => res.stdout.trim()) + console.log( + colors.bold( + `\n${colors.blue(`i`)} Commits of ${colors.green( + pkgName + )} since ${colors.green(tag)} ${colors.gray(`(${sha.slice(0, 5)})`)}` + ) + ) + await run( + 'git', + [ + '--no-pager', + 'log', + `${sha}..HEAD`, + '--oneline', + '--', + `packages/${pkgName}` + ], + { stdio: 'inherit' } + ) + console.log() +} + export async function updateTemplateVersions(version: string) { if (/beta|alpha|rc/.test(version)) return From 73dcf0932f466e67f526f265915fc1401449e0e3 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 18:36:08 +0800 Subject: [PATCH 7/9] chore: update --- scripts/release.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/release.ts b/scripts/release.ts index 4ef47749bfcae9..6611e947f22465 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -74,10 +74,8 @@ async function main(): Promise { } step('\nUpdating package version...') - if (!isDryRun) { - updateVersion(pkgPath, targetVersion) - if (pkgName === 'create-vite') updateTemplateVersions(targetVersion) - } + updateVersion(pkgPath, targetVersion) + if (pkgName === 'create-vite') updateTemplateVersions(targetVersion) step('\nGenerating changelog...') const changelogArgs = [ @@ -91,7 +89,7 @@ async function main(): Promise { '.' ] if (pkgName !== 'vite') changelogArgs.push('--lerna-package', 'plugin-vue') - await runIfNotDry('npx', changelogArgs, { cwd: pkgPath }) + await run('npx', changelogArgs, { cwd: pkgPath }) const { stdout } = await run('git', ['diff'], { stdio: 'pipe' }) if (stdout) { @@ -101,6 +99,7 @@ async function main(): Promise { await runIfNotDry('git', ['tag', tag]) } else { console.log('No changes to commit.') + return } step('\nPushing to GitHub...') @@ -109,12 +108,14 @@ async function main(): Promise { if (isDryRun) { console.log(`\nDry run finished - run git diff to see package changes.`) + } else { + console.log( + colors.green( + '\nPushed, publishing should starts shortly on CI.\nhttps://github.com/vitejs/vite/actions/workflows/publish.yml' + ) + ) } - step( - '\nTag pushed, publishing should starts shortly on CI.\nhttps://github.com/vitejs/vite/actions/workflows/publish.yml' - ) - console.log() } From 586d37828b51d857866f5025f678a2e34d006286 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 18:39:01 +0800 Subject: [PATCH 8/9] chore: update --- scripts/publishCI.ts | 4 ++-- scripts/release.ts | 4 ++-- scripts/releaseUtils.ts | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/publishCI.ts b/scripts/publishCI.ts index ac93abcc920eb3..7df0893a15b788 100644 --- a/scripts/publishCI.ts +++ b/scripts/publishCI.ts @@ -15,14 +15,14 @@ async function main() { if (version.startsWith('v')) version = version.slice(1) - const { currentVersion, pkgPath } = getPackageInfo(pkgName) + const { currentVersion, pkgDir } = getPackageInfo(pkgName) if (currentVersion !== version) throw new Error( `Package version from tag "${version}" mismatches with current version "${currentVersion}"` ) step('Publishing package...') - await publishPackage(pkgPath, version.includes('beta') ? 'beta' : undefined) + await publishPackage(pkgDir, version.includes('beta') ? 'beta' : undefined) } main().catch((err) => { diff --git a/scripts/release.ts b/scripts/release.ts index 6611e947f22465..6ec929a1d3a340 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -29,7 +29,7 @@ async function main(): Promise { await logRecentCommits(pkg) - const { currentVersion, pkgName, pkgPath } = getPackageInfo(pkg) + const { currentVersion, pkgName, pkgPath, pkgDir } = getPackageInfo(pkg) if (!targetVersion) { const { release }: { release: string } = await prompts({ @@ -89,7 +89,7 @@ async function main(): Promise { '.' ] if (pkgName !== 'vite') changelogArgs.push('--lerna-package', 'plugin-vue') - await run('npx', changelogArgs, { cwd: pkgPath }) + await run('npx', changelogArgs, { cwd: pkgDir }) const { stdout } = await run('git', ['diff'], { stdio: 'pipe' }) if (stdout) { diff --git a/scripts/releaseUtils.ts b/scripts/releaseUtils.ts index b39968a2a859b5..fd35950bcbdaa1 100644 --- a/scripts/releaseUtils.ts +++ b/scripts/releaseUtils.ts @@ -57,8 +57,9 @@ export function getPackageInfo(pkgName: string) { } return { - pkgName, pkg, + pkgName, + pkgDir, pkgPath, currentVersion } @@ -137,7 +138,7 @@ export function updateVersion(pkgPath: string, version: string): void { } export async function publishPackage( - pkgPath: string, + pkdDir: string, tag?: string ): Promise { const publicArgs = ['publish', '--access', 'public'] @@ -146,7 +147,7 @@ export async function publishPackage( } await runIfNotDry('npm', publicArgs, { stdio: 'pipe', - cwd: pkgPath + cwd: pkdDir }) } From 396cdbdfc23602e5f9bb24ed104a1abcc74bbd8a Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 18:59:02 +0800 Subject: [PATCH 9/9] Update scripts/releaseUtils.ts Co-authored-by: patak --- scripts/releaseUtils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/releaseUtils.ts b/scripts/releaseUtils.ts index fd35950bcbdaa1..c2626a083552d0 100644 --- a/scripts/releaseUtils.ts +++ b/scripts/releaseUtils.ts @@ -116,12 +116,16 @@ export function getVersionChoices(currentVersion: string) { { title: 'beta-major', value: inc('premajor') + }, + { + title: 'minor', + value: inc('minor') + }, + { + title: 'major', + value: inc('major') } ]), - ...versionIncrements.map((i) => ({ - value: inc(i), - title: i - })), { value: 'custom', title: 'custom' } ].map((i) => { i.title = `${i.title} (${i.value})`