Skip to content

Commit

Permalink
fix(bin): fallback for webpack config path
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-pribilinskiy committed Jan 31, 2024
1 parent 82d3737 commit 355429a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/bin/download-federated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../helpers';

import {
assertRunningFromRoot, getOptionsFromWebpackConfig,
assertRunningFromRoot, getOptionsFromWebpackConfig, getWebpackConfigPathFromArgs,
} from './helpers';

assertRunningFromRoot();
Expand All @@ -23,7 +23,7 @@ type Argv = {
};

const argv = parseArgs<Argv>(process.argv.slice(2));
const webpackConfigPath = argv['webpack-config'] || 'webpack.config.js';
const webpackConfigPath = getWebpackConfigPathFromArgs(argv['webpack-config']);

const { mfPluginOptions, mfTypesPluginOptions } = getOptionsFromWebpackConfig(webpackConfigPath);

Expand Down
16 changes: 16 additions & 0 deletions src/bin/helpers/getWebpackConfigPathFromArgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { existsSync } from 'fs';

export function getWebpackConfigPathFromArgs(webpackConfigPath?: string): string {
if (!webpackConfigPath) {
if (existsSync('webpack.config.ts')) {
webpackConfigPath = 'webpack.config.ts';
} else if (existsSync('webpack.config.js')) {
webpackConfigPath = 'webpack.config.js';
} else {
console.error(`Could not find webpack.config.ts file at ${process.cwd()}`);
process.exit(1);
}
}

return webpackConfigPath;
}
1 change: 1 addition & 0 deletions src/bin/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './assertRunningFromRoot';
export * from './getFederationConfig';
export * from './getOptionsFromWebpackConfig';
export * from './getWebpackConfigPathFromArgs';
15 changes: 9 additions & 6 deletions src/bin/make-federated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { setLogger } from '../helpers';
import { FederationConfig } from '../models';

import {
assertRunningFromRoot, getFederationConfig, getOptionsFromWebpackConfig,
assertRunningFromRoot, getFederationConfig, getOptionsFromWebpackConfig, getWebpackConfigPathFromArgs,
} from './helpers';

assertRunningFromRoot();
Expand All @@ -36,12 +36,15 @@ const argv = parseArgs<Argv>(process.argv.slice(2), {
} as Partial<Argv>,
});

const webpackConfigPath = argv['webpack-config'] || 'webpack.config.js';
const federationConfig = webpackConfigPath
? getOptionsFromWebpackConfig(webpackConfigPath).mfPluginOptions as unknown as FederationConfig
: getFederationConfig(argv['federation-config']);
const compileFiles = Object.values(federationConfig.exposes);
let federationConfig: FederationConfig;
if (argv['federation-config']) {
federationConfig = getFederationConfig(argv['federation-config']);
} else {
const webpackConfigPath = getWebpackConfigPathFromArgs(argv['webpack-config']);
federationConfig = getOptionsFromWebpackConfig(webpackConfigPath).mfPluginOptions as FederationConfig;
}

const compileFiles = Object.values(federationConfig.exposes);
const outDir = argv['output-types-folder'] || path.join(DEFAULT_DIR_DIST, DEFAULT_DIR_EMITTED_TYPES);
const outFile = path.join(outDir, 'index.d.ts');
const dirGlobalTypes = argv['global-types'] || DEFAULT_DIR_GLOBAL_TYPES;
Expand Down

0 comments on commit 355429a

Please sign in to comment.