Skip to content

Commit

Permalink
Add support for windows paths for glob sync
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Jun 9, 2023
1 parent 4faaf2f commit a317de1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 40 deletions.
66 changes: 26 additions & 40 deletions src/cmd/cloud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ describe('Cloud Commands', () => {
await cloud._processDirIncludes(fileMapping, dir);

expect(fileMapping.map).to.eql({
[path.join('src', 'app.cpp')]: path.join('src', 'app.cpp'),
[path.join('lib', 'spi', 'src', 'spi.c')]: path.join('lib', 'spi', 'src', 'spi.c'),
[path.join('lib', 'spi', 'src', 'spi.h')]: path.join('lib', 'spi', 'src', 'spi.h')
[path.join('src/app.cpp')]: path.join('src/app.cpp'),
[path.join('lib/spi/src/spi.c')]: path.join('lib/spi/src/spi.c'),
[path.join('lib/spi/src/spi.h')]: path.join('lib/spi/src/spi.h')
});
});
});
Expand Down Expand Up @@ -397,12 +397,12 @@ describe('Cloud Commands', () => {
await cloud._processDirIncludes(fileMapping, dir);

expect(fileMapping.map).to.eql({
[path.join('src', 'app.cpp')]: path.join('src', 'app.cpp'),
[path.join('src', 'app.def')]: path.join('src', 'app.def'),
[path.join('lib', 'spi', 'src', 'spi.c')]: path.join('lib', 'spi', 'src', 'spi.c'),
[path.join('lib', 'spi', 'src', 'spi.h')]: path.join('lib', 'spi', 'src', 'spi.h'),
[path.join('lib', 'spi', 'src', 'spi.def')]: path.join('lib', 'spi', 'src', 'spi.def'),
[path.join('lib', 'spi', 'src', 'spi.cmd')]: path.join('lib', 'spi', 'src', 'spi.cmd')
[path.join('src/app.cpp')]: path.join('src/app.cpp'),
[path.join('src/app.def')]: path.join('src/app.def'),
[path.join('lib/spi/src/spi.c')]: path.join('lib/spi/src/spi.c'),
[path.join('lib/spi/src/spi.h')]: path.join('lib/spi/src/spi.h'),
[path.join('lib/spi/src/spi.def')]: path.join('lib/spi/src/spi.def'),
[path.join('lib/spi/src/spi.cmd')]: path.join('lib/spi/src/spi.cmd')
});
});
});
Expand All @@ -420,9 +420,9 @@ describe('Cloud Commands', () => {
await cloud._processDirIncludes(fileMapping, dir);

expect(fileMapping.map).to.eql({
[path.join('src', 'app.cpp')]: path.join('src', 'app.cpp'),
[path.join('lib', 'spi', 'src', 'spi.c')]: path.join('lib', 'spi', 'src', 'spi.c'),
[path.join('lib', 'spi', 'src', 'spi.h')]: path.join('lib', 'spi', 'src', 'spi.h')
[path.join('src/app.cpp')]: path.join('src/app.cpp'),
[path.join('lib/spi/src/spi.c')]: path.join('lib/spi/src/spi.c'),
[path.join('lib/spi/src/spi.h')]: path.join('lib/spi/src/spi.h')
});
});
});
Expand All @@ -443,10 +443,10 @@ describe('Cloud Commands', () => {
await cloud._processDirIncludes(fileMapping, dir);

expect(fileMapping.map).to.eql({
[path.join('src', 'app.cpp')]: path.join('src', 'app.cpp'),
[path.join('lib', 'spi', 'src', 'spi.c')]: path.join('lib', 'spi', 'src', 'spi.c'),
[path.join('lib', 'spi', 'src', 'spi.h')]: path.join('lib', 'spi', 'src', 'spi.h'),
[path.join('lib', 'spi', 'src', 'spi.txt')]: path.join('lib', 'spi', 'src', 'spi.txt')
[path.join('src/app.cpp')]: path.join('src/app.cpp'),
[path.join('lib/spi/src/spi.c')]: path.join('lib/spi/src/spi.c'),
[path.join('lib/spi/src/spi.h')]: path.join('lib/spi/src/spi.h'),
[path.join('lib/spi/src/spi.txt')]: path.join('lib/spi/src/spi.txt')
});
});
});
Expand Down Expand Up @@ -495,9 +495,9 @@ describe('Cloud Commands', () => {
await cloud._processDirIncludes(fileMapping, dir);

expect(fileMapping.map).to.eql({
[path.join('lib', 'spi', 'src', 'spi.c')]: path.join('lib', 'spi', 'src', 'spi.c'),
[path.join('lib', 'spi', 'src', 'spi.h')]: path.join('lib', 'spi', 'src', 'spi.h'),
[path.join('lib', 'spi', 'src', 'spi.txt')]: path.join('lib', 'spi', 'src', 'spi.txt')
[path.join('lib/spi/src/spi.c')]: path.join('lib/spi/src/spi.c'),
[path.join('lib/spi/src/spi.h')]: path.join('lib/spi/src/spi.h'),
[path.join('lib/spi/src/spi.txt')]: path.join('lib/spi/src/spi.txt')
});
});
});
Expand All @@ -517,9 +517,7 @@ describe('Cloud Commands', () => {

cloud._getDefaultIncludes(files, dir, {});

let filesArr = Array.from(files);
filesArr.forEach(file => path.resolve(file));
expect([...filesArr]).to.have.same.members([
expect([...files]).to.have.same.members([
path.resolve(dir, 'src/app.cpp'),
path.resolve(dir, 'lib/spi/src/spi.c'),
path.resolve(dir, 'lib/spi/src/spi.h'),
Expand All @@ -542,9 +540,7 @@ describe('Cloud Commands', () => {

cloud._getDefaultIncludes(files, dir, {} );

let filesArr = Array.from(files);
filesArr.forEach(file => path.resolve(file));
expect([...filesArr]).to.have.same.members([
expect([...files]).to.have.same.members([
path.resolve(dir, 'src/app.cpp'),
path.resolve(dir, 'lib/spi/src/spi.c'),
path.resolve(dir, 'lib/spi/src/spi.h')
Expand All @@ -568,9 +564,7 @@ describe('Cloud Commands', () => {

cloud._getCustomIncludes(files, dir, {} );

let filesArr = Array.from(files);
filesArr.forEach(file => path.resolve(file));
expect([...filesArr]).to.have.same.members([
expect([...files]).to.have.same.members([
path.resolve(dir, 'src/app.def')
]);
});
Expand All @@ -595,9 +589,7 @@ describe('Cloud Commands', () => {

cloud._getCustomIncludes(files, dir, {} );

let filesArr = Array.from(files);
filesArr.forEach(file => path.resolve(file));
expect([...filesArr]).to.have.same.members([
expect([...files]).to.have.same.members([
path.resolve(dir, 'src/app.def'),
path.resolve(dir, 'src/file.txt')
]);
Expand All @@ -624,9 +616,7 @@ describe('Cloud Commands', () => {

cloud._getCustomIncludes(files, dir, {} );

let filesArr = Array.from(files);
filesArr.forEach(file => path.resolve(file));
expect([...filesArr]).to.have.same.members([
expect([...files]).to.have.same.members([
path.resolve(dir, 'src/app.def'),
path.resolve(dir, 'lib/file.txt'),
path.resolve(dir, 'lib/file.def')
Expand Down Expand Up @@ -654,9 +644,7 @@ describe('Cloud Commands', () => {

cloud._getCustomIncludes(files, dir, {} );

let filesArr = Array.from(files);
filesArr.forEach(file => path.resolve(file));
expect([...filesArr]).to.have.same.members([
expect([...files]).to.have.same.members([
path.resolve(dir, 'src/app.def'),
path.resolve(dir, 'lib/file.txt'),
path.resolve(dir, 'lib/file.def')
Expand Down Expand Up @@ -700,9 +688,7 @@ describe('Cloud Commands', () => {

cloud._getCustomIncludes(files, dir, {} );

let filesArr = Array.from(files);
filesArr.forEach(file => path.resolve(file));
expect([...filesArr]).to.have.same.members([
expect([...files]).to.have.same.members([
path.resolve(dir, 'src/app.def')
]);
});
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ License along with this program; if not, see <http://www.gnu.org/licenses/>.

const fs = require('fs');
const _ = require('lodash');
const os = require('os');
const path = require('path');
const glob = require('glob');
const VError = require('verror');
Expand Down Expand Up @@ -205,6 +206,10 @@ module.exports = {
line = path.join(basepath, line);
}
found = glob.sync(line, { nodir: true, follow: !!followSymlinks });
if (os.platform() === 'win32') {
// because glob pattern is always in posix format
found = found.map(file => path.win32.normalize(file));
}

if (found && (found.length > 0)){
files = files.concat(found);
Expand Down

0 comments on commit a317de1

Please sign in to comment.