beachball
Advanced tools
Comparing version 2.36.1 to 2.37.0
@@ -48,3 +48,3 @@ "use strict"; | ||
break; | ||
default: | ||
case 'change': | ||
const { isChangeNeeded } = (0, validate_1.validate)(options, { allowMissingChangeFiles: true }); | ||
@@ -57,2 +57,4 @@ if (!isChangeNeeded && !options.package) { | ||
break; | ||
default: | ||
throw new Error('Invalid command: ' + options.command); | ||
} | ||
@@ -59,0 +61,0 @@ })().catch(e => { |
@@ -10,19 +10,16 @@ "use strict"; | ||
function getScopedPackages(options, packageInfos) { | ||
if (!options.scope) { | ||
const { scope, path: cwd } = options; | ||
if (!scope) { | ||
return Object.keys(packageInfos); | ||
} | ||
let includeScopes = options.scope.filter(s => !s.startsWith('!')); | ||
includeScopes = includeScopes.length > 0 ? includeScopes : ['**/*', '', '*']; | ||
const excludeScopes = options.scope.filter(s => s.startsWith('!')); | ||
const scopedPackages = []; | ||
for (let [pkgName, info] of Object.entries(packageInfos)) { | ||
const relativePath = path_1.default.relative(options.path, path_1.default.dirname(info.packageJsonPath)); | ||
const shouldInclude = (0, isPathIncluded_1.isPathIncluded)(relativePath, includeScopes, excludeScopes); | ||
if (shouldInclude) { | ||
scopedPackages.push(pkgName); | ||
} | ||
} | ||
return scopedPackages; | ||
let includeScopes = scope.filter(s => !s.startsWith('!')); | ||
// If there were no include scopes, include all paths by default | ||
includeScopes = includeScopes.length ? includeScopes : true; | ||
const excludeScopes = scope.filter(s => s.startsWith('!')); | ||
return Object.keys(packageInfos).filter(pkgName => { | ||
const packagePath = path_1.default.dirname(packageInfos[pkgName].packageJsonPath); | ||
return (0, isPathIncluded_1.isPathIncluded)(path_1.default.relative(cwd, packagePath), includeScopes, excludeScopes); | ||
}); | ||
} | ||
exports.getScopedPackages = getScopedPackages; | ||
//# sourceMappingURL=getScopedPackages.js.map |
/** | ||
* Check if a relative path should be included given include and exclude patterns using minimatch. | ||
* @param relativePath Relative path to check. | ||
* @param include Include pattern(s). If `true`, include all paths except those excluded. | ||
* @param exclude Exclude pattern(s). Currently these must be **negated** patterns: | ||
* e.g. if you want to exclude `packages/foo`, you must specify `exclude` as `!packages/foo`. | ||
* (This will be fixed in a future major version.) | ||
*/ | ||
export declare function isPathIncluded(relativePath: string, include: string | string[], exclude?: string | string[]): boolean; | ||
export declare function isPathIncluded(relativePath: string, include: string | string[] | true, exclude?: string | string[]): boolean; | ||
//# sourceMappingURL=isPathIncluded.d.ts.map |
@@ -10,9 +10,26 @@ "use strict"; | ||
* Check if a relative path should be included given include and exclude patterns using minimatch. | ||
* @param relativePath Relative path to check. | ||
* @param include Include pattern(s). If `true`, include all paths except those excluded. | ||
* @param exclude Exclude pattern(s). Currently these must be **negated** patterns: | ||
* e.g. if you want to exclude `packages/foo`, you must specify `exclude` as `!packages/foo`. | ||
* (This will be fixed in a future major version.) | ||
*/ | ||
function isPathIncluded(relativePath, include, exclude) { | ||
const includePatterns = typeof include === 'string' ? [include] : include; | ||
let shouldInclude = includePatterns.reduce((included, pattern) => included || (0, minimatch_1.default)(relativePath, pattern), false); | ||
if (exclude) { | ||
let shouldInclude; | ||
if (include === true) { | ||
shouldInclude = true; | ||
} | ||
else { | ||
const includePatterns = typeof include === 'string' ? [include] : include; | ||
shouldInclude = includePatterns.some(pattern => (0, minimatch_1.default)(relativePath, pattern)); | ||
} | ||
if (exclude?.length && shouldInclude) { | ||
// TODO: this is weird/buggy--it assumes that exclude patterns are always negated, | ||
// which intuitively (or comparing to other tools) is not how it should work. | ||
// If this is fixed, updates will be needed in: | ||
// - getScopedPackages() | ||
// - ChangelogGroupOptions | ||
// - VersionGroupOptions | ||
const excludePatterns = typeof exclude === 'string' ? [exclude] : exclude; | ||
shouldInclude = excludePatterns.reduce((excluded, pattern) => excluded && (0, minimatch_1.default)(relativePath, pattern), shouldInclude); | ||
shouldInclude = excludePatterns.every(pattern => (0, minimatch_1.default)(relativePath, pattern)); | ||
} | ||
@@ -19,0 +36,0 @@ return shouldInclude; |
import { CliOptions } from '../types/BeachballOptions'; | ||
export declare function getCliOptions(argv: string[]): CliOptions; | ||
export declare function getCliOptions(argv: string[], disableCache?: boolean): CliOptions; | ||
//# sourceMappingURL=getCliOptions.d.ts.map |
@@ -10,7 +10,91 @@ "use strict"; | ||
const env_1 = require("../env"); | ||
// For camelCased options, yargs will automatically accept them with-dashes too. | ||
const arrayOptions = ['disallowedChangeTypes', 'package', 'scope']; | ||
const booleanOptions = [ | ||
'all', | ||
'bump', | ||
'bumpDeps', | ||
'commit', | ||
'disallowDeletedChangeFiles', | ||
'fetch', | ||
'forceVersions', | ||
'gitTags', | ||
'help', | ||
'keepChangeFiles', | ||
'new', | ||
'publish', | ||
'push', | ||
'verbose', | ||
'version', | ||
'yes', | ||
]; | ||
const numberOptions = ['depth', 'gitTimeout', 'retries', 'timeout']; | ||
const stringOptions = [ | ||
'access', | ||
'authType', | ||
'branch', | ||
'canaryName', | ||
'changehint', | ||
'configPath', | ||
'dependentChangeType', | ||
'fromRef', | ||
'message', | ||
'prereleasePrefix', | ||
'registry', | ||
'tag', | ||
'token', | ||
'type', | ||
]; | ||
/** Type hack to verify that an array includes all keys of a type */ | ||
const allKeysOfType = () => (...x) => x; | ||
// Verify that all the known CLI options have types specified, to ensure correct parsing. | ||
// | ||
// NOTE: If a prop is missing, this will have a somewhat misleading error: | ||
// Argument of type '"disallowedChangeTypes"' is not assignable to parameter of type '"tag" | "version"' | ||
// | ||
// To fix, add the missing names after "parameter of type" ("tag" and "version" in this example) | ||
// to the appropriate array above. | ||
const knownOptions = allKeysOfType()(...arrayOptions, ...booleanOptions, ...numberOptions, ...stringOptions, | ||
// these options are filled in below, not respected from the command line | ||
'path', 'command'); | ||
const parserOptions = { | ||
configuration: { | ||
'boolean-negation': true, | ||
'camel-case-expansion': true, | ||
'dot-notation': false, | ||
'duplicate-arguments-array': true, | ||
'flatten-duplicate-arrays': true, | ||
'greedy-arrays': true, | ||
'parse-numbers': true, | ||
'parse-positional-numbers': false, | ||
'short-option-groups': false, | ||
'strip-aliased': true, | ||
'strip-dashed': true, | ||
}, | ||
// spread to get rid of readonly... | ||
array: [...arrayOptions], | ||
boolean: [...booleanOptions], | ||
number: [...numberOptions], | ||
string: [...stringOptions], | ||
alias: { | ||
authType: ['a'], | ||
branch: ['b'], | ||
configPath: ['c', 'config'], | ||
forceVersions: ['force'], | ||
fromRef: ['since'], | ||
help: ['h', '?'], | ||
message: ['m'], | ||
package: ['p'], | ||
registry: ['r'], | ||
tag: ['t'], | ||
token: ['n'], | ||
version: ['v'], | ||
yes: ['y'], | ||
}, | ||
}; | ||
let cachedCliOptions; | ||
function getCliOptions(argv) { | ||
function getCliOptions(argv, disableCache) { | ||
// Special case caching to process.argv which should be immutable | ||
if (argv === process.argv) { | ||
if (env_1.env.beachballDisableCache || !cachedCliOptions) { | ||
if (disableCache || env_1.env.beachballDisableCache || !cachedCliOptions) { | ||
cachedCliOptions = getCliOptionsUncached(process.argv); | ||
@@ -27,23 +111,5 @@ } | ||
// Be careful not to mutate the input argv | ||
const trimmedArgv = [...argv].splice(2); | ||
const args = (0, yargs_parser_1.default)(trimmedArgv, { | ||
string: ['branch', 'tag', 'message', 'package', 'since', 'dependent-change-type', 'config'], | ||
array: ['scope', 'disallowed-change-types'], | ||
boolean: ['git-tags', 'keep-change-files', 'force', 'disallow-deleted-change-files', 'no-commit', 'fetch'], | ||
number: ['depth'], | ||
alias: { | ||
authType: ['a'], | ||
branch: ['b'], | ||
config: ['c'], | ||
tag: ['t'], | ||
registry: ['r'], | ||
message: ['m'], | ||
token: ['n'], | ||
help: ['h', '?'], | ||
yes: ['y'], | ||
package: ['p'], | ||
version: ['v'], | ||
}, | ||
}); | ||
const { _, ...restArgs } = args; | ||
const trimmedArgv = argv.slice(2); | ||
const args = (0, yargs_parser_1.default)(trimmedArgv, parserOptions); | ||
const { _: positionalArgs, ...options } = args; | ||
let cwd; | ||
@@ -56,17 +122,14 @@ try { | ||
} | ||
if (positionalArgs.length > 1) { | ||
throw new Error(`Only one positional argument (the command) is allowed. Received: ${positionalArgs.join(' ')}`); | ||
} | ||
const cliOptions = { | ||
...(_.length > 0 && { command: _[0] }), | ||
...restArgs, | ||
...options, | ||
command: positionalArgs.length ? String(positionalArgs[0]) : 'change', | ||
path: cwd, | ||
fromRef: args.since, | ||
keepChangeFiles: args['keep-change-files'], | ||
disallowDeletedChangeFiles: args['disallow-deleted-change-files'], | ||
forceVersions: args.force, | ||
configPath: args.config, | ||
}; | ||
const disallowedChangeTypesArgs = args['disallowed-change-types']; | ||
if (disallowedChangeTypesArgs) { | ||
cliOptions.disallowedChangeTypes = disallowedChangeTypesArgs; | ||
} | ||
if (args.branch) { | ||
// TODO: This logic assumes the first segment of any branch name with a slash must be the remote, | ||
// which is not necessarily accurate. Ideally we should check if a remote with that name exists, | ||
// and if not, perform the default remote lookup. | ||
cliOptions.branch = | ||
@@ -80,4 +143,26 @@ args.branch.indexOf('/') > -1 | ||
} | ||
for (const key of Object.keys(cliOptions)) { | ||
const value = cliOptions[key]; | ||
if (value === undefined) { | ||
delete cliOptions[key]; | ||
} | ||
else if (typeof value === 'number' && isNaN(value)) { | ||
throw new Error(`Non-numeric value passed for numeric option "${key}"`); | ||
} | ||
else if (knownOptions.includes(key)) { | ||
if (Array.isArray(value) && !arrayOptions.includes(key)) { | ||
throw new Error(`Option "${key}" only accepts a single value. Received: ${value.join(' ')}`); | ||
} | ||
} | ||
else if (value === 'true') { | ||
// For unknown arguments like --foo=true or --bar=false, yargs will handle the value as a string. | ||
// Convert it to a boolean to avoid subtle bugs. | ||
cliOptions[key] = true; | ||
} | ||
else if (value === 'false') { | ||
cliOptions[key] = false; | ||
} | ||
} | ||
return cliOptions; | ||
} | ||
//# sourceMappingURL=getCliOptions.js.map |
@@ -7,3 +7,3 @@ import { AuthType } from './Auth'; | ||
export declare type BeachballOptions = CliOptions & RepoOptions & PackageOptions; | ||
export interface CliOptions extends Pick<RepoOptions, 'access' | 'branch' | 'bumpDeps' | 'changehint' | 'disallowedChangeTypes' | 'fetch' | 'gitTags' | 'message' | 'path' | 'prereleasePrefix' | 'publish' | 'push' | 'registry' | 'retries' | 'scope' | 'tag' | 'depth'> { | ||
export interface CliOptions extends Pick<RepoOptions, 'access' | 'branch' | 'bumpDeps' | 'changehint' | 'depth' | 'disallowedChangeTypes' | 'fetch' | 'gitTags' | 'message' | 'path' | 'prereleasePrefix' | 'publish' | 'push' | 'registry' | 'retries' | 'scope' | 'tag'> { | ||
all: boolean; | ||
@@ -158,5 +158,12 @@ authType: AuthType; | ||
export interface VersionGroupOptions { | ||
/** minimatch pattern (or array of minimatch) to detect which packages should be included in this group */ | ||
include: string | string[]; | ||
/** minimatch pattern (or array of minimatch) to detect which packages should be excluded in this group */ | ||
/** | ||
* minimatch pattern (or array of minimatch) to detect which packages should be included in this group. | ||
* If `true`, include all packages except those excluded by `exclude`. | ||
*/ | ||
include: string | string[] | true; | ||
/** | ||
* minimatch pattern (or array of minimatch) to detect which packages should be excluded in this group. | ||
* Currently this must use **negated patterns only**: e.g. if you want to exclude `packages/foo`, | ||
* you must specify `exclude` as `!packages/foo`. (This will be fixed in a future major version.) | ||
*/ | ||
exclude?: string | string[]; | ||
@@ -163,0 +170,0 @@ disallowedChangeTypes: ChangeType[] | null; |
@@ -34,5 +34,12 @@ import { ChangelogJson, PackageChangelog, ChangelogEntry } from './ChangeLog'; | ||
masterPackageName: string; | ||
/** minimatch pattern (or array of minimatch) to detect which packages should be included in this group */ | ||
include: string | string[]; | ||
/** minimatch pattern (or array of minimatch) to detect which packages should be excluded in this group */ | ||
/** | ||
* minimatch pattern (or array of minimatch) to detect which packages should be included in this group. | ||
* If `true`, include all packages except those excluded by `exclude`. | ||
*/ | ||
include: string | string[] | true; | ||
/** | ||
* minimatch pattern (or array of minimatch) to detect which packages should be excluded in this group. | ||
* Currently this must use **negated patterns only**: e.g. if you want to exclude `packages/foo`, | ||
* you must specify `exclude` as `!packages/foo`. (This will be fixed in a future major version.) | ||
*/ | ||
exclude?: string | string[]; | ||
@@ -39,0 +46,0 @@ changelogPath: string; |
{ | ||
"name": "beachball", | ||
"version": "2.36.1", | ||
"version": "2.37.0", | ||
"description": "The Sunniest Semantic Version Bumper", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
368606
4666