Skip to content

Commit b8522b6

Browse files
committed
fix: error on missing entry
closes nexe#467 closes nexe#464
1 parent d6d81b9 commit b8522b6

File tree

10 files changed

+203
-229
lines changed

10 files changed

+203
-229
lines changed

package-lock.json

Lines changed: 163 additions & 181 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@
4848
},
4949
"devDependencies": {
5050
"@types/chai": "^4.1.2",
51-
"@types/execa": "^0.8.1",
51+
"@types/execa": "^0.9.0",
5252
"@types/globby": "^6.1.0",
5353
"@types/minimist": "^1.2.0",
5454
"@types/mkdirp": "^0.5.2",
5555
"@types/mocha": "^2.2.48",
56-
"@types/ora": "^1.3.1",
57-
"@types/pify": "3.0.0",
56+
"@types/ora": "^1.3.3",
57+
"@types/pify": "3.0.1",
5858
"@types/rimraf": "2.0.2",
5959
"chai": "^4.1.2",
60-
"execa": "^0.9.0",
61-
"mocha": "^5.0.0",
62-
"prettier": "^1.10.2",
63-
"ts-node": "4.1.0",
60+
"execa": "^0.10.0",
61+
"mocha": "^5.0.4",
62+
"prettier": "^1.11.1",
63+
"ts-node": "5.0.1",
6464
"tslint": "^5.9.1",
65-
"tslint-config-prettier": "^1.7.0",
65+
"tslint-config-prettier": "^1.10.0",
6666
"tslint-plugin-prettier": "^1.3.0",
67-
"typescript": "2.7.1"
67+
"typescript": "2.7.2"
6868
}
6969
}

src/options.ts

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { isWindows, padRight } from './util'
44
import { basename, extname, join, isAbsolute, relative, dirname, resolve } from 'path'
55
import { getTarget, NexeTarget } from './target'
66
import { EOL, homedir } from 'os'
7-
import c from 'chalk'
7+
import chalk from 'chalk'
8+
import { resolveFileName } from 'resolve-dependencies'
89
const caw = require('caw')
10+
const c = process.platform === 'win32' ? chalk.constructor({ enabled: false }) : chalk
911

1012
export const version = '{{replace:0}}'
1113

@@ -150,16 +152,6 @@ function extractCliMap(match: RegExp, options: any) {
150152
)
151153
}
152154

153-
function tryResolveMainFileName(cwd: string) {
154-
let filename
155-
try {
156-
const file = require.resolve(cwd)
157-
filename = basename(file).replace(extname(file), '')
158-
} catch (_) {}
159-
160-
return filename ? filename : 'nexe_' + Date.now()
161-
}
162-
163155
function extractLogLevel(options: NexeOptions) {
164156
if (options.loglevel) return options.loglevel
165157
if (options.silent) return 'silent'
@@ -173,14 +165,11 @@ function isName(name: string) {
173165

174166
function extractName(options: NexeOptions) {
175167
let name = options.name
168+
//try and use the input filename as the output filename if its not index
176169
if (!isName(name) && typeof options.input === 'string') {
177170
name = basename(options.input).replace(extname(options.input), '')
178171
}
179-
180-
if (!isName(name)) {
181-
name = tryResolveMainFileName(options.cwd)
182-
}
183-
172+
//try and use the directory as the filename
184173
if (!isName(name) && basename(options.cwd)) {
185174
name = basename(options.cwd)
186175
}
@@ -189,29 +178,31 @@ function extractName(options: NexeOptions) {
189178
}
190179

191180
function isEntryFile(filename?: string): filename is string {
192-
return Boolean(
193-
filename && !isAbsolute(filename) && filename !== 'node' && /\.(tsx?|jsx?)$/.test(filename)
194-
)
181+
return Boolean(filename && !isAbsolute(filename))
195182
}
196183

197184
export function resolveEntry(input: string, cwd: string, maybeEntry?: string) {
198185
if (input === '-' || maybeEntry === '-') {
199186
return ''
200187
}
188+
let result = null
201189
if (input) {
202-
return resolve(cwd, input)
190+
result = resolveFileName(cwd, input, { silent: true })
203191
}
204192
if (isEntryFile(maybeEntry)) {
205-
return resolve(cwd, maybeEntry)
193+
result = resolveFileName(cwd, maybeEntry, { silent: true })
206194
}
207195
if (!process.stdin.isTTY) {
208196
return ''
209197
}
210-
try {
211-
return require.resolve(cwd)
212-
} catch (e) {
213-
throw new Error('No entry file found')
198+
199+
if (!result || !result.absPath) {
200+
result = resolveFileName(cwd, '.', { silent: true })
214201
}
202+
203+
if (!result.absPath) throw new Error(`Entry file "${input}" not found!`)
204+
205+
return result.absPath
215206
}
216207

217208
function isCli(options?: Partial<NexeOptions>) {

src/patches/snapshot.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ export default async function snapshot(compiler: NexeCompiler, next: () => Promi
1111
await compiler.replaceInFileAsync(
1212
'configure',
1313
'def configure_v8(o):',
14-
`def configure_v8(o):\n o['variables']['embed_script'] = '${
15-
snapshotFile
16-
}'\n o['variables']['warmup_script'] = '${warmupScript || snapshotFile}'`
14+
`def configure_v8(o):\n o['variables']['embed_script'] = '${snapshotFile}'\n o['variables']['warmup_script'] = '${warmupScript ||
15+
snapshotFile}'`
1716
)
1817

1918
return next()

tasks/ci.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const { env } = process
66

77
export function triggerMacBuild(release: NexeTarget, branch: string) {
88
assert.ok(env.CIRCLE_TOKEN)
9-
const circle = `https://circleci.com/api/v1.1/project/github/nexe/nexe/tree/${
10-
branch
11-
}?circle-token=${env.CIRCLE_TOKEN}`
9+
const circle = `https://circleci.com/api/v1.1/project/github/nexe/nexe/tree/${branch}?circle-token=${
10+
env.CIRCLE_TOKEN
11+
}`
1212
return got(circle, {
1313
json: true,
1414
body: {

test/fixture/dependency.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'abc'

test/fixture/entry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('hello world', require('./dependency'))

test/fixture/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"main": "entry-file.js"
2+
"main": "entry.js"
33
}

test/options.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ describe('options', () => {
1515
expect(options.input).to.equal(path.resolve('./index.js'))
1616
})
1717
it('should resolve pathed options against cwd', () => {
18-
const cwd = '/a/b/c'
18+
const cwd = path.join(process.cwd(), 'test/fixture')
1919
const options = normalizeOptions({
2020
cwd,
21-
input: '123.js',
21+
input: 'entry',
2222
output: 'abc',
2323
temp: './d'
2424
})
2525
expect(options.temp).to.equal(path.resolve(cwd, './d'))
26-
expect(options.input).to.equal(path.resolve(cwd, '123.js'))
26+
expect(options.input).to.equal(path.resolve(cwd, 'entry.js'))
2727
expect(options.output).to.equal(path.resolve(cwd, `abc${ext}`))
2828
})
2929
})
@@ -36,9 +36,9 @@ describe('options', () => {
3636
})
3737
it('should default to the input file name if not index', () => {
3838
const options = normalizeOptions({
39-
input: 'src/folder/app.js'
39+
input: './test/fixture'
4040
})
41-
expect(options.output).to.equal(path.resolve(`./app${ext}`))
41+
expect(options.output).to.equal(path.resolve(`./entry${ext}`))
4242
})
4343
it('should default to the folder/project name if filename is index', () => {
4444
const options = normalizeOptions()

test/target.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { padRight, isWindows } from '../src/util'
22
import { expect } from 'chai'
3-
import { blue as b } from 'chalk'
3+
import chalk from 'chalk'
44
import { getTarget, NexeTarget } from '../src/target'
5-
5+
const b = chalk.blue
66
const arch = process.arch === 'ia32' ? 'x86' : process.arch
77

88
describe('Targets', () => {

0 commit comments

Comments
 (0)