Skip to content

Commit 62bfbfa

Browse files
David Snidermeta-codesync[bot]
authored andcommitted
Some package doc updates
Summary: Including small missing details, update invariant, etc Reviewed By: tlil Differential Revision: D92434646 fbshipit-source-id: 5959c1cc390ad8ec7c971b7e9b45019b40bdbb05
1 parent 3d1377b commit 62bfbfa

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

hphp/hack/manual/hack/18-packages/01-introduction.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ include_paths = ["//"]
9595
This creates a package that captures all files not in other packages.
9696

9797
Once you've defined a set of packages, you can deploy them using [deployments](/hack/packages/deployments).
98+
99+
## Tests Directory Exemption
100+
101+
Test directories are exempt from package access checks:
102+
103+
Files in directories containing `__tests__` in their path are excluded from package enforcement:
104+
- They are **bidirectionally** excluded from typechecker package errors
105+
- They are automatically excluded from all deployments

hphp/hack/manual/hack/18-packages/03-cross-package-calls.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ if (package foo) {
142142
}
143143
```
144144

145-
**Note:** Package expressions are currently disallowed inside `invariant()` calls due to unexpected typechecker complexity.
146-
147145
### Runtime Behavior
148146

149147
- `package foo` desugars to `package_exists("foo")`
@@ -202,7 +200,33 @@ function conditional_caller(): void {
202200

203201
### Package Inclusion Requirements
204202

205-
When using `<<__RequirePackage('a')>>` or `<<__SoftRequirePackage('a')>>` in package 'b', package 'a' must include package 'b'.
203+
When using `<<__RequirePackage('a')>>` or `<<__SoftRequirePackage('a')>>` in package 'b', package 'a' must **strictly** include package 'b'. This means:
204+
205+
1. **Cannot require own package:** You cannot use `__(Soft)RequirePackage('b')` when already in package 'b'.
206+
207+
```hack no-extract
208+
// File in package 'intern'
209+
<<__RequirePackage('intern')>> // ERROR: cannot require own package
210+
function self_require(): void {}
211+
212+
<<__RequirePackage('prod')>> // ERROR: prod does not include intern
213+
function reverse_require(): void {} // (assuming intern includes prod, not vice versa)
214+
```
215+
216+
2. **Must not soft-include:** If package 'b' only `soft_includes` package 'a', you cannot use `__(Soft)RequirePackage('a')` in package 'b'.
217+
218+
```toml
219+
[packages.prod]
220+
soft_includes = ["dynamically_accessible"]
221+
```
222+
223+
```hack no-extract
224+
// File in package 'prod'
225+
<<__RequirePackage('dynamically_accessible')>> // ERROR: prod only soft-includes this package
226+
function illegal(): void {}
227+
```
228+
229+
206230

207231
### `__RequirePackage`
208232

@@ -443,6 +467,7 @@ Temporary exceptions support legacy build behaviors where certain symbol referen
443467

444468
**Bypassed contexts** (migration only):
445469
- **Type aliases**: `type MyType = ForeignPackageType`
470+
- **Newtype aliases**: `newtype MyType = ForeignPackageType`
446471
- **Type hints**: Parameters and return types referencing foreign package types
447472
- **Generics**: Reified and erased generics like `new C<ForeignPackageType>()`
448473
- **Function types**: `function(ForeignPackageType): int`
@@ -453,4 +478,4 @@ Temporary exceptions support legacy build behaviors where certain symbol referen
453478
- **Shape, vec, and dict types**: `shape('foo' => ForeignPackageType)`, `vec<ForeignPackageType>`, `dict<string, ForeignPackageType>`
454479
- **is/as expressions**: `$x is ForeignPackageType`, `$x as ForeignPackageType`
455480

456-
These exceptions are intended to be temporary and may be removed in future versions as codebases enable.
481+
These exceptions are intended to be temporary and may be removed in future versions as codebases enable stricter checking.

hphp/hack/manual/hack/18-packages/04-migration-guide.md renamed to hphp/hack/manual/hack/18-packages/05-migration-guide.md

File renamed without changes.

0 commit comments

Comments
 (0)