-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
make managerEntries be loaded as ESM, for improved tree-shaking #20070
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0c30e2
try to make builder-manager prefer mjs, for tree-shaking
ndelangen 4e3bd71
let's optimize manager entries!
ndelangen 546ffac
fix tests
ndelangen b54eea2
Merge branch 'next' into tech/improve-perf-by-using-mjs
ndelangen 31f44be
fix test for windows
ndelangen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,6 +10,7 @@ import type { | |||||
PresetConfig, | ||||||
Presets, | ||||||
} from '@storybook/types'; | ||||||
import { join, parse } from 'path'; | ||||||
import { loadCustomPresets } from './utils/load-custom-presets'; | ||||||
import { safeResolve, safeResolveFrom } from './utils/safeResolve'; | ||||||
import { interopRequireDefault } from './utils/interpret-require'; | ||||||
|
@@ -66,14 +67,19 @@ export const resolveAddonName = ( | |||||
const resolved = resolve(name); | ||||||
|
||||||
if (resolved) { | ||||||
if (name.match(/\/(manager|register(-panel)?)(\.(js|ts|tsx|jsx))?$/)) { | ||||||
const { dir: fdir, name: fname } = parse(resolved); | ||||||
|
||||||
if (name.match(/\/(manager|register(-panel)?)(\.(js|mjs|ts|tsx|jsx))?$/)) { | ||||||
return { | ||||||
type: 'virtual', | ||||||
name, | ||||||
managerEntries: [resolved], | ||||||
// we remove the extension | ||||||
// this is a bit of a hack to try en be able to find .mjs files | ||||||
// node can only ever resolve .js files; it does not look at the exports field in package.json | ||||||
managerEntries: [join(fdir, fname)], | ||||||
}; | ||||||
} | ||||||
if (name.match(/\/(preset)(\.(js|ts|tsx|jsx))?$/)) { | ||||||
if (name.match(/\/(preset)(\.(js|mjs|ts|tsx|jsx))?$/)) { | ||||||
return { | ||||||
type: 'presets', | ||||||
name: resolved, | ||||||
|
@@ -113,11 +119,19 @@ export const resolveAddonName = ( | |||||
const managerEntries = []; | ||||||
|
||||||
if (managerFile) { | ||||||
managerEntries.push(managerFile); | ||||||
// we remove the extension | ||||||
// this is a bit of a hack to try en be able to find .mjs files | ||||||
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.
Suggested change
|
||||||
// node can only ever resolve .js files; it does not look at the exports field in package.json | ||||||
const { dir: fdir, name: fname } = parse(managerFile); | ||||||
managerEntries.push(join(fdir, fname)); | ||||||
} | ||||||
// register file is the old way of registering addons | ||||||
if (!managerFile && registerFile && !presetFile) { | ||||||
managerEntries.push(registerFile); | ||||||
// we remove the extension | ||||||
// this is a bit of a hack to try en be able to find .mjs files | ||||||
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.
Suggested change
|
||||||
// node can only ever resolve .js files; it does not look at the exports field in package.json | ||||||
const { dir: fdir, name: fname } = parse(registerFile); | ||||||
managerEntries.push(join(fdir, fname)); | ||||||
} | ||||||
|
||||||
return { | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.