@gravity-ui/app-builder 0.12.0 → 0.12.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.
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import WebpackDevServer from 'webpack-dev-server';
|
|
2
2
|
import type { NormalizedServiceConfig } from '../../common/models';
|
|
3
|
-
export declare function watchClientCompilation(config: NormalizedServiceConfig,
|
|
3
|
+
export declare function watchClientCompilation(config: NormalizedServiceConfig, onManifestReady: () => void): Promise<WebpackDevServer>;
|
|
@@ -32,13 +32,18 @@ const fs = __importStar(require("node:fs"));
|
|
|
32
32
|
const webpack_1 = __importDefault(require("webpack"));
|
|
33
33
|
const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
34
34
|
const webpack_manifest_plugin_1 = require("webpack-manifest-plugin");
|
|
35
|
+
const webpack_assets_manifest_1 = __importDefault(require("webpack-assets-manifest"));
|
|
36
|
+
const utils_1 = require("../../common/utils");
|
|
35
37
|
const paths_1 = __importDefault(require("../../common/paths"));
|
|
36
38
|
const logger_1 = require("../../common/logger");
|
|
37
39
|
const config_1 = require("../../common/webpack/config");
|
|
38
|
-
async function watchClientCompilation(config,
|
|
40
|
+
async function watchClientCompilation(config, onManifestReady) {
|
|
39
41
|
const clientCompilation = await buildWebpackServer(config);
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
+
const compiler = clientCompilation.compiler;
|
|
43
|
+
if ('compilers' in compiler) {
|
|
44
|
+
throw new Error('Unexpected multi compiler');
|
|
45
|
+
}
|
|
46
|
+
subscribeToManifestReadyEvent(compiler, onManifestReady);
|
|
42
47
|
return clientCompilation;
|
|
43
48
|
}
|
|
44
49
|
async function buildWebpackServer(config) {
|
|
@@ -124,3 +129,17 @@ async function buildWebpackServer(config) {
|
|
|
124
129
|
}
|
|
125
130
|
return server;
|
|
126
131
|
}
|
|
132
|
+
function subscribeToManifestReadyEvent(compiler, onManifestReady) {
|
|
133
|
+
const promises = [];
|
|
134
|
+
const assetsManifestPlugin = compiler.options.plugins.find((plugin) => plugin instanceof webpack_assets_manifest_1.default);
|
|
135
|
+
if (assetsManifestPlugin) {
|
|
136
|
+
const assetsManifestReady = (0, utils_1.deferredPromise)();
|
|
137
|
+
promises.push(assetsManifestReady.promise);
|
|
138
|
+
assetsManifestPlugin.hooks.done.tap('app-builder', assetsManifestReady.resolve);
|
|
139
|
+
}
|
|
140
|
+
const manifestReady = (0, utils_1.deferredPromise)();
|
|
141
|
+
promises.push(manifestReady.promise);
|
|
142
|
+
const { afterEmit } = (0, webpack_manifest_plugin_1.getCompilerHooks)(compiler);
|
|
143
|
+
afterEmit.tap('app-builder', manifestReady.resolve);
|
|
144
|
+
Promise.all(promises).then(() => onManifestReady());
|
|
145
|
+
}
|
package/dist/common/utils.d.ts
CHANGED
|
@@ -4,3 +4,8 @@ export declare function getCacheDir(): Promise<string>;
|
|
|
4
4
|
export declare function getPort({ port }: {
|
|
5
5
|
port: number;
|
|
6
6
|
}): Promise<number>;
|
|
7
|
+
export declare function deferredPromise<T>(): {
|
|
8
|
+
promise: Promise<T | undefined>;
|
|
9
|
+
resolve: (value?: T) => void;
|
|
10
|
+
reject: (reason?: unknown) => void;
|
|
11
|
+
};
|
package/dist/common/utils.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.createRunFolder = createRunFolder;
|
|
|
7
7
|
exports.shouldCompileTarget = shouldCompileTarget;
|
|
8
8
|
exports.getCacheDir = getCacheDir;
|
|
9
9
|
exports.getPort = getPort;
|
|
10
|
+
exports.deferredPromise = deferredPromise;
|
|
10
11
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
12
|
const node_os_1 = __importDefault(require("node:os"));
|
|
12
13
|
const paths_1 = __importDefault(require("./paths"));
|
|
@@ -27,3 +28,13 @@ async function getPort({ port }) {
|
|
|
27
28
|
const { default: getPortDefault, portNumbers } = await import('get-port');
|
|
28
29
|
return getPortDefault({ port: portNumbers(port, port + 100) });
|
|
29
30
|
}
|
|
31
|
+
function deferredPromise() {
|
|
32
|
+
let resolve;
|
|
33
|
+
let reject;
|
|
34
|
+
const promise = new Promise((res, rej) => {
|
|
35
|
+
resolve = res;
|
|
36
|
+
reject = rej;
|
|
37
|
+
});
|
|
38
|
+
// @ts-expect-error Promise callback executes synchronously, so resolve and reject are initialized here
|
|
39
|
+
return { promise, resolve, reject };
|
|
40
|
+
}
|
|
@@ -517,6 +517,7 @@ function createMomentTimezoneDataPlugin(options = {}) {
|
|
|
517
517
|
function configurePlugins(options) {
|
|
518
518
|
const { isEnvDevelopment, isEnvProduction, config } = options;
|
|
519
519
|
const excludeFromClean = config.excludeFromClean || [];
|
|
520
|
+
const manifestFile = 'assets-manifest.json';
|
|
520
521
|
const plugins = [
|
|
521
522
|
new clean_webpack_plugin_1.CleanWebpackPlugin({
|
|
522
523
|
verbose: config.verbose,
|
|
@@ -530,6 +531,16 @@ function configurePlugins(options) {
|
|
|
530
531
|
writeToFileEmit: true,
|
|
531
532
|
publicPath: '',
|
|
532
533
|
}),
|
|
534
|
+
new webpack_assets_manifest_1.default(isEnvProduction
|
|
535
|
+
? {
|
|
536
|
+
entrypoints: true,
|
|
537
|
+
output: manifestFile,
|
|
538
|
+
}
|
|
539
|
+
: {
|
|
540
|
+
entrypoints: true,
|
|
541
|
+
writeToDisk: true,
|
|
542
|
+
output: path.resolve(paths_1.default.appBuild, manifestFile),
|
|
543
|
+
}),
|
|
533
544
|
createMomentTimezoneDataPlugin(config.momentTz),
|
|
534
545
|
new webpack.DefinePlugin({
|
|
535
546
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
@@ -628,17 +639,6 @@ function configurePlugins(options) {
|
|
|
628
639
|
}));
|
|
629
640
|
}
|
|
630
641
|
}
|
|
631
|
-
const manifestFile = 'assets-manifest.json';
|
|
632
|
-
plugins.push(new webpack_assets_manifest_1.default(isEnvProduction
|
|
633
|
-
? {
|
|
634
|
-
entrypoints: true,
|
|
635
|
-
output: manifestFile,
|
|
636
|
-
}
|
|
637
|
-
: {
|
|
638
|
-
entrypoints: true,
|
|
639
|
-
writeToDisk: true,
|
|
640
|
-
output: path.resolve(paths_1.default.appBuild, manifestFile),
|
|
641
|
-
}));
|
|
642
642
|
if (config.cdn) {
|
|
643
643
|
let credentialsGlobal;
|
|
644
644
|
if (process.env.FRONTEND_S3_ACCESS_KEY_ID && process.env.FRONTEND_S3_SECRET_ACCESS_KEY) {
|