fix: bundle extension using tsup (#268)

* fix: bundle extension using tsup

closes #267

* deps
This commit is contained in:
Amr Bashir
2024-09-02 19:53:00 +03:00
committed by GitHub
parent e9c0de4115
commit c64d572c1c
9 changed files with 1102 additions and 43 deletions

5
.changes/bundle-tsup.md Normal file
View File

@@ -0,0 +1,5 @@
---
'tauri-vscode': patch
---
Fix extension failing to active due missing dependencies

2
.gitignore vendored
View File

@@ -6,6 +6,6 @@
npm-debug.log npm-debug.log
Thumbs.db Thumbs.db
node_modules/ node_modules/
out/ dist/
.vs/ .vs/
.vscode-test/ .vscode-test/

2
.vscode/launch.json vendored
View File

@@ -15,7 +15,7 @@
"request": "launch", "request": "launch",
"runtimeExecutable": "${execPath}", "runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"], "args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"], "outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "${defaultBuildTask}" "preLaunchTask": "${defaultBuildTask}"
} }
] ]

4
.vscode/tasks.json vendored
View File

@@ -9,9 +9,7 @@
"tasks": [ "tasks": [
{ {
"type": "npm", "type": "npm",
"script": "watch", "script": "compile",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": { "presentation": {
"reveal": "never" "reveal": "never"
}, },

View File

@@ -4,10 +4,14 @@
.vscode/** .vscode/**
.vscode-test/** .vscode-test/**
out/test/** dist/test/**
src/** src/**
.gitignore .gitignore
vsc-extension-quickstart.md vsc-extension-quickstart.md
**/tsconfig.json **/tsconfig.json
**/*.map **/*.map
**/*.ts **/*.ts
.changes
.github
renovate.json
.prettierrc

View File

@@ -38,7 +38,7 @@
"workspaceContains:**/tauri.*.conf.json5", "workspaceContains:**/tauri.*.conf.json5",
"onFileSystem:tauri" "onFileSystem:tauri"
], ],
"main": "./out/extension.js", "main": "./dist/extension.js",
"contributes": { "contributes": {
"jsonValidation": [ "jsonValidation": [
{ {
@@ -82,20 +82,19 @@
}, },
"scripts": { "scripts": {
"vscode:prepublish": "pnpm run compile", "vscode:prepublish": "pnpm run compile",
"compile": "tsc -p ./", "compile": "tsup src/extension.ts --clean --format cjs --external vscode",
"watch": "tsc -watch -p ./", "watch": "pnpm run compile --watch",
"format": "prettier ./**/*.{json,ts,js} -w --ignore-path .gitignore" "format": "prettier ./**/*.{json,ts,js} -w --ignore-path .gitignore"
}, },
"dependencies": { "devDependencies": {
"axios": "1.7.7", "axios": "1.7.7",
"glob": "11.0.0", "glob": "11.0.0",
"run-in-terminal": "0.0.3", "run-in-terminal": "0.0.3",
"strip-ansi": "7.1.0" "strip-ansi": "7.1.0",
},
"devDependencies": {
"@types/node": "18.19.31", "@types/node": "18.19.31",
"@types/vscode": "1.75.0", "@types/vscode": "1.75.0",
"prettier": "3.3.3", "prettier": "3.3.3",
"tsup": "^8.2.4",
"typescript": "5.5.4" "typescript": "5.5.4"
}, },
"packageManager": "pnpm@9.9.0" "packageManager": "pnpm@9.9.0"

1082
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,14 +5,11 @@
import * as vscode from 'vscode' import * as vscode from 'vscode'
import { exec, execSync, ChildProcess } from 'child_process' import { exec, execSync, ChildProcess } from 'child_process'
import { runInTerminal } from 'run-in-terminal' import { runInTerminal } from 'run-in-terminal'
import { join } from 'path' import * as path from 'path'
import { existsSync, readFileSync } from 'fs' import * as fs from 'fs'
import axios from 'axios' import axios from 'axios'
import stripAnsi from 'strip-ansi'
const stripAnsi = require('strip-ansi') import { glob } from 'glob'
const glob = require('glob')
const path = require('path')
const fs = require('fs')
interface Process { interface Process {
process: ChildProcess process: ChildProcess
@@ -71,7 +68,7 @@ function registerSchemasHandler(context: vscode.ExtensionContext) {
) )
)[0] )[0]
if (schemaFile) return readFileSync(schemaFile.fsPath, 'utf-8') if (schemaFile) return fs.readFileSync(schemaFile.fsPath, 'utf-8')
async function getSchemaFromRelease(version: string) { async function getSchemaFromRelease(version: string) {
const filename = version.startsWith('1') const filename = version.startsWith('1')
@@ -89,7 +86,7 @@ function registerSchemasHandler(context: vscode.ExtensionContext) {
await vscode.workspace.findFiles('**/Cargo.lock') await vscode.workspace.findFiles('**/Cargo.lock')
)[0] )[0]
if (cargoLockPath) { if (cargoLockPath) {
const cargoLock = readFileSync(cargoLockPath.fsPath, 'utf-8') const cargoLock = fs.readFileSync(cargoLockPath.fsPath, 'utf-8')
const matches = const matches =
/\[\[package\]\]\nname = "tauri-build"\nversion = "(.*)"/g.exec( /\[\[package\]\]\nname = "tauri-build"\nversion = "(.*)"/g.exec(
cargoLock cargoLock
@@ -105,7 +102,7 @@ function registerSchemasHandler(context: vscode.ExtensionContext) {
await vscode.workspace.findFiles('**/Cargo.toml') await vscode.workspace.findFiles('**/Cargo.toml')
)[0] )[0]
if (cargoTomlPath) { if (cargoTomlPath) {
const cargoToml = readFileSync(cargoTomlPath.fsPath, 'utf-8') const cargoToml = fs.readFileSync(cargoTomlPath.fsPath, 'utf-8')
for (const regex of [ for (const regex of [
// specifying a dependency in Cargo.toml can be done in 4 ways // specifying a dependency in Cargo.toml can be done in 4 ways
@@ -172,7 +169,7 @@ function runTauriInit(): void {
: `${__getNpmBin()} install @tauri-apps/cli --save-dev` : `${__getNpmBin()} install @tauri-apps/cli --save-dev`
onInstall = () => { onInstall = () => {
const packageJson = JSON.parse( const packageJson = JSON.parse(
fs.readFileSync(`${projectPath}/package.json`) fs.readFileSync(`${projectPath}/package.json`, 'utf8')
) )
if (!packageJson.scripts) { if (!packageJson.scripts) {
packageJson.scripts = {} packageJson.scripts = {}
@@ -232,7 +229,7 @@ function __isVueCliApp(cwd: string): boolean {
} }
function __isNodeProject(cwd: string): boolean { function __isNodeProject(cwd: string): boolean {
return existsSync(join(cwd, 'package.json')) return fs.existsSync(path.join(cwd, 'package.json'))
} }
interface PackageJson { interface PackageJson {
@@ -244,10 +241,10 @@ interface PackageJson {
} }
} }
function __getPackageJson(path: string): PackageJson | null { function __getPackageJson(packageJsonPath: string): PackageJson | null {
const packagePath = join(path, 'package.json') const packagePath = path.join(packageJsonPath, 'package.json')
if (existsSync(packagePath)) { if (fs.existsSync(packageJsonPath)) {
const packageStr = readFileSync(packagePath).toString() const packageStr = fs.readFileSync(packageJsonPath).toString()
return JSON.parse(packageStr) as PackageJson return JSON.parse(packageStr) as PackageJson
} else { } else {
return null return null

View File

@@ -3,7 +3,7 @@
"module": "commonjs", "module": "commonjs",
"target": "es2020", "target": "es2020",
"lib": ["es2020"], "lib": ["es2020"],
"outDir": "out", "outDir": "dist",
"sourceMap": true, "sourceMap": true,
"skipLibCheck": true, "skipLibCheck": true,
"allowJs": false, "allowJs": false,