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

Add index.d.ts typings file #31

Merged
merged 1 commit into from
Apr 10, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export default {
// too permissive
exclude: 'node_modules/**',

// To replace every occurence of `<@foo@>` instead of every
// occurence of `foo`, supply delimiters
// To replace every occurrence of `<@foo@>` instead of every
// occurrence of `foo`, supply delimiters
delimiters: ['<@', '@>'],

// All other options are treated as `string: replacement`
Expand Down
35 changes: 35 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Plugin } from 'rollup';

type Replacement = string | ((id: string) => string);

interface RollupReplaceOptions {
/**
* A minimatch pattern, or array of patterns, of files that should be
* processed by this plugin (if omitted, all files are included by default)
*/
include?: string | RegExp | ReadonlyArray<string | RegExp> | null;
/**
* Files that should be excluded, if `include` is otherwise too permissive.
*/
exclude?: string | RegExp | ReadonlyArray<string | RegExp> | null;
/**
* To replace every occurrence of `<@foo@>` instead of every occurrence
* of `foo`, supply delimiters
*/
delimiters?: [string, string];
/**
* You can separate values to replace from other options.
*/
values?: { [str: string]: Replacement };

/**
* All other options are treated as `string: replacement` replacers,
* or `string: (id) => replacement` functions.
*/
[str: string]: Replacement | RollupReplaceOptions['include'] | RollupReplaceOptions['values'];
}

/**
* Replace strings in files while bundling them.
*/
export default function replace(options?: RollupReplaceOptions): Plugin;
6 changes: 6 additions & 0 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"rollup": "^1.6.0",
"rollup-plugin-buble": "^0.19.6",
"shx": "^0.3.2",
"source-map": "^0.7.3"
"source-map": "^0.7.3",
"typescript": "^3.4.2"
},
"main": "dist/rollup-plugin-replace.cjs.js",
"module": "dist/rollup-plugin-replace.es.js",
Expand All @@ -22,7 +23,7 @@
},
"scripts": {
"test": "npm run test:only",
"test:only": "mocha",
"test:only": "mocha && tsc",
"pretest": "npm run build",
"build": "rollup -c",
"prebuild": "shx rm -rf dist/*",
Expand All @@ -33,6 +34,7 @@
"files": [
"src",
"dist",
"index.d.ts",
"README.md"
],
"repository": "rollup/rollup-plugin-replace",
Expand Down
16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strict": true,
"noEmit": true,
"allowJs": true
},
"files": [
"index.d.ts",
"typings-test.js"
]
}
28 changes: 28 additions & 0 deletions typings-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @ts-check
import { dirname } from 'path';
import replace from '.';

/** @type {import("rollup").RollupOptions} */
const config = {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
replace({
include: 'config.js',
exclude: 'node_modules/**',
delimiters: ['<@', '@>'],
VERSION: '1.0.0',
ENVIRONMENT: JSON.stringify('development'),
__dirname: id => `'${dirname(id)}'`,
values: {
VERSION: '1.0.0',
ENVIRONMENT: JSON.stringify('development')
}
})
]
};

export default config;