Skip to content

Commit 9cb7aae

Browse files
authored
Merge pull request #395 from TomGrundy/master
Added namespace option to allow for namespacing, when running multiple instances of typescript-plugin-styled-components (fixes #381)
2 parents bb5cdd9 + 1ed316a commit 9cb7aae

File tree

12 files changed

+449
-19
lines changed

12 files changed

+449
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
55

6+
- namespace prefix to help multiple instances of library not clash (fix #381 in #395)
7+
68
## [1.5.0]
79

810
- transform anonymous default exports (fix #371 in #367)

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ interface Options {
225225
ssr: boolean;
226226
displayName: boolean;
227227
minify: boolean;
228+
componentIdPrefix: string;
228229
}
229230
```
230231

@@ -275,6 +276,12 @@ The minification is not exactly the same and may produce slightly different resu
275276

276277
Default value is `false` which means the minification is not being performed.
277278

279+
### `componentIdPrefix`
280+
281+
To avoid colisions when running more than one insance of typescript-plugin-styled-components at a time, you can add a componentIdPrefix by providing an arbitrary string to this option.
282+
283+
Default value is `''` which means that no namespacing will happen.
284+
278285
### `identifiers`
279286

280287
This option allows to customize identifiers used by `styled-components` API functions.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`issue33.ts 1`] = `
4+
5+
File: issue33.ts
6+
Source code:
7+
8+
declare const styled: any;
9+
declare const $: any;
10+
declare const jQuery: any;
11+
declare const _: any;
12+
13+
declare const Button: any;
14+
15+
const Button1 = Button.extend\` color: red \`;
16+
17+
const Button2 = $.extend\` color: red \`;
18+
const Button3 = jQuery.extend\` color: red \`;
19+
const Button4 = _.extend\` color: red \`;
20+
21+
22+
TypeScript before transform:
23+
24+
declare const styled: any;
25+
declare const $: any;
26+
declare const jQuery: any;
27+
declare const _: any;
28+
declare const Button: any;
29+
const Button1 = Button.extend \` color: red \`;
30+
const Button2 = $.extend \` color: red \`;
31+
const Button3 = jQuery.extend \` color: red \`;
32+
const Button4 = _.extend \` color: red \`;
33+
34+
35+
TypeScript after transform:
36+
37+
declare const styled: any;
38+
declare const $: any;
39+
declare const jQuery: any;
40+
declare const _: any;
41+
declare const Button: any;
42+
const Button1 = Button.extend \` color: red \`;
43+
const Button2 = $.extend \` color: red \`;
44+
const Button3 = jQuery.extend \` color: red \`;
45+
const Button4 = _.extend \` color: red \`;
46+
47+
48+
49+
`;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`multiple-components.tsx 1`] = `
4+
5+
File: multiple-components.tsx
6+
Source code:
7+
8+
import styled from 'styled-components';
9+
10+
export function createButtons() {
11+
const A = styled.button\` color: red; \`;
12+
const B = styled(A)\` color: blue; \`;
13+
14+
return { A, B };
15+
}
16+
17+
export function createDivs() {
18+
const A = styled.div\` color: green; \`;
19+
const B = styled(A)\` color: yellow; \`;
20+
21+
return { A, B };
22+
}
23+
24+
25+
TypeScript before transform:
26+
27+
import styled from "styled-components";
28+
export function createButtons() {
29+
const A = styled.button \` color: red; \`;
30+
const B = styled(A) \` color: blue; \`;
31+
return { A, B };
32+
}
33+
export function createDivs() {
34+
const A = styled.div \` color: green; \`;
35+
const B = styled(A) \` color: yellow; \`;
36+
return { A, B };
37+
}
38+
39+
40+
TypeScript after transform:
41+
42+
import styled from 'styled-components';
43+
export function createButtons() {
44+
const A = styled.button.withConfig({ displayName: "test-A", componentId: "test-hana72" }) \` color: red; \`;
45+
const B = styled(A).withConfig({ displayName: "test-B", componentId: "test-ke4nds" }) \` color: blue; \`;
46+
return { A, B };
47+
}
48+
export function createDivs() {
49+
const A = styled.div.withConfig({ displayName: "test-A", componentId: "test-1q7vmnt" }) \` color: green; \`;
50+
const B = styled(A).withConfig({ displayName: "test-B", componentId: "test-7q8oop" }) \` color: yellow; \`;
51+
return { A, B };
52+
}
53+
54+
55+
56+
`;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`sample1.ts 1`] = `
4+
5+
File: sample1.ts
6+
Source code:
7+
8+
import styled from 'styled-components';
9+
10+
const Button = styled.button\`
11+
color: red;
12+
\`;
13+
14+
declare const nonStyled: any;
15+
16+
const NonButton = nonStyled.button\`
17+
yo
18+
\`;
19+
20+
const OtherButton = styled(Button)\`
21+
color: blue;
22+
\`;
23+
24+
const SuperButton = Button.extend\`
25+
color: super;
26+
\`;
27+
28+
export default styled.link\`
29+
color: black;
30+
\`;
31+
32+
export const SmallButton = Button.extend\`
33+
font-size: .7em;
34+
\`;
35+
36+
const MiniButton = styled(SmallButton).attrs({ size: 'mini' })\`
37+
font-size: .1em;
38+
\`;
39+
40+
41+
TypeScript before transform:
42+
43+
import styled from "styled-components";
44+
const Button = styled.button \`
45+
color: red;
46+
\`;
47+
declare const nonStyled: any;
48+
const NonButton = nonStyled.button \`
49+
yo
50+
\`;
51+
const OtherButton = styled(Button) \`
52+
color: blue;
53+
\`;
54+
const SuperButton = Button.extend \`
55+
color: super;
56+
\`;
57+
export default styled.link \`
58+
color: black;
59+
\`;
60+
export const SmallButton = Button.extend \`
61+
font-size: .7em;
62+
\`;
63+
const MiniButton = styled(SmallButton).attrs({ size: "mini" }) \`
64+
font-size: .1em;
65+
\`;
66+
67+
68+
TypeScript after transform:
69+
70+
import styled from 'styled-components';
71+
const Button = styled.button.withConfig({ displayName: "test-Button", componentId: "test-1okqsxw" }) \`
72+
color: red;
73+
\`;
74+
declare const nonStyled: any;
75+
const NonButton = nonStyled.button \`
76+
yo
77+
\`;
78+
const OtherButton = styled(Button).withConfig({ displayName: "test-OtherButton", componentId: "test-ce0fkl" }) \`
79+
color: blue;
80+
\`;
81+
const SuperButton = Button.extend \`
82+
color: super;
83+
\`;
84+
export default styled.link.withConfig({ componentId: "test-vba0dl" }) \`
85+
color: black;
86+
\`;
87+
export const SmallButton = Button.extend \`
88+
font-size: .7em;
89+
\`;
90+
const MiniButton = styled(SmallButton).attrs({ size: "mini" }).withConfig({ displayName: "test-MiniButton", componentId: "test-ndnumj" }) \`
91+
font-size: .1em;
92+
\`;
93+
94+
95+
96+
`;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`sample2.ts 1`] = `
4+
5+
File: sample2.ts
6+
Source code:
7+
8+
import styled from 'styled-components';
9+
10+
const styled2 = styled;
11+
const NonButton = styled.button;
12+
const NonStyled = styled\` color: red; \`;
13+
const Link = styled(NonStyled)\` color: red; \`;
14+
15+
16+
TypeScript before transform:
17+
18+
import styled from "styled-components";
19+
const styled2 = styled;
20+
const NonButton = styled.button;
21+
const NonStyled = styled \` color: red; \`;
22+
const Link = styled(NonStyled) \` color: red; \`;
23+
24+
25+
TypeScript after transform:
26+
27+
import styled from 'styled-components';
28+
const styled2 = styled;
29+
const NonButton = styled.button;
30+
const NonStyled = styled \` color: red; \`;
31+
const Link = styled(NonStyled).withConfig({ displayName: "test-Link", componentId: "test-1xlc242" }) \` color: red; \`;
32+
33+
34+
35+
`;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`sample3.tsx 1`] = `
4+
5+
File: sample3.tsx
6+
Source code:
7+
8+
import * as React from 'react';
9+
import styled from '../themed-styled';
10+
import { SmallButton } from './sample1';
11+
12+
interface LabelProps {
13+
size: number;
14+
}
15+
16+
const CustomLabel = styled.label\`
17+
font-size: \${(props: LabelProps) => props.size + 'px'}
18+
\`;
19+
20+
const LabeledLink = () => <SmallButton />;
21+
22+
export default CustomLabel;
23+
24+
25+
TypeScript before transform:
26+
27+
import * as React from "react";
28+
import styled from "../themed-styled";
29+
import { SmallButton } from "./sample1";
30+
interface LabelProps {
31+
size: number;
32+
}
33+
const CustomLabel = styled.label \`
34+
font-size: \${(props: LabelProps) => props.size + "px"}
35+
\`;
36+
const LabeledLink = () => <SmallButton />;
37+
export default CustomLabel;
38+
39+
40+
TypeScript after transform:
41+
42+
import * as React from 'react';
43+
import styled from '../themed-styled';
44+
import { SmallButton } from './sample1';
45+
interface LabelProps {
46+
size: number;
47+
}
48+
const CustomLabel = styled.label.withConfig({ displayName: "test-CustomLabel", componentId: "test-1ydgk9x" }) \`
49+
font-size: \${(props: LabelProps) => props.size + 'px'}
50+
\`;
51+
const LabeledLink = () => <SmallButton />;
52+
export default CustomLabel;
53+
54+
55+
56+
`;

0 commit comments

Comments
 (0)