mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Build: Drop individual AMD modules
With this change, jQuery build no longer generates the `amd` directory with AMD modules transpiled from source `src` ECMAScript Modules. To use individual jQuery modules from source, ESM is now required. Note that this DOES NOT affect the main `"jquery"` AMD module defined by built jQuery files; those remain supported. Closes gh-5276
This commit is contained in:
parent
62b9a25834
commit
5701957b72
@ -1,4 +1,3 @@
|
|||||||
amd
|
|
||||||
external
|
external
|
||||||
node_modules
|
node_modules
|
||||||
*.min.js
|
*.min.js
|
||||||
|
4
.github/workflows/node.js.yml
vendored
4
.github/workflows/node.js.yml
vendored
@ -36,10 +36,6 @@ jobs:
|
|||||||
NODE_VERSION: "18.x"
|
NODE_VERSION: "18.x"
|
||||||
NPM_SCRIPT: "test:esmodules"
|
NPM_SCRIPT: "test:esmodules"
|
||||||
BROWSERS: "ChromeHeadless"
|
BROWSERS: "ChromeHeadless"
|
||||||
- NAME: "Browser tests: AMD build, Chrome"
|
|
||||||
NODE_VERSION: "18.x"
|
|
||||||
NPM_SCRIPT: "test:amd"
|
|
||||||
BROWSERS: "ChromeHeadless"
|
|
||||||
- NAME: "Browser tests: full build, Firefox ESR"
|
- NAME: "Browser tests: full build, Firefox ESR"
|
||||||
NODE_VERSION: "18.x"
|
NODE_VERSION: "18.x"
|
||||||
NPM_SCRIPT: "test:browser"
|
NPM_SCRIPT: "test:browser"
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,7 +16,6 @@ npm-debug.log*
|
|||||||
/dist/*
|
/dist/*
|
||||||
!/dist/.eslintrc.json
|
!/dist/.eslintrc.json
|
||||||
|
|
||||||
/amd
|
|
||||||
/external
|
/external
|
||||||
/node_modules
|
/node_modules
|
||||||
|
|
||||||
|
22
Gruntfile.js
22
Gruntfile.js
@ -225,12 +225,6 @@ module.exports = function( grunt ) {
|
|||||||
served: true,
|
served: true,
|
||||||
nocache: true
|
nocache: true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
pattern: "amd/**",
|
|
||||||
included: false,
|
|
||||||
served: true,
|
|
||||||
nocache: true
|
|
||||||
},
|
|
||||||
{ pattern: "external/**", included: false, served: true },
|
{ pattern: "external/**", included: false, served: true },
|
||||||
{
|
{
|
||||||
pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
|
pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
|
||||||
@ -268,21 +262,6 @@ module.exports = function( grunt ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
amd: {
|
|
||||||
browsers: customBrowsers || [ "ChromeHeadless" ],
|
|
||||||
options: {
|
|
||||||
client: {
|
|
||||||
qunit: {
|
|
||||||
|
|
||||||
// We're running `QUnit.start()` ourselves via `loadTests()`
|
|
||||||
// in test/jquery.js
|
|
||||||
autostart: false,
|
|
||||||
|
|
||||||
amd: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
jsdom: {
|
jsdom: {
|
||||||
options: {
|
options: {
|
||||||
@ -431,7 +410,6 @@ module.exports = function( grunt ) {
|
|||||||
grunt.registerTask( "default", [
|
grunt.registerTask( "default", [
|
||||||
runIfNewNode( "eslint:dev" ),
|
runIfNewNode( "eslint:dev" ),
|
||||||
"build:*:*",
|
"build:*:*",
|
||||||
"amd",
|
|
||||||
"terser",
|
"terser",
|
||||||
"remove_map_comment",
|
"remove_map_comment",
|
||||||
"dist:*",
|
"dist:*",
|
||||||
|
@ -32,12 +32,10 @@ module.exports = function( Release ) {
|
|||||||
issueTracker: "github",
|
issueTracker: "github",
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the version in the src folder for distributing ES modules
|
* Set the version in the src folder for distributing ES modules.
|
||||||
* and in the amd folder for AMD.
|
|
||||||
*/
|
*/
|
||||||
_setSrcVersion: function() {
|
_setSrcVersion: function() {
|
||||||
setSrcVersion( `${ __dirname }/../src/core.js` );
|
setSrcVersion( `${ __dirname }/../src/core.js` );
|
||||||
setSrcVersion( `${ __dirname }/../amd/core.js` );
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,7 +13,6 @@ module.exports = function( Release, files, complete ) {
|
|||||||
|
|
||||||
// These files are included with the distribution
|
// These files are included with the distribution
|
||||||
const extras = [
|
const extras = [
|
||||||
"amd",
|
|
||||||
"src",
|
"src",
|
||||||
"LICENSE.txt",
|
"LICENSE.txt",
|
||||||
"AUTHORS.txt",
|
"AUTHORS.txt",
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
/**
|
|
||||||
* Compiles sources from ES Modules in `src/` to AMD in `amd/`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = function( grunt ) {
|
|
||||||
const path = require( "path" );
|
|
||||||
const rimraf = require( "rimraf" );
|
|
||||||
const rollup = require( "rollup" );
|
|
||||||
const srcFolder = path.resolve( __dirname, "..", "..", "src" );
|
|
||||||
const amdFolder = path.resolve( srcFolder, "..", "amd" );
|
|
||||||
const inputFileName = "jquery.js";
|
|
||||||
|
|
||||||
const inputRollupOptions = {
|
|
||||||
input: path.resolve( srcFolder, inputFileName ),
|
|
||||||
preserveModules: true
|
|
||||||
};
|
|
||||||
|
|
||||||
const outputRollupOptions = {
|
|
||||||
format: "amd",
|
|
||||||
dir: "amd",
|
|
||||||
indent: false
|
|
||||||
};
|
|
||||||
|
|
||||||
grunt.registerTask(
|
|
||||||
"amd",
|
|
||||||
"Convert ES modules from `src/` to AMD modules in `amd/`",
|
|
||||||
async function() {
|
|
||||||
const done = this.async();
|
|
||||||
|
|
||||||
try {
|
|
||||||
grunt.verbose.writeln( "Removing the 'amd' directory..." );
|
|
||||||
rimraf( amdFolder, async function() {
|
|
||||||
const bundle = await rollup.rollup( inputRollupOptions );
|
|
||||||
await bundle.write( outputRollupOptions );
|
|
||||||
grunt.log.ok( "Sources from 'src' converted to AMD in 'amd'." );
|
|
||||||
done();
|
|
||||||
} );
|
|
||||||
} catch ( err ) {
|
|
||||||
done( err );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
};
|
|
@ -76,11 +76,10 @@
|
|||||||
"test:browserless": "grunt && grunt test:slow",
|
"test:browserless": "grunt && grunt test:slow",
|
||||||
"test:browser": "grunt && grunt karma:main",
|
"test:browser": "grunt && grunt karma:main",
|
||||||
"test:esmodules": "grunt && grunt karma:esmodules",
|
"test:esmodules": "grunt && grunt karma:esmodules",
|
||||||
"test:amd": "grunt && grunt karma:amd",
|
|
||||||
"test:no-deprecated": "grunt test:prepare && grunt custom:-deprecated && grunt karma:main",
|
"test:no-deprecated": "grunt test:prepare && grunt custom:-deprecated && grunt karma:main",
|
||||||
"test:selector-native": "grunt test:prepare && grunt custom:-selector && grunt karma:main",
|
"test:selector-native": "grunt test:prepare && grunt custom:-selector && grunt karma:main",
|
||||||
"test:slim": "grunt test:prepare && grunt custom:slim && grunt karma:main",
|
"test:slim": "grunt test:prepare && grunt custom:slim && grunt karma:main",
|
||||||
"test": "npm run test:slim && npm run test:no-deprecated && npm run test:selector-native && grunt && grunt test:slow && grunt karma:main && grunt karma:esmodules && grunt karma:amd",
|
"test": "npm run test:slim && npm run test:no-deprecated && npm run test:selector-native && grunt && grunt test:slow && grunt karma:main && grunt karma:esmodules",
|
||||||
"jenkins": "npm run test:browserless"
|
"jenkins": "npm run test:browserless"
|
||||||
},
|
},
|
||||||
"commitplease": {
|
"commitplease": {
|
||||||
|
@ -366,11 +366,10 @@ this.loadTests = function() {
|
|||||||
|
|
||||||
// QUnit.config is populated from QUnit.urlParams but only at the beginning
|
// QUnit.config is populated from QUnit.urlParams but only at the beginning
|
||||||
// of the test run. We need to read both.
|
// of the test run. We need to read both.
|
||||||
var esmodules = QUnit.config.esmodules || QUnit.urlParams.esmodules,
|
var esmodules = QUnit.config.esmodules || QUnit.urlParams.esmodules;
|
||||||
amd = QUnit.config.amd || QUnit.urlParams.amd;
|
|
||||||
|
|
||||||
// Directly load tests that need evaluation before DOMContentLoaded.
|
// Directly load tests that need evaluation before DOMContentLoaded.
|
||||||
if ( ( !esmodules && !amd ) || document.readyState === "loading" ) {
|
if ( !esmodules || document.readyState === "loading" ) {
|
||||||
document.write( "<script src='" + parentUrl + "test/unit/ready.js'><\x2Fscript>" );
|
document.write( "<script src='" + parentUrl + "test/unit/ready.js'><\x2Fscript>" );
|
||||||
} else {
|
} else {
|
||||||
QUnit.module( "ready", function() {
|
QUnit.module( "ready", function() {
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
<!-- See testinit for the list of tests -->
|
<!-- See testinit for the list of tests -->
|
||||||
<script src="data/testinit.js"></script>
|
<script src="data/testinit.js"></script>
|
||||||
|
|
||||||
<!-- A script that includes jQuery min, dev, ES modules or AMD modules -->
|
<!-- A script that includes jQuery min, dev or ES modules -->
|
||||||
<!-- Adds "basic" URL option, even to iframes -->
|
<!-- Adds "basic" URL option, even to iframes -->
|
||||||
<!-- iframes will not load AMD as loading needs to be synchronous for some tests -->
|
<!-- iframes will not load ESM as loading needs to be synchronous for some tests -->
|
||||||
<!-- Also executes the function above to load tests -->
|
<!-- Also executes the function above to load tests -->
|
||||||
<script src="jquery.js"></script>
|
<script src="jquery.js"></script>
|
||||||
|
|
||||||
@ -31,13 +31,12 @@
|
|||||||
// jQuery is on the page when the testrunner executes
|
// jQuery is on the page when the testrunner executes
|
||||||
// QUnit.config is populated from QUnit.urlParams but only at the beginning
|
// QUnit.config is populated from QUnit.urlParams but only at the beginning
|
||||||
// of the test run. We need to read both.
|
// of the test run. We need to read both.
|
||||||
var esmodules = QUnit.config.esmodules || QUnit.urlParams.esmodules,
|
var esmodules = QUnit.config.esmodules || QUnit.urlParams.esmodules;
|
||||||
amd = QUnit.config.amd || QUnit.urlParams.amd;
|
|
||||||
|
|
||||||
// Workaround: Remove call to `window.__karma__.loaded()`
|
// Workaround: Remove call to `window.__karma__.loaded()`
|
||||||
// in favor of calling `window.__karma__.start()` from `loadTests()`
|
// in favor of calling `window.__karma__.start()` from `loadTests()`
|
||||||
// because tests such as unit/ready.js should run after document ready.
|
// because tests such as unit/ready.js should run after document ready.
|
||||||
if ( !esmodules && !amd ) {
|
if ( !esmodules ) {
|
||||||
loadTests();
|
loadTests();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
18
test/jquery.js
vendored
18
test/jquery.js
vendored
@ -37,10 +37,6 @@
|
|||||||
id: "esmodules",
|
id: "esmodules",
|
||||||
label: "Load as modules",
|
label: "Load as modules",
|
||||||
tooltip: "Load the jQuery module file (and its dependencies)"
|
tooltip: "Load the jQuery module file (and its dependencies)"
|
||||||
}, {
|
|
||||||
id: "amd",
|
|
||||||
label: "Load with AMD",
|
|
||||||
tooltip: "Load the AMD jQuery file (and its dependencies)"
|
|
||||||
}, {
|
}, {
|
||||||
id: "dev",
|
id: "dev",
|
||||||
label: "Load unminified",
|
label: "Load unminified",
|
||||||
@ -77,20 +73,6 @@
|
|||||||
|
|
||||||
eval( dynamicImportSource );
|
eval( dynamicImportSource );
|
||||||
|
|
||||||
// Apply similar treatment for AMD modules
|
|
||||||
} else if ( config.amd && QUnit ) {
|
|
||||||
require.config( {
|
|
||||||
baseUrl: parentUrl
|
|
||||||
} );
|
|
||||||
src = "amd/jquery";
|
|
||||||
|
|
||||||
// Include tests if specified
|
|
||||||
if ( typeof loadTests !== "undefined" ) {
|
|
||||||
require( [ src ], loadTests );
|
|
||||||
} else {
|
|
||||||
require( [ src ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, load synchronously
|
// Otherwise, load synchronously
|
||||||
} else {
|
} else {
|
||||||
document.write( "<script id='jquery-js' nonce='jquery+hardcoded+nonce' src='" + parentUrl + src + "'><\x2Fscript>" );
|
document.write( "<script id='jquery-js' nonce='jquery+hardcoded+nonce' src='" + parentUrl + src + "'><\x2Fscript>" );
|
||||||
|
@ -30,13 +30,12 @@
|
|||||||
<script>
|
<script>
|
||||||
// QUnit.config is populated from QUnit.urlParams but only at the beginning
|
// QUnit.config is populated from QUnit.urlParams but only at the beginning
|
||||||
// of the test run. We need to read both.
|
// of the test run. We need to read both.
|
||||||
var esmodules = QUnit.config.esmodules || QUnit.urlParams.esmodules,
|
var esmodules = QUnit.config.esmodules || QUnit.urlParams.esmodules;
|
||||||
amd = QUnit.config.amd || QUnit.urlParams.amd;
|
|
||||||
|
|
||||||
// Workaround: Remove call to `window.__karma__.loaded()`
|
// Workaround: Remove call to `window.__karma__.loaded()`
|
||||||
// in favor of calling `window.__karma__.start()` from `loadTests()`
|
// in favor of calling `window.__karma__.start()` from `loadTests()`
|
||||||
// because tests such as unit/ready.js should run after document ready.
|
// because tests such as unit/ready.js should run after document ready.
|
||||||
if ( !esmodules && !amd ) {
|
if ( !esmodules ) {
|
||||||
loadTests();
|
loadTests();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -32,13 +32,12 @@
|
|||||||
<script>
|
<script>
|
||||||
// QUnit.config is populated from QUnit.urlParams but only at the beginning
|
// QUnit.config is populated from QUnit.urlParams but only at the beginning
|
||||||
// of the test run. We need to read both.
|
// of the test run. We need to read both.
|
||||||
var esmodules = QUnit.config.esmodules || QUnit.urlParams.esmodules,
|
var esmodules = QUnit.config.esmodules || QUnit.urlParams.esmodules;
|
||||||
amd = QUnit.config.amd || QUnit.urlParams.amd;
|
|
||||||
|
|
||||||
// Workaround: Remove call to `window.__karma__.loaded()`
|
// Workaround: Remove call to `window.__karma__.loaded()`
|
||||||
// in favor of calling `window.__karma__.start()` from `loadTests()`
|
// in favor of calling `window.__karma__.start()` from `loadTests()`
|
||||||
// because tests such as unit/ready.js should run after document ready.
|
// because tests such as unit/ready.js should run after document ready.
|
||||||
if ( !esmodules && !amd ) {
|
if ( !esmodules ) {
|
||||||
loadTests();
|
loadTests();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user