build: use npm prepare instead of prepublishOnly#1533
Merged
ferdikoomen merged 1 commit intoJul 5, 2023
Merged
Conversation
In NPM, the `prepublishOnly` script is run only before running `npm publish`. However, this means that people trying to use the git version of of this project (i.e. with `npm install ferdikoomen/openapi-typescript-codegen`) won't get a working version of this project, since there will be nothing in the `dist/` folder. [NPM (since v4.0.0)][1] supports a `prepack` script, that is called: > * Runs BEFORE the package is packed > * Runs BEFORE the package is published > * Runs on local `npm install` without any arguments > * Run 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. [1]: https://docs.npmjs.com/cli/v6/using-npm/scripts#life-cycle-scripts
Owner
|
Good idea! Merged! |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In NPM, the
prepublishOnlyscript is run only before runningnpm publish. However, this means that people trying to use the git version of of this project (i.e. withnpm install github:ferdikoomen/openapi-typescript-codegen) won't get a working version of this project, since there will be nothing in thedist/folder.NPM (since v4.0.0) supports a
prepackscript, that is called:According to the NPM docs, this is the recommended place to put scripts that do things like "Compiling CoffeeScript source code into JavaScript.".
Fixes #1457, resolves #1458 (this PR is cleaner than that PR)
Benefits
Installing directly from
gitcan be pretty useful, as it allowsopenapi-typescript-codegenusers to use a specific git commit/branch, e.g. so that they don't need to wait for an NPM release (or people can use a commit from a PR that hasn't yet been merged).Tests
Testing:
npx github:ferdikoomen/openapi-typescript-codegen --help(fails)npx github:aloisklink/openapi-typescript-codegen#build/use-npm-prepare-instead-of-prepublishOnly --help(works)npm publish: