diff --git a/docs/content/using-npm/config.md b/docs/content/using-npm/config.md index ddabe01d7d8d4..a5017e61db914 100644 --- a/docs/content/using-npm/config.md +++ b/docs/content/using-npm/config.md @@ -987,7 +987,7 @@ When passed to `npm config` this refers to which config file to use. * Default: Version 2 if no lockfile or current lockfile version less than or equal to 2, otherwise maintain current lockfile version -* Type: null, 1, 2, or 3 +* Type: null, 1, 2, 3, "1", "2", or "3" Set the lockfile format version to be used in package-lock.json and npm-shrinkwrap-json files. Possible options are: diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js index c9806b3c2890f..a725ee0fa1d6f 100644 --- a/lib/utils/config/definitions.js +++ b/lib/utils/config/definitions.js @@ -1157,7 +1157,7 @@ define('location', { define('lockfile-version', { default: null, - type: [null, 1, 2, 3], + type: [null, 1, 2, 3, '1', '2', '3'], defaultDescription: ` Version 2 if no lockfile or current lockfile version less than or equal to 2, otherwise maintain current lockfile version @@ -1179,7 +1179,9 @@ define('lockfile-version', { on disk than lockfile version 2, but not interoperable with older npm versions. Ideal if all users are on npm version 7 and higher. `, - flatten, + flatten: (key, obj, flatOptions) => { + flatOptions.lockfileVersion = obj[key] && parseInt(obj[key], 10) + }, }) define('loglevel', { diff --git a/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs b/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs index aaf59e6a2be34..8c85225f2f998 100644 --- a/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs @@ -1061,7 +1061,7 @@ exports[`test/lib/utils/config/definitions.js TAP > config description for lockf * Default: Version 2 if no lockfile or current lockfile version less than or equal to 2, otherwise maintain current lockfile version -* Type: null, 1, 2, or 3 +* Type: null, 1, 2, 3, "1", "2", or "3" Set the lockfile format version to be used in package-lock.json and npm-shrinkwrap-json files. Possible options are: diff --git a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs index dc55893d00bf9..1ebb336092e39 100644 --- a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs @@ -861,7 +861,7 @@ When passed to \`npm config\` this refers to which config file to use. * Default: Version 2 if no lockfile or current lockfile version less than or equal to 2, otherwise maintain current lockfile version -* Type: null, 1, 2, or 3 +* Type: null, 1, 2, 3, "1", "2", or "3" Set the lockfile format version to be used in package-lock.json and npm-shrinkwrap-json files. Possible options are: diff --git a/test/lib/utils/config/definitions.js b/test/lib/utils/config/definitions.js index 622e603bc75c6..15b43715f45bd 100644 --- a/test/lib/utils/config/definitions.js +++ b/test/lib/utils/config/definitions.js @@ -892,3 +892,12 @@ t.test('workspaces derived', t => { t.equal(flat.workspacesEnabled, false) t.end() }) + +t.test('lockfile version', t => { + const flat = {} + definitions['lockfile-version'].flatten('lockfile-version', { + 'lockfile-version': '3', + }, flat) + t.match(flat.lockfileVersion, 3, 'flattens to a number') + t.end() +})