10000 Fix: Normalize file paths in file operations for Windows compatibility by hd140283 · Pull Request #1044 · google/clasp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix: Normalize file paths in file operations for Windows compatibility #1044

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 1 commit into from
Mar 26, 2025
Merged
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
4 changes: 2 additions & 2 deletions src/core/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class Files {
const localPath = path.relative(process.cwd(), path.join(contentDir, filename));
const resolvedPath = path.relative(contentDir, localPath);
const parsedPath = path.parse(resolvedPath);
let remotePath = path.format({dir: normalizePath(parsedPath.dir), name: parsedPath.name});
let remotePath = normalizePath(path.format({dir: parsedPath.dir, name: parsedPath.name}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the remote filepath format be dependent on the local OS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify:

The remote path is normalized using normalize-path, so it's always converted to POSIX format (/), regardless of th 8000 e local OS. This ensures consistent behavior across different environments.

That logic was implemented in my PR and has already been merged into the master branch — but it hasn’t been released to NPM yet.

If you're using the latest published version of @google/clasp, the change may not be included yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just moved normalizePath() to wrap the result of path.format(), since path.format() is OS-dependent.


const type = getFileType(localPath, fileExtensionMap);
if (!type) {
Expand Down Expand Up @@ -293,7 +293,7 @@ export class Files {
if (dirsWithIncludedFiles.has(dir)) {
break;
}
excludedPath = `${dir}/`;
excludedPath = path.normalize(`${dir}/`);
}
debug('Found untracked file %s', excludedPath);
untrackedFiles.add(excludedPath);
Expand Down
12 changes: 6 additions & 6 deletions test/core/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ describe('File operations', function () {
});
const pulledFiles = await clasp.files.pull();
expect(pulledFiles).to.have.length(2);
expect(pulledFiles[0].localPath).to.equal('dist/appsscript.json');
expect(pulledFiles[1].localPath).to.equal('dist/Code.js');
expect(pulledFiles[0].localPath).to.equal(path.normalize('dist/appsscript.json'));
expect(pulledFiles[1].localPath).to.equal(path.normalize('dist/Code.js'));
});

afterEach(function () {
Expand Down Expand Up @@ -450,10 +450,10 @@ describe('File operations', function () {
credentials: mockCredentials(),
});
const foundFiles = await clasp.files.getUntrackedFiles();
expect(foundFiles).to.include('node_modules/');
expect(foundFiles).to.not.include('node_modules/test/');
expect(foundFiles).to.not.include('node_modules/test/file1.js');
expect(foundFiles).to.include('src/readme.md');
expect(foundFiles).to.include(path.normalize('node_modules/'));
expect(foundFiles).to.not.include(path.normalize('node_modules/test/'));
expect(foundFiles).to.not.include(path.normalize('node_modules/test/file1.js'));
expect(foundFiles).to.include(path.normalize('src/readme.md'));
});
});

Expand Down
0