From d514bfc15caedf89b077cdd9a361499ba8ed1817 Mon Sep 17 00:00:00 2001 From: Cody Olsen <81981+stipsan@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:14:38 +0100 Subject: [PATCH] refactor: use `PKG_VERSION` from `@sanity/pkg-utils` instead of manually regexing `SANITY_VERSION` (#6078) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: use `PKG_VERSION` from `@sanity/pkg-utils` instead of manually regexing `SANITY_VERSION` * chore(sanity): remove unused script (#6090) --------- Co-authored-by: Bjørge Næss --- packages/sanity/package.json | 5 +- .../sanity/scripts/writeRequiredUIVersion.ts | 65 ------------------- packages/sanity/scripts/writeVersion.ts | 22 ------- .../src/core/requiredSanityUiVersion.ts | 3 - packages/sanity/src/core/version.ts | 8 +-- turbo.json | 4 +- 6 files changed, 5 insertions(+), 102 deletions(-) delete mode 100644 packages/sanity/scripts/writeRequiredUIVersion.ts delete mode 100644 packages/sanity/scripts/writeVersion.ts delete mode 100644 packages/sanity/src/core/requiredSanityUiVersion.ts diff --git a/packages/sanity/package.json b/packages/sanity/package.json index 29b1170ae89..bc2e08e268e 100644 --- a/packages/sanity/package.json +++ b/packages/sanity/package.json @@ -181,13 +181,10 @@ "clean": "rimraf _internal.js cli.js desk.js lib presentation.js router.js", "coverage": "jest --coverage", "lint": "eslint .", - "prepublishOnly": "run-s write:version write:ui-version", "test": "pkg-utils --strict && jest", "test:ct": "playwright test -c playwright-ct.config.ts", "watch": "pkg-utils watch --tsconfig tsconfig.lib.json", - "write:playwright-report-as-pr-comment": "node -r esbuild-register playwright-ct/scripts/parsePlaywrightReportJson.ts", - "write:ui-version": "node -r esbuild-register scripts/writeRequiredUIVersion.ts", - "write:version": "node -r esbuild-register scripts/writeVersion.ts" + "write:playwright-report-as-pr-comment": "node -r esbuild-register playwright-ct/scripts/parsePlaywrightReportJson.ts" }, "dependencies": { "@dnd-kit/core": "^6.0.5", diff --git a/packages/sanity/scripts/writeRequiredUIVersion.ts b/packages/sanity/scripts/writeRequiredUIVersion.ts deleted file mode 100644 index 1dca1466d6a..00000000000 --- a/packages/sanity/scripts/writeRequiredUIVersion.ts +++ /dev/null @@ -1,65 +0,0 @@ -// // This overwrites the compiled ./lib/requiredSanityUiVersion.js with a the -// // actual version we currently depend on in the `sanity` module -// import fs from 'fs/promises' -// import pkg from '../package.json' - -// const template = (version: string) => `exports.REQUIRED_UI_VERSION = '${version}'` - -// let builtFile -// try { -// builtFile = require.resolve('../lib/cjs/requiredSanityUiVersion.js') -// } catch (error) { -// // eslint-disable-next-line no-console -// console.error( -// 'Error: Unable to resolve "requiredSanityUiVersion.js" in ./lib. Please make sure the project has been successfully built.' -// ) -// process.exit(1) -// } - -// let version = pkg.dependencies['@sanity/ui'] - -// if (typeof version === 'string' && version.startsWith('^')) { -// version = version.slice(1) -// } - -// fs.writeFile(builtFile, template(version || 'latest')) - -/* eslint-disable import/no-extraneous-dependencies */ -/* eslint-disable no-console */ -/* eslint-disable no-process-exit */ -/* eslint-disable no-sync */ - -import fs from 'fs' -import globby from 'globby' -import path from 'path' -import semver from 'semver' - -import pkg from '../package.json' - -const rawVersion = pkg.dependencies['@sanity/ui'] -const v = semver.parse( - rawVersion.startsWith('^') || rawVersion.startsWith('~') ? rawVersion.slice(1) : rawVersion, -) - -if (!v) { - console.log(`the version of @sanity/ui is invalid: ${rawVersion}`) - process.exit(1) -} - -const version = `${v.major}.${v.minor}.${v.patch}` - -globby([ - path.resolve(__dirname, '../lib/**/*.js'), - path.resolve(__dirname, '../lib/**/*.mjs'), -]).then((files) => { - for (const file of files) { - const buf = fs.readFileSync(file, 'utf8') - fs.writeFileSync( - file, - buf - .toString() - .replace('REQUIRED_UI_VERSION="0.0.0-development"', `REQUIRED_UI_VERSION="${version}"`), - 'utf8', - ) - } -}) diff --git a/packages/sanity/scripts/writeVersion.ts b/packages/sanity/scripts/writeVersion.ts deleted file mode 100644 index 185ae2088e3..00000000000 --- a/packages/sanity/scripts/writeVersion.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* eslint-disable import/no-extraneous-dependencies */ -/* eslint-disable no-sync */ - -import fs from 'fs' -import globby from 'globby' -import path from 'path' - -import {version} from '../package.json' - -globby([ - path.resolve(__dirname, '../lib/**/*.js'), - path.resolve(__dirname, '../lib/**/*.mjs'), -]).then((files) => { - for (const file of files) { - const buf = fs.readFileSync(file, 'utf8') - fs.writeFileSync( - file, - buf.toString().replace('SANITY_VERSION="0.0.0-development"', `SANITY_VERSION="${version}"`), - 'utf8', - ) - } -}) diff --git a/packages/sanity/src/core/requiredSanityUiVersion.ts b/packages/sanity/src/core/requiredSanityUiVersion.ts deleted file mode 100644 index 6e2c0831597..00000000000 --- a/packages/sanity/src/core/requiredSanityUiVersion.ts +++ /dev/null @@ -1,3 +0,0 @@ -// NOTE: This file is overwritten on prepublish - see `scripts/writeRequiredUIVersion.js` -// The version you see here is only read in monorepo development -export const REQUIRED_UI_VERSION = '0.0.0-development' diff --git a/packages/sanity/src/core/version.ts b/packages/sanity/src/core/version.ts index ab5e77e4250..9f8aa81b747 100644 --- a/packages/sanity/src/core/version.ts +++ b/packages/sanity/src/core/version.ts @@ -1,10 +1,6 @@ /** - * TODO: rename to `VERSION` - * - * + * This version is provided by `@sanity/pkg-utils` at build time * @hidden * @beta */ -// This string is overwritten by prepublish script with `.version` from package.json -// The version you see here is only read in monorepo development -export const SANITY_VERSION = '0.0.0-development' as string +export const SANITY_VERSION = process.env.PKG_VERSION || ('0.0.0-development' as string) diff --git a/turbo.json b/turbo.json index 98012d61249..484e438f2f8 100644 --- a/turbo.json +++ b/turbo.json @@ -1,7 +1,7 @@ { "$schema": "https://turbo.build/schema.json", - // This is probably overkill, this will segment between GH actions and everything else for now. - "globalEnv": ["OS", "RUNNER_OS"], + // All environment variables that should invalidate a cached build needs to be declared here + "globalEnv": ["OS", "RUNNER_OS", "PKG_FILE_PATH", "PKG_FORMAT", "PKG_RUNTIME", "PKG_VERSION"], // These root workspace files are reused in workspaces and may affect their build output "globalDependencies": [ ".babelrc",