@gravity-ui/app-builder 0.14.2-beta.0 → 0.15.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.
Files changed (47) hide show
  1. package/dist/commands/build/build-service/client.js +1 -4
  2. package/dist/commands/dev/client.d.ts +1 -2
  3. package/dist/commands/dev/client.js +25 -55
  4. package/dist/common/config.js +8 -9
  5. package/dist/common/library/index.js +0 -1
  6. package/dist/common/logger/colors.d.ts +1 -1
  7. package/dist/common/logger/index.d.ts +1 -1
  8. package/dist/common/models/index.d.ts +0 -13
  9. package/dist/common/s3-upload/index.d.ts +0 -1
  10. package/dist/common/s3-upload/index.js +1 -3
  11. package/dist/common/s3-upload/webpack-plugin.d.ts +2 -2
  12. package/dist/common/s3-upload/webpack-plugin.js +2 -3
  13. package/dist/common/typescript/compile.js +7 -7
  14. package/dist/common/typescript/watch.js +6 -6
  15. package/dist/common/webpack/compile.d.ts +1 -1
  16. package/dist/common/webpack/compile.js +5 -5
  17. package/dist/common/webpack/config.js +40 -2
  18. package/dist/common/webpack/node-externals.d.ts +4 -2
  19. package/dist/common/webpack/node-externals.js +5 -5
  20. package/dist/common/webpack/progress-plugin.d.ts +4 -5
  21. package/dist/common/webpack/progress-plugin.js +11 -33
  22. package/dist/common/webpack/storybook.d.ts +1 -1
  23. package/dist/common/webpack/utils.d.ts +2 -2
  24. package/dist/common/webpack/utils.js +4 -2
  25. package/dist/common/webpack/worker/worker-loader.d.ts +2 -2
  26. package/dist/common/webpack/worker/worker-loader.js +17 -17
  27. package/package.json +1 -9
  28. package/dist/common/rspack/compile.d.ts +0 -2
  29. package/dist/common/rspack/compile.js +0 -27
  30. package/dist/common/rspack/config.d.ts +0 -24
  31. package/dist/common/rspack/config.js +0 -772
  32. package/dist/common/rspack/lazy-client.d.ts +0 -1
  33. package/dist/common/rspack/lazy-client.js +0 -63
  34. package/dist/common/rspack/progress-plugin.d.ts +0 -11
  35. package/dist/common/rspack/progress-plugin.js +0 -43
  36. package/dist/common/rspack/public-path.d.ts +0 -1
  37. package/dist/common/rspack/public-path.js +0 -4
  38. package/dist/common/rspack/utils.d.ts +0 -4
  39. package/dist/common/rspack/utils.js +0 -81
  40. package/dist/common/rspack/worker/public-path.worker.d.ts +0 -1
  41. package/dist/common/rspack/worker/public-path.worker.js +0 -3
  42. package/dist/common/rspack/worker/web-worker.d.mts +0 -8
  43. package/dist/common/rspack/worker/web-worker.mjs +0 -32
  44. package/dist/common/rspack/worker/worker-loader.d.ts +0 -4
  45. package/dist/common/rspack/worker/worker-loader.js +0 -177
  46. package/dist/common/s3-upload/create-plugin.d.ts +0 -3
  47. package/dist/common/s3-upload/create-plugin.js +0 -47
@@ -2,9 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildClient = buildClient;
4
4
  const compile_1 = require("../../../common/webpack/compile");
5
- const compile_2 = require("../../../common/rspack/compile");
6
5
  function buildClient(config) {
7
- return config.client.bundler === 'webpack'
8
- ? (0, compile_1.webpackCompile)(config.client)
9
- : (0, compile_2.rspackCompile)(config.client);
6
+ return (0, compile_1.clientCompile)(config.client);
10
7
  }
@@ -1,4 +1,3 @@
1
1
  import WebpackDevServer from 'webpack-dev-server';
2
- import { RspackDevServer } from '@rspack/dev-server';
3
2
  import type { NormalizedServiceConfig } from '../../common/models';
4
- export declare function watchClientCompilation(config: NormalizedServiceConfig, onManifestReady: () => void): Promise<WebpackDevServer<import("express").Application, import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>> | RspackDevServer>;
3
+ export declare function watchClientCompilation(config: NormalizedServiceConfig, onManifestReady: () => void): Promise<WebpackDevServer<import("express").Application, import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>>;
@@ -34,14 +34,9 @@ const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
34
34
  const webpack_manifest_plugin_1 = require("webpack-manifest-plugin");
35
35
  const webpack_assets_manifest_1 = __importDefault(require("webpack-assets-manifest"));
36
36
  const utils_1 = require("../../common/utils");
37
- const rspack_manifest_plugin_1 = require("rspack-manifest-plugin");
38
- const core_1 = require("@rspack/core");
39
- const dev_server_1 = require("@rspack/dev-server");
40
37
  const paths_1 = __importDefault(require("../../common/paths"));
41
38
  const logger_1 = require("../../common/logger");
42
39
  const config_1 = require("../../common/webpack/config");
43
- const config_2 = require("../../common/rspack/config");
44
- const utils_2 = require("../../common/rspack/utils");
45
40
  async function watchClientCompilation(config, onManifestReady) {
46
41
  const clientCompilation = await buildDevServer(config);
47
42
  const compiler = clientCompilation.compiler;
@@ -49,25 +44,19 @@ async function watchClientCompilation(config, onManifestReady) {
49
44
  return clientCompilation;
50
45
  }
51
46
  async function buildDevServer(config) {
52
- const bundler = config.client.bundler;
53
- const logger = new logger_1.Logger(bundler, config.verbose);
47
+ const logger = new logger_1.Logger('client', config.verbose);
54
48
  const { webSocketPath = path.normalize(`/${config.client.publicPathPrefix}/build/sockjs-node`), writeToDisk, ...devServer } = config.client.devServer || {};
55
49
  const normalizedConfig = { ...config.client, devServer: { ...devServer, webSocketPath } };
50
+ const webpackConfigs = [
51
+ await (0, config_1.webpackConfigFactory)("development" /* WebpackMode.Dev */, normalizedConfig, { logger }),
52
+ ];
56
53
  const isSsr = Boolean(normalizedConfig.ssr);
57
- let webpackConfigs = [];
58
- let rspackConfigs = [];
59
- if (bundler === 'webpack') {
60
- webpackConfigs = [await (0, config_1.webpackConfigFactory)("development" /* WebpackMode.Dev */, normalizedConfig, { logger })];
61
- if (isSsr) {
62
- const logger = new logger_1.Logger('webpack(SSR)', config.verbose);
63
- webpackConfigs.push(await (0, config_1.webpackConfigFactory)("development" /* WebpackMode.Dev */, normalizedConfig, { logger, isSsr }));
64
- }
65
- }
66
- else {
67
- if (isSsr) {
68
- throw new Error(`SSR is not supported in ${bundler}`);
69
- }
70
- rspackConfigs = [await (0, config_2.rspackConfigFactory)("development" /* RspackMode.Dev */, normalizedConfig, { logger })];
54
+ if (isSsr) {
55
+ const ssrLogger = new logger_1.Logger('client(SSR)', config.verbose);
56
+ webpackConfigs.push(await (0, config_1.webpackConfigFactory)("development" /* WebpackMode.Dev */, normalizedConfig, {
57
+ logger: ssrLogger,
58
+ isSsr,
59
+ }));
71
60
  }
72
61
  const publicPath = path.normalize(config.client.publicPathPrefix + '/build/');
73
62
  const staticFolder = path.resolve(paths_1.default.appDist, 'public');
@@ -145,60 +134,41 @@ async function buildDevServer(config) {
145
134
  });
146
135
  }
147
136
  options.proxy = proxy;
148
- let server;
149
- if (bundler === 'rspack') {
150
- // Rspack multicompiler dont work with lazy compilation
151
- const compiler = (0, core_1.rspack)(rspackConfigs[0]);
152
- server = new dev_server_1.RspackDevServer(options, compiler);
153
- // Need to clean cache before start. https://github.com/web-infra-dev/rspack/issues/9025
154
- (0, utils_2.clearCacheDirectory)(rspackConfigs[0], logger);
155
- }
156
- else {
157
- const compiler = (0, webpack_1.default)(webpackConfigs);
158
- server = new webpack_dev_server_1.default(options, compiler);
159
- }
137
+ const compiler = (0, webpack_1.default)(webpackConfigs);
138
+ const server = new webpack_dev_server_1.default(options, compiler);
160
139
  try {
161
140
  await server.start();
162
141
  }
163
142
  catch (e) {
164
- logger.logError(`Cannot start ${bundler} dev server`, e);
143
+ logger.logError('Cannot start webpack dev server', e);
165
144
  }
166
145
  if (options.ipc && typeof options.ipc === 'string') {
167
146
  fs.chmod(options.ipc, 0o666, (e) => logger.logError('', e));
168
147
  }
169
148
  return server;
170
149
  }
171
- function isRspackCompiler(compiler) {
172
- return 'rspack' in compiler;
173
- }
174
- function subscribeToManifestReadyEvent(compiler, onManifestReady) {
150
+ function subscribeToManifestReadyEvent(webpackCompiler, onManifestReady) {
175
151
  const promises = [];
176
- const options = Array.isArray(compiler.options) ? compiler.options : [compiler.options];
177
- const compilers = 'compilers' in compiler ? compiler.compilers : [compiler];
152
+ const options = Array.isArray(webpackCompiler.options)
153
+ ? webpackCompiler.options
154
+ : [webpackCompiler.options];
155
+ const compilers = 'compilers' in webpackCompiler ? webpackCompiler.compilers : [webpackCompiler];
178
156
  for (let i = 0; i < options.length; i++) {
179
157
  const config = options[i];
180
158
  const compiler = compilers[i];
181
159
  if (!config || !compiler) {
182
160
  throw new Error('Something goes wrong!');
183
161
  }
184
- if (!isRspackCompiler(compiler)) {
185
- const assetsManifestPlugin = config.plugins.find((plugin) => plugin instanceof webpack_assets_manifest_1.default);
186
- if (assetsManifestPlugin) {
187
- const assetsManifestReady = (0, utils_1.deferredPromise)();
188
- promises.push(assetsManifestReady.promise);
189
- assetsManifestPlugin.hooks.done.tap('app-builder', assetsManifestReady.resolve);
190
- }
162
+ const assetsManifestPlugin = config.plugins.find((plugin) => plugin instanceof webpack_assets_manifest_1.default);
163
+ if (assetsManifestPlugin) {
164
+ const assetsManifestReady = (0, utils_1.deferredPromise)();
165
+ promises.push(assetsManifestReady.promise);
166
+ assetsManifestPlugin.hooks.done.tap('app-builder', assetsManifestReady.resolve);
191
167
  }
192
168
  const manifestReady = (0, utils_1.deferredPromise)();
193
169
  promises.push(manifestReady.promise);
194
- if (isRspackCompiler(compiler)) {
195
- const { afterEmit } = (0, rspack_manifest_plugin_1.getCompilerHooks)(compiler);
196
- afterEmit.tap('app-builder', manifestReady.resolve);
197
- }
198
- else {
199
- const { afterEmit } = (0, webpack_manifest_plugin_1.getCompilerHooks)(compiler);
200
- afterEmit.tap('app-builder', manifestReady.resolve);
201
- }
170
+ const { afterEmit } = (0, webpack_manifest_plugin_1.getCompilerHooks)(compiler);
171
+ afterEmit.tap('app-builder', manifestReady.resolve);
202
172
  }
203
173
  Promise.all(promises).then(() => onManifestReady());
204
174
  }
@@ -22,15 +22,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.getProjectConfig = getProjectConfig;
30
27
  exports.normalizeConfig = normalizeConfig;
31
- /* eslint-disable complexity */
32
28
  const path = __importStar(require("node:path"));
33
- const lodash_1 = __importDefault(require("lodash"));
34
29
  const cosmiconfig_1 = require("cosmiconfig");
35
30
  const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
36
31
  const models_1 = require("./models");
@@ -42,7 +37,13 @@ function remapPaths(paths) {
42
37
  return splitPaths(paths).map((p) => path.resolve(process.cwd(), p));
43
38
  }
44
39
  function omitUndefined(obj) {
45
- return lodash_1.default.omitBy(obj, lodash_1.default.isUndefined);
40
+ const newObj = {};
41
+ for (const [key, value] of Object.entries(obj)) {
42
+ if (value !== undefined) {
43
+ newObj[key] = value;
44
+ }
45
+ }
46
+ return newObj;
46
47
  }
47
48
  function getModuleLoader({ storybook } = {}) {
48
49
  if (!storybook) {
@@ -176,7 +177,7 @@ async function normalizeConfig(userConfig, mode) {
176
177
  };
177
178
  return config;
178
179
  }
179
- const config = lodash_1.default.cloneDeep(userConfig);
180
+ const config = structuredClone(userConfig);
180
181
  config.lib.newJsxTransform = config.lib.newJsxTransform ?? true;
181
182
  return config;
182
183
  }
@@ -196,11 +197,9 @@ async function normalizeClientConfig(client, mode) {
196
197
  svgr: client.svgr ?? {},
197
198
  entryFilter: client.entryFilter && splitPaths(client.entryFilter),
198
199
  webpack: typeof client.webpack === 'function' ? client.webpack : (config) => config,
199
- rspack: typeof client.rspack === 'function' ? client.rspack : (config) => config,
200
200
  babel: typeof client.babel === 'function' ? client.babel : (config) => config,
201
201
  devServer: undefined,
202
202
  lazyCompilation: undefined,
203
- bundler: client.bundler || 'webpack',
204
203
  };
205
204
  if (mode === 'dev') {
206
205
  if (client.lazyCompilation) {
@@ -129,7 +129,6 @@ function compileStyles(inputDir, outputDir, onFinish, additionalGlobs = []) {
129
129
  const sassTransformed = sass_1.default.compile(scssFile, {
130
130
  sourceMap: true,
131
131
  sourceMapIncludeSources: true,
132
- silenceDeprecations: ['legacy-js-api'],
133
132
  importers: [
134
133
  {
135
134
  findFileUrl(url) {
@@ -5,7 +5,7 @@ export declare const colors: chalk.Chalk & chalk.ChalkFunction & {
5
5
  Color: ("black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright") | ("bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "bgGray" | "bgGrey" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright");
6
6
  ForegroundColor: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright";
7
7
  BackgroundColor: "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "bgGray" | "bgGrey" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright";
8
- Modifiers: "bold" | "hidden" | "reset" | "dim" | "italic" | "underline" | "inverse" | "strikethrough" | "visible";
8
+ Modifiers: "bold" | "reset" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough" | "visible";
9
9
  stderr: chalk.Chalk & {
10
10
  supportsColor: chalk.ColorSupport | false;
11
11
  };
@@ -12,7 +12,7 @@ export declare class Logger implements BaseLogger {
12
12
  Color: ("black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright") | ("bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "bgGray" | "bgGrey" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright");
13
13
  ForegroundColor: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright";
14
14
  BackgroundColor: "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "bgGray" | "bgGrey" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright";
15
- Modifiers: "bold" | "hidden" | "reset" | "dim" | "italic" | "underline" | "inverse" | "strikethrough" | "visible";
15
+ Modifiers: "bold" | "reset" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough" | "visible";
16
16
  stderr: import("chalk").Chalk & {
17
17
  supportsColor: import("chalk").ColorSupport | false;
18
18
  };
@@ -3,7 +3,6 @@ import type { EditorFeature } from 'monaco-editor-webpack-plugin/out/features';
3
3
  import type { IFeatureDefinition } from 'monaco-editor-webpack-plugin/out/types';
4
4
  import type { Options as MomentTzOptions } from 'moment-timezone-data-webpack-plugin';
5
5
  import type { Configuration, DefinePlugin, FileCacheOptions, MemoryCacheOptions, ResolveOptions } from 'webpack';
6
- import type { Configuration as RspackConfiguration } from '@rspack/core';
7
6
  import type * as Babel from '@babel/core';
8
7
  import type { ServerConfiguration } from 'webpack-dev-server';
9
8
  import type { Options as CircularDependenciesOptions } from 'circular-dependency-plugin';
@@ -15,7 +14,6 @@ import type { WebpackMode } from '../webpack/config';
15
14
  import type { UploadOptions } from '../s3-upload/upload';
16
15
  import type { TerserOptions } from 'terser-webpack-plugin';
17
16
  import type { ReactRefreshPluginOptions } from '@pmmmwh/react-refresh-webpack-plugin/types/lib/types';
18
- type Bundler = 'webpack' | 'rspack';
19
17
  export interface Entities<T> {
20
18
  data: Record<string, T>;
21
19
  keys: string[];
@@ -184,12 +182,6 @@ export interface ClientConfig {
184
182
  configType: `${WebpackMode}`;
185
183
  isSsr?: boolean;
186
184
  }) => Configuration | Promise<Configuration>;
187
- /**
188
- * Modify or return a custom Rspack config.
189
- */
190
- rspack?: (config: RspackConfiguration, options: {
191
- configType: `${WebpackMode}`;
192
- }) => RspackConfiguration | Promise<RspackConfiguration>;
193
185
  /**
194
186
  * Modify or return a custom Babel config.
195
187
  */
@@ -205,7 +197,6 @@ export interface ClientConfig {
205
197
  noExternal?: string | RegExp | (string | RegExp)[] | true;
206
198
  moduleType?: 'commonjs' | 'esm';
207
199
  };
208
- bundler?: Bundler;
209
200
  }
210
201
  export interface CdnUploadConfig {
211
202
  bucket: string;
@@ -234,7 +225,6 @@ export interface ServiceConfig {
234
225
  verbose?: boolean;
235
226
  }
236
227
  export type NormalizedClientConfig = Omit<ClientConfig, 'publicPathPrefix' | 'hiddenSourceMap' | 'svgr' | 'lazyCompilation' | 'devServer' | 'disableForkTsChecker' | 'disableReactRefresh'> & {
237
- bundler: Bundler;
238
228
  publicPathPrefix: string;
239
229
  hiddenSourceMap: boolean;
240
230
  svgr: NonNullable<ClientConfig['svgr']>;
@@ -248,9 +238,6 @@ export type NormalizedClientConfig = Omit<ClientConfig, 'publicPathPrefix' | 'hi
248
238
  configType: `${WebpackMode}`;
249
239
  isSsr: boolean;
250
240
  }) => Configuration | Promise<Configuration>;
251
- rspack: (config: RspackConfiguration, options: {
252
- configType: `${WebpackMode}`;
253
- }) => RspackConfiguration | Promise<RspackConfiguration>;
254
241
  debugWebpack?: boolean;
255
242
  babel: (config: Babel.TransformOptions, options: {
256
243
  configType: `${WebpackMode}`;
@@ -1,4 +1,3 @@
1
1
  export { S3UploadPlugin } from './webpack-plugin';
2
2
  export { uploadFiles } from './upload';
3
- export { createS3UploadPlugins } from './create-plugin';
4
3
  export type { UploadFilesOptions } from './upload';
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createS3UploadPlugins = exports.uploadFiles = exports.S3UploadPlugin = void 0;
3
+ exports.uploadFiles = exports.S3UploadPlugin = void 0;
4
4
  var webpack_plugin_1 = require("./webpack-plugin");
5
5
  Object.defineProperty(exports, "S3UploadPlugin", { enumerable: true, get: function () { return webpack_plugin_1.S3UploadPlugin; } });
6
6
  var upload_1 = require("./upload");
7
7
  Object.defineProperty(exports, "uploadFiles", { enumerable: true, get: function () { return upload_1.uploadFiles; } });
8
- var create_plugin_1 = require("./create-plugin");
9
- Object.defineProperty(exports, "createS3UploadPlugins", { enumerable: true, get: function () { return create_plugin_1.createS3UploadPlugins; } });
@@ -1,4 +1,4 @@
1
- import type { Compiler } from 'webpack';
1
+ import type * as Webpack from 'webpack';
2
2
  import type { Logger } from '../logger/index.js';
3
3
  import type { UploadOptions } from './upload.js';
4
4
  import type { S3ClientOptions } from './s3-client.js';
@@ -14,7 +14,7 @@ interface S3UploadPluginOptions {
14
14
  export declare class S3UploadPlugin {
15
15
  private options;
16
16
  constructor(options: S3UploadPluginOptions);
17
- apply(compiler: Compiler): void;
17
+ apply(compiler: Webpack.Compiler): void;
18
18
  private isIncludeAndNotExclude;
19
19
  }
20
20
  type Rule = RegExp | string | ((s: string) => boolean);
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.S3UploadPlugin = void 0;
4
- const webpack_1 = require("webpack");
5
4
  const fast_glob_1 = require("fast-glob");
6
5
  const upload_js_1 = require("./upload.js");
7
6
  class S3UploadPlugin {
@@ -12,7 +11,7 @@ class S3UploadPlugin {
12
11
  apply(compiler) {
13
12
  compiler.hooks.done.tapPromise('s3-upload-plugin', async (stats) => {
14
13
  if (stats.hasErrors()) {
15
- stats.compilation.warnings.push(new webpack_1.WebpackError('s3-upload-plugin: skipped upload to s3 due to compilation errors'));
14
+ stats.compilation.warnings.push(new compiler.webpack.WebpackError('s3-upload-plugin: skipped upload to s3 due to compilation errors'));
16
15
  return;
17
16
  }
18
17
  let fileNames = Object.keys(stats.compilation.assets);
@@ -39,7 +38,7 @@ class S3UploadPlugin {
39
38
  this.options.logger?.success(`Files successfully uploaded to bucket ${this.options.s3UploadOptions.bucket}`);
40
39
  }
41
40
  catch (e) {
42
- const error = new webpack_1.WebpackError(`s3-upload-plugin: ${e instanceof Error ? e.message : e}`);
41
+ const error = new compiler.webpack.WebpackError(`s3-upload-plugin: ${e instanceof Error ? e.message : e}`);
43
42
  stats.compilation.errors.push(error);
44
43
  }
45
44
  });
@@ -24,7 +24,7 @@ function compile(ts, { projectPath, configFileName = 'tsconfig.json', optionsToE
24
24
  const program = ts.createProgram(parsedConfig.fileNames, parsedConfig.options, compilerHost);
25
25
  // @ts-expect-error
26
26
  const filesCount = compilerHost.readFile.disableDisplay();
27
- const allDiagnostics = ts.getPreEmitDiagnostics(program).slice();
27
+ let allDiagnostics = ts.getPreEmitDiagnostics(program);
28
28
  logger.verbose(`Program created, read ${filesCount} files`);
29
29
  if (!hasErrors(allDiagnostics)) {
30
30
  logger.verbose('We finished making the program! Emitting...');
@@ -34,7 +34,7 @@ function compile(ts, { projectPath, configFileName = 'tsconfig.json', optionsToE
34
34
  afterDeclarations: [transformPathsToLocalModules],
35
35
  });
36
36
  logger.verbose('Emit complete!');
37
- allDiagnostics.push(...emitResult.diagnostics);
37
+ allDiagnostics = ts.sortAndDeduplicateDiagnostics(allDiagnostics.concat(emitResult.diagnostics));
38
38
  }
39
39
  allDiagnostics.forEach(reportDiagnostic);
40
40
  if (hasErrors(allDiagnostics)) {
@@ -44,12 +44,12 @@ function compile(ts, { projectPath, configFileName = 'tsconfig.json', optionsToE
44
44
  else {
45
45
  logger.success(`Compiled successfully in ${(0, pretty_time_1.elapsedTime)(start)}`);
46
46
  }
47
- const formatHost = {
48
- getCanonicalFileName: (path) => path,
49
- getCurrentDirectory: ts.sys.getCurrentDirectory,
50
- getNewLine: () => ts.sys.newLine,
51
- };
52
47
  function reportDiagnostic(diagnostic) {
48
+ const formatHost = {
49
+ getCanonicalFileName: (path) => path,
50
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
51
+ getNewLine: () => ts.sys.newLine,
52
+ };
53
53
  if (logger.isVerbose) {
54
54
  logger.message(ts.formatDiagnosticsWithColorAndContext([diagnostic], formatHost));
55
55
  }
@@ -9,11 +9,6 @@ function watch(ts, projectPath, { logger, onAfterFilesEmitted, enableSourceMap,
9
9
  logger.message(`Typescript v${ts.version}`);
10
10
  const configPath = (0, utils_1.getTsProjectConfigPath)(ts, projectPath);
11
11
  const createProgram = ts.createEmitAndSemanticDiagnosticsBuilderProgram;
12
- const formatHost = {
13
- getCanonicalFileName: (path) => path,
14
- getCurrentDirectory: ts.sys.getCurrentDirectory,
15
- getNewLine: () => ts.sys.newLine,
16
- };
17
12
  const host = ts.createWatchCompilerHost(configPath, {
18
13
  noEmit: false,
19
14
  noEmitOnError: false,
@@ -46,6 +41,11 @@ function watch(ts, projectPath, { logger, onAfterFilesEmitted, enableSourceMap,
46
41
  // the program over time.
47
42
  ts.createWatchProgram(host);
48
43
  function reportDiagnostic(diagnostic) {
44
+ const formatHost = {
45
+ getCanonicalFileName: (path) => path,
46
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
47
+ getNewLine: () => ts.sys.newLine,
48
+ };
49
49
  if (logger.isVerbose) {
50
50
  logger.message(ts.formatDiagnosticsWithColorAndContext([diagnostic], formatHost));
51
51
  }
@@ -59,7 +59,7 @@ function watch(ts, projectPath, { logger, onAfterFilesEmitted, enableSourceMap,
59
59
  */
60
60
  function reportWatchStatusChanged(diagnostic) {
61
61
  if (diagnostic.messageText) {
62
- logger.message(ts.flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine()));
62
+ logger.message(ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine));
63
63
  }
64
64
  }
65
65
  }
@@ -1,2 +1,2 @@
1
1
  import type { NormalizedClientConfig } from '../models';
2
- export declare function webpackCompile(config: NormalizedClientConfig): Promise<void>;
2
+ export declare function clientCompile(config: NormalizedClientConfig): Promise<void>;
@@ -3,18 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.webpackCompile = webpackCompile;
6
+ exports.clientCompile = clientCompile;
7
7
  const webpack_1 = __importDefault(require("webpack"));
8
8
  const logger_1 = require("../logger");
9
9
  const config_1 = require("./config");
10
10
  const utils_1 = require("./utils");
11
- async function webpackCompile(config) {
12
- const logger = new logger_1.Logger('webpack', config.verbose);
11
+ async function clientCompile(config) {
12
+ const logger = new logger_1.Logger('client', config.verbose);
13
13
  const webpackConfigs = [await (0, config_1.webpackConfigFactory)("production" /* WebpackMode.Prod */, config, { logger })];
14
14
  const isSsr = Boolean(config.ssr);
15
15
  if (isSsr) {
16
- const logger = new logger_1.Logger('webpack(SSR)', config.verbose);
17
- webpackConfigs.push(await (0, config_1.webpackConfigFactory)("production" /* WebpackMode.Prod */, config, { logger, isSsr }));
16
+ const ssrLogger = new logger_1.Logger('client(SSR)', config.verbose);
17
+ webpackConfigs.push(await (0, config_1.webpackConfigFactory)("production" /* WebpackMode.Prod */, config, { logger: ssrLogger, isSsr }));
18
18
  }
19
19
  logger.verbose('Config created');
20
20
  return new Promise((resolve) => {
@@ -30,7 +30,6 @@ exports.webpackConfigFactory = webpackConfigFactory;
30
30
  exports.configureModuleRules = configureModuleRules;
31
31
  exports.configureResolve = configureResolve;
32
32
  exports.configureOptimization = configureOptimization;
33
- /* eslint-disable complexity */
34
33
  const path = __importStar(require("node:path"));
35
34
  const fs = __importStar(require("node:fs"));
36
35
  const webpack = __importStar(require("webpack"));
@@ -702,7 +701,46 @@ function configurePlugins(options) {
702
701
  }
703
702
  }
704
703
  if (config.cdn) {
705
- plugins.push(...(0, s3_upload_1.createS3UploadPlugins)(config, options.logger));
704
+ let credentialsGlobal;
705
+ if (process.env.FRONTEND_S3_ACCESS_KEY_ID &&
706
+ process.env.FRONTEND_S3_SECRET_ACCESS_KEY) {
707
+ credentialsGlobal = {
708
+ accessKeyId: process.env.FRONTEND_S3_ACCESS_KEY_ID,
709
+ secretAccessKey: process.env.FRONTEND_S3_SECRET_ACCESS_KEY,
710
+ };
711
+ }
712
+ const cdns = Array.isArray(config.cdn) ? config.cdn : [config.cdn];
713
+ for (let index = 0; index < cdns.length; index++) {
714
+ const cdn = cdns[index];
715
+ if (!cdn) {
716
+ continue;
717
+ }
718
+ let credentials = credentialsGlobal;
719
+ const accessKeyId = process.env[`FRONTEND_S3_ACCESS_KEY_ID_${index}`];
720
+ const secretAccessKey = process.env[`FRONTEND_S3_SECRET_ACCESS_KEY_${index}`];
721
+ if (accessKeyId && secretAccessKey) {
722
+ credentials = {
723
+ accessKeyId,
724
+ secretAccessKey,
725
+ };
726
+ }
727
+ plugins.push(new s3_upload_1.S3UploadPlugin({
728
+ exclude: config.hiddenSourceMap ? /\.map$/ : undefined,
729
+ compress: cdn.compress,
730
+ s3ClientOptions: {
731
+ region: cdn.region,
732
+ endpoint: cdn.endpoint,
733
+ credentials,
734
+ },
735
+ s3UploadOptions: {
736
+ bucket: cdn.bucket,
737
+ targetPath: cdn.prefix,
738
+ cacheControl: cdn.cacheControl,
739
+ },
740
+ additionalPattern: cdn.additionalPattern,
741
+ logger: options.logger,
742
+ }));
743
+ }
706
744
  }
707
745
  }
708
746
  return plugins;
@@ -1,8 +1,10 @@
1
- import type * as webpack from 'webpack';
2
1
  type Pattern = RegExp | ((v: string) => boolean) | string;
3
2
  export interface NodeExternalsOptions {
4
3
  noExternal?: Pattern | Pattern[];
5
4
  module?: boolean;
6
5
  }
7
- export declare function nodeExternals({ noExternal, module }: NodeExternalsOptions): (data: webpack.ExternalItemFunctionData) => Promise<string | undefined>;
6
+ export declare function nodeExternals({ noExternal, module }: NodeExternalsOptions): (data: {
7
+ request?: string;
8
+ dependencyType?: string;
9
+ }) => Promise<string | undefined>;
8
10
  export {};
@@ -35,7 +35,7 @@ function nodeExternals({ noExternal = [], module }) {
35
35
  const noExternals = Array().concat(webpackInternal).concat(noExternal);
36
36
  const nodeModules = readPackagesNames(paths_1.default.appNodeModules);
37
37
  return async (data) => {
38
- const { request } = data;
38
+ const { request, dependencyType } = data;
39
39
  if (!request) {
40
40
  return undefined;
41
41
  }
@@ -46,14 +46,14 @@ function nodeExternals({ noExternal = [], module }) {
46
46
  return undefined;
47
47
  }
48
48
  if (!module) {
49
- return `commonjs ${data.request}`;
49
+ return `commonjs ${request}`;
50
50
  }
51
- if (data.dependencyType === 'commonjs' ||
51
+ if (dependencyType === 'commonjs' ||
52
52
  // lodash/something without extension can't be imported so always require it
53
53
  (moduleName === 'lodash' && request.match(/^lodash\/[\w_]+($|\/[\w_]+$)/))) {
54
- return `node-commonjs ${data.request}`;
54
+ return `node-commonjs ${request}`;
55
55
  }
56
- return `module-import ${data.request}`;
56
+ return `module-import ${request}`;
57
57
  };
58
58
  }
59
59
  function readPackagesNames(dirName) {
@@ -1,13 +1,12 @@
1
- import * as webpack from 'webpack';
1
+ import webpack from 'webpack';
2
+ import type * as Webpack from 'webpack';
2
3
  import type { Logger } from '../logger';
3
4
  export declare class ProgressPlugin extends webpack.ProgressPlugin {
4
5
  private _logger;
5
- private _bundler;
6
6
  private _state;
7
- constructor({ logger, bundler }: {
7
+ constructor({ logger }: {
8
8
  logger: Logger;
9
- bundler?: string;
10
9
  });
11
10
  handler: (percent: number, message: string, ...details: string[]) => void;
12
- apply(compiler: webpack.Compiler): void;
11
+ apply(compiler: Webpack.Compiler): void;
13
12
  }
@@ -1,39 +1,17 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
6
  exports.ProgressPlugin = void 0;
27
- const webpack = __importStar(require("webpack"));
7
+ const webpack_1 = __importDefault(require("webpack"));
28
8
  const pretty_time_1 = require("../logger/pretty-time");
29
- class ProgressPlugin extends webpack.ProgressPlugin {
9
+ class ProgressPlugin extends webpack_1.default.ProgressPlugin {
30
10
  _logger;
31
- _bundler;
32
11
  _state = {};
33
- constructor({ logger, bundler = 'webpack' }) {
12
+ constructor({ logger }) {
34
13
  super();
35
14
  this._logger = logger;
36
- this._bundler = bundler;
37
15
  }
38
16
  handler = (percent, message, ...details) => {
39
17
  const progress = Math.floor(percent * 100);
@@ -43,12 +21,12 @@ class ProgressPlugin extends webpack.ProgressPlugin {
43
21
  super.apply(compiler);
44
22
  hook(compiler, 'compile', () => {
45
23
  this._logger.message('Start compilation');
46
- // @ts-ignore
47
- const compilerVersipn = this._bundler === 'webpack'
48
- ? compiler.webpack.version
49
- : // @ts-ignore
50
- compiler.webpack.rspackVersion;
51
- this._logger.message(`${this._bundler} v${compilerVersipn}`);
24
+ if ('rspackVersion' in compiler.webpack) {
25
+ this._logger.message(`Rspack v${compiler.webpack.rspackVersion}`);
26
+ }
27
+ else {
28
+ this._logger.message(`Webpack v${compiler.webpack.version}`);
29
+ }
52
30
  this._state.start = process.hrtime.bigint();
53
31
  });
54
32
  hook(compiler, 'invalid', (fileName, changeTime) => {
@@ -11,7 +11,7 @@ export declare function configureWebpackConfigForStorybook(mode: Mode, userConfi
11
11
  resolve: Webpack.ResolveOptions;
12
12
  plugins: (false | "" | 0 | ((this: Webpack.Compiler, compiler: Webpack.Compiler) => void) | Webpack.WebpackPluginInstance | null | undefined)[];
13
13
  optimization: {
14
- minimizer: (false | "" | 0 | Webpack.WebpackPluginInstance | "..." | ((this: Webpack.Compiler, compiler: Webpack.Compiler) => void) | null | undefined)[] | undefined;
14
+ minimizer: (false | "" | 0 | "..." | Webpack.WebpackPluginInstance | ((this: Webpack.Compiler, compiler: Webpack.Compiler) => void) | null | undefined)[] | undefined;
15
15
  };
16
16
  }>;
17
17
  export {};