Skip to content

Commit

Permalink
feat: removed cjs wrapper (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Dec 16, 2021
1 parent 012b0f3 commit 04140de
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 50 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"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",
"clean": "del-cli dist types",
"prebuild": "npm run clean",
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write",
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",
Expand Down
1 change: 0 additions & 1 deletion src/cjs.js

This file was deleted.

10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { validate } from "schema-utils";
const { validate } = require("schema-utils");

import 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 @@ -156,7 +156,7 @@ class JsonMinimizerPlugin {
};

try {
output = await minifyFn(options);
output = await minify(options);
} catch (error) {
compilation.errors.push(
/** @type {WebpackError} */ (
Expand Down Expand Up @@ -220,4 +220,4 @@ class JsonMinimizerPlugin {
}
}

export default JsonMinimizerPlugin;
module.exports = JsonMinimizerPlugin;
2 changes: 1 addition & 1 deletion src/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ const minify = async (options) => {
return { code: result };
};

module.exports.minify = minify;
module.exports = { minify };
8 changes: 0 additions & 8 deletions test/cjs.test.js

This file was deleted.

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

This file was deleted.

75 changes: 45 additions & 30 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
export default JsonMinimizerPlugin;
export type Schema = import("schema-utils/declarations/validate").Schema;
export type Compiler = import("webpack").Compiler;
export type Compilation = import("webpack").Compilation;
export type Asset = import("webpack").Asset;
export type WebpackError = import("webpack").WebpackError;
export type Rule = RegExp | string;
export type Rules = Rule[] | Rule;
export type JSONOptions = {
replacer?:
| ((this: any, key: string, value: any) => any | (number | string)[] | null)
| undefined;
space?: string | number | undefined;
};
export type BasePluginOptions = {
test?: Rules | undefined;
include?: Rules | undefined;
exclude?: Rules | undefined;
minimizerOptions?: JSONOptions | undefined;
};
export type MinimizedResult = {
code: string;
};
export type InternalOptions = {
input: string;
minimizerOptions?: JSONOptions | undefined;
};
export type InternalPluginOptions = BasePluginOptions;
export = JsonMinimizerPlugin;
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
/** @typedef {import("webpack").Compiler} Compiler */
/** @typedef {import("webpack").Compilation} Compilation */
Expand Down Expand Up @@ -59,13 +32,12 @@ export type InternalPluginOptions = BasePluginOptions;
*/
declare class JsonMinimizerPlugin {
/**
* @private
* @param {any} error
* @param {string} file
* @param {string} context
* @returns {Error}
*/
private static buildError;
static buildError(error: any, file: string, context: string): Error;
/**
* @param {BasePluginOptions} [options]
*/
Expand All @@ -89,3 +61,46 @@ declare class JsonMinimizerPlugin {
*/
apply(compiler: Compiler): void;
}
declare namespace JsonMinimizerPlugin {
export {
Schema,
Compiler,
Compilation,
Asset,
WebpackError,
Rule,
Rules,
JSONOptions,
BasePluginOptions,
MinimizedResult,
InternalOptions,
InternalPluginOptions,
};
}
type Compiler = import("webpack").Compiler;
type BasePluginOptions = {
test?: Rules | undefined;
include?: Rules | undefined;
exclude?: Rules | undefined;
minimizerOptions?: JSONOptions | undefined;
};
type Schema = import("schema-utils/declarations/validate").Schema;
type Compilation = import("webpack").Compilation;
type Asset = import("webpack").Asset;
type WebpackError = import("webpack").WebpackError;
type Rule = RegExp | string;
type Rules = Rule[] | Rule;
type JSONOptions = {
replacer?:
| ((this: any, key: string, value: any) => any | (number | string)[] | null)
| undefined;
space?: string | number | undefined;
};
type MinimizedResult = {
code: string;
};
type InternalOptions = {
input: string;
minimizerOptions?: JSONOptions | undefined;
};
type InternalPluginOptions = BasePluginOptions;

0 comments on commit 04140de

Please sign in to comment.