-
Notifications
You must be signed in to change notification settings - Fork 489
added support for including node_module folders #358
Changes from all commits
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 |
---|---|---|
|
@@ -41,8 +41,8 @@ const getPublicUrl = appPackageJson => | |
// like /todos/42/static/js/bundle.7289d.js. We have to know the root. | ||
function getServedPath(appPackageJson) { | ||
const publicUrl = getPublicUrl(appPackageJson); | ||
const servedUrl = envPublicUrl || | ||
(publicUrl ? url.parse(publicUrl).pathname : '/'); | ||
const servedUrl = | ||
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/'); | ||
return ensureSlash(servedUrl, true); | ||
} | ||
|
||
|
@@ -68,6 +68,12 @@ module.exports = { | |
// @remove-on-eject-begin | ||
const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath); | ||
|
||
// create array of node_module folders that also need typescript processing | ||
const folders = process.env.REACT_APP_TYPESCRIPT_NODE_MODULES_FOLDERS; | ||
const typescriptNodeModules = !folders | ||
? [] | ||
: folders.split(' ').map(folder => resolveApp(`node_modules/${folder}`)); | ||
|
||
// config before eject: we're in ./node_modules/react-scripts/config/ | ||
module.exports = { | ||
dotenv: resolveApp('.env'), | ||
|
@@ -90,11 +96,13 @@ module.exports = { | |
// These properties only exist before ejecting: | ||
ownPath: resolveOwn('.'), | ||
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3 | ||
typescriptModules: typescriptNodeModules, | ||
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. See comment for |
||
}; | ||
|
||
const ownPackageJson = require('../package.json'); | ||
const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`); | ||
const reactScriptsLinked = fs.existsSync(reactScriptsPath) && | ||
const reactScriptsLinked = | ||
fs.existsSync(reactScriptsPath) && | ||
fs.lstatSync(reactScriptsPath).isSymbolicLink(); | ||
|
||
// config before publish: we're in ./packages/react-scripts/config/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,7 +172,7 @@ module.exports = { | |
// Compile .tsx? | ||
{ | ||
test: /\.(ts|tsx)$/, | ||
include: paths.appSrc, | ||
include: [paths.appSrc, ...(paths.typescriptModules || [])], | ||
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. See comment for |
||
use: [ | ||
{ | ||
loader: require.resolve('ts-loader'), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,7 +176,7 @@ module.exports = { | |
// Compile .tsx? | ||
{ | ||
test: /\.(ts|tsx)$/, | ||
include: paths.appSrc, | ||
include: [paths.appSrc, ...(paths.typescriptModules || [])], | ||
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. See comment for |
||
use: [ | ||
{ | ||
loader: require.resolve('ts-loader'), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ module.exports = (resolve, rootDir, isEjecting) => { | |
), | ||
}, | ||
transformIgnorePatterns: [ | ||
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$', | ||
'[/\\\\]node_modules[/\\\\](?!@zept).+\\.(js|jsx|mjs|ts|tsx)$', | ||
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. Two issue hier:
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. This is a mistake in that I updated the package for our internal use to also ensure tests processed the package as well. I feel including all packages in the transform would slow tests down too. |
||
], | ||
moduleNameMapper: { | ||
'^react-native$': 'react-native-web', | ||
|
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'd say this is a bit too complicated. Importing
ts
source files fromnode
packages is more of an exceptional than regular behavior. Extending theinclude
clause of thetsx?
rule to cover thenode_modules
folder is more simple and does not hurt anyone not using it, since it is only applied in this very specific case.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.
Are you sure? I feel like that would slow down a large project during dev builds/testing to process every package...
I think what may be best is us maintaining a fork for ourselves, and maybe I will write a medium article on what I changed for anyone else that wants to do the same; since it is a pretty limited use-case.
I don't want to decrease dev performance for all users of this package just to meet our niche requirement.