mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
[npm extension] exclude top level npm_modules when detecting npm scripts in workspaces (#150205)
* Check if current folder is a path that should be excluded * update regex to be an exact match
This commit is contained in:
parent
0ff2646b7c
commit
6d91b80dd8
|
@ -12,10 +12,12 @@ import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as minimatch from 'minimatch';
|
import * as minimatch from 'minimatch';
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
|
import { Utils } from 'vscode-uri';
|
||||||
import { findPreferredPM } from './preferred-pm';
|
import { findPreferredPM } from './preferred-pm';
|
||||||
import { readScripts } from './readScripts';
|
import { readScripts } from './readScripts';
|
||||||
|
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
const excludeRegex = new RegExp('^(node_modules|.vscode-test)$', 'i');
|
||||||
|
|
||||||
export interface INpmTaskDefinition extends TaskDefinition {
|
export interface INpmTaskDefinition extends TaskDefinition {
|
||||||
script: string;
|
script: string;
|
||||||
|
@ -156,7 +158,7 @@ export async function hasNpmScripts(): Promise<boolean> {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
for (const folder of folders) {
|
for (const folder of folders) {
|
||||||
if (isAutoDetectionEnabled(folder)) {
|
if (isAutoDetectionEnabled(folder) && !excludeRegex.test(Utils.basename(folder.uri))) {
|
||||||
let relativePattern = new RelativePattern(folder, '**/package.json');
|
let relativePattern = new RelativePattern(folder, '**/package.json');
|
||||||
let paths = await workspace.findFiles(relativePattern, '**/node_modules/**');
|
let paths = await workspace.findFiles(relativePattern, '**/node_modules/**');
|
||||||
if (paths.length > 0) {
|
if (paths.length > 0) {
|
||||||
|
@ -182,7 +184,7 @@ async function detectNpmScripts(context: ExtensionContext, showWarning: boolean)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
for (const folder of folders) {
|
for (const folder of folders) {
|
||||||
if (isAutoDetectionEnabled(folder)) {
|
if (isAutoDetectionEnabled(folder) && !excludeRegex.test(Utils.basename(folder.uri))) {
|
||||||
let relativePattern = new RelativePattern(folder, '**/package.json');
|
let relativePattern = new RelativePattern(folder, '**/package.json');
|
||||||
let paths = await workspace.findFiles(relativePattern, '**/{node_modules,.vscode-test}/**');
|
let paths = await workspace.findFiles(relativePattern, '**/{node_modules,.vscode-test}/**');
|
||||||
for (const path of paths) {
|
for (const path of paths) {
|
||||||
|
@ -206,6 +208,9 @@ export async function detectNpmScriptsForFolder(context: ExtensionContext, folde
|
||||||
let folderTasks: IFolderTaskItem[] = [];
|
let folderTasks: IFolderTaskItem[] = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (excludeRegex.test(Utils.basename(folder))) {
|
||||||
|
return folderTasks;
|
||||||
|
}
|
||||||
let relativePattern = new RelativePattern(folder.fsPath, '**/package.json');
|
let relativePattern = new RelativePattern(folder.fsPath, '**/package.json');
|
||||||
let paths = await workspace.findFiles(relativePattern, '**/node_modules/**');
|
let paths = await workspace.findFiles(relativePattern, '**/node_modules/**');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue