Socket
Socket
Sign inDemoInstall

guess-parser

Package Overview
Dependencies
129
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.17 to 0.4.18

dist/guess-parser/src/angular/modules.d.ts

1

dist/common/interfaces.d.ts

@@ -16,2 +16,3 @@ export interface Neighbors {

lazy: boolean;
redirectTo?: string;
}

@@ -18,0 +19,0 @@ export interface Connection {

700

dist/guess-parser/index.js

@@ -10,3 +10,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

}
})(global, function(__WEBPACK_EXTERNAL_MODULE__0__, __WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__11__) {
})(global, function(__WEBPACK_EXTERNAL_MODULE__0__, __WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__14__) {
return /******/ (function(modules) { // webpackBootstrap

@@ -95,3 +95,3 @@ /******/ // The module cache

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 9);
/******/ return __webpack_require__(__webpack_require__.s = 11);
/******/ })

@@ -124,7 +124,7 @@ /************************************************************************/

Object.defineProperty(exports, "__esModule", { value: true });
var base_1 = __webpack_require__(12);
var base_1 = __webpack_require__(15);
exports.parseReactRoutes = base_1.parseReactRoutes;
var react_tsx_1 = __webpack_require__(13);
var react_tsx_1 = __webpack_require__(16);
exports.parseReactTSXRoutes = react_tsx_1.parseRoutes;
var react_jsx_1 = __webpack_require__(14);
var react_jsx_1 = __webpack_require__(17);
exports.parseReactJSXRoutes = react_jsx_1.parseRoutes;

@@ -139,13 +139,15 @@

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(__webpack_require__(13));
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __read = (this && this.__read) || function (o, n) {

@@ -171,17 +173,126 @@ var m = typeof Symbol === "function" && o[Symbol.iterator];

};
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
Object.defineProperty(exports, "__esModule", { value: true });
var ts = __webpack_require__(1);
var path_1 = __webpack_require__(0);
var fs_1 = __webpack_require__(2);
var routes_1 = __webpack_require__(6);
exports.findRootModule = function (registry) {
var childModules = new Set();
var traverseRoute = function (route) {
if (route.module) {
childModules.add(route.module);
}
route.children.forEach(traverseRoute);
};
var allModulePaths = Object.keys(registry);
allModulePaths.forEach(function (path) {
var declaration = registry[path];
// It's possible if the declaration does not exist
// See https://github.com/guess-js/guess/issues/311
if (declaration) {
declaration.eagerRoutes.forEach(traverseRoute);
declaration.lazyRoutes.forEach(traverseRoute);
}
});
var roots = allModulePaths.filter(function (m) { return !childModules.has(m); });
if (roots.length > 1) {
throw new Error('Multiple root routing modules found ' + roots.join(', '));
}
return roots[0];
};
Object.defineProperty(exports, "__esModule", { value: true });
var ts = __webpack_require__(1);
var fs_1 = __webpack_require__(2);
var path_1 = __webpack_require__(0);
var ts_evaluator_1 = __webpack_require__(11);
exports.collectRoutingModules = function (rootFile, registry, result, parentFilePath, currentRoutePath, existing) {
if (parentFilePath === void 0) { parentFilePath = rootFile; }
if (currentRoutePath === void 0) { currentRoutePath = ''; }
if (existing === void 0) { existing = new Set(); }
var declaration = registry[rootFile];
// It's possible if the declaration does not exist
// See https://github.com/guess-js/guess/issues/311
if (!declaration) {
return;
}
var process = function (r, routePath) {
if (routePath === void 0) { routePath = currentRoutePath; }
if (r.module) {
// tslint:disable-next-line: no-use-before-declare
return processLazyRoute(r, routePath);
}
// tslint:disable-next-line: no-use-before-declare
return processRoute(r, routePath);
};
var processRoute = function (r, routePath) {
if (routePath === void 0) { routePath = currentRoutePath; }
var path = (routePath + '/' + r.path).replace(/\/$/, '');
r.children.forEach(function (route) { return process(route, path); });
if (!existing.has(path)) {
var routingModule = {
path: path,
lazy: parentFilePath !== rootFile && r.redirectTo === undefined,
modulePath: rootFile,
parentModulePath: parentFilePath,
};
if (r.redirectTo !== undefined) {
routingModule.redirectTo = r.redirectTo;
}
result.push(routingModule);
existing.add(path);
}
};
var processLazyRoute = function (r, routePath) {
if (routePath === void 0) { routePath = currentRoutePath; }
var path = (routePath + '/' + r.path).replace(/\/$/, '');
r.children.forEach(function (route) { return process(route, path); });
exports.collectRoutingModules(r.module, registry, result, rootFile, path);
};
declaration.eagerRoutes.forEach(function (r) { return processRoute(r); });
declaration.lazyRoutes.forEach(function (r) { return processLazyRoute(r); });
};
exports.findMainModule = function (program) {
var tryFindMainModule = function (n, sf) {
if (n.kind === ts.SyntaxKind.Identifier &&
n.text === 'bootstrapModule') {
var propAccess = n.parent;
if (!propAccess ||
propAccess.kind !== ts.SyntaxKind.PropertyAccessExpression) {
return null;
}
var tempExpr = propAccess.parent;
if (!tempExpr || tempExpr.kind !== ts.SyntaxKind.CallExpression) {
return null;
}
var expr = tempExpr;
var module_1 = expr.arguments[0];
var tc = program.getTypeChecker();
var symbol = tc.getTypeAtLocation(module_1).getSymbol();
if (!symbol) {
return null;
}
var decl = symbol.getDeclarations();
if (!decl) {
return null;
}
return path_1.resolve(decl[0].getSourceFile().fileName);
}
var mainPath = null;
n.forEachChild(function (c) {
if (mainPath) {
return mainPath;
}
mainPath = tryFindMainModule(c, sf);
});
return mainPath;
};
return program.getSourceFiles().reduce(function (a, sf) {
if (a) {
return a;
}
var mainPath = null;
sf.forEachChild(function (n) {
if (mainPath) {
return;
}
mainPath = tryFindMainModule(n, sf);
});
return mainPath;
}, null);
};
var isImportDeclaration = function (node) {

@@ -196,2 +307,38 @@ return node.kind === ts.SyntaxKind.ImportDeclaration;

};
exports.getModulePathFromRoute = function (parentPath, loadChildren, program, host) {
var childModule = loadChildren.split('#')[0];
var resolvedModule = ts.resolveModuleName(childModule, parentPath, program.getCompilerOptions(), host).resolvedModule;
if (resolvedModule) {
return normalizeFilePath(resolvedModule.resolvedFileName);
}
var childModuleFile = childModule + '.ts';
var parentSegments = path_1.dirname(parentPath).split(path_1.sep);
var childSegments = childModuleFile.split('/');
var max = Math.min(parentSegments.length, childSegments.length);
var maxCommon = 0;
for (var i = 1; i < max; i += 1) {
for (var j = 0; j < i; j += 1) {
var common = 0;
if (parentSegments[parentSegments.length - 1 - j] === childSegments[j]) {
common++;
maxCommon = Math.max(maxCommon, common);
}
else {
// breaking here
common = 0;
j = i;
}
}
}
var path = path_1.join(path_1.dirname(parentPath), childModuleFile
.split('/')
.slice(maxCommon, childSegments.length)
.join('/'));
// This early failure provides better error message compared to the
// generic "Multiple root routing modules" error.
if (!fs_1.existsSync(path)) {
throw new Error("The relative path \"" + loadChildren + "\" to \"" + parentPath + "\" cannot be resolved to a module");
}
return path;
};
var imports = function (parent, child, program, host, importCache, visited) {

@@ -239,2 +386,3 @@ if (visited === void 0) { visited = {}; }

var cache = {};
exports.cleanModuleCache = function () { return (cache = {}); };
// This can potentially break if there's a lazy module

@@ -247,3 +395,3 @@ // that is not only loaded lazily but also imported

// this way the module entry point will be `app.module.ts`.
var getModuleEntryPoint = function (path, entryPoints, program, host) {
exports.getModuleEntryPoint = function (path, entryPoints, program, host) {
var parents = __spread(entryPoints).filter(function (e) { return imports(e, path, program, host, cache); });

@@ -259,2 +407,46 @@ // If no parents, this could be the root module

};
exports.getLazyEntryPoints = function (node, program, host) {
var value = routes_1.readLoadChildren(node, program.getTypeChecker());
if (!value) {
return null;
}
var parent = path_1.resolve(node.getSourceFile().fileName);
var module = exports.getModulePathFromRoute(parent, value, program, host);
return module;
};
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
var ts = __webpack_require__(1);
var ts_evaluator_1 = __webpack_require__(14);
var modules_1 = __webpack_require__(5);
var path_1 = __webpack_require__(0);
var getObjectProp = function (node, prop) {

@@ -288,3 +480,3 @@ var e_1, _a;

};
var readLoadChildren = function (node, typeChecker) {
exports.readLoadChildren = function (node, typeChecker) {
var expr = getObjectProp(node, 'loadChildren');

@@ -343,3 +535,17 @@ if (!expr) {

};
var readChildren = function (node) {
var readRedirect = function (node, typeChecker) {
var expr = getObjectProp(node, 'redirectTo');
if (!expr) {
return null;
}
var val = ts_evaluator_1.evaluate({
node: expr,
typeChecker: typeChecker
});
if (val.success) {
return val.value;
}
return null;
};
exports.readChildren = function (node) {
var expr = getObjectProp(node, 'children');

@@ -351,39 +557,3 @@ if (!expr) {

};
var getModulePathFromRoute = function (parentPath, loadChildren, program, host) {
var childModule = loadChildren.split('#')[0];
var resolvedModule = ts.resolveModuleName(childModule, parentPath, program.getCompilerOptions(), host).resolvedModule;
if (resolvedModule) {
return normalizeFilePath(resolvedModule.resolvedFileName);
}
var childModuleFile = childModule + '.ts';
var parentSegments = path_1.dirname(parentPath).split(path_1.sep);
var childSegments = childModuleFile.split('/');
var max = Math.min(parentSegments.length, childSegments.length);
var maxCommon = 0;
for (var i = 1; i < max; i += 1) {
for (var j = 0; j < i; j += 1) {
var common = 0;
if (parentSegments[parentSegments.length - 1 - j] === childSegments[j]) {
common++;
maxCommon = Math.max(maxCommon, common);
}
else {
// breaking here
common = 0;
j = i;
}
}
}
var path = path_1.join(path_1.dirname(parentPath), childModuleFile
.split('/')
.slice(maxCommon, childSegments.length)
.join('/'));
// This early failure provides better error message compared to the
// generic "Multiple root routing modules" error.
if (!fs_1.existsSync(path)) {
throw new Error("The relative path \"" + loadChildren + "\" to \"" + parentPath + "\" cannot be resolved to a module");
}
return path;
};
var getRoute = function (node, entryPoints, program, host) {
exports.getRoute = function (node, entryPoints, program, host) {
var path = readPath(node, program.getTypeChecker());

@@ -393,3 +563,3 @@ if (path === null) {

}
var childrenArray = readChildren(node);
var childrenArray = exports.readChildren(node);
var children = [];

@@ -402,3 +572,3 @@ if (childrenArray) {

}
return getRoute(c, entryPoints, program, host);
return exports.getRoute(c, entryPoints, program, host);
})

@@ -408,11 +578,15 @@ .filter(function (e) { return e !== null; });

var route = { path: path, children: children };
var loadChildren = readLoadChildren(node, program.getTypeChecker());
var redirectTo = readRedirect(node, program.getTypeChecker());
if (redirectTo) {
route.redirectTo = redirectTo;
}
var loadChildren = exports.readLoadChildren(node, program.getTypeChecker());
if (loadChildren) {
var parent_2 = getModuleEntryPoint(path_1.resolve(node.getSourceFile().fileName), entryPoints, program, host);
var module_1 = getModulePathFromRoute(parent_2, loadChildren, program, host);
return __assign({}, route, { module: module_1 });
var parent_2 = modules_1.getModuleEntryPoint(path_1.resolve(node.getSourceFile().fileName), entryPoints, program, host);
var module_1 = modules_1.getModulePathFromRoute(parent_2, loadChildren, program, host);
return __assign(__assign({}, route), { module: module_1 });
}
return route;
};
var isRoute = function (n, typeChecker) {
exports.isRoute = function (n, typeChecker, redirects) {
if (n.kind !== ts.SyntaxKind.ObjectLiteralExpression ||

@@ -425,218 +599,12 @@ !n.parent ||

var path = readPath(objLiteral, typeChecker) !== null;
var children = !!readChildren(objLiteral);
var loadChildren = !!readLoadChildren(objLiteral, typeChecker);
var redirectTo = redirects && readRedirect(objLiteral, typeChecker) !== null;
var children = !!exports.readChildren(objLiteral);
var loadChildren = !!exports.readLoadChildren(objLiteral, typeChecker);
var component = !!getObjectProp(objLiteral, 'component');
return (path && children) || (path && component) || (path && loadChildren);
return (path && children) || (path && component) || (path && loadChildren) || (path && redirectTo);
};
var findRootModule = function (registry) {
var childModules = new Set();
var traverseRoute = function (route) {
if (route.module) {
childModules.add(route.module);
}
route.children.forEach(traverseRoute);
};
var allModulePaths = Object.keys(registry);
allModulePaths.forEach(function (path) {
var declaration = registry[path];
// It's possible if the declaration does not exist
// See https://github.com/guess-js/guess/issues/311
if (declaration) {
declaration.eagerRoutes.forEach(traverseRoute);
declaration.lazyRoutes.forEach(traverseRoute);
}
});
var roots = allModulePaths.filter(function (m) { return !childModules.has(m); });
if (roots.length > 1) {
throw new Error('Multiple root routing modules found ' + roots.join(', '));
}
return roots[0];
};
var collectRoutingModules = function (rootFile, registry, result, parentFilePath, currentRoutePath, existing) {
if (parentFilePath === void 0) { parentFilePath = rootFile; }
if (currentRoutePath === void 0) { currentRoutePath = ''; }
if (existing === void 0) { existing = new Set(); }
var declaration = registry[rootFile];
// It's possible if the declaration does not exist
// See https://github.com/guess-js/guess/issues/311
if (!declaration) {
return;
}
var process = function (r, routePath) {
if (routePath === void 0) { routePath = currentRoutePath; }
if (r.module) {
// tslint:disable-next-line: no-use-before-declare
return processLazyRoute(r, routePath);
}
// tslint:disable-next-line: no-use-before-declare
return processRoute(r, routePath);
};
var processRoute = function (r, routePath) {
if (routePath === void 0) { routePath = currentRoutePath; }
var path = (routePath + '/' + r.path).replace(/\/$/, '');
r.children.forEach(function (route) { return process(route, path); });
if (!existing.has(path)) {
result.push({
path: path,
lazy: parentFilePath !== rootFile,
modulePath: rootFile,
parentModulePath: parentFilePath
});
existing.add(path);
}
};
var processLazyRoute = function (r, routePath) {
if (routePath === void 0) { routePath = currentRoutePath; }
var path = (routePath + '/' + r.path).replace(/\/$/, '');
r.children.forEach(function (route) { return process(route, path); });
collectRoutingModules(r.module, registry, result, rootFile, path);
};
declaration.eagerRoutes.forEach(function (r) { return processRoute(r); });
declaration.lazyRoutes.forEach(function (r) { return processLazyRoute(r); });
};
var findMainModule = function (program) {
var tryFindMainModule = function (n, sf) {
if (n.kind === ts.SyntaxKind.Identifier &&
n.text === 'bootstrapModule') {
var propAccess = n.parent;
if (!propAccess ||
propAccess.kind !== ts.SyntaxKind.PropertyAccessExpression) {
return null;
}
var tempExpr = propAccess.parent;
if (!tempExpr || tempExpr.kind !== ts.SyntaxKind.CallExpression) {
return null;
}
var expr = tempExpr;
var module_2 = expr.arguments[0];
var tc = program.getTypeChecker();
var symbol = tc.getTypeAtLocation(module_2).getSymbol();
if (!symbol) {
return null;
}
var decl = symbol.getDeclarations();
if (!decl) {
return null;
}
return path_1.resolve(decl[0].getSourceFile().fileName);
}
var mainPath = null;
n.forEachChild(function (c) {
if (mainPath) {
return mainPath;
}
mainPath = tryFindMainModule(c, sf);
});
return mainPath;
};
return program.getSourceFiles().reduce(function (a, sf) {
if (a) {
return a;
}
var mainPath = null;
sf.forEachChild(function (n) {
if (mainPath) {
return;
}
mainPath = tryFindMainModule(n, sf);
});
return mainPath;
}, null);
};
var getLazyEntryPoints = function (node, program, host) {
var value = readLoadChildren(node, program.getTypeChecker());
if (!value) {
return null;
}
var parent = path_1.resolve(node.getSourceFile().fileName);
var module = getModulePathFromRoute(parent, value, program, host);
return module;
};
exports.parseRoutes = function (tsconfig, exclude) {
if (exclude === void 0) { exclude = []; }
cache = {};
var parseConfigHost = {
fileExists: fs_1.existsSync,
readDirectory: ts.sys.readDirectory,
readFile: function (file) { return fs_1.readFileSync(file, 'utf8'); },
useCaseSensitiveFileNames: true
};
var config = ts.readConfigFile(tsconfig, function (path) {
return fs_1.readFileSync(path).toString();
});
var parsed = ts.parseJsonConfigFileContent(config.config, parseConfigHost, path_1.resolve(path_1.dirname(tsconfig)), {
noEmit: true
});
var host = ts.createCompilerHost(parsed.options, true);
var program = ts.createProgram(parsed.fileNames, parsed.options, host);
var typeChecker = program.getTypeChecker();
var toAbsolute = function (file) {
return file.startsWith('/') || file.startsWith(process.cwd()) ? file : path_1.join(process.cwd(), file);
};
var excludeFiles = new Set(exclude.map(toAbsolute));
var visitTopLevelRoutes = function (s, callback, n) {
if (excludeFiles.has(path_1.resolve(s.fileName))) {
return;
}
if (!n) {
return;
}
if (isRoute(n, typeChecker)) {
callback(n);
}
else {
n.forEachChild(visitTopLevelRoutes.bind(null, s, callback));
}
};
var mainPath = findMainModule(program);
if (!mainPath) {
throw new Error('Cannot find the main application module');
}
var entryPoints = new Set([mainPath]);
var collectEntryPoints = function (n) {
var path = getLazyEntryPoints(n, program, host);
if (!path) {
var childrenArray = readChildren(n);
if (childrenArray) {
childrenArray.forEach(collectEntryPoints);
}
return;
}
entryPoints.add(path);
};
program.getSourceFiles().map(function (s) {
s.forEachChild(visitTopLevelRoutes.bind(null, s, collectEntryPoints));
});
var registry = {};
program.getSourceFiles().map(function (s) {
s.forEachChild(visitTopLevelRoutes.bind(null, s, function (n) {
var path = path_1.resolve(n.getSourceFile().fileName);
var route = getRoute(n, entryPoints, program, host);
if (!route) {
return;
}
var modulePath = getModuleEntryPoint(path, entryPoints, program, host);
var current = registry[modulePath] || {
lazyRoutes: [],
eagerRoutes: []
};
if (route.module) {
current.lazyRoutes.push(route);
}
else {
current.eagerRoutes.push(route);
}
registry[modulePath] = current;
}));
});
var result = [];
if (Object.keys(registry).length > 0) {
collectRoutingModules(findRootModule(registry), registry, result);
}
return result;
};
/***/ }),
/* 5 */
/* 7 */
/***/ (function(module, exports, __webpack_require__) {

@@ -661,3 +629,3 @@

/***/ }),
/* 6 */
/* 8 */
/***/ (function(module, exports, __webpack_require__) {

@@ -690,4 +658,4 @@

var path = __webpack_require__(0);
var utils_1 = __webpack_require__(5);
var language_service_1 = __webpack_require__(15);
var utils_1 = __webpack_require__(7);
var language_service_1 = __webpack_require__(18);
var LazyRe = /routes\/((\w+\/index)|\w+)\.(js|jsx|ts|tsx)$/;

@@ -807,3 +775,3 @@ var getLazyDefinition = function (filename, identifier, ls) {

/***/ }),
/* 7 */
/* 9 */
/***/ (function(module, exports, __webpack_require__) {

@@ -825,3 +793,3 @@

/***/ }),
/* 8 */
/* 10 */
/***/ (function(module, exports, __webpack_require__) {

@@ -835,7 +803,7 @@

Object.defineProperty(exports, "__esModule", { value: true });
__export(__webpack_require__(16));
__export(__webpack_require__(19));
/***/ }),
/* 9 */
/* 11 */
/***/ (function(module, exports, __webpack_require__) {

@@ -849,5 +817,5 @@

Object.defineProperty(exports, "__esModule", { value: true });
var parser_1 = __webpack_require__(10);
var parser_1 = __webpack_require__(12);
exports.parseRoutes = parser_1.parseRoutes;
var detector_1 = __webpack_require__(8);
var detector_1 = __webpack_require__(10);
exports.detect = detector_1.detect;

@@ -857,7 +825,7 @@ var angular_1 = __webpack_require__(4);

__export(__webpack_require__(3));
__export(__webpack_require__(6));
__export(__webpack_require__(8));
/***/ }),
/* 10 */
/* 12 */
/***/ (function(module, exports, __webpack_require__) {

@@ -870,5 +838,5 @@

var react_1 = __webpack_require__(3);
var preact_1 = __webpack_require__(6);
var interfaces_1 = __webpack_require__(7);
var detector_1 = __webpack_require__(8);
var preact_1 = __webpack_require__(8);
var interfaces_1 = __webpack_require__(9);
var detector_1 = __webpack_require__(10);
var path_1 = __webpack_require__(0);

@@ -908,9 +876,123 @@ var unique = function (a) {

/***/ }),
/* 11 */
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var ts = __webpack_require__(1);
var fs_1 = __webpack_require__(2);
var path_1 = __webpack_require__(0);
var modules_1 = __webpack_require__(5);
var routes_1 = __webpack_require__(6);
var defaultOptions = {
redirects: false,
};
var normalizeOptions = function (options) { return (__assign(__assign({}, defaultOptions), options)); };
exports.parseRoutes = function (tsconfig, exclude, inputOptions) {
if (exclude === void 0) { exclude = []; }
if (inputOptions === void 0) { inputOptions = {}; }
var options = normalizeOptions(inputOptions);
modules_1.cleanModuleCache();
var parseConfigHost = {
fileExists: fs_1.existsSync,
readDirectory: ts.sys.readDirectory,
readFile: function (file) { return fs_1.readFileSync(file, 'utf8'); },
useCaseSensitiveFileNames: true
};
var config = ts.readConfigFile(tsconfig, function (path) {
return fs_1.readFileSync(path).toString();
});
var parsed = ts.parseJsonConfigFileContent(config.config, parseConfigHost, path_1.resolve(path_1.dirname(tsconfig)), {
noEmit: true
});
var host = ts.createCompilerHost(parsed.options, true);
var program = ts.createProgram(parsed.fileNames, parsed.options, host);
var typeChecker = program.getTypeChecker();
var toAbsolute = function (file) {
return file.startsWith('/') || file.startsWith(process.cwd()) ? file : path_1.join(process.cwd(), file);
};
var excludeFiles = new Set(exclude.map(toAbsolute));
var visitTopLevelRoutes = function (s, callback, n) {
if (excludeFiles.has(path_1.resolve(s.fileName))) {
return;
}
if (!n) {
return;
}
if (routes_1.isRoute(n, typeChecker, options.redirects)) {
callback(n);
}
else {
n.forEachChild(visitTopLevelRoutes.bind(null, s, callback));
}
};
var mainPath = modules_1.findMainModule(program);
if (!mainPath) {
throw new Error('Cannot find the main application module');
}
var entryPoints = new Set([mainPath]);
var collectEntryPoints = function (n) {
var path = modules_1.getLazyEntryPoints(n, program, host);
if (!path) {
var childrenArray = routes_1.readChildren(n);
if (childrenArray) {
childrenArray.forEach(collectEntryPoints);
}
return;
}
entryPoints.add(path);
};
program.getSourceFiles().map(function (s) {
s.forEachChild(visitTopLevelRoutes.bind(null, s, collectEntryPoints));
});
var registry = {};
program.getSourceFiles().map(function (s) {
s.forEachChild(visitTopLevelRoutes.bind(null, s, function (n) {
var path = path_1.resolve(n.getSourceFile().fileName);
var route = routes_1.getRoute(n, entryPoints, program, host);
if (!route) {
return;
}
var modulePath = modules_1.getModuleEntryPoint(path, entryPoints, program, host);
var current = registry[modulePath] || {
lazyRoutes: [],
eagerRoutes: []
};
if (route.module) {
current.lazyRoutes.push(route);
}
else {
current.eagerRoutes.push(route);
}
registry[modulePath] = current;
}));
});
var result = [];
if (Object.keys(registry).length > 0) {
modules_1.collectRoutingModules(modules_1.findRootModule(registry), registry, result);
}
return result;
};
/***/ }),
/* 14 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE__11__;
module.exports = __WEBPACK_EXTERNAL_MODULE__14__;
/***/ }),
/* 12 */
/* 15 */
/***/ (function(module, exports, __webpack_require__) {

@@ -1044,3 +1126,3 @@

/***/ }),
/* 13 */
/* 16 */
/***/ (function(module, exports, __webpack_require__) {

@@ -1080,3 +1162,3 @@

/***/ }),
/* 14 */
/* 17 */
/***/ (function(module, exports, __webpack_require__) {

@@ -1089,3 +1171,3 @@

var typescript_1 = __webpack_require__(1);
var utils_1 = __webpack_require__(5);
var utils_1 = __webpack_require__(7);
exports.parseRoutes = function (base) {

@@ -1100,3 +1182,3 @@ return _1.parseReactRoutes(utils_1.readFiles(base), {

/***/ }),
/* 15 */
/* 18 */
/***/ (function(module, exports, __webpack_require__) {

@@ -1133,3 +1215,3 @@

/***/ }),
/* 16 */
/* 19 */
/***/ (function(module, exports, __webpack_require__) {

@@ -1142,3 +1224,3 @@

var path_1 = __webpack_require__(0);
var interfaces_1 = __webpack_require__(7);
var interfaces_1 = __webpack_require__(9);
var dep = function (p) { return function (name) { return (p.dependencies ? p.dependencies[name] : undefined); }; };

@@ -1145,0 +1227,0 @@ var devDep = function (p) { return function (name) { return (p.devDependencies ? p.devDependencies[name] : undefined); }; };

@@ -1,2 +0,1 @@

import { RoutingModule } from '../../../common/interfaces';
export declare const parseRoutes: (tsconfig: string, exclude?: string[]) => RoutingModule[];
export * from './route-parser';
{
"name": "guess-parser",
"version": "0.4.17",
"version": "0.4.18",
"description": "Finds the route declarations in your application.",

@@ -29,3 +29,3 @@ "main": "dist/guess-parser/index.js",

"devDependencies": {
"ts-loader": "6.2.1"
"ts-loader": "7.0.0"
},

@@ -55,3 +55,3 @@ "peerDependencies": {

},
"gitHead": "11654bb8534a4bf87fc06d88d5575f65c1b56a8f"
"gitHead": "3f988e5fda8a5f3ece6175fd7c9d85654d92fcac"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc