Skip to content

Commit 1baf546

Browse files
committed
Gulp fails miserably with symlinks in node_modules, use glob and stat instead
Get correct stat of file In some cases glob module caches the file's stat with relative paths, in other - with full paths. Make sure we have correct stat by checking relative and full path and in case they are both null, stat the file on our own glob uses forward slashes on Windows, normalize glob paths
1 parent f134094 commit 1baf546

File tree

2 files changed

+47
-30
lines changed

2 files changed

+47
-30
lines changed

lib/tools/broccoli/builder.ts

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import * as constants from "../../../lib/constants";
55
import * as path from "path";
66
import Future = require("fibers/future");
77
import * as destCopyLib from "./node-modules-dest-copy";
8+
import * as fiberBootstrap from "../../common/fiber-bootstrap";
89

9-
let gulp = require("gulp");
10-
let vinylFilterSince = require("vinyl-filter-since");
11-
let through = require("through2");
10+
let glob = require("glob");
1211

1312
export class Builder implements IBroccoliBuilder {
1413
constructor(
@@ -28,30 +27,50 @@ export class Builder implements IBroccoliBuilder {
2827
let nodeModulesPath = path.join(projectDir, constants.NODE_MODULES_FOLDER_NAME);
2928
let nodeModules: any = {};
3029

31-
if(lastModifiedTime) {
32-
let pipeline = gulp.src(path.join(projectDir, "node_modules/**"))
33-
.pipe(vinylFilterSince(lastModifiedTime))
34-
.pipe(through.obj( (chunk: any, enc: any, cb: Function) => {
35-
if(chunk.path === nodeModulesPath) {
36-
isNodeModulesModified = true;
37-
}
38-
39-
if(!isNodeModulesModified) {
40-
let rootModuleName = chunk.path.split(nodeModulesPath)[1].split(path.sep)[1];
41-
let rootModuleFullPath = path.join(nodeModulesPath, rootModuleName);
42-
nodeModules[rootModuleFullPath] = rootModuleFullPath;
43-
}
44-
45-
cb(null);
46-
}))
47-
.pipe(gulp.dest(absoluteOutputPath));
48-
49-
let future = new Future<void>();
50-
51-
pipeline.on('end', (err: Error, data: any) => {
52-
if(err) {
53-
future.throw(err);
54-
} else {
30+
if (lastModifiedTime) {
31+
let future = new Future();
32+
33+
let match = new glob.Glob("node_modules/**", {
34+
cwd: projectDir,
35+
follow: true,
36+
stat: true
37+
}, (er: Error, files: string[]) => {
38+
fiberBootstrap.run(() => {
39+
if (er) {
40+
if (!future.isResolved()) {
41+
future.throw(er);
42+
}
43+
match.abort();
44+
return;
45+
}
46+
for (let i = 0, l = files.length; i < l; i++) {
47+
let file = files[i],
48+
resolvedPath = path.join(projectDir, file),
49+
relativePath = path.relative(projectDir, resolvedPath);
50+
let stat = match.statCache[resolvedPath] || match.statCache[relativePath];
51+
if (!stat) {
52+
match.statCache[resolvedPath] = stat = this.$fs.getFsStats(resolvedPath).wait();
53+
}
54+
55+
if (stat.mtime <= lastModifiedTime) {
56+
continue;
57+
}
58+
if (file === constants.NODE_MODULES_FOLDER_NAME) {
59+
isNodeModulesModified = true;
60+
match.abort();
61+
if (!future.isResolved()) {
62+
future.return();
63+
}
64+
return;
65+
}
66+
let rootModuleName = path.normalize(file).split(path.sep)[1];
67+
let rootModuleFullPath = path.join(nodeModulesPath, rootModuleName);
68+
nodeModules[rootModuleFullPath] = rootModuleFullPath;
69+
}
70+
});
71+
});
72+
match.on("end", () => {
73+
if (!future.isResolved()) {
5574
future.return();
5675
}
5776
});

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"fibers": "https://github.com/icenium/node-fibers/tarball/v1.0.6.3",
4141
"filesize": "3.1.2",
4242
"gaze": "0.5.2",
43-
"gulp": "3.9.0",
43+
"glob": "^7.0.3",
4444
"iconv-lite": "0.4.11",
4545
"inquirer": "0.9.0",
4646
"ios-sim-portable": "~1.0.20",
@@ -69,9 +69,7 @@
6969
"shelljs": "0.5.3",
7070
"tabtab": "https://github.com/Icenium/node-tabtab/tarball/master",
7171
"temp": "0.8.3",
72-
"through2": "2.0.0",
7372
"utf-8-validate": "https://github.com/telerik/utf-8-validate/tarball/v1.0.1.1",
74-
"vinyl-filter-since": "2.0.2",
7573
"winreg": "0.0.17",
7674
"ws": "0.7.1",
7775
"xcode": "https://github.com/NativeScript/node-xcode/archive/1.4.0.tar.gz",

0 commit comments

Comments
 (0)