Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1cb15ee

Browse files
committedMar 31, 2025··
Core: Provide a package.json exports setup inspired by jQuery Core
The Migrate setup is simpler than Core as it doesn't have the slim or factory versions, but the core ideas are similar. Ref jquery/jquery#5255 Ref jquery/jquery#5429
1 parent 868e11d commit 1cb15ee

26 files changed

+1635
-59
lines changed
 

‎.github/workflows/browser-tests.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ jobs:
4343
run: npm install
4444

4545
- name: Run tests
46-
run: |
47-
npm run pretest
48-
npm run test:unit -- -c jtr-local.yml \
49-
--headless -b ${{ matrix.BROWSER }} -f plugin=${{ matrix.MIGRATE_VERSION }}
46+
run: npm run test:browser -- -f plugin=${{ matrix.MIGRATE_VERSION }}
5047

5148
ie:
5249
runs-on: windows-latest

‎.github/workflows/browserstack.yml

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ jobs:
5858
- name: Install dependencies
5959
run: npm install
6060

61+
- name: Build jQuery
62+
run: npm run build:all
63+
6164
- name: Pretest script
6265
run: npm run pretest
6366

‎.github/workflows/node.js.yml

+18-11
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,39 @@ on:
55
push:
66
branches-ignore: "dependabot/**"
77

8-
env:
9-
NODE_VERSION: 22.x
10-
118
jobs:
12-
node-smoke-test:
9+
build-and-test:
1310
runs-on: ubuntu-latest
14-
name: Node smoke tests
11+
name: ${{ matrix.NPM_SCRIPT }} - ${{ matrix.NAME }} (${{ matrix.NODE_VERSION }})
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
NAME: ["Node"]
16+
NODE_VERSION: [18.x, 20.x, 22.x, 23.x]
17+
NPM_SCRIPT: ["test:browserless"]
18+
include:
19+
- NAME: "Node"
20+
NODE_VERSION: "22.x"
21+
NPM_SCRIPT: "lint"
1522
steps:
1623
- name: Checkout
1724
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1825

19-
- name: Use Node.js ${{ env.NODE_VERSION }}
26+
- name: Use Node.js ${{ matrix.NODE_VERSION }}
2027
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
2128
with:
22-
node-version: ${{ env.NODE_VERSION }}
29+
node-version: ${{ matrix.NODE_VERSION }}
2330

2431
- name: Cache
2532
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
2633
with:
2734
path: ~/.npm
28-
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-${{ hashFiles('**/package-lock.json') }}
35+
key: ${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-npm-lock-${{ hashFiles('**/package-lock.json') }}
2936
restore-keys: |
30-
${{ runner.os }}-node-${{ env.NODE_VERSION }}-npm-lock-
37+
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-npm-lock-
3138
3239
- name: Install dependencies
3340
run: npm install
3441

35-
- name: Run Node smoke tests
36-
run: npm run test:node_smoke_tests
42+
- name: Run tests
43+
run: npm run ${{ matrix.NPM_SCRIPT }}

‎.gitignore

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ CDN
1111
.eslintcache
1212

1313
# Ignore built files in `dist` folder
14-
# Leave package.json
14+
# Leave the package.json and wrappers
1515
/dist/*
1616
!/dist/package.json
17+
!/dist/wrappers
18+
19+
# Ignore built files in `dist-module` folder
20+
# Leave the package.json and wrappers
21+
/dist-module/*
22+
!/dist-module/package.json
23+
!/dist-module/wrappers
1724

1825
/external
1926
/node_modules

‎build/command.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import yargs from "yargs/yargs";
2+
import { build } from "./tasks/build.js";
3+
4+
const argv = yargs( process.argv.slice( 2 ) )
5+
.version( false )
6+
.command( {
7+
command: "[options]",
8+
describe: "Build a jQuery Migrate bundle"
9+
} )
10+
.option( "filename", {
11+
alias: "f",
12+
type: "string",
13+
description:
14+
"Set the filename of the built file. Defaults to jquery.js."
15+
} )
16+
.option( "dir", {
17+
alias: "d",
18+
type: "string",
19+
description:
20+
"Set the dir to which to output the built file. Defaults to /dist."
21+
} )
22+
.option( "version", {
23+
alias: "v",
24+
type: "string",
25+
description:
26+
"Set the version to include in the built file. " +
27+
"Defaults to the version in package.json plus the " +
28+
"short commit SHA and any excluded modules."
29+
} )
30+
.option( "watch", {
31+
alias: "w",
32+
type: "boolean",
33+
description:
34+
"Watch the source files and rebuild when they change."
35+
} )
36+
.option( "esm", {
37+
type: "boolean",
38+
description:
39+
"Build an ES module (ESM) bundle. " +
40+
"By default, a UMD bundle is built."
41+
} )
42+
.help()
43+
.argv;
44+
45+
build( argv );

‎build/tasks/build-default.js

-3
This file was deleted.

‎build/tasks/build-watch.js

-3
This file was deleted.

‎build/tasks/build.js

+54-19
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,33 @@ async function readJSON( filename ) {
2222
return JSON.parse( await read( filename ) );
2323
}
2424

25+
async function getOutputRollupOptions( {
26+
esm = false
27+
} = {} ) {
28+
const wrapperFilePath = path.join( "src", `wrapper${
29+
esm ? "-esm" : ""
30+
}.js` );
31+
32+
const wrapperSource = await read( wrapperFilePath );
33+
34+
// Catch `// @CODE` and subsequent comment lines event if they don't start
35+
// in the first column.
36+
const wrapper = wrapperSource.split(
37+
/[\x20\t]*\/\/ @CODE\n(?:[\x20\t]*\/\/[^\n]+\n)*/
38+
);
39+
40+
return {
41+
42+
// The ESM format is not actually used as we strip it during the
43+
// build, inserting our own wrappers; it's just that it doesn't
44+
// generate any extra wrappers so there's nothing for us to remove.
45+
format: "esm",
46+
47+
intro: wrapper[ 0 ].replace( /\n*$/, "" ),
48+
outro: wrapper[ 1 ].replace( /^\n*/, "" )
49+
};
50+
}
51+
2552
async function writeCompiled( { code, dir, filename, version } ) {
2653
const compiledContents = code
2754

@@ -34,12 +61,12 @@ async function writeCompiled( { code, dir, filename, version } ) {
3461

3562
await writeFile( path.join( dir, filename ), compiledContents );
3663
console.log( `[${ getTimestamp() }] ${ filename } v${ version } created.` );
37-
await minify( { dir, filename, version } );
3864
}
3965

4066
export async function build( {
4167
dir = "dist",
4268
filename = "jquery-migrate.js",
69+
esm = false,
4370
watch = false,
4471
version
4572
} = {} ) {
@@ -59,24 +86,8 @@ export async function build( {
5986
}`;
6087
}
6188

62-
// Catch `// @CODE` and subsequent comment lines event if they don't start
63-
// in the first column.
64-
const wrapperSrc = await read( "src/wrapper.js" );
65-
const wrapper = wrapperSrc.split(
66-
/[\x20\t]*\/\/ @CODE\n(?:[\x20\t]*\/\/[^\n]+\n)*/
67-
);
68-
6989
const inputRollupOptions = {};
70-
const outputRollupOptions = {
71-
72-
// The ESM format is not actually used as we strip it during
73-
// the build; it's just that it doesn't generate any extra
74-
// wrappers so there's nothing for us to remove.
75-
format: "esm",
76-
77-
intro: wrapper[ 0 ].replace( /\n*$/, "" ),
78-
outro: wrapper[ 1 ].replace( /^\n*/, "" )
79-
};
90+
const outputRollupOptions = await getOutputRollupOptions( { esm } );
8091
const src = "src/migrate.js";
8192

8293
inputRollupOptions.input = path.resolve( src );
@@ -122,9 +133,33 @@ export async function build( {
122133
} = await bundle.generate( outputRollupOptions );
123134

124135
await writeCompiled( { code, dir, filename, version } );
136+
await minify( { dir, filename, version } );
137+
}
138+
}
125139

140+
export async function buildDefaultFiles( {
141+
version = process.env.VERSION,
142+
watch
143+
} = {} ) {
144+
await Promise.all( [
145+
build( { version, watch } ),
146+
build( {
147+
dir: "dist-module",
148+
filename: "jquery-migrate.module.js",
149+
esm: true,
150+
version,
151+
watch
152+
} )
153+
] );
154+
155+
if ( watch ) {
156+
console.log( "Watching files..." );
157+
} else {
126158
return compareSize( {
127-
files: [ "dist/jquery-migrate.min.js" ]
159+
files: [
160+
"dist/jquery-migrate.min.js",
161+
"dist-module/jquery-migrate.module.min.js"
162+
]
128163
} );
129164
}
130165
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Node.js is able to import from a CommonJS module in an ESM one.
2+
import jQuery from "../../dist/jquery-migrate.js";
3+
4+
export { jQuery, jQuery as $ };
5+
export default jQuery;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
// Bundlers are able to synchronously require an ESM module from a CommonJS one.
4+
const { jQuery } = require( "../../dist-module/jquery-migrate.module.js" );
5+
module.exports = jQuery;

‎eslint.config.js

+51-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ export default [
1212
},
1313

1414
{
15-
files: [ "eslint.config.js", "build/**" ],
15+
files: [
16+
"eslint.config.js",
17+
".release-it.cjs",
18+
"build/**",
19+
"test/node_smoke_tests/**",
20+
"test/bundler_smoke_tests/**/*"
21+
],
1622
languageOptions: {
1723
ecmaVersion: "latest",
1824
globals: {
@@ -60,18 +66,44 @@ export default [
6066
}
6167
},
6268

69+
{
70+
files: [
71+
"src/wrapper.js",
72+
"src/wrapper-esm.js",
73+
"src/wrapper-factory.js",
74+
"src/wrapper-factory-esm.js"
75+
],
76+
languageOptions: {
77+
globals: {
78+
jQuery: false
79+
}
80+
},
81+
rules: {
82+
"no-unused-vars": "off",
83+
indent: [
84+
"error",
85+
"tab",
86+
{
87+
88+
// This makes it so code within the wrapper is not indented.
89+
ignoredNodes: [
90+
"Program > FunctionDeclaration > *"
91+
]
92+
}
93+
]
94+
}
95+
},
96+
6397
{
6498
files: [ "src/wrapper.js" ],
6599
languageOptions: {
66100
sourceType: "script",
67101
globals: {
68-
jQuery: false,
69102
define: false,
70103
module: false
71104
}
72105
},
73106
rules: {
74-
"no-unused-vars": "off",
75107
indent: [
76108
"error",
77109
"tab",
@@ -203,5 +235,21 @@ export default [
203235
ecmaVersion: 5,
204236
sourceType: "script"
205237
}
238+
},
239+
240+
{
241+
files: [ "dist-module/**" ],
242+
languageOptions: {
243+
ecmaVersion: 2015,
244+
sourceType: "module"
245+
}
246+
},
247+
248+
{
249+
files: [ "dist/wrappers/*.js" ],
250+
languageOptions: {
251+
ecmaVersion: 2015,
252+
sourceType: "commonjs"
253+
}
206254
}
207255
];

‎package-lock.json

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

‎package.json

+32-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22
"name": "jquery-migrate",
33
"title": "jQuery Migrate",
44
"description": "Migrate older jQuery code to jQuery 4.x",
5-
"main": "dist/jquery-migrate.js",
65
"version": "4.0.0-pre",
76
"type": "module",
7+
"exports": {
8+
"node": {
9+
"import": "./dist-module/wrappers/jquery-migrate.node-module-wrapper.js",
10+
"default": "./dist/jquery-migrate.js"
11+
},
12+
"module": {
13+
"import": "./dist-module/jquery-migrate.module.js",
14+
"default": "./dist/wrappers/jquery-migrate.bundler-require-wrapper.js"
15+
},
16+
"import": "./dist-module/jquery-migrate.module.js",
17+
"default": "./dist/jquery-migrate.js"
18+
},
19+
"main": "dist/jquery-migrate.js",
820
"homepage": "https://github.com/jquery/jquery-migrate",
921
"author": {
1022
"name": "OpenJS Foundation and other contributors",
@@ -19,24 +31,32 @@
1931
},
2032
"license": "MIT",
2133
"scripts": {
22-
"build": "node build/tasks/build-default.js",
34+
"build": "node ./build/command.js",
35+
"build:all": "node --input-type=module -e \"import { buildDefaultFiles } from './build/tasks/build.js'; buildDefaultFiles()\"",
36+
"build:clean": "rimraf --glob dist/*.{js,map} --glob dist-module/*.{js,map}",
37+
"build:main": "node --input-type=module -e \"import { build } from './build/tasks/build.js'; build()\"",
2338
"lint": "eslint --cache .",
2439
"npmcopy": "node build/tasks/npmcopy.js",
2540
"prepare": "husky",
26-
"pretest": "npm run npmcopy && npm run build && npm run lint",
27-
"start": "npm run npmcopy && node build/tasks/build-watch.js",
28-
"test:browser": "npm run pretest && npm run test:unit -- -b chrome -b firefox --headless",
29-
"test:ie": "npm run pretest && npm run test:unit -- -v -b ie",
30-
"test:node_smoke_tests": "npm run pretest && node test/node_smoke_tests/smoke_tests.cjs",
31-
"test:safari": "npm run pretest && npm run test:unit -- -v -b safari",
41+
"pretest": "npm run npmcopy",
42+
"start": "node --input-type=module -e \"import { buildDefaultFiles } from './build/tasks/build.js'; buildDefaultFiles({ watch: true })\"",
43+
"test:browser": "npm run pretest && npm run build:all && npm run test:unit -- -b chrome -b firefox --headless",
44+
"test:browserless": "npm run pretest && npm run build:all && node test/bundler_smoke_tests/run-jsdom-tests.js && node test/node_smoke_tests/node_smoke_tests.cjs",
45+
"test:ie": "npm run pretest && npm run build:all && npm run test:unit -- -v -b ie",
46+
"test:bundlers": "npm run pretest && npm run build:all && node test/bundler_smoke_tests/run-jsdom-tests.js",
47+
"test:node_smoke_tests": "npm run pretest && npm run build:all && node test/node_smoke_tests/node_smoke_tests.cjs",
48+
"test:safari": "npm run pretest && npm run build:all && npm run test:unit -- -v -b safari",
3249
"test:server": "jtr serve",
50+
"test:esm": "npm run pretest && npm run build:main && npm run test:unit -- -f plugin=esmodules --headless ",
3351
"test:unit": "jtr",
34-
"test": "npm run test:node_smoke_tests && npm run test:browser"
52+
"test": "npm run build:all && npm run lint && npm run test:browserless && npm run test:browser && npm run test:esm"
3553
},
3654
"peerDependencies": {
3755
"jquery": ">=4 <5"
3856
},
3957
"devDependencies": {
58+
"@rollup/plugin-commonjs": "28.0.3",
59+
"@rollup/plugin-node-resolve": "16.0.1",
4060
"chalk": "5.4.1",
4161
"commitplease": "3.2.0",
4262
"enquirer": "2.4.1",
@@ -52,7 +72,9 @@
5272
"qunit": "2.24.1",
5373
"rollup": "4.34.8",
5474
"sinon": "9.2.4",
55-
"uglify-js": "3.19.3"
75+
"uglify-js": "3.19.3",
76+
"webpack": "5.98.0",
77+
"yargs": "^17.7.2"
5678
},
5779
"keywords": [
5880
"jquery",

‎src/wrapper-esm.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*!
2+
* jQuery Migrate - v@VERSION - @DATE
3+
* Copyright OpenJS Foundation and other contributors
4+
*/
5+
import $ from "jquery";
6+
7+
// For ECMAScript module environments where a proper `window`
8+
// is present, execute the factory and get jQuery.
9+
function jQueryFactory( jQuery, window ) {
10+
11+
// @CODE
12+
// build.js inserts compiled jQuery here
13+
14+
return jQuery;
15+
}
16+
17+
var jQuery = jQueryFactory( $, window );
18+
19+
export { jQuery, jQuery as $ };
20+
21+
export default jQuery;
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { rollup } from "rollup";
2+
3+
import { loadConfigFile } from "rollup/loadConfigFile";
4+
import path from "node:path";
5+
import { fileURLToPath } from "node:url";
6+
7+
const dirname = path.dirname( fileURLToPath( import.meta.url ) );
8+
const pureEsmConfigPath = path.resolve(
9+
dirname, "..", "rollup-pure-esm.config.js" );
10+
const commonJSConfigPath = path.resolve(
11+
dirname, "..", "rollup-commonjs.config.js" );
12+
13+
// See https://rollupjs.org/javascript-api/#programmatically-loading-a-config-file
14+
async function runRollup( name, configPath ) {
15+
16+
console.log( `Running Rollup, version: ${ name }` );
17+
18+
// options is an array of "inputOptions" objects with an additional
19+
// "output" property that contains an array of "outputOptions".
20+
// We generate a single output so the array only has one element.
21+
const {
22+
options: [ optionsObj ],
23+
warnings
24+
} = await loadConfigFile( configPath, {} );
25+
26+
// "warnings" wraps the default `onwarn` handler passed by the CLI.
27+
// This prints all warnings up to this point:
28+
warnings.flush();
29+
30+
const bundle = await rollup( optionsObj );
31+
await Promise.all( optionsObj.output.map( bundle.write ) );
32+
33+
console.log( `Build completed: Rollup, version: ${ name }` );
34+
}
35+
36+
export async function runRollupPureEsm() {
37+
await runRollup( "pure ESM", pureEsmConfigPath );
38+
}
39+
40+
export async function runRollupEsmAndCommonJs() {
41+
await runRollup( "ESM + CommonJS", commonJSConfigPath );
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import webpack from "webpack";
2+
3+
// See https://webpack.js.org/api/node/#webpack
4+
export async function runWebpack() {
5+
return new Promise( async( resolve, reject ) => {
6+
console.log( "Running Webpack" );
7+
8+
const { default: config } = await import( "../webpack.config.cjs" );
9+
10+
webpack( config, ( err, stats ) => {
11+
if ( err || stats.hasErrors() ) {
12+
console.error( "Errors detected during Webpack compilation" );
13+
reject( err );
14+
return;
15+
}
16+
17+
console.log( "Build completed: Webpack" );
18+
resolve();
19+
} );
20+
} );
21+
}

‎test/bundler_smoke_tests/lib/utils.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
const dirname = path.dirname( fileURLToPath( import.meta.url ) );
6+
const TMP_BUNDLERS_DIR = path.resolve( dirname, "..", "tmp" );
7+
8+
export async function cleanTmpBundlersDir() {
9+
await fs.rm( TMP_BUNDLERS_DIR, {
10+
force: true,
11+
recursive: true
12+
} );
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import path from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import resolve from "@rollup/plugin-node-resolve";
4+
import commonjs from "@rollup/plugin-commonjs";
5+
6+
const dirname = path.dirname( fileURLToPath( import.meta.url ) );
7+
8+
export default {
9+
input: `${ dirname }/src-esm-commonjs/main.js`,
10+
output: {
11+
dir: `${ dirname }/tmp/rollup-commonjs`,
12+
format: "iife",
13+
sourcemap: true
14+
},
15+
plugins: [
16+
resolve(),
17+
commonjs()
18+
]
19+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import path from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import resolve from "@rollup/plugin-node-resolve";
4+
5+
const dirname = path.dirname( fileURLToPath( import.meta.url ) );
6+
7+
export default {
8+
input: `${ dirname }/src-pure-esm/main.js`,
9+
output: {
10+
dir: `${ dirname }/tmp/rollup-pure-esm`,
11+
format: "iife",
12+
sourcemap: true
13+
},
14+
plugins: [
15+
resolve()
16+
]
17+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import fs from "node:fs/promises";
2+
import jsdom, { JSDOM } from "jsdom";
3+
import path from "node:path";
4+
import { fileURLToPath } from "node:url";
5+
import { runRollupEsmAndCommonJs, runRollupPureEsm } from "./lib/run-rollup.js";
6+
import { runWebpack } from "./lib/run-webpack.js";
7+
import { cleanTmpBundlersDir } from "./lib/utils.js";
8+
9+
const dirname = path.dirname( fileURLToPath( import.meta.url ) );
10+
11+
async function runJSDOMTest( { title, folder } ) {
12+
console.log( "Running bundlers tests:", title );
13+
14+
const template = await fs.readFile( `${ dirname }/test.html`, "utf-8" );
15+
const scriptSource = await fs.readFile(
16+
`${ dirname }/tmp/${ folder }/main.js`, "utf-8" );
17+
18+
const html = template
19+
.replace( /@TITLE\b/, () => title )
20+
.replace( /@SCRIPT\b/, () => scriptSource );
21+
22+
const virtualConsole = new jsdom.VirtualConsole();
23+
virtualConsole.sendTo( console );
24+
virtualConsole.on( "assert", ( success ) => {
25+
if ( !success ) {
26+
process.exitCode = 1;
27+
}
28+
} );
29+
30+
new JSDOM( html, {
31+
resources: "usable",
32+
runScripts: "dangerously",
33+
virtualConsole
34+
} );
35+
36+
if ( process.exitCode === 0 || process.exitCode == null ) {
37+
console.log( "Bundlers tests passed for:", title );
38+
} else {
39+
console.error( "Bundlers tests failed for:", title );
40+
}
41+
}
42+
43+
async function buildAndTest() {
44+
await cleanTmpBundlersDir();
45+
46+
await Promise.all( [
47+
runRollupPureEsm(),
48+
runRollupEsmAndCommonJs(),
49+
runWebpack()
50+
] );
51+
52+
await Promise.all( [
53+
runJSDOMTest( {
54+
title: "Rollup with pure ESM setup",
55+
folder: "rollup-pure-esm"
56+
} ),
57+
58+
runJSDOMTest( {
59+
title: "Rollup with ESM + CommonJS",
60+
folder: "rollup-commonjs"
61+
} ),
62+
63+
runJSDOMTest( {
64+
title: "Webpack",
65+
folder: "webpack"
66+
} )
67+
] );
68+
69+
// The directory won't be cleaned in case of failures; this may aid debugging.
70+
await cleanTmpBundlersDir();
71+
}
72+
73+
await buildAndTest();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
const $ = require( "jquery-migrate" );
4+
5+
module.exports.$required = $;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { $ as $imported } from "jquery-migrate";
2+
3+
import { $required } from "./jquery-migrate-require.cjs";
4+
5+
console.assert( $required === $imported,
6+
"Only one copy of full jQuery should exist" );
7+
console.assert( /^jQuery/.test( $imported.expando ),
8+
"jQuery.expando should be detected on full jQuery" );
9+
console.assert( typeof $imported.migrateVersion === "string" && $imported.migrateVersion.length > 0,
10+
"jQuery.migrateVersion was not detected, the jQuery Migrate bootstrap process has failed" );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { $ } from "jquery-migrate";
2+
3+
console.assert( /^jQuery/.test( $.expando ),
4+
"jQuery.expando should be detected on full jQuery" );
5+
console.assert( typeof $.migrateVersion === "string" && $.migrateVersion.length > 0,
6+
"jQuery.migrateVersion was not detected, the jQuery Migrate bootstrap process has failed" );

‎test/bundler_smoke_tests/test.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html>
3+
<head lang='en'>
4+
<meta charset='utf-8'>
5+
<meta name='viewport' content='width=device-width'>
6+
<title>Bundlers tests: @TITLE</title>
7+
</head>
8+
<body>
9+
<script>@SCRIPT</script>
10+
</body>
11+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
module.exports = {
4+
entry: `${ __dirname }/src-esm-commonjs/main.js`,
5+
output: {
6+
filename: "main.js",
7+
path: `${ __dirname }/tmp/webpack`
8+
}
9+
};

‎test/node_smoke_tests/smoke_tests.cjs ‎test/node_smoke_tests/node_smoke_tests.cjs

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ console.log( "Running Node.js smoke tests..." );
55
const assert = require( "node:assert/strict" );
66
const { JSDOM } = require( "jsdom" );
77

8-
const { window } = new JSDOM( `<!DOCTYPE html><title>$</title>` );
8+
const { window } = new JSDOM( "<!DOCTYPE html><title>$</title>" );
99

1010
// Set the window global.
1111
globalThis.window = window;
1212

13-
// Require jQuery Migrate. Since Migrate doesn't specify exports,
14-
// `require( "jquery-migrate" )` won't work here.
15-
const $ = require( "../.." );
13+
const $ = require( "jquery-migrate" );
1614

1715
assert( /^jQuery/.test( $.expando ),
1816
"jQuery.expando was not detected, the jQuery bootstrap process has failed" );

0 commit comments

Comments
 (0)
Please sign in to comment.