This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add out-of-the-tbox typescript support (#38)
* Add doc. * Migrated typescript code from cypress Move through2 to dependencies. Fix * Add typescript. * Add e2e tests for typescript. * Test .tsx file. * Reason why simple_tsify is necessary. * Test typescript options + remove babelify even if it's not the last item * Test tsx file with enzyme. * Fix test failure. * remove enzyme * use arrow function syntax * move files into lib directory * remove duplicate file * remove need to extra test files * update error message * move e2e tests to unit tests * properly nest e2e tests * make it clear where error is coming from Co-authored-by: Chris Breiding <chrisbreiding@gmail.com>
- Loading branch information
1 parent
642a671
commit 344a057
Showing
13 changed files
with
353 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
let through = require('through2') | ||
|
||
const isJson = (code) => { | ||
try { | ||
JSON.parse(code) | ||
} catch (e) { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
// tsify doesn't have transpile-only option like ts-node or ts-loader. | ||
// It means it should check types whenever spec file is changed | ||
// and it slows down the test speed a lot. | ||
// We skip this slow type-checking process by using transpileModule() api. | ||
module.exports = function (b, opts) { | ||
const chunks = [] | ||
|
||
return through( | ||
(buf, enc, next) => { | ||
chunks.push(buf.toString()) | ||
next() | ||
}, | ||
function (next) { | ||
const ts = opts.typescript | ||
const text = chunks.join('') | ||
|
||
if (isJson(text)) { | ||
this.push(text) | ||
} else { | ||
this.push(ts.transpileModule(text, { | ||
compilerOptions: { | ||
esModuleInterop: true, | ||
jsx: 'react', | ||
}, | ||
}).outputText) | ||
} | ||
|
||
next() | ||
}, | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react' | ||
|
||
export default () => { | ||
return ( | ||
<div className="icon-star">icon</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
add: (a: number, b: number) => { | ||
return a + b | ||
}, | ||
} |
Oops, something went wrong.
344a057
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get
Is it because of this error when I run npm install?
SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.12: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
This hasn't been a problem earlier.
344a057
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@redReno Thanks for reporting. It's an issue with publishing after this commit. Will get it fixed and publish a new version soon.
344a057
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick fix!