fix: error on missing entry

closes #467

closes #464
This commit is contained in:
calebboyd
2018-03-18 16:59:26 -05:00
committed by Caleb Boyd
parent d6d81b9e23
commit b8522b6310
10 changed files with 203 additions and 229 deletions
+16 -25
View File
@@ -4,8 +4,10 @@ import { isWindows, padRight } from './util'
import { basename, extname, join, isAbsolute, relative, dirname, resolve } from 'path'
import { getTarget, NexeTarget } from './target'
import { EOL, homedir } from 'os'
import c from 'chalk'
import chalk from 'chalk'
import { resolveFileName } from 'resolve-dependencies'
const caw = require('caw')
const c = process.platform === 'win32' ? chalk.constructor({ enabled: false }) : chalk
export const version = '{{replace:0}}'
@@ -150,16 +152,6 @@ function extractCliMap(match: RegExp, options: any) {
)
}
function tryResolveMainFileName(cwd: string) {
let filename
try {
const file = require.resolve(cwd)
filename = basename(file).replace(extname(file), '')
} catch (_) {}
return filename ? filename : 'nexe_' + Date.now()
}
function extractLogLevel(options: NexeOptions) {
if (options.loglevel) return options.loglevel
if (options.silent) return 'silent'
@@ -173,14 +165,11 @@ function isName(name: string) {
function extractName(options: NexeOptions) {
let name = options.name
//try and use the input filename as the output filename if its not index
if (!isName(name) && typeof options.input === 'string') {
name = basename(options.input).replace(extname(options.input), '')
}
if (!isName(name)) {
name = tryResolveMainFileName(options.cwd)
}
//try and use the directory as the filename
if (!isName(name) && basename(options.cwd)) {
name = basename(options.cwd)
}
@@ -189,29 +178,31 @@ function extractName(options: NexeOptions) {
}
function isEntryFile(filename?: string): filename is string {
return Boolean(
filename && !isAbsolute(filename) && filename !== 'node' && /\.(tsx?|jsx?)$/.test(filename)
)
return Boolean(filename && !isAbsolute(filename))
}
export function resolveEntry(input: string, cwd: string, maybeEntry?: string) {
if (input === '-' || maybeEntry === '-') {
return ''
}
let result = null
if (input) {
return resolve(cwd, input)
result = resolveFileName(cwd, input, { silent: true })
}
if (isEntryFile(maybeEntry)) {
return resolve(cwd, maybeEntry)
result = resolveFileName(cwd, maybeEntry, { silent: true })
}
if (!process.stdin.isTTY) {
return ''
}
try {
return require.resolve(cwd)
} catch (e) {
throw new Error('No entry file found')
if (!result || !result.absPath) {
result = resolveFileName(cwd, '.', { silent: true })
}
if (!result.absPath) throw new Error(`Entry file "${input}" not found!`)
return result.absPath
}
function isCli(options?: Partial<NexeOptions>) {
+2 -3
View File
@@ -11,9 +11,8 @@ export default async function snapshot(compiler: NexeCompiler, next: () => Promi
await compiler.replaceInFileAsync(
'configure',
'def configure_v8(o):',
`def configure_v8(o):\n o['variables']['embed_script'] = '${
snapshotFile
}'\n o['variables']['warmup_script'] = '${warmupScript || snapshotFile}'`
`def configure_v8(o):\n o['variables']['embed_script'] = '${snapshotFile}'\n o['variables']['warmup_script'] = '${warmupScript ||
snapshotFile}'`
)
return next()