Skip to content

Commit 3507ed0

Browse files
committed
Fixes issues that were causing runtests-browser to fail
1 parent 9b8436c commit 3507ed0

7 files changed

Lines changed: 44 additions & 7 deletions

File tree

Jakefile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile
909909

910910
desc("Runs browserify on run.js to produce a file suitable for running tests in the browser");
911911
task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() {
912-
var cmd = 'browserify built/local/run.js -o built/local/bundle.js';
912+
var cmd = 'browserify built/local/run.js -t ./scripts/browserify-optional -o built/local/bundle.js';
913913
exec(cmd);
914914
}, {async: true});
915915

scripts/browserify-optional.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// simple script to optionally elide source-map-support (or other optional modules) when running browserify.
2+
3+
var stream = require("stream"),
4+
Transform = stream.Transform,
5+
resolve = require("browser-resolve");
6+
7+
var requirePattern = /require\s*\(\s*['"](source-map-support)['"]\s*\)/;
8+
module.exports = function (file) {
9+
return new Transform({
10+
transform: function (data, encoding, cb) {
11+
var text = encoding === "buffer" ? data.toString("utf8") : data;
12+
this.push(new Buffer(text.replace(requirePattern, function (originalText, moduleName) {
13+
try {
14+
resolve.sync(moduleName, { filename: file });
15+
return originalText;
16+
}
17+
catch (e) {
18+
return "(function () { throw new Error(\"module '" + moduleName + "' not found.\"); })()";
19+
}
20+
}), "utf8"));
21+
cb();
22+
}
23+
});
24+
};

src/compiler/program.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@ namespace ts {
644644
fileExists: fileName => sys.fileExists(fileName),
645645
readFile: fileName => sys.readFile(fileName),
646646
trace: (s: string) => sys.write(s + newLine),
647-
directoryExists: directoryName => sys.directoryExists(directoryName)
647+
directoryExists: directoryName => sys.directoryExists(directoryName),
648+
getEnvironmentVariable: sys.getEnvironmentVariable
648649
};
649650
}
650651

@@ -995,7 +996,7 @@ namespace ts {
995996
const start = new Date().getTime();
996997

997998
// TODO(rbuckton): remove USE_TRANSFORMS condition when we switch to transforms permanently.
998-
if (/^(y(es)?|t(rue|ransforms?)?|1|\+)$/i.test(sys.getEnvironmentVariable("USE_TRANSFORMS"))) {
999+
if (/^(y(es)?|t(rue|ransforms?)?|1|\+)$/i.test(getEnvironmentVariable("USE_TRANSFORMS", host))) {
9991000
options.experimentalTransforms = true;
10001001
}
10011002

src/compiler/sys.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ namespace ts {
7474
readDirectory(path: string, extension?: string, exclude?: string[]): string[];
7575
watchFile?(path: string, callback: FileWatcherCallback): FileWatcher;
7676
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
77+
getEnvironmentVariable?(name: string): string;
7778
};
7879

7980
export var sys: System = (function () {
@@ -632,9 +633,7 @@ namespace ts {
632633
createDirectory: ChakraHost.createDirectory,
633634
getExecutingFilePath: () => ChakraHost.executingFile,
634635
getCurrentDirectory: () => ChakraHost.currentDirectory,
635-
getEnvironmentVariable(name: string) {
636-
return "";
637-
},
636+
getEnvironmentVariable: ChakraHost.getEnvironmentVariable || ((name: string) => ""),
638637
readDirectory: ChakraHost.readDirectory,
639638
exit: ChakraHost.quit,
640639
};

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,6 +2805,7 @@ namespace ts {
28052805
* 'throw new Error("NotImplemented")'
28062806
*/
28072807
resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[];
2808+
getEnvironmentVariable?(name: string): string;
28082809
}
28092810

28102811
/* @internal */

src/compiler/utilities.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ namespace ts {
169169
return `${ file.fileName }(${ loc.line + 1 },${ loc.character + 1 })`;
170170
}
171171

172+
export function getEnvironmentVariable(name: string, host?: CompilerHost) {
173+
if (host && host.getEnvironmentVariable) {
174+
return host.getEnvironmentVariable(name);
175+
}
176+
177+
if (sys && sys.getEnvironmentVariable) {
178+
return sys.getEnvironmentVariable(name);
179+
}
180+
181+
return "";
182+
}
183+
172184
export function getStartPosOfNode(node: Node): number {
173185
return node.pos;
174186
}

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ namespace Harness {
16811681
if (Error) (<any>Error).stackTraceLimit = 1;
16821682
}
16831683

1684-
if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) {
1684+
if (ts.sys && ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) {
16851685
ts.sys.tryEnableSourceMapsForHost();
16861686
}
16871687

0 commit comments

Comments
 (0)