From 2646a8b07fcc2cf7cf384724f622eb0c27f9166c Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Thu, 27 Jul 2023 11:24:49 -0400 Subject: 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 --- build/tasks/build.js | 87 +++++------ build/tasks/compare_size.mjs | 193 ------------------------ build/tasks/dist.js | 6 +- build/tasks/lib/compareSize.js | 193 ++++++++++++++++++++++++ build/tasks/lib/getTimestamp.js | 6 +- build/tasks/lib/isCleanWorkingDir.js | 10 +- build/tasks/lib/rollup-plugin-file-overrides.js | 24 --- build/tasks/lib/rollupFileOverridesPlugin.js | 22 +++ build/tasks/lib/slim-exclude.js | 4 +- build/tasks/lib/verifyNodeVersion.js | 12 -- build/tasks/minify.js | 16 +- build/tasks/node_smoke_tests.js | 13 +- build/tasks/npmcopy.js | 8 +- build/tasks/promises_aplus_tests.js | 16 +- build/tasks/qunit-fixture.js | 4 +- 15 files changed, 289 insertions(+), 325 deletions(-) delete mode 100644 build/tasks/compare_size.mjs create mode 100644 build/tasks/lib/compareSize.js delete mode 100644 build/tasks/lib/rollup-plugin-file-overrides.js create mode 100644 build/tasks/lib/rollupFileOverridesPlugin.js delete mode 100644 build/tasks/lib/verifyNodeVersion.js (limited to 'build/tasks') 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/compare_size.mjs b/build/tasks/compare_size.mjs deleted file mode 100644 index a94cf42f0..000000000 --- a/build/tasks/compare_size.mjs +++ /dev/null @@ -1,193 +0,0 @@ -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"; - -const VERSION = 1; -const lastRunBranch = " last run"; - -const gzip = promisify( zlib.gzip ); -const exec = promisify( nodeExec ); - -async function getBranchName() { - const { stdout } = await exec( "git rev-parse --abbrev-ref HEAD" ); - return stdout.trim(); -} - -async function getCommitHash() { - const { stdout } = await exec( "git rev-parse HEAD" ); - return stdout.trim(); -} - -function getBranchHeader( branch, commit ) { - let branchHeader = branch.trim(); - if ( commit ) { - branchHeader = chalk.bold( branchHeader ) + chalk.gray( ` @${ commit }` ); - } else { - branchHeader = chalk.italic( branchHeader ); - } - return branchHeader; -} - -async function getCache( loc ) { - let cache; - try { - const contents = await fs.readFile( loc, "utf8" ); - cache = JSON.parse( contents ); - } catch ( err ) { - return {}; - } - - const lastRun = cache[ lastRunBranch ]; - if ( !lastRun || !lastRun.meta || lastRun.meta.version !== VERSION ) { - console.log( "Compare cache version mismatch. Rewriting..." ); - return {}; - } - return cache; -} - -function cacheResults( results ) { - const files = Object.create( null ); - results.forEach( function( result ) { - files[ result.filename ] = { - raw: result.raw, - gz: result.gz - }; - } ); - return files; -} - -function saveCache( loc, cache ) { - - // Keep cache readable for manual edits - return fs.writeFile( loc, JSON.stringify( cache, null, " " ) + "\n" ); -} - -function compareSizes( existing, current, padLength ) { - if ( typeof current !== "number" ) { - return chalk.grey( `${ existing }`.padStart( padLength ) ); - } - const delta = current - existing; - if ( delta > 0 ) { - return chalk.red( `+${ delta }`.padStart( padLength ) ); - } - return chalk.green( `${ delta }`.padStart( padLength ) ); -} - -function sortBranches( a, b ) { - if ( a === lastRunBranch ) { - return 1; - } - if ( b === lastRunBranch ) { - return -1; - } - if ( a < b ) { - return -1; - } - if ( a > b ) { - return 1; - } - return 0; -} - -export async function compareSize( { cache = ".sizecache.json", files } = {} ) { - if ( !files || !files.length ) { - throw new Error( "No files specified" ); - } - - const branch = await getBranchName(); - const commit = await getCommitHash(); - const sizeCache = await getCache( cache ); - - let rawPadLength = 0; - let gzPadLength = 0; - const results = await Promise.all( - files.map( async function( filename ) { - - let contents = await fs.readFile( filename, "utf8" ); - - // Remove the short SHA and .dirty from comparisons. - // The short SHA so commits can be compared against each other - // and .dirty to compare with the existing branch during development. - const sha = /jQuery v\d+.\d+.\d+(?:-\w+)?(?:\+slim\.|\+)?([^ \.]+(?:\.dirty)?)?/.exec( contents )[ 1 ]; - contents = contents.replace( new RegExp( sha, "g" ), "" ); - - const size = Buffer.byteLength( contents, "utf8" ); - const gzippedSize = ( await gzip( contents ) ).length; - - // Add one to give space for the `+` or `-` in the comparison - rawPadLength = Math.max( rawPadLength, size.toString().length + 1 ); - gzPadLength = Math.max( gzPadLength, gzippedSize.toString().length + 1 ); - - return { filename, raw: size, gz: gzippedSize }; - } ) - ); - - const sizeHeader = "raw".padStart( rawPadLength ) + - "gz".padStart( gzPadLength + 1 ) + - " Filename"; - - const sizes = results.map( function( result ) { - const rawSize = result.raw.toString().padStart( rawPadLength ); - const gzSize = result.gz.toString().padStart( gzPadLength ); - return `${ rawSize } ${ gzSize } ${ result.filename }`; - } ); - - const comparisons = Object.keys( sizeCache ).sort( sortBranches ).map( function( branch ) { - const meta = sizeCache[ branch ].meta || {}; - const commit = meta.commit; - - const files = sizeCache[ branch ].files; - const branchSizes = Object.keys( files ).map( function( filename ) { - const branchResult = files[ filename ]; - const compareResult = results.find( function( result ) { - return result.filename === filename; - } ) || {}; - - const compareRaw = compareSizes( branchResult.raw, compareResult.raw, rawPadLength ); - const compareGz = compareSizes( branchResult.gz, compareResult.gz, gzPadLength ); - return `${ compareRaw } ${ compareGz } ${ filename }`; - } ); - - return [ - "", // New line before each branch - getBranchHeader( branch, commit ), - sizeHeader, - ...branchSizes - ].join( "\n" ); - } ); - - const output = [ - "", // Opening new line - chalk.bold( "Sizes" ), - sizeHeader, - ...sizes, - ...comparisons, - "" // Closing new line - ].join( "\n" ); - - console.log( output ); - - // Always save the last run - // Save version under last run - sizeCache[ lastRunBranch ] = { - meta: { version: VERSION }, - files: cacheResults( results ) - }; - - // Only save cache for the current branch - // if the working directory is clean. - if ( await isCleanWorkingDir() ) { - sizeCache[ branch ] = { - meta: { commit }, - files: cacheResults( results ) - }; - console.log( `Saved cache for ${ branch }.` ); - } - - await saveCache( cache, sizeCache ); - - return results; -} 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/lib/compareSize.js b/build/tasks/lib/compareSize.js new file mode 100644 index 000000000..729bb37f2 --- /dev/null +++ b/build/tasks/lib/compareSize.js @@ -0,0 +1,193 @@ +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 chalk from "chalk"; +import isCleanWorkingDir from "./isCleanWorkingDir.js"; + +const VERSION = 1; +const lastRunBranch = " last run"; + +const gzip = promisify( zlib.gzip ); +const exec = promisify( nodeExec ); + +async function getBranchName() { + const { stdout } = await exec( "git rev-parse --abbrev-ref HEAD" ); + return stdout.trim(); +} + +async function getCommitHash() { + const { stdout } = await exec( "git rev-parse HEAD" ); + return stdout.trim(); +} + +function getBranchHeader( branch, commit ) { + let branchHeader = branch.trim(); + if ( commit ) { + branchHeader = chalk.bold( branchHeader ) + chalk.gray( ` @${ commit }` ); + } else { + branchHeader = chalk.italic( branchHeader ); + } + return branchHeader; +} + +async function getCache( loc ) { + let cache; + try { + const contents = await fs.readFile( loc, "utf8" ); + cache = JSON.parse( contents ); + } catch ( err ) { + return {}; + } + + const lastRun = cache[ lastRunBranch ]; + if ( !lastRun || !lastRun.meta || lastRun.meta.version !== VERSION ) { + console.log( "Compare cache version mismatch. Rewriting..." ); + return {}; + } + return cache; +} + +function cacheResults( results ) { + const files = Object.create( null ); + results.forEach( function( result ) { + files[ result.filename ] = { + raw: result.raw, + gz: result.gz + }; + } ); + return files; +} + +function saveCache( loc, cache ) { + + // Keep cache readable for manual edits + return fs.writeFile( loc, JSON.stringify( cache, null, " " ) + "\n" ); +} + +function compareSizes( existing, current, padLength ) { + if ( typeof current !== "number" ) { + return chalk.grey( `${ existing }`.padStart( padLength ) ); + } + const delta = current - existing; + if ( delta > 0 ) { + return chalk.red( `+${ delta }`.padStart( padLength ) ); + } + return chalk.green( `${ delta }`.padStart( padLength ) ); +} + +function sortBranches( a, b ) { + if ( a === lastRunBranch ) { + return 1; + } + if ( b === lastRunBranch ) { + return -1; + } + if ( a < b ) { + return -1; + } + if ( a > b ) { + return 1; + } + return 0; +} + +export async function compareSize( { cache = ".sizecache.json", files } = {} ) { + if ( !files || !files.length ) { + throw new Error( "No files specified" ); + } + + const branch = await getBranchName(); + const commit = await getCommitHash(); + const sizeCache = await getCache( cache ); + + let rawPadLength = 0; + let gzPadLength = 0; + const results = await Promise.all( + files.map( async function( filename ) { + + let contents = await fs.readFile( filename, "utf8" ); + + // Remove the short SHA and .dirty from comparisons. + // The short SHA so commits can be compared against each other + // and .dirty to compare with the existing branch during development. + const sha = /jQuery v\d+.\d+.\d+(?:-\w+)?(?:\+slim\.|\+)?([^ \.]+(?:\.dirty)?)?/.exec( contents )[ 1 ]; + contents = contents.replace( new RegExp( sha, "g" ), "" ); + + const size = Buffer.byteLength( contents, "utf8" ); + const gzippedSize = ( await gzip( contents ) ).length; + + // Add one to give space for the `+` or `-` in the comparison + rawPadLength = Math.max( rawPadLength, size.toString().length + 1 ); + gzPadLength = Math.max( gzPadLength, gzippedSize.toString().length + 1 ); + + return { filename, raw: size, gz: gzippedSize }; + } ) + ); + + const sizeHeader = "raw".padStart( rawPadLength ) + + "gz".padStart( gzPadLength + 1 ) + + " Filename"; + + const sizes = results.map( function( result ) { + const rawSize = result.raw.toString().padStart( rawPadLength ); + const gzSize = result.gz.toString().padStart( gzPadLength ); + return `${ rawSize } ${ gzSize } ${ result.filename }`; + } ); + + const comparisons = Object.keys( sizeCache ).sort( sortBranches ).map( function( branch ) { + const meta = sizeCache[ branch ].meta || {}; + const commit = meta.commit; + + const files = sizeCache[ branch ].files; + const branchSizes = Object.keys( files ).map( function( filename ) { + const branchResult = files[ filename ]; + const compareResult = results.find( function( result ) { + return result.filename === filename; + } ) || {}; + + const compareRaw = compareSizes( branchResult.raw, compareResult.raw, rawPadLength ); + const compareGz = compareSizes( branchResult.gz, compareResult.gz, gzPadLength ); + return `${ compareRaw } ${ compareGz } ${ filename }`; + } ); + + return [ + "", // New line before each branch + getBranchHeader( branch, commit ), + sizeHeader, + ...branchSizes + ].join( "\n" ); + } ); + + const output = [ + "", // Opening new line + chalk.bold( "Sizes" ), + sizeHeader, + ...sizes, + ...comparisons, + "" // Closing new line + ].join( "\n" ); + + console.log( output ); + + // Always save the last run + // Save version under last run + sizeCache[ lastRunBranch ] = { + meta: { version: VERSION }, + files: cacheResults( results ) + }; + + // Only save cache for the current branch + // if the working directory is clean. + if ( await isCleanWorkingDir() ) { + sizeCache[ branch ] = { + meta: { commit }, + files: cacheResults( results ) + }; + console.log( `Saved cache for ${ branch }.` ); + } + + await saveCache( cache, sizeCache ); + + return results; +} 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/rollup-plugin-file-overrides.js deleted file mode 100644 index c494e4e5d..000000000 --- a/build/tasks/lib/rollup-plugin-file-overrides.js +++ /dev/null @@ -1,24 +0,0 @@ -"use strict"; - -/** - * A Rollup plugin accepting a file overrides map and changing - * module sources to the overridden ones where provided. Files - * without overrides are loaded from disk. - * - * @param {Map} fileOverrides - */ -module.exports = ( fileOverrides ) => { - return { - name: "jquery-file-overrides", - load( id ) { - if ( fileOverrides.has( id ) ) { - - // Replace the module by a fake source. - return fileOverrides.get( id ); - } - - // Handle this module via the file system. - return null; - } - }; -}; diff --git a/build/tasks/lib/rollupFileOverridesPlugin.js b/build/tasks/lib/rollupFileOverridesPlugin.js new file mode 100644 index 000000000..fecb4efaa --- /dev/null +++ b/build/tasks/lib/rollupFileOverridesPlugin.js @@ -0,0 +1,22 @@ +/** + * A Rollup plugin accepting a file overrides map and changing + * module sources to the overridden ones where provided. Files + * without overrides are loaded from disk. + * + * @param {Map} fileOverrides + */ +export default function rollupFileOverrides( fileOverrides ) { + return { + name: "jquery-file-overrides", + load( id ) { + if ( fileOverrides.has( id ) ) { + + // Replace the module by a fake source. + return fileOverrides.get( id ); + } + + // Handle this module via the file system. + 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" ); -- cgit v1.2.3