From c807a34e905621ada691f8dedc83b2b198c782ec Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 6 Mar 2025 14:41:20 +0900 Subject: [PATCH 01/26] chore: use pnpm --- .gitignore | 1 + package.json | 5 +++-- pnpm-workspace.yaml | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 pnpm-workspace.yaml diff --git a/.gitignore b/.gitignore index 8ce1d1d..16d0aa1 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ node_modules/ # Lockfiles are not required for npm packages package-lock.json yarn.lock +pnpm-lock.yaml # tarballs packed by `npm pack` *.tgz diff --git a/package.json b/package.json index d54d760..fd176ec 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ }, "engines": { "node": ">=18.x", - "npm": ">=10.x" - } + "pnpm": ">=10.x" + }, + "packageManager": "pnpm@10.18.2+sha512.9fb969fa749b3ade6035e0f109f0b8a60b5d08a1a87fdf72e337da90dcc93336e2280ca4e44f2358a649b83c17959e9993e777c2080879f3801e6f0d999ad3dd" } diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..cb8238f --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,3 @@ +onlyBuiltDependencies: + - esbuild + - unrs-resolver From faf96d96d6bb2994c805c72b72684c0432180114 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 6 Mar 2025 14:50:17 +0900 Subject: [PATCH 02/26] chore: apply latest `@phanect/configs` to tsconfigs --- src/nodejs/tsconfig.json | 10 ++++++++++ tsconfig.json | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/nodejs/tsconfig.json diff --git a/src/nodejs/tsconfig.json b/src/nodejs/tsconfig.json new file mode 100644 index 0000000..1c53588 --- /dev/null +++ b/src/nodejs/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": [ + "@phanect/configs/ts/nodejs", + "@phanect/configs/ts/addons/npm" + ], + "include": [ + "./**/*.ts", + "./**/*.js" + ] +} diff --git a/tsconfig.json b/tsconfig.json index e9153d0..4c0b5bd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,17 @@ { "extends": [ - "@phanect/configs/tsconfig/frontend", - "@phanect/configs/tsconfig/addons/npm" + "@phanect/configs/ts", + "@phanect/configs/ts/addons/npm" ], - "include": ["**/*.ts", "**/*.js"], - "exclude": ["dist", "node_modules"] + "include": [ + "**/*.ts", + "**/*.tsx", + "**/*.js", + "**/*.mjs", + "**/*.jsx" + ], + "exclude": [ + "dist", + "node_modules" + ] } From de88615878298d58173441ad9e4971c71a04cb1d Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 6 Mar 2025 14:53:21 +0900 Subject: [PATCH 03/26] chore: switch back from Biome to ESLint --- biome.jsonc | 4 ---- eslint.config.ts | 31 +++++++++++++++++++++++++++++++ package.json | 8 +++++--- src/universal/sort-objects.ts | 4 ++-- 4 files changed, 38 insertions(+), 9 deletions(-) delete mode 100644 biome.jsonc create mode 100644 eslint.config.ts diff --git a/biome.jsonc b/biome.jsonc deleted file mode 100644 index 704227a..0000000 --- a/biome.jsonc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", - "extends": ["@phanect/configs/biome"] -} diff --git a/eslint.config.ts b/eslint.config.ts new file mode 100644 index 0000000..b5d0097 --- /dev/null +++ b/eslint.config.ts @@ -0,0 +1,31 @@ +import { core, nodejs, unbundled } from "@phanect/lint"; +import type { Linter } from "eslint"; + +const configs: Linter.Config[] = [ + { + ignores: [ + "./**/dist/**", + ], + }, + + ...core, + ...unbundled, + + ...nodejs.map((config) => ({ + ...config, + files: [ "./src/nodejs/**/*.ts" ], + })), + + { + // Do not add `files: [ "*" ],` here. + + languageOptions: { + parserOptions: { + projectService: true, + tsconfigRootDir: import.meta.dirname, + }, + }, + }, +]; + +export default configs; diff --git a/package.json b/package.json index fd176ec..63a71ea 100644 --- a/package.json +++ b/package.json @@ -24,15 +24,17 @@ }, "scripts": { "build": "unbuild", - "lint": "tsc --noEmit && biome check", - "fix": "biome check --write", + "lint": "tsc --noEmit && eslint", + "fix": "eslint --fix", "release": "npm publish --access public --non-interactive", "test": "vitest run" }, "devDependencies": { - "@biomejs/biome": "^1.8.3", "@phanect/configs": "latest", + "@phanect/lint": "latest", "@types/node": "^22.1.0", + "eslint": "^9.21.0", + "jiti": "^2.4.2", "typescript": "^5.3.3", "unbuild": "^2.0.0", "vitest": "^2.0.2" diff --git a/src/universal/sort-objects.ts b/src/universal/sort-objects.ts index 4d9fb82..23085bc 100644 --- a/src/universal/sort-objects.ts +++ b/src/universal/sort-objects.ts @@ -3,8 +3,8 @@ * @param objects - Aarray of objects. * @returns - Sorted array of the objects. */ -/* biome-ignore lint/suspicious/noExplicitAny: - * `{ [key: string]: unknown }` is not acceptable and we must use `any` here. +/* eslint-disable-next-line @typescript-eslint/no-explicit-any -- + * `{ [key: string]: unknown }` is not acceptable and we must use `any` here. * See: https://github.com/microsoft/TypeScript/wiki/Breaking-Changes/83af27fca396d172b4d895d480b10c3bacf89112#-k-string-unknown--is-no-longer-a-wildcard-assignment-target */ export const sortObjects = ( From d34bc2b06b7e12d098c430d66d620e34f40ce4ad Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Wed, 4 Jun 2025 22:10:48 +0900 Subject: [PATCH 04/26] fix: place `type` before others This is warned by tsup. --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 63a71ea..1aa7e2d 100644 --- a/package.json +++ b/package.json @@ -11,15 +11,15 @@ "exports": { ".": { "import": { - "default": "./dist/universal.mjs", - "types": "./dist/universal.d.ts" + "types": "./dist/universal.d.ts", + "default": "./dist/universal.mjs" }, "require": "./dist/universal.cjs" }, "./nodejs": { + "types": "./dist/nodejs.d.ts", "import": "./dist/nodejs.mjs", - "require": "./dist/nodejs.cjs", - "types": "./dist/nodejs.d.ts" + "require": "./dist/nodejs.cjs" } }, "scripts": { From c859ec226e34430a39e92e8db674fa525e2cd398 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 6 Mar 2025 15:02:51 +0900 Subject: [PATCH 05/26] style: fix ESLint warnings & errors --- src/nodejs/cmd.ts | 15 +++++++-------- src/nodejs/load-json.ts | 8 ++++---- src/universal/get-last-element-of.ts | 8 ++++---- src/universal/npm-package-exists.ts | 12 ++++++------ src/universal/sort-objects.ts | 10 +++------- test/cmd.test.ts | 8 ++++---- test/fixtures/load-json/fixture.json | 2 +- test/nodejs/load-json.test.ts | 2 +- test/universal/get-last-element-of.test.ts | 6 +++--- 9 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/nodejs/cmd.ts b/src/nodejs/cmd.ts index ab9a8da..c271bd6 100644 --- a/src/nodejs/cmd.ts +++ b/src/nodejs/cmd.ts @@ -1,5 +1,5 @@ -import type { Buffer } from "node:buffer"; import { exec as execCallback } from "node:child_process"; +import type { Buffer } from "node:buffer"; type CmdParams = Parameters; type CommandString = CmdParams[0]; @@ -48,9 +48,8 @@ export const cmd = async ( const log = (queued: Queued): void => { const logger = queued.target === "stdout" ? console.info : console.error; - const prefix = - (queued.isCommand ? (0 < queued.processId ? "\n" : "") + ">>> " : "") + - `[${queued.processId}]`; + const prefix = (queued.isCommand ? (0 < queued.processId ? "\n" : "") + ">>> " : "") + + `[${ queued.processId }]`; const trailingLineBreaks = queued.isCommand ? "\n\n" : "\n"; if (typeof queued.text === "string" || !!queued.text?.toString) { @@ -59,7 +58,7 @@ export const cmd = async ( .toString() .trim() // strip leading & trailing linebreaks .split("\n") - .map((line) => `${prefix} ${line}`) + .map((line) => `${ prefix } ${ line }`) .join("\n") + trailingLineBreaks, ); } else { @@ -75,8 +74,8 @@ export const cmd = async ( text: string | Buffer | unknown, { target, processId, isCommand = false }: AddToPrintQueueOptions, ): void => { - const _text = - typeof text === "string" || !text?.toString ? text : text.toString(); + const _text + = typeof text === "string" || !text?.toString ? text : text.toString(); if (processId <= currentProcessId) { log({ @@ -108,7 +107,7 @@ export const cmd = async ( }; const promises: Promise[] = ( - Array.isArray(commands) ? commands : [commands] + Array.isArray(commands) ? commands : [ commands ] ).map( (command, i) => new Promise((resolve, reject) => { diff --git a/src/nodejs/load-json.ts b/src/nodejs/load-json.ts index c45cd48..ec50a75 100644 --- a/src/nodejs/load-json.ts +++ b/src/nodejs/load-json.ts @@ -1,20 +1,20 @@ -import type { ObjectEncodingOptions } from "node:fs"; import { readFile, stat } from "node:fs/promises"; +import type { ObjectEncodingOptions } from "node:fs"; -export const loadJSON = async ( +export const loadJSON = async >( jsonPath: string, options?: ObjectEncodingOptions, ): Promise => { try { if (!(await stat(jsonPath)).isFile()) { - throw new Error(`"${jsonPath}" does not exist of not a regular file.`); + throw new Error(`"${ jsonPath }" does not exist of not a regular file.`); } const jsonString = await readFile(jsonPath, { ...options, encoding: options?.encoding ?? "utf8", }); - const loadedJSON: JsonObject = JSON.parse(jsonString); + const loadedJSON = JSON.parse(jsonString) as JsonObject; return loadedJSON; } catch (err) { diff --git a/src/universal/get-last-element-of.ts b/src/universal/get-last-element-of.ts index 4b1758e..bc0ddfc 100644 --- a/src/universal/get-last-element-of.ts +++ b/src/universal/get-last-element-of.ts @@ -1,11 +1,11 @@ export function getLastElementOf( arr: T[], - options?: { withIndex?: false }, + options?: { withIndex?: false; }, ): T | undefined; export function getLastElementOf( arr: T[], - options: { withIndex: true }, -): { el: T; index: number } | undefined; + options: { withIndex: true; }, +): { el: T; index: number; } | undefined; /** * @param arr - The array to get the last element. @@ -19,7 +19,7 @@ export function getLastElementOf( options: { withIndex?: boolean; } = {}, -): T | { el: T; index: number } | undefined { +): T | { el: T; index: number; } | undefined { if (arr.length <= 0) { return undefined; } diff --git a/src/universal/npm-package-exists.ts b/src/universal/npm-package-exists.ts index 97af56e..46934c1 100644 --- a/src/universal/npm-package-exists.ts +++ b/src/universal/npm-package-exists.ts @@ -1,7 +1,7 @@ import { trimLines } from "./trim-lines.ts"; export const npmPackageExists = async (pkgName: string): Promise => { - const res = await fetch(`https://registry.npmjs.com/${pkgName}`); + const res = await fetch(`https://registry.npmjs.com/${ pkgName }`); if (res.status < 400) { return true; @@ -10,24 +10,24 @@ export const npmPackageExists = async (pkgName: string): Promise => { } else if (400 <= res.status && res.status < 500) { throw new Error( trimLines(` - [ERROR] Package name "${pkgName}" may be invalid. + [ERROR] Package name "${ pkgName }" may be invalid. Could not check if npm package exists. - HTTP ${res.status} ${res.statusText} https://registry.npmjs.com/${pkgName} + HTTP ${ res.status } ${ res.statusText } https://registry.npmjs.com/${ pkgName } `), ); } else if (500 <= res.status) { throw new Error( trimLines(` [ERROR] registry.npmjs.com may be down. See: https://status.npmjs.org - Could not check if npm package "${pkgName}" exists. - HTTP ${res.status} ${res.statusText} https://registry.npmjs.com/${pkgName} + Could not check if npm package "${ pkgName }" exists. + HTTP ${ res.status } ${ res.statusText } https://registry.npmjs.com/${ pkgName } `), ); } else { throw new Error( trimLines(` - [ERROR] Unexpected HTTP Status Code ${res.status} ${res.statusText} while checking https://registry.npmjs.com/${pkgName} + [ERROR] Unexpected HTTP Status Code ${ res.status } ${ res.statusText } while checking https://registry.npmjs.com/${ pkgName } `), ); } diff --git a/src/universal/sort-objects.ts b/src/universal/sort-objects.ts index 23085bc..ac51ece 100644 --- a/src/universal/sort-objects.ts +++ b/src/universal/sort-objects.ts @@ -7,7 +7,7 @@ * `{ [key: string]: unknown }` is not acceptable and we must use `any` here. * See: https://github.com/microsoft/TypeScript/wiki/Breaking-Changes/83af27fca396d172b4d895d480b10c3bacf89112#-k-string-unknown--is-no-longer-a-wildcard-assignment-target */ -export const sortObjects = ( +export const sortObjects = >( objects: T[], ): T[] => objects.sort((obj1, obj2) => { @@ -18,13 +18,9 @@ export const sortObjects = ( for (const key of keys) { if (!(key in obj1 && key in obj2) || obj1[key] === obj2[key]) { // continue - } - // if the values are not comparable, false is returned. - else if ((obj1[key] as Comparable) < (obj2[key] as Comparable)) { + } else if ((obj1[key] as Comparable) < (obj2[key] as Comparable)) { // false if if not comparable return -1; - } - // if the values are not comparable, false is returned. - else if ((obj1[key] as Comparable) > (obj2[key] as Comparable)) { + } else if ((obj1[key] as Comparable) > (obj2[key] as Comparable)) { // false if if not comparable return 1; } else { // continue diff --git a/test/cmd.test.ts b/test/cmd.test.ts index 46e1f23..5556379 100644 --- a/test/cmd.test.ts +++ b/test/cmd.test.ts @@ -24,18 +24,18 @@ describe("Mock tests", () => { }); await cmd([ - `bash ${join(__dirname, "fixtures/cmd/command1.sh")}`, - `bash ${join(__dirname, "fixtures/cmd/command2.sh")}`, + `bash ${ join(__dirname, "fixtures/cmd/command1.sh") }`, + `bash ${ join(__dirname, "fixtures/cmd/command2.sh") }`, ]); expect(output).toStrictEqual( deindent(` - >>> [0] bash ${join(join(__dirname, "fixtures/cmd/command1.sh"))} + >>> [0] bash ${ join(join(__dirname, "fixtures/cmd/command1.sh")) } [0] Command 1 started. [0] This message is printed after three seconds, but it should be shown before the output of command 2. - >>> [1] bash ${join(__dirname, "fixtures/cmd/command2.sh")} + >>> [1] bash ${ join(__dirname, "fixtures/cmd/command2.sh") } [1] Command 2 executed. `).trim() + "\n", diff --git a/test/fixtures/load-json/fixture.json b/test/fixtures/load-json/fixture.json index e8b37fe..65b645f 100644 --- a/test/fixtures/load-json/fixture.json +++ b/test/fixtures/load-json/fixture.json @@ -1,4 +1,4 @@ { "foo": "bar", - "boo": ["a", "b", "c"] + "boo": [ "a", "b", "c" ] } diff --git a/test/nodejs/load-json.test.ts b/test/nodejs/load-json.test.ts index 66d8699..b3edce0 100644 --- a/test/nodejs/load-json.test.ts +++ b/test/nodejs/load-json.test.ts @@ -9,6 +9,6 @@ test("loadJSON", async () => { expect(obj).toStrictEqual({ foo: "bar", - boo: ["a", "b", "c"], + boo: [ "a", "b", "c" ], }); }); diff --git a/test/universal/get-last-element-of.test.ts b/test/universal/get-last-element-of.test.ts index 20647d0..f6224b5 100644 --- a/test/universal/get-last-element-of.test.ts +++ b/test/universal/get-last-element-of.test.ts @@ -2,11 +2,11 @@ import { expect, test } from "vitest"; import { getLastElementOf } from "../../src/universal.ts"; test("getLastElementOf (without index)", () => { - const lastElement = getLastElementOf(["a", "b", "c"]); + const lastElement = getLastElementOf([ "a", "b", "c" ]); expect(lastElement).toStrictEqual("c"); - const lastElementExplicitlyWithoutIndex = getLastElementOf(["a", "b", "c"], { + const lastElementExplicitlyWithoutIndex = getLastElementOf([ "a", "b", "c" ], { withIndex: false, }); @@ -14,7 +14,7 @@ test("getLastElementOf (without index)", () => { }); test("getLastElementOf (with index)", () => { - const lastElement = getLastElementOf(["a", "b", "c"], { withIndex: true }); + const lastElement = getLastElementOf([ "a", "b", "c" ], { withIndex: true }); expect(lastElement).toStrictEqual({ el: "c", index: 2 }); }); From 6564831ec50277008980dc8443564fa25bb55349 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 5 Jun 2025 10:28:55 +0900 Subject: [PATCH 06/26] feat: drop Node.js 18 and add Node.js 24 support --- .github/workflows/workflow.yaml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index a28ab7b..6807742 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -17,9 +17,9 @@ jobs: strategy: matrix: node-version: - - 18 - 20 - 22 + - 24 steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} diff --git a/package.json b/package.json index 1aa7e2d..5c087f5 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "vitest": "^2.0.2" }, "engines": { - "node": ">=18.x", + "node": "^20.11.0 || ^22.16.0 || >=24.0.0", "pnpm": ">=10.x" }, "packageManager": "pnpm@10.18.2+sha512.9fb969fa749b3ade6035e0f109f0b8a60b5d08a1a87fdf72e337da90dcc93336e2280ca4e44f2358a649b83c17959e9993e777c2080879f3801e6f0d999ad3dd" From 9e1b8809b7775b4f204c2fa50508d1ea3cf8b87e Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 16:55:18 +0900 Subject: [PATCH 07/26] chore: fix typo in .npmignore --- .npmignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.npmignore b/.npmignore index 3088814..80c5ffe 100644 --- a/.npmignore +++ b/.npmignore @@ -5,7 +5,7 @@ *.tgz .editorconfig .eslintrc.cjs -.gitarrtibutes +.gitattributes .gitignore build.config.* tsconfig.json From a296b90c099379a203857273921033f0dd528b2a Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Wed, 4 Jun 2025 22:02:32 +0900 Subject: [PATCH 08/26] chore: migrate to mise --- mise.toml | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 7 ------- 2 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 mise.toml diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..bba6617 --- /dev/null +++ b/mise.toml @@ -0,0 +1,51 @@ +[tools] +node = { version = "24" } +"npm:nushell" = "latest" + +[tasks] + [tasks.build] + run = "unbuild" + env = { NODE_ENV = "production" } + + [tasks.lint] + run = [ + "tsc --noEmit", + "eslint" + ] + + [tasks.fix] + run = "eslint --fix" + + [tasks.test] + run = "vitest run" + + [tasks.clean] + run = "git clean -dX --exclude=\"!mise.local.toml\" --force" + + [tasks.refresh] + depends = [ "clean" ] + run = [ + "rm --force ./pnpm-lock.yaml", + "corepack enable", + "corepack up", + "mise install" + ] + + [tasks.release] + run = "npm publish --access public --non-interactive" + +[hooks] +postinstall = [ + "corepack enable", + "pnpm install", +] + +[env] +_.path = "./node_modules/.bin" + +[settings] +jobs = 8 + +# Required for hooks as of 2025.10 +# https://mise.jdx.dev/hooks.html +experimental = true diff --git a/package.json b/package.json index 5c087f5..0129531 100644 --- a/package.json +++ b/package.json @@ -22,13 +22,6 @@ "require": "./dist/nodejs.cjs" } }, - "scripts": { - "build": "unbuild", - "lint": "tsc --noEmit && eslint", - "fix": "eslint --fix", - "release": "npm publish --access public --non-interactive", - "test": "vitest run" - }, "devDependencies": { "@phanect/configs": "latest", "@phanect/lint": "latest", From 57137c83b79c60416f062a971301470d9b869c7f Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 6 Mar 2025 14:59:05 +0900 Subject: [PATCH 09/26] chore: replace unbuild with tsdown --- build.config.ts | 9 --------- mise.toml | 2 +- package.json | 8 ++++---- tsdown.config.ts | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 14 deletions(-) delete mode 100644 build.config.ts create mode 100644 tsdown.config.ts diff --git a/build.config.ts b/build.config.ts deleted file mode 100644 index 7467145..0000000 --- a/build.config.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { defineBuildConfig } from "unbuild"; - -export default defineBuildConfig({ - entries: ["./src/universal.ts", "./src/nodejs.ts"], - declaration: true, - rollup: { - emitCJS: true, - }, -}); diff --git a/mise.toml b/mise.toml index bba6617..8b40631 100644 --- a/mise.toml +++ b/mise.toml @@ -4,7 +4,7 @@ node = { version = "24" } [tasks] [tasks.build] - run = "unbuild" + run = "tsdown" env = { NODE_ENV = "production" } [tasks.lint] diff --git a/package.json b/package.json index 0129531..d9768e8 100644 --- a/package.json +++ b/package.json @@ -6,19 +6,19 @@ "license": "MIT", "type": "module", "main": "./dist/universal.cjs", - "module": "./dist/universal.mjs", + "module": "./dist/universal.js", "types": "./dist/universal.d.ts", "exports": { ".": { "import": { "types": "./dist/universal.d.ts", - "default": "./dist/universal.mjs" + "default": "./dist/universal.js" }, "require": "./dist/universal.cjs" }, "./nodejs": { "types": "./dist/nodejs.d.ts", - "import": "./dist/nodejs.mjs", + "import": "./dist/nodejs.js", "require": "./dist/nodejs.cjs" } }, @@ -28,8 +28,8 @@ "@types/node": "^22.1.0", "eslint": "^9.21.0", "jiti": "^2.4.2", + "tsdown": "0.15.6", "typescript": "^5.3.3", - "unbuild": "^2.0.0", "vitest": "^2.0.2" }, "engines": { diff --git a/tsdown.config.ts b/tsdown.config.ts new file mode 100644 index 0000000..daf8a6d --- /dev/null +++ b/tsdown.config.ts @@ -0,0 +1,16 @@ +import { defineConfig } from "tsdown"; + +export default defineConfig({ + entry: [ + "./src/universal.ts", + "./src/nodejs.ts", + ], + + format: [ "esm", "cjs" ], + dts: true, + sourcemap: true, + + treeshake: false, + minify: false, + clean: true, +}); From f8fe270d8e3a6d0bf4033f6dd47cfd11b4b15da5 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 16:55:48 +0900 Subject: [PATCH 10/26] chore: add and update other project configs --- .github/CODEOWNERS | 1 + .github/dependabot.yml | 19 ++++++++- .gitignore | 86 ++++++++++++++++++++++++++++++++--------- .npmignore | 11 ++++-- .vscode/extensions.json | 8 ++++ .vscode/settings.json | 39 +++++++++++++++++++ 6 files changed, 140 insertions(+), 24 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..9cff13e --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @phanect diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6c3a2d4..94badf3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,13 +3,28 @@ updates: - package-ecosystem: "npm" directory: "/" schedule: - interval: "daily" + interval: "weekly" assignees: - "phanect" + groups: + compatible: + applies-to: "version-updates" + update-types: + - "minor" + - "patch" - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "daily" + interval: "weekly" assignees: - "phanect" + groups: + security: + applies-to: "security-updates" + patterns: + - "*" + normal: + applies-to: "version-updates" + patterns: + - "*" diff --git a/.gitignore b/.gitignore index 16d0aa1..5e7520f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,7 @@ # -# Project-Specific +# Generic # -# Built files -dist/ - -# -# System -# - -# Logs -logs/ -*.log - # PIDs *.pid *.seed @@ -22,25 +11,84 @@ pids # File manager configs .directory Thumbs.db -*.DS_Store +.DS_Store + +# Build directory +build/ +dist/ + +# tmp files +temp/ +tmp/ + +# Logs +logs/ +*.log + +# Archives +*.zip +*.tar.gz +*.tar.xz +*.tar +*.tgz + +# dotenv +.env +.env.* +!.env.example + +# SQLite DB +*.db +*.db-journal + +# mise +mise.local.toml # # JavaScript # -# NPM / Yarn +# NPM / package managers node_modules/ .npm/ .yarn-integrity +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + # Lockfiles are not required for npm packages +pnpm-lock.yaml package-lock.json yarn.lock -pnpm-lock.yaml +bun.lockb +npm-shrinkwrap.json -# tarballs packed by `npm pack` -*.tgz - -# Others +# Node.js .node_repl_history + +# TypeScript +*.tsbuildinfo + +# Frameworks +.next/ +.nuxt/ +out/ +.svelte-kit/ +.astro/ + +# Platforms +.wrangler/ +.dev.vars +worker-configuration.d.ts + +.vercel/ +.netlify/ + +# Vite +vite.config.js.timestamp-* +vite.config.ts.timestamp-* + +# ESLint .eslintcache diff --git a/.npmignore b/.npmignore index 80c5ffe..b60af40 100644 --- a/.npmignore +++ b/.npmignore @@ -1,11 +1,16 @@ +# TODO Remove this file if the project is not an npm package /.github/ +/.vscode/ /dist/*.d.mts /dist/*.d.cts -/test/ +src/ +test/ +tests/ +*.config.js +*.config.mjs +*.config.ts *.tgz .editorconfig -.eslintrc.cjs .gitattributes .gitignore -build.config.* tsconfig.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..46f2b23 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "dbaeumer.vscode-eslint", + "EditorConfig.EditorConfig", + "hverlin.mise-vscode", + "tamasfe.even-better-toml" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..92027ef --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,39 @@ +{ + "javascript.preferences.importModuleSpecifierEnding": "js", + "javascript.preferences.quoteStyle": "double", + "typescript.preferences.preferTypeOnlyAutoImports": true, + + "eslint.useFlatConfig": true, + "eslint.validate": [ + "javascript", + "typescript", + "javascriptreact", + "typescriptreact", + "vue", + "svelte", + "astro", + "html", + "json", + "jsonc", + "json5", + ], + + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.defaultFormatter": "dbaeumer.vscode-eslint", + "editor.codeActionsOnSave": { + "source.fixAll": "never" + }, + "eslint.format.enable": true, + "eslint.codeActionsOnSave.mode": "problems", + "eslint.codeActionsOnSave.rules": [ + "@stylistic/arrow-parens", + "@stylistic/quotes", + "@stylistic/semi", + "@stylistic/space-before-blocks", + "@stylistic/space-before-function-paren", + "@stylistic/space-in-parens" + ], + + "prettier.enable": false +} From 0116885140a199c48a6edf3a6734ccdebc56cc71 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 18:02:05 +0900 Subject: [PATCH 11/26] doc: add `repository` to package.json --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index d9768e8..80102b7 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,10 @@ "name": "@phanect/utils", "version": "1.5.0", "description": "@phanect's personal utility library for JavaScript & TypeScript", + "repository": { + "type": "git", + "url": "git+https://github.com/phanect/utils.git" + }, "author": "Jumpei Ogawa (https://phanective.org)", "license": "MIT", "type": "module", From 011e360f080da83c86eb6e45fae6ff62d3407085 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 16:57:33 +0900 Subject: [PATCH 12/26] doc: add dev doc to README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 212bf38..8bb6caf 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,21 @@ @phanect's personal utility library for JavaScript & TypeScript +## Development + +### Prerequisites + +- [mise](https://mise.jdx.dev) + +### Build + +Run the following commands: + +```sh +mise install +mise build +``` + ## License MIT From 5e14b65dc05273c20a2961fcdb8846a7d63dbfe0 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 16:38:38 +0900 Subject: [PATCH 13/26] doc: remove unnecessary comment --- .gitattributes | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index dbd44bf..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -# Auto detect text files and enforce LF as linebreaks * text=auto eol=lf From 8a0a3f22ee0e7629fae9c8d128f983d3ccde7cca Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 17:04:28 +0900 Subject: [PATCH 14/26] ci: upgrade `actions/checkout` to v5.0.0 --- .github/workflows/workflow.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 6807742..05276d9 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -21,7 +21,7 @@ jobs: - 22 - 24 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: @@ -37,7 +37,7 @@ jobs: if: github.event_name == 'release' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/setup-node@v4 with: node-version: 20 From f8662b21b32fd15eb7c6cf6143d73c66ed828020 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 17:12:31 +0900 Subject: [PATCH 15/26] ci: extract build process --- .github/workflows/workflow.yaml | 34 ++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 05276d9..0f3e54f 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -12,7 +12,26 @@ on: - published jobs: - build: + build-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - run: npm run lint + - run: npm run build + + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: dist + path: dist + if-no-files-found: error + retention-days: 1 + include-hidden-files: true + + test: runs-on: ubuntu-latest strategy: matrix: @@ -27,13 +46,12 @@ jobs: with: node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm run build - run: npm test - - run: npm run lint publish: - needs: build + needs: + - build-lint + - test if: github.event_name == 'release' runs-on: ubuntu-latest steps: @@ -42,8 +60,10 @@ jobs: with: node-version: 20 - - run: npm install - - run: npm run build + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: dist + path: dist - name: Set npm auth token run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_AUTH_TOKEN}}" > ~/.npmrc From 85438d977d8bca28d19542adb407220666a56568 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 17:12:42 +0900 Subject: [PATCH 16/26] ci: add missing permission --- .github/workflows/workflow.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 0f3e54f..3863a29 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -11,6 +11,9 @@ on: types: - published +permissions: + contents: read + jobs: build-lint: runs-on: ubuntu-latest From 21da38eeb64c5899a66bfe5671c473c63068f4ae Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 17:12:56 +0900 Subject: [PATCH 17/26] ci: add timeout minutes --- .github/workflows/workflow.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 3863a29..e457853 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -17,6 +17,7 @@ permissions: jobs: build-lint: runs-on: ubuntu-latest + timeout-minutes: 5 steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/setup-node@v4 @@ -36,6 +37,7 @@ jobs: test: runs-on: ubuntu-latest + timeout-minutes: 5 strategy: matrix: node-version: @@ -57,6 +59,7 @@ jobs: - test if: github.event_name == 'release' runs-on: ubuntu-latest + timeout-minutes: 5 steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/setup-node@v4 From 9c4a54d0285f42e9af9f47810bf75e97ec635fda Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 17:13:23 +0900 Subject: [PATCH 18/26] ci: add job name --- .github/workflows/workflow.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index e457853..7ca3cd5 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -36,6 +36,7 @@ jobs: include-hidden-files: true test: + name: test on Node.js v${{ matrix.node-version }} runs-on: ubuntu-latest timeout-minutes: 5 strategy: From 4eb136760282f0bc5bc739e592400d2211464735 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 17:14:10 +0900 Subject: [PATCH 19/26] ci: migrate to mise --- .github/workflows/workflow.yaml | 28 +++++++++++++++++----------- mise.toml | 1 - 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 7ca3cd5..a081954 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -20,12 +20,13 @@ jobs: timeout-minutes: 5 steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - uses: actions/setup-node@v4 + - uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4 with: - node-version: 20 + install: true + cache: true - - run: npm run lint - - run: npm run build + - run: mise lint + - run: mise build - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: @@ -45,14 +46,18 @@ jobs: - 20 - 22 - 24 + env: + # Override Node.js version over mise.toml + MISE_NODE_VERSION: ${{ matrix.node-version }} steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 + - uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4 with: - node-version: ${{ matrix.node-version }} + install: true + cache: true - - run: npm test + - run: mise test publish: needs: @@ -63,9 +68,10 @@ jobs: timeout-minutes: 5 steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - uses: actions/setup-node@v4 + - uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4 with: - node-version: 20 + install: true + cache: true - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 with: @@ -74,4 +80,4 @@ jobs: - name: Set npm auth token run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_AUTH_TOKEN}}" > ~/.npmrc - - run: npm run release + - run: mise release diff --git a/mise.toml b/mise.toml index 8b40631..89a056c 100644 --- a/mise.toml +++ b/mise.toml @@ -1,6 +1,5 @@ [tools] node = { version = "24" } -"npm:nushell" = "latest" [tasks] [tasks.build] From 25fcb90193da7040114daea3e80b4ef88ae7a33c Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 17:14:41 +0900 Subject: [PATCH 20/26] ci: rename file --- .github/workflows/{workflow.yaml => actions.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{workflow.yaml => actions.yml} (100%) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/actions.yml similarity index 100% rename from .github/workflows/workflow.yaml rename to .github/workflows/actions.yml From 73069d7931c97ff46d2a44a8f813f46eab72e40d Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 5 Jun 2025 10:37:37 +0900 Subject: [PATCH 21/26] refactor: remove unnecessary `catch` --- src/nodejs/load-json.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/nodejs/load-json.ts b/src/nodejs/load-json.ts index ec50a75..77f50ab 100644 --- a/src/nodejs/load-json.ts +++ b/src/nodejs/load-json.ts @@ -5,19 +5,15 @@ export const loadJSON = async >( jsonPath: string, options?: ObjectEncodingOptions, ): Promise => { - try { - if (!(await stat(jsonPath)).isFile()) { - throw new Error(`"${ jsonPath }" does not exist of not a regular file.`); - } + if (!(await stat(jsonPath)).isFile()) { + throw new Error(`"${ jsonPath }" does not exist of not a regular file.`); + } - const jsonString = await readFile(jsonPath, { - ...options, - encoding: options?.encoding ?? "utf8", - }); - const loadedJSON = JSON.parse(jsonString) as JsonObject; + const jsonString = await readFile(jsonPath, { + ...options, + encoding: options?.encoding ?? "utf8", + }); + const loadedJSON = JSON.parse(jsonString) as JsonObject; - return loadedJSON; - } catch (err) { - return Promise.reject(err); - } + return loadedJSON; }; From cc4ae6aa4b257a2f04e1189cf44fa7c07c96ffc2 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Thu, 5 Jun 2025 14:37:21 +0900 Subject: [PATCH 22/26] feat: remove no longer used `cmd()` --- src/nodejs.ts | 1 - src/nodejs/cmd.ts | 167 ---------------------------------------------- test/cmd.test.ts | 44 ------------ 3 files changed, 212 deletions(-) delete mode 100644 src/nodejs/cmd.ts delete mode 100644 test/cmd.test.ts diff --git a/src/nodejs.ts b/src/nodejs.ts index 0060f7f..a97b7ab 100644 --- a/src/nodejs.ts +++ b/src/nodejs.ts @@ -1,2 +1 @@ -export { cmd } from "./nodejs/cmd.ts"; export { loadJSON } from "./nodejs/load-json.ts"; diff --git a/src/nodejs/cmd.ts b/src/nodejs/cmd.ts deleted file mode 100644 index c271bd6..0000000 --- a/src/nodejs/cmd.ts +++ /dev/null @@ -1,167 +0,0 @@ -import { exec as execCallback } from "node:child_process"; -import type { Buffer } from "node:buffer"; - -type CmdParams = Parameters; -type CommandString = CmdParams[0]; -type CmdOptions = CmdParams[1] & { - output?: boolean; - printCommand?: boolean; -}; - -type CmdCallback = Exclude; -type CmdCallbackParams = Parameters; -type CmdStdOut = CmdCallbackParams[1]; -type CmdStdErr = CmdCallbackParams[2]; - -type CmdReturn = { - stdout: CmdStdOut; - stderr: CmdStdErr; - child: ReturnType; -}; - -type Queued = { - processId: number; - text: string | unknown; - target: "stdout" | "stderr"; - isCommand: boolean; -}; - -/** - * Run multiple commands asynchronously, but show their output sequentially. - * @param commands - Command(s) to run. - * @param options - Options. Same as Node.js's `child_process.exec()`'s + some additional options - * @param options.output - Print output if `true`. If `false`, no command output is printed and you have to print them manually from the return value. `true` by default. - * @param options.printCommand - Print command string before running the command. `true` by default. - * @returns Array of command output and child process object. - */ -export const cmd = async ( - commands: CommandString | CommandString[], - options?: CmdOptions, -): Promise => { - // Default options - const { output = true, printCommand = true } = options ?? {}; - /** Current command ID to be allowed to pring log */ - let currentProcessId = 0; - /** Queue of the texts waiting to be printed. */ - let queue: Queued[] = []; - const returnValues: CmdReturn[] = []; - - const log = (queued: Queued): void => { - const logger = queued.target === "stdout" ? console.info : console.error; - const prefix = (queued.isCommand ? (0 < queued.processId ? "\n" : "") + ">>> " : "") - + `[${ queued.processId }]`; - const trailingLineBreaks = queued.isCommand ? "\n\n" : "\n"; - - if (typeof queued.text === "string" || !!queued.text?.toString) { - logger( - queued.text - .toString() - .trim() // strip leading & trailing linebreaks - .split("\n") - .map((line) => `${ prefix } ${ line }`) - .join("\n") + trailingLineBreaks, - ); - } else { - logger(prefix, queued.text, trailingLineBreaks); - } - }; - - type AddToPrintQueueOptions = Omit & { - isCommand?: Queued["isCommand"] | undefined; - }; - - const addToPrintQueue = ( - text: string | Buffer | unknown, - { target, processId, isCommand = false }: AddToPrintQueueOptions, - ): void => { - const _text - = typeof text === "string" || !text?.toString ? text : text.toString(); - - if (processId <= currentProcessId) { - log({ - processId, - text: _text, - target, - isCommand, - }); - } else { - queue.push({ - processId, - text: _text, - target, - isCommand, - }); - } - }; - const dumpFromQueue = (processId: number): void => { - for (const queued of queue) { - if (queued.processId <= processId) { - log(queued); - } - } - queue = []; - }; - const nextProcess = (): void => { - currentProcessId++; - dumpFromQueue(currentProcessId); - }; - - const promises: Promise[] = ( - Array.isArray(commands) ? commands : [ commands ] - ).map( - (command, i) => - new Promise((resolve, reject) => { - try { - if (printCommand !== false) { - addToPrintQueue(command, { - target: "stdout", - processId: i, - isCommand: true, - }); - } - - // TODO use "error" event to print error, and "close" to resolve instead of callback. - // https://nodejs.org/docs/latest-v20.x/api/child_process.html#event-error - // https://nodejs.org/docs/latest-v20.x/api/child_process.html#event-close - - const child = execCallback( - command, - options, - (err, stdout, stderr) => { - if (err) { - reject(err); - return; - } - - resolve({ stdout, stderr, child }); - }, - ); - - if (output !== false) { - child.stdout?.on("data", (data: string | Buffer | unknown): void => - addToPrintQueue(data, { - target: "stdout", - processId: i, - }), - ); - - child.stderr?.on("data", (data: string | Buffer | unknown): void => - addToPrintQueue(data, { - target: "stderr", - processId: i, - }), - ); - } - } catch (err) { - reject(err); - } - }), - ); - - for (const promise of promises) { - returnValues.push(await promise); - nextProcess(); - } - - return Array.isArray(commands) ? returnValues : returnValues[0]; -}; diff --git a/test/cmd.test.ts b/test/cmd.test.ts deleted file mode 100644 index 5556379..0000000 --- a/test/cmd.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { join } from "node:path"; -import { fileURLToPath } from "node:url"; -import { afterEach, describe, expect, test, vi } from "vitest"; -import { cmd } from "../src/nodejs.ts"; -import { deindent } from "../src/universal.ts"; - -const __dirname = fileURLToPath(new URL(".", import.meta.url)); - -describe("Mock tests", () => { - afterEach(() => { - vi.restoreAllMocks(); - }); - - test("cmd", async () => { - let output = ""; - - vi.spyOn(console, "info").mockImplementation((printed) => { - output = output + printed; - return output; - }); - vi.spyOn(console, "error").mockImplementation((printed) => { - output = output + printed; - return output; - }); - - await cmd([ - `bash ${ join(__dirname, "fixtures/cmd/command1.sh") }`, - `bash ${ join(__dirname, "fixtures/cmd/command2.sh") }`, - ]); - - expect(output).toStrictEqual( - deindent(` - >>> [0] bash ${ join(join(__dirname, "fixtures/cmd/command1.sh")) } - - [0] Command 1 started. - [0] This message is printed after three seconds, but it should be shown before the output of command 2. - - >>> [1] bash ${ join(__dirname, "fixtures/cmd/command2.sh") } - - [1] Command 2 executed. - `).trim() + "\n", - ); - }); -}); From c7b703e1e64bbd855069601a289bf9649a0339f1 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 18:07:38 +0900 Subject: [PATCH 23/26] fix: typo in error message Co-Authored-By: Copilot <175728472+Copilot@users.noreply.github.com> --- src/nodejs/load-json.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nodejs/load-json.ts b/src/nodejs/load-json.ts index 77f50ab..28a165a 100644 --- a/src/nodejs/load-json.ts +++ b/src/nodejs/load-json.ts @@ -6,7 +6,7 @@ export const loadJSON = async >( options?: ObjectEncodingOptions, ): Promise => { if (!(await stat(jsonPath)).isFile()) { - throw new Error(`"${ jsonPath }" does not exist of not a regular file.`); + throw new Error(`"${ jsonPath }" does not exist or not a regular file.`); } const jsonString = await readFile(jsonPath, { From 942ac17813683c6772f3749f68c7b782954b88af Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 18:08:29 +0900 Subject: [PATCH 24/26] doc: fix typo in JSDoc Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/universal/sort-objects.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/universal/sort-objects.ts b/src/universal/sort-objects.ts index ac51ece..a1b06de 100644 --- a/src/universal/sort-objects.ts +++ b/src/universal/sort-objects.ts @@ -1,6 +1,6 @@ /** * Sort array of the objects by the keys in the alphabetical order. - * @param objects - Aarray of objects. + * @param objects - Array of objects. * @returns - Sorted array of the objects. */ /* eslint-disable-next-line @typescript-eslint/no-explicit-any -- From 9c342ef25d801093cf4d7ed40cb9f9fd0f96d855 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 16:48:47 +0900 Subject: [PATCH 25/26] doc: change license from MIT to Apache-2.0 --- LICENSE | 7 -- LICENSE.txt | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- package.json | 2 +- 4 files changed, 203 insertions(+), 9 deletions(-) delete mode 100644 LICENSE create mode 100644 LICENSE.txt diff --git a/LICENSE b/LICENSE deleted file mode 100644 index e2ce6f5..0000000 --- a/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright 2020 Jumpei Ogawa (https://phanective.org) - -Permission 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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE 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. diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 8bb6caf..448cce2 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,4 @@ mise build ## License -MIT +Licensed under the [Apache License 2.0](./LICENSE.txt). diff --git a/package.json b/package.json index 80102b7..df1f185 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "url": "git+https://github.com/phanect/utils.git" }, "author": "Jumpei Ogawa (https://phanective.org)", - "license": "MIT", + "license": "Apache-2.0", "type": "module", "main": "./dist/universal.cjs", "module": "./dist/universal.js", From b1dd581b8484784fbd3aa5d91e116e59c4614d95 Mon Sep 17 00:00:00 2001 From: Jumpei Ogawa Date: Sat, 11 Oct 2025 17:46:14 +0900 Subject: [PATCH 26/26] chore: v2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index df1f185..45bf29e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@phanect/utils", - "version": "1.5.0", + "version": "2.0.0", "description": "@phanect's personal utility library for JavaScript & TypeScript", "repository": { "type": "git",