Skip to content

Commit 5f2cac4

Browse files
authored
Merge pull request #22 from michmich112/breaking/kit-7800
Fix for #21
2 parents 06709af + 263cb0c commit 5f2cac4

File tree

3 files changed

+255
-250
lines changed

3 files changed

+255
-250
lines changed

index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function ({
2323
fallback,
2424
precompress = false,
2525
manifest = "manifest.json",
26-
emptyOutDir = true
26+
emptyOutDir = true,
2727
} = {}) {
2828
return {
2929
name: "sveltekit-adapter-chrome-extension",
@@ -61,7 +61,7 @@ export default function ({
6161
await removeInlineScripts(assets, builder.log);
6262

6363
await removeAppManifest(assets, builder.config.kit.appDir, builder.log);
64-
await removeAppManifest('.', assets, builder.log);
64+
await removeAppManifest(".", assets, builder.log);
6565

6666
// operation required since generated app manifest will overwrite the static extension manifest.json
6767
reWriteExtensionManifest(assets, manifest, builder);
@@ -94,7 +94,7 @@ async function removeAppManifest(directory, appDir, log) {
9494
absolute: true,
9595
filesOnly: true,
9696
});
97-
97+
9898
files.forEach((path) => {
9999
try {
100100
unlinkSync(path);
@@ -123,7 +123,7 @@ async function removeInlineScripts(directory, log) {
123123
const f = readFileSync(file);
124124
const $ = load(f.toString());
125125
const node = $('script[type="module"]').get()[0];
126-
126+
127127
if (!node) return;
128128
if (Object.keys(node.attribs).includes("src")) return; // if there is a src, it's not an inline script
129129

@@ -149,9 +149,14 @@ async function removeInlineScripts(directory, log) {
149149
}
150150

151151
function reWriteExtensionManifest(directory, manifest, builder) {
152-
const { log, getStaticDirectory, copy } = builder;
152+
const { log, getStaticDirectory, getClientDirectory, copy } = builder;
153153
log("Re-writing extension manifest");
154-
const sourceFilePath = join(getStaticDirectory(), manifest);
154+
let sourceFilePath;
155+
if (typeof getStaticDirectory !== "undefined") {
156+
sourceFilePath = join(getStaticDirectory(), manifest);
157+
} else {
158+
sourceFilePath = join(getClientDirectory(), manifest);
159+
}
155160
if (existsSync(sourceFilePath)) {
156161
log.info("Extension manifest found");
157162
const res = copy(sourceFilePath, join(directory, "manifest.json"));

0 commit comments

Comments
 (0)