Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d1542e8

Browse files
committedMar 22, 2023
Fix path differences with Windows and Linux
1 parent 57cf5a6 commit d1542e8

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed
 

‎package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"@fluent/syntax": "^0.19.0",
6666
"@rollup/pluginutils": "^5.0.0",
6767
"magic-string": "^0.30.0",
68+
"pathe": "^1.1.0",
6869
"unplugin": "^1.0.0"
6970
},
7071
"devDependencies": {

‎pnpm-lock.yaml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/plugins/external-plugin.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { join, relative } from 'node:path'
21
import { stat as fsStat } from 'node:fs/promises'
2+
import { dirname, join, relative } from 'pathe'
33
import { createUnplugin } from 'unplugin'
44

55
import MagicString from 'magic-string'
@@ -45,16 +45,13 @@ async function fileExists(filename: string): Promise<boolean> {
4545
}
4646
}
4747

48-
function normalizePath(path: string) {
49-
return path.replace(/\\/g, '/')
50-
}
51-
5248
const isVue = createFilter(['**/*.vue'])
5349
const isFtl = createFilter(['**/*.ftl'])
5450

5551
interface Dependency {
5652
locale: string
5753
ftlPath: string
54+
relativeFtlPath: string
5855
importVariable: string
5956
}
6057

@@ -78,13 +75,15 @@ export const unplugin = createUnplugin((options: ExternalPluginOptions, meta) =>
7875
const getTranslationsForFile = async (id: string) => {
7976
const dependencies: Dependency[] = []
8077
for (const locale of options.locales) {
81-
const ftlPath = normalizePath(resolvedOptions.getFtlPath(locale, id))
78+
const ftlPath = resolvedOptions.getFtlPath(locale, id)
8279
const ftlExists = await fileExists(ftlPath)
80+
const relativeFtlPath = relative(dirname(id), ftlPath)
8381

8482
if (ftlExists) {
8583
dependencies.push({
8684
locale,
8785
ftlPath,
86+
relativeFtlPath,
8887
importVariable: `${makeLegalIdentifier(locale)}_ftl`,
8988
})
9089
}
@@ -139,7 +138,7 @@ export const unplugin = createUnplugin((options: ExternalPluginOptions, meta) =>
139138
this.addWatchFile(ftlPath)
140139

141140
for (const dep of translations)
142-
magic.prepend(`import ${dep.importVariable} from '${dep.ftlPath}';\n`)
141+
magic.prepend(`import ${dep.importVariable} from '${dep.relativeFtlPath}';\n`)
143142
magic.appendLeft(insertPos, `${target}.fluent = ${target}.fluent || {};\n`)
144143
for (const dep of translations)
145144
magic.appendLeft(insertPos, `${target}.fluent['${dep.locale}'] = ${dep.importVariable}\n`)
@@ -148,7 +147,7 @@ export const unplugin = createUnplugin((options: ExternalPluginOptions, meta) =>
148147

149148
magic.appendLeft(insertPos, `
150149
if (${__HOT_API__}) {
151-
${__HOT_API__}.accept([${translations.map(dep => `'${dep.ftlPath}'`).join(', ')}], () => {
150+
${__HOT_API__}.accept([${translations.map(dep => `'${dep.relativeFtlPath}'`).join(', ')}], () => {
152151
${translations.map(({ locale, importVariable }) => `${target}.fluent['${locale}'] = ${importVariable}`).join('\n')}
153152
154153
delete ${target}._fluent

0 commit comments

Comments
 (0)