From cab28ef7ec1a3c7424cfab14179cdfb08d9b5b29 Mon Sep 17 00:00:00 2001 From: AminoffZ Date: Sat, 16 Mar 2024 18:08:50 +0200 Subject: [PATCH 1/2] Fix Build In WSL --- extract-inline.mjs => extract-inline.ts | 25 ++++++++-------- package.json | 2 +- public/manifest.json | 38 +++++++++++++++++++------ update-version.ts | 18 ++++++------ 4 files changed, 52 insertions(+), 31 deletions(-) rename extract-inline.mjs => extract-inline.ts (71%) diff --git a/extract-inline.mjs b/extract-inline.ts similarity index 71% rename from extract-inline.mjs rename to extract-inline.ts index 1e7e3ac..d922c4f 100644 --- a/extract-inline.mjs +++ b/extract-inline.ts @@ -1,31 +1,30 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ -const glob = require('tiny-glob'); -const path = require('path'); -const fs = require('fs'); +import { readFileSync, writeFileSync } from 'fs'; +import { join, resolve } from 'path'; +import glob from 'tiny-glob'; -function hash(value) { +function hash(value: string) { let hash = 5381; let i = value.length; while (i) hash = (hash * 33) ^ value.charCodeAt(--i); return (hash >>> 0).toString(36); } -async function removeInlineScriptAndStyle(directory) { +async function removeInlineScriptAndStyle(directory: string) { console.log('Removing Inline Scripts and Styles'); const scriptRegx = /]*>([\s\S]+?)<\/script>/g; const styleRegx = /]*>([\s\S]+?)<\/style>/g; const files = await glob('**/*.html', { cwd: directory, dot: true, - aboslute: true, + absolute: false, filesOnly: true, }); console.log(`Found ${files.length} files`); - for (const file of files.map((f) => path.join(directory, f))) { + for (const file of files.map((f) => join(directory, f))) { console.log(`Edit file: ${file}`); - let f = fs.readFileSync(file, { encoding: 'utf-8' }); + let f = readFileSync(file, { encoding: 'utf-8' }); let script; while ((script = scriptRegx.exec(f))) { @@ -40,7 +39,7 @@ async function removeInlineScriptAndStyle(directory) { script[0], // Using script[0] to replace the entire matched script tag `` ); - fs.writeFileSync(`${directory}${fn}`, inlineScriptContent); + writeFileSync(`${directory}${fn}`, inlineScriptContent); console.log(`Inline script extracted and saved at: ${directory}${fn}`); } @@ -52,14 +51,14 @@ async function removeInlineScriptAndStyle(directory) { style[0], // Using style[0] to replace the entire matched style tag `` ); - fs.writeFileSync(`${directory}${fn}`, inlineStyleContent); + writeFileSync(`${directory}${fn}`, inlineStyleContent); console.log(`Inline style extracted and saved at: ${directory}${fn}`); } - fs.writeFileSync(file, f); + writeFileSync(file, f); } } removeInlineScriptAndStyle( - path.resolve(import.meta.dir, 'github-repo-size-extension') + resolve(import.meta.dir, 'github-repo-size-extension') ); diff --git a/package.json b/package.json index 204a334..509e543 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build:firefox": "bun run versionCTRL firefox && bun run astro build && bun run csp && bun bundler.ts", "preview": "astro preview", "astro": "astro", - "csp": "bun -b extract-inline.mjs", + "csp": "bun -b extract-inline.ts", "versionCTRL": "bun -b update-version.ts", "format": "prettier --write '**/*.{js,jsx,json,mjs,cjs,ts,tsx,md,yml,yaml}' '!github-repo-size-extension/**' '!node_modules/**' --config ./.prettierrc", "checkFormat": "prettier --check '**/*.{js,jsx,mjs,cjs,ts,tsx,md,yml,yaml}' '!github-repo-size-extension/**' '!node_modules/**' --config ./.prettierrc", diff --git a/public/manifest.json b/public/manifest.json index bb039f8..d6f0be3 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -6,29 +6,51 @@ "version": "0.2.7", "web_accessible_resources": [ { - "resources": ["script.js"], - "matches": ["https://github.com/*"] + "resources": [ + "script.js" + ], + "matches": [ + "https://github.com/*" + ] } ], "content_scripts": [ { - "matches": ["https://github.com/*"], - "js": ["content.js"], + "matches": [ + "https://github.com/*" + ], + "js": [ + "content.js" + ], "run_at": "document_end", - "css": ["content.css"] + "css": [ + "content.css" + ] } ], "action": { "default_popup": "index.html" }, - "permissions": ["storage", "tabs", "webNavigation"], + "permissions": [ + "storage", + "tabs", + "webNavigation" + ], "background": { - "service_worker": "background.js" + "scripts": [ + "background.js" + ] }, "icons": { "16": "images/icon16.png", "32": "images/icon32.png", "48": "images/icon48.png", "128": "images/icon128.png" + }, + "browser_specific_settings": { + "gecko": { + "id": "mouiylus@gmail.com", + "strict_min_version": "121.0.1" + } } -} +} \ No newline at end of file diff --git a/update-version.ts b/update-version.ts index 3769051..b390c01 100644 --- a/update-version.ts +++ b/update-version.ts @@ -1,17 +1,17 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ -const fs = require('fs').promises; -const path = require('path'); -const chalk = require('chalk'); +import { join } from 'path'; +import { readFile, writeFile } from 'fs/promises'; +import chalk from 'chalk'; + async function updateManifestVersion() { try { const arg = process.argv[2]; const browser = arg && arg === 'firefox' ? 'firefox' : 'chrome'; - const packageJsonPath = path.join(import.meta.dir, 'package.json'); + const packageJsonPath = join(import.meta.dir, 'package.json'); const { version } = await import(packageJsonPath); - const manifestPath = path.join(import.meta.dir, 'public', 'manifest.json'); - const manifestData = await fs.readFile(manifestPath, 'utf-8'); + const manifestPath = join(import.meta.dir, 'public', 'manifest.json'); + const manifestData = await readFile(manifestPath, 'utf-8'); const manifest = JSON.parse(manifestData); manifest.version = version; @@ -33,7 +33,7 @@ async function updateManifestVersion() { }; delete manifest.browser_specific_settings; } - await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2)); + await writeFile(manifestPath, JSON.stringify(manifest, null, 2)); console.log( chalk.green( @@ -42,7 +42,7 @@ async function updateManifestVersion() { ' Browser!' ) ); - } catch (error: unknown) { + } catch (error: any) { console.error(chalk.red('Error updating version: ' + error.message)); process.exit(1); } From 011a02feaba6bc62c3fcab1d75170b8d37506db6 Mon Sep 17 00:00:00 2001 From: AminoffZ Date: Sat, 16 Mar 2024 18:15:53 +0200 Subject: [PATCH 2/2] Lint Fixes --- .eslintrc.cjs | 2 +- update-version.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index b8040b0..7a28af2 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -19,6 +19,6 @@ module.exports = { sourceType: 'module', }, plugins: ['@typescript-eslint'], - ignorePatterns: ['node_modules/', 'github-repo-extension/'], + ignorePatterns: ['node_modules/', 'github-repo-size-extension/'], rules: {}, }; diff --git a/update-version.ts b/update-version.ts index b390c01..3ec9348 100644 --- a/update-version.ts +++ b/update-version.ts @@ -42,8 +42,8 @@ async function updateManifestVersion() { ' Browser!' ) ); - } catch (error: any) { - console.error(chalk.red('Error updating version: ' + error.message)); + } catch (error) { + console.error(chalk.red('Error updating version: ' + error)); process.exit(1); } }