Skip to content

Commit 09a0598

Browse files
committed
Use relative paths for imports
1 parent dcbb418 commit 09a0598

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/plugins/external-plugin.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join, relative } from 'node:path'
1+
import { dirname, join, relative } from 'node:path'
22
import { stat as fsStat } from 'node:fs/promises'
33
import { createUnplugin } from 'unplugin'
44

@@ -55,6 +55,7 @@ const isFtl = createFilter(['**/*.ftl'])
5555
interface Dependency {
5656
locale: string
5757
ftlPath: string
58+
relativeFtlPath: string
5859
importVariable: string
5960
}
6061

@@ -80,11 +81,13 @@ export const unplugin = createUnplugin((options: ExternalPluginOptions, meta) =>
8081
for (const locale of options.locales) {
8182
const ftlPath = normalizePath(resolvedOptions.getFtlPath(locale, id))
8283
const ftlExists = await fileExists(ftlPath)
84+
const relativeFtlPath = relative(dirname(id), ftlPath)
8385

8486
if (ftlExists) {
8587
dependencies.push({
8688
locale,
8789
ftlPath,
90+
relativeFtlPath,
8891
importVariable: `${makeLegalIdentifier(locale)}_ftl`,
8992
})
9093
}
@@ -139,7 +142,7 @@ export const unplugin = createUnplugin((options: ExternalPluginOptions, meta) =>
139142
this.addWatchFile(ftlPath)
140143

141144
for (const dep of translations)
142-
magic.prepend(`import ${dep.importVariable} from '${dep.ftlPath}';\n`)
145+
magic.prepend(`import ${dep.importVariable} from '${dep.relativeFtlPath}';\n`)
143146
magic.appendLeft(insertPos, `${target}.fluent = ${target}.fluent || {};\n`)
144147
for (const dep of translations)
145148
magic.appendLeft(insertPos, `${target}.fluent['${dep.locale}'] = ${dep.importVariable}\n`)
@@ -148,7 +151,7 @@ export const unplugin = createUnplugin((options: ExternalPluginOptions, meta) =>
148151

149152
magic.appendLeft(insertPos, `
150153
if (${__HOT_API__}) {
151-
${__HOT_API__}.accept([${translations.map(dep => `'${dep.ftlPath}'`).join(', ')}], () => {
154+
${__HOT_API__}.accept([${translations.map(dep => `'${dep.relativeFtlPath}'`).join(', ')}], () => {
152155
${translations.map(({ locale, importVariable }) => `${target}.fluent['${locale}'] = ${importVariable}`).join('\n')}
153156
154157
delete ${target}._fluent

0 commit comments

Comments
 (0)