Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use NPM pack to manually download esbuild #167

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Mocha for VS Code",
"description": "Run and debug Mocha tests right within VS Code.",
"publisher": "coderline",
"version": "1.2.1",
"version": "1.2.2",
"icon": "icon.png",
"engines": {
"vscode": "^1.83.0"
Expand Down Expand Up @@ -132,6 +132,7 @@
},
"devDependencies": {
"@eslint/js": "^9.9.1",
"@jridgewell/trace-mapping": "^0.3.25",
"@types/chai": "^4.3.17",
"@types/eslint__js": "^8.42.3",
"@types/estree": "^1.0.5",
Expand All @@ -141,43 +142,43 @@
"@types/picomatch": "^3.0.1",
"@types/sinon": "^17.0.3",
"@types/split2": "^4.2.3",
"@types/which": "^3.0.4",
"@types/yargs": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@typescript-eslint/parser": "^8.6.0",
"@typescript-eslint/typescript-estree": "^8.7.0",
"@vscode/dts": "^0.4.1",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1",
"@vscode/vsce": "^3.1.1",
"acorn": "^8.12.1",
"acorn-loose": "^8.4.0",
"ansi-colors": "^4.1.3",
"chai": "^4.4.1",
"data-uri-to-buffer": "^6.0.2",
"enhanced-resolve": "^5.17.1",
"error-stack-parser": "^2.1.4",
"eslint": "^9.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-license-header": "^0.6.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-visitor-keys": "^4.1.0",
"glob": "^11.0.0",
"minimatch": "^10.0.1",
"mocha": "^10.7.3",
"prettier": "^3.3.3",
"prettier-eslint": "^16.3.0",
"prettier-eslint-cli": "^8.0.1",
"prettier-plugin-organize-imports": "^4.1.0",
"sinon": "^19.0.2",
"split2": "^4.2.0",
"stacktrace-parser": "^0.1.10",
"supports-color": "^9.4.0",
"tar": "^7.4.3",
"ts-node": "^10.9.2",
"tsx": "^4.19.1",
"typescript": "^5.6.2",
"typescript-eslint": "^8.6.0",
"@jridgewell/trace-mapping": "^0.3.25",
"@types/which": "^3.0.4",
"@typescript-eslint/typescript-estree": "^8.7.0",
"acorn-loose": "^8.4.0",
"ansi-colors": "^4.1.3",
"data-uri-to-buffer": "^6.0.2",
"enhanced-resolve": "^5.17.1",
"error-stack-parser": "^2.1.4",
"eslint-visitor-keys": "^4.1.0",
"glob": "^11.0.0",
"minimatch": "^10.0.1",
"split2": "^4.2.0",
"stacktrace-parser": "^0.1.10",
"supports-color": "^9.4.0",
"which": "^5.0.0"
},
"dependencies": {
Expand Down
41 changes: 27 additions & 14 deletions src/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { exec } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import * as tar from 'tar';
import * as vscode from 'vscode';

// this logic is aligned with the ESBuild install script, unfortunately we cannot use pkgAndSubpathForCurrentPlatform directly
Expand Down Expand Up @@ -90,6 +91,7 @@ export async function initESBuild(
let platformPackageAndVersion: string;
try {
logChannel.debug('Determining ESBuild platform package and version');

const packageJson = JSON.parse(
await fs.promises.readFile(
path.join(context.extensionPath, 'node_modules', 'esbuild', 'package.json'),
Expand Down Expand Up @@ -135,23 +137,17 @@ export async function initESBuild(
return;
}

const args = [
'install',
'--no-save',
'--omit=dev',
'--omit=optional',
'--omit=peer',
'--prefer-offline',
'--no-audit',
'--progress=false',
platformPackageAndVersion,
];
logChannel.debug(`Running npm install ${args.join(' ')}`);
const temp = path.join(context.extensionPath, 'tmp');
await fs.promises.rm(temp, { recursive: true, force: true });
await fs.promises.mkdir(temp);

const cmd = ['npm', 'pack', platformPackageAndVersion];
logChannel.debug(`Downloading npm package via ${cmd.join(' ')}`);
await new Promise<void>((resolve, reject) => {
exec(
`npm ${args.join(' ')}`,
cmd.join(' '),
{
cwd: context.extensionPath,
cwd: temp,
env: {
...process.env,
ELECTRON_RUN_AS_NODE: '1',
Expand All @@ -174,4 +170,21 @@ export async function initESBuild(
},
);
});

const tgzPath = (
await fs.promises.readdir(temp, {
withFileTypes: true,
recursive: false,
})
)[0];
logChannel.debug(`Extracting ${tgzPath.name}`);
await tar.extract({
file: path.join(temp, tgzPath.name),
cwd: temp,
});

const targetPath = path.join(context.extensionPath, 'node_modules', platformPackageName);
logChannel.debug(`Moving files to ${targetPath}`);
await fs.promises.rm(targetPath, { recursive: true, force: true });
await fs.promises.rename(path.join(temp, 'package'), targetPath);
}