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

Commit 1b56db1

Browse files
Merge pull request #24 from manifoldjs/fix-node-iis
Fix node iis
2 parents a667ec6 + bffedd9 commit 1b56db1

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

lib/log.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ var ansi = require('ansi'),
88
// that all access the global instance; otherwise, each one gets a separate
99
// instance of the logger.
1010
var log = global.manifoldjs_logger,
11-
cursor = ansi(process.stdout);
11+
cursor = ansi(process.stdout),
12+
utils = require('./utils');
1213

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

2324
try {
2425
if (!appPath) {
25-
appPath = path.dirname(require.main.filename);
26+
appPath = path.dirname(utils.getRootPackagePath());
2627
}
2728

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

6162
if (methodName !== 'write') {
62-
source = source || loggerName || getApplicationName();
63+
source = source || loggerName || getApplicationName() || 'Unknown';
6364
rawMethod(
6465
'[' + severity + new Array(Math.max(maxLenSeverity - severity.length + 1, 0)).join(' ') + '] ' +
6566
source + new Array(Math.max(maxLenSource - source.length + 1, 0)).join(' ') + ': ' +

lib/packageTools.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ var fs = require('fs'),
1010

1111
var CustomError = require('./customError'),
1212
exec = require('./processTools').exec,
13-
log = require('./log');
13+
log = require('./log'),
14+
utils = require('./utils');
1415

1516
var node_modules = 'node_modules';
1617
var packageJson = 'package.json';
@@ -66,13 +67,13 @@ function getPackageInformation (packageName, parentPackagePath) {
6667

6768
try {
6869
if (!parentPackagePath) {
69-
parentPackagePath = path.dirname(require.main.filename);
70+
parentPackagePath = path.dirname(utils.getRootPackagePath());
7071
}
7172

7273
var modulePath = parentPackagePath;
7374

7475
if (packageName) {
75-
modulePath = modulePath.endsWith(node_modules) ? modulePath : path.join(modulePath, node_modules);
76+
modulePath = (path.basename(modulePath) === node_modules) ? modulePath : path.join(modulePath, node_modules);
7677
modulePath = path.join(modulePath, packageName);
7778
}
7879
modulePath = path.join(modulePath, packageJson);
@@ -98,7 +99,7 @@ function getModuleInformation (dir) {
9899

99100
try {
100101
if (!dir) {
101-
dir = require.main.filename;
102+
dir = utils.getRootPackagePath();
102103
}
103104

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

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

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

257258
// build package list
258259
var sources = installQueue.map(function (item) {

lib/platformTools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var fileTools = require('./fileTools'),
1212
var platformConfiguration;
1313

1414
function getDefaultConfigPath () {
15-
return path.resolve(path.dirname(require.main.filename), 'platforms.json');
15+
return path.resolve(path.dirname(utils.getRootPackagePath()), 'platforms.json');
1616
}
1717

1818
function getPlatformModule(packageName, source) {

lib/utils.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

33
var os = require('os'),
4-
url = require('url');
4+
url = require('url'),
5+
path = require('path');
56

67
function parseJSON (data) {
78
try {
@@ -105,6 +106,19 @@ function getDefaultShortName (siteUrl) {
105106
return shortName;
106107
}
107108

109+
// Handle Node hosted in IIS
110+
function getRootPackagePath() {
111+
var fileName = path.basename(require.main.filename);
112+
113+
if (fileName === 'interceptor.js') {
114+
if (require.main.children.length > 0) {
115+
return require.main.children[0].filename;
116+
}
117+
}
118+
119+
return require.main.filename;
120+
}
121+
108122
module.exports = {
109123
parseJSON: parseJSON,
110124
isFunction: isFunction,
@@ -115,5 +129,6 @@ module.exports = {
115129
removeDupesInPlace: removeDupesInPlace,
116130
isURL: isURL,
117131
isWindows: /^win/.test(os.platform()),
118-
getDefaultShortName: getDefaultShortName
132+
getDefaultShortName: getDefaultShortName,
133+
getRootPackagePath: getRootPackagePath
119134
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "manifoldjs-lib",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "ManifoldJS Core Library",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)