A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/TypeStrong/ts-node/commit/e0a83b55d335f0a8c8bd53f5c24f6a47dedf14d4 below:

Add `--build` flag, improve TS module error (#896) · TypeStrong/ts-node@e0a83b5 · GitHub

@@ -56,6 +56,7 @@ export const VERSION = require('../package.json').version

56 56

* Registration options.

57 57

*/

58 58

export interface Options {

59 +

build?: boolean | null

59 60

pretty?: boolean | null

60 61

typeCheck?: boolean | null

61 62

transpileOnly?: boolean | null

@@ -64,8 +65,8 @@ export interface Options {

64 65

compiler?: string

65 66

ignore?: string[]

66 67

project?: string

67 -

skipIgnore?: boolean | null

68 68

skipProject?: boolean | null

69 +

skipIgnore?: boolean | null

69 70

preferTsExts?: boolean | null

70 71

compilerOptions?: object

71 72

ignoreDiagnostics?: Array<number | string>

@@ -95,19 +96,20 @@ export interface TypeInfo {

95 96

* Default register options.

96 97

*/

97 98

export const DEFAULTS: Options = {

98 -

files: yn(process.env['TS_NODE_FILES']),

99 -

pretty: yn(process.env['TS_NODE_PRETTY']),

100 -

compiler: process.env['TS_NODE_COMPILER'],

101 -

compilerOptions: parse(process.env['TS_NODE_COMPILER_OPTIONS']),

102 -

ignore: split(process.env['TS_NODE_IGNORE']),

103 -

project: process.env['TS_NODE_PROJECT'],

104 -

skipIgnore: yn(process.env['TS_NODE_SKIP_IGNORE']),

105 -

skipProject: yn(process.env['TS_NODE_SKIP_PROJECT']),

106 -

preferTsExts: yn(process.env['TS_NODE_PREFER_TS_EXTS']),

107 -

ignoreDiagnostics: split(process.env['TS_NODE_IGNORE_DIAGNOSTICS']),

108 -

typeCheck: yn(process.env['TS_NODE_TYPE_CHECK']),

109 -

transpileOnly: yn(process.env['TS_NODE_TRANSPILE_ONLY']),

110 -

logError: yn(process.env['TS_NODE_LOG_ERROR'])

99 +

files: yn(process.env.TS_NODE_FILES),

100 +

pretty: yn(process.env.TS_NODE_PRETTY),

101 +

compiler: process.env.TS_NODE_COMPILER,

102 +

compilerOptions: parse(process.env.TS_NODE_COMPILER_OPTIONS),

103 +

ignore: split(process.env.TS_NODE_IGNORE),

104 +

project: process.env.TS_NODE_PROJECT,

105 +

skipProject: yn(process.env.TS_NODE_SKIP_PROJECT),

106 +

skipIgnore: yn(process.env.TS_NODE_SKIP_IGNORE),

107 +

preferTsExts: yn(process.env.TS_NODE_PREFER_TS_EXTS),

108 +

ignoreDiagnostics: split(process.env.TS_NODE_IGNORE_DIAGNOSTICS),

109 +

typeCheck: yn(process.env.TS_NODE_TYPE_CHECK),

110 +

transpileOnly: yn(process.env.TS_NODE_TRANSPILE_ONLY),

111 +

logError: yn(process.env.TS_NODE_LOG_ERROR),

112 +

build: yn(process.env.TS_NODE_BUILD)

111 113

}

112 114 113 115

/**

@@ -191,7 +193,7 @@ function cachedLookup <T> (fn: (arg: string) => T): (arg: string) => T {

191 193

* Register TypeScript compiler.

192 194

*/

193 195

export function register (opts: Options = {}): Register {

194 -

const options = Object.assign({}, DEFAULTS, opts)

196 +

const options = { ...DEFAULTS, ...opts }

195 197

const originalJsHandler = require.extensions['.js'] // tslint:disable-line

196 198 197 199

const ignoreDiagnostics = [

@@ -201,9 +203,7 @@ export function register (opts: Options = {}): Register {

201 203

...(options.ignoreDiagnostics || [])

202 204

].map(Number)

203 205 204 -

const ignore = options.skipIgnore ? [] : (

205 -

options.ignore || ['/node_modules/']

206 -

).map(str => new RegExp(str))

206 +

const ignore = options.skipIgnore ? [] : (options.ignore || ['/node_modules/']).map(str => new RegExp(str))

207 207 208 208

// Require the TypeScript compiler and configuration.

209 209

const cwd = process.cwd()

@@ -369,31 +369,37 @@ export function register (opts: Options = {}): Register {

369 369

const sourceFile = builderProgram.getSourceFile(fileName)

370 370

if (!sourceFile) throw new TypeError(`Unable to read file: ${fileName}`)

371 371 372 -

const diagnostics = ts.getPreEmitDiagnostics(builderProgram.getProgram(), sourceFile)

372 +

const program = builderProgram.getProgram()

373 +

const diagnostics = ts.getPreEmitDiagnostics(program, sourceFile)

373 374

const diagnosticList = filterDiagnostics(diagnostics, ignoreDiagnostics)

374 375 375 376

if (diagnosticList.length) reportTSError(diagnosticList)

376 377 377 -

const result = builderProgram.emit(sourceFile, (path, file) => {

378 +

const result = builderProgram.emit(sourceFile, (path, file, writeByteOrderMark) => {

378 379

if (path.endsWith('.map')) {

379 380

output[1] = file

380 381

} else {

381 382

output[0] = file

382 383

}

384 + 385 +

if (options.build) sys.writeFile(path, file, writeByteOrderMark)

383 386

}, undefined, undefined, getCustomTransformers())

384 387 385 388

if (result.emitSkipped) {

386 389

throw new TypeError(`${relative(cwd, fileName)}: Emit skipped`)

387 390

}

388 391 389 -

// Throw an error when requiring `.d.ts` files.

392 +

// Throw an error when requiring files that cannot be compiled.

390 393

if (output[0] === '') {

394 +

if (program.isSourceFileFromExternalLibrary(sourceFile)) {

395 +

throw new TypeError(`Unable to compile file from external library: ${relative(cwd, fileName)}`)

396 +

}

397 + 391 398

throw new TypeError(

392 -

'Unable to require `.d.ts` file.\n' +

399 +

`Unable to require file: ${relative(cwd, fileName)}\n` +

393 400

'This is usually the result of a faulty configuration or import. ' +

394 -

'Make sure there is a `.js`, `.json` or another executable extension and ' +

395 -

'loader (attached before `ts-node`) available alongside ' +

396 -

`\`${basename(fileName)}\`.`

401 +

'Make sure there is a `.js`, `.json` or other executable extension with ' +

402 +

'loader attached before `ts-node` available.'

397 403

)

398 404

}

399 405

@@ -420,7 +426,8 @@ export function register (opts: Options = {}): Register {

420 426

}

421 427

}

422 428 423 -

if (config.options.incremental) {

429 +

// Write `.tsbuildinfo` when `--build` is enabled.

430 +

if (options.build && config.options.incremental) {

424 431

process.on('exit', () => {

425 432

// Emits `.tsbuildinfo` to filesystem.

426 433

(builderProgram.getProgram() as any).emitBuildInfo()


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4