Open jrson83 opened 2 years ago
Yes the WASM library is currently missing the type declarations. Is copying the existing type declarations from the Node.js library to index.d.ts
sufficient? I'm not sure how Deno detects type declarations.
@wilsonzlin thanks for replying. I have tested this locally. The index.d.ts
for Deno should include the following code:
// See comment below
/** import type { Buffer } from "https://deno.land/std/node/buffer.ts"; */
export interface CFG {
/** Do not minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant. */
do_not_minify_doctype?: boolean;
/** Ensure all unquoted attribute values in the output do not contain any characters prohibited by the WHATWG specification. */
ensure_spec_compliant_unquoted_attribute_values?: boolean;
/** Do not omit closing tags when possible. */
keep_closing_tags?: boolean;
/** Do not omit `<html>` and `<head>` opening tags when they don't have attributes. */
keep_html_and_head_opening_tags?: boolean;
/** Keep spaces between attributes when possible to conform to HTML standards. */
keep_spaces_between_attributes?: boolean;
/** Keep all comments. */
keep_comments?: boolean;
/**
* If enabled, content in `<script>` tags with a JS or no [MIME type](https://mimesniff.spec.whatwg.org/#javascript-mime-type) will be minified using [minify-js](https://github.com/wilsonzlin/minify-js).
*/
minify_js?: boolean;
/**
* If enabled, CSS in `<style>` tags and `style` attributes will be minified.
*/
minify_css?: boolean;
/** Remove all bangs. */
remove_bangs?: boolean;
/** Remove all processing_instructions. */
remove_processing_instructions?: boolean;
}
// Maybe we do not export the function at all, only the `CFG` interface, so we don't need to import/export `Buffer` at all
/** export function minify(src: Buffer, cfg: CFG): Buffer; */
Then inside your index.js
, the index.d.ts
file should be included using the triple-slash reference directive:
/// <reference types="./index.d.ts" />
It should be possible to re-export the type
inside my plugins deps.ts
file using (local path example):
export { default as init, minify } from "./minify-html/index.js";
export type { CFG } from "./minify-html/index.js"
Then inside my plugins mod.ts
:
import { init, minify as minifyHTML } from "./deps.ts";
import type { CFG } from "./deps.ts";
...
page.content = decoder.decode(
minifyHTML(encoder.encode(content), options.options),
);
It would be awesome if you have time to implement this. I would create a PR, but I never used Rust before.
Edit: Please see updated code
If the d.ts
file needs just to be created I could do a PR?
I'm using the deno package and want to create a plugin for Lume static site builder.
It would be really great if there was a seperate export of the type
interface
for thecfg
options, which is currently defined as parameter for theminify
function.Because there is no type export available and the index.js exported function
cfg
is typeany
, IDE type checking and auto-suggestions do not work.Or even worth:
Would you consider to change the
index.d.ts
to export aninterface CFG
and also make it available on deno?Update:
The Lume plugin is commited, you can check in the experimental-plugins repo.