diff options
author | Timmy Willison <timmywil@users.noreply.github.com> | 2023-07-27 11:24:49 -0400 |
---|---|---|
committer | Timmy Willison <timmywil@users.noreply.github.com> | 2024-07-11 10:00:56 -0400 |
commit | 2646a8b07fcc2cf7cf384724f622eb0c27f9166c (patch) | |
tree | 3367ad18d492486a692bb4a7a23b216ba155451f /build/tasks/build.js | |
parent | 3a98ef91dfa0b4897df7562f40bfd1715f5fc30e (diff) | |
download | jquery-2646a8b07fcc2cf7cf384724f622eb0c27f9166c.tar.gz jquery-2646a8b07fcc2cf7cf384724f622eb0c27f9166c.zip |
Release: migrate release process to release-it
*Authors*
- Checking and updating authors has been migrated
to a custom script in the repo
*Changelog*
- changelogplease is no longer maintained
- generate changelog in markdown for GitHub releases
- generate changelog in HTML for blog posts
- generate contributors list in HTML for blog posts
*dist*
- clone dist repo, copy files, and commit/push
- commit tag with dist files on main branch;
remove dist files from main branch after release
*cdn*
- clone cdn repo, copy files, and commit/push
- create versioned and unversioned copies in cdn/
- generate md5 sums and archives for Google and MSFT
*build*
- implement reproducible builds and verify release builds
* uses the last modified date for the latest commit
* See https://reproducible-builds.org/
- the verify workflow also ensures all files were
properly published to the CDN and npm
*docs*
- the new release workflow is documented at build/release/README.md
*misc*
- now that we don't need the jquery-release script and
now that we no longer need to build on Node 10, we can
use ESM in all files in the build folder
- move dist wrappers to "wrappers" folders for easy removal
of all built files
- limit certain workflows to the main repo (not forks)
- version in package.json has been set to beta.1 so that
the next release will be beta.2
- release-it added the `preReleaseBase` option and we
now always set it to `1` in the npm script. This is
a noop for stable releases.
Fixes jquery/jquery-release#114
Closes gh-5512
Diffstat (limited to 'build/tasks/build.js')
-rw-r--r-- | build/tasks/build.js | 87 |
1 files changed, 45 insertions, 42 deletions
diff --git a/build/tasks/build.js b/build/tasks/build.js index 5ed1b9c32..1a3ed1d82 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -4,22 +4,21 @@ * and includes/excludes specified modules */ -"use strict"; - -const fs = require( "node:fs/promises" ); -const path = require( "node:path" ); -const util = require( "node:util" ); -const exec = util.promisify( require( "node:child_process" ).exec ); -const rollup = require( "rollup" ); -const excludedFromSlim = require( "./lib/slim-exclude" ); -const rollupFileOverrides = require( "./lib/rollup-plugin-file-overrides" ); -const pkg = require( "../../package.json" ); -const isCleanWorkingDir = require( "./lib/isCleanWorkingDir" ); -const processForDist = require( "./dist" ); -const minify = require( "./minify" ); -const getTimestamp = require( "./lib/getTimestamp" ); -const verifyNodeVersion = require( "./lib/verifyNodeVersion" ); -const srcFolder = path.resolve( __dirname, "../../src" ); +import fs from "node:fs/promises"; +import path from "node:path"; +import util from "node:util"; +import { exec as nodeExec } from "node:child_process"; +import * as rollup from "rollup"; +import excludedFromSlim from "./lib/slim-exclude.js"; +import rollupFileOverrides from "./lib/rollupFileOverridesPlugin.js"; +import isCleanWorkingDir from "./lib/isCleanWorkingDir.js"; +import processForDist from "./dist.js"; +import minify from "./minify.js"; +import getTimestamp from "./lib/getTimestamp.js"; +import { compareSize } from "./lib/compareSize.js"; + +const exec = util.promisify( nodeExec ); +const pkg = JSON.parse( await fs.readFile( "./package.json", "utf8" ) ); const minimum = [ "core" ]; @@ -38,14 +37,14 @@ const removeWith = { }; async function read( filename ) { - return fs.readFile( path.join( srcFolder, filename ), "utf8" ); + return fs.readFile( path.join( "./src", filename ), "utf8" ); } // Remove the src folder and file extension // and ensure unix-style path separators function moduleName( filename ) { return filename - .replace( `${ srcFolder }${ path.sep }`, "" ) + .replace( new RegExp( `.*\\${ path.sep }src\\${ path.sep }` ), "" ) .replace( /\.js$/, "" ) .split( path.sep ) .join( path.posix.sep ); @@ -54,7 +53,7 @@ function moduleName( filename ) { async function readdirRecursive( dir, all = [] ) { let files; try { - files = await fs.readdir( path.join( srcFolder, dir ), { + files = await fs.readdir( path.join( "./src", dir ), { withFileTypes: true } ); } catch ( e ) { @@ -141,7 +140,15 @@ async function checkExclude( exclude, include ) { return [ unique( excluded ), unique( included ) ]; } +async function getLastModifiedDate() { + const { stdout } = await exec( "git log -1 --format=\"%at\"" ); + return new Date( parseInt( stdout, 10 ) * 1000 ); +} + async function writeCompiled( { code, dir, filename, version } ) { + + // Use the last modified date so builds are reproducible + const date = await getLastModifiedDate(); const compiledContents = code // Embed Version @@ -149,14 +156,14 @@ async function writeCompiled( { code, dir, filename, version } ) { // Embed Date // yyyy-mm-ddThh:mmZ - .replace( /@DATE/g, new Date().toISOString().replace( /:\d+\.\d+Z$/, "Z" ) ); + .replace( /@DATE/g, date.toISOString().replace( /:\d+\.\d+Z$/, "Z" ) ); await fs.writeFile( path.join( dir, filename ), compiledContents ); console.log( `[${ getTimestamp() }] ${ filename } v${ version } created.` ); } // Build jQuery ECMAScript modules -async function build( { +export async function build( { amd, dir = "dist", exclude = [], @@ -206,7 +213,7 @@ async function build( { if ( excluded.includes( "exports/global" ) ) { const index = excluded.indexOf( "exports/global" ); setOverride( - `${ srcFolder }/exports/global.js`, + "./src/exports/global.js", "import { jQuery } from \"../core.js\";\n\n" + "jQuery.noConflict = function() {};" ); @@ -225,7 +232,7 @@ async function build( { // No name means an anonymous define const amdExportContents = await read( "exports/amd.js" ); setOverride( - `${ srcFolder }/exports/amd.js`, + "./src/exports/amd.js", amdExportContents.replace( // Remove the comma for anonymous defines @@ -248,7 +255,7 @@ async function build( { } const inputOptions = { - input: `${ srcFolder }/jquery.js` + input: "./src/jquery.js" }; const includedImports = included @@ -274,7 +281,7 @@ async function build( { // Replace excluded modules with empty sources. for ( const module of excluded ) { setOverride( - `${ srcFolder }/${ module }.js`, + `./src/${ module }.js`, // The `selector` module is not removed, but replaced // with `selector-native`. @@ -290,7 +297,7 @@ async function build( { output: [ outputOptions ], plugins: [ rollupFileOverrides( fileOverrides ) ], watch: { - include: `${ srcFolder }/**`, + include: "./src/**", skipWrite: true } } ); @@ -352,7 +359,7 @@ async function build( { } } -async function buildDefaultFiles( { +export async function buildDefaultFiles( { version = process.env.VERSION, watch } = {} ) { @@ -407,20 +414,16 @@ async function buildDefaultFiles( { } ) ] ); - // Earlier Node.js versions do not support the ESM format. - if ( !verifyNodeVersion() ) { - return; + if ( watch ) { + console.log( "Watching files..." ); + } else { + return compareSize( { + files: [ + "dist/jquery.min.js", + "dist/jquery.slim.min.js", + "dist-module/jquery.module.min.js", + "dist-module/jquery.slim.module.min.js" + ] + } ); } - - const { compareSize } = await import( "./compare_size.mjs" ); - return compareSize( { - files: [ - "dist/jquery.min.js", - "dist/jquery.slim.min.js", - "dist-module/jquery.module.min.js", - "dist-module/jquery.slim.module.min.js" - ] - } ); } - -module.exports = { build, buildDefaultFiles }; |