Skip to content

Commit

Permalink
fix(unplugin-vue-i18n): support unplugin v0.8 (#154)
Browse files Browse the repository at this point in the history
* fix(unplugin-vue-i18n): support unplugin v0.8

* drop node v12
  • Loading branch information
kazupon authored Jul 26, 2022
1 parent 867e30d commit aef68a8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ env:

jobs:
test:
name: "Test on Node.js ${{ matrix.node }} OS: ${{matrix.os}}"
name: 'Test on Node.js ${{ matrix.node }} OS: ${{matrix.os}}'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node: [12, 14, 16]
node: [14.16, 16]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
5 changes: 3 additions & 2 deletions packages/unplugin-vue-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
"js-yaml": "^4.1.0",
"json5": "^2.2.0",
"pathe": "^0.2.0",
"picocolors": "^1.0.0",
"source-map": "0.6.1",
"unplugin": "^0.6.2"
"unplugin": "^0.8.0"
},
"devDependencies": {
"mlly": "^0.5.2",
"unbuild": "^0.7.4"
},
"engines": {
"node": ">= 12"
"node": ">= 14.16"
},
"files": [
"lib",
Expand Down
33 changes: 16 additions & 17 deletions packages/unplugin-vue-i18n/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,6 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
*/
enforce: meta.framework === 'vite' ? 'pre' : 'post',

transformInclude(id) {
debug('transformInclude', id)
if (meta.framework === 'vite') {
return true
} else {
const { filename } = parseVueRequest(id)
return filename.endsWith('vue') ||
filename.endsWith(INTLIFY_BUNDLE_IMPORT_ID) ||
filename.endsWith(INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID)
? true
: /\.(json5?|ya?ml)$/.test(id) && filter(id)
}
},

vite: {
config(config, { command }) {
normalizeConfigResolveAlias(config.resolve, meta.framework)
Expand Down Expand Up @@ -266,6 +252,21 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
}
},

transformInclude(id) {
debug('transformInclude', id)
if (meta.framework === 'vite') {
return true
} else {
const { filename } = parseVueRequest(id)
return (
filename.endsWith('vue') ||
filename.endsWith(INTLIFY_BUNDLE_IMPORT_ID) ||
filename.endsWith(INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) ||
(/\.(json5?|ya?ml)$/.test(filename) && filter(filename))
)
}
},

async transform(code, id) {
const { filename, query } = parseVueRequest(id)
debug('transform', id, JSON.stringify(query), filename)
Expand Down Expand Up @@ -411,9 +412,7 @@ async function loadWebpack() {
try {
webpack = await import('webpack').then(m => m.default || m)
} catch (e) {
console.warn(
`[@intlify/unplugin-vue-i18n] webpack not found, please install webpack.`
)
warn(`webpack not found, please install webpack.`)
}
return webpack
}
Expand Down
5 changes: 3 additions & 2 deletions packages/unplugin-vue-i18n/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { promises as fs } from 'fs'
import pc from 'picocolors'

export function warn(...args: unknown[]) {
console.warn(`[unplugin-vue-i18n] `, ...args)
console.warn(pc.yellow(pc.bold(`[unplugin-vue-i18n] `)), ...args)
}

export function error(...args: unknown[]) {
console.error(`[unplugin-vue-i18n] `, ...args)
console.error(pc.red(pc.bold(`[unplugin-vue-i18n] `)), ...args)
}

export async function getRaw(path: string): Promise<string> {
Expand Down
33 changes: 22 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,10 @@ __metadata:
json5: ^2.2.0
mlly: ^0.5.2
pathe: ^0.2.0
picocolors: ^1.0.0
source-map: 0.6.1
unbuild: ^0.7.4
unplugin: ^0.6.2
unplugin: ^0.8.0
peerDependencies:
petite-vue-i18n: "*"
vue-i18n: "*"
Expand Down Expand Up @@ -2780,6 +2781,15 @@ __metadata:
languageName: node
linkType: hard

"acorn@npm:^8.8.0":
version: 8.8.0
resolution: "acorn@npm:8.8.0"
bin:
acorn: bin/acorn
checksum: 7270ca82b242eafe5687a11fea6e088c960af712683756abf0791b68855ea9cace3057bd5e998ffcef50c944810c1e0ca1da526d02b32110e13c722aa959afdc
languageName: node
linkType: hard

"agent-base@npm:5":
version: 5.1.1
resolution: "agent-base@npm:5.1.1"
Expand Down Expand Up @@ -13457,17 +13467,18 @@ __metadata:
languageName: node
linkType: hard

"unplugin@npm:^0.6.2":
version: 0.6.2
resolution: "unplugin@npm:0.6.2"
"unplugin@npm:^0.8.0":
version: 0.8.0
resolution: "unplugin@npm:0.8.0"
dependencies:
acorn: ^8.8.0
chokidar: ^3.5.3
webpack-sources: ^3.2.3
webpack-virtual-modules: ^0.4.3
webpack-virtual-modules: ^0.4.4
peerDependencies:
esbuild: ">=0.13"
rollup: ^2.50.0
vite: ^2.3.0
vite: ^2.3.0 || ^3.0.0-0
webpack: 4 || 5
peerDependenciesMeta:
esbuild:
Expand All @@ -13478,7 +13489,7 @@ __metadata:
optional: true
webpack:
optional: true
checksum: 0ad0b290c00a528196f9af95cb31872d92221f1cd4a3b3ee7c72d6b1cf2130c1c342aca97ccee44e5c911b59cdf996c095c8188802d7ff7a002a98b84eafc4eb
checksum: 116052627de4b015ce6b856bfb589647390591cd4bd49120475ea591e14706d8ce3992f522192b222c6956a08afe361abd76d8139d028323fecc9821a5d8e5e5
languageName: node
linkType: hard

Expand Down Expand Up @@ -14070,10 +14081,10 @@ __metadata:
languageName: node
linkType: hard

"webpack-virtual-modules@npm:^0.4.3":
version: 0.4.3
resolution: "webpack-virtual-modules@npm:0.4.3"
checksum: 158d30633e0d9be3cfcde10fe959b28df5d5adb1068e0f057fcfb10b0b16ede6c892eba438f6ced089c7c442087748c2fcd1e3f035e4e2dc6760517a8c227714
"webpack-virtual-modules@npm:^0.4.4":
version: 0.4.4
resolution: "webpack-virtual-modules@npm:0.4.4"
checksum: 6720b4c47d76dc9cbaff557562506c192da7560a90395e9918a418e257a0c0cda9f5e3ac92107ec0789f8f23ad942313bd8cdebc95031d0adef1032bf6142bc7
languageName: node
linkType: hard

Expand Down

0 comments on commit aef68a8

Please sign in to comment.