Skip to content

Commit 4885d59

Browse files
feat(dsv,dynamic-import-vars,image,legacy,multi-entry,strip,sucrase,url,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
1 parent ca0540f commit 4885d59

File tree

30 files changed

+621
-273
lines changed

30 files changed

+621
-273
lines changed

packages/commonjs/test/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { RollupOptions } from 'rollup';
22

3-
import commonjs from '../types';
3+
import commonjs from '..';
44

55
const config: RollupOptions = {
66
input: 'main.js',

packages/dsv/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@
3030
},
3131
"files": [
3232
"dist",
33+
"types",
3334
"README.md",
3435
"LICENSE"
3536
],
3637
"dependencies": {
3738
"@rollup/pluginutils": "^3.1.0",
39+
"@types/d3-dsv": "~1.2.0",
3840
"d3-dsv": "1.2.0",
3941
"tosource": "^1.0.0"
4042
},
4143
"devDependencies": {
4244
"del-cli": "^3.0.1",
4345
"rollup": "^2.23.0"
4446
},
47+
"types": "./types/index.d.ts",
4548
"ava": {
4649
"babel": {
4750
"compileEnhancements": false

packages/dsv/test/types.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { RollupOptions } from 'rollup';
2+
3+
import dsv from '..';
4+
5+
const config: RollupOptions = {
6+
input: 'main.js',
7+
output: {
8+
file: 'bundle.js',
9+
format: 'iife'
10+
},
11+
plugins: [
12+
dsv({
13+
include: 'node_modules/**',
14+
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
15+
processRow(row) {
16+
return row;
17+
}
18+
})
19+
]
20+
};
21+
22+
export default config;

packages/dsv/types/index.d.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { DSVRowString } from 'd3-dsv';
2+
import { FilterPattern } from '@rollup/pluginutils';
3+
import { Plugin } from 'rollup';
4+
5+
interface RollupDsvOptions {
6+
/**
7+
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
8+
* should operate on.
9+
* By default all files are targeted.
10+
*/
11+
include?: FilterPattern;
12+
/**
13+
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
14+
* should _ignore_.
15+
* By default no files are ignored.
16+
*/
17+
exclude?: FilterPattern;
18+
/**
19+
* Specifies a function which processes each row in the parsed array.
20+
* The function can either manipulate the passed row, or return an entirely new row object.
21+
* @default undefined
22+
*/
23+
processRow?: null | ((row: DSVRowString, id: string) => DSVRowString | undefined);
24+
}
25+
26+
/**
27+
* Convert `.csv` and `.tsv `files into JavaScript modules with `d3-dsv`.
28+
*/
29+
export default function dsv(options?: RollupDsvOptions): Plugin;

packages/dynamic-import-vars/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"prettier": "^2.0.5",
6363
"rollup": "^2.23.0"
6464
},
65+
"types": "./types/index.d.ts",
6566
"ava": {
6667
"babel": {
6768
"compileEnhancements": false
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { RollupOptions } from 'rollup';
2+
3+
import dynamicImportVars from '..';
4+
5+
const config: RollupOptions = {
6+
input: 'main.js',
7+
output: {
8+
file: 'bundle.js',
9+
format: 'iife'
10+
},
11+
plugins: [
12+
dynamicImportVars({
13+
include: 'node_modules/**',
14+
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
15+
warnOnError: true
16+
})
17+
]
18+
};
19+
20+
export default config;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { FilterPattern } from '@rollup/pluginutils';
2+
import { walk } from 'estree-walker';
3+
import { Plugin } from 'rollup';
4+
5+
interface RollupDynamicImportVariablesOptions {
6+
/**
7+
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
8+
* should operate on.
9+
* By default all files are targeted.
10+
*/
11+
include?: FilterPattern;
12+
/**
13+
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
14+
* should _ignore_.
15+
* By default no files are ignored.
16+
*/
17+
exclude?: FilterPattern;
18+
/**
19+
* By default, the plugin quits the build process when it encounters an error.
20+
* If you set this option to true, it will throw a warning instead and leave the code untouched.
21+
* @default false
22+
*/
23+
warnOnError?: boolean;
24+
}
25+
26+
export class VariableDynamicImportError extends Error {}
27+
28+
export function dynamicImportToGlob(...params: Parameters<typeof walk>): null | string;
29+
30+
/**
31+
* Support variables in dynamic imports in Rollup.
32+
*/
33+
export default function dynamicImportVariables(
34+
options?: RollupDynamicImportVariablesOptions
35+
): Plugin;

packages/html/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface RollupHtmlOptions {
1515
fileName?: string;
1616
meta?: Record<string, any>[];
1717
publicPath?: string;
18-
template?: (templateOptions: RollupHtmlTemplateOptions) => string;
18+
template?: (templateoptions?: RollupHtmlTemplateOptions) => string;
1919
}
2020

2121
export function makeHtmlAttributes(attributes: Record<string, string>): string;

packages/image/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
},
3434
"files": [
3535
"dist",
36+
"tests",
3637
"README.md",
3738
"LICENSE"
3839
],
@@ -53,6 +54,7 @@
5354
"@rollup/plugin-buble": "^0.21.3",
5455
"rollup": "^2.23.0"
5556
},
57+
"types": "./types/index.d.ts",
5658
"ava": {
5759
"babel": {
5860
"compileEnhancements": false

packages/image/test/types.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { RollupOptions } from 'rollup';
2+
3+
import image from '..';
4+
5+
const config: RollupOptions = {
6+
input: 'main.js',
7+
output: {
8+
file: 'bundle.js',
9+
format: 'iife'
10+
},
11+
plugins: [
12+
image({
13+
include: 'node_modules/**',
14+
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
15+
dom: false
16+
})
17+
]
18+
};
19+
20+
export default config;

packages/image/types/index.d.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { FilterPattern } from '@rollup/pluginutils';
2+
import { Plugin } from 'rollup';
3+
4+
interface RollupImageOptions {
5+
/**
6+
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
7+
* should operate on.
8+
* By default all files are targeted.
9+
*/
10+
include?: FilterPattern;
11+
/**
12+
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
13+
* should _ignore_.
14+
* By default no files are ignored.
15+
*/
16+
exclude?: FilterPattern;
17+
/**
18+
* If `true`, instructs the plugin to generate an ES Module which exports a DOM `Image` which can
19+
* be used with a browser's DOM.
20+
* Otherwise, the plugin generates an ES Module which exports a `default const` containing the
21+
* Base64 representation of the image.
22+
*
23+
* Using this option set to `true`, the export can be used as such:
24+
*
25+
* @example
26+
* import logo from './rollup.png';
27+
* document.body.appendChild(logo);
28+
*
29+
* @default false
30+
*/
31+
dom?: boolean;
32+
}
33+
34+
export default function image(options?: RollupImageOptions): Plugin;

packages/legacy/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
},
3131
"files": [
3232
"dist",
33+
"types",
3334
"README.md",
3435
"LICENSE"
3536
],

packages/legacy/test/types.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { RollupOptions } from 'rollup';
2+
3+
import legacy from '..';
4+
5+
const config: RollupOptions = {
6+
input: 'main.js',
7+
output: {
8+
file: 'bundle.js',
9+
format: 'iife'
10+
},
11+
plugins: [
12+
legacy({
13+
'vendor/some-library.js': 'someLibrary',
14+
15+
'vendor/another-library.js': {
16+
foo: 'anotherLib.foo',
17+
bar: 'anotherLib.bar',
18+
baz: 'anotherLib.baz'
19+
}
20+
})
21+
]
22+
};
23+
24+
export default config;

packages/legacy/types/index.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Plugin } from 'rollup';
2+
3+
interface RollupLegacyOptions {
4+
[key: string]: string | { [key: string]: string };
5+
}
6+
7+
/**
8+
* A Rollup plugin which adds `export` declarations to legacy non-module scripts.
9+
*/
10+
export default function legacy(options: RollupLegacyOptions): Plugin;

packages/multi-entry/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
},
3434
"files": [
3535
"dist",
36+
"types",
3637
"README.md",
3738
"LICENSE"
3839
],
@@ -54,6 +55,7 @@
5455
"devDependencies": {
5556
"rollup": "^2.23.0"
5657
},
58+
"types": "./types/index.d.ts",
5759
"ava": {
5860
"babel": {
5961
"compileEnhancements": false

packages/multi-entry/test/types.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { RollupOptions } from 'rollup';
2+
3+
import multiEntry from '..';
4+
5+
const config: RollupOptions = {
6+
input: 'main.js',
7+
output: {
8+
file: 'bundle.js',
9+
format: 'iife'
10+
},
11+
plugins: [
12+
multiEntry({
13+
include: 'node_modules/**',
14+
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
15+
exports: false,
16+
entryFileName: 'multi-entry.js'
17+
})
18+
]
19+
};
20+
21+
export default config;

packages/multi-entry/types/index.d.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { FilterPattern } from '@rollup/pluginutils';
2+
import { Plugin } from 'rollup';
3+
4+
interface RollupMultiEntryOptions {
5+
/**
6+
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
7+
* should operate on.
8+
* By default all files are targeted.
9+
*/
10+
include?: FilterPattern;
11+
/**
12+
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin
13+
* should _ignore_.
14+
* By default no files are ignored.
15+
*/
16+
exclude?: FilterPattern;
17+
/**
18+
* - If `true`, instructs the plugin to export named exports to the bundle from all entries.
19+
* - If `false`, the plugin will not export any entry exports to the bundle.
20+
* @default true
21+
*/
22+
exports?: boolean;
23+
/**
24+
* `entryFileName` changes the name of the generated entry file.
25+
* By default, it will override `outputOptions.entryFileNames` to be `'multi-entry.js'`.
26+
* @default 'multi-entry.js'
27+
*/
28+
entryFileName?: string;
29+
}
30+
31+
/**
32+
* A Rollup plugin which allows use of multiple entry points for a bundle.
33+
*
34+
* _Note: `default` exports cannot be combined and exported by this plugin. Only named exports
35+
* will be exported._
36+
*/
37+
export default function multiEntry(options?: RollupMultiEntryOptions): Plugin;

packages/strip/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"test": "ava"
2828
},
2929
"files": [
30-
"dist"
30+
"dist",
31+
"types"
3132
],
3233
"keywords": [
3334
"rollup",
@@ -47,6 +48,7 @@
4748
"acorn": "^7.3.1",
4849
"rollup": "^2.23.0"
4950
},
51+
"types": "./types/index.d.ts",
5052
"ava": {
5153
"babel": {
5254
"compileEnhancements": false

packages/strip/test/types.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { RollupOptions } from 'rollup';
2+
3+
import strip from '../types/index';
4+
5+
const config: RollupOptions = {
6+
input: 'main.js',
7+
output: {
8+
file: 'bundle.js',
9+
format: 'iife'
10+
},
11+
plugins: [
12+
strip({
13+
include: 'node_modules/**',
14+
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
15+
debugger: true,
16+
functions: ['console.*', 'assert.*', 'expect'],
17+
labels: [],
18+
sourceMap: true
19+
})
20+
]
21+
};
22+
23+
export default config;

0 commit comments

Comments
 (0)