Skip to content

Commit

Permalink
Hack around chokidar's path problems
Browse files Browse the repository at this point in the history
cokidar doesn't like paths which contain glob patterns.
See paulmillr/chokidar#300
Prefer relative paths to make problems less likely.
  • Loading branch information
RobDangerous committed Aug 23, 2016
1 parent e97fead commit 3d1d23d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
23 changes: 21 additions & 2 deletions out/Project.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions src/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export class Target {
}
}

function contains(main, sub) {
main = path.resolve(main);
sub = path.resolve(sub);
if (process.platform === 'win32') {
main = main.toLowerCase();
sub = sub.toLowerCase();
}
return sub.indexOf(main) === 0 && sub.slice(main.length)[0] === path.sep;
}

export class Project {
name: string;
sources: Array<string>;
Expand Down Expand Up @@ -64,7 +74,14 @@ export class Project {
*/
addAssets(match: string, options: any) {
if (!options) options = {};
this.assetMatchers.push({ match: path.resolve(this.scriptdir, match), options: options });

// try to avoid weird paths - remove when https://github.com/paulmillr/chokidar/issues/300 is fixed
match = path.resolve(this.scriptdir, match);
if (contains(process.cwd(), match)) {
match = path.relative(process.cwd(), match);
}

this.assetMatchers.push({ match: match, options: options });
}

addSources(source) {
Expand All @@ -77,7 +94,14 @@ export class Project {
*/
addShaders(match: string, options: any) {
if (!options) options = {};
this.shaderMatchers.push({ match: path.resolve(this.scriptdir, match), options: options });

// try to avoid weird paths - remove when https://github.com/paulmillr/chokidar/issues/300 is fixed
match = path.resolve(this.scriptdir, match);
if (contains(process.cwd(), match)) {
match = path.relative(process.cwd(), match);
}

this.shaderMatchers.push({ match: match, options: options });
}

addDefine(define) {
Expand Down

0 comments on commit 3d1d23d

Please sign in to comment.