module-keys
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -141,3 +141,3 @@ /** | ||
if (isCommonJsModule) { | ||
// require('module-keys/cjs').polyfill(module, require, 'path'); | ||
// require('module-keys/cjs').polyfill(module, require); | ||
polyfills.push( | ||
@@ -144,0 +144,0 @@ t.expressionStatement( |
@@ -36,3 +36,3 @@ /** | ||
const { sep } = require('path'); | ||
const { makeModuleKeys, publicKeySymbol } = require('../index.js'); | ||
const { makeModuleKeys, publicKeySymbol, keysSymbol } = require('../index.js'); | ||
@@ -51,4 +51,9 @@ const sepGlobalPattern = sep === '\\' ? /\\/g : new RegExp(`[${ sep }]`, 'g'); | ||
function polyfill(module, require) { | ||
if (apply(hasOwnProperty, require, [ 'keys' ])) { | ||
return; | ||
const hasKeysProp = apply(hasOwnProperty, require, [ 'keys' ]); | ||
if (hasKeysProp) { | ||
const oldKeys = require.keys; | ||
if (oldKeys && typeof oldKeys.publicKey === 'function' && | ||
typeof oldKeys.isPublicKey === 'function') { | ||
return; | ||
} | ||
} | ||
@@ -62,4 +67,9 @@ let moduleIdentifier = `${ module.filename }`; | ||
} | ||
const keysObj = makeModuleKeys(moduleIdentifier); | ||
require.keys = keysObj; | ||
if (!hasKeysProp) { | ||
require.keys = keysObj; | ||
} | ||
require[keysSymbol] = keysObj; | ||
const { publicKey } = keysObj; | ||
@@ -66,0 +76,0 @@ // Export the public key. |
@@ -124,2 +124,7 @@ /** | ||
/** | ||
* Symbol used to attach keys to CommonJS require. | ||
*/ | ||
const keysSymbol = Symbol('keys'); | ||
/** An opaque token used to represent a boxed value in transit. */ | ||
@@ -279,2 +284,3 @@ class Box { | ||
publicKeySymbol: { value: publicKeySymbol, enumerable: true }, | ||
keysSymbol: { value: keysSymbol, enumerable: true }, | ||
@@ -281,0 +287,0 @@ // The public key for this module. Exported for consistency. |
{ | ||
"name": "module-keys", | ||
"description": "Module identity as a basis for privilege separation for ESM & CommonJS modules", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "design-patterns", |
Sorry, the diff of this file is not supported yet
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
55978
1000
0