|
1 | | -import mimeTypes from '@paulcbetts/mime-types'; |
2 | 1 | import fs from 'fs'; |
3 | 2 | import zlib from 'zlib'; |
4 | 3 | import path from 'path'; |
5 | 4 | import {pfs, pzlib} from './promise'; |
6 | 5 |
|
| 6 | +import mimeTypes from './mime-types'; |
7 | 7 | import {forAllFiles, forAllFilesSync} from './for-all-files'; |
8 | 8 | import CompileCache from './compile-cache'; |
9 | 9 | import FileChangedCache from './file-change-cache'; |
10 | 10 | import ReadOnlyCompiler from './read-only-compiler'; |
11 | 11 |
|
12 | 12 | const d = require('debug-electron')('electron-compile:compiler-host'); |
13 | 13 |
|
14 | | -require('./rig-mime-types').init(); |
15 | | - |
16 | 14 | // This isn't even my |
17 | 15 | const finalForms = { |
18 | 16 | 'text/javascript': true, |
@@ -267,7 +265,6 @@ export default class CompilerHost { |
267 | 265 |
|
268 | 266 | if (hashInfo.isInNodeModules) { |
269 | 267 | let code = hashInfo.sourceCode || await pfs.readFile(filePath, 'utf8'); |
270 | | - code = await CompilerHost.fixNodeModulesSourceMapping(code, filePath, this.fileChangeCache.appRoot); |
271 | 268 | return { code, mimeType: type }; |
272 | 269 | } |
273 | 270 |
|
@@ -306,7 +303,9 @@ export default class CompilerHost { |
306 | 303 | }; |
307 | 304 | } |
308 | 305 |
|
309 | | - let ctx = {}; |
| 306 | + let ctx = { |
| 307 | + appRoot: this.appRoot, |
| 308 | + }; |
310 | 309 | let code = hashInfo.sourceCode || await pfs.readFile(filePath, 'utf8'); |
311 | 310 |
|
312 | 311 | if (!(await compiler.shouldCompileFile(code, ctx))) { |
@@ -491,7 +490,6 @@ export default class CompilerHost { |
491 | 490 |
|
492 | 491 | if (hashInfo.isInNodeModules) { |
493 | 492 | let code = hashInfo.sourceCode || fs.readFileSync(filePath, 'utf8'); |
494 | | - code = CompilerHost.fixNodeModulesSourceMappingSync(code, filePath, this.fileChangeCache.appRoot); |
495 | 493 | return { code, mimeType: type }; |
496 | 494 | } |
497 | 495 |
|
@@ -602,58 +600,4 @@ export default class CompilerHost { |
602 | 600 | static shouldPassthrough(hashInfo) { |
603 | 601 | return hashInfo.isMinified || hashInfo.isInNodeModules || hashInfo.hasSourceMap || hashInfo.isFileBinary; |
604 | 602 | } |
605 | | - |
606 | | - /** |
607 | | - * Look at the code of a node modules and see the sourceMapping path. |
608 | | - * If there is any, check the path and try to fix it with and |
609 | | - * root relative path. |
610 | | - * @private |
611 | | - */ |
612 | | - static async fixNodeModulesSourceMapping(sourceCode, sourcePath, appRoot) { |
613 | | - let regexSourceMapping = /\/\/#.*sourceMappingURL=(?!data:)([^"'].*)/i; |
614 | | - let sourceMappingCheck = sourceCode.match(regexSourceMapping); |
615 | | - |
616 | | - if (sourceMappingCheck && sourceMappingCheck[1] && sourceMappingCheck[1] !== ''){ |
617 | | - let sourceMapPath = sourceMappingCheck[1]; |
618 | | - |
619 | | - try { |
620 | | - await pfs.stat(sourceMapPath); |
621 | | - } catch (error) { |
622 | | - let normRoot = path.normalize(appRoot); |
623 | | - let absPathToModule = path.dirname(sourcePath.replace(normRoot, '').substring(1)); |
624 | | - let newMapPath = path.join(absPathToModule, sourceMapPath); |
625 | | - |
626 | | - return sourceCode.replace(regexSourceMapping, `//# sourceMappingURL=${newMapPath}`); |
627 | | - } |
628 | | - } |
629 | | - |
630 | | - return sourceCode; |
631 | | - } |
632 | | - |
633 | | - /** |
634 | | - * Look at the code of a node modules and see the sourceMapping path. |
635 | | - * If there is any, check the path and try to fix it with and |
636 | | - * root relative path. |
637 | | - * @private |
638 | | - */ |
639 | | - static fixNodeModulesSourceMappingSync(sourceCode, sourcePath, appRoot) { |
640 | | - let regexSourceMapping = /\/\/#.*sourceMappingURL=(?!data:)([^"'].*)/i; |
641 | | - let sourceMappingCheck = sourceCode.match(regexSourceMapping); |
642 | | - |
643 | | - if (sourceMappingCheck && sourceMappingCheck[1] && sourceMappingCheck[1] !== ''){ |
644 | | - let sourceMapPath = sourceMappingCheck[1]; |
645 | | - |
646 | | - try { |
647 | | - fs.statSync(sourceMapPath); |
648 | | - } catch (error) { |
649 | | - let normRoot = path.normalize(appRoot); |
650 | | - let absPathToModule = path.dirname(sourcePath.replace(normRoot, '').substring(1)); |
651 | | - let newMapPath = path.join(absPathToModule, sourceMapPath); |
652 | | - |
653 | | - return sourceCode.replace(regexSourceMapping, `//# sourceMappingURL=${newMapPath}`); |
654 | | - } |
655 | | - } |
656 | | - |
657 | | - return sourceCode; |
658 | | - } |
659 | 603 | } |
0 commit comments