Skip to content

feat(project): add subpath pattern to package.json to restrict internal imports #3186

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

Merged
merged 6 commits into from
Apr 18, 2023
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
5 changes: 5 additions & 0 deletions .changeset/chilled-crabs-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

Modules under an internal export pattern are not able to be imported from outside @primer/react
23 changes: 11 additions & 12 deletions contributor-docs/adrs/adr-016-internal-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
| Stage | Status |
| -------- | ------ |
| Approved | ✅ |
| Adopted | 🚧 |
| Adopted | |

## Context

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

```json5
{
"exports": {
exports: {
// ...
"./lib-esm/*": {
"import": [
'./lib-esm/*': {
import: [
// ...
],
"require": [
require: [
// ...
]
}
}
],
},
},
}
```

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

```json5
{
"exports": {
exports: {
// ...
"./lib-esm/internal/*": null
}
'./lib-esm/internal/*': null,
},
}
```

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


### Impact

- Update the `"exports"` field in `package.json` to exclude `./lib-esm/internal` from usage
Expand Down
1 change: 1 addition & 0 deletions generated/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
{
"name": "direction",
"type": "'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw'",
"defaultValue": "n",
"description": "Sets where the tooltip renders in relation to the target."
},
{
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"./lib/*.js",
"./lib/*/index.js"
]
}
},
"./lib-esm/internal/*": null
},
"typings": "lib/index.d.ts",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion src/DataTable/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {Column, CellAlignment} from './column'
import {UniqueRow} from './row'
import {SortDirection} from './sorting'
import {useTableLayout} from './useTable'
import {useOverflow} from '../hooks/useOverflow'
import {useOverflow} from '../internal/hooks/useOverflow'

// ----------------------------------------------------------------------------
// Table
Expand Down
2 changes: 1 addition & 1 deletion src/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {useSlots} from '../hooks/useSlots'
import {BetterSystemStyleObject, merge, SxProp} from '../sx'
import {Theme} from '../ThemeProvider'
import {canUseDOM} from '../utils/environment'
import {useOverflow} from '../utils/useOverflow'
import {useOverflow} from '../internal/hooks/useOverflow'
import {warning} from '../utils/warning'
import VisuallyHidden from '../_VisuallyHidden'
import {useStickyPaneHeight} from './useStickyPaneHeight'
Expand Down
File renamed without changes.
24 changes: 0 additions & 24 deletions src/utils/useOverflow.ts

This file was deleted.