Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/debugSession/BrightScriptDebugSession.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1608,8 +1608,13 @@ describe('BrightScriptDebugSession', () => {
sinon.stub(ComponentLibraryProject.prototype, 'stage').resolves();
sinon.stub(ComponentLibraryProject.prototype, 'postfixFiles').resolves();
sinon.stub(ComponentLibraryProject.prototype, 'zipPackage').resolves();
sinon.stub(ComponentLibraryProject.prototype, 'fixMainProjectLibraryDependency').resolves();
session['launchConfiguration'].host = '192.168.1.100';
session['launchConfiguration'].password = 'test123';
session.projectManager.mainProject = <any>{
stagingDir: s`${tempDir}/main-staging`,
zipPackage: sinon.stub().resolves()
};
}

it('installs libraries sequentially when marked install=true', async () => {
Expand Down Expand Up @@ -1683,8 +1688,13 @@ describe('BrightScriptDebugSession', () => {
sinon.stub(rokuDeploy, 'deleteAllComponentLibraries').resolves();
sinon.stub(session['componentLibraryServer'], 'startStaticFileHosting').resolves();
sinon.stub(ComponentLibraryProject.prototype, 'postfixFiles').resolves();
sinon.stub(ComponentLibraryProject.prototype, 'fixMainProjectLibraryDependency').resolves();
session['launchConfiguration'].host = '192.168.1.100';
session['launchConfiguration'].password = 'test123';
session.projectManager.mainProject = <any>{
stagingDir: s`${tempDir}/main-staging`,
zipPackage: sinon.stub().resolves()
};

const events = [];
sinon.stub(ComponentLibraryProject.prototype, 'stage').callsFake(async function(this: ComponentLibraryProject) {
Expand Down
3 changes: 3 additions & 0 deletions src/debugSession/BrightScriptDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,9 @@ export class BrightScriptDebugSession extends BaseDebugSession {
//wait for this complib to finish being staged and zipped
await compLibPromises[i];

await compLibProject.fixMainProjectLibraryDependency(this.projectManager.mainProject.stagingDir);
await this.projectManager.mainProject.zipPackage({ retainStagingFolder: true });

if (componentLibraries[i].packageTask) {
await this.sendCustomRequest('executeTask', { task: componentLibraries[i].packageTask });
}
Expand Down
35 changes: 35 additions & 0 deletions src/managers/ProjectManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,4 +873,39 @@ describe('ComponentLibraryProject', () => {
expect(project.name).to.equal('SGLibrary');
});
});

describe('fixMainProjectLibraryDependency', () => {
const mainStagingDir = s`${tempPath}/mainStagingDir`;

it('replaces Library statement with postfixed filename when file is in fileMappings', async () => {
const project = new ComponentLibraryProject(params);
project.fileMappings = [{
src: s`${rootDir}/source/mylib.brs`,
dest: s`${params.stagingDir}/source/mylib__lib0.brs`
}];
fsExtra.outputFileSync(s`${mainStagingDir}/source/main.brs`, `Library "mylib.brs"`);

await project.fixMainProjectLibraryDependency(mainStagingDir);

expect(
fsExtra.readFileSync(s`${mainStagingDir}/source/main.brs`).toString()
).to.equal(`Library "mylib__lib0.brs"`);
});

it('leaves Library statement unchanged when file is not in fileMappings', async () => {
const project = new ComponentLibraryProject(params);
project.fileMappings = [{
src: s`${rootDir}/source/otherlib.brs`,
dest: s`${params.stagingDir}/source/otherlib__lib0.brs`
}];
const original = `Library "mylib.brs"`;
fsExtra.outputFileSync(s`${mainStagingDir}/source/main.brs`, original);

await project.fixMainProjectLibraryDependency(mainStagingDir);

expect(
fsExtra.readFileSync(s`${mainStagingDir}/source/main.brs`).toString()
).to.equal(original);
});
});
});
25 changes: 25 additions & 0 deletions src/managers/ProjectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,4 +769,29 @@ export class ComponentLibraryProject extends Project {
}
});
}

public async fixMainProjectLibraryDependency(mainProjectStagingDir: string) {
await replaceInFile({
files: [
path.join(mainProjectStagingDir, '**/*.brs')
],
from: /Library\s+"(.+)\.brs"/gi,
to: (match: string) => {
const pathMatch = /"([^"]+)"/.exec(match);
if (!pathMatch) {
return match;
}

const internalPath = pathMatch[1];
const fileNameWithoutExtension = internalPath.replace(/\.brs$/i, '');
for (let fileMapping of this.fileMappings) {
if (fileMapping.dest.includes(fileNameWithoutExtension)) {
const fileWithPostfix = `${fileNameWithoutExtension}${this.postfix}`;
return match.replace(fileNameWithoutExtension, fileWithPostfix);
}
}
return match;
}
});
}
}