Skip to content

Commit

Permalink
feat: support hash and query properties in manifest HTML filenames
Browse files Browse the repository at this point in the history
closes #90
  • Loading branch information
samrum committed Apr 12, 2023
1 parent 7226eb5 commit 459c51c
Show file tree
Hide file tree
Showing 13 changed files with 565 additions and 14 deletions.
13 changes: 1 addition & 12 deletions src/manifestParser/manifestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default abstract class ManifestParser<

protected parseInputHtmlFiles(result: ParseResult<Manifest>) {
this.getHtmlFileNames(result.manifest).forEach((htmlFileName) =>
this.parseInputHtmlFile(htmlFileName, result)
this.addInputToParseResult(htmlFileName, result)
);

return result;
Expand All @@ -177,17 +177,6 @@ export default abstract class ManifestParser<
return result;
}

protected parseInputHtmlFile(
htmlFileName: string | undefined,
result: ParseResult<Manifest>
): ParseResult<Manifest> {
if (!htmlFileName) {
return result;
}

return this.addInputToParseResult(htmlFileName, result);
}

protected parseOutputContentCss(
cssFileName: string,
bundle: OutputBundle
Expand Down
4 changes: 3 additions & 1 deletion src/manifestParser/manifestV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default class ManifestV2 extends ManifestParser<Manifest> {
manifest.chrome_url_overrides?.newtab,
manifest.chrome_url_overrides?.history,
manifest.chrome_url_overrides?.bookmarks,
].filter((fileName): fileName is string => typeof fileName === "string");
]
.filter((fileName): fileName is string => typeof fileName === "string")
.map((fileName) => fileName.split(/[\?\#]/)[0]);
}

protected getParseInputMethods(): ((
Expand Down
4 changes: 3 additions & 1 deletion src/manifestParser/manifestV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export default class ManifestV3 extends ManifestParser<Manifest> {
manifest.chrome_url_overrides?.newtab,
manifest.chrome_url_overrides?.history,
manifest.chrome_url_overrides?.bookmarks,
].filter((fileName): fileName is string => typeof fileName === "string");
]
.filter((fileName): fileName is string => typeof fileName === "string")
.map((fileName) => fileName.split(/[\?\#]/)[0]);
}

protected getParseInputMethods(): ((
Expand Down
248 changes: 248 additions & 0 deletions test/manifest/__snapshots__/htmlUrlProperties.v2.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
// Vitest Snapshot v1

exports[`htmlUrlProperties - Manifest V2 1`] = `
[
{
"code": "function log(message) {
console.log(message);
}
export {
log as l
};
",
"dynamicImports": [],
"exports": [
"l",
],
"facadeModuleId": null,
"fileName": "assets/log.js",
"implicitlyLoadedBefore": [],
"importedBindings": {},
"imports": [],
"isDynamicEntry": false,
"isEntry": false,
"isImplicitEntry": false,
"map": null,
"modules": {
"vite-plugin-web-extension/test/manifest/resources/shared/log.js": {
"code": "function log(message) {
console.log(message);
}",
"originalLength": 65,
"removedExports": [],
"renderedExports": [
"default",
],
"renderedLength": 49,
},
},
"name": "log",
"referencedFiles": [],
"type": "chunk",
"viteMetadata": {
"importedAssets": Set {},
"importedCss": Set {},
},
},
{
"code": "import { l as log } from \\"../../../../log.js\\";
log(\\"devtools\\");
",
"dynamicImports": [],
"exports": [],
"facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/htmlUrlProperties/devtools.html",
"fileName": "assets/test/manifest/resources/htmlUrlProperties/devtools.js",
"implicitlyLoadedBefore": [],
"importedBindings": {
"assets/log.js": [
"l",
],
},
"imports": [
"assets/log.js",
],
"isDynamicEntry": false,
"isEntry": true,
"isImplicitEntry": false,
"map": null,
"modules": {
"vite-plugin-web-extension/test/manifest/resources/htmlUrlProperties/devtools.html": {
"code": null,
"originalLength": 227,
"removedExports": [],
"renderedExports": [],
"renderedLength": 0,
},
"vite-plugin-web-extension/test/manifest/resources/htmlUrlProperties/devtools.js": {
"code": "log(\\"devtools\\");",
"originalLength": 53,
"removedExports": [],
"renderedExports": [],
"renderedLength": 16,
},
},
"name": "test/manifest/resources/htmlUrlProperties/devtools",
"referencedFiles": [],
"type": "chunk",
"viteMetadata": {
"importedAssets": Set {},
"importedCss": Set {},
},
},
{
"code": "import { l as log } from \\"../../../../log.js\\";
log(\\"options\\");
",
"dynamicImports": [],
"exports": [],
"facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/htmlUrlProperties/options.html",
"fileName": "assets/test/manifest/resources/htmlUrlProperties/options.js",
"implicitlyLoadedBefore": [],
"importedBindings": {
"assets/log.js": [
"l",
],
},
"imports": [
"assets/log.js",
],
"isDynamicEntry": false,
"isEntry": true,
"isImplicitEntry": false,
"map": null,
"modules": {
"vite-plugin-web-extension/test/manifest/resources/htmlUrlProperties/options.html": {
"code": null,
"originalLength": 226,
"removedExports": [],
"renderedExports": [],
"renderedLength": 0,
},
"vite-plugin-web-extension/test/manifest/resources/htmlUrlProperties/options.js": {
"code": "log(\\"options\\");",
"originalLength": 52,
"removedExports": [],
"renderedExports": [],
"renderedLength": 15,
},
},
"name": "test/manifest/resources/htmlUrlProperties/options",
"referencedFiles": [],
"type": "chunk",
"viteMetadata": {
"importedAssets": Set {},
"importedCss": Set {},
},
},
{
"code": "import { l as log } from \\"../../../../log.js\\";
log(\\"popup\\");
",
"dynamicImports": [],
"exports": [],
"facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/htmlUrlProperties/popup.html",
"fileName": "assets/test/manifest/resources/htmlUrlProperties/popup.js",
"implicitlyLoadedBefore": [],
"importedBindings": {
"assets/log.js": [
"l",
],
},
"imports": [
"assets/log.js",
],
"isDynamicEntry": false,
"isEntry": true,
"isImplicitEntry": false,
"map": null,
"modules": {
"vite-plugin-web-extension/test/manifest/resources/htmlUrlProperties/popup.html": {
"code": null,
"originalLength": 224,
"removedExports": [],
"renderedExports": [],
"renderedLength": 0,
},
"vite-plugin-web-extension/test/manifest/resources/htmlUrlProperties/popup.js": {
"code": "log(\\"popup\\");",
"originalLength": 50,
"removedExports": [],
"renderedExports": [],
"renderedLength": 13,
},
},
"name": "test/manifest/resources/htmlUrlProperties/popup",
"referencedFiles": [],
"type": "chunk",
"viteMetadata": {
"importedAssets": Set {},
"importedCss": Set {},
},
},
{
"fileName": "manifest.json",
"name": undefined,
"source": "{
\\"version\\": \\"1.0.0\\",
\\"name\\": \\"Manifest Name\\",
\\"manifest_version\\": 2,
\\"browser_action\\": {
\\"default_popup\\": \\"test/manifest/resources/htmlUrlProperties/popup.html#hashValue\\"
},
\\"devtools_page\\": \\"test/manifest/resources/htmlUrlProperties/devtools.html?query=1\\",
\\"options_ui\\": {
\\"page\\": \\"test/manifest/resources/htmlUrlProperties/options.html?query=1#hashValue\\"
}
}",
"type": "asset",
},
{
"fileName": "test/manifest/resources/htmlUrlProperties/devtools.html",
"name": undefined,
"source": "<!DOCTYPE html>
<html lang=\\"en\\">
<head>
<meta charset=\\"UTF-8\\" />
<script type=\\"module\\" src=\\"http://example.com/httpModuleScript.js\\"></script>
<script type=\\"module\\" crossorigin src=\\"/assets/test/manifest/resources/htmlUrlProperties/devtools.js\\"></script>
</head>
</html>
",
"type": "asset",
},
{
"fileName": "test/manifest/resources/htmlUrlProperties/options.html",
"name": undefined,
"source": "<!DOCTYPE html>
<html lang=\\"en\\">
<head>
<meta charset=\\"UTF-8\\" />
<script type=\\"module\\" src=\\"http://example.com/httpModuleScript.js\\"></script>
<script type=\\"module\\" crossorigin src=\\"/assets/test/manifest/resources/htmlUrlProperties/options.js\\"></script>
</head>
</html>
",
"type": "asset",
},
{
"fileName": "test/manifest/resources/htmlUrlProperties/popup.html",
"name": undefined,
"source": "<!DOCTYPE html>
<html lang=\\"en\\">
<head>
<meta charset=\\"UTF-8\\" />
<script type=\\"module\\" src=\\"http://example.com/httpModuleScript.js\\"></script>
<script type=\\"module\\" crossorigin src=\\"/assets/test/manifest/resources/htmlUrlProperties/popup.js\\"></script>
</head>
</html>
",
"type": "asset",
},
]
`;
Loading

0 comments on commit 459c51c

Please sign in to comment.