Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Format JavaScript checks and GitHub scripts

Manav Rathi159b3a3c6b27
diff --git a/.github/checks/documentation-comments/check.mjs b/.github/checks/documentation-comments/check.mjs
index 97b19da377..b2fb373b17 100644
--- a/.github/checks/documentation-comments/check.mjs
+++ b/.github/checks/documentation-comments/check.mjs
@@ -34,7 +34,12 @@ const paths = git(
"-z",
)
.split("\0")
- .filter((path) => path && extensions.has(extname(path)) && existsSync(resolve(root, path)));
+ .filter(
+ (path) =>
+ path &&
+ extensions.has(extname(path)) &&
+ existsSync(resolve(root, path)),
+ );
if (!paths.length) throw new Error(`${root}: found no source files`);
@@ -45,7 +50,12 @@ for (const path of paths) {
const clap = path.endsWith(".rs") ? clapRanges(source, comments) : [];
for (const comment of comments) {
if (isToolInput(path, comment.text)) continue;
- if (clap.some(([start, end]) => comment.line >= start && comment.line <= end)) continue;
+ if (
+ clap.some(
+ ([start, end]) => comment.line >= start && comment.line <= end,
+ )
+ )
+ continue;
console.error(
`${path}:${comment.line}: documentation comment; use an ordinary comment if needed`,
);
@@ -67,21 +77,34 @@ function documentationComments(source) {
for (let i = 0; i < lines.length; i++) {
if (/^\s*(?:\/\/\/|\/\/!)/.test(lines[i])) {
const start = i;
- while (i < lines.length - 1 && /^\s*(?:\/\/\/|\/\/!)/.test(lines[i + 1])) i++;
- comments.push({ line: start + 1, endLine: i + 1, text: lines.slice(start, i + 1).join("\n") });
+ while (
+ i < lines.length - 1 &&
+ /^\s*(?:\/\/\/|\/\/!)/.test(lines[i + 1])
+ )
+ i++;
+ comments.push({
+ line: start + 1,
+ endLine: i + 1,
+ text: lines.slice(start, i + 1).join("\n"),
+ });
continue;
}
if (!/^\s*\/\*(?:\*|!)/.test(lines[i])) continue;
const start = i;
while (i < lines.length && !lines[i].includes("*/")) i++;
- comments.push({ line: start + 1, endLine: i + 1, text: lines.slice(start, i + 1).join("\n") });
+ comments.push({
+ line: start + 1,
+ endLine: i + 1,
+ text: lines.slice(start, i + 1).join("\n"),
+ });
}
return comments;
}
function isToolInput(path, comment) {
const extension = extname(path);
- if (![".cjs", ".js", ".jsx", ".mjs", ".ts", ".tsx"].includes(extension)) return false;
+ if (![".cjs", ".js", ".jsx", ".mjs", ".ts", ".tsx"].includes(extension))
+ return false;
if (
comment
.split("\n")
@@ -128,10 +151,14 @@ function clapRanges(source, comments) {
const help = comments.find((comment) => comment.endLine === start - 1);
if (help) start = help.line;
let derive = lines[i];
- while (i < lines.length - 1 && !derive.includes(")]")) derive += `\n${lines[++i]}`;
+ while (i < lines.length - 1 && !derive.includes(")]"))
+ derive += `\n${lines[++i]}`;
if (!/\b(?:Args|Parser|Subcommand)\b/.test(derive)) continue;
let declaration = i + 1;
- while (declaration < lines.length && !/\b(?:struct|enum)\s+\w+/.test(lines[declaration])) {
+ while (
+ declaration < lines.length &&
+ !/\b(?:struct|enum)\s+\w+/.test(lines[declaration])
+ ) {
declaration++;
}
let depth = 0;
diff --git a/.github/checks/documentation-comments/test.mjs b/.github/checks/documentation-comments/test.mjs
index 305643a339..6181831a07 100644
--- a/.github/checks/documentation-comments/test.mjs
+++ b/.github/checks/documentation-comments/test.mjs
@@ -16,7 +16,8 @@ let result = run(
"styles/value.scss": "/** API documentation. */\n.value {}\n",
"styles/value.css": "/** API documentation. */\n.value {}\n",
"build/plugin.gradle": "/// API documentation.\n",
- "gen/value.ts": "/** A path alone does not mark a file as generated. */\n",
+ "gen/value.ts":
+ "/** A path alone does not mark a file as generated. */\n",
"web/reference.ts": [
'/// <reference types="vite/client" />',
"/// API documentation.",
@@ -27,16 +28,19 @@ let result = run(
" */",
"function configure(value) {}",
].join("\n"),
- "web/type.js": "/** @type {string} API documentation. */\nconst value = '';\n",
+ "web/type.js":
+ "/** @type {string} API documentation. */\nconst value = '';\n",
"web/type.ts": "/** @type {string} */\nconst value = '';\n",
- "web/param.js": "/** @param {string} */\nfunction configure(value) {}\n",
+ "web/param.js":
+ "/** @param {string} */\nfunction configure(value) {}\n",
"web/satisfies.js": [
"/** @satisfies {Record<string, string>}",
" * API documentation.",
" */",
"const values = {};",
].join("\n"),
- "web/returns.js": "/** @returns {string} API documentation. */\nfunction value() {}\n",
+ "web/returns.js":
+ "/** @returns {string} API documentation. */\nfunction value() {}\n",
"rust/clap.rs": [
"#[derive(clap::Parser)]",
"struct Args {",
@@ -55,9 +59,7 @@ let result = run(
].join("\n"),
"deleted.rs": "/// Deleted documentation.\n",
},
- {
- "native/Value.swift": "/// API documentation.\nstruct Value {}\n",
- },
+ { "native/Value.swift": "/// API documentation.\nstruct Value {}\n" },
["deleted.rs"],
);
assert.equal(result.status, 1, result.stderr);
@@ -89,7 +91,8 @@ assert.doesNotMatch(result.stderr, /rust\/clap\.rs:3/);
assert.doesNotMatch(result.stderr, /rust\/unit_clap\.rs:1/);
result = run({
- "rust/local.rs": "// Non-obvious implementation reason.\npub fn value() {}\n",
+ "rust/local.rs":
+ "// Non-obvious implementation reason.\npub fn value() {}\n",
"rust/args.rs": [
"/// Printed in top-level command help.",
"#[derive(clap::Parser)]",
@@ -148,10 +151,12 @@ function run(tracked, untracked = {}, deleted = []) {
const root = mkdtempSync(join(tmpdir(), "ente-documentation-comments-"));
try {
spawn("git", ["init", "-q"], root);
- for (const [path, content] of Object.entries(tracked)) write(root, path, content);
+ for (const [path, content] of Object.entries(tracked))
+ write(root, path, content);
spawn("git", ["add", "."], root);
for (const path of deleted) rmSync(join(root, path));
- for (const [path, content] of Object.entries(untracked)) write(root, path, content);
+ for (const [path, content] of Object.entries(untracked))
+ write(root, path, content);
return spawn(process.execPath, [check, root]);
} finally {
rmSync(root, { recursive: true });
diff --git a/.github/scripts/app-version.mjs b/.github/scripts/app-version.mjs
index 8aabf224ad..b159791431 100644
--- a/.github/scripts/app-version.mjs
+++ b/.github/scripts/app-version.mjs
@@ -49,10 +49,11 @@ if (!scripts[app] || !command) {
function run(cmd, cmdArgs = [], opts = {}) {
const [script, ...prefix] = scripts[app];
- return execFileSync("node", [path.join(dir, script), ...prefix, cmd, ...cmdArgs], {
- encoding: "utf8",
- ...opts,
- });
+ return execFileSync(
+ "node",
+ [path.join(dir, script), ...prefix, cmd, ...cmdArgs],
+ { encoding: "utf8", ...opts },
+ );
}
function commitVersion() {
@@ -60,10 +61,17 @@ function commitVersion() {
const version = run("get", [], capture).trim();
const build = run("get-build-base", [], capture).trim();
const title = app[0].toUpperCase() + app.slice(1);
- execFileSync("git", ["commit", "-m", `${title} ${version}+${build}`, "--", ...versionFiles[app]], {
- cwd: root,
- stdio: "inherit",
- });
+ execFileSync(
+ "git",
+ [
+ "commit",
+ "-m",
+ `${title} ${version}+${build}`,
+ "--",
+ ...versionFiles[app],
+ ],
+ { cwd: root, stdio: "inherit" },
+ );
}
try {
diff --git a/.github/scripts/ensu-version.mjs b/.github/scripts/ensu-version.mjs
index cd5ba41d8c..277004254d 100644
--- a/.github/scripts/ensu-version.mjs
+++ b/.github/scripts/ensu-version.mjs
@@ -4,7 +4,10 @@ import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
-const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
+const root = path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ "../..",
+);
const files = {
packageJson: path.join(root, "rust/apps/ensu/package.json"),
packageLock: path.join(root, "rust/apps/ensu/package-lock.json"),
@@ -43,14 +46,17 @@ function replace(file, regex, replacement) {
let count = 0;
const next = text.replace(regex, (...args) => {
count += 1;
- return typeof replacement === "function" ? replacement(...args) : replacement;
+ return typeof replacement === "function"
+ ? replacement(...args)
+ : replacement;
});
if (!count) throw new Error(`No match in ${path.relative(root, file)}`);
write(file, next);
}
function expect(label, actual, wanted) {
- if (actual !== wanted) throw new Error(`${label}: expected ${wanted}, found ${actual}`);
+ if (actual !== wanted)
+ throw new Error(`${label}: expected ${wanted}, found ${actual}`);
}
function sourceBuildNumber() {
@@ -60,8 +66,16 @@ function sourceBuildNumber() {
}
function setBuildNumber(buildNumber) {
- replace(files.android, /(versionCode = .*\?: )\d+/, (_m, prefix) => `${prefix}${buildNumber}`);
- replace(files.xcode, /CURRENT_PROJECT_VERSION = [^;]+;/g, `CURRENT_PROJECT_VERSION = ${buildNumber};`);
+ replace(
+ files.android,
+ /(versionCode = .*\?: )\d+/,
+ (_m, prefix) => `${prefix}${buildNumber}`,
+ );
+ replace(
+ files.xcode,
+ /CURRENT_PROJECT_VERSION = [^;]+;/g,
+ `CURRENT_PROJECT_VERSION = ${buildNumber};`,
+ );
}
function check() {
@@ -69,22 +83,68 @@ function check() {
const releaseVersion = trimVersion(version);
const buildNumber = sourceBuildNumber();
- const xcodeBuildNumbers = [...read(files.xcode).matchAll(/CURRENT_PROJECT_VERSION = ([^;]+);/g)];
- if (!xcodeBuildNumbers.length) throw new Error("Xcode CURRENT_PROJECT_VERSION: no entries found");
+ const xcodeBuildNumbers = [
+ ...read(files.xcode).matchAll(/CURRENT_PROJECT_VERSION = ([^;]+);/g),
+ ];
+ if (!xcodeBuildNumbers.length)
+ throw new Error("Xcode CURRENT_PROJECT_VERSION: no entries found");
for (const match of xcodeBuildNumbers) {
expect("Xcode CURRENT_PROJECT_VERSION", match[1], buildNumber);
}
- expect("tauri.conf.json", value(files.tauri, /^\s*"version"\s*:\s*"([^"]+)"/m), version);
- expect("package-lock.json", value(files.packageLock, /"name": "ensu-desktop",\n\s+"version": "([^"]+)"/), version);
- expect("package-lock.json packages[\"\"]", value(files.packageLock, /"": \{\n\s+"name": "ensu-desktop",\n\s+"version": "([^"]+)"/), version);
- expect("Cargo.toml", value(files.cargoToml, /\[package\][\s\S]*?^version = "([^"]+)"/m), version);
- expect("Cargo.lock", value(files.cargoLock, /\[\[package\]\]\nname = "ensu-desktop"\nversion = "([^"]+)"/), version);
- expect("Android versionName", value(files.android, /versionName = "([^"]+)"/), releaseVersion);
- expect("Info.plist", value(files.plist, /<key>CFBundleShortVersionString<\/key>\s*<string>([^<]+)<\/string>/), releaseVersion);
-
- const xcodeMarketingVersions = [...read(files.xcode).matchAll(/MARKETING_VERSION = ([^;]+);/g)];
- if (!xcodeMarketingVersions.length) throw new Error("Xcode MARKETING_VERSION: no entries found");
+ expect(
+ "tauri.conf.json",
+ value(files.tauri, /^\s*"version"\s*:\s*"([^"]+)"/m),
+ version,
+ );
+ expect(
+ "package-lock.json",
+ value(
+ files.packageLock,
+ /"name": "ensu-desktop",\n\s+"version": "([^"]+)"/,
+ ),
+ version,
+ );
+ expect(
+ 'package-lock.json packages[""]',
+ value(
+ files.packageLock,
+ /"": \{\n\s+"name": "ensu-desktop",\n\s+"version": "([^"]+)"/,
+ ),
+ version,
+ );
+ expect(
+ "Cargo.toml",
+ value(files.cargoToml, /\[package\][\s\S]*?^version = "([^"]+)"/m),
+ version,
+ );
+ expect(
+ "Cargo.lock",
+ value(
+ files.cargoLock,
+ /\[\[package\]\]\nname = "ensu-desktop"\nversion = "([^"]+)"/,
+ ),
+ version,
+ );
+ expect(
+ "Android versionName",
+ value(files.android, /versionName = "([^"]+)"/),
+ releaseVersion,
+ );
+ expect(
+ "Info.plist",
+ value(
+ files.plist,
+ /<key>CFBundleShortVersionString<\/key>\s*<string>([^<]+)<\/string>/,
+ ),
+ releaseVersion,
+ );
+
+ const xcodeMarketingVersions = [
+ ...read(files.xcode).matchAll(/MARKETING_VERSION = ([^;]+);/g),
+ ];
+ if (!xcodeMarketingVersions.length)
+ throw new Error("Xcode MARKETING_VERSION: no entries found");
for (const match of xcodeMarketingVersions) {
expect("Xcode MARKETING_VERSION", match[1], releaseVersion);
}
@@ -93,15 +153,51 @@ function check() {
function setVersion(version) {
const releaseVersion = trimVersion(version);
- replace(files.packageJson, /("name": "ensu-desktop",\n\s+"version": ")[^"]+(")/, (_m, a, b) => `${a}${version}${b}`);
- replace(files.packageLock, /("name": "ensu-desktop",\n\s+"version": ")[^"]+(")/, (_m, a, b) => `${a}${version}${b}`);
- replace(files.packageLock, /("": \{\n\s+"name": "ensu-desktop",\n\s+"version": ")[^"]+(")/, (_m, a, b) => `${a}${version}${b}`);
- replace(files.tauri, /^(\s*"version"\s*:\s*")[^"]+(")/m, (_m, a, b) => `${a}${version}${b}`);
- replace(files.cargoToml, /(\[package\][\s\S]*?^version = ")[^"]+(")/m, (_m, a, b) => `${a}${version}${b}`);
- replace(files.cargoLock, /(\[\[package\]\]\nname = "ensu-desktop"\nversion = ")[^"]+(")/, (_m, a, b) => `${a}${version}${b}`);
- replace(files.android, /versionName = "[^"]+"/, `versionName = "${releaseVersion}"`);
- replace(files.xcode, /MARKETING_VERSION = [^;]+;/g, `MARKETING_VERSION = ${releaseVersion};`);
- replace(files.plist, /(<key>CFBundleShortVersionString<\/key>\s*<string>)[^<]+(<\/string>)/, (_m, a, b) => `${a}${releaseVersion}${b}`);
+ replace(
+ files.packageJson,
+ /("name": "ensu-desktop",\n\s+"version": ")[^"]+(")/,
+ (_m, a, b) => `${a}${version}${b}`,
+ );
+ replace(
+ files.packageLock,
+ /("name": "ensu-desktop",\n\s+"version": ")[^"]+(")/,
+ (_m, a, b) => `${a}${version}${b}`,
+ );
+ replace(
+ files.packageLock,
+ /("": \{\n\s+"name": "ensu-desktop",\n\s+"version": ")[^"]+(")/,
+ (_m, a, b) => `${a}${version}${b}`,
+ );
+ replace(
+ files.tauri,
+ /^(\s*"version"\s*:\s*")[^"]+(")/m,
+ (_m, a, b) => `${a}${version}${b}`,
+ );
+ replace(
+ files.cargoToml,
+ /(\[package\][\s\S]*?^version = ")[^"]+(")/m,
+ (_m, a, b) => `${a}${version}${b}`,
+ );
+ replace(
+ files.cargoLock,
+ /(\[\[package\]\]\nname = "ensu-desktop"\nversion = ")[^"]+(")/,
+ (_m, a, b) => `${a}${version}${b}`,
+ );
+ replace(
+ files.android,
+ /versionName = "[^"]+"/,
+ `versionName = "${releaseVersion}"`,
+ );
+ replace(
+ files.xcode,
+ /MARKETING_VERSION = [^;]+;/g,
+ `MARKETING_VERSION = ${releaseVersion};`,
+ );
+ replace(
+ files.plist,
+ /(<key>CFBundleShortVersionString<\/key>\s*<string>)[^<]+(<\/string>)/,
+ (_m, a, b) => `${a}${releaseVersion}${b}`,
+ );
}
function usage() {
@@ -127,7 +223,8 @@ try {
setVersion(args[0]);
check();
} else if (command === "set-build") {
- if (!/^\d+$/.test(args[1])) throw new Error(`Invalid Ensu build number: ${args[1]}`);
+ if (!/^\d+$/.test(args[1]))
+ throw new Error(`Invalid Ensu build number: ${args[1]}`);
setVersion(args[0]);
setBuildNumber(args[1]);
check();
diff --git a/.github/scripts/flutter-version.mjs b/.github/scripts/flutter-version.mjs
index 5847e2d30b..158e9965b1 100644
--- a/.github/scripts/flutter-version.mjs
+++ b/.github/scripts/flutter-version.mjs
@@ -4,7 +4,10 @@ import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
-const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
+const root = path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ "../..",
+);
const [app, command = "get", ...args] = process.argv.slice(2);
function usage() {
@@ -46,7 +49,10 @@ function setPubspecVersion(version) {
count += 1;
return `version: ${version}`;
});
- if (!count) throw new Error(`No version field found in ${path.relative(root, pubspec)}`);
+ if (!count)
+ throw new Error(
+ `No version field found in ${path.relative(root, pubspec)}`,
+ );
write(next);
}
@@ -56,11 +62,14 @@ try {
} else if (command === "get-build-base") {
console.log(pubspecVersion().buildBase);
} else if (command === "set") {
- if (!/^\d+\.\d+\.\d+$/.test(args[0])) throw new Error(`Invalid ${app} version: ${args[0]}`);
+ if (!/^\d+\.\d+\.\d+$/.test(args[0]))
+ throw new Error(`Invalid ${app} version: ${args[0]}`);
setPubspecVersion(`${args[0]}+${pubspecVersion().buildBase}`);
} else if (command === "set-build") {
- if (!/^\d+\.\d+\.\d+$/.test(args[0])) throw new Error(`Invalid ${app} release version: ${args[0]}`);
- if (!/^\d+$/.test(args[1])) throw new Error(`Invalid ${app} build number: ${args[1]}`);
+ if (!/^\d+\.\d+\.\d+$/.test(args[0]))
+ throw new Error(`Invalid ${app} release version: ${args[0]}`);
+ if (!/^\d+$/.test(args[1]))
+ throw new Error(`Invalid ${app} build number: ${args[1]}`);
setPubspecVersion(`${args[0]}+${args[1]}`);
} else if (command === "bump-build") {
const { source, buildBase } = pubspecVersion();
diff --git a/.github/scripts/photos-desktop-version.mjs b/.github/scripts/photos-desktop-version.mjs
index cf65b6552e..a2c88f37f1 100644
--- a/.github/scripts/photos-desktop-version.mjs
+++ b/.github/scripts/photos-desktop-version.mjs
@@ -4,7 +4,10 @@ import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
-const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
+const root = path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ "../..",
+);
const files = {
packageJson: path.join(root, "desktop/package.json"),
packageLock: path.join(root, "desktop/package-lock.json"),
@@ -38,27 +41,53 @@ function replace(file, regex, replacement) {
let count = 0;
const next = text.replace(regex, (...args) => {
count += 1;
- return typeof replacement === "function" ? replacement(...args) : replacement;
+ return typeof replacement === "function"
+ ? replacement(...args)
+ : replacement;
});
if (!count) throw new Error(`No match in ${path.relative(root, file)}`);
write(file, next);
}
function expect(label, actual, wanted) {
- if (actual !== wanted) throw new Error(`${label}: expected ${wanted}, found ${actual}`);
+ if (actual !== wanted)
+ throw new Error(`${label}: expected ${wanted}, found ${actual}`);
}
function check() {
const version = sourceVersion();
- expect("package-lock.json", value(files.packageLock, /"name": "ente",\n\s+"version": "([^"]+)"/), version);
- expect('package-lock.json packages[""]', value(files.packageLock, /"": \{\n\s+"name": "ente",\n\s+"version": "([^"]+)"/), version);
+ expect(
+ "package-lock.json",
+ value(files.packageLock, /"name": "ente",\n\s+"version": "([^"]+)"/),
+ version,
+ );
+ expect(
+ 'package-lock.json packages[""]',
+ value(
+ files.packageLock,
+ /"": \{\n\s+"name": "ente",\n\s+"version": "([^"]+)"/,
+ ),
+ version,
+ );
}
function setVersion(version) {
validateVersion(version);
- replace(files.packageJson, /("name": "ente",\n\s+"version": ")[^"]+(")/, (_m, a, b) => `${a}${version}${b}`);
- replace(files.packageLock, /("name": "ente",\n\s+"version": ")[^"]+(")/, (_m, a, b) => `${a}${version}${b}`);
- replace(files.packageLock, /("": \{\n\s+"name": "ente",\n\s+"version": ")[^"]+(")/, (_m, a, b) => `${a}${version}${b}`);
+ replace(
+ files.packageJson,
+ /("name": "ente",\n\s+"version": ")[^"]+(")/,
+ (_m, a, b) => `${a}${version}${b}`,
+ );
+ replace(
+ files.packageLock,
+ /("name": "ente",\n\s+"version": ")[^"]+(")/,
+ (_m, a, b) => `${a}${version}${b}`,
+ );
+ replace(
+ files.packageLock,
+ /("": \{\n\s+"name": "ente",\n\s+"version": ")[^"]+(")/,
+ (_m, a, b) => `${a}${version}${b}`,
+ );
check();
}
diff --git a/.github/scripts/release-notes.mjs b/.github/scripts/release-notes.mjs
index dbe4a4036c..43f22cc47d 100644
--- a/.github/scripts/release-notes.mjs
+++ b/.github/scripts/release-notes.mjs
@@ -7,7 +7,9 @@ import { spawnSync } from "node:child_process";
const [changesDir, previousRef] = process.argv.slice(2);
if (!changesDir) {
- console.error("Usage: node .github/scripts/release-notes.mjs <changes-dir> [previous-ref]");
+ console.error(
+ "Usage: node .github/scripts/release-notes.mjs <changes-dir> [previous-ref]",
+ );
process.exit(2);
}
@@ -17,7 +19,10 @@ function git(args) {
}
function readMarkdown(file) {
- return fs.readFileSync(file, "utf8").replace(/\r\n/g, "\n").replace(/\n?$/, "\n");
+ return fs
+ .readFileSync(file, "utf8")
+ .replace(/\r\n/g, "\n")
+ .replace(/\n?$/, "\n");
}
function changesetFiles(dir) {
@@ -35,7 +40,10 @@ function changesetFilesAtRef(dir, ref) {
return git(["ls-tree", "-r", "--name-only", ref, "--", prefix])
.split("\n")
.filter((file) => path.dirname(file) === prefix)
- .filter((file) => file.endsWith(".md") && path.basename(file) !== "README.md")
+ .filter(
+ (file) =>
+ file.endsWith(".md") && path.basename(file) !== "README.md",
+ )
.sort();
}
@@ -46,7 +54,11 @@ function currentBody() {
function previousBody() {
if (!previousRef) return "";
return changesetFilesAtRef(changesDir, previousRef)
- .map((file) => git(["show", `${previousRef}:${file}`]).replace(/\r\n/g, "\n").replace(/\n?$/, "\n"))
+ .map((file) =>
+ git(["show", `${previousRef}:${file}`])
+ .replace(/\r\n/g, "\n")
+ .replace(/\n?$/, "\n"),
+ )
.join("")
.trim();
}
@@ -59,15 +71,18 @@ function releaseNotes(body, previous) {
(previousLines.has(line) ? previousAgain : latest).push(line);
}
- const groupedBody =
- previousAgain.length
- ? [latest.join("\n"), `Previous changes:\n${previousAgain.join("\n")}`].filter(Boolean).join("\n\n")
- : body;
+ const groupedBody = previousAgain.length
+ ? [latest.join("\n"), `Previous changes:\n${previousAgain.join("\n")}`]
+ .filter(Boolean)
+ .join("\n\n")
+ : body;
return { groupedBody, hasNewChanges: latest.length > 0 };
}
function playStoreBody(body) {
- return Array.from(body || "Bug fixes and improvements").slice(0, 500).join("");
+ return Array.from(body || "Bug fixes and improvements")
+ .slice(0, 500)
+ .join("");
}
function output(name, text) {
diff --git a/.github/scripts/release-notify.mjs b/.github/scripts/release-notify.mjs
index c88ff23ea4..855362f104 100644
--- a/.github/scripts/release-notify.mjs
+++ b/.github/scripts/release-notify.mjs
@@ -19,16 +19,16 @@ const apps = {
testFlightId: "6758197006",
accentColor: 16633363,
},
- "photos-desktop": {
- accentColor: 65280,
- },
+ "photos-desktop": { accentColor: 65280 },
};
const app = process.argv[2];
const config = apps[app];
const releaseTag = process.argv[3];
if (!config || !releaseTag) {
- throw new Error(`Usage: node .github/scripts/release-notify.mjs ${Object.keys(apps).join("|")} <release-tag>`);
+ throw new Error(
+ `Usage: node .github/scripts/release-notify.mjs ${Object.keys(apps).join("|")} <release-tag>`,
+ );
}
const releaseUrl = `https://github.com/ente/nightly/releases/tag/${releaseTag}`;
@@ -62,10 +62,14 @@ const releaseBodyDiscord =
const downloadLinks = [];
if (config.packageId) {
- downloadLinks.push(`[Play Store](https://play.google.com/store/apps/details?id=${config.packageId})`);
+ downloadLinks.push(
+ `[Play Store](https://play.google.com/store/apps/details?id=${config.packageId})`,
+ );
}
if (config.testFlightId) {
- downloadLinks.push(`[TestFlight](https://appstoreconnect.apple.com/apps/${config.testFlightId}/testflight/ios)`);
+ downloadLinks.push(
+ `[TestFlight](https://appstoreconnect.apple.com/apps/${config.testFlightId}/testflight/ios)`,
+ );
}
downloadLinks.push(`[GitHub Release](${releaseUrl})`);
const downloadLine = `-# Download: ${downloadLinks.join(" | ")}`;
@@ -83,15 +87,13 @@ const response = await fetch(`${env("DISCORD_WEBHOOK")}?with_components=true`, {
body: JSON.stringify({
flags: 32768,
components: [
- {
- type: 17,
- accent_color: config.accentColor,
- components,
- },
+ { type: 17, accent_color: config.accentColor, components },
],
}),
});
if (!response.ok) {
- throw new Error(`Discord notification failed: ${response.status} ${await response.text()}`);
+ throw new Error(
+ `Discord notification failed: ${response.status} ${await response.text()}`,
+ );
}
diff --git a/.github/scripts/sync-help-changelog.mjs b/.github/scripts/sync-help-changelog.mjs
index 5b7388c04b..be7559f1af 100644
--- a/.github/scripts/sync-help-changelog.mjs
+++ b/.github/scripts/sync-help-changelog.mjs
@@ -4,11 +4,17 @@ import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
-const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
+const root = path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ "../..",
+);
const apps = {
photos: { changelog: "docs/docs/photos/changelog.md", label: "mobile" },
- "photos-desktop": { changelog: "docs/docs/photos/changelog.md", label: "desktop" },
+ "photos-desktop": {
+ changelog: "docs/docs/photos/changelog.md",
+ label: "desktop",
+ },
auth: { changelog: "docs/docs/auth/changelog.md", label: undefined },
locker: { changelog: "docs/docs/locker/changelog.md", label: "mobile" },
ensu: { changelog: "docs/docs/ensu/changelog.md", label: undefined },
@@ -16,15 +22,22 @@ const apps = {
const normalizeReleaseBodyIndent = (body) => {
const lines = body.replace(/\r\n?/g, "\n").split("\n");
- const indents = lines.filter((line) => line.trim()).map((line) => line.match(/^[ \t]*/)[0].length);
+ const indents = lines
+ .filter((line) => line.trim())
+ .map((line) => line.match(/^[ \t]*/)[0].length);
const indent = indents.length ? Math.min(...indents) : 0;
- return lines.map((line) => line.slice(indent)).join("\n").trim();
+ return lines
+ .map((line) => line.slice(indent))
+ .join("\n")
+ .trim();
};
const [app, version] = process.argv.slice(2);
const config = apps[app];
if (!config || !version) {
- throw new Error(`Usage: RELEASE_BODY=... node .github/scripts/sync-help-changelog.mjs ${Object.keys(apps).join("|")} <version>`);
+ throw new Error(
+ `Usage: RELEASE_BODY=... node .github/scripts/sync-help-changelog.mjs ${Object.keys(apps).join("|")} <version>`,
+ );
}
const file = path.join(root, config.changelog);
@@ -36,11 +49,19 @@ if (content.includes(`${heading} - `)) {
process.exit(0);
}
-const date = new Date().toLocaleString("en-US", { month: "short", year: "numeric", timeZone: "UTC" });
+const date = new Date().toLocaleString("en-US", {
+ month: "short",
+ year: "numeric",
+ timeZone: "UTC",
+});
const body = normalizeReleaseBodyIndent(process.env.RELEASE_BODY ?? "");
const section = `${heading} - ${date}\n\n${body}\n`;
const at = content.search(/^## v/m);
-if (at < 0) throw new Error(`No "## v" entry to insert before in ${config.changelog}`);
+if (at < 0)
+ throw new Error(`No "## v" entry to insert before in ${config.changelog}`);
-fs.writeFileSync(file, `${content.slice(0, at)}${section}\n${content.slice(at)}`);
+fs.writeFileSync(
+ file,
+ `${content.slice(0, at)}${section}\n${content.slice(at)}`,
+);
diff --git a/rust/checks/dependency-boundaries/check.mjs b/rust/checks/dependency-boundaries/check.mjs
index b42c0a885e..49f82ef582 100644
--- a/rust/checks/dependency-boundaries/check.mjs
+++ b/rust/checks/dependency-boundaries/check.mjs
@@ -19,7 +19,8 @@ const metadata = JSON.parse(
);
const root = resolve(metadata.workspace_root, "..");
const bindings = resolve(root, "rust/bindings");
-const framework = /^(?:wasm-bindgen(?:-.*)?|js-sys|web-sys|serde-wasm-bindgen|tsify(?:-.*)?|flutter_rust_bridge(?:_.*)?|uniffi(?:_.*)?|napi(?:-.*)?)$/;
+const framework =
+ /^(?:wasm-bindgen(?:-.*)?|js-sys|web-sys|serde-wasm-bindgen|tsify(?:-.*)?|flutter_rust_bridge(?:_.*)?|uniffi(?:_.*)?|napi(?:-.*)?)$/;
const pathFromRoot = (path) => relative(root, path).split(sep).join("/");
const domain = metadata.packages.filter((pkg) =>
pathFromRoot(pkg.manifest_path).startsWith("rust/crates/"),
@@ -54,7 +55,11 @@ if (!domain.length) {
for (const pkg of domain) {
const manifest = pathFromRoot(pkg.manifest_path);
for (const dependency of pkg.dependencies) {
- if (!framework.test(dependency.name) && !inside(bindings, dependency.path)) continue;
+ if (
+ !framework.test(dependency.name) &&
+ !inside(bindings, dependency.path)
+ )
+ continue;
console.error(
`${manifest}: dependency ${JSON.stringify(dependency.name)} crosses the Rust binding boundary`,
);
@@ -62,7 +67,9 @@ for (const pkg of domain) {
}
}
-const registered = new Set(domain.map((pkg) => pathFromRoot(pkg.manifest_path)));
+const registered = new Set(
+ domain.map((pkg) => pathFromRoot(pkg.manifest_path)),
+);
for (const manifest of git(
"ls-files",
"--cached",
@@ -75,7 +82,9 @@ for (const manifest of git(
.split("\0")
.filter((path) => path && existsSync(resolve(root, path)))) {
if (registered.has(manifest)) continue;
- console.error(`${manifest}: domain crate is not registered in the Cargo workspace`);
+ console.error(
+ `${manifest}: domain crate is not registered in the Cargo workspace`,
+ );
process.exitCode = 1;
}
@@ -90,7 +99,9 @@ for (const path of git(
"rust/bindings/frb/lib/src",
)
.split("\0")
- .filter((path) => path.endsWith(".rs") && existsSync(resolve(root, path)))) {
+ .filter(
+ (path) => path.endsWith(".rs") && existsSync(resolve(root, path)),
+ )) {
const source = readFileSync(resolve(root, path), "utf8");
const declarations = [
...source.matchAll(
@@ -112,5 +123,7 @@ function git(...args) {
function inside(directory, path) {
if (!path) return false;
const local = relative(directory, path);
- return local !== ".." && !local.startsWith(`..${sep}`) && !isAbsolute(local);
+ return (
+ local !== ".." && !local.startsWith(`..${sep}`) && !isAbsolute(local)
+ );
}
diff --git a/rust/checks/dependency-boundaries/test.mjs b/rust/checks/dependency-boundaries/test.mjs
index 0cbb7500fd..87bc9f59cf 100644
--- a/rust/checks/dependency-boundaries/test.mjs
+++ b/rust/checks/dependency-boundaries/test.mjs
@@ -25,7 +25,10 @@ for (const framework of [
]) {
result = run({ framework });
assert.equal(result.status, 1, result.stderr);
- assert.match(result.stderr, new RegExp(`dependency "${framework}" crosses`));
+ assert.match(
+ result.stderr,
+ new RegExp(`dependency "${framework}" crosses`),
+ );
}
result = run({ binding: true });
@@ -39,7 +42,10 @@ assert.equal(result.status, 0, result.stderr);
result = run({ unregistered: true });
assert.equal(result.status, 1, result.stderr);
-assert.match(result.stderr, /rust\/crates\/unregistered\/Cargo\.toml: domain crate is not registered/);
+assert.match(
+ result.stderr,
+ /rust\/crates\/unregistered\/Cargo\.toml: domain crate is not registered/,
+);
result = run({ empty: true });
assert.equal(result.status, 1, result.stderr);
@@ -58,15 +64,25 @@ for (const dependencyKind of [
]) {
result = run({ framework: "reqwest", dependencyKind });
assert.equal(result.status, 1, result.stderr);
- assert.match(result.stderr, /use ente-core::http instead of a direct reqwest dependency/);
+ assert.match(
+ result.stderr,
+ /use ente-core::http instead of a direct reqwest dependency/,
+ );
}
result = run({ framework: "reqwest", bindingDependencyKind: "dependencies" });
assert.equal(result.status, 1, result.stderr);
-assert.match(result.stderr, /rust\/bindings\/wasm\/lib\/Cargo\.toml: use ente-core::http/);
+assert.match(
+ result.stderr,
+ /rust\/bindings\/wasm\/lib\/Cargo\.toml: use ente-core::http/,
+);
for (const domainName of ["core", "assets"]) {
- result = run({ framework: "reqwest", dependencyKind: "dependencies", domainName });
+ result = run({
+ framework: "reqwest",
+ dependencyKind: "dependencies",
+ domainName,
+ });
assert.equal(result.status, 0, result.stderr);
}
@@ -129,23 +145,47 @@ function run({
packageToml(domainName, dependencies),
);
write(root, `rust/crates/${domainName}/src/lib.rs`, source);
- write(root, "rust/bindings/wasm/lib/Cargo.toml", packageToml(
- "ente-binding",
- bindingDependencyKind
- ? `\n[${bindingDependencyKind}]\nhttp = { package = ${JSON.stringify(framework)}, path = "../../../vendor/framework" }\n`
- : "",
- ));
- write(root, "rust/bindings/wasm/lib/src/lib.rs", "pub fn binding() {}\n");
+ write(
+ root,
+ "rust/bindings/wasm/lib/Cargo.toml",
+ packageToml(
+ "ente-binding",
+ bindingDependencyKind
+ ? `\n[${bindingDependencyKind}]\nhttp = { package = ${JSON.stringify(framework)}, path = "../../../vendor/framework" }\n`
+ : "",
+ ),
+ );
+ write(
+ root,
+ "rust/bindings/wasm/lib/src/lib.rs",
+ "pub fn binding() {}\n",
+ );
for (const [path, source] of Object.entries(projections)) {
write(root, path, source);
}
if (framework) {
- write(root, "rust/vendor/framework/Cargo.toml", packageToml(framework));
- write(root, "rust/vendor/framework/src/lib.rs", "pub fn framework() {}\n");
+ write(
+ root,
+ "rust/vendor/framework/Cargo.toml",
+ packageToml(framework),
+ );
+ write(
+ root,
+ "rust/vendor/framework/src/lib.rs",
+ "pub fn framework() {}\n",
+ );
}
if (unregistered || deleted) {
- write(root, "rust/crates/unregistered/Cargo.toml", packageToml("unregistered"));
- write(root, "rust/crates/unregistered/src/lib.rs", "pub fn unregistered() {}\n");
+ write(
+ root,
+ "rust/crates/unregistered/Cargo.toml",
+ packageToml("unregistered"),
+ );
+ write(
+ root,
+ "rust/crates/unregistered/src/lib.rs",
+ "pub fn unregistered() {}\n",
+ );
}
}
spawn(
@@ -154,7 +194,8 @@ function run({
join(root, "rust"),
);
spawn("git", ["add", "."], root);
- if (deleted) rmSync(join(root, "rust/crates/unregistered"), { recursive: true });
+ if (deleted)
+ rmSync(join(root, "rust/crates/unregistered"), { recursive: true });
return spawnSync(process.execPath, [check, root], { encoding: "utf8" });
} finally {
rmSync(root, { recursive: true });