us-state-flag-icons 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/LICENSE +21 -0
- package/README.md +248 -0
- package/flags.css +65 -0
- package/index.cjs +21 -0
- package/index.d.cts +15 -0
- package/index.d.ts +15 -0
- package/index.js +21 -0
- package/package.json +556 -0
- package/react/AK.d.ts +11 -0
- package/react/AK.js +81 -0
- package/react/AL.d.ts +11 -0
- package/react/AL.js +21 -0
- package/react/AR.d.ts +11 -0
- package/react/AR.js +200 -0
- package/react/AS.d.ts +11 -0
- package/react/AS.js +213 -0
- package/react/AZ.d.ts +11 -0
- package/react/AZ.js +31 -0
- package/react/CA.d.ts +11 -0
- package/react/CA.js +61 -0
- package/react/CO.d.ts +11 -0
- package/react/CO.js +28 -0
- package/react/CT.d.ts +11 -0
- package/react/CT.js +1184 -0
- package/react/DC.d.ts +11 -0
- package/react/DC.js +51 -0
- package/react/DE.d.ts +11 -0
- package/react/DE.js +1520 -0
- package/react/FL.d.ts +11 -0
- package/react/FL.js +232 -0
- package/react/GA.d.ts +11 -0
- package/react/GA.js +427 -0
- package/react/GU.d.ts +11 -0
- package/react/GU.js +128 -0
- package/react/HI.d.ts +11 -0
- package/react/HI.js +47 -0
- package/react/IA.d.ts +11 -0
- package/react/IA.js +52 -0
- package/react/ID.d.ts +11 -0
- package/react/ID.js +277 -0
- package/react/IL.d.ts +11 -0
- package/react/IL.js +547 -0
- package/react/IN.d.ts +11 -0
- package/react/IN.js +80 -0
- package/react/KS.d.ts +11 -0
- package/react/KS.js +1714 -0
- package/react/KY.d.ts +11 -0
- package/react/KY.js +639 -0
- package/react/LA.d.ts +11 -0
- package/react/LA.js +380 -0
- package/react/MA.d.ts +11 -0
- package/react/MA.js +121 -0
- package/react/MD.d.ts +11 -0
- package/react/MD.js +54 -0
- package/react/ME.d.ts +11 -0
- package/react/ME.js +2156 -0
- package/react/MI.d.ts +11 -0
- package/react/MI.js +409 -0
- package/react/MN.d.ts +11 -0
- package/react/MN.js +41 -0
- package/react/MO.d.ts +11 -0
- package/react/MO.js +2206 -0
- package/react/MP.d.ts +11 -0
- package/react/MP.js +1734 -0
- package/react/MS.d.ts +11 -0
- package/react/MS.js +35 -0
- package/react/MT.d.ts +11 -0
- package/react/MT.js +296 -0
- package/react/NC.d.ts +11 -0
- package/react/NC.js +537 -0
- package/react/ND.d.ts +11 -0
- package/react/ND.js +1371 -0
- package/react/NE.d.ts +11 -0
- package/react/NE.js +3316 -0
- package/react/NH.d.ts +11 -0
- package/react/NH.js +1337 -0
- package/react/NJ.d.ts +11 -0
- package/react/NJ.js +2537 -0
- package/react/NM.d.ts +11 -0
- package/react/NM.js +29 -0
- package/react/NV.d.ts +11 -0
- package/react/NV.js +183 -0
- package/react/NY.d.ts +11 -0
- package/react/NY.js +5853 -0
- package/react/OH.d.ts +11 -0
- package/react/OH.js +99 -0
- package/react/OK.d.ts +11 -0
- package/react/OK.js +1136 -0
- package/react/OR.d.ts +11 -0
- package/react/OR.js +39 -0
- package/react/PA.d.ts +11 -0
- package/react/PA.js +96 -0
- package/react/PR.d.ts +11 -0
- package/react/PR.js +25 -0
- package/react/RI.d.ts +11 -0
- package/react/RI.js +97 -0
- package/react/SC.d.ts +11 -0
- package/react/SC.js +50 -0
- package/react/SD.d.ts +11 -0
- package/react/SD.js +150 -0
- package/react/TN.d.ts +11 -0
- package/react/TN.js +66 -0
- package/react/TX.d.ts +11 -0
- package/react/TX.js +48 -0
- package/react/UT.d.ts +11 -0
- package/react/UT.js +37 -0
- package/react/VA.d.ts +11 -0
- package/react/VA.js +450 -0
- package/react/VI.d.ts +11 -0
- package/react/VI.js +331 -0
- package/react/VT.d.ts +11 -0
- package/react/VT.js +560 -0
- package/react/WA.d.ts +11 -0
- package/react/WA.js +506 -0
- package/react/WI.d.ts +11 -0
- package/react/WI.js +324 -0
- package/react/WV.d.ts +11 -0
- package/react/WV.js +3838 -0
- package/react/WY.d.ts +11 -0
- package/react/WY.js +78 -0
- package/react/index.d.ts +64 -0
- package/react/index.js +56 -0
- package/source/states.json +562 -0
- package/source/states.json.js +1 -0
- package/string/AK.d.ts +2 -0
- package/string/AK.js +1 -0
- package/string/AL.d.ts +2 -0
- package/string/AL.js +1 -0
- package/string/AR.d.ts +2 -0
- package/string/AR.js +1 -0
- package/string/AS.d.ts +2 -0
- package/string/AS.js +1 -0
- package/string/AZ.d.ts +2 -0
- package/string/AZ.js +1 -0
- package/string/CA.d.ts +2 -0
- package/string/CA.js +1 -0
- package/string/CO.d.ts +2 -0
- package/string/CO.js +1 -0
- package/string/CT.d.ts +2 -0
- package/string/CT.js +1 -0
- package/string/DC.d.ts +2 -0
- package/string/DC.js +1 -0
- package/string/DE.d.ts +2 -0
- package/string/DE.js +1 -0
- package/string/FL.d.ts +2 -0
- package/string/FL.js +1 -0
- package/string/GA.d.ts +2 -0
- package/string/GA.js +1 -0
- package/string/GU.d.ts +2 -0
- package/string/GU.js +1 -0
- package/string/HI.d.ts +2 -0
- package/string/HI.js +1 -0
- package/string/IA.d.ts +2 -0
- package/string/IA.js +1 -0
- package/string/ID.d.ts +2 -0
- package/string/ID.js +1 -0
- package/string/IL.d.ts +2 -0
- package/string/IL.js +1 -0
- package/string/IN.d.ts +2 -0
- package/string/IN.js +1 -0
- package/string/KS.d.ts +2 -0
- package/string/KS.js +1 -0
- package/string/KY.d.ts +2 -0
- package/string/KY.js +1 -0
- package/string/LA.d.ts +2 -0
- package/string/LA.js +1 -0
- package/string/MA.d.ts +2 -0
- package/string/MA.js +1 -0
- package/string/MD.d.ts +2 -0
- package/string/MD.js +1 -0
- package/string/ME.d.ts +2 -0
- package/string/ME.js +1 -0
- package/string/MI.d.ts +2 -0
- package/string/MI.js +1 -0
- package/string/MN.d.ts +2 -0
- package/string/MN.js +1 -0
- package/string/MO.d.ts +2 -0
- package/string/MO.js +1 -0
- package/string/MP.d.ts +2 -0
- package/string/MP.js +1 -0
- package/string/MS.d.ts +2 -0
- package/string/MS.js +1 -0
- package/string/MT.d.ts +2 -0
- package/string/MT.js +1 -0
- package/string/NC.d.ts +2 -0
- package/string/NC.js +1 -0
- package/string/ND.d.ts +2 -0
- package/string/ND.js +1 -0
- package/string/NE.d.ts +2 -0
- package/string/NE.js +1 -0
- package/string/NH.d.ts +2 -0
- package/string/NH.js +1 -0
- package/string/NJ.d.ts +2 -0
- package/string/NJ.js +1 -0
- package/string/NM.d.ts +2 -0
- package/string/NM.js +1 -0
- package/string/NV.d.ts +2 -0
- package/string/NV.js +1 -0
- package/string/NY.d.ts +2 -0
- package/string/NY.js +1 -0
- package/string/OH.d.ts +2 -0
- package/string/OH.js +1 -0
- package/string/OK.d.ts +2 -0
- package/string/OK.js +1 -0
- package/string/OR.d.ts +2 -0
- package/string/OR.js +1 -0
- package/string/PA.d.ts +2 -0
- package/string/PA.js +1 -0
- package/string/PR.d.ts +2 -0
- package/string/PR.js +1 -0
- package/string/RI.d.ts +2 -0
- package/string/RI.js +1 -0
- package/string/SC.d.ts +2 -0
- package/string/SC.js +1 -0
- package/string/SD.d.ts +2 -0
- package/string/SD.js +1 -0
- package/string/TN.d.ts +2 -0
- package/string/TN.js +1 -0
- package/string/TX.d.ts +2 -0
- package/string/TX.js +1 -0
- package/string/UT.d.ts +2 -0
- package/string/UT.js +1 -0
- package/string/VA.d.ts +2 -0
- package/string/VA.js +1 -0
- package/string/VI.d.ts +2 -0
- package/string/VI.js +1 -0
- package/string/VT.d.ts +2 -0
- package/string/VT.js +1 -0
- package/string/WA.d.ts +2 -0
- package/string/WA.js +1 -0
- package/string/WI.d.ts +2 -0
- package/string/WI.js +1 -0
- package/string/WV.d.ts +2 -0
- package/string/WV.js +1 -0
- package/string/WY.d.ts +2 -0
- package/string/WY.js +1 -0
- package/string/index.d.ts +56 -0
- package/string/index.js +56 -0
- package/svg/AK.svg +1 -0
- package/svg/AL.svg +1 -0
- package/svg/AR.svg +1 -0
- package/svg/AS.svg +1 -0
- package/svg/AZ.svg +1 -0
- package/svg/CA.svg +1 -0
- package/svg/CO.svg +1 -0
- package/svg/CT.svg +1 -0
- package/svg/DC.svg +1 -0
- package/svg/DE.svg +1 -0
- package/svg/FL.svg +1 -0
- package/svg/GA.svg +1 -0
- package/svg/GU.svg +1 -0
- package/svg/HI.svg +1 -0
- package/svg/IA.svg +1 -0
- package/svg/ID.svg +1 -0
- package/svg/IL.svg +1 -0
- package/svg/IN.svg +1 -0
- package/svg/KS.svg +1 -0
- package/svg/KY.svg +1 -0
- package/svg/LA.svg +1 -0
- package/svg/MA.svg +1 -0
- package/svg/MD.svg +1 -0
- package/svg/ME.svg +1 -0
- package/svg/MI.svg +1 -0
- package/svg/MN.svg +1 -0
- package/svg/MO.svg +1 -0
- package/svg/MP.svg +1 -0
- package/svg/MS.svg +1 -0
- package/svg/MT.svg +1 -0
- package/svg/NC.svg +1 -0
- package/svg/ND.svg +1 -0
- package/svg/NE.svg +1 -0
- package/svg/NH.svg +1 -0
- package/svg/NJ.svg +1 -0
- package/svg/NM.svg +1 -0
- package/svg/NV.svg +1 -0
- package/svg/NY.svg +1 -0
- package/svg/OH.svg +1 -0
- package/svg/OK.svg +1 -0
- package/svg/OR.svg +1 -0
- package/svg/PA.svg +1 -0
- package/svg/PR.svg +1 -0
- package/svg/RI.svg +1 -0
- package/svg/SC.svg +1 -0
- package/svg/SD.svg +1 -0
- package/svg/TN.svg +1 -0
- package/svg/TX.svg +1 -0
- package/svg/UT.svg +1 -0
- package/svg/VA.svg +1 -0
- package/svg/VI.svg +1 -0
- package/svg/VT.svg +1 -0
- package/svg/WA.svg +1 -0
- package/svg/WI.svg +1 -0
- package/svg/WV.svg +1 -0
- package/svg/WY.svg +1 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mo-Ibra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# us-state-flag-icons
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/us-state-flag-icons)
|
|
4
|
+
[](https://www.npmjs.com/package/us-state-flag-icons)
|
|
5
|
+
|
|
6
|
+
Vector flags for the 50 US states, the District of Columbia, and the inhabited
|
|
7
|
+
territories, available as plain SVG files, React components, JS strings, and CSS
|
|
8
|
+
classes.
|
|
9
|
+
|
|
10
|
+
- Covers all 50 states plus `DC`, `PR`, `GU`, `VI`, `AS`, and `MP`.
|
|
11
|
+
- Preserves each flag's **native aspect ratio** (state flags are not all the
|
|
12
|
+
same shape — Ohio is a swallowtail pennant).
|
|
13
|
+
- React components render an accessible `<title>` automatically.
|
|
14
|
+
- Tiny core API (`hasState`, `states`, `getStateName`).
|
|
15
|
+
|
|
16
|
+
> There is no Unicode/emoji equivalent for US state flags, so unlike
|
|
17
|
+
> `country-flag-icons` this package has no `/unicode` subpackage.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm install us-state-flag-icons
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### SVG files
|
|
28
|
+
|
|
29
|
+
The optimized SVGs live in the `svg/` folder of the package:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<img
|
|
33
|
+
alt="California"
|
|
34
|
+
src="https://unpkg.com/us-state-flag-icons/svg/CA.svg"
|
|
35
|
+
height="40"/>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Or import the file path through your bundler:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import caFlagUrl from 'us-state-flag-icons/svg/CA.svg'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Because flags have different aspect ratios, set only **one** of `width`/`height`
|
|
45
|
+
(and let the SVG scale) to avoid distortion.
|
|
46
|
+
|
|
47
|
+
### CSS
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import 'us-state-flag-icons/flags.css'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<span class="flag:CA"></span>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The icon height is controlled by the `--StateFlagIcon-height` CSS variable
|
|
58
|
+
(default `1em`), so it also follows `font-size`:
|
|
59
|
+
|
|
60
|
+
```css
|
|
61
|
+
/* Global flag height. */
|
|
62
|
+
[class*=' flag:'],
|
|
63
|
+
[class^='flag:'] {
|
|
64
|
+
--StateFlagIcon-height: 24px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* Or per flag. */
|
|
68
|
+
.flag\:CA {
|
|
69
|
+
font-size: 24px;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### React
|
|
74
|
+
|
|
75
|
+
```jsx
|
|
76
|
+
import { CA, TX } from 'us-state-flag-icons/react'
|
|
77
|
+
|
|
78
|
+
<CA title="California"/>
|
|
79
|
+
<TX title="Texas" className="my-flag"/>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Every flag is also available as a per-flag default import (useful if your
|
|
83
|
+
bundler does not support tree-shaking):
|
|
84
|
+
|
|
85
|
+
```jsx
|
|
86
|
+
import CA from 'us-state-flag-icons/react/CA'
|
|
87
|
+
|
|
88
|
+
<CA title="California"/>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Passing `title` renders a `<title>` element (and `aria-labelledby`) for
|
|
92
|
+
accessibility. `react` is an optional peer dependency — only install it if you
|
|
93
|
+
use the `/react` subpackage.
|
|
94
|
+
|
|
95
|
+
### String
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
import { CA } from 'us-state-flag-icons/string'
|
|
99
|
+
|
|
100
|
+
// Or the per-flag default import:
|
|
101
|
+
import CA from 'us-state-flag-icons/string/CA'
|
|
102
|
+
|
|
103
|
+
console.log(CA) // > '<svg xmlns="http://www.w3.org/2000/svg" ...</svg>'
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## API
|
|
107
|
+
|
|
108
|
+
The core entry point is available as both ESM and CommonJS.
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
import { hasState, states, getStateName, stateData } from 'us-state-flag-icons'
|
|
112
|
+
|
|
113
|
+
hasState('CA') // => true
|
|
114
|
+
hasState('ZZ') // => false
|
|
115
|
+
|
|
116
|
+
states // => ['AK', 'AL', 'AZ', ...]
|
|
117
|
+
|
|
118
|
+
getStateName('CA') // => 'California'
|
|
119
|
+
getStateName('ZZ') // => undefined
|
|
120
|
+
|
|
121
|
+
stateData[0]
|
|
122
|
+
// => {
|
|
123
|
+
// code: 'AK',
|
|
124
|
+
// name: 'Alaska',
|
|
125
|
+
// width: 1416, height: 1000, aspectRatio: 1.416,
|
|
126
|
+
// viewBox: '0 0 1416 1000',
|
|
127
|
+
// license: 'Public domain',
|
|
128
|
+
// source: 'https://commons.wikimedia.org/wiki/File:Flag_of_Alaska.svg'
|
|
129
|
+
// }
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `hasState(code: string): boolean`
|
|
133
|
+
|
|
134
|
+
Whether a flag exists for a two-letter code.
|
|
135
|
+
|
|
136
|
+
### `states: string[]`
|
|
137
|
+
|
|
138
|
+
All supported codes.
|
|
139
|
+
|
|
140
|
+
### `getStateName(code: string): string | undefined`
|
|
141
|
+
|
|
142
|
+
The display name for a code.
|
|
143
|
+
|
|
144
|
+
### `stateData: State[]`
|
|
145
|
+
|
|
146
|
+
The full dataset, one record per flag.
|
|
147
|
+
|
|
148
|
+
## Aspect ratios
|
|
149
|
+
|
|
150
|
+
Unlike national flags, US state flags are **not** a uniform shape. The library
|
|
151
|
+
keeps each flag's native ratio and exposes it via `stateData`, so the React
|
|
152
|
+
components, the CSS classes, and the SVGs all scale correctly.
|
|
153
|
+
|
|
154
|
+
| Flag | Ratio | Note |
|
|
155
|
+
| --- | --- | --- |
|
|
156
|
+
| `AL`, `CA`, `TX` | 3:2 | standard |
|
|
157
|
+
| `OH` | 26:16 | swallowtail (non-rectangular) |
|
|
158
|
+
| `HI`, `NY`, `DC`, `AS`, `MP` | 2:1 | |
|
|
159
|
+
| `RI` | ~1.14:1 | nearly square |
|
|
160
|
+
| `PA` | 1.37:1 | |
|
|
161
|
+
|
|
162
|
+
There are 16 distinct aspect ratios in total.
|
|
163
|
+
|
|
164
|
+
## Package size
|
|
165
|
+
|
|
166
|
+
The artwork is detailed (many flags contain a state seal), so the published
|
|
167
|
+
package is several megabytes. For comparison, `country-flag-icons` ships
|
|
168
|
+
simplified, hand-drawn flags at roughly 1 KB each. If package size is critical,
|
|
169
|
+
that simplified approach is the alternative.
|
|
170
|
+
|
|
171
|
+
The React and string subpackages are **ES modules only**; the core API also
|
|
172
|
+
provides a CommonJS build.
|
|
173
|
+
|
|
174
|
+
## Licensing
|
|
175
|
+
|
|
176
|
+
- **Code:** [MIT](./LICENSE).
|
|
177
|
+
- **Flag artwork:** sourced from Wikimedia Commons. Almost all of it is public
|
|
178
|
+
domain; per-flag provenance, author, and license are recorded in
|
|
179
|
+
[`flags/credits.json`](./flags/credits.json). No attribution is required, but
|
|
180
|
+
check that file before redistribution.
|
|
181
|
+
|
|
182
|
+
## Development
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
npm install
|
|
186
|
+
|
|
187
|
+
# Re-download/re-curate the source SVGs (only needed to add or refresh a flag).
|
|
188
|
+
npm run fetch-flags
|
|
189
|
+
|
|
190
|
+
npm run build
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
| Script | Description |
|
|
194
|
+
| --- | --- |
|
|
195
|
+
| `npm run fetch-flags` | Download + normalize the source SVGs and license metadata |
|
|
196
|
+
| `npm run generate-states` | Build `source/states.json` from the flags + credits |
|
|
197
|
+
| `npm run build` | Generate all distributable assets and the `exports` map |
|
|
198
|
+
| `npm test` | Unit tests (API, generated assets, React rendering) |
|
|
199
|
+
| `npm run test:package` | Pack the tarball, install it in a temp project, run ESM/CJS/React consumers |
|
|
200
|
+
| `npm run lint:package` | Validate the package with [`publint`](https://publint.dev) |
|
|
201
|
+
| `npm run check:types` | Validate type resolution with [Are The Types Wrong](https://arethetypeswrong.github.io) |
|
|
202
|
+
|
|
203
|
+
### Build pipeline
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
flags/ hand-curated source SVGs (+ credits.json)
|
|
207
|
+
│ optimize-flags
|
|
208
|
+
▼
|
|
209
|
+
svg/ optimized, scalable SVGs
|
|
210
|
+
├─ generate-string-flags → string/
|
|
211
|
+
├─ generate-react-flags → react/
|
|
212
|
+
├─ generate-css → flags.css
|
|
213
|
+
└─ create-flags-zip → flags.zip
|
|
214
|
+
source/states.json generated dataset (from flags + credits)
|
|
215
|
+
└─ update-package-exports → package.json "exports"/"files"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Publishing
|
|
219
|
+
|
|
220
|
+
`npm publish` runs a full gate via `prepublishOnly`:
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
build → unit tests → publint → Are The Types Wrong → install-the-tarball package test
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Before the first publish, set `repository`, `homepage`, and `bugs` in
|
|
227
|
+
`package.json`, and make sure the package name is available on npm.
|
|
228
|
+
|
|
229
|
+
### Previewing the tarball
|
|
230
|
+
|
|
231
|
+
To see exactly what would be uploaded, without publishing:
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
npm publish --dry-run --ignore-scripts
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
`--ignore-scripts` is required because the gate itself runs `npm pack`, which
|
|
238
|
+
npm suppresses while it is in dry-run mode. Use `npm run prepublishOnly` to
|
|
239
|
+
exercise the full gate.
|
|
240
|
+
|
|
241
|
+
### GitHub Actions
|
|
242
|
+
|
|
243
|
+
`.github/workflows/ci.yml` runs the gate on push/PR.
|
|
244
|
+
`.github/workflows/publish.yml` publishes on GitHub release; add an `NPM_TOKEN`
|
|
245
|
+
repository secret (or configure
|
|
246
|
+
[npm trusted publishing](https://docs.npmjs.com/trusted-publishers)) for it to
|
|
247
|
+
work.
|
|
248
|
+
|