Skip to content

build bundle.js #147

@stevan-krstic

Description

@stevan-krstic

When creating a bundle.js, the current code requires a package.json file to be present in one of the candidate paths. If no package.json is found, it throws an error.

However, in some bundling scenarios, only the bundle.js file exists and there is no package.json. In these cases, it would be better if the code handled the missing package.json gracefully by setting the npmPackage to an empty object instead of throwing an error.

This improvement would allow bundling without requiring a package.json file, which is a common scenario.

Line 169:
var npmPackage
var base
for (var i in candidatePackagePaths) {
try {
base = candidatePackagePaths[i]

  npmPackage = require(nodePath.join(base, 'package.json'))
  break
} catch (e) {
  // noop
}

}

This causes a problem after the build. When running node bundle.js, it throws an error. Instead of creating an empty package.json with an empty object, we can remove the error or just console.warn instead fo throw error.
if (typeof npmPackage !== 'object') {
var pathString = candidatePackagePaths.join(',\n')
throw new Error('Unable to find package.json in any of:\n[' + pathString + ']')
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions