Skip to content

Commit

Permalink
feat: removed cjs wrapper and generated types in commonjs format (`ex…
Browse files Browse the repository at this point in the history
…port =` and `namespaces` used in types), now you can directly use exported types
  • Loading branch information
alexander-akait committed Dec 16, 2021
1 parent c5747b5 commit 3262a9a
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 157 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
"type": "opencollective",
"url": "https://opencollective.com/webpack"
},
"main": "dist/cjs.js",
"types": "types/cjs.d.ts",
"main": "dist/index.js",
"types": "types/index.d.ts",
"engines": {
"node": ">= 12.13.0"
},
"scripts": {
"start": "npm run build -- -w",
"clean": "del-cli dist",
"prebuild": "npm run clean",
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write && prettier types --write",
"prebuild": "npm run clean types",
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write",
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",
"build": "npm-run-all -p \"build:**\"",
"commitlint": "commitlint --from=master",
Expand Down
3 changes: 0 additions & 3 deletions src/cjs.js

This file was deleted.

22 changes: 11 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as os from "os";
const os = require("os");

import { SourceMapConsumer } from "source-map";
import { validate } from "schema-utils";
import serialize from "serialize-javascript";
import { Worker } from "jest-worker";
const { SourceMapConsumer } = require("source-map");
const { validate } = require("schema-utils");
const serialize = require("serialize-javascript");
const { Worker } = require("jest-worker");

import {
const {
throttleAll,
cssnanoMinify,
cssoMinify,
cleanCssMinify,
esbuildMinify,
} from "./utils";
} = require("./utils");

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

/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
/** @typedef {import("webpack").Compiler} Compiler */
Expand Down Expand Up @@ -529,7 +529,7 @@ class CssMinimizerPlugin {
try {
result = await (getWorker
? getWorker().transform(serialize(options))
: minifyFn(options));
: minify(options));
} catch (error) {
const hasSourceMap =
inputSourceMap && CssMinimizerPlugin.isSourceMap(inputSourceMap);
Expand Down Expand Up @@ -715,4 +715,4 @@ CssMinimizerPlugin.cssoMinify = cssoMinify;
CssMinimizerPlugin.cleanCssMinify = cleanCssMinify;
CssMinimizerPlugin.esbuildMinify = esbuildMinify;

export default CssMinimizerPlugin;
module.exports = CssMinimizerPlugin;
3 changes: 1 addition & 2 deletions src/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@ async function transform(options) {
return minify(evaluatedOptions);
}

module.exports.minify = minify;
module.exports.transform = transform;
module.exports = { minify, transform };
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
};
}

export {
module.exports = {
throttleAll,
cssnanoMinify,
cssoMinify,
Expand Down
18 changes: 18 additions & 0 deletions test/cache-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ describe('"cache" option', () => {
expect(readAssets(compiler, newStats, /\.css$/)).toMatchSnapshot("assets");
expect(getErrors(newStats)).toMatchSnapshot("errors");
expect(getWarnings(newStats)).toMatchSnapshot("warnings");

await new Promise((resolve) => {
compiler.close(() => {
resolve();
});
});
});

it('should work with the "memory" value for the "cache.type" option', async () => {
Expand Down Expand Up @@ -154,6 +160,12 @@ describe('"cache" option', () => {
expect(readAssets(compiler, newStats, /\.css$/)).toMatchSnapshot("assets");
expect(getErrors(newStats)).toMatchSnapshot("errors");
expect(getWarnings(newStats)).toMatchSnapshot("warnings");

await new Promise((resolve) => {
compiler.close(() => {
resolve();
});
});
});

it('should work with the "filesystem" value for the "cache.type" option', async () => {
Expand Down Expand Up @@ -217,6 +229,12 @@ describe('"cache" option', () => {
expect(readAssets(compiler, newStats, /\.css$/)).toMatchSnapshot("assets");
expect(getErrors(newStats)).toMatchSnapshot("errors");
expect(getWarnings(newStats)).toMatchSnapshot("warnings");

await new Promise((resolve) => {
compiler.close(() => {
resolve();
});
});
});

it('should work with the "filesystem" value for the "cache.type" option and source maps', async () => {
Expand Down
8 changes: 0 additions & 8 deletions test/cjs.test.js

This file was deleted.

3 changes: 0 additions & 3 deletions types/cjs.d.ts

This file was deleted.

0 comments on commit 3262a9a

Please sign in to comment.