@contrast/require-hook
Advanced tools
Comparing version 4.2.0 to 5.0.0
@@ -69,3 +69,3 @@ // @ts-check | ||
if (typeof rv == 'function' && rv != xport) { | ||
// @ts-expect-error we've validated this.seen.get is valid in `#filter`. | ||
// @ts-expect-error | ||
this.seen.set(rv, this.seen.get(xport)); | ||
@@ -72,0 +72,0 @@ } |
@@ -12,3 +12,3 @@ /** | ||
/** | ||
* ponyfill for `module.isBuiltin` prior to Node v16.17.0 | ||
* polyfill for `module.isBuiltin` prior to Node v16.17.0 | ||
* see: https://nodejs.org/docs/latest-v16.x/api/module.html#moduleisbuiltinmodulename | ||
@@ -15,0 +15,0 @@ * @param {string} name |
@@ -30,3 +30,3 @@ // @ts-check | ||
/** | ||
* ponyfill for `module.isBuiltin` prior to Node v16.17.0 | ||
* polyfill for `module.isBuiltin` prior to Node v16.17.0 | ||
* see: https://nodejs.org/docs/latest-v16.x/api/module.html#moduleisbuiltinmodulename | ||
@@ -37,4 +37,7 @@ * @param {string} name | ||
function isBuiltin(name) { | ||
if (name.startsWith('node:')) { | ||
name = name.substring(5); | ||
} | ||
// @ts-expect-error we've set the node version to 14 before this was added. | ||
return Module.isBuiltin?.(name) ?? (Module.builtinModules.indexOf(name) >= 0 || (name.startsWith('node:') && Module.builtinModules.indexOf(name.substring(5)) >= 0)); | ||
return Module.isBuiltin?.(name) ?? Module.builtinModules.includes(name); | ||
} | ||
@@ -41,0 +44,0 @@ module.exports = { |
@@ -5,3 +5,5 @@ // @ts-check | ||
const path = require('node:path'); | ||
const parentPackageJson = require('parent-package-json'); | ||
const fs = require('fs'); | ||
// @ts-expect-error | ||
const { findPackageJsonSync } = require('@contrast/find-package-json'); | ||
const { isBuiltin } = require('./helpers'); | ||
@@ -35,4 +37,5 @@ /** | ||
} | ||
const manifest = parentPackageJson(filename); | ||
if (!manifest) { | ||
const resolved = path.dirname(filename); | ||
const pdj = findPackageJsonSync({ cwd: resolved }); | ||
if (!pdj) { | ||
logger?.error('unable to find package.json for %s', filename); | ||
@@ -42,7 +45,8 @@ return null; | ||
try { | ||
const { name, version, main } = manifest.parse(); | ||
const json = fs.readFileSync(pdj, 'utf8'); | ||
const { name, version, main } = JSON.parse(json); | ||
return { | ||
name, | ||
version, | ||
packageDir: path.dirname(manifest.path), | ||
packageDir: path.dirname(pdj), | ||
file: filename, | ||
@@ -53,3 +57,3 @@ main, | ||
catch (err) { | ||
logger?.error({ err }, 'unable to parse %s', manifest.path); | ||
logger?.error({ err }, 'unable to parse %s', pdj); | ||
return null; | ||
@@ -56,0 +60,0 @@ } |
{ | ||
"name": "@contrast/require-hook", | ||
"version": "4.2.0", | ||
"version": "5.0.0", | ||
"description": "Post hooks for Module.prototype.require", | ||
@@ -22,8 +22,6 @@ "license": "MIT", | ||
"preversion": "npm test", | ||
"postversion": "npm publish", | ||
"postpublish": "git push && git push --tags", | ||
"prepare": "husky install && npm run build" | ||
}, | ||
"dependencies": { | ||
"parent-package-json": "^2.0.1", | ||
"@contrast/find-package-json": "^1.0.0", | ||
"semver": "^7.5.4" | ||
@@ -39,3 +37,2 @@ }, | ||
"@types/node": "^14.18.63", | ||
"@types/parent-package-json": "^2.0.3", | ||
"@types/semver": "^7.5.3", | ||
@@ -45,2 +42,3 @@ "@types/sinon": "^10.0.18", | ||
"chai": "^4.3.10", | ||
"chai-as-promised": "^7.1.1", | ||
"express": "^4.18.2", | ||
@@ -47,0 +45,0 @@ "express-4.17.3": "npm:express@4.17.3", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54090
905
2
+ Added@contrast/find-package-json@1.2.0(transitive)
- Removedparent-package-json@^2.0.1
- Removedparent-package-json@2.0.1(transitive)