@backstage-community/plugin-scaffolder-backend-module-regex 2.17.0 → 2.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @backstage-community/plugin-scaffolder-backend-module-regex
|
|
2
2
|
|
|
3
|
+
## 2.17.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cce0831: Add module wiring tests, direct Zod schema validation coverage, a local dev/ harness, and contributor documentation so Backstage dependency bumps are caught by scoped automated tests.
|
|
8
|
+
|
|
3
9
|
## 2.17.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This plugin provides [Backstage](https://backstage.io/) template [actions](https://backstage.io/docs/features/software-templates/builtin-actions) for [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp).
|
|
4
4
|
|
|
5
|
+
For contributor setup and local development, see [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
6
|
+
|
|
5
7
|
The following actions are currently supported in this plugin:
|
|
6
8
|
|
|
7
9
|
- [String replacement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
4
4
|
var replace_example = require('./replace.example.cjs.js');
|
|
5
|
+
var replace_schema = require('./replace.schema.cjs.js');
|
|
5
6
|
|
|
6
7
|
const id = "regex:replace";
|
|
7
8
|
const createReplaceAction = () => {
|
|
@@ -11,36 +12,7 @@ const createReplaceAction = () => {
|
|
|
11
12
|
examples: replace_example.examples,
|
|
12
13
|
schema: {
|
|
13
14
|
input: {
|
|
14
|
-
regExps:
|
|
15
|
-
z.object({
|
|
16
|
-
pattern: z.string().refine(
|
|
17
|
-
// You should not parse a regex (regular language) with a regex (regular language),
|
|
18
|
-
// you actually need a context free grammar to parse a regex (regular language).
|
|
19
|
-
// Hence, we are using a string comparison here.
|
|
20
|
-
(value) => !value.startsWith("/") && !value.endsWith("/"),
|
|
21
|
-
{
|
|
22
|
-
message: "The RegExp constructor cannot take a string pattern with a leading and trailing forward slash."
|
|
23
|
-
}
|
|
24
|
-
).describe(
|
|
25
|
-
"The regex pattern to match the value like in String.prototype.replace()"
|
|
26
|
-
),
|
|
27
|
-
flags: z.array(
|
|
28
|
-
// Prefer array over set here because input values are normally defined in YAML which doesn't support Sets.
|
|
29
|
-
z.enum(["g", "m", "i", "y", "u", "s", "d"], {
|
|
30
|
-
invalid_type_error: "Invalid flag, possible values are: g, m, i, y, u, s, d"
|
|
31
|
-
})
|
|
32
|
-
).optional().describe("The flags for the regex"),
|
|
33
|
-
replacement: z.string().describe(
|
|
34
|
-
"The replacement value for the regex like in String.prototype.replace()"
|
|
35
|
-
),
|
|
36
|
-
values: z.array(
|
|
37
|
-
z.object({
|
|
38
|
-
key: z.string().describe("The key to access the regex value"),
|
|
39
|
-
value: z.string().describe("The input value of the regex")
|
|
40
|
-
})
|
|
41
|
-
)
|
|
42
|
-
})
|
|
43
|
-
)
|
|
15
|
+
regExps: replace_schema.regExpsSchema
|
|
44
16
|
}
|
|
45
17
|
},
|
|
46
18
|
async handler(ctx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace.cjs.js","sources":["../../../src/actions/regex/replace.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\n\nimport { examples } from './replace.example';\n\nconst id = 'regex:replace';\n\n/**\n * @public\n */\nexport const createReplaceAction = () => {\n return createTemplateAction({\n id,\n description:\n 'Replaces strings that match a regular expression pattern with a specified replacement string',\n examples,\n schema: {\n input: {\n regExps:
|
|
1
|
+
{"version":3,"file":"replace.cjs.js","sources":["../../../src/actions/regex/replace.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\n\nimport { examples } from './replace.example';\nimport { regExpsSchema } from './replace.schema';\n\nconst id = 'regex:replace';\n\n/**\n * @public\n */\nexport const createReplaceAction = () => {\n return createTemplateAction({\n id,\n description:\n 'Replaces strings that match a regular expression pattern with a specified replacement string',\n examples,\n schema: {\n input: {\n regExps: regExpsSchema,\n },\n },\n\n async handler(ctx) {\n const input = ctx.input;\n\n const values: Record<string, string> = {};\n\n for (const {\n pattern,\n flags: flagsInput,\n replacement,\n values: valuesInput,\n } of input.regExps) {\n // remove duplicates from the flags input array\n const flags = flagsInput\n ? Array.from(new Set(flagsInput)).join('')\n : '';\n const regex = new RegExp(pattern, flags);\n\n for (const { key, value } of valuesInput) {\n const match = value.replace(regex, replacement);\n\n if (values.hasOwnProperty(key)) {\n throw new Error(\n `The key '${key}' is used more than once in the input.`,\n );\n }\n\n values[key] = match;\n }\n }\n\n ctx.output('values', values);\n },\n });\n};\n"],"names":["createTemplateAction","examples","regExpsSchema"],"mappings":";;;;;;AAo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ict';
|
|
2
|
+
|
|
3
|
+
const regExpsSchema = (z) => z.array(
|
|
4
|
+
z.object({
|
|
5
|
+
pattern: z.string().refine(
|
|
6
|
+
// You should not parse a regex (regular language) with a regex (regular language),
|
|
7
|
+
// you actually need a context free grammar to parse a regex (regular language).
|
|
8
|
+
// Hence, we are using a string comparison here.
|
|
9
|
+
(value) => !value.startsWith("/") && !value.endsWith("/"),
|
|
10
|
+
{
|
|
11
|
+
message: "The RegExp constructor cannot take a string pattern with a leading and/or trailing forward slash."
|
|
12
|
+
}
|
|
13
|
+
).describe(
|
|
14
|
+
"The regex pattern to match the value like in String.prototype.replace()"
|
|
15
|
+
),
|
|
16
|
+
flags: z.array(
|
|
17
|
+
// Prefer array over set here because input values are normally defined in YAML which doesn't support Sets.
|
|
18
|
+
z.enum(["g", "m", "i", "y", "u", "s", "d"], {
|
|
19
|
+
invalid_type_error: "Invalid flag, possible values are: g, m, i, y, u, s, d"
|
|
20
|
+
})
|
|
21
|
+
).optional().describe("The flags for the regex"),
|
|
22
|
+
replacement: z.string().describe(
|
|
23
|
+
"The replacement value for the regex like in String.prototype.replace()"
|
|
24
|
+
),
|
|
25
|
+
values: z.array(
|
|
26
|
+
z.object({
|
|
27
|
+
key: z.string().describe("The key to access the regex value"),
|
|
28
|
+
value: z.string().describe("The input value of the regex")
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
exports.regExpsSchema = regExpsSchema;
|
|
35
|
+
//# sourceMappingURL=replace.schema.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace.schema.cjs.js","sources":["../../../src/actions/regex/replace.schema.ts"],"sourcesContent":["/*\n * Copyright 2026 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type { z as zType } from 'zod/v3';\n\n/**\n * The `regExps` input schema for the `regex:replace` action, extracted so\n * that it can be exercised directly in tests. Calling the action handler in\n * a mock environment does not run Zod validation, so the `pattern` refine\n * below would otherwise have no coverage.\n */\nexport const regExpsSchema = (z: typeof zType) =>\n z.array(\n z.object({\n pattern: z\n .string()\n .refine(\n // You should not parse a regex (regular language) with a regex (regular language),\n // you actually need a context free grammar to parse a regex (regular language).\n // Hence, we are using a string comparison here.\n value => !value.startsWith('/') && !value.endsWith('/'),\n {\n message:\n 'The RegExp constructor cannot take a string pattern with a leading and/or trailing forward slash.',\n },\n )\n .describe(\n 'The regex pattern to match the value like in String.prototype.replace()',\n ),\n flags: z\n .array(\n // Prefer array over set here because input values are normally defined in YAML which doesn't support Sets.\n z.enum(['g', 'm', 'i', 'y', 'u', 's', 'd'], {\n invalid_type_error:\n 'Invalid flag, possible values are: g, m, i, y, u, s, d',\n }),\n )\n .optional()\n .describe('The flags for the regex'),\n replacement: z\n .string()\n .describe(\n 'The replacement value for the regex like in String.prototype.replace()',\n ),\n values: z.array(\n z.object({\n key: z.string().describe('The key to access the regex value'),\n value: z.string().describe('The input value of the regex'),\n }),\n ),\n }),\n );\n"],"names":[],"mappings":";;AAuBO,MAAM,aAAA,GAAgB,CAAC,CAAA,KAC5B,CAAA,CAAE,KAAA;AAAA,EACA,EAAE,MAAA,CAAO;AAAA,IACP,OAAA,EAAS,CAAA,CACN,MAAA,EAAO,CACP,MAAA;AAAA;AAAA;AAAA;AAAA,MAIC,CAAA,KAAA,KAAS,CAAC,KAAA,CAAM,UAAA,CAAW,GAAG,CAAA,IAAK,CAAC,KAAA,CAAM,QAAA,CAAS,GAAG,CAAA;AAAA,MACtD;AAAA,QACE,OAAA,EACE;AAAA;AACJ,KACF,CACC,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,OAAO,CAAA,CACJ,KAAA;AAAA;AAAA,MAEC,CAAA,CAAE,IAAA,CAAK,CAAC,GAAA,EAAK,GAAA,EAAK,KAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAG,CAAA,EAAG;AAAA,QAC1C,kBAAA,EACE;AAAA,OACH;AAAA,KACH,CACC,QAAA,EAAS,CACT,QAAA,CAAS,yBAAyB,CAAA;AAAA,IACrC,WAAA,EAAa,CAAA,CACV,MAAA,EAAO,CACP,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,QAAQ,CAAA,CAAE,KAAA;AAAA,MACR,EAAE,MAAA,CAAO;AAAA,QACP,GAAA,EAAK,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,mCAAmC,CAAA;AAAA,QAC5D,KAAA,EAAO,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,8BAA8B;AAAA,OAC1D;AAAA;AACH,GACD;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage-community/plugin-scaffolder-backend-module-regex",
|
|
3
3
|
"description": "The regex custom actions",
|
|
4
|
-
"version": "2.17.
|
|
4
|
+
"version": "2.17.1",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -51,8 +51,12 @@
|
|
|
51
51
|
"yaml": "^2.3.3"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
+
"@backstage/backend-defaults": "^0.17.3",
|
|
55
|
+
"@backstage/backend-test-utils": "^1.11.4",
|
|
54
56
|
"@backstage/cli": "^0.36.3",
|
|
55
|
-
"@backstage/plugin-scaffolder-
|
|
57
|
+
"@backstage/plugin-scaffolder-backend": "^4.0.1",
|
|
58
|
+
"@backstage/plugin-scaffolder-node-test-utils": "^0.3.12",
|
|
59
|
+
"zod": "^3.25.76 || ^4.0.0"
|
|
56
60
|
},
|
|
57
61
|
"files": [
|
|
58
62
|
"dist",
|