nwutils/nw-builder

Validation of package.json failing

dominickbrasileiro opened this issue · 0 comments

Issue Type

  • Bug Fix
  • Feature
  • Other

Current/Missing Behaviour

The nw-builder CLI throws an error when reading the properties from a package.json:
image

This error is caused by the validation logic in src/nwbuild.js:130:

// If the nwbuild property exists in srcDir/package.json, then they take precedence
if (typeof nwPkg.nwbuild === "object") {
  options = { ...nwPkg.nwbuild };
}
if (typeof nwPkg.nwbuild === "undefined") {
  log.debug(`nwbuild property is not defined in package.json`);
} else {
  throw new Error(
    `nwbuild property in the package.json is of type ${typeof nwPkg.nwbuild}. Expected type object.`,
  );
}

If typeof nwPkg.nwbuild is equal to "object", the options will be parsed and the error will be thrown.

Expected/Proposed Behaviour

Fix the logic to stop the validation if any of the requirements is met:

// If the nwbuild property exists in srcDir/package.json, then they take precedence
if (typeof nwPkg.nwbuild === "object") {
  options = { ...nwPkg.nwbuild };
} else if (typeof nwPkg.nwbuild === "undefined") {
  log.debug(`nwbuild property is not defined in package.json`);
} else {
  throw new Error(
    `nwbuild property in the package.json is of type ${typeof nwPkg.nwbuild}. Expected type object.`,
  );
}

Additional Info

  • Operating System: Ubuntu 22.04
  • Node version: v18.13.0
  • NW.js version: 4.0.6