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

Update dependencies to commonjs branches #76

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
language: node_js
node_js:
- 4
- 6
- 8
- 10
script: npm run $COMMAND
env:
- COMMAND=test
- COMMAND=integration MR_VERSION=16.0.5
- COMMAND=integration MR_VERSION=latest
- COMMAND=integration MR_VERSION="#master"
- COMMAND=integration MONTAGE_VERSION=16.0.3
- COMMAND=integration MONTAGE_VERSION=latest
- COMMAND=integration MONTAGE_VERSION="#master"
# - COMMAND=integration MR_VERSION=16.0.5
# - COMMAND=integration MR_VERSION=latest
- COMMAND=integration MR_VERSION="#commonjs"
# - COMMAND=integration MONTAGE_VERSION=16.0.3
# - COMMAND=integration MONTAGE_VERSION=latest
- COMMAND=integration MONTAGE_VERSION="#commonjs"
notifications:
irc:
channels:
Expand Down
10 changes: 2 additions & 8 deletions lib/bundle/montage.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,10 @@ function loadMontageScript(element, file, config) {
.then(function (applicationPackage) {
return applicationPackage.loadPackage(montageLocation)
.then(function (montagePackage) {

// load the promise package so we can inject the bootstrapped
// promise library back into it
var promiseLocation = URL.resolve(montagePackage.location, "node_modules/bluebird");

return [
montagePackage,
montagePackage.loadPackage({
location: promiseLocation
name: "bluebird"
})
];
})
Expand Down Expand Up @@ -123,8 +118,7 @@ function collectMontageBootstrapBundle(loader, bundler, config) {
var bundle = [
montagePackage.files["montage.js"].utf8,
requirePackage.files["require.js"].utf8,
requirePackage.files["browser.js"].utf8,
promisePackage.files["js/browser/bluebird.min.js"].utf8
promisePackage.files["js/browser/bluebird.min.js"].utf8,
];

// some of the modules used in bootstrapping get injected into the run-time
Expand Down
3 changes: 1 addition & 2 deletions lib/bundle/mr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

var Bundle = require("../bundle");
var MrBootstrap = require("mr/bootstrap-node");
var MrBootstrap = require("mr/bootstrap");
var URL = require("url2");

module.exports = bundleMrHtml;
Expand Down Expand Up @@ -61,7 +61,6 @@ function collectMrBootstrapBundle(loader, bundler, config) {
var bundle = [
requirePackage.files["bootstrap.js"].utf8,
requirePackage.files["require.js"].utf8,
requirePackage.files["browser.js"].utf8,
promisePackage.files["js/browser/bluebird.min.js"].utf8
];

Expand Down
60 changes: 42 additions & 18 deletions lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ var keys = require('object-keys');

module.exports = read;
function read(location, config) {

return MontageBootstrap.loadPackage(location, config)
.then(function (appPackage) {
return loadDeepPackages(appPackage)
.then(verifyVersions)
.then(function (package) {
return verifyVersions(package, config);
})
.then(function () {
var packages = values(appPackage.packages);
config.files = {}; // by location
Expand All @@ -38,32 +40,48 @@ function read(location, config) {
});
}

function verifyVersions(package) {
function verifyVersions(package, config) {
return new Promise(function (resolve, reject) {

if (package.hasPackage({name: "montage"})) {
var montage = package.getPackage({name: "montage"});
var montagePredicate = mopDescription.dependencies.montage;
if (!semver.satisfies(montage.packageDescription.version, montagePredicate)) {
reject(new Error(
"Mop only supports Montage " + montagePredicate + ". This app has " +
montage.packageDescription.version
));
return;
if (
montagePredicate.indexOf('github:') === 0 ?
montage.packageDescription._from !== montagePredicate :
!semver.satisfies(montage.packageDescription.version, montagePredicate)
) {
var montageErr = "Mop only supports Montage " + montagePredicate + ". This app has " +
montage.packageDescription.version;

if (config.checkVersion) {
reject(new Error(montageErr));
return;
} else {
console.warn(montageErr);
}
}
}

if (package.hasPackage({name: "mr"})) {
var mr = package.getPackage({name: "mr"});
var mrPredicate = mopDescription.dependencies.mr;
if (!semver.satisfies(mr.packageDescription.version, mrPredicate)) {
reject(new Error(
"Mop only supports Montage Require (mr) " + mrPredicate + ". This app has " +
mr.packageDescription.version
));
return;
if (
mrPredicate.indexOf('github:') === 0 ?
mr.packageDescription._from !== mrPredicate :
!semver.satisfies(mr.packageDescription.version, mrPredicate)
) {
var mrErr = "Mop only supports Montage Require (mr) " + mrPredicate + ". This app has " +
mr.packageDescription.version;

if (config.checkVersion) {
reject(new Error(mrErr));
return;
} else {
console.warn(mrErr);
}
}
}
}

return resolve(package);
});
Expand All @@ -78,6 +96,12 @@ function loadDeepPackages(package, memo) {
if (!memo[location]) {
var loading = package.loadPackage(location)
.then(function (dependency) {
// mr may have had to retry the package at a different location,
// make sure the mapping location is updated too
if (location !== dependency.location) {
location = mapping.location = dependency.location;
memo[location] = loading;
}
return loadDeepPackages(dependency, memo);
});
memo[location] = loading;
Expand Down Expand Up @@ -141,7 +165,7 @@ function readPackage(package, config, appPackage) {
config.out.status();
return Promise.each(names, function (name) {
config.out.status("Reading files", name);
var fileLocation = URL.resolve(config.location, Location.fromPath(name));
var fileLocation = URL.resolve(config.location || '', Location.fromPath(name));
var relativeLocation = URL.relative(location, fileLocation);
return config.fs.read(name)
.then(function (content) {
Expand Down
37 changes: 21 additions & 16 deletions optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Path = require("path");
var build = require("./lib/build");
var spinner = require("./lib/spinner");
var Location = require("./lib/location");
var mr = require("mr/require");

/**
* Optimize the package at the given location.
Expand Down Expand Up @@ -64,22 +65,26 @@ function optimize(location, config) {
return fs.read(path);
}

return build(location, {
// configurable
buildLocation: URL.resolve(location, (config.buildLocation || "builds") + "/"),
minify: config.minify !== void 0 ? !!config.minify : true,
lint: config.lint !== void 0 ? !!config.lint : false,
noCss: config.noCss !== void 0 ? !!config.noCss : false,
cssEmbedding: config.cssEmbedding !== void 0 ? !!config.cssEmbedding : true,
delimiter: config.delimiter !== void 0 ? config.delimiter : "@",
out: config.out || spinner,

fs: fs,
read: read,

// non-configurable
overlays: ["browser"],
production: true
return mr.loadPackageLock({ location: location })
.then(function (packageLock) {
return build(location, {
// configurable
buildLocation: URL.resolve(location, (config.buildLocation || "builds") + "/"),
minify: config.minify !== void 0 ? !!config.minify : true,
lint: config.lint !== void 0 ? !!config.lint : false,
noCss: config.noCss !== void 0 ? !!config.noCss : false,
cssEmbedding: config.cssEmbedding !== void 0 ? !!config.cssEmbedding : true,
delimiter: config.delimiter !== void 0 ? config.delimiter : "@",
out: config.out || spinner,

fs: fs,
read: read,

// non-configurable
overlays: ["browser"],
production: true,
packageLock: packageLock
});
});

// Once implemented but currently disabled options:
Expand Down
Loading