Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: init when there's a package.json in folder #1980

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 22 additions & 18 deletions packages/cli-config/src/loadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ function getDependencyConfig(
) as DependencyConfig;
}

// Try our best to figure out what version of React Native we're running. This is
// currently being used to get our deeplinks working, so it's only worried with
// the major and minor version.
function getReactNativeVersion(reactNativePath: string) {
try {
let semver = version.current(reactNativePath);
if (semver) {
// Retain only these version, since they correspond with our documentation.
return `${semver.major}.${semver.minor}`;
}
} catch (e) {
// If we don't seem to be in a well formed project, give up quietly.
if (!(e instanceof UnknownProjectError)) {
throw e;
}
}
return 'unknown';
}

/**
* Loads CLI configuration
*/
Expand All @@ -67,7 +86,9 @@ function loadConfig(projectRoot: string = findProjectRoot()): Config {
? path.resolve(projectRoot, userConfig.reactNativePath)
: resolveReactNativePath(projectRoot);
},
reactNativeVersion: 'unknown',
get reactNativeVersion() {
return getReactNativeVersion(initialConfig.reactNativePath);
},
dependencies: userConfig.dependencies,
commands: userConfig.commands,
healthChecks: [],
Expand All @@ -92,22 +113,6 @@ function loadConfig(projectRoot: string = findProjectRoot()): Config {
},
};

// Try our best to figure out what version of React Native we're running. This is
// currently being used to get our deeplinks working, so it's only worried with
// the major and minor version.
try {
let semver = version.current(initialConfig.reactNativePath);
if (semver) {
// Retain only these version, since they correspond with our documentation.
initialConfig.reactNativeVersion = `${semver.major}.${semver.minor}`;
}
} catch (e) {
// If we don't seem to be in a well formed project, give up quietly.
if (!(e instanceof UnknownProjectError)) {
throw e;
}
}

const finalConfig = Array.from(
new Set([
...Object.keys(userConfig.dependencies),
Expand All @@ -117,7 +122,6 @@ function loadConfig(projectRoot: string = findProjectRoot()): Config {
const localDependencyRoot =
userConfig.dependencies[dependencyName] &&
userConfig.dependencies[dependencyName].root;

try {
let root =
localDependencyRoot ||
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-tools/src/releaseChecker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function current(projectRoot: string): SemVer | undefined {
if (found) {
return found;
}
} catch (_) {
} catch {
throw new UnknownProjectError(projectRoot);
}
return undefined;
Expand Down