From bc748d2927e059edcc66ebe2f5b6b98463acbe11 Mon Sep 17 00:00:00 2001 From: Hengchang Lu <44047106+luhc228@users.noreply.github.com> Date: Tue, 7 Jul 2020 20:18:34 +0800 Subject: [PATCH] fix: path undefined when workspace is empty (#190) --- extensions/iceworks-component-builder/package.json | 2 +- extensions/iceworks-page-builder/package.json | 2 +- packages/block-service/package.json | 4 ++-- packages/block-service/src/utils/downloadBlock.ts | 10 ++-------- packages/project-service/package.json | 2 +- packages/project-service/src/constant.ts | 1 + 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/extensions/iceworks-component-builder/package.json b/extensions/iceworks-component-builder/package.json index e009b6b23..1f6e057ad 100644 --- a/extensions/iceworks-component-builder/package.json +++ b/extensions/iceworks-component-builder/package.json @@ -111,4 +111,4 @@ "url": "https://github.com/ice-lab/iceworks/issues", "email": "iceworksteam@163.com" } -} +} \ No newline at end of file diff --git a/extensions/iceworks-page-builder/package.json b/extensions/iceworks-page-builder/package.json index 795ede288..2a7aa92f3 100644 --- a/extensions/iceworks-page-builder/package.json +++ b/extensions/iceworks-page-builder/package.json @@ -110,4 +110,4 @@ "url": "https://github.com/ice-lab/iceworks/issues", "email": "iceworksteam@163.com" } -} +} \ No newline at end of file diff --git a/packages/block-service/package.json b/packages/block-service/package.json index c155cc9f4..c993b4064 100644 --- a/packages/block-service/package.json +++ b/packages/block-service/package.json @@ -1,6 +1,6 @@ { "name": "@iceworks/block-service", - "version": "0.1.8", + "version": "0.1.9", "description": "Iceworks block service for VSCode extension.", "files": [ "lib" @@ -29,4 +29,4 @@ "access": "public" }, "gitHead": "fc5b35f95ab4cc24898845916acf598c2f34d576" -} +} \ No newline at end of file diff --git a/packages/block-service/src/utils/downloadBlock.ts b/packages/block-service/src/utils/downloadBlock.ts index 5405928f5..2534c5006 100644 --- a/packages/block-service/src/utils/downloadBlock.ts +++ b/packages/block-service/src/utils/downloadBlock.ts @@ -1,18 +1,12 @@ import * as path from 'path'; import * as fsExtra from 'fs-extra'; -import * as vscode from 'vscode'; import { getAndExtractTarball } from 'ice-npm-utils'; import { IMaterialBlock, getTarballURLByMaterielSource } from '@iceworks/material-utils'; -import { getIceVersion, packageJSONFilename, getPackageJSON } from '@iceworks/project-service'; - -const { workspace } = vscode; - -const projectPath = workspace.rootPath!; -const packagePath = path.join(projectPath, packageJSONFilename); +import { getIceVersion, getPackageJSON, packageJSONPath } from '@iceworks/project-service'; export async function downloadBlock(block: IMaterialBlock, targetDir: string, log: (text: string) => void): Promise { const { name: blockName, source, repository } = block; - const projectPackageJSON = await getPackageJSON(packagePath); + const projectPackageJSON = await getPackageJSON(packageJSONPath); await fsExtra.mkdirp(targetDir); const iceVersion: string = getIceVersion(projectPackageJSON); diff --git a/packages/project-service/package.json b/packages/project-service/package.json index f298eaa4b..04d514620 100644 --- a/packages/project-service/package.json +++ b/packages/project-service/package.json @@ -1,6 +1,6 @@ { "name": "@iceworks/project-service", - "version": "0.1.9", + "version": "0.1.10", "description": "Iceworks project service for VSCode extension.", "files": [ "lib" diff --git a/packages/project-service/src/constant.ts b/packages/project-service/src/constant.ts index 9cecad0fb..f11ea3fac 100644 --- a/packages/project-service/src/constant.ts +++ b/packages/project-service/src/constant.ts @@ -10,6 +10,7 @@ export const COMPONENT_DIR_NAME = 'components'; export const dependencyDir = 'node_modules'; export const packageJSONFilename = 'package.json'; export const jsxFileExtnames = ['.jsx', '.tsx', '.js']; +export const packageJSONPath = path.join(projectPath, packageJSONFilename); export const generatorCreatetaskUrl = 'https://api.def.alibaba-inc.com/api/generator/generator/createtask'; export const generatorTaskResultUrl = 'https://api.def.alibaba-inc.com/api/generator/generator/task';