@file-viewer/cli 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ import type { PackageManager } from './types.js';
2
+ export type YarnGeneration = 'classic' | 'berry' | 'unknown';
3
+ export interface FileViewerCarrierCommand {
4
+ command: string;
5
+ args: string[];
6
+ compatibilityMode: 'native' | 'npm-exec-for-yarn-classic';
7
+ }
8
+ export declare function detectYarnGeneration(projectRoot: string): YarnGeneration;
9
+ export declare function createFileViewerCarrierCommand(manager: PackageManager, packageSpec: string, passthrough: readonly string[], options: {
10
+ projectRoot: string;
11
+ yarnGeneration?: YarnGeneration;
12
+ }): FileViewerCarrierCommand;
13
+ export declare function createFileViewerRegistryEnvironment(registry: string): {
14
+ npm_config_registry: string;
15
+ YARN_NPM_REGISTRY_SERVER: string;
16
+ BUN_CONFIG_REGISTRY: string;
17
+ };
@@ -0,0 +1,47 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { readDeclaredPackageManagerVersion } from './project-adapters.js';
4
+ export function detectYarnGeneration(projectRoot) {
5
+ const declared = readDeclaredPackageManagerVersion(projectRoot, 'yarn');
6
+ const major = Number(declared?.match(/^(\d+)/)?.[1] ?? NaN);
7
+ if (Number.isFinite(major))
8
+ return major >= 2 ? 'berry' : 'classic';
9
+ if (existsSync(resolve(projectRoot, '.yarnrc.yml')))
10
+ return 'berry';
11
+ if (existsSync(resolve(projectRoot, '.yarnrc')))
12
+ return 'classic';
13
+ return 'unknown';
14
+ }
15
+ export function createFileViewerCarrierCommand(manager, packageSpec, passthrough, options) {
16
+ if (!/^file-viewer-copy-assets@[^\s]+$/.test(packageSpec))
17
+ throw new Error('Invalid file-viewer-copy-assets package spec.');
18
+ if (manager === 'pnpm')
19
+ return { command: 'pnpm', args: ['dlx', packageSpec, ...passthrough], compatibilityMode: 'native' };
20
+ if (manager === 'bun')
21
+ return { command: 'bunx', args: [packageSpec, ...passthrough], compatibilityMode: 'native' };
22
+ if (manager === 'npm') {
23
+ return {
24
+ command: 'npm',
25
+ args: ['exec', '--yes', '--package', packageSpec, '--', 'file-viewer-copy-assets', ...passthrough],
26
+ compatibilityMode: 'native',
27
+ };
28
+ }
29
+ const generation = options.yarnGeneration ?? detectYarnGeneration(options.projectRoot);
30
+ if (generation === 'berry')
31
+ return { command: 'yarn', args: ['dlx', packageSpec, ...passthrough], compatibilityMode: 'native' };
32
+ // Yarn Classic has no `dlx`. npm exec is non-mutating and ships with the
33
+ // supported Node runtime, so it is safer than adding a temporary dependency
34
+ // to the user's project. Unknown Yarn versions take the same conservative path.
35
+ return {
36
+ command: 'npm',
37
+ args: ['exec', '--yes', '--package', packageSpec, '--', 'file-viewer-copy-assets', ...passthrough],
38
+ compatibilityMode: 'npm-exec-for-yarn-classic',
39
+ };
40
+ }
41
+ export function createFileViewerRegistryEnvironment(registry) {
42
+ return {
43
+ npm_config_registry: registry,
44
+ YARN_NPM_REGISTRY_SERVER: registry,
45
+ BUN_CONFIG_REGISTRY: registry,
46
+ };
47
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};