From aff2c16b1e7a8bc1f68a10f7ce2c5aa83471337e Mon Sep 17 00:00:00 2001 From: Brian Do Date: Wed, 13 Dec 2023 12:07:23 -0800 Subject: [PATCH] Publish bundle-stats-cli and parcel-query (#9431) * 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> --- gulpfile.js | 2 + packages/dev/bundle-stats-cli/bin.js | 12 ---- packages/dev/bundle-stats-cli/package.json | 19 ++++-- packages/dev/bundle-stats-cli/src/bin.js | 14 +++++ packages/dev/bundle-stats-cli/src/cli.js | 12 ++-- .../dev/bundle-stats-cli/src/deep-imports.js | 30 +++++++++ packages/dev/query/package.json | 19 +++++- packages/dev/query/src/cli.js | 13 ++-- packages/dev/query/src/deep-imports.js | 62 +++++++++++++------ packages/dev/query/src/index.js | 4 +- 10 files changed, 136 insertions(+), 51 deletions(-) delete mode 100755 packages/dev/bundle-stats-cli/bin.js create mode 100755 packages/dev/bundle-stats-cli/src/bin.js create mode 100644 packages/dev/bundle-stats-cli/src/deep-imports.js diff --git a/gulpfile.js b/gulpfile.js index e67919724f5..4b524e694ad 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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/', }; diff --git a/packages/dev/bundle-stats-cli/bin.js b/packages/dev/bundle-stats-cli/bin.js deleted file mode 100755 index 24263e2c0de..00000000000 --- a/packages/dev/bundle-stats-cli/bin.js +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env node - -/* eslint-disable no-console */ -// @flow strict-local -'use strict'; - -// $FlowFixMe[untyped-import] -require('@parcel/babel-register'); - -const cli = require('./src/cli'); - -cli.command.parse(); diff --git a/packages/dev/bundle-stats-cli/package.json b/packages/dev/bundle-stats-cli/package.json index 1fecd90e7b3..05445fbfa05 100644 --- a/packages/dev/bundle-stats-cli/package.json +++ b/packages/dev/bundle-stats-cli/package.json @@ -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", @@ -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", diff --git a/packages/dev/bundle-stats-cli/src/bin.js b/packages/dev/bundle-stats-cli/src/bin.js new file mode 100755 index 00000000000..1ba742589ce --- /dev/null +++ b/packages/dev/bundle-stats-cli/src/bin.js @@ -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(); diff --git a/packages/dev/bundle-stats-cli/src/cli.js b/packages/dev/bundle-stats-cli/src/cli.js index fd60930f27b..9ae2fb90295 100644 --- a/packages/dev/bundle-stats-cli/src/cli.js +++ b/packages/dev/bundle-stats-cli/src/cli.js @@ -1,8 +1,8 @@ /* 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'; @@ -10,13 +10,13 @@ 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 diff --git a/packages/dev/bundle-stats-cli/src/deep-imports.js b/packages/dev/bundle-stats-cli/src/deep-imports.js new file mode 100644 index 00000000000..bb90ebdf480 --- /dev/null +++ b/packages/dev/bundle-stats-cli/src/deep-imports.js @@ -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, +|}); diff --git a/packages/dev/query/package.json b/packages/dev/query/package.json index 49b41e055e8..5ffc6b75a10 100644 --- a/packages/dev/query/package.json +++ b/packages/dev/query/package.json @@ -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", diff --git a/packages/dev/query/src/cli.js b/packages/dev/query/src/cli.js index 9db57cc9679..23c5ee274df 100644 --- a/packages/dev/query/src/cli.js +++ b/packages/dev/query/src/cli.js @@ -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'; @@ -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'); diff --git a/packages/dev/query/src/deep-imports.js b/packages/dev/query/src/deep-imports.js index 1c064db2ccc..4f661ae219d 100644 --- a/packages/dev/query/src/deep-imports.js +++ b/packages/dev/query/src/deep-imports.js @@ -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, |}); diff --git a/packages/dev/query/src/index.js b/packages/dev/query/src/index.js index fd0f8f60aa6..ee33d54f7c9 100644 --- a/packages/dev/query/src/index.js +++ b/packages/dev/query/src/index.js @@ -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<{|