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

Commit

Permalink
Use webpack to write declaration files, gives better reporting (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz authored and s-panferov committed Jun 10, 2018
1 parent ea03615 commit 1d4568a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/index.ts
@@ -1,6 +1,5 @@
import * as _ from 'lodash'
import * as path from 'path'
import * as fs from 'fs'

import { findCompiledModule, cache } from './cache'
import * as helpers from './helpers'
Expand All @@ -9,7 +8,6 @@ import { PathPlugin } from './paths-plugin'
import { CheckerPlugin as _CheckerPlugin } from './watch-mode'

const loaderUtils = require('loader-utils')
const mkdirp = require('mkdirp')

function loader(text) {
try {
Expand Down Expand Up @@ -170,8 +168,7 @@ function transform(
}

if (emitResult.declaration) {
mkdirp.sync(path.dirname(emitResult.declaration.name))
fs.writeFileSync(emitResult.declaration.name, emitResult.declaration.text)
instance.compiledDeclarations.push(emitResult.declaration)
}

return {
Expand Down
14 changes: 14 additions & 0 deletions src/instance.ts
Expand Up @@ -23,6 +23,7 @@ export interface Instance {
id: number
babelImpl?: any
compiledFiles: { [key: string]: boolean }
compiledDeclarations: { name: string; text: string }[]
configFilePath: string
compilerConfig: TsConfig
loaderConfig: LoaderConfig
Expand Down Expand Up @@ -160,6 +161,7 @@ export function ensureInstance(
id: ++id,
babelImpl,
compiledFiles: {},
compiledDeclarations: [],
loaderConfig,
configFilePath,
compilerConfig,
Expand Down Expand Up @@ -385,6 +387,7 @@ function setupWatchRun(compiler, instanceName: string) {
const lastCompiled = instance.compiledFiles

instance.compiledFiles = {}
instance.compiledDeclarations = [];
instance.startTime = startTime

const set = new Set(Object.keys(times).map(toUnix))
Expand Down Expand Up @@ -479,6 +482,17 @@ function setupAfterCompile(compiler, instanceName, forkChecker = false) {
Array.prototype.push.apply(compilation.fileDependencies, files.map(path.normalize))
})

instance.compiledDeclarations.forEach(declaration => {
const assetPath = path.relative(
compilation.compiler.context,
declaration.name
)
compilation.assets[assetPath] = {
source: () => declaration.text,
size: () => declaration.text.length
}
})

const timeStart = +new Date()
const diag = () =>
instance.loaderConfig.transpileOnly
Expand Down

0 comments on commit 1d4568a

Please sign in to comment.