index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.run = run;
  4. const runTsc_1 = require("@volar/typescript/lib/quickstart/runTsc");
  5. const vue = require("@vue/language-core");
  6. const windowsPathReg = /\\/g;
  7. function run(tscPath = require.resolve('typescript/lib/tsc')) {
  8. let runExtensions = ['.vue'];
  9. const extensionsChangedException = new Error('extensions changed');
  10. const main = () => (0, runTsc_1.runTsc)(tscPath, runExtensions, (ts, options) => {
  11. const { configFilePath } = options.options;
  12. const vueOptions = typeof configFilePath === 'string'
  13. ? vue.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions
  14. : vue.getDefaultCompilerOptions();
  15. const allExtensions = vue.getAllExtensions(vueOptions);
  16. if (runExtensions.length === allExtensions.length
  17. && runExtensions.every(ext => allExtensions.includes(ext))) {
  18. const vueLanguagePlugin = vue.createVueLanguagePlugin(ts, options.options, vueOptions, id => id);
  19. return { languagePlugins: [vueLanguagePlugin] };
  20. }
  21. else {
  22. runExtensions = allExtensions;
  23. throw extensionsChangedException;
  24. }
  25. });
  26. try {
  27. main();
  28. }
  29. catch (err) {
  30. if (err === extensionsChangedException) {
  31. main();
  32. }
  33. else {
  34. throw err;
  35. }
  36. }
  37. }
  38. //# sourceMappingURL=index.js.map