npm package diff
Package: @forge/bundler
Versions: 4.21.1-next.14-experimental-f55f6f2 - 4.22.0-next.16
File: package/out/runtime.js
Index: package/out/runtime.js
===================================================================
--- package/out/runtime.js
+++ package/out/runtime.js
@@ -8,8 +8,9 @@
var RawSource = webpack_1.default.sources.RawSource;
const cli_shared_1 = require("@forge/cli-shared");
const common_1 = require("./config/common");
const sandbox_1 = require("./config/sandbox");
+const typescript_1 = require("./typescript");
const webpack_2 = require("./webpack");
const i18n_1 = require("@forge/i18n");
class SandboxBundler extends webpack_2.WebpackBundler {
constructor(logger) {
@@ -90,8 +91,56 @@
});
return webpackConfig;
}
}
+class TypeScriptNodeBundler extends typescript_1.TypeScriptBundler {
+ wrapperProvider;
+ statsigReader;
+ constructor(logger, wrapperProvider, statsigReader) {
+ super(logger);
+ this.wrapperProvider = wrapperProvider;
+ this.statsigReader = statsigReader;
+ }
+ async getResult(args, outputDir) {
+ if (!(await this.statsigReader.packageSingleWrapper())) {
+ throw new cli_shared_1.UserError('Single wrapper feature flag must be enabled to use the TypeScript bundler.');
+ }
+ const result = await super.getResult(args, outputDir);
+ const emit = async (name, contents) => {
+ const outputPath = path_1.default.join(outputDir, name);
+ await promises_1.default.mkdir(path_1.default.dirname(outputPath), { recursive: true });
+ await promises_1.default.writeFile(outputPath, contents);
+ };
+ await emitWrapperFiles(this.wrapperProvider, args.entryPoints, emit, true);
+ if (args.i18nResourceBundle) {
+ await emitI18nFiles(args.i18nResourceBundle, emit);
+ }
+ return result;
+ }
+}
+class ConfigBundler {
+ configReader;
+ bundlers;
+ constructor(logger, wrapperProvider, configReader, statsigReader) {
+ this.configReader = configReader;
+ this.bundlers = new Map([
+ ['webpack', new NodeBundler(logger, wrapperProvider, statsigReader)],
+ ['typescript', new TypeScriptNodeBundler(logger, wrapperProvider, statsigReader)]
+ ]);
+ }
+ async getBundlerType() {
+ return (await this.configReader.readConfig()).app.package?.bundler ?? 'webpack';
+ }
+ async getBundler() {
+ return this.bundlers.get(await this.getBundlerType());
+ }
+ async bundle(args) {
+ return (await this.getBundler()).bundle(args);
+ }
+ async watch(args, watch) {
+ return (await this.getBundler()).watch(args, watch);
+ }
+}
function getNodeBundler(logger, wrapperProvider, configReader, statsigReader) {
- return new NodeBundler(logger, wrapperProvider, statsigReader);
+ return new ConfigBundler(logger, wrapperProvider, configReader, statsigReader);
}
exports.getNodeBundler = getNodeBundler;