diff --git a/packages/config-templates/pluginTemplates/@react-native-community/cli/overrides.json b/packages/config-templates/pluginTemplates/@react-native-community/cli/overrides.json new file mode 100644 index 0000000000..7c650c3e09 --- /dev/null +++ b/packages/config-templates/pluginTemplates/@react-native-community/cli/overrides.json @@ -0,0 +1,7 @@ +{ + "overrides": { + "build/bin.js": { + "require(\"./tools/gracefulifyFs\");": "require(\"./tools/gracefulifyFs\"/*RNV*/); var dotenv = require('dotenv'); if(dotenv) dotenv.config();" + } + } +} \ No newline at end of file diff --git a/packages/config-templates/renative.templates.json b/packages/config-templates/renative.templates.json index bf4fa34e81..b9e66a9c50 100644 --- a/packages/config-templates/renative.templates.json +++ b/packages/config-templates/renative.templates.json @@ -480,6 +480,7 @@ "version": "0.5.9" }, "@react-native-community/cli": { + "disableNpm": true, "version": "^6.0.0" }, "@react-native-community/cli-platform-android": { diff --git a/packages/engine-core/src/tasks/bootstrap/questions/installTemplate.ts b/packages/engine-core/src/tasks/bootstrap/questions/installTemplate.ts index 7fc323c526..101f214706 100644 --- a/packages/engine-core/src/tasks/bootstrap/questions/installTemplate.ts +++ b/packages/engine-core/src/tasks/bootstrap/questions/installTemplate.ts @@ -100,7 +100,7 @@ const Question = async (data: NewProjectData) => { } } - const nmDir = path.join(c.paths.project.dir, RnvFolderName.dotRnv, RnvFolderName.npmCache); + const npmCacheDir = path.join(c.paths.project.dir, RnvFolderName.dotRnv, RnvFolderName.npmCache); if (localTemplatePath) { if (!fsExistsSync(localTemplatePath)) { @@ -112,7 +112,7 @@ const Question = async (data: NewProjectData) => { } const pkg = readObjectSync(localTemplatePkgPath); - mkdirSync(nmDir); + mkdirSync(npmCacheDir); if (!pkg?.name) { return Promise.reject(`Invalid package ${localTemplatePkgPath} missing name field`); } @@ -123,7 +123,7 @@ const Question = async (data: NewProjectData) => { if (!inputs.template) return; - const nmTemplatePath = path.join(nmDir, pkg?.name); + const nmTemplatePath = path.join(npmCacheDir, pkg?.name); logInfo(`Found local template: ${pkg.name}@${pkg.version}`); @@ -189,6 +189,7 @@ const Question = async (data: NewProjectData) => { } ); // Check if node_modules folder exists + const nmDir = path.join(c.paths.project.dir, 'node_modules'); if (!fsExistsSync(nmDir)) { return Promise.reject( `${isYarnInstalled() ? 'yarn' : 'npm'} add ${inputs.template.packageName}@${ diff --git a/packages/engine-lightning/src/sdk/env.ts b/packages/engine-lightning/src/sdk/env.ts index 592b3fb0c0..ea8df8f089 100644 --- a/packages/engine-lightning/src/sdk/env.ts +++ b/packages/engine-lightning/src/sdk/env.ts @@ -11,7 +11,7 @@ export const EnvVars = { LNG_SERVE_PORT: () => { const ctx = getContext(); return { - LNG_SERVE_PORT: ctx.runtime.currentPlatform?.defaultPort, + LNG_SERVE_PORT: ctx.runtime.port, }; }, LNG_DIST_FOLDER: () => { diff --git a/packages/engine-lightning/src/sdk/runner.ts b/packages/engine-lightning/src/sdk/runner.ts index 4bcb2914a4..8100ed8965 100644 --- a/packages/engine-lightning/src/sdk/runner.ts +++ b/packages/engine-lightning/src/sdk/runner.ts @@ -23,7 +23,15 @@ import semver from 'semver'; import { runTizenSimOrDevice, CLI_TIZEN } from '@rnv/sdk-tizen'; import { CLI_WEBOS_ARES_PACKAGE, runWebosSimOrDevice } from '@rnv/sdk-webos'; -import { getAppVersion, getAppTitle, getAppId, getAppDescription, addSystemInjects } from '@rnv/sdk-utils'; +import { + getAppVersion, + getAppTitle, + getAppId, + getAppDescription, + addSystemInjects, + checkPortInUse, + confirmActiveBundler, +} from '@rnv/sdk-utils'; import { EnvVars } from './env'; export const runLightningProject = async () => { @@ -34,17 +42,35 @@ export const runLightningProject = async () => { const isHosted = hosted && !getConfigProp('bundleAssets'); if (isHosted) { - await executeAsync('lng dev', { - stdio: 'inherit', - silent: false, - env: { - ...CoreEnvVars.BASE(), - ...CoreEnvVars.RNV_EXTENSIONS(), - ...EnvVars.LNG_BUILD_FOLDER(), - ...EnvVars.LNG_ENTRY_FILE(), - ...EnvVars.LNG_SERVE_PORT(), - }, - }); + const isPortActive = await checkPortInUse(c.runtime.port); + if (isPortActive) { + const resetCompleted = await confirmActiveBundler(); + if (resetCompleted) { + await executeAsync('lng dev', { + stdio: 'inherit', + silent: false, + env: { + ...CoreEnvVars.BASE(), + ...CoreEnvVars.RNV_EXTENSIONS(), + ...EnvVars.LNG_BUILD_FOLDER(), + ...EnvVars.LNG_ENTRY_FILE(), + ...EnvVars.LNG_SERVE_PORT(), + }, + }); + } + } else { + await executeAsync('lng dev', { + stdio: 'inherit', + silent: false, + env: { + ...CoreEnvVars.BASE(), + ...CoreEnvVars.RNV_EXTENSIONS(), + ...EnvVars.LNG_BUILD_FOLDER(), + ...EnvVars.LNG_ENTRY_FILE(), + ...EnvVars.LNG_SERVE_PORT(), + }, + }); + } } else { await buildLightningProject(); if (platform === 'tizen') { diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index 2a8fd83c77..3df394127f 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -61,7 +61,7 @@ import { composeDevicesArray, } from './deviceManager'; import { ANDROID_COLORS, ANDROID_STRINGS, ANDROID_STYLES, CLI_ANDROID_ADB } from './constants'; -import { runReactNativeAndroid, packageReactNativeAndroid } from '@rnv/sdk-react-native'; +import { runReactNativeAndroid, packageReactNativeAndroid, generateEnvVarsFile } from '@rnv/sdk-react-native'; import { getEntryFile } from '@rnv/sdk-utils'; export const packageAndroid = async () => { @@ -361,6 +361,7 @@ export const configureGradleProject = async () => { await configureAndroidProperties(); await configureProject(); await copyBuildsFolder(); + await generateEnvVarsFile(); return true; }; diff --git a/packages/sdk-react-native/src/env.ts b/packages/sdk-react-native/src/env.ts index b37f9c2af6..249820ae61 100644 --- a/packages/sdk-react-native/src/env.ts +++ b/packages/sdk-react-native/src/env.ts @@ -1,5 +1,15 @@ -import { doResolve, getConfigProp, getContext, getRelativePath, parsePlugins } from '@rnv/core'; +import { + CoreEnvVars, + doResolve, + fsWriteFileSync, + getAppFolder, + getConfigProp, + getContext, + getRelativePath, + parsePlugins, +} from '@rnv/core'; import { getAppId } from '@rnv/sdk-utils'; +import path from 'path'; export const EnvVars = { RCT_METRO_PORT: () => { @@ -57,3 +67,25 @@ export const EnvVars = { return {}; }, }; + +export const generateEnvVarsFile = async () => { + const destDir = getAppFolder(); + const destPath = path.join(destDir, '.env'); + const envVars: Record = { + ...CoreEnvVars.BASE(), + RNV_EXTENSIONS: CoreEnvVars.RNV_EXTENSIONS().RNV_EXTENSIONS.join(', '), + ...EnvVars.RCT_METRO_PORT(), + ...EnvVars.RNV_REACT_NATIVE_PATH(), + ...EnvVars.RCT_NO_LAUNCH_PACKAGER(), + ...EnvVars.RNV_APP_ID(), + ...EnvVars.RCT_NEW_ARCH_ENABLED(), + ...EnvVars.RNV_FLIPPER_ENABLED(), + ...EnvVars.RNV_SKIP_LINKING(), + }; + let env = ''; + Object.keys(envVars).forEach((key) => { + env += `${key}=${envVars[key]}\n`; + }); + + fsWriteFileSync(destPath, env); +}; diff --git a/packages/template-starter/renative.json b/packages/template-starter/renative.json index 68b22e272e..193dd0a16c 100644 --- a/packages/template-starter/renative.json +++ b/packages/template-starter/renative.json @@ -82,9 +82,7 @@ "minSdkVersion": 21, "extendPlatform": "android", "engine": "engine-rn-tvos", - "includedPermissions": [ - "INTERNET" - ] + "includedPermissions": ["INTERNET"] }, "web": { "engine": "engine-rn-next" @@ -114,31 +112,20 @@ "react-dom": "source:rnv", "react-native-gesture-handler": "source:rnv", "@react-native-community/cli-platform-ios": { - "supportedPlatforms": [ - "tvos", - "ios" - ] + "supportedPlatforms": ["tvos", "ios"] + }, + "@react-native-community/cli": { + "supportedPlatforms": ["tvos", "ios"] }, "react-native": "source:rnv", "next": { - "supportedPlatforms": [ - "web" - ] + "supportedPlatforms": ["web"] }, "react-native-web": { - "supportedPlatforms": [ - "web", - "tizen", - "webos", - "macos" - ] + "supportedPlatforms": ["web", "tizen", "webos", "macos"] }, "react-native-tvos": { - "supportedPlatforms": [ - "tvos", - "firetv", - "androidtv" - ] + "supportedPlatforms": ["tvos", "firetv", "androidtv"] } }, "permissions": {