Skip to content

[benchmark] Set intended environment#25402

Merged
eps1lon merged 4 commits intomui:nextfrom
eps1lon:benchmark/fix
Mar 18, 2021
Merged

[benchmark] Set intended environment#25402
eps1lon merged 4 commits intomui:nextfrom
eps1lon:benchmark/fix

Conversation

@eps1lon
Copy link
Member

@eps1lon eps1lon commented Mar 18, 2021

My assumption that mode: 'production' sets NODE_ENV to 'production' in babel-loader was wrong. We didn't actually use the babel aliases at all an instead reliead on webpack resolve.alias.

But we do want to run in production.

Test Plan:

/cc @mnajdova, @oliviertassinari
Just as a notice in case you made the same assumption as I did.

@eps1lon eps1lon added the internal Behind-the-scenes enhancement. Formerly called “core”. label Mar 18, 2021
options: { cacheDirectory: true, cwd: workspaceRoot },
options: {
cacheDirectory: true,
configFile: path.join(workspaceRoot, 'babel.config.js'),
Copy link
Member Author

Choose a reason for hiding this comment

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

Switched from cwd to an explicit configFile. cwd did mislead me because I assumed it applies to every relative filepath in the babel config. However, it only applies to the programmatic options of babel-loader:

The working directory that all paths in the programmatic options will be resolved relative to.

-- https://babeljs.io/docs/en/options#cwd

@mui-pr-bot
Copy link

mui-pr-bot commented Mar 18, 2021

No bundle size changes

Generated by 🚫 dangerJS against b874ba8

@eps1lon eps1lon marked this pull request as ready for review March 18, 2021 12:05

function resolveAliasPath(relativeToBabelConf) {
const resolvedPath = path.relative(process.cwd(), path.resolve(__dirname, relativeToBabelConf));
return `./${resolvedPath.replace('\\', '/')}`;
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, why not use an absolute path?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would prefer an absolute path as well but I recall this being problematic. You would transpile files to

import Typography from '/home/eps1lon/Development/material-ui/packages/material-ui/src/Typography';

And I think bundlers/nextjs would then treat them as external files and not transpile the imported files. Though it's very likely that this was just a symptom of another problem (that might've been fixed).

I can check this in a follow-up (want to see a full,clean CI/CD run) to make sure.

Technically, we should be able to transpile it to import Typography from 'file://home/eps1lon/Development/material-ui/packages/material-ui/src/Typography' i.e. use an actual URI which is valid in ES6 modules. Though this would require a lot of other infra work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the biggest problem is that this would result in C:\\users\eps1lon\eps1lon\Development\material-ui\packages\material-ui\src\Typography which might be considered a "remote" file (definitely by rsync). This may not be an issue but we get into really weird territory where it's hard to reason about "where" the file is.

I'm not even 100% sure if win32 paths are valid in ES6 modules. So this is all "just works" code that has no solid foundation.

Copy link
Member

Choose a reason for hiding this comment

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

Your explanation makes a lot of sense. I recall trying this change too and seeing warnings raised by rollup.

Copy link
Member Author

Choose a reason for hiding this comment

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

Though definitely right to call this out. This code has now more visibility and the next person who runs into issues with that code is aware that this might just be completely wrong code.

@eps1lon eps1lon merged commit 09addbf into mui:next Mar 18, 2021
@eps1lon eps1lon deleted the benchmark/fix branch March 18, 2021 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Behind-the-scenes enhancement. Formerly called “core”.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants