New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

collect-require

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

collect-require - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

test/data/wrapper-script-sample.js

2

package.json
{
"name": "collect-require",
"version": "1.3.0",
"version": "1.4.0",
"description": "collect require-js based codebase into a singel js file ",

@@ -5,0 +5,0 @@ "main": "src/collect-require.js",

@@ -6,3 +6,2 @@ require("./require-template");

apiNamePlaceHolder = "SCRIPT_COLLECTOR_API_NAME",
globalHookPlaceHolder = "GLOBAL_HOOK",
scriptMappingsPlaceholder = "/*!<SCRIPT-MAPPINGS>!*/";

@@ -21,14 +20,13 @@

save: function(options){
var script = wrapperScript.replace(scriptMappingsPlaceholder, scriptMapping)
var rawScript = wrapperScript.replace(scriptMappingsPlaceholder, scriptMapping)
.replace("/*!<SCRIPT-MAIN>!*/", options.main.replace(".js", ""))
.replace(apiNamePlaceHolder, options.apiName);
if(options.buildNashorn){
fs.writeFileSync(options.buildNashorn, script.replace(globalHookPlaceHolder, "GLOBAL"));
}
if(options.buildBrowser){
fs.writeFileSync(options.buildBrowser, script.replace(globalHookPlaceHolder, "window"));
}
var script = options.wrapper ? options.wrapper.replace("/* COLLECT-REQUIRE-SCRIPT */", rawScript) : rawScript;
return fs.writeFileSync(
options.path,
script
);
}

@@ -35,0 +33,0 @@ };

@@ -22,3 +22,42 @@ var

};
/****************** Begin Nashorn Support *******************/
GLOBAL_HOOK.SCRIPT_COLLECTOR_API_NAME = standalone[main]();
var NASHORN = {
packNumber : function(number){
var isInt = number % 1 === 0;
return isInt ? new java.lang.Integer(number) : number;
},
packArray : function(array){
var list = new java.util.ArrayList();
for(var i = 0 ; i < array.length; i++){
list.add(array[i]);
}
return list;
},
pack : function(json){
for(var field in json){
var value = json[field],
isArray = value instanceof Array,
isNumber = (typeof value == "number"),
isSubtree = (typeof value == "object") && !(value instanceof Array);
if(isSubtree){
json[field] = NASHORN.pack(json[field]);
}
if(isArray){
json[field] = json[field].map(function(field){
return NASHORN.pack(field);
});
json[field] = NASHORN.packArray(json[field]);
}
if(isNumber){
json[field] = NASHORN.packNumber(json[field]);
}
}
return json;
}
};
/****************** End Nashorn Support *******************/
var collectRequire = function(){
return standalone[main]();
};
var expect = require('chai').expect,
helper = require("../test-helper")
collector = require("../../src/collect-require");
collector = require("../../src/collect-require");

@@ -26,5 +26,5 @@ describe('Create Standalone Script', function() {

standalone.save({
buildNashorn : path,
main : "three/three.five/script-three.five" ,
apiName : "Jeyson",
path : path,
main : "three/three.five/script-three.five" ,
apiName : "Jeyson",
});

@@ -35,3 +35,3 @@

it('should create standalone Nashorn script', function () {
it('should create standalone script file', function () {
var path = helper.aWritableFilePath(),

@@ -41,3 +41,3 @@ standalone = collector.collect(helper.codebasePath);

standalone.save({
buildNashorn : path,
path : path,
main : "index.js" ,

@@ -47,25 +47,20 @@ apiName : "Jeyson",

helper.evalScript(path);
expect(Jeyson.get()).to.equal("from script three");
expect(helper.evalScript(path).get()).to.equal("from script three");
});
it('should create standalone Browser script', function () {
it('should allow specifying entry file', function () {
var path = helper.aWritableFilePath(),
standalone = collector.collect(helper.codebasePath);
standalone.save({
buildBrowser : path,
main : "index.js" ,
apiName : "Jeyson",
path : path,
main : "two/script-two.js",
apiName : "ScriptTwo",
});
GLOBAL.window = GLOBAL;
helper.evalScript(path);
expect(Jeyson.get()).to.equal("from script three");
expect(helper.evalScript(path)).to.equal("from script three");
});
it('should allow specifying entry file', function () {
it('shold support wrapper over script', function () {
var path = helper.aWritableFilePath(),

@@ -76,12 +71,15 @@ standalone = collector.collect(helper.codebasePath);

standalone.save({
buildNashorn : path,
main : "two/script-two.js",
apiName : "ScriptTwo",
path : helper.aWritableFilePath(),
main : "two/script-two.js",
apiName : "ScriptTwo",
wrapper : helper.wrapper,
});
helper.evalScript(path);
var loaded = helper.getScript(path);
var collected = eval(loaded)("from outside");
expect(ScriptTwo).to.equal("from script three");
expect(collected.args).to.equal("from outside");
expect(collected.run()).to.equal("from script three");
});
});

@@ -14,6 +14,12 @@ var fs = require("fs"),

scriptThreeFiveContent: readFile("test/data/sample-codebase/three/three.five/script-three.five.js"),
wrapper: fs.readFileSync("test/data/wrapper-script-sample.js").toString('utf8'),
aWritableFilePath : function(){return "test/data/output/script.js";},
getScript : function(path){
return fs.readFileSync(path).toString('utf8');
},
evalScript : function(path){
return eval(fs.readFileSync(path).toString('utf8'));
var script = fs.readFileSync(path).toString('utf8');
return eval(script + "collectRequire();");
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc