UNPKG

jsii-pacmak

Version:

A code generation framework for jsii backend languages

84 lines 3.65 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.traverseDependencyGraph = traverseDependencyGraph; const fs = __importStar(require("fs-extra")); const path_1 = require("path"); const util = __importStar(require("./util")); /** * Traverses the dependency graph and invokes the provided callback method for * each individual dependency root directory (including the current package). * The dependency roots are de-duplicated based on their absolute path on the * file system. * * @param packageDir the current package's root directory (i.e: where the * `package.json` file is located) * @param callback the function to invoke with each package's informations * @param host the dependency graph traversal host to use (this parameter * should typically not be provided unless this module is * being unit tested) */ async function traverseDependencyGraph(packageDir, callback, host = { readJson: fs.readJson, findDependencyDirectory: util.findDependencyDirectory, }) { return real$traverseDependencyGraph(packageDir, callback, host, new Set()); } async function real$traverseDependencyGraph(packageDir, callback, host, visited) { // We're at the root if we have not visited anything yet. How convenient! const isRoot = visited.size === 0; if (visited.has(packageDir)) { return void 0; } visited.add(packageDir); const meta = await host.readJson((0, path_1.join)(packageDir, 'package.json')); if (!(await callback(packageDir, meta, isRoot))) { return void 0; } const deps = new Set([ ...Object.keys(meta.dependencies ?? {}), ...Object.keys(meta.peerDependencies ?? {}), ]); return Promise.all(Array.from(deps) // No need to pacmak the dependency if it's built-in, or if it's bundled .filter((m) => !util.isBuiltinModule(m) && !meta.bundledDependencies?.includes(m) && !meta.bundleDependencies?.includes(m)) .map(async (dep) => { const dependencyDir = await host.findDependencyDirectory(dep, packageDir); return real$traverseDependencyGraph(dependencyDir, callback, host, visited); })).then(); } //# sourceMappingURL=dependency-graph.js.map