Skip to content

Commit 897c328

Browse files
committed
fix: handling desktop non-matching cwd scenarios for projectPath
1 parent f35cef0 commit 897c328

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/client/deployMessages.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ export const createResponses =
117117
...response,
118118
filePath:
119119
// deployResults will produce filePaths relative to cwd, which might not be set in all environments
120-
// if our CS had a projectDir set, we'll make the results relative to that path
121-
projectPath && process.cwd() === projectPath ? response.filePath : join(projectPath ?? '', response.filePath),
120+
// if our CS had a projectDir set, we'll make the results relative to that path unless it already is
121+
projectPath && process.cwd() !== projectPath && !response.filePath.startsWith(projectPath)
122+
? join(projectPath, response.filePath)
123+
: response.filePath,
122124
})) satisfies FileResponseSuccess[];
123125
});
124126

src/resolve/treeContainers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export abstract class TreeContainer {
6363

6464
/** if the container has cwd set, apply it to the path */
6565
protected getUpdatedFsPath(fsPath: SourcePath): string {
66-
return this.cwd ? join(this.cwd, fsPath) : fsPath;
66+
return this.cwd && !fsPath.startsWith(this.cwd) ? join(this.cwd, fsPath) : fsPath;
6767
}
6868

6969
/**

test/resolve/treeContainers.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,34 @@ describe('Tree Containers', () => {
141141
env.stub(fs, 'existsSync').returns(true);
142142
expect(tree.stream(path)).to.deep.equal(readable);
143143
});
144+
145+
describe('with projectPath/cwd', () => {
146+
let projectPath: string;
147+
// mocking fs will defeat the goal of these tests, so we'll use the real one and clean it up
148+
before(async () => {
149+
projectPath = join('path', 'to', 'project');
150+
await fs.promises.mkdir(projectPath, { recursive: true });
151+
await fs.promises.writeFile(join(projectPath, 'test.txt'), 'test');
152+
});
153+
154+
after(async () => {
155+
await fs.promises.rm(projectPath, { recursive: true });
156+
});
157+
158+
it('should return the path as is if it is already relative to the project path', () => {
159+
const tree = new NodeFSTreeContainer(projectPath);
160+
const path = join(projectPath, 'test.txt');
161+
expect(tree.exists(path)).to.be.true;
162+
expect(tree.readDirectory(projectPath)).to.deep.equal(['test.txt']);
163+
});
164+
165+
it('should add the project path to the path if it is not already relative to the project path', () => {
166+
const tree = new NodeFSTreeContainer(projectPath);
167+
const path = 'test.txt';
168+
expect(tree.exists(path)).to.be.true;
169+
expect(tree.readDirectory(projectPath)).to.deep.equal(['test.txt']);
170+
});
171+
});
144172
});
145173

146174
describe('ZipTreeContainer', () => {

0 commit comments

Comments
 (0)