Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prepare hook to run build when installed as git dependency directly #467

Merged
merged 1 commit into from
Jun 23, 2024

Conversation

kindjie
Copy link
Contributor

@kindjie kindjie commented Jun 22, 2024

Issue

Currently, adding chess.js as a dependency from npm works without issue, i.e. npm install chess.js. However, adding it as a git or Github dependency directly using npm install github:jhlywa/chess.js (or similar) will cause an import error.

Installing the dependency from a git repo directly is required to use commits after the most recent npm published version.

Cause

For example, Vite may give: Failed to resolve entry for package "chess.js". The package may have incorrect main/module/exports specified in its package.json.
This occurs because the chess.js package.json specifies paths in the dist directory that doesn't exist until npm run build is done.

Solution

This PR adds a prepare hook that triggers npm run build in the following cases:

prepare (since [email protected])

  • Runs BEFORE the package is packed, i.e. during npm publish and npm pack
  • Runs on local npm install without any arguments
  • Runs AFTER prepublish, but BEFORE prepublishOnly
  • NOTE: If a package being installed through git contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed.
  • As of npm@7 these scripts run in the background. To see the output, run with: --foreground-scripts.

See: npm CLI life cycle scripts documentation.

This is a tiny change to package.json.

@kindjie kindjie changed the title Add prepare hook to run build when installed as git depedency directly Add prepare hook to run build when installed as git dependency directly Jun 22, 2024
@jhlywa jhlywa merged commit 56ed974 into jhlywa:master Jun 23, 2024
3 checks passed
@jhlywa
Copy link
Owner

jhlywa commented Jun 23, 2024

Thanks for the PR!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants