Skip to content

Commit

Permalink
Merge pull request #48 from stramel/babel-7-upgrade
Browse files Browse the repository at this point in the history
[Breaking] Upgrade to babel 7
  • Loading branch information
ljharb authored Oct 9, 2018
2 parents 7665543 + 83cae6f commit cec0fff
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@ node_js:
- "10"
- "9"
- "8"
- "7"
- "6"
- "5"
- "4"
before_install:
- 'case "${TRAVIS_NODE_VERSION}" in 0.*) export NPM_CONFIG_STRICT_SSL=false ;; esac'
- 'nvm install-latest-npm'
install:
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
script:
- 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi'
- 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ $ babel --plugins inline-react-svg script.js


```javascript
require('babel-core').transform('code', {
require('@babel/core').transform('code', {
plugins: ['inline-react-svg']
}) // => { code, map, ast };
```
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@
},
"homepage": "https://github.com/kesne/babel-plugin-inline-react-svg#readme",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-airbnb": "^2.5.1",
"babel-preset-react": "^6.24.1",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/node": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-preset-airbnb": "^3.0.1",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.10.0",
"react": "^15.3.1"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
},
"dependencies": {
"babylon": "^6.18.0",
"@babel/helper-plugin-utils": "^7.0.0",
"@babel/parser": "^7.0.0",
"lodash.isplainobject": "^4.0.6",
"resolve": "^1.8.1",
"svgo": "^0.7.2"
Expand Down
14 changes: 11 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { extname, dirname } from 'path';
import { readFileSync } from 'fs';
import { parse } from 'babylon';
import { parse } from '@babel/parser';
import { declare } from '@babel/helper-plugin-utils';
import resolve from 'resolve';

import optimize from './optimize';
Expand All @@ -10,7 +11,14 @@ import fileExistsWithCaseSync from './fileExistsWithCaseSync';

let ignoreRegex;

export default ({ template, traverse, types: t }) => {
export default declare(({
assertVersion,
template,
traverse,
types: t,
}) => {
assertVersion(7);

const buildSvg = template(`
var SVG_NAME = function SVG_NAME(props) { return SVG_CODE; };
`);
Expand Down Expand Up @@ -125,4 +133,4 @@ export default ({ template, traverse, types: t }) => {
},
},
};
};
});
33 changes: 17 additions & 16 deletions test/sanity.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { transformFile } from 'babel-core';
import { transformFile } from '@babel/core';
import fs from 'fs';
import path from 'path';
import inlineReactSvgPlugin from '../src';

function assertReactImport(result) {
const match = result.code.match(/import React from 'react'/g);
const match = result.code.match(/import React from ['"]react['"]/g);
if (!match) {
throw new Error('no React import found');
}
Expand All @@ -20,9 +21,9 @@ function validateDefaultProps(result) {

transformFile('test/fixtures/test-import.jsx', {
babelrc: false,
presets: ['react'],
presets: ['@babel/preset-react'],
plugins: [
'../../src/index',
inlineReactSvgPlugin,
],
}, (err, result) => {
if (err) throw err;
Expand All @@ -33,9 +34,9 @@ transformFile('test/fixtures/test-import.jsx', {

transformFile('test/fixtures/test-multiple-svg.jsx', {
babelrc: false,
presets: ['react'],
presets: ['@babel/preset-react'],
plugins: [
'../../src/index',
inlineReactSvgPlugin,
],
}, (err, result) => {
if (err) throw err;
Expand All @@ -46,9 +47,9 @@ transformFile('test/fixtures/test-multiple-svg.jsx', {

transformFile('test/fixtures/test-no-react.jsx', {
babelrc: false,
presets: ['react'],
presets: ['@babel/preset-react'],
plugins: [
'../../src/index',
inlineReactSvgPlugin,
],
}, (err, result) => {
if (err) throw err;
Expand All @@ -60,17 +61,17 @@ transformFile('test/fixtures/test-no-react.jsx', {
if (fs.existsSync(path.resolve('./PACKAGE.JSON'))) {
transformFile('test/fixtures/test-case-sensitive.jsx', {
babelrc: false,
presets: ['react'],
presets: ['@babel/preset-react'],
plugins: [
['../../src/index', {
[inlineReactSvgPlugin, {
caseSensitive: true,
}],
],
}, (err) => {
if (err && err.message.indexOf('match case') !== -1) {
console.log('test/fixtures/test-case-sensitive.jsx', 'Test passed: Expected case sensitive error was thrown');
} else {
throw new Error("Test failed: Expected case sensitive error wasn't thrown");
throw new Error('Test failed: Expected case sensitive error wasnt thrown');
}
});
} else {
Expand All @@ -81,7 +82,7 @@ transformFile('test/fixtures/test-no-svg-or-react.js', {
babelrc: false,
presets: [],
plugins: [
'../../src/index',
inlineReactSvgPlugin,
],
}, (err, result) => {
if (err) throw err;
Expand All @@ -94,28 +95,28 @@ transformFile('test/fixtures/test-no-svg-or-react.js', {
transformFile('test/fixtures/test-import.jsx', {
presets: ['airbnb'],
plugins: [
'../../src/index',
inlineReactSvgPlugin,
],
}, (err1, importResult) => {
if (err1) throw err1;
console.log('test/fixtures/test-import.jsx', importResult.code);
transformFile('test/fixtures/test-require.jsx', {
presets: ['airbnb'],
plugins: [
'../../src/index',
inlineReactSvgPlugin,
],
}, (err2, requireResult) => {
if (err2) throw err2;
if (importResult.code !== requireResult.code) {
throw new Error('Test failed: Import and require tests don\'t match');
throw new Error('Test failed: Import and require tests dont match');
}
});
});

transformFile('test/fixtures/test-dynamic-require.jsx', {
presets: ['airbnb'],
plugins: [
'../../src/index',
inlineReactSvgPlugin,
],
}, (err, result) => {
if (err) throw err;
Expand Down

0 comments on commit cec0fff

Please sign in to comment.