Skip to content

Commit e679552

Browse files
authored
re-structure project environment (#380)
* chore: use pnpm * chore: pass params to test:unit * fix: re-structure e2e and example * add todo memo * add more task * fix: use pnpm on github actions
1 parent b7421c1 commit e679552

37 files changed

+12700
-15082
lines changed

.github/workflows/build.yml

+11-5
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ jobs:
2626
steps:
2727
- name: Checkout
2828
uses: actions/checkout@v4
29+
30+
- name: Enable corepack
31+
run: corepack enable
32+
2933
- name: Setup Node.js ${{ matrix.node }}
3034
uses: actions/setup-node@v4
3135
with:
3236
node-version: ${{ matrix.node }}
33-
cache: 'yarn'
34-
- name: Install
35-
run: yarn --immutable
36-
- name: Build
37-
run: yarn build
37+
cache: 'pnpm'
38+
39+
- name: Install dependencies
40+
run: pnpm install
41+
42+
- name: Building
43+
run: pnpm build

.github/workflows/lint.yml

+11-5
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ jobs:
2626
steps:
2727
- name: Checkout
2828
uses: actions/checkout@v4
29+
30+
- name: Enable corepack
31+
run: corepack enable
32+
2933
- name: Setup Node.js ${{ matrix.node }}
3034
uses: actions/setup-node@v4
3135
with:
3236
node-version: ${{ matrix.node }}
33-
cache: 'yarn'
34-
- name: Install
35-
run: yarn --immutable
36-
- name: Lint
37-
run: yarn lint
37+
cache: 'pnpm'
38+
39+
- name: Install dependencies
40+
run: pnpm install
41+
42+
- name: Linting
43+
run: pnpm lint

.github/workflows/test.yml

+28-5
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,35 @@ jobs:
2626
steps:
2727
- name: Checkout
2828
uses: actions/checkout@v4
29+
30+
- name: Enable corepack
31+
run: corepack enable
32+
2933
- name: Setup Node.js ${{ matrix.node }}
3034
uses: actions/setup-node@v4
3135
with:
3236
node-version: ${{ matrix.node }}
33-
cache: 'yarn'
34-
- name: Install
35-
run: yarn --immutable
36-
- name: Test
37-
run: yarn test
37+
cache: 'pnpm'
38+
39+
- name: Install dependencies
40+
run: pnpm install
41+
42+
# https://github.com/vitejs/vite/blob/main/.github/workflows/ci.yml#L62
43+
# Install playwright's binary under custom directory to cache
44+
- name: Set Playwright path
45+
run: echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/playwright-bin" >> $GITHUB_ENV
46+
47+
- name: Cache Playwright's binary
48+
uses: actions/cache@v4
49+
with:
50+
# Playwright removes unused browsers automatically
51+
# So does not need to add playwright version to key
52+
key: ${{ runner.os }}-playwright-bin-v1
53+
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
54+
55+
- name: Install Playwright
56+
# does not need to explicitly set chromium after https://github.com/microsoft/playwright/issues/14862 is solved
57+
run: pnpm playwright install chromium
58+
59+
- name: Testing
60+
run: pnpm test

.yarn/releases/yarn-3.1.1.cjs

-768
This file was deleted.

TODO.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# TODO
2+
- [ ] upgrade vitest 1.0 (need to fix `checkInstallPackage` issue in test env)
3+
- [ ] drop fully jest pupeeter for rollup-plugin-vue-i18n, vue-i18n-loader, and vite-plugin-vue-i18n
4+
- [ ] ESLint: migrate flat config style

e2e/helper.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Page } from 'playwright'
2+
3+
export async function getText(
4+
page: Page,
5+
selector: string,
6+
options?: Parameters<Page['locator']>[1]
7+
) {
8+
return (await page.locator(selector, options).allTextContents())[0]
9+
}

e2e/setup-server.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { getRandomPort, waitForPort } from 'get-port-please'
2+
import { ChildProcess, spawn } from 'node:child_process'
3+
4+
export type ServerContext = {
5+
serverProcess: ChildProcess
6+
url: (val: string) => string
7+
}
8+
export async function startServer(): Promise<ServerContext> {
9+
const host = '127.0.0.1'
10+
const port = await getRandomPort(host)
11+
12+
const serverProcess = spawn(
13+
'pnpm',
14+
['play:vite', '--port', String(port), '--host', host],
15+
{ stdio: 'inherit', env: { ...process.env } }
16+
)
17+
18+
await waitForPort(port, { retries: 32, host })
19+
20+
return {
21+
serverProcess,
22+
url: (val: string) => `http://${host}:${port}${val}`
23+
}
24+
}

e2e/vite.spec.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { startServer } from './setup-server'
2+
import { getText } from './helper'
3+
4+
import type { ServerContext } from './setup-server'
5+
import type { Browser, Page } from 'playwright'
6+
7+
// TODO: extract to shim.d.ts
8+
// eslint-disable-next-line @typescript-eslint/no-namespace
9+
declare namespace global {
10+
let browser: Browser
11+
let page: Page
12+
}
13+
14+
let ctx: ServerContext
15+
describe('vite', () => {
16+
beforeAll(async () => {
17+
ctx = await startServer()
18+
await global.page.goto(ctx.url('/'))
19+
})
20+
21+
afterAll(async () => {
22+
ctx.serverProcess.kill()
23+
})
24+
25+
test('initial rendering', async () => {
26+
expect(await getText(global.page, '#lang label')).toMatch('言語')
27+
expect(await getText(global.page, '#fruits label')).toMatch(
28+
'バナナが欲しい?'
29+
)
30+
expect(await getText(global.page, '#msg')).toMatch('こんにちは、世界!')
31+
expect(await getText(global.page, '#custom-directive')).toMatch('やあ!')
32+
})
33+
34+
test('change locale', async () => {
35+
await global.page.selectOption('#lang select', 'en')
36+
expect(await getText(global.page, '#lang label')).toMatch('Language')
37+
expect(await getText(global.page, '#msg')).toMatch('hello, world!')
38+
expect(await getText(global.page, '#custom-directive')).toMatch('Hi!')
39+
})
40+
41+
test('change banana select', async () => {
42+
await global.page.selectOption('#fruits select', '3')
43+
expect(await getText(global.page, '#banana')).toMatch('バナナ 3 個')
44+
})
45+
})
File renamed without changes.

packages/unplugin-vue-i18n/examples/vite/src/App.vue examples/vite/src/App.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
2-
<form>
2+
<form id="lang">
33
<label>{{ t('language') }}</label>
44
<select v-model="locale">
55
<option value="en">en</option>
66
<option value="ja">ja</option>
77
</select>
88
</form>
9-
<p>{{ t('hello') }}</p>
10-
<p v-t="'hi'"></p>
9+
<p id="msg">{{ t('hello') }}</p>
10+
<p id="custom-directive" v-t="'hi'"></p>
1111
<Banana />
1212
</template>
1313

packages/unplugin-vue-i18n/examples/vite/src/Banana.vue examples/vite/src/Banana.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<option value="3">3</option>
99
</select>
1010
</form>
11-
<p>{{ t('fruits.banana', select, { n: select }) }}</p>
11+
<p id="banana">{{ t('fruits.banana', select, { n: select }) }}</p>
1212
</template>
1313

1414
<script setup lang="ts">
File renamed without changes.

packages/unplugin-vue-i18n/examples/vite/vite.config.ts examples/vite/vite.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import path from 'path'
22
import { defineConfig } from 'vite'
33
import vue from '@vitejs/plugin-vue'
4-
import vueI18n from '../../src/vite'
4+
import vueI18n from '../../packages/unplugin-vue-i18n/src/vite'
55

66
export default defineConfig({
77
resolve: {
88
alias: {
99
vue: path.resolve(
1010
__dirname,
11-
'../../../../node_modules/vue/dist/vue.esm-bundler.js'
11+
'../../node_modules/vue/dist/vue.esm-bundler.js'
1212
)
1313
}
1414
},

packages/unplugin-vue-i18n/examples/webpack/webpack.config.js examples/webpack/webpack.config.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path')
22
const { VueLoaderPlugin } = require('vue-loader')
3-
const VueI18nPlugin = require('../../lib/webpack.cjs')
3+
const VueI18nPlugin = require('../../packages/unplugin-vue-i18n/lib/webpack.cjs')
44

55
module.exports = {
66
mode: 'development',
@@ -13,16 +13,16 @@ module.exports = {
1313
},
1414
resolve: {
1515
alias: {
16-
// this isn't technically needed, since the default `vue` entry for bundlers
17-
// is a simple `export * from '@vue/runtime-dom`. However having this
18-
// extra re-export somehow causes webpack to always invalidate the module
19-
// on the first HMR update and causes the page to reload.
20-
vue: '@vue/runtime-dom'
16+
vue: path.resolve(
17+
__dirname,
18+
'../../node_modules/vue/dist/vue.esm-bundler.js'
19+
)
2120
}
2221
},
2322
devServer: {
24-
stats: 'minimal',
25-
contentBase: __dirname
23+
static: {
24+
directory: path.join(__dirname, './')
25+
}
2626
},
2727
module: {
2828
rules: [

package.json

+44-41
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"eslint-plugin-vue": "^9.26.0",
6060
"esno": "^0.17.0",
6161
"execa": "^5.1.1",
62+
"get-port-please": "^3.1.2",
6263
"jest": "^27.2.3",
6364
"jest-puppeteer": "^6.0.0",
6465
"jest-watch-typeahead": "^0.6.4",
@@ -72,6 +73,7 @@
7273
"prettier": "^3.2.5",
7374
"prompts": "^2.4.1",
7475
"puppeteer": "^10.4.0",
76+
"playwright": "^1.44.0",
7577
"rollup": "^2.53.1",
7678
"rollup-plugin-vue": "^6.0.0",
7779
"secretlint": "^3.2.0",
@@ -113,54 +115,55 @@
113115
},
114116
"scripts": {
115117
"prepare": "git config --local core.hooksPath .githooks",
116-
"build": "npm-run-all -s \"build:utils\" \"build:unplugin\"",
117-
"build:utils": "yarn workspace @intlify/bundle-utils build",
118-
"build:rollup": "yarn workspace @intlify/rollup-plugin-vue-i18n build",
119-
"build:vite": "yarn workspace @intlify/vite-plugin-vue-i18n build",
120-
"build:webpack": "yarn workspace @intlify/vue-i18n-loader build",
121-
"build:unplugin": "yarn workspace @intlify/unplugin-vue-i18n build",
122-
"example:unplugin": "yarn workspace @intlify/unplugin-vue-i18n build:example",
123-
"play:unplugin:vite": "yarn workspace @intlify/unplugin-vue-i18n dev:vite",
124-
"play:unplugin:webpack": "yarn workspace @intlify/unplugin-vue-i18n dev:webpack",
125-
"clean": "npm-run-all --parallel \"clean:*\"",
126-
"clean:utils": "yarn workspace @intlify/bundle-utils clean",
127-
"clean:rollup": "yarn workspace @intlify/rollup-plugin-vue-i18n clean",
128-
"clean:vite": "yarn workspace @intlify/vite-plugin-vue-i18n clean",
129-
"clean:webpack": "yarn workspace @intlify/vue-i18n-loader clean",
130-
"clean:unplugin": "yarn workspace @intlify/unplugin-vue-i18n clean",
118+
"build": "run-s \"build:utils\" \"build:unplugin\"",
119+
"build:utils": "pnpm --filter @intlify/bundle-utils build",
120+
"build:rollup": "pnpm --filter @intlify/rollup-plugin-vue-i18n build",
121+
"build:vite": "pnpm --filter @intlify/vite-plugin-vue-i18n build",
122+
"build:webpack": "pnpm --filter @intlify/vue-i18n-loader build",
123+
"build:unplugin": "pnpm --filter @intlify/unplugin-vue-i18n build",
124+
"build:example": "run-s \"build:example:vite {@}\" \"build:example:webpack\" --",
125+
"build:example:vite": "cd examples/vite && vite build --config ./vite.config.ts --outDir ./dist",
126+
"build:example:webpack": "pnpm build && webpack --config ./examples/webpack/webpack.config.js",
127+
"play:vite": "vite examples/vite -c examples/vite/vite.config.ts",
128+
"play:webpack": "pnpm run build:unplugin && webpack serve --config ./examples/webpack/webpack.config.js",
129+
"preview:vite": "vite preview examples/vite --outDir dist",
130+
"check-install": "jiti scripts/playwright.ts",
131+
"clean": "run-p \"clean:*\"",
132+
"clean:utils": "pnpm --filter @intlify/bundle-utils clean",
133+
"clean:rollup": "pnpm --filter @intlify/rollup-plugin-vue-i18n clean",
134+
"clean:vite": "pnpm --filter @intlify/vite-plugin-vue-i18n clean",
135+
"clean:webpack": "pnpm --filter @intlify/vue-i18n-loader clean",
136+
"clean:unplugin": "pnpm --filter @intlify/unplugin-vue-i18n clean",
131137
"coverage": "opener coverage/lcov-report/index.html",
132-
"fix": "npm-run-all --parallel lint:eslint:fix format:fix",
138+
"fix": "run-p lint:eslint:fix format:fix",
133139
"format": "prettier --config .prettierrc --ignore-path .prettierignore '**/*.{js,json,html}'",
134-
"format:fix": "yarn format --write",
135-
"lint": "npm-run-all --parallel lint:eslint lint:secret",
140+
"format:fix": "pnpm format --write",
141+
"lint": "run-p lint:eslint lint:secret",
136142
"lint:eslint": "eslint ./packages ./scripts --ext .ts",
137-
"lint:eslint:fix": "yarn lint:eslint --fix",
143+
"lint:eslint:fix": "pnpm lint:eslint --fix",
138144
"lint:secret": "npx secretlint \"**/*\"",
139-
"test": "yarn test:unit && yarn test:e2e",
140-
"test:e2e": "npm-run-all test:e2e:unplugin",
141-
"test:e2e:rollup": "yarn workspace @intlify/rollup-plugin-vue-i18n test:e2e",
142-
"test:e2e:vite": "yarn workspace @intlify/vite-plugin-vue-i18n test:e2e",
143-
"test:e2e:webpack": "yarn workspace @intlify/vue-i18n-loader test:e2e",
144-
"test:e2e:unplugin": "yarn workspace @intlify/unplugin-vue-i18n test:e2e",
145-
"test:unit": "run-s \"test:unit:utils\" \"test:unit:unplugin\"",
146-
"test:unit:utils": "yarn run build:utils && vitest run packages/bundle-utils",
145+
"test": "pnpm test:unit && pnpm test:e2e",
146+
"test:e2e": "pnpm check-install && vitest -c ./vitest.e2e.config.ts run",
147+
"test:e2e:rollup": "pnpm --filter @intlify/rollup-plugin-vue-i18n test:e2e",
148+
"test:e2e:vite": "pnpm --filter @intlify/vite-plugin-vue-i18n test:e2e",
149+
"test:e2e:webpack": "pnpm --filter @intlify/vue-i18n-loader test:e2e",
150+
"test:e2e:unplugin": "pnpm --filter @intlify/unplugin-vue-i18n test:e2e",
151+
"test:unit": "run-s \"test:unit:utils {@}\" \"test:unit:unplugin {@}\" --",
152+
"test:unit:utils": "vitest run packages/bundle-utils",
147153
"test:unit:rollup": "vitest run packages/rollup-plugin-vue-i18n/test",
148154
"test:unit:unplugin": "vitest run packages/unplugin-vue-i18n/test",
149155
"changelog": "jiti ./scripts/changelog.ts",
150-
"changelog:utils": "yarn workspace @intlify/bundle-utils changelog",
151-
"changelog:rollup": "yarn workspace @intlify/rollup-plugin-vue-i18n changelog",
152-
"changelog:vite": "yarn workspace @intlify/vite-plugin-vue-i18n changelog",
153-
"changelog:webpack": "yarn workspace @intlify/vue-i18n-loader changelog",
154-
"changelog:unplugin": "yarn workspace @intlify/unplugin-vue-i18n changelog",
156+
"changelog:utils": "pnpm --filter @intlify/bundle-utils changelog",
157+
"changelog:rollup": "pnpm --filter @intlify/rollup-plugin-vue-i18n changelog",
158+
"changelog:vite": "pnpm --filter @intlify/vite-plugin-vue-i18n changelog",
159+
"changelog:webpack": "pnpm --filter @intlify/vue-i18n-loader changelog",
160+
"changelog:unplugin": "pnpm --filter @intlify/unplugin-vue-i18n changelog",
155161
"release": "jiti ./scripts/release.ts",
156-
"release:utils": "yarn workspace @intlify/bundle-utils release",
157-
"release:rollup": "yarn workspace @intlify/rollup-plugin-vue-i18n release",
158-
"release:vite": "yarn workspace @intlify/vite-plugin-vue-i18n release",
159-
"release:webpack": "yarn workspace @intlify/vue-i18n-loader release",
160-
"release:unplugin": "yarn workspace @intlify/unplugin-vue-i18n release"
162+
"release:utils": "pnpm --filter @intlify/bundle-utils release",
163+
"release:rollup": "pnpm --filter @intlify/rollup-plugin-vue-i18n release",
164+
"release:vite": "pnpm --filter @intlify/vite-plugin-vue-i18n release",
165+
"release:webpack": "pnpm --filter @intlify/vue-i18n-loader release",
166+
"release:unplugin": "pnpm --filter @intlify/unplugin-vue-i18n release"
161167
},
162-
"workspaces": [
163-
"packages/bundle-utils",
164-
"packages/unplugin-vue-i18n"
165-
]
168+
"packageManager": "[email protected]+sha256.e1f9e8d1a16607a46dd3c158b5f7a7dc7945501d1c6222d454d63d033d1d918f"
166169
}

packages/bundle-utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
"scripts": {
6363
"build": "unbuild",
64-
"clean": "npm-run-all \"clean:*\"",
64+
"clean": "run-p \"clean:*\"",
6565
"clean:lib": "rm -rf ./lib",
6666
"changelog": "jiti ../../scripts/changelog.ts",
6767
"release": "jiti ../../scripts/release.ts"

packages/unplugin-vue-i18n/e2e/vite.test.js

-25
This file was deleted.

0 commit comments

Comments
 (0)