function publish( pkg, clbk ) {
	var fmtProdMsgVersion;
	var triggerRelease;
	var customLicense;
	var isTopLevelNS;
	var workflowPath;
	var ghpagesOpts;
	var jscodeshift;
	var pkgJsonPath;
	var releaseType;
	var extractCLI;
	var repoExists;
	var readmePath;
	var noBundles;
	var changelog;
	var contents;
	var mainJSON;
	var schedule;
	var workflow;
	var command;
	var devDeps;
	var distPkg;
	var pkgJSON;
	var version;
	var badges;
	var branch;
	var nLines;
	var readme;
	var mdPath;
	var about;
	var alias;
	var deps;
	var dist;
	var file;
	var opts;
	var src;
	var pth;
	var i;

	src = join( mainDir, 'lib/node_modules', '@stdlib', pkg );
	distPkg = replace( pkg, /\//g, '-' );
	pth = 'https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/'+pkg;

	dist = join( mainDir, 'build', '@stdlib', distPkg );
	command = 'git ls-remote https://'+ ENV.GITHUB_TOKEN + '@github.com/stdlib-js/'+distPkg+'.git main';
	try {
		shell( command );
		repoExists = true;
	} catch ( error ) {
		console.error( 'Encountered an error when attempting to check whether the repository exists. Error: %s', error.message );
		repoExists = false;
	}
	command = 'git ls-remote --tags --sort="v:refname" https://'+ ENV.GITHUB_TOKEN + '@github.com/stdlib-js/'+distPkg+'.git | grep -E \'v[0-9]+.[0-9]+.[0-9]+\'';
	debug( 'Executing command to retrieve last version: %s', command );
	try {
		command = shell( command ).toString();
		version = substringAfterLast( command, '/' );
		version = replace( version, /[-a-z.]*\^{}/, '' );
		version = trim( removeFirst( version ) ); // Remove leading `v`...
	} catch ( error ) {
		console.error( 'Encountered an error when attempting to retrieve the last version. Error: %s', error.message );
	}
	if ( !version ) {
		version = '0.0.0';
	}
	else if ( flags[ 'only-unpublished' ] ) {
		// Case: the package has already been published (as indicated by the presence of a version tag) and the `--only-unpublished` flag is set, so we skip the package...
		return invokeCallback( null, 'skipped' );
	}

	if ( flags[ 'release-type' ] ) {
		// Case: release type specified, so we generate a changelog for the specified release type...
		changelog = generateChangelog( '@stdlib/'+pkg, {
			'releaseType': flags[ 'release-type' ]
		});
	} else {
		// Case: no release type specified, so we generate a changelog for a non-release...
		changelog = generateChangelog( '@stdlib/'+pkg );
	}
	releaseType = changelog.releaseType;

	mainJSON = readJSON( join( mainDir, 'package.json' ) );

	console.log( 'Creating directory and copying source files...' );
	command = 'mkdir -p '+dist;
	debug( 'Creating build directory: %s', command );
	shell( command );

	isTopLevelNS = !contains( pkg, '/' );
	if ( isTopLevelNS ) {
		// Copy all files and subdirectories:
		command = 'cp -r '+src+'/* '+dist;
	}
	else {
		// Do not copy nested packages which will instead be pulled in as separate dependencies:
		command = 'rsync -r --ignore-missing-args --include=\'benchmark/***\' --include=\'bin/***\' --include=\'data/***\' --include=\'docs/***\' --include=\'etc/***\' --include=\'examples/***\' --include=\'lib/***\' --include=\'include/***\' --include=\'scripts/***\' --include=\'src/***\' --include=\'static/***\'  --include=\'test/***\' --exclude=\'*/***\' '+src+'/*** '+dist;
	}
	debug( 'Copying files: %s', command );
	shell( command );

	debug( 'Copying configuration files...' );
	for ( i = 0; i < DOTFILES.length; i++ ) {
		file = DOTFILES[ i ];
		fs.copyFileSync( join( mainDir, file ), join( dist, file ) );
	}
	if ( existsSync( join( dist, 'LICENSE' ) ) ) {
		customLicense = true;
	} else {
		fs.copyFileSync( join( __dirname, 'templates', 'license_apache2.txt' ), join( dist, 'LICENSE' ) );
		command = [
			'# Extract custom licenses from all descendant packages:',
			'find '+src+' -type f -name "LICENSE" -exec cat {} \\; > LICENSE.tmp',
			'',
			'# Check whether LICENSE.tmp is empty:',
			'if [ -s LICENSE.tmp ]; then',
			'',
			'  # Attach attribution notice to LICENSE file:',
			'  cat '+dist+'/LICENSE '+join( __dirname, 'templates', 'license_attribution.txt' )+' LICENSE.tmp > LICENSE.out',
			'',
			'  # Remove duplicate licenses, i.e., multiline strings:',
			'  awk -v RS= \'!x[$0]++{print; print ""}\' LICENSE.out > LICENSE.tmp',
			'',
			'  # Move LICENSE.tmp to LICENSE:',
			'  mv LICENSE.tmp '+dist+'/LICENSE',
			'',
			'  # Remove temporary file:',
			'  rm LICENSE.out',
			'fi'
		].join( '\n' );
		shell( command );

		customLicense = false;
	}
	fs.copyFileSync( join( __dirname, 'templates', '.npmignore.txt' ), join( dist, '.npmignore' ) );
	fs.copyFileSync( join( __dirname, 'templates', 'Makefile.txt' ), join( dist, 'Makefile' ) );
	fs.copyFileSync( join( __dirname, 'templates', '.eslintrc.js.txt' ), join( dist, '.eslintrc.js' ) );
	writeFileSync( join( dist, 'CHANGELOG.md' ), changelog.content );
	fs.copyFileSync( join( __dirname, 'templates', 'SECURITY.md.txt' ), join( dist, 'SECURITY.md' ) );

	pkgJsonPath = join( dist, 'package.json' );
	pkgJSON = readJSON( pkgJsonPath );
	pkgJSON.name = '@stdlib/'+distPkg;

	// Check if the package should not contain browser bundles:
	noBundles = pkgJSON[ '__stdlib__' ] &&
	pkgJSON[ '__stdlib__' ][ 'envs' ] &&
	( pkgJSON[ '__stdlib__' ][ 'envs' ][ 'browser' ] === false );

	if ( isTopLevelNS ) {
		deps = namespaceDeps( '@stdlib/'+pkg, {
			'level': 1,
			'dev': false
		});
		deps = name2standalone( deps );
		devDeps = namespaceDeps( '@stdlib/'+pkg, {
			'level': 1,
			'dev': true
		});
		devDeps = name2standalone( devDeps );
	} else {
		deps = depList( '@stdlib/'+pkg, {
			'dev': false
		});
		deps = name2standalone( deps );
		devDeps = depList( '@stdlib/'+pkg, {
			'dev': true
		});
		devDeps = name2standalone( devDeps );
	}

	command = 'grep -r proxyquire '+dist+' | wc -l';
	debug( 'Count the number of lines including `proxyquire`: %s', command );
	nLines = shell( command ).toString();
	if ( parseInt( nLines, 10 ) > 0 && !contains( devDeps, 'proxyquire' ) ) {
		// Case: `proxyquire` is used outside of package code, e.g. in test fixtures, and has to be separately included in the list of development dependencies
		devDeps.push( 'proxyquire' );
	}
	triggerRelease = (
		releaseType === 'patch' ||
		releaseType === 'minor' ||
		releaseType === 'major'
	);
	if ( triggerRelease ) {
		version = semver.inc( version, releaseType );
	}
	debug( 'Copying and populating README.md file...' );
	readmePath = join( dist, 'README.md' );
	readme = readFileSync( readmePath, 'utf-8' );
	extractCLI = !isTopLevelNS && RE_CLI_USAGE_SECTION.test( readme );

	readme = replace( readme, RE_CLI_USAGE_SECTION, replacer );
	readme = replace( readme, RE_C_USAGE_SECTION, replacer );
	readme = replace( readme, RE_USAGE_SECTION, replacer );

	about = readFileSync( join( __dirname, 'templates', 'about_details.txt' ), 'utf-8' );
	readme = replace( readme, /\n#/, '\n\n'+about+'\n\n#' );

	badges = '[![NPM version][npm-image]][npm-url]';
	badges += ' ';
	if ( contains( devDeps, 'tape' ) ) {
		badges += '[![Build Status][test-image]][test-url]';
		badges += ' ';
		badges += '[![Coverage Status][coverage-image]][coverage-url]';
		badges += ' ';
	}
	badges += '<!-- ';
	badges += '[![dependencies][dependencies-image]][dependencies-url]';
	badges += ' -->';
	readme = replace( readme, /\n>/, '\n'+badges+'\n\n>' );
	readme = replace( readme, '\'@stdlib/'+pkg, '\'@stdlib/'+distPkg );

	branch = ( triggerRelease ) ? 'v'+version : 'main';
	if ( contains( readme, '<section class="links">' ) ) {
		readme = replace( readme, '<section class="links">', mainRepoSection( customLicense, branch, !noBundles, extractCLI ) );
	} else {
		readme += mainRepoSection( customLicense, branch, !noBundles, extractCLI );
		readme += '\n\n';
		readme += '</section>';
		readme += '\n\n';
		readme += '<!-- /.links -->';
	}
	readme = replace( readme, '<pkg>', distPkg );
	writeFileSync( readmePath, readme );

	opts = {
		'cwd': dist
	};
	command = [
		'find . -type f -name \'*.md\' -print0 ', // Find all regular Markdown files in the destination directory and print their full names to standard output...
		'| xargs -0 ', // Convert standard input to the arguments for following `sed` command...
		'sed -Ei ', // Edit files in-place without creating a backup...
		'\'s/',
		'(@stdlib\\/'+distPkg+')([^:]*)\\]: https.*$', // Match start of internal package link until end of line...
		'/',
		'\\1\\2]: https:\\/\\/github.com\\/stdlib-js\\/'+distPkg+'\\/tree\\/main\\2', // Replacement string generated via back-referencing the two created capture groups...
		'/g\'' // Replace all occurrences and not just the first...
	].join( '' );
	debug( 'Executing command: %s', command );
	shell( command, opts );

	command = [
		'find . -type f -name \'*.md\' -print0 ', // Find all regular Markdown files in the destination directory and print their full names to standard output...
		'| xargs -0 ', // Convert standard input to the arguments for following `sed` command...
		'sed -Ei ', // Edit files in-place without creating a backup...
		'"/',
		'^[^:]+: https:\\/\\/github.com\\/stdlib-js\\/stdlib\\/tree\\/develop\\/lib\\/node_modules\\/%40stdlib\\/', // Match start of external `@stdlib` package link (as internal ones are already processed) until end of line...
		'/ ',
		[
			'{',
			'    h', // Copy pattern space to hold space...
			'    s/:.*/: https:\\/\\/github.com\\/stdlib-js\\//', // Replace everything after the colon in the matched pattern with the beginning of new replacement URL...
			'    x', // Exchange the contents of the hold and pattern spaces...
			'    s/[^:]+: https:\\/\\/github.com\\/stdlib-js\\/stdlib\\/tree\\/develop\\/lib\\/node_modules\\/%40stdlib\\///', // Remove everything up to the beginning of the existing main project URL in the pattern space...
			'    s/\\//-/g', // Replace all occurrences of `/` with `-`...
			'    H', // Append pattern space to hold space...
			'    g', // Copy hold space to pattern space...
			'    s/\\n//', // Remove newline character added when appending pattern space to hold space
			'}'
		].join( '\n' ),
		'"'
	].join( '' );
	debug( 'Executing command: %s', command );
	shell( command, opts );

	if ( isTopLevelNS ) {
		// Rewrite internal packages as relative paths outside of documentation:
		for ( i = 0; i < MAX_TREE_DEPTH; i++ ) {
			command = [
				'find . -mindepth '+(1+i)+' -maxdepth '+(2+i)+' -type f \\( -name \'*.[jt]s\' \\) -print0 ', // Find all JavaScript and TypeScript files in the destination directory at the respective depth and print their full names to standard output...
				'| xargs -0 ', // Convert standard input to the arguments for following `sed` command...
				'sed -Ei ', // Edit files in-place without creating a backup...
				'"/',
				'\'@stdlib\\/types', // Skip over `@stdlib/types`...
				'/b; ',
				'/',
				'^[^\\*].+\'@stdlib\\/'+pkg, // Match internal packages outside of JSDoc comments...
				'/',
				[
					'{',
					'    s/\'@stdlib\\/'+pkg+'(.+)/\'.'+repeat( '\\/..', i+1 )+'\\1/', // Replace the start of internal package requires with a relative path of the respective depth
					'}'
				].join( '\n' ),
				'"'
			].join( '' );
			debug( 'Executing command: %s', command );
			try {
				shell( command, opts );
			} catch ( err ) {
				// Break out of loop in case of no input files...
				debug( 'Encountered an error: %s', err.message );
				break;
			}
		}
	}
	else {
		command = [
			'find . -type f \\( -name \'*.[jt]s\' -o -name \'*.md\' -o -name \'cli\' -o -name \'*.js.txt\' \\) -print0 ', // Find all JavaScript and TypeScript files in the destination directory and print their full names to standard output...
			'| xargs -0 ', // Convert standard input to the arguments for following `sed` command...
			'sed -Ei ', // Edit files in-place without creating a backup...
			'"/',
			'\'@stdlib\\/types', // Skip over `@stdlib/types`...
			'/b; ',
			'/',
			'\\/\\/ returns', // Skip over `// returns` annotations...
			'/b; ',
			'/',
			'\'@stdlib\\/', // Match `@stdlib` packages...
			'/ ',
			[
				'{',
				'    h', // Copy pattern space to hold space...
				'    s/^.+(\'.*$)/\\1/', // Remove everything before the last single quote
				'    x', // Exchange the contents of the hold and pattern spaces...
				'    s/\'[^\']*$//', // Remove everything after the last single quote
				'    s/\\//-/2g', // Replace any but the first occurrence of `/` with `-`...
				'    s/-data-([^\']*[.][^\']*)/\\/data\\/\\1/', // Revert back to backslashes for part of require path loading files from a package's `data` directory
				'    G', // Append hold space to pattern space...
				'    s/\\n//', // Remove newline character added when appending hold space to pattern space
				'}'
			].join( '\n' ),
			'"'
		].join( '' );
		debug( 'Executing command: %s', command );
		shell( command, opts );

		// Rewrite related packages in READMEs to point to standalone packages:
		command = [
			'find . -type f -name \'*.md\' ', // Find all Markdown files in the destination directory and print their full names to standard output...
			'-exec ', // Convert standard input to the arguments for following `sed` command...
			'sed -i ', // Edit files in-place...
			'\'',
			's/`@stdlib\\/\\([^/]*\\)\\/\\(.*\\)/`@stdlib\\/\\1-\\2/g', // Replace all forward slashes in package names except the first one...
			'\'',
			' {} +'
		].join( '' );
		debug( 'Executing command: %s', command );
		shell( command, opts );

		command = [
			'find . -type f -name \'*.js\' -print0 ', // Find all JavaScript files in the destination directory and print their full names to standard output...
			'| xargs -0 ', // Convert standard input to the arguments for following `sed` command...
			'sed -Ei ', // Edit files in-place without creating a backup...
			'"/',
			'@module @stdlib\\/', // Match @stdlib packages in JSDoc @module comment...
			'/s/',
			'\\/',
			'/',
			'-',
			'/2g"' // Replace all forward slashes in package name except the first one...
		].join( '' );
		debug( 'Executing command: %s', command );
		shell( command, opts );

		command = [
			'find . -type f -name \'include.gypi\' -print0 ', // Find all `include.gypi` files in the destination directory and print their full names to standard output...
			'| xargs -r -0 ', // Convert standard input to the arguments for following `sed` command...
			'sed -Ei ', // Edit files in-place without creating a backup...
			'"s/',
			'@stdlib\\/utils\\/library-manifest',
			'/',
			'@stdlib\\/utils-library-manifest', // Replace with standalone `library-manifest` package
			'/"'
		].join( '' );
		debug( 'Executing command: %s', command );
		shell( command, opts );

		command = [
			'find . -type f -name \'manifest.json\' -print0 ', // Find all `manifest.json` files in the destination directory and print their full names to standard output...
			'| xargs -r -0 ', // Convert standard input to the arguments for following `sed` command if `find` returns output...
			'sed -Ei ', // Edit files in-place without creating a backup...
			'"/',
			'@stdlib\\/[^ ]+', // Match @stdlib package names in dependencies
			'/s/',
			'\\/',
			'/',
			'-',
			'/2g"' // Replace all forward slashes in package names except the first one...
		].join( '' );
		debug( 'Executing command: %s', command );
		shell( command, opts );
	}
	pkgJSON.homepage = 'https://stdlib.io';
	pkgJSON.repository = {
		'type': 'git',
		'url': 'git://github.com/stdlib-js/'+distPkg+'.git'
	};

	// Ensure `npm install` does not automatically build a native add-on...
	if ( pkgJSON.gypfile ) {
		// TODO: consider removing this once we have determined our native add-on story for individual packages
		pkgJSON.gypfile = false;
	}
	pkgJSON.version = version;
	pkgJSON.funding = FUNDING;
	pkgJSON = populateDeps( pkgJSON, deps, devDeps, mainJSON, isTopLevelNS );
	fs.mkdirSync( join( dist, '.github', 'workflows' ), {
		'recursive': true
	});
	if ( isTopLevelNS ) {
		fs.copyFileSync( join( __dirname, 'templates', 'workflow_publish_toplevel.yml.txt' ), join( dist, '.github', 'workflows', 'publish.yml' ) );
	} else {
		fs.copyFileSync( join( __dirname, 'templates', 'workflow_publish.yml.txt' ), join( dist, '.github', 'workflows', 'publish.yml' ) );
		if ( extractCLI ) {
			fs.copyFileSync( join( __dirname, 'templates', 'workflow_publish_cli.yml.txt' ), join( dist, '.github', 'workflows', 'publish_cli.yml' ) );
		}
	}
	schedule = cronSchedule( '@stdlib/'+pkg );

	workflow = readFileSync( join( __dirname, 'templates', 'workflow_test_install.yml.txt' ), 'utf8' );
	workflow = replace( workflow, '{{cron}}', schedule );
	writeFileSync( join( dist, '.github', 'workflows', 'test_install.yml' ), workflow );

	workflow = readFileSync( join( __dirname, 'templates', 'workflow_npm_downloads.yml.txt' ), 'utf8' );
	workflow = replace( workflow, '{{cron}}', schedule );
	writeFileSync( join( dist, '.github', 'workflows', 'npm_downloads.yml' ), workflow );

	if ( !noBundles ) {
		if ( extractCLI ) {
			fs.copyFileSync( join( __dirname, 'templates', 'workflow_productionize_cli.yml.txt' ), join( dist, '.github', 'workflows', 'productionize.yml' ) );
		} else {
			fs.copyFileSync( join( __dirname, 'templates', 'workflow_productionize.yml.txt' ), join( dist, '.github', 'workflows', 'productionize.yml' ) );
		}
		fs.copyFileSync( join( __dirname, 'templates', 'workflow_test_bundles.yml.txt' ), join( dist, '.github', 'workflows', 'test_bundles.yml' ) );
	}
	workflowPath = join( dist, '.github', 'workflows', 'close_pull_requests.yml' );
	writeFileSync( workflowPath, replace( WORKFLOW_CLOSE_PULLS, '<pkg-path>', pth ) );
	if ( contains( devDeps, 'tape' ) ) {
		workflow = readFileSync( join( __dirname, 'templates', 'workflow_test.yml.txt' ), 'utf8' );
		workflow = replace( workflow, '{{cron}}', schedule );
		writeFileSync( join( dist, '.github', 'workflows', 'test.yml' ), workflow );

		pkgJSON.scripts[ 'test' ] = 'make test';
		pkgJSON.scripts[ 'test-cov' ] = 'make test-cov';

		pkgJSON.devDependencies[ 'istanbul' ] = '^0.4.1';
		pkgJSON.devDependencies[ 'tap-min' ] = 'git+https://github.com/Planeshifter/tap-min.git';
		fs.copyFileSync( join( __dirname, 'templates', 'workflow_test_coverage.yml.txt' ), join( dist, '.github', 'workflows', 'test_coverage.yml' ) );
	}
	if ( existsSync( join( dist, 'examples' ) ) ) {
		fs.copyFileSync( join( __dirname, 'templates', 'workflow_examples.yml.txt' ), join( dist, '.github', 'workflows', 'examples.yml' ) );
		pkgJSON.scripts.examples = 'make examples';
	}
	if ( contains( devDeps, '@stdlib/bench' ) ) {
		fs.copyFileSync( join( __dirname, 'templates', 'workflow_benchmark.yml.txt' ), join( dist, '.github', 'workflows', 'benchmark.yml' ) );
		pkgJSON.scripts.benchmark = 'make benchmark';

		if ( !isTopLevelNS ) {
			// Replace `@stdlib/bench` with `@stdlib/bench-harness` in standalone packages:
			command = 'find '+dist+' -type f -name \'*.js\' -print0 | xargs -0 sed -i "s/\'@stdlib\\/bench\'/\'@stdlib\\/bench-harness\'/g"';
			shell( command );
			pkgJSON.devDependencies[ '@stdlib/bench-harness' ] = memoizedNPMversionForDevDeps( '@stdlib/bench-harness' );
			delete pkgJSON.devDependencies[ '@stdlib/bench' ];
		}
	}
	fs.copyFileSync( join( __dirname, 'templates', 'workflow_cancel.yml.txt' ), join( dist, '.github', 'workflows', 'cancel.yml' ) );

	workflow = readFileSync( join( __dirname, 'templates', 'workflow_test_published_package.yml.txt' ), 'utf8' );
	workflow = replace( workflow, '{{cron}}', schedule );
	writeFileSync( join( dist, '.github', 'workflows', 'test_published_package.yml' ), workflow );

	// Write the current date to the `.keepalive` file...
	if ( flags[ 'keep-alive' ] ) {
		fs.writeFileSync( join( dist, '.github', '.keepalive' ), new Date().toISOString() + '\n' );
	}

	fs.copyFileSync( join( __dirname, 'templates', 'CODE_OF_CONDUCT.md.txt' ), join( dist, 'CODE_OF_CONDUCT.md' ) );
	fs.copyFileSync( join( __dirname, 'templates', 'CONTRIBUTING.md.txt' ), join( dist, 'CONTRIBUTING.md' ) );

	if ( extractCLI ) {
		writeFileSync( join( dist, 'branches.md' ), replace( replace( BRANCHES_WITH_CLI, '<pkg-path>', pth ), '<pkg>', distPkg ) );
	} else {
		writeFileSync( join( dist, 'branches.md' ), replace( replace( BRANCHES, '<pkg-path>', pth ), '<pkg>', distPkg ) );
	}

	mdPath = join( dist, '.github', 'PULL_REQUEST_TEMPLATE.md' );
	writeFileSync( mdPath, replace( PULL_REQUEST_TEMPLATE, '<pkg-path>', pth ) );

	// Add `@stdlib/error-tools-fmtprodmsg` in package.json if the package depends on `@stdlib/string-format`:
	if ( pkgJSON.dependencies[ '@stdlib/string-format' ] ) {
		fmtProdMsgVersion = memoizedNPMversionForDeps( '@stdlib/error-tools-fmtprodmsg' );
		pkgJSON.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = fmtProdMsgVersion;
		deps.push( '@stdlib/error-tools-fmtprodmsg' );
	}
	debug( 'Saving `package.json` file...' );
	writeFileSync( pkgJsonPath, JSON.stringify( pkgJSON, null, '  ' ).concat( '\n' ) );

	if ( !isTopLevelNS ) {
		// Minify, bundle, and save files to `dist` subdirectory:
		try {
			command = 'mkdir dist';
			shell( command, opts );
			command = [
				'npx esbuild lib/index.js --bundle --format=cjs --target=es5',
				'--sourcemap --minify --platform=node --outfile=dist/index.js',
				'--external:'+deps.join( ' --external:' )
			].join( ' ' );
			debug( 'Executing command: %s', command );
			shell( command, opts );
		} catch ( error ) {
			debug( 'Encountered an error when attempting to bundle the package: %s', error.message );

			// Copy all source files to the `dist` subdirectory to proceed without bundling:
			command = 'cp -r lib/* dist';
			shell( command, opts );
		}
		// Apply code transformations:
		jscodeshift = join( rootDir(), 'node_modules', '.bin', 'jscodeshift' );
		command = 'STDLIB_INPUT_SOURCE_MAP=\'./dist/index.js.map\' STDLIB_PKG=\'@stdlib/'+distPkg+'\' '+jscodeshift+' ./dist/index.js -t '+join( __dirname, 'transform.js' );
		debug( 'Executing command: %s', command );
		shell( command, opts );
		try {
			// Extract the alias from the Typescript definition file (after `export =` but before the semicolon):
			command = 'grep -oP \'(?<=export = ).*?(?=;)\' docs/types/index.d.ts';
			alias = trim( shell( command, opts ).toString() );

			// Create the contents of a `index.d.ts` file in `dist` subdirectory that reexports `docs/types/index.d.ts` (we don't want to duplicate type definitions, so we just reexport them):
			contents = [
				'/// <reference path="../docs/types/index.d.ts" />',
				'import '+alias+' from \'../docs/types/index\';',
				'export = '+alias+';'
			].join( '\n' );
			writeFileSync( join( dist, 'dist', 'index.d.ts' ), contents );
		} catch ( error ) {
			debug( 'Encountered an error when attempting to extract the alias from the Typescript definition file: %s', error.message );
		}
		// Add test file(s) for `dist` builds:
		try {
			command = 'mkdir -p test/dist';
			shell( command, opts );
			fs.copyFileSync( join( __dirname, 'templates', 'test_dist_test.js.txt' ), join( dist, 'test', 'dist', 'test.js' ) );
		} catch ( error ) {
			debug( 'Encountered an error when attempting to copy a boilerplate test file to `dist`: %s', error.message );
		}
		// Add `dist` directory to `package.json`:
		if ( pkgJSON.directories ) {
			pkgJSON.directories.dist = './dist';
		}
	}

	if ( flags[ 'skip-upload' ] ) {
		return invokeCallback( null, 'skipped' );
	}
	ghpagesOpts = {
		'branch': 'main',
		'dotfiles': true,
		'src': [
			'**/*',
			'!**/.cache/**'
		],
		'repo': 'https://'+ ENV.GITHUB_TOKEN + '@github.com/stdlib-js/' + distPkg,
		'user': {
			'name': 'stdlib-bot',
			'email': 'noreply@stdlib.io'
		},
		'history': true,
		'beforeAdd': updatePermissions
	};
	if ( triggerRelease ) {
		ghpagesOpts.tag = branch;
		ghpagesOpts.message = 'Release v'+version;
	} else {
		ghpagesOpts.message = 'Auto-generated commit';
	}
	if ( repoExists ) {
		console.log( 'Publishing '+dist+' to GitHub...' );
		if ( triggerRelease ) {
			ghpages.publish( dist, ghpagesOpts, publishToNPM );
		} else {
			ghpages.publish( dist, ghpagesOpts, invokeCallback );
		}
		if ( flags[ 'overwrite-topics' ] ) {
			topics( 'stdlib-js/' + distPkg, createTopics( pkgJSON.keywords ) );
		}
	} else {
		console.log( 'Creating new remote repository: stdlib-js/'+distPkg );
		createRepo( distPkg, {
			'org': 'stdlib-js',
			'desc': pkgJSON.description,
			'homepage': 'https://github.com/stdlib-js/stdlib',
			'issues': false,
			'wiki': false,
			'projects': false,
			'private': false,
			'token': ENV.GITHUB_TOKEN,
			'allowSquashMerge': true,
			'allowRebaseMerge': false,
			'allowMergeCommit': false
		}, onRepoCreation );
	}

	/**
	* Publishes the package to npm.
	*
	* @private
	*/
	function publishToNPM() {
		var command;
		var escaped;
		var cliPkg;
		var found;
		var dep;

		console.log( 'Publishing '+dist+' to npm...' );
		pkgJSON = populateDeps( pkgJSON, deps, devDeps, mainJSON, false );

		command = 'rm -f docs/repl.txt && rm -f docs/types/test.ts';
		shell( command, opts );
		if ( extractCLI ) {
			// Delete the `bin` field from the `package.json` file:
			delete pkgJSON.bin;

			// Delete files:
			command = 'rm -rf ./bin/cli test/test.cli.js etc/cli_opts.json docs/usage.txt';
			shell( command, opts );

			// Remove CLI section:
			command = 'find . -type f -name \'*.md\' -print0 | xargs -0 perl -0777 -i -pe "s/(\\* \\* \\*\n+)?<section class=\\"cli\\">[\\s\\S]+?<\\!\\-\\- \\/.cli \\-\\->//"';
			shell( command, opts );

			// Add entry for CLI package to "See Also" section of README.md:
			cliPkg = '@stdlib/' + distPkg + '-cli';
			cliPkg = replace( cliPkg, '/', '\\/' );
			cliPkg = replace( cliPkg, '@', '\\@' );
			command = 'find . -type f -name \'*.md\' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\\"related\\">(?:\n\n\\* \\* \\*\n\n## See Also\n\n)?/<section class=\\"related\\">\n\n## See Also\n\n-   <span class=\\"package-name\\">[\\`'+cliPkg+'\\`]['+cliPkg+']<\\/span><span class=\\"delimiter\\">: <\\/span><span class=\\"description\\">CLI package for use as a command-line utility.<\\/span>\n/"';
			shell( command, opts );

			// Add link definition for CLI package to README.md:
			command = 'find . -type f -name \'*.md\' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\\"links\\">/<section class=\\"links\\">\n\n['+cliPkg+']: https:\\/\\/www.npmjs.com\\/package\\/'+cliPkg+'/"';
			shell( command, opts );
		}

		if ( !isTopLevelNS ) {
			// For all dependencies, check in *.js files if they are used in what will be published to npm; if not, remove them:
			for ( dep in pkgJSON.dependencies ) {
				if ( hasOwnProp( pkgJSON.dependencies, dep ) ) {
					escaped = replace( dep, '@', '\\@' );
					escaped = replace( escaped, '/', '\\/' );
					command = [
						'if ! find lib -name "*.js" -exec grep -q "'+escaped+'" {} + && ! grep -q -s "'+escaped+'" manifest.json && ! grep -q -s "'+escaped+'" include.gypi; then',
						'  printf "false"',
						'else',
						'  printf "true"',
						'fi'
					].join( '\n' );
					found = shell( command, opts ).toString();
					if ( found === 'false' && dep !== '@stdlib/error-tools-fmtprodmsg' ) {
						delete pkgJSON.dependencies[ dep ];
					}
				}
			}
		}

		debug( 'Replace GitHub MathJax equations with SVGs...' );
		command = 'find . -type f -name \'*.md\' -print0 | xargs -0 perl -0777 -i -pe \'s/```math\\n([\\s\\S]+?)\\n```\\n\\n//g\'';
		shell( command, opts );
		command = 'find . -type f -name \'*.md\' -print0 | xargs -0 perl -0777 -i -pe \'s/<!-- <div class="equation"(.*)(<\\/div>\\s*-->)/<div class="equation"$1<\\/div>/sg\'';
		shell( command, opts );

		debug( 'Replace GitHub links to individual packages with npm links...' );
		command = 'find . -type f -name \'*.md\' -print0 | xargs -0 sed -Ei \'/tree\\/main/b; s/@stdlib\\/([^:]*)\\]: https:\\/\\/github.com\\/stdlib-js/@stdlib\\/\\1\\]: https:\\/\\/www.npmjs.com\\/package\\/@stdlib/g\'';
		shell( command, opts );

		debug( 'Replace list with links to other branches from installation section...' );
		command = 'find . -type f -name \'*.md\' -print0 | xargs -0 perl -0777 -i -pe "s/\\`\\`\\`\n\nAlternatively,[^<]+<\\/section>/\\`\\`\\`\n\n<\\/section>/"';
		shell( command, opts );

		// Set `scripts` and `devDependencies` to an empty object and update `directories`:
		pkgJSON.scripts = {};
		pkgJSON.devDependencies = {};
		if ( pkgJSON.directories ) {
			delete pkgJSON.directories.benchmark;
			delete pkgJSON.directories.example;
			delete pkgJSON.directories.test;
		}
		writeFileSync( pkgJsonPath, JSON.stringify( pkgJSON, null, '  ' ).concat( '\n' ) );

		shell( 'npm publish --access public', opts );
		invokeCallback();
	}

	/**
	* Adds executable permission to `bin/cli` files.
	*
	* @private
	* @param {Object} git - `git` class instance
	*/
	function updatePermissions( git ) {
		shell( 'find '+git.cwd+' -regex \'.*/bin/cli\' -print0 | xargs -r -0 chmod +x' );
	}

	/**
	* Replacer function for inserting an install section before a usage section.
	*
	* @private
	* @param {string} match - entire match
	* @param {string} p1 - first capture group
	* @param {string} p2 - second capture group
	* @returns {string} replacement
	*/
	function replacer( match, p1, p2 ) {
		var out;

		if ( isString( p1 ) ) {
			if ( startsWith( p1, '## CLI' ) ) {
				return p1 + CLI_INSTALLATION_SECTION + ( p2 || '\n<!-- CLI usage documentation. -->\n' ) + '\n<section class="usage">';
			}
			if ( startsWith( p1, '<!-- C usage documentation. -->' ) ) {
				return p1 + '<section class="usage">';
			}
		}
		if ( noBundles ) {
			out = INSTALLATION_SECTION_BASIC;
		} else {
			out = INSTALLATION_SECTION_BUNDLES;
			out = out.replace( '<cli>', ( extractCLI ) ? INSTALLATION_SECTION_BUNDLES_CLI : '' );
		}
		out += '\n<section class="usage">';
		return out;
	}

	/**
	* Callback invoked upon pushing package contents to remote GitHub repository.
	*
	* @private
	* @param {(Error|null)} error - encountered error
	* @param {string} [status] - publish status
	* @returns {void}
	*/
	function invokeCallback( error, status ) {
		var pkgInfo = {
			'name': pkgJSON && pkgJSON.name,
			'description': pkgJSON && pkgJSON.description,
			'status': status || ( ( error )? 'failure' : 'success' )
		};
		clbk( error, pkgInfo );
	}

	/**
	* Callback invoked upon creating GitHub repository.
	*
	* @private
	* @param {(Error|null)} error - encountered error
	* @param {Object} repo - repo data
	* @param {Object} info - rate limit info
	* @returns {void}
	*/
	function onRepoCreation( error, repo, info ) {
		var currentTime;
		var waitTime;
		if ( error ) {
			return console.error( error );
		}
		console.log( 'GitHub repository '+repo.full_name+' has been successfully created.' );
		console.log( 'Rate limit information: '+JSON.stringify( info ) );

		topics( 'stdlib-js/' + distPkg, createTopics( pkgJSON.keywords ) );
		if ( info.remaining === 0 ) {
			currentTime = new Date().getTime();
			waitTime = new Date( info.reset * 1000 ).getTime() - currentTime;
			ghpages.publish( dist, ghpagesOpts, withDelay );
		} else {
			ghpages.publish( dist, ghpagesOpts, invokeCallback );
		}

		/**
		* Invokes callback for once pushing package contents to remote GitHub repository after a specified delay.
		*
		* @private
		* @param {(Error|null)} err - error object or `null`
		* @returns {void}
		*/
		function withDelay( err ) {
			if ( err ) {
				return console.log( err );
			}
			console.log( 'Waiting '+waitTime+'ms before moving to next package...' );
			setTimeout( invokeCallback, waitTime );
		}
	}
}
Publishes a package to the respective GitHub repository.

@private
@param {string} pkg - package name
@param {Function} clbk - callback function
@throws {Error} no input files
@returns {void}