Skip to content

Commit

Permalink
parcel-query tool (#8478)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Dec 13, 2022
1 parent f8d3fc3 commit cafaeaf
Show file tree
Hide file tree
Showing 6 changed files with 921 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/dev/query/README.md
@@ -0,0 +1,42 @@
# `parcel-query`

A REPL to investigate the Parcel graphs in the cache ("offline", after the build).

## Installation

Clone and run `yarn`, then `cd packages/dev/query && yarn link` to make the `parcel-query` binary
globally available.

## Usage

Call `.help` to view a list of commands.

In a project root containing a `.parcel-cache` folder:

```sh
$ parcel-query
> .findBundleReason 27494aebac508bd8 TJbGI
# Asset is main entry of bundle: false
# Asset is an entry of bundle: false
# Incoming dependencies contained in the bundle:
{
id: '3fd182662e2a6fa9',
type: 'dependency',
value: {
specifier: '../../foo',
specifierType: 0,
...
```
In the `.getAsset 3Xzt5` variant, no quotes/parenthesis are
needed. Alternatively, you can use proper JS: `getAsset("3Xzt5")`.
The variables `assetGraph` and `bundleGraph` contain the deserialized objects.
For a single query, the command (which has to be a JS call) can be specified as a CLI parameter (the
disadvantage here is that the graphs have to be loaded on every call as opposed to once when
starting the REPL):
```sh
$ parcel-query 'findBundleReason("b0696febf20b57ce", "bNAUZ")'
```
17 changes: 17 additions & 0 deletions packages/dev/query/package.json
@@ -0,0 +1,17 @@
{
"name": "parcel-query",
"version": "2.8.1",
"private": true,
"bin": "src/bin.js",
"main": "src/index.js",
"dependencies": {
"@parcel/core": "2.8.1",
"@parcel/graph": "2.8.1",
"nullthrows": "^1.1.1",
"v8-compile-cache": "^2.0.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@parcel/babel-register": "2.8.1"
}
}
13 changes: 13 additions & 0 deletions packages/dev/query/src/bin.js
@@ -0,0 +1,13 @@
#!/usr/bin/env node

'use strict';

if (
process.env.PARCEL_BUILD_ENV !== 'production' ||
process.env.PARCEL_SELF_BUILD
) {
require('@parcel/babel-register');
}

require('v8-compile-cache');
require('./cli');

0 comments on commit cafaeaf

Please sign in to comment.