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

Commit

Permalink
Add types (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods authored and lukastaegert committed Apr 10, 2019
1 parent 1d18852 commit 8fec857
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
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
@@ -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
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
@@ -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
@@ -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;

0 comments on commit 8fec857

Please sign in to comment.