Skip to content
This repository was archived by the owner on Sep 17, 2022. It is now read-only.

Commit 9ebb853

Browse files
committed
Fix finding insert position script setup files
1 parent acd1810 commit 9ebb853

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/index.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function getInsertInfo(source: string): InsertInfo {
3535
vue = 2
3636
}
3737
else {
38-
insertPos = source.indexOf('script.render = render')
38+
insertPos = source.indexOf('script.__file')
3939
vue = 3
4040
}
4141

@@ -56,11 +56,17 @@ export default function fluentPlugin({ blockType = 'fluent', external }: PluginO
5656
},
5757
async load(id) {
5858
if (id.endsWith('.ftl')) {
59-
const ftl = await fs.readFile(id, 'utf8')
60-
return `
59+
try {
60+
const ftl = await fs.readFile(id, 'utf8')
61+
return `
6162
import { FluentResource } from '@fluent/bundle'
6263
export default new FluentResource(${JSON.stringify(ftl)})
6364
`
65+
}
66+
catch (e) {
67+
this.warn(`Missing ftl file: ${id}`)
68+
return 'export default null'
69+
}
6470
}
6571
},
6672
async transform(code, id) {
@@ -79,7 +85,7 @@ export default new FluentResource(${JSON.stringify(ftl)})
7985
magic.prepend('import { FluentResource } from \'@fluent/bundle\';\n')
8086

8187
const { insertPos, target } = getInsertInfo(code)
82-
magic.appendLeft(insertPos - 1, `${target}.fluent = { ${external.locales.map(locale => `${locale}: ${locale}_ftl`).join(', ')} }`)
88+
magic.appendLeft(insertPos, `${target}.fluent = { ${external.locales.map(locale => `${locale}: ${locale}_ftl`).join(', ')} };\n`)
8389

8490
return {
8591
code: magic.toString(),

0 commit comments

Comments
 (0)