Skip to content

Commit

Permalink
Merge pull request #21 from oe/feat/drop-deploy-toolkit
Browse files Browse the repository at this point in the history
chore: remove dependence deploy-toolkit
  • Loading branch information
oe authored May 17, 2024
2 parents dbb20c8 + 8c6bbd9 commit 9304734
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 116 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
# events but only for the main branch
on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@types/semver": "^7.3.9",
"@types/yargs": "^17.0.13",
"cosmiconfig": "^7.0.1",
"deploy-toolkit": "^0.1.1",
"detect-indent": "^6.0.0",
"find-packages": "^9.0.10",
"fixpack": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/can-publish/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import semver from 'semver'
import { runShellCmd } from 'deploy-toolkit'
import {
getAllPackageDigests,
EVerSource,
Expand All @@ -10,6 +9,7 @@ import {
getVersionFormRegistry,
logger,
IChangedPackage,
runShellCmd,
} from '../common'
import { syncLocal } from '../sync-local'
import { getChanged } from '../changed'
Expand Down
3 changes: 1 addition & 2 deletions src/common/get-all-packages/lerna.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from 'fs'
import path from 'path'
import { runShellCmd } from 'deploy-toolkit'
import { IPackageDigest } from '../types'
import { getProjectRoot, isWin, runNpmCmd } from '../utils'
import { getProjectRoot, isWin, runNpmCmd, runShellCmd } from '../utils'

/**
* get all package's info in a lerna project
Expand Down
3 changes: 1 addition & 2 deletions src/common/get-all-packages/native-client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import path from 'path'
import fs from 'fs'
import { runShellCmd } from 'deploy-toolkit'
import findPkgs from 'find-packages'
import { IPackageDigest } from '../types'
import { getProjectRoot, readPackageJson, readRootPkgJson } from '../utils'
import { getProjectRoot, readPackageJson, readRootPkgJson, runShellCmd } from '../utils'
import { getRepoNpmClient } from '../get-package-version/npm'
/**
* get all package's info in a lerna project
Expand Down
4 changes: 2 additions & 2 deletions src/common/get-package-version/git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { runShellCmd } from 'deploy-toolkit'

import { IVersionPickStrategy, IVersionMap } from '../types'
import { maxVersion, syncPruneGitTags } from '../utils'
import { runShellCmd, maxVersion, syncPruneGitTags } from '../utils'
/**
* get package version from git tags
*/
Expand Down
3 changes: 1 addition & 2 deletions src/common/get-package-version/npm/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import path from 'path'
import fs from 'fs'
import { runShellCmd } from 'deploy-toolkit'
import { IGetPkgVersionFromRegistryOptions } from './common'
import { getProjectRoot, readRootPkgJson } from '../../utils'
import { runShellCmd, getProjectRoot, readRootPkgJson } from '../../utils'
import { IVersionPickStrategy, IVersionMap } from '../../types'
import { logger } from '../../logger'
import * as npm from './npm'
Expand Down
2 changes: 1 addition & 1 deletion src/common/get-package-version/npm/npm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { runShellCmd } from 'deploy-toolkit'
import { runShellCmd } from '../../utils'
import { IGetPkgVersionFromRegistry, getMaxStableVersion } from './common'

/**
Expand Down
2 changes: 1 addition & 1 deletion src/common/get-package-version/npm/yarn-next.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { runShellCmd } from 'deploy-toolkit'
import { runShellCmd } from '../../utils'
import { IGetPkgVersionFromRegistry, getMaxStableVersion } from './common'

export const getPkgVersion: IGetPkgVersionFromRegistry = async (options): Promise<string> => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/get-package-version/npm/yarn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { runShellCmd } from 'deploy-toolkit'
import { runShellCmd } from '../../utils'
import { IGetPkgVersionFromRegistry, getMaxStableVersion } from './common'

export const getPkgVersion: IGetPkgVersionFromRegistry = async (options): Promise<string> => {
Expand Down
84 changes: 83 additions & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import fs from 'fs'
import semver from 'semver'
import { runShellCmd, findFileRecursive } from 'deploy-toolkit'
import child_process, { type SpawnOptions } from 'child_process'
import { IPackageDigest } from './types'

/**
Expand All @@ -12,6 +12,88 @@ export const PKG_DEP_KEYS = <const>['dependencies', 'devDependencies', 'peerDep
/** platform detect */
export const isWin = /^win/.test(process.platform)


/**
* run local shell command with spawn
* resolve with command exec outputs if cmd return 0, or reject with error message
* @param {String} cmd cmd name
* @param {Array<String>} args args list
* @param {Object} options spawn cmd options, cwd is vital
*/
export function runShellCmd (cmd: string, options?: SpawnOptions): Promise<string>
export function runShellCmd (cmd: string, args?: string[], options?: SpawnOptions): Promise<string>
export function runShellCmd (cmd: string, args?: string[] | SpawnOptions, options?: SpawnOptions) {
if (!Array.isArray(args)) {
options = args
args = []
}
const task = child_process.spawn(
cmd,
// @ts-ignore
args,
Object.assign(
{
cwd: process.cwd(),
shell: true
},
options
)
)

return new Promise<string>((resolve, reject) => {
// record response content
const stdout: (string | Buffer)[] = []
const stderr: (string | Buffer)[] = []
task.stdout!.on('data', data => {
stdout.push(data)
})
task.stderr!.on('data', data => {
stderr.push(data)
})

// listen on error, to aviod command crash
task.on('error', () => {
reject(stderr.join('').toString())
})

task.on('exit', code => {
if (code) {
stderr.unshift(`error code: ${code}\n`)
reject(stderr.join('').toString())
} else {
resolve(stdout.join('').toString())
}
})
})
}

/**
* find a file(dir) recursive( aka try to find package.json, node_modules, etc.)
* @param fileName file name(or dir name if isDir is true)
* @param dir the initial dir path to find, use `process.cwd()` by default
* @param isDir whether to find a dir
*/
export function findFileRecursive (fileName: string | string[], dir = process.cwd(), isDir = false): string {
// const filepath = path.join(dir, fileName)
const fileNames = Array.isArray(fileName) ? fileName : [fileName]
let f: string | undefined = ''
// tslint:disable-next-line:no-conditional-assignment
while ((f = fileNames.shift())) {
const filepath = path.join(dir, f)
try {
const stat = fs.statSync(filepath)
const isFound = isDir ? stat.isDirectory() : stat.isFile()
if (isFound) return filepath
} catch (e) {
// xxx
}
}
// has reach the top root
const parentDir = path.dirname(dir)
if (parentDir === dir) return ''
return findFileRecursive(fileName, parentDir, isDir)
}

/** run npm command via npx */
export async function runNpmCmd(...args: string[]) {
const rootPath = await getProjectRoot()
Expand Down
99 changes: 0 additions & 99 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -180,29 +180,11 @@
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.3.tgz#472eaab5f15c1ffdd7f8628bd4c4f753995ec79e"
integrity sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==

"@types/glob@^7.1.1":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
integrity sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==
dependencies:
"@types/minimatch" "*"
"@types/node" "*"

"@types/json-schema@^7.0.9":
version "7.0.11"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==

"@types/minimatch@*":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==

"@types/node@*":
version "18.7.19"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.7.19.tgz#ad83aa9b7af470fab7e0f562be87e97dc8ffe08e"
integrity sha512-Sq1itGUKUX1ap7GgZlrzdBydjbsJL/NSQt/4wkAxUJ7/OS5c2WkoN6WSpWc2Yc5wtKMZOUA0VCs/j2XJadN3HA==

"@types/node@14":
version "14.18.30"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.30.tgz#34c8d934fe86b6ee5c21c08fc1b7858599c84a5a"
Expand Down Expand Up @@ -377,13 +359,6 @@ array-union@^2.1.0:
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==

asn1@~0.2.0:
version "0.2.6"
resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.6.tgz#0d3a7bb6e64e02a90c0303b31f292868ea09a08d"
integrity sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==
dependencies:
safer-buffer "~2.1.0"

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
Expand Down Expand Up @@ -514,15 +489,6 @@ deep-is@^0.1.3:
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.4.tgz#a6f2dce612fadd2ef1f519b73551f17e85199831"
integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==

deploy-toolkit@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/deploy-toolkit/-/deploy-toolkit-0.1.1.tgz#98c7537c7f8b177a748a9a5689b8b9989ba95bff"
integrity sha512-WMloOccEhWvuX0uoBBRtyz8gy54yz4OcVIuoBHpETmiMgUFpZp/EK+mt/QrjRc2a+Y2c+aD2K26+5RLzLRxbHw==
dependencies:
"@types/glob" "^7.1.1"
glob "^7.1.3"
node-ssh "^5.1.2"

detect-indent@^6.0.0, detect-indent@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-6.1.0.tgz#592485ebbbf6b3b1ab2be175c8393d04ca0d57e6"
Expand Down Expand Up @@ -1067,17 +1033,6 @@ natural-compare@^1.4.0:
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==

node-ssh@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/node-ssh/-/node-ssh-5.1.2.tgz#10712969d55c7d5ad5bb66a593ca6499e8dc8d10"
integrity sha512-Z1dXZzKthWELy7/+obyQmxgci8UNS89bzvKMdNTynskt5QWrhXhry0GdfH4kmqyKUo2BB3JELIQDk+6mSJLylA==
dependencies:
p-map "^1.2.0"
sb-promisify "^2.0.1"
sb-scandir "^2.0.0"
shell-escape "^0.2.0"
ssh2 "^0.5.0"

once@^1.3.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
Expand Down Expand Up @@ -1118,11 +1073,6 @@ p-locate@^5.0.0:
dependencies:
p-limit "^3.0.2"

p-map@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.2.0.tgz#e4e94f311eabbc8633a1e79908165fca26241b6b"
integrity sha512-r6zKACMNhjPJMTl8KcFH4li//gkrXWfbD6feV8l6doRHlzljFWGJ2AP6iKaCJXyZmAUMOPtvbW7EXkbWO/pLEA==

p-map@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/p-map/-/p-map-2.1.0.tgz#310928feef9c9ecc65b68b17693018a665cea175"
Expand Down Expand Up @@ -1249,29 +1199,6 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"

safer-buffer@~2.1.0:
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==

sb-promisify@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/sb-promisify/-/sb-promisify-2.0.2.tgz#4277a54754488aa9675d886e354db894c9bdc981"
integrity sha512-i7k8tMx+mJWIzM+Q5WWT7hfwUEaMfreDf0otZf+V41X3aKAjbLE9kCX4vR44BuqJalKHmGMYpWQP3yaMI2JP3g==

sb-scandir@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/sb-scandir/-/sb-scandir-2.0.0.tgz#a02ad1fa44a8bd2bfaf30193d14d23c2f35ab6b2"
integrity sha512-SKbyMJB0DUt9OgN4tP2RBcn9OsR26DEpe+nwaDkQTNcrJSJI0FlLhXhBpTd/YEnlQ2GdLrbszSNekGLw4rweOQ==
dependencies:
p-map "^1.2.0"
sb-promisify "^2.0.1"

semver@^5.1.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

semver@^7.3.5, semver@^7.3.7:
version "7.3.7"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
Expand All @@ -1291,11 +1218,6 @@ shebang-regex@^3.0.0:
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==

shell-escape@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/shell-escape/-/shell-escape-0.2.0.tgz#68fd025eb0490b4f567a027f0bf22480b5f84133"
integrity sha512-uRRBT2MfEOyxuECseCZd28jC1AJ8hmqqneWQ4VWUTgCAFvb3wKU1jLqj6egC4Exrr88ogg3dp+zroH4wJuaXzw==

signal-exit@^3.0.2:
version "3.0.7"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
Expand All @@ -1313,27 +1235,6 @@ sort-keys@^4.2.0:
dependencies:
is-plain-obj "^2.0.0"

ssh2-streams@~0.1.18:
version "0.1.20"
resolved "https://registry.yarnpkg.com/ssh2-streams/-/ssh2-streams-0.1.20.tgz#51118d154555df5469ee1f67e0cf1e7e8a2c0e3a"
integrity sha512-uqI2NfwMXF0PgY1IWivWWlfr4Ws6wsFF5Eug/bmpyyVn/k7T2VoNfJT6ynhM0JW1NpeIZuYHOENUCLx6NFK6Jw==
dependencies:
asn1 "~0.2.0"
semver "^5.1.0"
streamsearch "~0.1.2"

ssh2@^0.5.0:
version "0.5.5"
resolved "https://registry.yarnpkg.com/ssh2/-/ssh2-0.5.5.tgz#c7781ecd2ece7304a253cf620fab5a5c22bb2235"
integrity sha512-FF+j7szpg7oegbs6anQEgBU3S+GXvTYYGBpPuKUZd306rpsY2qHxwpaK1hc+6AIBr5uIl2gt1pYVjvdo+C67Hw==
dependencies:
ssh2-streams "~0.1.18"

streamsearch@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-0.1.2.tgz#808b9d0e56fc273d809ba57338e929919a1a9f1a"
integrity sha512-jos8u++JKm0ARcSUTAZXOVC0mSox7Bhn6sBgty73P1f3JGf7yG2clTbBNHUdde/kdvP2FESam+vM6l8jBrNxHA==

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
Expand Down

0 comments on commit 9304734

Please sign in to comment.