Skip to content

Commit fca3767

Browse files
committed
Merge remote-tracking branch 'remotes/origin/master' into ianc/fixing-git-policy
2 parents 7b8b730 + b5e4042 commit fca3767

26 files changed

Lines changed: 428 additions & 247 deletions

‎apps/rush-lib/src/cli/RushCommandLineParser.ts‎

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,31 @@ export class RushCommandLineParser extends CommandLineParser {
117117
}
118118

119119
private _populateScriptActions(): void {
120-
if (!this.rushConfiguration) {
121-
return;
122-
}
120+
let commandLineConfiguration: CommandLineConfiguration | undefined = undefined;
123121

124-
const commandLineConfigFile: string = path.join(
125-
this.rushConfiguration.commonRushConfigFolder, RushConstants.commandLineFilename
126-
);
127-
const commandLineConfiguration: CommandLineConfiguration
128-
= CommandLineConfiguration.loadFromFileOrDefault(commandLineConfigFile);
122+
// If there is not a rush.json file, we still want "build" and "rebuild" to appear in the
123+
// command-line help
124+
if (this.rushConfiguration) {
125+
const commandLineConfigFile: string = path.join(
126+
this.rushConfiguration.commonRushConfigFolder, RushConstants.commandLineFilename
127+
);
129128

130-
const documentationForBuild: string = 'The Rush build command assumes that the package.json file for each'
131-
+ ' project contains a "scripts" entry for "npm run build". It invokes'
132-
+ ' this commands to build each project. Projects are built in parallel where'
133-
+ ' possible, but always respecting the dependency graph for locally linked projects.'
134-
+ ' The number of simultaneous processes will be based on the number of machine cores'
135-
+ ' unless overridden by the --parallelism flag.';
129+
commandLineConfiguration = CommandLineConfiguration.loadFromFileOrDefault(commandLineConfigFile);
130+
}
136131

137132
// always create a build and a rebuild command
138133
this.addAction(new BulkScriptAction({
139134
actionName: 'build',
140135
summary: '(EXPERIMENTAL) Build all projects that haven\'t been built, or have changed since they were last '
141136
+ 'built.',
142-
documentation: documentationForBuild,
143-
137+
documentation: 'This command is similar to "rush rebuild", except that "rush build" performs'
138+
+ ' an incremental build. In other words, it only builds projects whose source files have'
139+
+ ' changed since the last successful build. The analysis requires a Git working tree, and'
140+
+ ' only considers source files that are tracked by Git and whose path is under the project folder.'
141+
+ ' (For more details about this algorithm, see the documentation for the "package-deps-hash"'
142+
+ ' NPM package.) The incremental build state is tracked in a file "package-deps.json" which should'
143+
+ ' NOT be added to Git. The build command is tracked by the "arguments" field in this JSON file;'
144+
+ ' a full rebuild is forced whenever the command has changed (e.g. "--production" or not).',
144145
parser: this,
145146
commandLineConfiguration: commandLineConfiguration,
146147

@@ -151,15 +152,25 @@ export class RushCommandLineParser extends CommandLineParser {
151152
this.addAction(new BulkScriptAction({
152153
actionName: 'rebuild',
153154
summary: 'Clean and rebuild the entire set of projects',
154-
documentation: documentationForBuild,
155-
155+
documentation: 'This command assumes that the package.json file for each project contains'
156+
+ ' a "scripts" entry for "npm run build" that performs a full clean build.'
157+
+ ' Rush invokes this script to build each project that is registered in rush.json.'
158+
+ ' Projects are built in parallel where possible, but always respecting the dependency'
159+
+ ' graph for locally linked projects. The number of simultaneous processes will be'
160+
+ ' based on the number of machine cores unless overridden by the --parallelism flag.'
161+
+ ' (For an incremental build, see "rush build" instead of "rush rebuild".)',
156162
parser: this,
157163
commandLineConfiguration: commandLineConfiguration,
158164

159165
enableParallelism: true,
160166
ignoreMissingScript: false
161167
}));
162168

169+
if (!commandLineConfiguration) {
170+
// If there is not a rush.json file, so don't attempt to define custom commands/parameters
171+
return;
172+
}
173+
163174
// Register each custom command
164175
for (const command of commandLineConfiguration.commands) {
165176
if (this.tryGetAction(command.name)) {

‎apps/rush-lib/src/cli/actions/PublishAction.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,11 @@ export class PublishAction extends BaseRushAction {
387387
const destFolder: string = this._releaseFolder.value ?
388388
this._releaseFolder.value : path.join(this.rushConfiguration.commonTempFolder, 'artifacts', 'packages');
389389

390-
FileSystem.move(tarballPath, path.join(destFolder, tarballName), { overwrite: true });
390+
FileSystem.move({
391+
sourcePath: tarballPath,
392+
destinationPath: path.join(destFolder, tarballName),
393+
overwrite: true
394+
});
391395
}
392396
}
393397

@@ -416,7 +420,10 @@ export class PublishAction extends BaseRushAction {
416420
const toApiFolderPath: string = path.join(project.projectFolder, toApiFolder);
417421
if (FileSystem.exists(fromApiFolderPath) && FileSystem.exists(toApiFolderPath)) {
418422
FileSystem.readFolder(fromApiFolderPath).forEach(fileName => {
419-
FileSystem.copyFile(path.join(fromApiFolderPath, fileName), path.join(toApiFolderPath, fileName));
423+
FileSystem.copyFile({
424+
sourcePath: path.join(fromApiFolderPath, fileName),
425+
destinationPath: path.join(toApiFolderPath, fileName)
426+
});
420427
console.log(`Copied file ${fileName} from ${fromApiFolderPath} to ${toApiFolderPath}`);
421428
});
422429
}

‎apps/rush-lib/src/cli/scriptActions/BaseScriptAction.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { RushConstants } from '../../logic/RushConstants';
1111
* Constructor parameters for BaseScriptAction
1212
*/
1313
export interface IBaseScriptActionOptions extends IBaseRushActionOptions {
14-
commandLineConfiguration: CommandLineConfiguration;
14+
commandLineConfiguration: CommandLineConfiguration | undefined;
1515
}
1616

1717
/**
@@ -25,7 +25,7 @@ export interface IBaseScriptActionOptions extends IBaseRushActionOptions {
2525
* The two subclasses are BulkScriptAction and GlobalScriptAction.
2626
*/
2727
export abstract class BaseScriptAction extends BaseRushAction {
28-
protected readonly _commandLineConfiguration: CommandLineConfiguration;
28+
protected readonly _commandLineConfiguration: CommandLineConfiguration | undefined;
2929
protected readonly customParameters: CommandLineParameter[] = [];
3030

3131
constructor(
@@ -36,6 +36,10 @@ export abstract class BaseScriptAction extends BaseRushAction {
3636
}
3737

3838
protected defineScriptParameters(): void {
39+
if (!this._commandLineConfiguration) {
40+
return;
41+
}
42+
3943
// Find any parameters that are associated with this command
4044
for (const parameter of this._commandLineConfiguration.parameters) {
4145
let associated: boolean = false;

‎apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class BulkScriptAction extends BaseScriptAction {
6969

7070
const isQuietMode: boolean = !(this._verboseParameter.value);
7171

72-
// if this is parallizable, then use the value from the flag (undefined or a number),
72+
// if this is parallelizable, then use the value from the flag (undefined or a number),
7373
// if parallelism is not enabled, then restrict to 1 core
7474
const parallelism: string | undefined = this._isParallelismEnabled()
7575
? this._parallelismParameter!.value

‎apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ exports[`CommandLineHelp prints the help for "rush build" 1`] = `
5656
[-o] [-s] [-m]
5757
5858
59-
The Rush build command assumes that the package.json file for each project
60-
contains a \\"scripts\\" entry for \\"npm run build\\". It invokes this commands to
61-
build each project. Projects are built in parallel where possible, but always
62-
respecting the dependency graph for locally linked projects. The number of
63-
simultaneous processes will be based on the number of machine cores unless
64-
overridden by the --parallelism flag.
59+
This command is similar to \\"rush rebuild\\", except that \\"rush build\\" performs
60+
an incremental build. In other words, it only builds projects whose source
61+
files have changed since the last successful build. The analysis requires a
62+
Git working tree, and only considers source files that are tracked by Git and
63+
whose path is under the project folder. (For more details about this
64+
algorithm, see the documentation for the \\"package-deps-hash\\" NPM package.)
65+
The incremental build state is tracked in a file \\"package-deps.json\\" which
66+
should NOT be added to Git. The build command is tracked by the \\"arguments\\"
67+
field in this JSON file; a full rebuild is forced whenever the command has
68+
changed (e.g. \\"--production\\" or not).
6569
6670
Optional arguments:
6771
-h, --help Show this help message and exit.
@@ -336,12 +340,14 @@ exports[`CommandLineHelp prints the help for "rush rebuild" 1`] = `
336340
[-v] [-s] [-m]
337341
338342
339-
The Rush build command assumes that the package.json file for each project
340-
contains a \\"scripts\\" entry for \\"npm run build\\". It invokes this commands to
341-
build each project. Projects are built in parallel where possible, but always
342-
respecting the dependency graph for locally linked projects. The number of
343-
simultaneous processes will be based on the number of machine cores unless
344-
overridden by the --parallelism flag.
343+
This command assumes that the package.json file for each project contains a
344+
\\"scripts\\" entry for \\"npm run build\\" that performs a full clean build. Rush
345+
invokes this script to build each project that is registered in rush.json.
346+
Projects are built in parallel where possible, but always respecting the
347+
dependency graph for locally linked projects. The number of simultaneous
348+
processes will be based on the number of machine cores unless overridden by
349+
the --parallelism flag. (For an incremental build, see \\"rush build\\" instead
350+
of \\"rush rebuild\\".)
345351
346352
Optional arguments:
347353
-h, --help Show this help message and exit.

‎apps/rush-lib/src/logic/InstallManager.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ export class InstallManager {
333333
}
334334
}
335335

336-
FileSystem.createSymbolicLinkJunction(packageManagerToolFolder, localPackageManagerToolFolder);
336+
FileSystem.createSymbolicLinkJunction({
337+
linkTargetPath: packageManagerToolFolder,
338+
newLinkPath: localPackageManagerToolFolder
339+
});
337340

338341
lock.release();
339342
});
@@ -976,17 +979,17 @@ export class InstallManager {
976979
}
977980

978981
/**
979-
* Copies the file "sourcePath" to "targetPath", overwriting the target file location.
982+
* Copies the file "sourcePath" to "destinationPath", overwriting the target file location.
980983
* If the source file does not exist, then the target file is deleted.
981984
*/
982-
private _syncFile(sourcePath: string, targetPath: string): void {
985+
private _syncFile(sourcePath: string, destinationPath: string): void {
983986
if (FileSystem.exists(sourcePath)) {
984-
console.log('Updating ' + targetPath);
985-
FileSystem.copyFile(sourcePath, targetPath);
987+
console.log('Updating ' + destinationPath);
988+
FileSystem.copyFile({sourcePath, destinationPath});
986989
} else {
987-
if (FileSystem.exists(targetPath)) {
988-
console.log('Deleting ' + targetPath);
989-
FileSystem.deleteFile(targetPath);
990+
if (FileSystem.exists(destinationPath)) {
991+
console.log('Deleting ' + destinationPath);
992+
FileSystem.deleteFile(destinationPath);
990993
}
991994
}
992995
}

‎apps/rush-lib/src/logic/StandardScriptUpdater.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ export class StandardScriptUpdater {
7474
+ ' for this Rush version. Please run "rush update" and commit the changes.');
7575
} else {
7676
console.log(`Script is out of date; updating "${targetFilePath}"`);
77-
FileSystem.copyFile(sourceFilePath, targetFilePath);
77+
FileSystem.copyFile({
78+
sourcePath: sourceFilePath,
79+
destinationPath: targetFilePath
80+
});
7881
}
7982
}
8083

‎apps/rush-lib/src/logic/base/BaseLinkManager.ts‎

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as fs from 'fs';
66
import * as os from 'os';
77
import * as path from 'path';
88

9-
import { FileSystem } from '@microsoft/node-core-library';
9+
import { FileSystem, IFileSystemCreateLinkOptions } from '@microsoft/node-core-library';
1010

1111
import { RushConfiguration } from '../../api/RushConfiguration';
1212
import { Utilities } from '../../utilities/Utilities';
@@ -18,24 +18,37 @@ export enum SymlinkKind {
1818
Directory
1919
}
2020

21+
export interface IBaseLinkManagerCreateSymlinkOptions extends IFileSystemCreateLinkOptions {
22+
symlinkKind: SymlinkKind;
23+
}
24+
2125
export abstract class BaseLinkManager {
2226
protected _rushConfiguration: RushConfiguration;
2327

24-
protected static _createSymlink(linkTarget: string, linkSource: string, symlinkKind: SymlinkKind): void {
25-
FileSystem.ensureFolder(path.dirname(linkSource));
28+
protected static _createSymlink(options: IBaseLinkManagerCreateSymlinkOptions): void {
29+
FileSystem.ensureFolder(path.dirname(options.newLinkPath));
2630

27-
if (symlinkKind === SymlinkKind.Directory) {
31+
if (options.symlinkKind === SymlinkKind.Directory) {
2832
// For directories, we use a Windows "junction". On Unix, this produces a regular symlink.
29-
FileSystem.createSymbolicLinkJunction(linkTarget, linkSource);
33+
FileSystem.createSymbolicLinkJunction({
34+
linkTargetPath: options.linkTargetPath,
35+
newLinkPath: options.newLinkPath
36+
});
3037
} else {
3138
if (process.platform === 'win32') {
3239
// For files, we use a Windows "hard link", because creating a symbolic link requires
3340
// administrator permission.
34-
FileSystem.createHardLink(linkTarget, linkSource);
41+
FileSystem.createHardLink({
42+
linkTargetPath: options.linkTargetPath,
43+
newLinkPath: options.newLinkPath
44+
});
3545
} else {
3646
// However hard links seem to cause build failures on Mac, so for all other operating systems
3747
// we use symbolic links for this case.
38-
FileSystem.createSymbolicLinkFile(linkTarget, linkSource);
48+
FileSystem.createSymbolicLinkFile({
49+
linkTargetPath: options.linkTargetPath,
50+
newLinkPath: options.newLinkPath
51+
});
3952
}
4053
}
4154
}
@@ -91,10 +104,11 @@ export abstract class BaseLinkManager {
91104

92105
if (localPackage.children.length === 0) {
93106
// If there are no children, then we can symlink the entire folder
94-
BaseLinkManager._createSymlink(
95-
localPackage.symlinkTargetFolderPath,
96-
localPackage.folderPath,
97-
SymlinkKind.Directory);
107+
BaseLinkManager._createSymlink({
108+
linkTargetPath: localPackage.symlinkTargetFolderPath,
109+
newLinkPath: localPackage.folderPath,
110+
symlinkKind: SymlinkKind.Directory
111+
});
98112
} else {
99113
// If there are children, then we need to symlink each item in the folder individually
100114
Utilities.createFolderWithRetry(localPackage.folderPath);
@@ -126,7 +140,11 @@ export abstract class BaseLinkManager {
126140
symlinkKind = SymlinkKind.Directory;
127141
}
128142

129-
BaseLinkManager._createSymlink(linkTarget, linkSource, symlinkKind);
143+
BaseLinkManager._createSymlink({
144+
linkTargetPath: linkTarget,
145+
newLinkPath: linkSource,
146+
symlinkKind
147+
});
130148
}
131149
}
132150
}

‎apps/rush-lib/src/logic/npm/NpmLinkManager.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ export class NpmLinkManager extends BaseLinkManager {
324324
const projectBinFolder: string = path.join(localProjectPackage.folderPath, 'node_modules', '.bin');
325325

326326
if (FileSystem.exists(commonBinFolder)) {
327-
NpmLinkManager._createSymlink(commonBinFolder, projectBinFolder, SymlinkKind.Directory);
327+
NpmLinkManager._createSymlink({
328+
linkTargetPath: commonBinFolder,
329+
newLinkPath: projectBinFolder,
330+
symlinkKind: SymlinkKind.Directory
331+
});
328332
}
329333
}
330334
}

‎apps/rush-lib/src/utilities/AsyncRecycler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class AsyncRecycler {
7474
}
7575

7676
Utilities.retryUntilTimeout(
77-
() => FileSystem.move(folderPath, newFolderPath),
77+
() => FileSystem.move({ sourcePath: folderPath, destinationPath: newFolderPath }),
7878
maxWaitTimeMs,
7979
(e) => new Error(`Error: ${e}${os.EOL}Often this is caused by a file lock ` +
8080
'from a process like the virus scanner.'),

0 commit comments

Comments
 (0)