@@ -7,10 +7,12 @@ import {
77} from "../infra/install-safe-path.js" ;
88import { resolveConfigDir , resolveUserPath } from "../utils.js" ;
99
10+ /** Encodes arbitrary input as a safe plugin install filename. */
1011export function safePluginInstallFileName ( input : string ) : string {
1112 return safeDirName ( input ) ;
1213}
1314
15+ /** Encodes a plugin id for use as an install directory name. */
1416export function encodePluginInstallDirName ( pluginId : string ) : string {
1517 const trimmed = pluginId . trim ( ) ;
1618 if ( ! trimmed . includes ( "/" ) ) {
@@ -21,6 +23,7 @@ export function encodePluginInstallDirName(pluginId: string): string {
2123 return `@${ safePathSegmentHashed ( trimmed ) } ` ;
2224}
2325
26+ /** Validates a plugin id for install path safety. */
2427export function validatePluginId ( pluginId : string ) : string | null {
2528 const trimmed = pluginId . trim ( ) ;
2629 if ( ! trimmed ) {
@@ -51,6 +54,7 @@ export function validatePluginId(pluginId: string): string | null {
5154 return null ;
5255}
5356
57+ /** Checks whether an installed plugin id matches the expected id, including old npm keying. */
5458export function matchesExpectedPluginId ( params : {
5559 expectedPluginId ?: string ;
5660 pluginId : string ;
@@ -73,20 +77,23 @@ export function matchesExpectedPluginId(params: {
7377 ) ;
7478}
7579
80+ /** Resolves the default directory for path-installed plugin extensions. */
7681export function resolveDefaultPluginExtensionsDir (
7782 env : NodeJS . ProcessEnv = process . env ,
7883 homedir ?: ( ) => string ,
7984) : string {
8085 return path . join ( resolveConfigDir ( env , homedir ) , "extensions" ) ;
8186}
8287
88+ /** Resolves the default directory for managed npm plugin installs. */
8389export function resolveDefaultPluginNpmDir (
8490 env : NodeJS . ProcessEnv = process . env ,
8591 homedir ?: ( ) => string ,
8692) : string {
8793 return path . join ( resolveConfigDir ( env , homedir ) , "npm" ) ;
8894}
8995
96+ /** Encodes an npm package name into a managed npm project directory name. */
9097export function encodePluginNpmProjectDirName ( packageName : string ) : string {
9198 const trimmed = packageName . trim ( ) ;
9299 if ( ! trimmed ) {
@@ -95,11 +102,13 @@ export function encodePluginNpmProjectDirName(packageName: string): string {
95102 return safePathSegmentHashed ( trimmed ) ;
96103}
97104
105+ /** Resolves the directory containing managed npm plugin projects. */
98106export function resolvePluginNpmProjectsDir ( npmDir ?: string ) : string {
99107 const npmBase = npmDir ? resolveUserPath ( npmDir ) : resolveDefaultPluginNpmDir ( ) ;
100108 return path . join ( npmBase , "projects" ) ;
101109}
102110
111+ /** Resolves the managed npm project directory for a package name. */
103112export function resolvePluginNpmProjectDir ( params : {
104113 packageName : string ;
105114 npmDir ?: string ;
@@ -110,6 +119,7 @@ export function resolvePluginNpmProjectDir(params: {
110119 ) ;
111120}
112121
122+ /** Resolves the installed node_modules package directory for a managed npm plugin. */
113123export function resolvePluginNpmPackageDir ( params : {
114124 packageName : string ;
115125 npmDir ?: string ;
@@ -121,13 +131,15 @@ export function resolvePluginNpmPackageDir(params: {
121131 ) ;
122132}
123133
134+ /** Resolves the default directory for git-installed plugins. */
124135export function resolveDefaultPluginGitDir (
125136 env : NodeJS . ProcessEnv = process . env ,
126137 homedir ?: ( ) => string ,
127138) : string {
128139 return path . join ( resolveConfigDir ( env , homedir ) , "git" ) ;
129140}
130141
142+ /** Resolves the safe install directory for one plugin id. */
131143export function resolvePluginInstallDir ( pluginId : string , extensionsDir ?: string ) : string {
132144 const extensionsBase = extensionsDir
133145 ? resolveUserPath ( extensionsDir )
0 commit comments