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

Commit a606ed8

Browse files
author
Stanislav Panferov
committed
fix(*): fix program update issue
1 parent 0a2f1ce commit a606ed8

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/index.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,15 @@ async function compiler(webpack: IWebPack, text: string): Promise<void> {
9090
state.fileAnalyzer.dependencies.addCompiledModule(fileName, compiledModule.fileName);
9191
transformation = {
9292
text: compiledModule.text,
93-
map: JSON.parse(compiledModule.map)
93+
map: compiledModule.map
94+
? JSON.parse(compiledModule.map)
95+
: null
9496
}
9597
} else {
9698

9799
function transform() {
98100
let resultText;
99-
let resultSourceMap;
101+
let resultSourceMap = null;
100102
let output = state.emit(fileName);
101103

102104
let result = helpers.findResultFor(output, fileName);
@@ -106,14 +108,20 @@ async function compiler(webpack: IWebPack, text: string): Promise<void> {
106108
}
107109

108110
resultText = result.text;
109-
resultSourceMap = JSON.parse(result.sourceMap);
110-
resultSourceMap.sources = [ fileName ];
111-
resultSourceMap.file = fileName;
112-
resultSourceMap.sourcesContent = [ text ];
111+
112+
if (result.sourceMap) {
113+
resultSourceMap = JSON.parse(result.sourceMap);
114+
resultSourceMap.sources = [ loaderUtils.getRemainingRequest(webpack) ];
115+
resultSourceMap.file = fileName;
116+
resultSourceMap.sourcesContent = [ text ];
117+
118+
resultText = resultText.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
119+
}
113120

114121
if (instance.options.useBabel) {
115122
let defaultOptions = {
116123
inputSourceMap: resultSourceMap,
124+
sourceRoot: process.cwd(),
117125
filename: fileName,
118126
sourceMap: true
119127
}

src/instance.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ export function ensureInstance(webpack: IWebPack, options: ICompilerOptions, ins
160160

161161
let babelImpl: any;
162162
if (options.useBabel) {
163+
console.error('babel')
163164
try {
164-
babelImpl = require(path.join(process.cwd(), 'node_modules', 'babel'));
165+
babelImpl = require(path.join(process.cwd(), 'node_modules', 'babel-core'));
165166
} catch (e) {
166167
console.error(BABEL_ERROR);
167168
process.exit(1);
@@ -262,6 +263,12 @@ function setupAfterCompile(compiler, instanceName, forkChecker = false) {
262263
payload
263264
});
264265
} else {
266+
if (!state.program) {
267+
// program may be undefined here, if all files
268+
// will be loaded by tsconfig
269+
state.updateProgram();
270+
}
271+
265272
let diagnostics = state.ts.getPreEmitDiagnostics(state.program);
266273
let emitError = (err) => {
267274
if (compilation.bail) {

0 commit comments

Comments
 (0)