Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Extract the code that resolves paths to look at
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Jul 28, 2019
1 parent 53d2c3d commit a8a39fc
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,37 +183,48 @@ function isNotRelative (file) {
return isRelative(file) && file[0] !== '.'
}

function parse (opts) {
function resolveDefaultEntriesPaths (opts) {
const pkgPath = opts.path
const pkgDir = path.dirname(pkgPath)
const pkg = opts.package
const extensions = opts.extensions

const deps = {}
const seen = []
const core = []
const mainPath = path.resolve(pkg.main || path.join(path.dirname(pkgPath), 'index.js'))
const mainPath = path.resolve(pkg.main || path.join(pkgDir, 'index.js'))

let paths = []

if (!opts.noDefaultEntries && fs.existsSync(mainPath)) paths.push(mainPath)
// Add the path of the main file
if (fs.existsSync(mainPath)) paths.push(mainPath)

if (!opts.noDefaultEntries && pkg.bin) {
// Add the path of binaries
if (pkg.bin) {
if (typeof pkg.bin === 'string') {
paths.push(path.resolve(path.join(path.dirname(pkgPath), pkg.bin)))
} else {
Object.keys(pkg.bin).forEach(cmdName => {
const cmd = pkg.bin[cmdName]
paths.push(path.resolve(path.join(path.dirname(pkgPath), cmd)))
paths.push(path.resolve(path.join(pkgDir, cmd)))
})
}
}

// pass in custom additional entries e.g. ['./test.js']
if (opts.entries) {
paths = paths.concat(
resolveGlobbedPath(opts.entries, path.dirname(pkgPath))
)
}
return paths
}

function resolvePaths (opts) {
return [
...(!opts.noDefaultEntries ? resolveDefaultEntriesPaths(opts) : []),
...(opts.entries ? resolveGlobbedPath(opts.entries, path.dirname(opts.path)) : [])
]
}

function parse (opts) {
const pkg = opts.package
const extensions = opts.extensions

const deps = {}
const seen = []
const core = []

const paths = resolvePaths(opts)

debug('entry paths', paths)

Expand Down

0 comments on commit a8a39fc

Please sign in to comment.