diff --git a/packages/eslint-config-react-native/package.json b/packages/eslint-config-react-native/package.json index 937b51e14be..99fc3a8d2e9 100644 --- a/packages/eslint-config-react-native/package.json +++ b/packages/eslint-config-react-native/package.json @@ -23,6 +23,7 @@ ".": "./index.js", "./flat": "./flat.js" }, + "files": ["README.md", "flat.js", "index.js", "shared.js"], "dependencies": { "@babel/core": "^7.25.2", "@babel/eslint-parser": "^7.25.1", diff --git a/packages/eslint-plugin-react-native/package.json b/packages/eslint-plugin-react-native/package.json index c655ccbd884..d6900b4ff4c 100644 --- a/packages/eslint-plugin-react-native/package.json +++ b/packages/eslint-plugin-react-native/package.json @@ -17,6 +17,13 @@ ], "bugs": "https://github.com/react/react-native/issues", "main": "index.js", + "files": [ + "README.md", + "index.js", + "no-deep-imports.js", + "platform-colors.js", + "utils.js" + ], "devDependencies": { "babel-plugin-syntax-hermes-parser": "0.36.1", "hermes-eslint": "0.36.1" diff --git a/packages/eslint-plugin-specs/package.json b/packages/eslint-plugin-specs/package.json index 60ad0fb9672..882071d9c48 100644 --- a/packages/eslint-plugin-specs/package.json +++ b/packages/eslint-plugin-specs/package.json @@ -19,6 +19,12 @@ ], "bugs": "https://github.com/react/react-native/issues", "main": "index.js", + "files": [ + "README.md", + "index.js", + "react-native-modules.js", + "with-babel-register" + ], "scripts": { "prepack": "node prepack.js", "postpack": "node postpack.js" diff --git a/packages/typescript-config/package.json b/packages/typescript-config/package.json index 98c39c04112..8d938d94b0e 100644 --- a/packages/typescript-config/package.json +++ b/packages/typescript-config/package.json @@ -17,5 +17,6 @@ "bugs": "https://github.com/react/react-native/issues", "exports": { ".": "./tsconfig.json" - } + }, + "files": ["README.md", "tsconfig.json", "tsconfig.strict.json"] } diff --git a/scripts/monorepo-tests/__tests__/check-packages-test.js b/scripts/monorepo-tests/__tests__/check-packages-test.js index 3fc0611203a..93dd3ba58a5 100644 --- a/scripts/monorepo-tests/__tests__/check-packages-test.js +++ b/scripts/monorepo-tests/__tests__/check-packages-test.js @@ -8,11 +8,13 @@ * @format */ -import {REPO_ROOT} from '../../shared/consts'; +import {PRIVATE_DIR, REPO_ROOT} from '../../shared/consts'; import { + getPackages, getReactNativePackage, getWorkspaceRoot, } from '../../shared/monorepoUtils'; +import path from 'path'; import {globSync} from 'tinyglobby'; describe('package manifests', () => { @@ -25,6 +27,52 @@ describe('package manifests', () => { const {packageJson} = await getReactNativePackage(); expect(packageJson).not.toHaveProperty('devDependencies'); }); + + test('published packages must declare required fields', async () => { + const packages = await getPackages({includeReactNative: true}); + const violations: Array = []; + + for (const name of Object.keys(packages)) { + const {packageJson} = packages[name]; + + if (!packageJson.version) { + violations.push(`${name}: missing "version"`); + } + if (packageJson.license == null || packageJson.license === '') { + violations.push(`${name}: missing "license"`); + } + // "repository" is required for npm's trusted publishing / provenance (OIDC) + if ( + packageJson.repository?.url == null || + packageJson.repository.url === '' + ) { + violations.push(`${name}: missing "repository.url"`); + } + if ( + packageJson.repository?.directory == null || + packageJson.repository.directory === '' + ) { + violations.push(`${name}: missing "repository.directory"`); + } + if (packageJson.files == null || packageJson.files.length === 0) { + violations.push(`${name}: missing "files"`); + } + } + + expect(violations).toEqual([]); + }); + + test('packages under private/ must set "private": true', async () => { + const packages = await getPackages({ + includeReactNative: true, + includePrivate: true, + }); + const notPrivate = Object.keys(packages) + .filter(name => packages[name].path.startsWith(PRIVATE_DIR + path.sep)) + .filter(name => packages[name].packageJson.private !== true); + + expect(notPrivate).toEqual([]); + }); }); describe('package file structure', () => { diff --git a/scripts/shared/monorepoUtils.js b/scripts/shared/monorepoUtils.js index eecb81250a0..0e43fa0f845 100644 --- a/scripts/shared/monorepoUtils.js +++ b/scripts/shared/monorepoUtils.js @@ -19,11 +19,14 @@ const WORKSPACES_CONFIG = '{packages,private}/*'; export type PackageJson = { name: string, version: string, - private?: boolean, dependencies?: Record, devDependencies?: Record, - peerDependencies?: Record, + files?: ReadonlyArray, + license?: string, main?: string, + peerDependencies?: Record, + private?: boolean, + repository?: {type?: string, url?: string, directory?: string, ...}, ... };