Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): use exportName transform #616

Merged
merged 1 commit into from
Nov 11, 2021
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
4 changes: 2 additions & 2 deletions packages/cli/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { promises as fs } from 'fs'
import { red } from 'chalk'
import svgrConvert, { Config, State } from '@svgr/core'
import { transform, Config, State } from '@svgr/core'
import svgo from '@svgr/plugin-svgo'
import jsx from '@svgr/plugin-jsx'
import prettier from '@svgr/plugin-prettier'
Expand Down Expand Up @@ -31,7 +31,7 @@ export const convert = (
config: Config,
state: Partial<State>,
): string => {
return svgrConvert.sync(code, config, {
return transform.sync(code, config, {
...state,
caller: {
name: '@svgr/cli',
Expand Down
4 changes: 2 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ npm install @svgr/core
## Usage

```js
import svgr from '@svgr/core'
import { transform } from '@svgr/core'

const svgCode = `
<svg xmlns="http://www.w3.org/2000/svg"
Expand All @@ -23,7 +23,7 @@ const svgCode = `
</svg>
`

svgr(svgCode, { icon: true }, { componentName: 'MyComponent' }).then(
transform(svgCode, { icon: true }, { componentName: 'MyComponent' }).then(
(jsCode) => {
console.log(jsCode)
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default } from './convert'
export { transform } from './transform'
export * from './config'
export type { State } from './state'
export type { Plugin, ConfigPlugin } from './plugins'
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import convert, { Config, State } from '.'
import { transform, Config, State } from '.'

function convertWithAllPlugins(
code: string,
config?: Config,
state?: Partial<State>,
) {
return convert(
return transform(
code,
{
plugins: [
Expand All @@ -24,7 +24,7 @@ function convertSyncWithAllPlugins(
config?: Config,
state?: Partial<State>,
) {
return convert.sync(
return transform.sync(
code,
{
plugins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const run = (code: string, config: Config, state: Partial<State>): string => {
return nextCode
}

const convert = async (
export const transform = async (
code: string,
config: Config = {},
state: Partial<State> = {},
Expand All @@ -24,13 +24,11 @@ const convert = async (
return run(code, config, state)
}

convert.sync = (
transform.sync = (
code: string,
config: Config = {},
state: Partial<State> = {},
): string => {
config = loadConfig.sync(config, state)
return run(code, config, state)
}

export default convert
4 changes: 2 additions & 2 deletions packages/rollup/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs'
import convert, { Config } from '@svgr/core'
import { transform, Config } from '@svgr/core'
import { createFilter, CreateFilter } from 'rollup-pluginutils'
import { transformAsync, createConfigItem } from '@babel/core'
import svgo from '@svgr/plugin-svgo'
Expand Down Expand Up @@ -58,7 +58,7 @@ const plugin: PluginImpl<Options> = (options = {}) => {

const previousExport = exportMatches ? data : null

const jsCode = await convert(load, options, {
const jsCode = await transform(load, options, {
filePath: id,
caller: {
name: '@svgr/rollup',
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { callbackify } from 'util'
import { transformAsync, createConfigItem } from '@babel/core'
import convert, { Config, State } from '@svgr/core'
import { transform, Config, State } from '@svgr/core'
import { normalize } from 'path'
import svgo from '@svgr/plugin-svgo'
import jsx from '@svgr/plugin-jsx'
Expand Down Expand Up @@ -42,7 +42,7 @@ interface LoaderOptions extends Config {
const tranformSvg = callbackify(
async (contents: string, options: LoaderOptions, state: Partial<State>) => {
const { babel = true, ...config } = options
const jsCode = await convert(contents, config, state)
const jsCode = await transform(contents, config, state)
if (!babel) return jsCode
const result = await transformAsync(
jsCode,
Expand Down