npm package diff
Package: @forge/bundler
Versions: 4.19.0-next.13 - 4.19.0-next.14
File: package/out/webpack.js
Index: package/out/webpack.js
===================================================================
--- package/out/webpack.js
+++ package/out/webpack.js
@@ -1,21 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-exports.nativeUiBundle = exports.getNodeBundler = exports.getSandboxBundler = exports.createBundler = exports.watch = exports.runLinter = exports.getCompiler = exports.getInMemoryBundle = exports.handleWebpackCompilationResult = void 0;
+exports.nativeUiBundle = exports.getNodeBundler = exports.getSandboxBundler = exports.createBundler = exports.runLinter = exports.getMetadata = exports.getCompiler = exports.handleWebpackCompilationResult = void 0;
const tslib_1 = require("tslib");
-const memfs_1 = require("memfs");
-const webpack_1 = tslib_1.__importDefault(require("webpack"));
+const fs_1 = require("fs");
const path_1 = tslib_1.__importDefault(require("path"));
-const text_1 = require("./text");
+const webpack_1 = tslib_1.__importDefault(require("webpack"));
const cli_shared_1 = require("@forge/cli-shared");
const lint_1 = require("@forge/lint");
-const sandbox_1 = require("./config/sandbox");
-const node_1 = require("./config/node");
const nativeui_1 = require("./config/nativeui");
-const compilerOutputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
-const readMemoryFileSync = (outputFileSystem, filePath) => {
- return outputFileSystem.readFileSync('/' + filePath, { encoding: 'utf8' }).toString();
-};
+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;
}
@@ -41,47 +37,13 @@
}
}
}
exports.handleWebpackCompilationResult = handleWebpackCompilationResult;
-function tryReadSourceMapSync(fileSystem, sourceMap, fileName) {
- const mapFileName = `${fileName}.map`;
- try {
- sourceMap[mapFileName] = readMemoryFileSync(fileSystem, mapFileName);
- }
- catch (e) {
- }
+function getCompiler(config) {
+ return (0, webpack_1.default)(config);
}
-function getInMemoryBundle(config, fileSystem) {
- const output = {}, sourceMap = {};
- const outputFileSystem = fileSystem || compilerOutputFileSystem;
- const fileNamePattern = config.output?.filename ?? '[name].js';
- for (const name in config.entry) {
- const fileName = fileNamePattern.replace('[name]', name);
- output[fileName] = readMemoryFileSync(outputFileSystem, fileName);
- if (config.name === node_1.NODE_WEBPACK_CONFIG_NAME && name.startsWith(node_1.NODE_WEBPACK_USER_CODE_DIR + '/')) {
- const wrapperName = name.slice(node_1.NODE_WEBPACK_USER_CODE_DIR.length + 1);
- const wrapperFileName = `${wrapperName}.cjs`;
- output[wrapperFileName] = readMemoryFileSync(outputFileSystem, wrapperFileName);
- tryReadSourceMapSync(outputFileSystem, sourceMap, wrapperFileName);
- }
- tryReadSourceMapSync(outputFileSystem, sourceMap, fileName);
- }
- const metadata = {};
- if (config.name === node_1.NODE_WEBPACK_CONFIG_NAME) {
- metadata.nodeRuntimeVersion = readMemoryFileSync(outputFileSystem, node_1.NODE_RUNTIME_VERSION_FILE);
- }
- return { output, sourceMap, metadata };
-}
-exports.getInMemoryBundle = getInMemoryBundle;
-const getCompiler = (webpackConfig, options) => {
- const compiler = (0, webpack_1.default)(webpackConfig);
- if (!options?.writeToDisk) {
- compiler.outputFileSystem = compilerOutputFileSystem;
- }
- return compiler;
-};
exports.getCompiler = getCompiler;
-const getNodeModuleNames = (stats) => {
+function getNodeModuleNames(stats) {
const { modules } = stats.toJson({ modules: true });
if (modules) {
const filteredModuleNames = new Set();
modules
@@ -97,18 +59,20 @@
}
});
return Array.from(filteredModuleNames);
}
-};
-class Monitor {
- watcher;
- constructor(watcher) {
- this.watcher = watcher;
+}
+function getMetadata(config, stats) {
+ const metadata = {};
+ if (stats) {
+ metadata.modules = getNodeModuleNames(stats);
}
- stop() {
- this.watcher.close(() => null);
+ 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);
@@ -134,54 +98,26 @@
logger.info(cli_shared_1.Text.tunnel.lintFailed + '\n');
}
};
exports.runLinter = runLinter;
-const watch = (logger, entryPoints, debugMode, callback, watchRun) => {
- const config = (0, sandbox_1.getSandboxedRuntimeBuildConfig)(entryPoints, {
- isWatchMode: true,
- isDebugMode: debugMode,
- appDirectory: process.cwd()
- });
- const compiler = (0, exports.getCompiler)(config);
- if (typeof watchRun === 'function') {
- compiler.hooks.watchRun.tapAsync('watchRun', (watchRunCompiler, watchRunCallback) => {
- watchRun(watchRunCompiler, exports.runLinter, watchRunCallback);
- });
- }
- const watcher = compiler.watch({ poll: 1000 }, (compilerError, stats) => {
- try {
- handleWebpackCompilationResult(logger, compilerError, stats);
- callback(null, getInMemoryBundle(config));
- }
- catch (fileReadError) {
- callback(fileReadError);
- }
- });
- return new Monitor(watcher);
-};
-exports.watch = watch;
function createBundler(getBuildConfig) {
return (logger, appDirectory, endpoints) => {
- const config = getBuildConfig(endpoints, { isWatchMode: false, appDirectory });
- const compiler = (0, exports.getCompiler)(config);
+ const outputDir = (0, cli_shared_1.tmpDir)('dist');
+ const config = getBuildConfig(endpoints, { isWatchMode: false, appDirectory, outputDir });
+ const compiler = getCompiler(config);
return new Promise((resolve, reject) => {
compiler.run((compilerError, stats) => {
try {
handleWebpackCompilationResult(logger, compilerError, stats);
- const result = getInMemoryBundle(config);
compiler.close((closeError) => {
if (closeError) {
reject(closeError);
}
});
- result.metadata = {
- modules: getNodeModuleNames(stats),
- ...result.metadata
- };
- resolve(result);
+ resolve({ outputDir, metadata: getMetadata(config, stats) });
}
- catch (fileReadError) {
- reject(fileReadError);
+ catch (err) {
+ reject(err);
}
});
});
};
@@ -190,18 +126,16 @@
const getSandboxBundler = () => createBundler(sandbox_1.getSandboxedRuntimeBuildConfig);
exports.getSandboxBundler = getSandboxBundler;
const getNodeBundler = (wrapperProvider) => createBundler((0, node_1.getNodeRuntimeBuildConfig)(wrapperProvider));
exports.getNodeBundler = getNodeBundler;
-const nativeUiBundle = (logger, entrypoints, i18nConfig) => {
+const nativeUiBundle = (logger, appDirectory, entrypoints, i18nConfig) => {
const config = (0, nativeui_1.getNativeUiBuildConfig)(entrypoints, i18nConfig);
- const compiler = (0, exports.getCompiler)(config, { writeToDisk: true });
+ const compiler = getCompiler(config);
return new Promise((resolve, reject) => {
compiler.run((compilerError, stats) => {
try {
handleWebpackCompilationResult(logger, compilerError, stats);
- resolve({
- outputDir: config.output.path
- });
+ resolve({ outputDir: config.output.path });
}
catch (err) {
reject(err);
}