Skip to content

Commit

Permalink
feat: detect target
Browse files Browse the repository at this point in the history
Co-authored-by: Sebasiten Chopin <seb@nuxtjs.com>
  • Loading branch information
pi0 and atinux committed Nov 6, 2020
1 parent a057776 commit ea250b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'path'
import defu from 'defu'
import { NuxtOptions } from '@nuxt/types'
import { tryImport, LIB_DIR, resolvePath } from './utils'
import { tryImport, LIB_DIR, resolvePath, detectTarget } from './utils'

export type UnresolvedPath = string | ((SLSOptions) => string)

Expand Down Expand Up @@ -57,7 +57,7 @@ export function getoptions (nuxtOptions: NuxtOptions): SLSOptions {
targetDir: null
}

let target = process.env.NUXT_SLS_TARGET || nuxtOptions.serverless.target || 'node'
let target = process.env.NUXT_SLS_TARGET || nuxtOptions.serverless.target || detectTarget()
if (typeof target === 'function') {
target = target(nuxtOptions)
}
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,17 @@ export function resolvePath (options: SLSOptions, path: UnresolvedPath, resolveB
return resolve(resolveBase, typeof path === 'string' ? path : path(options))
}

export function detectTarget () {
if (process.env.NETLIFY) {
return 'netlify'
}

if (process.env.VERCEL_URL) {
return 'vercel'
}

return 'node'
}

export const LIB_DIR = resolve(__dirname, '../lib')
export const RUNTIME_DIR = resolve(LIB_DIR, 'runtime')

0 comments on commit ea250b3

Please sign in to comment.