Skip to content

Instantly share code, notes, and snippets.

@irgendwr
Last active March 24, 2022 20:23
Show Gist options
  • Save irgendwr/8bdeefc8d715333a69e09fe83548a717 to your computer and use it in GitHub Desktop.
Save irgendwr/8bdeefc8d715333a69e09fe83548a717 to your computer and use it in GitHub Desktop.
How to patch parcel (or basically any other npm package)

How to patch parcel

Patch to enable MV3 support

This shows how to apply this PR by @101arrowz to enable manifest v3 support. Please be aware that the patch is not production ready and might still have some issues.

Go to your project and add patch-package and postinstall-postinstall as devDependencies, then download the patch:

cd <path-to-your-project>
npm install -D patch-package
npm install -D postinstall-postinstall
mkdir patches
cd patches
# download the patch file, eg. via curl
curl -L -O https://gist.githubusercontent.com/irgendwr/09bfa9af38d6ef42572c0bbddd813242/raw/@parcel+transformer-webextension+2.4.0.patch
cd ..

Add this to your package.json or append the postinstall line to your existing scripts section:

"scripts": {
    "postinstall": "patch-package"
},

Now, npm install should apply the patch.

How to create and apply a patch

This describes how to build, patch parcel and use the patched version somewhere else.

Clone parcel:

git clone https://github.com/parcel-bundler/parcel.git
cd parcel

Apply the patch. In this case I'll apply the pull-request parcel-bundler/parcel#7050.

git remote add 101arrowz https://github.com/101arrowz/parcel.git
git fetch 101arrowz
git checkout 101arrowz/v2

Build (this requires node, yarn and rustup; see this):

yarn install
yarn build-native-release
yarn build

Copy the required module, eg. @parcel/transformer-webextension:

cp -r packages/transformers/webextension <path-to-your-project>/node_modules/@parcel/transformer-webextension

Go to your project and add patch-package and postinstall-postinstall as devDependencies:

cd <path-to-your-project>
npm install -D patch-package
npm install -D postinstall-postinstall

Create the patch:

npx patch-package @parcel/transformer-webextension

Add this to your package.json or append the postinstall line to your existing scripts section:

"scripts": {
    "postinstall": "patch-package"
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment