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

Add .d.ts typings file #189

Merged
merged 4 commits into from Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -20,9 +20,9 @@ export default {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
format: 'iife',
name: 'MyModule'
},
name: 'MyModule',
plugins: [
resolve({
// use "module" field for ES6 module if possible
Expand All @@ -35,7 +35,7 @@ export default {
jsnext: true, // Default: false

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

Expand Down
73 changes: 73 additions & 0 deletions index.d.ts
@@ -0,0 +1,73 @@
import { Plugin } from 'rollup';
import { AsyncOpts } from 'resolve';

interface RollupNodeResolveOptions {
/**
* use "module" field for ES6 module if possible
* @default true
*/
module?: boolean;
/**
* use "jsnext:main" if possible
* legacy field pointing to ES6 module in third-party libraries,
* deprecated in favor of "pkg.module":
* - see: https://github.com/rollup/rollup/wiki/pkg.module
* @default false
*/
jsnext?: boolean;
/**
* use "main" field or index.js, even if it's not an ES6 module
* (needs to be converted from CommonJS to ES6)
* – see https://github.com/rollup/rollup-plugin-commonjs
* @default true
*/
main?: boolean;
/**
* some package.json files have a `browser` field which
* specifies alternative files to load for people bundling
* for the browser. If that's you, use this option, otherwise
* pkg.browser will be ignored
* @default false
*/
browser?: boolean;
/**
* not all files you want to resolve are .js files
* @default [ '.mjs', '.js', '.json', '.node' ]
*/
extensions?: ReadonlyArray<string>;
/**
* whether to prefer built-in modules (e.g. `fs`, `path`) or
* local ones with the same names
* @default true
*/
preferBuiltins?: boolean;
/**
* Lock the module search in this path (like a chroot). Module defined
* outside this path will be marked as external
* @default '/'
*/
jail?: string;
/**
* Set to an array of strings and/or regexps to lock the module search
* to modules that match at least one entry. Modules not matching any
* entry will be marked as external
* @default null
*/
only?: ReadonlyArray<string | RegExp> | null;
/**
* If true, inspect resolved files to check that they are
* ES2015 modules
* @default false
*/
modulesOnly?: boolean;
/**
* Any additional options that should be passed through
* to node-resolve
*/
customResolveOptions?: AsyncOpts;
}

/**
* Locate modules using the Node resolution algorithm, for using third party modules in node_modules
*/
export default function nodeResolve(options?: RollupNodeResolveOptions): Plugin;
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -11,6 +11,7 @@
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-commonjs": "^9.3.4",
"string-capitalize": "^1.0.1",
"typescript": "^3.4.1",
"vlq": "^1.0.0"
},
"main": "dist/rollup-plugin-node-resolve.cjs.js",
Expand All @@ -20,16 +21,18 @@
"build": "rollup -c",
"pretest": "npm run build",
"test": "mocha",
"posttest": "eslint src test/*.js",
"posttest": "tsc && eslint src test/*.js",
"lint": "eslint src",
"prepublishOnly": "npm test",
"prepare": "npm run build"
},
"files": [
"src",
"dist"
"dist",
"index.d.ts"
],
"dependencies": {
"@types/resolve": "0.0.8",
"builtin-modules": "^3.0.0",
"is-module": "^1.0.0",
"resolve": "^1.10.0"
Expand Down
16 changes: 16 additions & 0 deletions tsconfig.json
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strict": true,
"noEmit": true,
"allowJs": true
},
"files": [
"index.d.ts",
"typings-test.js"
]
}
30 changes: 30 additions & 0 deletions typings-test.js
@@ -0,0 +1,30 @@
// @ts-check
import resolve from '.';

/** @type {import("rollup").RollupOptions} */
const config = {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife',
name: 'MyModule',
},
plugins: [
resolve({
module: true,
jsnext: true,
main: true,
browser: true,
extensions: [ '.mjs', '.js', '.jsx', '.json' ],
preferBuiltins: false,
jail: '/my/jail/path',
only: [ 'some_module', /^@some_scope\/.*$/ ],
modulesOnly: true,
customResolveOptions: {
moduleDirectory: 'js_modules'
}
})
]
};

export default config;