Skip to content

Commit

Permalink
breaking(unplugin-vue-i18n): drop jitCompilation option (#362)
Browse files Browse the repository at this point in the history
* breaking(unplugin-vue-i18n): drop `jitCompilation` option

* chore: update test

* fix: bump
  • Loading branch information
kazupon authored May 15, 2024
1 parent 06e76ba commit 7114e8e
Show file tree
Hide file tree
Showing 18 changed files with 2,532 additions and 326 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [18.x]
node: [18, 20, 22]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
},
"devDependencies": {
"@intlify/core-base": "^9.13.1",
"@intlify/core-base": "10.0.0-alpha.5",
"@kazupon/lerna-changelog": "^4.3.0",
"@octokit/rest": "^18.6.0",
"@rollup/plugin-alias": "^3.1.5",
Expand Down Expand Up @@ -83,7 +83,7 @@
"vite": "^4.4.9",
"vitest": "^0.29.8",
"vue": "^2.6.14",
"vue-i18n": "9.13.1",
"vue-i18n": "10.0.0-alpha.5",
"vue-loader": "^16.3.0",
"vue-loader15": "npm:[email protected]",
"vue-loader17": "npm:[email protected]",
Expand Down
11 changes: 6 additions & 5 deletions packages/unplugin-vue-i18n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,11 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi
- **Default:** `true`

> [!IMPORTANT]
'jitCompilation' option now defaults to `true` from 3.0.
'jitCompilation' option is deprected in v5.
This option will be supported with vue-i18n until v9 latest version.

Whether locale mesages should be compiled by JIT (Just in Time) compilation with vue-i18n's message compiler.

> [!NOTE]
This option works with vue-i18n v9.3 and later.

JIT compilation has been supported since vue-i18n v9.3. This means that since v9 was released until now, the message compiler compiles to executable JavaScript code, however it did not work in the CSP environment. Also, since this was an AOT (Ahead of Time) compilation, it was not possible to dynamically retrieve locale messages from the back-end Database and compose locale mesages with programatic.

> [!WARNING]
Expand All @@ -374,7 +372,10 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi

Whether to tree-shake message compiler when we will be bundling.

If you chose to use this option, you will need to enable `jitCompilation` option.
If do you will use this option, you need to enable `jitCompilation` option.

> [NOTE]
> After v5 or later, this option can be set with or without `jitCompilation`.
> [!NOTE]
This option works with vue-i18n v9.3 and later.
Expand Down
3 changes: 1 addition & 2 deletions packages/unplugin-vue-i18n/examples/vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export default defineConfig({
plugins: [
vue(),
vueI18n({
include: path.resolve(__dirname, './src/locales/**'),
jitCompilation: true
include: path.resolve(__dirname, './src/locales/**')
})
]
})
2 changes: 1 addition & 1 deletion packages/unplugin-vue-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"@intlify/bundle-utils": "^8.0.0",
"@intlify/shared": "^9.4.0",
"@intlify/shared": "^10.0.0-alpha.5",
"@rollup/pluginutils": "^5.1.0",
"@vue/compiler-sfc": "^3.2.47",
"debug": "^4.3.3",
Expand Down
42 changes: 9 additions & 33 deletions packages/unplugin-vue-i18n/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
: true
debug('runtimeOnly', runtimeOnly)

const jitCompilation = isBoolean(options.jitCompilation)
? options.jitCompilation
: true
debug('jitCompilation', jitCompilation)

const dropMessageCompiler = jitCompilation
? !!options.dropMessageCompiler
: false
const dropMessageCompiler = !!options.dropMessageCompiler
debug('dropMessageCompiler', dropMessageCompiler)

// prettier-ignore
Expand Down Expand Up @@ -233,10 +226,6 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
debug(
`set __VUE_I18N_FULL_INSTALL__ is '${config.define['__VUE_I18N_FULL_INSTALL__']}'`
)
config.define['__INTLIFY_JIT_COMPILATION__'] = jitCompilation
debug(
`set __INTLIFY_JIT_COMPILATION__ is '${config.define['__INTLIFY_JIT_COMPILATION__']}'`
)
config.define['__INTLIFY_DROP_MESSAGE_COMPILER__'] = dropMessageCompiler
debug(
`set __INTLIFY_DROP_MESSAGE_COMPILER__ is '${config.define['__INTLIFY_DROP_MESSAGE_COMPILER__']}'`
Expand Down Expand Up @@ -327,7 +316,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
allowDynamic,
strictMessage,
escapeHtml,
jit: jitCompilation,
jit: true,
onlyLocales,
forceStringify
}
Expand All @@ -342,12 +331,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {

return {
code: generatedCode,
// prettier-ignore
map: (jitCompilation
? { mappings: '' }
: sourceMap
? map
: { mappings: '' }) as any // eslint-disable-line @typescript-eslint/no-explicit-any
map: { mappings: '' }
}
} else {
return result
Expand Down Expand Up @@ -519,7 +503,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
allowDynamic,
strictMessage,
escapeHtml,
jit: jitCompilation,
jit: true,
onlyLocales,
forceStringify
}
Expand All @@ -535,11 +519,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
return {
code: generatedCode,
// prettier-ignore
map: (jitCompilation
? { mappings: '' }
: sourceMap
? map
: { mappings: '' }) as any // eslint-disable-line @typescript-eslint/no-explicit-any
map: { mappings: '' }
}
} else {
// TODO: support virtual import identifier
Expand Down Expand Up @@ -574,7 +554,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
inSourceMap,
isGlobal: globalSFCScope,
useClassComponent,
jit: jitCompilation,
jit: true,
strictMessage,
escapeHtml,
onlyLocales,
Expand All @@ -599,11 +579,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
return {
code: generatedCode,
// prettier-ignore
map: (jitCompilation
? { mappings: '' }
: sourceMap
? map
: { mappings: '' }) as any // eslint-disable-line @typescript-eslint/no-explicit-any
map: { mappings: '' }
}
}
}
Expand Down Expand Up @@ -669,7 +645,7 @@ async function generateBundleResources(
strictMessage = true,
escapeHtml = false,
useClassComponent = false,
jit = false
jit = true
}: {
forceStringify?: boolean
isGlobal?: boolean
Expand Down Expand Up @@ -790,7 +766,7 @@ function getOptions(
allowDynamic = false,
strictMessage = true,
escapeHtml = false,
jit = false
jit = true
}: {
inSourceMap?: RawSourceMap
forceStringify?: boolean
Expand Down
1 change: 0 additions & 1 deletion packages/unplugin-vue-i18n/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export interface PluginOptions {
include?: string | string[]
onlyLocales?: string | string[]
allowDynamic?: boolean
jitCompilation?: boolean
dropMessageCompiler?: boolean
runtimeOnly?: boolean
compositionOnly?: boolean
Expand Down
2 changes: 0 additions & 2 deletions packages/unplugin-vue-i18n/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export async function bundleVite(
? options.strictMessage
: true
options.escapeHtml = !!options.escapeHtml
options.jitCompilation = !!options.jitCompilation

const alias: Record<string, string> = {
vue: 'vue/dist/vue.runtime.esm-browser.js'
Expand Down Expand Up @@ -167,7 +166,6 @@ export async function bundleAndRun(
? options.strictMessage
: true
options.escapeHtml = !!options.escapeHtml
options.jitCompilation = !!options.jitCompilation

const { code, map } = await bundler(fixture, options)

Expand Down
Loading

0 comments on commit 7114e8e

Please sign in to comment.