npm package diff
Package: @forge/bundler
Versions: 4.20.1-next.6 - 4.20.1-next.7
File: package/out/webpack.js
Index: package/out/webpack.js
===================================================================
--- package/out/webpack.js
+++ package/out/webpack.js
@@ -1,16 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-exports.nativeUiBundle = exports.getNodeBundler = exports.getSandboxBundler = exports.createBundler = exports.runLinter = exports.getMetadata = exports.getCompiler = exports.handleWebpackCompilationResult = void 0;
+exports.WebpackBundler = exports.runLinter = exports.getCompiler = exports.handleWebpackCompilationResult = void 0;
const tslib_1 = require("tslib");
-const fs_1 = require("fs");
const path_1 = tslib_1.__importDefault(require("path"));
const webpack_1 = tslib_1.__importDefault(require("webpack"));
const cli_shared_1 = require("@forge/cli-shared");
const lint_1 = require("@forge/lint");
-const nativeui_1 = require("./config/nativeui");
-const node_1 = require("./config/node");
-const sandbox_1 = require("./config/sandbox");
const text_1 = require("./text");
function handleWebpackCompilationResult(logger, err, stats) {
if (err) {
throw err;
@@ -60,19 +56,8 @@
});
return Array.from(filteredModuleNames);
}
}
-function getMetadata(config, stats) {
- const metadata = {};
- if (stats) {
- metadata.modules = getNodeModuleNames(stats);
- }
- if (config.name === node_1.NODE_WEBPACK_CONFIG_NAME && config.output?.path) {
- metadata.nodeRuntimeVersion = (0, fs_1.readFileSync)(path_1.default.join(config.output.path, node_1.NODE_RUNTIME_VERSION_FILE)).toString();
- }
- return metadata;
-}
-exports.getMetadata = getMetadata;
const runLinter = async (logger = { info: console.log }, fileSystemReader = new cli_shared_1.FileSystemReader(), fileSystemWriter = new cli_shared_1.FileSystemWriter()) => {
logger.info(`\n${cli_shared_1.Text.tunnel.preBundleTask(cli_shared_1.Text.lint.running)}`);
const exclude = [...(await (0, cli_shared_1.listGitIgnoreFiles)(fileSystemReader)), '.git', 'node_modules'];
const configFile = new cli_shared_1.ConfigFile(fileSystemReader, fileSystemWriter);
@@ -98,48 +83,74 @@
logger.info(cli_shared_1.Text.tunnel.lintFailed + '\n');
}
};
exports.runLinter = runLinter;
-function createBundler(getBuildConfig) {
- return (logger, appDirectory, endpoints) => {
- const outputDir = (0, cli_shared_1.tmpDir)('dist');
- const config = getBuildConfig(endpoints, { isWatchMode: false, appDirectory, outputDir });
+class WebpackBundler {
+ logger;
+ constructor(logger) {
+ this.logger = logger;
+ }
+ getOutput(config, stats) {
+ const outputDir = config.output.path;
+ const metadata = {};
+ if (stats) {
+ metadata.modules = getNodeModuleNames(stats);
+ }
+ return { outputDir, metadata };
+ }
+ async runCompiler(config) {
const compiler = getCompiler(config);
return new Promise((resolve, reject) => {
compiler.run((compilerError, stats) => {
try {
- handleWebpackCompilationResult(logger, compilerError, stats);
+ handleWebpackCompilationResult(this.logger, compilerError, stats);
compiler.close((closeError) => {
if (closeError) {
reject(closeError);
}
});
- resolve({ outputDir, metadata: getMetadata(config, stats) });
+ resolve(this.getOutput(config, stats));
}
catch (err) {
reject(err);
}
});
});
- };
-}
-exports.createBundler = createBundler;
-const getSandboxBundler = () => createBundler(sandbox_1.getSandboxedRuntimeBuildConfig);
-exports.getSandboxBundler = getSandboxBundler;
-const getNodeBundler = (wrapperProvider) => createBundler((0, node_1.getNodeRuntimeBuildConfig)(wrapperProvider));
-exports.getNodeBundler = getNodeBundler;
-const nativeUiBundle = (logger, appDirectory, entrypoints, i18nConfig) => {
- const config = (0, nativeui_1.getNativeUiBuildConfig)(entrypoints, i18nConfig);
- const compiler = getCompiler(config);
- return new Promise((resolve, reject) => {
- compiler.run((compilerError, stats) => {
- try {
- handleWebpackCompilationResult(logger, compilerError, stats);
- resolve({ outputDir: config.output.path });
+ }
+ async bundle(args) {
+ const config = this.getConfig(args);
+ return await this.runCompiler(config);
+ }
+ async watch(args, watch) {
+ const config = this.getConfig(args);
+ const compiler = getCompiler(config);
+ let isFirstRun = true;
+ compiler.hooks.watchRun.tapAsync('watchRun', async (_, watchRunCallback) => {
+ if (!isFirstRun) {
+ await watch.onBuildWillStart();
}
- catch (err) {
- reject(err);
- }
+ watchRunCallback();
});
- });
-};
-exports.nativeUiBundle = nativeUiBundle;
+ return new Promise((resolve, reject) => {
+ const watching = compiler.watch({ poll: 1000 }, async (compilerError, stats) => {
+ try {
+ handleWebpackCompilationResult(this.logger, compilerError, stats);
+ this.logger.info(cli_shared_1.LogColor.trace(args.successMessage));
+ const result = this.getOutput(config, stats);
+ if (isFirstRun) {
+ isFirstRun = false;
+ resolve({ result, stop: () => watching.close(() => void 0) });
+ }
+ else {
+ await watch.onBuildFinished(null, result);
+ }
+ }
+ catch (err) {
+ await watch.onBuildFinished(err);
+ isFirstRun = false;
+ reject(err);
+ }
+ });
+ });
+ }
+}
+exports.WebpackBundler = WebpackBundler;