aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/modules/typescript
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@theqtcompany.com>2016-03-23 09:04:43 -0700
committerJake Petroules <jake.petroules@theqtcompany.com>2016-03-24 16:27:50 +0000
commite6d4dbb52021ad9d9047d3e2fe12b8d598772d9c (patch)
tree454509edc896326695e86e572a6076874cbfb0dc /share/qbs/modules/typescript
parentd092d287b3b287fed52128263cd6dd6d7ff054cd (diff)
Fix typescript module to work with newer TypeScript versions.
Change-Id: I068413c66349037da82c97d67cdff65b5846bf90 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'share/qbs/modules/typescript')
-rw-r--r--share/qbs/modules/typescript/TypeScriptModule.qbs62
-rw-r--r--share/qbs/modules/typescript/typescript.js18
2 files changed, 74 insertions, 6 deletions
diff --git a/share/qbs/modules/typescript/TypeScriptModule.qbs b/share/qbs/modules/typescript/TypeScriptModule.qbs
index 5173fb916..fbcd4fcf0 100644
--- a/share/qbs/modules/typescript/TypeScriptModule.qbs
+++ b/share/qbs/modules/typescript/TypeScriptModule.qbs
@@ -47,6 +47,7 @@ Module {
Probes.TypeScriptProbe {
id: tsc
+ interpreterPath: FileInfo.path(nodejs.interpreterFilePath)
packageManagerBinPath: nodejs.packageManagerBinPath
packageManagerRootPath: nodejs.packageManagerRootPath
}
@@ -78,7 +79,7 @@ Module {
PropertyOptions {
name: "targetVersion"
description: "ECMAScript target version"
- allowedValues: ["ES3", "ES5"]
+ allowedValues: ["ES3", "ES5", "ES2015"]
}
property string moduleLoader
@@ -120,6 +121,22 @@ Module {
}
validate: {
+ var interpreterMessage = "TypeScript requires the Node.js interpreter to be called 'node'.";
+ if (File.exists("/etc/debian_version")) {
+ interpreterMessage += " Did you forget to install the nodejs-legacy package? " +
+ "See https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html " +
+ "for more information.";
+ }
+
+ var preValidator = new ModUtils.PropertyValidator("nodejs");
+ preValidator.addCustomValidator("interpreterFileName", nodejs.interpreterFileName, function (value) {
+ return value === "node" + (qbs.hostOS.contains("windows") ? ".exe" : "");
+ }, interpreterMessage);
+ preValidator.addCustomValidator("interpreterFilePath", nodejs.interpreterFilePath, function (value) {
+ return value.endsWith(nodejs.interpreterFileName);
+ }, interpreterMessage);
+ preValidator.validate();
+
var validator = new ModUtils.PropertyValidator("typescript");
validator.setRequiredProperty("toolchainInstallPath", toolchainInstallPath);
validator.setRequiredProperty("compilerName", compilerName);
@@ -158,7 +175,8 @@ Module {
name: "io.qt.qbs.internal.typescript-helper"
files: [
FileInfo.joinPaths(path, "qbs-tsc-scan", "qbs-tsc-scan.ts"),
- FileInfo.joinPaths(typescript.toolchainLibInstallPath, "typescript.d.ts")
+ FileInfo.joinPaths(typescript.toolchainLibInstallPath, "typescript.d.ts"),
+ FileInfo.joinPaths(typescript.toolchainLibInstallPath, "..", "package.json")
]
fileTags: ["typescript.typescript-internal"]
}
@@ -173,6 +191,23 @@ Module {
return [];
return [{
filePath: FileInfo.joinPaths(product.buildDirectory,
+ ".io.qt.qbs.internal.typescript", "qbs-tsc-scan.ts"),
+ fileTags: ["typescript.typescript-internal.copy"]
+ },
+ {
+ filePath: FileInfo.joinPaths(product.buildDirectory,
+ ".io.qt.qbs.internal.typescript",
+ "node_modules", "typescript", "lib", "typescript.d.ts"),
+ fileTags: ["typescript.typescript-internal.copy"]
+ },
+ {
+ filePath: FileInfo.joinPaths(product.buildDirectory,
+ ".io.qt.qbs.internal.typescript",
+ "node_modules", "typescript", "package.json"),
+ fileTags: ["typescript.typescript-internal.copy"]
+ },
+ {
+ filePath: FileInfo.joinPaths(product.buildDirectory,
".io.qt.qbs.internal.typescript", "qbs-tsc-scan.js"),
fileTags: ["typescript.compiled_typescript-internal"]
}];
@@ -183,11 +218,30 @@ Module {
return input.filePath;
});
+ var outputPaths = outputs["typescript.typescript-internal.copy"].map(function (output) {
+ return output.filePath;
+ });
+
+ var sortFunc = function (a, b) {
+ return FileInfo.fileName(a).localeCompare(FileInfo.fileName(b));
+ };
+
+ var jcmd = new JavaScriptCommand();
+ jcmd.silent = true;
+ jcmd.inputPaths = inputPaths.sort(sortFunc);
+ jcmd.outputPaths = outputPaths.sort(sortFunc);
+ jcmd.sourceCode = function() {
+ for (var i = 0; i < inputPaths.length; ++i)
+ File.copy(inputPaths[i], outputPaths[i]);
+ };
+
+ var outDir = FileInfo.path(
+ outputs["typescript.compiled_typescript-internal"][0].filePath);
var args = ["--module", "commonjs",
- "--outDir", FileInfo.path(output.filePath)].concat(inputPaths);
+ "--outDir", outDir].concat(outputPaths.filter(function (f) { return !f.endsWith(".json"); }));
var cmd = new Command(ModUtils.moduleProperty(product, "compilerPath"), args);
cmd.silent = true;
- return [cmd];
+ return [jcmd, cmd];
}
}
diff --git a/share/qbs/modules/typescript/typescript.js b/share/qbs/modules/typescript/typescript.js
index 96bd6ec69..d7b7db9b7 100644
--- a/share/qbs/modules/typescript/typescript.js
+++ b/share/qbs/modules/typescript/typescript.js
@@ -92,7 +92,7 @@ function tscArguments(product, inputs) {
args.push("--outDir", product.buildDirectory);
if (ModUtils.moduleProperty(product, "singleFile")) {
- args.push("--out",
+ args.push(outOption(product),
FileInfo.joinPaths(product.destinationDirectory, product.targetName) + ".js");
}
@@ -129,7 +129,10 @@ function outputArtifacts(product, inputs) {
var process;
try {
process = new Process();
- process.setEnv("NODE_PATH", ModUtils.moduleProperty(product, "toolchainInstallPath"));
+ process.setEnv("NODE_PATH", [
+ ModUtils.moduleProperty(product, "toolchainInstallPath"),
+ product.moduleProperty("nodejs", "packageManagerRootPath")
+ ].join(product.moduleProperty("qbs", "pathListSeparator")));
process.exec(product.moduleProperty("nodejs", "interpreterFilePath"),
[FileInfo.joinPaths(product.buildDirectory,
".io.qt.qbs.internal.typescript",
@@ -247,6 +250,17 @@ function legacyOutputArtifacts(product, inputs) {
return artifacts;
}
+function outOption(product) {
+ var compilerVersionMajor = ModUtils.moduleProperty(product, "versionMajor");
+ if (compilerVersionMajor === 1) {
+ if (ModUtils.moduleProperty(product, "versionMinor") < 6) {
+ return "--out";
+ }
+ }
+
+ return "--outFile";
+}
+
function supportsModernFeatures(product) {
var compilerVersionMajor = ModUtils.moduleProperty(product, "versionMajor");
if (compilerVersionMajor === 1) {