diff --git a/packages/grafana-i18n/package.json b/packages/grafana-i18n/package.json index 365211e2faa..ba8d2311acf 100644 --- a/packages/grafana-i18n/package.json +++ b/packages/grafana-i18n/package.json @@ -28,6 +28,7 @@ "require": "./src/internal/index.ts" }, "./eslint-plugin": { + "types": "./src/eslint/index.d.ts", "import": "./src/eslint/index.cjs", "require": "./src/eslint/index.cjs" } diff --git a/packages/grafana-i18n/src/eslint/index.d.ts b/packages/grafana-i18n/src/eslint/index.d.ts new file mode 100644 index 00000000000..d9ce3ca877c --- /dev/null +++ b/packages/grafana-i18n/src/eslint/index.d.ts @@ -0,0 +1,6 @@ +// Stub type definition for the eslint plugin to pass our package validation. +// Will revisit this when we fix our package building and packaging process. + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +declare const plugin: any; +export = plugin; diff --git a/scripts/prepare-npm-package.js b/scripts/prepare-npm-package.js index 13c0ea08730..054b3d12609 100644 --- a/scripts/prepare-npm-package.js +++ b/scripts/prepare-npm-package.js @@ -34,6 +34,7 @@ try { // Fix for @grafana/i18n so eslint-plugin can be imported by consumers if (pkgJson.content.name === '@grafana/i18n') { exports['./eslint-plugin'] = { + types: './dist/eslint/index.d.ts', import: './dist/eslint/index.cjs', require: './dist/eslint/index.cjs', }; diff --git a/scripts/validate-npm-packages.sh b/scripts/validate-npm-packages.sh index 47b82a49717..92e871b6899 100755 --- a/scripts/validate-npm-packages.sh +++ b/scripts/validate-npm-packages.sh @@ -1,18 +1,43 @@ -#!/bin/bash +#!/usr/bin/env bash +set -e # This script is used to validate the npm packages that are published to npmjs.org are in the correct format. # It won't catch things like malformed JS or Types but it will assert that the package has # the correct files and package.json properties. ARTIFACTS_DIR="./npm-artifacts" +failed_checks=() + for file in "$ARTIFACTS_DIR"/*.tgz; do echo "🔍 Checking NPM package: $file" - # Ignore named-exports for now as builds aren't compatible yet. - yarn attw "$file" --ignore-rules "named-exports" - yarn publint "$file" + # TODO: Fix the error with @grafana/i18n/eslint-resolution + if [[ "$file" == *"@grafana-i18n"* ]]; then + ATTW_FLAGS="--profile node16" + fi + # shellcheck disable=SC2086 + if ! yarn attw "$file" --ignore-rules "false-cjs" $ATTW_FLAGS; then + echo "attw check failed for $file" + echo "" + failed_checks+=("$file - yarn attw") + fi + + if ! yarn publint "$file"; then + echo "publint check failed for $file" + echo "" + failed_checks+=("$file - yarn publint") + fi done +if (( ${#failed_checks[@]} > 0 )); then + echo "" + echo "❌ The following NPM package checks failed:" + for check in "${failed_checks[@]}"; do + echo " - $check" + done + exit 1 +fi + echo "🚀 All NPM package checks passed! 🚀" exit 0