Files
asciidisco.com/build/node_modules/prepack/lib/detect_bad_deps.js
2023-08-01 13:49:46 +02:00

103 lines
3.3 KiB
JavaScript

"use strict";
var _madge = require("madge");
var _madge2 = _interopRequireDefault(_madge);
var _child_process = require("child_process");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
(0, _child_process.exec)("flow check --profile", function (error, stdout, stderr) {
error;
stdout;
/*
pattern format:
...
cycle detected among the following files:
file1
file2
...
filen
... more flow output after unindented line
*/
var start = stderr.indexOf("cycle detected among the following nodes");
var lines = stderr.substr(start).split("\n").splice(1);
var found_ecma = false;
var found_realm = false;
var cycle_len = 0;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var line = _step.value;
if (!line.startsWith("\t")) break;
cycle_len += 1;
found_ecma = found_ecma || line.includes("/ecma262/");
found_realm = found_realm || line.includes("/realm.js");
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
if (found_ecma && found_realm) {
console.error("Invalid Dependencies: ecma262/ is in a circular dependency with realm.js");
process.exit(1);
}
console.log("Biggest cycle: " + cycle_len);
var MAX_CYCLE_LEN = 56; // NEVER EVER increase this value
if (cycle_len > MAX_CYCLE_LEN) {
console.error("Error: You increased cycle length from the previous high of " + MAX_CYCLE_LEN);
console.error("This is never OK.");
process.exit(1);
}
});
// NB: This doesn't prevent cycles using "import type" because those are
// erased in the lib folder but madge doesn't work with flow type imports.
(0, _madge2.default)("./lib/").then(function (res) {
var deps = res.obj();
var idx_deps = res.depends("intrinsics/index");
if (idx_deps.length !== 1 || idx_deps[0] !== "construct_realm") {
console.error("Invalid Dependency: Intrinsics index depends on " + idx_deps[0]);
process.exit(1);
}
for (var dep in deps) {
// Nothing in intrinsics/ecma262 depends on anything but intrinsics/index except Error and global.
if (dep.startsWith("intrinsics/ecma262") && dep !== "intrinsics/ecma262/Error" && dep !== "intrinsics/ecma262/global") {
var ext_deps = res.depends(dep).filter(function (depend) {
return depend !== "intrinsics/index" && !depend.startsWith("intrinsics/ecma262");
});
if (ext_deps.length > 0) {
console.error("Invalid Dependency: " + dep + " depends on " + ext_deps);
process.exit(1);
}
}
}
});
//# sourceMappingURL=detect_bad_deps.js.map