Skip to content

Commit

Permalink
Fix forking server
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviut committed Aug 15, 2019
1 parent 2105046 commit eeca1ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
45 changes: 21 additions & 24 deletions src/frontend/assets/classes/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,39 @@ import {CompileResult} from '../../../interfaces'

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

import TypescriptAsset from 'parcel-bundler/src/assets/TypeScriptAsset'

export interface TranspileAsset extends JSAsset {
config: Promise<Configuration>

transpile(code: string): Promise<string>
}

export function MakeTranspileAsset(name: string, options: any): {new(): TranspileAsset} {
const {parser} = options
const Asset = parser.findParser('file.js') as typeof JSAsset

return class TSAsset extends Asset {
public readonly config: Promise<Configuration>
private readonly transpiler: Promise<Transpiler>
export class MakeTranspileAsset extends TypescriptAsset {
public readonly config: Promise<Configuration>
private readonly transpiler: Promise<Transpiler>

constructor() {
super(name, options)
constructor(name: string, options: any) {
super(name, options)

this.config = loadConfiguration(name, options.rootDir)
this.transpiler = this.config.then(config =>
new Transpiler(config)
)
}
this.config = loadConfiguration(name, options.rootDir)
this.transpiler = this.config.then(config =>
new Transpiler(config)
)
}

public async parse(code: string) {
this.contents = await this.transpile(code)
public async parse(code: string) {
this.contents = await this.transpile(code)

// 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 async transpile(code: string): Promise<string> {
const transpiler = await this.transpiler
const {sources} = transpiler.transpile(code, this.name)
public async transpile(code: string): Promise<string> {
const transpiler = await this.transpiler
const {sources} = transpiler.transpile(code, this.name)

return processSourceMaps(this, sources).js
}
return processSourceMaps(this, sources).js
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/assets/forked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {IPCClient} from '../../backend/worker/client'
import {MakeTranspileAsset} from './classes/transpile'

export = function(name: string, options: any): any {
return new (class extends MakeTranspileAsset(name, options) {
return new (class extends MakeTranspileAsset {
public async transpile(code: string) {
const config = await this.config
const reportErrors = !config.typescript.options.noEmitOnError
Expand All @@ -25,5 +25,5 @@ export = function(name: string, options: any): any {

return super.transpile(code)
}
})()
})(name, options)
}
2 changes: 1 addition & 1 deletion src/frontend/assets/transpile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {MakeTranspileAsset, TranspileAsset} from './classes/transpile'

export = function(name: string, options: any): TranspileAsset {
return new (MakeTranspileAsset(name, options))()
return new MakeTranspileAsset(name, options)
}

0 comments on commit eeca1ff

Please sign in to comment.