diff --git a/apps/vs-code-designer/package.json b/apps/vs-code-designer/package.json index 50078a08104..f5739494f3b 100644 --- a/apps/vs-code-designer/package.json +++ b/apps/vs-code-designer/package.json @@ -60,11 +60,11 @@ }, "private": true, "scripts": { - "build:extension": "tsup && pnpm run copyFiles && cd dist && npm install --ignore-scripts", + "build:extension": "tsup && pnpm run copyFiles && node scripts/install-dist-dependencies.js --ignore-scripts", "build:ui": "tsup --config tsup.e2e.test.config.ts", "copyFiles": "node extension-copy-svgs.js", "vscode:designer:pack": "pnpm run vscode:designer:pack:step1 && pnpm run vscode:designer:pack:step2", - "vscode:designer:pack:step1": "cd ./dist && npm install", + "vscode:designer:pack:step1": "node scripts/install-dist-dependencies.js", "vscode:designer:pack:step2": "cd ./dist && vsce package", "lint": "eslint . --report-unused-disable-directives --max-warnings 0", "test:extension-unit": "vitest run --retry=3", diff --git a/apps/vs-code-designer/scripts/install-dist-dependencies.js b/apps/vs-code-designer/scripts/install-dist-dependencies.js new file mode 100644 index 00000000000..e997e2d82a0 --- /dev/null +++ b/apps/vs-code-designer/scripts/install-dist-dependencies.js @@ -0,0 +1,42 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +const { spawnSync } = require('child_process'); +const { existsSync } = require('fs'); +const { join } = require('path'); + +const distPath = join(__dirname, '..', 'dist'); +if (!existsSync(distPath)) { + console.error(`Extension dist folder does not exist: ${distPath}`); + process.exit(1); +} + +const args = ['install', ...process.argv.slice(2)]; +const npmUserConfig = process.env.NPM_CONFIG_USERCONFIG?.trim(); +if (npmUserConfig) { + if (!existsSync(npmUserConfig)) { + console.error('NPM_CONFIG_USERCONFIG is set, but the configured npm userconfig file does not exist.'); + process.exit(1); + } + + console.log('Using npm userconfig from NPM_CONFIG_USERCONFIG.'); + args.push('--userconfig', npmUserConfig); +} + +const npmCliPath = join(process.execPath, '..', 'node_modules', 'npm', 'bin', 'npm-cli.js'); +const command = existsSync(npmCliPath) ? process.execPath : process.platform === 'win32' ? 'npm.cmd' : 'npm'; +const commandArgs = existsSync(npmCliPath) ? [npmCliPath, ...args] : args; + +const result = spawnSync(command, commandArgs, { + cwd: distPath, + stdio: 'inherit', + shell: false, +}); + +if (result.error) { + console.error(result.error.message); + process.exit(1); +} + +process.exit(result.status ?? 1);