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

Fix transforming via API #53

Merged
merged 2 commits into from
Oct 22, 2018
Merged

Fix transforming via API #53

merged 2 commits into from
Oct 22, 2018

Conversation

ljharb
Copy link
Collaborator

@ljharb ljharb commented Oct 19, 2018

No description provided.

danoc and others added 2 commits October 19, 2018 11:40
@ljharb ljharb added the bug label Oct 19, 2018
@ljharb
Copy link
Collaborator Author

ljharb commented Oct 19, 2018

@danoc, can you test out this solution?

const { ignorePattern, caseSensitive } = state.opts;
const { file } = state;
const { ignorePattern, caseSensitive, filename: providedFilename } = state.opts;
const { file, filename } = state;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like filename was originally coming from state.file.opts on ln 47, was this updated somewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no longer using that value, but it seems like it will be populated by state.filename when transforming a file, and state.opts.filename when the option is provided, so this seemed more straightforward.

@danoc
Copy link
Contributor

danoc commented Oct 22, 2018

Hi, a few minutes late to the party but when I test this locally I get the following error:

Error: [BABEL] unknown: .filename is not a valid Plugin property
    at Object.keys.forEach.key (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/validation/plugins.js:52:56)
    at Array.forEach (<anonymous>)
    at validatePluginObject (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/validation/plugins.js:50:20)
    at instantiatePlugin (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/full.js:209:55)
    at cachedFunction (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/caching.js:33:19)
    at loadPluginDescriptor (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/full.js:200:10)
    at config.plugins.reduce (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/full.js:69:20)
    at Array.reduce (<anonymous>)
    at recurseDescriptors (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/full.js:67:38)
    at loadFullConfig (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/full.js:108:6)
error Command failed with exit code 1.

Does babel-plugin-inline-react-svg need to register the option with babel?

If I omit filename, the plugin correctly errors:

TypeError: the "filename" option is required when transforming code
    at PluginPass.enter (/Users/doconnor/Thumbtack/thumbprint/packages/thumbprint-icons/node_modules/babel-plugin-inline-react-svg/lib/index.js:146:35)
    at newFn (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/traverse/lib/visitors.js:193:21)
    at NodePath._call (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitSingle (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/traverse/lib/context.js:90:19)
    at TraversalContext.visit (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/traverse/lib/context.js:146:19)
    at Function.traverse.node (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/traverse/lib/index.js:94:17)
    at traverse (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/traverse/lib/index.js:76:12)

@ljharb
Copy link
Collaborator Author

ljharb commented Oct 22, 2018

@danoc what config are you using with that first error?

@danoc
Copy link
Contributor

danoc commented Oct 22, 2018

@ljharb Using this config:

    const es = babelTransform(buildFile(componentName, path), {
        presets: ['@babel/preset-env', '@babel/preset-react'],
        plugins: ['inline-react-svg', { filename: 'unknown' }],
        babelrc: false,
    }).code;

If I change filename to filenameeee, I get the same error:

/Users/doconnor/Thumbtack/thumbprint/packages/thumbprint-icons/scripts/build-javascript.js:13
    throw error;
    ^
Error: [BABEL] unknown: .filenameeeee is not a valid Plugin property
    at Object.keys.forEach.key (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/validation/plugins.js:52:56)
    at Array.forEach (<anonymous>)
    at validatePluginObject (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/validation/plugins.js:50:20)
    at instantiatePlugin (/Users/doconnor/Thumbtack/thumbprint/node_modules/@babel/core/lib/config/full.js:209:55)

Could be something wrong on my end. I'm testing this by pulling down the code in this PR, building the lib folder, then manually replacing my node_modules/babel-plugin-inline-react-svg/lib/index.js with the version I built.

@ljharb
Copy link
Collaborator Author

ljharb commented Oct 22, 2018

@danoc when providing options to a plugin, you need an extra wrapping array. Try this:

    const es = babelTransform(buildFile(componentName, path), {
        presets: ['@babel/preset-env', '@babel/preset-react'],
        plugins: [['inline-react-svg', { filename: 'unknown' }]],
        babelrc: false,
    }).code;

@danoc
Copy link
Contributor

danoc commented Oct 22, 2018

Ah, nice catch. That was the issue.

I really appreciate your help on this! 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants