GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — opencode-mobile/scripts/foss-prepare.mjs at main · drpr/opencode-mobile

Expand file tree

/

foss-prepare.mjs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
111 lines (100 loc) · 4.57 KB
/

foss-prepare.mjs

Copy path

File metadata and controls

111 lines (100 loc) · 4.57 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env node
// Applies every patch that turns the vendored dependencies into a build that
// F-Droid's inclusion policy accepts. Shared by scripts/build-android-release.mjs
// (FOSS flavor) and the fdroiddata recipe so both apply the same patches.
//
// Patches:
// 1. package.json -> exclude the native expo-iap / expo-camera /
// expo-store-review modules
// 2. expo-notifications -> drop proprietary firebase-messaging, compile
// against F-Droid's firebase-stubs instead (local notifications only)
// 3. expo-application -> drop the proprietary com.android.installreferrer
// dependency and replace its AsyncFunction with a no-op
//
// Safe to run more than once.
import fs from 'node:fs';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
function run(command, args, options = {}) {
const result = spawnSync(command, args, { stdio: 'inherit', ...options });
if (result.status !== 0) {
throw new Error(`Command failed: ${command} ${args.join(' ')}`);
}
}
function patchAutolinking(repoRoot) {
const packageJsonPath = path.join(repoRoot, 'package.json');
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
pkg.expo = { ...(pkg.expo ?? {}) };
pkg.expo.autolinking = { ...(pkg.expo.autolinking ?? {}) };
pkg.expo.autolinking.exclude = [
...new Set([...(pkg.expo.autolinking.exclude ?? []), 'expo-iap', 'expo-camera', 'expo-store-review', 'expo-in-app-updates']),
];
pkg.expo.autolinking.android = { ...(pkg.expo.autolinking.android ?? {}) };
pkg.expo.autolinking.android.buildFromSource = [...new Set([...(pkg.expo.autolinking.android.buildFromSource ?? []), 'expo-application', 'expo-notifications'])];
fs.writeFileSync(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`);
}
function patchExpoNotifications(repoRoot) {
const androidDir = path.join(repoRoot, 'node_modules', 'expo-notifications', 'android');
const gradlePath = path.join(androidDir, 'build.gradle');
const gradle = fs.readFileSync(gradlePath, 'utf8');
if (gradle.includes('firebase-messaging')) {
fs.writeFileSync(
gradlePath,
gradle.split('\n').filter((line) => !line.includes('firebase-messaging')).join('\n'),
);
}
const marker = path.join(
androidDir,
'src/main/java/com/google/firebase/messaging/FirebaseMessaging.java',
);
if (fs.existsSync(marker)) return;
const localSrcDir = process.env.FIREBASE_STUB_SRC_DIR?.trim();
const stubSrcDir = localSrcDir ? path.resolve(localSrcDir) : undefined;
if (!stubSrcDir || !fs.existsSync(path.join(stubSrcDir, 'main/java/com/google/firebase/messaging/FirebaseMessaging.java'))) {
throw new Error('Firebase stub sources are missing. Set FIREBASE_STUB_SRC_DIR or run npm run build:foss:android.');
}
run('cp', ['-a', `${stubSrcDir}/.`, `${path.join(androidDir, 'src')}/`]);
}
function patchExpoApplication(repoRoot) {
const androidDir = path.join(repoRoot, 'node_modules', 'expo-application', 'android');
const gradlePath = path.join(androidDir, 'build.gradle');
const gradle = fs.readFileSync(gradlePath, 'utf8');
if (gradle.includes('installreferrer')) {
fs.writeFileSync(
gradlePath,
gradle.split('\n').filter((line) => !line.includes('installreferrer')).join('\n'),
);
}
const modulePath = path.join(
androidDir,
'src/main/java/expo/modules/application/ApplicationModule.kt',
);
const source = fs.readFileSync(modulePath, 'utf8');
if (!source.includes('com.android.installreferrer')) return;
const cleaned = source
.split('\n')
.filter((line) => !line.includes('com.android.installreferrer'))
.filter((line) => line.trim() !== 'import android.os.RemoteException')
.join('\n');
const start = cleaned.indexOf(' suspend fun getInstallReferrerAsync(): String =');
if (start < 0) throw new Error('Review expo-application FOSS install-referrer removal for this SDK.');
const open = cleaned.indexOf('{', start);
let depth = 1;
let end = open + 1;
for (; end < cleaned.length && depth; end++) {
if (cleaned[end] === '{') depth++;
else if (cleaned[end] === '}') depth--;
}
if (open < 0 || depth) throw new Error('Unrecognized install-referrer function.');
const patched = cleaned.slice(0, start) + ' suspend fun getInstallReferrerAsync(): String = ""' + cleaned.slice(end);
fs.writeFileSync(modulePath, patched);
}
export function prepareFoss(repoRoot = process.cwd()) {
patchAutolinking(repoRoot);
patchExpoNotifications(repoRoot);
patchExpoApplication(repoRoot);
}
if (import.meta.url === `file://${process.argv[1]}`) {
prepareFoss();
console.log('FOSS dependency patches applied.');
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.