Skip to content

Commit

Permalink
add an ensure-npm script (#961)
Browse files Browse the repository at this point in the history
* ensure npm script

* version and changelog
  • Loading branch information
newhouse authored Jul 15, 2024
1 parent 6afcde1 commit 2fd75d8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
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",
"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

0 comments on commit 2fd75d8

Please sign in to comment.