Skip to content

Commit 56e7b66

Browse files
fix(index.ts): ensure replacement.from and replacement.to default to empty arrays
1 parent 4e8b9c0 commit 56e7b66

File tree

12 files changed

+97
-80
lines changed

12 files changed

+97
-80
lines changed

.github/linters/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"module": "NodeNext",
4+
"target": "ES2022",
5+
"outDir": "dist",
6+
"declaration": true,
7+
"declarationDir": "./dist",
8+
"esModuleInterop": true,
9+
"skipLibCheck": true,
10+
"moduleResolution": "NodeNext"
11+
},
12+
"include": ["src/**/*.ts"],
13+
"exclude": ["node_modules"]
14+
}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ on:
77
jobs:
88
release:
99
uses: centralnicgroup-opensource/rtldev-middleware-shareable-workflows/.github/workflows/semantic-release-replace-release.yml@main
10-
secrets: inherit
10+
secrets: inherit

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist/
22
lib/
3-
node_modules/
3+
node_modules/
4+
HISTORY.md

.releaserc.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
"ci": false,
33
"branches": ["main"],
44
"plugins": [
5-
"@semantic-release/commit-analyzer",
6-
"@semantic-release/release-notes-generator",
7-
[
8-
"@semantic-release/changelog",
9-
{
10-
"changelogFile": "HISTORY.md"
11-
}
12-
],
13-
[
14-
"@semantic-release/git",
15-
{
16-
"assets": [
17-
"docs",
18-
"@(package?(-lock)|composer).json",
19-
"src/*",
20-
"dist/*",
21-
"(HISTORY|README|LICENSE).md"
22-
]
23-
}
24-
],
25-
"semantic-release-teams-notify-plugin",
26-
"@semantic-release/github"
5+
"@semantic-release/commit-analyzer",
6+
"@semantic-release/release-notes-generator",
7+
[
8+
"@semantic-release/changelog",
9+
{
10+
"changelogFile": "HISTORY.md"
11+
}
12+
],
13+
[
14+
"@semantic-release/git",
15+
{
16+
"assets": [
17+
"docs",
18+
"@(package?(-lock)|composer).json",
19+
"src/*",
20+
"dist/*",
21+
"(HISTORY|README|LICENSE).md"
22+
]
23+
}
24+
],
25+
"semantic-release-teams-notify-plugin",
26+
"@semantic-release/github"
2727
]
28-
}
28+
}

CONTRIBUTING.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
**Table of contents**
44

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

1010
## Contributor License Agreements
1111

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

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

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

57-
[setup]: https://cloud.google.com/nodejs/docs/setup
57+
[setup]: https://cloud.google.com/nodejs/docs/setup

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The following example uses this plugin to demonstrate using semantic-release in
5656
]
5757
}
5858
```
59+
5960
### Validation
6061

6162
The presence of the `results` array will trigger validation that a replacement has been made. This is optional but recommended.

dist/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export async function prepare(PluginConfig, context) {
4747
delete replacement.results;
4848
const replaceInFileConfig = {
4949
...replacement,
50-
from: replacement.from,
51-
to: replacement.to,
50+
from: replacement.from ?? [],
51+
to: replacement.to ?? [],
5252
};
5353
// The `replace-in-file` package uses `String.replace` under the hood for
5454
// the actual replacement. If `from` is a string, this means only a

docs/README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ semantic-release-replace-plugin
2828

2929
#### Defined in
3030

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

33-
___
33+
---
3434

3535
### FromCallback
3636

@@ -42,30 +42,30 @@ ___
4242

4343
##### Parameters
4444

45-
| Name | Type |
46-
| :------ | :------ |
47-
| `filename` | `string` |
48-
| `...args` | `unknown`[] |
45+
| Name | Type |
46+
| :--------- | :---------- |
47+
| `filename` | `string` |
48+
| `...args` | `unknown`[] |
4949

5050
##### Returns
5151

5252
`RegExp` \| `string`
5353

5454
#### Defined in
5555

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

58-
___
58+
---
5959

6060
### To
6161

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

6464
#### Defined in
6565

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

68-
___
68+
---
6969

7070
### ToCallback
7171

@@ -77,9 +77,9 @@ ___
7777

7878
##### Parameters
7979

80-
| Name | Type |
81-
| :------ | :------ |
82-
| `match` | `string` |
80+
| Name | Type |
81+
| :-------- | :---------- |
82+
| `match` | `string` |
8383
| `...args` | `unknown`[] |
8484

8585
##### Returns
@@ -88,7 +88,7 @@ ___
8888

8989
#### Defined in
9090

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

9393
## Functions
9494

@@ -98,15 +98,15 @@ ___
9898

9999
#### Parameters
100100

101-
| Name | Type |
102-
| :------ | :------ |
101+
| Name | Type |
102+
| :------------- | :------------------------------------------- |
103103
| `PluginConfig` | [`PluginConfig`](interfaces/PluginConfig.md) |
104-
| `context` | `VerifyReleaseContext` |
104+
| `context` | `VerifyReleaseContext` |
105105

106106
#### Returns
107107

108108
`Promise`\<`void`\>
109109

110110
#### Defined in
111111

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

docs/interfaces/PluginConfig.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ An array of replacements to be made.
4444

4545
#### Defined in
4646

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

docs/interfaces/Replacement.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,49 +28,49 @@ with the difference being the single string for `to` and `from`.
2828

2929
#### Defined in
3030

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

33-
___
33+
---
3434

3535
### countMatches
3636

3737
`Optional` **countMatches**: `boolean`
3838

3939
#### Defined in
4040

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

43-
___
43+
---
4444

4545
### disableGlobs
4646

4747
`Optional` **disableGlobs**: `boolean`
4848

4949
#### Defined in
5050

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

53-
___
53+
---
5454

5555
### dry
5656

5757
`Optional` **dry**: `boolean`
5858

5959
#### Defined in
6060

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

63-
___
63+
---
6464

6565
### encoding
6666

6767
`Optional` **encoding**: `string`
6868

6969
#### Defined in
7070

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

73-
___
73+
---
7474

7575
### files
7676

@@ -80,9 +80,9 @@ files to search for replacements
8080

8181
#### Defined in
8282

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

85-
___
85+
---
8686

8787
### from
8888

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

105105
#### Defined in
106106

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

109-
___
109+
---
110110

111111
### ignore
112112

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

115115
#### Defined in
116116

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

119-
___
119+
---
120120

121121
### results
122122

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

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

128128
#### Defined in
129129

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

132-
___
132+
---
133133

134134
### to
135135

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

145145
For advanced replacement (NOTE: only for use with `release.config.js` file version), pass in a function to replace non-standard variables
146+
146147
```
147148
{
148149
from: `__VERSION__ = 11`, // eslint-disable-line
@@ -162,4 +163,4 @@ to match the amount of `from` matchers.
162163

163164
#### Defined in
164165

165-
[index.ts:85](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/17307cb/src/index.ts#L85)
166+
[index.ts:85](https://github.com/centralnicgroup-opensource/rtldev-middleware-semantic-release-replace-plugin/blob/a490964/src/index.ts#L85)

0 commit comments

Comments
 (0)