Skip to content

Commit 4511d0d

Browse files
committed
fix: ci
- lint fix - fix snapshot tests
1 parent e645308 commit 4511d0d

File tree

6 files changed

+141
-129
lines changed

6 files changed

+141
-129
lines changed

smoke-tests/tap-snapshots/test/index.js.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ All commands:
2626
edit, exec, explain, explore, find-dupes, fund, get, help,
2727
hook, init, install, install-ci-test, install-test, link,
2828
ll, login, logout, ls, org, outdated, owner, pack, ping,
29-
pkg, prefix, profile, prune, publish, rebuild, repo,
29+
pkg, prefix, profile, prune, publish, query, rebuild, repo,
3030
restart, root, run-script, search, set, set-script,
3131
shrinkwrap, star, stars, start, stop, team, test, token,
3232
uninstall, unpublish, unstar, update, version, view, whoami

tap-snapshots/test/lib/commands/query.js.test.cjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ exports[`test/lib/commands/query.js TAP global > should return expected linked n
1313
1414
"pkgid": "[email protected]",
1515
"location": "node_modules/lorem",
16-
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-global/globalDir/lib/node_modules/lorem",
17-
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-global/globalDir/lib/node_modules/lorem",
16+
"path": "{CWD}/test/lib/commands/tap-testdir-query-global/globalDir/lib/node_modules/lorem",
17+
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-global/globalDir/lib/node_modules/lorem",
1818
"resolved": null,
1919
"isLink": false,
2020
"isWorkspace": false
@@ -30,8 +30,8 @@ exports[`test/lib/commands/query.js TAP linked node > should return expected lin
3030
3131
"pkgid": "[email protected]",
3232
"location": "a",
33-
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-linked-node/a",
34-
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-linked-node/a",
33+
"path": "{CWD}/test/lib/commands/tap-testdir-query-linked-node/a",
34+
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-linked-node/a",
3535
"resolved": null,
3636
"isLink": false,
3737
"isWorkspace": false
@@ -49,26 +49,26 @@ exports[`test/lib/commands/query.js TAP simple query > should return expected ob
4949
},
5050
"pkgid": "project@",
5151
"location": "",
52-
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query",
53-
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query",
52+
"path": "{CWD}/test/lib/commands/tap-testdir-query-simple-query",
53+
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-simple-query",
5454
"resolved": null,
5555
"isLink": false,
5656
"isWorkspace": false
5757
},
5858
{
5959
"pkgid": "a@",
6060
"location": "node_modules/a",
61-
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query/node_modules/a",
62-
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query/node_modules/a",
61+
"path": "{CWD}/test/lib/commands/tap-testdir-query-simple-query/node_modules/a",
62+
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-simple-query/node_modules/a",
6363
"resolved": null,
6464
"isLink": false,
6565
"isWorkspace": false
6666
},
6767
{
6868
"pkgid": "b@",
6969
"location": "node_modules/b",
70-
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query/node_modules/b",
71-
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query/node_modules/b",
70+
"path": "{CWD}/test/lib/commands/tap-testdir-query-simple-query/node_modules/b",
71+
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-simple-query/node_modules/b",
7272
"resolved": null,
7373
"isLink": false,
7474
"isWorkspace": false
@@ -84,8 +84,8 @@ exports[`test/lib/commands/query.js TAP workspace query > should return expected
8484
8585
"pkgid": "[email protected]",
8686
"location": "c",
87-
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-workspace-query/c",
88-
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-workspace-query/c",
87+
"path": "{CWD}/test/lib/commands/tap-testdir-query-workspace-query/c",
88+
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-workspace-query/c",
8989
"resolved": null,
9090
"isLink": false,
9191
"isWorkspace": true

test/lib/commands/query.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ const t = require('tap')
33
const { fake: mockNpm } = require('../../fixtures/mock-npm')
44
const Query = require('../../../lib/commands/query.js')
55

6+
const redactCwd = (path) => {
7+
const normalizePath = p => p
8+
.replace(/\\+/g, '/')
9+
.replace(/\r\n/g, '\n')
10+
return normalizePath(path)
11+
.replace(new RegExp(normalizePath(process.cwd()), 'g'), '{CWD}')
12+
}
13+
14+
t.cleanSnapshot = (str) => redactCwd(str)
615
const config = {
716
global: false,
817
}

workspaces/arborist/lib/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ class Node {
14501450

14511451
// maybe accept both string value or array of strings
14521452
// seems to be what dom API does
1453-
querySelectorAll(query) {
1453+
querySelectorAll (query) {
14541454
return querySelectorAll(this, query)
14551455
}
14561456

workspaces/arborist/lib/query-selector-all.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Results {
2020
this.#currentAstSelector = rootAstNode.nodes[0]
2121
}
2222

23+
/* eslint-disable-next-line accessor-pairs */
2324
set currentAstSelector (value) {
2425
this.#currentAstSelector = value
2526
}
@@ -35,7 +36,7 @@ class Results {
3536
// when collecting results to a root astNode, we traverse the list of
3637
// child selector nodes and collect all of their resulting arborist nodes
3738
// into a single/flat Set of items, this ensures we also deduplicate items
38-
collect(rootAstNode) {
39+
collect (rootAstNode) {
3940
const acc = new Set()
4041
for (const n of rootAstNode.nodes) {
4142
for (const node of this.#results.get(n)) {
@@ -51,25 +52,28 @@ const retrieveNodesFromParsedAst = async ({
5152
initialItems,
5253
inventory,
5354
rootAstNode,
54-
targetNode
55+
targetNode,
5556
}) => {
5657
if (!rootAstNode.nodes) {
5758
return new Set()
5859
}
5960

6061
const ArboristNode = targetNode.constructor
6162

62-
let results = new Results(rootAstNode)
63+
const results = new Results(rootAstNode)
6364
let currentAstNode = rootAstNode
64-
let prevAstNode = null
6565
let pendingCombinator = null
6666

6767
results.currentResult = initialItems
6868

6969
// maps containing the logic to parse each of the supported css selectors
7070
const attributeOperatorsMap = new Map(Object.entries({
71-
'' ({ attribute, value, pkg }) { return Boolean(pkg[attribute]) },
72-
'=' ({ attribute, value, pkg }) { return String(pkg[attribute] || '') === value },
71+
'' ({ attribute, value, pkg }) {
72+
return Boolean(pkg[attribute])
73+
},
74+
'=' ({ attribute, value, pkg }) {
75+
return String(pkg[attribute] || '') === value
76+
},
7377
'~=' ({ attribute, value, pkg }) {
7478
return (String(pkg[attribute] || '').match(/\w+/g) || []).includes(value)
7579
},
@@ -318,8 +322,8 @@ const retrieveNodesFromParsedAst = async ({
318322
return getInitialItems().filter(node =>
319323
currentAstNode.pathValue
320324
? minimatch(
321-
node.realpath,
322-
resolve(node.root.realpath, currentAstNode.pathValue)
325+
node.realpath.replace(/\\+/g, '/'),
326+
resolve(node.root.realpath, currentAstNode.pathValue).replace(/\\+/g, '/')
323327
)
324328
: true
325329
)
@@ -356,7 +360,7 @@ const retrieveNodesFromParsedAst = async ({
356360
// of filtered results, for example a query for `.workspace` actually
357361
// means the same as `*.workspace` so we want to start with the full
358362
// inventory if that's the first ast node we're reading but if it appears
359-
// in the middle of a query it should respect the previous filtered
363+
// in the middle of a query it should respect the previous filtered
360364
// results, combinators are a special case in which we always want to
361365
// have the complete inventory list in order to use the left-hand side
362366
// ast node as a filter combined with the element on its right-hand side
@@ -410,7 +414,8 @@ const retrieveNodesFromParsedAst = async ({
410414
attribute,
411415
value,
412416
pkg: node.package,
413-
})})
417+
})
418+
})
414419
results.currentResult =
415420
await processPendingCombinator(prevResults, nextResults)
416421
}
@@ -472,7 +477,7 @@ const retrieveNodesFromParsedAst = async ({
472477
// to a function that parses it
473478
const retrieveByType = new Map(Object.entries({
474479
attribute,
475-
'class': classType,
480+
class: classType,
476481
combinator,
477482
id,
478483
pseudo,
@@ -488,7 +493,6 @@ const retrieveNodesFromParsedAst = async ({
488493
})
489494

490495
for (const nextAstNode of astNodeQueue) {
491-
prevAstNode = currentAstNode
492496
currentAstNode = nextAstNode
493497

494498
const updateResult =
@@ -509,7 +513,7 @@ const querySelectorAll = async (targetNode, query) => {
509513
initialItems: inventory,
510514
inventory,
511515
rootAstNode,
512-
targetNode
516+
targetNode,
513517
})
514518

515519
// returns nodes ordered by realpath

0 commit comments

Comments
 (0)