Skip to content

Commit

Permalink
perf(plugin): update type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
mohatt committed Apr 5, 2021
1 parent 96c512f commit 6b50078
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ events emitted by [file transformers](#file-transformers).

The plugin comes with these tasks out of the box:
- [Purgecss](https://github.com/mohatt/gatsby-plugin-postbuild/blob/master/src/tasks/purgecss)
Optimizes generated HTML/CSS files by removing unused CSS selectors.
Optimizes HTML/CSS files by removing unused CSS selectors.
- [Netlify Headers](https://github.com/mohatt/gatsby-plugin-postbuild/blob/master/src/tasks/netlify-headers)
Transforms HTML link tags with resource hints into HTTP Link headers using Netlify's `_headers` file.
- [Minify](https://github.com/mohatt/gatsby-plugin-postbuild/blob/master/src/tasks/minify)
Minifies HTML inline scripts and styles using [terser](https://github.com/terser/terser) and [cssnano](https://github.com/cssnano/cssnano).

---
- [Installation](#installation)
Expand Down
1 change: 1 addition & 0 deletions src/files/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Filesystem, IFilesystemReportMeta } from '../filesystem'
import type { IExtensionOptions } from '../options'
import type { GatsbyNodeArgs } from '../gatsby'

/** @internal */
export interface FileConstructorArgs {
filesystem: Filesystem
tasks: Tasks
Expand Down
5 changes: 5 additions & 0 deletions types/files/base.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IFilesystemReportMeta } from '../filesystem'
import type { IExtensionOptions } from '../options'
/**
* Base class for all file types
*/
Expand All @@ -15,6 +16,10 @@ export default abstract class File {
* File extension
*/
extension: string
/**
* File extension options
*/
options: IExtensionOptions
/**
* Meta fields to be displayed in
* the file write report
Expand Down
14 changes: 12 additions & 2 deletions types/files/html.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import * as parse5 from 'parse5'
import parse5Adaptor from 'parse5/lib/tree-adapters/default'
import File from './base'
import type { IExtensionOptions } from '../index'
export declare type IFileHtmlOptions = IExtensionOptions<{
commons: {
[type: string]: string[]
}
}>
/**
* A callback function to be run on tree nodes
* @see FileHtml.walk
*/
export declare type IFileHtmlNodeWalker = (node: parse5.Node) => Promise<void> | void
export declare type IFileHtmlNodeWalker = (node: parse5.Node, prev?: parse5.Node, next?: parse5.Node) => Promise<void> | void
/**
* Interface for html files
*/
Expand All @@ -22,11 +28,15 @@ export declare class FileHtml extends File {
* Parse5 tree adaptor
*/
adaptor: typeof parse5Adaptor
/**
* Html extension options
*/
options: IFileHtmlOptions
/**
* Recursively walks through a parse5 tree invoking a callback
* on every node on the tree.
*/
walk (cb: IFileHtmlNodeWalker, node?: parse5.Node): Promise<void>;
walk (cb: IFileHtmlNodeWalker, root?: parse5.Node, processGatsbyNode?: boolean): Promise<void>;
/**
* Resolves a href attribute of a given node into local file path
*
Expand Down
7 changes: 3 additions & 4 deletions types/gatsby-node.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { GatsbyJoi, GatsbyNodeArgs, GatsbyPluginOptions } from './gatsby'
/**
* Initializes Postbuild and validates user-defined
* options against the final options schema
* Runs before any other node API
* Initializes Postbuild and validates user-defined options against
* the final options schema. Runs before any other node API
*/
export declare function pluginOptionsSchema ({ Joi }: {
Joi: GatsbyJoi
Expand All @@ -12,6 +11,6 @@ export declare function pluginOptionsSchema ({ Joi }: {
*/
export declare function onPreBootstrap (gatsby: GatsbyNodeArgs, pluginOptions: GatsbyPluginOptions): Promise<void>
/**
* Runs Postbuild on the generated files under `/public`
* Runs Postbuild on the generated static files
*/
export declare function onPostBuild (gatsby: GatsbyNodeArgs): Promise<void>
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
export type { IPostbuildArg } from './postbuild'
export type { ITaskApi, ITaskApiOptions, ITaskApiEvents, ITaskOptions, IEvents } from './tasks'
export type { Filesystem, IFilesystemReportMeta, IGlobOptions } from './filesystem'
export type { IOptions, IOptionProcessing, IOptionProcessingStrategy } from './options'
export type { IOptions, IExtensionOptions, IOptionProcessing, IOptionProcessingStrategy } from './options'
export * from './files'
5 changes: 4 additions & 1 deletion types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export interface IOptionProcessing {
concurrency: number
strategy: IOptionProcessingStrategy
}
export declare type IExtensionOptions<O = {
[option: string]: any
}> = IOptionProcessing & O
/**
* Plugin options interface
*/
Expand All @@ -17,7 +20,7 @@ export declare type IOptions = {
events: ITaskApiEvents<any>
processing: IOptionProcessing
extensions: {
[ext: string]: Partial<IOptionProcessing> | undefined
[ext: string]: Partial<IExtensionOptions>
}
} & {
[task: string]: ITaskOptions
Expand Down
8 changes: 5 additions & 3 deletions types/tasks.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Node as parse5Node } from 'parse5'
import type { GatsbyJoi } from './gatsby'
import type { IPostbuildArg, IOptionProcessing, File, FileGeneric, FileHtml } from './index'
import type { IPostbuildArg, IExtensionOptions, File, FileGeneric, FileHtml } from './index'
/**
* Generic type for async/sync functions
*/
Expand All @@ -20,14 +20,16 @@ export interface IEvents<O extends ITaskOptions> {
}
html: {
configure: IEvent<O, {
config: IOptionProcessing
config: IExtensionOptions
}>
parse: IEvent<O, {
html: string
}, FileHtml, string>
tree: IEvent<O, {}, FileHtml>
node: IEvent<O, {
node: parse5Node
previousNode?: parse5Node
nextNode?: parse5Node
}, FileHtml>
serialize: IEvent<O, {}, FileHtml>
write: IEvent<O, {
Expand All @@ -36,7 +38,7 @@ export interface IEvents<O extends ITaskOptions> {
}
unknown: {
configure: IEvent<O, {
config: IOptionProcessing
config: IExtensionOptions
}>
content: IEvent<O, {
raw: string
Expand Down

0 comments on commit 6b50078

Please sign in to comment.