diff --git a/src/main.ts b/src/main.ts index 754a9c1..3408d6f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,12 +7,12 @@ import { show } from './show'; import { search } from './search'; import { listPublishers, createPublisher, deletePublisher, loginPublisher, logoutPublisher } from './store'; import { getLatestVersion } from './npm'; -import { CancellationToken, isCancelledError, log } from './util'; +import { CancellationToken, log } from './util'; import * as semver from 'semver'; import { isatty } from 'tty'; const pkg = require('../package.json'); -function fatal(message: any, ...args: any[]): void { +function fatal(message: any, ...args: any[]): void { if (message instanceof Error) { message = message.message; diff --git a/src/npm.ts b/src/npm.ts index 7548482..07fcac8 100644 --- a/src/npm.ts +++ b/src/npm.ts @@ -3,7 +3,7 @@ import * as fs from 'fs'; import * as cp from 'child_process'; import * as parseSemver from 'parse-semver'; import * as _ from 'lodash'; -import { CancellationToken, log } from './util'; +import { CancellationToken } from './util'; interface IOptions { cwd?: string; diff --git a/src/package.ts b/src/package.ts index ba2a420..c5275f4 100644 --- a/src/package.ts +++ b/src/package.ts @@ -17,11 +17,6 @@ import * as urljoin from 'url-join'; import { validatePublisher, validateExtensionName, validateVersion, validateEngineCompatibility, validateVSCodeTypesCompatibility } from './validation'; import { getDependencies } from './npm'; -interface IReadFile { - (filePath: string): Promise; - (filePath: string, encoding?: string): Promise; -} - const readFile = denodeify(fs.readFile); const unlink = denodeify(fs.unlink as any); const stat = denodeify(fs.stat); @@ -472,7 +467,7 @@ export class MarkdownProcessor extends BaseProcessor { } }); - $('svg').each((_, svg) => { + $('svg').each(() => { throw new Error(`SVG tags are not allowed in ${this.name}.`); }); @@ -761,7 +756,7 @@ export function readManifest(cwd = process.cwd(), nls = true): Promise } -export function toVsixManifest(assets: IAsset[], vsix: any, options: IPackageOptions = {}): Promise { +export function toVsixManifest(vsix: any): Promise { return readFile(vsixManifestTemplatePath, 'utf8') .then(vsixManifestTemplateStr => _.template(vsixManifestTemplateStr)) .then(vsixManifestTemplate => vsixManifestTemplate(vsix)); @@ -853,7 +848,7 @@ function collectFiles(cwd: string, useYarn = false, dependencyEntryPoints?: stri }); } -export function processFiles(processors: IProcessor[], files: IFile[], options: IPackageOptions = {}): Promise { +export function processFiles(processors: IProcessor[], files: IFile[]): Promise { const processedFiles = files.map(file => util.chain(file, processors, (file, processor) => processor.onFile(file))); return Promise.all(processedFiles).then(files => { @@ -861,7 +856,7 @@ export function processFiles(processors: IProcessor[], files: IFile[], options: const assets = _.flatten(processors.map(p => p.assets)); const vsix = processors.reduce((r, p) => ({ ...r, ...p.vsix }), { assets }); - return Promise.all([toVsixManifest(assets, vsix, options), toContentTypes(files)]).then(result => { + return Promise.all([toVsixManifest(vsix), toContentTypes(files)]).then(result => { return [ { path: 'extension.vsixmanifest', contents: new Buffer(result[0], 'utf8') }, { path: '[Content_Types].xml', contents: new Buffer(result[1], 'utf8') }, @@ -895,7 +890,7 @@ export function collect(manifest: Manifest, options: IPackageOptions = {}): Prom return collectFiles(cwd, useYarn, packagedDependencies, ignoreFile).then(fileNames => { const files = fileNames.map(f => ({ path: `extension/${f}`, localPath: path.join(cwd, f) })); - return processFiles(processors, files, options); + return processFiles(processors, files); }); } @@ -920,20 +915,16 @@ function getDefaultPackageName(manifest: Manifest): string { return `${manifest.name}-${manifest.version}.vsix`; } -function prepublish(cwd: string, manifest: Manifest, useYarn: boolean = false): Promise { +async function prepublish(cwd: string, manifest: Manifest, useYarn: boolean = false): Promise { if (!manifest.scripts || !manifest.scripts['vscode:prepublish']) { - return Promise.resolve(manifest); + return; } console.warn(`Executing prepublish script '${useYarn ? 'yarn' : 'npm'} run vscode:prepublish'...`); - return exec(`${useYarn ? 'yarn' : 'npm'} run vscode:prepublish`, { cwd, maxBuffer: 5000 * 1024 }) - .then(({ stdout, stderr }) => { - process.stdout.write(stdout); - process.stderr.write(stderr); - return Promise.resolve(manifest); - }) - .catch(err => Promise.reject(err.message)); + const { stdout, stderr } = await exec(`${useYarn ? 'yarn' : 'npm'} run vscode:prepublish`, { cwd, maxBuffer: 5000 * 1024 }); + process.stdout.write(stdout); + process.stderr.write(stderr); } async function getPackagePath(cwd: string, manifest: Manifest, options: IPackageOptions = {}): Promise { @@ -957,8 +948,8 @@ async function getPackagePath(cwd: string, manifest: Manifest, options: IPackage export async function pack(options: IPackageOptions = {}): Promise { const cwd = options.cwd || process.cwd(); - let manifest = await readManifest(cwd); - manifest = await prepublish(cwd, manifest, options.useYarn); + const manifest = await readManifest(cwd); + await prepublish(cwd, manifest, options.useYarn); const files = await collect(manifest, options); const jsFiles = files.filter(f => /\.js$/i.test(f.path)); @@ -996,7 +987,7 @@ export async function packageCommand(options: IPackageOptions = {}): Promise { return readManifest(cwd) - .then(manifest => collectFiles(cwd, useYarn, packagedDependencies, ignoreFile)); + .then(() => collectFiles(cwd, useYarn, packagedDependencies, ignoreFile)); } /** @@ -1005,6 +996,6 @@ export function listFiles(cwd = process.cwd(), useYarn = false, packagedDependen export function ls(cwd = process.cwd(), useYarn = false, packagedDependencies?: string[], ignoreFile?: string): Promise { return readManifest(cwd) .then(manifest => prepublish(cwd, manifest, useYarn)) - .then(manifest => collectFiles(cwd, useYarn, packagedDependencies, ignoreFile)) + .then(() => collectFiles(cwd, useYarn, packagedDependencies, ignoreFile)) .then(files => files.forEach(f => console.log(`${f}`))); } diff --git a/src/publicgalleryapi.ts b/src/publicgalleryapi.ts index 74feff9..cb47dea 100644 --- a/src/publicgalleryapi.ts +++ b/src/publicgalleryapi.ts @@ -1,19 +1,14 @@ import { HttpClient, HttpClientResponse } from 'typed-rest-client/HttpClient'; -import { - PublishedExtension, ExtensionQueryFlags, FilterCriteria, SortOrderType, - SortByType, ExtensionQueryFilterType, TypeInfo -} from 'azure-devops-node-api/interfaces/GalleryInterfaces'; +import { PublishedExtension, ExtensionQueryFlags, FilterCriteria, ExtensionQueryFilterType, TypeInfo } from 'azure-devops-node-api/interfaces/GalleryInterfaces'; import { IHeaders } from 'azure-devops-node-api/interfaces/common/VsoBaseInterfaces'; import { ContractSerializer } from 'azure-devops-node-api/Serialization'; export interface ExtensionQuery { - pageNumber?: number; - pageSize?: number; - sortBy?: SortByType; - sortOrder?: SortOrderType; - flags?: ExtensionQueryFlags[]; - criteria?: FilterCriteria[]; - assetTypes?: string[]; + readonly pageNumber?: number; + readonly pageSize?: number; + readonly flags?: ExtensionQueryFlags[]; + readonly criteria?: FilterCriteria[]; + readonly assetTypes?: string[]; } export class PublicGalleryAPI { @@ -29,8 +24,6 @@ export class PublicGalleryAPI { async extensionQuery({ pageNumber = 1, pageSize = 1, - sortBy = SortByType.Relevance, - sortOrder = SortOrderType.Default, flags = [], criteria = [], assetTypes = [], diff --git a/src/publish.ts b/src/publish.ts index 39c78cd..0966080 100644 --- a/src/publish.ts +++ b/src/publish.ts @@ -1,10 +1,9 @@ import * as fs from 'fs'; -import { ExtensionQueryFlags, PublishedExtension, ExtensionQueryFilterType, PagingDirection, SortByType, SortOrderType } from 'azure-devops-node-api/interfaces/GalleryInterfaces'; +import { ExtensionQueryFlags, PublishedExtension } from 'azure-devops-node-api/interfaces/GalleryInterfaces'; import { pack, readManifest, IPackage } from './package'; import * as tmp from 'tmp'; import { getPublisher } from './store'; import { getGalleryAPI, read, getPublishedUrl, log } from './util'; -import { validatePublisher } from './validation'; import { Manifest } from './manifest'; import * as denodeify from 'denodeify'; import * as yauzl from 'yauzl'; diff --git a/src/search.ts b/src/search.ts index 2dbb113..d91af33 100644 --- a/src/search.ts +++ b/src/search.ts @@ -4,7 +4,7 @@ import { tableView, wordTrim } from './viewutils'; const pageSize = 100; -export async function search(searchText: string, json: boolean = false, pageNumber: number = 1): Promise { +export async function search(searchText: string, json: boolean = false): Promise { const flags = []; const api = getPublicGalleryAPI(); const results = await api.extensionQuery({ diff --git a/src/test/package.test.ts b/src/test/package.test.ts index 8cb26ed..4b4597f 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -71,7 +71,7 @@ function _toVsixManifest(manifest: Manifest, files: IFile[]): Promise { const assets = _.flatten(processors.map(p => p.assets)); const vsix = processors.reduce((r, p) => ({ ...r, ...p.vsix }), { assets }); - return toVsixManifest(assets, vsix); + return toVsixManifest(vsix); }); } diff --git a/src/viewutils.ts b/src/viewutils.ts index 247b214..26366e6 100644 --- a/src/viewutils.ts +++ b/src/viewutils.ts @@ -13,16 +13,9 @@ const columns = process.stdout.columns ? process.stdout.columns : 80; // unicode charset. For now we use fallback icons when on windows. const useFallbackIcons = process.platform === 'win32'; -export const icons = useFallbackIcons? -{ - download: '\u{2193}', - star: '\u{2665}', - emptyStar: '\u{2022}', -} : { - download: '\u{2913}', - star: '\u{2605}', - emptyStar: '\u{2606}', -}; +export const icons = useFallbackIcons + ? { download: '\u{2193}', star: '\u{2665}', emptyStar: '\u{2022}', } + : { download: '\u{2913}', star: '\u{2605}', emptyStar: '\u{2606}', }; export function formatDate(date) { return date.toLocaleString(fixedLocale, format.date); } export function formatTime(date) { return date.toLocaleString(fixedLocale, format.time); } @@ -53,11 +46,11 @@ export function wordWrap(text: string, width: number = columns): string { return text .replace(/^\s+/, '') .split('') - .reduce(([out, buffer, pos], ch, i) => { + .reduce(([out, buffer, pos], ch) => { const nl = pos === maxWidth ? `\n${indent}` : ''; const newPos: number = nl ? 0 : +pos + 1; return / |-|,|\./.test(ch) ? - [`${out}${buffer}${ch}${nl}`, '', newPos] : [`${out}${nl}`, buffer+ch, newPos]; + [`${out}${buffer}${ch}${nl}`, '', newPos] : [`${out}${nl}`, buffer + ch, newPos]; }, [indent, '', 0]) .slice(0, 2) .join(''); diff --git a/tsconfig.json b/tsconfig.json index ac83d46..558af2d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,9 @@ "target": "es2015", "module": "commonjs", "declaration": true, - "outDir": "out" + "outDir": "out", + "noUnusedLocals": true, + "noUnusedParameters": true }, "include": [ "src"