google/tachometer

Issues getting metrics to run.

Westbrook opened this issue · 5 comments

I've previously used Tachometer on my component library with code inspired heavily by that found in the Material Web Components project and had no trouble getting the packages to install, build or load. When recently working to update to v0.5.1, when attempting to run tests I get the following dump:

/Users/westbrook/Documents/web/repos/swc/node_modules/tachometer/node_modules/typescript/lib/typescript.js:19871
            var sourceFile = new SourceFileConstructor(290 /* SourceFile */, /*pos*/ 0, /* end */ sourceText.length);
                                                                                                             ^

TypeError: Cannot read property 'length' of undefined
    at createSourceFile (/Users/westbrook/Documents/web/repos/swc/node_modules/tachometer/node_modules/typescript/lib/typescript.js:19871:110)
    at Object.parseJsonText (/Users/westbrook/Documents/web/repos/swc/node_modules/tachometer/node_modules/typescript/lib/typescript.js:19709:26)
    at Object.parseJsonText (/Users/westbrook/Documents/web/repos/swc/node_modules/tachometer/node_modules/typescript/lib/typescript.js:19530:23)
    at Object.parseConfigFileTextToJson (/Users/westbrook/Documents/web/repos/swc/node_modules/tachometer/node_modules/typescript/lib/typescript.js:27974:33)
    at programFromConfig (/Users/westbrook/Documents/web/repos/swc/node_modules/tachometer/node_modules/typescript-json-schema/dist/typescript-json-schema.js:1063:21)
    at Object.exec (/Users/westbrook/Documents/web/repos/swc/node_modules/tachometer/node_modules/typescript-json-schema/dist/typescript-json-schema.js:1098:19)
    at Object.run (/Users/westbrook/Documents/web/repos/swc/node_modules/tachometer/node_modules/typescript-json-schema/dist/typescript-json-schema-cli.js:50:30)
    at Object.<anonymous> (/Users/westbrook/Documents/web/repos/swc/node_modules/tachometer/node_modules/typescript-json-schema/bin/typescript-json-schema:3:5)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tachometer@0.5.1 generate-json-schema: `typescript-json-schema tsconfig.json ConfigFile --include src/configfile.ts --required --noExtraProps > config.schema.json`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the tachometer@0.5.1 generate-json-schema script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/westbrook/.npm/_logs/2020-09-01T00_57_58_773Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tachometer@0.5.1 build: `rimraf lib/ client/lib/ && mkdir lib && npm run generate-json-schema && tsc && tsc -p client/ && npm run lint`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the tachometer@0.5.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/westbrook/.npm/_logs/2020-09-01T00_57_58_788Z-debug.log
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Error: Command failed: yarn add chromedriver@*
    at makeError (/Users/westbrook/Documents/web/repos/swc/node_modules/execa/index.js:174:9)
    at /Users/westbrook/Documents/web/repos/swc/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 1,
  stdout: null,
  stderr: null,
  failed: true,
  signal: null,
  cmd: 'yarn add chromedriver@*',
  timedOut: false,
  killed: false
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I have no problem running tests when reverting to v0.4.2 and am not sure whether there is something that I need to do locally to get the newest version working.

cdata commented

Hey @Westbrook thanks for reporting this. I'm investigating the issue now. I can tell you from a glance that it is related to a change we made to how some packages are installed in #177 . Specifically, it seems to be an unanticipated side-effect of how the yarn package manager performs installation for single packages.

Given Yarn's emphasis on reproducible builds, it makes sense that they would run package scripts even when we only wish to install a single package. However, this is an undesirable trait for the on-demand package installation we are trying to perform. I'll update this thread as I learn more.

cdata commented

I have done some investigation into this issue today. It seems as though the core issue is that yarn will invoke the prepare NPM script when installing a packed package, even though NPM does not. Per the NPM docs on the install command, the prepare script is only run for the package being installed when it is installed from a Git repository: https://docs.npmjs.com/cli/install. The difference in behavior between Yarn and NPM here has been confirmed empirically.

I have a workaround for this problem in my local environment. In the workaround, I modified the prepare script to detect if NPM is the package manager being used to install before running the build script.

This workaround seems to address the issue: since we use NPM for development of tachometer, the scripts should always run when intended; npm does not run the prepare script when the packed package is installed; the script will be skipped when installed using yarn by a package consumer, emulating NPM behavior.

But, it also has at least one significant shortcoming: the build script still needs to be run when a consumer installs from a Git repository via Yarn, and the current workaround will prevent that from happening.

@aomarks I would be interested to hear your thoughts on this issue if you have any.

Thanks for getting into this @cdata! Is the single package install a specific script that could leverage --ignore-scripts to prevent this? Also, could you point to the command that does this in the project? I could look at work arounds (manual and otherwise) in the interim.

A quick fix that should work is to install chromedriver as your own dependency. That way the auto-install logic won't trigger.

@Westbrook cdata's fix is released in v0.5.2