diff --git a/.eslintrc.js b/.eslintrc.js index 73aea2d35..b012f8e21 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -94,7 +94,7 @@ module.exports = { "import/no-extraneous-dependencies": [ "error", { - devDependencies: ["tests*/**", "scripts/**"], + devDependencies: ["jest.config.mjs", "tests*/**", "scripts/**"], }, ], "import/order": "error", diff --git a/jest.config.js b/jest.config.mjs similarity index 90% rename from jest.config.js rename to jest.config.mjs index cef136fd3..f80024e76 100644 --- a/jest.config.js +++ b/jest.config.mjs @@ -1,9 +1,8 @@ -"use strict"; +import path from "node:path"; +import createEsmUtils from "esm-utils"; +import installPrettier from "./tests/config/install-prettier.mjs"; -const path = require("path"); -const installPrettier = require("./tests/config/install-prettier.js"); - -const PROJECT_ROOT = __dirname; +const { dirname: PROJECT_ROOT } = createEsmUtils(import.meta); const isProduction = process.env.NODE_ENV === "production"; const ENABLE_CODE_COVERAGE = Boolean(process.env.ENABLE_CODE_COVERAGE); const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE); @@ -52,7 +51,7 @@ if (isProduction) { ); } -module.exports = { +const config = { setupFiles: ["/tests/config/setup.js"], snapshotSerializers: [ "jest-snapshot-serializer-raw", @@ -82,3 +81,5 @@ module.exports = { "jest-watch-typeahead/testname", ], }; + +export default config; diff --git a/package.json b/package.json index 15326b6fb..b8137bf46 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "eslint-plugin-regexp": "1.5.0", "eslint-plugin-unicorn": "39.0.0", "esm-utils": "2.0.0", - "execa": "5.1.1", + "execa": "6.0.0", "jest": "27.3.1", "jest-snapshot-serializer-ansi": "1.0.0", "jest-snapshot-serializer-raw": "1.2.0", diff --git a/scripts/build-website.mjs b/scripts/build-website.mjs index 8ec0afa6b..0b0034e27 100644 --- a/scripts/build-website.mjs +++ b/scripts/build-website.mjs @@ -5,7 +5,7 @@ import fs from "node:fs/promises"; import globby from "globby"; import prettier from "prettier"; import createEsmUtils from "esm-utils"; -import execa from "execa"; +import { execa } from "execa"; import { PROJECT_ROOT, DIST_DIR, diff --git a/scripts/clean-cspell.mjs b/scripts/clean-cspell.mjs index eaa4ea01a..c22af2427 100644 --- a/scripts/clean-cspell.mjs +++ b/scripts/clean-cspell.mjs @@ -1,7 +1,7 @@ #!/usr/bin/env node import fs from "node:fs/promises"; -import execa from "execa"; +import { execa } from "execa"; const CSPELL_CONFIG_FILE = new URL("../cspell.json", import.meta.url); const updateConfig = (config) => diff --git a/tests/config/install-prettier.js b/tests/config/install-prettier.mjs similarity index 71% rename from tests/config/install-prettier.js rename to tests/config/install-prettier.mjs index 2be746ab4..15c9f5f1a 100644 --- a/tests/config/install-prettier.js +++ b/tests/config/install-prettier.mjs @@ -1,9 +1,7 @@ -"use strict"; - -const path = require("path"); -const fs = require("fs"); -const execa = require("execa"); -const tempy = require("tempy"); +import path from "node:path"; +import fs from "node:fs"; +import { execaSync } from "execa"; +import tempy from "tempy"; const allowedClients = new Set(["yarn", "npm", "pnpm"]); @@ -12,17 +10,17 @@ if (!allowedClients.has(client)) { client = "yarn"; } -module.exports = (packageDir) => { +function installPrettier(packageDir) { const tmpDir = tempy.directory(); - const fileName = execa - .sync("npm", ["pack"], { cwd: packageDir }) - .stdout.trim(); + const fileName = execaSync("npm", ["pack"], { + cwd: packageDir, + }).stdout.trim(); const file = path.join(packageDir, fileName); const packed = path.join(tmpDir, fileName); fs.copyFileSync(file, packed); fs.unlinkSync(file); - execa.sync(client, ["init", "-y"], { cwd: tmpDir }); + execaSync(client, ["init", "-y"], { cwd: tmpDir }); let installArguments = []; switch (client) { @@ -39,8 +37,10 @@ module.exports = (packageDir) => { installArguments = ["add", packed]; } - execa.sync(client, installArguments, { cwd: tmpDir }); + execaSync(client, installArguments, { cwd: tmpDir }); fs.unlinkSync(packed); return path.join(tmpDir, "node_modules/prettier"); -}; +} + +export default installPrettier; diff --git a/tsconfig.json b/tsconfig.json index 0c539b74a..f6894d48d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,7 @@ "exclude": [ "coverage/", "test*.*", + "jest.config.mjs", // [TBD] JavaScript sources *not* affected by src/language-*: "src/main/ast-to-doc.js", "src/main/core.js", diff --git a/yarn.lock b/yarn.lock index 1100a211b..0171987f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3036,7 +3036,22 @@ esutils@2.0.3, esutils@^2.0.2: resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== -execa@5.1.1, execa@^5.0.0: +execa@6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/execa/-/execa-6.0.0.tgz#598b46f09ae44f5d8097a30cfb1681d0f0371503" + integrity sha512-m4wU9j4Z9nXXoqT8RSfl28JSwmMNLFF69OON8H/lL3NeU0tNpGz313bcOfYoBBHokB0dC2tMl3VUcKgHELhL2Q== + dependencies: + cross-spawn "^7.0.3" + get-stream "^6.0.1" + human-signals "^3.0.1" + is-stream "^3.0.0" + merge-stream "^2.0.0" + npm-run-path "^5.0.1" + onetime "^6.0.0" + signal-exit "^3.0.5" + strip-final-newline "^3.0.0" + +execa@^5.0.0: version "5.1.1" resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd" integrity sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg== @@ -3273,7 +3288,7 @@ get-stdin@8.0.0, get-stdin@^8.0.0: resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-8.0.0.tgz#cbad6a73feb75f6eeb22ba9e01f89aa28aa97a53" integrity sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg== -get-stream@^6.0.0: +get-stream@^6.0.0, get-stream@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== @@ -3463,6 +3478,11 @@ human-signals@^2.1.0: resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0" integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw== +human-signals@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-3.0.1.tgz#c740920859dafa50e5a3222da9d3bf4bb0e5eef5" + integrity sha512-rQLskxnM/5OCldHo+wNXbpVgDn5A17CUoKX+7Sokwaknlq7CdSnphy0W39GU8dw59XiCXmFXDg4fRuckQRKewQ== + iconv-lite@0.4.24: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" @@ -3706,6 +3726,11 @@ is-stream@^2.0.0: resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077" integrity sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg== +is-stream@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-3.0.0.tgz#e6bfd7aa6bef69f4f472ce9bb681e3e57b4319ac" + integrity sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA== + is-string@^1.0.5, is-string@^1.0.7: version "1.0.7" resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.7.tgz#0dd12bf2006f255bb58f695110eff7491eebc0fd" @@ -4583,6 +4608,11 @@ mimic-fn@^3.1.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-3.1.0.tgz#65755145bbf3e36954b949c16450427451d5ca74" integrity sha512-Ysbi9uYW9hFyfrThdDEQuykN4Ey6BuwPD2kpI5ES/nFTDn/98yxYNLZJcgUAKPT/mcrLLKaGzJR9YVxJrIdASQ== +mimic-fn@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-4.0.0.tgz#60a90550d5cb0b239cca65d893b1a53b29871ecc" + integrity sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw== + min-indent@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869" @@ -4710,6 +4740,13 @@ npm-run-path@^4.0.1: dependencies: path-key "^3.0.0" +npm-run-path@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-5.0.1.tgz#748dd68ed7de377bb1f7132c7dafe657be5ab400" + integrity sha512-ybBJQUSyFwEEhqO2lXmyKOl9ucHtyZBWVM0h0FiMfT/+WKxCUZFa95qAR2X3w/w6oigN3B0b2UNHZbD+kdfD5w== + dependencies: + path-key "^4.0.0" + nwsapi@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.0.tgz#204879a9e3d068ff2a55139c2c772780681a38b7" @@ -4789,6 +4826,13 @@ onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" +onetime@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/onetime/-/onetime-6.0.0.tgz#7c24c18ed1fd2e9bca4bd26806a33613c77d34b4" + integrity sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ== + dependencies: + mimic-fn "^4.0.0" + optionator@^0.8.1: version "0.8.3" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495" @@ -4965,6 +5009,11 @@ path-key@^3.0.0, path-key@^3.1.0: resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== +path-key@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-key/-/path-key-4.0.0.tgz#295588dc3aee64154f877adb9d780b81c554bf18" + integrity sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ== + path-parse@^1.0.6: version "1.0.7" resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" @@ -5549,7 +5598,7 @@ sigmund@^1.0.1: resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" integrity sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA= -signal-exit@^3.0.2, signal-exit@^3.0.3: +signal-exit@^3.0.2, signal-exit@^3.0.3, signal-exit@^3.0.5: version "3.0.6" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.6.tgz#24e630c4b0f03fea446a2bd299e62b4a6ca8d0af" integrity sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ== @@ -5773,6 +5822,11 @@ strip-final-newline@^2.0.0: resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad" integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA== +strip-final-newline@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-3.0.0.tgz#52894c313fbff318835280aed60ff71ebf12b8fd" + integrity sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw== + strip-indent@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-3.0.0.tgz#c32e1cee940b6b3432c771bc2c54bcce73cd3001"