@vvedantb/config 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,277 @@
1
+ // Shared logic for the `vvedantb-android-release` bin: build a signed,
2
+ // sideloadable Android release APK with Gradle, then write release.json next
3
+ // to it. No EAS. The bin (android-release-cli.ts) orchestrates the real tools
4
+ // (pnpm, expo prebuild, gradlew, aapt2, apksigner) on Linux CI; this module
5
+ // holds the pure, per-app pieces so they can be tested without a build.
6
+ /** Semantic version like `1.0.1`. */
7
+ const VERSION_NAME_RE = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/;
8
+ /** Android caps versionCode at 2_100_000_000. */
9
+ const VERSION_CODE_RE = /^[1-9][0-9]{0,9}$/;
10
+ const MAX_VERSION_CODE = 2_100_000_000;
11
+ /** Returns `value` when it is a version like `1.0.1`, else throws. */
12
+ export function validateVersionName(value) {
13
+ if (value === undefined || !VERSION_NAME_RE.test(value)) {
14
+ throw new Error("Set VERSION_NAME to a version like 1.0.1.");
15
+ }
16
+ return value;
17
+ }
18
+ /** Returns the versionCode as a number when valid (1..2_100_000_000), else throws. */
19
+ export function validateVersionCode(value) {
20
+ if (value === undefined || !VERSION_CODE_RE.test(value)) {
21
+ throw new Error("Set VERSION_CODE to a whole number from 1 to 2100000000, higher than every published release.json.");
22
+ }
23
+ const code = Number(value);
24
+ if (code > MAX_VERSION_CODE) {
25
+ throw new Error("Set VERSION_CODE to a whole number from 1 to 2100000000, higher than every published release.json.");
26
+ }
27
+ return code;
28
+ }
29
+ function escapeRegExp(value) {
30
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
31
+ }
32
+ function literalFromConfig(contents, name, operators) {
33
+ const ops = operators.map((op) => escapeRegExp(op)).join("|");
34
+ const re = new RegExp(`process\\.env\\.${escapeRegExp(name)}\\s*(?:${ops})\\s*"([^"]+)"`);
35
+ return re.exec(contents)?.[1];
36
+ }
37
+ function easProfileEnv(easContents, profile, name) {
38
+ const parsed = JSON.parse(easContents);
39
+ if (typeof parsed !== "object" || parsed === null)
40
+ return undefined;
41
+ const build = parsed.build;
42
+ if (typeof build !== "object" || build === null)
43
+ return undefined;
44
+ const profileNode = build[profile];
45
+ if (typeof profileNode !== "object" || profileNode === null)
46
+ return undefined;
47
+ const env = profileNode.env;
48
+ if (typeof env !== "object" || env === null)
49
+ return undefined;
50
+ const value = env[name];
51
+ return typeof value === "string" ? value : undefined;
52
+ }
53
+ /**
54
+ * Resolves an `EXPO_PUBLIC_*` value: the environment first, then each source in
55
+ * turn (an `eas.json` profile, or a `process.env.NAME ?? "literal"` default in a
56
+ * config file). Returns `""` when nothing supplies it, so callers decide whether
57
+ * a missing value is an error.
58
+ */
59
+ export function publicEnvDefault(name, options) {
60
+ const fromEnv = options.env[name];
61
+ if (fromEnv !== undefined && fromEnv !== "")
62
+ return fromEnv;
63
+ for (const source of options.sources ?? []) {
64
+ if (source.kind === "eas-profile") {
65
+ const contents = options.readAppFile("eas.json");
66
+ if (contents === undefined)
67
+ continue;
68
+ const value = easProfileEnv(contents, source.profile ?? "production", name);
69
+ if (value !== undefined && value !== "")
70
+ return value;
71
+ }
72
+ else {
73
+ const contents = options.readAppFile(source.file);
74
+ if (contents === undefined)
75
+ continue;
76
+ const value = literalFromConfig(contents, name, source.operators ?? ["??", "||"]);
77
+ if (value !== undefined && value !== "")
78
+ return value;
79
+ }
80
+ }
81
+ return "";
82
+ }
83
+ /** The edits the release build makes to `gradle.properties`, in order. */
84
+ export const DEFAULT_GRADLE_PROPERTY_EDITS = [
85
+ { key: "reactNativeArchitectures", value: "arm64-v8a,x86_64", replace: true },
86
+ { key: "org.gradle.jvmargs", value: "-Xmx4096m -XX:MaxMetaspaceSize=1024m", replace: true },
87
+ { key: "org.gradle.workers.max", value: "2", replace: false },
88
+ { key: "android.lint.checkReleaseBuilds", value: "false", replace: false },
89
+ ];
90
+ function withTrailingNewline(contents) {
91
+ if (contents.length === 0)
92
+ return contents;
93
+ return contents.endsWith("\n") ? contents : contents + "\n";
94
+ }
95
+ /**
96
+ * Applies the release edits to `gradle.properties` contents and returns the new
97
+ * text. A `replace` edit overwrites an existing `key=` line or appends when
98
+ * absent; a non-replace edit only appends when the key is absent. Always ends
99
+ * with a trailing newline (an append onto a file without one joins two lines and
100
+ * Gradle fails to parse it).
101
+ */
102
+ export function gradlePropertiesEdits(contents, edits = DEFAULT_GRADLE_PROPERTY_EDITS) {
103
+ let text = withTrailingNewline(contents);
104
+ for (const edit of edits) {
105
+ const line = `${edit.key}=${edit.value}`;
106
+ const keyRe = new RegExp(`^${escapeRegExp(edit.key)}=.*$`, "m");
107
+ if (keyRe.test(text)) {
108
+ if (edit.replace)
109
+ text = text.replace(keyRe, line);
110
+ }
111
+ else {
112
+ text = withTrailingNewline(text) + line + "\n";
113
+ }
114
+ }
115
+ return text;
116
+ }
117
+ /** Parses the `package:` line of `aapt2 dump badging` output. */
118
+ export function parseBadging(output) {
119
+ const line = output.split("\n").find((l) => l.startsWith("package:")) ?? "";
120
+ const field = (key) => new RegExp(`${key}='([^']*)'`).exec(line)?.[1] ?? "";
121
+ return {
122
+ name: field("name"),
123
+ versionCode: field("versionCode"),
124
+ versionName: field("versionName"),
125
+ };
126
+ }
127
+ /** Builds the release.json object from the version values and APK hash. */
128
+ export function releaseJson(versionName, versionCode, sha256) {
129
+ return { versionName, versionCode, sha256 };
130
+ }
131
+ /** Serialises release.json exactly as published (2-space indent, trailing newline). */
132
+ export function formatReleaseJson(release) {
133
+ return JSON.stringify(release, null, 2) + "\n";
134
+ }
135
+ /** Formats the `key=value` lines appended to `$GITHUB_OUTPUT`. */
136
+ export function formatGithubOutput(outputs) {
137
+ return (Object.entries(outputs)
138
+ .map(([key, value]) => `${key}=${value}`)
139
+ .join("\n") + "\n");
140
+ }
141
+ const DEFAULT_CONFIG = {
142
+ appDir: "apps/mobile",
143
+ publicEnvSources: [],
144
+ pnpmFilters: ["{.}"],
145
+ prebuildNoInstall: true,
146
+ extraEnv: {},
147
+ optionalEnv: [],
148
+ preChecks: [],
149
+ preBuildSteps: [],
150
+ };
151
+ function asStringArray(value, field) {
152
+ if (!Array.isArray(value) || value.some((v) => typeof v !== "string")) {
153
+ throw new Error(`android-release config: "${field}" must be an array of strings.`);
154
+ }
155
+ return value;
156
+ }
157
+ /**
158
+ * Validates a parsed JSON config object into an {@link AndroidReleaseConfig},
159
+ * filling defaults. Throws a clear error on a bad shape. Kept hand-written so
160
+ * the package takes no schema dependency.
161
+ */
162
+ export function parseAndroidReleaseConfig(input) {
163
+ if (typeof input !== "object" || input === null) {
164
+ throw new Error("android-release config: expected a JSON object.");
165
+ }
166
+ const raw = input;
167
+ if (typeof raw.packageId !== "string") {
168
+ throw new Error('android-release config: "packageId" is required.');
169
+ }
170
+ if (typeof raw.apkPrefix !== "string") {
171
+ throw new Error('android-release config: "apkPrefix" is required.');
172
+ }
173
+ const config = {
174
+ ...DEFAULT_CONFIG,
175
+ packageId: raw.packageId,
176
+ apkPrefix: raw.apkPrefix,
177
+ publicEnv: asStringArray(raw.publicEnv ?? [], "publicEnv"),
178
+ };
179
+ if (raw.appDir !== undefined) {
180
+ if (typeof raw.appDir !== "string")
181
+ throw new Error('android-release config: "appDir" must be a string.');
182
+ config.appDir = raw.appDir;
183
+ }
184
+ if (raw.publicEnvSources !== undefined) {
185
+ if (!Array.isArray(raw.publicEnvSources)) {
186
+ throw new Error('android-release config: "publicEnvSources" must be an array.');
187
+ }
188
+ config.publicEnvSources = raw.publicEnvSources.map((source) => parsePublicEnvSource(source));
189
+ }
190
+ if (raw.pnpmFilters !== undefined)
191
+ config.pnpmFilters = asStringArray(raw.pnpmFilters, "pnpmFilters");
192
+ if (raw.prebuildNoInstall !== undefined) {
193
+ if (typeof raw.prebuildNoInstall !== "boolean") {
194
+ throw new Error('android-release config: "prebuildNoInstall" must be a boolean.');
195
+ }
196
+ config.prebuildNoInstall = raw.prebuildNoInstall;
197
+ }
198
+ if (raw.extraEnv !== undefined)
199
+ config.extraEnv = parseStringRecord(raw.extraEnv, "extraEnv");
200
+ if (raw.optionalEnv !== undefined)
201
+ config.optionalEnv = asStringArray(raw.optionalEnv, "optionalEnv");
202
+ if (raw.preChecks !== undefined)
203
+ config.preChecks = asStringArray(raw.preChecks, "preChecks");
204
+ if (raw.preBuildSteps !== undefined)
205
+ config.preBuildSteps = asStringArray(raw.preBuildSteps, "preBuildSteps");
206
+ if (raw.gradleWrapperPin !== undefined)
207
+ config.gradleWrapperPin = parseWrapperPin(raw.gradleWrapperPin);
208
+ if (raw.summary !== undefined)
209
+ config.summary = parseSummary(raw.summary);
210
+ return config;
211
+ }
212
+ function parsePublicEnvSource(input) {
213
+ if (typeof input !== "object" || input === null) {
214
+ throw new Error('android-release config: each "publicEnvSources" entry must be an object.');
215
+ }
216
+ const raw = input;
217
+ if (raw.kind === "eas-profile") {
218
+ const source = { kind: "eas-profile" };
219
+ if (raw.profile !== undefined) {
220
+ if (typeof raw.profile !== "string")
221
+ throw new Error('android-release config: "profile" must be a string.');
222
+ source.profile = raw.profile;
223
+ }
224
+ return source;
225
+ }
226
+ if (raw.kind === "config-literal") {
227
+ if (typeof raw.file !== "string") {
228
+ throw new Error('android-release config: a "config-literal" source needs a "file".');
229
+ }
230
+ const source = { kind: "config-literal", file: raw.file };
231
+ if (raw.operators !== undefined) {
232
+ if (!Array.isArray(raw.operators) ||
233
+ raw.operators.some((op) => op !== "??" && op !== "||")) {
234
+ throw new Error('android-release config: "operators" must be a list of "??" or "||".');
235
+ }
236
+ source.operators = raw.operators;
237
+ }
238
+ return source;
239
+ }
240
+ throw new Error('android-release config: source "kind" must be "eas-profile" or "config-literal".');
241
+ }
242
+ function parseStringRecord(input, field) {
243
+ if (typeof input !== "object" || input === null) {
244
+ throw new Error(`android-release config: "${field}" must be an object.`);
245
+ }
246
+ const result = {};
247
+ for (const [key, value] of Object.entries(input)) {
248
+ if (typeof value !== "string")
249
+ throw new Error(`android-release config: "${field}.${key}" must be a string.`);
250
+ result[key] = value;
251
+ }
252
+ return result;
253
+ }
254
+ function parseWrapperPin(input) {
255
+ if (typeof input !== "object" || input === null) {
256
+ throw new Error('android-release config: "gradleWrapperPin" must be an object.');
257
+ }
258
+ const raw = input;
259
+ if (typeof raw.ifContains !== "string" || typeof raw.distributionUrl !== "string") {
260
+ throw new Error('android-release config: "gradleWrapperPin" needs "ifContains" and "distributionUrl".');
261
+ }
262
+ return { ifContains: raw.ifContains, distributionUrl: raw.distributionUrl };
263
+ }
264
+ function parseSummary(input) {
265
+ if (typeof input !== "object" || input === null) {
266
+ throw new Error('android-release config: "summary" must be an object.');
267
+ }
268
+ const raw = input;
269
+ if (typeof raw.label !== "string" || typeof raw.envVar !== "string") {
270
+ throw new Error('android-release config: "summary" needs "label" and "envVar".');
271
+ }
272
+ return { label: raw.label, envVar: raw.envVar };
273
+ }
274
+ /** The published APK file name for a version, such as `vmem-1.0.1-android.apk`. */
275
+ export function apkFileName(apkPrefix, versionName) {
276
+ return `${apkPrefix}-${versionName}-android.apk`;
277
+ }
File without changes
File without changes
package/dist/cli.js CHANGED
File without changes
package/dist/expo.d.ts CHANGED
@@ -13,17 +13,27 @@ export interface ExpoBabelConfig {
13
13
  * Babel resolves the preset names from the app, as before.
14
14
  */
15
15
  export declare function expoBabelConfig(api: BabelApi): ExpoBabelConfig;
16
+ /** A Metro resolver context: the part the singleton resolver reads and forwards. */
17
+ export interface MetroResolveContext {
18
+ resolveRequest: (context: MetroResolveContext, moduleName: string, platform: string | null) => unknown;
19
+ originModulePath?: string;
20
+ }
21
+ /** A Metro `resolver.resolveRequest` function. */
22
+ export type MetroResolveRequest = (context: MetroResolveContext, moduleName: string, platform: string | null) => unknown;
16
23
  /** The part of Metro's config the preset sets. */
17
24
  export interface MetroConfigLike {
18
25
  watchFolders?: readonly string[];
19
26
  resolver?: {
20
27
  nodeModulesPaths?: readonly string[];
21
28
  unstable_enablePackageExports?: boolean;
29
+ resolveRequest?: MetroResolveRequest;
22
30
  };
23
31
  }
24
32
  export interface NativeWindMetroOptions {
25
33
  input: string;
26
34
  inlineRem?: number;
35
+ /** NativeWind `configPath` (the Tailwind config). Not passed when unset. */
36
+ configPath?: string;
27
37
  }
28
38
  export interface ExpoMetroOptions<Config extends MetroConfigLike> {
29
39
  /** The app folder: `__dirname`. */
@@ -36,6 +46,14 @@ export interface ExpoMetroOptions<Config extends MetroConfigLike> {
36
46
  input?: string;
37
47
  /** NativeWind `inlineRem`. Not passed when unset, so NativeWind keeps its default. */
38
48
  inlineRem?: number;
49
+ /** NativeWind `configPath` (the Tailwind config), relative to `projectRoot` or absolute. Not passed when unset. */
50
+ nativeWindConfig?: string;
51
+ /**
52
+ * Module names to resolve from the app, not a nested copy, such as
53
+ * `["react", "react-dom"]`. Sets `resolver.resolveRequest` before
54
+ * `withNativeWind`, so a single React instance is used across the monorepo.
55
+ */
56
+ singletons?: readonly string[];
39
57
  /** Monorepo root relative to `projectRoot`, such as `"../.."`. Watches it and resolves from both node_modules folders. */
40
58
  monorepoRoot?: string;
41
59
  /** Sets `resolver.unstable_enablePackageExports: true`. */
package/dist/expo.js CHANGED
@@ -10,6 +10,27 @@ export function expoBabelConfig(api) {
10
10
  presets: [["babel-preset-expo", { jsxImportSource: "nativewind" }], "nativewind/babel"],
11
11
  };
12
12
  }
13
+ /**
14
+ * Sets `resolver.resolveRequest` so the given module names resolve from the
15
+ * app root (`package.json`), not from a nested copy. Mutates `config` in place,
16
+ * before `withNativeWind` wraps it (NativeWind chains to this resolver).
17
+ */
18
+ function installSingletonResolver(config, projectRoot, singletons) {
19
+ const resolver = config.resolver;
20
+ if (resolver === undefined)
21
+ return;
22
+ const appOrigin = resolve(projectRoot, "package.json");
23
+ const names = new Set(singletons);
24
+ const base = resolver.resolveRequest;
25
+ resolver.resolveRequest = (context, moduleName, platform) => {
26
+ const head = moduleName.split("/")[0];
27
+ const forward = base ?? context.resolveRequest;
28
+ if (head !== undefined && names.has(head)) {
29
+ return forward({ ...context, originModulePath: appOrigin }, moduleName, platform);
30
+ }
31
+ return forward(context, moduleName, platform);
32
+ };
33
+ }
13
34
  /**
14
35
  * `metro.config.js` for Expo with NativeWind: the Expo default config wrapped
15
36
  * by `withNativeWind`, then the monorepo and package-exports resolver settings.
@@ -19,7 +40,14 @@ export function defineExpoMetroConfig(options) {
19
40
  const nativeWind = { input: options.input ?? "./global.css" };
20
41
  if (options.inlineRem !== undefined)
21
42
  nativeWind.inlineRem = options.inlineRem;
22
- const config = options.withNativeWind(options.getDefaultConfig(options.projectRoot), nativeWind);
43
+ if (options.nativeWindConfig !== undefined) {
44
+ nativeWind.configPath = resolve(options.projectRoot, options.nativeWindConfig);
45
+ }
46
+ const base = options.getDefaultConfig(options.projectRoot);
47
+ if (options.singletons !== undefined && options.singletons.length > 0) {
48
+ installSingletonResolver(base, options.projectRoot, options.singletons);
49
+ }
50
+ const config = options.withNativeWind(base, nativeWind);
23
51
  if (options.monorepoRoot === undefined && !options.packageExports)
24
52
  return config;
25
53
  const resolver = { ...config.resolver };
package/dist/index.d.ts CHANGED
@@ -4,4 +4,6 @@ export { runCli, type CliIo } from "./run.js";
4
4
  export { CHECK_ASAR_CHILD_ENV, findBareImports, findSpecifiers, packageName, runCheckAsar, type AsarCheckHook, type AsarCheckHookContext, type CheckAsarIo, } from "./check-asar.js";
5
5
  export { runClerkAllow, type ClerkAllowFetch, type ClerkAllowIo, type ClerkAllowResponse, } from "./clerk-allow.js";
6
6
  export { REACT_DEDUPE, defineWebViteConfig, defineWebVitestConfig, reactPlugins, srcAlias, vendorChunkBuild, type AliasOptions, type BabelReactCompiler, type PathOptions, type ReactSetup, type ResolveConfig, type RouterPluginOptions, type VendorChunk, type VendorChunkGroup, type VitePlugin, type VitePluginOption, type WebBuildConfig, type WebViteConfig, type WebViteOptions, type WebVitestConfig, type WebVitestOptions, } from "./vite.js";
7
- export { defineExpoMetroConfig, expoBabelConfig, type BabelApi, type ExpoBabelConfig, type ExpoMetroOptions, type MetroConfigLike, type NativeWindMetroOptions, } from "./expo.js";
7
+ export { defineExpoMetroConfig, expoBabelConfig, type BabelApi, type ExpoBabelConfig, type ExpoMetroOptions, type MetroConfigLike, type MetroResolveContext, type MetroResolveRequest, type NativeWindMetroOptions, } from "./expo.js";
8
+ export { DEFAULT_RELEASE_SIGNING_MARKER, appendReleaseSigning, releaseSigningGradle, withReleaseSigning, type AppBuildGradleMod, type ReleaseSigningOptions, type ReleaseSigningPropertyKeys, type WithAppBuildGradle, type WithReleaseSigningOptions, } from "./release-signing.js";
9
+ export { DEFAULT_GRADLE_PROPERTY_EDITS, apkFileName, formatGithubOutput, formatReleaseJson, gradlePropertiesEdits, parseAndroidReleaseConfig, parseBadging, publicEnvDefault, releaseJson, validateVersionCode, validateVersionName, type AndroidReleaseConfig, type BadgingFields, type GradlePropertyEdit, type PublicEnvSource, type ReadAppFile, type ReleaseJson, } from "./android-release.js";
package/dist/index.js CHANGED
@@ -5,3 +5,5 @@ export { CHECK_ASAR_CHILD_ENV, findBareImports, findSpecifiers, packageName, run
5
5
  export { runClerkAllow, } from "./clerk-allow.js";
6
6
  export { REACT_DEDUPE, defineWebViteConfig, defineWebVitestConfig, reactPlugins, srcAlias, vendorChunkBuild, } from "./vite.js";
7
7
  export { defineExpoMetroConfig, expoBabelConfig, } from "./expo.js";
8
+ export { DEFAULT_RELEASE_SIGNING_MARKER, appendReleaseSigning, releaseSigningGradle, withReleaseSigning, } from "./release-signing.js";
9
+ export { DEFAULT_GRADLE_PROPERTY_EDITS, apkFileName, formatGithubOutput, formatReleaseJson, gradlePropertiesEdits, parseAndroidReleaseConfig, parseBadging, publicEnvDefault, releaseJson, validateVersionCode, validateVersionName, } from "./android-release.js";
@@ -0,0 +1,66 @@
1
+ /** The keystore.properties / environment variable names the Groovy reads. */
2
+ export interface ReleaseSigningPropertyKeys {
3
+ /** Key for the keystore file path. */
4
+ storeFile: string;
5
+ /** Key for the keystore password. */
6
+ storePassword: string;
7
+ /** Key for the key alias. */
8
+ keyAlias: string;
9
+ /** Key for the key password. */
10
+ keyPassword: string;
11
+ }
12
+ export interface ReleaseSigningOptions {
13
+ /**
14
+ * The marker comment line. It makes the append idempotent and is what a
15
+ * build script greps for. Default `DEFAULT_RELEASE_SIGNING_MARKER`.
16
+ * Set it to the token the app's build script already matches.
17
+ */
18
+ marker?: string;
19
+ /**
20
+ * Groovy expression for the `keystore.properties` file, read inside
21
+ * `app/build.gradle`. Default `rootProject.file("../../../keystore.properties")`
22
+ * (the repository root, three levels above `android/app`).
23
+ */
24
+ keystorePropertiesFile?: string;
25
+ /** Environment / properties key names. Default the `ANDROID_*` set. */
26
+ propertyKeys?: Partial<ReleaseSigningPropertyKeys>;
27
+ /** `storeType` for the signing config, such as `"pkcs12"`. Omitted when unset. */
28
+ storeType?: string;
29
+ /** Skip the append when `EAS_BUILD` is set (EAS handles its own signing). Default `false`. */
30
+ skipOnEasBuild?: boolean;
31
+ /**
32
+ * Groovy boolean expression deciding whether a build signs `release`. It runs
33
+ * inside `gradle.taskGraph.whenReady { graph -> ... }` with `graph` and
34
+ * `project` in scope. Default: any task of this project whose name contains
35
+ * `"release"` (case-insensitive).
36
+ */
37
+ releaseTaskCondition?: string;
38
+ }
39
+ /** The part of an Expo `appBuildGradle` mod this plugin touches. */
40
+ export interface AppBuildGradleMod {
41
+ modResults: {
42
+ contents: string;
43
+ };
44
+ }
45
+ /** The part of `withAppBuildGradle` from `expo/config-plugins` this plugin uses. */
46
+ export type WithAppBuildGradle = <Config>(config: Config, action: (mod: AppBuildGradleMod) => AppBuildGradleMod) => Config;
47
+ export interface WithReleaseSigningOptions extends ReleaseSigningOptions {
48
+ /** `withAppBuildGradle` from `expo/config-plugins`. Resolved from the app when unset. */
49
+ withAppBuildGradle?: WithAppBuildGradle;
50
+ }
51
+ export declare const DEFAULT_RELEASE_SIGNING_MARKER = "// @generated @vvedantb/config plugins/withReleaseSigning.js";
52
+ /**
53
+ * The Groovy block appended to `app/build.gradle`. Groovy `${...}` stays
54
+ * literal for Gradle to evaluate, so it is written as `\${...}` here.
55
+ */
56
+ export declare function releaseSigningGradle(options?: ReleaseSigningOptions): string;
57
+ /**
58
+ * Appends the signing block to `app/build.gradle` contents, once. Returns the
59
+ * contents unchanged when the marker is already present (idempotent).
60
+ */
61
+ export declare function appendReleaseSigning(contents: string, options?: ReleaseSigningOptions): string;
62
+ /**
63
+ * Expo config plugin: appends the release signing block to `app/build.gradle`.
64
+ * Pass this through `plugins` in `app.config`, or call it directly on a config.
65
+ */
66
+ export declare function withReleaseSigning<Config>(config: Config, options?: WithReleaseSigningOptions): Config;
@@ -0,0 +1,101 @@
1
+ import { createRequire } from "node:module";
2
+ import { join } from "node:path";
3
+ // The default contains `plugins/withReleaseSigning.js` on purpose: each app's
4
+ // build script greps android/app/build.gradle for that exact substring to
5
+ // confirm signing was patched in, so the default marker satisfies that grep.
6
+ // An app whose own test asserts a different marker passes `marker` to match it.
7
+ export const DEFAULT_RELEASE_SIGNING_MARKER = "// @generated @vvedantb/config plugins/withReleaseSigning.js";
8
+ const DEFAULT_PROPERTY_KEYS = {
9
+ storeFile: "ANDROID_KEYSTORE_PATH",
10
+ storePassword: "ANDROID_KEYSTORE_PASSWORD",
11
+ keyAlias: "ANDROID_KEY_ALIAS",
12
+ keyPassword: "ANDROID_KEY_PASSWORD",
13
+ };
14
+ const DEFAULT_KEYSTORE_FILE = 'rootProject.file("../../../keystore.properties")';
15
+ const DEFAULT_RELEASE_TASK_CONDITION = 'graph.allTasks.any { it.project == project && it.name.toLowerCase().contains("release") }';
16
+ function resolvedKeys(options) {
17
+ return { ...DEFAULT_PROPERTY_KEYS, ...options?.propertyKeys };
18
+ }
19
+ /**
20
+ * The Groovy block appended to `app/build.gradle`. Groovy `${...}` stays
21
+ * literal for Gradle to evaluate, so it is written as `\${...}` here.
22
+ */
23
+ export function releaseSigningGradle(options) {
24
+ const marker = options?.marker ?? DEFAULT_RELEASE_SIGNING_MARKER;
25
+ const keys = resolvedKeys(options);
26
+ const keystoreFile = options?.keystorePropertiesFile ?? DEFAULT_KEYSTORE_FILE;
27
+ const condition = options?.releaseTaskCondition ?? DEFAULT_RELEASE_TASK_CONDITION;
28
+ const names = [keys.storeFile, keys.storePassword, keys.keyAlias, keys.keyPassword];
29
+ const nameList = names.map((name) => ` "${name}",`).join("\n");
30
+ const storeTypeLine = options?.storeType
31
+ ? ` storeType "${options.storeType}"\n`
32
+ : "";
33
+ return `
34
+ ${marker}
35
+ def releaseSigningProps = new Properties()
36
+ def releaseSigningFile = ${keystoreFile}
37
+ if (releaseSigningFile.exists()) {
38
+ releaseSigningFile.withInputStream { releaseSigningProps.load(it) }
39
+ }
40
+ def releaseSigning = [
41
+ ${nameList}
42
+ ].collectEntries { name -> [(name): System.getenv(name) ?: releaseSigningProps.getProperty(name)] }
43
+ def releaseSigningMissing = releaseSigning.findAll { !it.value }.keySet()
44
+
45
+ android {
46
+ signingConfigs {
47
+ release {
48
+ if (releaseSigningMissing.isEmpty()) {
49
+ ${storeTypeLine} storeFile file(releaseSigning.get("${keys.storeFile}"))
50
+ storePassword releaseSigning.get("${keys.storePassword}")
51
+ keyAlias releaseSigning.get("${keys.keyAlias}")
52
+ keyPassword releaseSigning.get("${keys.keyPassword}")
53
+ }
54
+ }
55
+ }
56
+ buildTypes {
57
+ release {
58
+ signingConfig signingConfigs.release
59
+ }
60
+ }
61
+ }
62
+
63
+ gradle.taskGraph.whenReady { graph ->
64
+ def release = ${condition}
65
+ if (release && !releaseSigningMissing.isEmpty()) {
66
+ throw new GradleException("Release signing needs \${releaseSigningMissing.join(", ")} in the environment or keystore.properties. Missing: \${releaseSigningMissing.join(", ")}.")
67
+ }
68
+ }
69
+ `;
70
+ }
71
+ /**
72
+ * Appends the signing block to `app/build.gradle` contents, once. Returns the
73
+ * contents unchanged when the marker is already present (idempotent).
74
+ */
75
+ export function appendReleaseSigning(contents, options) {
76
+ const marker = options?.marker ?? DEFAULT_RELEASE_SIGNING_MARKER;
77
+ if (contents.includes(marker))
78
+ return contents;
79
+ return contents + releaseSigningGradle(options);
80
+ }
81
+ function loadWithAppBuildGradle() {
82
+ // Resolve from the app (Expo runs config plugins with the app as the working
83
+ // directory), not from this package: under a strict node_modules layout this
84
+ // package cannot see the app's `expo`.
85
+ const require = createRequire(join(process.cwd(), "package.json"));
86
+ const plugins = require("expo/config-plugins");
87
+ return plugins.withAppBuildGradle;
88
+ }
89
+ /**
90
+ * Expo config plugin: appends the release signing block to `app/build.gradle`.
91
+ * Pass this through `plugins` in `app.config`, or call it directly on a config.
92
+ */
93
+ export function withReleaseSigning(config, options) {
94
+ const withGradle = options?.withAppBuildGradle ?? loadWithAppBuildGradle();
95
+ return withGradle(config, (mod) => {
96
+ if (options?.skipOnEasBuild && process.env.EAS_BUILD)
97
+ return mod;
98
+ mod.modResults.contents = appendReleaseSigning(mod.modResults.contents, options);
99
+ return mod;
100
+ });
101
+ }
@@ -0,0 +1,32 @@
1
+ // Shared oxlint JS plugin for the @vvedantb monorepos. Rule ids have no app
2
+ // prefix; configure them under the plugin name `vvedantb`, for example:
3
+ //
4
+ // // .oxlintrc.json
5
+ // {
6
+ // "jsPlugins": [
7
+ // { "name": "vvedantb", "specifier": "@vvedantb/config/oxlint/plugin.mjs" }
8
+ // ],
9
+ // "rules": {
10
+ // "vvedantb/no-value-block-in-try": "error",
11
+ // "vvedantb/no-source-text-in-tests": "error",
12
+ // "vvedantb/no-double-cast": "error",
13
+ // "vvedantb/no-json-parse": "error"
14
+ // }
15
+ // }
16
+ //
17
+ // oxlint reports each as `vvedantb(<rule>)`.
18
+
19
+ import noDoubleCast from "./rules/no-double-cast.mjs";
20
+ import noJsonParse from "./rules/no-json-parse.mjs";
21
+ import noSourceTextInTests from "./rules/no-source-text-in-tests.mjs";
22
+ import noValueBlockInTry from "./rules/no-value-block-in-try.mjs";
23
+
24
+ export default {
25
+ meta: { name: "vvedantb" },
26
+ rules: {
27
+ "no-double-cast": noDoubleCast,
28
+ "no-json-parse": noJsonParse,
29
+ "no-source-text-in-tests": noSourceTextInTests,
30
+ "no-value-block-in-try": noValueBlockInTry,
31
+ },
32
+ };
@@ -0,0 +1,21 @@
1
+ const message =
2
+ "Avoid double casts (`x as A as B`, `x as unknown as T`). They silence the type " +
3
+ "checker instead of proving the type. Validate at the boundary with a zod schema, " +
4
+ "or fix the source type so a single (or no) cast suffices.";
5
+
6
+ export default {
7
+ meta: {
8
+ type: "problem",
9
+ docs: { description: message },
10
+ },
11
+ create(context) {
12
+ return {
13
+ // `x as A as B` nests one TSAsExpression inside another.
14
+ TSAsExpression(node) {
15
+ if (node.expression?.type === "TSAsExpression") {
16
+ context.report({ node, message });
17
+ }
18
+ },
19
+ };
20
+ },
21
+ };