Skip to content

Commit d4b04ae

Browse files
authoredMar 17, 2025··
Build: Don't commit the min file or version to main, add release process
Changes: 1. Don't commit the minified file to the `main` branch. 2. Move the source file to `src/`. 3. Compute the version during the build. 4. Add a `release-it`-based release process. Closes gh-250
1 parent 65c0f35 commit d4b04ae

15 files changed

+4197
-300
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ tmp
1212

1313
npm-debug.log*
1414

15+
/dist
1516
/node_modules
1617

1718
# Ignore BrowserStack testing files

‎.release-it.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
module.exports = {
4+
preReleaseBase: 1,
5+
hooks: {
6+
"before:init": "bash ./build/release/pre-release.sh",
7+
"after:version:bump":
8+
"sed -i 's/main\\/AUTHORS.txt/${version}\\/AUTHORS.txt/' package.json",
9+
"after:bump": "cross-env VERSION=${version} npm run build",
10+
"before:git:release": "git add -f dist/",
11+
"after:release": "echo 'Run the following to complete the release:' && " +
12+
"echo './build/release/post-release.sh $\{version}'"
13+
},
14+
git: {
15+
commitMessage: "Release: ${version}",
16+
getLatestTagFromAllRefs: true,
17+
pushRepo: "git@github.com:jquery/jquery-mousewheel.git",
18+
requireBranch: "main",
19+
requireCleanWorkingDir: true
20+
},
21+
github: {
22+
pushRepo: "git@github.com:jquery/jquery-mousewheel.git",
23+
release: true,
24+
tokenRef: "JQUERY_GITHUB_TOKEN"
25+
},
26+
npm: {
27+
publish: true
28+
}
29+
};

‎ChangeLog.md ‎CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Mouse Wheel ChangeLog
1+
# Mouse Wheel Change Log
22

33
## 3.2.2
44

‎build/release/post-release.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
set -euo pipefail
4+
5+
# $1: Version
6+
7+
dist=tmp/release/dist
8+
9+
if [[ -z "$1" ]] then
10+
echo "Version is not set (1st argument)"
11+
exit 1
12+
fi
13+
14+
if [[ -z "$2" ]] then
15+
echo "Blog URL is not set (2nd argument)"
16+
exit 1
17+
fi
18+
19+
# Restore AUTHORS URL
20+
sed -i "s/$1\/AUTHORS.txt/main\/AUTHORS.txt/" package.json
21+
git add package.json
22+
23+
# Remove built files from tracking.
24+
npm run build:clean
25+
git rm --cached -r dist/
26+
git commit -m "Release: remove dist files from main branch"
27+
28+
# Wait for confirmation from user to push changes
29+
read -p "Press enter to push changes to main branch"
30+
git push

‎build/release/pre-release.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
set -euo pipefail
4+
5+
read -p "Press enter if you updated CHANGELOG.md; abort otherwise"
6+
7+
# Install dependencies
8+
npm ci
9+
10+
# Clean all release and build artifacts
11+
npm run build:clean
12+
13+
# Run tests
14+
npm test

‎build/tasks/build.mjs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
3+
import { exec as nodeExec } from "node:child_process";
4+
import util from "node:util";
5+
import { minify } from "./minify.mjs";
6+
7+
const exec = util.promisify( nodeExec );
8+
9+
const pkg = JSON.parse( await fs.readFile( "./package.json", "utf8" ) );
10+
11+
async function isCleanWorkingDir() {
12+
const { stdout } = await exec( "git status --untracked-files=no --porcelain" );
13+
return !stdout.trim();
14+
}
15+
16+
async function versionForDist( { srcPath, destPath, version } ) {
17+
const code = await fs.readFile( srcPath, "utf8" );
18+
const compiledContents = code.replace( /@VERSION/g, version );
19+
20+
await fs.mkdir( path.dirname( destPath ), { recursive: true } );
21+
await fs.writeFile( destPath, compiledContents );
22+
console.log( `${ destPath } v${ version } created.` );
23+
}
24+
25+
export async function build( { version = process.env.VERSION } = {} ) {
26+
27+
// Add the short commit hash to the version string
28+
// when the version is not for a release.
29+
if ( !version ) {
30+
const { stdout } = await exec( "git rev-parse --short HEAD" );
31+
const isClean = await isCleanWorkingDir();
32+
33+
// "+SHA" is semantically correct
34+
// Add ".dirty" as well if the working dir is not clean
35+
version = `${ pkg.version }+${ stdout.trim() }${
36+
isClean ? "" : ".dirty"
37+
}`;
38+
}
39+
40+
await versionForDist( {
41+
srcPath: "src/jquery.mousewheel.js",
42+
destPath: "dist/jquery.mousewheel.js",
43+
version
44+
} );
45+
46+
await minify( {
47+
srcPath: "dist/jquery.mousewheel.js",
48+
destPath: "dist/jquery.mousewheel.min.js",
49+
version
50+
} );
51+
}
+11-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import fs from "node:fs/promises";
2-
import path from "node:path";
32
import swc from "@swc/core";
3+
import path from "node:path";
44

5-
const rjs = /\.js$/;
5+
export async function minify( { srcPath, destPath, version } ) {
6+
const contents = await fs.readFile( srcPath, "utf8" );
67

7-
export async function minify( { filename, dir } ) {
8-
const contents = await fs.readFile( path.join( dir, filename ), "utf8" );
8+
await fs.mkdir( path.dirname( destPath ), { recursive: true } );
99

1010
const { code } = await swc.minify(
1111
contents,
@@ -17,7 +17,11 @@ export async function minify( { filename, dir } ) {
1717
},
1818
format: {
1919
ecma: 5,
20-
asciiOnly: true
20+
asciiOnly: true,
21+
comments: false,
22+
preamble: `/*! jQuery Mousewheel ${ version }` +
23+
" | (c) OpenJS Foundation and other contributors" +
24+
" | jquery.org/license */\n"
2125
},
2226
inlineSourcesContent: false,
2327
mangle: true,
@@ -26,12 +30,10 @@ export async function minify( { filename, dir } ) {
2630
}
2731
);
2832

29-
const minFilename = filename.replace( rjs, ".min.js" );
30-
3133
await fs.writeFile(
32-
path.join( dir, minFilename ),
34+
destPath,
3335
code
3436
);
3537

36-
console.log( `file ${ minFilename } created.` );
38+
console.log( `file ${ destPath } created.` );
3739
}

‎eslint.config.mjs

+22-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ import globals from "globals";
33

44
export default [
55
{
6-
ignores: [ "**/*.min.js" ],
6+
ignores: [ "dist/**/*.js" ],
77
rules: {
88
...jqueryConfig.rules,
99
indent: [ "error", 4 ]
1010
}
1111
},
1212

1313
{
14-
files: [ "jquery.mousewheel.js", "jquery.mousewheel.min.js", "test/**/*.js" ],
14+
files: [
15+
"src/**/*.js",
16+
"dist/**/*.js",
17+
"test/**/*.js"
18+
],
1519
languageOptions: {
1620

1721
// Support: IE 9 - 11+
@@ -31,7 +35,7 @@ export default [
3135
},
3236

3337
{
34-
files: [ "jquery.mousewheel.js" ],
38+
files: [ "src/**/*.js" ],
3539
rules: {
3640
strict: [ "error", "function" ],
3741
indent: [
@@ -61,7 +65,21 @@ export default [
6165
},
6266

6367
{
64-
files: [ "eslint.config.mjs", "build/**/*.mjs" ],
68+
files: [ "*.js" ],
69+
languageOptions: {
70+
ecmaVersion: "latest",
71+
sourceType: "commonjs",
72+
globals: {
73+
...globals.node
74+
}
75+
},
76+
rules: {
77+
...jqueryConfig.rules
78+
}
79+
},
80+
81+
{
82+
files: [ "*.mjs", "build/**/*.mjs" ],
6583
languageOptions: {
6684
ecmaVersion: "latest",
6785
sourceType: "module",

‎jquery.mousewheel.min.js

-4
This file was deleted.

‎package-lock.json

+4,017-267
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+12-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"description": "A jQuery plugin that adds cross-browser mouse wheel support.",
99
"license": "MIT",
1010
"homepage": "https://github.com/jquery/jquery-mousewheel",
11-
"main": "./jquery.mousewheel.js",
11+
"main": "dist/jquery.mousewheel.js",
1212
"repository": {
1313
"type": "git",
1414
"url": "https://github.com/jquery/jquery-mousewheel.git"
@@ -26,19 +26,20 @@
2626
"browser"
2727
],
2828
"files": [
29-
"ChangeLog.md",
30-
"jquery.mousewheel.js",
31-
"jquery.mousewheel.min.js",
29+
"CHANGELOG.md",
30+
"dist/jquery.mousewheel.js",
31+
"dist/jquery.mousewheel.min.js",
3232
"README.md",
3333
"LICENSE.txt"
3434
],
3535
"directories": {
3636
"test": "test"
3737
},
3838
"scripts": {
39-
"build": "npm run minify",
40-
"minify": "node --input-type=module -e \"import { minify } from './build/minify.mjs'; minify( { dir: '.', filename: 'jquery.mousewheel.js' } )\"",
39+
"build": "node --input-type=module -e \"import { build } from './build/tasks/build.mjs'; build()\"",
40+
"build:clean": "rimraf dist",
4141
"lint": "eslint .",
42+
"release": "release-it",
4243
"test:browser": "npm run build && npm run test:unit -- -b chrome -b firefox --headless",
4344
"test:chrome": "npm run build && npm run test:unit -- -v -b chrome --headless",
4445
"test:edge": "npm run build && npm run test:unit -- -v -b edge --headless",
@@ -52,12 +53,14 @@
5253
"jquery": ">=1.2.6"
5354
},
5455
"devDependencies": {
55-
"@swc/core": "^1.11.8",
56+
"@swc/core": "1.11.8",
5657
"eslint": "9.22.0",
5758
"eslint-config-jquery": "3.0.2",
58-
"globals": "^16.0.0",
59+
"globals": "16.0.0",
5960
"jquery-test-runner": "0.2.6",
6061
"qunit": "2.24.1",
61-
"requirejs": "2.3.7"
62+
"requirejs": "2.3.7",
63+
"release-it": "18.1.2",
64+
"rimraf": "^6.0.1"
6265
}
6366
}

‎jquery.mousewheel.js ‎src/jquery.mousewheel.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/*!
2-
* jQuery Mousewheel 3.2.2
2+
* jQuery Mousewheel v@VERSION
3+
* https://github.com/jquery/jquery-mousewheel
4+
*
35
* Copyright OpenJS Foundation and other contributors
6+
* Released under the MIT license
7+
* https://jquery.org/license
48
*/
5-
69
( function( factory ) {
710
"use strict";
811

@@ -36,7 +39,7 @@
3639
}
3740

3841
var special = $.event.special.mousewheel = {
39-
version: "3.2.2",
42+
version: "@VERSION",
4043

4144
setup: function() {
4245
if ( this.addEventListener ) {

‎test/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
document.write( "<script src=\"" + scriptUrl + "\"><" + "/script>" );
1919
</script>
20-
<script src="../jquery.mousewheel.js"></script>
20+
<script src="../src/jquery.mousewheel.js"></script>
2121
<script src="unit.js"></script>
2222
<script>
2323
jQuery( function( $ ) {

‎test/manual.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
}
214214
} );
215215
</script>
216-
<script src="../jquery.mousewheel.js"></script>
216+
<script src="../src/jquery.mousewheel.js"></script>
217217
</head>
218218
<body>
219219
<h1 id="banner">jQuery mousewheel.js Test with jQuery <span id="jqueryVersion"></span></h1>

‎test/scroll.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
document.write( "<script src=\"" + src + "\"><\/script>" );
2525
} )();
2626
</script>
27-
<script src="../jquery.mousewheel.js"></script>
27+
<script src="../src/jquery.mousewheel.js"></script>
2828
<script>
2929
var lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus rhoncus nibh ac ultricies blandit. Nunc blandit blandit lobortis. Maecenas id dolor scelerisque, facilisis dolor eu, interdum urna. Nullam consectetur lectus quis mi interdum accumsan. Nulla malesuada est nec neque suscipit pulvinar. Vivamus sagittis, nunc a porttitor tempus, mi neque eleifend diam, nec porttitor metus dui a orci. Cras tempus lobortis nisl ut sagittis. Maecenas semper in magna mollis venenatis. Vestibulum fermentum tincidunt fringilla.";
3030
$( function() {

0 commit comments

Comments
 (0)
Please sign in to comment.