Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
feons committed Aug 10, 2017
1 parent 8b3f818 commit 14a4445
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 39 deletions.
80 changes: 61 additions & 19 deletions build/liveview.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
Module._port = parseInt(port, 10) || 8324;
Module._requireNative = globalCtx.require;
Module.evtServer && Module.evtServer.close();
Module._compileList = [];

// FIX for android bug
try {
Expand Down Expand Up @@ -506,6 +507,33 @@
eval.call(ctx, src); // eslint-disable-line no-eval
};

/**
* convert relative to absolute path
* @param {string} parent
* @param {string} relative
*
* @public
*/
Module.toAbsolute = function (parent, relative) {
var newPath = parent.split('/'),
parts = relative.split('/');

newPath.pop();

for (var i = 0; i < parts.length; i++) {
if (parts[i] === '.') {
continue;
}

if (parts[i] === '..') {
newPath.pop();
} else {
newPath.push(parts[i]);
}
}
return newPath.join('/');
};

/**
* commonjs module loader
* @param {string} id module identifier
Expand All @@ -514,32 +542,44 @@
*/
Module.require = function (id) {
var fullPath = id;
var cached = Module.getCached(fullPath);
var cached = Module.getCached(fullPath) || Module.getCached(fullPath + '/index');

if (cached) {
return cached.exports;
}

if (!Module.exists(fullPath)) {
var hlDir = '/hyperloop/';
if (fullPath.indexOf('.*') !== -1) {
fullPath = id.slice(0, id.length - 2);
}

var modLowerCase = fullPath.toLowerCase();
if (Module.exists(hlDir + fullPath)) {
fullPath = hlDir + fullPath;
} else if (Module.exists(hlDir + modLowerCase)) {
fullPath = hlDir + modLowerCase;
} else if (fullPath.indexOf('.') === -1 && Module.exists(hlDir + fullPath + '/' + fullPath)) {
fullPath = hlDir + fullPath + '/' + fullPath;
} else if (fullPath.indexOf('.') === -1 && Module.exists(hlDir + modLowerCase + '/' + modLowerCase)) {
fullPath = hlDir + modLowerCase + '/' + modLowerCase;
if (fullPath.indexOf('./') === 0 || fullPath.indexOf('../') === 0) {
var parent = Module._compileList[Module._compileList.length - 1];
var tempFullPath = Module.toAbsolute(parent, fullPath);
if (Module.exists(tempFullPath)) {
fullPath = tempFullPath;
}
} else if (fullPath.indexOf('/') === 0) {
if (Module.exists(fullPath + '/index')) {
fullPath = fullPath + '/index';
}
} else {
var lastIndex = fullPath.lastIndexOf('.');
var tempPath = hlDir + fullPath.slice(0, lastIndex) + '$' + fullPath.slice(lastIndex + 1);
if (Module.exists(fullPath)) {
fullPath = tempPath;
var hlDir = '/hyperloop/';
if (fullPath.indexOf('.*') !== -1) {
fullPath = id.slice(0, id.length - 2);
}

var modLowerCase = fullPath.toLowerCase();
if (Module.exists(hlDir + fullPath)) {
fullPath = hlDir + fullPath;
} else if (Module.exists(hlDir + modLowerCase)) {
fullPath = hlDir + modLowerCase;
} else if (fullPath.indexOf('.') === -1 && Module.exists(hlDir + fullPath + '/' + fullPath)) {
fullPath = hlDir + fullPath + '/' + fullPath;
} else if (fullPath.indexOf('.') === -1 && Module.exists(hlDir + modLowerCase + '/' + modLowerCase)) {
fullPath = hlDir + modLowerCase + '/' + modLowerCase;
} else {
var lastIndex = fullPath.lastIndexOf('.');
var tempPath = hlDir + fullPath.slice(0, lastIndex) + '$' + fullPath.slice(lastIndex + 1);
if (Module.exists(fullPath)) {
fullPath = tempPath;
}
}
}
}
Expand Down Expand Up @@ -672,6 +712,7 @@
this.loaded = true;
return;
}
Module._compileList.push(this.id);
this.source = Module._wrap(src);
try {
var fn = new Function('exports, require, module, __filename, __dirname, lvGlobal', this.source); // eslint-disable-line no-new-func
Expand All @@ -680,6 +721,7 @@
process.emit('uncaughtException', { module: this.id, error: err, source: ('' + this.source).split('\n') });
}

Module._compileList.pop();
this.loaded = true;
};

Expand Down
80 changes: 61 additions & 19 deletions lib/platform/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Module.patch = function (globalCtx, url, port) {
Module._port = parseInt(port, 10) || 8324;
Module._requireNative = globalCtx.require;
Module.evtServer && Module.evtServer.close();
Module._compileList = [];

// FIX for android bug
try {
Expand Down Expand Up @@ -178,6 +179,33 @@ Module.include = function (ctx, id) {
eval.call(ctx, src); // eslint-disable-line no-eval
};

/**
* convert relative to absolute path
* @param {string} parent
* @param {string} relative
*
* @public
*/
Module.toAbsolute = function (parent, relative) {
var newPath = parent.split('/'),
parts = relative.split('/');

newPath.pop();

for (var i = 0; i < parts.length; i++) {
if (parts[i] === '.') {
continue;
}

if (parts[i] === '..') {
newPath.pop();
} else {
newPath.push(parts[i]);
}
}
return newPath.join('/');
};

/**
* commonjs module loader
* @param {string} id module identifier
Expand All @@ -186,32 +214,44 @@ Module.include = function (ctx, id) {
*/
Module.require = function (id) {
let fullPath = id;
const cached = Module.getCached(fullPath);
const cached = Module.getCached(fullPath) || Module.getCached(fullPath + '/index');

if (cached) {
return cached.exports;
}

if (!Module.exists(fullPath)) {
const hlDir = '/hyperloop/';
if (fullPath.indexOf('.*') !== -1) {
fullPath = id.slice(0, id.length - 2);
}

const modLowerCase = fullPath.toLowerCase();
if (Module.exists(hlDir + fullPath)) {
fullPath = hlDir + fullPath;
} else if (Module.exists(hlDir + modLowerCase)) {
fullPath = hlDir + modLowerCase;
} else if (fullPath.indexOf('.') === -1 && Module.exists(hlDir + fullPath + '/' + fullPath)) {
fullPath = hlDir + fullPath + '/' + fullPath;
} else if (fullPath.indexOf('.') === -1 && Module.exists(hlDir + modLowerCase + '/' + modLowerCase)) {
fullPath = hlDir + modLowerCase + '/' + modLowerCase;
if (fullPath.indexOf('./') === 0 || fullPath.indexOf('../') === 0) {
const parent = Module._compileList[Module._compileList.length - 1];
const tempFullPath = Module.toAbsolute(parent, fullPath);
if (Module.exists(tempFullPath)) {
fullPath = tempFullPath;
}
} else if (fullPath.indexOf('/') === 0) {
if (Module.exists(fullPath + '/index')) {
fullPath = fullPath + '/index';
}
} else {
const lastIndex = fullPath.lastIndexOf('.');
const tempPath = hlDir + fullPath.slice(0, lastIndex) + '$' + fullPath.slice(lastIndex + 1);
if (Module.exists(fullPath)) {
fullPath = tempPath;
const hlDir = '/hyperloop/';
if (fullPath.indexOf('.*') !== -1) {
fullPath = id.slice(0, id.length - 2);
}

const modLowerCase = fullPath.toLowerCase();
if (Module.exists(hlDir + fullPath)) {
fullPath = hlDir + fullPath;
} else if (Module.exists(hlDir + modLowerCase)) {
fullPath = hlDir + modLowerCase;
} else if (fullPath.indexOf('.') === -1 && Module.exists(hlDir + fullPath + '/' + fullPath)) {
fullPath = hlDir + fullPath + '/' + fullPath;
} else if (fullPath.indexOf('.') === -1 && Module.exists(hlDir + modLowerCase + '/' + modLowerCase)) {
fullPath = hlDir + modLowerCase + '/' + modLowerCase;
} else {
const lastIndex = fullPath.lastIndexOf('.');
const tempPath = hlDir + fullPath.slice(0, lastIndex) + '$' + fullPath.slice(lastIndex + 1);
if (Module.exists(fullPath)) {
fullPath = tempPath;
}
}
}
}
Expand Down Expand Up @@ -354,6 +394,7 @@ Module.prototype._compile = function () {
this.loaded = true;
return;
}
Module._compileList.push(this.id);
this.source = Module._wrap(src);
try {
const fn = new Function('exports, require, module, __filename, __dirname, lvGlobal', this.source); // eslint-disable-line no-new-func
Expand All @@ -362,6 +403,7 @@ Module.prototype._compile = function () {
process.emit('uncaughtException', { module: this.id, error: err, source: ('' + this.source).split('\n') });
}

Module._compileList.pop();
this.loaded = true;
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "liveview",
"version": "1.2.0",
"version": "1.2.1",
"description": "Titanium Live Realtime App Development",
"main": "index.js",
"private": true,
Expand Down

0 comments on commit 14a4445

Please sign in to comment.