Skip to content
Open
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
1 change: 1 addition & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ graph LR;
npmcli-arborist-->walk-up-path;
npmcli-config-->ci-info;
npmcli-config-->ini;
npmcli-config-->ms;
npmcli-config-->nopt;
npmcli-config-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-config-->npmcli-map-workspaces["@npmcli/map-workspaces"];
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8365,6 +8365,8 @@
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally we do not allow dependency changes from external PRs. This is for two reasons: first is for security, since those packages are bundled in node_modules it's best that we add those ourselves instead of try to audit the files that get added. Second, the addition of a dependency needs a discrete deps: commit so that it shows up in the changelog, and for most folks it's onerous for us to ask them to juggle commits in their PR like that.

Since this isn't introducing the dependency to node_modules itself we can verify the integrity here and allow it.

$ npm view ms@2.1.3 --json|npx json dist.integrity
sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

If you are willing to make the addition of ms to the config workspace a discrete deps: commit, this can be considered as-is and we'll make an exception for the dependency policy.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, sorry for that, wasn't 100% sure if the guideline still applied as ms is already used elsewhere in the CLI. Will split it out into a separate commit later today.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split the ms change into commit 9b1a390.

"inBundle": true,
"license": "MIT"
},
Expand Down Expand Up @@ -14736,6 +14738,7 @@
"@npmcli/package-json": "^7.0.0",
"ci-info": "^4.0.0",
"ini": "^6.0.0",
"ms": "^2.1.3",
"nopt": "^9.0.0",
"proc-log": "^6.0.0",
"semver": "^7.3.5",
Expand Down
4 changes: 3 additions & 1 deletion tap-snapshots/test/lib/docs.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,15 @@ config is given, this value will always be set to \`legacy\`.
#### \`before\`

* Default: null
* Type: null or Date
* Type: null, Date, or class RelativeDate {}

If passed to \`npm install\`, will rebuild the npm tree such that only
versions that were available **on or before** the given date are installed.
If there are no versions available for the current set of dependencies, the
command will error.

Accepts either a Date string or a relative date, e.g. "24h", "7d".

If the requested version is a \`dist-tag\` and the given tag does not pass the
\`--before\` filter, the most recent version less than or equal to that tag
will be used. For example, \`foo@latest\` might install \`foo@1.2\` even though
Expand Down
5 changes: 4 additions & 1 deletion workspaces/config/lib/definitions/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const {
Umask: { type: Umask },
url: { type: url },
path: { type: path },
relativeDate: { type: RelativeDate },
} = require('../type-defs.js')

// basic flattening function, just copy it over camelCase
Expand Down Expand Up @@ -231,13 +232,15 @@ const definitions = {
before: new Definition('before', {
default: null,
hint: '<date>',
type: [null, Date],
type: [null, Date, RelativeDate],
description: `
If passed to \`npm install\`, will rebuild the npm tree such that only
versions that were available **on or before** the given date are
installed. If there are no versions available for the current set of
dependencies, the command will error.

Accepts either a Date string or a relative date, e.g. "24h", "7d".

If the requested version is a \`dist-tag\` and the given tag does not
pass the \`--before\` filter, the most recent version less than or equal
to that tag will be used. For example, \`foo@latest\` might install
Expand Down
15 changes: 15 additions & 0 deletions workspaces/config/lib/type-defs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const nopt = require('nopt')
const ms = require('ms')

const { validate: validateUmask } = require('./umask.js')

class Umask {}
class Semver {}
class RelativeDate {}
const semverValid = require('semver/functions/valid')
const validateSemver = (data, k, val) => {
const valid = semverValid(val)
Expand All @@ -21,6 +23,14 @@ const validatePath = (data, k, val) => {
return noptValidatePath(data, k, val)
}

const validateRelativeDate = (data, k, val) => {
const valid = ms(val)
if (valid === undefined) {
return false
}
data[k] = new Date(Date.now() - valid)
}

// add descriptions so we can validate more usefully
module.exports = {
...nopt.typeDefs,
Expand All @@ -34,6 +44,11 @@ module.exports = {
validate: validateUmask,
description: 'octal number in range 0o000..0o777 (0..511)',
},
relativeDate: {
type: RelativeDate,
validate: validateRelativeDate,
description: 'valid relative date string e.g. "24h", "7d"',
},
url: {
...nopt.typeDefs.url,
description: 'full url with "http://"',
Expand Down
1 change: 1 addition & 0 deletions workspaces/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@npmcli/package-json": "^7.0.0",
"ci-info": "^4.0.0",
"ini": "^6.0.0",
"ms": "^2.1.3",
"nopt": "^9.0.0",
"proc-log": "^6.0.0",
"semver": "^7.3.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Object {
"before": Array [
null,
"valid Date string",
"valid relative date string e.g. \\"24h\\", \\"7d\\"",
],
"bin-links": Array [
"boolean value (true or false)",
Expand Down
5 changes: 5 additions & 0 deletions workspaces/config/test/type-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const {
path: {
validate: validatePath,
},
relativeDate: {
validate: validateRelativeDate,
},
} = typeDefs
const { resolve } = require('node:path')

Expand All @@ -20,3 +23,5 @@ t.equal(validatePath(d, 'somePath', null), false)
t.equal(validatePath(d, 'somePath', 1234), false)
t.equal(validatePath(d, 'somePath', 'false'), true)
t.equal(d.somePath, resolve('false'))
t.equal(validateRelativeDate(d, 'someDate', 'foobar'), false)
t.equal(validateRelativeDate(d, 'someDate', '1d'), undefined)
Loading