From c6543c434108bfc22830a7de58a1c3ef78db6116 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 10 Jan 2025 08:09:56 -0600 Subject: [PATCH] JS Tools: update the GH action lint to use ESM for chalk v5 (#40944) --- .github/workflows/linting.yml | 6 ++++-- tools/js-tools/git-hooks/pre-commit-hook.mjs | 2 +- .../js-tools/{lint-gh-actions.js => lint-gh-actions.mjs} | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) rename tools/js-tools/{lint-gh-actions.js => lint-gh-actions.mjs} (97%) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 5e5b2e6b0b60c..b8fdf3f47c14e 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -93,6 +93,8 @@ jobs: - '.github/workflows/*.{yml,yaml}' - '.github/actions/*/action.{yml,yaml}' - 'projects/github-actions/*/action.{yml,yaml}' + # If we edit the linting JS files, we need to run it. + - 'tools/js-tools/lint-gh-actions.{js,mjs}' misc_php: # If composer, phpcs config, or the codesniffer package itself changed, there may be a new standard. - 'composer.json' @@ -341,7 +343,7 @@ jobs: run: pnpm run lint-changed --git-base=$SHA $(jq -rn --argjson files "$FILES" '$files[]') ### Lints GitHub Actions yaml files. - # Local equivalent: `./tools/js-tools/lint-gh-actions.js ` + # Local equivalent: `./tools/js-tools/lint-gh-actions.mjs ` lint_gh_actions: name: Lint GitHub Actions yaml files runs-on: ubuntu-latest @@ -358,7 +360,7 @@ jobs: - run: pnpm install - name: Run lint - run: ./tools/js-tools/lint-gh-actions.js -v '.github/workflows/*.{yml,yaml}' '.github/actions/*/action.{yml,yaml}' 'projects/github-actions/*/action.{yml,yaml}' + run: ./tools/js-tools/lint-gh-actions.mjs -v '.github/workflows/*.{yml,yaml}' '.github/actions/*/action.{yml,yaml}' 'projects/github-actions/*/action.{yml,yaml}' ### Checks that copied files (e.g. readme, license) are in sync # Local equivalent: `./tools/check-copied-files.sh` diff --git a/tools/js-tools/git-hooks/pre-commit-hook.mjs b/tools/js-tools/git-hooks/pre-commit-hook.mjs index bd7e0073ead50..ab98a7046d384 100644 --- a/tools/js-tools/git-hooks/pre-commit-hook.mjs +++ b/tools/js-tools/git-hooks/pre-commit-hook.mjs @@ -439,7 +439,7 @@ function runCheckGitHubActionsYamlFiles() { return; } - const result = spawnSync( './tools/js-tools/lint-gh-actions.js', files, { + const result = spawnSync( './tools/js-tools/lint-gh-actions.mjs', files, { stdio: 'inherit', } ); if ( result && result.status ) { diff --git a/tools/js-tools/lint-gh-actions.js b/tools/js-tools/lint-gh-actions.mjs similarity index 97% rename from tools/js-tools/lint-gh-actions.js rename to tools/js-tools/lint-gh-actions.mjs index 2e89b66b32d27..1aa82d5220f84 100755 --- a/tools/js-tools/lint-gh-actions.js +++ b/tools/js-tools/lint-gh-actions.mjs @@ -2,10 +2,10 @@ /* eslint-env node */ -const fs = require( 'fs' ); -const chalk = require( 'chalk' ); -const { glob } = require( 'glob' ); -const YAML = require( 'yaml' ); +import fs from 'fs'; +import chalk from 'chalk'; +import { glob } from 'glob'; +import YAML from 'yaml'; const isCI = !! process.env.CI;