Skip to content

Commit cafaeaf

Browse files
authored
parcel-query tool (#8478)
1 parent f8d3fc3 commit cafaeaf

File tree

6 files changed

+921
-0
lines changed

6 files changed

+921
-0
lines changed

packages/dev/query/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# `parcel-query`
2+
3+
A REPL to investigate the Parcel graphs in the cache ("offline", after the build).
4+
5+
## Installation
6+
7+
Clone and run `yarn`, then `cd packages/dev/query && yarn link` to make the `parcel-query` binary
8+
globally available.
9+
10+
## Usage
11+
12+
Call `.help` to view a list of commands.
13+
14+
In a project root containing a `.parcel-cache` folder:
15+
16+
```sh
17+
$ parcel-query
18+
> .findBundleReason 27494aebac508bd8 TJbGI
19+
# Asset is main entry of bundle: false
20+
# Asset is an entry of bundle: false
21+
# Incoming dependencies contained in the bundle:
22+
{
23+
id: '3fd182662e2a6fa9',
24+
type: 'dependency',
25+
value: {
26+
specifier: '../../foo',
27+
specifierType: 0,
28+
...
29+
```
30+
31+
In the `.getAsset 3Xzt5` variant, no quotes/parenthesis are
32+
needed. Alternatively, you can use proper JS: `getAsset("3Xzt5")`.
33+
34+
The variables `assetGraph` and `bundleGraph` contain the deserialized objects.
35+
36+
For a single query, the command (which has to be a JS call) can be specified as a CLI parameter (the
37+
disadvantage here is that the graphs have to be loaded on every call as opposed to once when
38+
starting the REPL):
39+
40+
```sh
41+
$ parcel-query 'findBundleReason("b0696febf20b57ce", "bNAUZ")'
42+
```

packages/dev/query/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "parcel-query",
3+
"version": "2.8.1",
4+
"private": true,
5+
"bin": "src/bin.js",
6+
"main": "src/index.js",
7+
"dependencies": {
8+
"@parcel/core": "2.8.1",
9+
"@parcel/graph": "2.8.1",
10+
"nullthrows": "^1.1.1",
11+
"v8-compile-cache": "^2.0.0"
12+
},
13+
"devDependencies": {
14+
"@babel/core": "^7.0.0",
15+
"@parcel/babel-register": "2.8.1"
16+
}
17+
}

packages/dev/query/src/bin.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
if (
6+
process.env.PARCEL_BUILD_ENV !== 'production' ||
7+
process.env.PARCEL_SELF_BUILD
8+
) {
9+
require('@parcel/babel-register');
10+
}
11+
12+
require('v8-compile-cache');
13+
require('./cli');

0 commit comments

Comments
 (0)