parcel icon indicating copy to clipboard operation
parcel copied to clipboard

Building issues with @parcel/config-webextension if we use custom manifest file name

Open akash07k opened this issue 2 years ago • 9 comments

🐛 bug report

I'm building a web extension and I have separate manifests for both Chrome and Firefox. Let's say my manifest is named manifest-firefox.json So, if I try to build my extension by using parcel build src/manifest-firefox.json then it doesn't build the extension and doesn't even throw an error. When I check the dist directory, I see that it has created only 1 file called: manifest-firefox.js Whereas if I rename the original manifest file to "manifest.json" and use the command like: parcel build src/manifest.json Then it successfully builds the extension. (PS: Manifest is unchanged in both the scenarios, only the file is renamed nothing else.) So it seems that parcel has some bug where it doesn't work with custom named manifests.

🎛 Configuration (.babelrc, package.json, cli command)

I'm not using any babel config. My .parcelrc is below:

{
	"extends": "@parcel/config-webextension"
}

🤔 Expected Behavior

Extension should be built correctly even though we supply custom manifest file name

😯 Current Behavior

The extension didn't built properly and I got only 1 file in dist directory named manifest-firefox.js with contents: JSON.parse('{"//My manifest json here"}

💁 Possible Solution

🔦 Context

Trying to build extension for chrome and firefox with separate manifests

💻 Code Sample

"build-firefox": "parcel build src/manifest-firefox.json --no-content-hash --no-source-maps --dist-dir dist --no-cache --detailed-report 10"

🌍 Your Environment

Software Version(s)
Parcel 2.7.0
parcel/config-webextension 2.7.0
Node 2.7.0
npm/Yarn NPM 8.15.0
Operating System Windows 11

akash07k avatar Aug 18 '22 08:08 akash07k

@parcel/config-webextension only sets manifest.json as a supported filename. If you want a different name, you have to configure it, otherwise it just treats it as a regular JSON file.

https://github.com/parcel-bundler/parcel/blob/cbc84b0c1d538b0ec15a3bf01f95da3ed623ebbb/packages/configs/webextension/index.json#L3-L10

But I think it's easier to create firefox/manifest.json and chrome/manifest.json

fregante avatar Aug 18 '22 09:08 fregante

@fregante You are right buddy, I tried this approach too, but there the issue was that I was unable to reference my scripts from the manifests because they are lying in one level up. For example, the structure is like this: scripts, firefox>manifest.json chrome>manifest.json

Now I was unable to reference my scripts and was getting errors if I was using the syntax like: "service_worker": "../scripts/background/background.js", Am I missing something? If there is any way to fix this, then I'll really appreciate it

akash07k avatar Aug 18 '22 12:08 akash07k

That's described by:

  • https://github.com/parcel-bundler/parcel/issues/8071

fregante avatar Aug 18 '22 14:08 fregante

You're commenting in the wrong issue. The issue you opened is not a bug in Parcel, you just need to add configuration in your .parcelrc as suggested.

The second part is unrelated and already has an issue open.

This issue can be closed.

fregante avatar Aug 18 '22 16:08 fregante

@fregante Nevermind. Fixed it. The issue is certainly valid though. Parcel should honor the custom manifest name too. Certainly a parcel bug

akash07k avatar Aug 18 '22 17:08 akash07k

Not a bug.

parcel build data.json is perfectly valid and is not expected to read the paths within it. If your name is not exactly manifest.json, then Parcel can't assume that every imported json file is a manifest.

There is nothing special to config-webextension other than telling Parcel how to deal with specifically manifest.json. If you use a different name, you can extend the default configuration.

fregante avatar Aug 18 '22 18:08 fregante

@fregante No, I'm not saying that. I'm saying that simply if we use another name for the manifest like manifest-firefox.json, and supply the same name to Parcel build command, then too it doesn't build. I fixed the second issue myself. I'm not talking about it. Read the issue description properly before commenting

akash07k avatar Aug 18 '22 19:08 akash07k

@fregante @akash07k as far as I can understand there is a misunderstanding in implicit knowledge on how to use @parcel/config-webextension. I think the reason for confusion is that @parcel/config-webextension is using hardcoded manifest.json as manifest file name, but it's not mentioned anywhere in the web extensions getting started docs. A simple NOTE in the docs clarifying that the manifest.json name is hardcoded and mandatory would certainly save people hours of work. Considering the recent push by google for migrations to manifest v3, a lot of cross-browser extension developers are starting to use separate names for manifest while previously they were usually always using manifest.json. Taking this into consideration would be a great win for all developers.

piotrwitek avatar Sep 06 '22 17:09 piotrwitek

@piotrwitek Yes, you are quite right. The fact that the manifest name is hardcoded should be mentioned in the docs, or it will be even better if the name customization can be allowed by setting some flags or environment variables.

akash07k avatar Sep 06 '22 18:09 akash07k

Since the driver behind this seems to be the need to support two different manifest versions because of the Chrome Store MV3 fiasco, I was wondering if a useful feature might be a transformer that parses some sort of primary manifest file (which could be in JS or JSON5) and cooks it into the appropriate MV2 / MV3 format JSON manifest, depending on which parcel config file we use.

Wins:

  1. no duplication of mostly similar data to maintain
  2. can use comments in the manifest
  3. might be able to pull the version out of our package.json on the fly so there's only a single place to maintain it

bentorkington avatar Oct 01 '22 00:10 bentorkington

@akash07k How did you solve the issue with relative scripts and locales?

The problem I'm facing now, if I create separate manifests, e.g. src/production/manifest.json and src/development/manifest.json, I have to duplicate and copy the _locales folder to each of them, because there is no way to describe a relative path to the _locales folder in the manifest.json.

everdimension avatar Nov 01 '22 08:11 everdimension

@everdimension The best way which now use is to simlink your _locales directory. By that, you won't be required to duplicate that dir either, and the workaround will also be made

akash07k avatar Nov 01 '22 13:11 akash07k

Does this resolve everyone's concerns regarding different filenames for the manifest?

https://github.com/parcel-bundler/website/pull/1052

mischnic avatar Nov 01 '22 16:11 mischnic

@mischnic Commented on that PR.

akash07k avatar Nov 01 '22 17:11 akash07k

Not stail

akash07k avatar May 24 '23 12:05 akash07k