From d5383dd1e5f818376016e1fa43e16915e589640c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20M=C4=99drek?= Date: Thu, 22 Oct 2026 17:40:41 +0200 Subject: [PATCH] fix: example packages not being marked as private which fails publishing CI workflow --- .github/workflows/lint-release.yml | 34 +++++++++++++ examples/node-example/__utils__/utils.ts | 30 +++++++++++ examples/node-example/jest-setup.js | 13 +++++ examples/node-example/jest-teardown.js | 13 +++++ examples/node-example/jest.config.js | 2 + .../package.json | 4 +- .../package.json | 4 +- .../package.json | 4 +- .../package.json | 4 +- .../package.json | 4 +- .../package.json | 4 +- .../package.json | 4 +- .../package.json | 4 +- .../package.json | 4 +- .../package.json | 4 +- .../package.json | 4 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../package.json | 3 +- .../example-license-unlicensed/package.json | 3 +- lefthook.yml | 4 ++ package.json | 1 + packages/visualizer/tsconfig.json | 3 +- scripts/lint-public-workspace-packages.js | 51 +++++++++++++++++++ 37 files changed, 206 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/lint-release.yml create mode 100644 examples/node-example/jest-setup.js create mode 100644 examples/node-example/jest-teardown.js create mode 100755 scripts/lint-public-workspace-packages.js diff --git a/.github/workflows/lint-release.yml b/.github/workflows/lint-release.yml new file mode 100644 index 00000000..6b0ef2cd --- /dev/null +++ b/.github/workflows/lint-release.yml @@ -0,0 +1,34 @@ +name: Lint Release + +on: + pull_request: + paths: + - '.github/workflows/lint-release.yml' + - 'packages/react-native-legal/**/package.json' + - 'packages/licenses-api/**/package.json' + - 'packages/license-kit/**/package.json' + - 'examples/**/package.json' + - 'examples/**/package.json' + +concurrency: ${{ github.workflow }}-${{ github.ref }} + +permissions: + contents: read + +jobs: + lint-release: + name: Lint Release + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + + - name: Setup + uses: ./.github/actions/setup + with: + enable-cache: true + + - name: Run linter + run: yarn lint:release diff --git a/examples/node-example/__utils__/utils.ts b/examples/node-example/__utils__/utils.ts index a99033fc..f58fa257 100644 --- a/examples/node-example/__utils__/utils.ts +++ b/examples/node-example/__utils__/utils.ts @@ -1,4 +1,6 @@ import child_process from 'node:child_process'; +import fs from 'node:fs'; +import path from 'node:path'; import { stripVTControlCharacters } from 'node:util'; /** @@ -61,3 +63,31 @@ export function runLicenseKit(args: string[] = []) { ); }); } + +/** + * All workspace packages that are not meant to be published to NPM need to be private + * + * The problem is that we would like to use some fixture packages for tests and for that we actually need + * to have them non-private :C + * + * The solution is to make them non-private only in test environment - jest exposes `globalSetup` and `globalTeardown` + * that we can use to monkey patch the packages before and after all test suite run (not ideal, but works) + */ +export function patchFixturesPackages(fixturesDir: string, isPrivate: boolean) { + for (const packageName of fs.readdirSync(fixturesDir)) { + if (packageName === 'example-private-package') { + continue; + } + + const packagePath = path.join(fixturesDir, packageName, 'package.json'); + const packageJson = JSON.parse(fs.readFileSync(packagePath, { encoding: 'utf8' })); + + if (isPrivate) { + packageJson.private = true; + } else { + delete packageJson.private; + } + + fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + '\n', { encoding: 'utf8' }); + } +} diff --git a/examples/node-example/jest-setup.js b/examples/node-example/jest-setup.js new file mode 100644 index 00000000..c0ef4ad3 --- /dev/null +++ b/examples/node-example/jest-setup.js @@ -0,0 +1,13 @@ +const path = require('path'); + +const { patchFixturesPackages } = require('./__utils__/utils'); + +/** + * @param {import('@jest/types').Config.GlobalConfig} globalConfig + * @param {import('@jest/types').Config.ProjectConfig} projectConfig + */ +function setup(_globalConfig, _projectConfig) { + patchFixturesPackages(path.resolve(__dirname, '..', 'packages'), false); +} + +module.exports = setup; diff --git a/examples/node-example/jest-teardown.js b/examples/node-example/jest-teardown.js new file mode 100644 index 00000000..ef40d101 --- /dev/null +++ b/examples/node-example/jest-teardown.js @@ -0,0 +1,13 @@ +const path = require('path'); + +const { patchFixturesPackages } = require('./__utils__/utils'); + +/** + * @param {import('@jest/types').Config.GlobalConfig} globalConfig + * @param {import('@jest/types').Config.ProjectConfig} projectConfig + */ +function teardown(_globalConfig, _projectConfig) { + patchFixturesPackages(path.resolve(__dirname, '..', 'packages'), true); +} + +module.exports = teardown; diff --git a/examples/node-example/jest.config.js b/examples/node-example/jest.config.js index 71c0f77e..61e73358 100644 --- a/examples/node-example/jest.config.js +++ b/examples/node-example/jest.config.js @@ -3,6 +3,8 @@ const config = { testEnvironment: 'node', setupFilesAfterEnv: ['jest-extended/all'], testPathIgnorePatterns: ['__utils__'], + globalSetup: './jest-setup.js', + globalTeardown: './jest-teardown.js', }; module.exports = config; diff --git a/examples/packages/example-additional-project-root-2/package.json b/examples/packages/example-additional-project-root-2/package.json index 62cd6a07..2003f3d3 100644 --- a/examples/packages/example-additional-project-root-2/package.json +++ b/examples/packages/example-additional-project-root-2/package.json @@ -1,7 +1,7 @@ { "name": "@callstack/example-additional-project-root-2", - "private": true, "dependencies": { "clsx": "2.1.1" - } + }, + "private": true } diff --git a/examples/packages/example-additional-project-root/package.json b/examples/packages/example-additional-project-root/package.json index 8a8c7bc4..03e87078 100644 --- a/examples/packages/example-additional-project-root/package.json +++ b/examples/packages/example-additional-project-root/package.json @@ -1,7 +1,7 @@ { "name": "@callstack/example-additional-project-root", - "private": true, "dependencies": { "is-even": "1.0.0" - } + }, + "private": true } diff --git a/examples/packages/example-copyleft-root-copyleft-avoidable-by-or-policy/package.json b/examples/packages/example-copyleft-root-copyleft-avoidable-by-or-policy/package.json index ced8702c..356ead03 100644 --- a/examples/packages/example-copyleft-root-copyleft-avoidable-by-or-policy/package.json +++ b/examples/packages/example-copyleft-root-copyleft-avoidable-by-or-policy/package.json @@ -1,10 +1,10 @@ { "name": "@callstack/example-copyleft-root-copyleft-avoidable-by-or-policy", - "private": true, "description": "Test project for the license-kit copyleft exit code integration tests", "packageManager": "yarn@3.6.1", "dependencies": { "@callstack/example-license-apache-2.0-or-lgpl-3.0-and-mit-or-gpl-2.0": "workspace:*", "@callstack/example-license-mit-or-gpl-3.0": "workspace:*" - } + }, + "private": true } diff --git a/examples/packages/example-copyleft-root-copyleft-unavoidable/package.json b/examples/packages/example-copyleft-root-copyleft-unavoidable/package.json index 54671828..501421d1 100644 --- a/examples/packages/example-copyleft-root-copyleft-unavoidable/package.json +++ b/examples/packages/example-copyleft-root-copyleft-unavoidable/package.json @@ -1,9 +1,9 @@ { "name": "@callstack/example-copyleft-root-copyleft-unavoidable", - "private": true, "description": "Test project for the license-kit copyleft exit code integration tests", "packageManager": "yarn@3.6.1", "dependencies": { "@callstack/example-license-gpl-3.0-and-mit-or-apache-2.0": "workspace:*" - } + }, + "private": true } diff --git a/examples/packages/example-copyleft-root-legacy-licenses-array/package.json b/examples/packages/example-copyleft-root-legacy-licenses-array/package.json index f9abcb59..3fbc27e7 100644 --- a/examples/packages/example-copyleft-root-legacy-licenses-array/package.json +++ b/examples/packages/example-copyleft-root-legacy-licenses-array/package.json @@ -1,9 +1,9 @@ { "name": "@callstack/example-copyleft-root-legacy-licenses-array", - "private": true, "description": "Test project for the license-kit integration tests", "packageManager": "yarn@3.6.1", "dependencies": { "@callstack/example-license-legacy-licenses-array": "workspace:*" - } + }, + "private": true } diff --git a/examples/packages/example-copyleft-root-license-ref/package.json b/examples/packages/example-copyleft-root-license-ref/package.json index 56f65c64..43fc79bc 100644 --- a/examples/packages/example-copyleft-root-license-ref/package.json +++ b/examples/packages/example-copyleft-root-license-ref/package.json @@ -1,9 +1,9 @@ { "name": "@callstack/example-copyleft-root-license-ref", - "private": true, "description": "Test project for the license-kit integration tests", "packageManager": "yarn@3.6.1", "dependencies": { "@callstack/example-license-gpl-3.0-and-license-ref": "workspace:*" - } + }, + "private": true } diff --git a/examples/packages/example-copyleft-root-no-copyleft/package.json b/examples/packages/example-copyleft-root-no-copyleft/package.json index 0b16a96a..cbfbe52c 100644 --- a/examples/packages/example-copyleft-root-no-copyleft/package.json +++ b/examples/packages/example-copyleft-root-no-copyleft/package.json @@ -1,10 +1,10 @@ { "name": "@callstack/example-copyleft-root-no-copyleft", - "private": true, "description": "Test project for the license-kit copyleft exit code integration tests", "packageManager": "yarn@3.6.1", "dependencies": { "@callstack/example-license-mit-or-apache-2.0": "workspace:*", "@callstack/example-license-mit-or-apache-2.0-and-isc": "workspace:*" - } + }, + "private": true } diff --git a/examples/packages/example-copyleft-root-unknown-licenses/package.json b/examples/packages/example-copyleft-root-unknown-licenses/package.json index 2905b8f8..1fed7d1f 100644 --- a/examples/packages/example-copyleft-root-unknown-licenses/package.json +++ b/examples/packages/example-copyleft-root-unknown-licenses/package.json @@ -1,10 +1,10 @@ { "name": "@callstack/example-copyleft-root-unknown-licenses", - "private": true, "description": "Test project for the license-kit integration tests", "packageManager": "yarn@3.6.1", "dependencies": { "@callstack/example-license-see-license-in": "workspace:*", "@callstack/example-license-unlicensed": "workspace:*" - } + }, + "private": true } diff --git a/examples/packages/example-copyleft-root-weak-and-unidentified/package.json b/examples/packages/example-copyleft-root-weak-and-unidentified/package.json index b7b8b784..85724b64 100644 --- a/examples/packages/example-copyleft-root-weak-and-unidentified/package.json +++ b/examples/packages/example-copyleft-root-weak-and-unidentified/package.json @@ -1,9 +1,9 @@ { "name": "@callstack/example-copyleft-root-weak-and-unidentified", - "private": true, "description": "Test project for the license-kit integration tests", "packageManager": "yarn@3.6.1", "dependencies": { "@callstack/example-license-lgpl-2.1-and-license-ref": "workspace:*" - } + }, + "private": true } diff --git a/examples/packages/example-copyleft-root-weak-copyleft-only/package.json b/examples/packages/example-copyleft-root-weak-copyleft-only/package.json index ae0e5d3d..267969f2 100644 --- a/examples/packages/example-copyleft-root-weak-copyleft-only/package.json +++ b/examples/packages/example-copyleft-root-weak-copyleft-only/package.json @@ -1,9 +1,9 @@ { "name": "@callstack/example-copyleft-root-weak-copyleft-only", - "private": true, "description": "Test project for the license-kit copyleft exit code integration tests", "packageManager": "yarn@3.6.1", "dependencies": { "@callstack/example-license-mit-and-lgpl-2.1": "workspace:*" - } + }, + "private": true } diff --git a/examples/packages/example-copyleft-root-with-exception/package.json b/examples/packages/example-copyleft-root-with-exception/package.json index d9ae0c19..502934be 100644 --- a/examples/packages/example-copyleft-root-with-exception/package.json +++ b/examples/packages/example-copyleft-root-with-exception/package.json @@ -1,9 +1,9 @@ { "name": "@callstack/example-copyleft-root-with-exception", - "private": true, "description": "Test project for the license-kit integration tests", "packageManager": "yarn@3.6.1", "dependencies": { "@callstack/example-license-gpl-2.0-with-classpath-exception": "workspace:*" - } + }, + "private": true } diff --git a/examples/packages/example-license-apache-2.0-or-lgpl-3.0-and-mit-or-gpl-2.0/package.json b/examples/packages/example-license-apache-2.0-or-lgpl-3.0-and-mit-or-gpl-2.0/package.json index bf7da9f5..262ac5fe 100644 --- a/examples/packages/example-license-apache-2.0-or-lgpl-3.0-and-mit-or-gpl-2.0/package.json +++ b/examples/packages/example-license-apache-2.0-or-lgpl-3.0-and-mit-or-gpl-2.0/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with two Dual Licenses combined with AND, for the license-kit integration tests", "license": "(Apache-2.0 OR LGPL-3.0-only) AND (MIT OR GPL-2.0-only)", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-gpl-2.0-with-classpath-exception-with-text/package.json b/examples/packages/example-license-gpl-2.0-with-classpath-exception-with-text/package.json index 5fc9f809..c6018ba7 100644 --- a/examples/packages/example-license-gpl-2.0-with-classpath-exception-with-text/package.json +++ b/examples/packages/example-license-gpl-2.0-with-classpath-exception-with-text/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with a License Exception and a COPYING file, for the example apps", "license": "GPL-2.0-only WITH Classpath-exception-2.0", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-gpl-2.0-with-classpath-exception/package.json b/examples/packages/example-license-gpl-2.0-with-classpath-exception/package.json index 8ea42f5f..5ae8056d 100644 --- a/examples/packages/example-license-gpl-2.0-with-classpath-exception/package.json +++ b/examples/packages/example-license-gpl-2.0-with-classpath-exception/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with a strong copyleft license and a License Exception, for the license-kit integration tests", "license": "GPL-2.0-only WITH Classpath-exception-2.0", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-gpl-3.0-and-license-ref/package.json b/examples/packages/example-license-gpl-3.0-and-license-ref/package.json index 8a1a67c1..dd390fff 100644 --- a/examples/packages/example-license-gpl-3.0-and-license-ref/package.json +++ b/examples/packages/example-license-gpl-3.0-and-license-ref/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with strong copyleft next to a custom license, for the license-kit integration tests", "license": "GPL-3.0-only AND LicenseRef-Custom", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-gpl-3.0-and-mit-or-apache-2.0/package.json b/examples/packages/example-license-gpl-3.0-and-mit-or-apache-2.0/package.json index 11576084..4045ba74 100644 --- a/examples/packages/example-license-gpl-3.0-and-mit-or-apache-2.0/package.json +++ b/examples/packages/example-license-gpl-3.0-and-mit-or-apache-2.0/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with a strong copyleft license combined with AND with a Dual License, for the license-kit integration tests", "license": "GPL-3.0-only AND (MIT OR Apache-2.0)", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-legacy-licenses-array/package.json b/examples/packages/example-license-legacy-licenses-array/package.json index 24f17af1..2ce03aee 100644 --- a/examples/packages/example-license-legacy-licenses-array/package.json +++ b/examples/packages/example-license-legacy-licenses-array/package.json @@ -10,5 +10,6 @@ "type": "Apache-2.0" } ], - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-lgpl-2.1-and-license-ref/package.json b/examples/packages/example-license-lgpl-2.1-and-license-ref/package.json index e910a121..65e6e58c 100644 --- a/examples/packages/example-license-lgpl-2.1-and-license-ref/package.json +++ b/examples/packages/example-license-lgpl-2.1-and-license-ref/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with weak copyleft next to a custom license, for the license-kit integration tests", "license": "LGPL-2.1-only AND LicenseRef-Custom", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-lgpl-2.1-or-gpl-3.0/package.json b/examples/packages/example-license-lgpl-2.1-or-gpl-3.0/package.json index 10dc153e..d29ed5b7 100644 --- a/examples/packages/example-license-lgpl-2.1-or-gpl-3.0/package.json +++ b/examples/packages/example-license-lgpl-2.1-or-gpl-3.0/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with a Dual License of a weak and a strong copyleft license, for the license-kit integration tests", "license": "LGPL-2.1-only OR GPL-3.0-only", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-lgpl-3.0-plus/package.json b/examples/packages/example-license-lgpl-3.0-plus/package.json index 87a50ade..b6080eb5 100644 --- a/examples/packages/example-license-lgpl-3.0-plus/package.json +++ b/examples/packages/example-license-lgpl-3.0-plus/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with an LGPL-3.0+ license and a LICENSE.txt file, for the example apps", "license": "LGPL-3.0+", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-mit-and-lgpl-2.1/package.json b/examples/packages/example-license-mit-and-lgpl-2.1/package.json index e521fbe5..1dae794a 100644 --- a/examples/packages/example-license-mit-and-lgpl-2.1/package.json +++ b/examples/packages/example-license-mit-and-lgpl-2.1/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with a permissive and a weak copyleft license combined with AND, for the license-kit integration tests", "license": "MIT AND LGPL-2.1-only", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-mit-or-apache-2.0-and-isc/package.json b/examples/packages/example-license-mit-or-apache-2.0-and-isc/package.json index 328ab3b1..667ebd2a 100644 --- a/examples/packages/example-license-mit-or-apache-2.0-and-isc/package.json +++ b/examples/packages/example-license-mit-or-apache-2.0-and-isc/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with an expression relying on AND binding tighter than OR, for the license-kit integration tests", "license": "MIT OR Apache-2.0 AND ISC", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-mit-or-apache-2.0-single-file/package.json b/examples/packages/example-license-mit-or-apache-2.0-single-file/package.json index 71e50848..deac96cb 100644 --- a/examples/packages/example-license-mit-or-apache-2.0-single-file/package.json +++ b/examples/packages/example-license-mit-or-apache-2.0-single-file/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with a Dual License and a single unlinked license file, for the example apps", "license": "MIT OR Apache-2.0", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-mit-or-apache-2.0/package.json b/examples/packages/example-license-mit-or-apache-2.0/package.json index b3d064a1..032f00d7 100644 --- a/examples/packages/example-license-mit-or-apache-2.0/package.json +++ b/examples/packages/example-license-mit-or-apache-2.0/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with a Dual License of two permissive licenses, for the license-kit integration tests", "license": "MIT OR Apache-2.0", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-mit-or-gpl-3.0-in-and-with-lgpl-2.1/package.json b/examples/packages/example-license-mit-or-gpl-3.0-in-and-with-lgpl-2.1/package.json index 13586fbd..9bb33a68 100644 --- a/examples/packages/example-license-mit-or-gpl-3.0-in-and-with-lgpl-2.1/package.json +++ b/examples/packages/example-license-mit-or-gpl-3.0-in-and-with-lgpl-2.1/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with a Dual License nested inside AND, for the license-kit integration tests", "license": "(MIT OR GPL-3.0-only) AND LGPL-2.1-only", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-mit-or-gpl-3.0/package.json b/examples/packages/example-license-mit-or-gpl-3.0/package.json index 2e85a779..0d73917f 100644 --- a/examples/packages/example-license-mit-or-gpl-3.0/package.json +++ b/examples/packages/example-license-mit-or-gpl-3.0/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with a Dual License of a permissive and a strong copyleft license, for the license-kit integration tests", "license": "MIT OR GPL-3.0-only", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-see-license-in/package.json b/examples/packages/example-license-see-license-in/package.json index 0ed650e6..596ff211 100644 --- a/examples/packages/example-license-see-license-in/package.json +++ b/examples/packages/example-license-see-license-in/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package whose license points to a file, for the license-kit integration tests", "license": "SEE LICENSE IN LICENSE.md", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/examples/packages/example-license-unlicensed/package.json b/examples/packages/example-license-unlicensed/package.json index eccfe506..0cfc749d 100644 --- a/examples/packages/example-license-unlicensed/package.json +++ b/examples/packages/example-license-unlicensed/package.json @@ -3,5 +3,6 @@ "version": "1.0.0", "description": "Test package with no license grant, for the license-kit integration tests", "license": "UNLICENSED", - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "private": true } diff --git a/lefthook.yml b/lefthook.yml index 18996ad8..028b28e7 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,6 +1,10 @@ pre-push: piped: true commands: + lint-release: + files: git diff --name-only --cached origin/main + glob: '*/package.json' + run: yarn lint:release lint-js: # Run ESLint for root ESLint config JS/TS files if any of them are staged files: git diff --name-only --cached origin/main diff --git a/package.json b/package.json index b7508af4..c0e56299 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "scripts": { "build:library": "yarn workspace @callstack/licenses build && yarn workspace react-native-legal build-plugins && yarn workspace license-kit build-library && yarn workspace react-native-legal build-library", "build:visualizer": "yarn workspace @callstack/license-kit-visualizer build", + "lint:release": "./scripts/lint-public-workspace-packages.js -p 'react-native-legal' -p 'license-kit' -p '@callstack/licenses' -i '**/node_modules/**' -i '**/dist/**' -i '**/lib/**' -i '**/visualizer-build/**'", "lint:js": "eslint \"**/*.{js,ts,tsx}\"", "lint:docs": "yarn workspace docs check", "typescript": "yarn build:library && tsc --noEmit -p examples/bare-example/tsconfig.json && tsc --noEmit -p examples/bare-metro-graph-example/tsconfig.json && tsc --noEmit -p examples/expo-example/tsconfig.json && tsc --noEmit -p examples/expo-metro-graph-example/tsconfig.json", diff --git a/packages/visualizer/tsconfig.json b/packages/visualizer/tsconfig.json index 73832f2e..06e45c64 100644 --- a/packages/visualizer/tsconfig.json +++ b/packages/visualizer/tsconfig.json @@ -37,7 +37,8 @@ "next-env.d.ts", "../license-kit/visualizer-build/types/**/*.ts", "../license-kit/visualizer-build/dev/types/**/*.ts", - ".next/dev/types/**/*.ts" + ".next/dev/types/**/*.ts", + "../license-kit/visualizer-build/dev/dev/types/**/*.ts" ], "exclude": [ "node_modules" diff --git a/scripts/lint-public-workspace-packages.js b/scripts/lint-public-workspace-packages.js new file mode 100755 index 00000000..0777526e --- /dev/null +++ b/scripts/lint-public-workspace-packages.js @@ -0,0 +1,51 @@ +#!/usr/bin/env node +/* eslint-disable import/no-extraneous-dependencies */ +const fs = require('fs'); +const path = require('path'); +const { parseArgs, styleText } = require('util'); + +const { globSync } = require('glob'); + +const options = { + publicPackages: { + type: 'string', + multiple: true, + short: 'p', + }, + ignored: { + type: 'string', + multiple: true, + short: 'i', + }, +}; + +const { values } = parseArgs({ args: process.argv.slice(2), options }); + +const paths = globSync('**/package.json', { + cwd: path.resolve(process.cwd()), + ignore: values.ignored, +}); + +const errorPaths = []; + +for (const packageJsonPath of paths) { + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' })); + + if (!values.publicPackages.includes(packageJson.name) && packageJson.private !== true) { + errorPaths.push(packageJsonPath); + } +} + +if (errorPaths.length > 0) { + const listOfErrorPathsStr = errorPaths.reduce((acc, curr) => { + acc += styleText('red', ` - ${curr}\n`); + return acc; + }, ''); + + console.error(styleText('redBright', 'There are public workspaces packages that should not be public!!!')); + console.error(`\n${listOfErrorPathsStr}`); + process.exit(1); +} else { + console.log(styleText('green', 'Public packages surface is correct')); + process.exit(0); +}