Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish-codemod-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
if: steps.resolve.outputs.registry_entry == 'cornerstone3d/5'
run: |
TARGET="$(mktemp -d)"
npx codemod run cornerstone3d/5/generic-viewport --dry-run -t "$TARGET" --allow-dirty --no-interactive
npx codemod run @cornerstonejs/cornerstone3d-5-generic-viewport --dry-run -t "$TARGET" --allow-dirty --no-interactive

- name: Publish registry entry
uses: codemod/publish-action@v1
Expand Down
12 changes: 6 additions & 6 deletions packages/codemods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ the Codemod registry so users run them with `npx codemod`.
Run the full Cornerstone3D v5 migration:

```sh
npx codemod cornerstone3d/5
npx codemod @cornerstonejs/cornerstone3d-5
```

Run only the Generic Viewport migration:

```sh
npx codemod cornerstone3d/5/generic-viewport
npx codemod @cornerstonejs/cornerstone3d-5-generic-viewport
```

## Registry Packages

This workspace currently includes:

- `cornerstone3d/5`: runs all available Cornerstone3D v5 migration packages in
the recommended order.
- `cornerstone3d/5/generic-viewport`: migrates removed RenderingEngine viewport
accessor APIs.
- `@cornerstonejs/cornerstone3d-5`: runs all available Cornerstone3D v5
migration packages in the recommended order.
- `@cornerstonejs/cornerstone3d-5-generic-viewport`: migrates removed
RenderingEngine viewport accessor APIs.

The Generic Viewport migration changes:

Expand Down
4 changes: 3 additions & 1 deletion packages/codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"name": "@cornerstonejs/codemods",
"version": "5.0.1",
"description": "Codemod registry packages for Cornerstone3D migrations",
"private": true,
"keywords": [
"cornerstone3d",
"codemod",
"migration"
],
"publishConfig": {
"access": "public"
},
Comment on lines +10 to +12

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Align npm visibility docs with the new public publish config.

Line 10 switches this package to public publish behavior, but the registry publishing docs currently state the package is intentionally private to npm (packages/codemods/README.md, Lines 68-69). Please update that text to avoid release-process confusion.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/codemods/package.json` around lines 10 - 12, The README currently
states this package is intentionally private but package.json now sets
"publishConfig": {"access":"public"}, so update the codemods README text that
mentions npm visibility to reflect the package is published publicly; locate the
README section that says the package is intentionally private and change the
wording to indicate it is published to the public npm registry (or remove the
private reference), and ensure the messaging aligns with the "publishConfig"
entry in package.json so release docs are consistent.

"repository": "https://github.com/cornerstonejs/cornerstone3D",
"sideEffects": false,
"scripts": {
Expand Down
13 changes: 7 additions & 6 deletions packages/codemods/registry/cornerstone3d/5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ order.
## Usage

```sh
npx codemod cornerstone3d/5
npx codemod @cornerstonejs/cornerstone3d-5
```

To preview changes before writing files:

```sh
npx codemod cornerstone3d/5 --dry-run
npx codemod @cornerstonejs/cornerstone3d-5 --dry-run
```

## Included Migrations

- `cornerstone3d/5/generic-viewport`: replaces removed RenderingEngine viewport
accessor APIs with Cornerstone3D v5 compatible viewport APIs.
- `@cornerstonejs/cornerstone3d-5-generic-viewport`: replaces removed
RenderingEngine viewport accessor APIs with Cornerstone3D v5 compatible
viewport APIs.

## Publishing

Publish child migration packages before publishing this aggregate package. The
workflow resolves `cornerstone3d/5/generic-viewport` from the Codemod registry at
runtime.
workflow resolves `@cornerstonejs/cornerstone3d-5-generic-viewport` from the
Codemod registry at runtime.
2 changes: 1 addition & 1 deletion packages/codemods/registry/cornerstone3d/5/codemod.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
schema_version: '1.0'
name: 'cornerstone3d/5'
name: '@cornerstonejs/cornerstone3d-5'
version: '0.1.0'
description: 'Apply all available Cornerstone3D v5 migration transforms in the recommended order.'
author: 'Cornerstone.js Contributors'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ compatible viewport APIs.
## Usage

```sh
npx codemod cornerstone3d/5/generic-viewport
npx codemod @cornerstonejs/cornerstone3d-5-generic-viewport
```

To preview changes before writing files:

```sh
npx codemod cornerstone3d/5/generic-viewport --dry-run
npx codemod @cornerstonejs/cornerstone3d-5-generic-viewport --dry-run
```

## Changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
schema_version: '1.0'
name: 'cornerstone3d/5/generic-viewport'
name: '@cornerstonejs/cornerstone3d-5-generic-viewport'
version: '0.1.0'
description: 'Replace removed RenderingEngine viewport accessors with Cornerstone3D v5 compatible viewport APIs.'
author: 'Cornerstone.js Contributors'
Expand Down
2 changes: 1 addition & 1 deletion packages/codemods/registry/cornerstone3d/5/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ nodes:
steps:
- name: Apply RenderingEngine viewport accessor transform
codemod:
source: cornerstone3d/5/generic-viewport
source: '@cornerstonejs/cornerstone3d-5-generic-viewport'
3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
"types": "./dist/esm/version.d.ts"
}
},
"publishConfig": {
"access": "public"
},
"scripts": {
"prebuild": "node ../../scripts/generate-version.js ./",
"build:esm": "pnpm run prebuild && tsc --project ./tsconfig.json",
Expand Down
6 changes: 3 additions & 3 deletions packages/docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ module.exports = {
],
},
{
to: '/docs/migration-guides/4x',
label: '4.0 Migration Guides',
to: '/docs/migration-guides/5x',
label: '5.0 Migration Guides',
position: 'left',
className: 'new-badge',
},
Expand Down Expand Up @@ -223,7 +223,7 @@ module.exports = {
onlyIncludeVersions: ['current'],
versions: {
current: {
label: `4.0 (Latest)`,
label: `5.0 (Latest)`,
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions packages/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
"types": "./dist/esm/version.d.ts"
}
},
"publishConfig": {
"access": "public"
},
"scripts": {
"prebuild": "node ../../scripts/generate-version.js ./",
"build:esm": "pnpm run prebuild && tsc --project ./tsconfig.json",
Expand Down
59 changes: 57 additions & 2 deletions publish-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ async function run() {

// Run lerna version without pushing
// lerna will update package.json files and create a commit
//
// NOTE: --create-release github is intentionally NOT passed here. lerna only
// creates the GitHub release when it pushes the tag itself, and we run with
// --no-push (so the version bump + generated files land as a single amended
// commit). The GitHub release is created explicitly after the tag is pushed,
// below.
await execa('npx', [
'lerna',
'version',
Expand All @@ -129,8 +135,6 @@ async function run() {
'--message',
`chore(version): Update package versions to ${nextVersion} [skip ci]`,
'--conventional-commits',
'--create-release',
'github',
'--no-push',
// The repo enforces frozenLockfile via pnpm-workspace.yaml, but lerna must
// update the lockfile after bumping versions. Relax it for this one install.
Expand Down Expand Up @@ -170,9 +174,60 @@ async function run() {
console.log('Pushing tag...');
await execa('git', ['push', 'origin', tagName]);

// Create the GitHub release for the tag we just pushed.
//
// Historically `lerna version --create-release github` created this release,
// authenticating with the GH_TOKEN environment variable. When lerna switched
// to --no-push (to land the version bump as a single amended commit) it stopped
// creating releases, because lerna only creates a release when it pushes the
// tag itself. As a result npm kept publishing while GitHub Releases froze.
//
// We now create the release explicitly via the gh CLI, after pushing the tag,
// reusing the same GH_TOKEN. This is best-effort: a missing token or a CLI
// error logs a warning but never fails the build/release (the npm publish step
// is separate).
await createGithubRelease(tagName, nextVersion.trim());

console.log('Version set using lerna');
}

// Best-effort GitHub release creation for an already-pushed tag. Never throws;
// any failure is logged as a warning so it cannot fail the release.
async function createGithubRelease(tagName, version) {
const ghToken = process.env.GH_TOKEN || process.env.GITHUB_TOKEN;

if (!ghToken) {
console.warn(
`GH_TOKEN/GITHUB_TOKEN not set - skipping GitHub release creation for ${tagName}. ` +
'Set GH_TOKEN in the CircleCI project/context environment to enable releases.'
);
return;
}

// gh reads GH_TOKEN/GITHUB_TOKEN from the environment and infers the repo from
// the origin remote. --verify-tag ensures the tag we just pushed exists before
// creating the release.
try {
await execa('gh', [
'release',
'create',
tagName,
'--title',
tagName,
'--generate-notes',
'--verify-tag',
...(version.includes('-') ? ['--prerelease'] : []),
]);
console.log(`Created GitHub release ${tagName}`);
} catch (err) {
console.warn(
`GitHub release creation for ${tagName} failed (non-fatal): ${
err.shortMessage || err.message
}`
);
}
Comment thread
wayfarer3130 marked this conversation as resolved.
}

async function unlinkFile(filePath) {
try {
await fs.access(filePath);
Expand Down
39 changes: 27 additions & 12 deletions scripts/generate-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,34 @@ if (!packagePath) {
process.exit(1);
}

// Get the root directory (two levels up from scripts/)
const rootDir = path.resolve(__dirname, '..');
// Only stamp version.ts for packages that are actually published. Published
// packages set publishConfig.access to 'public'; anything else (e.g. the private
// docs site) is skipped rather than failing the release.
const packageJsonPath = path.join(packagePath, 'package.json');
let packageJson;
try {
packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
} catch (error) {
console.log(`Skipping ${packagePath}: could not read package.json`);
process.exit(0);
}
Comment thread
wayfarer3130 marked this conversation as resolved.

// Read the version.json file from the root directory
if (packageJson.publishConfig?.access !== 'public') {
console.log(`Skipping ${packagePath}: publishConfig.access is not 'public'`);
process.exit(0);
}

// A published package may still have no src directory (e.g. the codemods
// registry package). There is nowhere to stamp version.ts, so skip rather than
// fail the release.
const srcDir = path.join(packagePath, 'src');
if (!fs.existsSync(srcDir)) {
console.log(`Skipping ${packagePath}: no src directory`);
process.exit(0);
}

// Read the version.json file from the root directory (two levels up from scripts/)
const rootDir = path.resolve(__dirname, '..');
const versionJsonPath = path.join(rootDir, 'version.json');
let versionData;

Expand All @@ -33,15 +57,6 @@ const versionContent = `/**
*/
export const version = '${versionData.version}';\n`;

// Determine the src directory
const srcDir = path.join(packagePath, 'src');
if (!fs.existsSync(srcDir)) {
// Packages without a src directory (e.g. private codemods, the docs site)
// have nowhere to stamp version.ts. Skip rather than fail the release.
console.log(`Skipping ${packagePath}: no src directory`);
process.exit(0);
}

// Write the version.ts file
const versionFilePath = path.join(srcDir, 'version.ts');
try {
Expand Down
Loading