Skip to content

Commit 23133aa

Browse files
authored
fix: normalize include exclude paths (#507)
* fix: normalize resource glob options * fix: linting
1 parent c7215b3 commit 23133aa

File tree

3 files changed

+18
-36
lines changed

3 files changed

+18
-36
lines changed

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ This changelog is generated by [GitHub Releases](https://github.com/intlify/bund
44

55
<!-- Release notes generated using configuration in .github/release.yml at v11.0.0 -->
66

7-
8-
97
**Full Changelog**: https://github.com/intlify/bundle-tools/compare/v11.0.0-beta.5...v11.0.0
108

11-
129
# v11.0.0-beta.5 (2025-07-22T06:37:41Z)
1310

1411
This changelog is generated by [GitHub Releases](https://github.com/intlify/bundle-tools/releases/tag/v11.0.0-beta.5)

packages/unplugin-vue-i18n/src/core/options.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import { isString, isBoolean, isArray } from '@intlify/shared'
1+
import { isArray, isBoolean, isString } from '@intlify/shared'
2+
import { normalize } from 'pathe'
23

34
import type { PluginOptions } from '../types'
45
import type { TranslationDirectiveResolveIndetifier } from '../vue'
56

7+
function normalizeGlobOption(val: string | string[] | undefined) {
8+
if (!val) return undefined
9+
return isString(val) ? [normalize(val)] : val.map(normalize)
10+
}
11+
612
export function resolveOptions(options: PluginOptions) {
713
const moduleType = (options.module || 'vue-i18n') as string
814

@@ -53,8 +59,8 @@ export function resolveOptions(options: PluginOptions) {
5359
typeof options.transformI18nBlock === 'function' ? options.transformI18nBlock : null
5460

5561
return {
56-
include: options.include,
57-
exclude: options.exclude,
62+
include: normalizeGlobOption(options.include),
63+
exclude: normalizeGlobOption(options.exclude),
5864
module: moduleType,
5965
onlyLocales,
6066
forceStringify,

packages/unplugin-vue-i18n/src/core/resource.ts

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,12 @@ import {
44
generateTypescript,
55
generateYAML
66
} from '@intlify/bundle-utils'
7-
import {
8-
assign,
9-
generateCodeFrame,
10-
isArray,
11-
isEmptyObject,
12-
isNumber,
13-
isString
14-
} from '@intlify/shared'
7+
import { assign, generateCodeFrame, isEmptyObject, isNumber, isString } from '@intlify/shared'
158
import { createFilter } from '@rollup/pluginutils'
169
import createDebug from 'debug'
1710
import fg from 'fast-glob'
1811
import { promises as fs } from 'node:fs'
1912
import { parse as parsePath } from 'node:path'
20-
import { normalize } from 'pathe'
2113
import { parse } from 'vue/compiler-sfc'
2214
import { checkVuePlugin, error, getVitePlugin, raiseError, resolveNamespace, warn } from '../utils'
2315
import { getVueCompiler, parseVueRequest } from '../vue'
@@ -83,30 +75,18 @@ export function resourcePlugin(
8375
function resolveIncludeExclude() {
8476
const customBlockInclude =
8577
meta.framework === 'vite' ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK
86-
if (isArray(include)) {
87-
return [[...include, customBlockInclude], exclude]
88-
} else if (isString(include)) {
89-
return [[include, customBlockInclude], exclude]
90-
} else {
91-
return [[RE_RESOURCE_FORMAT, customBlockInclude], exclude]
92-
}
78+
return include
79+
? [[...include, customBlockInclude], exclude]
80+
: [[RE_RESOURCE_FORMAT, customBlockInclude], exclude]
9381
}
9482

9583
function resolveIncludeExcludeForLegacy() {
9684
const customBlockInclude =
9785
meta.framework === 'vite' ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK
98-
let _include: string | (string | RegExp)[] | undefined = undefined
99-
let _exclude: string | (string | RegExp)[] | undefined = undefined
100-
if (include) {
101-
if (isArray(include)) {
102-
_include = [...include.map(item => normalize(item)), customBlockInclude]
103-
} else if (isString(include)) {
104-
_include = [normalize(include), customBlockInclude]
105-
}
106-
} else {
107-
_exclude = '**/**'
108-
}
109-
return [_include, _exclude]
86+
// prettier-ignore
87+
return include
88+
? [[...include, customBlockInclude], undefined]
89+
: [undefined, ['**/**']]
11090
}
11191

11292
let _filter: ReturnType<typeof createFilter> | null = null
@@ -337,8 +317,7 @@ export function resourcePlugin(
337317
debug('load', id)
338318
if (INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework) && include) {
339319
let resourcePaths = [] as string[]
340-
const includePaths = isArray(include) ? include : [include]
341-
for (const inc of includePaths) {
320+
for (const inc of include) {
342321
resourcePaths = [...resourcePaths, ...(await fg(inc))]
343322
}
344323
resourcePaths = resourcePaths.filter((el, pos) => resourcePaths.indexOf(el) === pos)

0 commit comments

Comments
 (0)