facebook / fbjs

A collection of utility libraries used by other Meta JS projects.
MIT License
1.95k stars 313 forks source link

'instrument' required, then optional? Resulting in `TypeError: Cannot destructure property 'instrument' of 'options' as it is undefined.` #460

Closed DonBranson closed 3 years ago

DonBranson commented 3 years ago

This is for fbjs-scripts 3.0.0

https://github.com/facebook/fbjs/blob/d8f0f430a689ee1e5bb070d501155fa29e329019/packages/fbjs-scripts/jest/createCacheKeyFunction.js#L35 https://github.com/facebook/fbjs/blob/d8f0f430a689ee1e5bb070d501155fa29e329019/packages/fbjs-scripts/jest/createCacheKeyFunction.js#L46

I have a question about this code, since we're failing on const {instrument, config} = options; because instrument does not exist in options. However, are we not expecting instrument could be missing in .update(instrument ? 'instrument' : '')? If so, could it be optional when destructered from options? We've been looking for a workaround, but nothing works yet.

  return (src, file, configString, options) => {
    const {instrument, config} = options;
    const rootDir = config && config.rootDir;

    return crypto
      .createHash('md5')
      .update(globalCacheKey)
      .update('\0', 'utf8')
      .update(src)
      .update('\0', 'utf8')
      .update(rootDir ? path.relative(config.rootDir, file) : '')
      .update('\0', 'utf8')
      .update(instrument ? 'instrument' : '')
      .digest('hex');
  };
}