-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript #90
TypeScript #90
Conversation
|
||
const { code: tsLoader, assets: tsLoaderAssets } = await ncc( | ||
__dirname + "/../src/ts-loader" | ||
); |
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.
Added this
if ( | ||
Object.keys(cliAssets).length || | ||
Object.keys(indexAssets).length || | ||
Object.keys(tsLoaderAssets).length || |
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.
Added this
scripts/build.js
Outdated
} | ||
|
||
writeFileSync(__dirname + "/../dist/ncc/cli.js", cli); | ||
writeFileSync(__dirname + "/../dist/ncc/index.js", index); | ||
writeFileSync(__dirname + "/../dist/ncc/ts-loader.js", tsLoader); |
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.
Added this
src/index.js
Outdated
|
||
const SUPPORTED_EXTENSIONS = [".js", ".mjs", ".json"]; | ||
const SUPPORTED_EXTENSIONS = [".ts", ".tsx", ".js", ".mjs", ".json"]; |
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.
Added this
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.
Do we want to support ".tsx" or just ".ts"? Just seems like then we should be supporting ".jsx" as well?
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.
@guybedford .tsx
is officially supported by TypeScript, but .jsx
is not (by either TS or Node)
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 understand that, it just seems a little inconsistent to me that jsx can be supported through TS only... I don't think Deno supports tsx for example.
test: /\.(js|mjs)/, | ||
test: /\.tsx?$/, | ||
use: [{ loader: __dirname + "/ts-loader.js" }] | ||
}, |
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.
Added this
src/ts-loader.js
Outdated
// optional bundle for the ts-loader, that | ||
// doesn't get loaded unless the user is | ||
// compiling typescript | ||
module.exports = require("ts-loader"); |
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.
Added this
test/index.test.js
Outdated
module.exports && module.exports.default | ||
? module.exports.default | ||
: module.exports; | ||
if ("function" !== typeof exp) { |
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.
Added this
} | ||
} | ||
|
||
for (const integrationTest of fs.readdirSync(__dirname + "/integration")) { | ||
// ignore e.g.: `.json` files | ||
if (!integrationTest.endsWith(".js")) continue; | ||
if (!/\.(mjs|tsx?|js)$/.test(integrationTest)) continue; |
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.
Added this
test/index.test.js
Outdated
throw new Error( | ||
`Integration test "${integrationTest}" evaluation failed. It does not export a function` | ||
); | ||
} | ||
await module.exports(); | ||
await exp(); |
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.
Added this
Codecov Report
@@ Coverage Diff @@
## master #90 +/- ##
==========================================
- Coverage 76.44% 76.15% -0.29%
==========================================
Files 7 8 +1
Lines 433 432 -1
==========================================
- Hits 331 329 -2
- Misses 102 103 +1
Continue to review full report at Codecov.
|
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.
👍 👍
src/index.js
Outdated
|
||
const SUPPORTED_EXTENSIONS = [".js", ".mjs", ".json"]; | ||
const SUPPORTED_EXTENSIONS = [".ts", ".tsx", ".js", ".mjs", ".json"]; |
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.
Do we want to support ".tsx" or just ".ts"? Just seems like then we should be supporting ".jsx" as well?
"target": "es2015" | ||
} | ||
} | ||
``` |
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 wonder if we could make the tsconfig.json
optional with the above as the default?
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.
Good observation. It's not recommended due to editor integration. In other words, e.g.: VSCode would need a mechanism to understand what rules ncc
would be using.
It's a small extra step, but keeps all tooling in sync. Plus, depending on what Node.js version the developer is targeting, the target
can be adjusted, which is quite nice.
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.
Makes sense 👍
2ca4a69
to
835171e
Compare
I've gone ahead and rebased this PR - please test it again before merging though. |
835171e
to
0b11972
Compare
I can't get it working, I've cloned the repo (because it's not published yet), ran I've also tried installing it in both ncc dir (and running Here's my file (test.tsx):
And tsconfig.json:
Here's what I get:
|
Perhaps see #118.
…On Thu, 06 Dec 2018 at 19:19, Kamil Tomšík ***@***.***> wrote:
I can't get it working, I've cloned the repo (because it's not published
yet), ran npm i && npm link and yet I still get error about missing
ts-loader.
I've also tried installing it in both ncc dir (and running npm run build
again to regenerate ncc) and also in my test dir
Here's my file (test.tsx):
console.log('Hello')
And tsconfig.json:
{
"compilerOptions": {
"lib": ["es2017"],
"target": "es2017",
"module": "commonjs",
"jsx": "react",
"experimentalDecorators": true
}
}
Here's what I get:
ncc-tsx-test$ ncc build test.tsx
Error: Hash: b30f5d0d1693b0400894
Version: webpack 4.27.1
Time: 141ms
Built at: 12/06/2018 6:16:46 PM
Asset Size Chunks Chunk Names
index.js 3.94 KiB 0 main
index.js.map 3.45 KiB 0 main
Entrypoint main = index.js index.js.map
[0] ./test.tsx 322 bytes {0} [built] [failed] [1 error]
ERROR in ./test.tsx
Module build failed (from ../ncc/dist/ncc/loaders/ts-loader.js):
Error: Cannot find module '/Users/cztomsik/Desktop/playground/ncc/dist/ncc/loaders/ts-loader.js'
at /Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:75024:9
at process._tickCallback (internal/process/next_tick.js:68:7)
at compiler.run (/Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:65133:23)
at finalCallback (/Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:66089:39)
at hooks.done.callAsync.err (/Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:66105:13)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:15151:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (/Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:14592:20)
at onCompiled (/Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:66103:21)
at hooks.afterCompile.callAsync.err (/Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:66431:14)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:15151:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (/Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:14592:20)
at compilation.seal.err (/Users/cztomsik/Desktop/playground/ncc/dist/ncc/index.js:66428:30)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAkiyjI3EsiNf0tDJyuRFoBdob5xb4kGks5u2VGogaJpZM4Y94na>
.
|
thx, it helped |
Is it possible use custom version of Typescript? |
This PR:
ts-loader.js
filetypescript
tsconfig.json
undertest/integration/
which is a requirementCloses #31