Skip to content

Commit 71a9ce9

Browse files
fix: ignore modules without identifier (#627)
1 parent 028b4f2 commit 71a9ce9

File tree

7 files changed

+1428
-1656
lines changed

7 files changed

+1428
-1656
lines changed

Diff for: package-lock.json

+1,367-1,645
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@
4949
"webpack-sources": "^1.1.0"
5050
},
5151
"devDependencies": {
52-
"@babel/cli": "^7.11.6",
53-
"@babel/core": "^7.11.6",
54-
"@babel/preset-env": "^7.11.5",
52+
"@babel/cli": "^7.12.1",
53+
"@babel/core": "^7.12.3",
54+
"@babel/preset-env": "^7.12.1",
5555
"@commitlint/cli": "^11.0.0",
5656
"@commitlint/config-conventional": "^11.0.0",
5757
"@webpack-contrib/defaults": "^6.3.0",
5858
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
59-
"babel-eslint": "^10.0.2",
59+
"babel-eslint": "^10.1.0",
6060
"babel-jest": "^26.5.2",
6161
"cross-env": "^7.0.2",
62-
"css-loader": "^4.3.0",
62+
"css-loader": "^5.0.0",
6363
"del": "^6.0.0",
6464
"del-cli": "^3.0.1",
6565
"es-check": "^5.1.1",
66-
"eslint": "^7.10.0",
67-
"eslint-config-prettier": "^6.12.0",
66+
"eslint": "^7.11.0",
67+
"eslint-config-prettier": "^6.13.0",
6868
"eslint-plugin-import": "^2.22.1",
69-
"file-loader": "^6.1.0",
69+
"file-loader": "^6.1.1",
7070
"husky": "^4.3.0",
7171
"jest": "^26.5.2",
7272
"jsdom": "^16.4.0",
@@ -76,7 +76,7 @@
7676
"prettier": "^2.1.2",
7777
"standard-version": "^9.0.0",
7878
"webpack": "^5.1.0",
79-
"webpack-cli": "^3.3.6",
79+
"webpack-cli": "^4.1.0",
8080
"webpack-dev-server": "^3.7.2"
8181
},
8282
"keywords": [

Diff for: src/loader.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ export function pitch(request) {
150150
const identifierCountMap = new Map();
151151

152152
for (const dependency of dependencies) {
153+
if (!dependency.identifier) {
154+
// eslint-disable-next-line no-continue
155+
continue;
156+
}
157+
153158
const count = identifierCountMap.get(dependency.identifier) || 0;
154159

155160
this._module.addDependency(
@@ -197,7 +202,10 @@ export function pitch(request) {
197202
if (namedExport) {
198203
Object.keys(originalExports).forEach((key) => {
199204
if (key !== 'default') {
200-
if (!locals) locals = {};
205+
if (!locals) {
206+
locals = {};
207+
}
208+
201209
locals[key] = originalExports[key];
202210
}
203211
});

Diff for: test/TestCases.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('TestCases', () => {
192192
outputDirectoryForCase,
193193
expectedDirectoryByVersion
194194
);
195-
} else {
195+
} else if (fs.existsSync(expectedDirectory)) {
196196
compareDirectory(outputDirectoryForCase, expectedDirectory);
197197
}
198198

Diff for: test/cases/no-identifier/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './style.css';

Diff for: test/cases/no-identifier/style.css

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.a {
2+
background: red;
3+
}
4+
5+
:local(.b) {
6+
color: green;
7+
}
8+
9+
:global(.c) {
10+
color: blue;
11+
}

Diff for: test/cases/no-identifier/webpack.config.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Self from '../../../src';
2+
3+
module.exports = {
4+
entry: './index.js',
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [
10+
Self.loader,
11+
{
12+
loader: 'css-loader',
13+
options: {
14+
modules: {
15+
mode: 'local',
16+
localIdentName: 'foo__[name]__[local]',
17+
exportOnlyLocals: true,
18+
},
19+
},
20+
},
21+
],
22+
},
23+
],
24+
},
25+
plugins: [
26+
new Self({
27+
filename: '[name].css',
28+
}),
29+
],
30+
};

0 commit comments

Comments
 (0)