From 60ec97d3b70093d9fe60c4277d3bff38070fb876 Mon Sep 17 00:00:00 2001 From: INeedJobToStartWork Date: Tue, 29 Oct 2024 22:09:40 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20=20Chore(packages):=20prep?= =?UTF-8?q?are=20packages=20to=20publish,=20fix=20and=20add=20features?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/pre.json | 9 --- .husky/pre-commit | 1 - packages/semver/CHANGELOG.md | 7 ++ packages/semver/README.md | 18 ++++- packages/semver/config/tsuprc/tsup.prod.ts | 1 - packages/semver/package.json | 4 +- packages/semver/src/classes/semVer.ts | 9 +-- packages/semver/src/functions/compare.test.ts | 1 - packages/semver/src/functions/compare.ts | 11 +-- .../semver/src/functions/difference.test.ts | 1 - .../semver/src/functions/increase.test.ts | 1 - packages/semver/src/functions/increase.ts | 10 +-- .../semver/src/functions/minVersion.test.ts | 1 - packages/semver/src/functions/minVersion.ts | 2 - packages/semver/src/functions/parseSemVer.ts | 30 ++++---- .../semver/src/functions/satisfies.test.ts | 1 - packages/semver/src/functions/satisfies.ts | 1 - .../semver/src/functions/simplifyRange.ts | 1 - .../semver/src/functions/versionValidator.ts | 4 -- .../validate-npm-package-name/CHANGELOG.md | 6 ++ .../config/tsuprc/tsup.prod.ts | 3 +- .../validate-npm-package-name/package.json | 7 +- ...alidator.test.js => nameValidator.test.ts} | 0 .../src/functions/name/nameValidator.ts | 70 +++++++------------ .../validate-npm-package-name/src/index.ts | 2 +- pnpm-lock.yaml | 23 +++--- 26 files changed, 97 insertions(+), 127 deletions(-) delete mode 100644 .changeset/pre.json create mode 100644 packages/semver/CHANGELOG.md rename packages/validate-npm-package-name/src/functions/name/{nameValidator.test.js => nameValidator.test.ts} (100%) diff --git a/.changeset/pre.json b/.changeset/pre.json deleted file mode 100644 index fa89229..0000000 --- a/.changeset/pre.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "mode": "exit", - "tag": "1.0.0", - "initialVersions": { - "@betternpm/semver": "1.0.0-prerelease", - "@betternpm/validate-npm-package-name": "1.0.0" - }, - "changesets": [] -} diff --git a/.husky/pre-commit b/.husky/pre-commit index 8b13789..e69de29 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +0,0 @@ - diff --git a/packages/semver/CHANGELOG.md b/packages/semver/CHANGELOG.md new file mode 100644 index 0000000..590e354 --- /dev/null +++ b/packages/semver/CHANGELOG.md @@ -0,0 +1,7 @@ +# @betternpm/semver + +## 1.0.0 + +### Major Changes + +- add `PATTERN_STRICT_SEMVER`, `PATTERN_LOOSE_SEMVER`, `PATTERN_RANGE_MODE` and fixed `d.ts` file. diff --git a/packages/semver/README.md b/packages/semver/README.md index 1a48389..506afcf 100644 --- a/packages/semver/README.md +++ b/packages/semver/README.md @@ -1,4 +1,4 @@ -![image](https://github.com/user-attachments/assets/985f8c86-4dad-400f-a5fa-16f57d0546d8) +![image](https://github.com/user-attachments/assets/a8138f88-869d-4fae-9b2a-0021e6957aaa)

Semver versioning handler

semver

@@ -35,7 +35,8 @@ - [Types](#types-1) - [TReleases](#treleases) - [Variables](#variables-1) - - [RELEASE\_TYPES](#release_types) + - [PATTERNS](#patterns) + - [RELEASE_TYPES](#release_types) ## Install @@ -404,6 +405,19 @@ type with every possible release (from variable [RELEASE_TYPES](###RELEASE_TYPES ## Variables +### PATTERNS + +| Name | Description | +| --------------------- | ------------------------------------ | +| PATTERN_STRICT_SEMVER | RegEx Pattern used for strict semver | +| PATTERN_LOOSE_SEMVER | RegEx Pattern used for loose semver | +| PATTERN_RANGE_MODE | RegEx Pattern used for range semver | + +**Links:**
+[[📄File]](https://github.com/INeedJobToStartWork/BetterNPM/tree/main/packages/semver/src/functions/parseSemVer.ts) + +[Scroll to List of Contest](#-list-of-contest) + ### RELEASE_TYPES Array with every possible diff --git a/packages/semver/config/tsuprc/tsup.prod.ts b/packages/semver/config/tsuprc/tsup.prod.ts index 093473f..79e59dd 100644 --- a/packages/semver/config/tsuprc/tsup.prod.ts +++ b/packages/semver/config/tsuprc/tsup.prod.ts @@ -1,7 +1,6 @@ import config from "./tsup.base"; import { copy } from "esbuild-plugin-copy"; import noInternalExportsPlugin from "@esplugins/no-internal-exports"; - import { defineConfig } from "tsup"; export default defineConfig({ diff --git a/packages/semver/package.json b/packages/semver/package.json index c5d4fde..bdbda7a 100644 --- a/packages/semver/package.json +++ b/packages/semver/package.json @@ -1,6 +1,6 @@ { "name": "@betternpm/semver", - "version": "1.0.0-prerelease", + "version": "1.0.0", "description": "Rewritten semver by @betternpm", "keywords": [ "semver", @@ -44,7 +44,7 @@ "oh-my-error": "2.0.0-prerelease.0" }, "devDependencies": { - "@esplugins/no-internal-exports": "1.0.0-prerelease.1", + "@esplugins/no-internal-exports": "^1.0.0", "@ineedj/eslintrc": "~1.2.2", "@ineedj/prettierrc": "^2.0.0", "@ineedj/tsconfig": "^1.0.0", diff --git a/packages/semver/src/classes/semVer.ts b/packages/semver/src/classes/semVer.ts index 6b54be7..065ee0e 100644 --- a/packages/semver/src/classes/semVer.ts +++ b/packages/semver/src/classes/semVer.ts @@ -1,5 +1,3 @@ -/* eslint-disable @EslintImports/no-deprecated */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ import type { TOptionsSemVer } from "@/functions"; import { compareSemver, @@ -38,14 +36,9 @@ export default class SemVer { ? inputVersion : inputVersion.version(); - // SPLITTING - // const { patch, buildmetadata, major, minor, prerelease, version } = isSemVer - // ? inputVersion - // : parseSemVer(this.raw, { rangeMode: false }); - const { patch, buildmetadata, major, minor, prerelease, version } = isSemVer ? inputVersion - : (parseSemVer(this.raw, mergedOptions) as ReturnType>); //TODO:fix + : parseSemVer(this.raw, mergedOptions); //TODO:fix this.version = version; this.major = major; this.minor = minor; diff --git a/packages/semver/src/functions/compare.test.ts b/packages/semver/src/functions/compare.test.ts index 5c9a665..7b71218 100644 --- a/packages/semver/src/functions/compare.test.ts +++ b/packages/semver/src/functions/compare.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable @EslintSonar/no-duplicate-string */ import { describe, expect, it } from "vitest"; import compareSemver, { compareBuild, compareMinorMajorPatch, comparePrerelease } from "./compare"; import { myErrorWrapper } from "oh-my-error"; diff --git a/packages/semver/src/functions/compare.ts b/packages/semver/src/functions/compare.ts index cc97068..257821b 100644 --- a/packages/semver/src/functions/compare.ts +++ b/packages/semver/src/functions/compare.ts @@ -1,5 +1,3 @@ -/* eslint-disable curly */ -/* eslint-disable complexity */ import type { TOptionsSemVer } from "./parseSemVer"; import { OptionsSemVerDefaults, parseSemVer } from "./parseSemVer"; import { isX } from "@/utils"; @@ -57,12 +55,15 @@ export const compareMinorMajorPatch = ( const checkX = (val1: number | string, val2: number | string): boolean => Boolean((mergedOptions.rangeMode && isX(val1)) || isX(val2)); - if (!checkX(version1.major, version2.major) && version1.major !== version2.major) + if (!checkX(version1.major, version2.major) && version1.major !== version2.major) { return version1.major > version2.major ? 1 : -1; - if (!checkX(version1.minor, version2.minor) && version1.minor !== version2.minor) + } + if (!checkX(version1.minor, version2.minor) && version1.minor !== version2.minor) { return version1.minor > version2.minor ? 1 : -1; - if (!checkX(version1.patch, version2.patch) && version1.patch !== version2.patch) + } + if (!checkX(version1.patch, version2.patch) && version1.patch !== version2.patch) { return version1.patch > version2.patch ? 1 : -1; + } return 0; }; diff --git a/packages/semver/src/functions/difference.test.ts b/packages/semver/src/functions/difference.test.ts index 621a236..b350cb4 100644 --- a/packages/semver/src/functions/difference.test.ts +++ b/packages/semver/src/functions/difference.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable @EslintSonar/no-duplicate-string */ import { describe, expect, test } from "vitest"; import { difference } from "./difference"; diff --git a/packages/semver/src/functions/increase.test.ts b/packages/semver/src/functions/increase.test.ts index 4988660..3cda5d2 100644 --- a/packages/semver/src/functions/increase.test.ts +++ b/packages/semver/src/functions/increase.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable @EslintSonar/no-duplicate-string */ // import { SemVer } from "@/classes"; // import type { TOptionsSemVer } from "./parseSemVer"; // import { OptionsSemVerDefaults } from "./parseSemVer"; diff --git a/packages/semver/src/functions/increase.ts b/packages/semver/src/functions/increase.ts index 8b25157..50375d7 100644 --- a/packages/semver/src/functions/increase.ts +++ b/packages/semver/src/functions/increase.ts @@ -37,24 +37,24 @@ const MYERRORLIST = { /** * Possible update types for version increment. - * @intelType //TODO: no-internal-exports plugin need update to fix it + * @dontexport //TODO: no-internal-exports plugin need update to fix it */ type UpdateType = "buildmetadata" | "major" | "minor" | "patch" | "premajor" | "preminor" | "prepatch" | "prerelease"; /** * Possible return types for the increase function. - * @intelType + * @dontexport */ type ReturnTypes = "object" | "SemVer" | "string"; -/** @intelType */ +/** @dontexport */ type TTTTT = "premajor" | "preminor" | "prepatch" | "prerelease"; -/** @intelType */ +/** @dontexport */ // eslint-disable-next-line @typescript-eslint/ban-types type TOptionsForPrerelease = TOptionsSemVer & { value?: "alpha" | "beta" | "rc" | (Object & string) }; -/** @intelType */ +/** @dontexport */ // eslint-disable-next-line @typescript-eslint/ban-types type OptionsForBuild = TOptionsSemVer & { value?: "BUILD" | (Object & string) }; diff --git a/packages/semver/src/functions/minVersion.test.ts b/packages/semver/src/functions/minVersion.test.ts index 9a33d7d..7f6b9ba 100644 --- a/packages/semver/src/functions/minVersion.test.ts +++ b/packages/semver/src/functions/minVersion.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable @EslintSonar/no-duplicate-string */ import { describe, it, expect } from "vitest"; import minVersion from "./minVersion"; diff --git a/packages/semver/src/functions/minVersion.ts b/packages/semver/src/functions/minVersion.ts index a35bb6b..6d898bd 100644 --- a/packages/semver/src/functions/minVersion.ts +++ b/packages/semver/src/functions/minVersion.ts @@ -1,5 +1,3 @@ -/* eslint-disable complexity */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ import type { IparseRange, satisfies, TCondition } from "@/functions"; import { compareSemver, increase, parseRange, parseSemVer } from "@/functions"; import { isX } from "@/utils"; diff --git a/packages/semver/src/functions/parseSemVer.ts b/packages/semver/src/functions/parseSemVer.ts index f7e98ca..0484cca 100644 --- a/packages/semver/src/functions/parseSemVer.ts +++ b/packages/semver/src/functions/parseSemVer.ts @@ -1,10 +1,4 @@ -// TODO: optimize regex? -/* eslint-disable @EslintImports/no-deprecated */ /* eslint-disable @EslintOptRegConf/optimize-regex */ -/* eslint-disable curly */ -/* eslint-disable complexity */ -/* eslint-disable no-nested-ternary */ -/* eslint-disable @EslintUnicorn/no-nested-ternary */ /* eslint-disable @EslintSecurity/detect-unsafe-regex */ import { SemVer } from "@/classes"; import type { TMyErrorList } from "oh-my-error"; @@ -15,19 +9,13 @@ import { versionPostValidator, versionPreValidator } from "./versionValidator"; //---------------------- // Global CONST //---------------------- -/** - * @internal - */ + export const PATTERN_STRICT_SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*))*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/u; -/** - * @internal - */ + export const PATTERN_LOOSE_SEMVER = /^v?(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-z-][\da-z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-z-][\da-z-]*))*))?(?:\+([\da-z-]+(?:\.[\da-z-]+)*))?$/iu; -/** - * @internal - */ + export const PATTERN_RANGE_MODE = /^v?(0|[1-9]\d*|x|X|\*)(?:\.(0|[1-9]\d*|x|X|\*))?(?:\.(0|[1-9]\d*|x|X|\*))?(?:-((?:0|[1-9]\d*|\d*[a-z-][\da-z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-z-][\da-z-]*))*))?(?:\+([\da-z-]+(?:\.[\da-z-]+)*))?$/iu; @@ -63,6 +51,7 @@ export const formatVersion = (version: Required | Required; major?: number; @@ -73,6 +62,7 @@ export interface IparseSemVer { version?: () => string; } +/** @dontexport */ export interface IparseRange extends Omit { major?: number | "*" | "X" | "x"; minor?: number | "*" | "X" | "x"; @@ -81,6 +71,7 @@ export interface IparseRange extends Omit( inputVersion: Required | Required | SemVer | string, options: T = OptionsSemVerDefaults as T ): T | boolean extends { rangeMode: false } ? Required : Required { - if (typeof inputVersion != "string" && inputVersion instanceof SemVer) + if (typeof inputVersion != "string" && inputVersion instanceof SemVer) { return resultsFormat(inputVersion) as Required; + } const mergedOptions: Required = { ...OptionsSemVerDefaults, ...options }; const version = typeof inputVersion === "object" ? formatVersion(inputVersion) : inputVersion; // PRE VALIDATION - if (mergedOptions.validators == true || mergedOptions.validators == "Pre") + if (mergedOptions.validators == true || mergedOptions.validators == "Pre") { versionPreValidator(version, { returnType: mergedOptions.returnType }); + } // PARSING const versionTrimmed = version.trim(); @@ -165,8 +158,9 @@ export function parseSemVer( : [] }) as typeof mergedOptions extends { rangeMode: false } ? Required : Required; - if (mergedOptions.validators == true || mergedOptions.validators == "Pre") + if (mergedOptions.validators == true || mergedOptions.validators == "Pre") { versionPostValidator(result, { returnType: mergedOptions.returnType }); + } return result; } diff --git a/packages/semver/src/functions/satisfies.test.ts b/packages/semver/src/functions/satisfies.test.ts index 91a9703..f8627a0 100644 --- a/packages/semver/src/functions/satisfies.test.ts +++ b/packages/semver/src/functions/satisfies.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable @EslintSonar/no-duplicate-string */ import { describe, it, expect } from "vitest"; import satisfies from "./satisfies"; import { myErrorWrapper } from "oh-my-error"; diff --git a/packages/semver/src/functions/satisfies.ts b/packages/semver/src/functions/satisfies.ts index ff095f8..d04b214 100644 --- a/packages/semver/src/functions/satisfies.ts +++ b/packages/semver/src/functions/satisfies.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity */ import type { TOptionsSemVer } from "@/functions"; import { compareSemver, OptionsSemVerDefaults, parseSemVer } from "@/functions"; diff --git a/packages/semver/src/functions/simplifyRange.ts b/packages/semver/src/functions/simplifyRange.ts index 87f8083..139cbbc 100644 --- a/packages/semver/src/functions/simplifyRange.ts +++ b/packages/semver/src/functions/simplifyRange.ts @@ -1,4 +1,3 @@ -/* eslint-disable complexity */ import { satisfies } from "./satisfies"; import { compareSemver } from "./compare"; import { OptionsSemVerDefaults } from "./parseSemVer"; diff --git a/packages/semver/src/functions/versionValidator.ts b/packages/semver/src/functions/versionValidator.ts index 3713b4c..208debf 100644 --- a/packages/semver/src/functions/versionValidator.ts +++ b/packages/semver/src/functions/versionValidator.ts @@ -1,7 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable complexity */ -/* eslint-disable @EslintSonar/no-duplicate-string */ import { MAX_SAFE_BUILD_LENGTH, MAX_SAFE_INTEGER } from "@/internals/constants"; import type { TValidationList } from "@/utils"; import { isX, validator } from "@/utils"; diff --git a/packages/validate-npm-package-name/CHANGELOG.md b/packages/validate-npm-package-name/CHANGELOG.md index 1c7903e..60dcafb 100644 --- a/packages/validate-npm-package-name/CHANGELOG.md +++ b/packages/validate-npm-package-name/CHANGELOG.md @@ -1,5 +1,11 @@ # @myutilia/env +## 1.0.1 + +### Patch Changes + +- change error messages + ## 1.0.0 ### Major Changes diff --git a/packages/validate-npm-package-name/config/tsuprc/tsup.prod.ts b/packages/validate-npm-package-name/config/tsuprc/tsup.prod.ts index 39b49c1..c98fc2d 100644 --- a/packages/validate-npm-package-name/config/tsuprc/tsup.prod.ts +++ b/packages/validate-npm-package-name/config/tsuprc/tsup.prod.ts @@ -1,5 +1,6 @@ import config from "./tsup.base"; import { copy } from "esbuild-plugin-copy"; +import noInternalExports from "@esplugins/no-internal-exports"; import { defineConfig } from "tsup"; export default defineConfig({ @@ -30,7 +31,7 @@ export default defineConfig({ { from: "./.npmrc", to: "./.npmrc" }, { from: "./.npmignore", to: "./.npmignore" }, { from: "./README.md", to: "./README.md" }, - { from: "./LICENSE", to: "./LICENSE" } + { from: "./LICENSE", to: "./" } ] }) ] diff --git a/packages/validate-npm-package-name/package.json b/packages/validate-npm-package-name/package.json index 2e2b4e8..5c9bfdf 100644 --- a/packages/validate-npm-package-name/package.json +++ b/packages/validate-npm-package-name/package.json @@ -1,6 +1,6 @@ { "name": "@betternpm/validate-npm-package-name", - "version": "1.0.0", + "version": "1.0.1", "description": "NPMs utility module", "keywords": [ "utils", @@ -42,10 +42,11 @@ ] }, "dependencies": { - "oh-my-error": "1.1.1" + "oh-my-error": "^2.0.0-prerelease.0" }, "devDependencies": { - "@ineedj/eslintrc": "~1.2.0", + "@esplugins/no-internal-exports": "^1.0.0", + "@ineedj/eslintrc": "~1.2.2", "@ineedj/prettierrc": "^2.0.0", "@ineedj/tsconfig": "^1.0.0", "@types/eslint": "~8.56.12", diff --git a/packages/validate-npm-package-name/src/functions/name/nameValidator.test.js b/packages/validate-npm-package-name/src/functions/name/nameValidator.test.ts similarity index 100% rename from packages/validate-npm-package-name/src/functions/name/nameValidator.test.js rename to packages/validate-npm-package-name/src/functions/name/nameValidator.test.ts diff --git a/packages/validate-npm-package-name/src/functions/name/nameValidator.ts b/packages/validate-npm-package-name/src/functions/name/nameValidator.ts index c074b45..a77b933 100644 --- a/packages/validate-npm-package-name/src/functions/name/nameValidator.ts +++ b/packages/validate-npm-package-name/src/functions/name/nameValidator.ts @@ -1,6 +1,6 @@ -/* eslint-disable guard-for-in */ -/* eslint-disable @typescript-eslint/no-unnecessary-condition , @EslintSonar/no-duplicate-string */ -import type { TMyError, TMyErrorList } from "oh-my-error"; +/* eslint-disable @EslintImports/no-deprecated */ +/* eslint-disable @typescript-eslint/no-unnecessary-condition */ +import type { IMyError, TMyErrorList } from "oh-my-error"; import { myError } from "oh-my-error"; import { builtinModules } from "node:module"; import isScopedPackage from "./isScopedPackage"; @@ -55,82 +55,61 @@ export const MyErrorList = { TOO_LONG_LENGTH_NAME: { code: "TOO_LONG_LENGTH_NAME", hint: { user: "Shorten the name to 214 characters or less" }, - message: { - dev: "Name cannot contain more than 214 characters", - user: "The name is too long. Please use 214 characters or less." - }, + message: "The name is too long. Please use 214 characters or less.", name: "Too Long Name Error" }, CANNOT_START_WITH_UNDERSCORE: { code: "CANNOT_START_WITH_UNDERSCORE", hint: { user: "Remove the leading underscore from the name" }, - message: { - dev: "Name cannot start with an underscore", - user: "The name cannot start with an underscore (_)." - }, + message: "The name cannot start with an underscore (_).", name: "Invalid Starting Character Error" }, CANNOT_START_WITH_PERIOD: { code: "CANNOT_START_WITH_PERIOD", hint: { user: "Remove the leading period from the name" }, - message: { - dev: "Name cannot start with a period", - user: "The name cannot start with a period (.)." - }, + message: "The name cannot start with a period (.).", name: "Invalid Starting Character Error" }, CANNOT_HAVE_SPACES: { code: "CANNOT_HAVE_SPACES", - hint: { user: "Remove all spaces from the name" }, - message: { - dev: "Name cannot contain spaces", - user: "The name cannot contain spaces." - }, + hint: "Remove all spaces from the name", + message: "The name cannot contain spaces.", name: "Invalid Character Error" }, CORE_MODULE_NAME: { code: "CORE_MODULE_NAME", - hint: { user: "Choose a differenceerent name that is not a core module name" }, + hint: { user: "Choose a different name that is not a core module name" }, message: { dev: "Name cannot be a core module name", - user: "This name is reserved. Please choose a differenceerent name." + user: "This name is reserved. Please choose a different name." }, name: "Reserved Name Error" }, BLACK_LISTED: { code: "BLACKLISTED", - hint: { user: "Choose a differenceerent name that is not blacklisted" }, + hint: { user: "Choose a different name that is not blacklisted" }, message: { dev: "Name is blacklisted", - user: "This name is not allowed. Please choose a differenceerent name." + user: "This name is not allowed. Please choose a different name." }, name: "Prohibited Name Error" }, NO_CAPITAL_LETTERS: { code: "NO_CAPITAL_LETTERS", hint: { user: "Convert all capital letters to lowercase" }, - message: { - dev: "Name cannot contain capital letters", - user: "The name should only contain lowercase letters." - }, + message: "The name should only contain lowercase letters.", name: "Invalid Case Error" }, SPECIAL_CHARACTERS: { code: "SPECIAL_CHARACTERS", hint: { user: "Remove special characters (~'!()*) from the name" }, - message: { - dev: "Name cannot contain special characters (~'!()*)", - user: "The name cannot contain special characters (~'!()*)" - }, + message: "The name cannot contain special characters (~'!()*)", name: "Invalid Character Error" }, URL_FRIENDLY: { code: "URL_FRIENDLY", hint: { user: "Remove special characters (~'!()*) from the name" }, - message: { - dev: "Name cannot contain special characters (~'!()*)", - user: "Name can only contain URL-friendly characters no [ (~'!()*) ]" - }, + message: "Name can only contain URL-friendly characters no [ (~'!()*) ]", name: "Invalid Character Error" } } as const satisfies TMyErrorList; @@ -163,10 +142,10 @@ export function nameValidator( name: string, errorThrow = false ): { - errors?: TMyError[]; + errors?: IMyError[]; validForNewPackages: boolean; validForOldPackages: boolean; - warnings?: TMyError[]; + warnings?: IMyError[]; } { /** * Returns the validation result for the package name. @@ -185,7 +164,7 @@ export function nameValidator( /** * Object to store validation problems. */ - const problems: { errors: Array>; warnings: Array> } = { + const problems: { errors: Array>; warnings: Array> } = { warnings: [], errors: [] }; @@ -214,16 +193,17 @@ export function nameValidator( } as const; for (const key in ValidationList) { - const currentValidation = ValidationList[key as keyof typeof ValidationList]; - if (Object.hasOwn(ValidationList, key) && currentValidation?.condition()) { - if (errorThrow) throw myError(MyErrorList[key as keyof typeof MyErrorList] as Required); + if (Object.hasOwn(ValidationList, key)) { + const currentValidation = ValidationList[key as keyof typeof ValidationList]; + if (!currentValidation?.condition()) continue; + if (errorThrow) throw myError(MyErrorList[key as keyof typeof MyErrorList] as Required); if (currentValidation.type == "error") { - problems.errors.push(MyErrorList[key as keyof typeof MyErrorList] as Required); + problems.errors.push(MyErrorList[key as keyof typeof MyErrorList] as Required); } if (currentValidation.type == "warning") { - problems.warnings.push(MyErrorList[key as keyof typeof MyErrorList] as Required); + problems.warnings.push(MyErrorList[key as keyof typeof MyErrorList] as Required); } - if (currentValidation?.exit) return result(problems); + if (currentValidation.exit) return result(problems); } } diff --git a/packages/validate-npm-package-name/src/index.ts b/packages/validate-npm-package-name/src/index.ts index 5f286ff..337216f 100644 --- a/packages/validate-npm-package-name/src/index.ts +++ b/packages/validate-npm-package-name/src/index.ts @@ -1 +1 @@ -export * from "./functions"; +export * from "@/functions"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 71023f4..2f81612 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -37,8 +37,8 @@ importers: version: 2.0.0-prerelease.0 devDependencies: '@esplugins/no-internal-exports': - specifier: 1.0.0-prerelease.1 - version: 1.0.0-prerelease.1 + specifier: ^1.0.0 + version: 1.0.0 '@ineedj/eslintrc': specifier: ~1.2.2 version: 1.2.2(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.2))(tailwindcss@3.4.10)(typescript@5.6.2)(vitest@2.0.5(@types/node@22.5.1)) @@ -83,9 +83,12 @@ importers: packages/validate-npm-package-name: dependencies: oh-my-error: - specifier: 1.1.1 - version: 1.1.1 + specifier: ^2.0.0-prerelease.0 + version: 2.0.0-prerelease.0 devDependencies: + '@esplugins/no-internal-exports': + specifier: ^1.0.0 + version: 1.0.0 '@ineedj/eslintrc': specifier: ~1.2.0 version: 1.2.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.5.4))(tailwindcss@3.4.10)(typescript@5.5.4)(vitest@2.0.5(@types/node@22.5.1)) @@ -517,8 +520,8 @@ packages: resolution: {integrity: sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - '@esplugins/no-internal-exports@1.0.0-prerelease.1': - resolution: {integrity: sha512-CHhtavI0MdUJGyldy7+XJLuC47LBoEemniflVsBml4gT2yeTPSQ4THhDnlm48pO4hK9PYFVR+BvwLsPFIyxu5A==} + '@esplugins/no-internal-exports@1.0.0': + resolution: {integrity: sha512-G6EqhUcXGvmCibvWMVT7+EQxR9lk828E9tfpagAJOWCQdd2o7bTFAb0jbCkfFaPEOetlFGpx7cK0LsmEFeDShQ==} '@humanwhocodes/config-array@0.11.14': resolution: {integrity: sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==} @@ -2883,10 +2886,6 @@ packages: resolution: {integrity: sha512-yBYjY9QX2hnRmZHAjG/f13MzmBzxzYgQhFrke06TTyKY5zSTEqkOeukBzIdVA3j3ulu8Qa3MbVFShV7T2RmGtQ==} engines: {node: '>= 0.4'} - oh-my-error@1.1.1: - resolution: {integrity: sha512-bt8NkFwdnS4h23S7p2oxJWOTK9IRWPYEpz1xzo/BubKZxwUCBxwm2ZRx2UOs2NPt+hjonuLMfPecxzwtj6gNsQ==} - engines: {node: '>=18'} - oh-my-error@2.0.0-prerelease.0: resolution: {integrity: sha512-+c+9jL0H+ZKmxkCdUMsnEhjKnNOfditA9ikCnbNLN4uCtl29hQg1UuU3+f/Hm/PmORA1RqtbYd2PgRzOjl8gbA==} engines: {node: '>=18'} @@ -4333,7 +4332,7 @@ snapshots: '@eslint/js@8.57.0': {} - '@esplugins/no-internal-exports@1.0.0-prerelease.1': + '@esplugins/no-internal-exports@1.0.0': dependencies: magic-regexp: 0.8.0 oh-my-error: 2.0.0-prerelease.0 @@ -7698,8 +7697,6 @@ snapshots: define-properties: 1.2.1 es-object-atoms: 1.0.0 - oh-my-error@1.1.1: {} - oh-my-error@2.0.0-prerelease.0: {} once@1.4.0: