diff --git a/common/CHANGELOG.md b/common/CHANGELOG.md index eb8ca3a..4b96f5a 100644 --- a/common/CHANGELOG.md +++ b/common/CHANGELOG.md @@ -1,5 +1,11 @@ # @simple-photo-gallery/common +## 2.2.1 + +### Patch Changes + +- Fix bundled theme resolution when the CLI is invoked through a global npm binary symlink. + ## 2.2.0 ### Minor Changes diff --git a/common/package.json b/common/package.json index 7627021..c686bc3 100644 --- a/common/package.json +++ b/common/package.json @@ -1,6 +1,6 @@ { "name": "@simple-photo-gallery/common", - "version": "2.2.0", + "version": "2.2.1", "description": "Shared utilities and types for Simple Photo Gallery", "license": "MIT", "author": "Vladimir Haltakov, Tomasz Rusin", diff --git a/gallery/CHANGELOG.md b/gallery/CHANGELOG.md index d693324..434e7af 100644 --- a/gallery/CHANGELOG.md +++ b/gallery/CHANGELOG.md @@ -1,5 +1,14 @@ # simple-photo-gallery +## 2.2.1 + +### Patch Changes + +- Fix bundled theme resolution when the CLI is invoked through a global npm binary symlink. +- Updated dependencies + - @simple-photo-gallery/common@2.2.1 + - @simple-photo-gallery/theme-modern@2.2.1 + ## 2.2.0 ### Minor Changes diff --git a/gallery/package.json b/gallery/package.json index 9ec21db..8a53f19 100644 --- a/gallery/package.json +++ b/gallery/package.json @@ -1,6 +1,6 @@ { "name": "simple-photo-gallery", - "version": "2.2.0", + "version": "2.2.1", "description": "Simple Photo Gallery CLI", "license": "MIT", "author": "Vladimir Haltakov, Tomasz Rusin", diff --git a/gallery/src/modules/build/index.ts b/gallery/src/modules/build/index.ts index b0ea1cd..06f2054 100644 --- a/gallery/src/modules/build/index.ts +++ b/gallery/src/modules/build/index.ts @@ -438,7 +438,10 @@ function isLocalThemePath(theme: string): boolean { } function resolvePackageJsonPath(packageName: string): string { - const candidates = [path.join(process.cwd(), 'package.json'), process.argv[1]].filter(Boolean) as string[]; + const cliPath = process.argv[1]; + // Global npm bins are symlinks, so also resolve from the installed package's real path. + const installedCliPath = cliPath && fs.existsSync(cliPath) ? fs.realpathSync(cliPath) : undefined; + const candidates = [path.join(process.cwd(), 'package.json'), cliPath, installedCliPath].filter(Boolean) as string[]; for (const candidate of candidates) { try { diff --git a/gallery/tests/cli-e2e.test.ts b/gallery/tests/cli-e2e.test.ts index b3cd772..6c11ea2 100644 --- a/gallery/tests/cli-e2e.test.ts +++ b/gallery/tests/cli-e2e.test.ts @@ -1,5 +1,15 @@ import { execFileSync, spawnSync } from 'node:child_process'; -import { copyFileSync, existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'; +import { + copyFileSync, + existsSync, + mkdirSync, + mkdtempSync, + readFileSync, + readdirSync, + rmSync, + symlinkSync, + writeFileSync, +} from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import process from 'node:process'; @@ -486,4 +496,19 @@ describe('packaged CLI e2e smoke', () => { expect(existsSync(path.join(themeDir, 'src', 'pages', 'index.astro'))).toBe(true); expect(readdirSync(themeDir)).not.toContain('node_modules'); }); + + test('resolves the bundled theme when invoked through a global-style bin symlink', () => { + const installDir = makeTempDir('dist-global-install'); + const binDir = path.join(installDir, 'bin'); + const cliSymlinkPath = path.join(binDir, 'spg'); + const galleryDir = makeTempDir('dist-global-gallery'); + mkdirSync(binDir, { recursive: true }); + symlinkSync(distCliPath, cliSymlinkPath); + copySingleFixture(galleryDir); + + runCommand(process.execPath, [cliSymlinkPath, 'init', '--default'], { cwd: galleryDir }); + runCommand(process.execPath, [cliSymlinkPath, 'build', '--no-scan', '--no-thumbnails'], { cwd: galleryDir }); + + expect(existsSync(path.join(galleryDir, 'index.html'))).toBe(true); + }); }); diff --git a/themes/modern/CHANGELOG.md b/themes/modern/CHANGELOG.md index 39be6db..82c9b65 100644 --- a/themes/modern/CHANGELOG.md +++ b/themes/modern/CHANGELOG.md @@ -1,5 +1,11 @@ # @simple-photo-gallery/theme-modern +## 2.2.1 + +### Patch Changes + +- Fix bundled theme resolution when the CLI is invoked through a global npm binary symlink. + ## 2.2.0 ### Minor Changes diff --git a/themes/modern/package.json b/themes/modern/package.json index fc215ee..1c41126 100644 --- a/themes/modern/package.json +++ b/themes/modern/package.json @@ -1,6 +1,6 @@ { "name": "@simple-photo-gallery/theme-modern", - "version": "2.2.0", + "version": "2.2.1", "description": "Modern theme for Simple Photo Gallery", "license": "MIT", "author": "Vladimir Haltakov, Tomasz Rusin",