2022-01-08 22:59:18 +03:00
|
|
|
const path = require("path");
|
2025-10-20 18:43:06 +02:00
|
|
|
const fs = require("fs");
|
2022-01-08 22:59:18 +03:00
|
|
|
const CopyPlugin = require("copy-webpack-plugin");
|
2026-09-01 23:41:28 +02:00
|
|
|
const webpack = require("webpack");
|
|
|
|
|
const { LiveBuildMarkerPlugin, createLiveBuildId } = require("./webpack.live-build-marker");
|
2021-12-14 23:13:20 +01:00
|
|
|
|
2026-09-01 23:41:28 +02:00
|
|
|
const extensionVersion = (process.env.npm_package_version || require("./package.json").version).replace("-", ".");
|
2025-10-20 18:43:06 +02:00
|
|
|
const entries = ["ryd.content-script", "ryd.background", "popup", "ryd.changelog"];
|
2022-01-10 23:35:07 +01:00
|
|
|
|
|
|
|
|
const ignorePatterns = [
|
|
|
|
|
"**/manifest-**",
|
|
|
|
|
"**/dist/**",
|
|
|
|
|
"**/src/**",
|
|
|
|
|
"**/readme.md",
|
2022-07-26 00:05:20 +02:00
|
|
|
...entries.map((entry) => `**/${entry}.js`),
|
2022-01-10 23:35:07 +01:00
|
|
|
];
|
|
|
|
|
|
2024-01-15 11:10:35 +03:00
|
|
|
const manifestTransform = (content, filename) => {
|
|
|
|
|
const filteredContent = content
|
|
|
|
|
.toString()
|
2025-10-20 18:43:06 +02:00
|
|
|
.split("\n")
|
|
|
|
|
.filter((str) => !str.trimStart().startsWith("//"))
|
|
|
|
|
.join("\n");
|
2024-01-15 11:10:35 +03:00
|
|
|
|
|
|
|
|
const manifestData = JSON.parse(filteredContent);
|
|
|
|
|
manifestData.version = extensionVersion;
|
|
|
|
|
return JSON.stringify(manifestData, null, 2);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const i18nTransform = (content, filename) => {
|
2025-10-20 18:43:06 +02:00
|
|
|
if (!filename.endsWith("messages.json")) return content;
|
2024-01-15 11:10:35 +03:00
|
|
|
|
|
|
|
|
return content.toString().replace(/__RYD_VERSION__/g, extensionVersion);
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-20 18:43:06 +02:00
|
|
|
class MirrorJsOutputsPlugin {
|
|
|
|
|
constructor(targetDirs) {
|
|
|
|
|
this.targetDirs = targetDirs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
apply(compiler) {
|
|
|
|
|
compiler.hooks.afterEmit.tapPromise("MirrorJsOutputsPlugin", async () => {
|
|
|
|
|
const { promises: fsp } = fs;
|
|
|
|
|
const outputPath = compiler.options.output.path;
|
|
|
|
|
const entries = await fsp.readdir(outputPath).catch(() => []);
|
|
|
|
|
const jsAssets = entries.filter((name) => name.endsWith(".js"));
|
|
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
|
this.targetDirs.map(async (dir) => {
|
|
|
|
|
const targetDir = path.join(outputPath, dir);
|
|
|
|
|
await fsp.mkdir(targetDir, { recursive: true });
|
|
|
|
|
|
|
|
|
|
const existingFiles = await fsp.readdir(targetDir).catch(() => []);
|
|
|
|
|
await Promise.all(
|
|
|
|
|
existingFiles
|
2026-09-01 23:41:28 +02:00
|
|
|
.filter((file) => jsAssets.includes(file))
|
|
|
|
|
.map((file) => fsp.rm(path.join(targetDir, file), { force: true })),
|
2025-10-20 18:43:06 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
|
jsAssets.map((asset) =>
|
|
|
|
|
fsp.copyFile(path.join(outputPath, asset), path.join(targetDir, path.basename(asset))),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-01 23:41:28 +02:00
|
|
|
module.exports = (env = {}, argv = {}) => {
|
|
|
|
|
const liveTestBuild = env.liveTest === true || env.liveTest === "true";
|
|
|
|
|
const liveBuildId = createLiveBuildId(liveTestBuild);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
entry: Object.fromEntries(
|
|
|
|
|
entries.map((entry) => [entry, path.join(__dirname, "./Extensions/combined/", `${entry}.js`)]),
|
|
|
|
|
),
|
|
|
|
|
output: {
|
|
|
|
|
filename: "[name].js",
|
|
|
|
|
path: path.resolve(__dirname, "Extensions/combined/dist"),
|
|
|
|
|
clean: true,
|
|
|
|
|
},
|
|
|
|
|
cache: false,
|
|
|
|
|
optimization: {
|
|
|
|
|
minimize: false,
|
|
|
|
|
},
|
|
|
|
|
watchOptions: {
|
|
|
|
|
ignored: "**/dist/**",
|
|
|
|
|
},
|
|
|
|
|
plugins: [
|
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
|
__RYD_LIVE_BUILD_ID__: JSON.stringify(liveBuildId),
|
|
|
|
|
__RYD_LIVE_TEST_BUILD__: JSON.stringify(liveTestBuild),
|
|
|
|
|
}),
|
|
|
|
|
...(liveTestBuild
|
|
|
|
|
? [
|
|
|
|
|
new LiveBuildMarkerPlugin(liveBuildId, [
|
|
|
|
|
"chrome/live-build.json",
|
|
|
|
|
"firefox/live-build.json",
|
|
|
|
|
"safari/live-build.json",
|
|
|
|
|
]),
|
|
|
|
|
]
|
|
|
|
|
: []),
|
|
|
|
|
// exclude locale files in moment
|
|
|
|
|
new CopyPlugin({
|
|
|
|
|
patterns: [
|
|
|
|
|
{
|
|
|
|
|
from: "./Extensions/combined",
|
|
|
|
|
to: "./chrome",
|
|
|
|
|
globOptions: {
|
|
|
|
|
ignore: ignorePatterns,
|
|
|
|
|
},
|
|
|
|
|
transform: i18nTransform,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: "./Extensions/combined/manifest-chrome.json",
|
|
|
|
|
to: "./chrome/manifest.json",
|
|
|
|
|
transform: manifestTransform,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: "./Extensions/combined",
|
|
|
|
|
to: "./firefox",
|
|
|
|
|
globOptions: {
|
|
|
|
|
ignore: ignorePatterns,
|
|
|
|
|
},
|
|
|
|
|
transform: i18nTransform,
|
2022-01-08 22:59:18 +03:00
|
|
|
},
|
2026-09-01 23:41:28 +02:00
|
|
|
{
|
|
|
|
|
from: "./Extensions/combined/manifest-firefox.json",
|
|
|
|
|
to: "./firefox/manifest.json",
|
|
|
|
|
transform: manifestTransform,
|
2022-01-08 22:59:18 +03:00
|
|
|
},
|
2026-09-01 23:41:28 +02:00
|
|
|
{
|
|
|
|
|
from: "./Extensions/combined",
|
|
|
|
|
to: "./safari",
|
|
|
|
|
globOptions: {
|
|
|
|
|
ignore: ignorePatterns,
|
|
|
|
|
},
|
|
|
|
|
transform: i18nTransform,
|
2023-04-02 05:17:18 -07:00
|
|
|
},
|
2026-09-01 23:41:28 +02:00
|
|
|
{
|
|
|
|
|
from: "./Extensions/combined/manifest-safari.json",
|
|
|
|
|
to: "./safari/manifest.json",
|
|
|
|
|
transform: manifestTransform,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}),
|
|
|
|
|
new MirrorJsOutputsPlugin(["chrome", "firefox", "safari"]),
|
|
|
|
|
],
|
|
|
|
|
experiments: {
|
|
|
|
|
topLevelAwait: true,
|
|
|
|
|
},
|
|
|
|
|
devtool: argv.mode === "development" ? "inline-source-map" : false,
|
|
|
|
|
};
|
|
|
|
|
};
|