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

Use babel-loader from react-scripts #5308

Merged
merged 1 commit into from
Apr 9, 2019
Merged

Conversation

mrmckeb
Copy link
Member

@mrmckeb mrmckeb commented Jan 20, 2019

Issue: #5183

What I did

This is an attempt to resolve babel-loader from react-scripts, rather than installing our own.

How to test

This is not ready to merge, it needs local testing and unit tests will be added.

@tmeasday
Copy link
Member

This seems great, but probably @igor-dv or @ndelangen should approve it as they are closer to this code

app/react/package.json Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jan 30, 2019

Codecov Report

Merging #5308 into next will increase coverage by 0.21%.
The diff coverage is 11.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #5308      +/-   ##
==========================================
+ Coverage   40.85%   41.06%   +0.21%     
==========================================
  Files         612      612              
  Lines        8486     8449      -37     
  Branches      535      411     -124     
==========================================
+ Hits         3467     3470       +3     
+ Misses       4927     4924       -3     
+ Partials       92       55      -37
Impacted Files Coverage Δ
lib/core/src/server/build-static.js 0% <ø> (ø) ⬆️
.../core/src/server/utils/load-custom-babel-config.js 0% <0%> (ø) ⬆️
app/react/src/server/framework-preset-cra.js 0% <0%> (ø) ⬆️
lib/core/src/server/manager/manager-config.js 0% <0%> (ø) ⬆️
app/react/src/server/cra-config.js 87.5% <100%> (ø) ⬆️
lib/components/src/ScrollArea/ScrollArea.tsx
lib/components/src/tooltip/WithTooltip.stories.tsx
lib/components/src/ActionBar/ActionBar.tsx
lib/components/src/tooltip/ListItem.stories.tsx
lib/components/src/form/form.stories.tsx
... and 95 more

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 bdc537e...074d0f3. Read the comment docs.

lib/core/src/server/utils/load-custom-babel-config.js Outdated Show resolved Hide resolved
lib/core/src/server/preview/preview-preset.js Outdated Show resolved Hide resolved
lib/cli/generators/REACT_SCRIPTS/index.js Outdated Show resolved Hide resolved
@mrmckeb mrmckeb force-pushed the feature/cra-babel-loader branch 3 times, most recently from 76d8f77 to 42ddd30 Compare February 3, 2019 17:24
@mrmckeb
Copy link
Member Author

mrmckeb commented Feb 3, 2019

@igor-dv, this should be ready for a re-review now. Thanks!

@VincentLanglet
Copy link

@mrmckeb Hello ! Did you try this changes ?

I did, in order to do a patch locally. This is what I did in the dist folder :

function isBabelLoader8 {
  return true

And

    resolveLoader: {
      modules: ['node_modules', _path.default.join(getReactScriptsPath(), 'node_modules')],
    },

It load but wait forever with these messages :

info => Loading create-react-app config.
webpack built b41fbb2dacde6d54f87d in 2415ms 

I found the issue come from here, @storybook/core/dist/server/dev-server.js, the managerPromise.

Promise.all([managerPromise, previewPromise])
    .then(([managerStats, previewStats]) => {
      router.get('/', (request, response) => {
        response.set('Content-Type', 'text/html');
        response.sendFile(path.join(`${outputDir}/index.html`));
      });
      router.get(/\/sb_dll\/(.+\.js)$/, (request, response) => {
        response.set('Content-Type', 'text/javascript');
        response.sendFile(path.join(`${dllPath}/${request.params[0]}`));
      });
      router.get(/\/sb_dll\/(.+\.LICENCE)$/, (request, response) => {
        response.set('Content-Type', 'text/html');
        response.sendFile(path.join(`${dllPath}/${request.params[0]}`));
      });
      router.get(/(.+\.js)$/, (request, response) => {
        response.set('Content-Type', 'text/javascript');
        response.sendFile(path.join(`${outputDir}/${request.params[0]}`));
      });

      webpackResolve({ previewStats, managerStats, managerTotalTime, previewTotalTime });
    })
    .catch(e => webpackReject(e));

The Promise.all([managerPromise, previewPromise]) is never resolved but Promise.all([previewPromise]) is.

Looking down to the managerPromise:

const managerPromise = loadManagerConfig({
    configType,
    outputDir,
    configDir,
    cache,
    corePresets: [require.resolve('./manager/manager-preset.js')],
  }).then(
    config =>
      new Promise((resolve, reject) => {
        webpack(config).watch(
          {
            aggregateTimeout: 1,
            ignored: /node_modules/,
          },
          (err, stats) => {
            managerTotalTime = process.hrtime(startTime);
            if (err) {
              reject(err);
            } else if (stats.hasErrors()) {
              reject(stats);
            } else {
              resolve(stats);
            }
          }
        );
      })
  );

Here, stats.hasErrors() return true. First question: Why the reject is silent ?

If I console.log the stats, I can see

 missingDependencies:
      SortableSet [Set] {
        '/Users/node_modules',
        '/Users/vlanglet/Project/myPath/node_modules/babel-loader',
        '/Users/vlanglet/Project/myPath/node_modules/babel-loader.js',
        '/Users/vlanglet/Project/myPath/node_modules/babel-loader.json',
        '/Users/vlanglet/Project/myPath/node_modules',
        '/Users/vlanglet/Project/node_modules',
        '/Users/vlanglet/node_modules',
        '/node_modules',
        _sortFn: undefined,
        _lastActiveSortFn: undefined,
        _cache: undefined,
        _cacheOrderIndependent: undefined
       } 

So either there is something else to do in your PR, or I got it wrong.
I'll keep looking for a solution.

@VincentLanglet
Copy link

@mrmckeb Adding

resolveLoader: {
  modules: ['node_modules', _path.default.join(process.cwd() + '/node_modules/react-scripts', 'node_modules')],
}

In the @storybook/core/dist/server/manager/manager-webpack-config.js fix the problem.

So I think you have to do something in @storybook/core/src/server/manager/manager-webpack-config.js.

@mrmckeb
Copy link
Member Author

mrmckeb commented Feb 10, 2019

Hi @VincentLanglet, I've been a little stalled on this work sorry, but plan to pick it back up this week.

This was more of a POC, it's not ready to merge yet.

@VincentLanglet
Copy link

@mrmckeb Hi ! I know it was a POC, I just tried to help you to finish this PR.
Thanks to your starting work I was able to create a patch (with patch-package) in my project ; I explained to you what I did more.

@ndelangen ndelangen self-assigned this Feb 14, 2019
@VincentLanglet
Copy link

Hello @mrmckeb ; do you need some help ? :)

@mrmckeb
Copy link
Member Author

mrmckeb commented Mar 25, 2019

Hi @shilman, sorry I was away, and I'm back home again. I've just completed a PR for create-react-app (CRA) to add templates support, and we were thinking of ways to support this at that time - but didn't come up with a silver bullet.

There were a few suggestions, and I think I'll start this branch again (as it was originally built on Storybook v4) and update the PR this week (or this weekend).

@igor-dv had previously stated that he felt this was a little "hacky" *#5308 (diff) - and whilst I don't agree, I can certainly try to find another approach. The issue is that it seems that core takes a lot of the responsibility, and I'm not sure that there will be a cleaner approach to solve this.

@mrmckeb
Copy link
Member Author

mrmckeb commented Mar 31, 2019

Hi all, this version is a little simplified and tests are now working. Sorry again for the long delay before reworking.

CC @shilman @igor-dv @VincentLanglet

If you're still seeing the previous issue, @VincentLanglet, it would be really helpful to see the output of an npm ls on your system.

@VincentLanglet
Copy link

VincentLanglet commented Apr 1, 2019

@mrmckeb Since the new storybook version, I have no issue and I don't need any patch.
But it's maybe only temporary.

My npm ls is too big for a copy paste...

@mrmckeb
Copy link
Member Author

mrmckeb commented Apr 1, 2019

Thanks @VincentLanglet - I meant to write npm ls babel-loader 😆 Sorry!

BUT, I have reproduced your issue and I'm working on a fix.

This issue will reappear next time CRA and Storybook go out of sync, so it needs to be fixed at some stage. Thanks :)

@vercel
Copy link

vercel bot commented Apr 7, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://monorepo-git-feature-cra-babel-loader.storybook.now.sh

@mrmckeb
Copy link
Member Author

mrmckeb commented Apr 7, 2019

Thanks @igor-dv, I've solved the last issue. This is now (finally) ready for a re-review.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

let's let the webpack gurus weigh in but LGTM

}));
return satisfies(babelLoaderPkg.version, '>=8.0.0-0');
} catch (e) {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

In what case there will be an error here ? do we want to hide 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.

Good question @igor-dv. This happens when babel-loader isn't in the root of node_modules. When testing, this was sufficient to handle the error and still load successfully.

@igor-dv
Copy link
Member

igor-dv commented Apr 8, 2019

Something is happening with CI. It shows that the artefact size decreased dramatically. Maybe the build-storybook is not working or something ?

@mrmckeb
Copy link
Member Author

mrmckeb commented Apr 8, 2019

@igor-dv, I've rebased and I'm pushing up again to see if that helps.

Otherwise, do you think it could be related to this? It's the only related change I can think of - but seems odd.
https://github.com/storybooks/storybook/pull/5308/files#diff-329a7cb6ceb533e8db66ba0c81dda4a0R123

@igor-dv
Copy link
Member

igor-dv commented Apr 8, 2019

Can't thing about something specific.. can you try to build-storybook locally and check if it's working ?

@mrmckeb
Copy link
Member Author

mrmckeb commented Apr 8, 2019

@igor-dv It looks like it was that change. I've removed for now as it isn't needed for this PR I believe (correct me if I'm wrong).

@igor-dv
Copy link
Member

igor-dv commented Apr 8, 2019

@mrmckeb, but then the managerWebpack won't work in the framework presets, am I wrong ?

@igor-dv
Copy link
Member

igor-dv commented Apr 8, 2019

I mean, that what fixed it, right ?

@mrmckeb
Copy link
Member Author

mrmckeb commented Apr 8, 2019

@igor-dv I only made that change to align with dev-server - a change someone else had already made before I got there... but it looks like that may be required for build-static too.

Passing in all options was breaking everything, so I'll try just passing in what's required. Waiting for the CI...

@mrmckeb
Copy link
Member Author

mrmckeb commented Apr 8, 2019

@igor-dv That fixed it, the previously failing tests are now passing. I've just squashed my commits and will merge once the CI has completed again.

Thanks for your help.

@mrmckeb mrmckeb merged commit 423edd1 into next Apr 9, 2019
@mrmckeb mrmckeb deleted the feature/cra-babel-loader branch April 9, 2019 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cra Prioritize create-react-app compatibility react
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants