From 6ea6e08d23a967461cdb5a5fc6d48a6625188c2f Mon Sep 17 00:00:00 2001 From: patak-dev Date: Sat, 12 Feb 2022 08:09:45 +0100 Subject: [PATCH 001/188] release: plugin-vue-jsx@1.3.5 --- packages/plugin-vue-jsx/CHANGELOG.md | 4 ++++ packages/plugin-vue-jsx/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue-jsx/CHANGELOG.md b/packages/plugin-vue-jsx/CHANGELOG.md index 30618d5b056ef9..594f12c90f0909 100644 --- a/packages/plugin-vue-jsx/CHANGELOG.md +++ b/packages/plugin-vue-jsx/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.3.5](https://github.com/vitejs/vite/compare/plugin-vue-jsx@1.3.4...plugin-vue-jsx@1.3.5) (2022-02-12) + + + ## [1.3.4](https://github.com/vitejs/vite/compare/plugin-vue-jsx@1.3.3...plugin-vue-jsx@1.3.4) (2022-02-09) diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 3724cd25c7c381..c26a343c9c4227 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-vue-jsx", - "version": "1.3.4", + "version": "1.3.5", "license": "MIT", "author": "Evan You", "files": [ From fe8ef39eb37df7565dbbfce6a09c2eb7ceeaa56e Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 19:14:31 +0800 Subject: [PATCH 002/188] workflow: separate version bumping and publishing on release (#6879) --- .github/workflows/publish.yml | 37 ++++ .github/workflows/release.yml | 79 -------- package.json | 2 + packages/create-vite/package.json | 4 - packages/create-vite/updateVersions.ts | 23 --- packages/plugin-legacy/package.json | 4 - packages/plugin-react/package.json | 3 +- packages/plugin-vue-jsx/package.json | 4 - packages/plugin-vue/package.json | 3 +- packages/vite/package.json | 3 +- scripts/publishCI.ts | 31 +++ scripts/release.ts | 265 +++++++------------------ scripts/releaseUtils.ts | 215 ++++++++++++++++++++ 13 files changed, 361 insertions(+), 312 deletions(-) create mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 packages/create-vite/updateVersions.ts 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..f4df5af00cc23c --- /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: + NODE_AUTH_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/create-vite/package.json b/packages/create-vite/package.json index 6ff118b7793840..5d873b83fe515b 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -12,10 +12,6 @@ "template-*" ], "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" - }, "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 45c09f607fdfab..e464c18b4dca1d 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -9,10 +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", - "release": "ts-node ../../scripts/release.ts --skipBuild" - }, "engines": { "node": ">=12.0.0" }, diff --git a/packages/plugin-react/package.json b/packages/plugin-react/package.json index 1047a390865f4f..67df1d30b89b0c 100644 --- a/packages/plugin-react/package.json +++ b/packages/plugin-react/package.json @@ -18,8 +18,7 @@ "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", - "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..dff19a227804d1 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -9,10 +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", - "release": "ts-node ../../scripts/release.ts --skipBuild" - }, "engines": { "node": ">=12.0.0" }, diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index f54042da5bf948..ca8836d8e81d36 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -16,8 +16,7 @@ "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", - "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..9bd14ca89a4d16 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -39,8 +39,7 @@ "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 .", - "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..7df0893a15b788 --- /dev/null +++ b/scripts/publishCI.ts @@ -0,0 +1,31 @@ +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')) version = version.slice(1) + + 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(pkgDir, 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..6ec929a1d3a340 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -1,134 +1,54 @@ -/** - * 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, + logRecentCommits, + packages, + run, + runIfNotDry, + step, + updateTemplateVersions, + 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 }) - -type DryRunFn = (bin: string, args: string[], opts?: any) => void +async function main(): Promise { + 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)) + await logRecentCommits(pkg) -async function main(): Promise { - let targetVersion: string | undefined = args._[0] + const { currentVersion, pkgName, pkgPath, pkgDir } = 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 +59,37 @@ 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)`) - } + updateVersion(pkgPath, targetVersion) + if (pkgName === 'create-vite') updateTemplateVersions(targetVersion) step('\nGenerating changelog...') - await run('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 run('npx', changelogArgs, { cwd: pkgDir }) const { stdout } = await run('git', ['diff'], { stdio: 'pipe' }) if (stdout) { @@ -186,59 +99,27 @@ async function main(): Promise { await runIfNotDry('git', ['tag', tag]) } else { console.log('No changes to commit.') + return } - step('\nPublishing package...') - await publishPackage(targetVersion, runIfNotDry) - step('\nPushing to GitHub...') await runIfNotDry('git', ['push', 'origin', `refs/tags/${tag}`]) await runIfNotDry('git', ['push']) 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' + ) + ) } 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') -} - -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 - } - } -} - 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..c2626a083552d0 --- /dev/null +++ b/scripts/releaseUtils.ts @@ -0,0 +1,215 @@ +/** + * 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, readdirSync } 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 + +if (isDryRun) { + console.log(colors.inverse(colors.yellow(' DRY RUN '))) + console.log() +} + +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 { + pkg, + pkgName, + pkgDir, + 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(' ')}`), + opts || '' + ) +} + +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-minor', + value: inc('preminor') + }, + { + title: 'beta-major', + value: inc('premajor') + }, + { + title: 'minor', + value: inc('minor') + }, + { + title: 'major', + value: inc('major') + } + ]), + { 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( + pkdDir: string, + tag?: string +): Promise { + const publicArgs = ['publish', '--access', 'public'] + if (tag) { + publicArgs.push(`--tag`, tag) + } + await runIfNotDry('npm', publicArgs, { + stdio: 'pipe', + cwd: pkdDir + }) +} + +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 + + 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 8e923fae96de811ca9c621049c061d0fffcc52d1 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 19:25:35 +0800 Subject: [PATCH 003/188] chore(ci): remove dry flag --- .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 f4df5af00cc23c..ffdd5ea6399ad5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -32,6 +32,6 @@ jobs: run: pnpm install - name: Publish package - run: pnpm run ci-publish -- ${{ github.ref_name }} --dry + run: pnpm run ci-publish -- ${{ github.ref_name }} env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From 254cc456c190086b2cba9c9e149720828ca3f00d Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 19:31:21 +0800 Subject: [PATCH 004/188] chore: fix create-vite bumping script (#6881) --- scripts/release.ts | 2 +- scripts/releaseUtils.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/release.ts b/scripts/release.ts index 6ec929a1d3a340..d536eca1f70586 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -75,7 +75,7 @@ async function main(): Promise { step('\nUpdating package version...') updateVersion(pkgPath, targetVersion) - if (pkgName === 'create-vite') updateTemplateVersions(targetVersion) + if (pkgName === 'create-vite') updateTemplateVersions() step('\nGenerating changelog...') const changelogArgs = [ diff --git a/scripts/releaseUtils.ts b/scripts/releaseUtils.ts index c2626a083552d0..b444835db7b6d0 100644 --- a/scripts/releaseUtils.ts +++ b/scripts/releaseUtils.ts @@ -194,8 +194,9 @@ export async function logRecentCommits(pkgName: string) { console.log() } -export async function updateTemplateVersions(version: string) { - if (/beta|alpha|rc/.test(version)) return +export async function updateTemplateVersions() { + const viteVersion = require('../packages/vite/package.json').version + if (/beta|alpha|rc/.test(viteVersion)) return const dir = path.resolve(__dirname, '../packages/create-vite') @@ -205,7 +206,7 @@ export async function updateTemplateVersions(version: string) { for (const template of templates) { const pkgPath = path.join(dir, template, `package.json`) const pkg = require(pkgPath) - pkg.devDependencies.vite = `^` + version + pkg.devDependencies.vite = `^` + viteVersion if (template.startsWith('template-vue')) { pkg.devDependencies['@vitejs/plugin-vue'] = `^` + require('../packages/plugin-vue/package.json').version From fcb53a365832449b9c23783781141498a4d0da58 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 19:31:50 +0800 Subject: [PATCH 005/188] release: plugin-vue-jsx@1.3.6 --- packages/plugin-vue-jsx/CHANGELOG.md | 9 +++++++++ packages/plugin-vue-jsx/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue-jsx/CHANGELOG.md b/packages/plugin-vue-jsx/CHANGELOG.md index 594f12c90f0909..8473e8f8af24f3 100644 --- a/packages/plugin-vue-jsx/CHANGELOG.md +++ b/packages/plugin-vue-jsx/CHANGELOG.md @@ -1,3 +1,12 @@ +## [1.3.6](https://github.com/vitejs/vite/compare/plugin-vue@2.2.0...plugin-vue@1.3.6) (2022-02-12) + + +### Bug Fixes + +* **deps:** update all non-major dependencies ([#6782](https://github.com/vitejs/vite/issues/6782)) ([e38be3e](https://github.com/vitejs/vite/commit/e38be3e6ca7bf79319d5d7188e1d347b1d6091ef)) + + + ## [1.3.5](https://github.com/vitejs/vite/compare/plugin-vue-jsx@1.3.4...plugin-vue-jsx@1.3.5) (2022-02-12) diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index dff19a227804d1..027f6d99180163 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-vue-jsx", - "version": "1.3.5", + "version": "1.3.6", "license": "MIT", "author": "Evan You", "files": [ From 5e26d5f663a9c8888405ea495a64271b51a9046d Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Feb 2022 19:47:58 +0800 Subject: [PATCH 006/188] chore: fix releasing token (#6882) --- .github/workflows/publish.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ffdd5ea6399ad5..eb8f4513707872 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -26,11 +26,20 @@ jobs: uses: actions/setup-node@v2 with: node-version: 16.x + registry-url: https://registry.npmjs.org/ cache: "pnpm" - name: Install deps run: pnpm install + - name: Creating .npmrc + run: | + cat << EOF > "$HOME/.npmrc" + //registry.npmjs.org/:_authToken=$NPM_TOKEN + EOF + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Publish package run: pnpm run ci-publish -- ${{ github.ref_name }} env: From 78e84c80c0f49d6f7c8a0e10c4257a477a221280 Mon Sep 17 00:00:00 2001 From: Michael Oliver Date: Sat, 12 Feb 2022 20:50:18 +0000 Subject: [PATCH 007/188] feat: make `import.meta.glob` and `import.meta.globEager` generic (#5073) --- packages/vite/types/importMeta.d.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/vite/types/importMeta.d.ts b/packages/vite/types/importMeta.d.ts index 625e075333e48d..732310490350eb 100644 --- a/packages/vite/types/importMeta.d.ts +++ b/packages/vite/types/importMeta.d.ts @@ -59,25 +59,15 @@ interface ImportMeta { readonly env: ImportMetaEnv - glob( + glob( pattern: string, options?: AssertOptions - ): Record< - string, - () => Promise<{ - [key: string]: any - }> - > + ): Record Promise> - globEager( + globEager( pattern: string, options?: AssertOptions - ): Record< - string, - { - [key: string]: any - } - > + ): Record } interface ImportMetaEnv { From 62cbe68ab713d5aba626a1e3a4da46e8c2320bf3 Mon Sep 17 00:00:00 2001 From: Ivan Demchuk Date: Sun, 13 Feb 2022 11:58:49 +0200 Subject: [PATCH 008/188] perf: improve isFileReadable performance (#6868) --- packages/vite/src/node/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index d723b25a54122d..2b2ba6fb859107 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -422,8 +422,8 @@ export function writeFile( */ export function isFileReadable(filename: string): boolean { try { - fs.accessSync(filename, fs.constants.R_OK) - return true + const stat = fs.statSync(filename, { throwIfNoEntry: false }) + return !!stat } catch { return false } From 2eabcb9a30a413ff540cbdd60a919a0d1f72fb35 Mon Sep 17 00:00:00 2001 From: Jeff Yang <32727188+ydcjeff@users.noreply.github.com> Date: Sun, 13 Feb 2022 22:24:33 +0630 Subject: [PATCH 009/188] perf: lazy import preview function (#6898) --- packages/vite/src/node/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts index 1b3af6b90e6f65..2a4f3a77918144 100644 --- a/packages/vite/src/node/cli.ts +++ b/packages/vite/src/node/cli.ts @@ -6,7 +6,6 @@ import type { ServerOptions } from './server' import type { LogLevel } from './logger' import { createLogger } from './logger' import { resolveConfig } from '.' -import { preview } from './preview' const cli = cac('vite') @@ -230,6 +229,7 @@ cli strictPort?: boolean } & GlobalCLIOptions ) => { + const { preview } = await import('./preview') try { const server = await preview({ root, From e385346c53b3bb54f2e1abcb7348e33d7e075fd4 Mon Sep 17 00:00:00 2001 From: ygj6 <7699524+ygj6@users.noreply.github.com> Date: Mon, 14 Feb 2022 11:49:36 +0800 Subject: [PATCH 010/188] feat: custom manifest file name (#6667) --- docs/config/index.md | 8 ++++---- packages/vite/src/node/build.ts | 4 ++-- packages/vite/src/node/cli.ts | 4 ++-- packages/vite/src/node/plugins/manifest.ts | 5 ++++- packages/vite/src/node/ssr/ssrManifestPlugin.ts | 5 ++++- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 233e08b8f864e3..ba84c49b2f5820 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -772,19 +772,19 @@ export default defineConfig({ ### build.manifest -- **Type:** `boolean` +- **Type:** `boolean | string` - **Default:** `false` - **Related:** [Backend Integration](/guide/backend-integration) - When set to `true`, the build will also generate a `manifest.json` file that contains a mapping of non-hashed asset filenames to their hashed versions, which can then be used by a server framework to render the correct asset links. + When set to `true`, the build will also generate a `manifest.json` file that contains a mapping of non-hashed asset filenames to their hashed versions, which can then be used by a server framework to render the correct asset links. When the value is a string, it will be used as the manifest file name. ### build.ssrManifest -- **Type:** `boolean` +- **Type:** `boolean | string` - **Default:** `false` - **Related:** [Server-Side Rendering](/guide/ssr) - When set to `true`, the build will also generate a SSR manifest for determining style links and asset preload directives in production. + When set to `true`, the build will also generate a SSR manifest for determining style links and asset preload directives in production. When the value is a string, it will be used as the manifest file name. ### build.ssr diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index b9936f8583b46c..c8a1a0f17fa4a4 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -179,7 +179,7 @@ export interface BuildOptions { * ``` * @default false */ - manifest?: boolean + manifest?: boolean | string /** * Build in library mode. The value should be the global name of the lib in * UMD mode. This will produce esm + cjs + umd bundle formats with default @@ -195,7 +195,7 @@ export interface BuildOptions { * Generate SSR manifest for determining style links and asset preload * directives in production. */ - ssrManifest?: boolean + ssrManifest?: boolean | string /** * Set to false to disable reporting compressed chunk sizes. * Can slightly improve build speed. diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts index 2a4f3a77918144..91b3d4e6bee998 100644 --- a/packages/vite/src/node/cli.ts +++ b/packages/vite/src/node/cli.ts @@ -149,8 +149,8 @@ cli `[boolean | "terser" | "esbuild"] enable/disable minification, ` + `or specify minifier to use (default: esbuild)` ) - .option('--manifest', `[boolean] emit build manifest json`) - .option('--ssrManifest', `[boolean] emit ssr manifest json`) + .option('--manifest [name]', `[boolean | string] emit build manifest json`) + .option('--ssrManifest [name]', `[boolean | string] emit ssr manifest json`) .option( '--emptyOutDir', `[boolean] force empty outDir when it's outside of root` diff --git a/packages/vite/src/node/plugins/manifest.ts b/packages/vite/src/node/plugins/manifest.ts index 2ce4869e67d98d..d6dceb507ca946 100644 --- a/packages/vite/src/node/plugins/manifest.ts +++ b/packages/vite/src/node/plugins/manifest.ts @@ -113,7 +113,10 @@ export function manifestPlugin(config: ResolvedConfig): Plugin { const outputLength = Array.isArray(output) ? output.length : 1 if (outputCount >= outputLength) { this.emitFile({ - fileName: `manifest.json`, + fileName: + typeof config.build.manifest === 'string' + ? config.build.manifest + : 'manifest.json', type: 'asset', source: JSON.stringify(manifest, null, 2) }) diff --git a/packages/vite/src/node/ssr/ssrManifestPlugin.ts b/packages/vite/src/node/ssr/ssrManifestPlugin.ts index e6811eae29b210..a92550e39d4ed0 100644 --- a/packages/vite/src/node/ssr/ssrManifestPlugin.ts +++ b/packages/vite/src/node/ssr/ssrManifestPlugin.ts @@ -96,7 +96,10 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin { } this.emitFile({ - fileName: 'ssr-manifest.json', + fileName: + typeof config.build.ssrManifest === 'string' + ? config.build.ssrManifest + : 'ssr-manifest.json', type: 'asset', source: JSON.stringify(ssrManifest, null, 2) }) From 55eca7cf2750690d66eff8007bc1d6b5f0edb292 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 14 Feb 2022 11:13:56 +0100 Subject: [PATCH 011/188] release: plugin-vue-jsx@1.3.7 --- packages/plugin-vue-jsx/CHANGELOG.md | 9 +++++++++ packages/plugin-vue-jsx/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue-jsx/CHANGELOG.md b/packages/plugin-vue-jsx/CHANGELOG.md index 8473e8f8af24f3..0ad338dbd211eb 100644 --- a/packages/plugin-vue-jsx/CHANGELOG.md +++ b/packages/plugin-vue-jsx/CHANGELOG.md @@ -1,3 +1,12 @@ +## [1.3.7](https://github.com/vitejs/vite/compare/plugin-vue@2.2.0...plugin-vue@1.3.7) (2022-02-14) + + +### Bug Fixes + +* **deps:** update all non-major dependencies ([#6782](https://github.com/vitejs/vite/issues/6782)) ([e38be3e](https://github.com/vitejs/vite/commit/e38be3e6ca7bf79319d5d7188e1d347b1d6091ef)) + + + ## [1.3.6](https://github.com/vitejs/vite/compare/plugin-vue@2.2.0...plugin-vue@1.3.6) (2022-02-12) diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 027f6d99180163..f8289b79f4c445 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-vue-jsx", - "version": "1.3.6", + "version": "1.3.7", "license": "MIT", "author": "Evan You", "files": [ From e8c840abd2767445a5e49bab6540a66b941d7239 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 14 Feb 2022 11:21:37 +0100 Subject: [PATCH 012/188] release: v2.8.2 --- packages/vite/CHANGELOG.md | 16 ++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 50925e58baffdb..13226de36642eb 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,19 @@ +## [2.8.2](https://github.com/vitejs/vite/compare/v2.8.1...v2.8.2) (2022-02-14) + + +### Features + +* custom manifest file name ([#6667](https://github.com/vitejs/vite/issues/6667)) ([e385346](https://github.com/vitejs/vite/commit/e385346c53b3bb54f2e1abcb7348e33d7e075fd4)) +* make `import.meta.glob` and `import.meta.globEager` generic ([#5073](https://github.com/vitejs/vite/issues/5073)) ([78e84c8](https://github.com/vitejs/vite/commit/78e84c80c0f49d6f7c8a0e10c4257a477a221280)) + + +### Performance Improvements + +* improve isFileReadable performance ([#6868](https://github.com/vitejs/vite/issues/6868)) ([62cbe68](https://github.com/vitejs/vite/commit/62cbe68ab713d5aba626a1e3a4da46e8c2320bf3)) +* lazy import preview function ([#6898](https://github.com/vitejs/vite/issues/6898)) ([2eabcb9](https://github.com/vitejs/vite/commit/2eabcb9a30a413ff540cbdd60a919a0d1f72fb35)) + + + ## [2.8.1](https://github.com/vitejs/vite/compare/v2.8.0...v2.8.1) (2022-02-11) diff --git a/packages/vite/package.json b/packages/vite/package.json index 9bd14ca89a4d16..94029dc45cc008 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.8.1", + "version": "2.8.2", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 0e58e72ab3b36156fb32bf983fe56c7621a11106 Mon Sep 17 00:00:00 2001 From: Zheeeng Date: Tue, 15 Feb 2022 15:21:55 +0800 Subject: [PATCH 013/188] chore: prefer using nullish-coalescing over or logic operator (#6790) --- packages/playground/testUtils.ts | 4 ++-- packages/vite/src/node/ssr/ssrManifestPlugin.ts | 2 +- packages/vite/src/node/ssr/ssrStacktrace.ts | 2 +- packages/vite/src/node/utils.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/playground/testUtils.ts b/packages/playground/testUtils.ts index 3c6cba769b3ffe..0ae0c6e8766e95 100644 --- a/packages/playground/testUtils.ts +++ b/packages/playground/testUtils.ts @@ -56,7 +56,7 @@ async function toEl(el: string | ElementHandle): Promise { export async function getColor(el: string | ElementHandle): Promise { el = await toEl(el) const rgb = await el.evaluate((el) => getComputedStyle(el as Element).color) - return hexToNameMap[rgbToHex(rgb)] || rgb + return hexToNameMap[rgbToHex(rgb)] ?? rgb } export async function getBg(el: string | ElementHandle): Promise { @@ -119,7 +119,7 @@ export async function untilUpdated( if (isBuild && !runInBuild) return const maxTries = process.env.CI ? 100 : 50 for (let tries = 0; tries < maxTries; tries++) { - const actual = (await poll()) || '' + const actual = (await poll()) ?? '' if (actual.indexOf(expected) > -1 || tries === maxTries - 1) { expect(actual).toMatch(expected) break diff --git a/packages/vite/src/node/ssr/ssrManifestPlugin.ts b/packages/vite/src/node/ssr/ssrManifestPlugin.ts index a92550e39d4ed0..351c91349a3ca3 100644 --- a/packages/vite/src/node/ssr/ssrManifestPlugin.ts +++ b/packages/vite/src/node/ssr/ssrManifestPlugin.ts @@ -29,7 +29,7 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin { for (const id in chunk.modules) { const normalizedId = normalizePath(relative(config.root, id)) const mappedChunks = - ssrManifest[normalizedId] || (ssrManifest[normalizedId] = []) + ssrManifest[normalizedId] ?? (ssrManifest[normalizedId] = []) if (!chunk.isEntry) { mappedChunks.push(base + chunk.fileName) } diff --git a/packages/vite/src/node/ssr/ssrStacktrace.ts b/packages/vite/src/node/ssr/ssrStacktrace.ts index 75fcd8d2933c6f..0d847cb7da7041 100644 --- a/packages/vite/src/node/ssr/ssrStacktrace.ts +++ b/packages/vite/src/node/ssr/ssrStacktrace.ts @@ -46,7 +46,7 @@ export function ssrRewriteStacktrace( return input } - const source = `${pos.source}:${pos.line || 0}:${pos.column || 0}` + const source = `${pos.source}:${pos.line ?? 0}:${pos.column ?? 0}` if (!varName || varName === 'eval') { return ` at ${source}` } else { diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 2b2ba6fb859107..3012e6d57e6c65 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -222,7 +222,7 @@ export function injectQuery(url: string, queryToInject: string): string { } pathname = decodeURIComponent(pathname) return `${pathname}?${queryToInject}${search ? `&` + search.slice(1) : ''}${ - hash || '' + hash ?? '' }` } @@ -518,7 +518,7 @@ export async function processSrcSet( ) return ret.reduce((prev, { url, descriptor }, index) => { - descriptor = descriptor || '' + descriptor ??= '' return (prev += url + ` ${descriptor}${index === ret.length - 1 ? '' : ', '}`) }, '') From 3480f27d4db7f7ebd27164d9185e7b387762274e Mon Sep 17 00:00:00 2001 From: Zheeeng Date: Tue, 15 Feb 2022 15:22:33 +0800 Subject: [PATCH 014/188] chore(types): correct typing in jestPerTestSetup (#6786) --- scripts/jestPerTestSetup.ts | 24 +++++++++++++----------- scripts/tsconfig.json | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/scripts/jestPerTestSetup.ts b/scripts/jestPerTestSetup.ts index 89209c3ffcbf69..9c15edf9f059bf 100644 --- a/scripts/jestPerTestSetup.ts +++ b/scripts/jestPerTestSetup.ts @@ -10,8 +10,7 @@ import type { Logger } from 'vite' import { createServer, build } from 'vite' -import type { Page } from 'playwright-chromium' -// eslint-disable-next-line node/no-extraneous-import +import type { Page, ConsoleMessage } from 'playwright-chromium' import type { RollupError, RollupWatcher, RollupWatcherEvent } from 'rollup' const isBuildTest = !!process.env.VITE_TEST_BUILD @@ -45,13 +44,15 @@ let server: ViteDevServer | http.Server let tempDir: string let rootDir: string -const setBeforeAllError = (err) => ((global as any).beforeAllError = err) -const getBeforeAllError = () => (global as any).beforeAllError +const setBeforeAllError = (err: Error | null) => { + global.beforeAllError = err +} +const getBeforeAllError = () => global.beforeAllError //init with null so old errors don't carry over setBeforeAllError(null) -const logs = ((global as any).browserLogs = []) -const onConsole = (msg) => { +const logs: string[] = (global.browserLogs = []) +const onConsole = (msg: ConsoleMessage) => { logs.push(msg.text()) } @@ -145,7 +146,7 @@ beforeAll(async () => { await page.goto(url) } } - } catch (e) { + } catch (e: any) { // jest doesn't exit if our setup has error here // https://github.com/facebook/jest/issues/2713 setBeforeAllError(e) @@ -172,11 +173,12 @@ afterAll(async () => { function startStaticServer(): Promise { // check if the test project has base config const configFile = resolve(rootDir, 'vite.config.js') - let config: UserConfig + let config: UserConfig | undefined try { config = require(configFile) } catch (e) {} - const base = (config?.base || '/') === '/' ? '' : config.base + // fallback internal base to '' + const base = (config?.base ?? '/') === '/' ? '' : config?.base ?? '' // @ts-ignore if (config && config.__test__) { @@ -219,10 +221,10 @@ export async function notifyRebuildComplete( watcher: RollupWatcher ): Promise { let callback: (event: RollupWatcherEvent) => void - await new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { callback = (event) => { if (event.code === 'END') { - resolve(true) + resolve() } } watcher.on('event', callback) diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 6a32b899cb43ab..5c70fcc7f15823 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -8,6 +8,6 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, - "types": ["node"] + "types": ["node", "jest"] } } From a9a1ae2db6a81a2fd31db370b58686e442047d9e Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 15 Feb 2022 17:17:28 +0100 Subject: [PATCH 015/188] fix: revert update dotenv-expand #6703, fix #6858 (#6934) --- packages/vite/package.json | 2 +- packages/vite/src/node/config.ts | 2 +- pnpm-lock.yaml | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/vite/package.json b/packages/vite/package.json index 94029dc45cc008..728f6e00b84c7f 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -87,7 +87,7 @@ "cross-spawn": "^7.0.3", "debug": "^4.3.3", "dotenv": "^14.3.2", - "dotenv-expand": "^6.0.1", + "dotenv-expand": "^5.1.0", "es-module-lexer": "^0.9.3", "estree-walker": "^2.0.2", "etag": "^1.8.1", diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index f73f4fb8662d6b..2a607dd6ba9948 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -21,7 +21,7 @@ import { resolvePlugins } from './plugins' import colors from 'picocolors' import type { ESBuildOptions } from './plugins/esbuild' import dotenv from 'dotenv' -import { expand as dotenvExpand } from 'dotenv-expand' +import dotenvExpand from 'dotenv-expand' import type { Alias, AliasOptions } from 'types/alias' import { CLIENT_ENTRY, ENV_ENTRY, DEFAULT_ASSETS_RE } from './constants' import type { InternalResolveOptions, ResolveOptions } from './plugins/resolve' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab4083cb6a7635..418cf16f0eb6b1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -770,7 +770,7 @@ importers: cross-spawn: ^7.0.3 debug: ^4.3.3 dotenv: ^14.3.2 - dotenv-expand: ^6.0.1 + dotenv-expand: ^5.1.0 es-module-lexer: ^0.9.3 esbuild: ^0.14.14 estree-walker: ^2.0.2 @@ -848,7 +848,7 @@ importers: cross-spawn: 7.0.3 debug: 4.3.3 dotenv: 14.3.2 - dotenv-expand: 6.0.1 + dotenv-expand: 5.1.0 es-module-lexer: 0.9.3 estree-walker: 2.0.2 etag: 1.8.1 @@ -4212,9 +4212,8 @@ packages: is-obj: 2.0.0 dev: true - /dotenv-expand/6.0.1: - resolution: {integrity: sha512-GNHcCOyRKLCXWnH3L/+sJ04PQxxgTOZDCPuQQnqkqPMGIilyoxHZ2JUNmh2VWKCfzVKH/AZsqcbuSYlDDVb/xw==} - engines: {node: '>=12'} + /dotenv-expand/5.1.0: + resolution: {integrity: sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==} dev: true /dotenv/14.3.2: From ac9652b0fc9aa947da4a62ff9553e23aee1dee8f Mon Sep 17 00:00:00 2001 From: patak-dev Date: Tue, 15 Feb 2022 18:07:13 +0100 Subject: [PATCH 016/188] release: v2.8.3 --- packages/vite/CHANGELOG.md | 9 +++++++++ packages/vite/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 13226de36642eb..fb262e6e13e783 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,12 @@ +## [2.8.3](https://github.com/vitejs/vite/compare/v2.8.2...v2.8.3) (2022-02-15) + + +### Bug Fixes + +* revert update dotenv-expand [#6703](https://github.com/vitejs/vite/issues/6703), fix [#6858](https://github.com/vitejs/vite/issues/6858) ([#6934](https://github.com/vitejs/vite/issues/6934)) ([a9a1ae2](https://github.com/vitejs/vite/commit/a9a1ae2db6a81a2fd31db370b58686e442047d9e)) + + + ## [2.8.2](https://github.com/vitejs/vite/compare/v2.8.1...v2.8.2) (2022-02-14) diff --git a/packages/vite/package.json b/packages/vite/package.json index 728f6e00b84c7f..0eff7b535822df 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.8.2", + "version": "2.8.3", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 3f27d58036bfe4149e563a105c08c2d4771db288 Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 15 Feb 2022 22:33:41 +0100 Subject: [PATCH 017/188] chore(deps): avoid updating dotenv-expand to v6+ (#6936) --- .github/renovate.json5 | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 763dfcfc467d9d..06fe0e7ea2aaff 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -28,6 +28,7 @@ "react-router", // `react-router:v6.0.0+` has breaking changes "react-router-dom", // `react-router-dom:v6.0.0+` has breaking changes "source-map", // `source-map:v0.7.0+` needs more investigation + "dotenv-expand", // `dotenv-expand:6.0.0+` has breaking changes (#6858) // ESM Only => https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-move-my-commonjs-project-to-esm "node-fetch", From e2349569cf96e506e0d5fff1d043727a77fdad70 Mon Sep 17 00:00:00 2001 From: ocavue Date: Wed, 16 Feb 2022 21:20:45 +0800 Subject: [PATCH 018/188] docs: add backticks (#6945) --- docs/config/index.md | 2 +- packages/vite/src/node/config.ts | 2 +- packages/vite/src/node/optimizer/index.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index ba84c49b2f5820..d4ee7a96a6fa67 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -923,7 +923,7 @@ export default defineConfig({ - **Type:** `string | string[]` - By default, Vite will crawl your index.html to detect dependencies that need to be pre-bundled. If build.rollupOptions.input is specified, Vite will crawl those entry points instead. + By default, Vite will crawl your `index.html` to detect dependencies that need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite will crawl those entry points instead. If neither of these fit your needs, you can specify custom entries using this option - the value should be a [fast-glob pattern](https://github.com/mrmlnc/fast-glob#basic-syntax) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 2a607dd6ba9948..fbda8d5166cb1b 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -92,7 +92,7 @@ export interface UserConfig { * the performance. You can use `--force` flag or manually delete the directory * to regenerate the cache files. The value can be either an absolute file * system path or a path relative to . - * Default to `.vite` when no package.json is detected. + * Default to `.vite` when no `package.json` is detected. * @default 'node_modules/.vite' */ cacheDir?: string diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 6102e832841a89..c13a26c63b3c1c 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -30,8 +30,8 @@ export type ExportsData = ReturnType & { export interface DepOptimizationOptions { /** - * By default, Vite will crawl your index.html to detect dependencies that - * need to be pre-bundled. If build.rollupOptions.input is specified, Vite + * By default, Vite will crawl your `index.html` to detect dependencies that + * need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite * will crawl those entry points instead. * * If neither of these fit your needs, you can specify custom entries using From 4120908c518c8a89354aa93ffd6ebf5436123134 Mon Sep 17 00:00:00 2001 From: yoho <907415276@qq.com> Date: Thu, 17 Feb 2022 21:14:06 +0800 Subject: [PATCH 019/188] docs: import.meta.glob support ?raw (#6953) Co-authored-by: ygj6 <7699524+ygj6@users.noreply.github.com> --- docs/guide/features.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/guide/features.md b/docs/guide/features.md index da8e3b1de092b2..c7fd2424b53cb1 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -298,6 +298,22 @@ const modules = { } ``` +`import.meta.glob` and `import.meta.globEager` also support importing files as strings, similar to [Importing Asset as String](https://vitejs.dev/guide/assets.html#importing-asset-as-string). Here, we use the [Import Assertions](https://github.com/tc39/proposal-import-assertions#synopsis) syntax to import. + +```js +const modules = import.meta.glob('./dir/*.js', { assert: { type: 'raw' } }) +``` + +The above will be transformed into the following: + +```js +// code produced by vite +const modules = { + './dir/foo.js': '{\n "msg": "foo"\n}\n', + './dir/bar.js': '{\n "msg": "bar"\n}\n' +} +``` + Note that: - This is a Vite-only feature and is not a web or ES standard. From 08cf4e106534481fd8eff2e6e4a986270c28f894 Mon Sep 17 00:00:00 2001 From: Sepush Date: Thu, 17 Feb 2022 21:15:51 +0800 Subject: [PATCH 020/188] chore(ci): update issue-helper version (#6955) --- .github/workflows/issue-close-require.yml | 2 +- .github/workflows/issue-labeled.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/issue-close-require.yml b/.github/workflows/issue-close-require.yml index 02ac374b06c426..97f9dd3a449c3c 100644 --- a/.github/workflows/issue-close-require.yml +++ b/.github/workflows/issue-close-require.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: need reproduction - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "close-issues" token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/issue-labeled.yml b/.github/workflows/issue-labeled.yml index a63021952fd73d..b6f3919dfa63a2 100644 --- a/.github/workflows/issue-labeled.yml +++ b/.github/workflows/issue-labeled.yml @@ -10,7 +10,7 @@ jobs: steps: - name: contribution welcome if: github.event.label.name == 'contribution welcome' || github.event.label.name == 'help wanted' - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "create-comment, remove-labels" token: ${{ secrets.GITHUB_TOKEN }} @@ -21,7 +21,7 @@ jobs: - name: remove pending if: github.event.label.name == 'enhancement' || github.event.label.name == 'bug' || (contains(github.event.label.name, 'pending triage') == false && startsWith(github.event.label.name, 'bug:') == true) - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "remove-labels" token: ${{ secrets.GITHUB_TOKEN }} @@ -30,7 +30,7 @@ jobs: - name: need reproduction if: github.event.label.name == 'need reproduction' - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "create-comment, remove-labels" token: ${{ secrets.GITHUB_TOKEN }} From 3f3f4737d5242547fb83f8d2522ba91cc1d96fb0 Mon Sep 17 00:00:00 2001 From: Nurettin Kaya Date: Thu, 17 Feb 2022 13:24:44 -0800 Subject: [PATCH 021/188] fix: normalize postcss dependency messages (#6959) --- .../tailwind/__test__/tailwind.spec.ts | 22 ++++++++++++++++++- packages/playground/tailwind/src/App.vue | 2 +- .../playground/tailwind/tailwind.config.js | 7 +++++- packages/vite/src/node/plugins/css.ts | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/playground/tailwind/__test__/tailwind.spec.ts b/packages/playground/tailwind/__test__/tailwind.spec.ts index 105eb245bf207e..47f6b7ccf49037 100644 --- a/packages/playground/tailwind/__test__/tailwind.spec.ts +++ b/packages/playground/tailwind/__test__/tailwind.spec.ts @@ -5,7 +5,7 @@ test('should render', async () => { }) if (!isBuild) { - test('regenerate CSS and HMR', async () => { + test('regenerate CSS and HMR (glob pattern)', async () => { browserLogs.length = 0 const el = await page.$('#pagetitle') const el2 = await page.$('#helloroot') @@ -37,4 +37,24 @@ if (!isBuild) { browserLogs.length = 0 }) + + test('regenerate CSS and HMR (relative path)', async () => { + browserLogs.length = 0 + const el = await page.$('h1') + + expect(await getColor(el)).toBe('black') + + editFile('src/App.vue', (code) => + code.replace('text-black', 'text-[rgb(11,22,33)]') + ) + + await untilUpdated(() => getColor(el), 'rgb(11, 22, 33)') + + expect(browserLogs).toMatchObject([ + '[vite] css hot updated: /index.css', + '[vite] hot updated: /src/App.vue' + ]) + + browserLogs.length = 0 + }) } diff --git a/packages/playground/tailwind/src/App.vue b/packages/playground/tailwind/src/App.vue index b032d5e0db77e3..25835fc414a06f 100644 --- a/packages/playground/tailwind/src/App.vue +++ b/packages/playground/tailwind/src/App.vue @@ -1,6 +1,6 @@