Skip to content

Commit 36d7c55

Browse files
committed
gogogo
1 parent b071848 commit 36d7c55

33 files changed

+2667
-658
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
**/coverage/**
22
**/lib/**
33
**/fixtures/**
4+
**/__file_snapshots__/**
45
**/flow-typed/**
56
**/node_modules/**
67
**/CHANGELOG.md

getLocalName.js renamed to lib/getLocalName.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
1111
const reRelativePath = /^\.+/;
1212

1313
module.exports = function getLocalName(
14+
filename,
1415
localName,
1516
loaderContext,
1617
loaderOptions,
1718
) {
1819
const hashPrefix = loaderOptions.hashPrefix || '';
1920
const context = loaderOptions.context || loaderContext.rootContext;
20-
const request = path.relative(context || '', loaderContext.resourcePath);
21+
const request = path.relative(context || '', filename);
2122

2223
// eslint-disable-next-line no-param-reassign
2324
const content = `${hashPrefix + request}+${localName}`;
@@ -27,7 +28,7 @@ module.exports = function getLocalName(
2728
return cssesc(
2829
loaderUtils
2930
.interpolateName(
30-
loaderContext,
31+
{ ...loaderContext, resourcePath: filename },
3132
loaderOptions.localIdentName || '[name]--[local]--[hash:base64:5]',
3233
{
3334
context,

index.js renamed to lib/index.js

File renamed without changes.

loader.js renamed to lib/loader.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const { getOptions } = require('loader-utils');
66
const getLocalName = require('./getLocalName');
77

88
const PROCESSOR = Symbol('@modular-css processor');
9+
const CACHE = Symbol('loadModule cache module');
10+
911

1012
function getLoadFilePrefix(loaderContext) {
1113
// loads a file with all loaders configured after this one
@@ -26,21 +28,27 @@ function loader(src) {
2628

2729
const prefix = getLoadFilePrefix(this);
2830

29-
const loadModule = promisify((request, done) =>
30-
this.loadModule(request, (err, moduleSource) => {
31-
done(err, JSON.parse(moduleSource.toString()));
32-
}),
31+
const loadFile = promisify((file, done) => {
32+
if (compilation[CACHE].has(file)) {
33+
return done(null, compilation[CACHE].get(file))
34+
}
35+
36+
this.loadModule(`${prefix}${file}`, (err, moduleSource) => {
37+
const content = JSON.parse(moduleSource.toString())
38+
// console.log('CACHE', file)
39+
compilation[CACHE].set(file, content)
40+
done(err, content);
41+
})
42+
}
3343
);
3444

45+
if (!compilation[CACHE]) {
46+
compilation[CACHE] = new Map();
47+
}
3548
if (!compilation[PROCESSOR]) {
3649
compilation[PROCESSOR] = new Processor({
37-
namer: (_, localName) => getLocalName(localName, this, options),
38-
async loadFile(file) {
39-
// console.log('LOAD');
40-
const txt = await loadModule(`${prefix}${file}`);
41-
// console.log(txt);
42-
return txt;
43-
},
50+
loadFile,
51+
namer: (filename, localName) => getLocalName(filename, localName, this, options),
4452
});
4553
}
4654

@@ -58,10 +66,12 @@ function loader(src) {
5866

5967
let icssExport = ':export {\n';
6068
for (const [key, value] of Object.entries(exports)) {
61-
icssExport += ` ${key}: ${value.join(' ')}\n`;
69+
icssExport += ` ${key}: ${[].concat(value).join(' ')};\n`;
6270
}
6371
icssExport += '}';
6472

73+
74+
6575
return `${details.result.css}\n\n${icssImport}\n\n${icssExport}`;
6676
};
6777

@@ -74,3 +84,13 @@ function loader(src) {
7484
}
7585

7686
module.exports = loader;
87+
88+
// module.exports.pitch = function pitch(remainingRequest) {
89+
// const cache = this._compilation[CACHE];
90+
91+
// if (cache && cache.has(this.resourcePath)) {
92+
// console.log('cache hit!', this.resourcePath)
93+
// return loader.call(this, cache.get(this.resourcePath))
94+
// // return cache.get(this.resourcePath)
95+
// }
96+
// }
File renamed without changes.

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "css-module-loader",
33
"version": "1.0.0",
4-
"main": "index.js",
4+
"main": "lib/index.js",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/4Catalyzer/css-module-loader.git"
@@ -26,7 +26,7 @@
2626
}
2727
},
2828
"lint-staged": {
29-
"*": [
29+
"!(__file_snapshots__/)*.js": [
3030
"yarn 4c lint --fix",
3131
"git add"
3232
]
@@ -44,34 +44,34 @@
4444
},
4545
"release": {},
4646
"devDependencies": {
47-
"@4c/cli": "^0.7.12",
48-
"@4c/import-sort": "^4.3.3",
47+
"@4c/cli": "^1.0.1",
48+
"@4c/import-sort": "^4.3.6",
4949
"@4c/jest-preset": "^1.3.0",
5050
"@4c/prettier-config": "^1.1.0",
5151
"css-loader": "^3.2.0",
52-
"eslint": "^5.12.0",
53-
"eslint-config-4catalyzer": "^0.7.0",
54-
"eslint-config-4catalyzer-jest": "^1.1.0",
55-
"eslint-config-prettier": "^4.0.0",
52+
"eslint": "^6.6.0",
53+
"eslint-config-4catalyzer": "^1.0.0",
54+
"eslint-config-4catalyzer-jest": "^2.0.1",
55+
"eslint-config-prettier": "^6.5.0",
5656
"eslint-plugin-import": "^2.8.0",
57-
"eslint-plugin-jest": "^22.1.2",
58-
"eslint-plugin-prettier": "^3.0.1",
59-
"husky": "^1.1.2",
57+
"eslint-plugin-jest": "^23.0.2",
58+
"eslint-plugin-prettier": "^3.1.1",
59+
"husky": "^3.0.9",
6060
"jest": "^24.0.0",
6161
"jest-file-snapshot": "^0.3.7",
62-
"lint-staged": "^8.1.0",
62+
"lint-staged": "^9.4.2",
6363
"mini-css-extract-plugin": "^0.8.0",
6464
"prettier": "^1.15.3",
65-
"sass": "^1.22.12",
65+
"sass": "^1.23.3",
6666
"strip-ansi": "^5.2.0"
6767
},
6868
"dependencies": {
69-
"@modular-css/processor": "^24.2.2",
69+
"@modular-css/processor": "^25.2.0",
7070
"cssesc": "^3.0.0",
7171
"fs-extra": "^8.1.0",
7272
"loader-utils": "^1.2.3",
73-
"memory-fs": "^0.4.1",
73+
"memory-fs": "^0.5.0",
7474
"sass-loader": "^8.0.0",
75-
"webpack": "^4.40.2"
75+
"webpack": "^4.41.2"
7676
}
7777
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["main"],{
22

3-
/***/ "./test/integration/common/externals.scss":
4-
/*!************************************************!*\
5-
!*** ./test/integration/common/externals.scss ***!
6-
\************************************************/
3+
/***/ "./test/fixtures/common/externals.scss":
4+
/*!*********************************************!*\
5+
!*** ./test/fixtures/common/externals.scss ***!
6+
\*********************************************/
77
/*! no static exports found */
88
/***/ (function(module, exports, __webpack_require__) {
99

1010
// extracted by mini-css-extract-plugin
11-
module.exports = {"toolbar":"externals--toolbar--3Adsi"};
11+
module.exports = {"toolbar":"externals--toolbar--3HGQb"};
1212

1313
/***/ }),
1414

15-
/***/ "./test/integration/externals.js":
16-
/*!***************************************!*\
17-
!*** ./test/integration/externals.js ***!
18-
\***************************************/
15+
/***/ "./test/fixtures/externals.js":
16+
/*!************************************!*\
17+
!*** ./test/fixtures/externals.js ***!
18+
\************************************/
1919
/*! no static exports found */
2020
/***/ (function(module, exports, __webpack_require__) {
2121

22-
const styles = __webpack_require__(/*! ./common/externals.scss */ "./test/integration/common/externals.scss");
22+
const styles = __webpack_require__(/*! ./common/externals.scss */ "./test/fixtures/common/externals.scss");
2323

2424

2525
/***/ })
2626

27-
},[["./test/integration/externals.js","runtime~main"]]]);
27+
},[["./test/fixtures/externals.js","runtime~main"]]]);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
.externals--base--2HU_u {
1+
.base--base--1uAtd {
22
color: blue;
33
}
4-
.externals--button--3mvEh {
4+
.button--button--32Qrn {
55
color: red;
66
}
7-
.externals--toolbar--3Adsi > .externals--base--2HU_u.externals--button--3mvEh {
7+
.externals--toolbar--3HGQb > .base--base--1uAtd.button--button--32Qrn {
88
margin-left: 2rem;
99
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["main"],{
2+
3+
/***/ "./test/fixtures/complex-names.module.scss":
4+
/*!*************************************************!*\
5+
!*** ./test/fixtures/complex-names.module.scss ***!
6+
\*************************************************/
7+
/*! no static exports found */
8+
/***/ (function(module, exports, __webpack_require__) {
9+
10+
// extracted by mini-css-extract-plugin
11+
module.exports = {"foo-bar":"complex-names-module--foo-bar--3PvWR","fooBar":"complex-names-module--foo-bar--3PvWR","btn-primary__inner":"complex-names-module--btn-primary__inner--3fdjV","btnPrimaryInner":"complex-names-module--btn-primary__inner--3fdjV"};
12+
13+
/***/ })
14+
15+
},[["./test/fixtures/complex-names.module.scss","runtime~main"]]]);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["main"],{
2+
3+
/***/ "./test/fixtures/complex-names.module.scss":
4+
/*!*************************************************!*\
5+
!*** ./test/fixtures/complex-names.module.scss ***!
6+
\*************************************************/
7+
/*! no static exports found */
8+
/***/ (function(module, exports, __webpack_require__) {
9+
10+
// extracted by mini-css-extract-plugin
11+
module.exports = {"fooBar":"complex-names-module--foo-bar--3PvWR","btnPrimaryInner":"complex-names-module--btn-primary__inner--3fdjV"};
12+
13+
/***/ })
14+
15+
},[["./test/fixtures/complex-names.module.scss","runtime~main"]]]);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["main"],{
2+
3+
/***/ "./test/fixtures/complex-names.module.scss":
4+
/*!*************************************************!*\
5+
!*** ./test/fixtures/complex-names.module.scss ***!
6+
\*************************************************/
7+
/*! no static exports found */
8+
/***/ (function(module, exports, __webpack_require__) {
9+
10+
// extracted by mini-css-extract-plugin
11+
module.exports = {"foo-bar":"complex-names-module--foo-bar--3PvWR","fooBar":"complex-names-module--foo-bar--3PvWR","btn-primary__inner":"complex-names-module--btn-primary__inner--3fdjV","btnPrimary__inner":"complex-names-module--btn-primary__inner--3fdjV"};
12+
13+
/***/ })
14+
15+
},[["./test/fixtures/complex-names.module.scss","runtime~main"]]]);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["main"],{
2+
3+
/***/ "./test/fixtures/complex-names.module.scss":
4+
/*!*************************************************!*\
5+
!*** ./test/fixtures/complex-names.module.scss ***!
6+
\*************************************************/
7+
/*! no static exports found */
8+
/***/ (function(module, exports, __webpack_require__) {
9+
10+
// extracted by mini-css-extract-plugin
11+
module.exports = {"fooBar":"complex-names-module--foo-bar--3PvWR","btnPrimary__inner":"complex-names-module--btn-primary__inner--3fdjV"};
12+
13+
/***/ })
14+
15+
},[["./test/fixtures/complex-names.module.scss","runtime~main"]]]);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["main"],{
2+
3+
/***/ "./test/fixtures/nested-deps.js":
4+
/*!**************************************!*\
5+
!*** ./test/fixtures/nested-deps.js ***!
6+
\**************************************/
7+
/*! no static exports found */
8+
/***/ (function(module, exports, __webpack_require__) {
9+
10+
__webpack_require__(/*! ./nested/one.scss */ "./test/fixtures/nested/one.scss")
11+
__webpack_require__(/*! ./nested/two.scss */ "./test/fixtures/nested/two.scss")
12+
__webpack_require__(/*! ./nested/three.scss */ "./test/fixtures/nested/three.scss")
13+
14+
15+
/***/ }),
16+
17+
/***/ "./test/fixtures/nested/one.scss":
18+
/*!***************************************!*\
19+
!*** ./test/fixtures/nested/one.scss ***!
20+
\***************************************/
21+
/*! no static exports found */
22+
/***/ (function(module, exports, __webpack_require__) {
23+
24+
// extracted by mini-css-extract-plugin
25+
module.exports = {"base":"one--base--2z77O"};
26+
27+
/***/ }),
28+
29+
/***/ "./test/fixtures/nested/three.scss":
30+
/*!*****************************************!*\
31+
!*** ./test/fixtures/nested/three.scss ***!
32+
\*****************************************/
33+
/*! no static exports found */
34+
/***/ (function(module, exports, __webpack_require__) {
35+
36+
// extracted by mini-css-extract-plugin
37+
module.exports = {"blue":"rgb(0, 0, 255)","inner":"three--inner--2a-T6"};
38+
39+
/***/ }),
40+
41+
/***/ "./test/fixtures/nested/two.scss":
42+
/*!***************************************!*\
43+
!*** ./test/fixtures/nested/two.scss ***!
44+
\***************************************/
45+
/*! no static exports found */
46+
/***/ (function(module, exports, __webpack_require__) {
47+
48+
// extracted by mini-css-extract-plugin
49+
module.exports = {"red":"rgb(255, 0 ,0)","base":"two--base--2113t"};
50+
51+
/***/ })
52+
53+
},[["./test/fixtures/nested-deps.js","runtime~main"]]]);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
.three--inner--2a-T6 {
3+
color: rgb(0, 0, 255);
4+
}
5+
.one--base--2z77O .three--inner--2a-T6 {
6+
color: red;
7+
}
8+
.two--base--2113t .three--inner--2a-T6 {
9+
color: rgb(255, 0 ,0);
10+
}

test/__file_snapshots__/onlyLocals.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["main"],{
2+
3+
/***/ "./test/fixtures/common/externals.scss":
4+
/*!*********************************************!*\
5+
!*** ./test/fixtures/common/externals.scss ***!
6+
\*********************************************/
7+
/*! no static exports found */
8+
/***/ (function(module, exports) {
9+
10+
// Exports
11+
module.exports = {
12+
"toolbar": "externals--toolbar--3HGQb"
13+
};
14+
15+
/***/ }),
16+
17+
/***/ "./test/fixtures/externals.js":
18+
/*!************************************!*\
19+
!*** ./test/fixtures/externals.js ***!
20+
\************************************/
21+
/*! no static exports found */
22+
/***/ (function(module, exports, __webpack_require__) {
23+
24+
const styles = __webpack_require__(/*! ./common/externals.scss */ "./test/fixtures/common/externals.scss");
25+
26+
27+
/***/ })
28+
29+
},[["./test/fixtures/externals.js","runtime~main"]]]);

0 commit comments

Comments
 (0)