Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce setup-brew package #266

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dev/cpp_vcpkg_project/**/*",
"**/.venv/",
"**/.*cache/",
"coverage/",
"**/coverage/"
],
"ignoreUnknown": true
Expand Down
10 changes: 5 additions & 5 deletions dist/actions/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/setup-cpp.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/modern/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions jest.config.ts → jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Config } from "jest"

const jestConfig: Config = {
/**
* @type {import('jest').Config}
*/
const jestConfig = {
testMatch: ["**/*.test.ts"],
testEnvironment: "node",
extensionsToTreatAsEsm: [".ts", ".tsx", ".jsx"],
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
"build.babel": "babel ./dist --out-dir dist --plugins @upleveled/babel-plugin-remove-node-prefix --plugins @babel/plugin-transform-private-methods --compact --no-babelrc --source-maps true",
"build.modern": "shx cp -r ./dist/actions/* ./dist/modern",
"bump": "ncu -u -x numerous,execa,prettier,@types/node,eslint,@types/eslint && pnpm update && pnpx typesync && pnpm run clean",
"clean": "shx rm -rf ./dist ./exe ./.parcel-cache && shx mkdir -p ./dist/legacy ./dist/actions ./dist/modern ",
"clean": "shx rm -rf ./dist ./packages/*/dist ./exe ./.parcel-cache && shx mkdir -p ./dist/legacy ./dist/actions ./dist/modern ",
"copy.matchers": "run-p copy.matchers.legacy copy.matchers.actions",
"copy.matchers.legacy": "shx cp ./src/gcc/gcc_matcher.json ./dist/legacy/ && shx cp ./src/msvc/msvc_matcher.json ./dist/legacy/ && shx cp ./src/python/python_matcher.json ./dist/legacy/ && shx cp ./src/llvm/llvm_matcher.json ./dist/legacy/",
"copy.matchers.actions": "shx cp ./src/gcc/gcc_matcher.json ./dist/actions/ && shx cp ./src/msvc/msvc_matcher.json ./dist/actions/ && shx cp ./src/python/python_matcher.json ./dist/actions/ && shx cp ./src/llvm/llvm_matcher.json ./dist/actions/",
"dev": "cross-env NODE_ENV=development parcel watch",
"dev.parcel": "cross-env NODE_ENV=development parcel watch",
"dev.packages": "turbo dev",
"dev": "run-p dev.packages dev.parcel",
"docs": "shx rm -rf packages/*/README.md && pnpm -r exec readme --path ../../dev/readme/template.md -y && pnpm -r exec ts-readme",
"format": "run-s lint.dprint",
"lint": "turbo lint && run-p --aggregate-output --continue-on-error lint.**",
Expand All @@ -52,7 +54,7 @@
"test.lint.root.eslint": "eslint ./{src,dev}/**/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
"test.lint.biome": "biome check",
"test.lint.dprint": "dprint check",
"test": "jest --runInBand --forceExit --coverage",
"test": "turbo test && jest --runInBand --forceExit --coverage",
"build.docker-ci": "node ./dev/docker/ci/docker-ci.mjs"
},
"devDependencies": {
Expand Down Expand Up @@ -114,6 +116,7 @@
"retry-as-promised": "^7.0.4",
"semver": "7.6.3",
"setup-python": "github:aminya/setup-python#a783db655c6e40317e2c0c96f9d162d9c9f4a751",
"setup-brew": "workspace:*",
"shx": "0.3.4",
"simple-update-notifier": "^2.0.0",
"terser-config-atomic": "^1.0.0",
Expand Down Expand Up @@ -157,6 +160,7 @@
"retry-as-promised",
"semver",
"setup-apt",
"setup-brew",
"setup-python",
"simple-update-notifier",
"time-delta",
Expand Down
4 changes: 3 additions & 1 deletion packages/ci-log/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h1 align="center">ci-log</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
<a href="https://www.npmjs.com/package/ci-log" target="_blank">
<img alt="Version" src="https://img.shields.io/npm/v/ci-log.svg">
</a>
<a href="#" target="_blank">
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
</a>
Expand Down
2 changes: 2 additions & 0 deletions packages/ci-log/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"author": "Amin Yahyaabadi",
"main": "./dist/index.js",
"source": "./src/index.ts",
"type": "module",
"scripts": {
"build": "tsc --pretty",
"dev": "tsc --watch --pretty",
"lint.tsc": "tsc --noEmit --pretty",
"lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/ --fix",
"prepublishOnly": "pnpm run build"
Expand Down
12 changes: 11 additions & 1 deletion packages/envosman/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h1 align="center">envosman</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
<a href="https://www.npmjs.com/package/envosman" target="_blank">
<img alt="Version" src="https://img.shields.io/npm/v/envosman.svg">
</a>
<img src="https://img.shields.io/badge/node-%3E%3D12-blue.svg" />
<a href="#" target="_blank">
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
Expand All @@ -23,6 +25,8 @@ npm install --save envosman

### `RcOptions` (type)

Options for adding an rc file

### `sourceRCInRc` (variable)

handles adding conditions to source rc file from .bashrc and .profile
Expand All @@ -48,6 +52,8 @@ Escape a string for use in a shell command

### `AddEnvOptions` (type)

The options for adding an environment variable

### `addEnv` (function)

Add an environment variable.
Expand All @@ -62,6 +68,10 @@ This function is cross-platforms and works in all the local or CI systems.

**returns:** Promise<void>

### `AddPathOptions` (type)

The options for adding a PATH variable

### `addPath` (function)

Add a path to the PATH environment variable.
Expand Down
2 changes: 2 additions & 0 deletions packages/envosman/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"author": "Amin Yahyaabadi",
"main": "./dist/index.js",
"source": "./src/index.ts",
"type": "module",
"scripts": {
"build": "tsc --pretty",
"dev": "tsc --watch --pretty",
"lint.tsc": "tsc --noEmit --pretty",
"lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/ --fix",
"prepublishOnly": "pnpm run build"
Expand Down
2 changes: 1 addition & 1 deletion packages/envosman/src/add-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { appendFile } = promises
/**
* The options for adding a PATH variable
*/
type AddPathOptions = {
export type AddPathOptions = {
/**
* The path to the RC file that the PATH variables should be added to.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/envosman/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { addEnv } from "./add-env.js"
export { addPath } from "./add-path.js"
export { addEnv, AddEnvOptions } from "./add-env.js"
export { addPath, AddPathOptions } from "./add-path.js"
export { finalizeRC, sourceRCInRc as sourceRC } from "./rc-file.js"
4 changes: 3 additions & 1 deletion packages/exec-powershell/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h1 align="center">exec-powershell</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
<a href="https://www.npmjs.com/package/exec-powershell" target="_blank">
<img alt="Version" src="https://img.shields.io/npm/v/exec-powershell.svg">
</a>
<a href="#" target="_blank">
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
</a>
Expand Down
2 changes: 2 additions & 0 deletions packages/exec-powershell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"author": "Amin Yahyaabadi",
"main": "./dist/index.js",
"source": "./src/index.ts",
"type": "module",
"scripts": {
"build": "tsc --pretty",
"dev": "tsc --watch --pretty",
"lint.tsc": "tsc --noEmit --pretty",
"lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/ --fix",
"prepublishOnly": "pnpm run build"
Expand Down
4 changes: 3 additions & 1 deletion packages/setup-apt/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h1 align="center">setup-apt</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
<a href="https://www.npmjs.com/package/setup-apt" target="_blank">
<img alt="Version" src="https://img.shields.io/npm/v/setup-apt.svg">
</a>
<img src="https://img.shields.io/badge/node-%3E%3D12-blue.svg" />
<a href="#" target="_blank">
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
Expand Down
2 changes: 2 additions & 0 deletions packages/setup-apt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"author": "Amin Yahyaabadi",
"main": "./dist/index.js",
"source": "./src/index.ts",
"type": "module",
"scripts": {
"build": "tsc --pretty",
"dev": "tsc --watch --pretty",
"lint.tsc": "tsc --noEmit --pretty",
"lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/ --fix",
"prepublishOnly": "pnpm run build"
Expand Down
3 changes: 3 additions & 0 deletions packages/setup-brew/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../.eslintrc.json"
}
65 changes: 65 additions & 0 deletions packages/setup-brew/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<h1 align="center">setup-brew</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
<img src="https://img.shields.io/badge/node-%3E%3D12-blue.svg" />
<a href="#" target="_blank">
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
</a>
</p>

> Setup brew and brew packages

## Install

```sh
npm install --save setup-brew
```

## Usage

<!-- INSERT GENERATED DOCS START -->

### `InstallationInfo` (type)

The information about an installation result

### `SetupBrewOptions` (type)

### `setupBrew` (function)

**Parameters:**

- options (`SetupBrewOptions`)

**returns:** Promise<InstallationInfo>

### `getBrewBinDir` (function)

Get the path where brew is installed

**returns:** "/opt/homebrew/bin/" | "/usr/local/bin/" | "/home/linuxbrew/.linuxbrew/bin/"

### `BrewPackOptions` (type)

### `installBrewPack` (function)

A function that installs a package using brew

**Parameters:**

- name (`string`)
- version (`string`)
- givenOptions (`BrewPackOptions`)

**returns:** Promise<InstallationInfo>

<!-- INSERT GENERATED DOCS END -->

## 🤝 Contributing

You can sponsor my work here:

https://github.com/sponsors/aminya

Pull requests, issues and feature requests are welcome.
See the [Contributing guide](https://github.com/aminya/setup-cpp/blob/master/CONTRIBUTING.md).
45 changes: 45 additions & 0 deletions packages/setup-brew/__tests__/brew.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { join } from "path"
import spawn from "cross-spawn"
import { pathExists } from "path-exists"
import { addExeExt } from "patha"
import which from "which"
import { setupBrew } from "../src/index.js"

jest.setTimeout(300000)
describe("setup-brew", () => {
if (process.platform === "win32") {
it.skip("should setup brew", () => {})
return
}
it("should setup brew", async () => {
const installInfo = await setupBrew()
await testBin("brew", ["--version"], installInfo?.binDir)
})
})

async function testBin(
name: string,
args: string[] | null = ["--version"],
binDir: string | undefined = undefined,
) {
try {
let bin = name
if (typeof binDir === "string") {
console.log(`Testing the existence of ${binDir}`)
expect(binDir).toBeDefined()
expect(binDir).not.toHaveLength(0)
expect(await pathExists(binDir)).toBeTruthy()
bin = join(binDir, addExeExt(name))
}

if (args !== null) {
console.log(`Running ${bin} ${args.join(" ")}`)
const { status } = spawn.sync(bin, args, { stdio: "inherit" })
expect(status).toBe(0)
}

expect((await which(name, { nothrow: true }))?.includes(bin))
} catch (err) {
throw new Error(`Failed to test bin ${name}: ${err}`)
}
}
4 changes: 4 additions & 0 deletions packages/setup-brew/__tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.ts"]
}
2 changes: 2 additions & 0 deletions packages/setup-brew/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import jestConfig from "../../jest.config.mjs"
export default jestConfig
53 changes: 53 additions & 0 deletions packages/setup-brew/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "setup-brew",
"version": "1.0.0",
"description": "Setup brew and brew packages",
"repository": "https://github.com/aminya/setup-cpp",
"homepage": "https://github.com/aminya/setup-cpp/tree/master/packages/setup-brew",
"license": "Apache-2.0",
"author": "Amin Yahyaabadi",
"main": "./dist/index.js",
"source": "./src/index.ts",
"type": "module",
"scripts": {
"build": "tsc --pretty",
"dev": "tsc --watch --pretty",
"lint.tsc": "tsc --noEmit --pretty",
"lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/ --fix",
"prepublishOnly": "pnpm run build",
"test": "jest --coverage"
},
"dependencies": {
"@types/node": "^12",
"ci-log": "workspace:*",
"envosman": "workspace:*",
"which": "4.0.0",
"execa": "^7.2.0",
"setup-apt": "workspace:*",
"node-downloader-helper": "2.1.9"
},
"devDependencies": {
"path-exists": "5.0.0",
"patha": "0.4.1"
},
"engines": {
"node": ">=12"
},
"keywords": [
"setup",
"brew",
"install",
"brew-install",
"cask",
"formula",
"package",
"setup-brew",
"repositories",
"macos",
"homebrew",
"linuxbrew",
"osx",
"linux",
"ubuntu"
]
}
12 changes: 12 additions & 0 deletions packages/setup-brew/src/InstallationInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* The information about an installation result
*/

export type InstallationInfo = {
/** The install dir of the package (Defaults to `undefined`) */
installDir?: string
/** The bin dir of the package (Defaults to `/usr/bin`) */
binDir: string
/** The bin path of the package (Defaults to `undefined`) */
bin?: string
}
2 changes: 2 additions & 0 deletions packages/setup-brew/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./install-pack.js"
export * from "./install.js"
Loading
Loading