iohook icon indicating copy to clipboard operation
iohook copied to clipboard

Not working with pnpm

Open vjpr opened this issue 4 years ago • 3 comments

pnpm rebuild --reporter=ndjson
  let mainPath = Array(attempts).join("../");
  try {
    const content = fs.readFileSync(path.join(__dirname, mainPath, 'package.json'), 'utf-8');
    const packageJson = JSON.parse(content);
    const opts = packageJson.iohook || {};
    if (!opts.targets) {
      opts.targets = []
    }
    if (!opts.platforms) opts.platforms = [process.platform];
    if (!opts.arches) opts.arches = [process.arch];
    return opts
  } catch (e) {
    return optionsFromPackage(attempts + 1);
  }

Expected Behavior

Should find package.json config properly.

Current Behavior

{"time":1607995718300,"hostname":"VMBP2019.fritz.box","pid":54464,"level":"debug","name":"pnpm:lifecycle","depPath":"/iohook/0.7.2","line":"Can't resolve main package.json file","stage":"install","stdio":"stdout","wd":"/Users/Vaughan/dev-mono/thirtyfive/node_modules/.pnpm/[email protected]/node_modules/iohook"}

Possible Solution

For mainPath use require.main.

Steps to Reproduce (for bugs)

pnpm rebuild --reporter=ndjson

Workaround

Use env vars:

const options = optionsFromPackage();
if (process.env.npm_config_targets) {
  options.targets = options.targets.concat(process.env.npm_config_targets.split(','));
}
options.targets = options.targets.map(targetStr => targetStr.split('-'));
if (process.env.npm_config_targets === 'all') {
  options.targets = supportedTargets.map(arr => [arr[0], arr[2]]);
  options.platforms = ['win32', 'darwin', 'linux'];
  options.arches = ['x64', 'ia32']
}
if (process.env.npm_config_platforms) {
  options.platforms = options.platforms.concat(process.env.npm_config_platforms.split(','));
}
if (process.env.npm_config_arches) {
  options.arches = options.arches.concat(process.env.npm_config_arches.split(','));
}

Add to .npmrc:

# For iohook
targets=electron-85

vjpr avatar Dec 15 '20 01:12 vjpr

Closing as irrelevant, as in not something I think anyone is interested in addressing. If anyone is interested please feel free to reopen and PR.

ash0x0 avatar Jun 11 '21 20:06 ash0x0

It would be better to say "closed due to inactivity".

vjpr avatar Jun 11 '21 21:06 vjpr

It would be better to say "closed due to inactivity".

@vjpr True :sweat_smile: Though the inactivity isn't odd. It's a niche issue so I didn't think anyone would be interested, didn't mean that it's not important :smile: While I have you here, are there issues with the workaround you posted? If this workaround is an ok way to do it with pnpm then I'll include it in docs, if it requires a fix and it's something we can feasibly knock down in a couple of hours then I can add it to todo list.

ash0x0 avatar Jun 11 '21 21:06 ash0x0