aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2019-12-09 20:00:44 +0100
committerGitHub <noreply@github.com>2019-12-09 20:00:44 +0100
commitf37c2e51f36c8f8bab3879064a90e86a685feafc (patch)
treeb5a5c406a6550722af65ebf579f0a51d6d8c336e /build
parentd5c505e35d8c74ce8e9d99731a1a7eab0e0d911c (diff)
downloadjquery-f37c2e51f36c8f8bab3879064a90e86a685feafc.tar.gz
jquery-f37c2e51f36c8f8bab3879064a90e86a685feafc.zip
Build: Auto-convert sources to AMD
jQuery source has been migrated in gh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`. A "Load with AMD" checkbox was also restored to the QUnit setup. Note that, contrary to jQuery 3.x, AMD files need to be generated via `grunt amd` or `grunt` as sources are not authored in ECMAScript modules. To achieve a similar no-compile experience during jQuery 4.x testing, use the new "Load as modules" checkbox which works in all supported browsers except for IE & Edge (the legacy, EdgeHTML-based one). Ref gh-4541 Closes gh-4554
Diffstat (limited to 'build')
-rw-r--r--build/release.js15
-rw-r--r--build/release/dist.js1
-rw-r--r--build/tasks/amd.js43
3 files changed, 54 insertions, 5 deletions
diff --git a/build/release.js b/build/release.js
index 6011066ff..f463d8e40 100644
--- a/build/release.js
+++ b/build/release.js
@@ -22,18 +22,23 @@ module.exports = function( Release ) {
npmTags = Release.npmTags;
+ function setSrcVersion( filepath ) {
+ var contents = fs.readFileSync( filepath, "utf8" );
+ contents = contents.replace( /@VERSION/g, Release.newVersion );
+ fs.writeFileSync( filepath, contents, "utf8" );
+ }
+
Release.define( {
npmPublish: true,
issueTracker: "github",
/**
- * Set the version in the src folder for distributing AMD
+ * Set the version in the src folder for distributing ES modules
+ * and in the amd folder for AMD.
*/
_setSrcVersion: function() {
- var corePath = __dirname + "/../src/core.js",
- contents = fs.readFileSync( corePath, "utf8" );
- contents = contents.replace( /@VERSION/g, Release.newVersion );
- fs.writeFileSync( corePath, contents, "utf8" );
+ setSrcVersion( `${ __dirname }/../src/core.js` );
+ setSrcVersion( `${ __dirname }/../amd/core.js` );
},
/**
diff --git a/build/release/dist.js b/build/release/dist.js
index 0ca396811..e2b1c5fb4 100644
--- a/build/release/dist.js
+++ b/build/release/dist.js
@@ -13,6 +13,7 @@ module.exports = function( Release, files, complete ) {
// These files are included with the distribution
extras = [
+ "amd",
"src",
"LICENSE.txt",
"AUTHORS.txt",
diff --git a/build/tasks/amd.js b/build/tasks/amd.js
new file mode 100644
index 000000000..617773ff2
--- /dev/null
+++ b/build/tasks/amd.js
@@ -0,0 +1,43 @@
+/**
+ * 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"
+ };
+
+ 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 );
+ }
+ } );
+};