Skip to content

Commit 81bbc1f

Browse files
fix: forceignore ignores output file correctly - cleanup extra type declarations
1 parent 1750d02 commit 81bbc1f

File tree

10 files changed

+22
-27
lines changed

10 files changed

+22
-27
lines changed

src/client/metadataApiRetrieve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class MetadataApiRetrieve extends MetadataTransfer<
119119
MetadataApiRetrieveOptions
120120
> {
121121
public static DEFAULT_OPTIONS: Partial<MetadataApiRetrieveOptions> = { merge: false };
122-
private options: MetadataApiRetrieveOptions;
122+
private readonly options: MetadataApiRetrieveOptions;
123123
private orgId?: string;
124124

125125
public constructor(options: MetadataApiRetrieveOptions) {

src/collections/componentSetBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class ComponentSetBuilder {
133133
}`
134134
);
135135

136-
const mdMap: MetadataMap = metadata
136+
const mdMap = metadata
137137
? buildMapFromComponents(metadata.metadataEntries.map(entryToTypeAndName(registryAccess)))
138138
: (new Map() as MetadataMap);
139139

@@ -281,7 +281,7 @@ const typeAndNameToMetadataComponents =
281281

282282
// TODO: use Map.groupBy when it's available
283283
const buildMapFromComponents = (components: MetadataTypeAndMetadataName[]): MetadataMap => {
284-
const mdMap: MetadataMap = new Map();
284+
const mdMap: MetadataMap = new Map<string, string[]>();
285285
components.map((cmp) => {
286286
mdMap.set(cmp.type.name, [...(mdMap.get(cmp.type.name) ?? []), cmp.metadataName]);
287287
});

src/convert/metadataConverter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ function getMergeConfigOutputs(
183183
mergeSet.add(component.parent ?? component);
184184
}
185185
const writer = new StandardWriter(output.defaultDirectory);
186-
if (output.forceIgnoredPaths) {
187-
writer.forceIgnoredPaths = output.forceIgnoredPaths;
188-
}
186+
189187
return {
190188
writer,
191189
mergeSet,

src/convert/streams.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import { basename, dirname, isAbsolute, join } from 'node:path';
7+
import { isAbsolute, join } from 'node:path';
88
import { pipeline as cbPipeline, Readable, Stream, Transform, Writable } from 'node:stream';
99
import { promisify } from 'node:util';
1010
import { Messages, SfError } from '@salesforce/core';
@@ -20,6 +20,7 @@ import { ComponentSet } from '../collections/componentSet';
2020
import { RegistryAccess } from '../registry/registryAccess';
2121
import { ensureFileExists } from '../utils/fileSystemHandler';
2222
import { ComponentStatus, FileResponseSuccess } from '../client/types';
23+
import { ForceIgnore } from '../resolve';
2324
import { MetadataTransformerFactory } from './transformers/metadataTransformerFactory';
2425
import { ConvertContext } from './convertContext/convertContext';
2526
import { SfdxFileFormat, WriteInfo, WriterFormat } from './types';
@@ -113,7 +114,6 @@ export class ComponentConverter extends Transform {
113114
}
114115

115116
export abstract class ComponentWriter extends Writable {
116-
public forceIgnoredPaths: Set<string> = new Set<string>();
117117
protected rootDestination?: SourcePath;
118118
protected logger: Logger;
119119

@@ -128,9 +128,11 @@ export class StandardWriter extends ComponentWriter {
128128
/** filepaths that converted files were written to */
129129
public readonly converted: string[] = [];
130130
public readonly deleted: FileResponseSuccess[] = [];
131+
public readonly forceignore: ForceIgnore;
131132

132133
public constructor(rootDestination: SourcePath) {
133134
super(rootDestination);
135+
this.forceignore = ForceIgnore.findAndCreate(rootDestination);
134136
}
135137

136138
public async _write(chunk: WriterFormat, encoding: string, callback: (err?: Error) => void): Promise<void> {
@@ -144,8 +146,7 @@ export class StandardWriter extends ComponentWriter {
144146
await Promise.all(
145147
chunk.writeInfos
146148
.map(makeWriteInfoAbsolute(this.rootDestination))
147-
.filter(existsOrDoesntMatchIgnored(this.forceIgnoredPaths))
148-
.filter((info) => !this.forceIgnoredPaths.has(info.output))
149+
.filter(existsOrDoesntMatchIgnored(this.forceignore))
149150
.map((info) => {
150151
if (info.shouldDelete) {
151152
this.deleted.push({
@@ -288,11 +289,6 @@ const makeWriteInfoAbsolute =
288289
});
289290

290291
const existsOrDoesntMatchIgnored =
291-
(ignoredPaths: Set<string>) =>
292+
(forceignore: ForceIgnore) =>
292293
(writeInfo: WriteInfo): boolean =>
293-
existsSync(writeInfo.output) ||
294-
[...ignoredPaths].every(
295-
(ignoredPath) =>
296-
!dirname(ignoredPath).includes(dirname(writeInfo.output)) &&
297-
!basename(ignoredPath).includes(basename(writeInfo.output))
298-
);
294+
existsSync(writeInfo.output) || forceignore.accepts(writeInfo.output);

src/resolve/adapters/baseSourceAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export abstract class BaseSourceAdapter implements SourceAdapter {
3535
public constructor(
3636
type: MetadataType,
3737
registry = new RegistryAccess(),
38-
forceIgnore: ForceIgnore = new ForceIgnore(),
39-
tree: TreeContainer = new NodeFSTreeContainer()
38+
forceIgnore = new ForceIgnore(),
39+
tree = new NodeFSTreeContainer()
4040
) {
4141
this.type = type;
4242
this.registry = registry;

src/resolve/connectionResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export class ConnectionResolver {
166166
// The 'singleRecordQuery' method was having connection errors, using `retry` resolves this
167167
// Note that this type of connection retry logic may someday be added to jsforce v2
168168
// Once that happens this logic could be reverted
169-
const standardValueSetRecord: StdValueSetRecord = await retry(async () => {
169+
const standardValueSetRecord = await retry<StdValueSetRecord>(async () => {
170170
try {
171171
return await this.connection.singleRecordQuery(
172172
`SELECT Id, MasterLabel, Metadata FROM StandardValueSet WHERE MasterLabel = '${standardValueSetFullName}'`,

src/resolve/forceIgnore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ForceIgnore {
1717

1818
private readonly parser?: Ignore;
1919
private readonly forceIgnoreDirectory?: string;
20-
private DEFAULT_IGNORE: string[] = ['**/*.dup', '**/.*', '**/package2-descriptor.json', '**/package2-manifest.json'];
20+
private DEFAULT_IGNORE = ['**/*.dup', '**/.*', '**/package2-descriptor.json', '**/package2-manifest.json'];
2121

2222
public constructor(forceIgnorePath = '') {
2323
try {

src/resolve/metadataResolver.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class MetadataResolver {
3131
/**
3232
* @param registry Custom registry data
3333
* @param tree `TreeContainer` to traverse with
34+
* @param useFsForceIgnore false = use default forceignore entries, true = search and use forceignore in project
3435
*/
3536
public constructor(
3637
private registry = new RegistryAccess(),
@@ -186,7 +187,7 @@ const isProbablyPackageManifest =
186187
* If a type can be determined from a directory path, and the end part of the path isn't
187188
* the directoryName of the type itself, infer the path is part of a mixedContent component
188189
*
189-
* @param dirPath Path to a directory
190+
* @param registry the registry to resolve a type against
190191
*/
191192
const resolveDirectoryAsComponent =
192193
(registry: RegistryAccess) =>
@@ -227,8 +228,8 @@ const isMetadata =
227228
* Attempt to find similar types for types that could not be inferred
228229
* To be used after executing the resolveType() method
229230
*
230-
* @param fsPath
231231
* @returns an array of suggestions
232+
* @param registry a metdata registry to resolve types against
232233
*/
233234
const getSuggestionsForUnresolvedTypes =
234235
(registry: RegistryAccess) =>
@@ -350,7 +351,7 @@ const resolveType =
350351
/**
351352
* Any file with a registered suffix is potentially a content metadata file.
352353
*
353-
* @param fsPath File path of a potential content metadata file
354+
* @param registry a metadata registry to resolve types agsinst
354355
*/
355356
const parseAsContentMetadataXml =
356357
(registry: RegistryAccess) =>

src/resolve/sourceComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export class SourceComponent implements MetadataComponent {
4545
public parentType?: MetadataType;
4646
public content?: string;
4747
public replacements?: Record<string, MarkedReplacement[]>;
48-
private treeContainer: TreeContainer;
49-
private forceIgnore: ForceIgnore;
48+
private readonly treeContainer: TreeContainer;
49+
private readonly forceIgnore: ForceIgnore;
5050
private markedForDelete = false;
5151
private destructiveChangesType?: DestructiveChangesType;
5252

test/mock/type-constants/staticresourceConstant.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const MIXED_CONTENT_DIRECTORY_SOURCE_PATHS = [
2222
join(MIXED_CONTENT_DIRECTORY_CONTENT_PATH, 'tests', 'test.js'),
2323
join(MIXED_CONTENT_DIRECTORY_CONTENT_PATH, 'tests', 'test2.pdf'),
2424
];
25-
export const MIXED_CONTENT_DIRECTORY_COMPONENT: SourceComponent = new SourceComponent({
25+
export const MIXED_CONTENT_DIRECTORY_COMPONENT = new SourceComponent({
2626
name: 'aStaticResource',
2727
type,
2828
xml: MIXED_CONTENT_DIRECTORY_XML_PATHS[0],

0 commit comments

Comments
 (0)