Skip to content

Commit 24990a8

Browse files
committed
fidgeting with runTsc
1 parent 9d7f77e commit 24990a8

File tree

5 files changed

+86
-10
lines changed

5 files changed

+86
-10
lines changed

Diff for: packages/core/bin/glint.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
#!/usr/bin/env node
2-
import '../lib/cli/index.js';
2+
// @ts-check
3+
import { run } from '../lib/cli/run-volar-tsc.js';
4+
5+
run();

Diff for: packages/core/src/cli/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,25 @@ if (argv.build) {
115115
let projects = [cwd];
116116

117117
if (argv.watch) {
118+
// build
119+
118120
// performBuildWatch(ts, projects, buildOptions);
119121
throw new Error("TODO performBuildWatch");
120122
} else {
121123
// performBuild(ts, projects, buildOptions);
122124
throw new Error("TODO performBuild");
123125
}
124126
} else {
127+
// why does typechecking require glint config but not performBuild watch?
128+
// not sure...
129+
125130
const glintConfig = loadConfig(argv.project ?? cwd);
126131
const optionsToExtend = determineOptionsToExtend(argv);
127132

128133
validateTSOrExit(glintConfig.ts);
129134

130135
if (argv.watch) {
131-
throw new Error("TODO performBuild");
136+
throw new Error("TODO performWatch");
132137

133138
// performWatch(glintConfig, optionsToExtend);
134139
} else {

Diff for: packages/core/src/cli/run-volar-tsc.ts

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { runTsc } from '@volar/typescript/lib/quickstart/runTsc.js';
2+
import { createGtsLanguagePlugin } from '../volar/gts-language-plugin.js';
3+
import { loadConfig } from '../config/index.js';
4+
// import * as vue from '@vue/language-core';
5+
6+
// const windowsPathReg = /\\/g;
7+
8+
export function run() {
9+
10+
let runExtensions = ['.js', '.ts', '.gjs', '.gts', '.hbs'];
11+
let cwd = process.cwd();
12+
13+
// const extensionsChangedException = new Error('extensions changed');
14+
const main = () => runTsc(
15+
require.resolve('typescript/lib/tsc'),
16+
runExtensions,
17+
(ts, options) => {
18+
19+
const glintConfig = loadConfig(cwd);
20+
const gtsLanguagePlugin = createGtsLanguagePlugin(glintConfig);
21+
return [gtsLanguagePlugin];
22+
23+
// const { configFilePath } = options.options;
24+
// const vueOptions = typeof configFilePath === 'string'
25+
// ? vue.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions
26+
// : vue.resolveVueCompilerOptions({});
27+
// const allExtensions = [
28+
// ...vueOptions.extensions,
29+
// ...vueOptions.vitePressExtensions,
30+
// ...vueOptions.petiteVueExtensions,
31+
// ];
32+
// if (
33+
// runExtensions.length === allExtensions.length
34+
// && runExtensions.every(ext => allExtensions.includes(ext))
35+
// ) {
36+
// const writeFile = options.host!.writeFile.bind(options.host);
37+
// options.host!.writeFile = (fileName, contents, ...args) => {
38+
// return writeFile(fileName, removeEmitGlobalTypes(contents), ...args);
39+
// };
40+
41+
// const glintConfig = loadConfig(cwd);
42+
// const gtsLanguagePlugin = createGtsLanguagePlugin(glintConfig);
43+
// return [gtsLanguagePlugin];
44+
// }
45+
// else {
46+
// runExtensions = allExtensions;
47+
// throw extensionsChangedException;
48+
// }
49+
}
50+
);
51+
52+
main();
53+
// try {
54+
// } catch (err) {
55+
// if (err === extensionsChangedException) {
56+
// main();
57+
// } else {
58+
// console.error(err);
59+
// }
60+
// }
61+
}
62+
63+
// const removeEmitGlobalTypesRegexp = /^[^\n]*__VLS_globalTypesStart[\w\W]*__VLS_globalTypesEnd[^\n]*\n?$/mg;
64+
65+
// export function removeEmitGlobalTypes(dts: string) {
66+
// return dts.replace(removeEmitGlobalTypesRegexp, '');
67+
// }

Diff for: packages/core/src/volar/gts-language-plugin.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type TS = typeof ts;
1313
/**
1414
* Create a [Volar](https://volarjs.dev) language module to support GTS.
1515
*/
16-
export function createGtsLanguagePlugin(glintConfig: GlintConfig): LanguagePlugin<URI> {
16+
export function createGtsLanguagePlugin<T extends URI | string>(glintConfig: GlintConfig): LanguagePlugin<T> {
1717
return {
1818
/**
1919
* For files that are not opened in the IDE, the language ID will not be provided
@@ -25,14 +25,14 @@ export function createGtsLanguagePlugin(glintConfig: GlintConfig): LanguagePlugi
2525
* contexts, in which case this hook is called to determine it for a file based on its
2626
* extension.
2727
*/
28-
getLanguageId(uri) {
29-
if (uri.path.endsWith('.gts')) {
28+
getLanguageId(fileNameOrUri) {
29+
if (String(fileNameOrUri).endsWith('.gts')) {
3030
return 'glimmer-ts';
3131
}
32-
if (uri.path.endsWith('.gjs')) {
32+
if (String(fileNameOrUri).endsWith('.gjs')) {
3333
return 'glimmer-js';
3434
}
35-
if (uri.path.endsWith('.hbs')) {
35+
if (String(fileNameOrUri).endsWith('.hbs')) {
3636
return 'handlebars';
3737
}
3838
},

Diff for: tsconfig.compileroptions.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
// Node16 allows top-level `await`, which was also unflagged in Node 14.8
55
"module": "Node16",
66
"moduleResolution": "Node16",
7-
8-
// changing this was necessary for WeakRef to be available (required/referenced in Volar)
9-
"lib": ["ESNext", "dom"],
7+
"lib": [
8+
"WebWorker",
9+
"ES2021"
10+
],
1011
"strict": true,
1112
"noImplicitOverride": true,
1213
"noPropertyAccessFromIndexSignature": true,

0 commit comments

Comments
 (0)