Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf37c2e5

Browse files
authored
Build: Auto-convert sources to AMD
jQuery source has been migrated ingh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe 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 similarno-compile experience during jQuery 4.x testing, use the new "Load as modules"checkbox which works in all supported browsers except for IE & Edge (thelegacy, EdgeHTML-based one).Refgh-4541Closesgh-4554
1 parentd5c505e commitf37c2e5

File tree

10 files changed

+91
-16
lines changed

10 files changed

+91
-16
lines changed

‎.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
external
1+
amd
22
node_modules
33
*.min.js
44
dist/**

‎.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ npm-debug.log*
1616
/dist/*
1717
!/dist/.eslintrc.json
1818

19+
/amd
20+
1921
/node_modules
2022

2123
/test/data/core/jquery-iterability-transpiled.js

‎Gruntfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ module.exports = function( grunt ) {
178178

179179
{pattern:"dist/jquery.*",included:false,served:true},
180180
{pattern:"src/**",type:"module",included:false,served:true},
181+
{pattern:"amd/**",included:false,served:true},
181182
{pattern:"node_modules/**",included:false,served:true},
182183
{
183184
pattern:"test/**/*.@(js|css|jpg|html|xml|svg)",
@@ -319,6 +320,7 @@ module.exports = function( grunt ) {
319320
grunt.registerTask("default",[
320321
"eslint:dev",
321322
"build:*:*",
323+
"amd",
322324
"uglify",
323325
"remove_map_comment",
324326
"dist:*",

‎build/release.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@ module.exports = function( Release ) {
2222

2323
npmTags=Release.npmTags;
2424

25+
functionsetSrcVersion(filepath){
26+
varcontents=fs.readFileSync(filepath,"utf8");
27+
contents=contents.replace(/@VERSION/g,Release.newVersion);
28+
fs.writeFileSync(filepath,contents,"utf8");
29+
}
30+
2531
Release.define({
2632
npmPublish:true,
2733
issueTracker:"github",
2834

2935
/**
30-
* Set the version in the src folder for distributing AMD
36+
* Set the version in the src folder for distributing ES modules
37+
* and in the amd folder for AMD.
3138
*/
3239
_setSrcVersion:function(){
33-
varcorePath=__dirname+"/../src/core.js",
34-
contents=fs.readFileSync(corePath,"utf8");
35-
contents=contents.replace(/@VERSION/g,Release.newVersion);
36-
fs.writeFileSync(corePath,contents,"utf8");
40+
setSrcVersion(`${__dirname}/../src/core.js`);
41+
setSrcVersion(`${__dirname}/../amd/core.js`);
3742
},
3843

3944
/**

‎build/release/dist.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = function( Release, files, complete ) {
1313

1414
// These files are included with the distribution
1515
extras=[
16+
"amd",
1617
"src",
1718
"LICENSE.txt",
1819
"AUTHORS.txt",

‎build/tasks/amd.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Compiles sources from ES Modules in `src/` to AMD in `amd/`.
3+
*/
4+
5+
"use strict";
6+
7+
module.exports=function(grunt){
8+
constpath=require("path");
9+
constrimraf=require("rimraf");
10+
constrollup=require("rollup");
11+
constsrcFolder=path.resolve(__dirname,"..","..","src");
12+
constamdFolder=path.resolve(srcFolder,"..","amd");
13+
constinputFileName="jquery.js";
14+
15+
constinputRollupOptions={
16+
input:path.resolve(srcFolder,inputFileName),
17+
preserveModules:true
18+
};
19+
20+
constoutputRollupOptions={
21+
format:"amd",
22+
dir:"amd"
23+
};
24+
25+
grunt.registerTask(
26+
"amd",
27+
"Convert ES modules from `src/` to AMD modules in `amd/`",
28+
asyncfunction(){
29+
constdone=this.async();
30+
31+
try{
32+
grunt.verbose.writeln("Removing the 'amd' directory...");
33+
rimraf(amdFolder,asyncfunction(){
34+
constbundle=awaitrollup.rollup(inputRollupOptions);
35+
awaitbundle.write(outputRollupOptions);
36+
grunt.log.ok("Sources from 'src' converted to AMD in 'amd'.");
37+
done();
38+
});
39+
}catch(err){
40+
done(err);
41+
}
42+
});
43+
};

‎package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"qunit":"2.9.2",
6161
"raw-body":"2.3.3",
6262
"requirejs":"2.3.6",
63-
"rollup":"1.25.2",
63+
"rimraf":"3.0.0",
64+
"rollup":"1.27.6",
6465
"sinon":"7.3.1",
6566
"strip-json-comments":"2.0.1",
6667
"testswarm":"1.1.0",

‎test/data/testinit.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,16 @@ QUnit.testUnlessIE = QUnit.isIE ? QUnit.skip : QUnit.test;
299299

300300
this.loadTests=function(){
301301

302-
// Directly load tests that need synchronous evaluation
303-
if(!QUnit.urlParams.esmodules||document.readyState==="loading"){
302+
// QUnit.config is populated from QUnit.urlParams but only at the beginning
303+
// of the test run. We need to read both.
304+
varamd=QUnit.config.amd||QUnit.urlParams.amd;
305+
306+
// Directly load tests that need evaluation before DOMContentLoaded.
307+
if(!amd||document.readyState==="loading"){
304308
document.write("<script src='"+parentUrl+"test/unit/ready.js'><\x2Fscript>");
305309
}else{
306310
QUnit.module("ready",function(){
307-
QUnit.test("jQuery ready",function(assert){
308-
assert.ok(false,"Test should be initialized before DOM ready");
309-
});
311+
QUnit.skip("jQuery ready tests skipped in async mode",function(){});
310312
});
311313
}
312314

‎test/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<!-- See testinit for the list of tests -->
2020
<scriptsrc="data/testinit.js"></script>
2121

22-
<!-- A script that includes jQuery min, dev,orES modules -->
22+
<!-- A script that includes jQuery min, dev, ES modules or AMD -->
2323
<!-- Adds "basic" URL option, even to iframes -->
2424
<!-- iframes will not load AMD as loading needs to be synchronous for some tests -->
2525
<!-- Also executes the function above to load tests -->
@@ -29,7 +29,7 @@
2929
// Load tests if they have not been loaded
3030
// This is in a different script tag to ensure that
3131
// jQuery is on the page when the testrunner executes
32-
if(!QUnit.urlParams.esmodules){
32+
if(!QUnit.urlParams.esmodules&&!QUnit.urlParams.amd){
3333
loadTests();
3434
}
3535
</script>

‎test/jquery.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828
QUnit.config.urlConfig.push({
2929
id:"esmodules",
3030
label:"Load as modules",
31-
tooltip:"Load a relevant jQuery module file (and its dependencies)"
31+
tooltip:"Load the jQuery module file (and its dependencies)"
32+
});
33+
QUnit.config.urlConfig.push({
34+
id:"amd",
35+
label:"Load with AMD",
36+
tooltip:"Load the AMD jQuery file (and its dependencies)"
3237
});
3338
}
3439

@@ -39,7 +44,7 @@
3944
});
4045
}
4146

42-
// HonorAMD loading on the main window (detected by seeing QUnit on it).
47+
// HonorES modules loading on the main window (detected by seeing QUnit on it).
4348
// This doesn't apply to iframes because they synchronously expect jQuery to be there.
4449
if(urlParams.esmodules&&window.QUnit){
4550

@@ -57,6 +62,20 @@
5762

5863
eval(dynamicImportSource);
5964

65+
// Apply similar treatment for AMD modules
66+
}elseif(urlParams.amd&&window.QUnit){
67+
require.config({
68+
baseUrl:parentUrl
69+
});
70+
src="amd/jquery";
71+
72+
// Include tests if specified
73+
if(typeofloadTests!=="undefined"){
74+
require([src],loadTests);
75+
}else{
76+
require([src]);
77+
}
78+
6079
// Otherwise, load synchronously
6180
}else{
6281
document.write("<script id='jquery-js' nonce='jquery+hardcoded+nonce' src='"+parentUrl+src+"'><\x2Fscript>");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp