fix: add more types (#16)

This commit is contained in:
Daniel Roe 2020-11-08 23:19:23 +00:00 committed by GitHub
parent 799e872b80
commit fc0934dd0c
3 changed files with 14 additions and 6 deletions

View File

@ -5,7 +5,8 @@ import Hookable, { configHooksT } from 'hookable'
import { tryImport, resolvePath, detectTarget, extendTarget } from './utils'
import * as TARGETS from './targets'
export type UnresolvedPath = string | ((SLSOptions) => string)
// eslint-disable-next-line
export type UnresolvedPath = string | ((config: SLSOptions) => string)
export interface Nuxt extends Hookable{
options: NuxtOptions
@ -45,17 +46,24 @@ export interface SLSConfig extends Omit<Partial<SLSOptions>, 'targetDir'> {
targetDir?: UnresolvedPath
}
export type SLSTargetFn = (SLSConfig) => SLSConfig
export type SLSTargetFn = (config: SLSConfig) => SLSConfig
export type SLSTarget = SLSConfig | SLSTargetFn
export function getoptions (nuxt: Nuxt): SLSOptions {
interface SLSNuxt extends Nuxt {
options: Nuxt['options'] & {
generate: Nuxt['options']['generate'] & {
staticAssets: string[]
}
}
}
export function getoptions (nuxt: SLSNuxt): SLSOptions {
const defaults: SLSConfig = {
rootDir: nuxt.options.rootDir,
buildDir: nuxt.options.buildDir,
publicDir: nuxt.options.generate.dir,
routerBase: nuxt.options.router.base,
fullStatic: nuxt.options.target === 'static' && !nuxt.options._legacyGenerate,
// @ts-ignore
staticAssets: nuxt.options.generate.staticAssets,
outName: '_nuxt.js',

View File

@ -30,7 +30,7 @@ export default <Module> function slsModule () {
nuxt.addHooks(options.nuxtHooks)
}
nuxt.hook('generate:cache:ignore', (ignore) => {
nuxt.hook('generate:cache:ignore', (ignore: string[]) => {
ignore.push(options.slsDir)
ignore.push(options.targetDir)
ignore.push(...options.generateIgnore)

View File

@ -23,7 +23,7 @@ export function serializeTemplate (contents: string) {
return `export default (params) => \`${contents.replace(/{{ (\w+) }}/g, '${params.$1}')}\``
}
export async function writeFileP (path, contents) {
export async function writeFileP (path: string, contents: string) {
await mkdirp(dirname(path))
await writeFile(path, contents)
}