From 8da4cdda83c60d33565d39fc205f198831d1c979 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 17 Apr 2023 16:00:38 -0500 Subject: [PATCH 1/5] feat(project): add subpath pattern to package.json to restrict internal imports --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9c4f28e2b9f..0f68fa657a0 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "./lib/*.js", "./lib/*/index.js" ] - } + }, + "./lib-esm/internal/*": null }, "typings": "lib/index.d.ts", "sideEffects": false, From f6c57c993470881a5b0636b89dc72bf107585cb3 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 17 Apr 2023 16:00:57 -0500 Subject: [PATCH 2/5] refactor(project): move useOverflow to internal/hooks --- src/DataTable/Table.tsx | 2 +- src/PageLayout/PageLayout.tsx | 2 +- src/{ => internal}/hooks/useOverflow.ts | 0 src/utils/useOverflow.ts | 24 ------------------------ 4 files changed, 2 insertions(+), 26 deletions(-) rename src/{ => internal}/hooks/useOverflow.ts (100%) delete mode 100644 src/utils/useOverflow.ts diff --git a/src/DataTable/Table.tsx b/src/DataTable/Table.tsx index b3857e0721e..bfa899e2be2 100644 --- a/src/DataTable/Table.tsx +++ b/src/DataTable/Table.tsx @@ -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 diff --git a/src/PageLayout/PageLayout.tsx b/src/PageLayout/PageLayout.tsx index 13b181e448e..fe50d009a0b 100644 --- a/src/PageLayout/PageLayout.tsx +++ b/src/PageLayout/PageLayout.tsx @@ -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' diff --git a/src/hooks/useOverflow.ts b/src/internal/hooks/useOverflow.ts similarity index 100% rename from src/hooks/useOverflow.ts rename to src/internal/hooks/useOverflow.ts diff --git a/src/utils/useOverflow.ts b/src/utils/useOverflow.ts deleted file mode 100644 index c54e00a134d..00000000000 --- a/src/utils/useOverflow.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {useEffect, useState} from 'react' - -export function useOverflow(ref: React.RefObject) { - const [hasOverflow, setHasOverflow] = useState(false) - - useEffect(() => { - if (ref.current === null) return - - const observer = new ResizeObserver(entries => { - for (const entry of entries) { - setHasOverflow( - entry.target.scrollHeight > entry.target.clientHeight || entry.target.scrollWidth > entry.target.clientWidth, - ) - } - }) - - observer.observe(ref.current) - return () => { - observer.disconnect() - } - }, [ref]) - - return hasOverflow -} From 7706b0ff820a1940e937ccb3eac7d3cc1c48e6ab Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 17 Apr 2023 16:01:56 -0500 Subject: [PATCH 3/5] docs(adrs): update adopted status for adr --- .../adrs/adr-016-internal-modules.md | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/contributor-docs/adrs/adr-016-internal-modules.md b/contributor-docs/adrs/adr-016-internal-modules.md index cc91c68e3f3..eadc8c9d053 100644 --- a/contributor-docs/adrs/adr-016-internal-modules.md +++ b/contributor-docs/adrs/adr-016-internal-modules.md @@ -5,7 +5,7 @@ | Stage | Status | | -------- | ------ | | Approved | ✅ | -| Adopted | 🚧 | +| Adopted | ✅ | ## Context @@ -13,17 +13,17 @@ Currently all files live under the `src` directory. In the `npm` package for `@p ```json5 { - "exports": { + exports: { // ... - "./lib-esm/*": { - "import": [ + './lib-esm/*': { + import: [ // ... ], - "require": [ + require: [ // ... - ] - } - } + ], + }, + }, } ``` @@ -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, + }, } ``` @@ -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 From fc46486b135f6062a392355370a709f59a6c4876 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 17 Apr 2023 16:03:25 -0500 Subject: [PATCH 4/5] chore: add changeset --- .changeset/chilled-crabs-bow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilled-crabs-bow.md diff --git a/.changeset/chilled-crabs-bow.md b/.changeset/chilled-crabs-bow.md new file mode 100644 index 00000000000..b508afeeddb --- /dev/null +++ b/.changeset/chilled-crabs-bow.md @@ -0,0 +1,5 @@ +--- +'@primer/react': minor +--- + +Modules under an internal export pattern are not able to be imported from outside @primer/react From 79658b1bccd9205f167565cf362e9d5a7dd7a164 Mon Sep 17 00:00:00 2001 From: joshblack Date: Tue, 18 Apr 2023 14:55:57 +0000 Subject: [PATCH 5/5] Update generated/components.json --- generated/components.json | 1 + 1 file changed, 1 insertion(+) diff --git a/generated/components.json b/generated/components.json index cd2307492bd..5b0b4a5f931 100644 --- a/generated/components.json +++ b/generated/components.json @@ -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." }, {