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

Support npm 3+ #2006

Merged
merged 9 commits into from
Aug 9, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
language: node_js
node_js:
- "4"
- 4
- 6
- 8
- 10
script: npm run $COMMAND
env:
- COMMAND=test
- COMMAND=test:karma-travis
#- COMMAND=integration MONTAGE_VERSION=. MOP_VERSION=latest
- COMMAND=integration MONTAGE_VERSION=. MOP_VERSION="#master"
- COMMAND=integration MONTAGE_VERSION=. MOP_VERSION="#feature/npm3"
before_install:
- "npm set legacy-bundling=true"
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
Expand Down
62 changes: 29 additions & 33 deletions montage.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,19 @@
}
},

load: function (location,loadCallback) {
load: function (location, callback) {
var script = document.createElement("script");
script.src = location;
script.onload = function () {
if(loadCallback) {
loadCallback(script);
if (callback) {
callback(null, script);
}
// remove clutter
script.parentNode.removeChild(script);
};
script.onerror = function () {
if (callback) {
callback(new Error("Can't load script " + JSON.stringify(location)), script);
}
// remove clutter
script.parentNode.removeChild(script);
Expand Down Expand Up @@ -253,13 +260,28 @@
allModulesLoaded();
};

var montageLocation;
function loadModuleScript(path, callback) {
montageLocation = montageLocation || resolve(global.location, params.montageLocation);
// try loading script relative to app first (npm 3+)
browser.load(resolve(global.location, path), function (err, script) {
if (err) {
// if that fails, the app may have been installed with
// npm 2 or with --legacy-bundling, in which case the
// script will be under montage's node_modules
browser.load(resolve(montageLocation, path), callback);
} else if (callback) {
callback(null, script);
}
});
}

// load in parallel, but only if we're not using a preloaded cache.
// otherwise, these scripts will be inlined after already
if (typeof global.BUNDLE === "undefined") {
var montageLocation = resolve(global.location, params.montageLocation);

//Special Case bluebird for now:
browser.load(resolve(montageLocation, pending.promise), function() {
// Special Case bluebird for now:
loadModuleScript(pending.promise, function () {
delete pending.promise;

//global.bootstrap cleans itself from global once all known are loaded. "bluebird" is not known, so needs to do it first
Expand All @@ -272,7 +294,7 @@

for (var module in pending) {
if (pending.hasOwnProperty(module)) {
browser.load(resolve(montageLocation, pending[module]));
loadModuleScript(pending[module]);
}
}
});
Expand Down Expand Up @@ -777,34 +799,8 @@
hash: params.montageHash
})
.then(function (montageRequire) {
// load the promise package so we can inject the bootstrapped
// promise library back into it
var promiseLocation;
if (params.promiseLocation) {
promiseLocation = URL.resolve(Require.getLocation(), params.promiseLocation);
} else {
//promiseLocation = URL.resolve(montageLocation, "packages/mr/packages/q");
//node tools/build --features="core timers call_get" --browser
promiseLocation = URL.resolve(montageLocation, "node_modules/bluebird");
}

var result = [
montageRequire,
montageRequire.loadPackage({
location: promiseLocation,
hash: params.promiseHash
})
];

return result;
})
.spread(function (montageRequire, promiseRequire) {
montageRequire.inject("core/mini-url", URL);
montageRequire.inject("core/promise", {Promise: Promise});
promiseRequire.inject("bluebird", Promise);

// This prevents bluebird to be loaded twice by mousse's code
promiseRequire.inject("js/browser/bluebird", Promise);

// install the linter, which loads on the first error
config.lint = function (module) {
Expand Down
5 changes: 2 additions & 3 deletions node.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ function getMontageMontageDeserializer() {
return getMontageMontageDeserializer._promise;
}

return (getMontageMontageDeserializer._promise = MontageBoot.loadPackage(
PATH.join(__dirname, "."), {mainPackageLocation: PATH.join(__dirname, "../")})
return (getMontageMontageDeserializer._promise = MontageBoot.loadPackage(PATH.join(__dirname, "."))
.then(function (mr) {
return mr.async("./core/serialization/deserializer/montage-deserializer")
.then(function (MontageDeserializerModule) {
return (MontageBoot.MontageDeserializer =
return (MontageBoot.MontageDeserializer =
MontageDeserializerModule.MontageDeserializer
);
});
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "montage",
"version": "17.2.1",
"version": "18.0.0-rc2",
"description": "Build your next application with a browser based platform that really gets the web.",
"license": "BSD-3-Clause",
"repository": {
Expand All @@ -9,8 +9,8 @@
},
"main": "montage",
"engines": {
"node": "<=4.9.1",
"npm": "<=2.15.11"
"node": ">=4",
"npm": ">=2"
},
"overlay": {
"browser": {
Expand Down Expand Up @@ -53,7 +53,7 @@
"frb": "~4.0.x",
"htmlparser2": "~3.0.5",
"q-io": "^1.13.3",
"mr": "^17.0.11",
"mr": "18.0.0-rc2",
"weak-map": "^1.0.5",
"lodash.kebabcase": "^4.1.1",
"lodash.camelcase": "^4.3.0",
Expand Down