Skip to content

Commit

Permalink
fix(frontend): node_modules whitelist works for scoped modules (Googl…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkozy committed Jul 26, 2018
1 parent 43e149e commit 3c5b399
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
29 changes: 27 additions & 2 deletions front_end/ndb/NdbMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,41 @@ Ndb.NdbMain = class extends Common.Object {

const regexPatterns = Common.moduleSetting('skipStackFramesPattern').getAsArray()
.filter(({pattern}) => !pattern.includes(`\\[eval\\]`) && pattern !== `node_debug_demon[\\/]preload\\.js`);
regexPatterns.push({pattern:pattern });
regexPatterns.push({pattern: pattern });
regexPatterns.push({pattern: `node_debug_demon[\\/]preload\\.js`});
Common.moduleSetting('skipStackFramesPattern').setAsArray(regexPatterns);

if (whitelistModules.length > 0) {
const root = {name: 'node_modules', subfolders: []};
populateFolders(whitelistModules, root);
const setting = Persistence.isolatedFileSystemManager.workspaceFolderExcludePatternSetting();
let folders = [];
folders.push(`/node_modules/(?!${whitelistModules.join('|')}).+`);
folders.push(`^/node_modules/(?!($|${root.subfolders.map(generatePattern).join('|')}))`);
setting.set(folders.join('|'));
}

function populateFolders(folders, currentRoot) {
const perParent = new Map();
for (const folder of folders) {
const [parent, ...tail] = folder.split('/');
if (!perParent.has(parent))
perParent.set(parent, [tail.join('/')]);
else
perParent.get(parent).push(tail.join('/'));
}
for (const [parent, tails] of perParent) {
const node = {name: parent, subfolders: []};
if (tails.filter(a => a.length).length)
populateFolders(tails, node);
currentRoot.subfolders.push(node);
}
}

function generatePattern(node) {
if (!node.subfolders || !node.subfolders.length)
return `${node.name}/`;
return `${node.name}/($|${node.subfolders.map(generatePattern).join('|')})`;
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion front_end/ndb/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"className": "Ndb.ContextMenuProvider"
}
],
"dependencies": ["common", "sdk"],
"dependencies": ["common", "sdk", "bindings"],
"scripts": [
"NdbMain.js"
]
Expand Down
2 changes: 1 addition & 1 deletion front_end/ndb_ui/NodeModulesBlackboxing.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Ndb.NodeModulesBlackboxing = class extends UI.VBox {
async _update() {
const processManager = await Ndb.NodeProcessManager.instance();
const {error, code, stderror, stdout} = await processManager.run(NdbProcessInfo.npmExecPath, ['ls', '--depth=0', '--json']);
if (error || code !== 0 || stderror)
if (!stdout || stdout.length === 0)
return;
let dependencies;
try {
Expand Down

0 comments on commit 3c5b399

Please sign in to comment.