diff --git a/README.md b/README.md index fa43956c..88bda3be 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ You can configure the behavior of `vsce` by using CLI flags (run `vsce --help` t $ npx @vscode/vsce publish --baseImagesUrl https://my.custom/base/images/url ``` -Or you can also set them in the `package.json`, so that you avoid having to retype the common options again. Example: +You can define the options for `publish` and `package` the `package.json` under the `vsce` property, so that you avoid having to retype the common options again. Example: ```jsonc // package.json diff --git a/src/manifest.ts b/src/manifest.ts index cb2d8234..eacbb756 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -1,3 +1,6 @@ +import type { IPackageOptions } from "./package"; +import type { IPublishOptions } from "./publish"; + export interface Person { name: string; url?: string; @@ -110,7 +113,7 @@ export interface ManifestPackage { files?: string[]; // vsce - vsce?: any; + vsce?: Partial; // not supported (npm) // bin diff --git a/src/package.ts b/src/package.ts index f795bfc1..ed645abc 100644 --- a/src/package.ts +++ b/src/package.ts @@ -2040,6 +2040,7 @@ interface ILSOptions { export async function ls(options: ILSOptions = {}): Promise { const cwd = process.cwd(); const manifest = await readManifest(cwd); + util.patchOptionsWithManifest(options, manifest); const files = await listFiles({ ...options, cwd, manifest }); diff --git a/src/util.ts b/src/util.ts index b18a4777..d7fde8bb 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,6 +8,8 @@ import { PublicGalleryAPI } from './publicgalleryapi'; import { ISecurityRolesApi } from 'azure-devops-node-api/SecurityRolesApi'; import { ManifestPackage } from './manifest'; import { EOL } from 'os'; +import type { IPublishOptions } from './publish'; +import type { IPackageOptions } from './package'; const __read = promisify<_read.Options, string>(_read); export function read(prompt: string, options: _read.Options = {}): Promise { @@ -171,16 +173,22 @@ export const log = { error: _log.bind(null, LogMessageType.ERROR) as LogFn, }; -export function patchOptionsWithManifest(options: any, manifest: ManifestPackage): void { +type Writable = { + -readonly [key in keyof T]: T[key]; +}; +type PatchableOptions = IPublishOptions | IPackageOptions; + +export function patchOptionsWithManifest(options: PatchableOptions, manifest: ManifestPackage): void { if (!manifest.vsce) { return; } for (const key of Object.keys(manifest.vsce)) { - const optionsKey = key === 'yarn' ? 'useYarn' : key; + const optionsKey = (key === 'yarn' ? 'useYarn' : key) as keyof PatchableOptions; if (options[optionsKey] === undefined) { - options[optionsKey] = manifest.vsce[key]; + const value = manifest.vsce[key as keyof typeof manifest.vsce]; + (options as Writable)[optionsKey] = value as any; } } } @@ -229,7 +237,7 @@ export async function generateFileStructureTree(rootFolder: string, filePaths: { // Create the node if it doesn't exist if (!currentLevel[part]) { if (isFile) { - // The file size is stored in the leaf node, + // The file size is stored in the leaf node, currentLevel[part] = 0; } else { // The folder size is stored in the folder node