|
5 | 5 | * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6 | 6 | */
|
7 | 7 | import * as fs from 'fs';
|
8 |
| -import { isAbsolute, relative, resolve, normalize } from 'path'; |
| 8 | +import { isAbsolute, relative, resolve, sep, normalize } from 'path'; |
9 | 9 | import { EOL } from 'os';
|
10 | 10 | import { NamedPackageDir, Logger, Org, SfdxProject } from '@salesforce/core';
|
11 | 11 | import { AsyncCreatable } from '@salesforce/kit';
|
@@ -34,7 +34,7 @@ import {
|
34 | 34 | RemoteChangeElement,
|
35 | 35 | } from './shared/types';
|
36 | 36 | import { sourceComponentGuard, metadataMemberGuard } from './shared/guards';
|
37 |
| -import { getKeyFromObject, getMetadataKey } from './shared/functions'; |
| 37 | +import { getKeyFromObject, getMetadataKey, isBundle } from './shared/functions'; |
38 | 38 |
|
39 | 39 | export interface SourceTrackingOptions {
|
40 | 40 | org: Org;
|
@@ -83,7 +83,6 @@ export class SourceTracking extends AsyncCreatable {
|
83 | 83 | */
|
84 | 84 | public async localChangesAsComponentSet(byPackageDir = false): Promise<ComponentSet[]> {
|
85 | 85 | const [projectConfig] = await Promise.all([this.project.resolveProjectConfig(), this.ensureLocalTracking()]);
|
86 |
| - // path may have been cloned from the other OS |
87 | 86 | this.forceIgnore ??= ForceIgnore.findAndCreate(this.project.getDefaultPackage().name);
|
88 | 87 |
|
89 | 88 | const sourceApiVersion = getString(projectConfig, 'sourceApiVersion');
|
@@ -138,11 +137,7 @@ export class SourceTracking extends AsyncCreatable {
|
138 | 137 | .filter(sourceComponentGuard)
|
139 | 138 | .map((component) => {
|
140 | 139 | // if the component is a file in a bundle type AND there are files from the bundle that are not deleted, set the bundle for deploy, not for delete
|
141 |
| - if ( |
142 |
| - component.type.strategies?.adapter === 'bundle' && |
143 |
| - component.content && |
144 |
| - fs.existsSync(component.content) |
145 |
| - ) { |
| 140 | + if (isBundle(component) && component.content && fs.existsSync(component.content)) { |
146 | 141 | // all bundle types have a directory name
|
147 | 142 | try {
|
148 | 143 | resolverForNonDeletes
|
@@ -343,9 +338,39 @@ export class SourceTracking extends AsyncCreatable {
|
343 | 338 | */
|
344 | 339 | public async updateLocalTracking(options: LocalUpdateOptions): Promise<void> {
|
345 | 340 | await this.ensureLocalTracking();
|
| 341 | + |
| 342 | + // relative paths make smaller trees AND isogit wants them relative |
| 343 | + const relativeOptions = { |
| 344 | + files: (options.files ?? []).map((file) => this.ensureRelative(file)), |
| 345 | + deletedFiles: (options.deletedFiles ?? []).map((file) => this.ensureRelative(file)), |
| 346 | + }; |
| 347 | + // plot twist: if you delete a member of a bundle (ex: lwc/foo/foo.css) and push, it'll not be in the fileResponses (deployedFiles) or deletedFiles |
| 348 | + // what got deleted? Any local changes NOT in the fileResponses but part of a successfully deployed bundle |
| 349 | + const deployedFilesAsVirtualComponentSet = ComponentSet.fromSource({ |
| 350 | + // resolve from highest possible level. TODO: can we use [.] |
| 351 | + fsPaths: relativeOptions.files.length ? [relativeOptions.files[0].split(sep)[0]] : [], |
| 352 | + tree: VirtualTreeContainer.fromFilePaths(relativeOptions.files), |
| 353 | + }); |
| 354 | + // these are top-level bundle paths like lwc/foo |
| 355 | + const bundlesWithDeletedFiles = ( |
| 356 | + await this.getChanges<SourceComponent>({ origin: 'local', state: 'delete', format: 'SourceComponent' }) |
| 357 | + ) |
| 358 | + .filter(isBundle) |
| 359 | + .filter((cmp) => deployedFilesAsVirtualComponentSet.has({ type: cmp.type, fullName: cmp.fullName })) |
| 360 | + .map((cmp) => cmp.content) |
| 361 | + .filter(isString); |
| 362 | + |
346 | 363 | await this.localRepo.commitChanges({
|
347 |
| - deployedFiles: options.files?.map((file) => this.ensureRelative(file)), |
348 |
| - deletedFiles: options.deletedFiles?.map((file) => this.ensureRelative(file)), |
| 364 | + deployedFiles: relativeOptions.files, |
| 365 | + deletedFiles: relativeOptions.deletedFiles.concat( |
| 366 | + ( |
| 367 | + await this.localRepo.getDeleteFilenames() |
| 368 | + ).filter( |
| 369 | + (deployedFile) => |
| 370 | + bundlesWithDeletedFiles.some((bundlePath) => deployedFile.startsWith(bundlePath)) && |
| 371 | + !relativeOptions.files.includes(deployedFile) |
| 372 | + ) |
| 373 | + ), |
349 | 374 | });
|
350 | 375 | }
|
351 | 376 |
|
|
0 commit comments