Skip to content

Commit 1777031

Browse files
committed
feat: improve windows path lengths test
1 parent 97afa7b commit 1777031

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

command-snapshot.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{
1818
"command": "cli:tarballs:verify",
1919
"plugin": "@salesforce/plugin-release-management",
20-
"flags": ["cli", "json", "loglevel"]
20+
"flags": ["cli", "json", "loglevel", "windows-username-buffer"]
2121
},
2222
{
2323
"command": "cli:versions:inspect",

messages/cli.tarballs.verify.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"description": "verify that tarballs are ready to be uploaded",
33
"cli": "the cli to verify",
4+
"windowsUsernameBuffer": "the number of characters to allow for windows usernames",
45
"examples": [
56
"<%= config.bin %> <%= command.id %>",
67
"<%= config.bin %> <%= command.id %> --cli sfdx",

src/commands/cli/tarballs/verify.ts

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as fg from 'fast-glob';
1111
import { exec } from 'shelljs';
1212
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
1313
import { fs, Messages, SfdxError } from '@salesforce/core';
14-
import { ensure } from '@salesforce/ts-types';
14+
import { ensure, ensureNumber } from '@salesforce/ts-types';
1515
import { red, yellow, green } from 'chalk';
1616

1717
Messages.importMessagesDirectory(__dirname);
@@ -38,6 +38,11 @@ export default class Verify extends SfdxCommand {
3838
default: 'sfdx',
3939
char: 'c',
4040
}),
41+
['windows-username-buffer']: flags.number({
42+
description: messages.getMessage('windowsUsernameBuffer'),
43+
default: 41,
44+
char: 'w',
45+
}),
4146
};
4247

4348
private baseDir!: string;
@@ -63,8 +68,7 @@ export default class Verify extends SfdxCommand {
6368
[CLI.SF]: [
6469
this.ensureNoDistTestsOrMaps.bind(this),
6570
this.ensureNoUnexpectedfiles.bind(this),
66-
// TODO: add this back before R1
67-
// this.ensureWindowsPathLengths.bind(this),
71+
this.ensureWindowsPathLengths.bind(this),
6872
],
6973
};
7074

@@ -118,32 +122,51 @@ export default class Verify extends SfdxCommand {
118122
}
119123

120124
/**
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.
122126
*
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
132130
*/
133131
public async ensureWindowsPathLengths(): Promise<void> {
134132
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+
137158
const paths = (await fg(`${this.baseDir}/node_modules/**/*`)).map((p) =>
138159
p.replace(`${this.baseDir}${path.sep}`, '')
139160
);
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();
142165
if (warnPaths.length) {
143166
this.log(
144167
`${yellow.bold(
145168
'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!`
147170
);
148171
warnPaths.forEach((p) => this.log(`${p.length} - ${p}`));
149172
}

0 commit comments

Comments
 (0)