Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
},
"peerDependencies": {
"parcel-bundler": "^1.9.0",
"typescript": "^2.4.0"
"typescript": "^3.4.5"
},
"dependencies": {
"@babel/code-frame": "^7.0.0-beta.34",
"@types/parcel-bundler": "^1.12.0",
"body-parser": "^1.18.2",
"chalk": "^2.3.0",
"comment-json": "^1.1.3",
"express": "^4.16.2",
"find-up": "^2.1.0",
"normalize-path": "^2.1.1",
"resolve-from": "^4.0.0",
"tmp": "^0.0.33",
"find-up": "^3.0.0",
"normalize-path": "^3.0.0",
"resolve-from": "^5.0.0",
"tmp": "^0.1.0",
"tslib": "^1.8.1",
"uuid": "^3.1.0"
},
Expand All @@ -39,16 +40,16 @@
"@types/comment-json": "^1.1.0",
"@types/express": "^4.11.0",
"@types/find-up": "^2.1.1",
"@types/node": "~7.0.0",
"@types/resolve-from": "^0.0.18",
"@types/tmp": "^0.0.33",
"@types/node": "~11.13.8",
"@types/resolve-from": "^5.0.1",
"@types/tmp": "^0.1.0",
"@types/uuid": "^3.4.3",
"husky": "^0.14.3",
"husky": "^2.1.0",
"npm-run-all": "^4.1.2",
"parcel-bundler": "^1.2.0",
"standard-version": "^4.2.0",
"standard-version": "^5.0.2",
"tslint": "^5.8.0",
"tslint-eslint-rules": "^4.1.1",
"typescript": "^2.7.2"
"tslint-eslint-rules": "^5.4.0",
"typescript": "^3.4.5"
}
}
4 changes: 1 addition & 3 deletions src/backend/ipc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export class Server<RQ, RS, K extends Keys<RQ, RS> = Keys<RQ, RS>> {
private readonly app = express()
private readonly server: HTTPServer

private listening = false

constructor(name: string, handler: Handler<RQ, RS>) {
const app = this.app.use(bodyParser.json({limit: '10mb'}))

Expand All @@ -35,7 +33,7 @@ export class Server<RQ, RS, K extends Keys<RQ, RS> = Keys<RQ, RS>> {
)

this.server = app
.listen(setSocketPath(name), () => this.listening = true)
.listen(setSocketPath(name))
.on('error', err => console.error(err))
}

Expand Down
4 changes: 3 additions & 1 deletion src/backend/ipc/worker/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ process.on('message', async (message: RequestMessage<{}>) => {
try {
const result = await handler[message.method](message.data)
const response: ResponseMessage<{}> = {
id, method, type: 'response', data: {result, error: null}
// don't quite understand how this type signature is supposed to
// work (I think it's impossible to satisfy), so just cast to any.
id, method, type: 'response', data: {result, error: null} as any
}

process.send!(response)
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/assets/TypeScriptAsset.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "parcel-bundler/src/assets/TypeScriptAsset" {
import JSAsset from "parcel-bundler/lib/assets/JSAsset"

export = JSAsset;
}
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)
}
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(name: string, options: any) {
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
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"importHelpers": true,
"downlevelIteration": true,
"moduleResolution": "node",
"esModuleInterop": true,

"rootDir": "src",
"outDir": "build"
Expand Down
1 change: 0 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"no-duplicate-variable": true,
"no-string-literal": false,
"no-console": [false],
"no-unused-variable": [true],
"whitespace": [
true,
"check-operator", "check-separator", "check-type", "check-typecast"
Expand Down
Loading