lib/createInlinePluginCreator.js
/**
	 * Create an inline plugin for an individual package in a multirelease.
	 * This is called once per package and returns the inline plugin used for semanticRelease()
	 *
	 * @param {Package} pkg The package this function is being called on.
	 * @returns {Object} A semantic-release inline plugin containing plugin step functions.
	 *
	 * @internal
	 */
Create an inline plugin for an individual package in a multirelease.
This is called once per package and returns the inline plugin used for semanticRelease()

@param {Package} pkg The package this function is being called on.
@returns {Object} A semantic-release inline plugin containing plugin step functions.

@internal
Create an inline plugin for an individual package in a multirelease . This is called once per package and returns the inline plugin used for semanticRelease () @param { Package } pkg The package this function is being called on . @returns { Object } A semantic - release inline plugin containing plugin step functions . @internal
function createInlinePlugin(pkg) {
		const { plugins, dir, name } = pkg;
		const next = () => {
			pkg._tagged = true;
			emit(
				"_readyForTagging",
				todo().find((p) => p._nextType && !p._tagged)
			);
		};
		const verifyConditions = async (pluginOptions, context) => {
			Object.assign(context.options, context.options._pkgOptions);
			Object.assign(pkg.loggerRef, context.logger);
			pkg._ready = true;
			emit(
				"_readyForRelease",
				todo().find((p) => !p._ready)
			);
			const res = await plugins.verifyConditions(context);
			debug("verified conditions: %s", pkg.name);
			return res;
		};
		const analyzeCommits = async (pluginOptions, context) => {
			pkg._preRelease = context.branch.prerelease || null;
			pkg._branch = context.branch.name;
			const firstParentBranch = flags.firstParent ? context.branch.name : undefined;
			const commits = await getCommitsFiltered(
				cwd,
				dir,
				context.lastRelease ? context.lastRelease.gitHead : undefined,
				context.nextRelease ? context.nextRelease.gitHead : undefined,
				firstParentBranch
			);
			context.commits = commits;
			pkg._lastRelease = context.lastRelease;
			pkg._nextType = await plugins.analyzeCommits(context);
			pkg._analyzed = true;
			await waitForAll("_analyzed");
			pkg._nextType = resolveReleaseType(pkg, flags.deps.bump, flags.deps.release);
			debug("commits analyzed: %s", pkg.name);
			debug("release type: %s", pkg._nextType);
			return pkg._nextType;
		};
		const generateNotes = async (pluginOptions, context) => {
			pkg._nextRelease = context.nextRelease;
			await waitForAll("_nextRelease", (p) => p._nextType);
			const notes = [];
			if (context.lastRelease && context.lastRelease.gitTag) {
				if (!context.lastRelease.gitHead || context.lastRelease.gitHead === context.lastRelease.gitTag) {
					context.lastRelease.gitHead = await getTagHead(context.lastRelease.gitTag, {
						cwd: context.cwd,
						env: context.env,
					});
				}
			}
			const firstParentBranch = flags.firstParent ? context.branch.name : undefined;
			const commits = await getCommitsFiltered(
				cwd,
				dir,
				context.lastRelease ? context.lastRelease.gitHead : undefined,
				context.nextRelease ? context.nextRelease.gitHead : undefined,
				firstParentBranch
			);
			context.commits = commits;
			const subs = await plugins.generateNotes(context);
			if (subs) notes.push(subs.replace(/^(#+) (\[?\d+\.\d+\.\d+\]?)/, `$1 ${name} $2`));
			const upgrades = pkg.localDeps.filter((d) => d._nextRelease);
			if (upgrades.length) {
				notes.push(`### Dependencies`);
				const bullets = upgrades.map((d) => `* **${d.name}:** upgraded to ${d._nextRelease.version}`);
				notes.push(bullets.join("\n"));
			}
			debug("notes generated: %s", pkg.name);
			if (pkg.options.dryRun) {
				next();
			}
			return notes.join("\n\n");
		};
		const prepare = async (pluginOptions, context) => {
			getLucky("_readyForTagging", pkg);
			await waitFor("_readyForTagging", pkg);
			updateManifestDeps(pkg);
			pkg._depsUpdated = true;
			const res = await plugins.prepare(context);
			pkg._prepared = true;
			debug("prepared: %s", pkg.name);
			return res;
		};
		const publish = async (pluginOptions, context) => {
			next();
			const res = await plugins.publish(context);
			pkg._published = true;
			debug("published: %s", pkg.name);
			return res.length ? res[0] : {};
		};
		const inlinePlugin = {
			verifyConditions,
			analyzeCommits,
			generateNotes,
			prepare,
			publish,
		};
		Object.keys(inlinePlugin).forEach((type) =>
			Reflect.defineProperty(inlinePlugin[type], "pluginName", {
				value: "Inline plugin",
				writable: false,
				enumerable: true,
			})
		);
		debug("inlinePlugin created: %s", pkg.name);
		return inlinePlugin;
	}
function createInlinePlugin ( pkg ) { const { plugins , dir , name } = pkg ; const next = ( ) => { pkg . _tagged = true ; emit ( "_readyForTagging" , todo ( ) . find ( ( p ) => p . _nextType && ! p . _tagged ) ) ; } ; const verifyConditions = async ( pluginOptions , context ) => { Object . assign ( context . options , context . options . _pkgOptions ) ; Object . assign ( pkg . loggerRef , context . logger ) ; pkg . _ready = true ; emit ( "_readyForRelease" , todo ( ) . find ( ( p ) => ! p . _ready ) ) ; const res = await plugins . verifyConditions ( context ) ; debug ( "verified conditions: %s" , pkg . name ) ; return res ; } ; const analyzeCommits = async ( pluginOptions , context ) => { pkg . _preRelease = context . branch . prerelease || null ; pkg . _branch = context . branch . name ; const firstParentBranch = flags . firstParent ? context . branch . name : undefined ; const commits = await getCommitsFiltered ( cwd , dir , context . lastRelease ? context . lastRelease . gitHead : undefined , context . nextRelease ? context . nextRelease . gitHead : undefined , firstParentBranch ) ; context . commits = commits ; pkg . _lastRelease = context . lastRelease ; pkg . _nextType = await plugins . analyzeCommits ( context ) ; pkg . _analyzed = true ; await waitForAll ( "_analyzed" ) ; pkg . _nextType = resolveReleaseType ( pkg , flags . deps . bump , flags . deps . release ) ; debug ( "commits analyzed: %s" , pkg . name ) ; debug ( "release type: %s" , pkg . _nextType ) ; return pkg . _nextType ; } ; const generateNotes = async ( pluginOptions , context ) => { pkg . _nextRelease = context . nextRelease ; await waitForAll ( "_nextRelease" , ( p ) => p . _nextType ) ; const notes = [ ] ; if ( context . lastRelease && context . lastRelease . gitTag ) { if ( ! context . lastRelease . gitHead || context . lastRelease . gitHead === context . lastRelease . gitTag ) { context . lastRelease . gitHead = await getTagHead ( context . lastRelease . gitTag , { cwd : context . cwd , env : context . env , } ) ; } } const firstParentBranch = flags . firstParent ? context . branch . name : undefined ; const commits = await getCommitsFiltered ( cwd , dir , context . lastRelease ? context . lastRelease . gitHead : undefined , context . nextRelease ? context . nextRelease . gitHead : undefined , firstParentBranch ) ; context . commits = commits ; const subs = await plugins . generateNotes ( context ) ; if ( subs ) notes . push ( subs . replace ( / ^(#+) (\[?\d+\.\d+\.\d+\]?) / , ` ${ name } ` ) ) ; const upgrades = pkg . localDeps . filter ( ( d ) => d . _nextRelease ) ; if ( upgrades . length ) { notes . push ( ` ` ) ; const bullets = upgrades . map ( ( d ) => ` ${ d . name } ${ d . _nextRelease . version } ` ) ; notes . push ( bullets . join ( "\n" ) ) ; } debug ( "notes generated: %s" , pkg . name ) ; if ( pkg . options . dryRun ) { next ( ) ; } return notes . join ( "\n\n" ) ; } ; const prepare = async ( pluginOptions , context ) => { getLucky ( "_readyForTagging" , pkg ) ; await waitFor ( "_readyForTagging" , pkg ) ; updateManifestDeps ( pkg ) ; pkg . _depsUpdated = true ; const res = await plugins . prepare ( context ) ; pkg . _prepared = true ; debug ( "prepared: %s" , pkg . name ) ; return res ; } ; const publish = async ( pluginOptions , context ) => { next ( ) ; const res = await plugins . publish ( context ) ; pkg . _published = true ; debug ( "published: %s" , pkg . name ) ; return res . length ? res [ 0 ] : { } ; } ; const inlinePlugin = { verifyConditions , analyzeCommits , generateNotes , prepare , publish , } ; Object . keys ( inlinePlugin ) . forEach ( ( type ) => Reflect . defineProperty ( inlinePlugin [ type ] , "pluginName" , { value : "Inline plugin" , writable : false , enumerable : true , } ) ) ; debug ( "inlinePlugin created: %s" , pkg . name ) ; return inlinePlugin ; }
Create an inline plugin for an individual package in a multirelease.
Create an inline plugin for an individual package in a multirelease .
// Vars. /**
		 * @param {object} pluginOptions Options to configure this plugin.
		 * @param {object} context The semantic-release context.
		 * @returns {Promise<void>} void
		 * @internal
		 */ // Restore context for plugins that does not rely on parsed opts. // And bind actual logger. /**
		 * Analyze commits step.
		 * Responsible for determining the type of the next release (major, minor or patch). If multiple plugins with a analyzeCommits step are defined, the release type will be the highest one among plugins output.
		 *
		 * In multirelease: Returns "patch" if the package contains references to other local packages that have changed, or null if this package references no local packages or they have not changed.
		 * Also updates the `context.commits` setting with one returned from `getCommitsFiltered()` (which is filtered by package directory).
		 *
		 * @param {object} pluginOptions Options to configure this plugin.
		 * @param {object} context The semantic-release context.
		 * @returns {Promise<void>} Promise that resolves when done.
		 *
		 * @internal
		 */ // Filter commits by directory. // Set context.commits so analyzeCommits does correct analysis. // Set lastRelease for package from context. // Set nextType for package from plugins. // Wait until all todo packages have been analyzed. // Make sure type is "patch" if the package has any deps that have changed. // Return type. /**
		 * Generate notes step (after).
		 * Responsible for generating the content of the release note. If multiple plugins with a generateNotes step are defined, the release notes will be the result of the concatenation of each plugin output.
		 *
		 * In multirelease: Edit the H2 to insert the package name and add an upgrades section to the note.
		 * We want this at the _end_ of the release note which is why it's stored in steps-after.
		 *
		 * Should look like:
		 *
		 *     ## my-amazing-package [9.2.1](github.com/etc) 2018-12-01
		 *
		 *     ### Features
		 *
		 *     * etc
		 *
		 *     ### Dependencies
		 *
		 *     * **my-amazing-plugin:** upgraded to 1.2.3
		 *     * **my-other-plugin:** upgraded to 4.9.6
		 *
		 * @param {object} pluginOptions Options to configure this plugin.
		 * @param {object} context The semantic-release context.
		 * @returns {Promise<void>} Promise that resolves to the string
		 *
		 * @internal
		 */ // Set nextRelease for package. // Wait until all todo packages are ready to generate notes. // Vars. //get SHA of lastRelease if not already there (should have been done by Semantic Release...) // Filter commits by directory (and release range) // Set context.commits so generateNotes does correct analysis. // Get subnotes and add to list. // Inject pkg name into title if it matches e.g. `# 1.0.0` or `## [1.0.1]` (as generate-release-notes does). // istanbul ignore else (unnecessary to test) // If it has upgrades add an upgrades section. // Return the notes. // Wait until the current pkg is ready to be tagged // istanbul ignore next // Add labels for logs.