Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resolution algorithm wip #240

Merged
merged 21 commits into from Nov 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
node_modules
sandbox
testlibs/jspm_packages
testlibs/config.js
testlibs/build.js
testlibs/build.js.map
10 changes: 6 additions & 4 deletions api.js
Expand Up @@ -64,7 +64,7 @@ ui.setResolver(API);
* jspm.install('jquery', 'github:components/jquery')
* jspm.install('jquery', { force: true });
* jspm.install({ jquery: '1.2.3' }, { force: true })
* jspm.install('jquery', { primary: false }); // not saved to packge.json
* jspm.install(true, options) // install from package.json
*
*/
API.install = function(name, target, options) {
Expand All @@ -78,7 +78,9 @@ API.install = function(name, target, options) {
// API.installed = function() {
// }


API.bundle = function(expression, fileName) {
return bundle.bundle(expression, fileName);
// options.inject
// options.sourceMaps
// options.minify
API.bundle = function(expression, fileName, options) {
return bundle.bundle(expression, fileName, options);
}
173 changes: 87 additions & 86 deletions cli.js
Expand Up @@ -21,6 +21,7 @@ var core = require('./lib/core');
var bundle = require('./lib/bundle');
var semver = require('./lib/semver');
var endpoint = require('./lib/endpoint');
var install = require('./lib/install');
var fs = require('graceful-fs');

var link = require('./lib/link');
Expand All @@ -45,47 +46,53 @@ process.on('uncaughtException', function(err) {
function showInstructions() {
showHeader();
ui.log('\n'
+ 'jspm install <name[=version]> [-o "{package override}" --force] \n'
+ ' install Install / update from package.json\n'
+ ' install jquery Install a package from the registry\n'
+ ' install npm:underscore Install latest version from NPM\n'
+ ' install jquery@1.1 Install latest minor version\n'
+ ' install jquery@1.1.1 Install an exact version\n'
+ ' install jquery npm:underscore Install multiple packages\n'
+ ' install jquery=1.1.1 Install a package to a specific version\n'
+ ' install jquery@1.2=1.2.3 Install a version range to a specific version\n'
+ 'jspm init Create / validate project configuration file\n'
+ '\n'
+ 'jspm inject <name[=version]> [-o "{package override}" --force] \n'
+ ' inject jquery Identical to install, but injects config\n'
+ ' only instead of downloading the package\n'
+ 'jspm install <name[=target]>+ [--force skips cache] [--latest]\n'
+ ' install jquery Install a package from the registry to latest\n'
+ ' install react=npm:react Install a package from an endpoint to latest\n'
+ ' install jquery=2 Install a package to a version or range\n'
+ '\n'
+ ' install Reproducible / shrinkwrap install package.json\n'
+ '\n'
+ ' install react --lock Stable install, locking existing dependencies\n'
+ '\n'
+ 'jspm link [endpoint:name@version] Link a local folder as an installable package\n'
+ 'jspm install --link name Install a linked package\n'
+ ' install dep -o override.json Install with the given custom override\n'
+ ' install dep -o "{override json}" useful for testing package overrides\n'
+ '\n'
+ 'jspm uninstall name Uninstall a package and any orphaned deps\n'
+ 'jspm update Update all packages from package.json\n'
+ 'jspm uninstall name Uninstall a package and clean dependencies\n'
+ 'jspm clean Clear unused and orphaned dependencies\n'
+ '\n'
+ 'jspm update [--force] Check and update existing modules\n'
+ 'jspm inspect [--forks] View all installed package versions\n'
+ 'jspm inspect npm:source-map View the versions and ranges of a package\n'
+ '\n'
+ 'jspm inject <name[=target]> [--force] [--latest] [--lock] [-o]\n'
+ ' inject jquery Identical to install, but injects config\n'
+ ' only instead of downloading the package\n'
+ '\n'
+ 'jspm init Create / recreate the configuration file\n'
+ 'jspm link endpoint:name@version Link a local folder as an installable package\n'
+ 'jspm install --link endpoint:name Install a linked package\n'
+ '\n'
+ 'jspm dl-loader [--edge --source] Download the jspm browser loader\n'
+ '\n'
+ 'jspm setmode <mode>\n'
+ ' setmode local Switch to locally downloaded libraries\n'
+ ' setmode remote Switch to CDN external package sources\n'
+ ' setmode dev Switch to the development baseURL\n'
+ ' setmode production Switch to the production baseURL\n'
+ ' setmode dev Switch to the app development folder\n'
+ ' setmode production Switch to the app production folder\n'
+ '\n'
+ 'jspm depcache [moduleName] Stores dep cache in config for flat pipelining\n'
+ 'jspm bundle A + B - C [file] [-i] Bundle an input module or module arithmetic\n'
+ 'jspm bundle moduleA + module/b [outfile] [--inject] [--skip-source-maps]\n'
+ 'jspm unbundle Remove injected bundle configuration\n'
+ 'jspm depcache moduleName Stores dep cache in config for flat pipelining\n'
+ '\n'
+ 'jspm endpoint <command> Manage endpoints\n'
+ ' endpoint config <endpoint-name> Configure an endpoint\n'
+ ' endpoint config <name> Configure an existing endpoint\n'
+ ' endpoint create <name> <pkg> Create a new custom endpoint instance\n'
// + ' endpoint export <endpoint-name> Export an endpoint programatically\n'
+ '\n'
+ 'jspm config <option> <setting> Configure jspm options\n'
+ ' Options are stored in ~/.jspm/config\n'
+ 'jspm config <option> <setting> Configure jspm global options\n'
+ ' Stored in ~/.jspm/config\n'
+ '\n'
+ 'All options work with the -y flag to skip prompts\n'
);
Expand All @@ -95,7 +102,7 @@ process.on('uncaughtException', function(err) {
showHeader();
ui.log('\n'
+ 'Version: ' + require('./package.json').version + '\n'
+ (process.env.localJspm == 'true' ? 'Running against local jspm install' : 'Running against global jspm install') + '\n'
+ (process.env.localJspm == 'true' ? 'Running against local jspm install.' : 'Running against global jspm install.') + '\n'
);
}

Expand All @@ -104,30 +111,22 @@ process.on('uncaughtException', function(err) {
case 'inject':
var inject = true;

case 'update':
var doUpdate = true;

case 'install':
var options = readOptions(args, ['--force', '--override', '--link', '--yes']);
var options = readOptions(args, ['--force', '--override', '--link', '--yes', '--lock', '--latest']);
options.inject = inject;

var args = options.args;
args = options.args;

var depMap;
for (var i = 1; i < (options.override || args.length); i++) {
depMap = depMap || {};
var name, target;
var arg = args[i];
if (arg.indexOf('=') == -1) {
// install jquery@1.2.3 -> install jquery=^1.2.3
name = arg.split('@')[0];
target = arg.split('@')[1] || '';

// valid semver -> make semver compatibility default
if (target && target.match(semver.semverRegEx))
target = '^' + target;
}
else {
name = arg.split('=')[0];
target = arg.split('=')[1];
}
name = arg.split('=')[0];
target = arg.split('=')[1];
depMap[name] = target;
}

Expand Down Expand Up @@ -155,8 +154,12 @@ process.on('uncaughtException', function(err) {
if (options.yes)
ui.useDefaults();

// jspm install with no arguments is locked
if (!depMap && !doUpdate)
options.lock = true;

// no install package -> install from package.json dependencies
(depMap ? core.install(depMap, options) : core.install(true, options))
(depMap ? install.install(depMap, options) : install.install(true, options))
.then(function() {
return core.checkDlLoader()
})
Expand All @@ -165,63 +168,67 @@ process.on('uncaughtException', function(err) {
})
.then(function() {
ui.log('');
ui.log('ok', 'Install complete');
ui.log('ok', 'Install complete.');
process.exit();
}, function(err) {
// something happened (cancel / err)
ui.log('err', err.stack || err);
ui.log('warn', 'Installation changes not saved');
ui.log('warn', 'Installation changes not saved.');
process.exit(1);
});

break;
case 'update':
var options = readOptions(args, ['--force', '--yes']);

case 'uninstall':
var options = readOptions(args, ['--yes']);

if (options.yes)
ui.useDefaults();

core.install(true, options)
install.uninstall(args.splice(1))
.then(function() {
ui.log('');
ui.log('ok', 'Update complete');
ui.log('ok', 'Uninstall complete.');
}, function(err) {
ui.log('err', err.stack || err);
ui.log('warn', 'Update changes not saved');
ui.log('warn', 'Uninstall changes not saved.');
process.exit(1);
});

break;

case 'uninstall':
case 'clean':
var options = readOptions(args, ['--yes']);
args = options.args;

if (options.yes)
ui.useDefaults();

core.uninstall(args.splice(1))
.then(function(removed) {
if (removed) {
ui.log('');
ui.log('ok', 'Uninstall complete');
}
else
ui.log('info', 'Nothing to remove');
install.clean()
.then(function() {
ui.log('');
ui.log('ok', 'Project cleaned successfully.');
}, function(err) {
ui.log('err', err.stack || err);
ui.log('warn', 'Uninstall changes not saved');
process.exit(1);
});
break;

case 'clean':
var options = readOptions(args, ['--yes']);

if (options.yes)
ui.useDefaults();
break;

core.clean();
case 'inspect':
var options = readOptions(args, ['--forks']);
args = options.args;

config.load()
.then(function() {
if (!args[1])
return install.showVersions(options.forks);
if (args[1].indexOf(':') == -1)
return ui.log('warn', 'Enter a full package name of the format `endpoint:repo`.');
return install.showInstallGraph(args[1]);
})
.catch(function(e) {
ui.log('err', e.stack || e);
});
break;

case 'init':
Expand All @@ -233,15 +240,6 @@ process.on('uncaughtException', function(err) {
core.init();
break;

case 'prune':
var options = readOptions(args, ['--yes']);

if (options.yes)
ui.useDefaults();

core.prune();
break;


case 'dl-loader':
var options = readOptions(args, ['--source', '--edge', '--yes']);
Expand Down Expand Up @@ -270,15 +268,14 @@ process.on('uncaughtException', function(err) {
break;

case 'bundle':
var options = readOptions(args, ['--inject', '--yes', '--skip-source-maps']);
var options = readOptions(args, ['--inject', '--yes', '--skip-source-maps', '--minify']);
if (options.yes)
ui.useDefaults();
var inject = !!options.inject;
var sourceMaps = !options['skip-source-maps'];
options.sourceMaps = !options['skip-source-maps'];
var bArgs = options.args.splice(1);

if (bArgs.length < 2) {
bundle.bundle(bArgs[0], undefined, inject, sourceMaps)
bundle.bundle(bArgs[0], undefined, options)
.catch(function(e) {
process.exit(1);
});
Expand All @@ -298,7 +295,7 @@ process.on('uncaughtException', function(err) {
expression = bArgs.splice(0, bArgs.length - 1).join(' ');
fileName = bArgs[bArgs.length - 1];
}
bundle.bundle(expression, fileName, inject, sourceMaps)
bundle.bundle(expression, fileName, options)
.catch(function(e) {
process.exit(1);
});
Expand All @@ -314,10 +311,12 @@ process.on('uncaughtException', function(err) {
break;

case 'bundle-sfx':
var options = readOptions(args, ['--yes']);
var options = readOptions(args, ['--yes', '--skip-source-maps', '--minify']);
if (options.yes)
ui.useDefaults();
bundle.bundleSFX(args[1], args[2])
var sourceMaps = !options['skip-source-maps'];
var bArgs = options.args.splice(1);
bundle.bundleSFX(bArgs[0], bArgs[1], sourceMaps, options.minify)
.catch(function(e) {
process.exit(1);
});
Expand Down Expand Up @@ -417,7 +416,7 @@ process.on('uncaughtException', function(err) {
}
else {
showInstructions();
ui.log('Invalid endpoint argument ' + args[1]);
ui.log('warn', 'Invalid endpoint argument %' + args[1] + '%.');
}
break;

Expand All @@ -441,7 +440,7 @@ process.on('uncaughtException', function(err) {
default:
showInstructions();
if (args[0])
ui.log('Invalid argument ' + args[0]);
ui.log('warn', 'Invalid argument %' + args[0] + '%.');
}
})();

Expand All @@ -459,10 +458,12 @@ function readOptions(args, flags, settings) {
}
else if (args[i].substr(0, 1) == '-' && args[i].length > 1) {
var opts = args[i].substr(1);
for (var j = 0; j < opts.length; j++) {
opl: for (var j = 0; j < opts.length; j++) {
for (var k = 0; k < flags.length; k++) {
if (flags[k].substr(2, 1) == opts[j])
if (flags[k].substr(2, 1) == opts[j]) {
argOptions[flags[k].substr(2)] = argOptions.args.length;
continue opl;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/build.js
Expand Up @@ -78,7 +78,7 @@ exports.buildPackage = function(dir, pjson) {
removeJSExtensions: pjson.useJSExtensions,
map: pjson.map,
transpile: !hasDist && pjson.buildConfig && pjson.buildConfig.transpile,
minify: !hasDist && pjson.buildConfig && (pjson.buildConfig.uglify || pjson.buildConfig.minify)
minify: false && !hasDist && pjson.buildConfig && (pjson.buildConfig.uglify || pjson.buildConfig.minify)
});
});
}
Expand Down