diff --git a/lib/defaults.js b/lib/defaults.js index e457865..1695cae 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -2,6 +2,7 @@ 'use strict'; const os = require('os'); const path = require('path'); +const ciInfo = require('ci-info'); const temp = os.tmpdir(); const uidOrPid = process.getuid ? process.getuid() : process.pid; @@ -29,6 +30,20 @@ const cacheExtra = process.platform === 'win32' ? 'npm-cache' : '.npm'; const cacheRoot = process.platform === 'win32' && process.env.APPDATA || home; const cache = path.resolve(cacheRoot, cacheExtra); +const editor = process.env.EDITOR || + process.env.VISUAL || + (isWindows ? `undefined\notepad.exe` : 'vi') + +const shell = isWindows + ? process.env.ComSpec || 'cmd' + : process.env.SHELL || 'sh' + +const unicode = /UTF-?8$/i.test( + process.env.LC_ALL || + process.env.LC_CTYPE || + process.env.LANG || '' +) + let defaults; let globalPrefix; @@ -50,127 +65,163 @@ Object.defineProperty(exports, 'defaults', { } } - defaults = { - access: null, - 'allow-same-version': false, - 'always-auth': false, - also: null, - audit: true, - 'auth-type': 'legacy', - 'bin-links': true, - browser: null, - ca: null, - cafile: null, - cache: cache, - 'cache-lock-stale': 60000, - 'cache-lock-retries': 10, - 'cache-lock-wait': 10000, - 'cache-max': Infinity, - 'cache-min': 10, - cert: null, - cidr: null, - color: process.env.NO_COLOR == null, - depth: Infinity, - description: true, - dev: false, - 'dry-run': false, - editor: osenv.editor(), - 'engine-strict': false, - force: false, - 'fetch-retries': 2, - 'fetch-retry-factor': 10, - 'fetch-retry-mintimeout': 10000, - 'fetch-retry-maxtimeout': 60000, - git: 'git', - 'git-tag-version': true, - 'commit-hooks': true, - global: false, - globalconfig: path.resolve(globalPrefix, 'etc', 'npmrc'), - 'global-style': false, - group: process.platform === 'win32' ? 0 : process.env.SUDO_GID || process.getgid && process.getgid(), - 'ham-it-up': false, - heading: 'npm', - 'if-present': false, - 'ignore-prepublish': false, - 'ignore-scripts': false, - 'init-module': path.resolve(home, '.npm-init.js'), - 'init-author-name': '', - 'init-author-email': '', - 'init-author-url': '', - 'init-version': '1.0.0', - 'init-license': 'ISC', - json: false, - key: null, - 'legacy-bundling': false, - link: false, - 'local-address': undefined, - loglevel: 'notice', - logstream: process.stderr, - 'logs-max': 10, - long: false, - maxsockets: 50, - message: '%s', - 'metrics-registry': null, - 'node-options': null, - // We remove node-version to fix the issue described here: https://github.com/pnpm/pnpm/issues/4203#issuecomment-1133872769 - 'offline': false, - 'onload-script': false, - only: null, - optional: true, - otp: null, - 'package-lock': true, - 'package-lock-only': false, - parseable: false, - 'prefer-offline': false, - 'prefer-online': false, - prefix: globalPrefix, - production: process.env.NODE_ENV === 'production', - 'progress': !process.env.TRAVIS && !process.env.CI, - provenance: false, - proxy: null, - 'https-proxy': null, - 'no-proxy': null, - 'user-agent': 'npm/{npm-version} ' + 'node/{node-version} ' + '{platform} ' + '{arch}', - 'read-only': false, - 'rebuild-bundle': true, - registry: 'https://registry.npmjs.org/', - rollback: true, - save: true, - 'save-bundle': false, - 'save-dev': false, - 'save-exact': false, - 'save-optional': false, - 'save-prefix': '^', - 'save-prod': false, - scope: '', - 'script-shell': null, - 'scripts-prepend-node-path': 'warn-only', - searchopts: '', - searchexclude: null, - searchlimit: 20, - searchstaleness: 15 * 60, - 'send-metrics': false, - shell: osenv.shell(), - shrinkwrap: true, - 'sign-git-tag': false, - 'sso-poll-frequency': 500, - 'sso-type': 'oauth', - 'strict-ssl': true, - tag: 'latest', - 'tag-version-prefix': 'v', - timing: false, - tmp: temp, - unicode: hasUnicode(), - 'unsafe-perm': process.platform === 'win32' || process.platform === 'cygwin' || !(process.getuid && process.setuid && process.getgid && process.setgid) || process.getuid() !== 0, - usage: false, - user: process.platform === 'win32' ? 0 : 'nobody', - userconfig: path.resolve(home, '.npmrc'), - umask: process.umask ? process.umask() : umask.fromString('022'), - version: false, - versions: false, - viewer: process.platform === 'win32' ? 'browser' : 'man', - _exit: true + defaults = { + '_auth' : null, + 'access' : null, + 'all' : false, + 'allow-same-version' : false, + 'also' : null, + 'audit' : true, + 'audit-level' : null, + 'auth-type' : 'web', + 'before' : null, + 'bin-links' : true, + 'browser' : null, + 'ca' : null, + 'cache' : cache, + 'cache-max' : Infinity, + 'cache-min' : 0, + 'cafile' : null, + 'call' : '', + 'cert' : null, + 'cidr' : null, + 'color' : !process.env.NO_COLOR || process.env.NO_COLOR === '0', + 'commit-hooks' : true, + 'cpu' : null, + 'os' : null, + 'depth' : null, + 'description' : true, + 'dev' : false, + 'diff' : [], + 'diff-ignore-all-space' : false, + 'diff-name-only' : false, + 'diff-no-prefix' : false, + 'diff-dst-prefix' : 'b/', + 'diff-src-prefix' : 'a/', + 'diff-text' : false, + 'diff-unified' : 3, + 'dry-run' : false, + 'editor' : editor, + 'engine-strict' : false, + 'fetch-retries' : 2, + 'fetch-retry-factor' : 10, + 'fetch-retry-maxtimeout' : 60000, + 'fetch-retry-mintimeout' : 10000, + 'fetch-timeout' : 5 * 60 * 1000, + 'force' : false, + 'foreground-scripts' : false, + 'format-package-lock' : true, + 'fund' : true, + 'git' : 'git', + 'git-tag-version' : true, + 'global' : false, + 'globalconfig' : '', + 'global-style' : false, + 'heading' : 'npm', + 'https-proxy' : null, + 'if-present' : false, + 'ignore-scripts' : false, + 'include' : [], + 'include-staged' : false, + 'include-workspace-root' : false, + 'init-author-email' : '', + 'init-author-name' : '', + 'init-author-url' : '', + 'init-license' : 'ISC', + 'init-module' : '~/.npm-init.js', + 'init-version' : '1.0.0', + 'init.author.email' : '', + 'init.author.name' : '', + 'init.author.url' : '', + 'init.license' : 'ISC', + 'init.module' : '~/.npm-init.js', + 'init.version' : '1.0.0', + 'install-links' : false, + 'install-strategy' : 'hoisted', + 'json' : false, + 'key' : null, + 'legacy-bundling' : false, + 'legacy-peer-deps' : false, + 'link' : false, + 'local-address' : null, + 'sbom-format' : null, + 'sbom-type' : 'library', + 'location' : 'user', + 'lockfile-version' : null, + 'loglevel' : 'notice', + 'logs-dir' : null, + 'logs-max' : 10, + 'long' : false, + 'maxsockets' : 15, + 'message' : '%s', + 'node-options' : null, + 'noproxy' : '', + 'offline' : false, + 'omit' : process.env.NODE_ENV === 'production' ? ['dev'] : [], + 'omit-lockfile-registry-resolved' : false, + 'only' : null, + 'optional' : null, + 'otp' : null, + 'package' : [], + 'package-lock' : true, + 'package-lock-only' : false, + 'pack-destination' : '.', + 'parseable' : false, + 'prefer-dedupe' : false, + 'prefer-offline' : false, + 'prefer-online' : false, + 'prefix' : '', + 'preid' : '', + 'production' : null, + 'progress' : !ciInfo.isCI, + 'provenance' : false, + 'provenance-file' : null, + 'proxy' : null, + 'read-only' : false, + 'rebuild-bundle' : true, + 'registry' : 'https://registry.npmjs.org/', + 'replace-registry-host' : 'npmjs', + 'save' : true, + 'save-bundle' : false, + 'save-dev' : false, + 'save-exact' : false, + 'save-optional' : false, + 'save-peer' : false, + 'save-prefix' : '^', + 'save-prod' : false, + 'scope' : '', + 'script-shell' : null, + 'searchexclude' : '', + 'searchlimit' : 20, + 'searchopts' : '', + 'searchstaleness' : 15 * 60, + 'shell' : shell, + 'shrinkwrap' : true, + 'sign-git-commit' : false, + 'sign-git-tag' : false, + 'strict-peer-deps' : false, + 'strict-ssl' : true, + 'tag' : 'latest', + 'tag-version-prefix' : 'v', + 'timing' : false, + 'umask' : 0, + 'unicode' : unicode, + 'update-notifier' : true, + 'usage' : false, + 'user-agent' : 'npm/{npm-version} ' + 'node/{node-version} ' + '{platform} ' + '{arch} ' + 'workspaces/{workspaces} ' + '{ci}', + 'userconfig' : '~/.npmrc', + 'version' : false, + 'versions' : false, + 'viewer' : isWindows ? 'browser' : 'man', + 'which' : null, + 'workspace' : [], + 'workspaces' : null, + 'workspaces-update' : true, + 'yes' : null, + }; return defaults; } }); + + \ No newline at end of file diff --git a/lib/make.js b/lib/make.js index 6806231..03e0e22 100644 --- a/lib/make.js +++ b/lib/make.js @@ -1,9 +1,14 @@ 'use strict'; const fs = require('fs'); const path = require('path'); -const babylon = require('babylon'); -const generate = require('babel-generator').default; -const traverse = require('babel-traverse').default; +const defFile = require.resolve('../node_modules/@npmcli/config/lib/definitions/definitions.js'); +const parser = require('@babel/parser').parse; +const traverse = require('@babel/traverse').default; +const generator = require('@babel/generator').default; + +const def = fs.readFileSync(defFile, 'utf8'); +const ast = parser(def); + const INDENT_REGEXP = /^((?: )+)/gmu; /** @param {string} match */ @@ -17,6 +22,7 @@ const defaultsTemplate = body => `\ 'use strict'; const os = require('os'); const path = require('path'); +const ciInfo = require('ci-info'); const temp = os.tmpdir(); const uidOrPid = process.getuid ? process.getuid() : process.pid; @@ -41,59 +47,109 @@ if (home) { } const cacheExtra = process.platform === 'win32' ? 'npm-cache' : '.npm'; -const cacheRoot = process.platform === 'win32' ? process.env.APPDATA : home; +const cacheRoot = process.platform === 'win32' && process.env.APPDATA || home; const cache = path.resolve(cacheRoot, cacheExtra); +const editor = process.env.EDITOR || + process.env.VISUAL || + (isWindows ? \`${process.env.SYSTEMROOT}\\notepad.exe\` : 'vi') + +const shell = isWindows + ? process.env.ComSpec || 'cmd' + : process.env.SHELL || 'sh' + +const unicode = /UTF-?8$/i.test( + process.env.LC_ALL || + process.env.LC_CTYPE || + process.env.LANG || '' +) + let defaults; let globalPrefix; -${body.replace(INDENT_REGEXP, INDENT_REPLACER).replace("'node-version': process.version,", '// We remove node-version to fix the issue described here: https://github.com/pnpm/pnpm/issues/4203#issuecomment-1133872769')}; -`; +Object.defineProperty(exports, 'defaults', { + get: function () { + if (defaults) return defaults; + + if (process.env.PREFIX) { + globalPrefix = process.env.PREFIX; + } else if (process.platform === 'win32') { + // c:\\node\\node.exe --> prefix=c:\\node\\ + globalPrefix = path.dirname(process.execPath); + } else { + // /usr/local/bin/node --> prefix=/usr/local + globalPrefix = path.dirname(path.dirname(process.execPath)); // destdir only is respected on Unix + + if (process.env.DESTDIR) { + globalPrefix = path.join(process.env.DESTDIR, globalPrefix); + } + } + + defaults = { + ${Object.keys(body).map(key => `\ + '${key}' : ${body[key]},`).join('\n')} + + }; + return defaults; + } +}); + + `; /** @param {string} body */ const typesTemplate = body => `\ // Generated with \`lib/make.js\` 'use strict'; const path = require('path'); -const Stream = require('stream').Stream; const url = require('url'); const Umask = () => {}; const getLocalAddresses = () => []; const semver = () => {}; -${body.replace(INDENT_REGEXP, INDENT_REPLACER)}; -`; - -const defaults = require.resolve('npm/lib/config/defaults'); -const ast = babylon.parse(fs.readFileSync(defaults, 'utf8')); - -const isDefaults = node => - node.callee.type === 'MemberExpression' && - node.callee.object.name === 'Object' && - node.callee.property.name === 'defineProperty' && - node.arguments.some(x => x.name === 'exports'); - -const isTypes = node => - node.type === 'MemberExpression' && - node.object.name === 'exports' && - node.property.name === 'types'; - -let defs; -let types; - -traverse(ast, { - CallExpression(path) { - if (isDefaults(path.node)) { - defs = path.node; - } - }, - AssignmentExpression(path) { - if (path.node.left && isTypes(path.node.left)) { - types = path.node; - } +exports.types = { + ${Object.keys(body).map(key => `\ + '${key}' : ${body[key]},`).join('\n')} } -}); - -fs.writeFileSync(path.join(__dirname, 'defaults.js'), defaultsTemplate(generate(defs).code)); -fs.writeFileSync(path.join(__dirname, 'types.js'), typesTemplate(generate(types).code)); + `; + + let extractedTypes = {}; + let extractedDefaults = {}; + + function extractProperties(properties) { + const result = {}; + properties.forEach(property => { + const propertyName = property.get('key').node.name; + const propertyValue = property.get('value').node; + result[propertyName] = propertyValue; + }); + return result; + } + + traverse(ast, { + CallExpression(path) { + const calleeName = path.get('callee.name').node; + if (calleeName === 'define' && path.get('arguments')[1].isObjectExpression()) { + const key = path.get('arguments')[0].node.value; + const properties = path.get('arguments')[1].get('properties'); + const extractedProperties = extractProperties(properties); + // console.log('Extracted Properties:', extractedProperties); + if (extractedProperties.type) { + //remove [] and replace , with | + extractedTypes[key] = generator(extractedProperties.type).code + } + + if (extractedProperties.default) { + extractedDefaults[key] = generator(extractedProperties.default).code; + } + } + }, + }); + + //We remove node-version to fix the issue described here: https://github.com/pnpm/pnpm/issues/4203#issuecomment-1133872769')}; + delete extractedDefaults['node-version']; + + console.log('Extracted Defaults:', extractedDefaults); + // console.log('Extracted Types:', extractedTypes); + fs.writeFileSync(path.join(__dirname, 'defaults.js'), defaultsTemplate(extractedDefaults)); + fs.writeFileSync(path.join(__dirname, 'types.js'), typesTemplate(extractedTypes)); \ No newline at end of file diff --git a/lib/types.d.ts b/lib/types.d.ts index d0756e3..fee7abf 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -1,122 +1,157 @@ /// -export var types: { +export const types: { + _auth: (StringConstructor | null)[]; access: (string | null)[]; + all: BooleanConstructor; 'allow-same-version': BooleanConstructor; - 'always-auth': BooleanConstructor; also: (string | null)[]; audit: BooleanConstructor; + 'audit-level': (string | null)[]; 'auth-type': string[]; + before: (DateConstructor | null)[]; 'bin-links': BooleanConstructor; - browser: (StringConstructor | null)[]; + browser: (StringConstructor | BooleanConstructor | null)[]; ca: (StringConstructor | ArrayConstructor | null)[]; - cafile: import("path").PlatformPath; - cache: import("path").PlatformPath; - 'cache-lock-stale': NumberConstructor; - 'cache-lock-retries': NumberConstructor; - 'cache-lock-wait': NumberConstructor; + cache: path.PlatformPath; 'cache-max': NumberConstructor; 'cache-min': NumberConstructor; + cafile: path.PlatformPath; + call: StringConstructor; cert: (StringConstructor | null)[]; cidr: (StringConstructor | ArrayConstructor | null)[]; color: (string | BooleanConstructor)[]; - depth: NumberConstructor; + 'commit-hooks': BooleanConstructor; + cpu: (StringConstructor | null)[]; + os: (StringConstructor | null)[]; + depth: (NumberConstructor | null)[]; description: BooleanConstructor; dev: BooleanConstructor; + diff: (StringConstructor | ArrayConstructor)[]; + 'diff-ignore-all-space': BooleanConstructor; + 'diff-name-only': BooleanConstructor; + 'diff-no-prefix': BooleanConstructor; + 'diff-dst-prefix': StringConstructor; + 'diff-src-prefix': StringConstructor; + 'diff-text': BooleanConstructor; + 'diff-unified': NumberConstructor; 'dry-run': BooleanConstructor; editor: StringConstructor; 'engine-strict': BooleanConstructor; - force: BooleanConstructor; 'fetch-retries': NumberConstructor; 'fetch-retry-factor': NumberConstructor; - 'fetch-retry-mintimeout': NumberConstructor; 'fetch-retry-maxtimeout': NumberConstructor; + 'fetch-retry-mintimeout': NumberConstructor; + 'fetch-timeout': NumberConstructor; + force: BooleanConstructor; + 'foreground-scripts': BooleanConstructor; + 'format-package-lock': BooleanConstructor; + fund: BooleanConstructor; git: StringConstructor; 'git-tag-version': BooleanConstructor; - 'commit-hooks': BooleanConstructor; global: BooleanConstructor; - globalconfig: import("path").PlatformPath; + globalconfig: path.PlatformPath; 'global-style': BooleanConstructor; - group: (StringConstructor | NumberConstructor)[]; - 'https-proxy': (typeof import("url") | null)[]; - 'user-agent': StringConstructor; - 'ham-it-up': BooleanConstructor; heading: StringConstructor; + 'https-proxy': (typeof url | null)[]; 'if-present': BooleanConstructor; - 'ignore-prepublish': BooleanConstructor; 'ignore-scripts': BooleanConstructor; - 'init-module': import("path").PlatformPath; - 'init-author-name': StringConstructor; + include: (string | ArrayConstructor)[]; + 'include-staged': BooleanConstructor; + 'include-workspace-root': BooleanConstructor; 'init-author-email': StringConstructor; - 'init-author-url': (string | typeof import("url"))[]; + 'init-author-name': StringConstructor; + 'init-author-url': (string | typeof url)[]; 'init-license': StringConstructor; + 'init-module': path.PlatformPath; 'init-version': () => void; + 'init.author.email': StringConstructor; + 'init.author.name': StringConstructor; + 'init.author.url': (string | typeof url)[]; + 'init.license': StringConstructor; + 'init.module': path.PlatformPath; + 'init.version': () => void; + 'install-links': BooleanConstructor; + 'install-strategy': string[]; json: BooleanConstructor; key: (StringConstructor | null)[]; 'legacy-bundling': BooleanConstructor; + 'legacy-peer-deps': BooleanConstructor; link: BooleanConstructor; 'local-address': never[]; + 'sbom-format': string[]; + 'sbom-type': string[]; + location: string[]; + 'lockfile-version': (string | number | null)[]; loglevel: string[]; - logstream: typeof import("stream").Stream; + 'logs-dir': (path.PlatformPath | null)[]; 'logs-max': NumberConstructor; long: BooleanConstructor; maxsockets: NumberConstructor; message: StringConstructor; - 'metrics-registry': (StringConstructor | null)[]; 'node-options': (StringConstructor | null)[]; - 'node-version': ((() => void) | null)[]; - 'no-proxy': (StringConstructor | ArrayConstructor | null)[]; + noproxy: (StringConstructor | ArrayConstructor)[]; offline: BooleanConstructor; - 'onload-script': (StringConstructor | null)[]; + omit: (string | ArrayConstructor)[]; + 'omit-lockfile-registry-resolved': BooleanConstructor; only: (string | null)[]; - optional: BooleanConstructor; - 'package-lock': BooleanConstructor; + optional: (BooleanConstructor | null)[]; otp: (StringConstructor | null)[]; + package: (StringConstructor | ArrayConstructor)[]; + 'package-lock': BooleanConstructor; 'package-lock-only': BooleanConstructor; + 'pack-destination': StringConstructor; parseable: BooleanConstructor; + 'prefer-dedupe': BooleanConstructor; 'prefer-offline': BooleanConstructor; 'prefer-online': BooleanConstructor; - prefix: import("path").PlatformPath; - production: BooleanConstructor; + prefix: path.PlatformPath; + preid: StringConstructor; + production: (BooleanConstructor | null)[]; progress: BooleanConstructor; provenance: BooleanConstructor; - proxy: (boolean | typeof import("url") | null)[]; + 'provenance-file': path.PlatformPath; + proxy: (boolean | typeof url | null)[]; 'read-only': BooleanConstructor; 'rebuild-bundle': BooleanConstructor; - registry: (typeof import("url") | null)[]; - rollback: BooleanConstructor; + registry: typeof url; + 'replace-registry-host': (string | StringConstructor)[]; save: BooleanConstructor; 'save-bundle': BooleanConstructor; 'save-dev': BooleanConstructor; 'save-exact': BooleanConstructor; 'save-optional': BooleanConstructor; + 'save-peer': BooleanConstructor; 'save-prefix': StringConstructor; 'save-prod': BooleanConstructor; scope: StringConstructor; 'script-shell': (StringConstructor | null)[]; - 'scripts-prepend-node-path': (string | boolean)[]; - searchopts: StringConstructor; - searchexclude: (StringConstructor | null)[]; + searchexclude: StringConstructor; searchlimit: NumberConstructor; + searchopts: StringConstructor; searchstaleness: NumberConstructor; - 'send-metrics': BooleanConstructor; shell: StringConstructor; shrinkwrap: BooleanConstructor; + 'sign-git-commit': BooleanConstructor; 'sign-git-tag': BooleanConstructor; - 'sso-poll-frequency': NumberConstructor; - 'sso-type': (string | null)[]; + 'strict-peer-deps': BooleanConstructor; 'strict-ssl': BooleanConstructor; tag: StringConstructor; + 'tag-version-prefix': StringConstructor; timing: BooleanConstructor; - tmp: import("path").PlatformPath; + umask: () => void; unicode: BooleanConstructor; - 'unsafe-perm': BooleanConstructor; + 'update-notifier': BooleanConstructor; usage: BooleanConstructor; - user: (StringConstructor | NumberConstructor)[]; - userconfig: import("path").PlatformPath; - umask: () => void; + 'user-agent': StringConstructor; + userconfig: path.PlatformPath; version: BooleanConstructor; - 'tag-version-prefix': StringConstructor; versions: BooleanConstructor; viewer: StringConstructor; - _exit: BooleanConstructor; + which: (NumberConstructor | null)[]; + workspace: (StringConstructor | ArrayConstructor)[]; + workspaces: (BooleanConstructor | null)[]; + 'workspaces-update': BooleanConstructor; + yes: (BooleanConstructor | null)[]; }; +import path = require("path"); +import url = require("url"); diff --git a/lib/types.js b/lib/types.js index eb0f590..92b0ca2 100644 --- a/lib/types.js +++ b/lib/types.js @@ -1,7 +1,6 @@ // Generated with `lib/make.js` 'use strict'; const path = require('path'); -const Stream = require('stream').Stream; const url = require('url'); const Umask = () => {}; @@ -9,126 +8,157 @@ const getLocalAddresses = () => []; const semver = () => {}; exports.types = { - access: [null, 'restricted', 'public'], - 'allow-same-version': Boolean, - 'always-auth': Boolean, - also: [null, 'dev', 'development'], - audit: Boolean, - 'auth-type': ['legacy', 'sso', 'saml', 'oauth'], - 'bin-links': Boolean, - browser: [null, String], - ca: [null, String, Array], - cafile: path, - cache: path, - 'cache-lock-stale': Number, - 'cache-lock-retries': Number, - 'cache-lock-wait': Number, - 'cache-max': Number, - 'cache-min': Number, - cert: [null, String], - cidr: [null, String, Array], - color: ['always', Boolean], - depth: Number, - description: Boolean, - dev: Boolean, - 'dry-run': Boolean, - editor: String, - 'engine-strict': Boolean, - force: Boolean, - 'fetch-retries': Number, - 'fetch-retry-factor': Number, - 'fetch-retry-mintimeout': Number, - 'fetch-retry-maxtimeout': Number, - git: String, - 'git-tag-version': Boolean, - 'commit-hooks': Boolean, - global: Boolean, - globalconfig: path, - 'global-style': Boolean, - group: [Number, String], - 'https-proxy': [null, url], - 'user-agent': String, - 'ham-it-up': Boolean, - 'heading': String, - 'if-present': Boolean, - 'ignore-prepublish': Boolean, - 'ignore-scripts': Boolean, - 'init-module': path, - 'init-author-name': String, - 'init-author-email': String, - 'init-author-url': ['', url], - 'init-license': String, - 'init-version': semver, - json: Boolean, - key: [null, String], - 'legacy-bundling': Boolean, - link: Boolean, - // local-address must be listed as an IP for a local network interface - // must be IPv4 due to node bug - 'local-address': getLocalAddresses(), - loglevel: ['silent', 'error', 'warn', 'notice', 'http', 'timing', 'info', 'verbose', 'silly'], - logstream: Stream, - 'logs-max': Number, - long: Boolean, - maxsockets: Number, - message: String, - 'metrics-registry': [null, String], - 'node-options': [null, String], - 'node-version': [null, semver], - 'no-proxy': [null, String, Array], - offline: Boolean, - 'onload-script': [null, String], - only: [null, 'dev', 'development', 'prod', 'production'], - optional: Boolean, - 'package-lock': Boolean, - otp: [null, String], - 'package-lock-only': Boolean, - parseable: Boolean, - 'prefer-offline': Boolean, - 'prefer-online': Boolean, - prefix: path, - production: Boolean, - progress: Boolean, - proxy: [null, false, url], - provenance: Boolean, - // allow proxy to be disabled explicitly - 'read-only': Boolean, - 'rebuild-bundle': Boolean, - registry: [null, url], - rollback: Boolean, - save: Boolean, - 'save-bundle': Boolean, - 'save-dev': Boolean, - 'save-exact': Boolean, - 'save-optional': Boolean, - 'save-prefix': String, - 'save-prod': Boolean, - scope: String, - 'script-shell': [null, String], - 'scripts-prepend-node-path': [false, true, 'auto', 'warn-only'], - searchopts: String, - searchexclude: [null, String], - searchlimit: Number, - searchstaleness: Number, - 'send-metrics': Boolean, - shell: String, - shrinkwrap: Boolean, - 'sign-git-tag': Boolean, - 'sso-poll-frequency': Number, - 'sso-type': [null, 'oauth', 'saml'], - 'strict-ssl': Boolean, - tag: String, - timing: Boolean, - tmp: path, - unicode: Boolean, - 'unsafe-perm': Boolean, - usage: Boolean, - user: [Number, String], - userconfig: path, - umask: Umask, - version: Boolean, - 'tag-version-prefix': String, - versions: Boolean, - viewer: String, - _exit: Boolean -}; + '_auth' : [null, String], + 'access' : [null, 'restricted', 'public'], + 'all' : Boolean, + 'allow-same-version' : Boolean, + 'also' : [null, 'dev', 'development'], + 'audit' : Boolean, + 'audit-level' : [null, 'info', 'low', 'moderate', 'high', 'critical', 'none'], + 'auth-type' : ['legacy', 'web'], + 'before' : [null, Date], + 'bin-links' : Boolean, + 'browser' : [null, Boolean, String], + 'ca' : [null, String, Array], + 'cache' : path, + 'cache-max' : Number, + 'cache-min' : Number, + 'cafile' : path, + 'call' : String, + 'cert' : [null, String], + 'cidr' : [null, String, Array], + 'color' : ['always', Boolean], + 'commit-hooks' : Boolean, + 'cpu' : [null, String], + 'os' : [null, String], + 'depth' : [null, Number], + 'description' : Boolean, + 'dev' : Boolean, + 'diff' : [String, Array], + 'diff-ignore-all-space' : Boolean, + 'diff-name-only' : Boolean, + 'diff-no-prefix' : Boolean, + 'diff-dst-prefix' : String, + 'diff-src-prefix' : String, + 'diff-text' : Boolean, + 'diff-unified' : Number, + 'dry-run' : Boolean, + 'editor' : String, + 'engine-strict' : Boolean, + 'fetch-retries' : Number, + 'fetch-retry-factor' : Number, + 'fetch-retry-maxtimeout' : Number, + 'fetch-retry-mintimeout' : Number, + 'fetch-timeout' : Number, + 'force' : Boolean, + 'foreground-scripts' : Boolean, + 'format-package-lock' : Boolean, + 'fund' : Boolean, + 'git' : String, + 'git-tag-version' : Boolean, + 'global' : Boolean, + 'globalconfig' : path, + 'global-style' : Boolean, + 'heading' : String, + 'https-proxy' : [null, url], + 'if-present' : Boolean, + 'ignore-scripts' : Boolean, + 'include' : [Array, 'prod', 'dev', 'optional', 'peer'], + 'include-staged' : Boolean, + 'include-workspace-root' : Boolean, + 'init-author-email' : String, + 'init-author-name' : String, + 'init-author-url' : ['', url], + 'init-license' : String, + 'init-module' : path, + 'init-version' : semver, + 'init.author.email' : String, + 'init.author.name' : String, + 'init.author.url' : ['', url], + 'init.license' : String, + 'init.module' : path, + 'init.version' : semver, + 'install-links' : Boolean, + 'install-strategy' : ['hoisted', 'nested', 'shallow', 'linked'], + 'json' : Boolean, + 'key' : [null, String], + 'legacy-bundling' : Boolean, + 'legacy-peer-deps' : Boolean, + 'link' : Boolean, + 'local-address' : getLocalAddresses(), + 'sbom-format' : ['cyclonedx', 'spdx'], + 'sbom-type' : ['library', 'application', 'framework'], + 'location' : ['global', 'user', 'project'], + 'lockfile-version' : [null, 1, 2, 3, '1', '2', '3'], + 'loglevel' : ['silent', 'error', 'warn', 'notice', 'http', 'info', 'verbose', 'silly'], + 'logs-dir' : [null, path], + 'logs-max' : Number, + 'long' : Boolean, + 'maxsockets' : Number, + 'message' : String, + 'node-options' : [null, String], + 'noproxy' : [String, Array], + 'offline' : Boolean, + 'omit' : [Array, 'dev', 'optional', 'peer'], + 'omit-lockfile-registry-resolved' : Boolean, + 'only' : [null, 'prod', 'production'], + 'optional' : [null, Boolean], + 'otp' : [null, String], + 'package' : [String, Array], + 'package-lock' : Boolean, + 'package-lock-only' : Boolean, + 'pack-destination' : String, + 'parseable' : Boolean, + 'prefer-dedupe' : Boolean, + 'prefer-offline' : Boolean, + 'prefer-online' : Boolean, + 'prefix' : path, + 'preid' : String, + 'production' : [null, Boolean], + 'progress' : Boolean, + 'provenance' : Boolean, + 'provenance-file' : path, + 'proxy' : [null, false, url], + 'read-only' : Boolean, + 'rebuild-bundle' : Boolean, + 'registry' : url, + 'replace-registry-host' : ['npmjs', 'never', 'always', String], + 'save' : Boolean, + 'save-bundle' : Boolean, + 'save-dev' : Boolean, + 'save-exact' : Boolean, + 'save-optional' : Boolean, + 'save-peer' : Boolean, + 'save-prefix' : String, + 'save-prod' : Boolean, + 'scope' : String, + 'script-shell' : [null, String], + 'searchexclude' : String, + 'searchlimit' : Number, + 'searchopts' : String, + 'searchstaleness' : Number, + 'shell' : String, + 'shrinkwrap' : Boolean, + 'sign-git-commit' : Boolean, + 'sign-git-tag' : Boolean, + 'strict-peer-deps' : Boolean, + 'strict-ssl' : Boolean, + 'tag' : String, + 'tag-version-prefix' : String, + 'timing' : Boolean, + 'umask' : Umask, + 'unicode' : Boolean, + 'update-notifier' : Boolean, + 'usage' : Boolean, + 'user-agent' : String, + 'userconfig' : path, + 'version' : Boolean, + 'versions' : Boolean, + 'viewer' : String, + 'which' : [null, Number], + 'workspace' : [String, Array], + 'workspaces' : [null, Boolean], + 'workspaces-update' : Boolean, + 'yes' : [null, Boolean], + } + \ No newline at end of file diff --git a/package.json b/package.json index c85af6b..bc93c77 100644 --- a/package.json +++ b/package.json @@ -26,17 +26,18 @@ ], "dependencies": { "@pnpm/config.env-replace": "^1.1.0", - "@pnpm/network.ca-file": "^1.0.1", - "config-chain": "^1.1.11" + "@pnpm/network.ca-file": "^1.0.2", + "ci-info": "^4.0.0", + "config-chain": "^1.1.13" }, "devDependencies": { - "@types/node": "^14.0.14", - "babel-generator": "^6.24.1", - "babel-traverse": "^6.24.1", - "babylon": "^6.17.1", - "eslint-import-resolver-node": "^0.3.2", - "jest": "^25.1.0", - "npm": "^5.0.4", - "typescript": "^3.9.6" + "@babel/generator": "^7.23.0", + "@babel/parser": "^7.23.0", + "@babel/traverse": "^7.23.2", + "@npmcli/config": "^8.0.1", + "@types/node": "^20.8.10", + "eslint-import-resolver-node": "^0.3.9", + "jest": "^29.7.0", + "typescript": "^5.2.2" } } diff --git a/test.js b/test.js index cc0a413..82a7603 100644 --- a/test.js +++ b/test.js @@ -1,27 +1,22 @@ // load `npmDefaults` first and clone them into a new object as `npmCore` mutates them -const npmDefaults = Object.assign({}, require('./node_modules/npm/lib/config/defaults').defaults); -const npmCore = require('npm/lib/config/core'); -const { promisify } = require('util'); +const npmDefaults = Object.assign({}, require('@npmcli/config/lib/definitions').defaults); +const npmConf = require('@npmcli/config/lib/definitions').defaults; const m = require('.'); -// The 'unicode' property is determined based on OS type and environment variables -delete npmDefaults.unicode; - test('mirror npm config', async () => { const { config: conf } = m(); - const npmConf = await promisify(npmCore.load)(); - expect(conf.globalPrefix).toBe(npmConf.globalPrefix); - expect(conf.localPrefix).toBe(npmConf.localPrefix); - expect(conf.get('prefix')).toBe(npmConf.get('prefix')); - expect(conf.get('registry')).toBe(npmConf.get('registry')); - expect(conf.get('tmp')).toBe(npmConf.get('tmp')); + expect(conf.get('prefix')).toBe(npmConf['prefix']); + expect(conf.get('registry')).toBe(npmConf['registry']); + expect(conf.get('tmp')).toBe(npmConf['tmp']); }); -test('mirror npm defaults', () => { - delete npmDefaults['node-version'] + test('mirror npm defaults', () => { + delete npmConf['node-version'] + delete npmConf['cache'] + delete npmDefaults['cache'] expect(m.defaults).toMatchObject(npmDefaults); -}); +}); test('npm builtin configs require failed', async () => {