Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
683 bytes
|
Line | |
---|
1 | // https://github.com/npm/rfcs/pull/183
|
---|
2 |
|
---|
3 | const envVal = val => Array.isArray(val) ? val.map(v => envVal(v)).join('\n\n')
|
---|
4 | : val === null || val === false ? ''
|
---|
5 | : String(val)
|
---|
6 |
|
---|
7 | const packageEnvs = (env, vals, prefix) => {
|
---|
8 | for (const [key, val] of Object.entries(vals)) {
|
---|
9 | if (val === undefined)
|
---|
10 | continue
|
---|
11 | else if (val && !Array.isArray(val) && typeof val === 'object')
|
---|
12 | packageEnvs(env, val, `${prefix}${key}_`)
|
---|
13 | else
|
---|
14 | env[`${prefix}${key}`] = envVal(val)
|
---|
15 | }
|
---|
16 | return env
|
---|
17 | }
|
---|
18 |
|
---|
19 | module.exports = (env, pkg) => packageEnvs({ ...env }, {
|
---|
20 | name: pkg.name,
|
---|
21 | version: pkg.version,
|
---|
22 | config: pkg.config,
|
---|
23 | engines: pkg.engines,
|
---|
24 | bin: pkg.bin,
|
---|
25 | }, 'npm_package_')
|
---|
Note:
See
TracBrowser
for help on using the repository browser.