@gravity-ui/app-builder 0.23.0 → 0.24.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.
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildClient = buildClient;
4
4
  const compile_1 = require("../../../common/webpack/compile");
5
5
  function buildClient(config) {
6
- return (0, compile_1.clientCompile)(config.client);
6
+ return (0, compile_1.clientCompile)(config.client, config.configPath);
7
7
  }
@@ -60,6 +60,7 @@ async function buildDevServer(config) {
60
60
  await (0, config_1.webpackConfigFactory)({
61
61
  webpackMode: "development" /* WebpackMode.Dev */,
62
62
  config: normalizedConfig,
63
+ configPath: config.configPath,
63
64
  logger,
64
65
  }),
65
66
  ];
@@ -68,6 +69,7 @@ async function buildDevServer(config) {
68
69
  webpackConfigs.push(await (0, config_1.webpackConfigFactory)({
69
70
  webpackMode: "development" /* WebpackMode.Dev */,
70
71
  config: normalizedConfig,
72
+ configPath: config.configPath,
71
73
  logger: ssrLogger,
72
74
  isSsr,
73
75
  }));
@@ -78,6 +80,7 @@ async function buildDevServer(config) {
78
80
  await (0, config_1.rspackConfigFactory)({
79
81
  webpackMode: "development" /* WebpackMode.Dev */,
80
82
  config: normalizedConfig,
83
+ configPath: config.configPath,
81
84
  logger,
82
85
  }),
83
86
  ];
@@ -86,6 +89,7 @@ async function buildDevServer(config) {
86
89
  rspackConfigs.push(await (0, config_1.rspackConfigFactory)({
87
90
  webpackMode: "development" /* WebpackMode.Dev */,
88
91
  config: normalizedConfig,
92
+ configPath: config.configPath,
89
93
  logger: ssrLogger,
90
94
  isSsr,
91
95
  }));
@@ -271,6 +271,7 @@ export interface ServiceConfig {
271
271
  server?: ServerConfig;
272
272
  lib?: never;
273
273
  verbose?: boolean;
274
+ configPath?: string;
274
275
  }
275
276
  export type NormalizedClientConfig = Omit<ClientConfig, 'publicPathPrefix' | 'publicPath' | 'assetsManifestFile' | 'hiddenSourceMap' | 'svgr' | 'lazyCompilation' | 'devServer' | 'disableForkTsChecker' | 'disableReactRefresh'> & {
276
277
  bundler: Bundler;
@@ -1,2 +1,2 @@
1
1
  import type { NormalizedClientConfig } from '../models';
2
- export declare function clientCompile(config: NormalizedClientConfig): Promise<void>;
2
+ export declare function clientCompile(config: NormalizedClientConfig, configPath?: string): Promise<void>;
@@ -9,30 +9,42 @@ const core_1 = require("@rspack/core");
9
9
  const logger_1 = require("../logger");
10
10
  const config_1 = require("./config");
11
11
  const utils_1 = require("./utils");
12
- async function clientCompile(config) {
12
+ async function clientCompile(config, configPath) {
13
13
  const logger = new logger_1.Logger('client', config.verbose);
14
14
  const webpackConfigs = [];
15
15
  const rspackConfigs = [];
16
16
  const isSsr = Boolean(config.ssr);
17
17
  if (config.bundler === 'rspack') {
18
- rspackConfigs.push(await (0, config_1.rspackConfigFactory)({ webpackMode: "production" /* WebpackMode.Prod */, config, logger }));
18
+ rspackConfigs.push(await (0, config_1.rspackConfigFactory)({
19
+ webpackMode: "production" /* WebpackMode.Prod */,
20
+ config,
21
+ configPath,
22
+ logger,
23
+ }));
19
24
  if (isSsr) {
20
25
  const ssrLogger = new logger_1.Logger('client(SSR)', config.verbose);
21
26
  rspackConfigs.push(await (0, config_1.rspackConfigFactory)({
22
27
  webpackMode: "production" /* WebpackMode.Prod */,
23
28
  config,
29
+ configPath,
24
30
  logger: ssrLogger,
25
31
  isSsr,
26
32
  }));
27
33
  }
28
34
  }
29
35
  else {
30
- webpackConfigs.push(await (0, config_1.webpackConfigFactory)({ webpackMode: "production" /* WebpackMode.Prod */, config, logger }));
36
+ webpackConfigs.push(await (0, config_1.webpackConfigFactory)({
37
+ webpackMode: "production" /* WebpackMode.Prod */,
38
+ config,
39
+ configPath,
40
+ logger,
41
+ }));
31
42
  if (isSsr) {
32
43
  const ssrLogger = new logger_1.Logger('client(SSR)', config.verbose);
33
44
  webpackConfigs.push(await (0, config_1.webpackConfigFactory)({
34
45
  webpackMode: "production" /* WebpackMode.Prod */,
35
46
  config,
47
+ configPath,
36
48
  logger: ssrLogger,
37
49
  isSsr,
38
50
  }));
@@ -13,6 +13,7 @@ export interface HelperOptions {
13
13
  entry?: string | string[] | Record<string, string | string[]>;
14
14
  entriesDirectory: string;
15
15
  isSsr: boolean;
16
+ configPath?: string;
16
17
  }
17
18
  export declare const enum WebpackMode {
18
19
  Prod = "production",
@@ -23,6 +24,7 @@ type ClientFactoryOptions = {
23
24
  config: NormalizedClientConfig;
24
25
  logger?: Logger;
25
26
  isSsr?: boolean;
27
+ configPath?: string;
26
28
  };
27
29
  export declare function webpackConfigFactory(options: ClientFactoryOptions): Promise<webpack.Configuration>;
28
30
  export declare function rspackConfigFactory(options: ClientFactoryOptions): Promise<Rspack.Configuration>;
@@ -60,7 +60,7 @@ const node_externals_1 = require("./node-externals");
60
60
  const statoscope_1 = require("./statoscope");
61
61
  const imagesSizeLimit = 2048;
62
62
  const fontSizeLimit = 8192;
63
- function getHelperOptions({ webpackMode, config, logger, isSsr = false, }) {
63
+ function getHelperOptions({ webpackMode, config, logger, isSsr = false, configPath, }) {
64
64
  const isEnvDevelopment = webpackMode === "development" /* WebpackMode.Dev */;
65
65
  const isEnvProduction = webpackMode === "production" /* WebpackMode.Prod */;
66
66
  return {
@@ -74,6 +74,7 @@ function getHelperOptions({ webpackMode, config, logger, isSsr = false, }) {
74
74
  entry: config.entry,
75
75
  entriesDirectory: isSsr ? paths_1.default.appSsrEntry : paths_1.default.appEntry,
76
76
  isSsr,
77
+ configPath,
77
78
  };
78
79
  }
79
80
  function configureExternals({ config, isSsr }) {
@@ -89,6 +90,16 @@ function configureExternals({ config, isSsr }) {
89
90
  }
90
91
  return externals;
91
92
  }
93
+ function configureWebpackCache(options) {
94
+ const { config } = options;
95
+ if (typeof config.cache === 'object' && config.cache.type === 'filesystem') {
96
+ return {
97
+ ...config.cache,
98
+ buildDependencies: getCacheBuildDependencies(options),
99
+ };
100
+ }
101
+ return config.cache;
102
+ }
92
103
  async function webpackConfigFactory(options) {
93
104
  const { config } = options;
94
105
  const helperOptions = getHelperOptions(options);
@@ -121,7 +132,7 @@ async function webpackConfigFactory(options) {
121
132
  snapshot: {
122
133
  managedPaths: config.watchOptions?.watchPackages ? [] : undefined,
123
134
  },
124
- cache: config.cache,
135
+ cache: configureWebpackCache(helperOptions),
125
136
  };
126
137
  webpackConfig = await config.webpack(webpackConfig, {
127
138
  configType: isEnvProduction ? 'production' : 'development',
@@ -211,6 +222,31 @@ function configureWatchOptions({ config }) {
211
222
  delete watchOptions.watchPackages;
212
223
  return watchOptions;
213
224
  }
225
+ function getCacheBuildDependencies({ config, configPath }) {
226
+ const buildDependencies = {};
227
+ const dependenciesGroups = {
228
+ appBuilderConfig: configPath ? [configPath] : [],
229
+ packageJson: [path.join(paths_1.default.app, 'package.json')],
230
+ tsconfig: [
231
+ path.join(paths_1.default.app, 'tsconfig.json'),
232
+ path.join(paths_1.default.appClient, 'tsconfig.json'),
233
+ ],
234
+ };
235
+ for (const [group, filePaths] of Object.entries(dependenciesGroups)) {
236
+ for (const filePath of filePaths) {
237
+ if (fs.existsSync(filePath)) {
238
+ buildDependencies[group] = [...(buildDependencies[group] || []), filePath];
239
+ }
240
+ }
241
+ }
242
+ const userBuildDependencies = typeof config.cache === 'object' && config.cache.type === 'filesystem'
243
+ ? config.cache.buildDependencies
244
+ : {};
245
+ return {
246
+ ...buildDependencies,
247
+ ...userBuildDependencies,
248
+ };
249
+ }
214
250
  function configureExperiments({ config, isEnvProduction, isSsr, }) {
215
251
  if (isSsr) {
216
252
  return config.ssr?.moduleType === 'esm' ? { outputModule: true } : undefined;
@@ -244,7 +280,8 @@ function configureExperiments({ config, isEnvProduction, isSsr, }) {
244
280
  lazyCompilation,
245
281
  };
246
282
  }
247
- function configureRspackExperiments({ config, isEnvProduction, isSsr, }) {
283
+ function configureRspackExperiments(options) {
284
+ const { config, isSsr, isEnvProduction } = options;
248
285
  if (isSsr) {
249
286
  return config.ssr?.moduleType === 'esm' ? { outputModule: true } : undefined;
250
287
  }
@@ -278,18 +315,24 @@ function configureRspackExperiments({ config, isEnvProduction, isSsr, }) {
278
315
  },
279
316
  };
280
317
  }
318
+ const filesystemCacheOptions = typeof config.cache === 'object' && config.cache.type === 'filesystem'
319
+ ? config.cache
320
+ : undefined;
321
+ const version = [filesystemCacheOptions?.name, filesystemCacheOptions?.version]
322
+ .filter(Boolean)
323
+ .join('-');
281
324
  return {
282
325
  cache: {
326
+ version: version || undefined,
283
327
  type: 'persistent',
284
328
  snapshot: {
285
329
  managedPaths: config.watchOptions?.watchPackages ? [] : undefined,
286
330
  },
287
331
  storage: {
288
332
  type: 'filesystem',
289
- directory: typeof config.cache === 'object' && 'cacheDirectory' in config.cache
290
- ? config.cache.cacheDirectory
291
- : undefined,
333
+ directory: filesystemCacheOptions?.cacheDirectory,
292
334
  },
335
+ buildDependencies: Object.values(getCacheBuildDependencies(options)).flat(),
293
336
  },
294
337
  lazyCompilation,
295
338
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/app-builder",
3
- "version": "0.23.0",
3
+ "version": "0.24.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",