chore: Fix installing from GitHub URL #5669
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The change to the install script to require TypeScript works fine when
installing from npm (because on npm the
lib
directory with thecompiled code already exists) but doesn't if you install from a GitHub
URL. By default it seems npm uses the
files
list when you install fromGitHub which means it's missing a bunch of files that we need to
compile.
Additionally by default when installing from a GitHub URL npm doesn't
install the dependencies which is an issue for us when we need to
compile TypeScript.
The fix is to create a
prepare
script that runs TypeScript ifrequired. From the npm docs 1:
And from the npm docs on install 2, it confirms that if a package has
a
prepare
script it is run when installing from GitHub:Despite having the
prepare
script we still need the TypeScript checkin
install.js
to satisfy the 3rd scenario below where we need to forcea compile:
puppeteer@X
from npm, the module ispublished with the
lib/
directory of compiled code, so I'm set.prepare
scriptwill run TypeScript for me so I'm set.
prepare
script alsoruns but after
npm install
which meansinstall.js
fails as itrequires
./lib/helper.js
. So ininstall.js
we callcompileTypeScriptIfRequired
to catch this case.Fixes #5660.