npm package diff

Package: @forge/bundler

Versions: 4.21.1-next.14-experimental-f55f6f2 - 4.22.0-next.16

File: package/out/dependencies.js

Index: package/out/dependencies.js
===================================================================
--- package/out/dependencies.js
+++ package/out/dependencies.js
@@ -0,0 +1,55 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.copyProductionDependencies = void 0;
+const tslib_1 = require("tslib");
+const fs_1 = require("fs");
+const promises_1 = require("fs/promises");
+const path_1 = tslib_1.__importDefault(require("path"));
+const fs_extra_1 = require("fs-extra");
+const common_1 = require("./common");
+async function readPackageJSON(directory) {
+    try {
+        const packageJson = await (0, promises_1.readFile)(path_1.default.join(directory, 'package.json'), 'utf8');
+        return JSON.parse(packageJson);
+    }
+    catch (e) {
+        return null;
+    }
+}
+async function dependencyDir(moduleDir, dependency) {
+    for (let source = moduleDir; source !== path_1.default.dirname(source); source = path_1.default.dirname(source)) {
+        const candidate = path_1.default.join(source, common_1.NODE_MODULES_DIR, dependency);
+        if ((0, fs_1.existsSync)(candidate)) {
+            return candidate;
+        }
+    }
+    return null;
+}
+function transplantDir(source, destination, directory) {
+    const relative = path_1.default.relative(source, directory);
+    return path_1.default.join(destination, relative);
+}
+async function copyProductionDependencies(moduleDir, target, options) {
+    const packageDef = await readPackageJSON(moduleDir);
+    if (!packageDef) {
+        return;
+    }
+    const exclude = options?.exclude ?? [];
+    for (const dependency of Object.keys(packageDef.dependencies ?? {})) {
+        if (exclude.includes(dependency)) {
+            continue;
+        }
+        const source = await dependencyDir(moduleDir, dependency);
+        if (source) {
+            const destination = transplantDir(moduleDir, target, source);
+            if ((0, fs_1.existsSync)(destination)) {
+                continue;
+            }
+            await (0, fs_extra_1.copy)(source, destination, {
+                filter: (src) => path_1.default.basename(src) !== common_1.NODE_MODULES_DIR
+            });
+            await copyProductionDependencies(source, destination, options);
+        }
+    }
+}
+exports.copyProductionDependencies = copyProductionDependencies;