rollup-plugin-inject
Advanced tools
Comparing version 1.2.0 to 1.3.0
# rollup-plugin-inject | ||
## 1.3.0 | ||
* Windows support ([#2](https://github.com/rollup/rollup-plugin-inject/issues/2)) | ||
* Node 0.12 support | ||
## 1.2.0 | ||
@@ -4,0 +9,0 @@ |
@@ -7,3 +7,2 @@ 'use strict'; | ||
var acorn = require('acorn'); | ||
acorn = 'default' in acorn ? acorn['default'] : acorn; | ||
var MagicString = require('magic-string'); | ||
@@ -19,2 +18,3 @@ MagicString = 'default' in MagicString ? MagicString['default'] : MagicString; | ||
}); | ||
function makeLegalIdentifier(str) { | ||
@@ -34,38 +34,21 @@ str = str.replace(/-(\w)/g, function (_, letter) { | ||
function isReference(_x, _x2) { | ||
var _left; | ||
function isReference(node, parent) { | ||
if (node.type === 'MemberExpression') { | ||
return !node.computed && isReference(node.object, node); | ||
} | ||
var _again = true; | ||
if (node.type === 'Identifier') { | ||
// TODO is this right? | ||
if (parent.type === 'MemberExpression') return parent.computed || node === parent.object; | ||
_function: while (_again) { | ||
var node = _x, | ||
parent = _x2; | ||
_again = false; | ||
// disregard the `bar` in { bar: foo } | ||
if (parent.type === 'Property' && node !== parent.value) return false; | ||
if (node.type === 'MemberExpression') { | ||
if (!(_left = !node.computed)) { | ||
return _left; | ||
} | ||
// disregard the `bar` in `class Foo { bar () {...} }` | ||
if (parent.type === 'MethodDefinition') return false; | ||
_x = node.object; | ||
_x2 = node; | ||
_again = true; | ||
continue _function; | ||
} | ||
// disregard the `bar` in `export { foo as bar }` | ||
if (parent.type === 'ExportSpecifier' && node !== parent.local) return; | ||
if (node.type === 'Identifier') { | ||
// TODO is this right? | ||
if (parent.type === 'MemberExpression') return parent.computed || node === parent.object; | ||
// disregard the `bar` in { bar: foo } | ||
if (parent.type === 'Property' && node !== parent.value) return false; | ||
// disregard the `bar` in `class Foo { bar () {...} }` | ||
if (parent.type === 'MethodDefinition') return false; | ||
// disregard the `bar` in `export { foo as bar }` | ||
if (parent.type === 'ExportSpecifier' && node !== parent.local) return; | ||
return true; | ||
} | ||
return true; | ||
} | ||
@@ -88,3 +71,15 @@ } | ||
} | ||
function provide(options) { | ||
function assign(target, source) { | ||
Object.keys(source).forEach(function (key) { | ||
target[key] = source[key]; | ||
}); | ||
return target; | ||
} | ||
function isArray(thing) { | ||
return Object.prototype.toString.call(thing) === '[object Array]'; | ||
} | ||
function inject(options) { | ||
if (!options) throw new Error('Missing options'); | ||
@@ -99,3 +94,3 @@ | ||
} else { | ||
modules = Object.assign({}, options); | ||
modules = assign({}, options); | ||
delete modules.include; | ||
@@ -105,2 +100,11 @@ delete modules.exclude; | ||
// Fix paths on Windows | ||
if (path.sep !== '/') { | ||
Object.keys(modules).forEach(function (key) { | ||
var module = modules[key]; | ||
modules[key] = isArray(module) ? [module[0].split(path.sep).join('/'), module[1]] : module.split(path.sep).join('/'); | ||
}); | ||
} | ||
var firstpass = new RegExp('(?:' + Object.keys(modules).map(escape).join('|') + ')', 'g'); | ||
@@ -145,5 +149,5 @@ var sourceMap = options.sourceMap !== false; | ||
if (keypath in modules && !scope.contains(name) && !imports[name]) { | ||
var _module = modules[keypath]; | ||
if (typeof _module === 'string') _module = [_module, 'default']; | ||
var hash = keypath + ':' + _module[0] + ':' + _module[1]; | ||
var module = modules[keypath]; | ||
if (typeof module === 'string') module = [module, 'default']; | ||
var hash = keypath + ':' + module[0] + ':' + module[1]; | ||
@@ -153,3 +157,3 @@ var importLocalName = name === keypath ? name : makeLegalIdentifier('$inject_' + keypath); | ||
if (!newImports[hash]) { | ||
newImports[hash] = 'import { ' + _module[1] + ' as ' + importLocalName + ' } from \'' + _module[0] + '\';'; | ||
newImports[hash] = 'import { ' + module[1] + ' as ' + importLocalName + ' } from \'' + module[0] + '\';'; | ||
} | ||
@@ -175,4 +179,4 @@ | ||
if (node.type === 'Property' && node.shorthand) { | ||
var _name = node.key.name; | ||
handleReference(node, _name, _name); | ||
var name = node.key.name; | ||
handleReference(node, name, name); | ||
return this.skip(); | ||
@@ -184,6 +188,6 @@ } | ||
var _name2 = _flatten.name; | ||
var name = _flatten.name; | ||
var keypath = _flatten.keypath; | ||
handleReference(node, _name2, keypath); | ||
handleReference(node, name, keypath); | ||
} | ||
@@ -212,2 +216,2 @@ }, | ||
module.exports = provide; | ||
module.exports = inject; |
import { attachScopes, createFilter } from 'rollup-pluginutils'; | ||
import { extname } from 'path'; | ||
import { extname, sep } from 'path'; | ||
import { walk } from 'estree-walker'; | ||
import acorn from 'acorn'; | ||
import { parse } from 'acorn'; | ||
import MagicString from 'magic-string'; | ||
@@ -14,2 +14,3 @@ | ||
}); | ||
function makeLegalIdentifier(str) { | ||
@@ -29,38 +30,21 @@ str = str.replace(/-(\w)/g, function (_, letter) { | ||
function isReference(_x, _x2) { | ||
var _left; | ||
function isReference(node, parent) { | ||
if (node.type === 'MemberExpression') { | ||
return !node.computed && isReference(node.object, node); | ||
} | ||
var _again = true; | ||
if (node.type === 'Identifier') { | ||
// TODO is this right? | ||
if (parent.type === 'MemberExpression') return parent.computed || node === parent.object; | ||
_function: while (_again) { | ||
var node = _x, | ||
parent = _x2; | ||
_again = false; | ||
// disregard the `bar` in { bar: foo } | ||
if (parent.type === 'Property' && node !== parent.value) return false; | ||
if (node.type === 'MemberExpression') { | ||
if (!(_left = !node.computed)) { | ||
return _left; | ||
} | ||
// disregard the `bar` in `class Foo { bar () {...} }` | ||
if (parent.type === 'MethodDefinition') return false; | ||
_x = node.object; | ||
_x2 = node; | ||
_again = true; | ||
continue _function; | ||
} | ||
// disregard the `bar` in `export { foo as bar }` | ||
if (parent.type === 'ExportSpecifier' && node !== parent.local) return; | ||
if (node.type === 'Identifier') { | ||
// TODO is this right? | ||
if (parent.type === 'MemberExpression') return parent.computed || node === parent.object; | ||
// disregard the `bar` in { bar: foo } | ||
if (parent.type === 'Property' && node !== parent.value) return false; | ||
// disregard the `bar` in `class Foo { bar () {...} }` | ||
if (parent.type === 'MethodDefinition') return false; | ||
// disregard the `bar` in `export { foo as bar }` | ||
if (parent.type === 'ExportSpecifier' && node !== parent.local) return; | ||
return true; | ||
} | ||
return true; | ||
} | ||
@@ -83,3 +67,15 @@ } | ||
} | ||
function provide(options) { | ||
function assign(target, source) { | ||
Object.keys(source).forEach(function (key) { | ||
target[key] = source[key]; | ||
}); | ||
return target; | ||
} | ||
function isArray(thing) { | ||
return Object.prototype.toString.call(thing) === '[object Array]'; | ||
} | ||
function inject(options) { | ||
if (!options) throw new Error('Missing options'); | ||
@@ -94,3 +90,3 @@ | ||
} else { | ||
modules = Object.assign({}, options); | ||
modules = assign({}, options); | ||
delete modules.include; | ||
@@ -100,2 +96,11 @@ delete modules.exclude; | ||
// Fix paths on Windows | ||
if (sep !== '/') { | ||
Object.keys(modules).forEach(function (key) { | ||
var module = modules[key]; | ||
modules[key] = isArray(module) ? [module[0].split(sep).join('/'), module[1]] : module.split(sep).join('/'); | ||
}); | ||
} | ||
var firstpass = new RegExp('(?:' + Object.keys(modules).map(escape).join('|') + ')', 'g'); | ||
@@ -113,3 +118,3 @@ var sourceMap = options.sourceMap !== false; | ||
try { | ||
ast = acorn.parse(code, { | ||
ast = parse(code, { | ||
ecmaVersion: 6, | ||
@@ -141,5 +146,5 @@ sourceType: 'module' | ||
if (keypath in modules && !scope.contains(name) && !imports[name]) { | ||
var _module = modules[keypath]; | ||
if (typeof _module === 'string') _module = [_module, 'default']; | ||
var hash = keypath + ':' + _module[0] + ':' + _module[1]; | ||
var module = modules[keypath]; | ||
if (typeof module === 'string') module = [module, 'default']; | ||
var hash = keypath + ':' + module[0] + ':' + module[1]; | ||
@@ -149,3 +154,3 @@ var importLocalName = name === keypath ? name : makeLegalIdentifier('$inject_' + keypath); | ||
if (!newImports[hash]) { | ||
newImports[hash] = 'import { ' + _module[1] + ' as ' + importLocalName + ' } from \'' + _module[0] + '\';'; | ||
newImports[hash] = 'import { ' + module[1] + ' as ' + importLocalName + ' } from \'' + module[0] + '\';'; | ||
} | ||
@@ -171,4 +176,4 @@ | ||
if (node.type === 'Property' && node.shorthand) { | ||
var _name = node.key.name; | ||
handleReference(node, _name, _name); | ||
var name = node.key.name; | ||
handleReference(node, name, name); | ||
return this.skip(); | ||
@@ -180,6 +185,6 @@ } | ||
var _name2 = _flatten.name; | ||
var name = _flatten.name; | ||
var keypath = _flatten.keypath; | ||
handleReference(node, _name2, keypath); | ||
handleReference(node, name, keypath); | ||
} | ||
@@ -208,2 +213,2 @@ }, | ||
export default provide; | ||
export default inject; |
{ | ||
"name": "rollup-plugin-inject", | ||
"version": "1.2.0", | ||
"description": "Scan modules for global variables and inject `import` statements where necessary", | ||
"version": "1.3.0", | ||
"devDependencies": { | ||
"babel-preset-es2015-rollup": "^1.0.0", | ||
"eslint": "^1.7.3", | ||
"mocha": "^2.3.3", | ||
"rollup": "^0.20.3", | ||
"rollup-plugin-babel": "^1.0.0" | ||
"rollup": "^0.22.0", | ||
"rollup-plugin-babel": "^2.2.0" | ||
}, | ||
@@ -27,5 +29,22 @@ "main": "dist/rollup-plugin-inject.cjs.js", | ||
"estree-walker": "^0.2.0", | ||
"magic-string": "^0.8.0", | ||
"magic-string": "^0.10.0", | ||
"rollup-pluginutils": "^1.2.0" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/rollup/rollup-plugin-inject.git" | ||
}, | ||
"keywords": [ | ||
"rollup", | ||
"rollup-plugin", | ||
"es2015", | ||
"npm", | ||
"modules" | ||
], | ||
"author": "Rich Harris <richard.a.harris@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/rollup/rollup-plugin-inject/issues" | ||
}, | ||
"homepage": "https://github.com/rollup/rollup-plugin-inject#readme" | ||
} |
import { attachScopes, createFilter } from 'rollup-pluginutils'; | ||
import { extname } from 'path'; | ||
import { extname, sep } from 'path'; | ||
import { walk } from 'estree-walker'; | ||
import acorn from 'acorn'; | ||
import { parse } from 'acorn'; | ||
import makeLegalIdentifier from './makeLegalIdentifier'; | ||
@@ -49,3 +49,14 @@ import MagicString from 'magic-string'; | ||
export default function provide ( options ) { | ||
function assign ( target, source ) { | ||
Object.keys( source ).forEach( key => { | ||
target[ key ] = source[ key ]; | ||
}); | ||
return target; | ||
} | ||
function isArray ( thing ) { | ||
return Object.prototype.toString.call( thing ) === '[object Array]'; | ||
} | ||
export default function inject ( options ) { | ||
if ( !options ) throw new Error( 'Missing options' ); | ||
@@ -60,3 +71,3 @@ | ||
} else { | ||
modules = Object.assign( {}, options ); | ||
modules = assign( {}, options ); | ||
delete modules.include; | ||
@@ -66,2 +77,13 @@ delete modules.exclude; | ||
// Fix paths on Windows | ||
if ( sep !== '/' ) { | ||
Object.keys( modules ).forEach( key => { | ||
const module = modules[ key ]; | ||
modules[ key ] = isArray( module ) ? | ||
[ module[0].split( sep ).join( '/' ), module[1] ] : | ||
module.split( sep ).join( '/' ); | ||
}); | ||
} | ||
const firstpass = new RegExp( `(?:${Object.keys( modules ).map( escape ).join( '|' )})`, 'g' ); | ||
@@ -79,3 +101,3 @@ const sourceMap = options.sourceMap !== false; | ||
try { | ||
ast = acorn.parse( code, { | ||
ast = parse( code, { | ||
ecmaVersion: 6, | ||
@@ -82,0 +104,0 @@ sourceType: 'module' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
20975
0
473
0
0
0
5
+ Addedmagic-string@0.10.2(transitive)
- Removedmagic-string@0.8.0(transitive)
Updatedmagic-string@^0.10.0