refactor: centralize ensemble manifest filename constant
This commit is contained in:
parent
b6e3c7883d
commit
05865eb04e
@ -27,6 +27,7 @@ import { parseTarVerboseListing } from '../../features/ensemble/tar-parser.js';
|
|||||||
import { resolveRef } from '../../features/ensemble/github-ref-resolver.js';
|
import { resolveRef } from '../../features/ensemble/github-ref-resolver.js';
|
||||||
import { atomicReplace, cleanupResiduals } from '../../features/ensemble/atomic-update.js';
|
import { atomicReplace, cleanupResiduals } from '../../features/ensemble/atomic-update.js';
|
||||||
import { generateLockFile, extractCommitSha } from '../../features/ensemble/lock-file.js';
|
import { generateLockFile, extractCommitSha } from '../../features/ensemble/lock-file.js';
|
||||||
|
import { TAKT_PACKAGE_MANIFEST_FILENAME } from '../../features/ensemble/constants.js';
|
||||||
import { summarizeFacetsByType, detectEditPieces, formatEditPieceWarnings } from '../../features/ensemble/pack-summary.js';
|
import { summarizeFacetsByType, detectEditPieces, formatEditPieceWarnings } from '../../features/ensemble/pack-summary.js';
|
||||||
import { confirm } from '../../shared/prompt/index.js';
|
import { confirm } from '../../shared/prompt/index.js';
|
||||||
import { info, success } from '../../shared/ui/index.js';
|
import { info, success } from '../../shared/ui/index.js';
|
||||||
@ -176,7 +177,7 @@ export async function ensembleAddCommand(spec: string): Promise<void> {
|
|||||||
mkdirSync(dirname(destFile), { recursive: true });
|
mkdirSync(dirname(destFile), { recursive: true });
|
||||||
copyFileSync(target.absolutePath, destFile);
|
copyFileSync(target.absolutePath, destFile);
|
||||||
}
|
}
|
||||||
copyFileSync(packConfigPath, join(packageDir, 'takt-package.yaml'));
|
copyFileSync(packConfigPath, join(packageDir, TAKT_PACKAGE_MANIFEST_FILENAME));
|
||||||
|
|
||||||
const lock = generateLockFile({
|
const lock = generateLockFile({
|
||||||
source: `github:${owner}/${repo}`,
|
source: `github:${owner}/${repo}`,
|
||||||
|
|||||||
6
src/features/ensemble/constants.ts
Normal file
6
src/features/ensemble/constants.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* Shared constants for ensemble package manifest handling.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Manifest filename inside a package repository and installed package directory. */
|
||||||
|
export const TAKT_PACKAGE_MANIFEST_FILENAME = 'takt-package.yaml';
|
||||||
@ -9,6 +9,7 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { parseTaktPackConfig } from './takt-pack-config.js';
|
import { parseTaktPackConfig } from './takt-pack-config.js';
|
||||||
import { parseLockFile } from './lock-file.js';
|
import { parseLockFile } from './lock-file.js';
|
||||||
|
import { TAKT_PACKAGE_MANIFEST_FILENAME } from './constants.js';
|
||||||
import { createLogger, getErrorMessage } from '../../shared/utils/index.js';
|
import { createLogger, getErrorMessage } from '../../shared/utils/index.js';
|
||||||
|
|
||||||
const log = createLogger('ensemble-list');
|
const log = createLogger('ensemble-list');
|
||||||
@ -29,7 +30,7 @@ export interface PackageInfo {
|
|||||||
* @param scope - e.g. "@nrslib/takt-fullstack"
|
* @param scope - e.g. "@nrslib/takt-fullstack"
|
||||||
*/
|
*/
|
||||||
export function readPackageInfo(packageDir: string, scope: string): PackageInfo {
|
export function readPackageInfo(packageDir: string, scope: string): PackageInfo {
|
||||||
const packConfigPath = join(packageDir, 'takt-package.yaml');
|
const packConfigPath = join(packageDir, TAKT_PACKAGE_MANIFEST_FILENAME);
|
||||||
const lockPath = join(packageDir, '.takt-pack-lock.yaml');
|
const lockPath = join(packageDir, '.takt-pack-lock.yaml');
|
||||||
|
|
||||||
const configYaml = existsSync(packConfigPath)
|
const configYaml = existsSync(packConfigPath)
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
import { existsSync, realpathSync } from 'node:fs';
|
import { existsSync, realpathSync } from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { parse as parseYaml } from 'yaml';
|
import { parse as parseYaml } from 'yaml';
|
||||||
|
import { TAKT_PACKAGE_MANIFEST_FILENAME } from './constants.js';
|
||||||
|
|
||||||
export interface TaktPackConfig {
|
export interface TaktPackConfig {
|
||||||
description?: string;
|
description?: string;
|
||||||
@ -52,14 +53,14 @@ export function parseTaktPackConfig(yaml: string): TaktPackConfig {
|
|||||||
*/
|
*/
|
||||||
export function validateTaktPackPath(path: string): void {
|
export function validateTaktPackPath(path: string): void {
|
||||||
if (path.startsWith('/')) {
|
if (path.startsWith('/')) {
|
||||||
throw new Error(`takt-package.yaml: path must not be absolute, got "${path}"`);
|
throw new Error(`${TAKT_PACKAGE_MANIFEST_FILENAME}: path must not be absolute, got "${path}"`);
|
||||||
}
|
}
|
||||||
if (path.startsWith('~')) {
|
if (path.startsWith('~')) {
|
||||||
throw new Error(`takt-package.yaml: path must not start with "~", got "${path}"`);
|
throw new Error(`${TAKT_PACKAGE_MANIFEST_FILENAME}: path must not start with "~", got "${path}"`);
|
||||||
}
|
}
|
||||||
const segments = path.split('/');
|
const segments = path.split('/');
|
||||||
if (segments.includes('..')) {
|
if (segments.includes('..')) {
|
||||||
throw new Error(`takt-package.yaml: path must not contain ".." segments, got "${path}"`);
|
throw new Error(`${TAKT_PACKAGE_MANIFEST_FILENAME}: path must not contain ".." segments, got "${path}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ export function validateTaktPackPath(path: string): void {
|
|||||||
export function validateMinVersion(version: string): void {
|
export function validateMinVersion(version: string): void {
|
||||||
if (!SEMVER_PATTERN.test(version)) {
|
if (!SEMVER_PATTERN.test(version)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`takt-package.yaml: takt.min_version must match X.Y.Z (no "v" prefix, no pre-release), got "${version}"`,
|
`${TAKT_PACKAGE_MANIFEST_FILENAME}: takt.min_version must match X.Y.Z (no "v" prefix, no pre-release), got "${version}"`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,13 +124,15 @@ export function checkPackageHasContent(packageRoot: string): void {
|
|||||||
* @throws if neither candidate exists
|
* @throws if neither candidate exists
|
||||||
*/
|
*/
|
||||||
export function resolvePackConfigPath(extractDir: string): string {
|
export function resolvePackConfigPath(extractDir: string): string {
|
||||||
const taktDirPath = join(extractDir, '.takt', 'takt-package.yaml');
|
const taktDirPath = join(extractDir, '.takt', TAKT_PACKAGE_MANIFEST_FILENAME);
|
||||||
if (existsSync(taktDirPath)) return taktDirPath;
|
if (existsSync(taktDirPath)) return taktDirPath;
|
||||||
|
|
||||||
const rootPath = join(extractDir, 'takt-package.yaml');
|
const rootPath = join(extractDir, TAKT_PACKAGE_MANIFEST_FILENAME);
|
||||||
if (existsSync(rootPath)) return rootPath;
|
if (existsSync(rootPath)) return rootPath;
|
||||||
|
|
||||||
throw new Error(`takt-package.yaml not found in "${extractDir}": checked .takt/takt-package.yaml and takt-package.yaml`);
|
throw new Error(
|
||||||
|
`${TAKT_PACKAGE_MANIFEST_FILENAME} not found in "${extractDir}": checked .takt/${TAKT_PACKAGE_MANIFEST_FILENAME} and ${TAKT_PACKAGE_MANIFEST_FILENAME}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user