Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gluejs

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gluejs - npm Package Compare versions

Comparing version 2.3.3 to 2.3.4

bin/usage-amd.txt

314

bin/get.js

@@ -7,13 +7,13 @@ #!/usr/bin/env node

Minilog = require('minilog'),
DetectiveList = require('../lib/detective-list.js'),
AmdList = require('../lib/amd-list.js'),
amdetective = require('amdetective'),
amdresolve = require('amd-resolve'),
SortDependencies = require('../lib/sort-dependencies.js'),
Cache = require('minitask').Cache;
AmdList = require('../lib/list/amd.js'),
loadAMDConfig = require('../lib/runner/amd/load-config.js'),
runner = require('../lib/runner/amd'),
Cache = require('minitask').Cache,
nodeResolve = require('resolve');
var opts = require('optimist')
var optimist = require('optimist')
.usage('Usage: $0 --include <file/dir ...>')
.options({
'amd': { },
'cache': { default: true },
'include': { },

@@ -23,3 +23,3 @@ 'main': { },

.boolean('amd'),
argv = opts.parse(process.argv);
argv = optimist.parse(process.argv);

@@ -30,2 +30,4 @@ if(!argv['include']) {

console.log(' --amd');
console.log(' --config');
console.log(' --vendor');
console.log(' --main <file>');

@@ -38,103 +40,81 @@ process.exit(1);

opts = {
'cache-method': 'stat',
'cache-path': os.tmpDir() + '/gluejs-' + new Date().getTime()
};
var homePath = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
homePath = (typeof homePath === 'string' ? path.normalize(homePath) : process.cwd());
// determine main
var main = argv.main || Array.isArray(argv.include) ? argv.include[0] : argv.include,
basepath = path.dirname(main);
function loadAMDConfig(filepath) {
// the config specification for RJS is painful to parse as it's not a JSON file
// but rather a JS file that defines as specifically named variable
var sandbox = {};
require('vm').runInNewContext(
fs.readFileSync(filepath).toString(), sandbox);
return sandbox.require;
if(!argv['cache-path']) {
argv['cache-path'] = homePath + path.sep + '.gluejs-cache' + path.sep;
}
if(argv.amd) {
opts.amdresolve = loadAMDConfig(argv.config);
// if the cache is disabled, then use a temp path
if(!argv.cache) {
argv['cache-path'] = os.tmpDir() + '/gluejs-' + new Date().getTime();
}
if(argv.amd && main) {
// baseDir is required for AMD
opts.amdresolve.baseDir = path.dirname(main);
var opts = {
'cache-method': argv['cache-method'] || 'stat',
'cache-path': argv['cache-path']
};
if(!Array.isArray(argv.include)) {
argv.include = [ argv.include ];
}
var list = (argv.amd ? new AmdList(opts) : new DetectiveList(opts));
// determine main
var main = argv.main || argv.include[0],
basepath = path.resolve(process.cwd(), argv.basepath) || path.dirname(main);
var cache = Cache.instance({
method: opts['cache-method'],
path: opts['cache-path']
// resolve paths relative to process.cwd
['list-files', 'out', 'vendor-base'].forEach(function(key) {
if(argv[key]) {
argv[key] = path.resolve(process.cwd(), argv[key]);
}
});
cache.begin();
function lookupDeps(filepath) {
var key = opts['cache-hash'] + '-amdependencies',
noCache = false; // for easy dev
// resolve paths relative to basepath
['config', 'vendor'].forEach(function(key) {
if(argv[key]) {
argv[key] = path.resolve(basepath, argv[key]);
}
});
return cache.file(filepath).data(key);
}
argv.include = argv.include.map(function(p) {
return path.resolve(basepath, p);
});
function wrapAMD(filepath, basePath) {
var deps = lookupDeps(filepath),
// the substr here will not be correct for files under folders which have been mapped unless the path length
// happens to be identical e.g. app and lib
relativeName = (path.dirname(filepath) + '/' + path.basename(filepath, path.extname(filepath))).substr(basePath.length + 1);
// load resources
return fs.readFileSync(filepath).toString().replace('define(', 'define(' +
JSON.stringify(relativeName) + ', ' +
JSON.stringify(deps) + ', '
);
if(argv.amd) {
opts.amdresolve = loadAMDConfig(argv.config);
}
var template = fs.readFileSync(__dirname + '/../lib/amd-vendor-wrap.js').toString();
if(argv.amd && main) {
// baseDir is required for AMD
opts.amdresolve.baseDir = basepath;
}
function wrapAMDVendor(name, filepath, deps, globalName) {
function findModule(name) {
var result = '';
if(!filepath) {
return '';
}
if(globalName) {
result += fs.readFileSync(filepath).toString();
result += template.replace('%name%', JSON.stringify(name)).replace('%deps%', JSON.stringify(deps)).replace('%global%', globalName);
} else {
if(!deps) {
try {
deps = amdetective(fs.readFileSync(filepath).toString());
} catch(e) {
}
console.log(deps);
try {
result = nodeResolve.sync(name, { basedir: process.cwd() });
} catch(e) {
try {
result = nodeResolve.sync(name, { basedir: __dirname });
} catch(e) {
console.error('Cannot find module ' + name + ' from ' + process.cwd() + ' or ' + __dirname);
throw e;
}
// assuming: define(function (require, exports, module) {
// -> define('decode',['require','exports','module'],function (require, exports, module) {
result += fs.readFileSync(filepath).toString().replace('define(', 'define(' +
JSON.stringify(name) + ', ' +
JSON.stringify(deps || ['require','exports','module']) + ', '
);
}
return result;
}
function uniq() {
var last = null;
return function(item) {
// to make a set of sorted keys unique, just check that consecutive keys are different
var isDuplicate = (item == last);
last = item;
return !isDuplicate;
};
}
var list = new AmdList(opts);
var cache = Cache.instance({
method: opts['cache-method'],
path: opts['cache-path']
});
cache.begin();
console.log('Reading files: ');
(Array.isArray(argv.include) ? argv.include : [ argv.include ]).map(function(filepath) {
argv.include.forEach(function(filepath) {
console.log(' ' + filepath);

@@ -145,134 +125,56 @@ list.add(filepath);

list.exec(function(err, files) {
cache.end();
var errs = list.resolveErrors();
console.log('done!');
console.log('Processing ' + files.length + ' files.');
/*
console.log(errs.map(function(item) {
return item.dep;
}).sort());
*/
console.log(files.length);
var vendor = require(path.resolve(process.cwd(), argv.vendor));
var vendorMap = vendor.paths;
files = files.filter(function(e) {
return path.basename(e.name) != 'application.js';
// resolve relative to --vendor-base
Object.keys(vendorMap).forEach(function(name) {
var value = vendorMap[name];
if (typeof value === 'string' && value.charAt(0) == '.') {
vendorMap[name] = path.resolve(argv['vendor-base'], value);
}
});
var sorter = new SortDependencies();
var basePath = path.dirname(argv.config);
var configjs = loadAMDConfig(argv.config);
// find the paths of the vendor files
var vendorNames = Object.keys(configjs.paths);
vendorPaths = { };
var missing = errs.map(function(item) {
return item.dep;
}).sort().filter(uniq());
missing.concat(vendorNames).forEach(function(name) {
if(vendorPaths[name]) {
return;
Object.keys(vendorMap).forEach(function(name) {
var value = vendorMap[name];
if(!fs.existsSync(value)) {
vendorMap[name] = false;
}
var fullpath = '';
});
configjs.relDir = basePath;
configjs.baseDir = basePath;
// prefix: function(name, filepath) {}
var plugins = {};
try {
fullpath = amdresolve.sync(name, configjs);
} catch(err) { }
if(fullpath) {
fullpath = path.normalize(fullpath);
stat = fs.statSync(fullpath);
if(stat.isFile()) {
vendorPaths[name] = fullpath;
}
Object.keys(argv).forEach(function(name) {
var matched = (typeof name === 'string' ? name.match(/plugin\-(.*)/) : false);
if(matched) {
var ext = matched[1];
argv[name] = findModule(argv[name]);
plugins[ext] = require(argv[name]);
}
});
missing = missing.filter(function(name) {
return !vendorPaths[name];
});
// list the still not found items
var failed = missing.sort().filter(uniq());
// console.log(vendorPaths, failed);
// TODO at this point, plug in the config data
// figure out the actual 3rd party dependencies (from the list) and extract names from paths key
// Note: the CANONICAL names are from the paths array
vendorNames.forEach(function(name) {
sorter.add({ name: name, deps: configjs.shim && configjs.shim[name] && configjs.shim[name].deps || [] });
});
var result = '';
// Use the resolver to output the vendor files first
sorter.resolve('require');
console.log('Vendor');
while(!sorter.isEmpty()) {
var next = sorter.next();
console.log('\t' + next.name + (vendorPaths[next.name] ? ' OK' : ''));
// due to unfilled dep on /v2/config
if(next.name != 'triconf') {
var vendorShimEntry = configjs.shim[next.name] || {};
result += wrapAMDVendor(next.name, vendorPaths[next.name], vendorShimEntry.deps, vendorShimEntry.exports || '');
runner({ files: files }, {
main: argv.main,
basepath: basepath,
configjs: opts.amdresolve,
errs: list.resolveErrors(),
'cache-method': opts['cache-method'],
'cache-path': opts['cache-path'],
cache: true,
jobs: require('os').cpus().length * 2,
vendor: vendorMap,
exclude: vendor.exclude,
extras: ['underscore'],
command: argv.command,
nomin: vendor.nomin || [],
plugins: plugins,
// set this so that builds are invalidated as the version changes
'gluejs-version': require('../package.json').version
}, fs.createWriteStream(argv['out']), function(err, processedFiles) {
if(argv['list-files']) {
fs.appendFileSync(argv['list-files'], processedFiles.join('\n'));
}
sorter.resolve(next);
}
// now add the other package files
files.forEach(function(file) {
sorter.add({ name: file.name, deps: lookupDeps(file.name) || [] });
cache.end();
});
sorter.resolve('require');
console.log('App');
while(!sorter.isEmpty()) {
var next = sorter.next();
console.log('\t' + next.name);
result += wrapAMD(next.name, basePath);
sorter.resolve(next);
}
fs.writeFileSync(path.resolve(process.cwd(), './bundle.js'), result);
/*
console.log(deps);
console.log(files.map(function(file) { return file.name + ' ' + lookupDeps(file.name); }));
console.log(files.length);
files.map();
*/
/*
var inferPackages = require('../lib/list-tasks/infer-packages.js'),
filterPackages = require('../lib/list-tasks/filter-packages.js');
inferPackages(list, { main: main, basepath: basepath });
// - for each package, apply excludes (package.json.files, .npmignore, .gitignore)
filterPackages(list);
console.log(util.inspect(list.packages, false, 1, true));
*/
});
var os = require('os'),
path = require('path'),
List = require('minitask').list,
DetectiveList = require('./lib/detective-list.js'),
DetectiveList = require('./lib/list/detective.js'),
packageCommonJs = require('./lib/runner/package-commonjs'),

@@ -6,0 +6,0 @@ Capture = require('./lib/file-tasks/capture.js'),

@@ -50,3 +50,3 @@ var fs = require('fs');

}
str += 'umd(r(' + JSON.stringify(opts['root-file']) +'), ' + JSON.stringify(opts['export']) + ');'
str += 'umd(r(' + JSON.stringify(opts['root-file']) +'), ' + JSON.stringify(opts['export']) + ');';
break;

@@ -53,0 +53,0 @@ }

{
"name": "gluejs",
"description": "Build CommonJS modules for the browser via a chainable API",
"version": "2.3.3",
"version": "2.3.4",
"author": {

@@ -37,3 +37,6 @@ "name": "Mikito Takada",

"browser-resolve": "~1.2.2",
"detective": "~2.4.0"
"detective": "~2.4.0",
"amd-resolve": "~0.1.1",
"amdetective": "0.0.1",
"resolve": "~0.6.1"
},

@@ -40,0 +43,0 @@ "devDependencies": {

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

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