* chore: reformat code
* refactor: getOrCreateArchive() for ASARs
- store cached archive in a Map
- return `null` instead of `false` on failures
* refactor: splitPath() for ASARs
- store custom extension in a constant
- remove magic numbers
- add comments
* refactor: explicitly use assert() for a developer error
* chore: remove console.log() calls
* refactor: replace "p" arguments with "pathArgument"
"path" would be a better name, but it is already taken
but the "path" Node module.
* refactor: createError() for ASARs
- return an `Error` instance
- use enum for error types
- minor improvements
* refactor: use more meaningful name for an arg than just "arg"
due to change in node.js(https://github.com/nodejs/node/issues/17076)
internalModuleReadFile has been renamed to internalModuleReadJSON, and
in vendor/node/lib/internal/modules/cjs/loader.js it will call
internalModuleReadJSON and result in can't read the package.json file.
NodeJS implements `child_process.exec` by simply passing the whole
command to `child_process.execFile`. See:
- https://github.com/nodejs/node/blob/master/lib/child_process.js#L90
- https://github.com/nodejs/node/blob/master/lib/child_process.js#L99
Electron patches `child_process.execFile` to add support for `asar`
archives by injecting logic that extracts the required files from the
`asar` to a temporary location before delegating the work to the
original `child_process.execFile`.
In order to decide whether to inject the custom `asar` extracting logic,
Electron makes use of a helper function called `splitPath()`. See:
- https://github.com/electron/electron/blob/master/lib/common/asar.js#L37
If the first argument of the returned array equals `true`, means that
the path is considered to be an `asar` archive, and thus the extraction
logic takes place. The problem is that if the command passed to
`child_process.execFile` *contains* a path to an asar archive, padded
with other commands/arguments, `splitPath()` will consider it to be an
`asar` archive, and will try to extract it, throwing a rightfully
`Invalid package` error.
Fixes: https://github.com/electron/electron/issues/5571
Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>