Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[config-types] android.intentFilters.data type fix #2707

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/config-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expo/config-types",
"version": "39.0.1",
"version": "40.0.0-beta.1",
"description": "Types for the Expo config object app.config.ts",
"main": "build/index.js",
"scripts": {
Expand Down
98 changes: 32 additions & 66 deletions packages/config-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ export interface ExpoConfig {
*/
backgroundColor?: string;
};
/**
* Adds a notification to your standalone app with refresh button and debug info.
*/
androidShowExponentNotificationInShellApp?: boolean;
/**
* Settings that apply specifically to running this app in a development client
*/
Expand Down Expand Up @@ -612,68 +608,8 @@ export interface ExpoConfig {
*/
autoVerify?: boolean;
action: string;
data?:
| {
/**
* the scheme of the URL, e.g. `https`
*/
scheme?: string;
/**
* the host, e.g. `myapp.io`
*/
host?: string;
/**
* the port, e.g. `3000`
*/
port?: string;
/**
* an exact path for URLs that should be matched by the filter, e.g. `/records`
*/
path?: string;
/**
* a regex for paths that should be matched by the filter, e.g. `.*`
*/
pathPattern?: string;
/**
* a prefix for paths that should be matched by the filter, e.g. `/records/` will match `/records/123`
*/
pathPrefix?: string;
/**
* a mime type for URLs that should be matched by the filter
*/
mimeType?: string;
}[]
| {
/**
* the scheme of the URL, e.g. `https`
*/
scheme?: string;
/**
* the host, e.g. `myapp.io`
*/
host?: string;
/**
* the port, e.g. `3000`
*/
port?: string;
/**
* an exact path for URLs that should be matched by the filter, e.g. `/records`
*/
path?: string;
/**
* a regex for paths that should be matched by the filter, e.g. `.*`
*/
pathPattern?: string;
/**
* a prefix for paths that should be matched by the filter, e.g. `/records/` will match `/records/123`
*/
pathPrefix?: string;
/**
* a mime type for URLs that should be matched by the filter
*/
mimeType?: string;
}[];
category?: string | any[];
data?: AndroidIntentFiltersData | AndroidIntentFiltersData[];
category?: string | string[];
}[];
/**
* Allows your user's app data to be automatically backed up to their Google Drive. If this is set to false, no backup or restore of the application will ever be performed (this is useful if your app deals with sensitive information). Defaults to the Android default, which is `true`.
Expand Down Expand Up @@ -880,3 +816,33 @@ export interface ExpoConfig {
turboModules?: boolean;
};
}
export interface AndroidIntentFiltersData {
/**
* the scheme of the URL, e.g. `https`
*/
scheme?: string;
/**
* the host, e.g. `myapp.io`
*/
host?: string;
/**
* the port, e.g. `3000`
*/
port?: string;
/**
* an exact path for URLs that should be matched by the filter, e.g. `/records`
*/
path?: string;
/**
* a regex for paths that should be matched by the filter, e.g. `.*`
*/
pathPattern?: string;
/**
* a prefix for paths that should be matched by the filter, e.g. `/records/` will match `/records/123`
*/
pathPrefix?: string;
/**
* a mime type for URLs that should be matched by the filter
*/
mimeType?: string;
}
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@babel/core": "7.9.0",
"@expo/babel-preset-cli": "0.2.18",
"@expo/config-types": "^39.0.0",
"@expo/config-types": "^40.0.0-beta.1",
"@expo/configure-splash-screen": "0.1.19",
"@expo/image-utils": "0.3.6",
"@expo/json-file": "8.2.24",
Expand Down
33 changes: 22 additions & 11 deletions packages/config/src/android/IntentFilters.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { AndroidIntentFiltersData, ExpoConfig } from '@expo/config-types';
import { Parser } from 'xml2js';

import { ExpoConfig } from '../Config.types';
import { Document, getMainActivity } from './Manifest';

type AndroidConfig = NonNullable<ExpoConfig['android']>;
type AndroidIntentFilters = NonNullable<AndroidConfig['intentFilters']>;
// TODO: make it so intent filters aren't written again if you run the command again

export function getIntentFilters(config: ExpoConfig) {
export function getIntentFilters(config: ExpoConfig): AndroidIntentFilters {
return config.android?.intentFilters ?? [];
}

export async function setAndroidIntentFilters(config: ExpoConfig, manifestDocument: Document) {
export async function setAndroidIntentFilters(
config: ExpoConfig,
manifestDocument: Document
): Promise<Document> {
const intentFilters = getIntentFilters(config);
if (!intentFilters.length) {
return manifestDocument;
Expand All @@ -30,7 +35,7 @@ export async function setAndroidIntentFilters(config: ExpoConfig, manifestDocume
return manifestDocument;
}

export default function renderIntentFilters(intentFilters: any) {
export default function renderIntentFilters(intentFilters: AndroidIntentFilters): string[] {
// returns an array of <intent-filter> tags:
// [
// `<intent-filter>
Expand All @@ -44,7 +49,7 @@ export default function renderIntentFilters(intentFilters: any) {
// </intent-filter>`,
// ...
// ]
return intentFilters.map((intentFilter: any) => {
return intentFilters.map(intentFilter => {
const autoVerify = intentFilter.autoVerify ? ' android:autoVerify="true"' : '';

return `<intent-filter${autoVerify}>
Expand All @@ -55,20 +60,26 @@ export default function renderIntentFilters(intentFilters: any) {
});
}

function renderIntentFilterDatumEntries(datum: any) {
return Object.keys(datum)
.map(key => `android:${key}="${datum[key]}"`)
.join(' ');
function renderIntentFilterDatumEntries(datum: AndroidIntentFiltersData = {}): string {
const entries: string[] = [];
for (const [key, value] of Object.entries(datum)) {
entries.push(`android:${key}="${value}"`);
}
return entries.join(' ');
}

function renderIntentFilterData(data: any) {
function renderIntentFilterData(
data?: AndroidIntentFiltersData | AndroidIntentFiltersData[]
): string {
return (Array.isArray(data) ? data : [data])
.filter(Boolean)
.map(datum => `<data ${renderIntentFilterDatumEntries(datum)}/>`)
.join('\n');
}

function renderIntentFilterCategory(category: any) {
function renderIntentFilterCategory(category?: string | string[]): string {
return (Array.isArray(category) ? category : [category])
.filter(Boolean)
.map(cat => `<category android:name="android.intent.category.${cat}"/>`)
.join('\n');
}
2 changes: 1 addition & 1 deletion packages/expo-cli/src/commands/client/clientBuildApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function createClientBuildRequest({
addUdid,
bundleIdentifier,
email,
customAppConfig,
customAppConfig: customAppConfig as any,
credentials: {
...(pushKey && pushKey.apnsKeyP8 ? { apnsKeyP8: pushKey.apnsKeyP8 } : null),
...(pushKey && pushKey.apnsKeyId ? { apnsKeyId: pushKey.apnsKeyId } : null),
Expand Down
8 changes: 4 additions & 4 deletions packages/expo-cli/src/commands/eject/Eject.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
WarningAggregator as ConfigWarningAggregator,
ExpoConfig,
PackageJSONConfig,
WarningAggregator,
getConfig,
PackageJSONConfig,
projectHasModule,
WarningAggregator,
} from '@expo/config';
import JsonFile from '@expo/json-file';
import JsonFile, { JSONObject } from '@expo/json-file';
import { Exp } from '@expo/xdl';
import chalk from 'chalk';
import crypto from 'crypto';
Expand Down Expand Up @@ -266,7 +266,7 @@ async function ensureConfigAsync(
await JsonFile.writeAsync(
// TODO: Write to app.config.json because it's easier to convert to a js config file.
path.join(projectRoot, 'app.json'),
{ expo: config.exp as Partial<ExpoConfig> },
{ expo: (config.exp as unknown) as JSONObject },
{ json5: false }
);
}
Expand Down
11 changes: 10 additions & 1 deletion packages/xdl/src/project/ExpSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getConfig } from '@expo/config';
import { JSONObject } from '@expo/json-file';
import Schemer from '@expo/schemer';
import fs from 'fs';
import { boolish } from 'getenv';
import path from 'path';

import ApiV2 from '../ApiV2';
Expand All @@ -24,6 +25,14 @@ export async function validatorFromProjectRoot(projectRoot: string): Promise<Sch
return validator;
}

export async function validateAsync(projectRoot: string) {
const { exp } = getConfig(projectRoot);
if (!exp.sdkVersion) throw new Error(`Couldn't read local manifest`);
const schema = await getSchemaAsync(exp.sdkVersion);
const validator = new Schemer(schema);
await validator.validateAll(exp);
}

export async function getSchemaAsync(sdkVersion: string): Promise<Schema> {
const json = await _getSchemaJSONAsync(sdkVersion);
return json.schema;
Expand Down Expand Up @@ -54,7 +63,7 @@ export async function getAssetSchemasAsync(sdkVersion: string): Promise<string[]
}

async function _getSchemaJSONAsync(sdkVersion: string): Promise<{ schema: Schema }> {
if (process.env.LOCAL_XDL_SCHEMA) {
if (boolish('LOCAL_XDL_SCHEMA', false)) {
if (process.env.EXPONENT_UNIVERSE_DIR) {
return JSON.parse(
fs
Expand Down
3 changes: 2 additions & 1 deletion packages/xdl/src/project/ManifestHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExpoAppManifest, ExpoConfig, getConfig } from '@expo/config';
import { JSONObject } from '@expo/json-file';
import express from 'express';
import http from 'http';
import os from 'os';
Expand Down Expand Up @@ -295,7 +296,7 @@ export async function getSignedManifestStringAsync(
remoteUsername: manifest.owner ?? (await UserManager.getCurrentUsernameAsync()),
remotePackageName: manifest.slug,
},
manifest,
manifest: manifest as JSONObject,
});
_cachedSignedManifest.manifestString = manifestString;
_cachedSignedManifest.signedManifest = response;
Expand Down