Skip to content

Commit

Permalink
Automatically run npm install when running npm start (github#35283)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com>
  • Loading branch information
peterbe and rsese authored Mar 7, 2023
1 parent 222be16 commit e77b7bf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ user-code/
# Logs from scripts
script/logs/
external-link-checker-db.json
.installed.package-lock.json
5 changes: 5 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# skip installing optional dependencies to avoid issues with troublesome `fsevents` module
omit=optional

# For 15-25% faster npm install
# https://www.peterbe.com/plog/benchmarking-npm-install-with-or-without-audit
# Also we have Dependabot alerts configured in the GitHub repo.
audit=false
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
"prevent-pushes-to-main": "node script/prevent-pushes-to-main.js",
"rest-dev": "src/rest/scripts/update-files.js",
"show-action-deps": "echo 'Action Dependencies:' && rg '^[\\s|-]*(uses:.*)$' .github -I -N --no-heading -r '$1$2' | sort | uniq | cut -c 7-",
"prestart": "script/cmp-files.js package-lock.json .installed.package-lock.json || npm install && cp package-lock.json .installed.package-lock.json",
"start": "cross-env NODE_ENV=development ENABLED_LANGUAGES=en nodemon server.js",
"start-all-languages": "cross-env NODE_ENV=development nodemon server.js",
"sync-search": "cross-env NODE_OPTIONS='--max_old_space_size=8192' start-server-and-test sync-search-server 4002 sync-search-indices",
Expand Down
31 changes: 31 additions & 0 deletions script/cmp-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node

// [start-readme]
//
// Given N files. Exit 0 if they all exist and are identical in content.
//
// [end-readme]

import fs from 'fs'

import { program } from 'commander'

program.description('Compare N files').arguments('[files...]', '').parse(process.argv)

main(program.args)

function main(files) {
if (files.length < 2) throw new Error('Must be at least 2 files')
try {
const contents = files.map((file) => fs.readFileSync(file, 'utf-8'))
if (new Set(contents).size > 1) {
process.exit(1)
}
} catch (error) {
if (error.code === 'ENOENT') {
process.exit(1)
} else {
throw error
}
}
}

0 comments on commit e77b7bf

Please sign in to comment.