Skip to content

Commit

Permalink
Publish bundle-stats-cli and parcel-query (#9431)
Browse files Browse the repository at this point in the history
* Publish bundle-stats-cli and parcel-query

* Add parcel-query and bundle-stats to gulpfile

* Rename to @parcel/query, add parcel-query bin

* Add condition to bundle-stats bin

* Update parcel-query dep in bundle-stats

* Update packages/dev/bundle-stats-cli/package.json

Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>

* Move bin.js to src

* Add deep imports for bundle-stats

* Add deep imports for @parcel/query

* Fix flow errors in bundle-stats

* Fix flow errors in @parcel/query

* Fix types in deep-imports.js

* Fix types in deep-imports.js

---------

Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
  • Loading branch information
thebriando and mischnic committed Dec 13, 2023
1 parent bd40574 commit aff2c16
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 51 deletions.
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const paths = {
packageJson: [
'packages/core/parcel/package.json',
'packages/utils/create-react-app/package.json',
'packages/dev/query/package.json',
'packages/dev/bundle-stats-cli/package.json',
],
packages: 'packages/',
};
Expand Down
12 changes: 0 additions & 12 deletions packages/dev/bundle-stats-cli/bin.js

This file was deleted.

19 changes: 15 additions & 4 deletions packages/dev/bundle-stats-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
{
"name": "@parcel/bundle-stats-cli",
"name": "@parcel/bundle-stats",
"version": "2.10.3",
"private": true,
"license": "MIT",
"publishConfig": {
"access": "public"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/parcel"
},
"repository": {
"type": "git",
"url": "https://github.com/parcel-bundler/parcel.git"
},
"main": "lib/cli.js",
"source": "src/cli.js",
"bin": {
"parcel-bundle-stats": "bin.js"
"parcel-bundle-stats": "src/bin.js"
},
"engines": {
"node": ">= 12.0.0",
Expand All @@ -16,7 +27,7 @@
"@parcel/reporter-bundle-stats": "2.10.3",
"@parcel/utils": "2.10.3",
"commander": "^7.0.0",
"parcel-query": "2.10.3"
"@parcel/query": "2.10.3"
},
"devDependencies": {
"@parcel/babel-register": "2.10.3",
Expand Down
14 changes: 14 additions & 0 deletions packages/dev/bundle-stats-cli/src/bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /usr/bin/env node

'use strict';

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

const cli = require('./cli');

cli.command.parse();
12 changes: 6 additions & 6 deletions packages/dev/bundle-stats-cli/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/* eslint-disable no-console, monorepo/no-internal-import */
// @flow strict-local

import type {PackagedBundle} from '@parcel/types';
import type {ParcelOptions} from '@parcel/core/src/types';
import type {commander$Command} from 'commander';

// $FlowFixMe[untyped-import]
import {version} from '../package.json';

import commander from 'commander';
import fs from 'fs';
import path from 'path';

import {DefaultMap} from '@parcel/utils';

import {loadGraphs} from 'parcel-query/src/index.js';
import {getBundleStats} from '@parcel/reporter-bundle-stats/src/BundleStatsReporter';
import {PackagedBundle as PackagedBundleClass} from '@parcel/core/src/public/Bundle';
import type {commander$Command} from 'commander';
const {
loadGraphs,
getBundleStats,
PackagedBundleClass,
} = require('./deep-imports.js');

async function run({cacheDir, outDir}) {
// 1. load bundle graph and info via parcel~query
Expand Down
30 changes: 30 additions & 0 deletions packages/dev/bundle-stats-cli/src/deep-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @flow
/* eslint-disable monorepo/no-internal-import */
import typeof {loadGraphs} from '@parcel/query/src/index.js';
import typeof {getBundleStats} from '@parcel/reporter-bundle-stats/src/BundleStatsReporter';
import typeof {PackagedBundle as PackagedBundleClass} from '@parcel/core/src/public/Bundle';

module.exports = ((process.env.PARCEL_BUILD_ENV === 'production'
? {
// Split up require specifier to outsmart packages/dev/babel-register/babel-plugin-module-translate.js
// $FlowFixMe(unsupported-syntax)
loadGraphs: require('@parcel/query' + '/lib/index.js').loadGraphs,
// $FlowFixMe(unsupported-syntax)
getBundleStats: require('@parcel/reporter-bundle-stats' +
'/lib/BundleStatsReporter.js').getBundleStats,
// $FlowFixMe(unsupported-syntax)
PackagedBundleClass: require('@parcel/core' + '/lib/public/Bundle.js')
.PackagedBundle,
}
: {
loadGraphs: require('@parcel/query/src/index.js').loadGraphs,
getBundleStats:
require('@parcel/reporter-bundle-stats/src/BundleStatsReporter.js')
.getBundleStats,
PackagedBundleClass: require('@parcel/core/src/public/Bundle.js')
.PackagedBundle,
}): {|
loadGraphs: loadGraphs,
getBundleStats: getBundleStats,
PackagedBundleClass: PackagedBundleClass,
|});
19 changes: 16 additions & 3 deletions packages/dev/query/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
{
"name": "parcel-query",
"name": "@parcel/query",
"version": "2.10.3",
"private": true,
"bin": "src/bin.js",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/parcel"
},
"repository": {
"type": "git",
"url": "https://github.com/parcel-bundler/parcel.git"
},
"bin": {
"parcel-query": "src/bin.js"
},
"main": "src/index.js",
"dependencies": {
"@parcel/cache": "2.10.3",
Expand Down
13 changes: 7 additions & 6 deletions packages/dev/query/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @flow strict-local
/* eslint-disable no-console, monorepo/no-internal-import */
import type {ContentGraph, ContentKey, NodeId} from '@parcel/graph';
import type {BundleGraphEdgeType} from '@parcel/core/src/BundleGraph';
import type {AssetGraphNode, BundleGraphNode} from '@parcel/core/src/types';
import type {BundleGraphEdgeType} from '@parcel/core/src/BundleGraph.js';

import path from 'path';
import fs from 'fs';
Expand All @@ -11,16 +11,17 @@ import os from 'os';
import nullthrows from 'nullthrows';
import invariant from 'assert';
import {serialize} from 'v8';

// $FlowFixMe
import {table} from 'table';

import {fromProjectPathRelative} from '@parcel/core/src/projectPath';
import {bundleGraphEdgeTypes} from '@parcel/core/src/BundleGraph.js';
import {Priority} from '@parcel/core/src/types';

import {loadGraphs} from './index.js';

const {
BundleGraph: {bundleGraphEdgeTypes: bundleGraphEdgeTypes},
Priority,
fromProjectPathRelative,
} = require('./deep-imports.js');

export async function run(input: string[]) {
let args = input;
let cacheDir = path.join(process.cwd(), '.parcel-cache');
Expand Down
62 changes: 44 additions & 18 deletions packages/dev/query/src/deep-imports.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,59 @@
// @flow
/* eslint-disable monorepo/no-internal-import */
import typeof AssetGraph from '@parcel/core/src/AssetGraph.js';
import typeof BundleGraph from '@parcel/core/src/BundleGraph.js';
import typeof BundleGraph, {
bundleGraphEdgeTypes,
} from '@parcel/core/src/BundleGraph.js';
import typeof RequestTracker, {
RequestGraph,
} from '@parcel/core/src/RequestTracker.js';
import {typeof requestGraphEdgeTypes} from '@parcel/core/src/RequestTracker.js';
import typeof {requestGraphEdgeTypes} from '@parcel/core/src/RequestTracker.js';
import typeof {LMDBCache} from '@parcel/cache/src/LMDBCache.js';
import typeof {Priority} from '@parcel/core/src/types.js';
import typeof {fromProjectPathRelative} from '@parcel/core/src/projectPath.js';

module.exports = ((process.env.PARCEL_BUILD_ENV === 'production'
? {
// Split up require specifier to outsmart packages/dev/babel-register/babel-plugin-module-translate.js
// $FlowFixMe(unsupported-syntax)
AssetGraph: require('@parcel/core' + '/lib/AssetGraph.js').default,
// $FlowFixMe(unsupported-syntax)
BundleGraph: require('@parcel/core' + '/lib/BundleGraph.js').default,
// $FlowFixMe(unsupported-syntax)
RequestTracker: require('@parcel/core' + '/lib/RequestTracker.js'),
}
: {
AssetGraph: require('@parcel/core/src/AssetGraph.js').default,
BundleGraph: require('@parcel/core/src/BundleGraph.js').default,
RequestTracker: require('@parcel/core/src/RequestTracker.js'),
}): {|
const v =
process.env.PARCEL_BUILD_ENV === 'production'
? {
// Split up require specifier to outsmart packages/dev/babel-register/babel-plugin-module-translate.js
// $FlowFixMe(unsupported-syntax)
AssetGraph: require('@parcel/core' + '/lib/AssetGraph.js').default,
// $FlowFixMe(unsupported-syntax)
BundleGraph: require('@parcel/core' + '/lib/BundleGraph.js'),
// $FlowFixMe(unsupported-syntax)
RequestTracker: require('@parcel/core' + '/lib/RequestTracker.js'),
// $FlowFixMe(unsupported-syntax)
LMDBCache: require('@parcel/cache' + '/lib/LMDBCache.js').LMDBCache,
// $FlowFixMe(unsupported-syntax)
Priority: require('@parcel/core' + '/lib/types.js').Priority,
// $FlowFixMe(unsupported-syntax)
fromProjectPathRelative: require('@parcel/core' + '/lib/projectPath.js')
.fromProjectPathRelative,
}
: {
AssetGraph: require('@parcel/core/src/AssetGraph.js').default,
BundleGraph: require('@parcel/core/src/BundleGraph.js'),
RequestTracker: require('@parcel/core/src/RequestTracker.js'),
LMDBCache: require('@parcel/cache/src/LMDBCache.js').LMDBCache,
Priority: require('@parcel/core/src/types.js').Priority,
fromProjectPathRelative: require('@parcel/core/src/projectPath.js')
.fromProjectPathRelative,
};

module.exports = (v: {|
AssetGraph: AssetGraph,
BundleGraph: BundleGraph,
BundleGraph: {
default: BundleGraph,
bundleGraphEdgeTypes: bundleGraphEdgeTypes,
...
},
RequestTracker: {
default: RequestTracker,
RequestGraph: RequestGraph,
requestGraphEdgeTypes: requestGraphEdgeTypes,
...
},
LMDBCache: LMDBCache,
Priority: Priority,
fromProjectPathRelative: fromProjectPathRelative,
|});
4 changes: 2 additions & 2 deletions packages/dev/query/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import path from 'path';
import v8 from 'v8';
import nullthrows from 'nullthrows';
import invariant from 'assert';
import {LMDBCache} from '@parcel/cache/src/LMDBCache';

const {
AssetGraph,
BundleGraph,
BundleGraph: {default: BundleGraph},
RequestTracker: {
default: RequestTracker,
RequestGraph,
requestGraphEdgeTypes,
},
LMDBCache,
} = require('./deep-imports.js');

export async function loadGraphs(cacheDir: string): Promise<{|
Expand Down

0 comments on commit aff2c16

Please sign in to comment.