Update remove file for sdk style sql projects (#17688)

* add support for removing file in new style project

* fix test

* only load files, not whole project when checking if a <Build Remove> needs to be added

* merge changes

* fixes after merge
This commit is contained in:
Kim Santiago
2021-11-22 14:45:43 -10:00
committed by GitHub
parent 4c191d4acc
commit 33f01054c0
3 changed files with 76 additions and 4 deletions

View File

@@ -17,6 +17,7 @@
<Build Include="..\other\folder1\file*.sql" />
<Build Include="..\other\folder1\test?.sql" />
<Build Include="..\other\folder2\*.sql" />
<Build Include="..\other\file1.sql" />
<Build Include="folder1\*.sql" />
</ItemGroup>
<ItemGroup>

View File

@@ -896,7 +896,7 @@ describe('Project: sdk style project content operations', function (): void {
const project: Project = await Project.openProject(projFilePath);
should(project.files.filter(f => f.type === EntryType.File).length).equal(17);
should(project.files.filter(f => f.type === EntryType.File).length).equal(18);
// make sure all the correct files from the globbing patterns were included
// ..\other\folder1\test?.sql
@@ -967,6 +967,48 @@ describe('Project: sdk style project content operations', function (): void {
should(project.files.filter(f => f.relativePath === 'file1.sql').length).equal(0);
});
it('Should handle excluding files included by glob patterns', async function (): Promise<void> {
const testFolderPath = await testUtils.generateTestFolderPath();
const mainProjectPath = path.join(testFolderPath, 'project');
const otherFolderPath = path.join(testFolderPath, 'other');
projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectWithGlobsSpecifiedBaseline, mainProjectPath);
await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath));
// create files outside of project folder that are included in the project file
await fs.mkdir(otherFolderPath);
await testUtils.createOtherDummyFiles(otherFolderPath);
const project: Project = await Project.openProject(projFilePath);
should(project.files.filter(f => f.type === EntryType.File).length).equal(18);
// exclude a file in the project's folder
should(project.files.filter(f => f.relativePath === 'folder1\\file1.sql').length).equal(1);
await project.exclude(project.files.find(f => f.relativePath === 'folder1\\file1.sql')!);
should(project.files.filter(f => f.relativePath === 'folder1\\file1.sql').length).equal(0);
// exclude explicitly included file from an outside folder
should(project.files.filter(f => f.relativePath === '..\\other\\file1.sql').length).equal(1);
await project.exclude(project.files.find(f => f.relativePath === '..\\other\\file1.sql')!);
should(project.files.filter(f => f.relativePath === '..\\other\\file1.sql').length).equal(0);
// exclude glob included file from an outside folder
should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\test2.sql').length).equal(1);
await project.exclude(project.files.find(f => f.relativePath === '..\\other\\folder1\\test2.sql')!);
should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\test2.sql').length).equal(0);
// make sure a <Build Remove="folder\file1.sql"> was added
const projFileText = (await fs.readFile(projFilePath)).toString();
should(projFileText.includes('<Build Remove="folder1\\file1.sql" />')).equal(true, projFileText);
// make sure <Build Include="..\other\file1.sql"> was removed and no <Build Remove"..."> was added for it
should(projFileText.includes('<Build Include="..\\other\\file1.sql" />')).equal(false, projFileText);
should(projFileText.includes('<Build Remove="..\\other\\file1.sql" />')).equal(false, projFileText);
// make sure a <Build Remove="..\other\folder1\test2.sql"> was added
should(projFileText.includes('<Build Remove="..\\other\\folder1\\test2.sql" />')).equal(true, projFileText);
});
it('Should only add Build entries to sqlproj for files not included by project folder glob and external streaming jobs', async function (): Promise<void> {
projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectBaseline);
const project = await Project.openProject(projFilePath);