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

move to @npmcli/package-json #192

Merged
merged 9 commits into from
Jan 19, 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
7 changes: 3 additions & 4 deletions lib/is-server-package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const util = require('util')
const fs = require('fs')
const { stat } = fs.promises || { stat: util.promisify(fs.stat) }
const { resolve } = require('path')
const { stat } = require('node:fs/promises')
const { resolve } = require('node:path')

module.exports = async path => {
try {
const st = await stat(resolve(path, 'server.js'))
Expand Down
2 changes: 0 additions & 2 deletions lib/is-windows.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/make-spawn-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const makeSpawnArgs = options => {
path,
scriptShell = true,
binPaths,
env = {},
env,
stdio,
cmd,
args = [],
args,
stdioString,
} = options

Expand Down
12 changes: 9 additions & 3 deletions lib/package-envs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// https://github.com/npm/rfcs/pull/183

const envVal = val => Array.isArray(val) ? val.map(v => envVal(v)).join('\n\n')
: val === null || val === false ? ''
: String(val)
const envVal = val => {
if (Array.isArray(val)) {
return val.map(v => envVal(v)).join('\n\n')
}
if (val === null || val === false) {
return ''
}
return String(val)
}

const packageEnvs = (env, vals, prefix) => {
for (const [key, val] of Object.entries(vals)) {
Expand Down
2 changes: 2 additions & 0 deletions lib/run-script-pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const runScriptPkg = async options => {

return p.catch(er => {
const { signal } = er
// coverage disabled because win32 never emits signals
/* istanbul ignore next */
if (stdio === 'inherit' && signal) {
// by the time we reach here, the child has already exited. we send the
// signal back to ourselves again so that npm will exit with the same
Expand Down
13 changes: 7 additions & 6 deletions lib/run-script.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const rpj = require('read-package-json-fast')
const PackageJson = require('@npmcli/package-json')
const runScriptPkg = require('./run-script-pkg.js')
const validateOptions = require('./validate-options.js')
const isServerPackage = require('./is-server-package.js')

const runScript = options => {
const runScript = async options => {
validateOptions(options)
const { pkg, path } = options
return pkg ? runScriptPkg(options)
: rpj(path + '/package.json')
.then(readPackage => runScriptPkg({ ...options, pkg: readPackage }))
if (options.pkg) {
return runScriptPkg(options)
}
const { content: pkg } = await PackageJson.normalize(options.path)
return runScriptPkg({ ...options, pkg })
}

module.exports = Object.assign(runScript, { isServerPackage })
1 change: 0 additions & 1 deletion map.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.21.3",
"require-inject": "^1.4.4",
"spawk": "^1.8.1",
"tap": "^16.0.1"
},
"dependencies": {
"@npmcli/node-gyp": "^3.0.0",
"@npmcli/package-json": "^5.0.0",
"@npmcli/promise-spawn": "^7.0.0",
"node-gyp": "^10.0.0",
"read-package-json-fast": "^3.0.0",
"which": "^4.0.0"
},
"files": [
Expand Down
27 changes: 0 additions & 27 deletions test/is-server-package.js

This file was deleted.

12 changes: 0 additions & 12 deletions test/is-windows.js

This file was deleted.

Loading
Loading