Skip to content

Commit 0b603d2

Browse files
authored
fix: transform/parse ts files and bundle using imports (#447)
* test: ensure snapshots default to vite if ran without env variable * refactor: apply option defaults and use sync fs * fix: virtual bundle for webpack and rspack * refactor: more cleanup and refactoring * chore: add dependencies * fix: transform and parse typescript and handle imports * fix: use workspace package as dependency * test: build before tests * fix: include transform resource paths * ci: build before test and reuse cache in jobs * ci: test job needs build * ci: fix test directory * ci: merge lint and test workflows and reuse build * ci: merge build and test workflows into one ci workflow * fix: resource plugin transformInclude for webpack and rspack * ci: set workflow group and cancellation rule * ci: keep running concurrent tests on failure * test: configure ts loaders for rspack and webpack tests * chore: remove dep * fix: simplify regexes * fix: remove redundant hmr handling * chore: add ts loaders in example projects * fix: example config paths in scripts * feat: add exclude option * test: exclude entry file from locale inclusion * refactor: improve logic readability * chore: add comment to mark fixme * fix: add parser initialization and fallback to wasm * fix: remove `oxc-parser` * test: remove init parser calls * test: update snapshots * fix: replace oxc-transform with babel for browser compat * fix: only allow and handle dynamic resource error for virtual bundle * refactor: cleanup * fix: improve js generated code formatting * fix: use hashes for virtual import names * fix: use error utility function * test: document why we add exclude to test util
1 parent 60d8cf7 commit 0b603d2

File tree

29 files changed

+1497
-1099
lines changed

29 files changed

+1497
-1099
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: CI
2+
on:
3+
push:
4+
branches-ignore:
5+
- gh-pages
6+
pull_request:
7+
branches-ignore:
8+
- gh-pages
9+
types:
10+
- opened
11+
- synchronize
12+
- reopened
13+
permissions:
14+
contents: read
15+
env:
16+
CI: true
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
20+
cancel-in-progress: ${{ github.event_name != 'push' }}
21+
22+
jobs:
23+
build:
24+
runs-on: ${{ matrix.os }}
25+
26+
strategy:
27+
matrix:
28+
os: [ubuntu-latest]
29+
node: [18]
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Install pnpm
36+
uses: pnpm/action-setup@v4
37+
38+
- name: Setup Node.js ${{ matrix.node }}
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: ${{ matrix.node }}
42+
cache: 'pnpm'
43+
44+
- name: Install dependencies
45+
run: pnpm install
46+
47+
- name: Build code
48+
run: pnpm build
49+
50+
- name: Cache dist
51+
uses: actions/cache@v4
52+
with:
53+
path: packages/*/lib
54+
key: build-intlify-bundle-tools-os-${{ matrix.os }}-${{ github.sha }}
55+
56+
lint:
57+
runs-on: ${{ matrix.os }}
58+
59+
needs:
60+
- build
61+
62+
strategy:
63+
matrix:
64+
os: [ubuntu-latest]
65+
node: [18]
66+
67+
steps:
68+
- name: Checkout
69+
uses: actions/checkout@v4
70+
71+
- name: Install pnpm
72+
uses: pnpm/action-setup@v4
73+
74+
- name: Setup Node.js ${{ matrix.node }}
75+
uses: actions/setup-node@v4
76+
with:
77+
node-version: ${{ matrix.node }}
78+
cache: 'pnpm'
79+
80+
- name: Install dependencies
81+
run: pnpm install
82+
83+
- name: Restore dist cache
84+
uses: actions/cache@v4
85+
with:
86+
path: packages/*/lib
87+
key: build-intlify-bundle-tools-os-${{ matrix.os }}-${{ github.sha }}
88+
89+
- name: Linting
90+
run: pnpm lint
91+
92+
test:
93+
runs-on: ${{ matrix.os }}
94+
95+
needs:
96+
- build
97+
98+
strategy:
99+
fail-fast: false
100+
matrix:
101+
os: [ubuntu-latest]
102+
node: [18, 20, 22]
103+
framework: ['vite', 'rspack', 'webpack']
104+
105+
steps:
106+
- name: Checkout
107+
uses: actions/checkout@v4
108+
109+
- name: Install pnpm
110+
uses: pnpm/action-setup@v4
111+
112+
- name: Setup Node.js ${{ matrix.node }}
113+
uses: actions/setup-node@v4
114+
with:
115+
node-version: ${{ matrix.node }}
116+
cache: 'pnpm'
117+
118+
- name: Install dependencies
119+
run: pnpm install
120+
121+
# https://github.com/vitejs/vite/blob/main/.github/workflows/ci.yml#L62
122+
# Install playwright's binary under custom directory to cache
123+
- name: Set Playwright path
124+
run: echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/playwright-bin" >> $GITHUB_ENV
125+
126+
- name: Cache Playwright's binary
127+
uses: actions/cache@v4
128+
with:
129+
# Playwright removes unused browsers automatically
130+
# So does not need to add playwright version to key
131+
key: ${{ runner.os }}-playwright-bin-v1
132+
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
133+
134+
- name: Install Playwright
135+
# does not need to explicitly set chromium after https://github.com/microsoft/playwright/issues/14862 is solved
136+
run: pnpm playwright install chromium
137+
138+
- name: Restore dist cache
139+
uses: actions/cache@v4
140+
with:
141+
path: packages/*/lib
142+
key: build-intlify-bundle-tools-os-${{ matrix.os }}-${{ github.sha }}
143+
144+
- name: Testing
145+
run: pnpm test
146+
env:
147+
TEST_FRAMEWORK: ${{ matrix.framework }}

.github/workflows/lint.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 0 additions & 63 deletions
This file was deleted.

examples/rspack/rspack.config.js renamed to examples/rspack/rspack.config.mjs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// @ts-check
2-
const path = require('path')
3-
const { VueLoaderPlugin } = require('vue-loader')
4-
const VueI18nPlugin = require('../../packages/unplugin-vue-i18n/lib/rspack.cjs')
2+
import { dirname, resolve, join } from 'path'
3+
import { VueLoaderPlugin } from 'vue-loader'
4+
import VueI18nPlugin from '../../packages/unplugin-vue-i18n/lib/rspack.mjs'
5+
import { fileURLToPath } from 'url'
6+
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = dirname(__filename)
59

610
function transformI18nBlock(source) {
711
const sourceCopy = source
@@ -27,30 +31,40 @@ function transformI18nBlock(source) {
2731
/**
2832
* @type {import('@rspack/core').RspackOptions}
2933
**/
30-
module.exports = {
34+
export default {
3135
mode: 'development',
3236
devtool: 'source-map',
33-
entry: path.resolve(__dirname, './src/main.js'),
37+
entry: resolve(__dirname, './src/main.js'),
3438
output: {
35-
path: path.resolve(__dirname, 'dist'),
39+
path: resolve(__dirname, 'dist'),
3640
filename: '[name].js',
3741
publicPath: '/dist/'
3842
},
3943
resolve: {
4044
alias: {
41-
vue: path.resolve(
42-
__dirname,
43-
'../../node_modules/vue/dist/vue.esm-bundler.js'
44-
)
45+
vue: resolve(__dirname, '../../node_modules/vue/dist/vue.esm-bundler.js')
4546
}
4647
},
4748
devServer: {
4849
static: {
49-
directory: path.join(__dirname, './')
50+
directory: join(__dirname, './')
5051
}
5152
},
5253
module: {
5354
rules: [
55+
{
56+
test: /\.ts$/,
57+
exclude: [/node_modules/],
58+
loader: 'builtin:swc-loader',
59+
options: {
60+
jsc: {
61+
parser: {
62+
syntax: 'typescript'
63+
}
64+
}
65+
},
66+
type: 'javascript/auto'
67+
},
5468
{
5569
test: /\.vue$/,
5670
loader: 'vue-loader'
@@ -64,7 +78,7 @@ module.exports = {
6478
plugins: [
6579
new VueLoaderPlugin(),
6680
VueI18nPlugin({
67-
include: [path.resolve(__dirname, './src/locales/**')],
81+
include: [resolve(__dirname, './src/locales/**')],
6882
transformI18nBlock: transformI18nBlock
6983
})
7084
]

examples/rspack/src/main.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { createApp } from 'vue'
22
import { createI18n } from 'vue-i18n'
33
import App from './App.vue'
4-
5-
import ja from './locales/ja.json'
6-
import en from './locales/en.yaml'
4+
import messages from '@intlify/unplugin-vue-i18n/messages'
75

86
const i18n = createI18n({
97
locale: 'ja',
10-
messages: {
11-
en,
12-
ja
13-
}
8+
messages
149
})
1510

1611
const app = createApp(App)

0 commit comments

Comments
 (0)