Add extracted source directory and README navigation

This commit is contained in:
Shawn Bot
2026-03-31 14:56:06 +00:00
parent 6252bb6eb5
commit 91e01d755b
4757 changed files with 984951 additions and 0 deletions

View File

@@ -0,0 +1,152 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Walker = void 0;
const debug = require("debug");
const fs = require("fs-extra");
const path = require("path");
const depTypes_1 = require("./depTypes");
const nativeModuleTypes_1 = require("./nativeModuleTypes");
const d = debug('flora-colossus');
class Walker {
constructor(modulePath) {
this.modules = [];
this.walkHistory = new Set();
this.cache = null;
if (!modulePath || typeof modulePath !== 'string') {
throw new Error('modulePath must be provided as a string');
}
d(`creating walker with rootModule=${modulePath}`);
this.rootModule = modulePath;
}
relativeModule(rootPath, moduleName) {
return path.resolve(rootPath, 'node_modules', moduleName);
}
async loadPackageJSON(modulePath) {
const pJPath = path.resolve(modulePath, 'package.json');
if (await fs.pathExists(pJPath)) {
const pJ = await fs.readJson(pJPath);
if (!pJ.dependencies)
pJ.dependencies = {};
if (!pJ.devDependencies)
pJ.devDependencies = {};
if (!pJ.optionalDependencies)
pJ.optionalDependencies = {};
return pJ;
}
return null;
}
async walkDependenciesForModuleInModule(moduleName, modulePath, depType) {
let testPath = modulePath;
let discoveredPath = null;
let lastRelative = null;
// Try find it while searching recursively up the tree
while (!discoveredPath && this.relativeModule(testPath, moduleName) !== lastRelative) {
lastRelative = this.relativeModule(testPath, moduleName);
if (await fs.pathExists(lastRelative)) {
discoveredPath = lastRelative;
}
else {
if (path.basename(path.dirname(testPath)) !== 'node_modules') {
testPath = path.dirname(testPath);
}
testPath = path.dirname(path.dirname(testPath));
}
}
// If we can't find it the install is probably buggered
if (!discoveredPath && depType !== depTypes_1.DepType.OPTIONAL && depType !== depTypes_1.DepType.DEV_OPTIONAL) {
throw new Error(`Failed to locate module "${moduleName}" from "${modulePath}"
This normally means that either you have deleted this package already somehow (check your ignore settings if using electron-packager). Or your module installation failed.`);
}
// If we can find it let's do the same thing for that module
if (discoveredPath) {
await this.walkDependenciesForModule(discoveredPath, depType);
}
}
async detectNativeModuleType(modulePath, pJ) {
if (pJ.dependencies['prebuild-install']) {
return nativeModuleTypes_1.NativeModuleType.PREBUILD;
}
else if (await fs.pathExists(path.join(modulePath, 'binding.gyp'))) {
return nativeModuleTypes_1.NativeModuleType.NODE_GYP;
}
return nativeModuleTypes_1.NativeModuleType.NONE;
}
async walkDependenciesForModule(modulePath, depType) {
d('walk reached:', modulePath, ' Type is:', depTypes_1.DepType[depType]);
// We have already traversed this module
if (this.walkHistory.has(modulePath)) {
d('already walked this route');
// Find the existing module reference
const existingModule = this.modules.find(module => module.path === modulePath);
// If the depType we are traversing with now is higher than the
// last traversal then update it (prod superseeds dev for instance)
if ((0, depTypes_1.depTypeGreater)(depType, existingModule.depType)) {
d(`existing module has a type of "${existingModule.depType}", new module type would be "${depType}" therefore updating`);
existingModule.depType = depType;
}
return;
}
const pJ = await this.loadPackageJSON(modulePath);
// If the module doesn't have a package.json file it is probably a
// dead install from yarn (they dont clean up for some reason)
if (!pJ) {
d('walk hit a dead end, this module is incomplete');
return;
}
// Record this module as being traversed
this.walkHistory.add(modulePath);
this.modules.push({
depType,
nativeModuleType: await this.detectNativeModuleType(modulePath, pJ),
path: modulePath,
name: pJ.name,
});
// For every prod dep
for (const moduleName in pJ.dependencies) {
// npm decides it's a funny thing to put optional dependencies in the "dependencies" section
// after install, because that makes perfect sense
if (moduleName in pJ.optionalDependencies) {
d(`found ${moduleName} in prod deps of ${modulePath} but it is also marked optional`);
continue;
}
await this.walkDependenciesForModuleInModule(moduleName, modulePath, (0, depTypes_1.childDepType)(depType, depTypes_1.DepType.PROD));
}
// For every optional dep
for (const moduleName in pJ.optionalDependencies) {
await this.walkDependenciesForModuleInModule(moduleName, modulePath, (0, depTypes_1.childDepType)(depType, depTypes_1.DepType.OPTIONAL));
}
// For every dev dep, but only if we are in the root module
if (depType === depTypes_1.DepType.ROOT) {
d('we\'re still at the beginning, walking down the dev route');
for (const moduleName in pJ.devDependencies) {
await this.walkDependenciesForModuleInModule(moduleName, modulePath, (0, depTypes_1.childDepType)(depType, depTypes_1.DepType.DEV));
}
}
}
async walkTree() {
d('starting tree walk');
if (!this.cache) {
this.cache = new Promise(async (resolve, reject) => {
this.modules = [];
try {
await this.walkDependenciesForModule(this.rootModule, depTypes_1.DepType.ROOT);
}
catch (err) {
reject(err);
return;
}
resolve(this.modules);
});
}
else {
d('tree walk in progress / completed already, waiting for existing walk to complete');
}
return await this.cache;
}
getRootModule() {
return this.rootModule;
}
}
exports.Walker = Walker;
//# sourceMappingURL=Walker.js.map

View File

@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.childDepType = exports.depTypeGreater = exports.DepType = void 0;
var DepType;
(function (DepType) {
DepType[DepType["PROD"] = 0] = "PROD";
DepType[DepType["DEV"] = 1] = "DEV";
DepType[DepType["OPTIONAL"] = 2] = "OPTIONAL";
DepType[DepType["DEV_OPTIONAL"] = 3] = "DEV_OPTIONAL";
DepType[DepType["ROOT"] = 4] = "ROOT";
})(DepType = exports.DepType || (exports.DepType = {}));
const depTypeGreater = (newType, existing) => {
switch (existing) {
case DepType.DEV:
switch (newType) {
case DepType.OPTIONAL:
case DepType.PROD:
case DepType.ROOT:
return true;
case DepType.DEV:
case DepType.DEV_OPTIONAL:
default:
return false;
}
case DepType.DEV_OPTIONAL:
switch (newType) {
case DepType.OPTIONAL:
case DepType.PROD:
case DepType.ROOT:
case DepType.DEV:
return true;
case DepType.DEV_OPTIONAL:
default:
return false;
}
case DepType.OPTIONAL:
switch (newType) {
case DepType.PROD:
case DepType.ROOT:
return true;
case DepType.OPTIONAL:
case DepType.DEV:
case DepType.DEV_OPTIONAL:
default:
return false;
}
case DepType.PROD:
switch (newType) {
case DepType.ROOT:
return true;
case DepType.PROD:
case DepType.OPTIONAL:
case DepType.DEV:
case DepType.DEV_OPTIONAL:
default:
return false;
}
case DepType.ROOT:
switch (newType) {
case DepType.ROOT:
case DepType.PROD:
case DepType.OPTIONAL:
case DepType.DEV:
case DepType.DEV_OPTIONAL:
default:
return false;
}
default:
return false;
}
};
exports.depTypeGreater = depTypeGreater;
const childDepType = (parentType, childType) => {
if (childType === DepType.ROOT) {
throw new Error('Something went wrong, a child dependency can\'t be marked as the ROOT');
}
switch (parentType) {
case DepType.ROOT:
return childType;
case DepType.PROD:
if (childType === DepType.OPTIONAL)
return DepType.OPTIONAL;
return DepType.PROD;
case DepType.OPTIONAL:
return DepType.OPTIONAL;
case DepType.DEV_OPTIONAL:
return DepType.DEV_OPTIONAL;
case DepType.DEV:
if (childType === DepType.OPTIONAL)
return DepType.DEV_OPTIONAL;
return DepType.DEV;
}
};
exports.childDepType = childDepType;
//# sourceMappingURL=depTypes.js.map

View File

@@ -0,0 +1,19 @@
"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 __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./Walker"), exports);
__exportStar(require("./depTypes"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NativeModuleType = void 0;
var NativeModuleType;
(function (NativeModuleType) {
NativeModuleType[NativeModuleType["NONE"] = 0] = "NONE";
NativeModuleType[NativeModuleType["NODE_GYP"] = 1] = "NODE_GYP";
NativeModuleType[NativeModuleType["PREBUILD"] = 2] = "PREBUILD";
})(NativeModuleType = exports.NativeModuleType || (exports.NativeModuleType = {}));
//# sourceMappingURL=nativeModuleTypes.js.map