Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit 6d3567e

Browse files
NotWoodslukastaegert
authored andcommitted
Add .d.ts typings file (#189)
* Add .d.ts typings file * Add test file to check that types are set correctly * Move typings test file to root so its not run by mocha * Automate type tests
1 parent ac791de commit 6d3567e

File tree

6 files changed

+141
-5
lines changed

6 files changed

+141
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export default {
2020
input: 'main.js',
2121
output: {
2222
file: 'bundle.js',
23-
format: 'iife'
23+
format: 'iife',
24+
name: 'MyModule'
2425
},
25-
name: 'MyModule',
2626
plugins: [
2727
resolve({
2828
// use "module" field for ES6 module if possible
@@ -35,7 +35,7 @@ export default {
3535
jsnext: true, // Default: false
3636

3737
// use "main" field or index.js, even if it's not an ES6 module
38-
// (needs to be converted from CommonJS to ES6
38+
// (needs to be converted from CommonJS to ES6)
3939
// – see https://github.com/rollup/rollup-plugin-commonjs
4040
main: true, // Default: true
4141

index.d.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { Plugin } from 'rollup';
2+
import { AsyncOpts } from 'resolve';
3+
4+
interface RollupNodeResolveOptions {
5+
/**
6+
* use "module" field for ES6 module if possible
7+
* @default true
8+
*/
9+
module?: boolean;
10+
/**
11+
* use "jsnext:main" if possible
12+
* legacy field pointing to ES6 module in third-party libraries,
13+
* deprecated in favor of "pkg.module":
14+
* - see: https://github.com/rollup/rollup/wiki/pkg.module
15+
* @default false
16+
*/
17+
jsnext?: boolean;
18+
/**
19+
* use "main" field or index.js, even if it's not an ES6 module
20+
* (needs to be converted from CommonJS to ES6)
21+
* – see https://github.com/rollup/rollup-plugin-commonjs
22+
* @default true
23+
*/
24+
main?: boolean;
25+
/**
26+
* some package.json files have a `browser` field which
27+
* specifies alternative files to load for people bundling
28+
* for the browser. If that's you, use this option, otherwise
29+
* pkg.browser will be ignored
30+
* @default false
31+
*/
32+
browser?: boolean;
33+
/**
34+
* not all files you want to resolve are .js files
35+
* @default [ '.mjs', '.js', '.json', '.node' ]
36+
*/
37+
extensions?: ReadonlyArray<string>;
38+
/**
39+
* whether to prefer built-in modules (e.g. `fs`, `path`) or
40+
* local ones with the same names
41+
* @default true
42+
*/
43+
preferBuiltins?: boolean;
44+
/**
45+
* Lock the module search in this path (like a chroot). Module defined
46+
* outside this path will be marked as external
47+
* @default '/'
48+
*/
49+
jail?: string;
50+
/**
51+
* Set to an array of strings and/or regexps to lock the module search
52+
* to modules that match at least one entry. Modules not matching any
53+
* entry will be marked as external
54+
* @default null
55+
*/
56+
only?: ReadonlyArray<string | RegExp> | null;
57+
/**
58+
* If true, inspect resolved files to check that they are
59+
* ES2015 modules
60+
* @default false
61+
*/
62+
modulesOnly?: boolean;
63+
/**
64+
* Any additional options that should be passed through
65+
* to node-resolve
66+
*/
67+
customResolveOptions?: AsyncOpts;
68+
}
69+
70+
/**
71+
* Locate modules using the Node resolution algorithm, for using third party modules in node_modules
72+
*/
73+
export default function nodeResolve(options?: RollupNodeResolveOptions): Plugin;

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"rollup-plugin-buble": "^0.19.6",
1212
"rollup-plugin-commonjs": "^9.3.4",
1313
"string-capitalize": "^1.0.1",
14+
"typescript": "^3.4.1",
1415
"vlq": "^1.0.0"
1516
},
1617
"main": "dist/rollup-plugin-node-resolve.cjs.js",
@@ -20,16 +21,18 @@
2021
"build": "rollup -c",
2122
"pretest": "npm run build",
2223
"test": "mocha",
23-
"posttest": "eslint src test/*.js",
24+
"posttest": "tsc && eslint src test/*.js",
2425
"lint": "eslint src",
2526
"prepublishOnly": "npm test",
2627
"prepare": "npm run build"
2728
},
2829
"files": [
2930
"src",
30-
"dist"
31+
"dist",
32+
"index.d.ts"
3133
],
3234
"dependencies": {
35+
"@types/resolve": "0.0.8",
3336
"builtin-modules": "^3.0.0",
3437
"is-module": "^1.0.0",
3538
"resolve": "^1.10.0"

tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"lib": [
4+
"es6"
5+
],
6+
"noImplicitAny": true,
7+
"noImplicitThis": true,
8+
"strict": true,
9+
"noEmit": true,
10+
"allowJs": true
11+
},
12+
"files": [
13+
"index.d.ts",
14+
"typings-test.js"
15+
]
16+
}

typings-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @ts-check
2+
import resolve from '.';
3+
4+
/** @type {import("rollup").RollupOptions} */
5+
const config = {
6+
input: 'main.js',
7+
output: {
8+
file: 'bundle.js',
9+
format: 'iife',
10+
name: 'MyModule',
11+
},
12+
plugins: [
13+
resolve({
14+
module: true,
15+
jsnext: true,
16+
main: true,
17+
browser: true,
18+
extensions: [ '.mjs', '.js', '.jsx', '.json' ],
19+
preferBuiltins: false,
20+
jail: '/my/jail/path',
21+
only: [ 'some_module', /^@some_scope\/.*$/ ],
22+
modulesOnly: true,
23+
customResolveOptions: {
24+
moduleDirectory: 'js_modules'
25+
}
26+
})
27+
]
28+
};
29+
30+
export default config;

0 commit comments

Comments
 (0)