Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-standard cross-browser fields support #123

Closed
wants to merge 1 commit into from

Conversation

cezaraugusto
Copy link
Member

Address #122

@joeframbach
Copy link
Contributor

This won't recurse in child arrays, if it matters.

{
  "foo": [
    {} // <--- won't touch this
  ]
}

@joeframbach
Copy link
Contributor

I may suggest

  private reviver (this: any, key: string, value: any) {
    if (
      key.startsWith(`${this.browser}:`) ||
      (key.startsWith('chromium:') &&
        this.chromiumBasedBrowsers.includes(this.browser))
    ) {
      this[key.substring(key.indexOf(':')+1)] = value;
      return
    }

    if (key.includes(':')) {
      return
    }

    return value
  }

  apply(compiler: Compiler) {
    compiler.hooks.emit.tapAsync(
      'HandleBrowserSpecificFields',
      (compilation, done) => {
        if (compilation.errors.length > 0) return

        const manifestSource = compilation
          .getAsset('manifest.json')
          ?.source.source()
        const manifest = JSON.parse((manifestSource || '{}').toString(), this.reviver)
        const patchedSource = JSON.stringify(manifest, null, 2)
        const rawSource = new sources.RawSource(patchedSource)

        compilation.updateAsset('manifest.json', rawSource)

        done()
      }
    )
  }

@cezaraugusto
Copy link
Member Author

hi @joeframbach, thanks for the tip!

Could you push a pull-request with the changes? I'll happily review it. I've been wanting this feature for a while but got to fix a few bugs first

@cezaraugusto
Copy link
Member Author

suppressed by #128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants