Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #24 from manifoldjs/fix-node-iis
Browse files Browse the repository at this point in the history
Fix node iis
  • Loading branch information
marcerodriguez authored Sep 21, 2016
2 parents a667ec6 + bffedd9 commit 1b56db1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
7 changes: 4 additions & 3 deletions lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var ansi = require('ansi'),
// that all access the global instance; otherwise, each one gets a separate
// instance of the logger.
var log = global.manifoldjs_logger,
cursor = ansi(process.stdout);
cursor = ansi(process.stdout),
utils = require('./utils');

var colorMap = {
'debug': 'green',
Expand All @@ -22,7 +23,7 @@ function getApplicationName (appPath) {

try {
if (!appPath) {
appPath = path.dirname(require.main.filename);
appPath = path.dirname(utils.getRootPackagePath());
}

var mainModule = path.join(appPath, 'package.json');
Expand Down Expand Up @@ -59,7 +60,7 @@ if (!log) {
message = (message || '').replace(/\n/g, '\n' + new Array(maxLenSeverity + maxLenSource + 6).join(' '));

if (methodName !== 'write') {
source = source || loggerName || getApplicationName();
source = source || loggerName || getApplicationName() || 'Unknown';
rawMethod(
'[' + severity + new Array(Math.max(maxLenSeverity - severity.length + 1, 0)).join(' ') + '] ' +
source + new Array(Math.max(maxLenSource - source.length + 1, 0)).join(' ') + ': ' +
Expand Down
13 changes: 7 additions & 6 deletions lib/packageTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var fs = require('fs'),

var CustomError = require('./customError'),
exec = require('./processTools').exec,
log = require('./log');
log = require('./log'),
utils = require('./utils');

var node_modules = 'node_modules';
var packageJson = 'package.json';
Expand Down Expand Up @@ -66,13 +67,13 @@ function getPackageInformation (packageName, parentPackagePath) {

try {
if (!parentPackagePath) {
parentPackagePath = path.dirname(require.main.filename);
parentPackagePath = path.dirname(utils.getRootPackagePath());
}

var modulePath = parentPackagePath;

if (packageName) {
modulePath = modulePath.endsWith(node_modules) ? modulePath : path.join(modulePath, node_modules);
modulePath = (path.basename(modulePath) === node_modules) ? modulePath : path.join(modulePath, node_modules);
modulePath = path.join(modulePath, packageName);
}
modulePath = path.join(modulePath, packageJson);
Expand All @@ -98,7 +99,7 @@ function getModuleInformation (dir) {

try {
if (!dir) {
dir = require.main.filename;
dir = utils.getRootPackagePath();
}

var info = fs.statSync(dir);
Expand Down Expand Up @@ -212,7 +213,7 @@ function installPackage (packageName, source, callback) {

// npm command in Windows is a batch file and needs to include extension to be resolved by spawn call
var npm = (process.platform === 'win32' ? 'npm.cmd' : 'npm');
var appRoot = path.dirname(require.main.filename);
var appRoot = path.dirname(utils.getRootPackagePath());
return exec(npm, ['install', source], { cwd: appRoot, statusMessage: 'Installing package ' }).then(function () {
var module = require(packageName);
return Q.resolve(module);
Expand Down Expand Up @@ -252,7 +253,7 @@ function installQueuedPackages () {

// npm command in Windows is a batch file and needs to include extension to be resolved by spawn call
var npm = (process.platform === 'win32' ? 'npm.cmd' : 'npm');
var appRoot = path.dirname(require.main.filename);
var appRoot = path.dirname(utils.getRootPackagePath());

// build package list
var sources = installQueue.map(function (item) {
Expand Down
2 changes: 1 addition & 1 deletion lib/platformTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var fileTools = require('./fileTools'),
var platformConfiguration;

function getDefaultConfigPath () {
return path.resolve(path.dirname(require.main.filename), 'platforms.json');
return path.resolve(path.dirname(utils.getRootPackagePath()), 'platforms.json');
}

function getPlatformModule(packageName, source) {
Expand Down
19 changes: 17 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var os = require('os'),
url = require('url');
url = require('url'),
path = require('path');

function parseJSON (data) {
try {
Expand Down Expand Up @@ -105,6 +106,19 @@ function getDefaultShortName (siteUrl) {
return shortName;
}

// Handle Node hosted in IIS
function getRootPackagePath() {
var fileName = path.basename(require.main.filename);

if (fileName === 'interceptor.js') {
if (require.main.children.length > 0) {
return require.main.children[0].filename;
}
}

return require.main.filename;
}

module.exports = {
parseJSON: parseJSON,
isFunction: isFunction,
Expand All @@ -115,5 +129,6 @@ module.exports = {
removeDupesInPlace: removeDupesInPlace,
isURL: isURL,
isWindows: /^win/.test(os.platform()),
getDefaultShortName: getDefaultShortName
getDefaultShortName: getDefaultShortName,
getRootPackagePath: getRootPackagePath
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "manifoldjs-lib",
"version": "1.0.0",
"version": "1.0.1",
"description": "ManifoldJS Core Library",
"repository": {
"type": "git",
Expand Down

0 comments on commit 1b56db1

Please sign in to comment.