Skip to content

Commit 6cac69d

Browse files
authored
Merge branch 'master' into dependabot/add-v2-config-file
2 parents f53f69f + bb0587d commit 6cac69d

File tree

14 files changed

+480
-45
lines changed

14 files changed

+480
-45
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.

example/yarn.lock

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,10 @@ bluebird@^3.5.1:
516516
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7"
517517
integrity sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==
518518

519-
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
520-
version "4.11.8"
521-
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
522-
integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==
519+
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.9:
520+
version "4.12.0"
521+
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
522+
integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==
523523

524524
body-parser@1.18.3:
525525
version "1.18.3"
@@ -561,7 +561,7 @@ braces@^2.3.0, braces@^2.3.1:
561561
split-string "^3.0.2"
562562
to-regex "^3.0.1"
563563

564-
brorand@^1.0.1:
564+
brorand@^1.0.1, brorand@^1.1.0:
565565
version "1.1.0"
566566
resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f"
567567
integrity sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=
@@ -1093,17 +1093,17 @@ ee-first@1.1.1:
10931093
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
10941094

10951095
elliptic@^6.0.0:
1096-
version "6.4.1"
1097-
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.4.1.tgz#c2d0b7776911b86722c632c3c06c60f2f819939a"
1098-
integrity sha512-BsXLz5sqX8OHcsh7CqBMztyXARmGQ3LWPtGjJi6DiJHq5C/qvi9P3OqgswKSDftbu8+IoI/QDTAm2fFnQ9SZSQ==
1096+
version "6.5.4"
1097+
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb"
1098+
integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==
10991099
dependencies:
1100-
bn.js "^4.4.0"
1101-
brorand "^1.0.1"
1100+
bn.js "^4.11.9"
1101+
brorand "^1.1.0"
11021102
hash.js "^1.0.0"
1103-
hmac-drbg "^1.0.0"
1104-
inherits "^2.0.1"
1105-
minimalistic-assert "^1.0.0"
1106-
minimalistic-crypto-utils "^1.0.0"
1103+
hmac-drbg "^1.0.1"
1104+
inherits "^2.0.4"
1105+
minimalistic-assert "^1.0.1"
1106+
minimalistic-crypto-utils "^1.0.1"
11071107

11081108
emojis-list@^2.0.0:
11091109
version "2.1.0"
@@ -1569,9 +1569,9 @@ hash-base@^3.0.0:
15691569
safe-buffer "^5.0.1"
15701570

15711571
hash.js@^1.0.0, hash.js@^1.0.3:
1572-
version "1.1.5"
1573-
resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.5.tgz#e38ab4b85dfb1e0c40fe9265c0e9b54854c23812"
1574-
integrity sha512-eWI5HG9Np+eHV1KQhisXWwM+4EPPYe5dFX1UZZH7k/E3JzDEazVH+VGlZi6R94ZqImq+A3D1mCEtrFIfg/E7sA==
1572+
version "1.1.7"
1573+
resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42"
1574+
integrity sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==
15751575
dependencies:
15761576
inherits "^2.0.3"
15771577
minimalistic-assert "^1.0.1"
@@ -1587,7 +1587,7 @@ history@^4.7.2:
15871587
value-equal "^0.4.0"
15881588
warning "^3.0.0"
15891589

1590-
hmac-drbg@^1.0.0:
1590+
hmac-drbg@^1.0.1:
15911591
version "1.0.1"
15921592
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
15931593
integrity sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=
@@ -1673,16 +1673,21 @@ inflight@^1.0.4:
16731673
once "^1.3.0"
16741674
wrappy "1"
16751675

1676-
inherits@2, inherits@2.0.3, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3:
1677-
version "2.0.3"
1678-
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
1679-
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
1676+
inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1, inherits@~2.0.3:
1677+
version "2.0.4"
1678+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
1679+
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
16801680

16811681
inherits@2.0.1:
16821682
version "2.0.1"
16831683
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1"
16841684
integrity sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=
16851685

1686+
inherits@2.0.3:
1687+
version "2.0.3"
1688+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
1689+
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
1690+
16861691
ini@~1.3.0:
16871692
version "1.3.5"
16881693
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
@@ -2114,7 +2119,7 @@ minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1:
21142119
resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7"
21152120
integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==
21162121

2117-
minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1:
2122+
minimalistic-crypto-utils@^1.0.1:
21182123
version "1.0.1"
21192124
resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a"
21202125
integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=
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+
`;

0 commit comments

Comments
 (0)