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): change plugin order to make styled-components/macro work #644

Merged
merged 1 commit into from
Sep 17, 2020
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: 1 addition & 3 deletions src/babelPluginTsdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const babelPluginTsdx = babelPlugin.custom(() => ({
// pragma: customOptions.jsx || 'h',
// pragmaFrag: customOptions.jsxFragment || 'Fragment',
// },
{ name: 'babel-plugin-macros' },
{ name: 'babel-plugin-annotate-pure-calls' },
{ name: 'babel-plugin-dev-expression' },
customOptions.format !== 'cjs' && {
Expand All @@ -86,9 +87,6 @@ export const babelPluginTsdx = babelPlugin.custom(() => ({
name: '@babel/plugin-transform-regenerator',
async: false,
},
{
name: 'babel-plugin-macros',
},
isTruthy(customOptions.extractErrors) && {
name: './errors/transformErrorMessages',
},
Expand Down
1 change: 0 additions & 1 deletion test/integration/fixtures/build-withBabel/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = {
'./test-babel-preset'
],
plugins: [
'styled-components',
['@babel/plugin-transform-runtime', { helpers: false }],
]
}
2 changes: 1 addition & 1 deletion test/integration/fixtures/build-withBabel/src/styled.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styled from 'styled-components';
import styled from 'styled-components/macro';

export const Title = styled.h1`
/* this comment should be removed */
Expand Down
15 changes: 9 additions & 6 deletions test/integration/tsdx-build-withBabel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ describe('integration :: tsdx build :: .babelrc.js', () => {
const output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);

// from styled.h1` to styled.h1(
const matched = grep(/styled.h1\(/, ['dist/build-withbabel.*.js']);
// from styled.h1` to styled.h1.withConfig(
const matched = grep(/styled.h1.withConfig\(/, [
'dist/build-withbabel.*.js',
]);
expect(matched).toBeTruthy();
});

// TODO: make this test work by allowing customization of plugin order
it.skip('should remove comments in the CSS', () => {
// TODO: make styled-components work with its Babel plugin and not just its
// macro by allowing customization of plugin order
it('should remove comments in the CSS', () => {
const output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);

// the "should be removed" comment shouldn't be there (gets error code)
// the comment "should be removed" should no longer be there
const matched = grep(/should be removed/, ['dist/build-withbabel.*.js']);
expect(matched).toBeTruthy();
expect(matched).toBeFalsy();
});

it('should add an import of regeneratorRuntime', () => {
Expand Down