From f553838f9d56ec2f6063c95c65b4e67f61c42fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20Hano=C4=9Flu?= Date: Tue, 10 Feb 2026 13:04:55 +0300 Subject: [PATCH 1/2] fix: Fixed "keepExisting" with "deep" option do not overwrite existing --- package.json | 35 ++---- src/merge.ts | 101 +++++++++--------- support/package.cjs.json | 3 - support/package.esm.json | 3 - support/postbuild.cjs | 31 ++++-- tsconfig-base.json | 7 +- tsconfig-build-cjs.json | 10 -- ...nfig-build-esm.json => tsconfig-build.json | 3 +- tsconfig.json | 4 +- 9 files changed, 89 insertions(+), 108 deletions(-) delete mode 100644 support/package.cjs.json delete mode 100644 support/package.esm.json delete mode 100644 tsconfig-build-cjs.json rename tsconfig-build-esm.json => tsconfig-build.json (77%) diff --git a/package.json b/package.json index df69872..597c481 100644 --- a/package.json +++ b/package.json @@ -32,15 +32,12 @@ }, "scripts": { "compile": "tsc --noEmit", + "prebuild": "npm run clean:build && npm run lint", + "build": "tsc -b tsconfig-build.json", + "postbuild": "node ./support/postbuild.cjs && rimraf build/*.tsbuildinfo", "clean": "npm run clean:src && npm run clean:dist", - "clean:dist": "rimraf build coverage", + "clean:build": "rimraf build *.tsbuildinfo", "clean:src": "ts-cleanup -s src --all | ts-cleanup -s test", - "prebuild": "npm run clean:dist && npm run lint", - "build": "npm run build:cjs && npm run build:esm", - "build:cjs": "tsc -b tsconfig-build-cjs.json && cp support/package.cjs.json ./build/cjs/package.json", - "build:esm": "tsc -b tsconfig-build-esm.json && cp support/package.esm.json ./build/esm/package.json", - "postbuild": "npm run postbuild:copyfiles && node ./support/postbuild.cjs", - "postbuild:copyfiles": "cp LICENSE README.md CHANGELOG.md ./build", "lint": "eslint . --max-warnings=0", "lint:fix": "eslint . --max-warnings=0 --fix", "format": "prettier . --write --log-level=warn", @@ -52,23 +49,15 @@ "version": "auto-changelog -p --starting-version v4.0.0 && git add CHANGELOG.md" }, "type": "module", + "module": "./index.js", + "types": "./index.d.ts", "exports": { ".": { - "import": { - "types": "./types/index.d.ts", - "default": "./esm/index.js" - }, - "require": { - "types": "./types/index.d.cts", - "default": "./cjs/index.js" - }, - "default": "./esm/index.js" + "types": "./index.d.ts", + "default": "./index.js" }, "./package.json": "./package.json" }, - "main": "./cjs/index.js", - "module": "./esm/index.js", - "types": "./types/index.d.ts", "contributors": [ "Eray Hanoglu " ], @@ -79,14 +68,6 @@ "engines": { "node": ">= 16.0" }, - "files": [ - "cjs/", - "esm/", - "types/", - "LICENSE", - "README.md", - "CHANGELOG.md" - ], "keywords": [ "object", "util", diff --git a/src/merge.ts b/src/merge.ts index b194b28..ebe2c41 100644 --- a/src/merge.ts +++ b/src/merge.ts @@ -110,8 +110,24 @@ export function merge( ) { continue; } + _goDeep = !!( + deep && + typeof srcVal === 'object' && + (!isBuiltIn(srcVal) || Array.isArray(srcVal)) + ); + if (_goDeep) { + if (deepFn) + _goDeep = deepFn(srcVal, { + key, + source, + target, + path: parentPath + (parentPath ? '.' : '') + String(key), + }); + else + _goDeep = deepFull || isPlainObject(srcVal) || Array.isArray(srcVal); + } - if (keepExisting && hasOwnProperty.call(target, key)) { + if (!_goDeep && keepExisting && hasOwnProperty.call(target, key)) { if (!keepExistingFn) continue; if ( keepExistingFn(srcVal, { @@ -145,59 +161,42 @@ export function merge( continue; } - if ( - deep && - typeof srcVal === 'object' && - (!isBuiltIn(srcVal) || Array.isArray(srcVal)) - ) { - _goDeep = - (deepFn && - deepFn(srcVal, { - key, - source, - target, - path: parentPath + (parentPath ? '.' : '') + String(key), - })) || - (!deepFn && - (deepFull || isPlainObject(srcVal) || Array.isArray(srcVal))); - if (_goDeep) { - /** Array */ - if (Array.isArray(srcVal)) { - if ( - Array.isArray(target[key]) && - (mergeArrays || - mergeArraysFn?.(srcVal, { - key, - source, - target, - path: parentPath + (parentPath ? '.' : '') + String(key), - })) - ) { - target[key] = _arrayClone( - target[key], - parentPath + (parentPath ? '.' : '') + String(key), - ); - } else target[key] = []; - - target[key].push( - ..._arrayClone( - srcVal, - parentPath + (parentPath ? '.' : '') + String(key), - ), - ); - if (mergeArraysUnique) - target[key] = Array.from(new Set(target[key])); - continue; - } else { - /** Object */ - if (!isObject(target[key])) target[key] = {}; - _merge( + if (_goDeep) { + /** Array */ + if (Array.isArray(srcVal)) { + if ( + Array.isArray(target[key]) && + (mergeArrays || + mergeArraysFn?.(srcVal, { + key, + source, + target, + path: parentPath + (parentPath ? '.' : '') + String(key), + })) + ) { + target[key] = _arrayClone( target[key], - srcVal, parentPath + (parentPath ? '.' : '') + String(key), ); - continue; - } + } else target[key] = []; + + target[key].push( + ..._arrayClone( + srcVal, + parentPath + (parentPath ? '.' : '') + String(key), + ), + ); + if (mergeArraysUnique) target[key] = Array.from(new Set(target[key])); + continue; + } else { + /** Object */ + if (!isObject(target[key])) target[key] = {}; + _merge( + target[key], + srcVal, + parentPath + (parentPath ? '.' : '') + String(key), + ); + continue; } } diff --git a/support/package.cjs.json b/support/package.cjs.json deleted file mode 100644 index 5bbefff..0000000 --- a/support/package.cjs.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "commonjs" -} diff --git a/support/package.esm.json b/support/package.esm.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/support/package.esm.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/support/postbuild.cjs b/support/postbuild.cjs index 6c842a1..86803b2 100644 --- a/support/postbuild.cjs +++ b/support/postbuild.cjs @@ -1,23 +1,38 @@ const fs = require('node:fs'); const path = require('node:path'); -function clearPackageJson() { - const targetPath = path.resolve(__dirname, '../build'); - +function postBuild() { + const projectRoot = process.cwd(); const json = JSON.parse( - fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf-8'), + fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf-8'), ); + + const buildDir = path.join(projectRoot, 'build'); + if (!fs.existsSync(buildDir)) throw new Error('Build directory not found'); + + json.type = 'module'; delete json.private; delete json.scripts; delete json.devDependencies; + fs.writeFileSync( - path.resolve(targetPath, 'package.json'), + path.resolve(buildDir, 'package.json'), JSON.stringify(json, undefined, 2), + 'utf-8', ); fs.copyFileSync( - path.resolve(targetPath, './types/index.d.ts'), - path.resolve(targetPath, './types/index.d.cts'), + path.resolve('./README.md'), + path.resolve(buildDir, 'README.md'), ); + fs.copyFileSync(path.resolve('./LICENSE'), path.resolve(buildDir, 'LICENSE')); + + /** Update version */ + const constantsFile = path.resolve(buildDir, 'constants.js'); + if (fs.existsSync(constantsFile)) { + let content = fs.readFileSync(constantsFile, 'utf8'); + content = content.replace(`version = '1'`, `version = '${json.version}'`); + fs.writeFileSync(constantsFile, content, 'utf-8'); + } } -clearPackageJson(); +postBuild(); diff --git a/tsconfig-base.json b/tsconfig-base.json index f4b0bf1..3fca16e 100644 --- a/tsconfig-base.json +++ b/tsconfig-base.json @@ -2,6 +2,11 @@ "extends": "@panates/tsconfig/node.json", "compilerOptions": { "types": ["node"], - "esModuleInterop": true + "sourceMap": true, + "moduleResolution": "nodenext", + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "module": "NodeNext", + "target": "ESNext" } } diff --git a/tsconfig-build-cjs.json b/tsconfig-build-cjs.json deleted file mode 100644 index 2b986dd..0000000 --- a/tsconfig-build-cjs.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": ["./tsconfig-base.json", "@panates/tsconfig/build.json"], - "compilerOptions": { - "module": "CommonJS", - "moduleResolution": "Node", - "declaration": false, - "outDir": "build/cjs" - }, - "include": ["src"] -} diff --git a/tsconfig-build-esm.json b/tsconfig-build.json similarity index 77% rename from tsconfig-build-esm.json rename to tsconfig-build.json index b79b387..6f3a42c 100644 --- a/tsconfig-build-esm.json +++ b/tsconfig-build.json @@ -4,8 +4,7 @@ "module": "NodeNext", "moduleResolution": "NodeNext", "declaration": true, - "outDir": "build/esm", - "declarationDir": "build/types" + "outDir": "build", }, "include": ["src"] } diff --git a/tsconfig.json b/tsconfig.json index 3d419a3..8499a82 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,7 @@ { "extends": "./tsconfig-base.json", "compilerOptions": { - "types": ["node"], - "module": "NodeNext", - "moduleResolution": "NodeNext" + "types": ["node"] }, "include": ["src"], "exclude": ["node_modules", "build"] From 991ccb2ef8460bc67f72ddaae8d84458fc62d760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20Hano=C4=9Flu?= Date: Tue, 10 Feb 2026 13:05:02 +0300 Subject: [PATCH 2/2] 2.1.1 --- CHANGELOG.md | 6 +++--- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8315922..f3d5d1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## Changelog -### [v2.1.0](https://github.com/panates/jsopen-objects/compare/v2.0.2...v2.1.0) - +### [v2.1.1](https://github.com/panates/jsopen-objects/compare/v2.1.0...v2.1.1) - -#### 🚀 New Features +#### 🪲 Fixes -- feat: Added `updateErrorMessage` helper method @Eray Hanoğlu +- fix: Fixed "keepExisting" with "deep" option do not overwrite existing @Eray Hanoğlu diff --git a/package-lock.json b/package-lock.json index ae5a78d..c485b8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@jsopen/objects", - "version": "2.1.0", + "version": "2.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@jsopen/objects", - "version": "2.1.0", + "version": "2.1.1", "license": "MIT", "dependencies": { "tslib": "^2.8.1" diff --git a/package.json b/package.json index 597c481..07d7458 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@jsopen/objects", "description": "Helper utilities for working with JavaScript objects and arrays", - "version": "2.1.0", + "version": "2.1.1", "author": "Panates", "license": "MIT", "private": true,