@gravity-ui/app-builder 0.11.2 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -205,7 +205,7 @@ With this `{rootDir}/src/ui/tsconfig.json`:
205
205
  - `options` (`import('https').ServerOptions`) — allow to provide your own certificate.
206
206
  - `watchOptions` — a set of options used to customize watch mode, [more](https://webpack.js.org/configuration/watch/#watchoptions)
207
207
  - `watchPackages` (`boolean`) - watch all changes in `node_modules`.
208
- - `disableReactRefresh` (`boolean`) — disable `react-refresh` in dev mode.
208
+ - `reactRefresh` (`false | (options: ReactRefreshPluginOptions) => ReactRefreshPluginOptions`) — disable or configure `react-refresh` in dev mode, [more](https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/API.md#options)
209
209
  - `detectCircularDependencies` (`true | CircularDependenciesOptions`) - detect modules with circular dependencies, [more](https://github.com/aackerman/circular-dependency-plugin)
210
210
  - `lazyCompilation` (`true | LazyCompilationConfig`) — enable experimental [lazy compilation](https://webpack.js.org/configuration/experiments/#experimentslazycompilation) feature
211
211
  - `true` — enable feature
@@ -244,8 +244,8 @@ With this `{rootDir}/src/ui/tsconfig.json`:
244
244
 
245
245
  - `monaco` (`object`) — use [monaco-editor-webpack-plugin](https://github.com/microsoft/monaco-editor/tree/main/webpack-plugin#monaco-editor-webpack-loader-plugin)
246
246
 
247
- - `fileName` (`string`) — custom filename template for worker scripts
248
- - `languages` (`string[]`) - include only a subset of the languages supported.
247
+ - `fileName` (`string`) — custom filename template for worker scripts.
248
+ - `languages` (`string[]`) - include only a subset of the languages supported. If you don't need support for all languages, set needed languages explicitly, since it may significantly affect build time.
249
249
  - `features` (`string[]`) - include only a subset of the editor features.
250
250
  - `customLanguages` (`IFeatureDefinition[]`) - include custom languages (outside of the ones shipped with the `monaco-editor`).
251
251
 
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.getProjectConfig = getProjectConfig;
30
30
  exports.normalizeConfig = normalizeConfig;
31
+ /* eslint-disable complexity */
31
32
  const path = __importStar(require("node:path"));
32
33
  const lodash_1 = __importDefault(require("lodash"));
33
34
  const cosmiconfig_1 = require("cosmiconfig");
@@ -183,6 +184,9 @@ async function normalizeClientConfig(client, mode) {
183
184
  const normalizedConfig = {
184
185
  ...client,
185
186
  forkTsChecker: client.disableForkTsChecker ? false : client.forkTsChecker,
187
+ reactRefresh: client.disableReactRefresh
188
+ ? false
189
+ : client.reactRefresh ?? ((options) => options),
186
190
  newJsxTransform: client.newJsxTransform ?? true,
187
191
  publicPathPrefix: client.publicPathPrefix || '',
188
192
  modules: client.modules && remapPaths(client.modules),
@@ -13,6 +13,7 @@ import type { SentryWebpackPluginOptions } from '@sentry/webpack-plugin';
13
13
  import type { WebpackMode } from '../webpack/config';
14
14
  import type { UploadOptions } from '../s3-upload/upload';
15
15
  import type { TerserOptions } from 'terser-webpack-plugin';
16
+ import type { ReactRefreshPluginOptions } from '@pmmmwh/react-refresh-webpack-plugin/types/lib/types';
16
17
  export interface Entities<T> {
17
18
  data: Record<string, T>;
18
19
  keys: string[];
@@ -129,9 +130,13 @@ export interface ClientConfig {
129
130
  statoscopeConfig?: Partial<StatoscopeOptions>;
130
131
  reactProfiling?: boolean;
131
132
  /**
132
- * Disable react-refresh in dev mode
133
+ * Disable react-refresh in dev mode
134
+ *
135
+ * @deprecated use `reactRefresh: false` instead
133
136
  */
134
137
  disableReactRefresh?: boolean;
138
+ /** Disable or configure react-refresh in dev mode */
139
+ reactRefresh?: false | ((options: ReactRefreshPluginOptions) => ReactRefreshPluginOptions);
135
140
  /**
136
141
  * Detect modules with circular dependencies
137
142
  */
@@ -213,7 +218,7 @@ export interface ServiceConfig {
213
218
  lib?: never;
214
219
  verbose?: boolean;
215
220
  }
216
- export type NormalizedClientConfig = Omit<ClientConfig, 'publicPathPrefix' | 'hiddenSourceMap' | 'svgr' | 'lazyCompilation' | 'devServer' | 'disableForkTsChecker'> & {
221
+ export type NormalizedClientConfig = Omit<ClientConfig, 'publicPathPrefix' | 'hiddenSourceMap' | 'svgr' | 'lazyCompilation' | 'devServer' | 'disableForkTsChecker' | 'disableReactRefresh'> & {
217
222
  publicPathPrefix: string;
218
223
  hiddenSourceMap: boolean;
219
224
  svgr: NonNullable<ClientConfig['svgr']>;
@@ -230,6 +235,7 @@ export type NormalizedClientConfig = Omit<ClientConfig, 'publicPathPrefix' | 'hi
230
235
  babel: (config: Babel.TransformOptions, options: {
231
236
  configType: `${WebpackMode}`;
232
237
  }) => Babel.TransformOptions | Promise<Babel.TransformOptions>;
238
+ reactRefresh: NonNullable<ClientConfig['reactRefresh']>;
233
239
  };
234
240
  export type NormalizedServerConfig = Omit<ServerConfig, 'port' | 'inspect' | 'inspectBrk'> & {
235
241
  port?: number;
@@ -223,7 +223,7 @@ function configureOutput({ isEnvDevelopment, ...rest }) {
223
223
  }
224
224
  function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, configType, config, }) {
225
225
  const plugins = [];
226
- if (isEnvDevelopment && !config.disableReactRefresh) {
226
+ if (isEnvDevelopment && config.reactRefresh !== false) {
227
227
  plugins.push([
228
228
  require.resolve('react-refresh/babel'),
229
229
  config.devServer?.webSocketPath
@@ -564,12 +564,12 @@ function configurePlugins(options) {
564
564
  publicPath: path.normalize(config.publicPathPrefix + '/build/'),
565
565
  }));
566
566
  }
567
- if (isEnvDevelopment && !config.disableReactRefresh) {
567
+ if (isEnvDevelopment && config.reactRefresh !== false) {
568
568
  const { webSocketPath = path.normalize(`/${config.publicPathPrefix}/build/sockjs-node`) } = config.devServer || {};
569
- plugins.push(new react_refresh_webpack_plugin_1.default({
569
+ plugins.push(new react_refresh_webpack_plugin_1.default(config.reactRefresh({
570
570
  overlay: { sockPath: webSocketPath },
571
571
  exclude: [/node_modules/, /\.worker\.[jt]sx?$/],
572
- }));
572
+ })));
573
573
  }
574
574
  if (config.detectCircularDependencies) {
575
575
  let circularPluginOptions = {
@@ -133,8 +133,8 @@ function configurePlugins({ isEnvDevelopment, isEnvProduction, config }) {
133
133
  publicPath: '/',
134
134
  }));
135
135
  }
136
- if (isEnvDevelopment && !config.disableReactRefresh) {
137
- plugins.push(new react_refresh_webpack_plugin_1.default());
136
+ if (isEnvDevelopment && config.reactRefresh !== false) {
137
+ plugins.push(new react_refresh_webpack_plugin_1.default(config.reactRefresh({})));
138
138
  }
139
139
  if (isEnvProduction) {
140
140
  plugins.push(new mini_css_extract_plugin_1.default({
@@ -73,13 +73,15 @@ const pitch = function (request) {
73
73
  configureSourceMap(workerCompiler);
74
74
  const cb = this.async();
75
75
  workerCompiler.compile((err, compilation) => {
76
- if (!compilation) {
77
- return undefined;
76
+ if (compilation) {
77
+ workerCompiler.parentCompilation?.children.push(compilation);
78
78
  }
79
- workerCompiler.parentCompilation?.children.push(compilation);
80
79
  if (err) {
81
80
  return cb(err);
82
81
  }
82
+ if (!compilation) {
83
+ return cb(new Error('Child compilation failed'));
84
+ }
83
85
  if (compilation.errors && compilation.errors.length) {
84
86
  const errorDetails = compilation.errors
85
87
  .map((error) => {
@@ -95,7 +97,7 @@ const pitch = function (request) {
95
97
  const cacheIdent = request;
96
98
  const objectToHash = compilation.assets[filename];
97
99
  if (!objectToHash) {
98
- throw new Error(`Asset ${filename} not found in compilation`);
100
+ return cb(new Error(`Asset ${filename} not found in compilation`));
99
101
  }
100
102
  const cacheETag = cache.getLazyHashedEtag(objectToHash);
101
103
  return cache.get(cacheIdent, cacheETag, (getCacheError, cacheContent) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/app-builder",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "description": "Develop and build your React client-server projects, powered by typescript and webpack",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",