FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: reduce bundle size and enforce Obsidian Sync budget (#2336) · sovf4717/tasknotes@8cb1f81 · GitHub

Repository navigation

Commit 8cb1f81

Browse files
committed
fix: reduce bundle size and enforce Obsidian Sync budget (callumalpass#2336)
1 parent 0c80bef commit 8cb1f81

7 files changed

Lines changed: 94 additions & 0 deletions

File tree

‎.github/workflows/release.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ jobs:
6060
EOF
6161
npm run build # This includes CSS building via npm run build-css
6262
63+
- name: Check Obsidian Sync bundle size budget
64+
run: npm run check:bundle-size
65+
6366
- name: Verify release notes
6467
run: |
6568
if [ ! -f "$RELEASE_NOTES_PATH" ]; then

‎.github/workflows/test.yml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,34 @@ on:
77
branches: [ main, develop, v3-maintenance ]
88

99
jobs:
10+
bundle-size:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
submodules: true
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '20'
22+
cache: 'npm'
23+
24+
- name: Install dependencies
25+
run: npm ci --prefer-offline --no-audit
26+
timeout-minutes: 5
27+
28+
- name: Test bundle size guard
29+
run: node --test scripts/check-bundle-size.test.mjs
30+
31+
- name: Build production plugin
32+
run: npm run build
33+
timeout-minutes: 10
34+
35+
- name: Check Obsidian Sync bundle size budget
36+
run: npm run check:bundle-size
37+
1038
test:
1139
runs-on: ubuntu-latest
1240
strategy:

‎docs/releases/unreleased.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ When a change has user-facing documentation, include a canonical tasknotes.dev l
3434

3535
## Fixed
3636

37+
- (#2336) Reduced the plugin bundle below Obsidian Sync Standard's 5 MB per-file limit so it can sync between devices again. Thanks to @kmalakoff for reporting and @CyberBlaed for confirming.
38+
3739
- (#2301) Fixed clicking the Pomodoro timer display to edit its duration. Thanks to @minnyee for reporting and identifying the cause.
3840

3941
- (#2328) Fixed direct status edits on occurrence notes not updating the recurring parent’s completion history or creating the next occurrence when configured. Thanks to @mudnug for reporting this.

‎esbuild.config.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const context = await esbuild.context({
9696
treeShaking: true,
9797
outfile: "main.js",
9898
minify: prod,
99+
// Avoid bulky Unicode escapes in translations; keep the bundle within Obsidian Sync's limit.
100+
charset: "utf8",
99101
plugins: [markdownPlugin, ...(!prod ? [copyToVaultPlugin] : [])],
100102
});
101103

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"build": "npm run build-css && node generate-release-notes-import.mjs && tsc -noEmit --skipLibCheck && node esbuild.config.mjs production",
88
"dev": "npm run build-css && node generate-release-notes-import.mjs && node esbuild.config.mjs",
99
"build:test": "npm run build && node copy-files.mjs",
10+
"check:bundle-size": "node scripts/check-bundle-size.mjs",
1011
"copy-files": "node copy-files.mjs",
1112
"build-css": "node build-css.mjs",
1213
"e2e": "playwright test",

‎scripts/check-bundle-size.mjs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { statSync } from "node:fs";
2+
3+
// Use decimal MB conservatively, and require headroom below the limit.
4+
const limit = 5_000_000;
5+
const bundle = process.argv[2] ?? "main.js";
6+
7+
try {
8+
const stats = statSync(bundle);
9+
if (!stats.isFile() || stats.size === 0) {
10+
throw new Error("expected a non-empty bundle file");
11+
}
12+
console.log(`${bundle}: ${stats.size.toLocaleString("en-US")} bytes; must be below ${limit.toLocaleString("en-US")} bytes.`);
13+
if (stats.size >= limit) {
14+
console.error("Bundle exceeds the size budget for Obsidian Sync Standard. Reduce the production bundle before releasing.");
15+
process.exitCode = 1;
16+
}
17+
} catch (error) {
18+
console.error(`Cannot check bundle ${bundle}: ${error.message}`);
19+
process.exitCode = 1;
20+
}

‎scripts/check-bundle-size.test.mjs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { test } from "node:test";
2+
import assert from "node:assert/strict";
3+
import { mkdtempSync, writeFileSync, truncateSync, rmSync } from "node:fs";
4+
import { tmpdir } from "node:os";
5+
import { join } from "node:path";
6+
import { fileURLToPath } from "node:url";
7+
import { spawnSync } from "node:child_process";
8+
9+
const script = fileURLToPath(new URL("./check-bundle-size.mjs", import.meta.url));
10+
11+
for (const [name, size, expectedStatus] of [
12+
["below limit", 4_999_999, 0],
13+
["at limit", 5_000_000, 1],
14+
["above limit", 5_000_001, 1],
15+
["empty file", 0, 1],
16+
["missing file", null, 1],
17+
]) {
18+
test(name, () => {
19+
const directory = mkdtempSync(join(tmpdir(), "tasknotes-bundle-size-"));
20+
try {
21+
const bundle = join(directory, "main.js");
22+
if (size !== null) {
23+
writeFileSync(bundle, "");
24+
truncateSync(bundle, size);
25+
}
26+
// Check both the default main.js path and an explicit path.
27+
for (const args of [[], [bundle]]) {
28+
const result = spawnSync(process.execPath, [script, ...args], {
29+
cwd: directory,
30+
encoding: "utf8",
31+
});
32+
assert.equal(result.status, expectedStatus, result.stdout + result.stderr);
33+
}
34+
} finally {
35+
rmSync(directory, { recursive: true, force: true });
36+
}
37+
});
38+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL