aboutsummaryrefslogtreecommitdiffstats
path: root/build/tasks
diff options
context:
space:
mode:
authorTimmy Willison <timmywil@users.noreply.github.com>2023-07-27 11:24:49 -0400
committerTimmy Willison <timmywil@users.noreply.github.com>2024-07-11 10:00:56 -0400
commit2646a8b07fcc2cf7cf384724f622eb0c27f9166c (patch)
tree3367ad18d492486a692bb4a7a23b216ba155451f /build/tasks
parent3a98ef91dfa0b4897df7562f40bfd1715f5fc30e (diff)
downloadjquery-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')
-rw-r--r--build/tasks/build.js87
-rw-r--r--build/tasks/dist.js6
-rw-r--r--build/tasks/lib/compareSize.js (renamed from build/tasks/compare_size.mjs)4
-rw-r--r--build/tasks/lib/getTimestamp.js6
-rw-r--r--build/tasks/lib/isCleanWorkingDir.js10
-rw-r--r--build/tasks/lib/rollupFileOverridesPlugin.js (renamed from build/tasks/lib/rollup-plugin-file-overrides.js)6
-rw-r--r--build/tasks/lib/slim-exclude.js4
-rw-r--r--build/tasks/lib/verifyNodeVersion.js12
-rw-r--r--build/tasks/minify.js16
-rw-r--r--build/tasks/node_smoke_tests.js13
-rw-r--r--build/tasks/npmcopy.js8
-rw-r--r--build/tasks/promises_aplus_tests.js16
-rw-r--r--build/tasks/qunit-fixture.js4
13 files changed, 78 insertions, 114 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 };
diff --git a/build/tasks/dist.js b/build/tasks/dist.js
index f15689e3d..9441dca35 100644
--- a/build/tasks/dist.js
+++ b/build/tasks/dist.js
@@ -1,7 +1,5 @@
-"use strict";
-
// Process files for distribution.
-module.exports = function processForDist( text, filename ) {
+export default function processForDist( text, filename ) {
if ( !text ) {
throw new Error( "text required for processForDist" );
}
@@ -28,4 +26,4 @@ module.exports = function processForDist( text, filename ) {
}
throw new Error( message );
}
-};
+}
diff --git a/build/tasks/compare_size.mjs b/build/tasks/lib/compareSize.js
index a94cf42f0..729bb37f2 100644
--- a/build/tasks/compare_size.mjs
+++ b/build/tasks/lib/compareSize.js
@@ -1,9 +1,9 @@
-import chalk from "chalk";
import fs from "node:fs/promises";
import { promisify } from "node:util";
import zlib from "node:zlib";
import { exec as nodeExec } from "node:child_process";
-import isCleanWorkingDir from "./lib/isCleanWorkingDir.js";
+import chalk from "chalk";
+import isCleanWorkingDir from "./isCleanWorkingDir.js";
const VERSION = 1;
const lastRunBranch = " last run";
diff --git a/build/tasks/lib/getTimestamp.js b/build/tasks/lib/getTimestamp.js
index 4706353c5..bca40bc6b 100644
--- a/build/tasks/lib/getTimestamp.js
+++ b/build/tasks/lib/getTimestamp.js
@@ -1,9 +1,7 @@
-"use strict";
-
-module.exports = function getTimestamp() {
+export default function getTimestamp() {
const now = new Date();
const hours = now.getHours().toString().padStart( 2, "0" );
const minutes = now.getMinutes().toString().padStart( 2, "0" );
const seconds = now.getSeconds().toString().padStart( 2, "0" );
return `${ hours }:${ minutes }:${ seconds }`;
-};
+}
diff --git a/build/tasks/lib/isCleanWorkingDir.js b/build/tasks/lib/isCleanWorkingDir.js
index 3ad8f89bc..5466cbdfd 100644
--- a/build/tasks/lib/isCleanWorkingDir.js
+++ b/build/tasks/lib/isCleanWorkingDir.js
@@ -1,9 +1,9 @@
-"use strict";
+import util from "node:util";
+import { exec as nodeExec } from "node:child_process";
-const util = require( "node:util" );
-const exec = util.promisify( require( "node:child_process" ).exec );
+const exec = util.promisify( nodeExec );
-module.exports = async function isCleanWorkingDir() {
+export default async function isCleanWorkingDir() {
const { stdout } = await exec( "git status --untracked-files=no --porcelain" );
return !stdout.trim();
-};
+}
diff --git a/build/tasks/lib/rollup-plugin-file-overrides.js b/build/tasks/lib/rollupFileOverridesPlugin.js
index c494e4e5d..fecb4efaa 100644
--- a/build/tasks/lib/rollup-plugin-file-overrides.js
+++ b/build/tasks/lib/rollupFileOverridesPlugin.js
@@ -1,5 +1,3 @@
-"use strict";
-
/**
* A Rollup plugin accepting a file overrides map and changing
* module sources to the overridden ones where provided. Files
@@ -7,7 +5,7 @@
*
* @param {Map<string, string>} fileOverrides
*/
-module.exports = ( fileOverrides ) => {
+export default function rollupFileOverrides( fileOverrides ) {
return {
name: "jquery-file-overrides",
load( id ) {
@@ -21,4 +19,4 @@ module.exports = ( fileOverrides ) => {
return null;
}
};
-};
+}
diff --git a/build/tasks/lib/slim-exclude.js b/build/tasks/lib/slim-exclude.js
index cc74cbac5..8ffc22728 100644
--- a/build/tasks/lib/slim-exclude.js
+++ b/build/tasks/lib/slim-exclude.js
@@ -1,7 +1,5 @@
-"use strict";
-
// NOTE: keep it in sync with test/data/testinit.js
-module.exports = [
+export default [
"ajax",
"callbacks",
"deferred",
diff --git a/build/tasks/lib/verifyNodeVersion.js b/build/tasks/lib/verifyNodeVersion.js
deleted file mode 100644
index 8ad700d19..000000000
--- a/build/tasks/lib/verifyNodeVersion.js
+++ /dev/null
@@ -1,12 +0,0 @@
-"use strict";
-
-const { version } = require( "process" );
-const nodeV18OrNewer = !/^v1[0-7]\./.test( version );
-
-module.exports = function verifyNodeVersion() {
- if ( !nodeV18OrNewer ) {
- console.log( "Old Node.js detected, task skipped..." );
- return false;
- }
- return true;
-};
diff --git a/build/tasks/minify.js b/build/tasks/minify.js
index 8c536c1ef..aff942b32 100644
--- a/build/tasks/minify.js
+++ b/build/tasks/minify.js
@@ -1,14 +1,12 @@
-"use strict";
-
-const swc = require( "@swc/core" );
-const fs = require( "node:fs/promises" );
-const path = require( "node:path" );
-const processForDist = require( "./dist" );
-const getTimestamp = require( "./lib/getTimestamp" );
+import fs from "node:fs/promises";
+import path from "node:path";
+import swc from "@swc/core";
+import processForDist from "./dist.js";
+import getTimestamp from "./lib/getTimestamp.js";
const rjs = /\.js$/;
-module.exports = async function minify( { filename, dir, esm } ) {
+export default async function minify( { filename, dir, esm } ) {
const contents = await fs.readFile( path.join( dir, filename ), "utf8" );
const version = /jQuery JavaScript Library ([^\n]+)/.exec( contents )[ 1 ];
@@ -67,4 +65,4 @@ module.exports = async function minify( { filename, dir, esm } ) {
console.log( `[${ getTimestamp() }] ${ minFilename } ${ version } with ${
mapFilename
} created.` );
-};
+}
diff --git a/build/tasks/node_smoke_tests.js b/build/tasks/node_smoke_tests.js
index 7d6588648..fa0922618 100644
--- a/build/tasks/node_smoke_tests.js
+++ b/build/tasks/node_smoke_tests.js
@@ -1,17 +1,12 @@
-"use strict";
+import fs from "node:fs/promises";
+import util from "node:util";
+import { exec as nodeExec } from "node:child_process";
-const fs = require( "node:fs/promises" );
-const util = require( "node:util" );
-const exec = util.promisify( require( "node:child_process" ).exec );
-const verifyNodeVersion = require( "./lib/verifyNodeVersion" );
+const exec = util.promisify( nodeExec );
const allowedLibraryTypes = new Set( [ "regular", "factory" ] );
const allowedSourceTypes = new Set( [ "commonjs", "module", "dual" ] );
-if ( !verifyNodeVersion() ) {
- return;
-}
-
// Fire up all tests defined in test/node_smoke_tests/*.js in spawned sub-processes.
// All the files under test/node_smoke_tests/*.js are supposed to exit with 0 code
// on success or another one on failure. Spawning in sub-processes is
diff --git a/build/tasks/npmcopy.js b/build/tasks/npmcopy.js
index 93c0658b9..91cfae95f 100644
--- a/build/tasks/npmcopy.js
+++ b/build/tasks/npmcopy.js
@@ -1,9 +1,7 @@
-"use strict";
+import fs from "node:fs/promises";
+import path from "node:path";
-const fs = require( "node:fs/promises" );
-const path = require( "node:path" );
-
-const projectDir = path.resolve( __dirname, "..", ".." );
+const projectDir = path.resolve( "." );
const files = {
"bootstrap/bootstrap.css": "bootstrap/dist/css/bootstrap.css",
diff --git a/build/tasks/promises_aplus_tests.js b/build/tasks/promises_aplus_tests.js
index 5c3c8fbee..6f49f0230 100644
--- a/build/tasks/promises_aplus_tests.js
+++ b/build/tasks/promises_aplus_tests.js
@@ -1,17 +1,9 @@
-"use strict";
-
-const { spawn } = require( "node:child_process" );
-const verifyNodeVersion = require( "./lib/verifyNodeVersion" );
-const path = require( "node:path" );
-const os = require( "node:os" );
-
-if ( !verifyNodeVersion() ) {
- return;
-}
+import path from "node:path";
+import os from "node:os";
+import { spawn } from "node:child_process";
const command = path.resolve(
- __dirname,
- `../../node_modules/.bin/promises-aplus-tests${ os.platform() === "win32" ? ".cmd" : "" }`
+ `node_modules/.bin/promises-aplus-tests${ os.platform() === "win32" ? ".cmd" : "" }`
);
const args = [ "--reporter", "dot", "--timeout", "2000" ];
const tests = [
diff --git a/build/tasks/qunit-fixture.js b/build/tasks/qunit-fixture.js
index dbb789b60..a8b90653f 100644
--- a/build/tasks/qunit-fixture.js
+++ b/build/tasks/qunit-fixture.js
@@ -1,6 +1,4 @@
-"use strict";
-
-const fs = require( "node:fs/promises" );
+import fs from "node:fs/promises";
async function generateFixture() {
const fixture = await fs.readFile( "./test/data/qunit-fixture.html", "utf8" );