Skip to content

Commit 2b14779

Browse files
authored
feat(project): add subpath pattern to package.json to restrict internal imports (#3186)
* feat(project): add subpath pattern to package.json to restrict internal imports * refactor(project): move useOverflow to internal/hooks * docs(adrs): update adopted status for adr * chore: add changeset * Update generated/components.json --------- Co-authored-by: Josh Black <[email protected]>
1 parent ca60603 commit 2b14779

File tree

8 files changed

+21
-39
lines changed

8 files changed

+21
-39
lines changed

.changeset/chilled-crabs-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
Modules under an internal export pattern are not able to be imported from outside @primer/react

contributor-docs/adrs/adr-016-internal-modules.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
| Stage | Status |
66
| -------- | ------ |
77
| Approved ||
8-
| Adopted | 🚧 |
8+
| Adopted | |
99

1010
## Context
1111

1212
Currently all files live under the `src` directory. In the `npm` package for `@primer/react`, we specify the following export pattern:
1313

1414
```json5
1515
{
16-
"exports": {
16+
exports: {
1717
// ...
18-
"./lib-esm/*": {
19-
"import": [
18+
'./lib-esm/*': {
19+
import: [
2020
// ...
2121
],
22-
"require": [
22+
require: [
2323
// ...
24-
]
25-
}
26-
}
24+
],
25+
},
26+
},
2727
}
2828
```
2929

@@ -37,10 +37,10 @@ In the `"exports"` field of our `npm` package, we can then add the following pat
3737

3838
```json5
3939
{
40-
"exports": {
40+
exports: {
4141
// ...
42-
"./lib-esm/internal/*": null
43-
}
42+
'./lib-esm/internal/*': null,
43+
},
4444
}
4545
```
4646

@@ -57,7 +57,6 @@ This pattern would remove any files and folders within `src/internal` from the p
5757
}
5858
```
5959

60-
6160
### Impact
6261

6362
- Update the `"exports"` field in `package.json` to exclude `./lib-esm/internal` from usage

generated/components.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
{
244244
"name": "direction",
245245
"type": "'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw'",
246+
"defaultValue": "n",
246247
"description": "Sets where the tooltip renders in relation to the target."
247248
},
248249
{

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"./lib/*.js",
2727
"./lib/*/index.js"
2828
]
29-
}
29+
},
30+
"./lib-esm/internal/*": null
3031
},
3132
"typings": "lib/index.d.ts",
3233
"sideEffects": false,

src/DataTable/Table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {Column, CellAlignment} from './column'
1111
import {UniqueRow} from './row'
1212
import {SortDirection} from './sorting'
1313
import {useTableLayout} from './useTable'
14-
import {useOverflow} from '../hooks/useOverflow'
14+
import {useOverflow} from '../internal/hooks/useOverflow'
1515

1616
// ----------------------------------------------------------------------------
1717
// Table

src/PageLayout/PageLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {useSlots} from '../hooks/useSlots'
88
import {BetterSystemStyleObject, merge, SxProp} from '../sx'
99
import {Theme} from '../ThemeProvider'
1010
import {canUseDOM} from '../utils/environment'
11-
import {useOverflow} from '../utils/useOverflow'
11+
import {useOverflow} from '../internal/hooks/useOverflow'
1212
import {warning} from '../utils/warning'
1313
import VisuallyHidden from '../_VisuallyHidden'
1414
import {useStickyPaneHeight} from './useStickyPaneHeight'
File renamed without changes.

src/utils/useOverflow.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)