2019-09-13 13:49:11 +02:00
|
|
|
import * as env from "../buildSrc/env.js"
|
2025-01-02 18:47:57 +01:00
|
|
|
import { preludeEnvPlugin } from "../buildSrc/env.js"
|
2022-05-09 18:41:10 +02:00
|
|
|
import fs from "fs-extra"
|
2025-01-02 18:47:57 +01:00
|
|
|
import path, { dirname } from "node:path"
|
2022-12-27 15:37:40 +01:00
|
|
|
import { renderHtml } from "../buildSrc/LaunchHtml.js"
|
2023-04-19 13:58:49 +02:00
|
|
|
import { getTutanotaAppVersion, runStep, writeFile } from "../buildSrc/buildUtils.js"
|
2023-02-23 18:09:24 +01:00
|
|
|
import { buildPackages } from "../buildSrc/packageBuilderFunctions.js"
|
2023-09-26 18:03:30 +02:00
|
|
|
import { domainConfigs } from "../buildSrc/DomainConfigs.js"
|
2023-04-19 13:58:49 +02:00
|
|
|
import { sh } from "../buildSrc/sh.js"
|
2025-01-02 18:47:57 +01:00
|
|
|
import { rolldown } from "rolldown"
|
|
|
|
import { resolveLibs } from "../buildSrc/RollupConfig.js"
|
|
|
|
import { nodeGypPlugin } from "../buildSrc/nodeGypPlugin.js"
|
|
|
|
import { fileURLToPath } from "node:url"
|
2025-04-24 16:55:58 +02:00
|
|
|
import { copyCryptoPrimitiveCrateIntoWasmDir, WASM_PACK_OUT_DIR } from "../buildSrc/cryptoPrimitivesUtils.js"
|
2025-01-02 18:47:57 +01:00
|
|
|
|
|
|
|
const currentDir = dirname(fileURLToPath(import.meta.url))
|
|
|
|
const projectRoot = path.resolve(path.join(currentDir, ".."))
|
2021-02-04 10:21:31 +01:00
|
|
|
|
2025-03-10 16:19:11 +01:00
|
|
|
export async function runTestBuild({ networkDebugging = false, clean, fast = false }) {
|
2022-05-09 18:41:10 +02:00
|
|
|
if (clean) {
|
|
|
|
await runStep("Clean", async () => {
|
|
|
|
await fs.emptyDir("build")
|
2025-04-24 16:55:58 +02:00
|
|
|
fs.rm(projectRoot + WASM_PACK_OUT_DIR, { recursive: true, force: true })
|
2022-05-09 18:41:10 +02:00
|
|
|
})
|
|
|
|
}
|
2019-09-13 13:49:11 +02:00
|
|
|
|
add MailDetails feature, #4719
server issues: 1276, 1271, 1279, 1272, 1270, 1258, 1254, 1253, 1242, 1241
2022-11-03 19:03:54 +01:00
|
|
|
if (!fast) {
|
|
|
|
await runStep("Packages", async () => {
|
2025-01-09 15:47:37 +01:00
|
|
|
await buildPackages("..")
|
2025-04-24 16:55:58 +02:00
|
|
|
// we know which wasm need to be included in the project, instead of running branches condition on each and every file of the project we do some
|
|
|
|
// transformation AOT for our three files (currently only crypto-primitives but argon2 and liboqs will follow
|
|
|
|
await copyCryptoPrimitiveCrateIntoWasmDir({
|
|
|
|
wasmOutputDir: "build",
|
|
|
|
pathSourcePrefix: "../",
|
|
|
|
})
|
add MailDetails feature, #4719
server issues: 1276, 1271, 1279, 1272, 1270, 1258, 1254, 1253, 1242, 1241
2022-11-03 19:03:54 +01:00
|
|
|
})
|
2019-09-13 13:49:11 +02:00
|
|
|
|
add MailDetails feature, #4719
server issues: 1276, 1271, 1279, 1272, 1270, 1258, 1254, 1253, 1242, 1241
2022-11-03 19:03:54 +01:00
|
|
|
await runStep("Types", async () => {
|
|
|
|
await sh`npx tsc --incremental true --noEmit true`
|
|
|
|
})
|
|
|
|
}
|
2022-05-09 18:41:10 +02:00
|
|
|
|
2023-04-19 13:58:49 +02:00
|
|
|
const version = await getTutanotaAppVersion()
|
2025-03-10 16:19:11 +01:00
|
|
|
const localEnv = env.create({
|
|
|
|
staticUrl: "http://localhost:9000",
|
|
|
|
version,
|
|
|
|
mode: "Test",
|
|
|
|
dist: false,
|
|
|
|
domainConfigs,
|
|
|
|
networkDebugging,
|
|
|
|
})
|
2019-09-13 13:49:11 +02:00
|
|
|
|
2022-05-09 18:41:10 +02:00
|
|
|
await runStep("Assets", async () => {
|
|
|
|
const pjPath = path.join("..", "package.json")
|
2022-12-27 15:37:40 +01:00
|
|
|
await fs.mkdir(inBuildDir(), { recursive: true })
|
2022-05-09 18:41:10 +02:00
|
|
|
await fs.copyFile(pjPath, inBuildDir("package.json"))
|
2022-05-12 16:51:15 +02:00
|
|
|
await createUnitTestHtml(localEnv)
|
2019-09-13 13:49:11 +02:00
|
|
|
})
|
2025-01-02 18:47:57 +01:00
|
|
|
await runStep("Rolldown", async () => {
|
|
|
|
const { rollupWasmLoader } = await import("@tutao/tuta-wasm-loader")
|
|
|
|
const bundle = await rolldown({
|
2025-07-09 15:28:44 +02:00
|
|
|
input: ["tests/testInBrowser.ts", "tests/testInNode.ts", "../src/common/api/common/pow-worker.ts"],
|
2025-01-02 18:47:57 +01:00
|
|
|
platform: "neutral",
|
2022-05-09 18:41:10 +02:00
|
|
|
define: {
|
|
|
|
// See Env.ts for explanation
|
2025-01-02 18:47:57 +01:00
|
|
|
LOAD_ASSERTIONS: "false",
|
2019-09-13 13:49:11 +02:00
|
|
|
},
|
2025-01-06 17:36:50 +01:00
|
|
|
|
2022-05-09 18:41:10 +02:00
|
|
|
external: [
|
|
|
|
"electron",
|
|
|
|
// esbuild can't deal with node imports in ESM output at the moment
|
|
|
|
// see https://github.com/evanw/esbuild/pull/2067
|
|
|
|
"xhr2",
|
|
|
|
"express",
|
|
|
|
"server-destroy",
|
|
|
|
"body-parser",
|
2022-06-27 15:33:32 +02:00
|
|
|
"jsdom",
|
2025-01-02 18:47:57 +01:00
|
|
|
/node:.*/,
|
2023-12-18 11:36:38 +01:00
|
|
|
"http",
|
|
|
|
"stream",
|
|
|
|
"fs",
|
|
|
|
"assert",
|
|
|
|
"net",
|
|
|
|
"diagnostics_channel",
|
|
|
|
"zlib",
|
|
|
|
"console",
|
|
|
|
"async_hooks",
|
|
|
|
"util/types",
|
|
|
|
"perf_hooks",
|
|
|
|
"worker_threads",
|
|
|
|
"path",
|
|
|
|
"tls",
|
|
|
|
"buffer",
|
|
|
|
"events",
|
2024-02-26 14:33:37 +01:00
|
|
|
"util",
|
2023-12-18 11:36:38 +01:00
|
|
|
"string_decoder",
|
2024-11-29 10:17:40 +01:00
|
|
|
"crypto", // oxmsg needs it
|
2025-02-17 12:05:09 +01:00
|
|
|
"memcpy", // optional dep of oxmsg
|
2022-05-09 18:41:10 +02:00
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
preludeEnvPlugin(localEnv),
|
2025-01-02 18:47:57 +01:00
|
|
|
resolveLibs(".."),
|
|
|
|
nodeGypPlugin({
|
|
|
|
rootDir: projectRoot,
|
2022-05-09 18:41:10 +02:00
|
|
|
platform: process.platform,
|
2023-11-20 17:47:22 +01:00
|
|
|
architecture: process.arch,
|
2025-04-25 13:43:07 +02:00
|
|
|
nodeModule: "@signalapp/sqlcipher",
|
2025-01-02 18:47:57 +01:00
|
|
|
environment: "node",
|
2025-04-25 13:43:07 +02:00
|
|
|
targetName: "node_sqlcipher",
|
2022-05-09 18:41:10 +02:00
|
|
|
}),
|
2025-01-02 18:47:57 +01:00
|
|
|
rollupWasmLoader({
|
2025-04-24 16:55:58 +02:00
|
|
|
output: `${process.cwd()}/build`,
|
2024-04-15 09:16:38 +02:00
|
|
|
webassemblyLibraries: [
|
|
|
|
{
|
|
|
|
name: "liboqs.wasm",
|
2025-01-06 18:34:51 +01:00
|
|
|
command: "make -f Makefile_liboqs build",
|
2024-07-02 16:10:27 +02:00
|
|
|
workingDir: `${process.cwd()}/../libs/webassembly/`,
|
2025-04-24 16:55:58 +02:00
|
|
|
outputPath: `${process.cwd()}/build/liboqs.wasm`,
|
2025-01-06 18:34:51 +01:00
|
|
|
fallback: {
|
|
|
|
command: "make -f Makefile_liboqs fallback",
|
|
|
|
workingDir: `${process.cwd()}/../libs/webassembly/`,
|
2025-04-24 16:55:58 +02:00
|
|
|
outputPath: `${process.cwd()}/build/liboqs.js`,
|
2025-01-06 18:34:51 +01:00
|
|
|
},
|
2024-04-15 09:16:38 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "argon2.wasm",
|
2025-01-06 18:34:51 +01:00
|
|
|
command: "make -f Makefile_argon2 build",
|
2024-07-02 16:10:27 +02:00
|
|
|
workingDir: `${process.cwd()}/../libs/webassembly/`,
|
2025-04-24 16:55:58 +02:00
|
|
|
outputPath: `${process.cwd()}/build/argon2.wasm`,
|
2025-01-06 18:34:51 +01:00
|
|
|
fallback: {
|
|
|
|
command: "make -f Makefile_argon2 fallback",
|
|
|
|
workingDir: `${process.cwd()}/../libs/webassembly/`,
|
2025-04-24 16:55:58 +02:00
|
|
|
outputPath: `${process.cwd()}/build/argon2.js`,
|
2025-01-06 18:34:51 +01:00
|
|
|
},
|
2024-04-15 09:16:38 +02:00
|
|
|
},
|
|
|
|
],
|
2023-07-17 11:42:02 +02:00
|
|
|
}),
|
2022-12-27 15:37:40 +01:00
|
|
|
],
|
2025-01-02 18:47:57 +01:00
|
|
|
resolve: {
|
|
|
|
mainFields: ["module", "main"],
|
|
|
|
alias: {
|
|
|
|
// Take browser testdouble without funny require() magic
|
|
|
|
testdouble: path.resolve("../node_modules/testdouble/dist/testdouble.js"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onwarn: (warning, defaultHandler) => {
|
|
|
|
if (warning.code !== "EVAL") {
|
|
|
|
defaultHandler(warning)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
await bundle.write({
|
|
|
|
dir: "./build",
|
|
|
|
format: "esm",
|
|
|
|
sourcemap: true,
|
2025-04-25 13:43:07 +02:00
|
|
|
// overwrite the files rather than keeping all versions in the build folder
|
|
|
|
chunkFileNames: "[name]-chunk.js",
|
2022-05-09 18:41:10 +02:00
|
|
|
})
|
|
|
|
})
|
2019-09-13 13:49:11 +02:00
|
|
|
}
|
|
|
|
|
2022-05-12 16:51:15 +02:00
|
|
|
async function createUnitTestHtml(localEnv) {
|
2023-06-29 18:26:45 +02:00
|
|
|
const imports = [{ src: `./testInBrowser.js`, type: "module" }]
|
2022-05-12 16:51:15 +02:00
|
|
|
const htmlFilePath = inBuildDir("test.html")
|
2021-02-16 19:48:27 +01:00
|
|
|
|
2022-05-12 16:51:15 +02:00
|
|
|
console.log(`Generating browser tests at "${htmlFilePath}"`)
|
2019-09-13 13:49:11 +02:00
|
|
|
|
|
|
|
const html = await renderHtml(imports, localEnv)
|
2022-05-12 16:51:15 +02:00
|
|
|
await writeFile(htmlFilePath, html)
|
2021-07-15 17:15:16 +02:00
|
|
|
}
|
|
|
|
|
2022-05-09 18:41:10 +02:00
|
|
|
function inBuildDir(...files) {
|
|
|
|
return path.join("build", ...files)
|
2022-12-27 15:37:40 +01:00
|
|
|
}
|