npm package diff

Package: @forge/bundler

Versions: 6.1.4-next.0 - 6.1.4-next.1

File: package/out/webpack.js

Index: package/out/webpack.js
===================================================================
--- package/out/webpack.js
+++ package/out/webpack.js
@@ -1,10 +1,12 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.WebpackBundler = exports.getCompiler = exports.handleWebpackCompilationResult = void 0;
 const tslib_1 = require("tslib");
+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 metadata_1 = require("./metadata");
 const text_1 = require("./text");
 function handleWebpackCompilationResult(logger, err, stats) {
     if (err) {
         throw err;
@@ -61,14 +63,53 @@
         this.logger = logger;
     }
     async getOutput(config, stats) {
         const outputDir = config.output.path;
-        const metadata = {};
+        const metadata = await (0, metadata_1.getMetadata)(this.logger, this.localModules(stats));
         if (stats) {
             metadata.modules = getNodeModuleNames(stats);
         }
         return { outputDir, metadata };
     }
+    isLocalModule(name) {
+        if (name.match(/\/node_modules\/(.+)$/)) {
+            return false;
+        }
+        if (name.match(/^external "(?:node:)?([^:"]+)"$/)) {
+            return false;
+        }
+        if (name.startsWith('webpack/runtime/')) {
+            return false;
+        }
+        if (path_1.default.extname(name) === '.json') {
+            return false;
+        }
+        if (!path_1.default.extname(name).match(/^\.[cm]?[jt]sx?$/)) {
+            throw new Error(`Unknown module type for ${JSON.stringify(name)}.`);
+        }
+        return true;
+    }
+    localModules(stats) {
+        const { modules } = stats.toJson({ modules: true });
+        const result = [];
+        const addModules = (modules) => {
+            for (const module of modules) {
+                if (module.modules) {
+                    addModules(module.modules);
+                }
+                else if (!module.name) {
+                    throw new Error('Module name is missing');
+                }
+                else if (this.isLocalModule(module.name)) {
+                    result.push(module.name);
+                }
+            }
+        };
+        if (modules) {
+            addModules(modules);
+        }
+        return result;
+    }
     async runCompiler(config) {
         const compiler = getCompiler(config);
         return new Promise((resolve, reject) => {
             compiler.run(async (compilerError, stats) => {