From 83954c4fabc900a1fe171e5786f65f7a15135f68 Mon Sep 17 00:00:00 2001 From: yangfan <18767120422@163.com> Date: Thu, 26 Aug 2021 17:05:09 +0800 Subject: [PATCH] Release 1.4.1 (#943) * chore: remove @ali/publish-visual extension (#938) * chore: remove @ali/publish-visual extension * fix: material-help (#944) * fix: material-help (#946) * fix: material-help * chore: add @ali/publish-visual to o2 pack (#948) * fix: import duplicate components when add routers (#947) * fix: import duplicate components when add routers * chore: remove comment * feat: update feedbackLink (#940) * feat: remove deprecated extension (#939) * fix: fail to remove compoennt (#942) Co-authored-by: yangfan <18767120422@163.com> * feat: add extensionDependencies (#945) * feat: update version and changelog (#941) * feat: update version and changelog * feat: update changelog * feat: update * fix: remove referenced identifiers (#949) Co-authored-by: Hengchang Lu <44047106+luhc228@users.noreply.github.com> Co-authored-by: qixuan <58852732+GiveMe-A-Name@users.noreply.github.com> --- extensions/application-manager/CHANGELOG.md | 7 + extensions/application-manager/package.json | 5 +- .../src/views/actionsView.ts | 6 +- extensions/appworks/CHANGELOG.md | 9 + extensions/appworks/README.md | 2 +- extensions/appworks/README.zh-CN.md | 2 +- extensions/appworks/package.json | 4 +- extensions/material-helper/CHANGELOG.md | 5 + extensions/material-helper/package.json | 9 +- .../importAutoComplete/getAlreadyImportSet.ts | 2 +- .../getCurrentMtopRequestCall.ts | 5 +- .../propTypesAutoComplete/getJsxPropKeys.ts | 2 +- .../getPropTypesDependentName.ts | 2 +- .../propsAutoComplete/getPropKeysFromCode.ts | 2 +- .../src/utils/getBabelParserPlugins.ts | 4 +- .../src/utils/getComponentSource.ts | 2 +- .../src/utils/getCurrentJsxElement.ts | 2 +- .../src/utils/getJsxElements.ts | 2 +- .../src/views/componentsView.ts | 4 +- extensions/project-creator/CHANGELOG.md | 5 + extensions/project-creator/package.json | 9 +- extensions/react-refactor/CHANGELOG.md | 4 + extensions/react-refactor/package.json | 2 +- .../src/__tests__/suite/index.ts | 8 +- .../modules/removeUselessReferences.ts | 21 +- .../refactor/utils/handleValidIdentifier.ts | 30 +- .../src/utils/prettierFormat.ts | 2 +- packages/material-engine/CHANGELOG.md | 4 + packages/material-engine/package.json | 2 +- packages/material-engine/src/router/index.ts | 257 +++++------------- packages/project-service/CHANGELOG.md | 4 + packages/project-service/package.json | 2 +- packages/project-service/src/index.ts | 4 +- scripts/o2/config.ts | 26 +- 34 files changed, 202 insertions(+), 254 deletions(-) diff --git a/extensions/application-manager/CHANGELOG.md b/extensions/application-manager/CHANGELOG.md index 262dcc792..464fdf162 100644 --- a/extensions/application-manager/CHANGELOG.md +++ b/extensions/application-manager/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 1.0.6 + +- feat: add extensionDependencies `doctor` +- fix: async function syntax error +- feat: update `@appworks/project-service` for feedbackLink +- chore: upgrade @appworks/material-engine version + ## 1.0.5 - feat: update activitybar icon diff --git a/extensions/application-manager/package.json b/extensions/application-manager/package.json index b93f65910..9b1b0f22b 100644 --- a/extensions/application-manager/package.json +++ b/extensions/application-manager/package.json @@ -3,7 +3,7 @@ "displayName": "Application Manager", "description": "Quick view your Universal Application(React/Rax/Vue, etc).", "publisher": "iceworks-team", - "version": "1.0.5", + "version": "1.0.6", "engines": { "vscode": "^1.41.0" }, @@ -353,7 +353,7 @@ "@appworks/common-service": "^0.1.0", "@appworks/constant": "^0.1.0", "@appworks/i18n": "^0.1.0", - "@appworks/material-engine": "^0.1.0", + "@appworks/material-engine": "^0.2.0", "@appworks/project-service": "^0.1.0", "@appworks/recorder": "^1.0.0", "@appworks/connector": "^0.1.0", @@ -366,6 +366,7 @@ "util": "^0.12.3" }, "extensionDependencies": [ + "iceworks-team.iceworks-doctor", "iceworks-team.iceworks-project-creator" ], "homepage": "https://github.com/appworks-lab/appworks/blob/master/extensions/application-manager/README.md", diff --git a/extensions/application-manager/src/views/actionsView.ts b/extensions/application-manager/src/views/actionsView.ts index 407c5d42c..6178e7c2e 100644 --- a/extensions/application-manager/src/views/actionsView.ts +++ b/extensions/application-manager/src/views/actionsView.ts @@ -44,7 +44,7 @@ export class ActionsProvider implements vscode.TreeDataProvider { itemDataList = element.children; } else { itemDataList = [ - ...this.buildQuickItems(), + ...await this.buildQuickItems(), this.buildDividerItem(), await this.buildScriptParentItem(), ]; @@ -84,7 +84,7 @@ export class ActionsProvider implements vscode.TreeDataProvider { return item; } - private buildQuickItems(): ItemData[] { + private async buildQuickItems(): Promise { const items: ItemData[] = []; const debugLabel = i18n.format('extension.applicationManager.showEntriesQuickPick.runDebug.label'); const debugItem = this.buildActionItem( @@ -112,7 +112,7 @@ export class ActionsProvider implements vscode.TreeDataProvider { items.push(createPageItem); } - const isAliInternal = checkIsAliInternal(); + const isAliInternal = await checkIsAliInternal(); if (isAliInternal) { const publishLabel = i18n.format('extension.applicationManager.showEntriesQuickPick.DefPublish.label'); const publishItem = this.buildActionItem( diff --git a/extensions/appworks/CHANGELOG.md b/extensions/appworks/CHANGELOG.md index 4d8639a1c..2ef436ddf 100644 --- a/extensions/appworks/CHANGELOG.md +++ b/extensions/appworks/CHANGELOG.md @@ -1,5 +1,14 @@ # Change Log +## [1.4.1](https://github.com/appworks-lab/appworks/releases/tag/v1.4.1) + +- feat: update feedback link [#940](https://github.com/appworks-lab/appworks/pull/940) +- feat: remove deprecated extension [#939](https://github.com/appworks-lab/appworks/pull/939) +- feat: add extensionDependencies [#945](https://github.com/appworks-lab/appworks/pull/945) +- fix: import duplicate components when add routers [#947](https://github.com/appworks-lab/appworks/pull/947) +- fix: fail to remove component [#942](https://github.com/appworks-lab/appworks/pull/942) +- fix: material-help babel parse error [#944](https://github.com/appworks-lab/appworks/pull/944) + ## [1.4.0](https://github.com/appworks-lab/appworks/releases/tag/v1.4.0) - feat: add React Generator [#933](https://github.com/appworks-lab/appworks/pull/933) diff --git a/extensions/appworks/README.md b/extensions/appworks/README.md index 67e5dfa38..45c9476c0 100644 --- a/extensions/appworks/README.md +++ b/extensions/appworks/README.md @@ -77,7 +77,7 @@ AppWorks Pack extension installs these recommend extensions: - [Auto Rename Tag](https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag): Auto rename paired HTML/XML tag. - [JavaScript (ES6) code snippets](https://marketplace.visualstudio.com/items?itemName=xabikos.JavaScriptSnippets): Code snippets for JavaScript in ES6 syntax. - [Simple React Snippets](https://marketplace.visualstudio.com/items?itemName=burkeholland.simple-react-snippets): The essential collection of React Snippets and commands. -- [Debugger for Chrome](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome): Debug your JavaScript code in the Chrome browser, or any other target that supports the Chrome Debugger protocol. +- [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner): Run code snippet or code file for multiple languages. - [Bookmarks](https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks): It helps you to navigate in your code, moving between important positions easily and quickly. ## Help diff --git a/extensions/appworks/README.zh-CN.md b/extensions/appworks/README.zh-CN.md index 2120b7731..71f2dd67e 100644 --- a/extensions/appworks/README.zh-CN.md +++ b/extensions/appworks/README.zh-CN.md @@ -77,7 +77,7 @@ AppWorks 套件内包含以下推荐的三方插件: - [Auto Complete Tag](https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-complete-tag): 自动闭合和重命名标签 - [JavaScript (ES6) code snippets](https://marketplace.visualstudio.com/items?itemName=xabikos.JavaScriptSnippets): ES6 语法的 JavaScript 代码片段 - [Simple React Snippets](https://marketplace.visualstudio.com/items?itemName=burkeholland.simple-react-snippets): React 代码片段 -- [Debugger for Chrome](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome): 在 Chrome 浏览器或任何其他支持 Chrome Debugger 协议的目标中调试 JavaScript 代码 +- [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner): 快速运行文件和代码片段,支持多种开发语言. - [Bookmarks](https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks): 源码阅读神器 ## 获取帮助 diff --git a/extensions/appworks/package.json b/extensions/appworks/package.json index f1905f619..4c7ea2b07 100644 --- a/extensions/appworks/package.json +++ b/extensions/appworks/package.json @@ -3,7 +3,7 @@ "displayName": "AppWorks", "description": "Application Development Pack, provide visualization and intelligent technology to build Universal Application faster and better, support Web / H5 / MiniProgram(小程序) Application.", "publisher": "iceworks-team", - "version": "1.4.0", + "version": "1.4.1", "engines": { "vscode": "^1.41.0" }, @@ -49,7 +49,7 @@ "formulahendry.auto-rename-tag", "xabikos.JavaScriptSnippets", "burkeholland.simple-react-snippets", - "msjsdiag.debugger-for-chrome", + "formulahendry.code-runner", "alefragnani.Bookmarks" ], "homepage": "https://github.com/appworks-lab/appworks/blob/master/extensions/appworks/README.md", diff --git a/extensions/material-helper/CHANGELOG.md b/extensions/material-helper/CHANGELOG.md index ab6b5025d..57452f127 100644 --- a/extensions/material-helper/CHANGELOG.md +++ b/extensions/material-helper/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 1.1.0 +- chore: add iceworks-refactor to extensionDependencies +- fix: the babel plugin's flow will cause error, when babel parse typescript files. +- fix: import duplicate components when add routers + ## 1.0.9 - feat: change auto fill code to React Generator extension. diff --git a/extensions/material-helper/package.json b/extensions/material-helper/package.json index 2d3dce06d..91b34ba80 100644 --- a/extensions/material-helper/package.json +++ b/extensions/material-helper/package.json @@ -3,7 +3,7 @@ "displayName": "Component Helper", "description": "Easily use Component in React/Vue/Rax.", "publisher": "iceworks-team", - "version": "1.0.9", + "version": "1.1.0", "main": "./build/extension.js", "engines": { "vscode": "^1.41.0" @@ -368,7 +368,7 @@ "@appworks/common-service": "^0.1.0", "@appworks/constant": "^0.1.0", "@appworks/i18n": "^0.1.0", - "@appworks/material-engine": "^0.1.0", + "@appworks/material-engine": "^0.2.0", "@appworks/project-service": "^0.1.0", "@appworks/project-utils": "^0.1.0", "@appworks/recorder": "^0.1.0", @@ -385,5 +385,8 @@ "bugs": { "url": "https://github.com/appworks-lab/appworks/issues", "email": "iceworksteam@163.com" - } + }, + "extensionDependencies": [ + "iceworks-team.iceworks-refactor" + ] } diff --git a/extensions/material-helper/src/importAutoComplete/getAlreadyImportSet.ts b/extensions/material-helper/src/importAutoComplete/getAlreadyImportSet.ts index 474f57684..61f2d5757 100644 --- a/extensions/material-helper/src/importAutoComplete/getAlreadyImportSet.ts +++ b/extensions/material-helper/src/importAutoComplete/getAlreadyImportSet.ts @@ -11,7 +11,7 @@ export default (doc: vscode.TextDocument): Set => { try { const ast = parse(documentText, { sourceType: 'module', - plugins: getBabelParserPlugins('jsx'), + plugins: getBabelParserPlugins('ts'), errorRecovery: true, }); traverse(ast, { diff --git a/extensions/material-helper/src/mtopAutoComplete/getCurrentMtopRequestCall.ts b/extensions/material-helper/src/mtopAutoComplete/getCurrentMtopRequestCall.ts index c7b373f67..caafb5294 100644 --- a/extensions/material-helper/src/mtopAutoComplete/getCurrentMtopRequestCall.ts +++ b/extensions/material-helper/src/mtopAutoComplete/getCurrentMtopRequestCall.ts @@ -7,8 +7,7 @@ import getBabelParserPlugins from '../utils/getBabelParserPlugins'; function isCursorInObjectExpression(callExpression: CallExpression, cursorPosition: number): boolean { const callArguments = callExpression.arguments; const node = callArguments?.[0]; - - return isObjectExpression(node) && (node.start < cursorPosition && cursorPosition < node.end); + return isObjectExpression(node) && (node.start < cursorPosition && cursorPosition < node.end); } function conditionOfCompletion(callExpression: CallExpression, cursorPosition: number): boolean { @@ -31,7 +30,7 @@ function getOriginCurrentCallExpress( try { const ast = parse(code, { sourceType: 'module', - plugins: getBabelParserPlugins('jsx'), + plugins: getBabelParserPlugins('ts'), }); traverse(ast, { CallExpression(path: NodePath) { diff --git a/extensions/material-helper/src/propTypesAutoComplete/getJsxPropKeys.ts b/extensions/material-helper/src/propTypesAutoComplete/getJsxPropKeys.ts index d712db145..6def858e3 100644 --- a/extensions/material-helper/src/propTypesAutoComplete/getJsxPropKeys.ts +++ b/extensions/material-helper/src/propTypesAutoComplete/getJsxPropKeys.ts @@ -14,7 +14,7 @@ export default (doc: vscode.TextDocument, location: vscode.Location): string[] = try { const ast = parse(definitionsCode, { sourceType: 'module', - plugins: getBabelParserPlugins('jsx'), + plugins: getBabelParserPlugins('js'), }); if (checkIsCapitalizeWord(originSelectionCode) && checkIsJsxComponent(ast)) { return getJsxPropKeysFromAst(ast); diff --git a/extensions/material-helper/src/propTypesAutoComplete/getPropTypesDependentName.ts b/extensions/material-helper/src/propTypesAutoComplete/getPropTypesDependentName.ts index 05f7ff15c..b52be82c7 100644 --- a/extensions/material-helper/src/propTypesAutoComplete/getPropTypesDependentName.ts +++ b/extensions/material-helper/src/propTypesAutoComplete/getPropTypesDependentName.ts @@ -9,7 +9,7 @@ export default (code: string, uri: vscode.Uri): string => { try { const ast = parse(code, { sourceType: 'module', - plugins: getBabelParserPlugins('jsx'), + plugins: getBabelParserPlugins('js'), errorRecovery: true, }); diff --git a/extensions/material-helper/src/propsAutoComplete/getPropKeysFromCode.ts b/extensions/material-helper/src/propsAutoComplete/getPropKeysFromCode.ts index 3752e6af3..775fdf0e6 100644 --- a/extensions/material-helper/src/propsAutoComplete/getPropKeysFromCode.ts +++ b/extensions/material-helper/src/propsAutoComplete/getPropKeysFromCode.ts @@ -12,7 +12,7 @@ export default function getPropKeysFromCode(componentPath: string): string[] { try { const ast = parse(fs.readFileSync(componentPath, 'utf-8'), { sourceType: 'module', - plugins: getBabelParserPlugins('jsx'), + plugins: getBabelParserPlugins('js'), }); if (ast) { diff --git a/extensions/material-helper/src/utils/getBabelParserPlugins.ts b/extensions/material-helper/src/utils/getBabelParserPlugins.ts index 67c98e6e7..afe75f5d9 100644 --- a/extensions/material-helper/src/utils/getBabelParserPlugins.ts +++ b/extensions/material-helper/src/utils/getBabelParserPlugins.ts @@ -1,7 +1,8 @@ import { ParserPlugin } from '@babel/parser'; -export default function getBabelParserPlugins(language: string): ParserPlugin[] { +export default function getBabelParserPlugins(language: 'ts' | 'js'): ParserPlugin[] { const plugins: ParserPlugin[] = [ + 'jsx', 'doExpressions', 'objectRestSpread', 'decorators-legacy', @@ -18,7 +19,6 @@ export default function getBabelParserPlugins(language: string): ParserPlugin[] plugins.unshift('typescript'); } else { plugins.unshift('flow'); - plugins.unshift('jsx'); } return plugins; diff --git a/extensions/material-helper/src/utils/getComponentSource.ts b/extensions/material-helper/src/utils/getComponentSource.ts index 843488d20..cc8684ad7 100644 --- a/extensions/material-helper/src/utils/getComponentSource.ts +++ b/extensions/material-helper/src/utils/getComponentSource.ts @@ -9,7 +9,7 @@ function getComponentSource( ) { const ast = parser.parse(documentText, { sourceType: 'module', - plugins: getBabelParserPlugins('jsx'), + plugins: getBabelParserPlugins('ts'), }); const result = { source: '', importedComponent: '' }; diff --git a/extensions/material-helper/src/utils/getCurrentJsxElement.ts b/extensions/material-helper/src/utils/getCurrentJsxElement.ts index c60be0f74..d3eade79e 100644 --- a/extensions/material-helper/src/utils/getCurrentJsxElement.ts +++ b/extensions/material-helper/src/utils/getCurrentJsxElement.ts @@ -16,7 +16,7 @@ export default function getCurrentJsxElement( // https://babeljs.io/docs/en/babel-parser const ast = parse(documentText, { sourceType: 'module', - plugins: getBabelParserPlugins('jsx'), + plugins: getBabelParserPlugins('ts'), }); if (ast) { diff --git a/extensions/material-helper/src/utils/getJsxElements.ts b/extensions/material-helper/src/utils/getJsxElements.ts index 06b659e61..43ce8e3fe 100644 --- a/extensions/material-helper/src/utils/getJsxElements.ts +++ b/extensions/material-helper/src/utils/getJsxElements.ts @@ -14,7 +14,7 @@ export default function getJsxElements( // https://babeljs.io/docs/en/babel-parser const ast = parse(documentText, { sourceType: 'module', - plugins: getBabelParserPlugins('jsx'), + plugins: getBabelParserPlugins('ts'), }); if (ast) { diff --git a/extensions/material-helper/src/views/componentsView.ts b/extensions/material-helper/src/views/componentsView.ts index 679921bf7..51ffab12f 100644 --- a/extensions/material-helper/src/views/componentsView.ts +++ b/extensions/material-helper/src/views/componentsView.ts @@ -175,9 +175,7 @@ export function createComponentsTreeView(context: vscode.ExtensionContext) { i18n.format('extension.iceworksMaterialHelper.cancel'), ); if (choice === confirmTitle) { - if (vscode.extensions.getExtension('iceworks-team.iceworks-refactor')) { - await vscode.commands.executeCommand('react-refactor.file-and-reference.remove', { path: component.fsPath }); - } + await vscode.commands.executeCommand('react-refactor.file-and-reference.remove', { path: component.fsPath }); } }); diff --git a/extensions/project-creator/CHANGELOG.md b/extensions/project-creator/CHANGELOG.md index 25d69c864..00de87d05 100644 --- a/extensions/project-creator/CHANGELOG.md +++ b/extensions/project-creator/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.0.5 + +- feat: add extensionDependencies +- chore: upgrade @appworks/material-engine version + ## 1.0.4 - feat: update official materials diff --git a/extensions/project-creator/package.json b/extensions/project-creator/package.json index a5c92413d..4e7df4a46 100644 --- a/extensions/project-creator/package.json +++ b/extensions/project-creator/package.json @@ -3,7 +3,7 @@ "displayName": "Application Creator", "description": "Quick create a Universal Application(React/Rax/Vue, etc).", "publisher": "iceworks-team", - "version": "1.0.4", + "version": "1.0.5", "engines": { "vscode": "^1.41.0" }, @@ -75,7 +75,7 @@ "@appworks/common-service": "^0.1.0", "@appworks/constant": "^0.1.0", "@appworks/i18n": "^0.1.0", - "@appworks/material-engine": "^0.1.0", + "@appworks/material-engine": "^0.2.0", "@iceworks/pegasus-service": "^0.1.0", "@appworks/project-service": "^0.1.1", "@appworks/recorder": "^0.1.0", @@ -87,5 +87,8 @@ "bugs": { "url": "https://github.com/appworks-lab/appworks/issues", "email": "iceworksteam@163.com" - } + }, + "extensionDependencies": [ + "iceworks-team.iceworks-app" + ] } diff --git a/extensions/react-refactor/CHANGELOG.md b/extensions/react-refactor/CHANGELOG.md index 6584432ec..14ac43671 100644 --- a/extensions/react-refactor/CHANGELOG.md +++ b/extensions/react-refactor/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 1.0.2 + +- fix: remove referenced identifiers in ArrayPattern and ObjectPattern + ## 1.0.1 - fix .vscodeignore configuration [#576](https://github.com/microsoft/vscode-vsce/issues/576) diff --git a/extensions/react-refactor/package.json b/extensions/react-refactor/package.json index d0ef53f90..20d387b18 100644 --- a/extensions/react-refactor/package.json +++ b/extensions/react-refactor/package.json @@ -4,7 +4,7 @@ "description": "Easily refactor Component in React/Rax.", "publisher": "iceworks-team", "icon": "assets/logo.png", - "version": "1.0.1", + "version": "1.0.2", "engines": { "vscode": "^1.41.0" }, diff --git a/extensions/react-refactor/src/__tests__/suite/index.ts b/extensions/react-refactor/src/__tests__/suite/index.ts index 71f12ac1b..6225f4950 100644 --- a/extensions/react-refactor/src/__tests__/suite/index.ts +++ b/extensions/react-refactor/src/__tests__/suite/index.ts @@ -46,7 +46,7 @@ class CoverageRunner { this.options = options; } - public setupCoverage(): void { + setupCoverage(): void { // Set up Code Coverage, hooking require so that instrumented code is returned const self = this; self.instrumenter = new istanbul.Instrumenter({ coverageVariable: self.coverageVar }); @@ -102,7 +102,7 @@ class CoverageRunner { * * @memberOf CoverageRunner */ - public reportCoverage(): void { + reportCoverage(): void { const self = this; istanbul.hook.unhookRequire(); let cov: any; @@ -173,11 +173,11 @@ export function run(): Promise { } // Add files to the test suite - files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); + files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); try { // Run the mocha test - mocha.run(failures => { + mocha.run((failures) => { if (failures > 0) { e(new Error(`${failures} tests failed.`)); } else { diff --git a/extensions/react-refactor/src/refactor/modules/removeUselessReferences.ts b/extensions/react-refactor/src/refactor/modules/removeUselessReferences.ts index e9302f76c..0e6ae13b7 100644 --- a/extensions/react-refactor/src/refactor/modules/removeUselessReferences.ts +++ b/extensions/react-refactor/src/refactor/modules/removeUselessReferences.ts @@ -150,7 +150,26 @@ export function removeUselessReferences(ast: any, originUnrefIdentifiers: string } if (path && path.node) { - binding.path.remove(); + const { id } = path.node as any; + if (id && (t.isArrayPattern(id) || t.isObjectPattern(id))) { + // const [a, b] = [1, 2] + // const { a, b } = obj; + const { properties, elements } = id as any; + if (properties) { + const propertyIndex = properties.findIndex(({ key }) => key.name === name); + if (propertyIndex) { + properties.splice(propertyIndex, 1); + } + } + if (elements) { + const elementIndex = elements.findIndex((item) => item.name === name); + if (elementIndex) { + elements.splice(elementIndex, 1); + } + } + } else { + binding.path.remove(); + } } } else { // remove identifier in the parent scope diff --git a/extensions/react-refactor/src/refactor/utils/handleValidIdentifier.ts b/extensions/react-refactor/src/refactor/utils/handleValidIdentifier.ts index 5ec6cf7f8..2f02194f8 100644 --- a/extensions/react-refactor/src/refactor/utils/handleValidIdentifier.ts +++ b/extensions/react-refactor/src/refactor/utils/handleValidIdentifier.ts @@ -1,20 +1,22 @@ function handleValidIdentifier(identifierPath, callback) { - switch (identifierPath.parent.type) { - case 'ObjectProperty': - if (identifierPath.parent.key !== identifierPath.node) { - callback(); - } - break; - case 'MemberExpression': + if (identifierPath.parent) { + switch (identifierPath.parent.type) { + case 'ObjectProperty': + if (identifierPath.parent.key !== identifierPath.node) { + callback(); + } + break; + case 'MemberExpression': // For list[index] - if (identifierPath.parent.computed) { - callback(); - } else if (identifierPath.parent.property !== identifierPath.node) { + if (identifierPath.parent.computed) { + callback(); + } else if (identifierPath.parent.property !== identifierPath.node) { + callback(); + } + break; + default: callback(); - } - break; - default: - callback(); + } } } diff --git a/extensions/react-refactor/src/utils/prettierFormat.ts b/extensions/react-refactor/src/utils/prettierFormat.ts index b32f9c2c2..52bc3330f 100644 --- a/extensions/react-refactor/src/utils/prettierFormat.ts +++ b/extensions/react-refactor/src/utils/prettierFormat.ts @@ -4,7 +4,7 @@ function prettierFormat(code: string) { return prettier.format(code, { singleQuote: true, trailingComma: 'es5', - parser: 'babel', + parser: 'typescript', }); } diff --git a/packages/material-engine/CHANGELOG.md b/packages/material-engine/CHANGELOG.md index d1c08871d..c36fcbea5 100644 --- a/packages/material-engine/CHANGELOG.md +++ b/packages/material-engine/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.2.0 + +- fix: import duplicate components when add routers + ## 0.1.2 - feat: update official materials diff --git a/packages/material-engine/package.json b/packages/material-engine/package.json index 865a04917..948a3deec 100644 --- a/packages/material-engine/package.json +++ b/packages/material-engine/package.json @@ -1,6 +1,6 @@ { "name": "@appworks/material-engine", - "version": "0.1.2", + "version": "0.2.0", "description": "AppWorks Material Engine for VSCode extension.", "files": [ "lib" diff --git a/packages/material-engine/src/router/index.ts b/packages/material-engine/src/router/index.ts index a848f42f3..6afe7fc8a 100644 --- a/packages/material-engine/src/router/index.ts +++ b/packages/material-engine/src/router/index.ts @@ -5,7 +5,7 @@ import * as t from '@babel/types'; import generate from '@babel/generator'; import * as prettier from 'prettier'; import * as upperCamelCase from 'uppercamelcase'; -import { getProjectLanguageType, getProjectType, projectPath, PAGE_DIRECTORY, LAYOUT_DIRECTORY, appJSONFileName } from '@appworks/project-service'; +import { getProjectLanguageType, getProjectType, projectPath, appJSONFileName } from '@appworks/project-service'; import getASTByCode from '../utils/getASTByCode'; interface IRouter { @@ -45,7 +45,7 @@ export async function create(data) { const { path: setPath, pageName, parent } = data; const projectType = await getProjectType(); if (projectType === 'react') { - await bulkCreateReactProjectRoutes(projectPath, [{ path: setPath, component: upperCamelCase(pageName) }], { parent }); + await bulkCreateReactProjectRouters(projectPath, [{ path: setPath, component: upperCamelCase(pageName) }], { parent }); } else if (projectType === 'rax') { const route = { path: setPath, @@ -101,31 +101,30 @@ export async function bulkCreateRaxProjectRoutes(targetProjectPath, data) { fse.writeJSONSync(appConfigPath, appConfig, { spaces: 2 }); } -export async function bulkCreateReactProjectRoutes(targetProjectPath: string, data: IRouter[], options: IRouterOptions = {}) { +export async function bulkCreateReactProjectRouters(targetProjectPath: string, routers: IRouter[], options: IRouterOptions = {}) { const { replacement = false, parent } = options; const routerConfigAST = await getRouterConfigAST(targetProjectPath); const projectLanguageType = await getProjectLanguageType(); const routeConfigPath = path.join(targetProjectPath, 'src', `${routerConfigFileName}.${projectLanguageType}`); - const currentData = await getAll(); + let allRouters = await getAll(); if (!replacement) { if (parent) { - const parentRouter = currentData.find((item) => { + const parentRouter = allRouters.find((item) => { if (item.children && item.path === parent) { return true; } return false; }); if (parentRouter) { - parentRouter.children = parentRouter.children.concat(data); - data = currentData; + parentRouter.children = parentRouter.children.concat(routers); } } else { - data = currentData.concat(data); + allRouters = allRouters.concat(routers); } } - setData(data, routerConfigAST, routeConfigPath); + setData(allRouters, routers, routerConfigAST, routeConfigPath); } async function getRouterConfigAST(targetProjectPath) { @@ -162,11 +161,59 @@ function parseRoute(elements) { return config; } -function setData(data, routerConfigAST, routeConfigPath) { - const dataAST = getASTByCode(JSON.stringify(sortData(data))); +function setData(allRouters: IRouter[], routers: IRouter[], routerConfigAST: any, routeConfigPath: string) { + const dataAST = getASTByCode(JSON.stringify(sortData(allRouters))); const arrayAST = dataAST.program.body[0]; - changeImportDeclarations(routerConfigAST, data); + // router import page or layout have @ + let existLazy = false; + // React.lazy(): the existLazyPrefix is true + // lazy(): the existLazyPrefix is false + let existLazyPrefix = false; + + // find if there is lazy import + traverse(routerConfigAST, { + // parse eg. `const Forbidden = React.lazy(() => import('./pages/Exception/Forbidden'));` + VariableDeclaration: ({ node }) => { + const { code } = generate(node.declarations[0]); + // parse const declaration to get directory type (layouts or pages) + // support three path types + // 1. const xxx = (React.)?lazy(() => import('pages/xxx')); + // 2. const xxx = (React.)?lazy(() => import('./pages/xxx')); + // 3. const xxx = (React.)?lazy(() => import('@/pages/xxx')); + const noPrefixReg = /(\w+)\s=\s(React\.)?lazy(.+)import\(['|"]((\w+)\/.+)['|"]\)/; + const hasPrefixReg = /(\w+)\s=\s(React\.)?lazy(.+)import\(['|"]((\.|@)\/(\w+)\/.+)['|"]\)/; + const matchLazyReg = noPathPrefix ? noPrefixReg : hasPrefixReg; + const idx = noPathPrefix ? 5 : 6; + const match = code.match(matchLazyReg); + + if (match && match.length > idx) { + existLazy = true; + if (match[2]) { + existLazyPrefix = true; + } + } + }, + }); + + let importCode = ''; + let lazyCode = ''; + const sign = '@'; + // import new routers + routers.forEach(({ component }) => { + if (existLazy) { + lazyCode += `const ${component} = ${existLazyPrefix ? 'React.' : ''}lazy(() => import('${sign}/pages/${component}'));\n`; + } + importCode += `import ${component} from '${sign}/pages/${component}';\n`; + }); + + const importCodeAST = getASTByCode(importCode); + const lazyCodeAST = getASTByCode(lazyCode); + + const lastIndex = findLastImportIndex(routerConfigAST, existLazy); + routerConfigAST.program.body.splice(lastIndex, 0, ...lazyCodeAST.program.body); + routerConfigAST.program.body.splice(existLazy ? lastIndex - 1 : lastIndex, 0, ...importCodeAST.program.body); + /** * { path: '/a', component: 'Page' } * transform to @@ -182,6 +229,7 @@ function setData(data, routerConfigAST, routeConfigPath) { } }, }); + traverse(routerConfigAST, { VariableDeclarator({ node }) { if (t.isIdentifier(node.id, { name: ROUTER_CONFIG_VARIABLE }) && t.isArrayExpression(node.init)) { @@ -189,6 +237,7 @@ function setData(data, routerConfigAST, routeConfigPath) { } }, }); + fse.writeFileSync(routeConfigPath, formatCodeFromAST(routerConfigAST)); } @@ -216,190 +265,6 @@ function sortData(data) { }); } -/** - * 1. constant if there is layout or component in the data and ImportDeclarations - * 2. remove import if there is no layout or component in the data - * 3. add import if there is no layout or component in the ImportDeclarations - */ -function changeImportDeclarations(routerConfigAST, data) { - const importDeclarations = []; - const removeIndex = []; - // router import page or layout have @ - let existLazy = false; - // React.lazy(): the existLazyPrefix is true - // lazy(): the existLazyPrefix is false - let existLazyPrefix = false; - - traverse(routerConfigAST, { - ImportDeclaration: ({ node, key }) => { - const { source } = node; - // parse import declaration to get directory type (layouts or pages) - // support three path types - // 1. import xxx from 'pages/xxx'; - // 2. import xxx from './pages/xxx'; - // 3. import xxx from '@/pages/xxx'; - const noPrefixReg = /^(layouts|pages)\//; - const hasPrefixReg = /^(\.|@)\/(layouts|pages)\//; - const reg = noPathPrefix ? noPrefixReg : hasPrefixReg; - const idx = noPathPrefix ? 1 : 2; - const match = source.value.match(reg); - - if (match && match[idx]) { - const { specifiers } = node; - const { name } = specifiers[0].local; - importDeclarations.push({ - index: key, - name, - type: match[idx], - }); - } - }, - - // parse eg. `const Forbidden = React.lazy(() => import('./pages/Exception/Forbidden'));` - VariableDeclaration: ({ node, key }) => { - const { code } = generate(node.declarations[0]); - // parse const declaration to get directory type (layouts or pages) - // support three path types - // 1. const xxx = (React.)?lazy(() => import('pages/xxx')); - // 2. const xxx = (React.)?lazy(() => import('./pages/xxx')); - // 3. const xxx = (React.)?lazy(() => import('@/pages/xxx')); - const noPrefixReg = /(\w+)\s=\s(React\.)?lazy(.+)import\(['|"]((\w+)\/.+)['|"]\)/; - const hasPrefixReg = /(\w+)\s=\s(React\.)?lazy(.+)import\(['|"]((\.|@)\/(\w+)\/.+)['|"]\)/; - const matchLazyReg = noPathPrefix ? noPrefixReg : hasPrefixReg; - const idx = noPathPrefix ? 5 : 6; - const match = code.match(matchLazyReg); - - if (match && match.length > idx) { - existLazy = true; - if (match[2]) { - existLazyPrefix = true; - } - importDeclarations.push({ - index: key, - name: match[1], - type: match[idx], - }); - } - }, - }); - - /** - * remove import if there is no layout or component in the data - */ - importDeclarations.forEach((importItem) => { - const { name, type, index } = importItem; - let needRemove = false; - - // match layout or page - if (type) { - let findRouter = null; - - if (type === LAYOUT_DIRECTORY) { - // layout only first layer - findRouter = data.find((item) => item.children && item.component === name); - } else if (type === PAGE_DIRECTORY) { - findRouter = data.find((item) => { - let pageItem = null; - - if (!item.children && item.component === name) { - pageItem = item; - } - - if (item.children) { - item.children.forEach((route) => { - if (route.component === name) { - pageItem = route; - } - }); - } - - return pageItem; - }); - } - if (!findRouter) { - needRemove = true; - } - } - - if (needRemove) { - removeIndex.unshift(index); - } - }); - - removeIndex.forEach((index) => { - routerConfigAST.program.body.splice(index, 1); - }); - - // add new page or layout - function setNewComponent(type, component) { - const componentExist = existImport(importDeclarations, component, type); - - // no component dont add import - if (!component) { - return false; - } - - if (!componentExist && !newImports.find((item) => item.name === component)) { - newImports.push({ - type, - name: component, - }); - } - } - - /** - * add import if there is no layout or component in the ImportDeclarations - */ - const newImports = []; - data.forEach(({ component, children }) => { - if (children) { - setNewComponent(LAYOUT_DIRECTORY, component); - children.forEach((route) => setNewComponent(PAGE_DIRECTORY, route.component)); - } else { - setNewComponent(PAGE_DIRECTORY, component); - } - }); - - /** - * add import to ast - * eg. - * import Page1 from './pages/Page1'; - * or - * const Profile = React.lazy(() => import('./pages/Profile')); - */ - let lazyCode = ''; - let importCode = ''; - const sign = '@'; - newImports.forEach(({ name, type }) => { - if (noPathPrefix) { - importCode += `import ${name} from '${type}/${name}';\n`; - } else if (!existLazy || type === LAYOUT_DIRECTORY) { - // layour or not exist lazy use `import Page from '@/pages/Page'` - importCode += `import ${name} from '${sign}/${type}/${name}';\n`; - } else { - // use lazy `const Page = React.lazy(() => import('@/pages/Page'))` - lazyCode += `const ${name} = ${existLazyPrefix ? 'React.' : ''}lazy(() => import('${sign}/${type}/${name}'));\n`; - } - }); - - // get ast from lazy or import code - const lazyCodeAST = getASTByCode(lazyCode); - const importCodeAST = getASTByCode(importCode); - - const lastIndex = findLastImportIndex(routerConfigAST, existLazy); - routerConfigAST.program.body.splice(lastIndex, 0, ...lazyCodeAST.program.body); - routerConfigAST.program.body.splice(existLazy ? lastIndex - 1 : lastIndex, 0, ...importCodeAST.program.body); -} - -function existImport(list, name, type) { - return list.some((item) => { - if (name === item.name && type === item.type) { - return true; - } - return false; - }); -} - /** * find last import index */ diff --git a/packages/project-service/CHANGELOG.md b/packages/project-service/CHANGELOG.md index 1f3587637..095163958 100644 --- a/packages/project-service/CHANGELOG.md +++ b/packages/project-service/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.1.3 + +- feat: update `feedbackLink` + ## 0.1.2 - fix: fail to execute getProjectDefInfo function in external diff --git a/packages/project-service/package.json b/packages/project-service/package.json index 817db0fc0..fec9b1c8a 100644 --- a/packages/project-service/package.json +++ b/packages/project-service/package.json @@ -1,6 +1,6 @@ { "name": "@appworks/project-service", - "version": "0.1.2", + "version": "0.1.3", "description": "AppWorks project service for VSCode extension.", "files": [ "lib" diff --git a/packages/project-service/src/index.ts b/packages/project-service/src/index.ts index ab0fe84c2..e4d799a17 100644 --- a/packages/project-service/src/index.ts +++ b/packages/project-service/src/index.ts @@ -52,9 +52,9 @@ export async function checkIsTargetProjectFramework() { export async function getFeedbackLink() { const framework = await getProjectFramework(); if (framework === 'icejs') { - return 'https://c.tb.cn/F3.ZpKQYk'; + return 'https://links.alipay.com/app/room/5f717ef787f98104f34edc18/?short_name=F3.ZA5bU1'; } else if (framework === 'rax-app') { - return 'https://c.tb.cn/F3.ZLhGNW'; + return 'https://links.alipay.com/app/room/5f6c6bf104dbbf056d050f25/?short_name=F3.ZzWClz'; } } diff --git a/scripts/o2/config.ts b/scripts/o2/config.ts index ea6768a14..cebe06d12 100644 --- a/scripts/o2/config.ts +++ b/scripts/o2/config.ts @@ -1,5 +1,12 @@ import * as camelCase from 'lodash.camelcase'; +interface OtherExtension { + packageName: string; + assetsFolders: string[]; + isActiveNode: boolean; + isActiveBrowser: boolean; +} + export const isBeta = !process.env.CI; // CI is true when running in GitHub action export const pushExtension2Npm = false; // modify it to true when publish to tnpm export const innerExtensions4pack = [ @@ -23,14 +30,27 @@ export const innerExtensions4pack = [ packageName: 'iceworks-team.iceworks-time-master', assetsFolders: ['assets', 'schemas'], }, -]; -export const otherExtensions4pack = [ { + packageName: 'iceworks-team.iceworks-refactor', + assetsFolders: ['assets', 'schemas'], + }, + { + packageName: 'iceworks-team.iceworks-generator', + assetsFolders: ['assets', 'schemas'], + }, +]; +const otherExtensions: OtherExtension[] = [ + { packageName: '@ali/publish-visual', assetsFolders: ['icons', 'resource'], isActiveNode: true, isActiveBrowser: true, }, -].map((otherExtension4pack) => ({ ...otherExtension4pack, extensionName: camelCase(otherExtension4pack.packageName), isOther: true })); +]; + +export const otherExtensions4pack = otherExtensions.map((otherExtension4pack) => ( + { ...otherExtension4pack, extensionName: camelCase(otherExtension4pack.packageName), isOther: true } +)); + export const npmRegistry = process.env.REGISTRY ? process.env.REGISTRY : 'https://registry.npm.alibaba-inc.com';