Skip to content

Commit 98d5774

Browse files
committed
fix buildint of ts plugin for prod
1 parent 2524f1f commit 98d5774

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

buildTsPlugin.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ export const buildTsPlugin = async (/** @type {string} */ outDir, /** @type {str
2828
})
2929
}
3030

31-
const name = 'my-typescript-plugin-2'
32-
buildTsPlugin(`out/node_modules/${name}`, name, 'typescript-2/src/index.ts')
31+
const name = 'ts-essential-plugins'
32+
buildTsPlugin(`out/node_modules/${name}`, name, 'typescript/src/index.ts')

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"private": true,
1919
"scripts": {
2020
"start": "vscode-framework start",
21+
"build": "vscode-framework build && node buildTsPlugin.mjs",
2122
"watch-plugin": "tsc -p typescript -w",
2223
"lint": "eslint src/**"
2324
},
@@ -40,6 +41,7 @@
4041
"eslint": "^8.7.0",
4142
"eslint-config-zardoy": "^0.2.8",
4243
"lodash": "^4.17.21",
44+
"lodash.get": "^4.4.2",
4345
"modify-json-file": "^1.2.2",
4446
"vscode-framework": "^0.0.18"
4547
}

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/src/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import fs from 'fs'
2-
import { join } from 'path/posix'
3-
import tslib, { createProgram, server, SymbolDisplayPartKind, TypeFlags, TypeFormatFlags } from 'typescript/lib/tsserverlibrary'
4-
import { get } from 'lodash'
1+
import get from 'lodash.get'
2+
import type tslib from 'typescript/lib/tsserverlibrary'
53

64
//@ts-ignore
75
import type { Configuration } from '../../src/configurationType'
86

9-
export = function ({ typescript }: { typescript: typeof tslib }) {
7+
export = function ({ typescript }: { typescript: typeof import('typescript/lib/tsserverlibrary') }) {
108
let _configuration: Configuration
119
const c = <T extends keyof Configuration>(key: T): Configuration[T] => get(_configuration, key)
1210

@@ -41,7 +39,7 @@ export = function ({ typescript }: { typescript: typeof tslib }) {
4139
// 'raw prior',
4240
// prior?.entries.map(entry => entry.name),
4341
// )
44-
const node = findChildContainingPosition(sourceFile, position)
42+
const node = findChildContainingPosition(typescript, sourceFile, position)
4543
if (node) {
4644
if (c('jsxPseudoEmmet.enable') && (typescript.isJsxElement(node) || (node.parent && typescript.isJsxElement(node.parent)))) {
4745
if (typescript.isJsxOpeningElement(node)) {
@@ -216,7 +214,7 @@ export = function ({ typescript }: { typescript: typeof tslib }) {
216214
// sourceFile.update('test', { span: textSpan, newLength: sourceFile.text.length + 2 })
217215
// sourceFile.text = patchText(sourceFile.text, textSpan.start, textSpan.start + textSpan.length, 'test')
218216
// console.log('sourceFile.text', sourceFile.text)
219-
const node = findChildContainingPosition(sourceFile, positionOrRange)
217+
const node = findChildContainingPosition(typescript, sourceFile, positionOrRange)
220218
if (!node) {
221219
console.log('no node')
222220
return []
@@ -266,10 +264,14 @@ const patchText = (input: string, start: number, end: number, newText: string) =
266264
return input.slice(0, start) + newText + input.slice(end)
267265
}
268266

269-
function findChildContainingPosition(sourceFile: tslib.SourceFile, position: number): tslib.Node | undefined {
267+
function findChildContainingPosition(
268+
typescript: typeof import('typescript/lib/tsserverlibrary'),
269+
sourceFile: tslib.SourceFile,
270+
position: number,
271+
): tslib.Node | undefined {
270272
function find(node: ts.Node): ts.Node | undefined {
271273
if (position >= node.getStart() && position < node.getEnd()) {
272-
return tslib.forEachChild(node, find) || node
274+
return typescript.forEachChild(node, find) || node
273275
}
274276
return
275277
}

0 commit comments

Comments
 (0)