| 1 | const { d, n } = require('../../options');
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * Normalizes the options for the plugin.
|
|---|
| 5 | * @param {import('../types').ReactRefreshPluginOptions} options Non-normalized plugin options.
|
|---|
| 6 | * @returns {import('../types').NormalizedPluginOptions} Normalized plugin options.
|
|---|
| 7 | */
|
|---|
| 8 | const normalizeOptions = (options) => {
|
|---|
| 9 | d(options, 'exclude', /node_modules/i);
|
|---|
| 10 | d(options, 'include', /\.([cm]js|[jt]sx?|flow)$/i);
|
|---|
| 11 | d(options, 'forceEnable');
|
|---|
| 12 | d(options, 'library');
|
|---|
| 13 |
|
|---|
| 14 | n(options, 'overlay', (overlay) => {
|
|---|
| 15 | /** @type {import('../types').NormalizedErrorOverlayOptions} */
|
|---|
| 16 | const defaults = {
|
|---|
| 17 | entry: require.resolve('../../client/ErrorOverlayEntry'),
|
|---|
| 18 | module: require.resolve('../../overlay'),
|
|---|
| 19 | sockIntegration: 'wds',
|
|---|
| 20 | };
|
|---|
| 21 |
|
|---|
| 22 | if (overlay === false) {
|
|---|
| 23 | return false;
|
|---|
| 24 | }
|
|---|
| 25 | if (typeof overlay === 'undefined' || overlay === true) {
|
|---|
| 26 | return defaults;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | d(overlay, 'entry', defaults.entry);
|
|---|
| 30 | d(overlay, 'module', defaults.module);
|
|---|
| 31 | d(overlay, 'sockIntegration', defaults.sockIntegration);
|
|---|
| 32 | d(overlay, 'sockHost');
|
|---|
| 33 | d(overlay, 'sockPath');
|
|---|
| 34 | d(overlay, 'sockPort');
|
|---|
| 35 | d(overlay, 'sockProtocol');
|
|---|
| 36 | d(options, 'useURLPolyfill');
|
|---|
| 37 |
|
|---|
| 38 | return overlay;
|
|---|
| 39 | });
|
|---|
| 40 |
|
|---|
| 41 | return options;
|
|---|
| 42 | };
|
|---|
| 43 |
|
|---|
| 44 | module.exports = normalizeOptions;
|
|---|