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

Update all packages #15

Merged
merged 1 commit into from
Jul 25, 2018
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
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"devDependencies": {
"eslint": "^3.5.0",
"mocha": "^3.0.2",
"rollup": "^0.36.0",
"rollup-plugin-buble": "^0.14.0"
"rollup": "^0.50.0",
"rollup-plugin-buble": "^0.16.0"
},
"main": "dist/rollup-plugin-inject.cjs.js",
"jsnext:main": "dist/rollup-plugin-inject.es6.js",
"scripts": {
"test": "mocha",
"pretest": "npm run build",
"build": "rollup -c -f cjs -o dist/rollup-plugin-inject.cjs.js && rollup -c -f es6 -o dist/rollup-plugin-inject.es6.js",
"build": "rollup -c -f cjs -o dist/rollup-plugin-inject.cjs.js && rollup -c -f es -o dist/rollup-plugin-inject.es6.js",
"prebuild": "rm -rf dist/*",
"prepublish": "npm test"
},
Expand All @@ -23,10 +23,10 @@
"README.md"
],
"dependencies": {
"acorn": "^4.0.3",
"estree-walker": "^0.2.0",
"magic-string": "^0.16.0",
"rollup-pluginutils": "^1.2.0"
"acorn": "^5.1.2",
"estree-walker": "^0.5.0",
"magic-string": "^0.22.4",
"rollup-pluginutils": "^2.0.1"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import buble from 'rollup-plugin-buble';
var external = Object.keys( require( './package.json' ).dependencies ).concat( 'path' );

export default {
entry: 'src/index.js',
input: 'src/index.js',
plugins: [ buble() ],
external: external
};
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { attachScopes, createFilter } from 'rollup-pluginutils';
import { attachScopes, createFilter, makeLegalIdentifier } from 'rollup-pluginutils';
import { sep } from 'path';
import { walk } from 'estree-walker';
import { parse } from 'acorn';
import makeLegalIdentifier from './makeLegalIdentifier';
import MagicString from 'magic-string';

function escape ( str ) {
Expand Down Expand Up @@ -146,7 +145,7 @@ export default function inject ( options ) {
}

if ( name !== keypath ) {
magicString.overwrite( node.start, node.end, importLocalName, true );
magicString.overwrite( node.start, node.end, importLocalName, { storeName: true } );
}

return true;
Expand Down
15 changes: 0 additions & 15 deletions src/makeLegalIdentifier.js

This file was deleted.

49 changes: 29 additions & 20 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ process.chdir( __dirname );
describe( 'rollup-plugin-inject', function () {
it( 'inserts a default import statement', function () {
return rollup.rollup({
entry: 'samples/basic/main.js',
input: 'samples/basic/main.js',
plugins: [
inject({ $: 'jquery' })
],
external: [ 'jquery' ]
}).then( function ( bundle ) {
var generated = bundle.generate();
return bundle.generate({ format: 'es' });
}).then( function ( generated ) {
var code = generated.code;

assert.ok( code.indexOf( "import $ from 'jquery'" ) !== -1, generated.code );
Expand All @@ -23,15 +24,16 @@ describe( 'rollup-plugin-inject', function () {

it( 'uses the modules property', function () {
return rollup.rollup({
entry: 'samples/basic/main.js',
input: 'samples/basic/main.js',
plugins: [
inject({
modules: { $: 'jquery' }
})
],
external: [ 'jquery' ]
}).then( function ( bundle ) {
var generated = bundle.generate();
return bundle.generate({ format: 'es' });
}).then( function ( generated ) {
var code = generated.code;

assert.ok( code.indexOf( "import $ from 'jquery'" ) !== -1, generated.code );
Expand All @@ -40,13 +42,14 @@ describe( 'rollup-plugin-inject', function () {

it( 'inserts a named import statement', function () {
return rollup.rollup({
entry: 'samples/named/main.js',
input: 'samples/named/main.js',
plugins: [
inject({ Promise: [ 'es6-promise', 'Promise' ] })
],
external: [ 'es6-promise' ]
}).then( function ( bundle ) {
var generated = bundle.generate();
return bundle.generate({ format: 'es' });
}).then( function ( generated ) {
var code = generated.code;

assert.ok( code.indexOf( "import { Promise } from 'es6-promise'" ) !== -1, generated.code );
Expand All @@ -55,12 +58,13 @@ describe( 'rollup-plugin-inject', function () {

it( 'overwrites keypaths', function () {
return rollup.rollup({
entry: 'samples/keypaths/main.js',
input: 'samples/keypaths/main.js',
plugins: [
inject({ 'Object.assign': path.resolve( 'samples/keypaths/polyfills/object-assign.js' ) })
]
}).then( function ( bundle ) {
var generated = bundle.generate();
return bundle.generate({ format: 'es' });
}).then( function ( generated ) {
var code = generated.code;

assert.notEqual( code.indexOf( "var clone = $inject_Object_assign" ), -1, code );
Expand All @@ -70,13 +74,14 @@ describe( 'rollup-plugin-inject', function () {

it( 'ignores existing imports', function () {
return rollup.rollup({
entry: 'samples/existing/main.js',
input: 'samples/existing/main.js',
plugins: [
inject({ $: 'jquery' })
],
external: [ 'jquery' ]
}).then( function ( bundle ) {
var generated = bundle.generate();
return bundle.generate({ format: 'es' });
}).then( function ( generated ) {
var code = generated.code;

code = code.replace( /import \$.+/, '' ); // remove first instance. there shouldn't be a second
Expand All @@ -87,13 +92,14 @@ describe( 'rollup-plugin-inject', function () {

it( 'handles shadowed variables', function () {
return rollup.rollup({
entry: 'samples/shadowing/main.js',
input: 'samples/shadowing/main.js',
plugins: [
inject({ $: 'jquery' })
],
external: [ 'jquery' ]
}).then( function ( bundle ) {
var generated = bundle.generate();
return bundle.generate({ format: 'es' });
}).then( function ( generated ) {
var code = generated.code;

assert.ok( code.indexOf( "'jquery'" ) === -1, generated.code );
Expand All @@ -102,13 +108,14 @@ describe( 'rollup-plugin-inject', function () {

it( 'handles shorthand properties', function () {
return rollup.rollup({
entry: 'samples/shorthand/main.js',
input: 'samples/shorthand/main.js',
plugins: [
inject({ Promise: [ 'es6-promise', 'Promise' ] })
],
external: [ 'es6-promise' ]
}).then( function ( bundle ) {
var generated = bundle.generate();
return bundle.generate({ format: 'es' });
}).then( function ( generated ) {
var code = generated.code;

assert.ok( code.indexOf( "import { Promise } from 'es6-promise'" ) !== -1, generated.code );
Expand All @@ -117,7 +124,7 @@ describe( 'rollup-plugin-inject', function () {

it( 'handles redundant keys', function () {
return rollup.rollup({
entry: 'samples/redundant-keys/main.js',
input: 'samples/redundant-keys/main.js',
plugins: [
inject({
Buffer: 'Buffer',
Expand All @@ -132,22 +139,23 @@ describe( 'rollup-plugin-inject', function () {

it( 'generates * imports', function () {
return rollup.rollup({
entry: 'samples/import-namespace/main.js',
input: 'samples/import-namespace/main.js',
plugins: [
inject({ foo: [ 'foo', '*' ] })
],
external: [ 'foo' ]
}).then( function ( bundle ) {
var generated = bundle.generate();
return bundle.generate({ format: 'es' });
}).then( function ( generated ) {
var code = generated.code;

assert.ok( code.indexOf( "import * as foo from 'foo'" ) !== -1, generated.code );
assert.ok( code.indexOf( "import { bar, baz } from 'foo'" ) !== -1, generated.code );
});
});

it( 'transpiles non-JS files but handles failures to parse', function () {
return rollup.rollup({
entry: 'samples/non-js/main.js',
input: 'samples/non-js/main.js',
plugins: [
inject({ relative: [ 'path', 'relative' ] }),
{
Expand All @@ -160,7 +168,8 @@ describe( 'rollup-plugin-inject', function () {
],
external: [ 'path' ]
}).then( function ( bundle ) {
var generated = bundle.generate({ format: 'cjs' });
return bundle.generate({ format: 'cjs' });
}).then( function ( generated ) {
var code = generated.code;

var fn = new Function( 'require', 'assert', code );
Expand Down