Skip to content

Commit

Permalink
fix: inline just-extend to prevent build failures
Browse files Browse the repository at this point in the history
Fixes: #12
  • Loading branch information
simonsmith committed Oct 18, 2023
1 parent 7eb876d commit c498800
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 11 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
"dependencies": {
"@types/jest-image-snapshot": "^6.1.0",
"chalk": "^4.1.2",
"jest-image-snapshot": "^6.1.0",
"just-extend": "^6.2.0"
"jest-image-snapshot": "^6.1.0"
},
"volta": {
"node": "18.16.0",
Expand Down
2 changes: 1 addition & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import extend from 'just-extend'
import extend from './util/extend'
import {MATCH, RECORD, RM} from './constants'
import type {
CypressImageSnapshotOptions,
Expand Down
3 changes: 3 additions & 0 deletions src/util/extend.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare function extend(obj1: object, ...objn: any[]): object
declare function extend(deep: boolean, obj1: object, ...objn: any[]): object
export default extend
77 changes: 77 additions & 0 deletions src/util/extend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* eslint-disable no-var, prefer-rest-params */
// https://github.com/angus-c/just/blob/master/packages/object-extend/index.mjs
var objectExtend = extend

/*
var obj = {a: 3, b: 5};
extend(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
obj; // {a: 4, b: 5, c: 8}
var obj = {a: 3, b: 5};
extend({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
obj; // {a: 3, b: 5}
var arr = [1, 2, 3];
var obj = {a: 3, b: 5};
extend(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
arr.push(4);
obj; // {a: 3, b: 5, c: [1, 2, 3, 4]}
var arr = [1, 2, 3];
var obj = {a: 3, b: 5};
extend(true, obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
arr.push(4);
obj; // {a: 3, b: 5, c: [1, 2, 3]}
extend({a: 4, b: 5}); // {a: 4, b: 5}
extend({a: 4, b: 5}, 3); {a: 4, b: 5}
extend({a: 4, b: 5}, true); {a: 4, b: 5}
extend('hello', {a: 4, b: 5}); // throws
extend(3, {a: 4, b: 5}); // throws
*/

function extend(/* [deep], obj1, obj2, [objn] */) {
var args = [].slice.call(arguments)
var deep = false
if (typeof args[0] == 'boolean') {
deep = args.shift()
}
var result = args[0]
if (isUnextendable(result)) {
throw new Error('extendee must be an object')
}
var extenders = args.slice(1)
var len = extenders.length
for (var i = 0; i < len; i++) {
var extender = extenders[i]
for (var key in extender) {
if (Object.prototype.hasOwnProperty.call(extender, key)) {
var value = extender[key]
if (deep && isCloneable(value)) {
var base = Array.isArray(value) ? [] : {}
result[key] = extend(
true,
Object.prototype.hasOwnProperty.call(result, key) &&
!isUnextendable(result[key])
? result[key]
: base,
value,
)
} else {
result[key] = value
}
}
}
}
return result
}

function isCloneable(obj) {
return Array.isArray(obj) || {}.toString.call(obj) == '[object Object]'
}

function isUnextendable(val) {
return !val || (typeof val != 'object' && typeof val != 'function')
}

export {objectExtend as default}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"strict": true,
"skipLibCheck": true,
"declaration": true,
Expand Down
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,6 @@ __metadata:
eslint-plugin-prettier: ^4.2.1
http-server: ^14.1.1
jest-image-snapshot: ^6.1.0
just-extend: ^6.2.0
npm-run-all: ^4.1.5
prettier: ^2.8.8
replace-json-property: ^1.9.0
Expand Down Expand Up @@ -4975,13 +4974,6 @@ __metadata:
languageName: node
linkType: hard

"just-extend@npm:^6.2.0":
version: 6.2.0
resolution: "just-extend@npm:6.2.0"
checksum: 022024d6f687c807963b97a24728a378799f7e4af7357d1c1f90dedb402943d5c12be99a5136654bed8362c37a358b1793feaad3366896f239a44e17c5032d86
languageName: node
linkType: hard

"kind-of@npm:^6.0.3":
version: 6.0.3
resolution: "kind-of@npm:6.0.3"
Expand Down

0 comments on commit c498800

Please sign in to comment.