From c39362d14e5a135645843ab4bc0dd58a2ae34e5e Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Mon, 18 Nov 2024 14:06:44 +0100 Subject: [PATCH 01/28] Remove Expo app.json configuration --- bin/expo-setup.js | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 25f3d57..e92c55f 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -10,38 +10,6 @@ import { readFile, writeFile } from 'node:fs/promises'; import isPlainObject from 'is-plain-obj'; -const appFilePath = 'app.json'; -const appJson = JSON.parse(await readFile(appFilePath, 'utf8')); - -if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { - throw new Error( - 'app.json either contains non-object or contains object without .expo property', - ); -} - -appJson.expo.experiments ||= {}; -// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- Set to empty object in previous line, if falsy -appJson.expo.experiments.typedRoutes = true; - -appJson.expo.plugins = [ - [ - 'expo-build-properties', - { - ios: { - newArchEnabled: true, - }, - android: { - newArchEnabled: true, - }, - }, - ], -]; - -await writeFile(appFilePath, JSON.stringify(appJson, null, 2), 'utf8'); -console.log( - '✅ Enabled New Architecture and typedRoutes experiment in app.json', -); - await writeFile('.env.development', 'EXPO_USE_FAST_RESOLVER=1', 'utf8'); console.log('✅ Enabled new Metro resolver in .env.development'); await writeFile('.env.production', 'EXPO_USE_FAST_RESOLVER=1', 'utf8'); From 08e5933220130dcbcee101bdfa70e22c27f7d42b Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Thu, 9 Jan 2025 12:04:18 +0100 Subject: [PATCH 02/28] Add Expo Router settings --- bin/expo-setup.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index e92c55f..cac252f 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -1,7 +1,7 @@ // Enable Expo non-default options for performance: // -// 1. app.json - Enable New Architecture for iOS and Android -// - https://docs.expo.dev/guides/new-architecture/ +// 1. app.json - Enable API Routes +// - https://docs.expo.dev/router/reference/api-routes/ // 2. .env.development, .env.production, eas.json - Enable the new Metro resolver available starting in Expo SDK 51 // - https://github.com/EvanBacon/pillar-valley/commit/ede321ef7addc67e4047624aedb3e92af3cb5060 // - https://archive.ph/MG03E @@ -10,6 +10,29 @@ import { readFile, writeFile } from 'node:fs/promises'; import isPlainObject from 'is-plain-obj'; +const appFilePath = 'app.json'; +const appJson = JSON.parse(await readFile(appFilePath, 'utf8')); + +if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { + throw new Error( + 'app.json either contains non-object or contains object without .expo property', + ); +} + +appJson.expo.plugins = [ + [ + 'expo-router', + { + origin: 'https://evanbacon.dev/', + }, + ], +]; + +appJson.expo.web.output = 'server'; + +await writeFile(appFilePath, JSON.stringify(appJson, null, 2), 'utf8'); +console.log('✅ Enabled Expo Router API Routes in app.json'); + await writeFile('.env.development', 'EXPO_USE_FAST_RESOLVER=1', 'utf8'); console.log('✅ Enabled new Metro resolver in .env.development'); await writeFile('.env.production', 'EXPO_USE_FAST_RESOLVER=1', 'utf8'); From 5285bc02b486ca28f1187b91df1359f2d739a285 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Thu, 9 Jan 2025 13:25:04 +0100 Subject: [PATCH 03/28] Add RSC config to app.json --- bin/expo-setup.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index cac252f..9586c07 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -1,7 +1,8 @@ // Enable Expo non-default options for performance: // -// 1. app.json - Enable API Routes +// 1. app.json - Enable API Routes and React Server Components // - https://docs.expo.dev/router/reference/api-routes/ +// - https://docs.expo.dev/guides/server-components/ // 2. .env.development, .env.production, eas.json - Enable the new Metro resolver available starting in Expo SDK 51 // - https://github.com/EvanBacon/pillar-valley/commit/ede321ef7addc67e4047624aedb3e92af3cb5060 // - https://archive.ph/MG03E @@ -30,6 +31,8 @@ appJson.expo.plugins = [ appJson.expo.web.output = 'server'; +appJson.expo.experiments = { reactServerFunctions: true }; + await writeFile(appFilePath, JSON.stringify(appJson, null, 2), 'utf8'); console.log('✅ Enabled Expo Router API Routes in app.json'); From e517f2ed149577710b154ddd46b957c79f264ad9 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Fri, 10 Jan 2025 15:34:06 +0100 Subject: [PATCH 04/28] Add rsc, expo-splash and eslint-disable --- bin/expo-setup.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 9586c07..8b869c5 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -20,6 +20,9 @@ if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { ); } +// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- appJson.expo.web is an object +appJson.expo.web.output = 'server'; + appJson.expo.plugins = [ [ 'expo-router', @@ -27,11 +30,19 @@ appJson.expo.plugins = [ origin: 'https://evanbacon.dev/', }, ], + [ + 'expo-splash-screen', + { + image: './assets/images/splash-icon.png', + imageWidth: 200, + resizeMode: 'contain', + backgroundColor: '#ffffff', + }, + ], ]; -appJson.expo.web.output = 'server'; - -appJson.expo.experiments = { reactServerFunctions: true }; +// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- appJson.expo.experiments is an object +appJson.expo.experiments.reactServerFunctions = true; await writeFile(appFilePath, JSON.stringify(appJson, null, 2), 'utf8'); console.log('✅ Enabled Expo Router API Routes in app.json'); From 4eba886f80c0389be3a59f56b9434407597beb75 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Tue, 14 Jan 2025 14:49:24 +0100 Subject: [PATCH 05/28] Add RSC to install log --- bin/expo-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 8b869c5..431f07c 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -45,7 +45,7 @@ appJson.expo.plugins = [ appJson.expo.experiments.reactServerFunctions = true; await writeFile(appFilePath, JSON.stringify(appJson, null, 2), 'utf8'); -console.log('✅ Enabled Expo Router API Routes in app.json'); +console.log('✅ Enabled Expo Router API Routes and RSC in app.json'); await writeFile('.env.development', 'EXPO_USE_FAST_RESOLVER=1', 'utf8'); console.log('✅ Enabled new Metro resolver in .env.development'); From c1dab945ee0105a5f9ada811ed3c679415efe7a2 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Wed, 15 Jan 2025 11:05:01 +0100 Subject: [PATCH 06/28] Remove RSC --- bin/expo-setup.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 431f07c..2fc919b 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -2,7 +2,6 @@ // // 1. app.json - Enable API Routes and React Server Components // - https://docs.expo.dev/router/reference/api-routes/ -// - https://docs.expo.dev/guides/server-components/ // 2. .env.development, .env.production, eas.json - Enable the new Metro resolver available starting in Expo SDK 51 // - https://github.com/EvanBacon/pillar-valley/commit/ede321ef7addc67e4047624aedb3e92af3cb5060 // - https://archive.ph/MG03E @@ -41,11 +40,8 @@ appJson.expo.plugins = [ ], ]; -// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- appJson.expo.experiments is an object -appJson.expo.experiments.reactServerFunctions = true; - await writeFile(appFilePath, JSON.stringify(appJson, null, 2), 'utf8'); -console.log('✅ Enabled Expo Router API Routes and RSC in app.json'); +console.log('✅ Enabled Expo Router API Routes in app.json'); await writeFile('.env.development', 'EXPO_USE_FAST_RESOLVER=1', 'utf8'); console.log('✅ Enabled new Metro resolver in .env.development'); From 1ef730581562c9af6d6a082b761640a2d5c55a34 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Wed, 15 Jan 2025 11:36:38 +0100 Subject: [PATCH 07/28] Remove RSC in comments --- bin/expo-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 2fc919b..1679455 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -1,6 +1,6 @@ // Enable Expo non-default options for performance: // -// 1. app.json - Enable API Routes and React Server Components +// 1. app.json - Enable API Routes // - https://docs.expo.dev/router/reference/api-routes/ // 2. .env.development, .env.production, eas.json - Enable the new Metro resolver available starting in Expo SDK 51 // - https://github.com/EvanBacon/pillar-valley/commit/ede321ef7addc67e4047624aedb3e92af3cb5060 From a26303949772e6f91e58920b5b9a712985ec9de4 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Mon, 20 Jan 2025 17:17:51 +0100 Subject: [PATCH 08/28] Convert app.json to app.config.ts --- bin/expo-setup.js | 49 +++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 1679455..b3e05e4 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -1,17 +1,17 @@ // Enable Expo non-default options for performance: // -// 1. app.json - Enable API Routes -// - https://docs.expo.dev/router/reference/api-routes/ +// 1. app.json - Convert to app.config.ts +// - https://docs.expo.dev/workflow/configuration/ // 2. .env.development, .env.production, eas.json - Enable the new Metro resolver available starting in Expo SDK 51 // - https://github.com/EvanBacon/pillar-valley/commit/ede321ef7addc67e4047624aedb3e92af3cb5060 // - https://archive.ph/MG03E // // TODO: Remove when Expo enables New Architecture and new Metro resolver by default -import { readFile, writeFile } from 'node:fs/promises'; +import { readFile, unlink, writeFile } from 'node:fs/promises'; import isPlainObject from 'is-plain-obj'; const appFilePath = 'app.json'; -const appJson = JSON.parse(await readFile(appFilePath, 'utf8')); +const appJson = JSON.parse(await readFile('app.json', 'utf8')); if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { throw new Error( @@ -19,29 +19,24 @@ if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { ); } -// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- appJson.expo.web is an object -appJson.expo.web.output = 'server'; - -appJson.expo.plugins = [ - [ - 'expo-router', - { - origin: 'https://evanbacon.dev/', - }, - ], - [ - 'expo-splash-screen', - { - image: './assets/images/splash-icon.png', - imageWidth: 200, - resizeMode: 'contain', - backgroundColor: '#ffffff', - }, - ], -]; - -await writeFile(appFilePath, JSON.stringify(appJson, null, 2), 'utf8'); -console.log('✅ Enabled Expo Router API Routes in app.json'); +const expoConfig = + `import { ExpoConfig } from "expo/config"; + +const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2) + .replace(/"([^\"]+)":/g, '$1:') + .replace(/"(.*?)"/g, `'$1'`) + .replace(/([}\]])(\s*[}\]])/g, '$1,$2') + .replace(/}(\s+\])/g, '},$1') + .replace(/(? Date: Wed, 22 Jan 2025 10:14:54 +0100 Subject: [PATCH 09/28] Fix lint error, trailing / --- bin/expo-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index b3e05e4..dccae70 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -23,7 +23,7 @@ const expoConfig = `import { ExpoConfig } from "expo/config"; const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2) - .replace(/"([^\"]+)":/g, '$1:') + .replace(/"([^"]+)":/g, '$1:') .replace(/"(.*?)"/g, `'$1'`) .replace(/([}\]])(\s*[}\]])/g, '$1,$2') .replace(/}(\s+\])/g, '},$1') From ab38f32599811c17ce29572bc488c76630a1cf7b Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Wed, 22 Jan 2025 10:17:55 +0100 Subject: [PATCH 10/28] Use variable instead of path --- bin/expo-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index dccae70..7427ec0 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -11,7 +11,7 @@ import { readFile, unlink, writeFile } from 'node:fs/promises'; import isPlainObject from 'is-plain-obj'; const appFilePath = 'app.json'; -const appJson = JSON.parse(await readFile('app.json', 'utf8')); +const appJson = JSON.parse(await readFile(appFilePath, 'utf8')); if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { throw new Error( From 722d8ce21118ed84d8af0fb58e7ee146e98fb078 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Wed, 22 Jan 2025 11:19:48 +0100 Subject: [PATCH 11/28] Format file with Prettier --- bin/expo-setup.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 7427ec0..37885f9 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -7,7 +7,9 @@ // - https://archive.ph/MG03E // // TODO: Remove when Expo enables New Architecture and new Metro resolver by default +import { exec } from 'node:child_process'; import { readFile, unlink, writeFile } from 'node:fs/promises'; +import { promisify } from 'node:util'; import isPlainObject from 'is-plain-obj'; const appFilePath = 'app.json'; @@ -19,22 +21,18 @@ if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { ); } -const expoConfig = - `import { ExpoConfig } from "expo/config"; +const expoConfig = `import { ExpoConfig } from "expo/config"; -const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2) - .replace(/"([^"]+)":/g, '$1:') - .replace(/"(.*?)"/g, `'$1'`) - .replace(/([}\]])(\s*[}\]])/g, '$1,$2') - .replace(/}(\s+\])/g, '},$1') - .replace(/(? Date: Wed, 22 Jan 2025 17:36:00 +0100 Subject: [PATCH 12/28] Update app.config comment with issue link --- bin/expo-setup.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 37885f9..d6c27e4 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -1,6 +1,8 @@ // Enable Expo non-default options for performance: // -// 1. app.json - Convert to app.config.ts +// 1. Convert app.json to app.config.ts for better flexibility, TypeScript support, and dynamic configuration +// This change is temporary until create-expo-app generates app.config.ts by default +// - Issue: https://github.com/expo/expo/issues/34357 // - https://docs.expo.dev/workflow/configuration/ // 2. .env.development, .env.production, eas.json - Enable the new Metro resolver available starting in Expo SDK 51 // - https://github.com/EvanBacon/pillar-valley/commit/ede321ef7addc67e4047624aedb3e92af3cb5060 From 135ab51a623c056d87413522d3b7e66b0653f01b Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Wed, 22 Jan 2025 18:37:46 +0100 Subject: [PATCH 13/28] Update bin/expo-setup.js Co-authored-by: Karl Horky --- bin/expo-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index d6c27e4..8a57e6c 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -1,4 +1,4 @@ -// Enable Expo non-default options for performance: +// Enable Expo non-default options for performance and consistency: // // 1. Convert app.json to app.config.ts for better flexibility, TypeScript support, and dynamic configuration // This change is temporary until create-expo-app generates app.config.ts by default From 42491bb708041fbae75cb33739752a1ca8b254b8 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Wed, 22 Jan 2025 18:37:53 +0100 Subject: [PATCH 14/28] Update bin/expo-setup.js Co-authored-by: Karl Horky --- bin/expo-setup.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 8a57e6c..abb33da 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -1,9 +1,10 @@ // Enable Expo non-default options for performance and consistency: // -// 1. Convert app.json to app.config.ts for better flexibility, TypeScript support, and dynamic configuration -// This change is temporary until create-expo-app generates app.config.ts by default -// - Issue: https://github.com/expo/expo/issues/34357 -// - https://docs.expo.dev/workflow/configuration/ +// 1. Convert app.json to app.config.ts for consistent TS language and dynamic config +// - https://docs.expo.dev/workflow/configuration/#dynamic-configuration +// +// TODO: Remove this if `create-expo-app` generates `app.config.ts` in future +// - https://github.com/expo/expo/issues/34357 // 2. .env.development, .env.production, eas.json - Enable the new Metro resolver available starting in Expo SDK 51 // - https://github.com/EvanBacon/pillar-valley/commit/ede321ef7addc67e4047624aedb3e92af3cb5060 // - https://archive.ph/MG03E From dad5d734e35902c4bb0997617eaed15e23b54915 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Thu, 23 Jan 2025 10:21:27 +0100 Subject: [PATCH 15/28] Run expo-setup with eslint install --- bin/expo-setup.js | 15 ++++++++------- bin/install.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index abb33da..2b7b616 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -10,10 +10,9 @@ // - https://archive.ph/MG03E // // TODO: Remove when Expo enables New Architecture and new Metro resolver by default -import { exec } from 'node:child_process'; import { readFile, unlink, writeFile } from 'node:fs/promises'; -import { promisify } from 'node:util'; import isPlainObject from 'is-plain-obj'; +import { format } from 'prettier'; const appFilePath = 'app.json'; const appJson = JSON.parse(await readFile(appFilePath, 'utf8')); @@ -24,17 +23,19 @@ if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { ); } -const expoConfig = `import { ExpoConfig } from "expo/config"; +const expoConfig = `import { type ExpoConfig } from "expo/config"; const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2)}; export default config;`.trim(); -await writeFile('app.config.ts', expoConfig, 'utf8'); -console.log('✅ Converted app.json to app.config.ts'); +const formattedConfig = await format(expoConfig, { + parser: 'typescript', + singleQuote: true, +}); -await promisify(exec)('npx prettier --write app.config.ts'); -console.log('✅ Formatted app.config.ts with Prettier'); +await writeFile('app.config.ts', formattedConfig, 'utf8'); +console.log('✅ Converted and formatted app.json to app.config.ts'); await unlink(appFilePath); console.log('✅ Deleted app.json'); diff --git a/bin/install.js b/bin/install.js index a70fe77..6b126c5 100755 --- a/bin/install.js +++ b/bin/install.js @@ -363,6 +363,20 @@ writeFileSync( console.log('✅ Done updating .gitignore'); +if (projectType === 'expo' || projectType === 'expo-postgresql') { + console.log('Running Expo setup script...'); + try { + const expoSetupPath = join( + dirname(fileURLToPath(import.meta.url)), + 'expo-setup.js', + ); + execSync(`node ${expoSetupPath}`, { stdio: 'inherit' }); + console.log('✅ Done running Expo setup script'); + } catch (error) { + console.error('❌ Failed to run Expo setup script', error); + } +} + // Commented out in case we need to patch Next.js again in the // future // ``` From abc0e437e92bdf2a639a37fc8a56a42b43a8b69e Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Thu, 23 Jan 2025 11:26:18 +0100 Subject: [PATCH 16/28] Remove script exec --- bin/install.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/bin/install.js b/bin/install.js index 6b126c5..a70fe77 100755 --- a/bin/install.js +++ b/bin/install.js @@ -363,20 +363,6 @@ writeFileSync( console.log('✅ Done updating .gitignore'); -if (projectType === 'expo' || projectType === 'expo-postgresql') { - console.log('Running Expo setup script...'); - try { - const expoSetupPath = join( - dirname(fileURLToPath(import.meta.url)), - 'expo-setup.js', - ); - execSync(`node ${expoSetupPath}`, { stdio: 'inherit' }); - console.log('✅ Done running Expo setup script'); - } catch (error) { - console.error('❌ Failed to run Expo setup script', error); - } -} - // Commented out in case we need to patch Next.js again in the // future // ``` From aac31418158a02a66f22ea681eaabc9f9523d552 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Thu, 23 Jan 2025 13:30:16 +0100 Subject: [PATCH 17/28] Revert to use replace instead of Prettier --- bin/expo-setup.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 2b7b616..6ea24a1 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -12,7 +12,6 @@ // TODO: Remove when Expo enables New Architecture and new Metro resolver by default import { readFile, unlink, writeFile } from 'node:fs/promises'; import isPlainObject from 'is-plain-obj'; -import { format } from 'prettier'; const appFilePath = 'app.json'; const appJson = JSON.parse(await readFile(appFilePath, 'utf8')); @@ -23,18 +22,19 @@ if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { ); } -const expoConfig = `import { type ExpoConfig } from "expo/config"; +const expoConfig = + `import { type ExpoConfig } from "expo/config"; -const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2)}; +const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2) + .replace(/"([^"]+)":/g, '$1:') + .replace(/"(.*?)"/g, `'$1'`) + .replace(/([}\]])(\s*[}\]])/g, '$1,$2') + .replace(/}(\s+\])/g, '},$1') + .replace(/(? Date: Fri, 24 Jan 2025 10:03:27 +0100 Subject: [PATCH 18/28] Add Prettier to expo-setup script --- bin/expo-setup.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 6ea24a1..49594d4 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -10,9 +10,14 @@ // - https://archive.ph/MG03E // // TODO: Remove when Expo enables New Architecture and new Metro resolver by default +import { execSync } from 'node:child_process'; import { readFile, unlink, writeFile } from 'node:fs/promises'; import isPlainObject from 'is-plain-obj'; +execSync('pnpm add --save-dev prettier', { stdio: 'inherit' }); + +const { format } = await import('prettier'); + const appFilePath = 'app.json'; const appJson = JSON.parse(await readFile(appFilePath, 'utf8')); @@ -22,19 +27,18 @@ if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { ); } -const expoConfig = - `import { type ExpoConfig } from "expo/config"; +const expoConfig = `import { type ExpoConfig } from 'expo/config'; + +const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2)}; -const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2) - .replace(/"([^"]+)":/g, '$1:') - .replace(/"(.*?)"/g, `'$1'`) - .replace(/([}\]])(\s*[}\]])/g, '$1,$2') - .replace(/}(\s+\])/g, '},$1') - .replace(/(? Date: Fri, 24 Jan 2025 10:29:58 +0100 Subject: [PATCH 19/28] Refactor expo-setup script to use promisified exec for adding Prettier --- bin/expo-setup.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 49594d4..c4254f2 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -10,11 +10,12 @@ // - https://archive.ph/MG03E // // TODO: Remove when Expo enables New Architecture and new Metro resolver by default -import { execSync } from 'node:child_process'; +import { exec } from 'node:child_process'; import { readFile, unlink, writeFile } from 'node:fs/promises'; +import { promisify } from 'node:util'; import isPlainObject from 'is-plain-obj'; -execSync('pnpm add --save-dev prettier', { stdio: 'inherit' }); +await promisify(exec)('pnpm add --save-dev prettier'); const { format } = await import('prettier'); @@ -75,7 +76,6 @@ easJson.build.development.extends = 'base'; easJson.build.development.env = { NODE_ENV: 'development', }; - easJson.build.preview.extends = 'base'; easJson.build.production.extends = 'base'; From c23acfc5dde69ea2c63acab9fb988cdc21c89356 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Fri, 24 Jan 2025 10:47:12 +0100 Subject: [PATCH 20/28] Add Prettier comment --- bin/expo-setup.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index c4254f2..e29d7fa 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -15,6 +15,10 @@ import { readFile, unlink, writeFile } from 'node:fs/promises'; import { promisify } from 'node:util'; import isPlainObject from 'is-plain-obj'; +// Add Prettier to format app.config.ts +// Keep installation near usage for clarity and easier removal later +// Simplifies cleanup when Expo generates app.config.ts by default +// - https://github.com/expo/expo/issues/34357 await promisify(exec)('pnpm add --save-dev prettier'); const { format } = await import('prettier'); From 758ed1f46762dc105dea50a6337e7deb25a0e03a Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Fri, 24 Jan 2025 11:01:42 +0100 Subject: [PATCH 21/28] Add empty line --- bin/expo-setup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index e29d7fa..249cda8 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -80,6 +80,7 @@ easJson.build.development.extends = 'base'; easJson.build.development.env = { NODE_ENV: 'development', }; + easJson.build.preview.extends = 'base'; easJson.build.production.extends = 'base'; From 3ee4cbce948feb1c41ceb97c1df9dc203bb20c6e Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Fri, 24 Jan 2025 11:38:48 +0100 Subject: [PATCH 22/28] Update comment --- bin/expo-setup.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 249cda8..9301d82 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -15,9 +15,9 @@ import { readFile, unlink, writeFile } from 'node:fs/promises'; import { promisify } from 'node:util'; import isPlainObject from 'is-plain-obj'; -// Add Prettier to format app.config.ts -// Keep installation near usage for clarity and easier removal later -// Simplifies cleanup when Expo generates app.config.ts by default +// Install Prettier to format app.config.ts +// - Keeps installation colocated with its usage for easier maintenance +// - Simplifies cleanup when Expo eventually generates app.config.ts by default // - https://github.com/expo/expo/issues/34357 await promisify(exec)('pnpm add --save-dev prettier'); From de6c8788cd234fa6daade368498cb00c8ebb7497 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Fri, 24 Jan 2025 11:54:48 +0100 Subject: [PATCH 23/28] Refactor inline variables --- bin/expo-setup.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 9301d82..9aa301b 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -23,8 +23,8 @@ await promisify(exec)('pnpm add --save-dev prettier'); const { format } = await import('prettier'); -const appFilePath = 'app.json'; -const appJson = JSON.parse(await readFile(appFilePath, 'utf8')); +const appJsonFilePath = 'app.json'; +const appJson = JSON.parse(await readFile(appJsonFilePath, 'utf8')); if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { throw new Error( @@ -32,21 +32,24 @@ if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { ); } -const expoConfig = `import { type ExpoConfig } from 'expo/config'; +await writeFile( + 'app.config.ts', + await format( + `import { type ExpoConfig } from 'expo/config'; const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2)}; -export default config;`.trim(); - -const formattedConfig = await format(expoConfig, { - parser: 'typescript', - singleQuote: true, -}); - -await writeFile('app.config.ts', formattedConfig, 'utf8'); +export default config;`.trim(), + { + parser: 'typescript', + singleQuote: true, + }, + ), + 'utf8', +); console.log('✅ Converted and formatted app.json to app.config.ts'); -await unlink(appFilePath); +await unlink(appJsonFilePath); console.log('✅ Deleted app.json'); await writeFile('.env.development', 'EXPO_USE_FAST_RESOLVER=1', 'utf8'); From 78bb7ef30add6d797a7e92eba2f3f430e7b23c1a Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Fri, 24 Jan 2025 11:55:11 +0100 Subject: [PATCH 24/28] Update bin/expo-setup.js Co-authored-by: Karl Horky --- bin/expo-setup.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 9aa301b..1d51e83 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -15,12 +15,12 @@ import { readFile, unlink, writeFile } from 'node:fs/promises'; import { promisify } from 'node:util'; import isPlainObject from 'is-plain-obj'; -// Install Prettier to format app.config.ts -// - Keeps installation colocated with its usage for easier maintenance -// - Simplifies cleanup when Expo eventually generates app.config.ts by default +// Install Prettier to format `app.config.ts`, colocated in this script for +// easier removal +// +// TODO: Remove if `create-expo-app` creates `app.config.ts` in future: // - https://github.com/expo/expo/issues/34357 await promisify(exec)('pnpm add --save-dev prettier'); - const { format } = await import('prettier'); const appJsonFilePath = 'app.json'; From ca81b513d606b34e4a98d92cf4c7b615b3342fd2 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Fri, 24 Jan 2025 11:56:27 +0100 Subject: [PATCH 25/28] Move import to code usage --- bin/expo-setup.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 1d51e83..0e6dda9 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -15,14 +15,6 @@ import { readFile, unlink, writeFile } from 'node:fs/promises'; import { promisify } from 'node:util'; import isPlainObject from 'is-plain-obj'; -// Install Prettier to format `app.config.ts`, colocated in this script for -// easier removal -// -// TODO: Remove if `create-expo-app` creates `app.config.ts` in future: -// - https://github.com/expo/expo/issues/34357 -await promisify(exec)('pnpm add --save-dev prettier'); -const { format } = await import('prettier'); - const appJsonFilePath = 'app.json'; const appJson = JSON.parse(await readFile(appJsonFilePath, 'utf8')); @@ -32,6 +24,14 @@ if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { ); } +// Install Prettier to format `app.config.ts`, colocated in this script for +// easier removal +// +// TODO: Remove if `create-expo-app` creates `app.config.ts` in future: +// - https://github.com/expo/expo/issues/34357 +await promisify(exec)('pnpm add --save-dev prettier'); +const { format } = await import('prettier'); + await writeFile( 'app.config.ts', await format( From 67a183391229f95b423827d842470209024c2288 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Fri, 24 Jan 2025 11:57:50 +0100 Subject: [PATCH 26/28] Update bin/expo-setup.js --- bin/expo-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 0e6dda9..a640e7d 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -27,7 +27,7 @@ if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) { // Install Prettier to format `app.config.ts`, colocated in this script for // easier removal // -// TODO: Remove if `create-expo-app` creates `app.config.ts` in future: +// TODO: Remove this if `create-expo-app` generates `app.config.ts` in future // - https://github.com/expo/expo/issues/34357 await promisify(exec)('pnpm add --save-dev prettier'); const { format } = await import('prettier'); From decbd225338ad51abbc9edf448755c292d970510 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Fri, 24 Jan 2025 12:02:37 +0100 Subject: [PATCH 27/28] Update bin/expo-setup.js --- bin/expo-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index a640e7d..6a0b3e1 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -47,7 +47,7 @@ export default config;`.trim(), ), 'utf8', ); -console.log('✅ Converted and formatted app.json to app.config.ts'); +console.log('✅ Created app.config.ts'); await unlink(appJsonFilePath); console.log('✅ Deleted app.json'); From a6a28630ac5fa624ebeaf833c574080ad4fe10b9 Mon Sep 17 00:00:00 2001 From: Lukas Prochazka Date: Fri, 24 Jan 2025 17:19:14 +0100 Subject: [PATCH 28/28] Remove .trim --- bin/expo-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/expo-setup.js b/bin/expo-setup.js index 6a0b3e1..05dad77 100644 --- a/bin/expo-setup.js +++ b/bin/expo-setup.js @@ -39,7 +39,7 @@ await writeFile( const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2)}; -export default config;`.trim(), +export default config;`, { parser: 'typescript', singleQuote: true,