Skip to content

Commit

Permalink
Merge commit 'refs/pull/294/head' of github.com:microsoft/vscode-vsce…
Browse files Browse the repository at this point in the history
… into pr/294
  • Loading branch information
joaomoreno committed Nov 28, 2019
2 parents c5a0e10 + 5477a63 commit 56f916b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export interface IListFilesOptions {
* no dependencies will be included.
*/
packagedDependencies?: string[];

/**
* The location of an alternative .vscodeignore file to be used.
* The `.vscodeignore` file located at the root of the project will be taken
* instead, if none is specified.
*/
ignoreFile?: string;
}

export interface IPublishVSIXOptions {
Expand Down Expand Up @@ -135,7 +142,7 @@ export function publish(options: IPublishOptions = {}): Promise<any> {
* Lists the files included in the extension's package.
*/
export function listFiles(options: IListFilesOptions = {}): Promise<string[]> {
return _listFiles(options.cwd, options.packageManager === PackageManager.Yarn, options.packagedDependencies);
return _listFiles(options.cwd, options.packageManager === PackageManager.Yarn, options.packagedDependencies, options.ignoreFile);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ module.exports = function (argv: string[]): void {
.description('Lists all the files that will be published')
.option('--yarn', 'Use yarn instead of npm')
.option('--packagedDependencies <path>', 'Select packages that should be published only (includes dependencies)', (val, all) => all ? all.concat(val) : [val], undefined)
.action(({ yarn, packagedDependencies }) => main(ls(undefined, yarn, packagedDependencies)));
.option('--ignoreFile [path]', 'Indicate alternative .vscodeignore')
.action(({ yarn, packagedDependencies, ignoreFile }) => main(ls(undefined, yarn, packagedDependencies, ignoreFile)));

program
.command('package')
Expand All @@ -72,7 +73,8 @@ module.exports = function (argv: string[]): void {
.option('--baseContentUrl [url]', 'Prepend all relative links in README.md with this url.')
.option('--baseImagesUrl [url]', 'Prepend all relative image links in README.md with this url.')
.option('--yarn', 'Use yarn instead of npm')
.action(({ out, baseContentUrl, baseImagesUrl, yarn }) => main(packageCommand({ packagePath: out, baseContentUrl, baseImagesUrl, useYarn: yarn })));
.option('--ignoreFile [path]', 'Indicate alternative .vscodeignore')
.action(({ out, baseContentUrl, baseImagesUrl, yarn, ignoreFile }) => main(packageCommand({ packagePath: out, baseContentUrl, baseImagesUrl, useYarn: yarn, ignoreFile })));

program
.command('publish [<version>]')
Expand All @@ -84,7 +86,8 @@ module.exports = function (argv: string[]): void {
.option('--baseImagesUrl [url]', 'Prepend all relative image links in README.md with this url.')
.option('--yarn', 'Use yarn instead of npm while packing extension files')
.option('--noVerify')
.action((version, { pat, message, packagePath, baseContentUrl, baseImagesUrl, yarn, noVerify }) => main(publish({ pat, commitMessage: message, version, packagePath, baseContentUrl, baseImagesUrl, useYarn: yarn, noVerify })));
.option('--ignoreFile [path]', 'Indicate alternative .vscodeignore')
.action((version, { pat, message, packagePath, baseContentUrl, baseImagesUrl, yarn, noVerify, ignoreFile }) => main(publish({ pat, commitMessage: message, version, packagePath, baseContentUrl, baseImagesUrl, useYarn: yarn, noVerify, ignoreFile })));

program
.command('unpublish [<extensionid>]')
Expand Down
18 changes: 10 additions & 8 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface IPackageOptions {
baseImagesUrl?: string;
useYarn?: boolean;
dependencyEntryPoints?: string[];
ignoreFile?: string;
}

export interface IProcessor {
Expand Down Expand Up @@ -827,12 +828,12 @@ function collectAllFiles(cwd: string, useYarn = false, dependencyEntryPoints?: s
});
}

function collectFiles(cwd: string, useYarn = false, dependencyEntryPoints?: string[]): Promise<string[]> {
function collectFiles(cwd: string, useYarn = false, dependencyEntryPoints?: string[], ignoreFile?: string): Promise<string[]> {
return collectAllFiles(cwd, useYarn, dependencyEntryPoints).then(files => {
files = files.filter(f => !/\r$/m.test(f));

return readFile(path.join(cwd, '.vscodeignore'), 'utf8')
.catch<string>(err => err.code !== 'ENOENT' ? Promise.reject(err) : Promise.resolve(''))
return readFile(ignoreFile ? ignoreFile : path.join(cwd, '.vscodeignore'), 'utf8')
.catch<string>(err => err.code !== 'ENOENT' ? Promise.reject(err) : ignoreFile ? Promise.reject(err) : Promise.resolve(''))

// Parse raw ignore by splitting output into lines and filtering out empty lines and comments
.then(rawIgnore => rawIgnore.split(/[\n\r]/).map(s => s.trim()).filter(s => !!s).filter(i => !/^\s*#/.test(i)))
Expand Down Expand Up @@ -888,9 +889,10 @@ export function collect(manifest: Manifest, options: IPackageOptions = {}): Prom
const cwd = options.cwd || process.cwd();
const useYarn = options.useYarn || false;
const packagedDependencies = options.dependencyEntryPoints || undefined;
const ignoreFile = options.ignoreFile || undefined;
const processors = createDefaultProcessors(manifest, options);

return collectFiles(cwd, useYarn, packagedDependencies).then(fileNames => {
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);
Expand Down Expand Up @@ -992,17 +994,17 @@ export async function packageCommand(options: IPackageOptions = {}): Promise<any
/**
* Lists the files included in the extension's package. Does not run prepublish.
*/
export function listFiles(cwd = process.cwd(), useYarn = false, packagedDependencies?: string[]): Promise<string[]> {
export function listFiles(cwd = process.cwd(), useYarn = false, packagedDependencies?: string[], ignoreFile?: string): Promise<string[]> {
return readManifest(cwd)
.then(manifest => collectFiles(cwd, useYarn, packagedDependencies));
.then(manifest => collectFiles(cwd, useYarn, packagedDependencies, ignoreFile));
}

/**
* Lists the files included in the extension's package. Runs prepublish.
*/
export function ls(cwd = process.cwd(), useYarn = false, packagedDependencies?: string[]): Promise<void> {
export function ls(cwd = process.cwd(), useYarn = false, packagedDependencies?: string[], ignoreFile?: string): Promise<void> {
return readManifest(cwd)
.then(manifest => prepublish(cwd, manifest, useYarn))
.then(manifest => collectFiles(cwd, useYarn, packagedDependencies))
.then(manifest => collectFiles(cwd, useYarn, packagedDependencies, ignoreFile))
.then(files => files.forEach(f => console.log(`${f}`)));
}
4 changes: 3 additions & 1 deletion src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface IPublishOptions {
baseImagesUrl?: string;
useYarn?: boolean;
noVerify?: boolean;
ignoreFile?: string;
}

function versionBump(cwd: string = process.cwd(), version?: string, commitMessage?: string): Promise<void> {
Expand Down Expand Up @@ -152,10 +153,11 @@ export function publish(options: IPublishOptions = {}): Promise<any> {
const baseContentUrl = options.baseContentUrl;
const baseImagesUrl = options.baseImagesUrl;
const useYarn = options.useYarn;
const ignoreFile = options.ignoreFile;

promise = versionBump(options.cwd, options.version, options.commitMessage)
.then(() => tmpName())
.then(packagePath => pack({ packagePath, cwd, baseContentUrl, baseImagesUrl, useYarn }));
.then(packagePath => pack({ packagePath, cwd, baseContentUrl, baseImagesUrl, useYarn, ignoreFile }));
}

return promise.then(({ manifest, packagePath }) => {
Expand Down

0 comments on commit 56f916b

Please sign in to comment.