@@ -11,7 +11,7 @@ import * as fg from 'fast-glob';
11
11
import { exec } from 'shelljs' ;
12
12
import { flags , FlagsConfig , SfdxCommand } from '@salesforce/command' ;
13
13
import { fs , Messages , SfdxError } from '@salesforce/core' ;
14
- import { ensure } from '@salesforce/ts-types' ;
14
+ import { ensure , ensureNumber } from '@salesforce/ts-types' ;
15
15
import { red , yellow , green } from 'chalk' ;
16
16
17
17
Messages . importMessagesDirectory ( __dirname ) ;
@@ -38,6 +38,11 @@ export default class Verify extends SfdxCommand {
38
38
default : 'sfdx' ,
39
39
char : 'c' ,
40
40
} ) ,
41
+ [ 'windows-username-buffer' ] : flags . number ( {
42
+ description : messages . getMessage ( 'windowsUsernameBuffer' ) ,
43
+ default : 41 ,
44
+ char : 'w' ,
45
+ } ) ,
41
46
} ;
42
47
43
48
private baseDir ! : string ;
@@ -63,8 +68,7 @@ export default class Verify extends SfdxCommand {
63
68
[ CLI . SF ] : [
64
69
this . ensureNoDistTestsOrMaps . bind ( this ) ,
65
70
this . ensureNoUnexpectedfiles . bind ( this ) ,
66
- // TODO: add this back before R1
67
- // this.ensureWindowsPathLengths.bind(this),
71
+ this . ensureWindowsPathLengths . bind ( this ) ,
68
72
] ,
69
73
} ;
70
74
@@ -118,32 +122,51 @@ export default class Verify extends SfdxCommand {
118
122
}
119
123
120
124
/**
121
- * Make sure cleaning was not too aggressive and that path lengths in the build tree are as windows- safe as they can be
125
+ * Ensure that the path lengths in the build tree are as windows safe as possible.
122
126
*
123
- * Check for potentially overflowing windows paths:
124
- * - assume a max practical windows username length of 64 characters (https://technet.microsoft.com/it-it/library/bb726984(en-us).aspx)
125
- * - add characters to account for the root sfdx client tmp untar path for a total of 135
126
- * e.g. C:\Users\<username>\AppData\Local\sfdx\tmp\sfdx-cli-v7.xx.yy-abcdef-windows-x64\
127
- * - subtract those 135 characters from the max windows path length of 259 to yield the allowable length of 124 path characters
128
- * - considering that we currently have some dependencies in the built output that exceed 124 characters (up to 139 in salesforce-lightning-cli)
129
- * we will consider the maximum path length of 139, plus 5 as a buffer, as the hard upper limit to our allowable path length;
130
- * this leaves us a relatively comfortable maximum windows username length of 48 characters with a hard maximum path length of 144 characters
131
- * - then scan the cleaned build output directory for paths exceding this threshold, and exit with an error if detected
127
+ * The check fails if the path lengths DO NOT allow for a username longer than the --windows-username-buffer
128
+ *
129
+ * Warnings will be emitted for any path that does not allow for a username longer than 48 characters
132
130
*/
133
131
public async ensureWindowsPathLengths ( ) : Promise < void > {
134
132
const validate = async ( ) : Promise < boolean > => {
135
- const warningLength = 124 ;
136
- const maxLength = 146 ;
133
+ const maxWindowsPath = 259 ;
134
+ const cli = ensure < CLI > ( this . flags . cli ) ;
135
+
136
+ const supportedUsernameLength = ensureNumber ( this . flags [ 'windows-username-buffer' ] ) ;
137
+ const fakeSupportedUsername = 'u' . repeat ( supportedUsernameLength ) ;
138
+ const supportedBaseWindowsPath = `C:\\Users\\${ fakeSupportedUsername } \\AppData\\Local\\${ cli } \\tmp\\${ cli } -cli-v1.xxx.yyy-abcdef-windows-x64\\` ;
139
+
140
+ const maxUsernameLength = 64 ;
141
+ const fakeMaxUsername = 'u' . repeat ( maxUsernameLength ) ;
142
+ const maxBaseWindowsPath = `C:\\Users\\${ fakeMaxUsername } \\AppData\\Local\\${ cli } \\tmp\\${ cli } -cli-v1.xxx.yyy-abcdef-windows-x64\\` ;
143
+
144
+ const supportedWindowsPathLength = maxWindowsPath - supportedBaseWindowsPath . length ;
145
+ const maxWindowsPathLength = maxWindowsPath - maxBaseWindowsPath . length ;
146
+
147
+ this . log ( 'Windows Path Length Test:' ) ;
148
+ this . log ( ` - max windows path length: ${ maxWindowsPath } ` ) ;
149
+ this . log ( ' ---- Upper Limit ----' ) ;
150
+ this . log ( ` - ${ cli } max username length: ${ maxUsernameLength } ` ) ;
151
+ this . log ( ` - ${ cli } max base path length: ${ maxBaseWindowsPath . length } ` ) ;
152
+ this . log ( ` - ${ cli } max allowable path length: ${ maxWindowsPathLength } ` ) ;
153
+ this . log ( ' ---- Supported Limit ----' ) ;
154
+ this . log ( ` - ${ cli } supported username length: ${ supportedUsernameLength } ` ) ;
155
+ this . log ( ` - ${ cli } supported base path length: ${ supportedBaseWindowsPath . length } ` ) ;
156
+ this . log ( ` - ${ cli } supported allowable path length: ${ supportedWindowsPathLength } ` ) ;
157
+
137
158
const paths = ( await fg ( `${ this . baseDir } /node_modules/**/*` ) ) . map ( ( p ) =>
138
159
p . replace ( `${ this . baseDir } ${ path . sep } ` , '' )
139
160
) ;
140
- const warnPaths = paths . filter ( ( p ) => p . length >= warningLength && p . length < maxLength ) . sort ( ) ;
141
- const errorPaths = paths . filter ( ( p ) => p . length >= maxLength ) . sort ( ) ;
161
+ const warnPaths = paths
162
+ . filter ( ( p ) => p . length >= maxWindowsPathLength && p . length < supportedWindowsPathLength )
163
+ . sort ( ) ;
164
+ const errorPaths = paths . filter ( ( p ) => p . length >= supportedWindowsPathLength ) . sort ( ) ;
142
165
if ( warnPaths . length ) {
143
166
this . log (
144
167
`${ yellow . bold (
145
168
'WARNING:'
146
- ) } Some paths could result in update errors for Windows users with usernames greater than 48 characters!`
169
+ ) } Some paths could result in errors for Windows users with usernames that are ${ maxUsernameLength } characters!`
147
170
) ;
148
171
warnPaths . forEach ( ( p ) => this . log ( `${ p . length } - ${ p } ` ) ) ;
149
172
}
0 commit comments