-
-
Notifications
You must be signed in to change notification settings - Fork 384
fix: enforce esm #546
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
Merged
Merged
fix: enforce esm #546
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { getCompiler, source, compile } from './helpers'; | ||
|
||
it('should enforce esm for empty module with options.esModule', async (done) => { | ||
const compiler = getCompiler( | ||
'./esm.js', | ||
{ esModule: true }, | ||
{ | ||
mode: 'production', | ||
optimization: { minimize: false }, | ||
} | ||
); | ||
const stats = await compile(compiler); | ||
expect(stats.hasErrors()).toBe(false); | ||
expect(source('./simple.css', stats)).toMatchInlineSnapshot(` | ||
"// extracted by mini-css-extract-plugin | ||
export {};" | ||
`); | ||
done(); | ||
}); | ||
|
||
it('should keep empty module without options.esModule', async (done) => { | ||
const compiler = getCompiler( | ||
'./esm.js', | ||
{}, | ||
{ | ||
mode: 'production', | ||
optimization: { minimize: false }, | ||
} | ||
); | ||
const stats = await compile(compiler); | ||
expect(stats.hasErrors()).toBe(false); | ||
expect(source('./simple.css', stats)).toMatchInlineSnapshot( | ||
`"// extracted by mini-css-extract-plugin"` | ||
); | ||
done(); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./simple.css"; |
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 |
---|---|---|
|
@@ -6,9 +6,11 @@ import { createFsFromVolume, Volume } from 'memfs'; | |
import MiniCssExtractPlugin from '../../src'; | ||
|
||
export default (fixture, loaderOptions = {}, config = {}) => { | ||
const { outputFileSystem, ...cnfg } = config; | ||
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. Not related to PR fix, I just wanted to look on output when was testing locally and found a bug with |
||
|
||
const fullConfig = { | ||
mode: 'development', | ||
devtool: config.devtool || false, | ||
devtool: cnfg.devtool || false, | ||
context: path.resolve(__dirname, '../fixtures'), | ||
entry: path.resolve(__dirname, '../fixtures', fixture), | ||
output: { | ||
|
@@ -40,16 +42,18 @@ export default (fixture, loaderOptions = {}, config = {}) => { | |
chunkFilename: '[id].css', | ||
}), | ||
], | ||
...config, | ||
...cnfg, | ||
}; | ||
|
||
const compiler = webpack(fullConfig); | ||
|
||
if (!config.outputFileSystem) { | ||
const outputFileSystem = createFsFromVolume(new Volume()); | ||
if (!outputFileSystem) { | ||
const outputFS = createFsFromVolume(new Volume()); | ||
// Todo remove when we drop webpack@4 support | ||
outputFileSystem.join = path.join.bind(path); | ||
outputFS.join = path.join.bind(path); | ||
|
||
compiler.outputFileSystem = outputFS; | ||
} else { | ||
compiler.outputFileSystem = outputFileSystem; | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import compile from './compile'; | ||
import getCompiler from './getCompiler'; | ||
import source from './source'; | ||
|
||
export { compile, getCompiler }; | ||
export { source, compile, getCompiler }; |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default function getSource(name, stats) { | ||
const { modules } = stats.toJson({ source: true }); | ||
|
||
for (let i = 0; i < modules.length; i++) { | ||
const module = modules[i]; | ||
|
||
if (module.modules && module.modules.length > 0) { | ||
for (let j = 0; j < module.modules.length; j++) { | ||
if (module.modules[j].name === name) { | ||
return module.modules[j].source; | ||
} | ||
} | ||
} else if (module.name === name) { | ||
return module.source; | ||
} | ||
} | ||
|
||
return undefined; | ||
} |
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.
Just snapshot module using name
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.
fixed, let me clean up and squash commit..