Skip to content

Commit 3262a9a

Browse files
feat: removed cjs wrapper and generated types in commonjs format (export = and namespaces used in types), now you can directly use exported types
1 parent c5747b5 commit 3262a9a

File tree

9 files changed

+196
-157
lines changed

9 files changed

+196
-157
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
"type": "opencollective",
1212
"url": "https://opencollective.com/webpack"
1313
},
14-
"main": "dist/cjs.js",
15-
"types": "types/cjs.d.ts",
14+
"main": "dist/index.js",
15+
"types": "types/index.d.ts",
1616
"engines": {
1717
"node": ">= 12.13.0"
1818
},
1919
"scripts": {
2020
"start": "npm run build -- -w",
2121
"clean": "del-cli dist",
22-
"prebuild": "npm run clean",
23-
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write && prettier types --write",
22+
"prebuild": "npm run clean types",
23+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write",
2424
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",
2525
"build": "npm-run-all -p \"build:**\"",
2626
"commitlint": "commitlint --from=master",

src/cjs.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import * as os from "os";
1+
const os = require("os");
22

3-
import { SourceMapConsumer } from "source-map";
4-
import { validate } from "schema-utils";
5-
import serialize from "serialize-javascript";
6-
import { Worker } from "jest-worker";
3+
const { SourceMapConsumer } = require("source-map");
4+
const { validate } = require("schema-utils");
5+
const serialize = require("serialize-javascript");
6+
const { Worker } = require("jest-worker");
77

8-
import {
8+
const {
99
throttleAll,
1010
cssnanoMinify,
1111
cssoMinify,
1212
cleanCssMinify,
1313
esbuildMinify,
14-
} from "./utils";
14+
} = require("./utils");
1515

16-
import * as schema from "./options.json";
17-
import { minify as minifyFn } from "./minify";
16+
const schema = require("./options.json");
17+
const { minify } = require("./minify");
1818

1919
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
2020
/** @typedef {import("webpack").Compiler} Compiler */
@@ -529,7 +529,7 @@ class CssMinimizerPlugin {
529529
try {
530530
result = await (getWorker
531531
? getWorker().transform(serialize(options))
532-
: minifyFn(options));
532+
: minify(options));
533533
} catch (error) {
534534
const hasSourceMap =
535535
inputSourceMap && CssMinimizerPlugin.isSourceMap(inputSourceMap);
@@ -715,4 +715,4 @@ CssMinimizerPlugin.cssoMinify = cssoMinify;
715715
CssMinimizerPlugin.cleanCssMinify = cleanCssMinify;
716716
CssMinimizerPlugin.esbuildMinify = esbuildMinify;
717717

718-
export default CssMinimizerPlugin;
718+
module.exports = CssMinimizerPlugin;

src/minify.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,4 @@ async function transform(options) {
8282
return minify(evaluatedOptions);
8383
}
8484

85-
module.exports.minify = minify;
86-
module.exports.transform = transform;
85+
module.exports = { minify, transform };

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
347347
};
348348
}
349349

350-
export {
350+
module.exports = {
351351
throttleAll,
352352
cssnanoMinify,
353353
cssoMinify,

test/cache-option.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ describe('"cache" option', () => {
9292
expect(readAssets(compiler, newStats, /\.css$/)).toMatchSnapshot("assets");
9393
expect(getErrors(newStats)).toMatchSnapshot("errors");
9494
expect(getWarnings(newStats)).toMatchSnapshot("warnings");
95+
96+
await new Promise((resolve) => {
97+
compiler.close(() => {
98+
resolve();
99+
});
100+
});
95101
});
96102

97103
it('should work with the "memory" value for the "cache.type" option', async () => {
@@ -154,6 +160,12 @@ describe('"cache" option', () => {
154160
expect(readAssets(compiler, newStats, /\.css$/)).toMatchSnapshot("assets");
155161
expect(getErrors(newStats)).toMatchSnapshot("errors");
156162
expect(getWarnings(newStats)).toMatchSnapshot("warnings");
163+
164+
await new Promise((resolve) => {
165+
compiler.close(() => {
166+
resolve();
167+
});
168+
});
157169
});
158170

159171
it('should work with the "filesystem" value for the "cache.type" option', async () => {
@@ -217,6 +229,12 @@ describe('"cache" option', () => {
217229
expect(readAssets(compiler, newStats, /\.css$/)).toMatchSnapshot("assets");
218230
expect(getErrors(newStats)).toMatchSnapshot("errors");
219231
expect(getWarnings(newStats)).toMatchSnapshot("warnings");
232+
233+
await new Promise((resolve) => {
234+
compiler.close(() => {
235+
resolve();
236+
});
237+
});
220238
});
221239

222240
it('should work with the "filesystem" value for the "cache.type" option and source maps', async () => {

test/cjs.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

types/cjs.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)