-
Notifications
You must be signed in to change notification settings - Fork 489
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
feat!: migrate to ESM #2092
feat!: migrate to ESM #2092
Changes from 35 commits
50ba488
d5ce138
64321da
8807176
5e41cac
ec82663
5aa8035
ac3460d
977c5a6
c1529e3
039c430
e1ef368
e1f0c9b
5c2563a
3bb96fc
b2cb7ab
25eb3b1
72cc358
e4f2cbb
7baa706
cc8bae0
4e27c4f
69f1dd1
1c62aba
c8dbbb5
1d295ef
2db8cb7
65846ee
39137a7
3fb7238
68c0136
bb6f391
05e5c19
c918b83
785771c
32c2049
5218305
8b64be5
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 |
---|---|---|
@@ -1,19 +1,18 @@ | ||
/* eslint-disable import/esm-extensions */ | ||
/** | ||
* @file StoryBook configuration file | ||
* @see https://github.com/storybookjs/storybook/blob/master/MIGRATION.md#from-version-52x-to-53x | ||
*/ | ||
|
||
const webpack = require('webpack') | ||
|
||
const { webpack: webpackOverride } = require('../config-overrides') | ||
|
||
/** @type {import('@storybook/core-common').StorybookConfig} */ | ||
const storybookConfig = { | ||
core: { | ||
builder: 'webpack5' | ||
}, | ||
reactOptions: { | ||
legacyRootApi: true | ||
legacyRootApi: false | ||
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. No need to disable this anymore. https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react18-new-root-api |
||
}, | ||
stories: [ | ||
'../src/**/*.stories.@(ts|js|tsx|jsx)' | ||
|
@@ -35,11 +34,32 @@ const storybookConfig = { | |
], | ||
features: { | ||
postcss: false, | ||
storyStoreV7: true | ||
storyStoreV7: true, | ||
babelModeV7: true | ||
Comment on lines
+37
to
+38
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. getting ready for v7 |
||
}, | ||
webpackFinal: async (config) => { | ||
// console.log('config: ', config) | ||
SgtPooki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { webpack: webpackOverride } = (await import('../config-overrides.js')).default | ||
|
||
config.module.rules.push({ | ||
test: /\.(m?js)$/, | ||
type: 'javascript/auto', | ||
resolve: { | ||
fullySpecified: false | ||
} | ||
}) | ||
return webpackOverride({ | ||
...config, | ||
resolve: { | ||
...config.resolve, | ||
alias: { | ||
...config.resolve.alias | ||
}, | ||
extensions: [ | ||
...config.resolve.extensions, | ||
'dist/esm/index.js' | ||
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. fixes some issues with imports that don't have proper export fields; or our tools (playwright/storybook) that don't handle ESM packages properly. |
||
] | ||
}, | ||
// @see https://github.com/storybookjs/storybook/issues/18276#issuecomment-1137101774 | ||
plugins: config.plugins.map(plugin => { | ||
if (plugin.constructor.name === 'IgnorePlugin') { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import React from 'react' | ||
import { Provider } from 'redux-bundler-react' | ||
import { I18nextProvider } from 'react-i18next' | ||
import { DndProvider } from 'react-dnd' | ||
import 'react-virtualized/styles.css' | ||
import '../src/index.css' | ||
|
||
import getStore from '../src/bundles' | ||
import i18n from '../src/i18n' | ||
import DndBackend from '../src/lib/dnd-backend' | ||
import getStore from '../src/bundles/index.js' | ||
import i18n from '../src/i18n.js' | ||
import DndBackend from '../src/lib/dnd-backend.js' | ||
|
||
/** | ||
* @type {import('@storybook/addons').BaseAnnotations} | ||
|
@@ -38,3 +39,8 @@ const baseAnnotations = { | |
|
||
export const decorators = baseAnnotations.decorators | ||
export const argTypes = baseAnnotations.argTypes | ||
|
||
// module.exports = { | ||
// decorators: baseAnnotations.decorators, | ||
// argTypes: baseAnnotations.argTypes | ||
// } | ||
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. will remove |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
module.exports = { | ||
presets: ['@babel/preset-react'] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
* @see https://github.com/facebook/create-react-app/issues/11756#issuecomment-1184657437 | ||
* @see https://alchemy.com/blog/how-to-polyfill-node-core-modules-in-webpack-5 | ||
*/ | ||
const webpack = require('webpack') | ||
import webpack from 'webpack' | ||
|
||
const PURE_ESM_MODULES = [ | ||
'ipfs-geoip' | ||
] | ||
|
@@ -67,14 +68,13 @@ function modifyBabelLoaderRuleForTest (rules) { | |
}) | ||
} | ||
|
||
function webpackOverride(config) { | ||
function webpackOverride (config) { | ||
const fallback = config.resolve.fallback || {} | ||
|
||
Object.assign(fallback, { | ||
assert: require.resolve('./src/webpack-fallbacks/assert'), | ||
stream: require.resolve('./src/webpack-fallbacks/stream'), | ||
os: require.resolve('./src/webpack-fallbacks/os'), | ||
path: require.resolve('./src/webpack-fallbacks/path') | ||
stream: 'stream-browserify', | ||
os: 'os-browserify/browser', | ||
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. does this need to be browser? 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. in all honesty, yes it does, doesn't it? We don't really have any instance of a backend web-server for webui. Even in ipfs-desktop, it's "serving" the content from So in all honesty, this is a very lazy way to not split up the build deps from the runtime deps, but we're not quite there yet. |
||
path: 'path-browserify' | ||
Comment on lines
+75
to
+77
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. we can import these directly again |
||
}) | ||
|
||
config.resolve.fallback = fallback | ||
|
@@ -87,6 +87,20 @@ function webpackOverride(config) { | |
]) | ||
|
||
config.module.rules = modifyBabelLoaderRuleForBuild(config.module.rules) | ||
config.module.rules.push({ | ||
test: /\.(js|jsx)$/, | ||
SgtPooki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exclude: /(node_modules|bower_components)/, | ||
loader: 'babel-loader', | ||
options: { presets: ['@babel/env', '@babel/preset-react'] } | ||
}) | ||
|
||
config.module.rules.push({ | ||
test: /\.(m?js)$/, | ||
SgtPooki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type: 'javascript/auto', | ||
resolve: { | ||
fullySpecified: false | ||
} | ||
}) | ||
|
||
// Instrument for code coverage in development mode | ||
const REACT_APP_ENV = process.env.REACT_APP_ENV ?? process.env.NODE_ENV ?? 'production' | ||
|
@@ -97,7 +111,22 @@ function webpackOverride(config) { | |
return config | ||
} | ||
|
||
module.exports = { | ||
const configOverride = { | ||
webpack: webpackOverride, | ||
jest: (config) => config | ||
jest: (config) => { | ||
/** | ||
* @type {import('jest').Config} | ||
*/ | ||
return ({ | ||
...config, | ||
setupFiles: [...config.setupFiles, 'fake-indexeddb/auto'], | ||
moduleNameMapper: { | ||
...config.moduleNameMapper, | ||
'multiformats/basics': '<rootDir>/node_modules/multiformats/cjs/src/basics.js', | ||
'multiformats/bases/(.*)$': '<rootDir>/node_modules/multiformats/cjs/src/bases/$1.js' | ||
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. optional perf, check if not the end 'multiformats/bases/([^$]+)$': '<rootDir>/node_modules/multiformats/cjs/src/bases/$1.js' we should at least check the size 'multiformats/bases/(.+)$': '<rootDir>/node_modules/multiformats/cjs/src/bases/$1.js' 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. There really shouldn't be any performance difference, and if anything, it should be more performant with the greedy match. we already know the size is > 0 because of the forward-slash in front of I put together a quick hyperfine test by doing jest: (config) => {
let mfBases = 'multiformats/bases/(.*)$'
if (process.env.MFBASE === '1') {
mfBases = 'multiformats/bases/(.+)$'
} else if (process.env.MFBASE === '2') {
mfBases = 'multiformats/bases/([^$]+)$'
}
/**
* @type {import('jest').Config}
*/
return ({
...config,
setupFiles: [...config.setupFiles, 'fake-indexeddb/auto'],
moduleNameMapper: {
...config.moduleNameMapper,
'multiformats/basics': '<rootDir>/node_modules/multiformats/cjs/src/basics.js',
[mfBases]: '<rootDir>/node_modules/multiformats/cjs/src/bases/$1.js'
}
})
} and running ╰─ ✔ ❯ hyperfine 'MFBASE=0 npm run test:unit' 'MFBASE=1 npm run test:unit' 'MFBASE=2 npm run test:unit'
Benchmark 1: MFBASE=0 npm run test:unit
Time (mean ± σ): 5.429 s ± 0.104 s [User: 3.829 s, System: 1.008 s]
Range (min … max): 5.232 s … 5.587 s 10 runs
Benchmark 2: MFBASE=1 npm run test:unit
Time (mean ± σ): 17.498 s ± 24.296 s [User: 4.158 s, System: 1.064 s]
Range (min … max): 5.483 s … 63.602 s 10 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
Benchmark 3: MFBASE=2 npm run test:unit
Time (mean ± σ): 5.675 s ± 0.114 s [User: 3.911 s, System: 1.042 s]
Range (min … max): 5.548 s … 5.919 s 10 runs
Summary
'MFBASE=0 npm run test:unit' ran
1.05 ± 0.03 times faster than 'MFBASE=2 npm run test:unit'
3.22 ± 4.48 times faster than 'MFBASE=1 npm run test:unit' npm/jest actually stalls out on MFBASE=1, below is the output when running Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. 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. MFBASE=0 actually has two additional checks for the process.env.MFBASE whereas the other two do not, so it's saying something that it's still faster. Either way, optimizing regex here is.. tedious =P |
||
} | ||
Comment on lines
+123
to
+127
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 should go away when we update to the latest. |
||
}) | ||
} | ||
} | ||
|
||
export default configOverride |
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.
This is basically a no-op if things are up to date, but required if any playwright updates are done (which were in this PR)