Files
pezkuwi-extension/packages/extension/webpack.shared.cjs
T
Kurdistan Tech Ministry 758d346078 Make the Firefox source build reproducible, and let its check fail
The diff step rebuilds the extension from master-ff-src.zip (the source
archive AMO reviews) and compares the result with our build. It had never
worked, which the removed continue-on-error was hiding:

- The source zip left out .yarn/releases (yarnPath points there, so yarn
  could not start in the unpacked source) and scripts/ (build:ff runs
  scripts/postbuild-cleanup.cjs). Both are now included.
- diff.sh used `[ a || b ]`, which is not valid test syntax, and piped
  `diff -qr` into `sort`, so the check exited 0 whatever diff found. It now
  goes by diff's own exit status; with a file altered it fails.
- With those fixed, the builds still differed: webpack inlined
  import.meta.url from @pezkuwi/* packageInfo.js as the absolute file://
  path of the build machine, which also put our build directory into the
  published extension. DefinePlugin now gives it a fixed value; it is only
  shown in duplicate-version warnings.

Also fail-fast: false on the matrix. Without continue-on-error, the first
red step cancelled the others, so their results were lost.

Checked locally with node_modules as locked: "Builds are identical".
2026-10-08 09:07:34 +04:00

162 lines
4.2 KiB
JavaScript

// Copyright 2019-2026 @pezkuwi/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const ManifestPlugin = require('webpack-extension-manifest-plugin');
const { blake2AsHex } = require('@pezkuwi/util-crypto');
const pkgJson = require('./package.json');
const manifest = require('./manifest.json');
const EXT_NAME = manifest.short_name;
const packages = [
'extension',
'extension-base',
'extension-chains',
'extension-dapp',
'extension-inject',
'extension-ui'
];
module.exports = (entry, alias = {}) => ({
context: __dirname,
devtool: false,
entry,
target: ['web', 'es2022'],
module: {
rules: [
{
test: /\.js$/,
loader: 'string-replace-loader',
options: {
multiple: [
{
search: /Function\s*\(\s*["']return this["']\s*\)\s*\(\s*\)/g,
replace: 'globalThis'
},
{
search: /Function\s*\(\s*["']return this["']\s*\)/g,
replace: '(function(){return globalThis})'
}
]
}
},
{
exclude: /(node_modules)/,
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('ts-loader'),
options: {
configFile: 'tsconfig.webpack.json',
transpileOnly: true
}
}
]
},
{
test: [/\.svg$/, /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.woff2?$/],
use: [
{
loader: require.resolve('url-loader'),
options: {
esModule: false,
limit: 10000,
name: 'static/[name].[ext]'
}
}
]
}
]
},
output: {
chunkFilename: '[name].js',
filename: '[name].js',
globalObject: 'globalThis',
path: path.join(__dirname, 'build'),
environment: {
arrowFunction: true,
bigIntLiteral: true,
const: true,
destructuring: true,
dynamicImport: true,
forOf: true,
module: true,
optionalChaining: true,
templateLiteral: true
}
},
performance: {
hints: false
},
optimization: {
minimizer: [
new (require('terser-webpack-plugin'))({
terserOptions: {
compress: {
evaluate: false,
unsafe_Function: false
},
mangle: true,
format: {
comments: false
}
},
extractComments: false
})
]
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser.js'
}),
new webpack.IgnorePlugin({
contextRegExp: /moment$/,
resourceRegExp: /^\.\/locale$/
}),
new webpack.DefinePlugin({
// @pezkuwi/* packageInfo.js reads import.meta.url, which webpack would bake in as
// the absolute file:// path of the machine that built it. That leaks the build
// directory into the published extension and makes the Firefox source build
// (scripts/diff.sh, and AMO's own review) differ from ours. The value is only
// shown in duplicate-version warnings.
'import.meta.url': JSON.stringify('file:///pezkuwi-extension/node_modules/'),
'process.env': {
EXTENSION_PREFIX: JSON.stringify(process.env.EXTENSION_PREFIX || EXT_NAME),
NODE_ENV: JSON.stringify('production'),
PORT_PREFIX: JSON.stringify(blake2AsHex(JSON.stringify(manifest), 64))
}
}),
new CopyPlugin({ patterns: [{ from: 'public' }] }),
new ManifestPlugin({
config: {
base: manifest,
extend: {
version: pkgJson.version.split('-')[0] // remove possible -beta.xx
}
}
})
],
resolve: {
alias: packages.reduce((alias, p) => ({
...alias,
[`@pezkuwi/${p}`]: path.resolve(__dirname, `../${p}/src`)
}), alias),
extensionAlias: {
'.js': ['.ts', '.tsx', '.js']
},
extensions: ['.js', '.jsx', '.ts', '.tsx'],
fallback: {
crypto: require.resolve('crypto-browserify'),
path: require.resolve('path-browserify'),
stream: require.resolve('stream-browserify')
}
},
watch: false
});