-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
51 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
// 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 packageEnvs = (env, vals, prefix) => { | ||
const packageEnvs = (vals, prefix, env = {}) => { | ||
for (const [key, val] of Object.entries(vals)) { | ||
if (val === undefined) { | ||
continue | ||
} else if (val && !Array.isArray(val) && typeof val === 'object') { | ||
packageEnvs(env, val, `${prefix}${key}_`) | ||
} else if (val === null || val === false) { | ||
env[`${prefix}${key}`] = '' | ||
} else if (Array.isArray(val)) { | ||
val.forEach((item, index) => { | ||
packageEnvs({ [`${key}_${index}`]: item }, `${prefix}`, env) | ||
}) | ||
} else if (typeof val === 'object') { | ||
packageEnvs(val, `${prefix}${key}_`, env) | ||
} else { | ||
env[`${prefix}${key}`] = envVal(val) | ||
env[`${prefix}${key}`] = String(val) | ||
} | ||
} | ||
return env | ||
} | ||
|
||
module.exports = (env, pkg) => packageEnvs({ ...env }, { | ||
name: pkg.name, | ||
version: pkg.version, | ||
config: pkg.config, | ||
engines: pkg.engines, | ||
bin: pkg.bin, | ||
}, 'npm_package_') | ||
// https://github.com/npm/rfcs/pull/183 defines which fields we put into the environment | ||
module.exports = pkg => { | ||
return packageEnvs({ | ||
name: pkg.name, | ||
version: pkg.version, | ||
config: pkg.config, | ||
engines: pkg.engines, | ||
bin: pkg.bin, | ||
}, 'npm_package_') | ||
} |
This file contains 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
This file contains 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
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 }) |
This file contains 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
This file contains 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
This file contains 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