From 42a02dea80094145bea4f07c72e84a5868d63e69 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Sun, 30 Aug 2026 01:01:48 +0530 Subject: feat: replaced python scripts with lua - using lua scripts where we previously used python for lower resource consumption --- .../chromium/extensions/inject_extension_key.lua | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 modules/web/chromium/extensions/inject_extension_key.lua (limited to 'modules/web/chromium/extensions/inject_extension_key.lua') diff --git a/modules/web/chromium/extensions/inject_extension_key.lua b/modules/web/chromium/extensions/inject_extension_key.lua new file mode 100644 index 0000000..30ed318 --- /dev/null +++ b/modules/web/chromium/extensions/inject_extension_key.lua @@ -0,0 +1,72 @@ +#!/usr/bin/env luajit +-- inject_extension_key: strip JSON comments and trailing commas from a +-- manifest, inject the extension's public key, and rewrite it. +local dkjson = require("dkjson") + +local manifest_path = assert(arg[1], "usage: inject_extension_key.lua ") +local ext_key = assert(arg[2], "usage: inject_extension_key.lua ") + +local f = assert(io.open(manifest_path, "r")) +local content = f:read("*a") +f:close() + +-- Hand-rolled scanner that removes // and /* */ comments and mid-JSON +-- trailing commas while respecting string literals (including escapes). +local sb = {} +local i, n = 1, #content +local in_string = false + +local function trim_trailing_comma() + while #sb > 0 and (sb[#sb] == " " or sb[#sb] == "\t" or sb[#sb] == "\n" or sb[#sb] == "\r") do + sb[#sb] = nil + end + if #sb > 0 and sb[#sb] == "," then + sb[#sb] = nil + end +end + +while i <= n do + local c = content:sub(i, i) + if in_string then + sb[#sb + 1] = c + if c == "\\" and i < n then + sb[#sb + 1] = content:sub(i + 1, i + 1) + i = i + 2 + else + if c == '"' then + in_string = false + end + i = i + 1 + end + else + local two = content:sub(i, i + 1) + if c == '"' then + in_string = true + sb[#sb + 1] = c + i = i + 1 + elseif two == "//" then + local nl = content:find("\n", i) or (n + 1) + i = nl + elseif two == "/*" then + local close = content:find("%*/", i + 2) + if not close then + break + end + i = close + 2 + elseif c == "]" or c == "}" then + trim_trailing_comma() + sb[#sb + 1] = c + i = i + 1 + else + sb[#sb + 1] = c + i = i + 1 + end + end +end + +local data = dkjson.decode(table.concat(sb)) +data.key = ext_key + +f = assert(io.open(manifest_path, "w")) +f:write(dkjson.encode(data, { indent = true })) +f:close() -- cgit v1.2.3