Skip to content

Commit

Permalink
fix: crx loader broken due to Chrome 130 (#1617)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizstacio authored Oct 18, 2024
1 parent 13b2eaa commit 3e75456
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-candles-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": patch
---

fix chrome runtim loader
36 changes: 36 additions & 0 deletions packages/app/vite-utils/fix-build-crx.plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import type { Plugin } from 'vite';

type FixCRXPlugin = {
outDir?: string;
};

export const fixCRXBuildPlugin = ({ outDir }: FixCRXPlugin) => {
const plugin: Plugin = {
name: 'fix-crx-plugin',
apply: 'build',
closeBundle: async () => {
const manifestPath = join(__dirname, '..', outDir, '/manifest.json');
console.log(manifestPath);
console.log(outDir);
const manifest = require(manifestPath);
const webAccessibleResources = manifest.web_accessible_resources;

const updatedWebAccessibleResources = webAccessibleResources.map(
(resource) => {
if (resource.use_dynamic_url) {
return {
...resource,
use_dynamic_url: false,
};
}
return resource;
}
);
manifest.web_accessible_resources = updatedWebAccessibleResources;
writeFileSync(manifestPath, JSON.stringify(manifest, null, 2), 'utf8');
},
};
return plugin;
};
1 change: 1 addition & 0 deletions packages/app/vite-utils/vite.base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Mode, plugin as viteMdPlugin } from 'vite-plugin-markdown';
import tsconfigPaths from 'vite-tsconfig-paths';

import '../load.envs.js';
import { fixCRXBuildPlugin } from './fix-build-crx.plugin.js';

const linkDeps = process.env.LINK_DEPS?.trim().split(' ').filter(Boolean) || [];

Expand Down
4 changes: 4 additions & 0 deletions packages/app/vite.crx.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { crx } from '@crxjs/vite-plugin';
import { defineConfig } from 'vite';

import manifest from './manifest.config';
import { fixCRXBuildPlugin } from './vite-utils/fix-build-crx.plugin';
import baseConfig from './vite-utils/vite.base.config';
import { zipBuildPlugin } from './vite-utils/zip-build.plugin';

Expand All @@ -21,6 +22,9 @@ export default defineConfig({
crx({
manifest,
}),
fixCRXBuildPlugin({
outDir: OUT_DIT,
}),
zipBuildPlugin({
inDir: OUT_DIT,
outDir: baseConfig.build?.outDir,
Expand Down

0 comments on commit 3e75456

Please sign in to comment.