Skip to content

Commit

Permalink
Add the Node.js exports
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Aug 30, 2024
1 parent e4bcbc1 commit bd3ad79
Show file tree
Hide file tree
Showing 5 changed files with 695 additions and 2,253 deletions.
10 changes: 10 additions & 0 deletions lib/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const {Plugin} = require("./bundle.js");

/**
* Creates a new plugin.
* @param {Partial<import("./index.js").PluginOptions>} options The plugin options.
* @returns {import("./index.js").Plugin} The newly created instance.
*/
module.exports = function phpMinifier(options = {}) {
return new Plugin(options);
}
61 changes: 61 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {Transform} from "node:stream";

/**
* Minifies PHP source code by removing comments and whitespace.
*/
export class Plugin extends Transform {

/**
* The path to the PHP executable.
*/
readonly binary: string;

/**
* The operation mode.
*/
readonly mode: TransformMode;

/**
* Value indicating whether to silence the plugin output.
*/
readonly silent: boolean;

/**
* Creates a new plugin.
* @param options An object providing values to initialize this instance.
*/
constructor(options?: Partial<PluginOptions>);
}

/**
* Defines the options of a {@link Plugin} instance.
*/
export type PluginOptions = {

/**
* The path to the PHP executable.
*/
binary: string;

/**
* The operation mode of the plugin.
*/
mode: TransformMode;

/**
* Value indicating whether to silence the plugin output.
*/
silent: boolean;
};

/**
* The operation mode of the minifier.
*/
export type TransformMode = "fast" | "safe";

/**
* Creates a new plugin.
* @param options The plugin options.
* @returns The newly created instance.
*/
export default function phpMinifier(options?: Partial<PluginOptions>): Plugin;
11 changes: 11 additions & 0 deletions lib/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import bundle from "./bundle.js";

/**
* Creates a new plugin.
* @param {Partial<import("./index.js").PluginOptions>} options The plugin options.
* @returns {import("./index.js").Plugin} The newly created instance.
*/
export default function phpMinifier(options = {}) {
const {Plugin} = bundle;
return new Plugin(options);
}
Loading

0 comments on commit bd3ad79

Please sign in to comment.