A RetroSearch Logo

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

Search Query:

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

use omit when checking ideal tree engine (#8372) · npm/cli@f163d01 · GitHub

File tree Expand file treeCollapse file tree 12 files changed

+205

-46

lines changed

Filter options

Expand file treeCollapse file tree 12 files changed

+205

-46

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

@@ -192,9 +192,11 @@ module.exports = cls => class IdealTreeBuilder extends cls {

192 192

}

193 193 194 194

async #checkEngineAndPlatform () {

195 -

const { engineStrict, npmVersion, nodeVersion } = this.options

195 +

const { engineStrict, npmVersion, nodeVersion, omit = [] } = this.options

196 +

const omitSet = new Set(omit)

197 + 196 198

for (const node of this.idealTree.inventory.values()) {

197 -

if (!node.optional) {

199 +

if (!node.optional && !node.shouldOmit(omitSet)) {

198 200

try {

199 201

// if devEngines is present in the root node we ignore the engines check

200 202

if (!(node.isRoot && node.package.devEngines)) {

Original file line number Diff line number Diff line change

@@ -84,9 +84,7 @@ module.exports = cls => class Reifier extends cls {

84 84

#bundleUnpacked = new Set() // the nodes we unpack to read their bundles

85 85

#dryRun

86 86

#nmValidated = new Set()

87 -

#omitDev

88 -

#omitPeer

89 -

#omitOptional

87 +

#omit

90 88

#retiredPaths = {}

91 89

#retiredUnchanged = {}

92 90

#savePrefix

@@ -110,10 +108,7 @@ module.exports = cls => class Reifier extends cls {

110 108

throw er

111 109

}

112 110 113 -

const omit = new Set(options.omit || [])

114 -

this.#omitDev = omit.has('dev')

115 -

this.#omitOptional = omit.has('optional')

116 -

this.#omitPeer = omit.has('peer')

111 +

this.#omit = new Set(options.omit)

117 112 118 113

// start tracker block

119 114

this.addTracker('reify')

@@ -562,12 +557,11 @@ module.exports = cls => class Reifier extends cls {

562 557

// adding to the trash list will skip reifying, and delete them

563 558

// if they are currently in the tree and otherwise untouched.

564 559

[_addOmitsToTrashList] () {

565 -

if (!this.#omitDev && !this.#omitOptional && !this.#omitPeer) {

560 +

if (!this.#omit.size) {

566 561

return

567 562

}

568 563 569 564

const timeEnd = time.start('reify:trashOmits')

570 - 571 565

for (const node of this.idealTree.inventory.values()) {

572 566

const { top } = node

573 567

@@ -583,12 +577,7 @@ module.exports = cls => class Reifier extends cls {

583 577

}

584 578 585 579

// omit node if the dep type matches any omit flags that were set

586 -

if (

587 -

node.peer && this.#omitPeer ||

588 -

node.dev && this.#omitDev ||

589 -

node.optional && this.#omitOptional ||

590 -

node.devOptional && this.#omitOptional && this.#omitDev

591 -

) {

580 +

if (node.shouldOmit(this.#omit)) {

592 581

this[_addNodeToTrashList](node)

593 582

}

594 583

}

Original file line number Diff line number Diff line change

@@ -148,7 +148,7 @@ class AuditReport extends Map {

148 148

if (!seen.has(k)) {

149 149

const p = []

150 150

for (const node of this.tree.inventory.query('packageName', name)) {

151 -

if (!shouldAudit(node, this[_omit], this.filterSet)) {

151 +

if (!this.shouldAudit(node)) {

152 152

continue

153 153

}

154 154

@@ -282,7 +282,7 @@ class AuditReport extends Map {

282 282 283 283

const timeEnd = time.start('auditReport:getReport')

284 284

try {

285 -

const body = prepareBulkData(this.tree, this[_omit], this.filterSet)

285 +

const body = this.prepareBulkData()

286 286

log.silly('audit', 'bulk request', body)

287 287 288 288

// no sense asking if we don't have anything to audit,

@@ -309,37 +309,33 @@ class AuditReport extends Map {

309 309

timeEnd()

310 310

}

311 311

}

312 -

}

313 312 314 -

// return true if we should audit this one

315 -

const shouldAudit = (node, omit, filterSet) =>

316 -

!node.version ? false

317 -

: node.isRoot ? false

318 -

: filterSet && filterSet.size !== 0 && !filterSet.has(node) ? false

319 -

: omit.size === 0 ? true

320 -

: !( // otherwise, just ensure we're not omitting this one

321 -

node.dev && omit.has('dev') ||

322 -

node.optional && omit.has('optional') ||

323 -

node.devOptional && omit.has('dev') && omit.has('optional') ||

324 -

node.peer && omit.has('peer')

325 -

)

326 - 327 -

const prepareBulkData = (tree, omit, filterSet) => {

328 -

const payload = {}

329 -

for (const name of tree.inventory.query('packageName')) {

330 -

const set = new Set()

331 -

for (const node of tree.inventory.query('packageName', name)) {

332 -

if (!shouldAudit(node, omit, filterSet)) {

333 -

continue

334 -

}

313 +

// return true if we should audit this one

314 +

shouldAudit (node) {

315 +

return !node.version ? false

316 +

: node.isRoot ? false

317 +

: this.filterSet && this.filterSet.size !== 0 && !this.filterSet.has(node) ? false

318 +

: this[_omit].size === 0 ? true

319 +

: !node.shouldOmit(this[_omit])

320 +

}

335 321 336 -

set.add(node.version)

337 -

}

338 -

if (set.size) {

339 -

payload[name] = [...set]

322 +

prepareBulkData () {

323 +

const payload = {}

324 +

for (const name of this.tree.inventory.query('packageName')) {

325 +

const set = new Set()

326 +

for (const node of this.tree.inventory.query('packageName', name)) {

327 +

if (!this.shouldAudit(node)) {

328 +

continue

329 +

}

330 + 331 +

set.add(node.version)

332 +

}

333 +

if (set.size) {

334 +

payload[name] = [...set]

335 +

}

340 336

}

337 +

return payload

341 338

}

342 -

return payload

343 339

}

344 340 345 341

module.exports = AuditReport

Original file line number Diff line number Diff line change

@@ -489,6 +489,15 @@ class Node {

489 489

return false

490 490

}

491 491 492 +

shouldOmit (omitSet) {

493 +

return (

494 +

this.peer && omitSet.has('peer') ||

495 +

this.dev && omitSet.has('dev') ||

496 +

this.optional && omitSet.has('optional') ||

497 +

this.devOptional && omitSet.has('optional') && omitSet.has('dev')

498 +

)

499 +

}

500 + 492 501

getBundler (path = []) {

493 502

// made a cycle, definitely not bundled!

494 503

if (path.includes(this)) {

Original file line number Diff line number Diff line change

@@ -4091,3 +4091,47 @@ t.test('should take devEngines in account', async t => {

4091 4091

const tree = await buildIdeal(path)

4092 4092

t.matchSnapshot(String(tree.meta))

4093 4093

})

4094 + 4095 +

t.test('engine checking respects omit flags', async t => {

4096 +

const testFixture = resolve(fixtures, 'engine-omit-test')

4097 + 4098 +

t.test('fail on engine mismatch in devDependencies without omit=dev', async t => {

4099 +

await t.rejects(buildIdeal(testFixture, {

4100 +

nodeVersion: '12.18.4',

4101 +

engineStrict: true,

4102 +

}),

4103 +

{ code: 'EBADENGINE' },

4104 +

'should fail with EBADENGINE when devDependencies have engine mismatch'

4105 +

)

4106 +

})

4107 + 4108 +

t.test('skip engine check for devDependencies with omit=dev', async t => {

4109 +

// This should NOT throw an EBADENGINE error

4110 +

await buildIdeal(testFixture, {

4111 +

nodeVersion: '12.18.4',

4112 +

engineStrict: true,

4113 +

omit: ['dev'],

4114 +

})

4115 +

t.pass('should succeed when omitting dev dependencies with engine mismatches')

4116 +

})

4117 + 4118 +

t.test('skip engine check for optionalDependencies with omit=optional', async t => {

4119 +

const optionalFixture = resolve(fixtures, 'optional-engine-omit-test')

4120 +

await buildIdeal(optionalFixture, {

4121 +

nodeVersion: '12.18.4',

4122 +

engineStrict: true,

4123 +

omit: ['optional'],

4124 +

})

4125 +

t.pass('should succeed when omitting optional dependencies with engine mismatches')

4126 +

})

4127 + 4128 +

t.test('skip engine check for peerDependencies with omit=peer', async t => {

4129 +

const peerFixture = resolve(fixtures, 'peer-engine-omit-test')

4130 +

await buildIdeal(peerFixture, {

4131 +

nodeVersion: '12.18.4',

4132 +

engineStrict: true,

4133 +

omit: ['peer'],

4134 +

})

4135 +

t.pass('should succeed when omitting peer dependencies with engine mismatches')

4136 +

})

4137 +

})

Original file line number Diff line number Diff line change

@@ -0,0 +1,7 @@

1 +

{

2 +

"name": "engine-omit-test",

3 +

"version": "1.0.0",

4 +

"devDependencies": {

5 +

"strict-engine-dev": "1.0.0"

6 +

}

7 +

}

Original file line number Diff line number Diff line change

@@ -0,0 +1,7 @@

1 +

{

2 +

"name": "optional-engine-omit-test",

3 +

"version": "1.0.0",

4 +

"optionalDependencies": {

5 +

"strict-engine-optional": "1.0.0"

6 +

}

7 +

}

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