Skip to content

Commit

Permalink
fix(cli): Load .env files automatically for migrations
Browse files Browse the repository at this point in the history
Fixes #2802
  • Loading branch information
michaelbromley committed Apr 25, 2024
1 parent 3a9c317 commit 777a5a5
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@vendure/common": "^2.2.0",
"change-case": "^4.1.2",
"commander": "^11.0.0",
"dotenv": "^16.4.5",
"fs-extra": "^11.2.0",
"picocolors": "^1.0.0",
"ts-morph": "^21.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function runGenerateMigration(): Promise<CliCommandReturnVal> {
cancel(cancelledMessage);
process.exit(0);
}
const config = loadVendureConfigFile(vendureConfig);
const config = await loadVendureConfigFile(vendureConfig);
const migrationSpinner = spinner();
migrationSpinner.start('Generating migration...');
const migrationName = await generateMigration(config, { name, outputDir: './src/migrations' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { register } from 'ts-node';
import { VendureConfigRef } from '../../shared/vendure-config-ref';
import { isRunningInTsNode } from '../../utilities/utils';

export function loadVendureConfigFile(vendureConfig: VendureConfigRef) {
export async function loadVendureConfigFile(vendureConfig: VendureConfigRef) {
await import('dotenv/config');
if (!isRunningInTsNode()) {
const tsConfigPath = path.join(process.cwd(), 'tsconfig.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function runRevertMigration(): Promise<CliCommandReturnVal> {
const project = await analyzeProject({ cancelledMessage });
const vendureConfig = new VendureConfigRef(project);
log.info('Using VendureConfig from ' + vendureConfig.getPathRelativeToProjectRoot());
const config = loadVendureConfigFile(vendureConfig);
const config = await loadVendureConfigFile(vendureConfig);

const runSpinner = spinner();
runSpinner.start('Reverting last migration...');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function runRunMigration(): Promise<CliCommandReturnVal> {
const project = await analyzeProject({ cancelledMessage });
const vendureConfig = new VendureConfigRef(project);
log.info('Using VendureConfig from ' + vendureConfig.getPathRelativeToProjectRoot());
const config = loadVendureConfigFile(vendureConfig);
const config = await loadVendureConfigFile(vendureConfig);

const runSpinner = spinner();
runSpinner.start('Running migrations...');
Expand Down

0 comments on commit 777a5a5

Please sign in to comment.