diff --git a/package.json b/package.json index c0b782bcabd2..f477bbf22426 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "ignore": "5.2.0", "jest-docblock": "27.5.1", "json5": "2.2.1", - "leven": "3.1.0", + "leven": "4.0.0", "lines-and-columns": "2.0.3", "linguist-languages": "7.15.0", "lodash": "4.17.21", diff --git a/scripts/vendors/vendor-meta.json b/scripts/vendors/vendor-meta.json index 0631c4c21b0b..da431f86e90b 100644 --- a/scripts/vendors/vendor-meta.json +++ b/scripts/vendors/vendor-meta.json @@ -388,6 +388,23 @@ } ] }, + { + "name": "leven", + "maintainers": [], + "version": "4.0.0", + "description": "Measure the difference between two strings using the Levenshtein distance algorithm", + "repository": "sindresorhus/leven", + "homepage": null, + "private": false, + "license": "MIT", + "licenseText": "MIT License\n\nCopyright (c) Sindre Sorhus (https://sindresorhus.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "https://sindresorhus.com" + }, + "contributors": [] + }, { "name": "mimic-fn", "maintainers": [], diff --git a/scripts/vendors/vendors.mjs b/scripts/vendors/vendors.mjs index dc00c233c782..aa811aade409 100644 --- a/scripts/vendors/vendors.mjs +++ b/scripts/vendors/vendors.mjs @@ -5,6 +5,7 @@ const vendors = [ "html-element-attributes", "html-tag-names", "html-void-elements", + "leven", "mem", "string-width", "tempy", diff --git a/src/cli/options/normalize-cli-options.js b/src/cli/options/normalize-cli-options.js index 6e063f69ee08..b0a9d378de96 100644 --- a/src/cli/options/normalize-cli-options.js +++ b/src/cli/options/normalize-cli-options.js @@ -1,9 +1,10 @@ "use strict"; -const leven = require("leven"); -const { optionsNormalizer } = require("../prettier-internal.js"); // eslint-disable-next-line no-restricted-modules const { default: chalk } = require("../../../vendors/chalk.js"); +// eslint-disable-next-line no-restricted-modules +const { default: leven } = require("../../../vendors/leven.js"); +const { optionsNormalizer } = require("../prettier-internal.js"); function normalizeCliOptions(options, optionInfos, opts) { return optionsNormalizer.normalizeCliOptions(options, optionInfos, { diff --git a/vendors/leven.d.ts b/vendors/leven.d.ts new file mode 100644 index 000000000000..31a132da699c --- /dev/null +++ b/vendors/leven.d.ts @@ -0,0 +1,3 @@ +// This file is generated automatically. +export {default} from "leven"; +export * from "leven"; diff --git a/vendors/leven.js b/vendors/leven.js new file mode 100644 index 000000000000..b22ff5a5960b --- /dev/null +++ b/vendors/leven.js @@ -0,0 +1,76 @@ +// @ts-nocheck +// This file is generated automatically +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// node_modules/leven/index.js +var leven_exports = {}; +__export(leven_exports, { + default: () => leven +}); +module.exports = __toCommonJS(leven_exports); +var array = []; +var characterCodeCache = []; +function leven(first, second) { + if (first === second) { + return 0; + } + const swap = first; + if (first.length > second.length) { + first = second; + second = swap; + } + let firstLength = first.length; + let secondLength = second.length; + while (firstLength > 0 && first.charCodeAt(~-firstLength) === second.charCodeAt(~-secondLength)) { + firstLength--; + secondLength--; + } + let start = 0; + while (start < firstLength && first.charCodeAt(start) === second.charCodeAt(start)) { + start++; + } + firstLength -= start; + secondLength -= start; + if (firstLength === 0) { + return secondLength; + } + let bCharacterCode; + let result; + let temporary; + let temporary2; + let index = 0; + let index2 = 0; + while (index < firstLength) { + characterCodeCache[index] = first.charCodeAt(start + index); + array[index] = ++index; + } + while (index2 < secondLength) { + bCharacterCode = second.charCodeAt(start + index2); + temporary = index2++; + result = index2; + for (index = 0; index < firstLength; index++) { + temporary2 = bCharacterCode === characterCodeCache[index] ? temporary : temporary + 1; + temporary = array[index]; + result = array[index] = temporary > result ? temporary2 > result ? result + 1 : temporary2 : temporary2 > temporary ? temporary + 1 : temporary2; + } + } + return result; +} +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = {}); diff --git a/yarn.lock b/yarn.lock index 4c944df49d23..8b38097e571c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4663,16 +4663,21 @@ kleur@^3.0.3: resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== -leven@3.1.0, leven@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2" - integrity sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A== +leven@4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/leven/-/leven-4.0.0.tgz#b9c39c803f835950fabef9e122a9b47b95708710" + integrity sha512-puehA3YKku3osqPlNuzGDUHq8WpwXupUg1V6NXdV38G+gr+gkBwFC8g1b/+YcIvp8gnqVIus+eJCH/eGsRmJNw== leven@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/leven/-/leven-2.1.0.tgz#c2e7a9f772094dee9d34202ae8acce4687875580" integrity sha1-wuep93IJTe6dNCAq6KzORoeHVYA= +leven@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2" + integrity sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A== + levn@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade"