Skip to content

Commit

Permalink
fix(index.ts): ensure replacement.from and replacement.to default to …
Browse files Browse the repository at this point in the history
…empty arrays
  • Loading branch information
AsifNawaz-cnic committed Jan 14, 2025
1 parent 4e8b9c0 commit 56e7b66
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 80 deletions.
14 changes: 14 additions & 0 deletions .github/linters/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "NodeNext",
"target": "ES2022",
"outDir": "dist",
"declaration": true,
"declarationDir": "./dist",
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "NodeNext"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ on:
jobs:
release:
uses: centralnicgroup-opensource/rtldev-middleware-shareable-workflows/.github/workflows/semantic-release-replace-release.yml@main
secrets: inherit
secrets: inherit
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
lib/
node_modules/
node_modules/
HISTORY.md
46 changes: 23 additions & 23 deletions .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
"ci": false,
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "HISTORY.md"
}
],
[
"@semantic-release/git",
{
"assets": [
"docs",
"@(package?(-lock)|composer).json",
"src/*",
"dist/*",
"(HISTORY|README|LICENSE).md"
]
}
],
"semantic-release-teams-notify-plugin",
"@semantic-release/github"
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "HISTORY.md"
}
],
[
"@semantic-release/git",
{
"assets": [
"docs",
"@(package?(-lock)|composer).json",
"src/*",
"dist/*",
"(HISTORY|README|LICENSE).md"
]
}
],
"semantic-release-teams-notify-plugin",
"@semantic-release/github"
]
}
}
18 changes: 9 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

**Table of contents**

* [Contributor License Agreements](#contributor-license-agreements)
* [Contributing a patch](#contributing-a-patch)
* [Running the tests](#running-the-tests)
* [Releasing the library](#releasing-the-library)
- [Contributor License Agreements](#contributor-license-agreements)
- [Contributing a patch](#contributing-a-patch)
- [Running the tests](#running-the-tests)
- [Releasing the library](#releasing-the-library)

## Contributor License Agreements

Expand All @@ -15,10 +15,10 @@ have to jump a couple of legal hurdles.
Please fill out either the individual or corporate Contributor License Agreement
(CLA).

* If you are an individual writing original source code and you're sure you
own the intellectual property, then you'll need to sign an [individual CLA](https://developers.google.com/open-source/cla/individual).
* If you work for a company that wants to allow you to contribute your work,
then you'll need to sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate).
- If you are an individual writing original source code and you're sure you
own the intellectual property, then you'll need to sign an [individual CLA](https://developers.google.com/open-source/cla/individual).
- If you work for a company that wants to allow you to contribute your work,
then you'll need to sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate).

Follow either of the two links above to access the appropriate CLA and
instructions for how to sign and return it. Once we receive it, we'll be able to
Expand Down Expand Up @@ -54,4 +54,4 @@ accept your pull requests.
npm run lint
npm run format

[setup]: https://cloud.google.com/nodejs/docs/setup
[setup]: https://cloud.google.com/nodejs/docs/setup
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The following example uses this plugin to demonstrate using semantic-release in
]
}
```

### Validation

The presence of the `results` array will trigger validation that a replacement has been made. This is optional but recommended.
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export async function prepare(PluginConfig, context) {
delete replacement.results;
const replaceInFileConfig = {
...replacement,
from: replacement.from,
to: replacement.to,
from: replacement.from ?? [],
to: replacement.to ?? [],
};
// The `replace-in-file` package uses `String.replace` under the hood for
// the actual replacement. If `from` is a string, this means only a
Expand Down
36 changes: 18 additions & 18 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ semantic-release-replace-plugin

#### Defined in

[index.ts:26](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L26)
[index.ts:26](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L26)

___
---

### FromCallback

Expand All @@ -42,30 +42,30 @@ ___

##### Parameters

| Name | Type |
| :------ | :------ |
| `filename` | `string` |
| `...args` | `unknown`[] |
| Name | Type |
| :--------- | :---------- |
| `filename` | `string` |
| `...args` | `unknown`[] |

##### Returns

`RegExp` \| `string`

#### Defined in

[index.ts:27](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L27)
[index.ts:27](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L27)

___
---

### To

Ƭ **To**: `string` \| [`ToCallback`](README.md#tocallback)

#### Defined in

[index.ts:31](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L31)
[index.ts:31](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L31)

___
---

### ToCallback

Expand All @@ -77,9 +77,9 @@ ___

##### Parameters

| Name | Type |
| :------ | :------ |
| `match` | `string` |
| Name | Type |
| :-------- | :---------- |
| `match` | `string` |
| `...args` | `unknown`[] |

##### Returns
Expand All @@ -88,7 +88,7 @@ ___

#### Defined in

[index.ts:32](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L32)
[index.ts:32](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L32)

## Functions

Expand All @@ -98,15 +98,15 @@ ___

#### Parameters

| Name | Type |
| :------ | :------ |
| Name | Type |
| :------------- | :------------------------------------------- |
| `PluginConfig` | [`PluginConfig`](interfaces/PluginConfig.md) |
| `context` | `VerifyReleaseContext` |
| `context` | `VerifyReleaseContext` |

#### Returns

`Promise`\<`void`\>

#### Defined in

[index.ts:163](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L163)
[index.ts:163](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L163)
2 changes: 1 addition & 1 deletion docs/interfaces/PluginConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ An array of replacements to be made.

#### Defined in

[index.ts:132](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L132)
[index.ts:132](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L132)
41 changes: 21 additions & 20 deletions docs/interfaces/Replacement.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,49 +28,49 @@ with the difference being the single string for `to` and `from`.

#### Defined in

[index.ts:87](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L87)
[index.ts:87](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L87)

___
---

### countMatches

`Optional` **countMatches**: `boolean`

#### Defined in

[index.ts:88](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L88)
[index.ts:88](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L88)

___
---

### disableGlobs

`Optional` **disableGlobs**: `boolean`

#### Defined in

[index.ts:89](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L89)
[index.ts:89](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L89)

___
---

### dry

`Optional` **dry**: `boolean`

#### Defined in

[index.ts:91](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L91)
[index.ts:91](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L91)

___
---

### encoding

`Optional` **encoding**: `string`

#### Defined in

[index.ts:90](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L90)
[index.ts:90](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L90)

___
---

### files

Expand All @@ -80,9 +80,9 @@ files to search for replacements

#### Defined in

[index.ts:42](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L42)
[index.ts:42](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L42)

___
---

### from

Expand All @@ -104,32 +104,32 @@ conversion rules as mentioned above.

#### Defined in

[index.ts:58](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L58)
[index.ts:58](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L58)

___
---

### ignore

`Optional` **ignore**: `string`[]

#### Defined in

[index.ts:86](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L86)
[index.ts:86](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L86)

___
---

### results

`Optional` **results**: \{ `file`: `string` ; `hasChanged`: `boolean` ; `numMatches?`: `number` ; `numReplacements?`: `number` }[]
`Optional` **results**: \{ `file`: `string` ; `hasChanged`: `boolean` ; `numMatches?`: `number` ; `numReplacements?`: `number` }[]

The results array can be passed to ensure that the expected replacements
have been made, and if not, throw and exception with the diff.

#### Defined in

[index.ts:96](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L96)
[index.ts:96](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L96)

___
---

### to

Expand All @@ -143,6 +143,7 @@ The context object is used to render the template. Additional values
can be found at: https://semantic-release.gitbook.io/semantic-release/developer-guide/js-api#result

For advanced replacement (NOTE: only for use with `release.config.js` file version), pass in a function to replace non-standard variables

```
{
from: `__VERSION__ = 11`, // eslint-disable-line
Expand All @@ -162,4 +163,4 @@ to match the amount of `from` matchers.

#### Defined in

[index.ts:85](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L85)
[index.ts:85](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L85)
4 changes: 2 additions & 2 deletions fixtures/foo.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
install with `npm i [email protected]`

or
or

install with `yarn add [email protected]`
install with `yarn add [email protected]`
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"all": "npm run build && npm run docs",
"build": "tsc",
"docs": "rm -rf docs && typedoc src/index.ts",
"lint": "eslint src/**/*.ts",
"format": "npm run lint -- --fix",
"lint": "prettier --write . --ignore-path .prettierignore && eslint src/**/*.ts",
"format": "eslint src/**/*.ts --fix",
"test": "tsc --noEmit && vitest --coverage",
"release": "semantic-release"
},
Expand Down Expand Up @@ -65,4 +65,4 @@
"publishConfig": {
"access": "public"
}
}
}

0 comments on commit 56e7b66

Please sign in to comment.