Skip to content

TagSpaces is an offline, open source, document manager with tagging support

chore: cleaning ios package from native modules

Ilian Sapundshiev074f172aac30
diff --git a/package.json b/package.json
index 420d4ecef..c9870a1ba 100644
--- a/package.json
+++ b/package.json
@@ -104,7 +104,7 @@
"prebuild": "rimraf release/app/dist && npm run prepare-node && npm run generate-extensions && npm run gen-licenses",
"prestart": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.main.dev.ts",
"prepare": "husky install",
- "prepare-capacitor": "npm run install-ext-web-check && rimraf capacitor/www/dist && rimraf capacitor/www/node_modules && shx cp -rL release/app/node_modules capacitor/www && shx cp LICENSE.txt capacitor/www",
+ "prepare-capacitor": "npm run install-ext-web-check && rimraf capacitor/www/dist && rimraf capacitor/www/node_modules && shx cp -rL release/app/node_modules capacitor/www && node scripts/strip-capacitor-natives.js && shx cp LICENSE.txt capacitor/www",
"prepare-cordova": "npm run install-ext-web-check && rimraf cordova/www/dist && rimraf cordova/www/node_modules && shx cp -rL release/app/node_modules cordova/www && shx cp LICENSE.txt cordova/www",
"prepare-cordova-pro": "npm run install-ext-web-check && rimraf cordova/www/dist && rimraf cordova/www/node_modules && shx cp -rL release/app/node_modules cordova/www && shx cp node_modules/@tagspacespro/tagspacespro/EULA.txt cordova/www",
"prepare-node": "npm run install-ext-node-check",
diff --git a/scripts/strip-capacitor-natives.js b/scripts/strip-capacitor-natives.js
new file mode 100644
index 000000000..bc3d2333c
--- /dev/null
+++ b/scripts/strip-capacitor-natives.js
@@ -0,0 +1,69 @@
+#!/usr/bin/env node
+// Strip native binaries from capacitor/www/node_modules before cap sync.
+// iOS App Review rejects any standalone executable/library (.node/.dylib/.so)
+// outside the main app binary; these files also can't be loaded inside a
+// WebView even on Android, so they're pure dead weight.
+
+const fs = require('fs');
+const path = require('path');
+
+const TARGET = path.resolve(
+ __dirname,
+ '..',
+ 'capacitor',
+ 'www',
+ 'node_modules',
+);
+
+// Packages that exist solely to ship native bindings — remove wholesale.
+// pdfjs-dist optionally pulls @napi-rs/canvas for node-side rendering; the
+// browser build doesn't need it.
+const NATIVE_ONLY_PACKAGES = [
+ '@napi-rs',
+ 'sharp',
+ 'fsevents',
+ 'better-sqlite3',
+];
+
+if (!fs.existsSync(TARGET)) {
+ console.log('strip-capacitor-natives: target missing, skipping:', TARGET);
+ process.exit(0);
+}
+
+let removed = 0;
+for (const pkg of NATIVE_ONLY_PACKAGES) {
+ const dir = path.join(TARGET, pkg);
+ if (fs.existsSync(dir)) {
+ fs.rmSync(dir, { recursive: true, force: true });
+ console.log('strip-capacitor-natives: removed', pkg);
+ removed++;
+ }
+}
+
+function* walk(dir) {
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
+ const p = path.join(dir, entry.name);
+ if (entry.isDirectory()) {
+ yield* walk(p);
+ } else {
+ yield p;
+ }
+ }
+}
+
+for (const file of walk(TARGET)) {
+ if (
+ file.endsWith('.node') ||
+ file.endsWith('.dylib') ||
+ file.endsWith('.so')
+ ) {
+ fs.unlinkSync(file);
+ console.log(
+ 'strip-capacitor-natives: removed',
+ path.relative(TARGET, file),
+ );
+ removed++;
+ }
+}
+
+console.log(`strip-capacitor-natives: ${removed} item(s) removed`);