Skip to content

Commit

Permalink
fix(download-types): default webpack config, require from cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-pribilinskiy committed Jan 9, 2024
1 parent f23e0e5 commit c5ab635
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ Or it can be added to `package.json`:
#### download-federated-types
| Option | Default value | Description |
|-------------------------------|-------------------|---------------------------|
| `--webpack-config` | `webpack/prod.ts` | Path to webpack-config.js |
| `--webpack-config` | `webpack/prod.ts` | Path to webpack.config.js |

If the config is written in TypeScript, the script should be called with `npx ts-node`.

#### make-federated-types
| Option | Default value | Description |
|-------------------------------|-------------------|--------------------------------------------------------------------------------|
| `--output-types-folder`, `-o` | `dist/@types` | Path to the output folder, absolute or relative to the working directory |
| `--global-types`, `-g` | `src/@types` | Path to project's global ambient type definitions, relative to the working dir |
| `--federation-config`, `-c` | `src/@types` | Path to federation.config, relative to the working dir |
| `--tsconfig`, `-t` | `src/@types` | Path to tsconfig.json, relative to the working dir |
| `--webpack-config` | `webpack/prod.ts` | Path to webpack-config.js |
| Option | Default value | Description |
|-------------------------------|---------------------|--------------------------------------------------------------------------------|
| `--output-types-folder`, `-o` | `dist/@types` | Path to the output folder, absolute or relative to the working directory |
| `--global-types`, `-g` | `src/@types` | Path to project's global ambient type definitions, relative to the working dir |
| `--federation-config`, `-c` | `src/@types` | Path to federation.config, relative to the working dir |
| `--tsconfig`, `-t` | `src/@types` | Path to tsconfig.json, relative to the working dir |
| `--webpack-config` | `webpack.config.js` | Path to webpack.config.js |

## Plugin Configuration

Expand Down
2 changes: 1 addition & 1 deletion src/bin/download-federated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Argv = {
};

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

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

Expand Down
4 changes: 3 additions & 1 deletion src/bin/helpers/getOptionsFromWebpackConfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import path from 'path';

import { Compiler } from 'webpack';

import { ModuleFederationTypesPluginOptions } from '../../models';

export function getOptionsFromWebpackConfig(webpackConfigPath: string) {
let webpackConfig: Compiler['options'];
try {
webpackConfig = require(webpackConfigPath);
webpackConfig = require(path.join(process.cwd(), webpackConfigPath));
webpackConfig = ((webpackConfig as unknown as Dict).default as Compiler['options']) || webpackConfig;
} catch (error) {
console.error(`Failed to import webpack config from ${webpackConfigPath}:`, error);
Expand Down

0 comments on commit c5ab635

Please sign in to comment.