Skip to content

Commit

Permalink
refactor(tsc): deprecate hooks api (#3793)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Dec 21, 2023
1 parent 7dc8c9d commit 5110a06
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 706 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
"experimentalRfc436": {
"deprecated": true
},
"hooks": {
"deprecated": true,
"type": "array",
"description": "Deprecated since v2.0.0.",
"markdownDescription": "https://github.com/vuejs/language-tools/pull/2217"
},
"narrowingTypesInInlineHandlers": {
"deprecated": true
},
Expand Down
4 changes: 0 additions & 4 deletions packages/language-core/schemas/vue-tsconfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@
"default": [ ],
"markdownDescription": "Plugins to be used in the SFC compiler."
},
"hooks": {
"type": "array",
"markdownDescription": "https://github.com/vuejs/language-tools/pull/2217"
},
"optionsWrapper": {
"type": "array",
"default": [
Expand Down
1 change: 0 additions & 1 deletion packages/language-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export interface VueCompilerOptions {
withDefaults: string[];
};
plugins: VueLanguagePlugin[];
hooks: string[];

// experimental
experimentalDefinePropProposal: 'kevinEdition' | 'johnsonEdition' | false;
Expand Down
6 changes: 0 additions & 6 deletions packages/language-core/src/utils/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ function getPartialVueCompilerOptions(

result.plugins = plugins;
}
if (rawOptions.hooks) {
result.hooks = rawOptions.hooks
.map(resolvePath)
.filter((hook): hook is NonNullable<typeof hook> => !!hook);
}
if (rawOptions.experimentalAdditionalLanguageModules) {
result.experimentalAdditionalLanguageModules = rawOptions.experimentalAdditionalLanguageModules
.map(resolvePath)
Expand Down Expand Up @@ -268,7 +263,6 @@ export function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions
...vueOptions.macros,
},
plugins: vueOptions.plugins ?? [],
hooks: vueOptions.hooks ?? [],

// experimental
experimentalDefinePropProposal: vueOptions.experimentalDefinePropProposal ?? false,
Expand Down
21 changes: 0 additions & 21 deletions packages/tsc-eslint-hook/LICENSE

This file was deleted.

59 changes: 0 additions & 59 deletions packages/tsc-eslint-hook/README.md

This file was deleted.

27 changes: 0 additions & 27 deletions packages/tsc-eslint-hook/package.json

This file was deleted.

139 changes: 0 additions & 139 deletions packages/tsc-eslint-hook/src/index.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/tsc-eslint-hook/tsconfig.json

This file was deleted.

15 changes: 1 addition & 14 deletions packages/tsc/bin/vue-tsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const tsPkg = require('typescript/package.json');
const readFileSync = fs.readFileSync;
const tscPath = require.resolve('typescript/lib/tsc');
const proxyApiPath = require.resolve('../out/index');
const { state } = require('../out/shared');

fs.readFileSync = (...args) => {
if (args[0] === tscPath) {
Expand Down Expand Up @@ -56,16 +55,4 @@ fs.readFileSync = (...args) => {
return readFileSync(...args);
};

(function main() {
try {
require(tscPath);
}
catch (err) {
if (err === 'hook') {
state.hook.worker.then(main);
}
else {
throw err;
}
}
})();
require(tscPath);
24 changes: 1 addition & 23 deletions packages/tsc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type * as ts from 'typescript/lib/tsserverlibrary';
import * as vue from '@vue/language-core';
import { createLanguage, decorateLanguageService, getDocumentRegistry, getProgram } from '@volar/typescript';
import { state } from './shared';

export type Hook = (program: _Program) => void;

export type _Program = ts.Program & { __vue: ProgramContext; };

Expand All @@ -28,11 +25,7 @@ export function createProgram(options: ts.CreateProgramOptions) {

let program = options.oldProgram as _Program | undefined;

if (state.hook) {
program = state.hook.program;
program.__vue.options = options;
}
else if (!program) {
if (!program) {

const ctx: ProgramContext = {
projectVersion: 0,
Expand Down Expand Up @@ -145,21 +138,6 @@ export function createProgram(options: ts.CreateProgramOptions) {
ctx.projectVersion++;
}

const vueCompilerOptions = program.__vue.vueCompilerOptions;
if (vueCompilerOptions?.hooks) {
const index = (state.hook?.index ?? -1) + 1;
if (index < vueCompilerOptions.hooks.length) {
const hookPath = vueCompilerOptions.hooks[index];
const hook: Hook = require(hookPath);
state.hook = {
program,
index,
worker: (async () => await hook(program))(),
};
throw 'hook';
}
}

for (const rootName of options.rootNames) {
// register file watchers
options.host.getSourceFile(rootName, ts.ScriptTarget.ESNext);
Expand Down
9 changes: 0 additions & 9 deletions packages/tsc/src/shared.ts

This file was deleted.

Loading

0 comments on commit 5110a06

Please sign in to comment.