Skip to content

Commit

Permalink
Fix build with newer parcel-bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviut committed May 1, 2019
1 parent f3045b7 commit 59e39af
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions src/frontend/assets/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,47 @@ import {Configuration, loadConfiguration} from '../../backend/config-loader'
import {IPCClient} from '../../backend/worker/client'

import {processSourceMaps} from '../../exports'
import {JSAsset} from './js-asset'

export = function MakeTranspileAsset(name: string, options: any) {
const {parser} = options
const Asset = parser.findParser('file.js') as typeof JSAsset
import TypescriptAsset from 'parcel-bundler/src/assets/TypeScriptAsset'

return new (class TSAsset extends Asset {
private readonly config: Promise<Configuration>
class TSAsset extends TypescriptAsset {
private readonly config: Promise<Configuration>

constructor() {
super(name, options)
constructor() {
super(name, options)

this.config = loadConfiguration(name, options.rootDir)
}
this.config = loadConfiguration(name, options.rootDir)
}

public async parse(): Promise<any> {
const config = await this.config
const reportErrors = !config.typescript.options.noEmitOnError
const result = await IPCClient.compile({
file: this.name,
rootDir: this.options.rootDir,
reportErrors
})
public async parse(): Promise<any> {
const config = await this.config
const reportErrors = !config.typescript.options.noEmitOnError
const result = await IPCClient.compile({
file: this.name,
rootDir: this.options.rootDir,
reportErrors
})

if(!reportErrors) {
const {diagnostics} = result
if(!reportErrors) {
const {diagnostics} = result

if(diagnostics) {
console.error(diagnostics)
if(diagnostics) {
console.error(diagnostics)

// tslint:disable:no-string-throw
throw 'TypeScript errors were found while compiling'
}
// tslint:disable:no-string-throw
throw 'TypeScript errors were found while compiling'
}
}

this.contents = processSourceMaps(this, result.sources).js
this.contents = processSourceMaps(this, result.sources).js

// Parse result as ast format through babylon
return super.parse(this.contents)
}
// Parse result as ast format through babylon
return super.parse(this.contents)
}

public generateErrorMessage(err: any) {
return err.stack || err.message || err
}
})()
public generateErrorMessage(err: any) {
return err.stack || err.message || err
}
}

export = TSAsset

0 comments on commit 59e39af

Please sign in to comment.