-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: bundle buddy reporter * Update BundleBuddyReporter.js * Add @parcel/reporter-bundle-analyzer to package.json * Update BundleBuddyReporter.js * fix lint Co-authored-by: Jasper De Moor <jasperdemoor@gmail.com>
- Loading branch information
1 parent
149c00b
commit 2668bee
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@parcel/reporter-bundle-buddy", | ||
"version": "2.0.0-alpha.3.1", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/parcel-bundler/parcel.git" | ||
}, | ||
"main": "lib/BundleBuddyReporter.js", | ||
"source": "src/BundleBuddyReporter.js", | ||
"engines": { | ||
"node": ">= 10.0.0", | ||
"parcel": "^2.0.0-alpha.1.1" | ||
}, | ||
"dependencies": { | ||
"@parcel/plugin": "^2.0.0-alpha.3.1" | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/reporters/bundle-buddy/src/BundleBuddyReporter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @flow strict-local | ||
import type {NamedBundle} from '@parcel/types'; | ||
import {Reporter} from '@parcel/plugin'; | ||
import path from 'path'; | ||
|
||
export default new Reporter({ | ||
async report({event, options}) { | ||
if (event.type !== 'buildSuccess' || process.env.BUNDLE_BUDDY == null) { | ||
return; | ||
} | ||
|
||
let bundlesByTarget: Map<string, Array<NamedBundle>> = new Map(); | ||
for (let bundle of event.bundleGraph.getBundles()) { | ||
if (!bundle.isInline) { | ||
let bundles = bundlesByTarget.get(bundle.target.distDir); | ||
if (!bundles) { | ||
bundles = []; | ||
bundlesByTarget.set(bundle.target.distDir, bundles); | ||
} | ||
|
||
bundles.push(bundle); | ||
} | ||
} | ||
|
||
for (let [targetDir, bundles] of bundlesByTarget) { | ||
let out = []; | ||
|
||
for (let bundle of bundles) { | ||
bundle.traverseAssets(asset => { | ||
let deps = event.bundleGraph.getDependencies(asset); | ||
for (let dep of deps) { | ||
let resolved = event.bundleGraph.getDependencyResolution(dep); | ||
if (!resolved) { | ||
continue; | ||
} | ||
|
||
out.push({ | ||
source: path.relative(options.projectRoot, asset.filePath), | ||
target: path.relative(options.projectRoot, resolved.filePath), | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
await options.outputFS.writeFile( | ||
`${targetDir}/bundle-buddy.json`, | ||
JSON.stringify(out), | ||
); | ||
} | ||
}, | ||
}); |