A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/npm/cli/commit/81a460f6e6317aca2288d16cda591aa6541540c6 below:

add package-lock-only mode to npm query · npm/cli@81a460f · GitHub

File tree Expand file treeCollapse file tree 5 files changed

+128

-2

lines changed

Filter options

Expand file treeCollapse file tree 5 files changed

+128

-2

lines changed Original file line number Diff line number Diff line change

@@ -133,6 +133,12 @@ npm query ":type(git)" | jq 'map(.name)' | xargs -I {} npm why {}

133 133

},

134 134

...

135 135

```

136 +

### Package lock only mode

137 + 138 +

If package-lock-only is enabled, only the information in the package

139 +

lock (or shrinkwrap) is loaded. This means that information from the

140 +

package.json files of your dependencies will not be included in the

141 +

result set (e.g. description, homepage, engines).

136 142 137 143

### Package lock only mode

138 144 Original file line number Diff line number Diff line change

@@ -2,6 +2,7 @@

2 2 3 3

const { resolve } = require('path')

4 4

const BaseCommand = require('../base-command.js')

5 +

const log = require('../utils/log-shim.js')

5 6 6 7

class QuerySelectorItem {

7 8

constructor (node) {

@@ -48,6 +49,7 @@ class Query extends BaseCommand {

48 49

'workspace',

49 50

'workspaces',

50 51

'include-workspace-root',

52 +

'package-lock-only',

51 53

]

52 54 53 55

get parsedResponse () {

@@ -64,7 +66,18 @@ class Query extends BaseCommand {

64 66

forceActual: true,

65 67

}

66 68

const arb = new Arborist(opts)

67 -

const tree = await arb.loadActual(opts)

69 +

let tree

70 +

if (this.npm.config.get('package-lock-only')) {

71 +

try {

72 +

tree = await arb.loadVirtual()

73 +

} catch (err) {

74 +

log.verbose('loadVirtual', err.stack)

75 +

/* eslint-disable-next-line max-len */

76 +

throw this.usageError('A package lock or shrinkwrap file is required in package-lock-only mode')

77 +

}

78 +

} else {

79 +

tree = await arb.loadActual(opts)

80 +

}

68 81

const items = await tree.querySelectorAll(args[0], this.npm.flatOptions)

69 82

this.buildResponse(items)

70 83 Original file line number Diff line number Diff line change

@@ -99,6 +99,54 @@ exports[`test/lib/commands/query.js TAP linked node > should return linked node

99 99

]

100 100

`

101 101 102 +

exports[`test/lib/commands/query.js TAP package-lock-only with package lock > should return valid response with only lock info 1`] = `

103 +

[

104 +

{

105 +

"name": "project",

106 +

"dependencies": {

107 +

"a": "^1.0.0"

108 +

},

109 +

"pkgid": "project@",

110 +

"location": "",

111 +

"path": "{CWD}/prefix",

112 +

"realpath": "{CWD}/prefix",

113 +

"resolved": null,

114 +

"from": [],

115 +

"to": [

116 +

"node_modules/a"

117 +

],

118 +

"dev": false,

119 +

"inBundle": false,

120 +

"deduped": false,

121 +

"overridden": false,

122 +

"queryContext": {}

123 +

},

124 +

{

125 +

"version": "1.2.3",

126 +

"resolved": "https://dummy.npmjs.org/a/-/a-1.2.3.tgz",

127 +

"integrity": "sha512-dummy",

128 +

"engines": {

129 +

"node": ">=14.17"

130 +

},

131 +

"name": "a",

132 +

"_id": "a@1.2.3",

133 +

"pkgid": "a@1.2.3",

134 +

"location": "node_modules/a",

135 +

"path": "{CWD}/prefix/node_modules/a",

136 +

"realpath": "{CWD}/prefix/node_modules/a",

137 +

"from": [

138 +

""

139 +

],

140 +

"to": [],

141 +

"dev": false,

142 +

"inBundle": false,

143 +

"deduped": false,

144 +

"overridden": false,

145 +

"queryContext": {}

146 +

}

147 +

]

148 +

`

149 + 102 150

exports[`test/lib/commands/query.js TAP recursive tree > should return everything in the tree, accounting for recursion 1`] = `

103 151

[

104 152

{

Original file line number Diff line number Diff line change

@@ -3797,7 +3797,7 @@ npm query <selector>

3797 3797

Options:

3798 3798

[-g|--global]

3799 3799

[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]

3800 -

[-ws|--workspaces] [--include-workspace-root]

3800 +

[-ws|--workspaces] [--include-workspace-root] [--package-lock-only]

3801 3801 3802 3802

Run "npm help query" for more info

3803 3803

@@ -3809,6 +3809,7 @@ npm query <selector>

3809 3809

#### \`workspace\`

3810 3810

#### \`workspaces\`

3811 3811

#### \`include-workspace-root\`

3812 +

#### \`package-lock-only\`

3812 3813

`

3813 3814 3814 3815

exports[`test/lib/docs.js TAP usage rebuild > must match snapshot 1`] = `

Original file line number Diff line number Diff line change

@@ -179,3 +179,61 @@ t.test('global', async t => {

179 179

await npm.exec('query', ['[name=lorem]'])

180 180

t.matchSnapshot(joinedOutput(), 'should return global package')

181 181

})

182 + 183 +

t.test('package-lock-only', t => {

184 +

t.test('no package lock', async t => {

185 +

const { npm } = await loadMockNpm(t, {

186 +

config: {

187 +

'package-lock-only': true,

188 +

},

189 +

prefixDir: {

190 +

'package.json': JSON.stringify({

191 +

name: 'project',

192 +

dependencies: {

193 +

a: '^1.0.0',

194 +

},

195 +

}),

196 +

},

197 +

})

198 +

await t.rejects(npm.exec('query', [':root, :root > *']), { code: 'EUSAGE' })

199 +

})

200 + 201 +

t.test('with package lock', async t => {

202 +

const { npm, joinedOutput } = await loadMockNpm(t, {

203 +

config: {

204 +

'package-lock-only': true,

205 +

},

206 +

prefixDir: {

207 +

'package.json': JSON.stringify({

208 +

name: 'project',

209 +

dependencies: {

210 +

a: '^1.0.0',

211 +

},

212 +

}),

213 +

'package-lock.json': JSON.stringify({

214 +

name: 'project',

215 +

lockfileVersion: 3,

216 +

requires: true,

217 +

packages: {

218 +

'': {

219 +

dependencies: {

220 +

a: '^1.0.0',

221 +

},

222 +

},

223 +

'node_modules/a': {

224 +

version: '1.2.3',

225 +

resolved: 'https://dummy.npmjs.org/a/-/a-1.2.3.tgz',

226 +

integrity: 'sha512-dummy',

227 +

engines: {

228 +

node: '>=14.17',

229 +

},

230 +

},

231 +

},

232 +

}),

233 +

},

234 +

})

235 +

await npm.exec('query', ['*'])

236 +

t.matchSnapshot(joinedOutput(), 'should return valid response with only lock info')

237 +

})

238 +

t.end()

239 +

})

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4