Skip to content
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

Allow extensions other than .js for entry point #4012

Closed
wants to merge 3 commits into from

Conversation

detrohutt
Copy link
Contributor

@detrohutt detrohutt commented Feb 11, 2018

This is my proposed solution to #3052 and #3941.

I changed the checkRequiredFiles function to allow passing files with no extension. When a file with no extension is received, it's assumed to be a js-like file. All of the js-like file extensions will be checked.

image

I can add tests and such over the next few days but I wanted to get some eyes on this to tell me if I'm heading in the right direction.

Edit: If the number of potential disk reads is a concern I could also use fs.readdirSync() upfront and search the returned array for the different extensions.

console.log(chalk.red(' Name: ') + chalk.cyan(file.base));
if (didFallbackExts) {
// Typescript files will pass the check but are not officially supported.
const extStr = fallbackExts.filter(e => /\.(?!tsx?)/.test(e)).join(', ');
Copy link
Contributor Author

@detrohutt detrohutt Feb 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included .ts and .tsx files but filtered them from the "Supported extensions" string. If you're not ok with this I'll change it, but I'd really love to see (and help with) any movement towards supporting Typescript, even if it's unofficial/undocumented just to make life easier for packages like the one I'm using. I realize the README suggests using create-react-app-typescript, but I prefer react-app-rewired(problem described in docs) because it doesn't "lag behind" when you guys update since it uses react-scripts unmodified, and I love to stay on the bleeding edge!

// If other types of files need to be passed later without extensions the
// checkRequiredFiles function will need to be modified.
const fallbackExts = [
'.web.js',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figure I should probably reorder this so .js is at the top since that's the file that will be there by default and I don't want to create unnecessary disk reads. This function just allows the run/build to continue anyway, it doesn't actually decide what file ends up resolved, just makes sure that there's at least one valid option.

for (const filePath of files) {
const file = path.parse(filePath);

if (file.ext === '') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered making this

if (file.ext === '' || !fs.existsSync(filePath))

so that files with extensions that aren't found would also be checked with fallbacks. But since at the moment the only file other than index.js being required is a .html file, that seemed a bad idea. If this function sees more use in the future, that concept could be revisited.

@detrohutt
Copy link
Contributor Author

@iansu I'm ready to continue working on this as soon as anyone gets a chance to offer some feedback. :)

@@ -54,7 +54,7 @@ module.exports = {
appBuild: resolveApp('build'),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
appIndexJs: resolveApp('src/index.js'),
appIndexJs: resolveApp('src/index'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
testsSetup: resolveApp('src/setupTests.js'),
Copy link

@lnhrdt lnhrdt Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@detrohutt: consider removing the .js extension on src/setupTests to generify this file as well (3 instances total in packages/react-scripts/config/paths.js).

@Timer Timer added this to the 2.0.0 milestone Apr 21, 2018
@Timer Timer closed this Sep 26, 2018
@Timer Timer reopened this Sep 26, 2018
@Timer Timer modified the milestones: 2.0.x, 2.x Sep 26, 2018
@brunolemos
Copy link
Contributor

brunolemos commented Oct 23, 2018

This is on master since #4837.

These are now accepted as an entry point:

  • index.js
  • index.jsx
  • index.mjs
  • index.ts
  • index.tsx
  • index.web.js
  • index.web.jsx
  • index.web.mjs
  • index.web.ts
  • index.web.tsx

These can be closed: #4012, #3941

@detrohutt detrohutt closed this Oct 23, 2018
@Timer Timer modified the milestones: 2.x, 2.1 Oct 23, 2018
@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants