-
Notifications
You must be signed in to change notification settings - Fork 492
Added the abillity to import js and jsx files with ts-loader #242
Changes from 11 commits
9a1dc3d
11630d6
353282d
9c17cd9
edcf231
0b6dac3
2122eb5
783abf1
a1c9ebf
cf4964e
7ad8514
506506e
80c3f0d
ff4fc18
1e0a7e4
f9e680f
5a75e0e
69eaa28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// @remove-file-on-eject | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
const babelJest = require('babel-jest'); | ||
|
||
module.exports = babelJest.createTransformer({ | ||
presets: [require.resolve('babel-preset-react-app')], | ||
babelrc: false, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ module.exports = { | |
// please link the files into your node_modules/ and let module-resolution kick in. | ||
// Make sure your source files are compiled, as they will not be processed in any way. | ||
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), | ||
new TsconfigPathsPlugin({configFile: paths.appTsConfig}) | ||
new TsconfigPathsPlugin({ configFile: paths.appTsConfig }), | ||
], | ||
}, | ||
module: { | ||
|
@@ -162,7 +162,7 @@ module.exports = { | |
}, | ||
// Compile .tsx? | ||
{ | ||
test: /\.(ts|tsx)$/, | ||
test: /\.(ts|tsx|js|jsx)$/, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... I don't think it's a good idea to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, no that's a very good point. I think we should load 'em all through ts-loader / ts-jest then. iirc ts-jest has no problems processing js. Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd still be concerned about potential differences from processing them with I'd favor to go the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if I'm understanding you right, what you're afraid of, is that the javascript code would behave different in CRA and CRA+TS ? I don't think babel is the right way to go, we considered it as well (replacing ts-jest with just babel. See our discussion here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
At least when users are migrating or re-using components that have been created to work with CRA or similar setups, yes. import React from "react"; The import * as React from "react"; But I doubt that those who were using Don't get me wrong: I'd only take
Additionally, this would be easier to maintain, since this rule can just be copied from upstream. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. Some valid concerns. So babel-loader for jsx files, and babel-jest (iirc is the loader that's normally used) for jest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I suppose that's preferable. |
||
include: paths.appSrc, | ||
use: [ | ||
{ | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,6 +22,8 @@ | |||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
"dependencies": { | ||||||||||||||||||||||||||||||||||||||||||
"autoprefixer": "7.1.6", | ||||||||||||||||||||||||||||||||||||||||||
"babel-jest": "^22.1.0", | ||||||||||||||||||||||||||||||||||||||||||
"babel-preset-react-app": "^3.1.1", | ||||||||||||||||||||||||||||||||||||||||||
"case-sensitive-paths-webpack-plugin": "2.1.1", | ||||||||||||||||||||||||||||||||||||||||||
"chalk": "1.1.3", | ||||||||||||||||||||||||||||||||||||||||||
"css-loader": "0.28.7", | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -31,7 +33,7 @@ | |||||||||||||||||||||||||||||||||||||||||
"fork-ts-checker-webpack-plugin": "^0.2.8", | ||||||||||||||||||||||||||||||||||||||||||
"fs-extra": "3.0.1", | ||||||||||||||||||||||||||||||||||||||||||
"html-webpack-plugin": "2.29.0", | ||||||||||||||||||||||||||||||||||||||||||
"jest": "20.0.4", | ||||||||||||||||||||||||||||||||||||||||||
"jest": "22.1.4", | ||||||||||||||||||||||||||||||||||||||||||
"object-assign": "4.1.1", | ||||||||||||||||||||||||||||||||||||||||||
"postcss-flexbugs-fixes": "3.2.0", | ||||||||||||||||||||||||||||||||||||||||||
"postcss-loader": "2.0.8", | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -41,7 +43,7 @@ | |||||||||||||||||||||||||||||||||||||||||
"source-map-loader": "^0.2.1", | ||||||||||||||||||||||||||||||||||||||||||
"style-loader": "0.19.0", | ||||||||||||||||||||||||||||||||||||||||||
"sw-precache-webpack-plugin": "0.11.4", | ||||||||||||||||||||||||||||||||||||||||||
"ts-jest": "^20.0.7", | ||||||||||||||||||||||||||||||||||||||||||
"ts-jest": "22.0.1", | ||||||||||||||||||||||||||||||||||||||||||
"ts-loader": "^2.3.7", | ||||||||||||||||||||||||||||||||||||||||||
"tsconfig-paths-webpack-plugin": "^2.0.0", | ||||||||||||||||||||||||||||||||||||||||||
"tslint": "^5.7.0", | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -54,7 +56,8 @@ | |||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
"devDependencies": { | ||||||||||||||||||||||||||||||||||||||||||
"react": "^15.5.4", | ||||||||||||||||||||||||||||||||||||||||||
"react-dom": "^15.5.4" | ||||||||||||||||||||||||||||||||||||||||||
"react-dom": "^15.5.4", | ||||||||||||||||||||||||||||||||||||||||||
"typescript": "^2.6.2" | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll check it out, but Travis crashed if typescript wasn't installed and I tried to run the tests without the cache. Internally ts-jest uses typescript as a peer-dependency, and the tests are written in typescript, so the package needs typescript as a dependency somehow. I think the reason it used to work was that Travis cached the typescript package. I'll research the travis issue a little bit more though, to make sure that we're not adding it needlessly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's currently added via the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean here? It doesn't seem to me like the init script is copying the devDependencies over? Only the predefined ones in 'types' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it executes a child process that runs create-react-app-typescript/packages/react-scripts/scripts/init.js Lines 107 to 126 in 7149b37
But as mentioned above, this only reliably happens in the "regular" (i.e.: user based) workflow, and it is possible that the tests are not heading this way. |
||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
"peerDependencies": { | ||||||||||||||||||||||||||||||||||||||||||
"typescript": "2.x" | ||||||||||||||||||||||||||||||||||||||||||
|
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.
Just recognized: This legal information is outdated, everything is using MIT currently. Don't think its a good idea to keep this.
The original version can be found here:
https://github.com/facebook/create-react-app/blob/next/packages/react-scripts/config/jest/babelTransform.js: