Skip to content

Commit

Permalink
feat(dsv,dynamic-import-vars,image,legacy,multi-entry,strip,sucrase,u…
Browse files Browse the repository at this point in the history
…rl,yaml): add typings (#898)

* feat(dsv): add typings

* feat(dynamic-import-vars): add typings

* feat(image): add typings

* feat(legacy): add typings

* feat(multi-entry): add typings

* feat(strip): add typings

* feat(sucrase): add typings

* feat(url): add typings

* feat(yaml): add typings

* fix(dynamic-import-vars): fix typings

* chore(types): make options optional

* chore(types): make options optional

* run linter

* test(types): add tests for typings

* deps(dsv): add @types/d3-dsv

* deps: make `@types/d3-dsv` a dependency

* chore(tests): explicitly import from `types` dir

* chore(tests): import plugins from root
  • Loading branch information
Luke-zhang-04 authored Jul 26, 2021
1 parent ca0540f commit 4885d59
Show file tree
Hide file tree
Showing 30 changed files with 621 additions and 273 deletions.
2 changes: 1 addition & 1 deletion packages/commonjs/test/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RollupOptions } from 'rollup';

import commonjs from '../types';
import commonjs from '..';

const config: RollupOptions = {
input: 'main.js',
Expand Down
3 changes: 3 additions & 0 deletions packages/dsv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@
},
"files": [
"dist",
"types",
"README.md",
"LICENSE"
],
"dependencies": {
"@rollup/pluginutils": "^3.1.0",
"@types/d3-dsv": "~1.2.0",
"d3-dsv": "1.2.0",
"tosource": "^1.0.0"
},
"devDependencies": {
"del-cli": "^3.0.1",
"rollup": "^2.23.0"
},
"types": "./types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
Expand Down
22 changes: 22 additions & 0 deletions packages/dsv/test/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { RollupOptions } from 'rollup';

import dsv from '..';

const config: RollupOptions = {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
dsv({
include: 'node_modules/**',
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
processRow(row) {
return row;
}
})
]
};

export default config;
29 changes: 29 additions & 0 deletions packages/dsv/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DSVRowString } from 'd3-dsv';
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';

interface RollupDsvOptions {
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
* should operate on.
* By default all files are targeted.
*/
include?: FilterPattern;
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
* should _ignore_.
* By default no files are ignored.
*/
exclude?: FilterPattern;
/**
* Specifies a function which processes each row in the parsed array.
* The function can either manipulate the passed row, or return an entirely new row object.
* @default undefined
*/
processRow?: null | ((row: DSVRowString, id: string) => DSVRowString | undefined);
}

/**
* Convert `.csv` and `.tsv `files into JavaScript modules with `d3-dsv`.
*/
export default function dsv(options?: RollupDsvOptions): Plugin;
1 change: 1 addition & 0 deletions packages/dynamic-import-vars/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"prettier": "^2.0.5",
"rollup": "^2.23.0"
},
"types": "./types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
Expand Down
20 changes: 20 additions & 0 deletions packages/dynamic-import-vars/test/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { RollupOptions } from 'rollup';

import dynamicImportVars from '..';

const config: RollupOptions = {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
dynamicImportVars({
include: 'node_modules/**',
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
warnOnError: true
})
]
};

export default config;
35 changes: 35 additions & 0 deletions packages/dynamic-import-vars/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { FilterPattern } from '@rollup/pluginutils';
import { walk } from 'estree-walker';
import { Plugin } from 'rollup';

interface RollupDynamicImportVariablesOptions {
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
* should operate on.
* By default all files are targeted.
*/
include?: FilterPattern;
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
* should _ignore_.
* By default no files are ignored.
*/
exclude?: FilterPattern;
/**
* By default, the plugin quits the build process when it encounters an error.
* If you set this option to true, it will throw a warning instead and leave the code untouched.
* @default false
*/
warnOnError?: boolean;
}

export class VariableDynamicImportError extends Error {}

export function dynamicImportToGlob(...params: Parameters<typeof walk>): null | string;

/**
* Support variables in dynamic imports in Rollup.
*/
export default function dynamicImportVariables(
options?: RollupDynamicImportVariablesOptions
): Plugin;
2 changes: 1 addition & 1 deletion packages/html/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface RollupHtmlOptions {
fileName?: string;
meta?: Record<string, any>[];
publicPath?: string;
template?: (templateOptions: RollupHtmlTemplateOptions) => string;
template?: (templateoptions?: RollupHtmlTemplateOptions) => string;
}

export function makeHtmlAttributes(attributes: Record<string, string>): string;
Expand Down
2 changes: 2 additions & 0 deletions packages/image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"files": [
"dist",
"tests",
"README.md",
"LICENSE"
],
Expand All @@ -53,6 +54,7 @@
"@rollup/plugin-buble": "^0.21.3",
"rollup": "^2.23.0"
},
"types": "./types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
Expand Down
20 changes: 20 additions & 0 deletions packages/image/test/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { RollupOptions } from 'rollup';

import image from '..';

const config: RollupOptions = {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
image({
include: 'node_modules/**',
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
dom: false
})
]
};

export default config;
34 changes: 34 additions & 0 deletions packages/image/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';

interface RollupImageOptions {
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
* should operate on.
* By default all files are targeted.
*/
include?: FilterPattern;
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
* should _ignore_.
* By default no files are ignored.
*/
exclude?: FilterPattern;
/**
* If `true`, instructs the plugin to generate an ES Module which exports a DOM `Image` which can
* be used with a browser's DOM.
* Otherwise, the plugin generates an ES Module which exports a `default const` containing the
* Base64 representation of the image.
*
* Using this option set to `true`, the export can be used as such:
*
* @example
* import logo from './rollup.png';
* document.body.appendChild(logo);
*
* @default false
*/
dom?: boolean;
}

export default function image(options?: RollupImageOptions): Plugin;
1 change: 1 addition & 0 deletions packages/legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"files": [
"dist",
"types",
"README.md",
"LICENSE"
],
Expand Down
24 changes: 24 additions & 0 deletions packages/legacy/test/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RollupOptions } from 'rollup';

import legacy from '..';

const config: RollupOptions = {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
legacy({
'vendor/some-library.js': 'someLibrary',

'vendor/another-library.js': {
foo: 'anotherLib.foo',
bar: 'anotherLib.bar',
baz: 'anotherLib.baz'
}
})
]
};

export default config;
10 changes: 10 additions & 0 deletions packages/legacy/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Plugin } from 'rollup';

interface RollupLegacyOptions {
[key: string]: string | { [key: string]: string };
}

/**
* A Rollup plugin which adds `export` declarations to legacy non-module scripts.
*/
export default function legacy(options: RollupLegacyOptions): Plugin;
2 changes: 2 additions & 0 deletions packages/multi-entry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"files": [
"dist",
"types",
"README.md",
"LICENSE"
],
Expand All @@ -54,6 +55,7 @@
"devDependencies": {
"rollup": "^2.23.0"
},
"types": "./types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
Expand Down
21 changes: 21 additions & 0 deletions packages/multi-entry/test/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { RollupOptions } from 'rollup';

import multiEntry from '..';

const config: RollupOptions = {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
multiEntry({
include: 'node_modules/**',
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
exports: false,
entryFileName: 'multi-entry.js'
})
]
};

export default config;
37 changes: 37 additions & 0 deletions packages/multi-entry/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';

interface RollupMultiEntryOptions {
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
* should operate on.
* By default all files are targeted.
*/
include?: FilterPattern;
/**
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
* should _ignore_.
* By default no files are ignored.
*/
exclude?: FilterPattern;
/**
* - If `true`, instructs the plugin to export named exports to the bundle from all entries.
* - If `false`, the plugin will not export any entry exports to the bundle.
* @default true
*/
exports?: boolean;
/**
* `entryFileName` changes the name of the generated entry file.
* By default, it will override `outputOptions.entryFileNames` to be `'multi-entry.js'`.
* @default 'multi-entry.js'
*/
entryFileName?: string;
}

/**
* A Rollup plugin which allows use of multiple entry points for a bundle.
*
* _Note: `default` exports cannot be combined and exported by this plugin. Only named exports
* will be exported._
*/
export default function multiEntry(options?: RollupMultiEntryOptions): Plugin;
4 changes: 3 additions & 1 deletion packages/strip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"test": "ava"
},
"files": [
"dist"
"dist",
"types"
],
"keywords": [
"rollup",
Expand All @@ -47,6 +48,7 @@
"acorn": "^7.3.1",
"rollup": "^2.23.0"
},
"types": "./types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
Expand Down
23 changes: 23 additions & 0 deletions packages/strip/test/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { RollupOptions } from 'rollup';

import strip from '../types/index';

const config: RollupOptions = {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
strip({
include: 'node_modules/**',
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
debugger: true,
functions: ['console.*', 'assert.*', 'expect'],
labels: [],
sourceMap: true
})
]
};

export default config;
Loading

0 comments on commit 4885d59

Please sign in to comment.