Skip to content

Commit ad6047d

Browse files
authored
workflow: switch to pnpm (#5060)
1 parent 77bd76f commit ad6047d

11 files changed

+108
-63
lines changed

.github/workflows/ci.yml

+24-35
Original file line numberDiff line numberDiff line change
@@ -33,44 +33,34 @@ jobs:
3333
- name: Checkout
3434
uses: actions/checkout@v2
3535

36+
- name: Install pnpm
37+
uses: pnpm/[email protected]
38+
with:
39+
version: 6.15.1
40+
3641
- name: Set node version to ${{ matrix.node_version }}
3742
uses: actions/setup-node@v2
3843
with:
3944
node-version: ${{ matrix.node_version }}
45+
cache: "pnpm"
4046

41-
- name: Get yarn cache directory
42-
id: yarn-cache
43-
run: echo "::set-output name=dir::$(yarn cache dir)"
44-
45-
- name: Set dependencies cache
46-
uses: actions/cache@v2
47-
with:
48-
path: ${{ steps.yarn-cache.outputs.dir }}
49-
key: ${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('yarn.lock') }}
50-
restore-keys: |
51-
${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('yarn.lock') }}
52-
${{ runner.os }}-${{ matrix.node_version }}-
53-
54-
- name: Versions
55-
run: yarn versions
56-
57-
- name: Install dependencies
58-
run: yarn install --frozen-lockfile
47+
- name: Install deps
48+
run: pnpm install
5949

6050
- name: Build vite
61-
run: yarn ci-build-vite
51+
run: pnpm run ci-build-vite
6252

6353
- name: Build plugin-vue
64-
run: yarn build-plugin-vue
54+
run: pnpm run build-plugin-vue
6555

6656
- name: Build plugin-react
67-
run: yarn build-plugin-react
57+
run: pnpm run build-plugin-react
6858

6959
- name: Test serve
70-
run: yarn test-serve --runInBand
60+
run: pnpm run test-serve -- --runInBand
7161

7262
- name: Test build
73-
run: yarn test-build --runInBand
63+
run: pnpm run test-build -- --runInBand
7464

7565
lint:
7666
runs-on: ubuntu-latest
@@ -80,25 +70,24 @@ jobs:
8070
with:
8171
fetch-depth: 0
8272

73+
- name: Install pnpm
74+
uses: pnpm/[email protected]
75+
with:
76+
version: 6.15.1
77+
8378
- name: Set node version to 14
8479
uses: actions/setup-node@v2
8580
with:
8681
node-version: 14
82+
cache: "pnpm"
8783

88-
- name: Set dependencies cache
89-
uses: actions/cache@v2
90-
with:
91-
path: ~/.cache/yarn
92-
key: lint-dependencies-${{ hashFiles('yarn.lock') }}
93-
restore-keys: |
94-
lint-dependencies-${{ hashFiles('yarn.lock') }}
95-
lint-dependencies-
84+
- name: Install deps
85+
run: pnpm install
9686

9787
- name: Prepare
9888
run: |
99-
yarn install --frozen-lockfile
100-
yarn ci-build-vite
101-
yarn build-plugin-vue
89+
pnpm run ci-build-vite
90+
pnpm run build-plugin-vue
10291
10392
- name: Lint
104-
run: yarn lint
93+
run: pnpm run lint

.prettierignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ packages/plugin-vue/dist/
66
packages/*/CHANGELOG.md
77
LICENSE.md
88
.prettierignore
9-
yarn.lock
9+
pnpm-lock.yaml
10+
pnpm-workspace.yaml
1011
packages/playground/tsconfig-json-load-error/has-error/tsconfig.json

package.json

+15-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"node": ">=12.0.0"
1010
},
1111
"scripts": {
12+
"preinstall": "node scripts/preinstall",
1213
"format": "prettier --write .",
1314
"lint": "eslint packages/*/{src,types}/**",
1415
"test": "run-s test-serve test-build",
@@ -20,10 +21,10 @@
2021
"build-docs": "vitepress build docs",
2122
"serve-docs": "vitepress serve docs",
2223
"build": "run-s build-vite build-plugin-vue build-plugin-react",
23-
"build-vite": "cd packages/vite && yarn build",
24-
"build-plugin-vue": "cd packages/plugin-vue && yarn build",
25-
"build-plugin-react": "cd packages/plugin-react && yarn build",
26-
"ci-build-vite": "cd packages/vite && yarn ci-build",
24+
"build-vite": "cd packages/vite && npm run build",
25+
"build-plugin-vue": "cd packages/plugin-vue && npm run build",
26+
"build-plugin-react": "cd packages/plugin-react && npm run build",
27+
"ci-build-vite": "cd packages/vite && npm run ci-build",
2728
"ci-docs": "run-s build-vite build-plugin-vue build-docs"
2829
},
2930
"devDependencies": {
@@ -57,7 +58,10 @@
5758
"ts-node": "^10.1.0",
5859
"typescript": "~4.3.5",
5960
"vitepress": "^0.19.1",
60-
"yorkie": "^2.0.0"
61+
"yorkie": "^2.0.0",
62+
"rollup": "^2.57.0",
63+
"esbuild": "^0.13.2",
64+
"vite": "workspace:*"
6165
},
6266
"gitHooks": {
6367
"pre-commit": "lint-staged --concurrent false",
@@ -73,5 +77,11 @@
7377
"packages/**/*.d.ts": [
7478
"eslint --ext .ts"
7579
]
80+
},
81+
"pnpm": {
82+
"overrides": {
83+
"vite": "workspace:*",
84+
"@vitejs/plugin-vue": "workspace:*"
85+
}
7686
}
7787
}

packages/plugin-vue/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"rollup": "^2.57.0",
4040
"slash": "^3.0.0",
4141
"source-map": "^0.6.1",
42-
"vue": "^3.2.14",
43-
"@vue/compiler-sfc": "^3.2.14"
42+
"vue": "^3.2.16",
43+
"@vue/compiler-sfc": "^3.2.16"
4444
}
4545
}

pnpm-workspace.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
packages:
2+
- 'packages/*'
3+
- 'packages/playground/**'

scripts/jestGlobalSetup.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
const os = require('os')
23
const fs = require('fs-extra')
34
const path = require('path')
@@ -17,5 +18,14 @@ module.exports = async () => {
1718

1819
await fs.mkdirp(DIR)
1920
await fs.writeFile(path.join(DIR, 'wsEndpoint'), browserServer.wsEndpoint())
20-
await fs.remove(path.resolve(__dirname, '../temp'))
21+
22+
const tempDir = path.resolve(__dirname, '../packages/temp')
23+
await fs.remove(tempDir)
24+
await fs.copy(path.resolve(__dirname, '../packages/playground'), tempDir, {
25+
dereference: false,
26+
filter(file) {
27+
file = file.replace(/\\/g, '/')
28+
return !file.includes('__tests__') && !file.match(/dist(\/|$)/)
29+
}
30+
})
2131
}

scripts/jestGlobalTeardown.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ const path = require('path')
44
module.exports = async () => {
55
await global.__BROWSER_SERVER__.close()
66
if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) {
7-
await fs.remove(path.resolve(__dirname, '../temp'))
7+
await fs.remove(path.resolve(__dirname, '../packages/temp'))
88
}
99
}

scripts/jestPerTestSetup.ts

+9-16
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,7 @@ beforeAll(async () => {
6262
// start a vite server in that directory.
6363
if (testName) {
6464
const playgroundRoot = resolve(__dirname, '../packages/playground')
65-
const srcDir = resolve(playgroundRoot, testName)
66-
tempDir = resolve(__dirname, '../temp', testName)
67-
await fs.copy(srcDir, tempDir, {
68-
dereference: true,
69-
filter(file) {
70-
file = slash(file)
71-
return (
72-
!file.includes('__tests__') &&
73-
!file.includes('node_modules') &&
74-
!file.match(/dist(\/|$)/)
75-
)
76-
}
77-
})
65+
tempDir = resolve(__dirname, '../packages/temp/', testName)
7866

7967
// when `root` dir is present, use it as vite's root
8068
let testCustomRoot = resolve(tempDir, 'root')
@@ -83,9 +71,14 @@ beforeAll(async () => {
8371
const testCustomServe = resolve(dirname(testPath), 'serve.js')
8472
if (fs.existsSync(testCustomServe)) {
8573
// test has custom server configuration.
86-
const { serve } = require(testCustomServe)
87-
server = await serve(rootDir, isBuildTest)
88-
return
74+
const { serve, preServe } = require(testCustomServe)
75+
if (preServe) {
76+
await preServe(rootDir, isBuildTest)
77+
}
78+
if (serve) {
79+
server = await serve(rootDir, isBuildTest)
80+
return
81+
}
8982
}
9083

9184
const options: UserConfig = {

scripts/patchFileDeps.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// pnpm treats file: protocols as link:, so it doesn't copy the actual files
2+
// into node_modules, causing Vite to still consider those deps linked.
3+
// This script is called from postinstall hooks in playground packages that
4+
// uses the file: protocol, and copies the file: deps into node_modules.
5+
6+
const fs = require('fs-extra')
7+
const path = require('path')
8+
const root = process.cwd()
9+
const pkg = require(path.join(root, 'package.json'))
10+
11+
let hasPatched
12+
for (const [key, val] of Object.entries(pkg.dependencies)) {
13+
if (val.startsWith('file:')) {
14+
hasPatched = true
15+
const src = path.resolve(root, val.slice('file:'.length))
16+
const dest = path.resolve(root, 'node_modules', key)
17+
fs.removeSync(dest)
18+
fs.copySync(src, dest, {
19+
dereference: true
20+
})
21+
console.log(`patched ${val}`)
22+
}
23+
}
24+
25+
if (hasPatched) {
26+
// remove node_modules/.ignored as pnpm will think our patched files are
27+
// installed by another package manager and move them into this directory.
28+
// On further installs it will error out if this directory is not empty.
29+
fs.removeSync(path.resolve(root, 'node_modules', '.ignored'))
30+
}

scripts/preinstall.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if (!/pnpm/.test(process.env.npm_execpath || '')) {
2+
console.warn(
3+
`\u001b[33mThis repository requires using pnpm as the package manager ` +
4+
` for scripts to work properly.\u001b[39m\n`
5+
)
6+
process.exit(1)
7+
}

scripts/release.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ async function main() {
141141

142142
step('\nBuilding package...')
143143
if (!skipBuild && !isDryRun) {
144-
await run('yarn', ['build'])
144+
await run('pnpm', ['run', 'build'])
145145
} else {
146146
console.log(`(skipped)`)
147147
}
148148

149149
step('\nGenerating changelog...')
150-
await run('yarn', ['changelog'])
150+
await run('pnpm', ['run', 'changelog'])
151151

152152
const { stdout } = await run('git', ['diff'], { stdio: 'pipe' })
153153
if (stdout) {
@@ -199,6 +199,8 @@ async function publishPackage(version, runIfNotDry) {
199199
publicArgs.push(`--tag`, args.tag)
200200
}
201201
try {
202+
// important: we still use Yarn 1 to publish since we rely on its specific
203+
// behavior
202204
await runIfNotDry('yarn', publicArgs, {
203205
stdio: 'pipe'
204206
})

0 commit comments

Comments
 (0)