diff --git a/packages/crx-monkey/src/node/config.ts b/packages/crx-monkey/src/node/config.ts index c8d740e..cc70cbb 100644 --- a/packages/crx-monkey/src/node/config.ts +++ b/packages/crx-monkey/src/node/config.ts @@ -63,12 +63,13 @@ async function search(dir: string): Promise { } function isKeyof(obj: object, key: T | string): key is T { - Object.entries(obj).forEach(([objkey]) => { + let result = false; + Object.keys(obj).forEach((objkey) => { if (key === objkey) { - return true; + result = true; } }); - return false; + return result; } function setDefaultConfig(config: Record) { diff --git a/packages/crx-monkey/src/node/handlers/dev/server/scriptHostingServer.ts b/packages/crx-monkey/src/node/handlers/dev/server/scriptHostingServer.ts index 2b4f18e..eae23f8 100644 --- a/packages/crx-monkey/src/node/handlers/dev/server/scriptHostingServer.ts +++ b/packages/crx-monkey/src/node/handlers/dev/server/scriptHostingServer.ts @@ -1,6 +1,7 @@ import express from 'express'; import { getConfig } from 'src/node/config'; import path from 'path'; +import fse from 'fs-extra'; export class ScriptHostingServer { private readonly app: express.Express; @@ -30,17 +31,24 @@ export class ScriptHostingServer { }); this.app.get('/userscript', (req, res) => { - if (config.userscriptOutput !== undefined) { - res.sendFile(config.userscriptOutput); + const filepath = path.join(path.dirname(config.manifestJsonPath), config.userscriptOutput); + + if (fse.existsSync(filepath)) { + res.sendFile(filepath); } else { res.send(400); } }); this.app.get('/dev.user.js', (req, res) => { - if (config.userscriptOutput !== undefined) { - const userscriptDir = path.dirname(config.userscriptOutput); - res.sendFile(path.join(userscriptDir, 'crx-monkey-dev.user.js')); + const filepath = path.join( + path.dirname(config.manifestJsonPath), + path.dirname(config.userscriptOutput), + 'crx-monkey-dev.user.js', + ); + + if (fse.existsSync(filepath)) { + res.sendFile(filepath); } else { res.send(400); } diff --git a/packages/crx-monkey/src/node/handlers/utils.ts b/packages/crx-monkey/src/node/handlers/utils.ts index 2f4a11e..1f820a8 100644 --- a/packages/crx-monkey/src/node/handlers/utils.ts +++ b/packages/crx-monkey/src/node/handlers/utils.ts @@ -25,13 +25,8 @@ export function getlocalesPath() { export function copyPublic() { const config = getConfig(); - const publicDir = config.publicDir; - - if ( - publicDir !== undefined && - fse.pathExistsSync(publicDir) && - config.chromeOutputDir !== undefined - ) { + const publicDir = path.join(process.cwd(), config.publicDir); + if (publicDir !== undefined && fse.pathExistsSync(publicDir)) { fse.copy(publicDir, path.join(config.chromeOutputDir, path.basename(publicDir))); } }