Skip to content

Commit

Permalink
Merge branch 'main' into docs/readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonghakseo authored Nov 26, 2023
2 parents 3cbb83e + 8ce6579 commit e4d0011
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
18 changes: 18 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,24 @@
"contributions": [
"doc"
]
},
{
"login": "gavinhow",
"name": "gavinhow",
"avatar_url": "https://avatars.githubusercontent.com/u/16214376?v=4",
"profile": "https://github.com/gavinhow",
"contributions": [
"bug"
]
},
{
"login": "anand-schultz",
"name": "Anand D.",
"avatar_url": "https://avatars.githubusercontent.com/u/133013727?v=4",
"profile": "https://github.com/anand-schultz",
"contributions": [
"doc"
]
}
]
}
2 changes: 1 addition & 1 deletion .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ markComment: >
# Comment to post when removing the stale label. Set to `false` to disable
unmarkComment: false
# Comment to post when closing a stale Issue or Pull Request. Set to `false` to disable
closeComment: ture
closeComment: true
# Limit to only `issues` or `pulls`
only: issues
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ manifest.json
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/wangxinyugithub"><img src="https://avatars.githubusercontent.com/u/39206932?v=4?s=50" width="50px;" alt="wangxy"/><br /><sub><b>wangxy</b></sub></a><br /><a href="#bug-wangxinyugithub" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/govza"><img src="https://avatars.githubusercontent.com/u/1425574?v=4?s=50" width="50px;" alt="Rasul"/><br /><sub><b>Rasul</b></sub></a><br /><a href="#doc-govza" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/gavinhow"><img src="https://avatars.githubusercontent.com/u/16214376?v=4?s=50" width="50px;" alt="gavinhow"/><br /><sub><b>gavinhow</b></sub></a><br /><a href="#bug-gavinhow" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/anand-schultz"><img src="https://avatars.githubusercontent.com/u/133013727?v=4?s=50" width="50px;" alt="Anand D."/><br /><sub><b>Anand D.</b></sub></a><br /><a href="#doc-anand-schultz" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
14 changes: 7 additions & 7 deletions utils/plugins/make-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ const getManifestWithCacheBurst = (): Promise<{ default: chrome.runtime.Manifest
return import(withCacheBurst(manifestFile));
};

export default function makeManifest(config: { contentScriptCssKey?: string }): PluginOption {
function makeManifest(manifest: chrome.runtime.ManifestV3, to: string) {
export default function makeManifest(config?: { getCacheInvalidationKey?: () => string }): PluginOption {
function makeManifest(manifest: chrome.runtime.ManifestV3, to: string, cacheKey?: string) {
if (!fs.existsSync(to)) {
fs.mkdirSync(to);
}
const manifestPath = resolve(to, 'manifest.json');

// Naming change for cache invalidation
if (config.contentScriptCssKey) {
if (cacheKey) {
// Naming change for cache invalidation
manifest.content_scripts.forEach(script => {
script.css = script.css.map(css => css.replace('<KEY>', config.contentScriptCssKey));
script.css = script.css.map(css => css.replace('<KEY>', cacheKey));
});
}

Expand All @@ -49,8 +48,9 @@ export default function makeManifest(config: { contentScriptCssKey?: string }):
this.addWatchFile(manifestFile);
},
async writeBundle() {
const invalidationKey = config.getCacheInvalidationKey?.();
const manifest = await getManifestWithCacheBurst();
makeManifest(manifest.default, distDir);
makeManifest(manifest.default, distDir, invalidationKey);
},
};
}
13 changes: 11 additions & 2 deletions utils/plugins/watch-rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WebSocket } from 'ws';
import MessageInterpreter from '../reload/interpreter';
import { LOCAL_RELOAD_SOCKET_URL } from '../reload/constant';

export default function watchRebuild(config: { whenWriteBundle: () => void }): PluginOption {
export default function watchRebuild(config: { afterWriteBundle: () => void }): PluginOption {
const ws = new WebSocket(LOCAL_RELOAD_SOCKET_URL);
return {
name: 'watch-rebuild',
Expand All @@ -13,7 +13,16 @@ export default function watchRebuild(config: { whenWriteBundle: () => void }): P
* The reload server will send a message to the client to reload or refresh the extension.
*/
ws.send(MessageInterpreter.send({ type: 'build_complete' }));
config.whenWriteBundle();

sendNextQueue(() => {
config.afterWriteBundle();
});
},
};
}

function sendNextQueue(callback: () => void) {
setTimeout(() => {
callback();
}, 0);
}
15 changes: 9 additions & 6 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const isProduction = !isDev;

// ENABLE HMR IN BACKGROUND SCRIPT
const enableHmrInBackgroundScript = true;
let cacheInvalidationKey: string = generateKey();
const cacheInvalidationKeyRef = { current: generateKey() };

export default defineConfig({
resolve: {
Expand All @@ -32,12 +32,12 @@ export default defineConfig({
},
plugins: [
makeManifest({
contentScriptCssKey: cacheInvalidationKey,
getCacheInvalidationKey,
}),
react(),
customDynamicImport(),
addHmr({ background: enableHmrInBackgroundScript, view: true }),
isDev && watchRebuild({ whenWriteBundle: regenerateCacheInvalidationKey }),
isDev && watchRebuild({ afterWriteBundle: regenerateCacheInvalidationKey }),
],
publicDir,
build: {
Expand Down Expand Up @@ -65,7 +65,7 @@ export default defineConfig({
chunkFileNames: isDev ? 'assets/js/[name].js' : 'assets/js/[name].[hash].js',
assetFileNames: assetInfo => {
const { name } = path.parse(assetInfo.name);
const assetFileName = name === 'contentStyle' ? `${name}${cacheInvalidationKey}` : name;
const assetFileName = name === 'contentStyle' ? `${name}${getCacheInvalidationKey()}` : name;
return `assets/[ext]/${assetFileName}.chunk.[ext]`;
},
},
Expand All @@ -79,9 +79,12 @@ export default defineConfig({
},
});

function getCacheInvalidationKey() {
return cacheInvalidationKeyRef.current;
}
function regenerateCacheInvalidationKey() {
cacheInvalidationKey = generateKey();
return cacheInvalidationKey;
cacheInvalidationKeyRef.current = generateKey();
return cacheInvalidationKeyRef;
}

function generateKey(): string {
Expand Down

0 comments on commit e4d0011

Please sign in to comment.