Skip to content
This repository was archived by the owner on Mar 1, 2020. It is now read-only.

Commit 63d1960

Browse files
committed
refactored externals to be compatible with windows
1 parent 141ad8d commit 63d1960

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

index.js

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
const path = require('path');
2+
const nodeModulesPath = path.resolve(__dirname, '..', '..', 'node_modules')
23

34
module.exports = (context, request, callback) => {
5+
if(context.startsWith(nodeModulesPath)) {
6+
const module = context.replace(nodeModulesPath, '').split(path.sep).find(p => !!p)
7+
try {
8+
const pkg = require(path.resolve(nodeModulesPath, module, 'package.json'))
49

5-
if (context.indexOf('tns-core-modules') !== -1
6-
|| context.indexOf('nativescript-') !== -1
7-
|| /^tns-core-modules/i.test(request)
8-
|| /^(ui|application)/i.test(request)) {
9-
10-
if (request.indexOf('../') === 0 || request.indexOf('./') === 0) {
11-
let index = context.indexOf('node_modules') + 'node_modules'.length + 1;
12-
13-
request = path.normalize(path.join(context.substring(index).replace(/\\/g, '/'), request)).replace(/\\/g, '/');
10+
if(pkg.nativescript) {
11+
if(request.match(/^\.{0,2}(?:\/|\\\\|\\)/)) {
12+
request = path.relative(nodeModulesPath, path.resolve(context, request))
13+
}
14+
return callback(null, 'commonjs ' + request.replace(/\\|\\\\/g, '/'))
15+
}
16+
} catch(e) {
17+
// ignore
1418
}
15-
else if (/^(ui|application)/i.test(request)) {
16-
request = `tns-core-modules/${request}`.replace(/\\/g, '/');
17-
}
18-
19-
return callback(null, 'commonjs ' + request);
2019
}
2120

22-
callback();
23-
};
21+
callback()
22+
}

0 commit comments

Comments
 (0)