fix(tauri.js) do not swallow init errors, fix conf inject (#802)

* fix(tauri.js) do not swallow init errors, fix conf inject

* fix(tauri.js) tests
This commit is contained in:
Lucas Fernandes Nogueira 2020-07-10 11:41:31 -03:00 committed by GitHub
parent a26cffc575
commit f208a68e40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 35 deletions

View File

@ -0,0 +1,5 @@
---
"tauri.js": patch
---
Fixes `tauri init` not generating `tauri.conf.json` on the Vue CLI Plugin.

View File

@ -18,6 +18,10 @@ interface InjectOptions {
} }
type InjectionType = 'conf' | 'template' | 'all' type InjectionType = 'conf' | 'template' | 'all'
interface UnknownObject {
[index: string]: any
}
const injectConfFile = ( const injectConfFile = (
injectPath: string, injectPath: string,
{ force, logging }: InjectOptions, { force, logging }: InjectOptions,
@ -29,27 +33,22 @@ const injectConfFile = (
Run \`tauri init --force conf\` to overwrite.`) Run \`tauri init --force conf\` to overwrite.`)
if (!force) return false if (!force) return false
} else { } else {
try { removeSync(path)
removeSync(path) Object.keys(defaultConfig).forEach(key => {
const finalConf = merge(defaultConfig as any, customConfig as any) as { // Options marked `null` should be removed
[index: string]: any /* eslint-disable security/detect-object-injection */
if ((customConfig as UnknownObject)[key] === null) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete (defaultConfig as UnknownObject)[key]
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete (customConfig as UnknownObject)[key]
} }
Object.keys(finalConf).forEach(key => { /* eslint-enable security/detect-object-injection */
// Options marked `null` should be removed })
/* eslint-disable security/detect-object-injection */ const finalConf = merge(defaultConfig as any, customConfig as any) as UnknownObject
if (finalConf[key] === null) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete writeFileSync(path, JSON.stringify(finalConf, undefined, 2))
delete finalConf[key] if (logging) log('Successfully wrote tauri.conf.json')
}
/* eslint-enable security/detect-object-injection */
})
writeFileSync(path, JSON.stringify(finalConf, undefined, 2))
} catch (e) {
if (logging) console.log(e)
return false
} finally {
if (logging) log('Successfully wrote tauri.conf.json')
}
} }
} }
@ -82,21 +81,15 @@ Run \`tauri init --force template\` to overwrite.`)
? `{ path = "${resolveTauriPath(tauriPath)}" }` ? `{ path = "${resolveTauriPath(tauriPath)}" }`
: `{ version = "${resolveCurrentTauriVersion()}" }` : `{ version = "${resolveCurrentTauriVersion()}" }`
try { removeSync(dir)
removeSync(dir) copyTemplates({
copyTemplates({ source: resolve(__dirname, '../../templates/src-tauri'),
source: resolve(__dirname, '../../templates/src-tauri'), scope: {
scope: { tauriDep
tauriDep },
}, target: dir
target: dir })
}) if (logging) log('Successfully wrote src-tauri')
} catch (e) {
if (logging) console.log(e)
return false
} finally {
if (logging) log('Successfully wrote src-tauri')
}
} }
const inject = ( const inject = (

View File

@ -27,7 +27,9 @@ describe('[CLI] tauri.js', () => {
it('will pass on an available command', async () => { it('will pass on an available command', async () => {
jest.spyOn(console, 'log') jest.spyOn(console, 'log')
jest.mock('fs') jest.mock('fs')
try {
tauri('init') tauri('init')
} catch {}
expect(console.log.mock.calls[0][0].split('.')[0]).toBe('[tauri]: running init') expect(console.log.mock.calls[0][0].split('.')[0]).toBe('[tauri]: running init')
jest.clearAllMocks() jest.clearAllMocks()
}) })