You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compilerSetup.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const semver = require("semver");
  4. const typescript = require("typescript");
  5. function getCompiler(loaderOptions, log) {
  6. let compiler;
  7. let errorMessage;
  8. let compilerDetailsLogMessage;
  9. let compilerCompatible = false;
  10. try {
  11. compiler = require(loaderOptions.compiler);
  12. }
  13. catch (e) {
  14. errorMessage =
  15. loaderOptions.compiler === 'typescript'
  16. ? 'Could not load TypeScript. Try installing with `yarn add typescript` or `npm install typescript`. If TypeScript is installed globally, try using `yarn link typescript` or `npm link typescript`.'
  17. : `Could not load TypeScript compiler with NPM package name \`${loaderOptions.compiler}\`. Are you sure it is correctly installed?`;
  18. }
  19. if (errorMessage === undefined) {
  20. compilerDetailsLogMessage = `ts-loader: Using ${loaderOptions.compiler}@${compiler.version}`;
  21. compilerCompatible = false;
  22. if (loaderOptions.compiler === 'typescript') {
  23. if (compiler.version !== undefined &&
  24. semver.gte(compiler.version, '2.4.1')) {
  25. // don't log yet in this case, if a tsconfig.json exists we want to combine the message
  26. compilerCompatible = true;
  27. }
  28. else {
  29. log.logError(`${compilerDetailsLogMessage}. This version is incompatible with ts-loader. Please upgrade to the latest version of TypeScript.`);
  30. }
  31. }
  32. else {
  33. log.logWarning(`${compilerDetailsLogMessage}. This version may or may not be compatible with ts-loader.`);
  34. }
  35. }
  36. return {
  37. compiler,
  38. compilerCompatible,
  39. compilerDetailsLogMessage,
  40. errorMessage
  41. };
  42. }
  43. exports.getCompiler = getCompiler;
  44. function getCompilerOptions(configParseResult) {
  45. const compilerOptions = Object.assign({}, configParseResult.options, {
  46. skipLibCheck: true,
  47. suppressOutputPathCheck: true // This is why: https://github.com/Microsoft/TypeScript/issues/7363
  48. });
  49. // if `module` is not specified and not using ES6+ target, default to CJS module output
  50. if (compilerOptions.module === undefined &&
  51. (compilerOptions.target !== undefined &&
  52. compilerOptions.target < typescript.ScriptTarget.ES2015)) {
  53. compilerOptions.module = typescript.ModuleKind.CommonJS;
  54. }
  55. return compilerOptions;
  56. }
  57. exports.getCompilerOptions = getCompilerOptions;