Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Updates and ESM Migration #68456

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from
49,870 changes: 28,923 additions & 20,947 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/scripts/bin/wp-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Internal dependencies
*/
const { getNodeArgsFromCLI, spawnScript } = require( '../utils' );
import { getNodeArgsFromCLI, spawnScript } from '../utils/cli.js';

const { scriptName, scriptArgs, nodeArgs } = getNodeArgsFromCLI();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* External dependencies
*/
const importSync = require( 'import-sync' );

/**
* Internal dependencies
*/
const { hasBabelConfig } = require( '../utils' );
const { hasBabelConfig } = importSync( '../utils/config.js' );

const eslintConfig = {
root: true,
Expand All @@ -23,5 +28,5 @@ if ( ! hasBabelConfig() ) {
},
};
}

// TODO: Update this ESLint 9 so ESM modules can be used with a eslint.config.mjs
module.exports = eslintConfig;
3 changes: 2 additions & 1 deletion packages/scripts/config/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require( '@wordpress/prettier-config' );
import prettierConfig from '@wordpress/prettier-config';
export default prettierConfig;
7 changes: 3 additions & 4 deletions packages/scripts/config/babel-transform.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* External dependencies
*/
const babelJest = require( 'babel-jest' );

// Remove this workaround when https://github.com/facebook/jest/issues/11444 gets resolved in Jest.
import babelJest from 'babel-jest';
// TODO: this was resolved so remove this workaround when https://github.com/facebook/jest/issues/11444 gets resolved in Jest.
const babelJestInterop = babelJest.__esModule ? babelJest.default : babelJest;

module.exports = babelJestInterop.createTransformer( {
export default babelJestInterop.createTransformer( {
presets: [ '@wordpress/babel-preset-default' ],
} );
9 changes: 6 additions & 3 deletions packages/scripts/config/jest-e2e.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/**
* External dependencies
*/
const path = require( 'path' );
import { fileURLToPath } from 'url';
import path from 'path';

/**
* Internal dependencies
*/
const { hasBabelConfig } = require( '../utils' );
import { hasBabelConfig } from '../utils/config.js';

const __dirname = path.dirname( fileURLToPath( import.meta.url ) );

const jestE2EConfig = {
globalSetup: path.join( __dirname, 'jest-environment-puppeteer', 'setup' ),
Expand All @@ -33,4 +36,4 @@ if ( ! hasBabelConfig() ) {
};
}

module.exports = jestE2EConfig;
export default jestE2EConfig;
42 changes: 22 additions & 20 deletions packages/scripts/config/jest-environment-puppeteer/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
/**
* External dependencies
*/
const fs = require( 'fs' );
const path = require( 'path' );
const { promisify } = require( 'util' );
const cwd = require( 'cwd' );
const merge = require( 'merge-deep' );
import fs from 'fs/promises';
import path from 'path';
import { merge } from 'ts-deepmerge';
import { packageUp } from 'package-up';

const exists = promisify( fs.exists );
import { createRequire } from 'module';
const require = createRequire( import.meta.url );

const DEFAULT_CONFIG = {
launch: {},
Expand All @@ -49,23 +49,28 @@ async function readConfig() {
const hasCustomConfigPath = !! process.env.JEST_PUPPETEER_CONFIG;
const configPath =
process.env.JEST_PUPPETEER_CONFIG || 'jest-puppeteer.config.js';
const absConfigPath = path.resolve( cwd(), configPath );
const configExists = await exists( absConfigPath );
const packageJsonPath = await packageUp( { cwd: process.cwd() } );
const absConfigPath = path.resolve(
packageJsonPath ? path.dirname( packageJsonPath ) : process.cwd(),
configPath
);

if ( hasCustomConfigPath && ! configExists ) {
throw new Error(
`Error: Can't find a root directory while resolving a config file path.\nProvided path to resolve: ${ configPath }`
);
}

if ( ! hasCustomConfigPath && ! configExists ) {
try {
await fs.access( absConfigPath );
} catch {
if ( hasCustomConfigPath ) {
throw new Error(
`Error: Can't find a root directory while resolving a config file path.\nProvided path to resolve: ${ configPath }`
);
}
return defaultConfig;
}

const localConfig = await require( absConfigPath );
const localConfig = require( absConfigPath );
return merge( {}, defaultConfig, localConfig );
}

// TODO: puppeteer now supports FireFox, this needs updating: https://hacks.mozilla.org/2024/08/puppeteer-support-for-firefox/
function getPuppeteer( { browser } ) {
switch ( browser.toLowerCase() ) {
case 'chromium':
Expand All @@ -79,7 +84,4 @@ function getPuppeteer( { browser } ) {
}
}

module.exports = {
readConfig,
getPuppeteer,
};
export { readConfig, getPuppeteer };
26 changes: 12 additions & 14 deletions packages/scripts/config/jest-environment-puppeteer/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
/**
* External dependencies
*/
const {
setup: setupServer,
teardown: teardownServer,
import {
setup as setupServer,
teardown as teardownServer,
ERROR_TIMEOUT,
ERROR_NO_COMMAND,
} = require( 'jest-dev-server' );
const chalk = require( 'chalk' );
} from 'jest-dev-server';
import pc from 'picocolors';

/**
* Internal dependencies
*/
const { readConfig, getPuppeteer } = require( './config' );
import { readConfig, getPuppeteer } from './config.js';

let browser;
let didAlreadyRunInWatchMode = false;
Expand All @@ -36,6 +36,7 @@ let servers = [];
async function setup( jestConfig = {} ) {
const config = await readConfig();
const puppeteer = getPuppeteer( config );

if ( config.connect ) {
browser = await puppeteer.connect( config.connect );
} else {
Expand All @@ -58,19 +59,19 @@ async function setup( jestConfig = {} ) {
const { error: printError } = console;
if ( error.code === ERROR_TIMEOUT ) {
printError( '' );
printError( chalk.red( error.message ) );
printError( pc.red( error.message ) );
printError(
chalk.blue(
pc.blue(
`\n☝️ You can set "server.launchTimeout" in jest-puppeteer.config.js`
)
);
process.exit( 1 );
}
if ( error.code === ERROR_NO_COMMAND ) {
printError( '' );
printError( chalk.red( error.message ) );
printError( pc.red( error.message ) );
printError(
chalk.blue(
pc.blue(
`\n☝️ You must set "server.command" in jest-puppeteer.config.js`
)
);
Expand All @@ -95,7 +96,4 @@ async function teardown( jestConfig = {} ) {
}
}

module.exports = {
setup,
teardown,
};
export { setup, teardown };
18 changes: 8 additions & 10 deletions packages/scripts/config/jest-environment-puppeteer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
/**
* External dependencies
*/
const path = require( 'path' );
const { writeFile, mkdir } = require( 'fs' ).promises;
const filenamify = require( 'filenamify' );
const NodeEnvironment = require( 'jest-environment-node' ).default;
const chalk = require( 'chalk' );
import path from 'path';
import { writeFile, mkdir } from 'fs/promises';
import filenamify from 'filenamify';
import NodeEnvironment from 'jest-environment-node';
import pc from 'picocolors';

/**
* Internal dependencies
*/
const { readConfig, getPuppeteer } = require( './config' );
import { readConfig, getPuppeteer } from './config.js';

const handleError = ( error ) => {
// To match the same behavior in jest-jasmine2:
Expand Down Expand Up @@ -72,9 +72,7 @@ class PuppeteerEnvironment extends NodeEnvironment {
} );
// eslint-disable-next-line no-console
console.log(
chalk.blue(
'\n\n🕵️‍ Code is paused, press enter to resume'
)
pc.blue( '\n\n🕵️‍ Code is paused, press enter to resume' )
);
// Run an infinite promise.
return new Promise( ( resolve ) => {
Expand Down Expand Up @@ -218,4 +216,4 @@ class PuppeteerEnvironment extends NodeEnvironment {
}
}

module.exports = PuppeteerEnvironment;
export default PuppeteerEnvironment;
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require( './global' ).setup;
import { setup } from './global.js';
export default setup;
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require( './global' ).teardown;
import { teardown } from './global.js';
export default teardown;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

const newLine = /\n/g;
const encodedNewLine = '%0A';
const lineAndColumnInStackTrace = /^.*?:([0-9]+):([0-9]+).*$/;
const lineAndColumnInStackTrace = /^.*?:(\d+):(\d+).*$/;

class GithubActionsReporter {
async onRunComplete( _contexts, _aggregatedResults ) {
Expand Down Expand Up @@ -63,4 +63,4 @@ function flatMap( fn ) {
return ( out, entry ) => out.concat( ...fn( entry ) );
}

module.exports = GithubActionsReporter;
export default GithubActionsReporter;
10 changes: 6 additions & 4 deletions packages/scripts/config/jest-unit.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* External dependencies
*/
const path = require( 'path' );

import { fileURLToPath } from 'url';
import path from 'path';
/**
* Internal dependencies
*/
const { hasBabelConfig } = require( '../utils' );
import { hasBabelConfig } from '../utils/config.js';

const __dirname = path.dirname( fileURLToPath( import.meta.url ) );

const jestUnitConfig = {
preset: '@wordpress/jest-preset-default',
Expand All @@ -22,4 +24,4 @@ if ( ! hasBabelConfig() ) {
};
}

module.exports = jestUnitConfig;
export default jestUnitConfig;
9 changes: 6 additions & 3 deletions packages/scripts/config/playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/**
* External dependencies
*/
const path = require( 'path' );
const { defineConfig, devices } = require( '@playwright/test' );
import path from 'path';
import { defineConfig, devices } from '@playwright/test';
// TODO: Remove this once https://nodejs.org/api/esm.html#importmetaresolvespecifier is stable.
import { createRequire } from 'module';
const require = createRequire( import.meta.url );

process.env.WP_ARTIFACTS_PATH ??= path.join( process.cwd(), 'artifacts' );
process.env.STORAGE_STATE_PATH ??= path.join(
Expand Down Expand Up @@ -57,4 +60,4 @@ const config = defineConfig( {
],
} );

module.exports = config;
export default config;
4 changes: 2 additions & 2 deletions packages/scripts/config/playwright/global-setup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* External dependencies
*/
const { request } = require( '@playwright/test' );
import { request } from '@playwright/test';

/**
* WordPress dependencies
*/
const { RequestUtils } = require( '@wordpress/e2e-test-utils-playwright' );
import { RequestUtils } from '@wordpress/e2e-test-utils-playwright';

/**
*
Expand Down
18 changes: 8 additions & 10 deletions packages/scripts/config/puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
module.exports = {
launch: {
devtools: process.env.PUPPETEER_DEVTOOLS === 'true',
headless: process.env.PUPPETEER_HEADLESS !== 'false',
slowMo: parseInt( process.env.PUPPETEER_SLOWMO, 10 ) || 0,
args: [
'--enable-blink-features=ComputedAccessibilityInfo',
'--disable-web-security',
],
},
export const launch = {
devtools: process.env.PUPPETEER_DEVTOOLS === 'true',
headless: process.env.PUPPETEER_HEADLESS !== 'false',
slowMo: parseInt( process.env.PUPPETEER_SLOWMO, 10 ) || 0,
args: [
'--enable-blink-features=ComputedAccessibilityInfo',
'--disable-web-security',
],
};
Loading
Loading