From d4d463f210d5a18ddc666042bc719ab1d8dff70b Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Mon, 9 Sep 2024 17:08:07 +0200 Subject: [PATCH] impr: Removing dark-mode only logo in README when preparing package. (#285) --- packages/tgpu-dev-cli/prepack.mjs | 49 ++++++++++++++++++++++++------- packages/typegpu/package.json | 6 ++-- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/packages/tgpu-dev-cli/prepack.mjs b/packages/tgpu-dev-cli/prepack.mjs index 319a60737..fafffef64 100755 --- a/packages/tgpu-dev-cli/prepack.mjs +++ b/packages/tgpu-dev-cli/prepack.mjs @@ -1,3 +1,4 @@ +// @ts-check /* * Used as a pre-publishing step. */ @@ -5,7 +6,7 @@ import { exec } from 'node:child_process'; import * as fs from 'node:fs/promises'; import process from 'node:process'; -import { omitBy } from 'remeda'; +import { entries, mapValues, omitBy } from 'remeda'; import { Frog } from './log.mjs'; const cwd = new URL(`file:${process.cwd()}/`); @@ -62,42 +63,70 @@ function deepMapStrings(value, transform, path = '') { return value; } -async function main() { +async function transformPackageJSON() { const packageJsonUrl = new URL('./package.json', cwd); const distPackageJsonUrl = new URL('./dist/package.json', cwd); const packageJson = JSON.parse(await fs.readFile(packageJsonUrl, 'utf-8')); - await promiseExec( - 'pnpm build && pnpm -w test:spec && pnpm test:types && biome check .', - ); - // Altering paths in the package.json const distPackageJson = deepMapStrings(packageJson, (_path, value) => { if (value.startsWith('./dist/')) { return value.replace(/^\.\/dist/, '.'); } - return value; }); + + // Erroring out on any wildcard dependencies + for (const [moduleKey, versionSpec] of [ + ...entries(distPackageJson.dependencies), + ...entries(distPackageJson.devDependencies), + ]) { + if (versionSpec === '*' || versionSpec === 'workspace:*') { + throw new Error( + `Cannot depend on a module with a wildcard version. (${moduleKey}: ${versionSpec})`, + ); + } + } + distPackageJson.private = false; distPackageJson.scripts = {}; - // Removing any links to other workspace packages. + // Removing any links to other workspace packages in dev dependencies. distPackageJson.devDependencies = omitBy( distPackageJson.devDependencies, (/** @type {string} */ value) => value.startsWith('workspace:'), ); + // Removing workspace specifiers in dependencies. + distPackageJson.dependencies = mapValues( + distPackageJson.dependencies, + (/** @type {string} */ value) => value.replace(/^workspace:/, ''), + ); await fs.writeFile( distPackageJsonUrl, JSON.stringify(distPackageJson, undefined, 2), 'utf-8', ); +} - // Copying over README.md +async function transformReadme() { const readmeUrl = new URL('./README.md', cwd); const distReadmeUrl = new URL('./dist/README.md', cwd); - await fs.copyFile(readmeUrl, distReadmeUrl); + + let readme = await fs.readFile(readmeUrl, 'utf-8'); + + // npmjs.com does not handle multiple logos well, remove the dark mode only one. + readme = readme.replace(/!.*#gh-dark-mode-only\)/, ''); + + await fs.writeFile(distReadmeUrl, readme, 'utf-8'); +} + +async function main() { + await promiseExec( + 'pnpm build && pnpm -w test:spec && pnpm test:types && biome check .', + ); + + await Promise.all([transformPackageJSON(), transformReadme()]); console.log( ` diff --git a/packages/typegpu/package.json b/packages/typegpu/package.json index a2e390e06..bdfe4f331 100644 --- a/packages/typegpu/package.json +++ b/packages/typegpu/package.json @@ -73,9 +73,9 @@ "@webgpu/types": "^0.1.43", "typescript": "^5.3.3", "tsup": "^8.0.2", - "@typegpu/wgsl-parser": "workspace:*", - "typegpu": "workspace:*", - "@typegpu/tgpu-dev-cli": "workspace:*" + "@typegpu/wgsl-parser": "workspace:0.0.0", + "typegpu": "workspace:0.1.0", + "@typegpu/tgpu-dev-cli": "workspace:0.0.0" }, "packageManager": "pnpm@8.15.8+sha256.691fe176eea9a8a80df20e4976f3dfb44a04841ceb885638fe2a26174f81e65e", "dependencies": {