@gravity-ui/app-builder 0.24.0 → 0.24.1-beta.1

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.
@@ -95,9 +95,22 @@ async function buildDevServer(config) {
95
95
  }));
96
96
  }
97
97
  }
98
+ // Rspack multicompiler dont work with lazy compilation.
99
+ // Pass a single config to avoid multicompiler when SSR disabled.
100
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
101
+ const compiler = bundler === 'rspack'
102
+ ? (0, core_1.rspack)(isSsr ? rspackConfigs : rspackConfigs[0])
103
+ : (0, webpack_1.default)(webpackConfigs);
98
104
  const staticFolder = path.resolve(paths_1.default.appDist, 'public');
99
105
  const options = {
100
106
  static: staticFolder,
107
+ setupMiddlewares(middlewares) {
108
+ if (config.client.lazyCompilation && bundler === 'rspack') {
109
+ const lazyCompilationMiddleware = core_1.rspack.experiments.lazyCompilationMiddleware(compiler, rspackConfigs[0]?.experiments?.lazyCompilation);
110
+ return [lazyCompilationMiddleware, ...middlewares];
111
+ }
112
+ return middlewares;
113
+ },
101
114
  devMiddleware: {
102
115
  publicPath,
103
116
  stats: 'errors-warnings',
@@ -172,14 +185,9 @@ async function buildDevServer(config) {
172
185
  options.proxy = proxy;
173
186
  let server;
174
187
  if (bundler === 'rspack') {
175
- // Rspack multicompiler dont work with lazy compilation.
176
- // Pass a single config to avoid multicompiler when SSR disabled.
177
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
178
- const compiler = (0, core_1.rspack)(isSsr ? rspackConfigs : rspackConfigs[0]);
179
188
  server = new dev_server_1.RspackDevServer(options, compiler);
180
189
  }
181
190
  else {
182
- const compiler = (0, webpack_1.default)(webpackConfigs);
183
191
  server = new webpack_dev_server_1.default(options, compiler);
184
192
  }
185
193
  try {
@@ -57,7 +57,6 @@ const s3_upload_1 = require("../s3-upload");
57
57
  const log_config_1 = require("../logger/log-config");
58
58
  const utils_2 = require("../typescript/utils");
59
59
  const node_externals_1 = require("./node-externals");
60
- const statoscope_1 = require("./statoscope");
61
60
  const imagesSizeLimit = 2048;
62
61
  const fontSizeLimit = 8192;
63
62
  function getHelperOptions({ webpackMode, config, logger, isSsr = false, configPath, }) {
@@ -289,26 +288,14 @@ function configureRspackExperiments(options) {
289
288
  return undefined;
290
289
  }
291
290
  let lazyCompilation;
292
- let port;
293
291
  if (config.lazyCompilation) {
294
- if (typeof config.lazyCompilation === 'object') {
295
- port = config.lazyCompilation.port;
296
- }
297
292
  lazyCompilation = {
298
293
  // Lazy compilation works without problems only with lazy imports
299
294
  // See https://github.com/web-infra-dev/rspack/issues/8503
300
295
  entries: false,
301
296
  imports: true,
302
- backend: {
303
- client: require.resolve('./lazy-client.js'),
304
- ...(port
305
- ? {
306
- listen: {
307
- port,
308
- },
309
- }
310
- : {}),
311
- },
297
+ serverUrl: `http://localhost:${config.lazyCompilation.port}`,
298
+ client: require.resolve('./lazy-client.js'),
312
299
  test(module) {
313
300
  // make sure that lazy-client.js won't be lazy compiled)
314
301
  return !module.nameForCondition()?.endsWith('lazy-client.js');
@@ -936,7 +923,7 @@ function configureCommonPlugins(options, bundlerPlugins) {
936
923
  }
937
924
  if (config.analyzeBundle === 'statoscope') {
938
925
  const customStatoscopeConfig = config.statoscopeConfig || {};
939
- const statoscopePlugin = new webpack_plugin_1.default({
926
+ plugins.push(new webpack_plugin_1.default({
940
927
  saveReportTo: path.resolve(options.buildDirectory, 'report.html'),
941
928
  saveStatsTo: path.resolve(options.buildDirectory, 'stats.json'),
942
929
  open: false,
@@ -944,14 +931,7 @@ function configureCommonPlugins(options, bundlerPlugins) {
944
931
  all: true,
945
932
  },
946
933
  ...customStatoscopeConfig,
947
- });
948
- // TIP: statoscope doesn't support rspack, but this workaround helps to run it
949
- if (config.bundler === 'rspack') {
950
- const compressor = statoscopePlugin.options.compressor;
951
- statoscopePlugin.extensions =
952
- compressor === false ? [] : [new statoscope_1.RspackCompressedExtension(compressor)];
953
- }
954
- plugins.push(statoscopePlugin);
934
+ }));
955
935
  }
956
936
  if (config.analyzeBundle === 'rsdoctor') {
957
937
  plugins.push(new bundlerPlugins.RSDoctorPlugin({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/app-builder",
3
- "version": "0.24.0",
3
+ "version": "0.24.1-beta.1",
4
4
  "description": "Develop and build your React client-server projects, powered by typescript and webpack",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -70,15 +70,15 @@
70
70
  "@babel/runtime": "^7.26.0",
71
71
  "@okikio/sharedworker": "^1.0.7",
72
72
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
73
- "@rsdoctor/rspack-plugin": "^0.4.13",
74
- "@rsdoctor/webpack-plugin": "^0.4.13",
75
- "@rspack/core": "1.2.8",
76
- "@rspack/dev-server": "^1.0.10",
77
- "@rspack/plugin-react-refresh": "^1.0.1",
78
- "@statoscope/webpack-plugin": "^5.28.2",
73
+ "@rsdoctor/rspack-plugin": "^1.0.1",
74
+ "@rsdoctor/webpack-plugin": "^1.0.1",
75
+ "@rspack/core": "1.3.4",
76
+ "@rspack/dev-server": "^1.1.1",
77
+ "@rspack/plugin-react-refresh": "^1.2.0",
78
+ "@statoscope/webpack-plugin": "^5.29.0",
79
79
  "@statoscope/stats": "^5.28.1",
80
80
  "@statoscope/stats-extension-compressed": "^5.28.1",
81
- "@statoscope/webpack-model": "^5.28.3",
81
+ "@statoscope/webpack-model": "^5.29.0",
82
82
  "@svgr/core": "^8.1.0",
83
83
  "@svgr/plugin-jsx": "^8.1.0",
84
84
  "@svgr/webpack": "^8.1.0",
@@ -1,12 +0,0 @@
1
- import { Compiler } from 'webpack';
2
- import { ExtensionDescriptor } from '@statoscope/stats/spec/extension';
3
- import CompressedExtensionGenerator, { CompressorOrPreset, Format, Payload } from '@statoscope/stats-extension-compressed/dist/generator';
4
- import { StatsExtensionWebpackAdapter } from '@statoscope/webpack-model';
5
- export declare class RspackCompressedExtension implements StatsExtensionWebpackAdapter<Payload> {
6
- compressor: CompressorOrPreset;
7
- descriptor: ExtensionDescriptor;
8
- compressedExtensionGenerator: CompressedExtensionGenerator;
9
- constructor(compressor: CompressorOrPreset);
10
- getExtension(): Format;
11
- handleCompiler(compiler: Compiler): void;
12
- }
@@ -1,159 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RspackCompressedExtension = void 0;
7
- /* eslint-disable max-depth */
8
- /**
9
- * Adapted Statoscope extension @statoscope/webpack-stats-extension-compressed to support Rspack.
10
- * This workaround will be removed once the pull request is merged into Statoscope:
11
- * https://github.com/statoscope/statoscope/pull/239
12
- */
13
- const path_1 = __importDefault(require("path"));
14
- const util_1 = require("util");
15
- const generator_1 = __importDefault(require("@statoscope/stats-extension-compressed/dist/generator"));
16
- const name = '@statoscope/webpack-stats-extension-compressed';
17
- const version = 'app-builder-version';
18
- const pluginName = `${name}@${version}`;
19
- class RspackCompressedExtension {
20
- compressor;
21
- descriptor = { name, version };
22
- compressedExtensionGenerator = new generator_1.default(this.descriptor);
23
- // eslint-disable-next-line @typescript-eslint/parameter-properties
24
- constructor(compressor) {
25
- this.compressor = compressor;
26
- }
27
- getExtension() {
28
- return this.compressedExtensionGenerator.get();
29
- }
30
- handleCompiler(compiler) {
31
- const isRspack = 'rspackVersion' in compiler.webpack;
32
- const rspackCodeGenerationResults = new Map();
33
- if (isRspack) {
34
- compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
35
- rspackCodeGenerationResults.clear();
36
- compilation.hooks.executeModule.tap(pluginName, ({ moduleObject, codeGenerationResult }) => {
37
- if (!moduleObject) {
38
- return;
39
- }
40
- rspackCodeGenerationResults.set(moduleObject.id, codeGenerationResult);
41
- });
42
- });
43
- }
44
- compiler.hooks.done.tapAsync(pluginName, async (stats, cb) => {
45
- const stack = [stats.compilation];
46
- let cursor;
47
- while ((cursor = stack.pop())) {
48
- stack.push(...cursor.children);
49
- // webpack 4
50
- let readFile = (0, util_1.promisify)(cursor.compiler.inputFileSystem.readFile.bind(cursor.compiler.inputFileSystem));
51
- // webpack 5
52
- if (cursor.compiler.outputFileSystem &&
53
- typeof cursor.compiler.outputFileSystem.readFile === 'function') {
54
- readFile = (0, util_1.promisify)(cursor.compiler.outputFileSystem.readFile.bind(cursor.compiler.outputFileSystem));
55
- }
56
- for (const name of Object.keys(cursor.assets)) {
57
- const assetPath = path_1.default.join(cursor.compiler.outputPath, name);
58
- let content;
59
- try {
60
- content = await readFile(assetPath);
61
- if (!content) {
62
- throw new Error();
63
- }
64
- this.compressedExtensionGenerator.handleResource(cursor.hash, name, content, this.compressor);
65
- }
66
- catch (e) {
67
- console.warn(`Can't read the asset ${name}`);
68
- }
69
- }
70
- const modulesStack = [...cursor.modules];
71
- let modulesCursor;
72
- while ((modulesCursor = modulesStack.pop())) {
73
- // @ts-ignore
74
- if (modulesCursor.modules) {
75
- // @ts-ignore
76
- modulesStack.push(...modulesCursor.modules);
77
- }
78
- let concatenated = Buffer.from('');
79
- if (modulesCursor.constructor.name === 'CssModule' &&
80
- // @ts-ignore
81
- (typeof modulesCursor.content === 'string' ||
82
- // @ts-ignore
83
- modulesCursor.content instanceof Buffer)) {
84
- this.compressedExtensionGenerator.handleResource(cursor.hash, modulesCursor.identifier(),
85
- // @ts-ignore
86
- modulesCursor.content, this.compressor);
87
- }
88
- else if (cursor.chunkGraph) {
89
- // webpack 5 and rspack
90
- if (isRspack) {
91
- // Identifier contains source type and path, but keys in rspackCodeGenerationResults don't contain the source type.
92
- const id = modulesCursor.identifier().split('|')[1];
93
- if (!id) {
94
- continue;
95
- }
96
- const codeGenerationResult = rspackCodeGenerationResults.get(id);
97
- if (!codeGenerationResult || !('get' in codeGenerationResult)) {
98
- continue;
99
- }
100
- // @ts-ignore
101
- const content = codeGenerationResult.get('javascript');
102
- if (content) {
103
- concatenated = Buffer.concat([
104
- // @ts-ignore
105
- concatenated,
106
- // @ts-ignore
107
- content instanceof Buffer ? content : Buffer.from(content),
108
- ]);
109
- }
110
- }
111
- else {
112
- for (const type of modulesCursor.getSourceTypes()) {
113
- const runtimeChunk = cursor.chunkGraph
114
- .getModuleChunks(modulesCursor)
115
- .find((chunk) => chunk.runtime);
116
- if (runtimeChunk) {
117
- const source = cursor.codeGenerationResults.getSource(modulesCursor, runtimeChunk.runtime, type);
118
- if (!source) {
119
- continue;
120
- }
121
- const content = source.source();
122
- concatenated = Buffer.concat([
123
- // @ts-ignore
124
- concatenated,
125
- // @ts-ignore
126
- content instanceof Buffer ? content : Buffer.from(content),
127
- ]);
128
- }
129
- }
130
- }
131
- }
132
- else {
133
- // webpack 4
134
- try {
135
- // @ts-ignore
136
- const source = cursor.moduleTemplates.javascript.render(modulesCursor, cursor.dependencyTemplates, { chunk: modulesCursor.getChunks()[0] });
137
- const content = source.source();
138
- concatenated = Buffer.concat([
139
- // @ts-ignore
140
- concatenated,
141
- // @ts-ignore
142
- content instanceof Buffer ? content : Buffer.from(content),
143
- ]);
144
- }
145
- catch (e) {
146
- // in webpack 4 we can't generate source for all the modules :(
147
- }
148
- }
149
- if (!concatenated.length) {
150
- continue;
151
- }
152
- this.compressedExtensionGenerator.handleResource(cursor.hash, modulesCursor.identifier(), concatenated, this.compressor);
153
- }
154
- }
155
- cb();
156
- });
157
- }
158
- }
159
- exports.RspackCompressedExtension = RspackCompressedExtension;