[Pkg-javascript-commits] [node-rollup-plugin-replace] 01/03: New upstream version 1.1.1
Julien Puydt
julien.puydt at laposte.net
Fri Jul 7 19:49:41 UTC 2017
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-rollup-plugin-replace.
commit b06eacc77288bab5c1cba21c59ba222d6eae2b24
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Fri Jul 7 09:36:10 2017 +0200
New upstream version 1.1.1
---
.eslintrc | 24 +++++++++++++++++
.gitignore | 4 +++
.travis.yml | 10 ++++++++
CHANGELOG.md | 17 ++++++++++++
README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++
appveyor.yml | 31 ++++++++++++++++++++++
package.json | 46 +++++++++++++++++++++++++++++++++
rollup.config.js | 9 +++++++
src/index.js | 45 ++++++++++++++++++++++++++++++++
test/index.js | 25 ++++++++++++++++++
test/samples/basic/main.js | 5 ++++
11 files changed, 280 insertions(+)
diff --git a/.eslintrc b/.eslintrc
new file mode 100644
index 0000000..c1780ab
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,24 @@
+{
+ "rules": {
+ "indent": [ 2, "tab", { "SwitchCase": 1 } ],
+ "quotes": [ 2, "single" ],
+ "linebreak-style": [ 2, "unix" ],
+ "semi": [ 2, "always" ],
+ "keyword-spacing": [ 2, { "before": true, "after": true } ],
+ "space-before-blocks": [ 2, "always" ],
+ "space-before-function-paren": [ 2, "always" ],
+ "no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ],
+ "no-cond-assign": [ 0 ]
+ },
+ "env": {
+ "es6": true,
+ "browser": true,
+ "mocha": true,
+ "node": true
+ },
+ "extends": "eslint:recommended",
+ "parserOptions": {
+ "sourceType": "module",
+ "ecmaVersion": 6
+ }
+}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..26ad730
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.DS_Store
+node_modules
+dist
+.gobble*
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..9a040ed
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,10 @@
+sudo: false
+language: node_js
+node_js:
+ - "0.12"
+ - "4"
+env:
+ global:
+ - BUILD_TIMEOUT=10000
+install: npm install
+# script: npm run ci
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..2e4d814
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,17 @@
+# rollup-plugin-replace changelog
+
+## 1.1.1
+
+* Return a `name`
+
+## 1.1.0
+
+* Generate sourcemaps by default
+
+## 1.0.1
+
+* Include correct files in package
+
+## 1.0.0
+
+* First release
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..fb4ae62
--- /dev/null
+++ b/README.md
@@ -0,0 +1,64 @@
+# rollup-plugin-replace
+
+Replace strings in files while bundling them.
+
+
+## Installation
+
+```bash
+npm install --save-dev rollup-plugin-replace
+```
+
+
+## Usage
+
+```js
+import { rollup } from 'rollup';
+import replace from 'rollup-plugin-replace';
+
+rollup({
+ entry: 'main.js',
+ plugins: [
+ replace({
+ ENVIRONMENT: JSON.stringify( 'production' )
+ })
+ ]
+}).then(...)
+```
+
+
+## Options
+
+```js
+{
+ // 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: 'config.js',
+
+ // ...and those that shouldn't, if `include` is otherwise
+ // too permissive
+ exclude: 'node_modules/**',
+
+ // To replace every occurence of `<@foo@>` instead of every
+ // occurence of `foo`, supply delimiters
+ delimiters: [ '<@', '@>' ],
+
+ // All other options are treated as `string: replacement`
+ // replacers...
+ VERSION: '1.0.0',
+ ENVIRONMENT: JSON.stringify( 'development' ),
+
+ // ...unless you want to be careful about separating
+ // values from other options, in which case you can:
+ values: {
+ VERSION: '1.0.0',
+ ENVIRONMENT: JSON.stringify( 'development' )
+ }
+}
+```
+
+
+## License
+
+MIT
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..6877afb
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,31 @@
+# http://www.appveyor.com/docs/appveyor-yml
+
+version: "{build}"
+
+clone_depth: 10
+
+init:
+ - git config --global core.autocrlf false
+
+environment:
+ matrix:
+ # node.js
+ - nodejs_version: 0.12
+ - nodejs_version: 4
+
+install:
+ - ps: Install-Product node $env:nodejs_version
+ - npm install
+
+build: off
+
+test_script:
+ - node --version && npm --version
+ - npm test
+
+matrix:
+ fast_finish: false
+
+# cache:
+# - C:\Users\appveyor\AppData\Roaming\npm-cache -> package.json # npm cache
+# - node_modules -> package.json # local npm modules
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..3775f21
--- /dev/null
+++ b/package.json
@@ -0,0 +1,46 @@
+{
+ "name": "rollup-plugin-replace",
+ "version": "1.1.1",
+ "devDependencies": {
+ "eslint": "^2.13.1",
+ "mocha": "^2.5.3",
+ "rollup": "^0.32.4",
+ "rollup-plugin-buble": "^0.12.1"
+ },
+ "main": "dist/rollup-plugin-replace.cjs.js",
+ "jsnext:main": "dist/rollup-plugin-replace.es.js",
+ "dependencies": {
+ "magic-string": "^0.15.2",
+ "minimatch": "^3.0.2",
+ "rollup-pluginutils": "^1.5.0"
+ },
+ "scripts": {
+ "test": "mocha",
+ "pretest": "npm run build",
+ "build": "rollup -c -f cjs -o dist/rollup-plugin-replace.cjs.js && rollup -c -f es -o dist/rollup-plugin-replace.es.js",
+ "prebuild": "rm -rf dist/*",
+ "prepublish": "npm test"
+ },
+ "files": [
+ "src",
+ "dist",
+ "README.md"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/rollup/rollup-plugin-replace.git"
+ },
+ "keywords": [
+ "rollup",
+ "rollup-plugin",
+ "es2015",
+ "npm",
+ "modules"
+ ],
+ "author": "Rich Harris <richard.a.harris at gmail.com>",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/rollup/rollup-plugin-replace/issues"
+ },
+ "homepage": "https://github.com/rollup/rollup-plugin-replace#readme"
+}
diff --git a/rollup.config.js b/rollup.config.js
new file mode 100644
index 0000000..cc033ad
--- /dev/null
+++ b/rollup.config.js
@@ -0,0 +1,9 @@
+import buble from 'rollup-plugin-buble';
+
+var external = Object.keys( require( './package.json' ).dependencies ).concat( 'path' );
+
+export default {
+ entry: 'src/index.js',
+ plugins: [ buble() ],
+ external: external
+};
diff --git a/src/index.js b/src/index.js
new file mode 100644
index 0000000..be9258b
--- /dev/null
+++ b/src/index.js
@@ -0,0 +1,45 @@
+import MagicString from 'magic-string';
+import { createFilter } from 'rollup-pluginutils';
+
+function escape ( str ) {
+ return str.replace( /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&' );
+}
+
+export default function replace ( options = {} ) {
+ const values = options.values || options;
+ const delimiters = ( options.delimiters || [ '', '' ] ).map( escape );
+ const pattern = new RegExp( delimiters[0] + '(' + Object.keys( values ).join( '|' ) + ')' + delimiters[1], 'g' );
+
+ const filter = createFilter( options.include, options.exclude );
+
+ return {
+ name: 'replace',
+
+ transform ( code, id ) {
+ if ( !filter( id ) ) return null;
+
+ const magicString = new MagicString( code );
+
+ let hasReplacements = false;
+ let match;
+ let start, end, replacement;
+
+ while ( match = pattern.exec( code ) ) {
+ hasReplacements = true;
+
+ start = match.index;
+ end = start + match[0].length;
+ replacement = String( values[ match[1] ] );
+
+ magicString.overwrite( start, end, replacement );
+ }
+
+ if ( !hasReplacements ) return null;
+
+ let result = { code: magicString.toString() };
+ if ( options.sourceMap !== false ) result.map = magicString.generateMap({ hires: true });
+
+ return result;
+ }
+ };
+}
diff --git a/test/index.js b/test/index.js
new file mode 100644
index 0000000..406f6dd
--- /dev/null
+++ b/test/index.js
@@ -0,0 +1,25 @@
+var assert = require( 'assert' );
+var rollup = require( 'rollup' );
+var replace = require( '..' );
+
+process.chdir( __dirname );
+
+describe( 'rollup-plugin-replace', function () {
+ it( 'replaces strings', function () {
+ return rollup.rollup({
+ entry: 'samples/basic/main.js',
+ plugins: [
+ replace({
+ ENV: "'production'"
+ })
+ ]
+ }).then( function ( bundle ) {
+ const generated = bundle.generate();
+ const code = generated.code;
+
+ assert.ok( code.indexOf( "'production' !== 'production'" ) !== -1 );
+ });
+ });
+
+ // TODO tests for delimiters, sourcemaps, etc
+});
diff --git a/test/samples/basic/main.js b/test/samples/basic/main.js
new file mode 100644
index 0000000..c48e748
--- /dev/null
+++ b/test/samples/basic/main.js
@@ -0,0 +1,5 @@
+if ( ENV !== 'production' ) {
+ console.log( 'running in debug mode...' );
+} else {
+ console.log( 'running...' );
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-rollup-plugin-replace.git
More information about the Pkg-javascript-commits
mailing list