Comparing version 0.1.6 to 0.1.7
var assert = require("assert"); | ||
var parse = require("./parser.js").parse; | ||
var parse; | ||
// TODO Cache this. | ||
function compile(code) { | ||
function compile(code, options) { | ||
if (typeof parse !== "function") { | ||
parse = require("./parser.js").parse; | ||
} | ||
var declarations = parse(code); | ||
var identical = declarations.length === 0; | ||
if (options && typeof options === "object") { | ||
options.identical = identical; | ||
} | ||
if (identical) { | ||
return code; | ||
} | ||
return replace(code, declarations, function (decl) { | ||
@@ -8,0 +21,0 @@ return typeHandlers[decl.type](code, decl); |
@@ -1,8 +0,4 @@ | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var hasOwn = Object.prototype.hasOwnProperty; | ||
var compile = require("../lib/compiler.js").compile; | ||
var compile = require("./caching-compiler.js").compile; | ||
var Module = require("./runtime.js").Module; | ||
var Mp = Module.prototype; | ||
var isEnabledCache = Object.create(null); | ||
@@ -18,5 +14,3 @@ // Override Module.prototype._compile to compile any code that will be | ||
// package that contains the file. | ||
isEnabled(filename) | ||
? compile(content) | ||
: content, | ||
compile(content, filename), | ||
filename | ||
@@ -26,65 +20,1 @@ ); | ||
} | ||
function isEnabled(filename) { | ||
if (hasOwn.call(isEnabledCache, filename)) { | ||
return isEnabledCache[filename]; | ||
} | ||
try { | ||
var stat = fs.statSync(filename); | ||
} catch (e) { | ||
return isEnabledCache[filename] = false; | ||
} | ||
if (stat.isDirectory()) { | ||
if (path.basename(filename) === "node_modules") { | ||
return isEnabledCache[filename] = false; | ||
} | ||
var pkg = readPkgInfo(filename); | ||
if (pkg) { | ||
if (hasOwn.call(pkg, "reify")) { | ||
// An explicit "reify": false property in package.json disables | ||
// reification even if "reify" is listed as a dependency. | ||
return isEnabledCache[filename] = !! pkg.reify; | ||
} | ||
function check(name) { | ||
return typeof pkg[name] === "object" && | ||
hasOwn.call(pkg[name], "reify"); | ||
} | ||
return isEnabledCache[filename] = | ||
check("dependencies") || | ||
check("peerDependencies") || | ||
// Use case: a package.json file may have "reify" in its | ||
// "devDependencies" section because it expects another package or | ||
// application to enable reification in production, but needs its | ||
// own copy of the "reify" package during development. Disabling | ||
// reification in production when it was enabled in development | ||
// would be dangerous in this case. | ||
check("devDependencies"); | ||
} | ||
} | ||
var parentDir = path.dirname(filename); | ||
return isEnabledCache[filename] = | ||
parentDir !== filename && | ||
isEnabled(parentDir); | ||
} | ||
function readPkgInfo(dir) { | ||
try { | ||
return JSON.parse(fs.readFileSync( | ||
path.join(dir, "package.json") | ||
)); | ||
} catch (e) { | ||
if (! (e instanceof SyntaxError || | ||
e.code === "ENOENT")) { | ||
throw e; | ||
} | ||
} | ||
return null; | ||
} |
{ | ||
"name": "reify", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"main": "node/index.js", | ||
@@ -27,5 +27,2 @@ "browser": "lib/empty.js", | ||
}, | ||
"reify": { | ||
"modules": true | ||
}, | ||
"scripts": { | ||
@@ -32,0 +29,0 @@ "test": "test/run.sh" |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 2 instances in 1 package
38262
3
19
724
1