diff --git a/.changeset/good-stingrays-bow.md b/.changeset/good-stingrays-bow.md new file mode 100644 index 000000000..1148dfe3f --- /dev/null +++ b/.changeset/good-stingrays-bow.md @@ -0,0 +1,35 @@ +--- +"@khanacademy/wonder-blocks-progress-spinner": patch +"@khanacademy/wonder-blocks-birthday-picker": patch +"@khanacademy/wonder-blocks-labeled-field": patch +"@khanacademy/wonder-blocks-search-field": patch +"@khanacademy/wonder-blocks-testing-core": patch +"@khanacademy/wonder-blocks-breadcrumbs": patch +"@khanacademy/wonder-blocks-icon-button": patch +"@khanacademy/wonder-blocks-typography": patch +"@khanacademy/wonder-blocks-accordion": patch +"@khanacademy/wonder-blocks-clickable": patch +"@khanacademy/wonder-blocks-dropdown": patch +"@khanacademy/wonder-blocks-popover": patch +"@khanacademy/wonder-blocks-testing": patch +"@khanacademy/wonder-blocks-theming": patch +"@khanacademy/wonder-blocks-toolbar": patch +"@khanacademy/wonder-blocks-tooltip": patch +"@khanacademy/wonder-blocks-banner": patch +"@khanacademy/wonder-blocks-button": patch +"@khanacademy/wonder-blocks-layout": patch +"@khanacademy/wonder-blocks-switch": patch +"@khanacademy/wonder-blocks-timing": patch +"@khanacademy/wonder-blocks-tokens": patch +"@khanacademy/wonder-blocks-modal": patch +"@khanacademy/wonder-blocks-cell": patch +"@khanacademy/wonder-blocks-core": patch +"@khanacademy/wonder-blocks-data": patch +"@khanacademy/wonder-blocks-form": patch +"@khanacademy/wonder-blocks-grid": patch +"@khanacademy/wonder-blocks-icon": patch +"@khanacademy/wonder-blocks-link": patch +"@khanacademy/wonder-blocks-pill": patch +--- + +No functional changes. Adding prepublishOnly script. diff --git a/.changeset/perfect-pens-pay.md b/.changeset/perfect-pens-pay.md new file mode 100644 index 000000000..a845151cc --- /dev/null +++ b/.changeset/perfect-pens-pay.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/.github/workflows/node-ci-lint.yml b/.github/workflows/node-ci-lint.yml index 71bcb5978..bd536032f 100644 --- a/.github/workflows/node-ci-lint.yml +++ b/.github/workflows/node-ci-lint.yml @@ -73,4 +73,4 @@ jobs: run: yarn build:types - name: Check package.json files - run: node utils/publish/pre-publish-check-ci.js + run: ./utils/publish/pre-publish-check-ci.ts diff --git a/.github/workflows/node-ci-pr.yml b/.github/workflows/node-ci-pr.yml index da64659d5..8c81b1b00 100644 --- a/.github/workflows/node-ci-pr.yml +++ b/.github/workflows/node-ci-pr.yml @@ -43,6 +43,11 @@ jobs: with: fetch-depth: 0 + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: Get changed files uses: Khan/actions@get-changed-files-v2 id: changed diff --git a/package.json b/package.json index eed2daec7..6e40b2d87 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lint:watch": "esw --watch --config ./eslint/eslintrc packages", "lint": "yarn lint:ci .", "lint:ci": "eslint --ext .ts --ext .js --ext .tsx --ext .jsx", - "publish:ci": "yarn run lint:pkg-json && node utils/publish/pre-publish-check-ci.js && git diff --stat --exit-code HEAD && yarn build && yarn build:types && changeset publish", + "publish:ci": "yarn run lint:pkg-json && ./utils/publish/pre-publish-check-ci.ts && git diff --stat --exit-code HEAD && yarn build && yarn build:types && changeset publish", "start": "yarn start:storybook", "start:storybook": "storybook dev -p 6061", "test:common": "yarn run build && yarn run lint && yarn run typecheck && yarn run alex", @@ -81,6 +81,7 @@ "@typescript-eslint/eslint-plugin": "^5.59.5", "@typescript-eslint/parser": "^5.59.5", "alex": "^11.0.0", + "ancesdir": "^6.0.0", "babel-jest": "^29.7.0", "babel-loader": "^8.2.3", "babel-plugin-dynamic-import-node": "^2.3.3", @@ -149,4 +150,4 @@ "strip-ansi": "6.0.1", "strip-ansi-explanation": "There's an issue with strip-ansi v7 which causes conflicts with the Khan/changeset-per-package action" } -} +} \ No newline at end of file diff --git a/packages/wonder-blocks-accordion/package.json b/packages/wonder-blocks-accordion/package.json index f04c95c80..4b9eabb22 100644 --- a/packages/wonder-blocks-accordion/package.json +++ b/packages/wonder-blocks-accordion/package.json @@ -7,7 +7,8 @@ "module": "dist/es/index.js", "source": "src/index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "types": "dist/index.d.ts", "author": "", diff --git a/packages/wonder-blocks-banner/package.json b/packages/wonder-blocks-banner/package.json index eb7513705..0b65a7f3b 100644 --- a/packages/wonder-blocks-banner/package.json +++ b/packages/wonder-blocks-banner/package.json @@ -7,7 +7,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-birthday-picker/package.json b/packages/wonder-blocks-birthday-picker/package.json index 8d9a42e28..8a126067d 100644 --- a/packages/wonder-blocks-birthday-picker/package.json +++ b/packages/wonder-blocks-birthday-picker/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "dependencies": { "@babel/runtime": "^7.18.6", diff --git a/packages/wonder-blocks-breadcrumbs/package.json b/packages/wonder-blocks-breadcrumbs/package.json index 114f9b5e0..8da185c6c 100644 --- a/packages/wonder-blocks-breadcrumbs/package.json +++ b/packages/wonder-blocks-breadcrumbs/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-button/package.json b/packages/wonder-blocks-button/package.json index 42965d46b..805554ef5 100644 --- a/packages/wonder-blocks-button/package.json +++ b/packages/wonder-blocks-button/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-cell/package.json b/packages/wonder-blocks-cell/package.json index cb8a78fa2..0f29d9c5c 100644 --- a/packages/wonder-blocks-cell/package.json +++ b/packages/wonder-blocks-cell/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "dependencies": { "@babel/runtime": "^7.18.6", diff --git a/packages/wonder-blocks-clickable/package.json b/packages/wonder-blocks-clickable/package.json index 39f05374a..fa9352131 100644 --- a/packages/wonder-blocks-clickable/package.json +++ b/packages/wonder-blocks-clickable/package.json @@ -7,7 +7,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-core/package.json b/packages/wonder-blocks-core/package.json index 793528576..5c995e05c 100644 --- a/packages/wonder-blocks-core/package.json +++ b/packages/wonder-blocks-core/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "dependencies": { "@babel/runtime": "^7.18.6" diff --git a/packages/wonder-blocks-data/package.json b/packages/wonder-blocks-data/package.json index f20be709c..539e3a7c9 100644 --- a/packages/wonder-blocks-data/package.json +++ b/packages/wonder-blocks-data/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "dependencies": { "@babel/runtime": "^7.18.6", diff --git a/packages/wonder-blocks-dropdown/package.json b/packages/wonder-blocks-dropdown/package.json index fad82af8e..563762d68 100644 --- a/packages/wonder-blocks-dropdown/package.json +++ b/packages/wonder-blocks-dropdown/package.json @@ -7,7 +7,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-form/package.json b/packages/wonder-blocks-form/package.json index ceabe7744..24b733308 100644 --- a/packages/wonder-blocks-form/package.json +++ b/packages/wonder-blocks-form/package.json @@ -7,7 +7,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-grid/package.json b/packages/wonder-blocks-grid/package.json index 8a0bffc3b..4c87b500a 100644 --- a/packages/wonder-blocks-grid/package.json +++ b/packages/wonder-blocks-grid/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-icon-button/package.json b/packages/wonder-blocks-icon-button/package.json index faab4ecd6..b1f61b447 100644 --- a/packages/wonder-blocks-icon-button/package.json +++ b/packages/wonder-blocks-icon-button/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-icon/package.json b/packages/wonder-blocks-icon/package.json index 420891fe4..4c6045cea 100644 --- a/packages/wonder-blocks-icon/package.json +++ b/packages/wonder-blocks-icon/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-labeled-field/package.json b/packages/wonder-blocks-labeled-field/package.json index 5b4cac252..99a6c4f96 100644 --- a/packages/wonder-blocks-labeled-field/package.json +++ b/packages/wonder-blocks-labeled-field/package.json @@ -7,7 +7,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-layout/package.json b/packages/wonder-blocks-layout/package.json index a13765a30..4648c3362 100644 --- a/packages/wonder-blocks-layout/package.json +++ b/packages/wonder-blocks-layout/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "dependencies": { "@babel/runtime": "^7.18.6", diff --git a/packages/wonder-blocks-link/package.json b/packages/wonder-blocks-link/package.json index 5dd1c0abc..790eb4a8e 100644 --- a/packages/wonder-blocks-link/package.json +++ b/packages/wonder-blocks-link/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-modal/package.json b/packages/wonder-blocks-modal/package.json index 3dceb0630..f29a542b1 100644 --- a/packages/wonder-blocks-modal/package.json +++ b/packages/wonder-blocks-modal/package.json @@ -10,7 +10,8 @@ "types": "dist/index.d.ts", "module": "dist/es/index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-pill/package.json b/packages/wonder-blocks-pill/package.json index 2e0b080f6..86b8b8b1c 100644 --- a/packages/wonder-blocks-pill/package.json +++ b/packages/wonder-blocks-pill/package.json @@ -8,7 +8,8 @@ "types": "dist/index.d.ts", "source": "src/index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-popover/package.json b/packages/wonder-blocks-popover/package.json index b85463019..d21a1a104 100644 --- a/packages/wonder-blocks-popover/package.json +++ b/packages/wonder-blocks-popover/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-progress-spinner/package.json b/packages/wonder-blocks-progress-spinner/package.json index 7955baa86..7fc88aca9 100644 --- a/packages/wonder-blocks-progress-spinner/package.json +++ b/packages/wonder-blocks-progress-spinner/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-search-field/package.json b/packages/wonder-blocks-search-field/package.json index ea4c07c90..ba440f4e5 100644 --- a/packages/wonder-blocks-search-field/package.json +++ b/packages/wonder-blocks-search-field/package.json @@ -7,7 +7,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-switch/package.json b/packages/wonder-blocks-switch/package.json index 65abd5ca3..e911bdf11 100644 --- a/packages/wonder-blocks-switch/package.json +++ b/packages/wonder-blocks-switch/package.json @@ -7,7 +7,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-testing-core/package.json b/packages/wonder-blocks-testing-core/package.json index ee44eb8d1..747bfefa7 100644 --- a/packages/wonder-blocks-testing-core/package.json +++ b/packages/wonder-blocks-testing-core/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "dependencies": { "@babel/runtime": "^7.18.6" diff --git a/packages/wonder-blocks-testing/package.json b/packages/wonder-blocks-testing/package.json index dcba560c5..cd79bfb0a 100644 --- a/packages/wonder-blocks-testing/package.json +++ b/packages/wonder-blocks-testing/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "dependencies": { "@babel/runtime": "^7.18.6", diff --git a/packages/wonder-blocks-theming/package.json b/packages/wonder-blocks-theming/package.json index 789a6a633..da53e7ede 100644 --- a/packages/wonder-blocks-theming/package.json +++ b/packages/wonder-blocks-theming/package.json @@ -9,7 +9,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "dependencies": {}, "peerDependencies": { diff --git a/packages/wonder-blocks-timing/package.json b/packages/wonder-blocks-timing/package.json index 843b92df4..71d5f1750 100644 --- a/packages/wonder-blocks-timing/package.json +++ b/packages/wonder-blocks-timing/package.json @@ -11,7 +11,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "peerDependencies": { "react": "18.2.0" diff --git a/packages/wonder-blocks-tokens/package.json b/packages/wonder-blocks-tokens/package.json index d47b26100..e4df9a7b3 100644 --- a/packages/wonder-blocks-tokens/package.json +++ b/packages/wonder-blocks-tokens/package.json @@ -6,7 +6,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-toolbar/package.json b/packages/wonder-blocks-toolbar/package.json index 54d00721d..123461e04 100644 --- a/packages/wonder-blocks-toolbar/package.json +++ b/packages/wonder-blocks-toolbar/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-tooltip/package.json b/packages/wonder-blocks-tooltip/package.json index c1804f7e1..b1f9c3885 100644 --- a/packages/wonder-blocks-tooltip/package.json +++ b/packages/wonder-blocks-tooltip/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/packages/wonder-blocks-typography/package.json b/packages/wonder-blocks-typography/package.json index 1c9a3f7a8..fb2ac3dad 100644 --- a/packages/wonder-blocks-typography/package.json +++ b/packages/wonder-blocks-typography/package.json @@ -10,7 +10,8 @@ "module": "dist/es/index.js", "types": "dist/index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "../../utils/publish/package-pre-publish-check.sh" }, "author": "", "license": "MIT", diff --git a/utils/publish/package-pre-publish-check.sh b/utils/publish/package-pre-publish-check.sh new file mode 100755 index 000000000..3dab0ddde --- /dev/null +++ b/utils/publish/package-pre-publish-check.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Check if SNAPSHOT_RELEASE is set and the version does not start with 0.0.0-PR +if [ "$SNAPSHOT_RELEASE" = "1" ] && ! [[ "$npm_package_version" =~ ^0\.0\.0-PR ]]; then + echo "Error: Snapshot publish attempted, but $npm_package_name@$npm_package_version does not match version scheme for snapshots. Publish disallowed." + exit 1 +fi diff --git a/utils/publish/pre-publish-check-ci.js b/utils/publish/pre-publish-check-ci.js deleted file mode 100644 index 866e5a6e6..000000000 --- a/utils/publish/pre-publish-check-ci.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint-disable - @typescript-eslint/no-var-requires, - import/no-commonjs, - no-console -*/ -/** - * Pre-publish checks to verify that our CI publish will go smoothly. - * - * NOTE: This script is run by changesets when the Release Manager is publishing - * a new version of the WB packages. - */ -const path = require("path"); -const fglob = require("fast-glob"); - -const { - checkPublishConfig, - checkPackageMain, - checkPackageModule, - checkPackageTypes, -} = require("./pre-publish-utils"); - -fglob(path.join(__dirname, "..", "..", "packages", "*", "package.json")) - .then((pkgPaths) => { - for (const pkgPath of pkgPaths) { - const pkgJson = require(path.relative(__dirname, pkgPath)); - - checkPublishConfig(pkgJson); - checkPackageMain(pkgJson); - checkPackageModule(pkgJson); - checkPackageTypes(pkgJson); - } - return; - }) - .catch((err) => { - console.error(err); - process.exit(1); - }); diff --git a/utils/publish/pre-publish-check-ci.ts b/utils/publish/pre-publish-check-ci.ts new file mode 100755 index 000000000..50548fced --- /dev/null +++ b/utils/publish/pre-publish-check-ci.ts @@ -0,0 +1,49 @@ +#!/usr/bin/env -S node -r @swc-node/register + +/** + * Pre-publish checks to verify that our publish will go smoothly. + * + * NOTE: This script is run by changesets when the Release Manager is publishing + * a new version of the WB packages. + */ +import path from "path"; + +import ancesdir from "ancesdir"; +import fg from "fast-glob"; + +import { + checkPrivate, + checkEntrypoints, + checkSource, + checkTypes, + checkPublishConfig, +} from "./pre-publish-utils"; + +// Get the root folder; use the LICENSE file as our root anchor. +const rootDir = ancesdir(__dirname, "LICENSE"); + +// eslint-disable-next-line promise/catch-or-return +fg(path.join(rootDir, "packages", "*", "package.json")).then((pkgPaths) => { + let allPassed = true; + // eslint-disable-next-line promise/always-return + for (const pkgPath of pkgPaths) { + // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires + const pkgJson = require(path.relative(__dirname, pkgPath)); + + if ( + !checkPrivate(pkgJson) && + !checkPublishConfig(pkgJson) && + !checkEntrypoints(pkgJson) && + !checkSource(pkgJson) && + !checkTypes(pkgJson) + ) { + allPassed = false; + } + } + + // Exit only after we've processed all the packages. + // eslint-disable-next-line promise/always-return + if (!allPassed) { + process.exit(1); + } +}); diff --git a/utils/publish/pre-publish-utils.js b/utils/publish/pre-publish-utils.js deleted file mode 100644 index ae3657399..000000000 --- a/utils/publish/pre-publish-utils.js +++ /dev/null @@ -1,63 +0,0 @@ -/* eslint-disable import/no-commonjs */ -/* eslint-disable no-console */ -/** - * Pre-publish utilities to verify that our publish will go smoothly. - */ - -const checkPublishConfig = ({name, publishConfig, private: isPrivate}) => { - // first check if is marked as public and there's access to publish the current package - if (!publishConfig || (!isPrivate && publishConfig.access !== "public")) { - const requiredAccessType = isPrivate ? "restricted" : "public"; - - console.error( - `ERROR: ${name} is missing a "publishConfig": {"access": "${requiredAccessType}"} section.`, - ); - process.exit(1); - } - - // also check if is marked as private and there's restricted access defined - if (isPrivate && publishConfig.access !== "restricted") { - console.error( - `ERROR: ${name} is marked as private but there is a "publishConfig": {"access": "public"} section already defined. Please change it to "access": "restricted" or remove "private": true to make the package public.`, - ); - process.exit(1); - } -}; - -const checkPackageField = (pkgJson, field, value) => { - if (pkgJson[field] !== value) { - console.error( - `ERROR: ${ - pkgJson.name - } must have a "${field}" set to ${JSON.stringify(value)}.`, - ); - process.exit(1); - } -}; - -const checkPackageMain = (pkgJson) => - checkPackageField(pkgJson, "main", "dist/index.js"); - -const checkPackageModule = (pkgJson) => - checkPackageField(pkgJson, "module", "dist/es/index.js"); - -const checkPackageTypes = (pkgJson) => - checkPackageField(pkgJson, "types", "dist/index.d.ts"); - -const checkPackagePrivate = (pkgJson) => { - if (pkgJson.private) { - console.warn( - `${pkgJson.name} is private and won't be published to NPM.`, - ); - return true; - } - return false; -}; - -module.exports = { - checkPublishConfig, - checkPackageMain, - checkPackageModule, - checkPackageTypes, - checkPackagePrivate, -}; diff --git a/utils/publish/pre-publish-utils.ts b/utils/publish/pre-publish-utils.ts new file mode 100644 index 000000000..a172bd755 --- /dev/null +++ b/utils/publish/pre-publish-utils.ts @@ -0,0 +1,107 @@ +/* eslint-disable no-console */ +type PackageJson = any; + +/** + * Pre-publish utilities to verify that our publish will go smoothly. + */ +const checkPublishConfig = ({ + name, + publishConfig, + private: isPrivate, + scripts, +}: PackageJson): boolean => { + let returnCode = true; + + // first check if is marked as public and there's access to publish the current package + if (!publishConfig || (!isPrivate && publishConfig.access !== "public")) { + const requiredAccessType = isPrivate ? "restricted" : "public"; + + console.error( + `ERROR: ${name} is missing a "publishConfig": {"access": "${requiredAccessType}"} section.`, + ); + returnCode = false; + } + + // also check if is marked as private and there's restricted access defined + if (isPrivate && publishConfig.access !== "restricted") { + console.error( + `ERROR: ${name} is marked as private but there is a "publishConfig": {"access": "public"} section already defined. Please change it to "access": "restricted" or remove "private": true to make the package public.`, + ); + returnCode = false; + } + + // check that we are running our pre-publish check for this package + if ( + !scripts.prepublishOnly || + !scripts.prepublishOnly.includes( + "utils/publish/package-pre-publish-check.sh", + ) + ) { + console.error( + `ERROR: ${name} must have a "prepublishOnly" script that runs "utils/publish/package-pre-publish-check.sh".`, + ); + returnCode = false; + } + return returnCode; +}; + +const checkField = ( + pkgJson: PackageJson, + field: string, + value: string | Array, +): boolean => { + let returnCode = true; + if (Array.isArray(value)) { + if (!value.includes(pkgJson[field])) { + console.error( + `ERROR: ${ + pkgJson.name + } must have a "${field}" set to one of ${value + .map((value) => JSON.stringify(value)) + .join(", ")}.`, + ); + returnCode = false; + } + } else if (pkgJson[field] !== value) { + console.error( + `ERROR: ${ + pkgJson.name + } must have a "${field}" set to ${JSON.stringify(value)}.`, + ); + returnCode = false; + } + return returnCode; +}; + +const checkMain = (pkgJson: PackageJson): boolean => + checkField(pkgJson, "main", "dist/index.js"); + +const checkModule = (pkgJson: PackageJson): boolean => + checkField(pkgJson, "module", "dist/es/index.js"); + +const checkTypes = (pkgJson: PackageJson): boolean => + checkField(pkgJson, "types", "dist/index.d.ts"); + +const checkSource = (pkgJson: PackageJson): boolean => + checkField(pkgJson, "source", ["src/index.js", "src/index.ts"]); + +const checkPrivate = (pkgJson: PackageJson): boolean => { + if (pkgJson.private) { + console.warn( + `${pkgJson.name} is private and won't be published to NPM.`, + ); + return true; + } + return false; +}; + +const checkEntrypoints = (pkgJson: PackageJson): boolean => + checkMain(pkgJson) && checkModule(pkgJson); + +export { + checkEntrypoints, + checkPrivate, + checkPublishConfig, + checkSource, + checkTypes, +}; diff --git a/utils/publish/publish-snapshot.sh b/utils/publish/publish-snapshot.sh index 1d9d28e14..302461acf 100755 --- a/utils/publish/publish-snapshot.sh +++ b/utils/publish/publish-snapshot.sh @@ -18,6 +18,15 @@ MYPATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) # ROOT is the root directory of our project. ROOT="$MYPATH/../.." +# This is used in prepublishOnly hooks to verify that the package is correctly +# versioned for a snapshot release before proceeding. +# This is done to catch a race condition where a main release is occurring +# while a snapshot release is requested, avoiding us publishing packages +# that we shouldn't be. +# See https://khanacademy.atlassian.net/wiki/spaces/ENG/pages/3571646568/Race+condition+breaks+Perseus+release +# Need to export this so that the invoked commands see it. +export SNAPSHOT_RELEASE=1 + pushd "$ROOT" verify_env() { @@ -75,7 +84,7 @@ check_for_changes() { } pre_publish_check() { - SWCRC=true node -r @swc-node/register "$ROOT/utils/publish/pre-publish-check-ci.js" + SWCRC=true node -r @swc-node/register "$ROOT/utils/publish/pre-publish-check-ci.ts" if ! git diff --stat --exit-code HEAD; then echo "Git repo is dirty. This is unexpected when running in CI." diff --git a/yarn.lock b/yarn.lock index 24b1a332f..ff5273ad9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4944,6 +4944,11 @@ alex@^11.0.0: vfile-reporter "^7.0.0" vfile-sort "^3.0.0" +ancesdir@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/ancesdir/-/ancesdir-6.0.0.tgz#1b39feeb65e7ee23a563fb036e2588383f47ed6b" + integrity sha512-WTgCOi7D15lDHIijVh/NZnC4nRu3Ay2NZ1SkfsRKexj6Cd20zsFDW1kYfHMa42kJvHMO3103aVg7mMFd58uiWA== + ansi-align@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-3.0.1.tgz#0cdf12e111ace773a86e9a1fad1225c43cb19a59"