Skip to content

Commit

Permalink
Add back parcel bundler to ensure the override sticks
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgv committed Nov 10, 2023
1 parent 74b7cb9 commit b02bb19
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 85 deletions.
2 changes: 1 addition & 1 deletion cli/plasmo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "dist/type.d.ts"
},
"types": "src/type.ts",
"module": "dist/index.js",
"main": "dist/index.js",
"bin": "bin/index.mjs",
"type": "module",
"files": [
Expand Down
3 changes: 3 additions & 0 deletions core/parcel-bundler/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules

dist/
35 changes: 35 additions & 0 deletions core/parcel-bundler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@plasmohq/parcel-bundler",
"version": "0.7.0",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/PlasmoHQ/plasmo.git"
},
"main": "dist/index.js",
"source": "src/index.ts",
"scripts": {
"prepublishOnly": "pnpm build",
"build": "tsup src/index.ts --minify --clean",
"dev": "tsup src/index.ts --sourcemap --watch"
},
"engines": {
"node": ">= 16.0.0",
"parcel": ">= 2.7.0"
},
"dependencies": {
"@parcel/diagnostic": "2.10.2",
"@parcel/graph": "3.0.2",
"@parcel/plugin": "2.10.2",
"@parcel/rust": "2.10.2",
"@parcel/utils": "2.10.2",
"nullthrows": "1.1.1"
},
"devDependencies": {
"@parcel/bundler-default": "2.10.2",
"@parcel/types": "2.10.2",
"@plasmo/config": "workspace:*",
"@plasmo/utils": "workspace:*",
"tsup": "7.2.0"
}
}
11 changes: 11 additions & 0 deletions core/parcel-bundler/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2023 Plasmo Corp. <[email protected]> (https://www.plasmo.com) and contributors
* MIT License
*
* Based on: https://github.com/parcel-bundler/parcel/blob/v2/packages/bundlers/default/package.json
* MIT License
*/

import Bundler from "@parcel/bundler-default"

export default Bundler
5 changes: 5 additions & 0 deletions core/parcel-bundler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "@plasmo/config/ts/framework",
"include": ["src/**/*.ts"],
"exclude": ["dist", "node_modules"]
}
2 changes: 1 addition & 1 deletion core/parcel-config/index.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@parcel/config-default",
"bundler": "@parcel/bundler-default",
"bundler": "@plasmohq/parcel-bundler",
"resolvers": [
"@plasmohq/parcel-resolver",
"@parcel/resolver-default",
Expand Down
4 changes: 2 additions & 2 deletions core/parcel-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
},
"main": "index.json",
"dependencies": {
"@parcel/bundler-default": "2.10.2",
"@parcel/compressor-raw": "2.10.2",
"@parcel/config-default": "2.10.2",
"@parcel/core": "2.10.2",
"@parcel/optimizer-data-url": "2.10.2",
"@parcel/reporter-bundle-buddy": "2.10.2",
"@parcel/resolver-default": "2.10.2",
"@parcel/runtime-js": "2.10.2",
"@parcel/runtime-js": "2.8.3",
"@parcel/runtime-service-worker": "2.10.2",
"@parcel/source-map": "2.1.1",
"@parcel/transformer-babel": "2.10.2",
Expand All @@ -30,6 +29,7 @@
"@parcel/transformer-sass": "2.10.2",
"@parcel/transformer-svg-react": "2.10.2",
"@parcel/transformer-worklet": "2.10.2",
"@plasmohq/parcel-bundler": "workspace:*",
"@plasmohq/parcel-compressor-utf8": "workspace:*",
"@plasmohq/parcel-namer-manifest": "workspace:*",
"@plasmohq/parcel-optimizer-encapsulate": "workspace:*",
Expand Down
47 changes: 8 additions & 39 deletions core/parcel-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ export default new Runtime({
return
}

const manifest = bundleGraph
.getBundles()
.find((b) => b.getMainEntry()?.meta.webextEntry === true)
// const manifest = bundleGraph
// .getBundles()
// .find((b) => b.getMainEntry()?.meta.webextEntry === true)

const entry = manifest?.getMainEntry()
const insertDep = entry?.meta.webextBGInsert
if (!manifest || !entry || insertDep === null) {
return
}
// const entry = manifest?.getMainEntry()
// const insertDep = entry?.meta.webextBGInsert
// if (!manifest || !entry || insertDep === null) {
// return
// }

const entryFilePath = bundle.getMainEntry()?.filePath
if (!entryFilePath) {
Expand Down Expand Up @@ -169,37 +169,6 @@ export default new Runtime({
sourceType: "module"
}
}
} else {
let firstInsertableBundle
const insertBundle = bundleGraph.getReferencedBundle(
entry?.getDependencies().find((dep) => dep.id === insertDep),
manifest
)
bundleGraph.traverseBundles((b, _, actions) => {
if (b.type == "js") {
firstInsertableBundle = b
actions.stop()
}
}, insertBundle)

if (bundle === firstInsertableBundle) {
return {
filePath: __filename,
code: `JSON.parse(${JSON.stringify(
JSON.stringify(
JSON.parse(
replaceURLReferences({
bundle: manifest,
bundleGraph,
contents: await entry.getCode(),
getReplacement: () => ""
}).contents
)
)
)})`,
isEntry: true
}
}
}
}
})
Loading

0 comments on commit b02bb19

Please sign in to comment.