]>
git.immae.eu Git - github/fretlink/purs-loader.git/blob - src/source-maps.js
3 const Promise
= require('bluebird');
5 const fs
= require('fs');
7 const path
= require('path');
9 const debug_
= require('debug');
11 const debugVerbose
= debug_('purs-loader:verbose');
13 module
.exports
= function sourceMap(psModule
, js
) {
14 const options
= psModule
.options
;
16 const jsPath
= psModule
.jsPath
;
18 const srcPath
= psModule
.srcPath
;
20 const source
= psModule
.source
;
22 const remainingRequest
= psModule
.remainingRequest
;
24 const sourceMapPath
= path
.join(path
.dirname(jsPath
), 'index.js.map');
26 const isSourceMapsEnabled
= options
.pscArgs
&& options
.pscArgs
.sourceMaps
;
28 return new Promise((resolve
, reject
) => {
29 if (!isSourceMapsEnabled
) {
36 debugVerbose('loading source map %s', sourceMapPath
);
38 fs
.readFile(sourceMapPath
, 'utf-8', (error
, result
) => {
44 const map
= Object
.assign(JSON
.parse(result
), {
48 file: path
.normalize(srcPath
),
54 const jsRemovedMapUrl
= js
.replace(/^\/\/# sourceMappingURL
=[^\r\n]*/gm
, '')