Skip to content

Commit

Permalink
workflow: switch to pnpm (#5060)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 24, 2021
1 parent 77bd76f commit ad6047d
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 63 deletions.
59 changes: 24 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,34 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2.0.1
with:
version: 6.15.1

- name: Set node version to ${{ matrix.node_version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node_version }}
cache: "pnpm"

- name: Get yarn cache directory
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Set dependencies cache
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('yarn.lock') }}
${{ runner.os }}-${{ matrix.node_version }}-
- name: Versions
run: yarn versions

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Install deps
run: pnpm install

- name: Build vite
run: yarn ci-build-vite
run: pnpm run ci-build-vite

- name: Build plugin-vue
run: yarn build-plugin-vue
run: pnpm run build-plugin-vue

- name: Build plugin-react
run: yarn build-plugin-react
run: pnpm run build-plugin-react

- name: Test serve
run: yarn test-serve --runInBand
run: pnpm run test-serve -- --runInBand

- name: Test build
run: yarn test-build --runInBand
run: pnpm run test-build -- --runInBand

lint:
runs-on: ubuntu-latest
Expand All @@ -80,25 +70,24 @@ jobs:
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v2.0.1
with:
version: 6.15.1

- name: Set node version to 14
uses: actions/setup-node@v2
with:
node-version: 14
cache: "pnpm"

- name: Set dependencies cache
uses: actions/cache@v2
with:
path: ~/.cache/yarn
key: lint-dependencies-${{ hashFiles('yarn.lock') }}
restore-keys: |
lint-dependencies-${{ hashFiles('yarn.lock') }}
lint-dependencies-
- name: Install deps
run: pnpm install

- name: Prepare
run: |
yarn install --frozen-lockfile
yarn ci-build-vite
yarn build-plugin-vue
pnpm run ci-build-vite
pnpm run build-plugin-vue
- name: Lint
run: yarn lint
run: pnpm run lint
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ packages/plugin-vue/dist/
packages/*/CHANGELOG.md
LICENSE.md
.prettierignore
yarn.lock
pnpm-lock.yaml
pnpm-workspace.yaml
packages/playground/tsconfig-json-load-error/has-error/tsconfig.json
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"node": ">=12.0.0"
},
"scripts": {
"preinstall": "node scripts/preinstall",
"format": "prettier --write .",
"lint": "eslint packages/*/{src,types}/**",
"test": "run-s test-serve test-build",
Expand All @@ -20,10 +21,10 @@
"build-docs": "vitepress build docs",
"serve-docs": "vitepress serve docs",
"build": "run-s build-vite build-plugin-vue build-plugin-react",
"build-vite": "cd packages/vite && yarn build",
"build-plugin-vue": "cd packages/plugin-vue && yarn build",
"build-plugin-react": "cd packages/plugin-react && yarn build",
"ci-build-vite": "cd packages/vite && yarn ci-build",
"build-vite": "cd packages/vite && npm run build",
"build-plugin-vue": "cd packages/plugin-vue && npm run build",
"build-plugin-react": "cd packages/plugin-react && npm run build",
"ci-build-vite": "cd packages/vite && npm run ci-build",
"ci-docs": "run-s build-vite build-plugin-vue build-docs"
},
"devDependencies": {
Expand Down Expand Up @@ -57,7 +58,10 @@
"ts-node": "^10.1.0",
"typescript": "~4.3.5",
"vitepress": "^0.19.1",
"yorkie": "^2.0.0"
"yorkie": "^2.0.0",
"rollup": "^2.57.0",
"esbuild": "^0.13.2",
"vite": "workspace:*"
},
"gitHooks": {
"pre-commit": "lint-staged --concurrent false",
Expand All @@ -73,5 +77,11 @@
"packages/**/*.d.ts": [
"eslint --ext .ts"
]
},
"pnpm": {
"overrides": {
"vite": "workspace:*",
"@vitejs/plugin-vue": "workspace:*"
}
}
}
4 changes: 2 additions & 2 deletions packages/plugin-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"rollup": "^2.57.0",
"slash": "^3.0.0",
"source-map": "^0.6.1",
"vue": "^3.2.14",
"@vue/compiler-sfc": "^3.2.14"
"vue": "^3.2.16",
"@vue/compiler-sfc": "^3.2.16"
}
}
3 changes: 3 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
- 'packages/*'
- 'packages/playground/**'
12 changes: 11 additions & 1 deletion scripts/jestGlobalSetup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
const os = require('os')
const fs = require('fs-extra')
const path = require('path')
Expand All @@ -17,5 +18,14 @@ module.exports = async () => {

await fs.mkdirp(DIR)
await fs.writeFile(path.join(DIR, 'wsEndpoint'), browserServer.wsEndpoint())
await fs.remove(path.resolve(__dirname, '../temp'))

const tempDir = path.resolve(__dirname, '../packages/temp')
await fs.remove(tempDir)
await fs.copy(path.resolve(__dirname, '../packages/playground'), tempDir, {
dereference: false,
filter(file) {
file = file.replace(/\\/g, '/')
return !file.includes('__tests__') && !file.match(/dist(\/|$)/)
}
})
}
2 changes: 1 addition & 1 deletion scripts/jestGlobalTeardown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ const path = require('path')
module.exports = async () => {
await global.__BROWSER_SERVER__.close()
if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) {
await fs.remove(path.resolve(__dirname, '../temp'))
await fs.remove(path.resolve(__dirname, '../packages/temp'))
}
}
25 changes: 9 additions & 16 deletions scripts/jestPerTestSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,7 @@ beforeAll(async () => {
// start a vite server in that directory.
if (testName) {
const playgroundRoot = resolve(__dirname, '../packages/playground')
const srcDir = resolve(playgroundRoot, testName)
tempDir = resolve(__dirname, '../temp', testName)
await fs.copy(srcDir, tempDir, {
dereference: true,
filter(file) {
file = slash(file)
return (
!file.includes('__tests__') &&
!file.includes('node_modules') &&
!file.match(/dist(\/|$)/)
)
}
})
tempDir = resolve(__dirname, '../packages/temp/', testName)

// when `root` dir is present, use it as vite's root
let testCustomRoot = resolve(tempDir, 'root')
Expand All @@ -83,9 +71,14 @@ beforeAll(async () => {
const testCustomServe = resolve(dirname(testPath), 'serve.js')
if (fs.existsSync(testCustomServe)) {
// test has custom server configuration.
const { serve } = require(testCustomServe)
server = await serve(rootDir, isBuildTest)
return
const { serve, preServe } = require(testCustomServe)
if (preServe) {
await preServe(rootDir, isBuildTest)
}
if (serve) {
server = await serve(rootDir, isBuildTest)
return
}
}

const options: UserConfig = {
Expand Down
30 changes: 30 additions & 0 deletions scripts/patchFileDeps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// pnpm treats file: protocols as link:, so it doesn't copy the actual files
// into node_modules, causing Vite to still consider those deps linked.
// This script is called from postinstall hooks in playground packages that
// uses the file: protocol, and copies the file: deps into node_modules.

const fs = require('fs-extra')
const path = require('path')
const root = process.cwd()
const pkg = require(path.join(root, 'package.json'))

let hasPatched
for (const [key, val] of Object.entries(pkg.dependencies)) {
if (val.startsWith('file:')) {
hasPatched = true
const src = path.resolve(root, val.slice('file:'.length))
const dest = path.resolve(root, 'node_modules', key)
fs.removeSync(dest)
fs.copySync(src, dest, {
dereference: true
})
console.log(`patched ${val}`)
}
}

if (hasPatched) {
// remove node_modules/.ignored as pnpm will think our patched files are
// installed by another package manager and move them into this directory.
// On further installs it will error out if this directory is not empty.
fs.removeSync(path.resolve(root, 'node_modules', '.ignored'))
}
7 changes: 7 additions & 0 deletions scripts/preinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if (!/pnpm/.test(process.env.npm_execpath || '')) {
console.warn(
`\u001b[33mThis repository requires using pnpm as the package manager ` +
` for scripts to work properly.\u001b[39m\n`
)
process.exit(1)
}
6 changes: 4 additions & 2 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ async function main() {

step('\nBuilding package...')
if (!skipBuild && !isDryRun) {
await run('yarn', ['build'])
await run('pnpm', ['run', 'build'])
} else {
console.log(`(skipped)`)
}

step('\nGenerating changelog...')
await run('yarn', ['changelog'])
await run('pnpm', ['run', 'changelog'])

const { stdout } = await run('git', ['diff'], { stdio: 'pipe' })
if (stdout) {
Expand Down Expand Up @@ -199,6 +199,8 @@ async function publishPackage(version, runIfNotDry) {
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'
})
Expand Down

0 comments on commit ad6047d

Please sign in to comment.