@gravity-ui/app-builder 0.14.2-beta.0 → 0.15.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.
Files changed (44) hide show
  1. package/dist/commands/build/build-service/client.js +1 -4
  2. package/dist/commands/dev/client.js +24 -8
  3. package/dist/common/config.js +8 -7
  4. package/dist/common/logger/colors.d.ts +1 -1
  5. package/dist/common/logger/index.d.ts +1 -1
  6. package/dist/common/models/index.d.ts +1 -0
  7. package/dist/common/s3-upload/webpack-plugin.d.ts +2 -2
  8. package/dist/common/s3-upload/webpack-plugin.js +2 -3
  9. package/dist/common/typescript/compile.js +7 -7
  10. package/dist/common/typescript/watch.js +6 -6
  11. package/dist/common/webpack/compile.d.ts +1 -1
  12. package/dist/common/webpack/compile.js +34 -10
  13. package/dist/common/webpack/config.d.ts +8 -3
  14. package/dist/common/webpack/config.js +373 -117
  15. package/dist/common/webpack/node-externals.d.ts +4 -2
  16. package/dist/common/webpack/node-externals.js +5 -5
  17. package/dist/common/webpack/progress-plugin.d.ts +4 -5
  18. package/dist/common/webpack/progress-plugin.js +11 -33
  19. package/dist/common/webpack/rspack.d.ts +7 -0
  20. package/dist/common/{rspack/utils.js → webpack/rspack.js} +57 -27
  21. package/dist/common/webpack/storybook.d.ts +1 -1
  22. package/dist/common/webpack/utils.d.ts +2 -2
  23. package/dist/common/webpack/utils.js +4 -2
  24. package/dist/common/webpack/worker/worker-loader.d.ts +2 -2
  25. package/dist/common/webpack/worker/worker-loader.js +17 -17
  26. package/dist/create-cli.d.ts +2 -2
  27. package/package.json +1 -3
  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/worker/public-path.worker.d.ts +0 -1
  40. package/dist/common/rspack/worker/public-path.worker.js +0 -3
  41. package/dist/common/rspack/worker/web-worker.d.mts +0 -8
  42. package/dist/common/rspack/worker/web-worker.mjs +0 -32
  43. package/dist/common/rspack/worker/worker-loader.d.ts +0 -4
  44. package/dist/common/rspack/worker/worker-loader.js +0 -177
@@ -1 +0,0 @@
1
- export function keepAlive(options: any): () => void;
@@ -1,63 +0,0 @@
1
- /* eslint-env browser */
2
- /* global __resourceQuery */
3
- 'use strict';
4
- if (typeof EventSource !== 'function') {
5
- throw new Error("Environment doesn't support lazy compilation (requires EventSource)");
6
- }
7
- const urlBase = new URL(decodeURIComponent(__resourceQuery.slice(1))).pathname;
8
- let activeEventSource;
9
- const activeKeys = new Map();
10
- const errorHandlers = new Set();
11
- const updateEventSource = function updateEventSource() {
12
- if (activeEventSource)
13
- activeEventSource.close();
14
- if (activeKeys.size) {
15
- activeEventSource = new EventSource('/build/lazy' + urlBase + Array.from(activeKeys.keys()).join('@'));
16
- activeEventSource.onerror = function (event) {
17
- errorHandlers.forEach(function (onError) {
18
- onError(new Error('Problem communicating active modules to the server: ' +
19
- event.message +
20
- ' ' +
21
- event.filename +
22
- ':' +
23
- event.lineno +
24
- ':' +
25
- event.colno +
26
- ' ' +
27
- event.error));
28
- });
29
- };
30
- }
31
- else {
32
- activeEventSource = undefined;
33
- }
34
- };
35
- exports.keepAlive = function (options) {
36
- const data = options.data;
37
- const onError = options.onError;
38
- const active = options.active;
39
- const module = options.module;
40
- errorHandlers.add(onError);
41
- const value = activeKeys.get(data) || 0;
42
- activeKeys.set(data, value + 1);
43
- if (value === 0) {
44
- updateEventSource();
45
- }
46
- if (!active && !module.hot) {
47
- // eslint-disable-next-line no-console
48
- console.log('Hot Module Replacement is not enabled. Waiting for process restart...');
49
- }
50
- return function () {
51
- errorHandlers.delete(onError);
52
- setTimeout(function () {
53
- const valueToReduce = activeKeys.get(data);
54
- if (valueToReduce === 1) {
55
- activeKeys.delete(data);
56
- updateEventSource();
57
- }
58
- else {
59
- activeKeys.set(data, valueToReduce - 1);
60
- }
61
- }, 1000);
62
- };
63
- };
@@ -1,11 +0,0 @@
1
- import { Compiler, rspack } from '@rspack/core';
2
- import type { Logger } from '../logger';
3
- export declare class ProgressPlugin extends rspack.ProgressPlugin {
4
- private _logger;
5
- private _state;
6
- constructor({ logger }: {
7
- logger: Logger;
8
- });
9
- handler: (percent: number, message: string, ...details: string[]) => void;
10
- apply(compiler: Compiler): void;
11
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProgressPlugin = void 0;
4
- const core_1 = require("@rspack/core");
5
- const pretty_time_1 = require("../logger/pretty-time");
6
- class ProgressPlugin extends core_1.rspack.ProgressPlugin {
7
- _logger;
8
- _state = {};
9
- constructor({ logger }) {
10
- super();
11
- this._logger = logger;
12
- }
13
- handler = (percent, message, ...details) => {
14
- const progress = Math.floor(percent * 100);
15
- this._logger.status(`${this._logger.colors.green(`${progress}%`)} - ${this._logger.colors.yellow(message)}${details.length > 0 ? `: ${this._logger.colors.dim(...details)}` : ''}`);
16
- };
17
- apply(compiler) {
18
- super.apply(compiler);
19
- hook(compiler, 'compile', () => {
20
- this._logger.message('Start compilation');
21
- this._logger.message(`rspack v${compiler.rspack.rspackVersion}`);
22
- this._state.start = process.hrtime.bigint();
23
- });
24
- hook(compiler, 'invalid', (fileName, changeTime) => {
25
- this._logger.verbose(`Invalidate file: ${fileName} at ${changeTime}`);
26
- });
27
- hook(compiler, 'done', (stats) => {
28
- const time = this._state.start ? ' in ' + (0, pretty_time_1.elapsedTime)(this._state.start) : '';
29
- const hasErrors = stats.hasErrors();
30
- if (hasErrors) {
31
- this._logger.error('Compiled with some errors' + time);
32
- }
33
- else {
34
- this._logger.success('Compiled successfully' + time);
35
- }
36
- });
37
- }
38
- }
39
- exports.ProgressPlugin = ProgressPlugin;
40
- function hook(compiler, hookName, callback) {
41
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
- compiler.hooks[hookName].tap(`app-builder: ${hookName}`, callback);
43
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // @ts-expect-error
4
- __webpack_public_path__ = globalThis.__PUBLIC_PATH__ ?? '/build/';
@@ -1,4 +0,0 @@
1
- import type { Configuration, MultiStats } from '@rspack/core';
2
- import type { Logger } from '../logger';
3
- export declare function clearCacheDirectory(config: Configuration, logger: Logger): void;
4
- export declare function rspackCompilerHandlerFactory(logger: Logger, onCompilationEnd?: () => void): (err?: Error | null, stats?: MultiStats) => Promise<void>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- __webpack_public_path__ = self.__PUBLIC_PATH__;
@@ -1,8 +0,0 @@
1
- import { SharedWorkerPolyfill } from '@okikio/sharedworker';
2
- declare class WebWorker extends Worker {
3
- constructor(url: string | URL, options?: WorkerOptions);
4
- }
5
- declare class SharedWebWorker extends SharedWorkerPolyfill {
6
- constructor(url: string | URL, options?: WorkerOptions);
7
- }
8
- export { WebWorker as Worker, SharedWebWorker as SharedWorker };
@@ -1,32 +0,0 @@
1
- import { SharedWorkerPolyfill } from '@okikio/sharedworker';
2
- class WebWorker extends Worker {
3
- constructor(url, options) {
4
- const objectURL = generateWorkerLoader(url);
5
- super(objectURL, options);
6
- URL.revokeObjectURL(objectURL);
7
- }
8
- }
9
- class SharedWebWorker extends SharedWorkerPolyfill {
10
- constructor(url, options) {
11
- const objectURL = generateWorkerLoader(url);
12
- super(objectURL, options);
13
- URL.revokeObjectURL(objectURL);
14
- }
15
- }
16
- export { WebWorker as Worker, SharedWebWorker as SharedWorker };
17
- function generateWorkerLoader(url) {
18
- // eslint-disable-next-line camelcase
19
- const publicPath = __webpack_public_path__;
20
- const workerPublicPath = publicPath.match(/^https?:\/\//)
21
- ? publicPath
22
- : new URL(publicPath, window.location.origin).toString();
23
- const objectURL = URL.createObjectURL(new Blob([
24
- [
25
- `self.__PUBLIC_PATH__ = ${JSON.stringify(workerPublicPath)}`,
26
- `importScripts(${JSON.stringify(url.toString())});`,
27
- ].join('\n'),
28
- ], {
29
- type: 'application/javascript',
30
- }));
31
- return objectURL;
32
- }
@@ -1,4 +0,0 @@
1
- import type { LoaderDefinition } from '@rspack/core';
2
- type PitchLoaderDefinitionFunction = Exclude<LoaderDefinition['pitch'], undefined>;
3
- export declare const pitch: PitchLoaderDefinitionFunction;
4
- export {};
@@ -1,177 +0,0 @@
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
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.pitch = void 0;
30
- const path = __importStar(require("node:path"));
31
- const paths_1 = __importDefault(require("../../paths"));
32
- const core_1 = require("@rspack/core");
33
- const pluginId = 'APP_BUILDER_WORKER_LOADER';
34
- const publicPath = path.resolve(__dirname, 'public-path.worker.js');
35
- const pitch = function (request) {
36
- this.cacheable(false);
37
- if (!this._compiler || !this._compilation) {
38
- throw new Error('Something went wrong');
39
- }
40
- const compilerOptions = this._compiler.options;
41
- const logger = this.getLogger(pluginId);
42
- if (compilerOptions.output.globalObject === 'window') {
43
- logger.warn('Warning (app-builder-worker-loader): output.globalObject is set to "window". It should be set to "self" or "this" to support HMR in Workers.');
44
- }
45
- const isEnvProduction = compilerOptions.mode === 'production';
46
- const filename = 'worker.js';
47
- const chunkFilename = isEnvProduction
48
- ? 'js/[name].[contenthash:8].worker.js'
49
- : 'js/[name].worker.js';
50
- const workerOptions = {
51
- filename,
52
- chunkFilename,
53
- publicPath: compilerOptions.output.publicPath,
54
- globalObject: 'self',
55
- devtoolNamespace: path.resolve('/', path.relative(paths_1.default.app, this.resource)),
56
- };
57
- const workerCompiler = this._compilation.createChildCompiler(`worker ${request}`, workerOptions, []);
58
- new core_1.webworker.WebWorkerTemplatePlugin().apply(workerCompiler);
59
- if (this.target !== 'webworker' && this.target !== 'web') {
60
- new core_1.node.NodeTargetPlugin().apply(workerCompiler);
61
- }
62
- /* TODO Unsupported
63
- new web.FetchCompileWasmPlugin({
64
- mangleImports: this._compiler.options.optimization.mangleWasmImports,
65
- }).apply(workerCompiler);
66
- */
67
- new core_1.web.FetchCompileAsyncWasmPlugin().apply(workerCompiler);
68
- const bundleName = path.parse(this.resourcePath).name;
69
- new core_1.EntryPlugin(this.context, `!!${publicPath}`, bundleName).apply(workerCompiler);
70
- new core_1.EntryPlugin(this.context, `!!${request}`, bundleName).apply(workerCompiler);
71
- configureSourceMap(workerCompiler);
72
- const cb = this.async();
73
- workerCompiler.compile((err, compilation) => {
74
- if (compilation) {
75
- workerCompiler.parentCompilation?.children.push(compilation);
76
- }
77
- if (err) {
78
- return cb(err);
79
- }
80
- if (!compilation) {
81
- return cb(new Error('Child compilation failed'));
82
- }
83
- if (compilation.errors && compilation.errors.length) {
84
- const errorDetails = compilation.errors
85
- .map((error) => {
86
- if (error instanceof Error) {
87
- return error.stack;
88
- }
89
- return error;
90
- })
91
- .join('\n');
92
- return cb(new Error('Child compilation failed:\n' + errorDetails));
93
- }
94
- const cache = workerCompiler.getCache(pluginId);
95
- const cacheIdent = request;
96
- const objectToHash = compilation.assets[filename];
97
- if (!objectToHash) {
98
- return cb(new Error(`Asset ${filename} not found in compilation`));
99
- }
100
- const cacheETag = cache.getLazyHashedEtag(objectToHash);
101
- return cache.get(cacheIdent, cacheETag, (getCacheError, cacheContent) => {
102
- if (getCacheError) {
103
- return cb(getCacheError);
104
- }
105
- if (cacheContent) {
106
- return cb(null, cacheContent.content, cacheContent.map);
107
- }
108
- let content = compilation.assets[filename]?.source().toString();
109
- const mapFile = `${filename}.map`;
110
- let map = compilation.assets[mapFile]?.source();
111
- if (map) {
112
- const sourceMap = JSON.parse(map.toString());
113
- if (Array.isArray(sourceMap.sources)) {
114
- sourceMap.sources = sourceMap.sources.map((pathname) => pathname.replace(/webpack:\/\/[^/]+\//, 'webpack://'));
115
- }
116
- map = JSON.stringify(sourceMap);
117
- }
118
- const licenseFile = `${filename}.LICENSE.txt`;
119
- const license = compilation.assets[licenseFile]?.source().toString();
120
- if (license && content) {
121
- if (content.startsWith('/*')) {
122
- content = content.replace(/^\/\*.*?\*\//, license);
123
- }
124
- }
125
- const parentCompilation = workerCompiler.parentCompilation;
126
- if (parentCompilation) {
127
- for (const [assetName, asset] of Object.entries(compilation.assets)) {
128
- if ([filename, mapFile, licenseFile].includes(assetName)) {
129
- continue;
130
- }
131
- if (parentCompilation.getAsset(assetName)) {
132
- continue;
133
- }
134
- parentCompilation.emitAsset(assetName, asset, compilation.getAsset(assetName)?.info);
135
- }
136
- }
137
- return cache.store(cacheIdent, cacheETag, { content, map: map?.toString() }, (storeCacheError) => {
138
- if (storeCacheError) {
139
- return cb(storeCacheError);
140
- }
141
- return cb(null, content, map?.toString());
142
- });
143
- });
144
- });
145
- };
146
- exports.pitch = pitch;
147
- function configureSourceMap(compiler) {
148
- const devtool = compiler.options.devtool;
149
- if (devtool) {
150
- if (devtool.includes('source-map')) {
151
- // remove parent SourceMapDevToolPlugin from compilation
152
- for (const hook of Object.values(compiler.hooks)) {
153
- for (let i = hook.taps.length - 1; i >= 0; i--) {
154
- const tap = hook.taps[i];
155
- if (tap?.name === 'SourceMapDevToolPlugin') {
156
- hook.taps.splice(i, 1);
157
- }
158
- }
159
- }
160
- const hidden = devtool.includes('hidden');
161
- const inline = devtool.includes('inline');
162
- const cheap = devtool.includes('cheap');
163
- const moduleMaps = devtool.includes('module');
164
- new core_1.rspack.SourceMapDevToolPlugin({
165
- filename: inline ? null : compiler.options.output.sourceMapFilename,
166
- moduleFilenameTemplate: compiler.options.output.devtoolModuleFilenameTemplate,
167
- fallbackModuleFilenameTemplate: compiler.options.output.devtoolFallbackModuleFilenameTemplate,
168
- append: hidden ? false : undefined,
169
- module: moduleMaps ? true : !cheap,
170
- columns: !cheap,
171
- noSources: false,
172
- namespace: (compiler.parentCompilation?.outputOptions.devtoolNamespace ?? '') +
173
- compiler.options.output.devtoolNamespace,
174
- }).apply(compiler);
175
- }
176
- }
177
- }