generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 20
ignored:list #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
ignored:list #391
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2a37b0f
feat: ignored list
mshanemc 393764e
chore: snapshot update
mshanemc ba6d266
refactor: use SDR compSet
mshanemc b9b445e
test: nut for ignored:list
mshanemc ec24217
test: ci for unstable org signup destinations
mshanemc d25bd7d
chore: bump stl/sdr
mshanemc 5c4f07e
Revert "test: ci for unstable org signup destinations"
mshanemc b213b04
test: pr feedback test ideas
mshanemc b2837ef
ci: run the misc command NUTs
mshanemc 2302bf1
refactor: revert to walking all files for ignored
mshanemc bae6d3d
Merge remote-tracking branch 'origin/main' into sm/ignored
mshanemc dee73b6
Merge branch 'main' into sm/ignored
WillieRuemmele e2c9a5d
test: spell nut path correctly
mshanemc 2060357
test: forceignore doesn't use windows paths
mshanemc f418130
chore: resolve conflicts
WillieRuemmele 553defa
Merge branch 'main' into sm/ignored
WillieRuemmele File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "description": "check your local project package directories for forceignored files", | ||
| "examples": ["$ sfdx force:source:ignored", "$ sfdx force:source:ignored --sourcepath force-app"], | ||
| "flags": { | ||
| "sourcepath": "file or directory of files that the command checks for foreceignored files" | ||
| }, | ||
| "invalidSourcePath": "File or directory '%s' doesn't exist in your project. Specify one that exists and rerun the command." | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * Copyright (c) 2022, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| import * as path from 'path'; | ||
| import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; | ||
| import { fs as fsCore, Messages, SfdxError } from '@salesforce/core'; | ||
| import { ForceIgnore } from '@salesforce/source-deploy-retrieve'; | ||
|
|
||
| Messages.importMessagesDirectory(__dirname); | ||
| const messages = Messages.loadMessages('@salesforce/plugin-source', 'ignored_list'); | ||
|
|
||
| export type SourceIgnoredResults = { | ||
| ignoredFiles: string[]; | ||
| }; | ||
|
|
||
| export class SourceIgnoredCommand extends SfdxCommand { | ||
| public static readonly description = messages.getMessage('description'); | ||
| public static readonly requiresProject = true; | ||
|
|
||
| public static readonly flagsConfig: FlagsConfig = { | ||
| sourcepath: flags.filepath({ | ||
| char: 'p', | ||
| description: messages.getMessage('flags.sourcepath'), | ||
| }), | ||
| }; | ||
|
|
||
| private forceIgnore: ForceIgnore; | ||
| /** | ||
| * Outputs all forceignored files from package directories of a project, | ||
| * or based on a sourcepath param that points to a specific file or directory. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/require-await | ||
| public async run(): Promise<SourceIgnoredResults> { | ||
| try { | ||
| this.forceIgnore = ForceIgnore.findAndCreate(this.project.getPath()); | ||
| const sourcepaths = this.flags.sourcepath | ||
| ? [this.flags.sourcepath as string] | ||
| : this.project.getUniquePackageDirectories().map((pDir) => pDir.path); | ||
|
|
||
| const ignoredFiles = (await Promise.all(sourcepaths.map((sp) => this.statIgnored(sp.trim())))).flat(); | ||
|
|
||
| // Command output | ||
| if (ignoredFiles.length) { | ||
| this.ux.log('Found the following ignored files:'); | ||
| ignoredFiles.forEach((filepath) => this.ux.log(filepath)); | ||
| } else { | ||
| this.ux.log('No ignored files found in paths:'); | ||
| sourcepaths.forEach((sp) => this.ux.log(sp)); | ||
| } | ||
|
|
||
| return { ignoredFiles }; | ||
| } catch (err) { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
| if (err.code === 'ENOENT') { | ||
| throw SfdxError.create('@salesforce/plugin-source', 'ignored_list', 'invalidSourcePath', [ | ||
| this.flags.sourcepath, | ||
| ]); | ||
| } | ||
| throw SfdxError.wrap(err); | ||
| } | ||
| } | ||
|
|
||
| // Stat the filepath. Test if a file, recurse if a directory. | ||
| private async statIgnored(filepath: string): Promise<string[]> { | ||
| const stats = await fsCore.stat(filepath); | ||
| if (stats.isDirectory()) { | ||
| return (await Promise.all(await this.findIgnored(filepath))).flat(); | ||
| } else { | ||
| return this.isIgnored(filepath) ? [filepath] : []; | ||
| } | ||
| } | ||
|
|
||
| // Recursively search a directory for source files to test. | ||
| private async findIgnored(dir: string): Promise<Array<Promise<string[]>>> { | ||
| this.logger.debug(`Searching dir: ${dir}`); | ||
| return (await fsCore.readdir(dir)).map((filename) => this.statIgnored(path.join(dir, filename))); | ||
| } | ||
|
|
||
| // Test if a source file is denied, adding any ignored files to | ||
| // the ignoredFiles array for output. | ||
| private isIgnored(filepath: string): boolean { | ||
| if (this.forceIgnore.denies(filepath)) { | ||
| this.logger.debug(`[DENIED]: ${filepath}`); | ||
| return true; | ||
| } | ||
| this.logger.debug(`[ACCEPTED]: ${filepath}`); | ||
| return false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| /* | ||
| * Copyright (c) 2020, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| import * as fs from 'fs'; | ||
| import * as os from 'os'; | ||
| import * as path from 'path'; | ||
| import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; | ||
| import { expect } from 'chai'; | ||
| import { AuthStrategy } from '@salesforce/cli-plugins-testkit/lib/hubAuth'; | ||
| import { SourceIgnoredResults } from '../../src/commands/force/source/ignored/list'; | ||
|
|
||
| describe('force:source:ignored:list', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we test the "no ignored files" possibility? |
||
| let session: TestSession; | ||
| let forceIgnorePath: string; | ||
| let originalForceIgnore; | ||
|
|
||
| const pathToIgnoredFile1 = path.join('foo-bar', 'app', 'classes', 'FooBar.cls'); | ||
| const pathToIgnoredFile2 = path.join('foo-bar', 'app', 'classes', 'FooBar.cls-meta.xml'); | ||
|
|
||
| before(async () => { | ||
| session = await TestSession.create({ | ||
| project: { | ||
| gitClone: 'https://github.com/salesforcecli/sample-project-multiple-packages', | ||
| }, | ||
| authStrategy: AuthStrategy.NONE, | ||
| }); | ||
| forceIgnorePath = path.join(session.project.dir, '.forceignore'); | ||
| originalForceIgnore = await fs.promises.readFile(forceIgnorePath, 'utf8'); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await session?.clean(); | ||
| }); | ||
|
|
||
| describe('no forceignore', () => { | ||
| before(async () => { | ||
| await fs.promises.rm(forceIgnorePath); | ||
| }); | ||
| after(async () => { | ||
| await fs.promises.writeFile(forceIgnorePath, originalForceIgnore); | ||
| }); | ||
| it('default PkgDir', () => { | ||
| const result = execCmd<SourceIgnoredResults>('force:source:ignored:list --json', { ensureExitCode: 0 }).jsonOutput | ||
| .result; | ||
| expect(result.ignoredFiles).to.deep.equal([]); | ||
| }); | ||
| it('specified sourcePath', () => { | ||
| const result2 = execCmd<SourceIgnoredResults>('force:source:ignored:list --json -p foo-bar', { | ||
| ensureExitCode: 0, | ||
| }).jsonOutput.result; | ||
| expect(result2.ignoredFiles).to.deep.equal([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('no files are ignored (empty forceignore)', () => { | ||
| before(async () => { | ||
| await fs.promises.writeFile(forceIgnorePath, ''); | ||
| }); | ||
| after(async () => { | ||
| await fs.promises.writeFile(forceIgnorePath, originalForceIgnore); | ||
| }); | ||
| it('default PkgDir', () => { | ||
| const result = execCmd<SourceIgnoredResults>('force:source:ignored:list --json', { ensureExitCode: 0 }).jsonOutput | ||
| .result; | ||
| expect(result.ignoredFiles).to.deep.equal([]); | ||
| }); | ||
| it('specified sourcePath', () => { | ||
| const result2 = execCmd<SourceIgnoredResults>('force:source:ignored:list --json -p foo-bar', { | ||
| ensureExitCode: 0, | ||
| }).jsonOutput.result; | ||
| expect(result2.ignoredFiles).to.deep.equal([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('returns an ignored class using specified path in forceignore', () => { | ||
| before(async () => { | ||
| // forceignore uses a library that wants ignore rules in posix format. | ||
| await fs.promises.appendFile( | ||
| forceIgnorePath, | ||
| `${path.normalize(pathToIgnoredFile1).split(path.sep).join(path.posix.sep)}${os.EOL}` | ||
| ); | ||
| await fs.promises.appendFile( | ||
| forceIgnorePath, | ||
| `${path.normalize(pathToIgnoredFile2).split(path.sep).join(path.posix.sep)}${os.EOL}` | ||
| ); | ||
| }); | ||
| after(async () => { | ||
| await fs.promises.writeFile(forceIgnorePath, originalForceIgnore); | ||
| }); | ||
| it('default PkgDir', () => { | ||
| const result = execCmd<SourceIgnoredResults>('force:source:ignored:list --json', { ensureExitCode: 0 }).jsonOutput | ||
| .result; | ||
| expect(result.ignoredFiles).to.include(pathToIgnoredFile1); | ||
| expect(result.ignoredFiles).to.include(pathToIgnoredFile2); | ||
| }); | ||
| it('specified sourcePath', () => { | ||
| const result2 = execCmd<SourceIgnoredResults>('force:source:ignored:list --json -p foo-bar', { | ||
| ensureExitCode: 0, | ||
| }).jsonOutput.result; | ||
| expect(result2.ignoredFiles).to.include(pathToIgnoredFile1); | ||
| expect(result2.ignoredFiles).to.include(pathToIgnoredFile2); | ||
| }); | ||
| }); | ||
|
|
||
| describe('returns an ignored class using wildcards', () => { | ||
| before(async () => { | ||
| await fs.promises.appendFile(forceIgnorePath, '**/FooBar.*'); | ||
| }); | ||
| after(async () => { | ||
| await fs.promises.writeFile(forceIgnorePath, originalForceIgnore); | ||
| }); | ||
|
|
||
| it('default PkgDir', () => { | ||
| const result = execCmd<SourceIgnoredResults>('force:source:ignored:list --json', { ensureExitCode: 0 }).jsonOutput | ||
| .result; | ||
| expect(result.ignoredFiles).to.include(pathToIgnoredFile1); | ||
| expect(result.ignoredFiles).to.include(pathToIgnoredFile2); | ||
| }); | ||
| it('specified sourcePath', () => { | ||
| const result2 = execCmd<SourceIgnoredResults>('force:source:ignored:list --json -p foo-bar', { | ||
| ensureExitCode: 0, | ||
| }).jsonOutput.result; | ||
| expect(result2.ignoredFiles).to.include(pathToIgnoredFile1); | ||
| expect(result2.ignoredFiles).to.include(pathToIgnoredFile2); | ||
| }); | ||
| }); | ||
|
|
||
| describe('returns an ignored non-metadata component', () => { | ||
| const lwcDir = path.join('foo-bar', 'app', 'lwc'); | ||
| const lwcConfigPath = path.join(lwcDir, 'jsconfig.json'); | ||
|
|
||
| before(async () => { | ||
| await fs.promises.mkdir(path.join(session.project.dir, lwcDir), { recursive: true }); | ||
| await fs.promises.writeFile(path.join(session.project.dir, lwcConfigPath), '{}'); | ||
| }); | ||
| after(async () => { | ||
| await fs.promises.writeFile(forceIgnorePath, originalForceIgnore); | ||
| }); | ||
|
|
||
| it('default PkgDir', () => { | ||
| const result = execCmd<SourceIgnoredResults>('force:source:ignored:list --json', { ensureExitCode: 0 }).jsonOutput | ||
| .result; | ||
| expect(result.ignoredFiles).to.include(lwcConfigPath); | ||
| }); | ||
| it('specified sourcePath', () => { | ||
| const result2 = execCmd<SourceIgnoredResults>('force:source:ignored:list --json -p foo-bar', { | ||
| ensureExitCode: 0, | ||
| }).jsonOutput.result; | ||
| expect(result2.ignoredFiles).to.include(lwcConfigPath); | ||
| }); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this message used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call...not anymore. SDR is gonna handle that