arui-scripts 20.0.0 → 20.2.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.
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CustomCompressionPlugin = void 0;
16
+ const crypto_1 = __importDefault(require("crypto"));
17
+ const serialize_javascript_1 = __importDefault(require("serialize-javascript"));
18
+ /*
19
+ Based on compression-webpack-plugin, https://github.com/webpack-contrib/compression-webpack-plugin/tree/master
20
+ MIT License http://www.opensource.org/licenses/mit-license.php
21
+ Author Tobias Koppers @sokra
22
+ */
23
+ class CustomCompressionPlugin {
24
+ constructor(options) {
25
+ this.options = options;
26
+ }
27
+ runCompressionAlgorithm(input, filename) {
28
+ return this.options.algorithm(input, { filename });
29
+ }
30
+ compress(compiler, compilation, assets) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const cache = compilation.getCache('BrCompressionWebpackPlugin');
33
+ const assetsForCompression = (yield Promise.all(Object.keys(assets).map((name) => __awaiter(this, void 0, void 0, function* () {
34
+ const asset = compilation.getAsset(name);
35
+ if (!asset || asset.info.compressed) {
36
+ return false;
37
+ }
38
+ if (!compiler.webpack.ModuleFilenameHelpers.matchObject.bind(undefined, this.options)(name)) {
39
+ return false;
40
+ }
41
+ const relatedName = `compression-function-${crypto_1.default
42
+ .createHash('md5')
43
+ .update((0, serialize_javascript_1.default)(this.options.filename))
44
+ .digest('hex')}`;
45
+ if (asset.info.related && asset.info.related[relatedName]) {
46
+ return false;
47
+ }
48
+ const cacheItem = cache.getItemCache((0, serialize_javascript_1.default)({
49
+ name,
50
+ algorithm: this.options.algorithm,
51
+ }), cache.getLazyHashedEtag(asset.source));
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ const output = ((yield cacheItem.getPromise()) || {});
54
+ let buffer;
55
+ // No need original buffer for cached files
56
+ if (!output.source) {
57
+ if (typeof asset.source.buffer === 'function') {
58
+ buffer = asset.source.buffer();
59
+ }
60
+ // Compatibility with webpack plugins which don't use `webpack-sources`
61
+ // See https://github.com/webpack-contrib/compression-webpack-plugin/issues/236
62
+ else {
63
+ buffer = asset.source.source();
64
+ if (!Buffer.isBuffer(buffer)) {
65
+ buffer = Buffer.from(buffer);
66
+ }
67
+ }
68
+ if (buffer.length < this.options.threshold) {
69
+ return false;
70
+ }
71
+ }
72
+ return { name, source: asset.source, info: asset.info, buffer, output, cacheItem, relatedName };
73
+ })))).filter(Boolean);
74
+ const { RawSource } = compiler.webpack.sources;
75
+ const scheduledTasks = [];
76
+ for (const asset of assetsForCompression) {
77
+ scheduledTasks.push((() => __awaiter(this, void 0, void 0, function* () {
78
+ if (!asset || !asset.buffer) {
79
+ return;
80
+ }
81
+ const { name, source, buffer, output, cacheItem, relatedName } = asset;
82
+ if (!output.source) {
83
+ if (!output.compressed) {
84
+ try {
85
+ output.compressed = yield this.runCompressionAlgorithm(buffer, name);
86
+ }
87
+ catch (error) {
88
+ compilation.errors.push(error);
89
+ return;
90
+ }
91
+ }
92
+ if (output.compressed.length / buffer.length >
93
+ this.options.minRatio) {
94
+ yield cacheItem.storePromise({ compressed: output.compressed });
95
+ return;
96
+ }
97
+ output.source = new RawSource(output.compressed);
98
+ yield cacheItem.storePromise(output);
99
+ }
100
+ const newFilename = compilation.getPath(this.options.filename({ filename: name }));
101
+ const newInfo = { compressed: true };
102
+ compilation.updateAsset(name, source, {
103
+ related: { [relatedName]: newFilename },
104
+ });
105
+ compilation.emitAsset(newFilename, output.source, newInfo);
106
+ }))());
107
+ }
108
+ yield Promise.all(scheduledTasks);
109
+ });
110
+ }
111
+ apply(compiler) {
112
+ const pluginName = this.constructor.name;
113
+ compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
114
+ compilation.hooks.processAssets.tapPromise({
115
+ name: pluginName,
116
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER,
117
+ // additionalAssets: true,
118
+ }, (assets) => this.compress(compiler, compilation, assets));
119
+ });
120
+ }
121
+ }
122
+ exports.CustomCompressionPlugin = CustomCompressionPlugin;
@@ -1,4 +1,4 @@
1
- import { Cluster } from 'cluster';
1
+ import { Worker } from 'cluster';
2
2
  import { ReactRefreshPluginOptions } from '@pmmmwh/react-refresh-webpack-plugin/types/lib/types';
3
3
  import { type CssExtractRspackPluginOptions, Configuration, DefinePlugin, NormalModuleReplacementPlugin } from '@rspack/core';
4
4
  import { BannerPluginOptions } from '@rspack/core/dist/builtin-plugin/BannerPlugin';
@@ -62,7 +62,7 @@ type PluginsListServer = {
62
62
  };
63
63
  ReloadServerPlugin: {
64
64
  done: (...props: unknown[]) => unknown | null;
65
- workers: Array<Cluster['Worker']>;
65
+ workers: Worker[];
66
66
  };
67
67
  CaseSensitivePathsPlugin: {
68
68
  options: CaseSensitivePathsPlugin.Options;
@@ -1,4 +1,6 @@
1
- export declare function tryResolve(...args: Parameters<typeof require.resolve>): string | undefined;
1
+ export declare function tryResolve(...args: [id: string, options?: {
2
+ paths?: string[] | undefined;
3
+ }]): string | undefined;
2
4
  /**
3
5
  * Возвращает полный путь до модуля из node_modules относительно базового пути.
4
6
  * Может быть полезно для определения пути до модуля, когда в проекте установлено сразу несколько модулей.
@@ -1,10 +1,34 @@
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;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
29
  exports.createClientWebpackConfig = exports.createSingleClientWebpackConfig = void 0;
7
30
  const path_1 = __importDefault(require("path"));
31
+ const zlib = __importStar(require("zlib"));
8
32
  const getCSSModuleLocalIdent_1 = __importDefault(require("react-dev-utils/getCSSModuleLocalIdent"));
9
33
  const react_refresh_typescript_1 = __importDefault(require("react-refresh-typescript"));
10
34
  const core_1 = require("@rspack/core");
@@ -15,7 +39,6 @@ const compression_webpack_plugin_1 = __importDefault(require("compression-webpac
15
39
  const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
16
40
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
17
41
  const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
18
- const mini_svg_data_uri_1 = __importDefault(require("mini-svg-data-uri"));
19
42
  const rspack_manifest_plugin_1 = require("rspack-manifest-plugin");
20
43
  const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
21
44
  const webpack_deduplication_plugin_1 = require("webpack-deduplication-plugin");
@@ -23,6 +46,7 @@ const arui_runtime_1 = require("../plugins/arui-runtime");
23
46
  const html_template_1 = require("../templates/html.template");
24
47
  const minimizers_1 = require("./config-extras/minimizers");
25
48
  const check_node_version_1 = require("./util/check-node-version");
49
+ const compression_plugins_for_dictionaries_1 = require("./util/compression-plugins-for-dictionaries");
26
50
  const get_entry_1 = require("./util/get-entry");
27
51
  const app_configs_1 = require("./app-configs");
28
52
  const babel_client_1 = require("./babel-client");
@@ -221,9 +245,6 @@ const createSingleClientWebpackConfig = (mode, entry, configName) => (Object.ass
221
245
  {
222
246
  test: /\.svg/,
223
247
  type: 'asset',
224
- generator: {
225
- dataUrl: (file) => (0, mini_svg_data_uri_1.default)(file.content.toString()),
226
- },
227
248
  parser: {
228
249
  dataUrlCondition: {
229
250
  maxSize: app_configs_1.configs.dataUrlMaxSize,
@@ -300,6 +321,9 @@ const createSingleClientWebpackConfig = (mode, entry, configName) => (Object.ass
300
321
  filename: '../index.html',
301
322
  }),
302
323
  mode === 'dev' && app_configs_1.configs.clientOnly && new client_env_config_1.ClientConfigPlugin(),
324
+ app_configs_1.configs.compressionPredefinedDictionaryPath && new core_1.CopyRspackPlugin({
325
+ patterns: app_configs_1.configs.compressionPredefinedDictionaryPath
326
+ }),
303
327
  // production plugins:
304
328
  mode === 'prod' && new rspack_manifest_plugin_1.RspackManifestPlugin({}),
305
329
  mode === 'prod' &&
@@ -315,9 +339,11 @@ const createSingleClientWebpackConfig = (mode, entry, configName) => (Object.ass
315
339
  new compression_webpack_plugin_1.default({
316
340
  filename: '[file].br',
317
341
  algorithm: 'brotliCompress',
318
- test: /\.(js|css|html|svg)$/,
342
+ test: /\.(js|css|html|svg|dict)$/,
319
343
  compressionOptions: {
320
- level: 11,
344
+ params: {
345
+ [zlib.constants.BROTLI_PARAM_QUALITY]: 11
346
+ },
321
347
  },
322
348
  threshold: 10240,
323
349
  minRatio: 0.8,
@@ -330,7 +356,9 @@ const createSingleClientWebpackConfig = (mode, entry, configName) => (Object.ass
330
356
  mode === 'prod' &&
331
357
  !app_configs_1.configs.keepPropTypes &&
332
358
  new core_1.NormalModuleReplacementPlugin(/^thrift-services\/proptypes/, noopPath),
333
- ].filter(Boolean),
359
+ ].concat([
360
+ ...(mode === 'prod' ? (0, compression_plugins_for_dictionaries_1.compressionPluginsForDictionaries)() : [])
361
+ ]).filter(Boolean),
334
362
  // Без этого комиляция трирегилась на изменение в node_modules и приводила к утечке памяти
335
363
  watchOptions: {
336
364
  ignored: new RegExp(app_configs_1.configs.watchIgnorePath.join('|')),
@@ -366,7 +394,7 @@ function getCodeLoader(mode) {
366
394
  test: /\.(js|jsx|mjs|ts|tsx|cjs)$/,
367
395
  include: app_configs_1.configs.appSrc,
368
396
  loader: 'builtin:swc-loader',
369
- options: Object.assign(Object.assign({ cacheDirectory: mode === 'dev', cacheCompression: false }, swc_1.swcClientConfig), { jsc: Object.assign(Object.assign({}, swc_1.swcClientConfig.jsc), { transform: Object.assign(Object.assign({}, (_a = swc_1.swcClientConfig.jsc) === null || _a === void 0 ? void 0 : _a.transform), { react: Object.assign(Object.assign({}, (_c = (_b = swc_1.swcClientConfig.jsc) === null || _b === void 0 ? void 0 : _b.transform) === null || _c === void 0 ? void 0 : _c.react), { refresh: mode === 'dev' }) }) }) }),
397
+ options: Object.assign(Object.assign({}, swc_1.swcClientConfig), { jsc: Object.assign(Object.assign({}, swc_1.swcClientConfig.jsc), { transform: Object.assign(Object.assign({}, (_a = swc_1.swcClientConfig.jsc) === null || _a === void 0 ? void 0 : _a.transform), { react: Object.assign(Object.assign({}, (_c = (_b = swc_1.swcClientConfig.jsc) === null || _b === void 0 ? void 0 : _b.transform) === null || _c === void 0 ? void 0 : _c.react), { refresh: mode === 'dev' }) }) }) }),
370
398
  };
371
399
  }
372
400
  return {
@@ -9,7 +9,6 @@ const path_1 = __importDefault(require("path"));
9
9
  const getCSSModuleLocalIdent_1 = __importDefault(require("react-dev-utils/getCSSModuleLocalIdent"));
10
10
  const core_1 = require("@rspack/core");
11
11
  const case_sensitive_paths_webpack_plugin_1 = __importDefault(require("case-sensitive-paths-webpack-plugin"));
12
- const mini_svg_data_uri_1 = __importDefault(require("mini-svg-data-uri"));
13
12
  const run_script_webpack_plugin_1 = require("run-script-webpack-plugin");
14
13
  const webpack_node_externals_1 = __importDefault(require("webpack-node-externals"));
15
14
  const reload_server_plugin_1 = require("../plugins/reload-server-plugin");
@@ -126,10 +125,6 @@ const createServerConfig = (mode) => ({
126
125
  {
127
126
  test: /\.svg/,
128
127
  type: 'asset',
129
- generator: {
130
- dataUrl: (file) => (0, mini_svg_data_uri_1.default)(file.content.toString()),
131
- publicPath: '',
132
- },
133
128
  parser: {
134
129
  dataUrlCondition: {
135
130
  maxSize: app_configs_1.configs.dataUrlMaxSize,
@@ -1,7 +1,7 @@
1
- import cluster from 'cluster';
1
+ import { Worker } from 'cluster';
2
2
  import { type Compiler } from 'webpack';
3
3
  export declare class ReloadServerPlugin {
4
- workers: cluster.Worker[];
4
+ workers: Worker[];
5
5
  done: null | (() => void);
6
6
  constructor({ script }?: {
7
7
  script: string;
@@ -30,7 +30,9 @@ class ReloadServerPlugin {
30
30
  this.done = callback;
31
31
  this.workers.forEach((worker) => {
32
32
  try {
33
- process.kill(worker.process.pid, 'SIGTERM');
33
+ if (worker.process.pid) {
34
+ process.kill(worker.process.pid, 'SIGTERM');
35
+ }
34
36
  }
35
37
  catch (e) {
36
38
  console.warn(`Unable to kill process #${worker.process.pid}`);
@@ -8,6 +8,7 @@ const nginxTemplate = `client_max_body_size 20m;
8
8
  server {
9
9
  listen ${app_configs_1.configs.clientServerPort};
10
10
  server_tokens off;
11
+ ${app_configs_1.configs.dictionaryCompression.enablePreviousVersionHeaders ? 'brotli_auto_dictionary on;' : ''}
11
12
 
12
13
  ${app_configs_1.configs.clientOnly
13
14
  ? `location / {