@gravity-ui/app-builder 0.14.1 → 0.14.2-beta.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.
- package/dist/commands/build/build-service/client.js +4 -1
- package/dist/commands/dev/client.d.ts +2 -1
- package/dist/commands/dev/client.js +57 -24
- package/dist/common/config.js +2 -0
- package/dist/common/library/index.js +1 -0
- package/dist/common/logger/colors.d.ts +1 -1
- package/dist/common/logger/index.d.ts +1 -1
- package/dist/common/models/index.d.ts +13 -0
- package/dist/common/rspack/compile.d.ts +2 -0
- package/dist/common/rspack/compile.js +27 -0
- package/dist/common/rspack/config.d.ts +24 -0
- package/dist/common/rspack/config.js +772 -0
- package/dist/common/rspack/lazy-client.d.ts +1 -0
- package/dist/common/rspack/lazy-client.js +63 -0
- package/dist/common/rspack/progress-plugin.d.ts +11 -0
- package/dist/common/rspack/progress-plugin.js +43 -0
- package/dist/common/rspack/public-path.d.ts +1 -0
- package/dist/common/rspack/public-path.js +4 -0
- package/dist/common/rspack/utils.d.ts +4 -0
- package/dist/common/rspack/utils.js +81 -0
- package/dist/common/rspack/worker/public-path.worker.d.ts +1 -0
- package/dist/common/rspack/worker/public-path.worker.js +3 -0
- package/dist/common/rspack/worker/web-worker.d.mts +8 -0
- package/dist/common/rspack/worker/web-worker.mjs +32 -0
- package/dist/common/rspack/worker/worker-loader.d.ts +4 -0
- package/dist/common/rspack/worker/worker-loader.js +177 -0
- package/dist/common/s3-upload/create-plugin.d.ts +3 -0
- package/dist/common/s3-upload/create-plugin.js +47 -0
- package/dist/common/s3-upload/index.d.ts +1 -0
- package/dist/common/s3-upload/index.js +3 -1
- package/dist/common/webpack/config.js +1 -40
- package/dist/common/webpack/progress-plugin.d.ts +3 -1
- package/dist/common/webpack/progress-plugin.js +9 -2
- package/dist/common/webpack/storybook.d.ts +1 -1
- package/package.json +7 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function keepAlive(options: any): () => void;
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
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>;
|
|
@@ -0,0 +1,81 @@
|
|
|
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.clearCacheDirectory = clearCacheDirectory;
|
|
30
|
+
exports.rspackCompilerHandlerFactory = rspackCompilerHandlerFactory;
|
|
31
|
+
const pretty_time_1 = require("../logger/pretty-time");
|
|
32
|
+
const fs = __importStar(require("node:fs"));
|
|
33
|
+
const path = __importStar(require("node:path"));
|
|
34
|
+
const paths_1 = __importDefault(require("../../common/paths"));
|
|
35
|
+
function clearCacheDirectory(config, logger) {
|
|
36
|
+
if (!config.cache) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
let cacheDirectory = path.join(paths_1.default.appNodeModules, '.cache/rspack');
|
|
40
|
+
if (typeof config.experiments?.cache === 'object' &&
|
|
41
|
+
config.experiments.cache.type === 'persistent' &&
|
|
42
|
+
config.experiments.cache.storage?.directory) {
|
|
43
|
+
cacheDirectory = config.experiments.cache.storage?.directory;
|
|
44
|
+
}
|
|
45
|
+
if (fs.existsSync(cacheDirectory)) {
|
|
46
|
+
fs.rmdirSync(cacheDirectory, { recursive: true });
|
|
47
|
+
logger.message(`Rspack cache ${cacheDirectory} successfully cleared`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function rspackCompilerHandlerFactory(logger, onCompilationEnd) {
|
|
51
|
+
return async (err, stats) => {
|
|
52
|
+
if (err) {
|
|
53
|
+
logger.panic(err.message, err);
|
|
54
|
+
}
|
|
55
|
+
if (stats) {
|
|
56
|
+
logger.message('Stats:\n' +
|
|
57
|
+
stats.toString({
|
|
58
|
+
preset: 'errors-warnings',
|
|
59
|
+
colors: process.stdout.isTTY,
|
|
60
|
+
assets: logger.isVerbose,
|
|
61
|
+
modules: logger.isVerbose,
|
|
62
|
+
entrypoints: logger.isVerbose,
|
|
63
|
+
timings: logger.isVerbose,
|
|
64
|
+
}));
|
|
65
|
+
if (stats.hasErrors()) {
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (onCompilationEnd) {
|
|
70
|
+
await onCompilationEnd();
|
|
71
|
+
}
|
|
72
|
+
const [clientStats] = stats?.stats ?? [];
|
|
73
|
+
if (clientStats) {
|
|
74
|
+
const time = (clientStats.endTime || 0) - (clientStats.startTime || 0);
|
|
75
|
+
logger.success(`Client was successfully compiled in ${(0, pretty_time_1.prettyTime)(BigInt(time) * BigInt(1_000_000))}`);
|
|
76
|
+
}
|
|
77
|
+
if (!clientStats) {
|
|
78
|
+
logger.success(`Client was successfully compiled`);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
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 };
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { NormalizedClientConfig } from '../models';
|
|
2
|
+
import type { Logger } from '../logger';
|
|
3
|
+
export declare function createS3UploadPlugins(config: NormalizedClientConfig, logger?: Logger): (false | "" | 0 | ((this: import("webpack").Compiler, compiler: import("webpack").Compiler) => void) | import("webpack").WebpackPluginInstance | null)[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createS3UploadPlugins = createS3UploadPlugins;
|
|
4
|
+
const webpack_plugin_1 = require("./webpack-plugin");
|
|
5
|
+
function createS3UploadPlugins(config, logger) {
|
|
6
|
+
const plugins = [];
|
|
7
|
+
let credentialsGlobal;
|
|
8
|
+
if (process.env.FRONTEND_S3_ACCESS_KEY_ID && process.env.FRONTEND_S3_SECRET_ACCESS_KEY) {
|
|
9
|
+
credentialsGlobal = {
|
|
10
|
+
accessKeyId: process.env.FRONTEND_S3_ACCESS_KEY_ID,
|
|
11
|
+
secretAccessKey: process.env.FRONTEND_S3_SECRET_ACCESS_KEY,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const cdns = Array.isArray(config.cdn) ? config.cdn : [config.cdn];
|
|
15
|
+
for (let index = 0; index < cdns.length; index++) {
|
|
16
|
+
const cdn = cdns[index];
|
|
17
|
+
if (!cdn) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
let credentials = credentialsGlobal;
|
|
21
|
+
const accessKeyId = process.env[`FRONTEND_S3_ACCESS_KEY_ID_${index}`];
|
|
22
|
+
const secretAccessKey = process.env[`FRONTEND_S3_SECRET_ACCESS_KEY_${index}`];
|
|
23
|
+
if (accessKeyId && secretAccessKey) {
|
|
24
|
+
credentials = {
|
|
25
|
+
accessKeyId,
|
|
26
|
+
secretAccessKey,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
plugins.push(new webpack_plugin_1.S3UploadPlugin({
|
|
30
|
+
exclude: config.hiddenSourceMap ? /\.map$/ : undefined,
|
|
31
|
+
compress: cdn.compress,
|
|
32
|
+
s3ClientOptions: {
|
|
33
|
+
region: cdn.region,
|
|
34
|
+
endpoint: cdn.endpoint,
|
|
35
|
+
credentials,
|
|
36
|
+
},
|
|
37
|
+
s3UploadOptions: {
|
|
38
|
+
bucket: cdn.bucket,
|
|
39
|
+
targetPath: cdn.prefix,
|
|
40
|
+
cacheControl: cdn.cacheControl,
|
|
41
|
+
},
|
|
42
|
+
additionalPattern: cdn.additionalPattern,
|
|
43
|
+
logger,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
return plugins;
|
|
47
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uploadFiles = exports.S3UploadPlugin = void 0;
|
|
3
|
+
exports.createS3UploadPlugins = 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; } });
|
|
@@ -702,46 +702,7 @@ function configurePlugins(options) {
|
|
|
702
702
|
}
|
|
703
703
|
}
|
|
704
704
|
if (config.cdn) {
|
|
705
|
-
|
|
706
|
-
if (process.env.FRONTEND_S3_ACCESS_KEY_ID &&
|
|
707
|
-
process.env.FRONTEND_S3_SECRET_ACCESS_KEY) {
|
|
708
|
-
credentialsGlobal = {
|
|
709
|
-
accessKeyId: process.env.FRONTEND_S3_ACCESS_KEY_ID,
|
|
710
|
-
secretAccessKey: process.env.FRONTEND_S3_SECRET_ACCESS_KEY,
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
const cdns = Array.isArray(config.cdn) ? config.cdn : [config.cdn];
|
|
714
|
-
for (let index = 0; index < cdns.length; index++) {
|
|
715
|
-
const cdn = cdns[index];
|
|
716
|
-
if (!cdn) {
|
|
717
|
-
continue;
|
|
718
|
-
}
|
|
719
|
-
let credentials = credentialsGlobal;
|
|
720
|
-
const accessKeyId = process.env[`FRONTEND_S3_ACCESS_KEY_ID_${index}`];
|
|
721
|
-
const secretAccessKey = process.env[`FRONTEND_S3_SECRET_ACCESS_KEY_${index}`];
|
|
722
|
-
if (accessKeyId && secretAccessKey) {
|
|
723
|
-
credentials = {
|
|
724
|
-
accessKeyId,
|
|
725
|
-
secretAccessKey,
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
plugins.push(new s3_upload_1.S3UploadPlugin({
|
|
729
|
-
exclude: config.hiddenSourceMap ? /\.map$/ : undefined,
|
|
730
|
-
compress: cdn.compress,
|
|
731
|
-
s3ClientOptions: {
|
|
732
|
-
region: cdn.region,
|
|
733
|
-
endpoint: cdn.endpoint,
|
|
734
|
-
credentials,
|
|
735
|
-
},
|
|
736
|
-
s3UploadOptions: {
|
|
737
|
-
bucket: cdn.bucket,
|
|
738
|
-
targetPath: cdn.prefix,
|
|
739
|
-
cacheControl: cdn.cacheControl,
|
|
740
|
-
},
|
|
741
|
-
additionalPattern: cdn.additionalPattern,
|
|
742
|
-
logger: options.logger,
|
|
743
|
-
}));
|
|
744
|
-
}
|
|
705
|
+
plugins.push(...(0, s3_upload_1.createS3UploadPlugins)(config, options.logger));
|
|
745
706
|
}
|
|
746
707
|
}
|
|
747
708
|
return plugins;
|
|
@@ -2,9 +2,11 @@ import * as webpack from 'webpack';
|
|
|
2
2
|
import type { Logger } from '../logger';
|
|
3
3
|
export declare class ProgressPlugin extends webpack.ProgressPlugin {
|
|
4
4
|
private _logger;
|
|
5
|
+
private _bundler;
|
|
5
6
|
private _state;
|
|
6
|
-
constructor({ logger }: {
|
|
7
|
+
constructor({ logger, bundler }: {
|
|
7
8
|
logger: Logger;
|
|
9
|
+
bundler?: string;
|
|
8
10
|
});
|
|
9
11
|
handler: (percent: number, message: string, ...details: string[]) => void;
|
|
10
12
|
apply(compiler: webpack.Compiler): void;
|
|
@@ -28,10 +28,12 @@ const webpack = __importStar(require("webpack"));
|
|
|
28
28
|
const pretty_time_1 = require("../logger/pretty-time");
|
|
29
29
|
class ProgressPlugin extends webpack.ProgressPlugin {
|
|
30
30
|
_logger;
|
|
31
|
+
_bundler;
|
|
31
32
|
_state = {};
|
|
32
|
-
constructor({ logger }) {
|
|
33
|
+
constructor({ logger, bundler = 'webpack' }) {
|
|
33
34
|
super();
|
|
34
35
|
this._logger = logger;
|
|
36
|
+
this._bundler = bundler;
|
|
35
37
|
}
|
|
36
38
|
handler = (percent, message, ...details) => {
|
|
37
39
|
const progress = Math.floor(percent * 100);
|
|
@@ -41,7 +43,12 @@ class ProgressPlugin extends webpack.ProgressPlugin {
|
|
|
41
43
|
super.apply(compiler);
|
|
42
44
|
hook(compiler, 'compile', () => {
|
|
43
45
|
this._logger.message('Start compilation');
|
|
44
|
-
|
|
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}`);
|
|
45
52
|
this._state.start = process.hrtime.bigint();
|
|
46
53
|
});
|
|
47
54
|
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 | "..." |
|
|
14
|
+
minimizer: (false | "" | 0 | Webpack.WebpackPluginInstance | "..." | ((this: Webpack.Compiler, compiler: Webpack.Compiler) => void) | null | undefined)[] | undefined;
|
|
15
15
|
};
|
|
16
16
|
}>;
|
|
17
17
|
export {};
|