Skip to content
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(webpack-5): opt-in to transitive only side effects #599

Merged
merged 1 commit into from Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CssDependency.js
Expand Up @@ -20,6 +20,11 @@ class CssDependency extends webpack.Dependency {
return `css-module-${this.identifier}-${this.identifierIndex}`;
}

// eslint-disable-next-line class-methods-use-this
getModuleEvaluationSideEffectsState() {
return webpack.ModuleGraphConnection.TRANSITIVE_ONLY;
}

serialize(context) {
const { write } = context;

Expand Down
28 changes: 18 additions & 10 deletions test/TestCases.test.js
Expand Up @@ -47,19 +47,23 @@ function compareDirectory(actual, expected) {
const content = fs.readFileSync(path.resolve(expected, file), 'utf8');
let actualContent;

try {
actualContent = fs.readFileSync(path.resolve(actual, file), 'utf8');
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
if (/^MISSING/.test(content)) {
expect(fs.existsSync(path.resolve(actual, file))).toBe(false);
} else {
try {
actualContent = fs.readFileSync(path.resolve(actual, file), 'utf8');
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);

const dir = fs.readdirSync(actual);
const dir = fs.readdirSync(actual);

// eslint-disable-next-line no-console
console.log({ [actual]: dir });
}
// eslint-disable-next-line no-console
console.log({ [actual]: dir });
}

expect(actualContent).toEqual(content);
expect(actualContent).toEqual(content);
}
}
}
}
Expand Down Expand Up @@ -119,6 +123,10 @@ describe('TestCases', () => {
done(err);
return;
}
if (stats.hasErrors()) {
done(new Error(stats.toString()));
return;
}

done();

Expand Down
@@ -1,37 +1,20 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ([
/* 0 */
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _styleC_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
/* harmony import */ var _styleC_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_styleC_css__WEBPACK_IMPORTED_MODULE_0__);



/***/ }),
/* 1 */
/***/ (() => {

// extracted by mini-css-extract-plugin

/***/ }),
/* 2 */
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _styleD_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
/* harmony import */ var _styleD_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_styleD_css__WEBPACK_IMPORTED_MODULE_0__);



/***/ }),
/* 3 */
/***/ (() => {

// extracted by mini-css-extract-plugin

/***/ })
/******/ ]);
Expand Down Expand Up @@ -63,30 +46,6 @@ __webpack_require__.r(__webpack_exports__);
/******/ __webpack_require__.m = __webpack_modules__;
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => module['default'] :
/******/ () => module;
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
Expand Down Expand Up @@ -116,7 +75,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ var deferredModules = [
/******/ [0],
/******/ [2]
/******/ [1]
/******/ ];
/******/ // no chunk on demand loading
/******/
Expand Down
@@ -1,41 +1,23 @@
(self["webpackChunk"] = self["webpackChunk"] || []).push([[1],[
/* 0 */,
/* 1 */,
/* 2 */,
/* 3 */,
/* 4 */
/* 2 */
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _styleB_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
/* harmony import */ var _styleB_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_styleB_css__WEBPACK_IMPORTED_MODULE_0__);



/***/ }),
/* 5 */
/***/ (() => {

// extracted by mini-css-extract-plugin

/***/ }),
/* 6 */
/* 3 */
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _styleA_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
/* harmony import */ var _styleA_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_styleA_css__WEBPACK_IMPORTED_MODULE_0__);



/***/ }),
/* 7 */
/***/ (() => {

// extracted by mini-css-extract-plugin

/***/ })
],
0,[[6,0],[4,0]]]);
0,[[3,0],[2,0]]]);
34 changes: 1 addition & 33 deletions test/cases/dependOn/expected/webpack-5/common.js
@@ -1,21 +1,13 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ([
/* 0 */
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _styleB_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
/* harmony import */ var _styleB_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_styleB_css__WEBPACK_IMPORTED_MODULE_0__);



/***/ }),
/* 1 */
/***/ (() => {

// extracted by mini-css-extract-plugin

/***/ })
/******/ ]);
/************************************************************************/
Expand Down Expand Up @@ -46,30 +38,6 @@ __webpack_require__.r(__webpack_exports__);
/******/ __webpack_require__.m = __webpack_modules__;
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => module['default'] :
/******/ () => module;
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
Expand Down
13 changes: 2 additions & 11 deletions test/cases/dependOn/expected/webpack-5/entry1.js
@@ -1,22 +1,13 @@
(self["webpackChunk"] = self["webpackChunk"] || []).push([[1],[
/* 0 */,
/* 1 */,
/* 2 */
/* 1 */
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _styleA_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
/* harmony import */ var _styleA_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_styleA_css__WEBPACK_IMPORTED_MODULE_0__);



/***/ }),
/* 3 */
/***/ (() => {

// extracted by mini-css-extract-plugin

/***/ })
],
0,[[2,0]]]);
0,[[1,0]]]);
3 changes: 3 additions & 0 deletions test/cases/es-module-concatenation-modules/a.css
@@ -0,0 +1,3 @@
.a {
background: red;
}
3 changes: 3 additions & 0 deletions test/cases/es-module-concatenation-modules/b.css
@@ -0,0 +1,3 @@
.b {
background: green;
}
3 changes: 3 additions & 0 deletions test/cases/es-module-concatenation-modules/c.css
@@ -0,0 +1,3 @@
.c {
background: blue;
}
@@ -0,0 +1,12 @@
.foo__a {
background: red;
}

.foo__b {
background: green;
}

.foo__c {
background: blue;
}