Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Some reveiw changes
  • Loading branch information
alexr00 committed Sep 24, 2020
commit 92178247e9a2dd9b1be3d7c09dcd56c9b04f1171
2 changes: 1 addition & 1 deletion extensions/npm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The extension fetches data from https://registry.npmjs.org and https://registry.

- `npm.autoDetect` - Enable detecting scripts as tasks, the default is `on`.
- `npm.runSilent` - Run npm script with the `--silent` option, the default is `false`.
- `npm.packageManager` - The package manager used to run the scripts: `auto`, `npm`, `yarn` or `pnpm`, the default is `auto`.
- `npm.packageManager` - The package manager used to run the scripts: `auto`, `npm`, `yarn` or `pnpm`, the default is `auto`, which detects your package manager based on your files.
- `npm.exclude` - Glob patterns for folders that should be excluded from automatic script detection. The pattern is matched against the **absolute path** of the package.json. For example, to exclude all test folders use '**/test/**'.
- `npm.enableScriptExplorer` - Enable an explorer view for npm scripts.
- `npm.scriptExplorerAction` - The default click action: `open` or `run`, the default is `open`.
Expand Down
1 change: 0 additions & 1 deletion extensions/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"find-yarn-workspace-root2": "^1.2.22",
"jsonc-parser": "^2.2.1",
"minimatch": "^3.0.4",
"path-exists": "^4.0.0",
"request-light": "^0.4.0",
"vscode-nls": "^4.1.1",
"which-pm": "^2.0.0"
Expand Down
1 change: 0 additions & 1 deletion extensions/npm/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"config.npm.scriptExplorerAction": "The default click action used in the npm scripts explorer: `open` or `run`, the default is `open`.",
"config.npm.enableRunFromFolder": "Enable running npm scripts contained in a folder from the Explorer context menu.",
"config.npm.fetchOnlinePackageInfo": "Fetch data from https://registry.npmjs.org and https://registry.bower.io to provide auto-completion and information on hover features on npm dependencies.",
"npm.multiplePMWarning": "Found multiple lockfiles. Using {0} as the preferred package manager.",
"npm.parseError": "Npm task detection: failed to parse the file {0}",
"taskdef.script": "The npm script to customize.",
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be omitted.",
Expand Down
31 changes: 19 additions & 12 deletions extensions/npm/src/preferred-pm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
*--------------------------------------------------------------------------------------------*/

import { findWorkspaceRoot } from 'find-yarn-workspace-root2';
import findUp from 'find-up';
import path from 'path';
import pathExists from 'path-exists';
import whichPM from 'which-pm';
import findUp = require('find-up');
import * as path from 'path';
import whichPM = require('which-pm');
import { Uri, workspace } from 'vscode';

const isPNPMPreferred = async (pkgPath: string) => {
async function pathExists(filePath: string) {
try {
await workspace.fs.stat(Uri.file(filePath));
} catch {
return false;
}
return true;
}

async function isPNPMPreferred(pkgPath: string) {
if (await pathExists(path.join(pkgPath, 'pnpm-lock.yaml'))) {
return true;
}
Expand All @@ -21,9 +30,9 @@ const isPNPMPreferred = async (pkgPath: string) => {
}

return false;
};
}

const isYarnPreferred = async (pkgPath: string) => {
async function isYarnPreferred(pkgPath: string) {
if (await pathExists(path.join(pkgPath, 'yarn.lock'))) {
return true;
}
Expand All @@ -35,13 +44,13 @@ const isYarnPreferred = async (pkgPath: string) => {
} catch (err) { }

return false;
};
}

const isNPMPreferred = (pkgPath: string) => {
return pathExists(path.join(pkgPath, 'package-lock.json'));
};

const findPreferredPM = async (pkgPath: string) => {
export async function findPreferredPM(pkgPath: string): Promise<{ name: string, multiplePMDetected: boolean }> {
const detectedPackageManagers = [];

if (await isNPMPreferred(pkgPath)) {
Expand All @@ -68,6 +77,4 @@ const findPreferredPM = async (pkgPath: string) => {
name: detectedPackageManagers[0] || 'npm',
multiplePMDetected
};
};

export default findPreferredPM;
}
7 changes: 3 additions & 4 deletions extensions/npm/src/scriptHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ export class NpmScriptHoverProvider implements HoverProvider {
return `${prefix}[${label}](command:${cmd}?${encodedArgs} "${tooltip}")`;
}

public runScriptFromHover(args: any) {
public async runScriptFromHover(args: any) {
let script = args.script;
let documentUri = args.documentUri;
let folder = workspace.getWorkspaceFolder(documentUri);
if (folder) {
createTask(script, `run ${script}`, folder, documentUri).then((task) => {
tasks.executeTask(task);
});
let task = await createTask(script, `run ${script}`, folder, documentUri);
tasks.executeTask(task);
}
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/npm/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
} from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import * as minimatch from 'minimatch';
import * as nls from 'vscode-nls';
import minimatch from 'minimatch';
import { JSONVisitor, visit, ParseErrorCode } from 'jsonc-parser';
import findPreferredPM from './preferred-pm';
import { findPreferredPM } from './preferred-pm';

const localize = nls.loadMessageBundle();

Expand Down
3 changes: 1 addition & 2 deletions extensions/npm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"extends": "../shared.tsconfig.json",
"compilerOptions": {
"outDir": "./out",
"esModuleInterop": true,
"outDir": "./out"
},
"include": [
"src/**/*"
Expand Down