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 an ensure-npm script #961

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
key: ${{ runner.os }}-node-${{ needs.prepare-node.outputs.build-node-version }}-${{ env.GITHUB_SHA }}

- run: yarn install
- run: yarn test-e2e:build
- run: npm run test-e2e:build

unit-test-and-package-test:
name: Unit Test & Package Test
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 3.0.1
- Added `ensure-npm` developer script
- Dependency updates

### 3.0.0
- BREAKING CHANGE: Drops support for Node 14
- Adds support for Node 20 and Node 22
Expand Down
25 changes: 25 additions & 0 deletions dev/ensure-npm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import readline from 'node:readline/promises'
import { stdin as input, stdout as output } from 'node:process'

const agent = process.env.npm_config_user_agent

// word boundary + "npm/" + a digit
const npmVersionRegEx = /\bnpm\/\d/

if (!agent?.match(npmVersionRegEx)) {
console.log('You do not appear to be using `npm` as your Node package manager. Are you using `yarn`? Try the same command with `npm`.')
process.exit(1)
}

(async () => {

const rl = readline.createInterface({ input, output })

const answer = await rl.question('Are you running "npm publish" or did you pack using "npm"? That\'s "npm" instead of "yarn". Very important!!! [Yy]')
rl.close()

if (answer?.toLowerCase() !== 'y') {
console.log('You must use `npm` (and not `yarn`) for this command.')
process.exit()
}
})()
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spectaql",
"version": "3.0.0",
"version": "3.0.1",
"description": "A powerful library for autogenerating static GraphQL API documentation",
"author": "Anvil Foundry Inc. <hello@useanvil.com>",
"homepage": "https://github.com/anvilco/spectaql",
Expand Down Expand Up @@ -56,7 +56,7 @@
"clean-build:vendor": "npm run clean:vendor && npm run build:vendor",
"clean-build": "npm run clean && npm run build",
"prepack": "husky install && npm run ensure-npm && npm run clean-build",
"ensure-npm": "read -p \"Are you running \\\"npm publish\\\" or did you pack using \\\"npm\\\"? That's \\\"npm\\\" instead of \\\"yarn\\\". Very important!!! [Yy]\" -n 1 -r; if [[ ! $REPLY =~ ^[Yy]$ ]]\nthen\n[[ \"$0\" = \"$BASH_SOURCE\" ]] && exit 1 || return 1\nfi",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't working anymore on mac...but node script should aways work

"ensure-npm": "node dev/ensure-npm.mjs",
"publish:dry-run": "npm pack --dry-run",
"publish:version": "npm version",
"publish:beta": "npm publish --tag beta",
Expand Down
Loading