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: adding semantic-release-pnpm #25

Merged
merged 4 commits into from
May 22, 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Check the README for each package within the `packages` directory for specific u
| Package | Version | Description |
|---------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| [multi-semantic-release](packages/multi-semantic-release/README.md) | ![npm](https://img.shields.io/npm/v/@anolilab/multi-semantic-release?style=flat-square&labelColor=292a44&color=663399&label=v) | A hacky semantic-release for monorepos based on qiwi/multi-semantic-release | | |
| [semantic-release-pnpm](packages/semantic-release-pnpm/README.md) | ![npm](https://img.shields.io/npm/v/@anolilab/semantic-release-pnpm?style=flat-square&labelColor=292a44&color=663399&label=v) | Semantic-release plugin to publish a npm package with pnpm | | |

## How We Version

Expand Down
15 changes: 15 additions & 0 deletions packages/rc/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dist
node_modules
coverage

__fixtures__
__docs__

vitest.config.ts
.prettierrc.cjs
tsup.config.ts
.secretlintrc.cjs
tsconfig.eslint.json

README.md

90 changes: 90 additions & 0 deletions packages/rc/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/** @ts-check */
// eslint-disable-next-line import/no-commonjs,import/no-unused-modules
const { defineConfig } = require("@anolilab/eslint-config/define-config");
// eslint-disable-next-line import/no-commonjs
const globals = require("@anolilab/eslint-config/globals");

/// <reference types="@eslint-types/unicorn" />
/// <reference types="@eslint-types/typescript-eslint" />
/// <reference types="@eslint-types/jsdoc" />
/// <reference types="@eslint-types/import" />
/// <reference types="@eslint-types/deprecation" />

/** @type {import('eslint').Linter.Config} */
module.exports = defineConfig({
env: {
// Your environments (which contains several predefined global variables)
// Most environments are loaded automatically if our rules are added
},
extends: ["@anolilab/eslint-config", "@anolilab/eslint-config/typescript-type-checking"],
globals: {
...globals.es2021,
// Your global variables (setting to false means it's not allowed to be reassigned)
// myGlobal: false
},
ignorePatterns: ["!**/*"],
overrides: [
{
files: ["*.ts", "*.tsx", "*.mts", "*.cts", "*.js", "*.jsx"],
// Set parserOptions.project for the project to allow TypeScript to create the type-checker behind the scenes when we run linting
parserOptions: {},
rules: {},
},
{
files: ["*.ts", "*.tsx", "*.mts", "*.cts"],
// Set parserOptions.project for the project to allow TypeScript to create the type-checker behind the scenes when we run linting
parserOptions: {},
rules: {
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"prefer-template": "off",
},
},
{
files: ["*.js", "*.jsx"],
rules: {},
},
{
files: ["*.mdx"],
rules: {
"jsx-a11y/anchor-has-content": "off",
// @see https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/917
"jsx-a11y/heading-has-content": "off",
},
},
{
files: ["src/index.ts"],
rules: {
"import/no-unused-modules": "off",
},
},
{
files: ["__docs__/**"],
rules: {
"import/no-unresolved": "off",
"import/no-unused-modules": "off",
"no-console": "off",
"no-undef": "off",
"no-unused-vars": "off",
"unicorn/prefer-top-level-await": "off",
},
},
{
files: ["__tests__/**"],
rules: {
"import/no-unused-modules": "off",
},
},
],
parserOptions: {
ecmaVersion: 2021,
project: "./tsconfig.eslint.json",
sourceType: "module",
},
// Report unused `eslint-disable` comments.
reportUnusedDisableDirectives: true,
root: true,
});
9 changes: 9 additions & 0 deletions packages/rc/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package-lock.json

src
__tests__
__stories__
__fixtures__
.rpt2_cache
fixup.sh
.releaserc.json
9 changes: 9 additions & 0 deletions packages/rc/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.gitkeep
.env*
*.ico
*.lock
dist
CHANGELOG.md
coverage
node_modules
.eslintcache
5 changes: 5 additions & 0 deletions packages/rc/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const config = require("@anolilab/prettier-config");

module.exports = {
...config,
};
3 changes: 3 additions & 0 deletions packages/rc/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@anolilab/semantic-release-preset/npm"
}
3 changes: 3 additions & 0 deletions packages/rc/.secretlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.pnpm-store
packages/**/node_modules
node_modules
7 changes: 7 additions & 0 deletions packages/rc/.secretlintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
rules: [
{
id: "@secretlint/secretlint-rule-preset-recommend",
},
],
};
Empty file added packages/rc/CHANGELOG.md
Empty file.
21 changes: 21 additions & 0 deletions packages/rc/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 anolilab

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
112 changes: 112 additions & 0 deletions packages/rc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<div align="center">
<h3>anolilab rc</h3>
<p>
This module provides a utility function to load rc configuration settings from various sources, including environment variables, default values, and configuration files located in multiple standard directories. It merges these settings into a single configuration object.
</p>
</div>

<br />

<div align="center">

[![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]

</div>

---

<div align="center">
<p>
<sup>
Daniel Bannert's open source work is supported by the community on <a href="https://github.com/sponsors/prisis">GitHub Sponsors</a>
</sup>
</p>
</div>

---

## Install

```sh
npm install @anolilab/rc
```

```sh
yarn add @anolilab/rc
```

```sh
pnpm add @anolilab/rc
```

## Usage

The main function provided by this module is rc. It allows you to load configuration settings for your application from different sources.

```ts
import { rc } from "@anolilab/rc";

const { config, files } = rc("npm");

// returns a merged config object with all found npmrc files and a files list what files where found.
```

### Api

- name (string): The application name. This is used to locate configuration files and environment variables.
- options (object, optional): An object with the following properties:
- config (string, optional): Path to a specific configuration file.
- cwd (string, optional): The current working directory to start searching for configuration files. Defaults to process.cwd().
- defaults (object, optional): Default configuration values.
- home (string, optional): The home directory to use. Defaults to os.homedir().
- stopAt (string, optional): Directory to stop searching for configuration files.

## Standards

Given your application name (appname), rc will look in all the obvious places for configuration.

- The defaults object you passed in
- `/etc/${appname}/config`
- `/etc/${appname}rc`
- `$HOME/.config/${appname}/config`
- `$HOME/.config/${appname}`
- `$HOME/.${appname}/config`
- `$HOME/.${appname}rc`
- a local `.${appname}/config` and `.${appname}rc` and all found looking in `../../../ ../../ ../ ./` etc.
- if you passed environment variable `${appname}_config` then from that file
- if you passed options.config variable, then from that file
- environment variables prefixed with `${appname}_`
or use "\_\_" to indicate nested properties <br/> _(e.g. `appname_foo__bar__baz` => `foo.bar.baz`)_

All configuration sources that were found will be flattened into one object, in this exact order.

## Related

- [rc](https://github.com/dominictarr/rc) - The non-configurable configuration loader for lazy people.

## Supported Node.js Versions

Libraries in this ecosystem make the best effort to track [Node.js’ release schedule](https://github.com/nodejs/release#release-schedule).
Here’s [a post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).

## Contributing

If you would like to help take a look at the [list of issues](https://github.com/anolilab/semantic-release/issues) and check our [Contributing](.github/CONTRIBUTING.md) guidelines.

> **Note:** please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

## Credits

- [Daniel Bannert](https://github.com/prisis)
- [All Contributors](https://github.com/anolilab/semantic-release/graphs/contributors)

## License

The anolilab rc is open-sourced software licensed under the [MIT][license-url]

[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[typescript-url]: "typescript"
[license-image]: https://img.shields.io/npm/l/@anolilab/rc?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md "license"
[npm-image]: https://img.shields.io/npm/v/@anolilab/rc/latest.svg?style=for-the-badge&logo=npm
[npm-url]: https://www.npmjs.com/package/@anolilab/rc/v/latest "npm"
104 changes: 104 additions & 0 deletions packages/rc/__tests__/rc-unmocked.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { rm } from "node:fs/promises";
import { env } from "node:process";

import { writeJsonSync } from "@visulima/fs";
import { join } from "@visulima/path";
import { temporaryDirectory } from "tempy";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

import { rc } from "../src";

const mocks = vi.hoisted(() => {
return { mockedCwd: vi.fn(), mockedFindUpSync: vi.fn(), mockedHomeDir: vi.fn(), mockedIsAccessibleSync: vi.fn(), mockedReadFileSync: vi.fn() };
});

vi.mock("node:os", () => {
return {
homedir: mocks.mockedHomeDir,
};
});

vi.mock("node:process", async () => {
const actual = await vi.importActual("node:process");

return {
...actual,
cwd: mocks.mockedCwd,
};
});

describe("rc-unmocked", () => {
let cwdPath: string;
let homePath: string;

const npmEnvironment: Record<keyof typeof env, string | undefined> = {};

beforeEach(async () => {
cwdPath = temporaryDirectory();
homePath = temporaryDirectory();

mocks.mockedCwd.mockReturnValue(cwdPath);
mocks.mockedHomeDir.mockReturnValue(homePath);

// eslint-disable-next-line no-loops/no-loops,no-restricted-syntax
for (const key in env) {
if (key.startsWith("npm_")) {
// eslint-disable-next-line security/detect-object-injection
npmEnvironment[key as keyof typeof env] = env[key];
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete,security/detect-object-injection
delete env[key];
}
}
});

afterEach(async () => {
// eslint-disable-next-line no-loops/no-loops,no-restricted-syntax,guard-for-in
for (const key in npmEnvironment) {
// eslint-disable-next-line security/detect-object-injection
env[key] = npmEnvironment[key];
}

await rm(cwdPath, { recursive: true });
await rm(homePath, { recursive: true });
});

it("should find configs in different folders", () => {
expect.assertions(1);

const files = [join("grandparent", "parent", "cwd", ".bemrc"), join("grandparent", "parent", ".bemrc"), join("grandparent", ".bemrc")];

files.forEach((file, index) => {
writeJsonSync(join(cwdPath, file), { test: index });
});

mocks.mockedCwd.mockReturnValue(join(cwdPath, "grandparent", "parent", "cwd"));

expect(rc("bem")).toStrictEqual({
config: {
test: 0,
},
files: files.map((file) => join(cwdPath, file)).reverse(),
});
});

it("should find configs in custom cwd", () => {
expect.assertions(1);

const files = [join("grandparent", "parent", "cwd", ".bemrc"), join("grandparent", "parent", ".bemrc"), join("grandparent", ".bemrc")];

files.forEach((file, index) => {
writeJsonSync(join(cwdPath, file), { test: index });
});

expect(
rc("bem", {
cwd: join(cwdPath, "grandparent", "parent", "cwd"),
}),
).toStrictEqual({
config: {
test: 0,
},
files: files.map((file) => join(cwdPath, file)).reverse(),
});
});
});
Loading
Loading