Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
error if attempting to preprocess typescript file but typescript opti…
Browse files Browse the repository at this point in the history
…on is not set
  • Loading branch information
chrisbreiding committed May 21, 2020
1 parent 772548d commit 36d77a8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const typescriptExtensionRegex = /\.tsx?$/
const errorTypes = {
TYPESCRIPT_AND_TSIFY: 'TYPESCRIPT_AND_TSIFY',
TYPESCRIPT_NONEXISTENT: 'TYPESCRIPT_NONEXISTENT',
TYPESCRIPT_NOT_CONFIGURED: 'TYPESCRIPT_NOT_CONFIGURED',
TYPESCRIPT_NOT_STRING: 'TYPESCRIPT_NOT_STRING',
}

Expand Down Expand Up @@ -193,6 +194,15 @@ const preprocessor = (options = {}) => {
const browserifyOptions = await getBrowserifyOptions(filePath, options.browserifyOptions, options.typescript)
const watchifyOptions = Object.assign({}, defaultOptions.watchifyOptions, options.watchifyOptions)

if (!options.typescript && typescriptExtensionRegex.test(filePath)) {
throwError({
type: errorTypes.TYPESCRIPT_NOT_CONFIGURED,
message: `You are attempting to preprocess a TypeScript file, but do not have TypeScript configured. Pass the 'typescript' option to enable TypeScript support.
The file: ${filePath}`,
})
}

const bundler = browserify(browserifyOptions)

if (file.shouldWatch) {
Expand Down
26 changes: 26 additions & 0 deletions test/unit/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,32 @@ describe('browserify preprocessor', function () {
expect(err.message).to.include(`It looks like you passed the 'typescript' option and also specified a browserify transform for TypeScript. This may cause conflicts`)
})
})

it('throws error when processing .ts file and typescript option is not set', function () {
this.options.typescript = undefined
this.file.filePath = 'path/to/file.ts'

return this.run()
.then(shouldntResolve)
.catch((err) => {
verifyErrorIncludesPrefix(err)
expect(err.type).to.equal(preprocessor.errorTypes.TYPESCRIPT_NOT_CONFIGURED)
expect(err.message).to.include(`You are attempting to preprocess a TypeScript file, but do not have TypeScript configured. Pass the 'typescript' option to enable TypeScript support`)
expect(err.message).to.include('path/to/file.ts')
})
})

it('throws error when processing .tsx file and typescript option is not set', function () {
this.options.typescript = undefined
this.file.filePath = 'path/to/file.tsx'

return this.run()
.then(shouldntResolve)
.catch((err) => {
verifyErrorIncludesPrefix(err)
expect(err.type).to.equal(preprocessor.errorTypes.TYPESCRIPT_NOT_CONFIGURED)
expect(err.message).to.include(`You are attempting to preprocess a TypeScript file, but do not have TypeScript configured. Pass the 'typescript' option to enable TypeScript support`)
expect(err.message).to.include('path/to/file.tsx')
})
})
})
Expand Down

0 comments on commit 36d77a8

Please sign in to comment.