module-keys
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -37,2 +37,3 @@ /** | ||
const rootParent = path.join(root, '..'); | ||
/* istanbul ignore next */ | ||
return path.basename(rootParent) === 'node_modules' ? | ||
@@ -111,3 +112,3 @@ path.join(rootParent, '..') : | ||
Program: { | ||
enter(nodePath, state) { | ||
enter(nodePath) { | ||
// until proven otherwise | ||
@@ -117,11 +118,9 @@ isCommonJsModule = true; | ||
sawEsPolyfill = false; | ||
const { filename } = state.file.opts; | ||
if (path.join(__dirname, '..') === path.dirname(filename)) { | ||
const basename = path.basename(filename); | ||
if (basename === 'index.js') { | ||
// Don't polyfill the index file. It bootstraps itself | ||
sawCjsPolyfill = true; | ||
} else if (basename === 'index.mjs') { | ||
sawEsPolyfill = true; | ||
} | ||
// Recognize a comment directive so that applying this plugin to all | ||
// dependencies does not prevent ../index.js from bootstrapping itself. | ||
if (nodePath.parent.comments.some( | ||
({ value }) => value.indexOf('!module-keys-babel-skip') >= 0)) { | ||
sawCjsPolyfill = true; | ||
sawEsPolyfill = true; | ||
} | ||
@@ -128,0 +127,0 @@ }, |
18
index.js
@@ -18,2 +18,3 @@ /** | ||
// !module-keys-babel-skip -- Do not polyfill this file | ||
'use strict'; | ||
@@ -84,2 +85,3 @@ | ||
const proto = getPrototypeOf(collection); | ||
/* istanbul ignore if */ | ||
if (!proto || getPrototypeOf(proto) !== ObjectPrototype) { | ||
@@ -155,2 +157,6 @@ // The loop below is insufficient. | ||
// Allow a private key to be used in lieu of the pair. | ||
defineProperty( | ||
privateKey, 'publicKey', { value: publicKey, enumerable: true }); | ||
// We attach a module identifier to the public key to enable | ||
@@ -289,8 +295,10 @@ // whitelisting based on strings in a configuration without having | ||
of Object.entries(Object.getOwnPropertyDescriptors(module))) { | ||
if (descriptor.configurable) { | ||
delete module[propertyName]; | ||
descriptor.writable = propertyName === 'loaded'; | ||
descriptor.configurable = false; | ||
defineProperty(module, propertyName, descriptor); | ||
/* istanbul ignore if */ | ||
if (!descriptor.configurable) { | ||
continue; | ||
} | ||
delete module[propertyName]; | ||
descriptor.writable = propertyName === 'loaded'; | ||
descriptor.configurable = false; | ||
defineProperty(module, propertyName, descriptor); | ||
} |
{ | ||
"name": "module-keys", | ||
"description": "Module identity as a basis for privilege separation for ESM & CommonJS modules", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "design-patterns", |
@@ -115,4 +115,4 @@ # Module Keys | ||
Boxes are opaque values, and the contained value can only be accessed by passing | ||
them to a `.unbox` which is described below. | ||
Boxes are opaque values, and the only way to access the contained value is to use | ||
an `.unbox` method as described below. | ||
@@ -201,2 +201,6 @@ ```js | ||
Each private key refers to its corresponding public key via its | ||
`publicKey` property, so to pass a key pair, it is sufficient to pass | ||
the private key. Public keys do not refer to private keys. | ||
**Warning**: Do not export your private keys as that may allow other | ||
@@ -203,0 +207,0 @@ code to impersonate you. If you need to provide your private key to a |
Sorry, the diff of this file is not supported yet
54669
958
255