Skip to content

Commit f401cbb

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Extend check-packages-test to validate additional required fields
Summary: Extend `check-packages-test.js` to catch two more classes of manifest drift: published packages missing required fields, and packages under `private/` missing the `private` flag. **Motivation** Inspired by react-native-community/template#241 — avoid a missing field blocking a future RN package publish. **Other changes** - To satisfy the new `files` requirement, add an explicit `files` allowlist to the four config packages that lacked one. As a side effect, this saves some `__tests__` files from being distributed. Changelog: [Internal] Differential Revision: D111471314
1 parent a5be3ce commit f401cbb

6 files changed

Lines changed: 64 additions & 4 deletions

File tree

packages/eslint-config-react-native/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
".": "./index.js",
2424
"./flat": "./flat.js"
2525
},
26+
"files": ["README.md", "flat.js", "index.js", "shared.js"],
2627
"dependencies": {
2728
"@babel/core": "^7.25.2",
2829
"@babel/eslint-parser": "^7.25.1",

packages/eslint-plugin-react-native/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
],
1818
"bugs": "https://github.com/react/react-native/issues",
1919
"main": "index.js",
20+
"files": [
21+
"README.md",
22+
"index.js",
23+
"no-deep-imports.js",
24+
"platform-colors.js",
25+
"utils.js"
26+
],
2027
"devDependencies": {
2128
"babel-plugin-syntax-hermes-parser": "0.36.1",
2229
"hermes-eslint": "0.36.1"

packages/eslint-plugin-specs/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
],
2020
"bugs": "https://github.com/react/react-native/issues",
2121
"main": "index.js",
22+
"files": [
23+
"README.md",
24+
"index.js",
25+
"react-native-modules.js",
26+
"with-babel-register"
27+
],
2228
"scripts": {
2329
"prepack": "node prepack.js",
2430
"postpack": "node postpack.js"

packages/typescript-config/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
"bugs": "https://github.com/react/react-native/issues",
1818
"exports": {
1919
".": "./tsconfig.json"
20-
}
20+
},
21+
"files": ["README.md", "tsconfig.json", "tsconfig.strict.json"]
2122
}

scripts/monorepo-tests/__tests__/check-packages-test.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
* @format
99
*/
1010

11-
import {REPO_ROOT} from '../../shared/consts';
11+
import {PRIVATE_DIR, REPO_ROOT} from '../../shared/consts';
1212
import {
13+
getPackages,
1314
getReactNativePackage,
1415
getWorkspaceRoot,
1516
} from '../../shared/monorepoUtils';
17+
import path from 'path';
1618
import {globSync} from 'tinyglobby';
1719

1820
describe('package manifests', () => {
@@ -25,6 +27,46 @@ describe('package manifests', () => {
2527
const {packageJson} = await getReactNativePackage();
2628
expect(packageJson).not.toHaveProperty('devDependencies');
2729
});
30+
31+
test('published packages must declare required fields', async () => {
32+
const packages = await getPackages({includeReactNative: true});
33+
const violations: Array<string> = [];
34+
35+
for (const name of Object.keys(packages)) {
36+
const {packageJson} = packages[name];
37+
38+
if (!packageJson.version) {
39+
violations.push(`${name}: missing "version"`);
40+
}
41+
if (!packageJson.license) {
42+
violations.push(`${name}: missing "license"`);
43+
}
44+
// "repository" is required for npm's trusted publishing / provenance (OIDC)
45+
if (!packageJson.repository?.url) {
46+
violations.push(`${name}: missing "repository.url"`);
47+
}
48+
if (!packageJson.repository?.directory) {
49+
violations.push(`${name}: missing "repository.directory"`);
50+
}
51+
if (packageJson.files == null || packageJson.files.length === 0) {
52+
violations.push(`${name}: missing "files"`);
53+
}
54+
}
55+
56+
expect(violations).toEqual([]);
57+
});
58+
59+
test('packages under private/ must set "private": true', async () => {
60+
const packages = await getPackages({
61+
includeReactNative: true,
62+
includePrivate: true,
63+
});
64+
const notPrivate = Object.keys(packages)
65+
.filter(name => packages[name].path.startsWith(PRIVATE_DIR + path.sep))
66+
.filter(name => packages[name].packageJson.private !== true);
67+
68+
expect(notPrivate).toEqual([]);
69+
});
2870
});
2971

3072
describe('package file structure', () => {

scripts/shared/monorepoUtils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ const WORKSPACES_CONFIG = '{packages,private}/*';
1919
export type PackageJson = {
2020
name: string,
2121
version: string,
22-
private?: boolean,
2322
dependencies?: Record<string, string>,
2423
devDependencies?: Record<string, string>,
25-
peerDependencies?: Record<string, string>,
24+
files?: ReadonlyArray<string>,
25+
license?: string,
2626
main?: string,
27+
peerDependencies?: Record<string, string>,
28+
private?: boolean,
29+
repository?: {type?: string, url?: string, directory?: string, ...},
2730
...
2831
};
2932

0 commit comments

Comments
 (0)