mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Consolidate package checks into one Jest test (#57509)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/57509 Simplify/unify various mechanisms for the monorepo's package invariants. These checks were previously scattered: - `private/monorepo-tests` package (manifest field checks) - `.github/workflow-scripts/lint_files.sh` (`.npmignore` ban) - `react-native/eslint-plugin-monorepo` (manifest field checks — duplicated) This folds everything into `scripts/monorepo-tests/__tests__/check-packages-test.js`. A plain Jest test is the most extensible home for future checks. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D111471313 fbshipit-source-id: ea50abd8148d92e70605dd7f809654348e3c0080
This commit is contained in:
1 parent
c948b61c05
commit
0ed6c560da
11 files changed
+42
-301
No files matched your search
@@ -61,12 +61,6 @@ module.exports = {
|
||||
files: ['package.json'],
|
||||
parser: 'jsonc-eslint-parser',
|
||||
},
|
||||
{
|
||||
files: ['package.json'],
|
||||
rules: {
|
||||
'@react-native/monorepo/react-native-manifest': 'error',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['flow-typed/**/*.js', 'packages/react-native/flow/**/*'],
|
||||
rules: {
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
set -e
|
||||
|
||||
if git ls-files | grep -E '\.npmignore$'; then
|
||||
echo "Error: Found unexpected .npmignore file(s). Please use package.json#files instead."
|
||||
exit 1
|
||||
fi
|
||||
@@ -453,9 +453,6 @@ jobs:
|
||||
uses: ./.github/actions/setup-node
|
||||
- name: Install dependencies
|
||||
uses: ./.github/actions/yarn-install
|
||||
- name: Lint file structure
|
||||
shell: bash
|
||||
run: ./.github/workflow-scripts/lint_files.sh
|
||||
- name: Run shellcheck
|
||||
shell: bash
|
||||
run: ./.github/workflow-scripts/analyze_scripts.sh
|
||||
|
||||
@@ -15,7 +15,6 @@ exports.rules = {
|
||||
'no-react-named-type-imports': require('./rules/no-react-named-type-imports'),
|
||||
'no-react-native-imports': require('./rules/no-react-native-imports'),
|
||||
'no-react-node-imports': require('./rules/no-react-node-imports'),
|
||||
'react-native-manifest': require('./rules/react-native-manifest'),
|
||||
'require-extends-error': require('./rules/require-extends-error'),
|
||||
'sort-imports': require('./rules/sort-imports'),
|
||||
'valid-flow-typed-signature': require('./rules/valid-flow-typed-signature'),
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @noflow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const rule = require('../react-native-manifest.js');
|
||||
const {RuleTester} = require('eslint');
|
||||
|
||||
const ruleTester = new RuleTester({
|
||||
parser: require.resolve('jsonc-eslint-parser'),
|
||||
});
|
||||
|
||||
ruleTester.run('react-native-manifest', rule, {
|
||||
valid: [
|
||||
{
|
||||
code: JSON.stringify({
|
||||
name: '@react-native/package-name',
|
||||
}),
|
||||
},
|
||||
{
|
||||
code: JSON.stringify({
|
||||
name: '@react-native/package-name',
|
||||
dependencies: {
|
||||
dependencyA: '1.0.0',
|
||||
},
|
||||
devDependencies: {
|
||||
dependencyB: '1.0.0',
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
code: JSON.stringify({
|
||||
name: '@react-native/monorepo',
|
||||
devDependencies: {
|
||||
dependencyB: '1.0.0',
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
code: JSON.stringify({
|
||||
name: 'react-native',
|
||||
dependencies: {
|
||||
dependencyA: '1.0.0',
|
||||
},
|
||||
}),
|
||||
},
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
code: JSON.stringify({
|
||||
name: '@react-native/monorepo',
|
||||
dependencies: {
|
||||
dependencyA: '1.0.0',
|
||||
},
|
||||
}),
|
||||
errors: [
|
||||
{
|
||||
messageId: 'propertyDisallowed',
|
||||
data: {
|
||||
property: 'dependencies',
|
||||
describe:
|
||||
"Declare 'dependencies' in `packages/react-native/package.json`.",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
code: JSON.stringify({
|
||||
name: 'react-native',
|
||||
devDependencies: {
|
||||
dependencyA: '1.0.0',
|
||||
},
|
||||
}),
|
||||
errors: [
|
||||
{
|
||||
messageId: 'propertyDisallowed',
|
||||
data: {
|
||||
property: 'devDependencies',
|
||||
describe: "Declare 'devDependencies' in `<root>/package.json`.",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -1,85 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @noflow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* React Native's monorepo requires that "devDependencies" be declared at the
|
||||
* root package.json and "dependencies" in the `react-native` package.json to
|
||||
* permit the ability to segment dependent workspaces into 1) a development
|
||||
* workspace root (which depends on the monorepo) and 2) a production workspace
|
||||
* (which depends on the `react-native` package).
|
||||
*/
|
||||
const PACKAGE_CONSTRAINTS = {
|
||||
'@react-native/monorepo': {
|
||||
disallowed: [
|
||||
{
|
||||
property: 'dependencies',
|
||||
describe:
|
||||
"Declare 'dependencies' in `packages/react-native/package.json`.",
|
||||
},
|
||||
],
|
||||
},
|
||||
'react-native': {
|
||||
disallowed: [
|
||||
{
|
||||
property: 'devDependencies',
|
||||
describe: "Declare 'devDependencies' in `<root>/package.json`.",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Enforce react-native manifest constraints',
|
||||
},
|
||||
messages: {
|
||||
propertyDisallowed:
|
||||
"'{{property}}' is disallowed in this file. {{describe}}",
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
|
||||
create(context) {
|
||||
// @see https://www.npmjs.com/package/jsonc-eslint-parser
|
||||
if (!context.parserServices.isJSON) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
'JSONExpressionStatement > JSONObjectExpression'(node) {
|
||||
const propertyNodes = {};
|
||||
for (const propertyNode of node.properties) {
|
||||
propertyNodes[propertyNode.key.value] = propertyNode;
|
||||
}
|
||||
|
||||
const name = propertyNodes.name?.value?.value;
|
||||
const constraints = PACKAGE_CONSTRAINTS[name];
|
||||
if (constraints == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const {property, describe} of constraints.disallowed) {
|
||||
const propertyNode = propertyNodes[property];
|
||||
if (propertyNode == null) {
|
||||
continue;
|
||||
}
|
||||
context.report({
|
||||
node: propertyNode,
|
||||
messageId: 'propertyDisallowed',
|
||||
data: {property, describe},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const CURRENT_DIR = __dirname;
|
||||
const PATH_TO_ROOT_PACKAGE_MANIFEST = path.join(
|
||||
CURRENT_DIR,
|
||||
'..',
|
||||
'..',
|
||||
'..',
|
||||
'package.json',
|
||||
);
|
||||
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(PATH_TO_ROOT_PACKAGE_MANIFEST).toString(),
|
||||
);
|
||||
|
||||
describe('@react-native/monorepo root package', () => {
|
||||
it('expected not to list any dependencies', () => {
|
||||
expect(manifest).not.toHaveProperty('dependencies');
|
||||
});
|
||||
});
|
||||
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const CURRENT_DIR = __dirname;
|
||||
const PATH_TO_REACT_NATIVE_PACKAGE_MANIFEST = path.join(
|
||||
CURRENT_DIR,
|
||||
'..',
|
||||
'..',
|
||||
'..',
|
||||
'packages',
|
||||
'react-native',
|
||||
'package.json',
|
||||
);
|
||||
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(PATH_TO_REACT_NATIVE_PACKAGE_MANIFEST).toString(),
|
||||
);
|
||||
|
||||
describe('react-native package', () => {
|
||||
it('expected not to list any devDependencies', () => {
|
||||
expect(manifest).not.toHaveProperty('devDependencies');
|
||||
});
|
||||
});
|
||||
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const CURRENT_DIR = __dirname;
|
||||
const PATH_TO_TESTER_PACKAGE_MANIFEST = path.join(
|
||||
CURRENT_DIR,
|
||||
'..',
|
||||
'..',
|
||||
'..',
|
||||
'packages',
|
||||
'rn-tester',
|
||||
'package.json',
|
||||
);
|
||||
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(PATH_TO_TESTER_PACKAGE_MANIFEST).toString(),
|
||||
);
|
||||
|
||||
describe('@react-native/tester package', () => {
|
||||
it('expected not to list any devDependencies', () => {
|
||||
expect(manifest).not.toHaveProperty('devDependencies');
|
||||
});
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name": "@react-native/monorepo-tests",
|
||||
"private": true,
|
||||
"version": "0.0.0"
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {REPO_ROOT} from '../../shared/consts';
|
||||
import {
|
||||
getReactNativePackage,
|
||||
getWorkspaceRoot,
|
||||
} from '../../shared/monorepoUtils';
|
||||
import {globSync} from 'tinyglobby';
|
||||
|
||||
describe('package manifests', () => {
|
||||
test('the workspace root must not declare runtime dependencies', async () => {
|
||||
const {packageJson} = await getWorkspaceRoot();
|
||||
expect(packageJson).not.toHaveProperty('dependencies');
|
||||
});
|
||||
|
||||
test('the react-native package must not declare devDependencies', async () => {
|
||||
const {packageJson} = await getReactNativePackage();
|
||||
expect(packageJson).not.toHaveProperty('devDependencies');
|
||||
});
|
||||
});
|
||||
|
||||
describe('package file structure', () => {
|
||||
test('packages must not contain .npmignore files', () => {
|
||||
// Publishing must be controlled via the package.json "files" field, which is
|
||||
// easier to audit and does not silently expand what gets shipped to npm.
|
||||
const npmignoreFiles = globSync('{packages,private}/**/.npmignore', {
|
||||
cwd: REPO_ROOT,
|
||||
dot: true,
|
||||
ignore: ['**/node_modules/**'],
|
||||
});
|
||||
|
||||
expect(npmignoreFiles).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user