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

refactor: refactor some code #614

Merged
merged 4 commits into from Apr 10, 2020
Merged

refactor: refactor some code #614

merged 4 commits into from Apr 10, 2020

Conversation

hiroppy
Copy link
Member

@hiroppy hiroppy commented Apr 6, 2020

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

Improve readability.

Breaking Changes

no

Additional Info

@codecov
Copy link

codecov bot commented Apr 6, 2020

Codecov Report

Merging #614 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #614      +/-   ##
==========================================
- Coverage   99.12%   99.11%   -0.01%     
==========================================
  Files           8        8              
  Lines         228      227       -1     
  Branches       71       70       -1     
==========================================
- Hits          226      225       -1     
  Misses          2        2              
Impacted Files Coverage Δ
src/utils/setupOutputFileSystem.js 100.00% <ø> (ø)
src/middleware.js 100.00% <100.00%> (ø)
src/utils/getFilenameFromUrl.js 97.95% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 43fa897...27dac08. Read the comment docs.

@@ -1,17 +1,19 @@
import fs from 'fs';
import path from 'path';

import { pluginName } from '../constants';
Copy link
Member

Choose a reason for hiding this comment

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

No need extra require for one string, keep it as is in source code

context.compiler.hooks.done.tap('DevMiddleware', done);
context.compiler.hooks.watchRun.tap(pluginName, invalid);
context.compiler.hooks.invalid.tap(pluginName, invalid);
context.compiler.hooks.done.tap(pluginName, done);
Copy link
Member

Choose a reason for hiding this comment

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

No need extra require, we don't change these lines very often

const { options } = context;
const paths = getPaths(context.stats, options);
const memoizedParse = mem(parse);
Copy link
Member

Choose a reason for hiding this comment

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

Memorize is broken, no need create it every time on each call

@@ -5,7 +5,7 @@ import querystring from 'querystring';
import mem from 'mem';

function getPaths(stats, options) {
const childStats = stats.stats ? stats.stats : [stats];
const childStats = Array.isArray(stats.stats) ? stats.stats : [stats];
Copy link
Member

Choose a reason for hiding this comment

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

Extra check, stats.stats exists only for mutli compiler mode

ready(context, processRequest, req);
});
res.send(content);
}
Copy link
Member

Choose a reason for hiding this comment

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

This is the most important part and any change here is critical, very difficult to read

Copy link
Member

Choose a reason for hiding this comment

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

Maybe you can add comments before main steps? I think it was necessary to do this earlier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you give me a comment? So you mean move res.send(content); to prev position?

Copy link
Member

Choose a reason for hiding this comment

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

No, just add comments something like:

// Check headers
// Search file in compilation
// Setup content-length for file
// Sending file

Copy link
Member Author

Choose a reason for hiding this comment

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

If you have points which are hard to read for you, please tell me.

}
if (headers) {
for (const name in headers) {
if (Reflect.has(headers, name)) {
Copy link
Member

Choose a reason for hiding this comment

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

Bad idea

Copy link
Member Author

Choose a reason for hiding this comment

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

Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

{}.hasOwnProperty.call(headers, name) is very poorly readable.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, looks Reflect has good supporting, so it is good to use it

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, this code is unnecessary. I updated.

@hiroppy
Copy link
Member Author

hiroppy commented Apr 6, 2020

@alexander-akait
Copy link
Member

@hiroppy Let's resolve the PR with migration on github actions

@hiroppy
Copy link
Member Author

hiroppy commented Apr 6, 2020

@evilebottnawi This pr has already been done. Please review.
#611

@hiroppy
Copy link
Member Author

hiroppy commented Apr 10, 2020

CI is green.

@alexander-akait alexander-akait merged commit 0946938 into master Apr 10, 2020
@alexander-akait alexander-akait deleted the feature/refactor-code branch April 10, 2020 10:54
@alexander-akait
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants