Skip to content

Commit a570f49

Browse files
authored
fix: Use NPM pack to manually download esbuild (#167)
1 parent 388a924 commit a570f49

File tree

3 files changed

+206
-29
lines changed

3 files changed

+206
-29
lines changed

package-lock.json

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

package.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Mocha for VS Code",
44
"description": "Run and debug Mocha tests right within VS Code.",
55
"publisher": "coderline",
6-
"version": "1.2.1",
6+
"version": "1.2.2",
77
"icon": "icon.png",
88
"engines": {
99
"vscode": "^1.83.0"
@@ -132,6 +132,7 @@
132132
},
133133
"devDependencies": {
134134
"@eslint/js": "^9.9.1",
135+
"@jridgewell/trace-mapping": "^0.3.25",
135136
"@types/chai": "^4.3.17",
136137
"@types/eslint__js": "^8.42.3",
137138
"@types/estree": "^1.0.5",
@@ -141,43 +142,43 @@
141142
"@types/picomatch": "^3.0.1",
142143
"@types/sinon": "^17.0.3",
143144
"@types/split2": "^4.2.3",
145+
"@types/which": "^3.0.4",
144146
"@types/yargs": "^17.0.33",
145147
"@typescript-eslint/eslint-plugin": "^8.8.0",
146148
"@typescript-eslint/parser": "^8.6.0",
149+
"@typescript-eslint/typescript-estree": "^8.7.0",
147150
"@vscode/dts": "^0.4.1",
148151
"@vscode/test-cli": "^0.0.10",
149152
"@vscode/test-electron": "^2.4.1",
150153
"@vscode/vsce": "^3.1.1",
151154
"acorn": "^8.12.1",
155+
"acorn-loose": "^8.4.0",
156+
"ansi-colors": "^4.1.3",
152157
"chai": "^4.4.1",
158+
"data-uri-to-buffer": "^6.0.2",
159+
"enhanced-resolve": "^5.17.1",
160+
"error-stack-parser": "^2.1.4",
153161
"eslint": "^9.11.0",
154162
"eslint-config-prettier": "^9.1.0",
155163
"eslint-plugin-license-header": "^0.6.1",
156164
"eslint-plugin-prettier": "^5.2.1",
165+
"eslint-visitor-keys": "^4.1.0",
166+
"glob": "^11.0.0",
167+
"minimatch": "^10.0.1",
157168
"mocha": "^10.7.3",
158169
"prettier": "^3.3.3",
159170
"prettier-eslint": "^16.3.0",
160171
"prettier-eslint-cli": "^8.0.1",
161172
"prettier-plugin-organize-imports": "^4.1.0",
162173
"sinon": "^19.0.2",
174+
"split2": "^4.2.0",
175+
"stacktrace-parser": "^0.1.10",
176+
"supports-color": "^9.4.0",
177+
"tar": "^7.4.3",
163178
"ts-node": "^10.9.2",
164179
"tsx": "^4.19.1",
165180
"typescript": "^5.6.2",
166181
"typescript-eslint": "^8.6.0",
167-
"@jridgewell/trace-mapping": "^0.3.25",
168-
"@types/which": "^3.0.4",
169-
"@typescript-eslint/typescript-estree": "^8.7.0",
170-
"acorn-loose": "^8.4.0",
171-
"ansi-colors": "^4.1.3",
172-
"data-uri-to-buffer": "^6.0.2",
173-
"enhanced-resolve": "^5.17.1",
174-
"error-stack-parser": "^2.1.4",
175-
"eslint-visitor-keys": "^4.1.0",
176-
"glob": "^11.0.0",
177-
"minimatch": "^10.0.1",
178-
"split2": "^4.2.0",
179-
"stacktrace-parser": "^0.1.10",
180-
"supports-color": "^9.4.0",
181182
"which": "^5.0.0"
182183
},
183184
"dependencies": {

src/esbuild.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { exec } from 'node:child_process';
1111
import fs from 'node:fs';
1212
import os from 'node:os';
1313
import path from 'node:path';
14+
import * as tar from 'tar';
1415
import * as vscode from 'vscode';
1516

1617
// this logic is aligned with the ESBuild install script, unfortunately we cannot use pkgAndSubpathForCurrentPlatform directly
@@ -90,6 +91,7 @@ export async function initESBuild(
9091
let platformPackageAndVersion: string;
9192
try {
9293
logChannel.debug('Determining ESBuild platform package and version');
94+
9395
const packageJson = JSON.parse(
9496
await fs.promises.readFile(
9597
path.join(context.extensionPath, 'node_modules', 'esbuild', 'package.json'),
@@ -135,23 +137,17 @@ export async function initESBuild(
135137
return;
136138
}
137139

138-
const args = [
139-
'install',
140-
'--no-save',
141-
'--omit=dev',
142-
'--omit=optional',
143-
'--omit=peer',
144-
'--prefer-offline',
145-
'--no-audit',
146-
'--progress=false',
147-
platformPackageAndVersion,
148-
];
149-
logChannel.debug(`Running npm install ${args.join(' ')}`);
140+
const temp = path.join(context.extensionPath, 'tmp');
141+
await fs.promises.rm(temp, { recursive: true, force: true });
142+
await fs.promises.mkdir(temp);
143+
144+
const cmd = ['npm', 'pack', platformPackageAndVersion];
145+
logChannel.debug(`Downloading npm package via ${cmd.join(' ')}`);
150146
await new Promise<void>((resolve, reject) => {
151147
exec(
152-
`npm ${args.join(' ')}`,
148+
cmd.join(' '),
153149
{
154-
cwd: context.extensionPath,
150+
cwd: temp,
155151
env: {
156152
...process.env,
157153
ELECTRON_RUN_AS_NODE: '1',
@@ -174,4 +170,21 @@ export async function initESBuild(
174170
},
175171
);
176172
});
173+
174+
const tgzPath = (
175+
await fs.promises.readdir(temp, {
176+
withFileTypes: true,
177+
recursive: false,
178+
})
179+
)[0];
180+
logChannel.debug(`Extracting ${tgzPath.name}`);
181+
await tar.extract({
182+
file: path.join(temp, tgzPath.name),
183+
cwd: temp,
184+
});
185+
186+
const targetPath = path.join(context.extensionPath, 'node_modules', platformPackageName);
187+
logChannel.debug(`Moving files to ${targetPath}`);
188+
await fs.promises.rm(targetPath, { recursive: true, force: true });
189+
await fs.promises.rename(path.join(temp, 'package'), targetPath);
177190
}

0 commit comments

Comments
 (0)