Repository: jquery/jquery
File: build/release/cdn.js (JavaScript)

Code before:
/**
 * Generates copies for the CDNs
 */
function makeReleaseCopies( Release ) {
	[
		{ filesMap: versionedReleaseFiles, cdnFolder: cdnFolderVersioned },
		{ filesMap: unversionedReleaseFiles, cdnFolder: cdnFolderUnversioned }
	].forEach( ( { filesMap, cdnFolder } ) => {
		shell.mkdir( "-p", cdnFolder );

		Object.keys( filesMap ).forEach( ( key ) => {
			let text;
			const builtFile = filesMap[ key ];
			const unpathedFile = key.replace( /@VER/g, Release.newVersion );
			const releaseFile = cdnFolder + "/" + unpathedFile;

			if ( /\.map$/.test( releaseFile ) ) {

				// Map files need to reference the new uncompressed name;
				// assume that all files reside in the same directory.
				// "file":"jquery.min.js" ... "sources":["jquery.js"]
				text = fs
					.readFileSync( builtFile, "utf8" )
					.replace(
						/"file":"([^"]+)"/,
						"\"file\":\"" + unpathedFile.replace( /\.min\.map/, ".min.js\"" )
					)
					.replace(
						/"sources":\["([^"]+)"\]/,
						"\"sources\":[\"" + unpathedFile.replace( /\.min\.map/, ".js" ) + "\"]"
					);
				fs.writeFileSync( releaseFile, text );
			} else if ( builtFile !== releaseFile ) {
				shell.cp( "-f", builtFile, releaseFile );
			}
		} );
	} );
}

async function makeArchives( Release ) {
	Release.chdir( Release.dir.repo );

	async function makeArchive( { cdn, filesMap, cdnFolder } ) {
		return new Promise( ( resolve, reject ) => {
			if ( Release.preRelease ) {
				console.log(
					"Skipping archive creation for " + cdn + "; this is a beta release."
				);
				resolve();
				return;
			}

Review comment (bug):
It'd probably be more readable as a template literal; quote escapes would also disappear:
```suggestion
						`"file":"${ unpathedFile.replace( /\.min\.map/, ".min.js\"" ) }`
```

I wonder, though - such replaces are risky, it's easy to match incorrectly and that can be hard to find. Why not parse this JSON, fix the fields and serialize again? We're doing something similar in SWC minify, although without the initial parsing as we already get an object.

Code after:
/**
 * Generates copies for the CDNs
 */
function makeReleaseCopies( Release ) {
	[
		{ filesMap: versionedReleaseFiles, cdnFolder: cdnFolderVersioned },
		{ filesMap: unversionedReleaseFiles, cdnFolder: cdnFolderUnversioned }
	].forEach( ( { filesMap, cdnFolder } ) => {
		shell.mkdir( "-p", cdnFolder );

		Object.keys( filesMap ).forEach( ( key ) => {
			let text;
			const builtFile = filesMap[ key ];
			const unpathedFile = key.replace( /@VER/g, Release.newVersion );
			const releaseFile = cdnFolder + "/" + unpathedFile;

			if ( /\.map$/.test( releaseFile ) ) {

				// Map files need to reference the new uncompressed name;
				// assume that all files reside in the same directory.
				// "file":"jquery.min.js" ... "sources":["jquery.js"]
				text = fs
					.readFileSync( builtFile, "utf8" )
					.replace(
						/"file":"([^"]+)"/,
						`"file":"${ unpathedFile.replace( /\.min\.map/, ".min.js" ) }"`
					)
					.replace(
						/"sources":\["([^"]+)"\]/,
						`"sources":["${ unpathedFile.replace( /\.min\.map/, ".js" ) }"]`
					);
				fs.writeFileSync( releaseFile, text );
			} else if ( builtFile !== releaseFile ) {
				shell.cp( "-f", builtFile, releaseFile );
			}
		} );
	} );
}

async function makeArchives( Release ) {
	Release.chdir( Release.dir.repo );

	async function makeArchive( { cdn, filesMap, cdnFolder } ) {
		return new Promise( ( resolve, reject ) => {
			if ( Release.preRelease ) {
				console.log(
					`Skipping archive creation for ${ cdn }; this is a beta release.`
				);
				resolve();
				return;
			}