Skip to content

Commit

Permalink
[#1] Support NPM Scope
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Nov 8, 2023
1 parent b2b29d7 commit b83f6a0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.nyc_output/
.idea/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Build Status](https://travis-ci.org/othiym23/shimmer.svg)](https://travis-ci.org/othiym23/shimmer)
[![Coverage Status](https://coveralls.io/repos/othiym23/shimmer/badge.svg?branch=master)](https://coveralls.io/r/othiym23/shimmer?branch=master)
## Changes
https://github.com/othiym23/shimmer.git differs in that it prevents duplicates monkeypatch.

## Safer monkeypatching for Node.js

Expand Down Expand Up @@ -29,7 +29,7 @@ not because it seems like fun.

### API

All monkeypatched functions have an attribute, `__wrapped`, set to true on
All monkeypatched functions have an attribute, `Symbol('__wrapped')`, set to true on
them.

#### shimmer(options)
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const isWrapped = Symbol('__wrapped')

function isFunction (funktion) {
return typeof funktion === 'function'
}
Expand Down Expand Up @@ -44,14 +46,18 @@ function wrap (nodule, name, wrapper) {
return
}

if (nodule[name][isWrapped]) {
return
}

var original = nodule[name]
var wrapped = wrapper(original, name)

defineProperty(wrapped, '__original', original)
defineProperty(wrapped, '__unwrap', function () {
if (nodule[name] === wrapped) defineProperty(nodule, name, original)
})
defineProperty(wrapped, '__wrapped', true)
defineProperty(wrapped, isWrapped, true)

defineProperty(nodule, name, wrapped)
return wrapped
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "shimmer",
"name": "@pinpoint-apm/shimmer",
"version": "1.2.1",
"description": "Safe(r) monkeypatching for JavaScript.",
"main": "index.js",
Expand All @@ -8,7 +8,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/othiym23/shimmer.git"
"url": "https://github.com/pinpoint-apm/shimmer.git"
},
"keywords": [
"monkeypatch",
Expand All @@ -20,6 +20,9 @@
],
"author": "Forrest L Norvell <[email protected]>",
"license": "BSD-2-Clause",
"publishConfig": {
"access": "public"
},
"devDependencies": {
"sinon": "^7.2.2",
"standard": "^12.0.1",
Expand Down

0 comments on commit b83f6a0

Please sign in to comment.