2020-05-11 19:37:57 +00:00
/* eslint-env node */
2023-03-25 07:48:40 +00:00
import fs from "fs" ;
import url from "url" ;
import json5 from "json5" ;
import CopyPlugin from "copy-webpack-plugin" ;
2019-08-20 04:29:53 +00:00
2023-03-25 07:48:40 +00:00
/ * *
* @ param { Buffer } content
* @ param { Record < string , any > } env
* @ returns { string }
* /
2021-04-21 19:26:02 +00:00
function transformManifest ( content , env ) {
2023-03-25 07:48:40 +00:00
const manifest = json5 . parse ( content . toString ( ) ) ;
2021-04-21 19:26:02 +00:00
2023-03-25 07:48:40 +00:00
let packageVersion = process . env [ "npm_package_version" ] ;
let versionChannel = process . env [ "CFG_RELEASE_CHANNEL" ] || "nightly" ;
2023-01-29 20:55:20 +00:00
let buildDate = new Date ( ) . toISOString ( ) . substring ( 0 , 10 ) ;
2023-05-30 20:24:43 +00:00
let buildId = process . env [ "BUILD_ID" ] ;
let firefoxExtensionId =
2023-03-25 07:48:40 +00:00
process . env [ "FIREFOX_EXTENSION_ID" ] || "ruffle@ruffle.rs" ;
2023-01-29 20:55:20 +00:00
2023-03-25 07:48:40 +00:00
if ( process . env [ "ENABLE_VERSION_SEAL" ] === "true" ) {
2023-01-29 20:55:20 +00:00
if ( fs . existsSync ( "../../version_seal.json" ) ) {
2023-05-30 20:24:43 +00:00
const versionSeal = JSON . parse (
2023-07-20 11:19:39 +00:00
fs . readFileSync ( "../../version_seal.json" , "utf8" ) ,
2023-01-29 20:55:20 +00:00
) ;
2023-05-30 20:24:43 +00:00
packageVersion = versionSeal . version _number ;
versionChannel = versionSeal . version _channel ;
buildDate = versionSeal . build _date . substring ( 0 , 10 ) ;
buildId = versionSeal . build _id ;
firefoxExtensionId = versionSeal . firefox _extension _id ;
2023-01-29 20:55:20 +00:00
} else {
throw new Error (
2023-10-27 17:50:22 +00:00
"Version seal requested but not found. To generate it, please run web/packages/core/tools/set_version.js using node in the web directory, with the ENABLE_VERSION_SEAL environment variable set to true." ,
2023-01-29 20:55:20 +00:00
) ;
}
}
// At this point all code below needs to be deterministic. If you want other
// information to be included here you must store it in the version seal
// when it gets generated in web/packages/core/tools/set_version.js and then
// load it in the code above.
2021-04-21 19:26:02 +00:00
// The extension marketplaces require the version to monotonically increase,
2022-01-07 14:47:12 +00:00
// so append the build number onto the end of the manifest version.
2023-05-30 20:24:43 +00:00
manifest . version = buildId
? ` ${ packageVersion } . ${ buildId } `
2021-04-21 19:26:02 +00:00
: packageVersion ;
2023-03-25 07:48:40 +00:00
if ( env [ "firefox" ] ) {
2021-08-16 19:34:12 +00:00
manifest . browser _specific _settings = {
gecko : {
2023-05-30 20:24:43 +00:00
id : firefoxExtensionId ,
2021-04-21 19:26:02 +00:00
} ,
2021-08-16 19:34:12 +00:00
} ;
} else {
manifest . version _name =
versionChannel === "nightly"
? ` ${ packageVersion } nightly ${ buildDate } `
: packageVersion ;
2021-04-21 19:26:02 +00:00
}
return JSON . stringify ( manifest ) ;
}
2023-03-25 07:48:40 +00:00
/ * *
* @ type { import ( "webpack-cli" ) . CallableOption }
* /
2023-08-12 19:52:12 +00:00
export default function ( /** @type {Record<string, any>} */ env , _argv ) {
2023-03-25 07:48:40 +00:00
const mode =
/** @type {import("webpack").Configuration["mode"]} */ (
process . env [ "NODE_ENV" ]
) || "production" ;
2020-05-12 22:24:41 +00:00
console . log ( ` Building ${ mode } ... ` ) ;
2019-08-20 04:29:53 +00:00
2020-05-12 22:24:41 +00:00
return {
2021-02-17 04:39:46 +00:00
mode ,
2019-08-27 02:22:00 +00:00
entry : {
2021-04-21 20:38:23 +00:00
popup : "./src/popup.ts" ,
options : "./src/options.ts" ,
content : "./src/content.ts" ,
ruffle : "./src/ruffle.ts" ,
background : "./src/background.ts" ,
player : "./src/player.ts" ,
2023-02-15 05:05:20 +00:00
pluginPolyfill : "./src/plugin-polyfill.ts" ,
2024-06-21 15:05:53 +00:00
siteContentScript4399 : "./src/4399-content-script.ts" ,
2019-08-27 02:22:00 +00:00
} ,
2020-05-12 22:24:41 +00:00
output : {
2023-03-25 07:48:40 +00:00
path : url . fileURLToPath ( new URL ( "assets/dist/" , import . meta . url ) ) ,
2021-02-17 04:39:46 +00:00
publicPath : "" ,
2021-03-03 14:19:46 +00:00
clean : true ,
2024-02-19 19:31:58 +00:00
assetModuleFilename : "assets/[name][ext][query]" ,
2020-05-12 22:24:41 +00:00
} ,
2021-02-17 04:39:46 +00:00
module : {
rules : [
2021-04-21 20:38:23 +00:00
{
test : /\.ts$/i ,
use : "ts-loader" ,
} ,
2021-02-17 04:39:46 +00:00
] ,
} ,
2021-04-21 20:38:23 +00:00
resolve : {
extensions : [ ".ts" , "..." ] ,
} ,
2021-12-10 18:23:51 +00:00
performance : {
2023-03-25 07:48:40 +00:00
/ * *
* @ param { string } assetFilename
* @ returns { boolean }
* /
2021-12-10 18:23:51 +00:00
assetFilter : ( assetFilename ) =>
! /\.(map|wasm)$/i . test ( assetFilename ) ,
} ,
2022-12-14 23:10:41 +00:00
optimization : {
minimize : false ,
} ,
2020-05-26 18:11:48 +00:00
plugins : [
2021-03-04 20:59:10 +00:00
new CopyPlugin ( {
2021-03-09 19:11:46 +00:00
patterns : [
{
2023-08-12 19:52:12 +00:00
from : env [ "firefox" ]
? "manifest_firefox.json5"
: "manifest_other.json5" ,
2021-04-21 19:26:02 +00:00
to : "../manifest.json" ,
2023-03-25 07:48:40 +00:00
transform : ( content ) =>
transformManifest (
content ,
2023-07-20 11:19:39 +00:00
/** @type {Record<string, any>} */ ( env ) ,
2023-03-25 07:48:40 +00:00
) ,
2021-03-09 19:11:46 +00:00
} ,
{ from : "LICENSE*" } ,
{ from : "README.md" } ,
2024-06-21 15:05:53 +00:00
{ from : "4399_rules.json" } ,
2021-03-09 19:11:46 +00:00
] ,
2020-05-26 18:11:48 +00:00
} ) ,
] ,
2020-05-12 22:24:41 +00:00
} ;
2023-03-25 07:48:40 +00:00
}