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

Refactor loadAndValidateOptions p.2 (config middleware) #1305

Merged
merged 1 commit into from
Dec 13, 2024
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
8 changes: 8 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { logger } = require('@hubspot/local-dev-lib/logger');
const { addUserAgentHeader } = require('@hubspot/local-dev-lib/http');
const {
loadConfig,
getAndLoadConfigIfNeeded,
configFileExists,
getConfigPath,
} = require('@hubspot/local-dev-lib/config');
Expand Down Expand Up @@ -148,6 +149,7 @@ const setRequestHeaders = () => {
};

const loadConfigMiddleware = async options => {
// Load the new config and check for the conflicting config flag
if (configFileExists(true)) {
loadConfig('', options);

Expand All @@ -159,14 +161,20 @@ const loadConfigMiddleware = async options => {
);
process.exit(EXIT_CODES.ERROR);
}
return;
}

// We need to load the config when options.config exists,
// so that getAccountIdFromConfig() in injectAccountIdMiddleware reads from the right config
if (options.config && fs.existsSync(options.config)) {
const { config: configPath } = options;
await loadConfig(configPath, options);
return;
}

// Load deprecated config without a config flag and with no warnings
getAndLoadConfigIfNeeded(options);
return;
};

const checkAndWarnGitInclusionMiddleware = () => {
Expand Down
4 changes: 0 additions & 4 deletions lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const {
} = require('@hubspot/local-dev-lib/constants/auth');
const { commaSeparatedValues } = require('@hubspot/local-dev-lib/text');
const {
loadConfig,
getConfigPath,
validateConfig,
getAccountConfig,
Expand All @@ -30,9 +29,6 @@ const { EXIT_CODES } = require('./enums/exitCodes');
const { logError } = require('./errorHandlers/index');

async function loadAndValidateOptions(options, shouldValidateAccount = true) {
const { config: configPath } = options;
loadConfig(configPath, options);

let validAccount = true;
if (shouldValidateAccount) {
validAccount = await validateAccount(options);
Expand Down
Loading