From 86357116885fe35845ed5fb526f9c41f89e32411 Mon Sep 17 00:00:00 2001 From: Korobeinikov Evgeny Date: Thu, 25 Jul 2024 12:38:11 +0300 Subject: [PATCH 1/3] publish ets-tsc compiler --- .gitignore | 2 + arkoala/package.json | 66 +++++++++++++++++-------------- arkoala/tools/publish.mjs | 68 ++++++++++++++++++++++++++++++++ arkoala/tools/rename_package.mjs | 25 ++++++++++++ incremental/package.json | 2 +- 5 files changed, 133 insertions(+), 30 deletions(-) create mode 100644 arkoala/tools/publish.mjs create mode 100644 arkoala/tools/rename_package.mjs diff --git a/.gitignore b/.gitignore index dd87e2d73..9d656d863 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules +.packages +.npmrc build diff --git a/arkoala/package.json b/arkoala/package.json index 497136a14..018fa733f 100644 --- a/arkoala/package.json +++ b/arkoala/package.json @@ -1,31 +1,39 @@ { - "name": "workspace", - "private": true, - "workspaces": [ - "framework", - "arkui-common", - "ets-plugin", - "../incremental/build-common", - "../incremental/compat", - "../incremental/common", - "../incremental/runtime", - "../incremental/compiler-plugin", - "../incrementalets-plugin", - "../interop" - ], - "devDependencies": { - "ohos-typescript": "4.9.5-r4", - "typescript": "4.9.5", - "bin-links": "^4.0.4", - "read-package-json-fast": "^3.0.2", - "ts-patch": "^2.1.0", - "tslib": "^2.3.1", - "ts-node": "^10.7.0", - "chai": "^4.3.6", - "@types/chai": "^4.3.1" - }, - "scripts": { - "prepare": "cd node_modules/typescript && ts-patch install", - "postinstall": "node tools/force_tsc.js" - } + "name": "workspace", + "private": true, + "workspaces": [ + "framework", + "arkui-common", + "ets-plugin", + "../incremental/build-common", + "../incremental/compat", + "../incremental/common", + "../incremental/runtime", + "../incremental/compiler-plugin", + "../incrementalets-plugin", + "../interop" + ], + "devDependencies": { + "ohos-typescript": "4.9.5-r4", + "typescript": "4.9.5", + "bin-links": "^4.0.4", + "read-package-json-fast": "^3.0.2", + "ts-patch": "^2.1.0", + "tslib": "^2.3.1", + "ts-node": "^10.7.0", + "chai": "^4.3.6", + "@types/chai": "^4.3.1" + }, + "scripts": { + "prepare": "cd node_modules/typescript && ts-patch install", + "postinstall": "node tools/force_tsc.js", + "clean": "rimraf .packages", + "copy-tsc": "mkdir -p .packages && cp -rf ./node_modules/typescript .packages", + "copy-ohos-tsc": "mkdir -p .packages && cp -rf ./node_modules/ohos-typescript .packages", + "patch-ts-patch": "node tools/patch-ts-patch.mjs ./node_modules/ts-patch", + "patch-ohos-tsc": "npm run patch-ts-patch && cd .packages/ohos-typescript && ts-patch install", + "rename-ohos-tsc": "node tools/rename_package.mjs @koalaui/ets-tsc .packages/ohos-typescript/", + "pack-ets-tsc": "npm run copy-ohos-tsc && npm run patch-ohos-tsc && npm run rename-ohos-tsc && npm pack .packages/ohos-typescript/ --pack-destination .packages/", + "publish": "npm run pack-ets-tsc && node tools/publish.mjs" + } } diff --git a/arkoala/tools/publish.mjs b/arkoala/tools/publish.mjs new file mode 100644 index 000000000..98e2290ae --- /dev/null +++ b/arkoala/tools/publish.mjs @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as fs from 'fs' +import path from 'path' +import process from "process" +import { execSync } from "child_process" +import chalk from "chalk" + +const CWD = process.cwd() +const packagePath = path.join(CWD, ".packages") + +const keyKoalaRegistry = "@koalaui:registry" +const koalaRegistry = "https://rnd-gitlab-msc.huawei.com/api/v4/projects/3921/packages/npm/" +const openlabRegistry = "https://nexus.bz-openlab.ru:10443/repository/koala-npm/" + +function setRegistry(key, value) { + execSync(`npm config --location project set ${key} ${value}`) +} + +function getRegistry(key) { + execSync(`npm config --location project get ${key}`) +} + +function publishToOpenlab() { + + setRegistry(keyKoalaRegistry, openlabRegistry) + setRegistry("strict-ssl", false) + + fs.readdirSync(packagePath).map(file => { + if (path.extname(file) === ".tgz") { + console.log(chalk.green(`> Publishing ${file}...`)) + execSync(`npm publish ${path.join(packagePath, file)}`) + } + }) + +} + +function publishToGitlab() { + + setRegistry(keyKoalaRegistry, koalaRegistry) + setRegistry("strict-ssl", false) + + fs.readdirSync(packagePath).map(file => { + if (path.extname(file) === ".tgz") { + console.log(chalk.green(`> Publishing ${file}...`)) + execSync(`npm publish ${path.join(packagePath, file)}`) + } + }) +} + +function publish() { + process.env.KOALA_BZ == true ? publishToOpenlab() : publishToGitlab() +} + +publish() \ No newline at end of file diff --git a/arkoala/tools/rename_package.mjs b/arkoala/tools/rename_package.mjs new file mode 100644 index 000000000..5774e8123 --- /dev/null +++ b/arkoala/tools/rename_package.mjs @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as fs from 'fs' +import path from 'path' + +const newName = process.argv[2] +const packagePath = process.argv[3] + +const packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, "package.json"))) +console.log(`> Renaming ${packageJson.name} to ${newName}`) +packageJson.name = newName +fs.writeFileSync(path.join(packagePath, "package.json"), JSON.stringify(packageJson, null, 2), 'utf8') \ No newline at end of file diff --git a/incremental/package.json b/incremental/package.json index 85d2922c4..772885320 100644 --- a/incremental/package.json +++ b/incremental/package.json @@ -6,7 +6,7 @@ "compat", "common", "runtime", - "compiler-plugin", + "compiler-plugin" ], "devDependencies": { "@types/chai": "4.3.10", -- Gitee From a79bc79a245f3a74f6fffb70ba7381a51c4c11ad Mon Sep 17 00:00:00 2001 From: Korobeinikov Evgeny Date: Thu, 25 Jul 2024 16:59:43 +0300 Subject: [PATCH 2/3] using ets-tsc in ets-plugin --- arkoala/ets-plugin/package.json | 6 ++---- arkoala/ets-plugin/tsconfig.json | 3 +-- arkoala/package.json | 5 ++--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/arkoala/ets-plugin/package.json b/arkoala/ets-plugin/package.json index 990563885..5515f9ac5 100644 --- a/arkoala/ets-plugin/package.json +++ b/arkoala/ets-plugin/package.json @@ -9,11 +9,9 @@ "build/lib/**/*.d.ts" ], "scripts": { - "patch-ts-patch": "node ../tools/patch-ts-patch.mjs ../node_modules/ts-patch", - "patch-ohos-typescript": "cd ../node_modules/ohos-typescript && ts-patch install", - "compile": "npm run patch-ts-patch && npm run patch-ohos-typescript && node ../node_modules/ohos-typescript/bin/tsc -b .", + "compile": "node ../node_modules/@koalaui/ets-tsc/bin/tsc -b .", "clean": "rimraf build dist test/dump test/generated test/ets/specification test/specification/ets2bundle", - "ets:test": "cd test/ets; ../../../node_modules/ohos-typescript/bin/tsc", + "ets:test": "cd test/ets; ../../../node_modules/@koalaui/ets-tsc/bin/tsc", "test": "npm run compile && npm run ets:test && mocha --reporter-option maxDiffSize=0", "test:coverage": "nyc mocha", "canonize": "cp -r test/generated/. test/golden/", diff --git a/arkoala/ets-plugin/tsconfig.json b/arkoala/ets-plugin/tsconfig.json index 86da8a451..171b3f3c0 100644 --- a/arkoala/ets-plugin/tsconfig.json +++ b/arkoala/ets-plugin/tsconfig.json @@ -4,8 +4,7 @@ "outDir": "build/lib", "rootDirs": ["src", "test"], "module": "CommonJS", - "moduleResolution": "node", - "baseUrl": "./ohos-typescript/node_modules" + "moduleResolution": "node" }, "include": ["src/**/*"] } diff --git a/arkoala/package.json b/arkoala/package.json index 018fa733f..e09c33e36 100644 --- a/arkoala/package.json +++ b/arkoala/package.json @@ -14,6 +14,7 @@ "../interop" ], "devDependencies": { + "@koalaui/ets-tsc": "4.9.5-r4", "ohos-typescript": "4.9.5-r4", "typescript": "4.9.5", "bin-links": "^4.0.4", @@ -25,8 +26,6 @@ "@types/chai": "^4.3.1" }, "scripts": { - "prepare": "cd node_modules/typescript && ts-patch install", - "postinstall": "node tools/force_tsc.js", "clean": "rimraf .packages", "copy-tsc": "mkdir -p .packages && cp -rf ./node_modules/typescript .packages", "copy-ohos-tsc": "mkdir -p .packages && cp -rf ./node_modules/ohos-typescript .packages", @@ -34,6 +33,6 @@ "patch-ohos-tsc": "npm run patch-ts-patch && cd .packages/ohos-typescript && ts-patch install", "rename-ohos-tsc": "node tools/rename_package.mjs @koalaui/ets-tsc .packages/ohos-typescript/", "pack-ets-tsc": "npm run copy-ohos-tsc && npm run patch-ohos-tsc && npm run rename-ohos-tsc && npm pack .packages/ohos-typescript/ --pack-destination .packages/", - "publish": "npm run pack-ets-tsc && node tools/publish.mjs" + "upload": "npm run pack-ets-tsc && node tools/publish.mjs" } } -- Gitee From 911f3539ef052679b1eba768f526f2dadc004c91 Mon Sep 17 00:00:00 2001 From: Korobeinikov Evgeny Date: Mon, 29 Jul 2024 14:36:41 +0300 Subject: [PATCH 3/3] add memo-tsc --- arkoala/ets-plugin/package.json | 8 ++++---- arkoala/package.json | 10 ++++++++-- arkoala/tools/rename_package.mjs | 29 +++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/arkoala/ets-plugin/package.json b/arkoala/ets-plugin/package.json index 5515f9ac5..1aa2187fb 100644 --- a/arkoala/ets-plugin/package.json +++ b/arkoala/ets-plugin/package.json @@ -9,16 +9,16 @@ "build/lib/**/*.d.ts" ], "scripts": { - "compile": "node ../node_modules/@koalaui/ets-tsc/bin/tsc -b .", + "compile": "node ../node_modules/@koalaui/ets-tsc/bin/ets-tsc -b .", "clean": "rimraf build dist test/dump test/generated test/ets/specification test/specification/ets2bundle", - "ets:test": "cd test/ets; ../../../node_modules/@koalaui/ets-tsc/bin/tsc", + "ets:test": "cd test/ets; ../../../node_modules/@koalaui/ets-tsc/bin/ets-tsc", "test": "npm run compile && npm run ets:test && mocha --reporter-option maxDiffSize=0", "test:coverage": "nyc mocha", "canonize": "cp -r test/generated/. test/golden/", - "compile:spec": "cd test/ets && ../../../node_modules/ohos-typescript/bin/tsc -p spec-tsconfig.json", + "compile:spec": "cd test/ets && ../../../node_modules/@koalaui/ets-tsc/bin/ets-tsc -p spec-tsconfig.json", "test:spec": "npm run compile && npm run sync:spec && npm run compile:spec && mocha --config spec.mocharc.json", - "compile:sync:spec": "cd test/scripts && ../../../node_modules/typescript/bin/tsc -p tsconfig-sync-specification.json", + "compile:sync:spec": "cd test/scripts && ../../../node_modules/@koalaui/memo-tsc/bin/memo-tsc -p tsconfig-sync-specification.json", "sync:spec": "npm run compile:sync:spec && cd build/test/scripts && node sync-specification.js" }, "keywords": [], diff --git a/arkoala/package.json b/arkoala/package.json index e09c33e36..cd6600e81 100644 --- a/arkoala/package.json +++ b/arkoala/package.json @@ -15,6 +15,7 @@ ], "devDependencies": { "@koalaui/ets-tsc": "4.9.5-r4", + "@koalaui/memo-tsc": "4.9.5", "ohos-typescript": "4.9.5-r4", "typescript": "4.9.5", "bin-links": "^4.0.4", @@ -29,10 +30,15 @@ "clean": "rimraf .packages", "copy-tsc": "mkdir -p .packages && cp -rf ./node_modules/typescript .packages", "copy-ohos-tsc": "mkdir -p .packages && cp -rf ./node_modules/ohos-typescript .packages", + "patch-tsc": "cd .packages/typescript && ts-patch install", "patch-ts-patch": "node tools/patch-ts-patch.mjs ./node_modules/ts-patch", "patch-ohos-tsc": "npm run patch-ts-patch && cd .packages/ohos-typescript && ts-patch install", - "rename-ohos-tsc": "node tools/rename_package.mjs @koalaui/ets-tsc .packages/ohos-typescript/", + "rename-ohos-tsc": "node tools/rename_package.mjs ets-tsc .packages/ohos-typescript/", + "rename-tsc": "node tools/rename_package.mjs memo-tsc .packages/typescript/", + "pack-memo-tsc": "npm run copy-tsc && npm run patch-tsc && npm run rename-tsc && npm pack .packages/typescript/ --pack-destination .packages/", "pack-ets-tsc": "npm run copy-ohos-tsc && npm run patch-ohos-tsc && npm run rename-ohos-tsc && npm pack .packages/ohos-typescript/ --pack-destination .packages/", - "upload": "npm run pack-ets-tsc && node tools/publish.mjs" + "upload-bz": "npm run pack-memo-tsc && npm run pack-ets-tsc && KOALA_BZ=1 node tools/publish.mjs", + "upload-gz": "npm run pack-memo-tsc && npm run pack-ets-tsc && KOALA_BZ=0 node tools/publish.mjs", + "upload": "npm run pack-memo-tsc && npm run pack-ets-tsc && node tools/publish.mjs" } } diff --git a/arkoala/tools/rename_package.mjs b/arkoala/tools/rename_package.mjs index 5774e8123..1782ad652 100644 --- a/arkoala/tools/rename_package.mjs +++ b/arkoala/tools/rename_package.mjs @@ -18,8 +18,29 @@ import path from 'path' const newName = process.argv[2] const packagePath = process.argv[3] +const packageKey = "@koalaui" -const packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, "package.json"))) -console.log(`> Renaming ${packageJson.name} to ${newName}`) -packageJson.name = newName -fs.writeFileSync(path.join(packagePath, "package.json"), JSON.stringify(packageJson, null, 2), 'utf8') \ No newline at end of file +function renamePackage() { + const packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, "package.json"))) + console.log(`> Renaming ${packageJson.name} to ${newName}`) + packageJson.name = packageKey + "/" + newName + fs.writeFileSync(path.join(packagePath, "package.json"), JSON.stringify(packageJson, null, 2), 'utf8') +} + +function renameBin() { + const tscPath = path.join(packagePath, "bin/tsc") + if (!fs.existsSync(tscPath)) throw new Error("bin/tsc not found") + const newPath = path.join(packagePath, `bin/${newName}`) + fs.renameSync(tscPath, newPath) +} + +function rename() { + if (newName !== "memo-tsc") { + renameBin() + renamePackage() + } else { + renamePackage() + } +} + +rename() \ No newline at end of file -- Gitee