Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
- lint fix
- fix snapshot tests
  • Loading branch information
ruyadorno committed Jun 10, 2022
1 parent e645308 commit 4511d0d
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 129 deletions.
2 changes: 1 addition & 1 deletion smoke-tests/tap-snapshots/test/index.js.test.cjs
Expand Up @@ -26,7 +26,7 @@ All commands:
edit, exec, explain, explore, find-dupes, fund, get, help,
hook, init, install, install-ci-test, install-test, link,
ll, login, logout, ls, org, outdated, owner, pack, ping,
pkg, prefix, profile, prune, publish, rebuild, repo,
pkg, prefix, profile, prune, publish, query, rebuild, repo,
restart, root, run-script, search, set, set-script,
shrinkwrap, star, stars, start, stop, team, test, token,
uninstall, unpublish, unstar, update, version, view, whoami
Expand Down
24 changes: 12 additions & 12 deletions tap-snapshots/test/lib/commands/query.js.test.cjs
Expand Up @@ -13,8 +13,8 @@ exports[`test/lib/commands/query.js TAP global > should return expected linked n
"_id": "lorem@2.0.0",
"pkgid": "lorem@2.0.0",
"location": "node_modules/lorem",
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-global/globalDir/lib/node_modules/lorem",
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-global/globalDir/lib/node_modules/lorem",
"path": "{CWD}/test/lib/commands/tap-testdir-query-global/globalDir/lib/node_modules/lorem",
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-global/globalDir/lib/node_modules/lorem",
"resolved": null,
"isLink": false,
"isWorkspace": false
Expand All @@ -30,8 +30,8 @@ exports[`test/lib/commands/query.js TAP linked node > should return expected lin
"_id": "a@1.0.0",
"pkgid": "a@1.0.0",
"location": "a",
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-linked-node/a",
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-linked-node/a",
"path": "{CWD}/test/lib/commands/tap-testdir-query-linked-node/a",
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-linked-node/a",
"resolved": null,
"isLink": false,
"isWorkspace": false
Expand All @@ -49,26 +49,26 @@ exports[`test/lib/commands/query.js TAP simple query > should return expected ob
},
"pkgid": "project@",
"location": "",
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query",
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query",
"path": "{CWD}/test/lib/commands/tap-testdir-query-simple-query",
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-simple-query",
"resolved": null,
"isLink": false,
"isWorkspace": false
},
{
"pkgid": "a@",
"location": "node_modules/a",
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query/node_modules/a",
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query/node_modules/a",
"path": "{CWD}/test/lib/commands/tap-testdir-query-simple-query/node_modules/a",
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-simple-query/node_modules/a",
"resolved": null,
"isLink": false,
"isWorkspace": false
},
{
"pkgid": "b@",
"location": "node_modules/b",
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query/node_modules/b",
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-simple-query/node_modules/b",
"path": "{CWD}/test/lib/commands/tap-testdir-query-simple-query/node_modules/b",
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-simple-query/node_modules/b",
"resolved": null,
"isLink": false,
"isWorkspace": false
Expand All @@ -84,8 +84,8 @@ exports[`test/lib/commands/query.js TAP workspace query > should return expected
"_id": "c@1.0.0",
"pkgid": "c@1.0.0",
"location": "c",
"path": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-workspace-query/c",
"realpath": "/Users/ruyadorno/Documents/workspace/cli/main/test/lib/commands/tap-testdir-query-workspace-query/c",
"path": "{CWD}/test/lib/commands/tap-testdir-query-workspace-query/c",
"realpath": "{CWD}/test/lib/commands/tap-testdir-query-workspace-query/c",
"resolved": null,
"isLink": false,
"isWorkspace": true
Expand Down
9 changes: 9 additions & 0 deletions test/lib/commands/query.js
Expand Up @@ -3,6 +3,15 @@ const t = require('tap')
const { fake: mockNpm } = require('../../fixtures/mock-npm')
const Query = require('../../../lib/commands/query.js')

const redactCwd = (path) => {
const normalizePath = p => p
.replace(/\\+/g, '/')
.replace(/\r\n/g, '\n')
return normalizePath(path)
.replace(new RegExp(normalizePath(process.cwd()), 'g'), '{CWD}')
}

t.cleanSnapshot = (str) => redactCwd(str)
const config = {
global: false,
}
Expand Down
2 changes: 1 addition & 1 deletion workspaces/arborist/lib/node.js
Expand Up @@ -1450,7 +1450,7 @@ class Node {

// maybe accept both string value or array of strings
// seems to be what dom API does
querySelectorAll(query) {
querySelectorAll (query) {
return querySelectorAll(this, query)
}

Expand Down
30 changes: 17 additions & 13 deletions workspaces/arborist/lib/query-selector-all.js
Expand Up @@ -20,6 +20,7 @@ class Results {
this.#currentAstSelector = rootAstNode.nodes[0]
}

/* eslint-disable-next-line accessor-pairs */
set currentAstSelector (value) {
this.#currentAstSelector = value
}
Expand All @@ -35,7 +36,7 @@ class Results {
// when collecting results to a root astNode, we traverse the list of
// child selector nodes and collect all of their resulting arborist nodes
// into a single/flat Set of items, this ensures we also deduplicate items
collect(rootAstNode) {
collect (rootAstNode) {
const acc = new Set()
for (const n of rootAstNode.nodes) {
for (const node of this.#results.get(n)) {
Expand All @@ -51,25 +52,28 @@ const retrieveNodesFromParsedAst = async ({
initialItems,
inventory,
rootAstNode,
targetNode
targetNode,
}) => {
if (!rootAstNode.nodes) {
return new Set()
}

const ArboristNode = targetNode.constructor

let results = new Results(rootAstNode)
const results = new Results(rootAstNode)
let currentAstNode = rootAstNode
let prevAstNode = null
let pendingCombinator = null

results.currentResult = initialItems

// maps containing the logic to parse each of the supported css selectors
const attributeOperatorsMap = new Map(Object.entries({
'' ({ attribute, value, pkg }) { return Boolean(pkg[attribute]) },
'=' ({ attribute, value, pkg }) { return String(pkg[attribute] || '') === value },
'' ({ attribute, value, pkg }) {
return Boolean(pkg[attribute])
},
'=' ({ attribute, value, pkg }) {
return String(pkg[attribute] || '') === value
},
'~=' ({ attribute, value, pkg }) {
return (String(pkg[attribute] || '').match(/\w+/g) || []).includes(value)
},
Expand Down Expand Up @@ -318,8 +322,8 @@ const retrieveNodesFromParsedAst = async ({
return getInitialItems().filter(node =>
currentAstNode.pathValue
? minimatch(
node.realpath,
resolve(node.root.realpath, currentAstNode.pathValue)
node.realpath.replace(/\\+/g, '/'),
resolve(node.root.realpath, currentAstNode.pathValue).replace(/\\+/g, '/')
)
: true
)
Expand Down Expand Up @@ -356,7 +360,7 @@ const retrieveNodesFromParsedAst = async ({
// of filtered results, for example a query for `.workspace` actually
// means the same as `*.workspace` so we want to start with the full
// inventory if that's the first ast node we're reading but if it appears
// in the middle of a query it should respect the previous filtered
// in the middle of a query it should respect the previous filtered
// results, combinators are a special case in which we always want to
// have the complete inventory list in order to use the left-hand side
// ast node as a filter combined with the element on its right-hand side
Expand Down Expand Up @@ -410,7 +414,8 @@ const retrieveNodesFromParsedAst = async ({
attribute,
value,
pkg: node.package,
})})
})
})
results.currentResult =
await processPendingCombinator(prevResults, nextResults)
}
Expand Down Expand Up @@ -472,7 +477,7 @@ const retrieveNodesFromParsedAst = async ({
// to a function that parses it
const retrieveByType = new Map(Object.entries({
attribute,
'class': classType,
class: classType,
combinator,
id,
pseudo,
Expand All @@ -488,7 +493,6 @@ const retrieveNodesFromParsedAst = async ({
})

for (const nextAstNode of astNodeQueue) {
prevAstNode = currentAstNode
currentAstNode = nextAstNode

const updateResult =
Expand All @@ -509,7 +513,7 @@ const querySelectorAll = async (targetNode, query) => {
initialItems: inventory,
inventory,
rootAstNode,
targetNode
targetNode,
})

// returns nodes ordered by realpath
Expand Down

0 comments on commit 4511d0d

Please sign in to comment.