|
1 | 1 | // @flow |
2 | 2 | const Module = require('module'); |
3 | 3 | const path = require('path'); |
| 4 | +const slash = require('slash'); |
4 | 5 | const Utils = require('./index'); |
5 | 6 | const Renderer = require('../renderer'); |
6 | 7 | const Models = require('../models'); |
@@ -59,25 +60,24 @@ function replaceRelativePaths(code: string, rootPath: string): string { |
59 | 60 | const currentMatchesDouble = code.match(/(require\("\.\/)/gm); |
60 | 61 | if (parentMatchesSingle) { |
61 | 62 | for (const match of parentMatchesSingle) { |
62 | | - code = code.replace(match, `require('${rootPath}/../`); |
| 63 | + code = code.replace(match, slash(`require('${rootPath}/../`)); |
63 | 64 | } |
64 | 65 | } |
65 | 66 | if (parentMatchesDouble) { |
66 | 67 | for (const match of parentMatchesDouble) { |
67 | | - code = code.replace(match, `require("${rootPath}/../`); |
| 68 | + code = code.replace(match, slash(`require("${rootPath}/../`)); |
68 | 69 | } |
69 | 70 | } |
70 | 71 | if (currentMatchesSingle) { |
71 | 72 | for (const match of currentMatchesSingle) { |
72 | | - code = code.replace(match, `require('${rootPath}/./`); |
| 73 | + code = code.replace(match, slash(`require('${rootPath}/./`)); |
73 | 74 | } |
74 | 75 | } |
75 | 76 | if (currentMatchesDouble) { |
76 | 77 | for (const match of currentMatchesDouble) { |
77 | | - code = code.replace(match, `require("${rootPath}/./`); |
| 78 | + code = code.replace(match, slash(`require("${rootPath}/./`)); |
78 | 79 | } |
79 | 80 | } |
80 | | - |
81 | 81 | return code; |
82 | 82 | } |
83 | 83 |
|
@@ -131,6 +131,7 @@ function requireFromString(code: string, filename: string = '', optsObj: Object |
131 | 131 | reject(error); |
132 | 132 | }); |
133 | 133 | } else { |
| 134 | + console.log(code) |
134 | 135 | m._compile(code, filename); |
135 | 136 | resolve(m.exports.default); |
136 | 137 | } |
|
0 commit comments