Skip to content

Commit

Permalink
update test and typescript add in rollup and webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
marques-kevin committed Jul 23, 2018
1 parent 34a9724 commit 934fef7
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async function run() {
}
}

if(config.typescript) config.ext = "ts"
if (config.typescript && !config.ext) config.ext = 'ts'

const command = program.outDir ? dirCommand : fileCommand
await command(program, filenames, config)
Expand Down
10 changes: 7 additions & 3 deletions packages/rollup/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ function svgrPlugin(options = {}) {
body: [],
}

const jsCode = await convert(load, options, {
rollup: { previousExport },
})
const jsCode = await convert(
load,
{ ...options, typescript: false },
{
rollup: { previousExport },
},
)

const pBabelTransform = async code =>
new Promise((resolve, reject) => {
Expand Down
25 changes: 25 additions & 0 deletions packages/webpack/src/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,28 @@ var SvgComponent = function SvgComponent() {
export default SvgComponent;"
`;

exports[`webpack loader should convert file with typescript 1`] = `
"import React from 'react';
var _ref =
/*#__PURE__*/
React.createElement(\\"svg\\", {
width: 88,
height: 88
}, React.createElement(\\"g\\", {
stroke: \\"#063855\\",
strokeWidth: 2,
fill: \\"none\\",
fillRule: \\"evenodd\\",
strokeLinecap: \\"square\\"
}, React.createElement(\\"path\\", {
d: \\"M51 37L37 51M51 51L37 37\\"
})));
var SvgComponent = function SvgComponent() {
return _ref;
};
export default SvgComponent;"
`;
8 changes: 7 additions & 1 deletion packages/webpack/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ function svgrLoader(source) {
})

readSvg()
.then(svg => convert(svg, options, { webpack: { previousExport } }))
.then(svg =>
convert(
svg,
{ ...options, typescript: false },
{ webpack: { previousExport } },
),
)
.then(jsCode => (babel ? pBabelTransform(jsCode) : jsCode))
.then(result => callback(null, result))
.catch(err => callback(err))
Expand Down
23 changes: 23 additions & 0 deletions packages/webpack/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,27 @@ describe('webpack loader', () => {
},
15000,
)

it(
'should convert file with typescript',
async () => {
const source = await compile([
{
test: /\.svg$/,
use: [
{
loader: path.resolve(__dirname, './index.js'),
options: {
expandProps: false,
typescript: true,
},
},
],
},
])

expect(source).toMatchSnapshot()
},
15000,
)
})

0 comments on commit 934fef7

Please sign in to comment.