@backstage/plugin-scaffolder-node 0.13.7-next.2 → 0.13.8-next.0
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 +33 -0
- package/dist/actions/createTemplateAction.cjs.js.map +1 -1
- package/dist/actions/executeShellCommand.cjs.js.map +1 -1
- package/dist/actions/fetch.cjs.js.map +1 -1
- package/dist/actions/gitHelpers.cjs.js.map +1 -1
- package/dist/actions/util.cjs.js.map +1 -1
- package/dist/alpha/filters/createTemplateFilter.cjs.js.map +1 -1
- package/dist/alpha/globals/createTemplateGlobal.cjs.js.map +1 -1
- package/dist/alpha.cjs.js.map +1 -1
- package/dist/extensions.cjs.js.map +1 -1
- package/dist/files/deserializeDirectoryContents.cjs.js.map +1 -1
- package/dist/files/serializeDirectoryContents.cjs.js.map +1 -1
- package/dist/scaffolderService.cjs.js.map +1 -1
- package/dist/scm/git.cjs.js.map +1 -1
- package/dist/tasks/serializer.cjs.js.map +1 -1
- package/dist/testUtils/scaffolderServiceMock.cjs.js.map +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-node
|
|
2
2
|
|
|
3
|
+
## 0.13.8-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/integration@2.1.3-next.0
|
|
9
|
+
- @backstage/errors@1.3.2-next.0
|
|
10
|
+
- @backstage/backend-test-utils@1.11.8-next.0
|
|
11
|
+
- @backstage/plugin-scaffolder-common@2.3.1-next.0
|
|
12
|
+
- @backstage/backend-plugin-api@1.10.2-next.0
|
|
13
|
+
- @backstage/plugin-permission-common@0.9.12-next.0
|
|
14
|
+
- @backstage/plugin-permission-node@0.11.5-next.0
|
|
15
|
+
- @backstage/catalog-model@1.10.2-next.0
|
|
16
|
+
|
|
17
|
+
## 0.13.7
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 3bb3710: Added optional cancellation support when waiting to claim a scaffolder task.
|
|
22
|
+
- e95b649: Added task recovery feature with new `scaffolder.taskRecovery` config section. When enabled, tasks that crash or timeout are automatically recovered and resume from the last completed step, task secrets are retained until the task reaches a terminal state so recovery can continue, and completed step outputs are persisted. Enabling recovery applies to all scaffolder tasks, so actions used by those tasks should be idempotent or use checkpoints. When recovery is disabled (the default), the previous behavior is unchanged: secrets are cleared as soon as a task is claimed and retries re-run every step. The new config consolidates previous experimental flags (`EXPERIMENTAL_recoverTasks`, `EXPERIMENTAL_workspaceSerialization`, `EXPERIMENTAL_recoverTasksTimeout`) which remain supported as fallbacks. The legacy workspace provider setting continues to select a provider only when `EXPERIMENTAL_workspaceSerialization` is `true`.
|
|
23
|
+
|
|
24
|
+
Workspace serialization for task recovery now requires installing a separate workspace provider module, including when you use the legacy configuration. For development, use `@backstage/plugin-scaffolder-backend-module-workspace-database` (50 MB limit, not recommended for production). On first startup, that module migrates existing database workspace snapshots from the legacy task storage. For production, use `@backstage/plugin-scaffolder-backend-module-gcp` or a similar external storage provider. The scaffolder rejects a configured provider that has not been installed and registered.
|
|
25
|
+
|
|
26
|
+
Enabling crash recovery does not keep completed task event streams open; normal task completion remains terminal for event-stream clients.
|
|
27
|
+
|
|
28
|
+
- Updated dependencies
|
|
29
|
+
- @backstage/integration@2.1.2
|
|
30
|
+
- @backstage/plugin-scaffolder-common@2.3.0
|
|
31
|
+
- @backstage/catalog-model@1.10.1
|
|
32
|
+
- @backstage/plugin-permission-node@0.11.4
|
|
33
|
+
- @backstage/backend-plugin-api@1.10.1
|
|
34
|
+
- @backstage/plugin-permission-common@0.9.11
|
|
35
|
+
|
|
3
36
|
## 0.13.7-next.2
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTemplateAction.cjs.js","sources":["../../src/actions/createTemplateAction.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { ActionContext, TemplateAction } from './types';\nimport { z } from 'zod/v3';\nimport { Expand, JsonObject } from '@backstage/types';\nimport { parseSchemas } from './util';\n\n/** @public */\nexport type TemplateExample = {\n description: string;\n example: string;\n};\n\n/** @public */\nexport type TemplateActionOptions<\n TActionInput extends JsonObject = {},\n TActionOutput extends JsonObject = {},\n TInputSchema extends\n | { [key in string]: (zImpl: typeof z) => z.ZodType }\n | ((zImpl: typeof z) => z.ZodType) = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TOutputSchema extends\n | {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n }\n | ((zImpl: typeof z) => z.ZodType) = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TSchemaType extends 'v2' = 'v2',\n> = {\n id: string;\n description?: string;\n examples?: TemplateExample[];\n supportsDryRun?: boolean;\n schema?: {\n input?: TInputSchema;\n output?: TOutputSchema;\n };\n handler: (\n ctx: ActionContext<TActionInput, TActionOutput, TSchemaType>,\n ) => Promise<void>;\n};\n\n/**\n * @ignore\n */\ntype FlattenOptionalProperties<T extends { [key in string]: unknown }> = Expand<\n {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K];\n } & {\n [K in keyof T as undefined extends T[K] ? K : never]?: T[K];\n }\n>;\n/**\n * This function is used to create new template actions to get type safety.\n * Will convert zod schemas to json schemas for use throughout the system.\n * @public\n */\nexport function createTemplateAction<\n TInputSchema extends\n | { [key in string]: (zImpl: typeof z) => z.ZodType }\n | ((zImpl: typeof z) => z.ZodType),\n TOutputSchema extends\n | { [key in string]: (zImpl: typeof z) => z.ZodType }\n | ((zImpl: typeof z) => z.ZodType),\n>(\n action: TemplateActionOptions<\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TInputSchema]: z.infer<ReturnType<TInputSchema[key]>>;\n }\n : TInputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.infer<ReturnType<TInputSchema>>\n : never,\n TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TOutputSchema]: z.infer<ReturnType<TOutputSchema[key]>>;\n }\n : TOutputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.infer<ReturnType<TOutputSchema>>\n : never,\n TInputSchema,\n TOutputSchema,\n 'v2'\n >,\n): TemplateAction<\n FlattenOptionalProperties<\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TInputSchema]: z.output<ReturnType<TInputSchema[key]>>;\n }\n : TInputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.output<ReturnType<TInputSchema>>\n : never\n >,\n FlattenOptionalProperties<\n TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TOutputSchema]: z.output<\n ReturnType<TOutputSchema[key]>\n >;\n }\n : TOutputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.output<ReturnType<TOutputSchema>>\n : never\n >,\n 'v2'\n>;\nexport function createTemplateAction<\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType } = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType } = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TActionInput extends JsonObject = TInputSchema extends {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n }\n ? Expand<{\n [key in keyof TInputSchema]: z.infer<ReturnType<TInputSchema[key]>>;\n }>\n : never,\n TActionOutput extends JsonObject = TOutputSchema extends {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n }\n ? Expand<{\n [key in keyof TOutputSchema]: z.infer<ReturnType<TOutputSchema[key]>>;\n }>\n : never,\n>(\n action: TemplateActionOptions<\n TActionInput,\n TActionOutput,\n TInputSchema,\n TOutputSchema\n >,\n): TemplateAction<TActionInput, TActionOutput, 'v2'> {\n const { inputSchema, outputSchema } = parseSchemas(\n action as TemplateActionOptions<any, any, any>,\n );\n\n return {\n ...action,\n schema: {\n ...action.schema,\n input: inputSchema,\n output: outputSchema,\n },\n };\n}\n"],"names":["parseSchemas"],"mappings":";;;;AA2HO,SAAS,qBAsBd,MAAA,EAMmD;AACnD,EAAA,MAAM,EAAE,WAAA,EAAa,YAAA,EAAa,GAAIA,iBAAA;AAAA,IACpC;AAAA,GACF;AAEA,EAAA,OAAO;AAAA,IACL,GAAG,MAAA;AAAA,IACH,MAAA,EAAQ;AAAA,MACN,GAAG,MAAA,CAAO,MAAA;AAAA,MACV,KAAA,EAAO,WAAA;AAAA,MACP,MAAA,EAAQ;AAAA;AACV,GACF;AACF
|
|
1
|
+
{"version":3,"file":"createTemplateAction.cjs.js","sources":["../../src/actions/createTemplateAction.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { ActionContext, TemplateAction } from './types';\nimport { z } from 'zod/v3';\nimport { Expand, JsonObject } from '@backstage/types';\nimport { parseSchemas } from './util';\n\n/** @public */\nexport type TemplateExample = {\n description: string;\n example: string;\n};\n\n/** @public */\nexport type TemplateActionOptions<\n TActionInput extends JsonObject = {},\n TActionOutput extends JsonObject = {},\n TInputSchema extends\n | { [key in string]: (zImpl: typeof z) => z.ZodType }\n | ((zImpl: typeof z) => z.ZodType) = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TOutputSchema extends\n | {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n }\n | ((zImpl: typeof z) => z.ZodType) = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TSchemaType extends 'v2' = 'v2',\n> = {\n id: string;\n description?: string;\n examples?: TemplateExample[];\n supportsDryRun?: boolean;\n schema?: {\n input?: TInputSchema;\n output?: TOutputSchema;\n };\n handler: (\n ctx: ActionContext<TActionInput, TActionOutput, TSchemaType>,\n ) => Promise<void>;\n};\n\n/**\n * @ignore\n */\ntype FlattenOptionalProperties<T extends { [key in string]: unknown }> = Expand<\n {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K];\n } & {\n [K in keyof T as undefined extends T[K] ? K : never]?: T[K];\n }\n>;\n/**\n * This function is used to create new template actions to get type safety.\n * Will convert zod schemas to json schemas for use throughout the system.\n * @public\n */\nexport function createTemplateAction<\n TInputSchema extends\n | { [key in string]: (zImpl: typeof z) => z.ZodType }\n | ((zImpl: typeof z) => z.ZodType),\n TOutputSchema extends\n | { [key in string]: (zImpl: typeof z) => z.ZodType }\n | ((zImpl: typeof z) => z.ZodType),\n>(\n action: TemplateActionOptions<\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TInputSchema]: z.infer<ReturnType<TInputSchema[key]>>;\n }\n : TInputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.infer<ReturnType<TInputSchema>>\n : never,\n TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TOutputSchema]: z.infer<ReturnType<TOutputSchema[key]>>;\n }\n : TOutputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.infer<ReturnType<TOutputSchema>>\n : never,\n TInputSchema,\n TOutputSchema,\n 'v2'\n >,\n): TemplateAction<\n FlattenOptionalProperties<\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TInputSchema]: z.output<ReturnType<TInputSchema[key]>>;\n }\n : TInputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.output<ReturnType<TInputSchema>>\n : never\n >,\n FlattenOptionalProperties<\n TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TOutputSchema]: z.output<\n ReturnType<TOutputSchema[key]>\n >;\n }\n : TOutputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.output<ReturnType<TOutputSchema>>\n : never\n >,\n 'v2'\n>;\nexport function createTemplateAction<\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType } = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType } = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TActionInput extends JsonObject = TInputSchema extends {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n }\n ? Expand<{\n [key in keyof TInputSchema]: z.infer<ReturnType<TInputSchema[key]>>;\n }>\n : never,\n TActionOutput extends JsonObject = TOutputSchema extends {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n }\n ? Expand<{\n [key in keyof TOutputSchema]: z.infer<ReturnType<TOutputSchema[key]>>;\n }>\n : never,\n>(\n action: TemplateActionOptions<\n TActionInput,\n TActionOutput,\n TInputSchema,\n TOutputSchema\n >,\n): TemplateAction<TActionInput, TActionOutput, 'v2'> {\n const { inputSchema, outputSchema } = parseSchemas(\n action as TemplateActionOptions<any, any, any>,\n );\n\n return {\n ...action,\n schema: {\n ...action.schema,\n input: inputSchema,\n output: outputSchema,\n },\n };\n}\n"],"names":["parseSchemas"],"mappings":";;;;AA2HO,SAAS,qBAsBd,MAAA,EAMmD;AACnD,EAAA,MAAM,EAAE,WAAA,EAAa,YAAA,EAAa,GAAIA,iBAAA;AAAA,IACpC;AAAA,GACF;AAEA,EAAA,OAAO;AAAA,IACL,GAAG,MAAA;AAAA,IACH,MAAA,EAAQ;AAAA,MACN,GAAG,MAAA,CAAO,MAAA;AAAA,MACV,KAAA,EAAO,WAAA;AAAA,MACP,MAAA,EAAQ;AAAA;AACV,GACF;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeShellCommand.cjs.js","sources":["../../src/actions/executeShellCommand.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { spawn, SpawnOptionsWithoutStdio } from 'node:child_process';\nimport { PassThrough, Writable } from 'node:stream';\n\n/**\n * Options for {@link executeShellCommand}.\n *\n * @public\n */\nexport type ExecuteShellCommandOptions = {\n /** command to run */\n command: string;\n /** arguments to pass the command */\n args: string[];\n /** options to pass to spawn */\n options?: SpawnOptionsWithoutStdio;\n /** logger to capture stdout and stderr output */\n logger?: LoggerService;\n /**\n * stream to capture stdout and stderr output\n * @deprecated please provide a logger instead.\n */\n logStream?: Writable;\n};\n\n/**\n * Run a command in a sub-process, normally a shell command.\n *\n * @public\n */\nexport async function executeShellCommand(\n options: ExecuteShellCommandOptions,\n): Promise<void> {\n const {\n command,\n args,\n options: spawnOptions,\n logger,\n logStream = new PassThrough(),\n } = options;\n\n await new Promise<void>((resolve, reject) => {\n const process = spawn(command, args, spawnOptions);\n\n process.stdout.on('data', chunk => {\n logStream?.write(chunk);\n logger?.info(\n Buffer.isBuffer(chunk) ? chunk.toString('utf8').trim() : chunk.trim(),\n );\n });\n process.stderr.on('data', chunk => {\n logStream?.write(chunk);\n logger?.error(\n Buffer.isBuffer(chunk) ? chunk.toString('utf8').trim() : chunk.trim(),\n );\n });\n process.on('error', error => {\n return reject(error);\n });\n\n process.on('close', code => {\n if (code !== 0) {\n return reject(\n new Error(`Command ${command} failed, exit code: ${code}`),\n );\n }\n return resolve();\n });\n });\n}\n"],"names":["PassThrough","spawn"],"mappings":";;;;;AA8CA,eAAsB,oBACpB,OAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,OAAA;AAAA,IACA,IAAA;AAAA,IACA,OAAA,EAAS,YAAA;AAAA,IACT,MAAA;AAAA,IACA,SAAA,GAAY,IAAIA,uBAAA;AAAY,GAC9B,GAAI,OAAA;AAEJ,EAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AAC3C,IAAA,MAAM,OAAA,GAAUC,wBAAA,CAAM,OAAA,EAAS,IAAA,EAAM,YAAY,CAAA;AAEjD,IAAA,OAAA,CAAQ,MAAA,CAAO,EAAA,CAAG,MAAA,EAAQ,CAAA,KAAA,KAAS;AACjC,MAAA,SAAA,EAAW,MAAM,KAAK,CAAA;AACtB,MAAA,MAAA,EAAQ,IAAA;AAAA,QACN,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,GAAI,KAAA,CAAM,QAAA,CAAS,MAAM,CAAA,CAAE,IAAA,EAAK,GAAI,KAAA,CAAM,IAAA;AAAK,OACtE;AAAA,IACF,CAAC,CAAA;AACD,IAAA,OAAA,CAAQ,MAAA,CAAO,EAAA,CAAG,MAAA,EAAQ,CAAA,KAAA,KAAS;AACjC,MAAA,SAAA,EAAW,MAAM,KAAK,CAAA;AACtB,MAAA,MAAA,EAAQ,KAAA;AAAA,QACN,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,GAAI,KAAA,CAAM,QAAA,CAAS,MAAM,CAAA,CAAE,IAAA,EAAK,GAAI,KAAA,CAAM,IAAA;AAAK,OACtE;AAAA,IACF,CAAC,CAAA;AACD,IAAA,OAAA,CAAQ,EAAA,CAAG,SAAS,CAAA,KAAA,KAAS;AAC3B,MAAA,OAAO,OAAO,KAAK,CAAA;AAAA,IACrB,CAAC,CAAA;AAED,IAAA,OAAA,CAAQ,EAAA,CAAG,SAAS,CAAA,IAAA,KAAQ;AAC1B,MAAA,IAAI,SAAS,CAAA,EAAG;AACd,QAAA,OAAO,MAAA;AAAA,UACL,IAAI,KAAA,CAAM,CAAA,QAAA,EAAW,OAAO,CAAA,oBAAA,EAAuB,IAAI,CAAA,CAAE;AAAA,SAC3D;AAAA,MACF;AACA,MAAA,OAAO,OAAA,EAAQ;AAAA,IACjB,CAAC,CAAA;AAAA,EACH,CAAC,CAAA;AACH
|
|
1
|
+
{"version":3,"file":"executeShellCommand.cjs.js","sources":["../../src/actions/executeShellCommand.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { spawn, SpawnOptionsWithoutStdio } from 'node:child_process';\nimport { PassThrough, Writable } from 'node:stream';\n\n/**\n * Options for {@link executeShellCommand}.\n *\n * @public\n */\nexport type ExecuteShellCommandOptions = {\n /** command to run */\n command: string;\n /** arguments to pass the command */\n args: string[];\n /** options to pass to spawn */\n options?: SpawnOptionsWithoutStdio;\n /** logger to capture stdout and stderr output */\n logger?: LoggerService;\n /**\n * stream to capture stdout and stderr output\n * @deprecated please provide a logger instead.\n */\n logStream?: Writable;\n};\n\n/**\n * Run a command in a sub-process, normally a shell command.\n *\n * @public\n */\nexport async function executeShellCommand(\n options: ExecuteShellCommandOptions,\n): Promise<void> {\n const {\n command,\n args,\n options: spawnOptions,\n logger,\n logStream = new PassThrough(),\n } = options;\n\n await new Promise<void>((resolve, reject) => {\n const process = spawn(command, args, spawnOptions);\n\n process.stdout.on('data', chunk => {\n logStream?.write(chunk);\n logger?.info(\n Buffer.isBuffer(chunk) ? chunk.toString('utf8').trim() : chunk.trim(),\n );\n });\n process.stderr.on('data', chunk => {\n logStream?.write(chunk);\n logger?.error(\n Buffer.isBuffer(chunk) ? chunk.toString('utf8').trim() : chunk.trim(),\n );\n });\n process.on('error', error => {\n return reject(error);\n });\n\n process.on('close', code => {\n if (code !== 0) {\n return reject(\n new Error(`Command ${command} failed, exit code: ${code}`),\n );\n }\n return resolve();\n });\n });\n}\n"],"names":["PassThrough","spawn"],"mappings":";;;;;AA8CA,eAAsB,oBACpB,OAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,OAAA;AAAA,IACA,IAAA;AAAA,IACA,OAAA,EAAS,YAAA;AAAA,IACT,MAAA;AAAA,IACA,SAAA,GAAY,IAAIA,uBAAA;AAAY,GAC9B,GAAI,OAAA;AAEJ,EAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AAC3C,IAAA,MAAM,OAAA,GAAUC,wBAAA,CAAM,OAAA,EAAS,IAAA,EAAM,YAAY,CAAA;AAEjD,IAAA,OAAA,CAAQ,MAAA,CAAO,EAAA,CAAG,MAAA,EAAQ,CAAA,KAAA,KAAS;AACjC,MAAA,SAAA,EAAW,MAAM,KAAK,CAAA;AACtB,MAAA,MAAA,EAAQ,IAAA;AAAA,QACN,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,GAAI,KAAA,CAAM,QAAA,CAAS,MAAM,CAAA,CAAE,IAAA,EAAK,GAAI,KAAA,CAAM,IAAA;AAAK,OACtE;AAAA,IACF,CAAC,CAAA;AACD,IAAA,OAAA,CAAQ,MAAA,CAAO,EAAA,CAAG,MAAA,EAAQ,CAAA,KAAA,KAAS;AACjC,MAAA,SAAA,EAAW,MAAM,KAAK,CAAA;AACtB,MAAA,MAAA,EAAQ,KAAA;AAAA,QACN,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,GAAI,KAAA,CAAM,QAAA,CAAS,MAAM,CAAA,CAAE,IAAA,EAAK,GAAI,KAAA,CAAM,IAAA;AAAK,OACtE;AAAA,IACF,CAAC,CAAA;AACD,IAAA,OAAA,CAAQ,EAAA,CAAG,SAAS,CAAA,KAAA,KAAS;AAC3B,MAAA,OAAO,OAAO,KAAK,CAAA;AAAA,IACrB,CAAC,CAAA;AAED,IAAA,OAAA,CAAQ,EAAA,CAAG,SAAS,CAAA,IAAA,KAAQ;AAC1B,MAAA,IAAI,SAAS,CAAA,EAAG;AACd,QAAA,OAAO,MAAA;AAAA,UACL,IAAI,KAAA,CAAM,CAAA,QAAA,EAAW,OAAO,CAAA,oBAAA,EAAuB,IAAI,CAAA,CAAE;AAAA,SAC3D;AAAA,MACF;AACA,MAAA,OAAO,OAAA,EAAQ;AAAA,IACjB,CAAC,CAAA;AAAA,EACH,CAAC,CAAA;AACH;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.cjs.js","sources":["../../src/actions/fetch.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { UrlReaderService } from '@backstage/backend-plugin-api';\nimport {\n isChildPath,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport fs from 'fs-extra';\nimport path from 'node:path';\n\n/**\n * A helper function that reads the contents of a directory from the given URL.\n * Can be used in your own actions, and also used behind fetch:template and fetch:plain\n *\n * @public\n */\nexport async function fetchContents(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n token?: string;\n}) {\n const {\n reader,\n integrations,\n baseUrl,\n fetchUrl = '.',\n outputPath,\n token,\n } = options;\n\n const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);\n\n // We handle both file locations and url ones\n if (!fetchUrlIsAbsolute && baseUrl?.startsWith('file://')) {\n const basePath = baseUrl.slice('file://'.length);\n const srcDir = resolveSafeChildPath(path.dirname(basePath), fetchUrl);\n await fs.copy(srcDir, outputPath, {\n filter: src => isChildPath(srcDir, src),\n });\n } else {\n const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);\n\n const res = await reader.readTree(readUrl, { token });\n await fs.ensureDir(outputPath);\n await res.dir({ targetDir: outputPath });\n }\n}\n\n/**\n * A helper function that reads the content of a single file from the given URL.\n * Can be used in your own actions, and also used behind `fetch:plain:file`\n *\n * @public\n */\nexport async function fetchFile(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n token?: string;\n}) {\n const {\n reader,\n integrations,\n baseUrl,\n fetchUrl = '.',\n outputPath,\n token,\n } = options;\n\n const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);\n\n // We handle both file locations and url ones\n if (!fetchUrlIsAbsolute && baseUrl?.startsWith('file://')) {\n const basePath = baseUrl.slice('file://'.length);\n const src = resolveSafeChildPath(path.dirname(basePath), fetchUrl);\n await fs.copyFile(src, outputPath);\n } else {\n const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);\n\n const res = await reader.readUrl(readUrl, { token });\n await fs.ensureDir(path.dirname(outputPath));\n const buffer = await res.buffer();\n await fs.outputFile(outputPath, buffer);\n }\n}\n\nfunction isFetchUrlAbsolute(fetchUrl: string) {\n let fetchUrlIsAbsolute = false;\n try {\n // eslint-disable-next-line no-new\n new URL(fetchUrl);\n fetchUrlIsAbsolute = true;\n } catch {\n /* ignored */\n }\n return fetchUrlIsAbsolute;\n}\n\nfunction getReadUrl(\n fetchUrl: string,\n baseUrl: string | undefined,\n integrations: ScmIntegrations,\n) {\n if (isFetchUrlAbsolute(fetchUrl)) {\n return fetchUrl;\n } else if (baseUrl) {\n const integration = integrations.byUrl(baseUrl);\n if (!integration) {\n throw new InputError(`No integration found for location ${baseUrl}`);\n }\n\n return integration.resolveUrl({\n url: fetchUrl,\n base: baseUrl,\n });\n }\n throw new InputError(\n `Failed to fetch, template location could not be determined and the fetch URL is relative, ${fetchUrl}`,\n );\n}\n"],"names":["resolveSafeChildPath","path","fs","isChildPath","InputError"],"mappings":";;;;;;;;;;;;AAgCA,eAAsB,cAAc,OAAA,EAOjC;AACD,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,YAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,GAAW,GAAA;AAAA,IACX,UAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,kBAAA,GAAqB,mBAAmB,QAAQ,CAAA;AAGtD,EAAA,IAAI,CAAC,kBAAA,IAAsB,OAAA,EAAS,UAAA,CAAW,SAAS,CAAA,EAAG;AACzD,IAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,KAAA,CAAM,SAAA,CAAU,MAAM,CAAA;AAC/C,IAAA,MAAM,SAASA,qCAAA,CAAqBC,qBAAA,CAAK,OAAA,CAAQ,QAAQ,GAAG,QAAQ,CAAA;AACpE,IAAA,MAAMC,mBAAA,CAAG,IAAA,CAAK,MAAA,EAAQ,UAAA,EAAY;AAAA,MAChC,MAAA,EAAQ,CAAA,GAAA,KAAOC,4BAAA,CAAY,MAAA,EAAQ,GAAG;AAAA,KACvC,CAAA;AAAA,EACH,CAAA,MAAO;AACL,IAAA,MAAM,OAAA,GAAU,U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AA,EACxC;AACF;AAEA,SAAS,mBAAmB,QAAA,EAAkB;AAC5C,EAAA,IAAI,kBAAA,GAAqB,KAAA;AACzB,EAAA,IAAI;AAEF,IAAA,IAAI,IAAI,QAAQ,CAAA;AAChB,IAAA,kBAAA,GAAqB,IAAA;AAAA,EACvB,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,OAAO,kBAAA;AACT;AAEA,SAAS,UAAA,CACP,QAAA,EACA,OAAA,EACA,YAAA,EACA;AACA,EAAA,IAAI,kBAAA,CAAmB,QAAQ,CAAA,EAAG;AAChC,IAAA,OAAO,QAAA;AAAA,EACT,WAAW,OAAA,EAAS;AAClB,IAAA,MAAM,WAAA,GAAc,YAAA,CAAa,KAAA,CAAM,OAAO,CAAA;AAC9C,IAAA,IAAI,CAAC,WAAA,EAAa;AAChB,MAAA,MAAM,IAAIE,iBAAA,CAAW,CAAA,kCAAA,EAAqC,OAAO,CAAA,CAAE,CAAA;AAAA,IACrE;AAEA,IAAA,OAAO,YAAY,UAAA,CAAW;AAAA,MAC5B,GAAA,EAAK,QAAA;AAAA,MACL,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACA,EAAA,MAAM,IAAIA,iBAAA;AAAA,IACR,6FAA6F,QAAQ,CAAA;AAAA,GACvG;AACF
|
|
1
|
+
{"version":3,"file":"fetch.cjs.js","sources":["../../src/actions/fetch.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { UrlReaderService } from '@backstage/backend-plugin-api';\nimport {\n isChildPath,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport fs from 'fs-extra';\nimport path from 'node:path';\n\n/**\n * A helper function that reads the contents of a directory from the given URL.\n * Can be used in your own actions, and also used behind fetch:template and fetch:plain\n *\n * @public\n */\nexport async function fetchContents(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n token?: string;\n}) {\n const {\n reader,\n integrations,\n baseUrl,\n fetchUrl = '.',\n outputPath,\n token,\n } = options;\n\n const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);\n\n // We handle both file locations and url ones\n if (!fetchUrlIsAbsolute && baseUrl?.startsWith('file://')) {\n const basePath = baseUrl.slice('file://'.length);\n const srcDir = resolveSafeChildPath(path.dirname(basePath), fetchUrl);\n await fs.copy(srcDir, outputPath, {\n filter: src => isChildPath(srcDir, src),\n });\n } else {\n const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);\n\n const res = await reader.readTree(readUrl, { token });\n await fs.ensureDir(outputPath);\n await res.dir({ targetDir: outputPath });\n }\n}\n\n/**\n * A helper function that reads the content of a single file from the given URL.\n * Can be used in your own actions, and also used behind `fetch:plain:file`\n *\n * @public\n */\nexport async function fetchFile(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n token?: string;\n}) {\n const {\n reader,\n integrations,\n baseUrl,\n fetchUrl = '.',\n outputPath,\n token,\n } = options;\n\n const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);\n\n // We handle both file locations and url ones\n if (!fetchUrlIsAbsolute && baseUrl?.startsWith('file://')) {\n const basePath = baseUrl.slice('file://'.length);\n const src = resolveSafeChildPath(path.dirname(basePath), fetchUrl);\n await fs.copyFile(src, outputPath);\n } else {\n const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);\n\n const res = await reader.readUrl(readUrl, { token });\n await fs.ensureDir(path.dirname(outputPath));\n const buffer = await res.buffer();\n await fs.outputFile(outputPath, buffer);\n }\n}\n\nfunction isFetchUrlAbsolute(fetchUrl: string) {\n let fetchUrlIsAbsolute = false;\n try {\n // eslint-disable-next-line no-new\n new URL(fetchUrl);\n fetchUrlIsAbsolute = true;\n } catch {\n /* ignored */\n }\n return fetchUrlIsAbsolute;\n}\n\nfunction getReadUrl(\n fetchUrl: string,\n baseUrl: string | undefined,\n integrations: ScmIntegrations,\n) {\n if (isFetchUrlAbsolute(fetchUrl)) {\n return fetchUrl;\n } else if (baseUrl) {\n const integration = integrations.byUrl(baseUrl);\n if (!integration) {\n throw new InputError(`No integration found for location ${baseUrl}`);\n }\n\n return integration.resolveUrl({\n url: fetchUrl,\n base: baseUrl,\n });\n }\n throw new InputError(\n `Failed to fetch, template location could not be determined and the fetch URL is relative, ${fetchUrl}`,\n );\n}\n"],"names":["resolveSafeChildPath","path","fs","isChildPath","InputError"],"mappings":";;;;;;;;;;;;AAgCA,eAAsB,cAAc,OAAA,EAOjC;AACD,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,YAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,GAAW,GAAA;AAAA,IACX,UAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,kBAAA,GAAqB,mBAAmB,QAAQ,CAAA;AAGtD,EAAA,IAAI,CAAC,kBAAA,IAAsB,OAAA,EAAS,UAAA,CAAW,SAAS,CAAA,EAAG;AACzD,IAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,KAAA,CAAM,SAAA,CAAU,MAAM,CAAA;AAC/C,IAAA,MAAM,SAASA,qCAAA,CAAqBC,qBAAA,CAAK,OAAA,CAAQ,QAAQ,GAAG,QAAQ,CAAA;AACpE,IAAA,MAAMC,mBAAA,CAAG,IAAA,CAAK,MAAA,EAAQ,UAAA,EAAY;AAAA,MAChC,MAAA,EAAQ,CAAA,GAAA,KAAOC,4BAAA,CAAY,M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CAAI,MAAA,EAAO;AAChC,IAAA,MAAMC,mBAAA,CAAG,UAAA,CAAW,UAAA,EAAY,MAAM,CAAA;AAAA,EACxC;AACF;AAEA,SAAS,mBAAmB,QAAA,EAAkB;AAC5C,EAAA,IAAI,kBAAA,GAAqB,KAAA;AACzB,EAAA,IAAI;AAEF,IAAA,IAAI,IAAI,QAAQ,CAAA;AAChB,IAAA,kBAAA,GAAqB,IAAA;AAAA,EACvB,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,OAAO,kBAAA;AACT;AAEA,SAAS,UAAA,CACP,QAAA,EACA,OAAA,EACA,YAAA,EACA;AACA,EAAA,IAAI,kBAAA,CAAmB,QAAQ,CAAA,EAAG;AAChC,IAAA,OAAO,QAAA;AAAA,EACT,WAAW,OAAA,EAAS;AAClB,IAAA,MAAM,WAAA,GAAc,YAAA,CAAa,KAAA,CAAM,OAAO,CAAA;AAC9C,IAAA,IAAI,CAAC,WAAA,EAAa;AAChB,MAAA,MAAM,IAAIE,iBAAA,CAAW,CAAA,kCAAA,EAAqC,OAAO,CAAA,CAAE,CAAA;AAAA,IACrE;AAEA,IAAA,OAAO,YAAY,UAAA,CAAW;AAAA,MAC5B,GAAA,EAAK,QAAA;AAAA,MACL,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACA,EAAA,MAAM,IAAIA,iBAAA;AAAA,IACR,6FAA6F,QAAQ,CAAA;AAAA,GACvG;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitHelpers.cjs.js","sources":["../../src/actions/gitHelpers.ts"],"sourcesContent":["/*\n * Copyright 2023 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 */\n\nimport { Git } from '../scm';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\n/**\n * @public\n */\nexport async function initRepoAndPush(input: {\n dir: string;\n remoteUrl: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: LoggerService;\n defaultBranch?: string;\n commitMessage?: string;\n gitAuthorInfo?: { name?: string; email?: string };\n signingKey?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n remoteUrl,\n auth,\n logger,\n defaultBranch = 'master',\n commitMessage = 'Initial commit',\n gitAuthorInfo,\n signingKey,\n } = input;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.init({\n dir,\n defaultBranch,\n });\n\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n signingKey,\n });\n\n await git.push({\n dir,\n remote: 'origin',\n url: remoteUrl,\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function commitAndPushRepo(input: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: LoggerService;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n signingKey?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n signingKey,\n } = input;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.fetch({ dir });\n await git.checkout({ dir, ref: branch });\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n signingKey,\n });\n\n await git.push({\n dir,\n remote: 'origin',\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function cloneRepo(options: {\n url: string;\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: LoggerService | undefined;\n ref?: string | undefined;\n depth?: number | undefined;\n noCheckout?: boolean | undefined;\n}): Promise<void> {\n const { url, dir, auth, logger, ref, depth, noCheckout } = options;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.clone({ url, dir, ref, depth, noCheckout });\n}\n\n/**\n * @public\n */\nexport async function createBranch(options: {\n dir: string;\n ref: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: LoggerService | undefined;\n}): Promise<void> {\n const { dir, ref, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.branch({ dir, ref });\n}\n\n/**\n * @public\n */\nexport async function addFiles(options: {\n dir: string;\n filepath: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: LoggerService | undefined;\n}): Promise<void> {\n const { dir, filepath, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.add({ dir, filepath });\n}\n\n/**\n * @public\n */\nexport async function removeFiles(options: {\n dir: string;\n filepath: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: LoggerService | undefined;\n}): Promise<void> {\n const { dir, filepath, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.remove({ dir, filepath });\n}\n\n/**\n * @public\n */\nexport async function commitAndPushBranch(options: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: LoggerService | undefined;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n remote?: string;\n signingKey?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n remote = 'origin',\n signingKey,\n } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n signingKey,\n });\n\n await git.push({\n dir,\n remote,\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n"],"names":["git","Git"],"mappings":";;;;AAsBA,eAAsB,gBAAgB,KAAA,EAYF;AAClC,EAAA,MAAM;AAAA,IACJ,GAAA;AAAA,IACA,SAAA;AAAA,IACA,IAAA;AAAA,IACA,MAAA;AAAA,IACA,aAAA,GAAgB,QAAA;AAAA,IAChB,aAAA,GAAgB,gBAAA;AAAA,IAChB,aAAA;AAAA,IACA;AAAA,GACF,GAAI,KAAA;AACJ,EAAA,MAAMA,KAAA,GAAMC,QAAI,QAAA,CAAS;AAAA,IACvB,GAAG,IAAA;AAAA,IACH;AAAA,GACD,CAAA;AAED,EAAA,MAAMD,MAAI,IAAA,CAAK;AAAA,IACb,GAAA;AAAA,IACA;AA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AA;AAAA,GAC7C,CAAA;AAED,EAAA,OAAO,EAAE,UAAA,EAAW;AACtB;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"gitHelpers.cjs.js","sources":["../../src/actions/gitHelpers.ts"],"sourcesContent":["/*\n * Copyright 2023 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 */\n\nimport { Git } from '../scm';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\n/**\n * @public\n */\nexport async function initRepoAndPush(input: {\n dir: string;\n remoteUrl: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: LoggerService;\n defaultBranch?: string;\n commitMessage?: string;\n gitAuthorInfo?: { name?: string; email?: string };\n signingKey?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n remoteUrl,\n auth,\n logger,\n defaultBranch = 'master',\n commitMessage = 'Initial commit',\n gitAuthorInfo,\n signingKey,\n } = input;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.init({\n dir,\n defaultBranch,\n });\n\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n signingKey,\n });\n\n await git.push({\n dir,\n remote: 'origin',\n url: remoteUrl,\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function commitAndPushRepo(input: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: LoggerService;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n signingKey?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n signingKey,\n } = input;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.fetch({ dir });\n await git.checkout({ dir, ref: branch });\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n signingKey,\n });\n\n await git.push({\n dir,\n remote: 'origin',\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function cloneRepo(options: {\n url: string;\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: LoggerService | undefined;\n ref?: string | undefined;\n depth?: number | undefined;\n noCheckout?: boolean | undefined;\n}): Promise<void> {\n const { url, dir, auth, logger, ref, depth, noCheckout } = options;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.clone({ url, dir, ref, depth, noCheckout });\n}\n\n/**\n * @public\n */\nexport async function createBranch(options: {\n dir: string;\n ref: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: LoggerService | undefined;\n}): Promise<void> {\n const { dir, ref, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.branch({ dir, ref });\n}\n\n/**\n * @public\n */\nexport async function addFiles(options: {\n dir: string;\n filepath: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: LoggerService | undefined;\n}): Promise<void> {\n const { dir, filepath, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.add({ dir, filepath });\n}\n\n/**\n * @public\n */\nexport async function removeFiles(options: {\n dir: string;\n filepath: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: LoggerService | undefined;\n}): Promise<void> {\n const { dir, filepath, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.remove({ dir, filepath });\n}\n\n/**\n * @public\n */\nexport async function commitAndPushBranch(options: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: LoggerService | undefined;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n remote?: string;\n signingKey?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n remote = 'origin',\n signingKey,\n } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n signingKey,\n });\n\n await git.push({\n dir,\n remote,\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n"],"names":["git","Git"],"mappings":";;;;AAsBA,eAAsB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Q,YAAA;AAAA,IAC7B,KAAA,EAAO,eAAe,KAAA,IAAS;AAAA,GACjC;AAEA,EAAA,MAAM,UAAA,GAAa,MAAMD,KAAA,CAAI,MAAA,CAAO;AAAA,IAClC,GAAA;AAAA,IACA,OAAA,EAAS,aAAA;AAAA,IACT,MAAA,EAAQ,UAAA;AAAA,IACR,SAAA,EAAW,UAAA;AAAA,IACX;AAAA,GACD,CAAA;AAED,EAAA,MAAMA,MAAI,IAAA,CAAK;AAAA,IACb,GAAA;AAAA,IACA,MAAA;AAAA,IACA,SAAA,EAAW,SAAA,IAAa,CAAA,WAAA,EAAc,MAAM,CAAA;AAAA,GAC7C,CAAA;AAED,EAAA,OAAO,EAAE,UAAA,EAAW;AACtB;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.cjs.js","sources":["../../src/actions/util.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { InputError } from '@backstage/errors';\nimport { isChildPath } from '@backstage/backend-plugin-api';\nimport { join as joinPath, normalize as normalizePath } from 'node:path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { TemplateActionOptions } from './createTemplateAction';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { z } from 'zod/v3';\nimport { Schema } from 'jsonschema';\nimport { trim } from 'lodash';\n\n/**\n * @public\n */\nexport const getRepoSourceDirectory = (\n workspacePath: string,\n sourcePath: string | undefined,\n) => {\n if (sourcePath) {\n const safeSuffix = normalizePath(sourcePath).replace(\n /^(\\.\\.(\\/|\\\\|$))+/,\n '',\n );\n const path = joinPath(workspacePath, safeSuffix);\n if (!isChildPath(workspacePath, path)) {\n throw new Error('Invalid source path');\n }\n return path;\n }\n return workspacePath;\n};\n\n/**\n * @public\n */\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): {\n repo: string;\n host: string;\n owner?: string;\n organization?: string;\n workspace?: string;\n project?: string;\n} => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n const { owner, organization, workspace, project, repo } = Object.fromEntries(\n ['owner', 'organization', 'workspace', 'project', 'repo'].map(param => [\n param,\n parsed.searchParams.has(param)\n ? trim(parsed.searchParams.get(param)!, '/')\n : undefined,\n ]),\n );\n switch (type) {\n case 'bitbucketCloud': {\n checkRequiredParams(parsed, 'workspace', 'project', 'repo');\n break;\n }\n case 'bitbucketServer': {\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'azure': {\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'gitlab': {\n // project is the projectID, and if defined, owner and repo won't be needed.\n if (!project) {\n checkRequiredParams(parsed, 'owner', 'repo');\n }\n break;\n }\n case 'gitea': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n case 'gerrit': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n default: {\n checkRequiredParams(parsed, 'repo', 'owner');\n break;\n }\n }\n return { host, owner, repo: repo!, organization, workspace, project };\n};\n\nfunction checkRequiredParams(repoUrl: URL, ...params: string[]) {\n for (let i = 0; i < params.length; i++) {\n if (!repoUrl.searchParams.get(params[i])) {\n throw new InputError(\n `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${\n params[i]\n }`,\n );\n }\n }\n}\n\nconst isKeyValueZodCallback = (\n schema: unknown,\n): schema is { [key in string]: (zImpl: typeof z) => z.ZodType } => {\n return (\n typeof schema === 'object' &&\n !!schema &&\n Object.values(schema).every(v => typeof v === 'function')\n );\n};\n\nconst isZodFunctionDefinition = (\n schema: unknown,\n): schema is (zImpl: typeof z) => z.ZodType => {\n return typeof schema === 'function';\n};\n\nexport const parseSchemas = (\n action: TemplateActionOptions<any, any, any>,\n): { inputSchema?: Schema; outputSchema?: Schema } => {\n if (!action.schema) {\n return { inputSchema: undefined, outputSchema: undefined };\n }\n\n if (isKeyValueZodCallback(action.schema.input)) {\n const input = z.object(\n Object.fromEntries(\n Object.entries(action.schema.input).map(([k, v]) => [k, v(z)]),\n ),\n );\n\n return {\n inputSchema: zodToJsonSchema(input) as Schema,\n outputSchema: isKeyValueZodCallback(action.schema.output)\n ? (zodToJsonSchema(\n z.object(\n Object.fromEntries(\n Object.entries(action.schema.output).map(([k, v]) => [k, v(z)]),\n ),\n ),\n ) as Schema)\n : undefined,\n };\n }\n\n if (isZodFunctionDefinition(action.schema.input)) {\n return {\n inputSchema: zodToJsonSchema(action.schema.input(z)) as Schema,\n outputSchema: isZodFunctionDefinition(action.schema.output)\n ? (zodToJsonSchema(action.schema.output(z)) as Schema)\n : undefined,\n };\n }\n\n return {\n inputSchema: undefined,\n outputSchema: undefined,\n };\n};\n\n/**\n * Filter function to exclude the .git directory and its contents\n * while keeping other files like .gitignore\n * @public\n */\nexport function isNotGitDirectoryOrContents(path: string): boolean {\n return !(path.endsWith('.git') || path.includes('.git/'));\n}\n"],"names":["normalizePath","path","joinPath","isChildPath","InputError","trim","z","zodToJsonSchema"],"mappings":";;;;;;;;;;;;;AA6BO,MAAM,sBAAA,GAAyB,CACpC,aAAA,EACA,UAAA,KACG;AACH,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,MAAM,UAAA,GAAaA,cAAA,CAAc,UAAU,CAAA,CAAE,OAAA;AAAA,MAC3C,mBAAA;AAAA,MACA;AAAA,KACF;AACA,IAAA,M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,CAAC,GAAG,CAAA,CAAEA,IAAC,CAAC,CAAC;AAAA;AAChE;AACF,OACF,GACA;AAAA,KACN;AAAA,EACF;AAEA,EAAA,IAAI,uBAAA,CAAwB,MAAA,CAAO,MAAA,CAAO,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO;AAAA,MACL,aAAaC,gCAAA,CAAgB,MAAA,CAAO,MAAA,CAAO,KAAA,CAAMD,IAAC,CAAC,CAAA;AAAA,MACnD,YAAA,EAAc,uBAAA,CAAwB,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA,GACrDC,gCAAA,CAAgB,MAAA,CAAO,MAAA,CAAO,MAAA,CAAOD,IAAC,CAAC,CAAA,GACxC;AAAA,KACN;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,WAAA,EAAa,MAAA;AAAA,IACb,YAAA,EAAc;AAAA,GAChB;AACF;AAOO,SAAS,4BAA4B,IAAA,EAAuB;AACjE,EAAA,OAAO,EAAE,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA,IAAK,IAAA,CAAK,SAAS,OAAO,CAAA,CAAA;AACzD
|
|
1
|
+
{"version":3,"file":"util.cjs.js","sources":["../../src/actions/util.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { InputError } from '@backstage/errors';\nimport { isChildPath } from '@backstage/backend-plugin-api';\nimport { join as joinPath, normalize as normalizePath } from 'node:path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { TemplateActionOptions } from './createTemplateAction';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { z } from 'zod/v3';\nimport { Schema } from 'jsonschema';\nimport { trim } from 'lodash';\n\n/**\n * @public\n */\nexport const getRepoSourceDirectory = (\n workspacePath: string,\n sourcePath: string | undefined,\n) => {\n if (sourcePath) {\n const safeSuffix = normalizePath(sourcePath).replace(\n /^(\\.\\.(\\/|\\\\|$))+/,\n '',\n );\n const path = joinPath(workspacePath, safeSuffix);\n if (!isChildPath(workspacePath, path)) {\n throw new Error('Invalid source path');\n }\n return path;\n }\n return workspacePath;\n};\n\n/**\n * @public\n */\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): {\n repo: string;\n host: string;\n owner?: string;\n organization?: string;\n workspace?: string;\n project?: string;\n} => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n const { owner, organization, workspace, project, repo } = Object.fromEntries(\n ['owner', 'organization', 'workspace', 'project', 'repo'].map(param => [\n param,\n parsed.searchParams.has(param)\n ? trim(parsed.searchParams.get(param)!, '/')\n : undefined,\n ]),\n );\n switch (type) {\n case 'bitbucketCloud': {\n checkRequiredParams(parsed, 'workspace', 'project', 'repo');\n break;\n }\n case 'bitbucketServer': {\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'azure': {\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'gitlab': {\n // project is the projectID, and if defined, owner and repo won't be needed.\n if (!project) {\n checkRequiredParams(parsed, 'owner', 'repo');\n }\n break;\n }\n case 'gitea': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n case 'gerrit': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n default: {\n checkRequiredParams(parsed, 'repo', 'owner');\n break;\n }\n }\n return { host, owner, repo: repo!, organization, workspace, project };\n};\n\nfunction checkRequiredParams(repoUrl: URL, ...params: string[]) {\n for (let i = 0; i < params.length; i++) {\n if (!repoUrl.searchParams.get(params[i])) {\n throw new InputError(\n `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${\n params[i]\n }`,\n );\n }\n }\n}\n\nconst isKeyValueZodCallback = (\n schema: unknown,\n): schema is { [key in string]: (zImpl: typeof z) => z.ZodType } => {\n return (\n typeof schema === 'object' &&\n !!schema &&\n Object.values(schema).every(v => typeof v === 'function')\n );\n};\n\nconst isZodFunctionDefinition = (\n schema: unknown,\n): schema is (zImpl: typeof z) => z.ZodType => {\n return typeof schema === 'function';\n};\n\nexport const parseSchemas = (\n action: TemplateActionOptions<any, any, any>,\n): { inputSchema?: Schema; outputSchema?: Schema } => {\n if (!action.schema) {\n return { inputSchema: undefined, outputSchema: undefined };\n }\n\n if (isKeyValueZodCallback(action.schema.input)) {\n const input = z.object(\n Object.fromEntries(\n Object.entries(action.schema.input).map(([k, v]) => [k, v(z)]),\n ),\n );\n\n return {\n inputSchema: zodToJsonSchema(input) as Schema,\n outputSchema: isKeyValueZodCallback(action.schema.output)\n ? (zodToJsonSchema(\n z.object(\n Object.fromEntries(\n Object.entries(action.schema.output).map(([k, v]) => [k, v(z)]),\n ),\n ),\n ) as Schema)\n : undefined,\n };\n }\n\n if (isZodFunctionDefinition(action.schema.input)) {\n return {\n inputSchema: zodToJsonSchema(action.schema.input(z)) as Schema,\n outputSchema: isZodFunctionDefinition(action.schema.output)\n ? (zodToJsonSchema(action.schema.output(z)) as Schema)\n : undefined,\n };\n }\n\n return {\n inputSchema: undefined,\n outputSchema: undefined,\n };\n};\n\n/**\n * Filter function to exclude the .git directory and its contents\n * while keeping other files like .gitignore\n * @public\n */\nexport function isNotGitDirectoryOrContents(path: string): boolean {\n return !(path.endsWith('.git') || path.includes('.git/'));\n}\n"],"names":["normalizePath","path","joinPath","isChildPath","InputError","trim","z","zodToJsonSchema"],"mappings":";;;;;;;;;;;;;AA6BO,MAAM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GACnDA,gCAAA;AAAA,QACCD,IAAA,CAAE,MAAA;AAAA,UACA,MAAA,CAAO,WAAA;AAAA,YACL,OAAO,OAAA,CAAQ,MAAA,CAAO,MAAA,CAAO,MAAM,EAAE,GAAA,CAAI,CAAC,CAAC,CAAA,EAAG,CAAC,CAAA,KAAM,CAAC,GAAG,CAAA,CAAEA,IAAC,CAAC,CAAC;AAAA;AAChE;AACF,OACF,GACA;AAAA,KACN;AAAA,EACF;AAEA,EAAA,IAAI,uBAAA,CAAwB,MAAA,CAAO,MAAA,CAAO,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO;AAAA,MACL,aAAaC,gCAAA,CAAgB,MAAA,CAAO,MAAA,CAAO,KAAA,CAAMD,IAAC,CAAC,CAAA;AAAA,MACnD,YAAA,EAAc,uBAAA,CAAwB,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA,GACrDC,gCAAA,CAAgB,MAAA,CAAO,MAAA,CAAO,MAAA,CAAOD,IAAC,CAAC,CAAA,GACxC;AAAA,KACN;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,WAAA,EAAa,MAAA;AAAA,IACb,YAAA,EAAc;AAAA,GAChB;AACF;AAOO,SAAS,4BAA4B,IAAA,EAAuB;AACjE,EAAA,OAAO,EAAE,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA,IAAK,IAAA,CAAK,SAAS,OAAO,CAAA,CAAA;AACzD;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTemplateFilter.cjs.js","sources":["../../../src/alpha/filters/createTemplateFilter.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\n\nimport { ZodFunctionSchema } from '../types';\nimport { CreatedTemplateFilter, TemplateFilterExample } from './types';\nimport { z } from 'zod/v3';\n\n/**\n * This function is used to create new template filters in type-safe manner.\n * @alpha\n */\nexport const createTemplateFilter = <\n TFunctionArgs extends [z.ZodTypeAny, ...z.ZodTypeAny[]],\n TReturnType extends z.ZodTypeAny,\n>(options: {\n id: string;\n description?: string;\n examples?: TemplateFilterExample[];\n schema?: ZodFunctionSchema<TFunctionArgs, TReturnType>;\n filter: (...args: z.infer<z.ZodTuple<TFunctionArgs>>) => z.infer<TReturnType>;\n}): CreatedTemplateFilter<TFunctionArgs, TReturnType> => options;\n"],"names":[],"mappings":";;AAwBO,MAAM,oBAAA,GAAuB,CAGlC,OAAA,KAMuD
|
|
1
|
+
{"version":3,"file":"createTemplateFilter.cjs.js","sources":["../../../src/alpha/filters/createTemplateFilter.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\n\nimport { ZodFunctionSchema } from '../types';\nimport { CreatedTemplateFilter, TemplateFilterExample } from './types';\nimport { z } from 'zod/v3';\n\n/**\n * This function is used to create new template filters in type-safe manner.\n * @alpha\n */\nexport const createTemplateFilter = <\n TFunctionArgs extends [z.ZodTypeAny, ...z.ZodTypeAny[]],\n TReturnType extends z.ZodTypeAny,\n>(options: {\n id: string;\n description?: string;\n examples?: TemplateFilterExample[];\n schema?: ZodFunctionSchema<TFunctionArgs, TReturnType>;\n filter: (...args: z.infer<z.ZodTuple<TFunctionArgs>>) => z.infer<TReturnType>;\n}): CreatedTemplateFilter<TFunctionArgs, TReturnType> => options;\n"],"names":[],"mappings":";;AAwBO,MAAM,oBAAA,GAAuB,CAGlC,OAAA,KAMuD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTemplateGlobal.cjs.js","sources":["../../../src/alpha/globals/createTemplateGlobal.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\n\nimport { z } from 'zod/v3';\nimport {\n CreatedTemplateGlobalFunction,\n CreatedTemplateGlobalValue,\n TemplateGlobalFunctionExample,\n} from './types';\nimport { ZodFunctionSchema } from '../types';\n\n/**\n * This function is used to create new template global values in type-safe manner.\n * @param t - CreatedTemplateGlobalValue | CreatedTemplateGlobalFunction\n * @returns t\n * @alpha\n */\nexport const createTemplateGlobalValue = (\n v: CreatedTemplateGlobalValue,\n): CreatedTemplateGlobalValue => v;\n\n/**\n * This function is used to create new template global functions in type-safe manner.\n * @param fn - CreatedTemplateGlobalFunction\n * @returns fn\n * @alpha\n */\nexport const createTemplateGlobalFunction = <\n TFunctionArgs extends [z.ZodTypeAny, ...z.ZodTypeAny[]],\n TReturnType extends z.ZodTypeAny,\n>(options: {\n id: string;\n description?: string;\n examples?: TemplateGlobalFunctionExample[];\n schema?: ZodFunctionSchema<TFunctionArgs, TReturnType>;\n fn: (...args: z.infer<z.ZodTuple<TFunctionArgs>>) => z.infer<TReturnType>;\n}): CreatedTemplateGlobalFunction<TFunctionArgs, TReturnType> => options;\n"],"names":[],"mappings":";;AA8BO,MAAM,yBAAA,GAA4B,CACvC,CAAA,KAC+B;AAQ1B,MAAM,4BAAA,GAA+B,CAG1C,OAAA,KAM+D
|
|
1
|
+
{"version":3,"file":"createTemplateGlobal.cjs.js","sources":["../../../src/alpha/globals/createTemplateGlobal.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\n\nimport { z } from 'zod/v3';\nimport {\n CreatedTemplateGlobalFunction,\n CreatedTemplateGlobalValue,\n TemplateGlobalFunctionExample,\n} from './types';\nimport { ZodFunctionSchema } from '../types';\n\n/**\n * This function is used to create new template global values in type-safe manner.\n * @param t - CreatedTemplateGlobalValue | CreatedTemplateGlobalFunction\n * @returns t\n * @alpha\n */\nexport const createTemplateGlobalValue = (\n v: CreatedTemplateGlobalValue,\n): CreatedTemplateGlobalValue => v;\n\n/**\n * This function is used to create new template global functions in type-safe manner.\n * @param fn - CreatedTemplateGlobalFunction\n * @returns fn\n * @alpha\n */\nexport const createTemplateGlobalFunction = <\n TFunctionArgs extends [z.ZodTypeAny, ...z.ZodTypeAny[]],\n TReturnType extends z.ZodTypeAny,\n>(options: {\n id: string;\n description?: string;\n examples?: TemplateGlobalFunctionExample[];\n schema?: ZodFunctionSchema<TFunctionArgs, TReturnType>;\n fn: (...args: z.infer<z.ZodTuple<TFunctionArgs>>) => z.infer<TReturnType>;\n}): CreatedTemplateGlobalFunction<TFunctionArgs, TReturnType> => options;\n"],"names":[],"mappings":";;AA8BO,MAAM,yBAAA,GAA4B,CACvC,CAAA,KAC+B;AAQ1B,MAAM,4BAAA,GAA+B,CAG1C,OAAA,KAM+D;;;"}
|
package/dist/alpha.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alpha.cjs.js","sources":["../src/alpha/index.ts"],"sourcesContent":["/*\n * Copyright 2022 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 */\n\nimport { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport {\n TaskBroker,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { CreatedTemplateFilter } from './filters';\nimport { CreatedTemplateGlobal } from './globals';\n\nexport * from '../tasks/alpha';\nexport * from './filters';\nexport * from './globals';\nexport * from './types';\nexport * from './checkpoints';\n\n/**\n * Extension point for replacing the scaffolder task broker.\n *\n * @alpha\n * @deprecated this extension point is planned to be removed, please reach out to us in an issue if you're using this extension point and your use cases.\n */\nexport interface ScaffolderTaskBrokerExtensionPoint {\n setTaskBroker(taskBroker: TaskBroker): void;\n}\n\n/**\n * Extension point for replacing the scaffolder task broker.\n *\n * @alpha\n * @deprecated this extension point is planned to be removed, please reach out to us in an issue if you're using this extension point and your use cases.\n */\nexport const scaffolderTaskBrokerExtensionPoint =\n createExtensionPoint<ScaffolderTaskBrokerExtensionPoint>({\n id: 'scaffolder.taskBroker',\n });\n\n/**\n * Extension point for adding template filters and globals.\n *\n * @alpha\n */\nexport interface ScaffolderTemplatingExtensionPoint {\n addTemplateFilters(\n filters: Record<string, TemplateFilter> | CreatedTemplateFilter<any, any>[],\n ): void;\n\n addTemplateGlobals(\n globals: Record<string, TemplateGlobal> | CreatedTemplateGlobal[],\n ): void;\n}\n\n/**\n * Extension point for adding template filters and globals.\n *\n * @alpha\n */\nexport const scaffolderTemplatingExtensionPoint =\n createExtensionPoint<ScaffolderTemplatingExtensionPoint>({\n id: 'scaffolder.templating',\n });\n\n/**\n * Autocomplete handler for the scaffolder.\n * @alpha\n */\nexport type AutocompleteHandler = ({\n resource,\n token,\n context,\n}: {\n resource: string;\n token: string;\n context: Record<string, string>;\n}) => Promise<{ results: { title?: string; id: string }[] }>;\n\n/**\n * Extension point for adding autocomplete handler providers\n * @alpha\n */\nexport interface ScaffolderAutocompleteExtensionPoint {\n addAutocompleteProvider({\n id,\n handler,\n }: {\n id: string;\n handler: AutocompleteHandler;\n }): void;\n}\n\n/**\n * Extension point for adding autocomplete handlers.\n *\n * @alpha\n */\nexport const scaffolderAutocompleteExtensionPoint =\n createExtensionPoint<ScaffolderAutocompleteExtensionPoint>({\n id: 'scaffolder.autocomplete',\n });\n\n/**\n * This provider has to be implemented to make it possible to serialize/deserialize scaffolder workspace.\n *\n * @alpha\n */\nexport interface WorkspaceProvider {\n serializeWorkspace({\n path,\n taskId,\n }: {\n path: string;\n taskId: string;\n }): Promise<void>;\n\n cleanWorkspace(options: { taskId: string }): Promise<void>;\n\n rehydrateWorkspace(options: {\n taskId: string;\n targetPath: string;\n }): Promise<void>;\n}\n\n/**\n * Extension point for adding workspace providers.\n *\n * @alpha\n */\nexport interface ScaffolderWorkspaceProviderExtensionPoint {\n addProviders(providers: Record<string, WorkspaceProvider>): void;\n}\n\n/**\n * Extension point for adding workspace providers.\n *\n * @alpha\n */\nexport const scaffolderWorkspaceProviderExtensionPoint =\n createExtensionPoint<ScaffolderWorkspaceProviderExtensionPoint>({\n id: 'scaffolder.workspace.provider',\n });\n\nimport { createPermissionResourceRef } from '@backstage/plugin-permission-node';\nimport {\n RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,\n RESOURCE_TYPE_SCAFFOLDER_ACTION,\n RESOURCE_TYPE_SCAFFOLDER_TASK,\n} from '@backstage/plugin-scaffolder-common/alpha';\nimport type {\n TemplateEntityStepV1beta3,\n TemplateParametersV1beta3,\n} from '@backstage/plugin-scaffolder-common';\nimport type { JsonObject } from '@backstage/types';\nimport type {\n SerializedTask,\n TaskFilter,\n} from '@backstage/plugin-scaffolder-node';\n\n/**\n * Permission resource ref for scaffolder templates.\n * @alpha\n */\nexport const scaffolderTemplatePermissionResourceRef =\n createPermissionResourceRef<\n TemplateEntityStepV1beta3 | TemplateParametersV1beta3,\n {}\n >().with({\n pluginId: 'scaffolder',\n resourceType: RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,\n });\n\n/**\n * Permission resource ref for scaffolder actions.\n * @alpha\n */\nexport const scaffolderActionPermissionResourceRef =\n createPermissionResourceRef<JsonObject, {}>().with({\n pluginId: 'scaffolder',\n resourceType: RESOURCE_TYPE_SCAFFOLDER_ACTION,\n });\n\n/**\n * Permission resource ref for scaffolder tasks.\n * @alpha\n */\nexport const scaffolderTaskPermissionResourceRef = createPermissionResourceRef<\n SerializedTask,\n TaskFilter\n>().with({\n pluginId: 'scaffolder',\n resourceType: RESOURCE_TYPE_SCAFFOLDER_TASK,\n});\n"],"names":["createExtensionPoint","createPermissionResourceRef","RESOURCE_TYPE_SCAFFOLDER_TEMPLATE","RESOURCE_TYPE_SCAFFOLDER_ACTION","RESOURCE_TYPE_SCAFFOLDER_TASK"],"mappings":";;;;;;;;;AA+CO,MAAM,qCACXA,qCAAA,CAAyD;AAAA,EACvD,EAAA,EAAI;AACN,CAAC;AAsBI,MAAM,qCACXA,qCAAA,CAAyD;AAAA,EACvD,EAAA,EAAI;AACN,CAAC;AAmCI,MAAM,uCACXA,qCAAA,CAA2D;AAAA,EACzD,EAAA,EAAI;AACN,CAAC;AAsCI,MAAM,4CACXA,qCAAA,CAAgE;AAAA,EAC9D,EAAA,EAAI;AACN,CAAC;AAsBI,MAAM,uCAAA,GACXC,gDAAA,EAGE,CAAE,IAAA,CAAK;AAAA,EACP,QAAA,EAAU,YAAA;AAAA,EACV,YAAA,EAAcC;AAChB,CAAC;AAMI,MAAM,qCAAA,GACXD,gDAAA,EAA4C,CAAE,IAAA,CAAK;AAAA,EACjD,QAAA,EAAU,YAAA;AAAA,EACV,YAAA,EAAcE;AAChB,CAAC;AAMI,MAAM,mCAAA,GAAsCF,gDAAA,EAGjD,CAAE,IAAA,CAAK;AAAA,EACP,QAAA,EAAU,YAAA;AAAA,EACV,YAAA,EAAcG;AAChB,CAAC
|
|
1
|
+
{"version":3,"file":"alpha.cjs.js","sources":["../src/alpha/index.ts"],"sourcesContent":["/*\n * Copyright 2022 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 */\n\nimport { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport {\n TaskBroker,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { CreatedTemplateFilter } from './filters';\nimport { CreatedTemplateGlobal } from './globals';\n\nexport * from '../tasks/alpha';\nexport * from './filters';\nexport * from './globals';\nexport * from './types';\nexport * from './checkpoints';\n\n/**\n * Extension point for replacing the scaffolder task broker.\n *\n * @alpha\n * @deprecated this extension point is planned to be removed, please reach out to us in an issue if you're using this extension point and your use cases.\n */\nexport interface ScaffolderTaskBrokerExtensionPoint {\n setTaskBroker(taskBroker: TaskBroker): void;\n}\n\n/**\n * Extension point for replacing the scaffolder task broker.\n *\n * @alpha\n * @deprecated this extension point is planned to be removed, please reach out to us in an issue if you're using this extension point and your use cases.\n */\nexport const scaffolderTaskBrokerExtensionPoint =\n createExtensionPoint<ScaffolderTaskBrokerExtensionPoint>({\n id: 'scaffolder.taskBroker',\n });\n\n/**\n * Extension point for adding template filters and globals.\n *\n * @alpha\n */\nexport interface ScaffolderTemplatingExtensionPoint {\n addTemplateFilters(\n filters: Record<string, TemplateFilter> | CreatedTemplateFilter<any, any>[],\n ): void;\n\n addTemplateGlobals(\n globals: Record<string, TemplateGlobal> | CreatedTemplateGlobal[],\n ): void;\n}\n\n/**\n * Extension point for adding template filters and globals.\n *\n * @alpha\n */\nexport const scaffolderTemplatingExtensionPoint =\n createExtensionPoint<ScaffolderTemplatingExtensionPoint>({\n id: 'scaffolder.templating',\n });\n\n/**\n * Autocomplete handler for the scaffolder.\n * @alpha\n */\nexport type AutocompleteHandler = ({\n resource,\n token,\n context,\n}: {\n resource: string;\n token: string;\n context: Record<string, string>;\n}) => Promise<{ results: { title?: string; id: string }[] }>;\n\n/**\n * Extension point for adding autocomplete handler providers\n * @alpha\n */\nexport interface ScaffolderAutocompleteExtensionPoint {\n addAutocompleteProvider({\n id,\n handler,\n }: {\n id: string;\n handler: AutocompleteHandler;\n }): void;\n}\n\n/**\n * Extension point for adding autocomplete handlers.\n *\n * @alpha\n */\nexport const scaffolderAutocompleteExtensionPoint =\n createExtensionPoint<ScaffolderAutocompleteExtensionPoint>({\n id: 'scaffolder.autocomplete',\n });\n\n/**\n * This provider has to be implemented to make it possible to serialize/deserialize scaffolder workspace.\n *\n * @alpha\n */\nexport interface WorkspaceProvider {\n serializeWorkspace({\n path,\n taskId,\n }: {\n path: string;\n taskId: string;\n }): Promise<void>;\n\n cleanWorkspace(options: { taskId: string }): Promise<void>;\n\n rehydrateWorkspace(options: {\n taskId: string;\n targetPath: string;\n }): Promise<void>;\n}\n\n/**\n * Extension point for adding workspace providers.\n *\n * @alpha\n */\nexport interface ScaffolderWorkspaceProviderExtensionPoint {\n addProviders(providers: Record<string, WorkspaceProvider>): void;\n}\n\n/**\n * Extension point for adding workspace providers.\n *\n * @alpha\n */\nexport const scaffolderWorkspaceProviderExtensionPoint =\n createExtensionPoint<ScaffolderWorkspaceProviderExtensionPoint>({\n id: 'scaffolder.workspace.provider',\n });\n\nimport { createPermissionResourceRef } from '@backstage/plugin-permission-node';\nimport {\n RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,\n RESOURCE_TYPE_SCAFFOLDER_ACTION,\n RESOURCE_TYPE_SCAFFOLDER_TASK,\n} from '@backstage/plugin-scaffolder-common/alpha';\nimport type {\n TemplateEntityStepV1beta3,\n TemplateParametersV1beta3,\n} from '@backstage/plugin-scaffolder-common';\nimport type { JsonObject } from '@backstage/types';\nimport type {\n SerializedTask,\n TaskFilter,\n} from '@backstage/plugin-scaffolder-node';\n\n/**\n * Permission resource ref for scaffolder templates.\n * @alpha\n */\nexport const scaffolderTemplatePermissionResourceRef =\n createPermissionResourceRef<\n TemplateEntityStepV1beta3 | TemplateParametersV1beta3,\n {}\n >().with({\n pluginId: 'scaffolder',\n resourceType: RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,\n });\n\n/**\n * Permission resource ref for scaffolder actions.\n * @alpha\n */\nexport const scaffolderActionPermissionResourceRef =\n createPermissionResourceRef<JsonObject, {}>().with({\n pluginId: 'scaffolder',\n resourceType: RESOURCE_TYPE_SCAFFOLDER_ACTION,\n });\n\n/**\n * Permission resource ref for scaffolder tasks.\n * @alpha\n */\nexport const scaffolderTaskPermissionResourceRef = createPermissionResourceRef<\n SerializedTask,\n TaskFilter\n>().with({\n pluginId: 'scaffolder',\n resourceType: RESOURCE_TYPE_SCAFFOLDER_TASK,\n});\n"],"names":["createExtensionPoint","createPermissionResourceRef","RESOURCE_TYPE_SCAFFOLDER_TEMPLATE","RESOURCE_TYPE_SCAFFOLDER_ACTION","RESOURCE_TYPE_SCAFFOLDER_TASK"],"mappings":";;;;;;;;;AA+CO,MAAM,qCACXA,qCAAA,CAAyD;AAAA,EACvD,EAAA,EAAI;AACN,CAAC;AAsBI,MAAM,qCACXA,qCAAA,CAAyD;AAAA,EACvD,EAAA,EAAI;AACN,CAAC;AAmCI,MAAM,uCACXA,qCAAA,CAA2D;AAAA,EACzD,EAAA,EAAI;AACN,CAAC;AAsCI,MAAM,4CACXA,qCAAA,CAAgE;AAAA,EAC9D,EAAA,EAAI;AACN,CAAC;AAsBI,MAAM,uCAAA,GACXC,gDAAA,EAGE,CAAE,IAAA,CAAK;AAAA,EACP,QAAA,EAAU,YAAA;AAAA,EACV,YAAA,EAAcC;AAChB,CAAC;AAMI,MAAM,qCAAA,GACXD,gDAAA,EAA4C,CAAE,IAAA,CAAK;AAAA,EACjD,QAAA,EAAU,YAAA;AAAA,EACV,YAAA,EAAcE;AAChB,CAAC;AAMI,MAAM,mCAAA,GAAsCF,gDAAA,EAGjD,CAAE,IAAA,CAAK;AAAA,EACP,QAAA,EAAU,YAAA;AAAA,EACV,YAAA,EAAcG;AAChB,CAAC;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions.cjs.js","sources":["../src/extensions.ts"],"sourcesContent":["/*\n * Copyright 2025 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 { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport { TemplateAction } from './actions';\n\n/**\n * Extension point for managing scaffolder actions.\n *\n * @public\n */\nexport interface ScaffolderActionsExtensionPoint {\n addActions(...actions: TemplateAction<any, any, any>[]): void;\n}\n\n/**\n * Extension point for managing scaffolder actions.\n *\n * @public\n */\nexport const scaffolderActionsExtensionPoint =\n createExtensionPoint<ScaffolderActionsExtensionPoint>({\n id: 'scaffolder.actions',\n });\n"],"names":["createExtensionPoint"],"mappings":";;;;AAgCO,MAAM,kCACXA,qCAAA,CAAsD;AAAA,EACpD,EAAA,EAAI;AACN,CAAC
|
|
1
|
+
{"version":3,"file":"extensions.cjs.js","sources":["../src/extensions.ts"],"sourcesContent":["/*\n * Copyright 2025 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 { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport { TemplateAction } from './actions';\n\n/**\n * Extension point for managing scaffolder actions.\n *\n * @public\n */\nexport interface ScaffolderActionsExtensionPoint {\n addActions(...actions: TemplateAction<any, any, any>[]): void;\n}\n\n/**\n * Extension point for managing scaffolder actions.\n *\n * @public\n */\nexport const scaffolderActionsExtensionPoint =\n createExtensionPoint<ScaffolderActionsExtensionPoint>({\n id: 'scaffolder.actions',\n });\n"],"names":["createExtensionPoint"],"mappings":";;;;AAgCO,MAAM,kCACXA,qCAAA,CAAsD;AAAA,EACpD,EAAA,EAAI;AACN,CAAC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserializeDirectoryContents.cjs.js","sources":["../../src/files/deserializeDirectoryContents.ts"],"sourcesContent":["/*\n * Copyright 2022 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 */\n\nimport fs from 'fs-extra';\nimport { dirname } from 'node:path';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { SerializedFile } from './types';\n\n/**\n * Deserializes a list of serialized files into the target directory.\n *\n * This method uses `resolveSafeChildPath` to make sure that files are\n * not written outside of the target directory.\n *\n * @public\n */\nexport async function deserializeDirectoryContents(\n targetPath: string,\n files: SerializedFile[],\n): Promise<void> {\n for (const file of files) {\n const filePath = resolveSafeChildPath(targetPath, file.path);\n await fs.ensureDir(dirname(filePath));\n await fs.writeFile(filePath, file.content); // Ignore file mode\n }\n}\n"],"names":["resolveSafeChildPath","fs","dirname"],"mappings":";;;;;;;;;;AA6BA,eAAsB,4BAAA,CACpB,YACA,KAAA,EACe;AACf,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,QAAA,GAAWA,qCAAA,CAAqB,UAAA,EAAY,IAAA,CAAK,IAAI,CAAA;AAC3D,IAAA,MAAMC,mBAAA,CAAG,SAAA,CAAUC,YAAA,CAAQ,QAAQ,CAAC,CAAA;AACpC,IAAA,MAAMD,mBAAA,CAAG,SAAA,CAAU,QAAA,EAAU,IAAA,CAAK,OAAO,CAAA;AAAA,EAC3C;AACF
|
|
1
|
+
{"version":3,"file":"deserializeDirectoryContents.cjs.js","sources":["../../src/files/deserializeDirectoryContents.ts"],"sourcesContent":["/*\n * Copyright 2022 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 */\n\nimport fs from 'fs-extra';\nimport { dirname } from 'node:path';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { SerializedFile } from './types';\n\n/**\n * Deserializes a list of serialized files into the target directory.\n *\n * This method uses `resolveSafeChildPath` to make sure that files are\n * not written outside of the target directory.\n *\n * @public\n */\nexport async function deserializeDirectoryContents(\n targetPath: string,\n files: SerializedFile[],\n): Promise<void> {\n for (const file of files) {\n const filePath = resolveSafeChildPath(targetPath, file.path);\n await fs.ensureDir(dirname(filePath));\n await fs.writeFile(filePath, file.content); // Ignore file mode\n }\n}\n"],"names":["resolveSafeChildPath","fs","dirname"],"mappings":";;;;;;;;;;AA6BA,eAAsB,4BAAA,CACpB,YACA,KAAA,EACe;AACf,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,QAAA,GAAWA,qCAAA,CAAqB,UAAA,EAAY,IAAA,CAAK,IAAI,CAAA;AAC3D,IAAA,MAAMC,mBAAA,CAAG,SAAA,CAAUC,YAAA,CAAQ,QAAQ,CAAC,CAAA;AACpC,IAAA,MAAMD,mBAAA,CAAG,SAAA,CAAU,QAAA,EAAU,IAAA,CAAK,OAAO,CAAA;AAAA,EAC3C;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializeDirectoryContents.cjs.js","sources":["../../src/files/serializeDirectoryContents.ts"],"sourcesContent":["/*\n * Copyright 2022 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 */\n\nimport { promises as fs } from 'node:fs';\nimport globby from 'globby';\nimport limiterFactory from 'p-limit';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { SerializedFile } from './types';\nimport { isError } from '@backstage/errors';\n\nconst DEFAULT_GLOB_PATTERNS = ['./**', '!.git'];\n\nexport const isExecutable = (fileMode: number | undefined) => {\n if (!fileMode) {\n return false;\n }\n\n const executeBitMask = 0o000111;\n const res = fileMode & executeBitMask;\n return res > 0;\n};\n\nasync function asyncFilter<T>(\n array: T[],\n callback: (value: T, index: number, array: T[]) => Promise<boolean>,\n): Promise<T[]> {\n const filterMap = await Promise.all(array.map(callback));\n return array.filter((_value, index) => filterMap[index]);\n}\n\n/**\n * @public\n */\nexport async function serializeDirectoryContents(\n sourcePath: string,\n options?: {\n gitignore?: boolean;\n globPatterns?: string[];\n },\n): Promise<SerializedFile[]> {\n const paths = await globby(options?.globPatterns ?? DEFAULT_GLOB_PATTERNS, {\n cwd: sourcePath,\n dot: true,\n gitignore: options?.gitignore,\n followSymbolicLinks: false,\n // In order to pick up 'broken' symlinks, we oxymoronically request files AND folders yet we filter out folders\n // This is because broken symlinks aren't classed as files so we need to glob everything\n onlyFiles: false,\n objectMode: true,\n stats: true,\n });\n\n const limiter = limiterFactory(10);\n\n const valid = await asyncFilter(paths, async ({ dirent, path }) => {\n if (dirent.isDirectory()) return false;\n if (!dirent.isSymbolicLink()) return true;\n\n const safePath = resolveSafeChildPath(sourcePath, path);\n\n // we only want files that don't exist\n try {\n await fs.stat(safePath);\n return false;\n } catch (e) {\n return isError(e) && e.code === 'ENOENT';\n }\n });\n\n return Promise.all(\n valid.map(async ({ dirent, path, stats }) => ({\n path,\n content: await limiter(async () => {\n const absFilePath = resolveSafeChildPath(sourcePath, path);\n if (dirent.isSymbolicLink()) {\n return fs.readlink(absFilePath, 'buffer');\n }\n return fs.readFile(absFilePath);\n }),\n executable: isExecutable(stats?.mode),\n symlink: dirent.isSymbolicLink(),\n })),\n );\n}\n"],"names":["globby","limiterFactory","resolveSafeChildPath","fs","isError"],"mappings":";;;;;;;;;;;;;AAuBA,MAAM,qBAAA,GAAwB,CAAC,MAAA,EAAQ,OAAO,CAAA;AAEvC,MAAM,YAAA,GAAe,CAAC,QAAA,KAAiC;AAC5D,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,cAAA,GAAiB,EAAA;AACvB,EAAA,MAAM,MAAM,QAAA,GAAW,cAAA;A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OAAO,OAAA,CAAQ,GAAA;AAAA,IACb,MAAM,GAAA,CAAI,OAAO,EAAE,MAAA,EAAQ,IAAA,EAAM,OAAM,MAAO;AAAA,MAC5C,IAAA;AAAA,MACA,OAAA,EAAS,MAAM,OAAA,CAAQ,YAAY;AACjC,QAAA,MAAM,WAAA,GAAcF,qCAAA,CAAqB,UAAA,EAAY,IAAI,CAAA;AACzD,QAAA,IAAI,MAAA,CAAO,gBAAe,EAAG;AAC3B,UAAA,OAAOC,gBAAA,CAAG,QAAA,CAAS,WAAA,EAAa,QAAQ,CAAA;AAAA,QAC1C;AACA,QAAA,OAAOA,gBAAA,CAAG,SAAS,WAAW,CAAA;AAAA,MAChC,CAAC,CAAA;AAAA,MACD,UAAA,EAAY,YAAA,CAAa,KAAA,EAAO,IAAI,CAAA;AAAA,MACpC,OAAA,EAAS,OAAO,cAAA;AAAe,KACjC,CAAE;AAAA,GACJ;AACF
|
|
1
|
+
{"version":3,"file":"serializeDirectoryContents.cjs.js","sources":["../../src/files/serializeDirectoryContents.ts"],"sourcesContent":["/*\n * Copyright 2022 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 */\n\nimport { promises as fs } from 'node:fs';\nimport globby from 'globby';\nimport limiterFactory from 'p-limit';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { SerializedFile } from './types';\nimport { isError } from '@backstage/errors';\n\nconst DEFAULT_GLOB_PATTERNS = ['./**', '!.git'];\n\nexport const isExecutable = (fileMode: number | undefined) => {\n if (!fileMode) {\n return false;\n }\n\n const executeBitMask = 0o000111;\n const res = fileMode & executeBitMask;\n return res > 0;\n};\n\nasync function asyncFilter<T>(\n array: T[],\n callback: (value: T, index: number, array: T[]) => Promise<boolean>,\n): Promise<T[]> {\n const filterMap = await Promise.all(array.map(callback));\n return array.filter((_value, index) => filterMap[index]);\n}\n\n/**\n * @public\n */\nexport async function serializeDirectoryContents(\n sourcePath: string,\n options?: {\n gitignore?: boolean;\n globPatterns?: string[];\n },\n): Promise<SerializedFile[]> {\n const paths = await globby(options?.globPatterns ?? DEFAULT_GLOB_PATTERNS, {\n cwd: sourcePath,\n dot: true,\n gitignore: options?.gitignore,\n followSymbolicLinks: false,\n // In order to pick up 'broken' symlinks, we oxymoronically request files AND folders yet we filter out folders\n // This is because broken symlinks aren't classed as files so we need to glob everything\n onlyFiles: false,\n objectMode: true,\n stats: true,\n });\n\n const limiter = limiterFactory(10);\n\n const valid = await asyncFilter(paths, async ({ dirent, path }) => {\n if (dirent.isDirectory()) return false;\n if (!dirent.isSymbolicLink()) return true;\n\n const safePath = resolveSafeChildPath(sourcePath, path);\n\n // we only want files that don't exist\n try {\n await fs.stat(safePath);\n return false;\n } catch (e) {\n return isError(e) && e.code === 'ENOENT';\n }\n });\n\n return Promise.all(\n valid.map(async ({ dirent, path, stats }) => ({\n path,\n content: await limiter(async () => {\n const absFilePath = resolveSafeChildPath(sourcePath, path);\n if (dirent.isSymbolicLink()) {\n return fs.readlink(absFilePath, 'buffer');\n }\n return fs.readFile(absFilePath);\n }),\n executable: isExecutable(stats?.mode),\n symlink: dirent.isSymbolicLink(),\n })),\n );\n}\n"],"names":["globby","limiterFactory","resolveSafeChildPath","fs","isError"],"mappings":";;;;;;;;;;;;;AAuBA,MAAM,qBAAA,GAAwB,CAAC,MAAA,EAAQ,OAAO,CAAA;AAEvC,MAAM,YAAA,GAAe,CAAC,QAAA,KAAiC;AAC5D,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,cAAA,GAAiB,EAAA;AACvB,EAAA,MAAM,MAAM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AC,CAAA;AAED,EAAA,OAAO,OAAA,CAAQ,GAAA;AAAA,IACb,MAAM,GAAA,CAAI,OAAO,EAAE,MAAA,EAAQ,IAAA,EAAM,OAAM,MAAO;AAAA,MAC5C,IAAA;AAAA,MACA,OAAA,EAAS,MAAM,OAAA,CAAQ,YAAY;AACjC,QAAA,MAAM,WAAA,GAAcF,qCAAA,CAAqB,UAAA,EAAY,IAAI,CAAA;AACzD,QAAA,IAAI,MAAA,CAAO,gBAAe,EAAG;AAC3B,UAAA,OAAOC,gBAAA,CAAG,QAAA,CAAS,WAAA,EAAa,QAAQ,CAAA;AAAA,QAC1C;AACA,QAAA,OAAOA,gBAAA,CAAG,SAAS,WAAW,CAAA;AAAA,MAChC,CAAC,CAAA;AAAA,MACD,UAAA,EAAY,YAAA,CAAa,KAAA,EAAO,IAAI,CAAA;AAAA,MACpC,OAAA,EAAS,OAAO,cAAA;AAAe,KACjC,CAAE;AAAA,GACJ;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffolderService.cjs.js","sources":["../src/scaffolderService.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\n\nimport {\n AuthService,\n BackstageCredentials,\n coreServices,\n createServiceFactory,\n createServiceRef,\n DiscoveryService,\n} from '@backstage/backend-plugin-api';\nimport { ResponseError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ListActionsResponse,\n ListTemplatingExtensionsResponse,\n LogEvent,\n ScaffolderClient,\n ScaffolderDryRunOptions,\n ScaffolderDryRunResponse,\n ScaffolderRequestOptions,\n ScaffolderScaffoldOptions,\n ScaffolderScaffoldResponse,\n ScaffolderTask,\n ScaffolderTaskStatus,\n} from '@backstage/plugin-scaffolder-common';\nimport type { TemplateParameterSchema } from '@backstage/plugin-scaffolder-common';\n\n/**\n * @public\n */\nexport interface ScaffolderServiceRequestOptions {\n credentials: BackstageCredentials;\n}\n\n/**\n * A backend service interface for the scaffolder that uses\n * {@link @backstage/backend-plugin-api#BackstageCredentials} instead of tokens.\n *\n * @public\n */\nexport interface ScaffolderService {\n getTemplateParameterSchema(\n request: { templateRef: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<TemplateParameterSchema>;\n\n scaffold(\n request: ScaffolderScaffoldOptions,\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderScaffoldResponse>;\n\n getTask(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderTask>;\n\n cancelTask(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ status?: ScaffolderTaskStatus }>;\n\n retry(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ id: string }>;\n\n listTasks(\n request: {\n createdBy?: string;\n limit?: number;\n offset?: number;\n status?: ScaffolderTaskStatus | ScaffolderTaskStatus[];\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ items: ScaffolderTask[]; totalItems: number }>;\n\n listActions(\n request?: {},\n options?: ScaffolderServiceRequestOptions,\n ): Promise<ListActionsResponse>;\n\n listTemplatingExtensions(\n request?: {},\n options?: ScaffolderServiceRequestOptions,\n ): Promise<ListTemplatingExtensionsResponse>;\n\n getLogs(\n request: {\n taskId: string;\n after?: number;\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<LogEvent[]>;\n\n dryRun(\n request: ScaffolderDryRunOptions,\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderDryRunResponse>;\n\n autocomplete(\n request: {\n token: string;\n provider: string;\n resource: string;\n context: Record<string, string>;\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ results: { title?: string; id: string }[] }>;\n}\n\nclass DefaultScaffolderService implements ScaffolderService {\n readonly #auth: AuthService;\n readonly #client: ScaffolderClient;\n readonly #discovery: DiscoveryService;\n\n constructor(options: {\n auth: AuthService;\n client: ScaffolderClient;\n discovery: DiscoveryService;\n }) {\n this.#auth = options.auth;\n this.#client = options.client;\n this.#discovery = options.discovery;\n }\n\n async getTemplateParameterSchema(\n request: { templateRef: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<TemplateParameterSchema> {\n return this.#client.getTemplateParameterSchema(\n request.templateRef,\n await this.#getOptions(options),\n );\n }\n\n async scaffold(\n request: ScaffolderScaffoldOptions,\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderScaffoldResponse> {\n return this.#client.scaffold(request, await this.#getOptions(options));\n }\n\n async getTask(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderTask> {\n return this.#client.getTask(\n request.taskId,\n await this.#getOptions(options),\n );\n }\n\n async cancelTask(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ status?: ScaffolderTaskStatus }> {\n return this.#client.cancelTask(\n request.taskId,\n await this.#getOptions(options),\n );\n }\n\n async retry(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ id: string }> {\n return this.#client.retry(request.taskId, await this.#getOptions(options));\n }\n\n async listTasks(\n request: {\n createdBy?: string;\n limit?: number;\n offset?: number;\n status?: ScaffolderTaskStatus | ScaffolderTaskStatus[];\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ items: ScaffolderTask[]; totalItems: number }> {\n const { token } = await this.#getOptions(options);\n const baseUrl = await this.#discovery.getBaseUrl('scaffolder');\n\n const params = new URLSearchParams();\n if (request.createdBy) {\n params.set('createdBy', request.createdBy);\n }\n if (request.limit !== undefined) {\n params.set('limit', String(request.limit));\n }\n if (request.offset !== undefined) {\n params.set('offset', String(request.offset));\n }\n if (request.status !== undefined) {\n for (const s of [request.status].flat()) {\n params.append('status', s);\n }\n }\n\n const query = params.toString();\n const url = `${baseUrl}/v2/tasks${query ? `?${query}` : ''}`;\n\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(token && { Authorization: `Bearer ${token}` }),\n },\n });\n\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n const body = await response.json();\n return {\n items: body.tasks,\n totalItems: body.totalTasks ?? 0,\n };\n }\n\n async listActions(\n _request?: {},\n options?: ScaffolderServiceRequestOptions,\n ): Promise<ListActionsResponse> {\n return this.#client.listActions(\n options ? await this.#getOptions(options) : {},\n );\n }\n\n async listTemplatingExtensions(\n _request?: {},\n options?: ScaffolderServiceRequestOptions,\n ): Promise<ListTemplatingExtensionsResponse> {\n return this.#client.listTemplatingExtensions(\n options ? await this.#getOptions(options) : {},\n );\n }\n\n async getLogs(\n request: {\n taskId: string;\n after?: number;\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<LogEvent[]> {\n const { token } = await this.#getOptions(options);\n const baseUrl = await this.#discovery.getBaseUrl('scaffolder');\n\n const params = new URLSearchParams();\n if (request.after !== undefined) {\n params.set('after', String(request.after));\n }\n\n const query = params.toString();\n const taskId = encodeURIComponent(request.taskId);\n const url = `${baseUrl}/v2/tasks/${taskId}/events${\n query ? `?${query}` : ''\n }`;\n\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(token && { Authorization: `Bearer ${token}` }),\n },\n });\n\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return response.json();\n }\n\n async dryRun(\n request: ScaffolderDryRunOptions,\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderDryRunResponse> {\n return this.#client.dryRun(request, await this.#getOptions(options));\n }\n\n async autocomplete(\n request: {\n token: string;\n provider: string;\n resource: string;\n context: Record<string, string>;\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ results: { title?: string; id: string }[] }> {\n return this.#client.autocomplete(request, await this.#getOptions(options));\n }\n\n async #getOptions(\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderRequestOptions> {\n return this.#auth.getPluginRequestToken({\n onBehalfOf: options.credentials,\n targetPluginId: 'scaffolder',\n });\n }\n}\n\n/**\n * A service ref for the scaffolder client, to be used by backend plugins\n * and modules that need to interact with the scaffolder API.\n *\n * @public\n */\nexport const scaffolderServiceRef = createServiceRef<ScaffolderService>({\n id: 'scaffolder-client',\n defaultFactory: async service =>\n createServiceFactory({\n service,\n deps: {\n auth: coreServices.auth,\n discovery: coreServices.discovery,\n config: coreServices.rootConfig,\n },\n async factory({ auth, discovery, config }) {\n const integrations = ScmIntegrations.fromConfig(config);\n const client = new ScaffolderClient({\n discoveryApi: discovery,\n fetchApi: { fetch },\n scmIntegrationsApi: integrations,\n });\n return new DefaultScaffolderService({\n auth,\n client,\n discovery,\n });\n },\n }),\n});\n"],"names":["ResponseError","createServiceRef","createServiceFactory","coreServices","ScmIntegrations","ScaffolderClient"],"mappings":";;;;;;;AA4HA,MAAM,wBAAA,CAAsD;AAAA,EACjD,KAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EAET,YAAY,OAAA,EAIT;AACD,IAAA,IAAA,CAAK,QAAQ,OAAA,CAAQ,IAAA;AACrB,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,MAAA;AACvB,IAAA,IAAA,CAAK,aAAa,OAAA,CAAQ,SAAA;AAAA,EAC5B;AAAA,EAEA,MAAM,0BAAA,CACJ,OAAA,EACA,OAAA,EACkC;AAClC,IAAA,OAAO,KAAK,OAAA,CAAQ,0BAAA;AAAA,MAClB,OAAA,CAAQ,WAAA;AAAA,MACR,MAAM,IAAA,CAAK,WAAA,CAAY,OAAO;AAAA,KAChC;AAAA,EACF;AAAA,EAEA,MAAM,QAAA,CACJ,OAAA,EACA,OAAA,EACqC;AACrC,IAAA,OAAO,IAAA,CAAK,QAAQ,QAAA,CAAS,OAAA,EAA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L,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"scaffolderService.cjs.js","sources":["../src/scaffolderService.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\n\nimport {\n AuthService,\n BackstageCredentials,\n coreServices,\n createServiceFactory,\n createServiceRef,\n DiscoveryService,\n} from '@backstage/backend-plugin-api';\nimport { ResponseError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ListActionsResponse,\n ListTemplatingExtensionsResponse,\n LogEvent,\n ScaffolderClient,\n ScaffolderDryRunOptions,\n ScaffolderDryRunResponse,\n ScaffolderRequestOptions,\n ScaffolderScaffoldOptions,\n ScaffolderScaffoldResponse,\n ScaffolderTask,\n ScaffolderTaskStatus,\n} from '@backstage/plugin-scaffolder-common';\nimport type { TemplateParameterSchema } from '@backstage/plugin-scaffolder-common';\n\n/**\n * @public\n */\nexport interface ScaffolderServiceRequestOptions {\n credentials: BackstageCredentials;\n}\n\n/**\n * A backend service interface for the scaffolder that uses\n * {@link @backstage/backend-plugin-api#BackstageCredentials} instead of tokens.\n *\n * @public\n */\nexport interface ScaffolderService {\n getTemplateParameterSchema(\n request: { templateRef: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<TemplateParameterSchema>;\n\n scaffold(\n request: ScaffolderScaffoldOptions,\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderScaffoldResponse>;\n\n getTask(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderTask>;\n\n cancelTask(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ status?: ScaffolderTaskStatus }>;\n\n retry(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ id: string }>;\n\n listTasks(\n request: {\n createdBy?: string;\n limit?: number;\n offset?: number;\n status?: ScaffolderTaskStatus | ScaffolderTaskStatus[];\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ items: ScaffolderTask[]; totalItems: number }>;\n\n listActions(\n request?: {},\n options?: ScaffolderServiceRequestOptions,\n ): Promise<ListActionsResponse>;\n\n listTemplatingExtensions(\n request?: {},\n options?: ScaffolderServiceRequestOptions,\n ): Promise<ListTemplatingExtensionsResponse>;\n\n getLogs(\n request: {\n taskId: string;\n after?: number;\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<LogEvent[]>;\n\n dryRun(\n request: ScaffolderDryRunOptions,\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderDryRunResponse>;\n\n autocomplete(\n request: {\n token: string;\n provider: string;\n resource: string;\n context: Record<string, string>;\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ results: { title?: string; id: string }[] }>;\n}\n\nclass DefaultScaffolderService implements ScaffolderService {\n readonly #auth: AuthService;\n readonly #client: ScaffolderClient;\n readonly #discovery: DiscoveryService;\n\n constructor(options: {\n auth: AuthService;\n client: ScaffolderClient;\n discovery: DiscoveryService;\n }) {\n this.#auth = options.auth;\n this.#client = options.client;\n this.#discovery = options.discovery;\n }\n\n async getTemplateParameterSchema(\n request: { templateRef: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<TemplateParameterSchema> {\n return this.#client.getTemplateParameterSchema(\n request.templateRef,\n await this.#getOptions(options),\n );\n }\n\n async scaffold(\n request: ScaffolderScaffoldOptions,\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderScaffoldResponse> {\n return this.#client.scaffold(request, await this.#getOptions(options));\n }\n\n async getTask(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderTask> {\n return this.#client.getTask(\n request.taskId,\n await this.#getOptions(options),\n );\n }\n\n async cancelTask(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ status?: ScaffolderTaskStatus }> {\n return this.#client.cancelTask(\n request.taskId,\n await this.#getOptions(options),\n );\n }\n\n async retry(\n request: { taskId: string },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ id: string }> {\n return this.#client.retry(request.taskId, await this.#getOptions(options));\n }\n\n async listTasks(\n request: {\n createdBy?: string;\n limit?: number;\n offset?: number;\n status?: ScaffolderTaskStatus | ScaffolderTaskStatus[];\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ items: ScaffolderTask[]; totalItems: number }> {\n const { token } = await this.#getOptions(options);\n const baseUrl = await this.#discovery.getBaseUrl('scaffolder');\n\n const params = new URLSearchParams();\n if (request.createdBy) {\n params.set('createdBy', request.createdBy);\n }\n if (request.limit !== undefined) {\n params.set('limit', String(request.limit));\n }\n if (request.offset !== undefined) {\n params.set('offset', String(request.offset));\n }\n if (request.status !== undefined) {\n for (const s of [request.status].flat()) {\n params.append('status', s);\n }\n }\n\n const query = params.toString();\n const url = `${baseUrl}/v2/tasks${query ? `?${query}` : ''}`;\n\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(token && { Authorization: `Bearer ${token}` }),\n },\n });\n\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n const body = await response.json();\n return {\n items: body.tasks,\n totalItems: body.totalTasks ?? 0,\n };\n }\n\n async listActions(\n _request?: {},\n options?: ScaffolderServiceRequestOptions,\n ): Promise<ListActionsResponse> {\n return this.#client.listActions(\n options ? await this.#getOptions(options) : {},\n );\n }\n\n async listTemplatingExtensions(\n _request?: {},\n options?: ScaffolderServiceRequestOptions,\n ): Promise<ListTemplatingExtensionsResponse> {\n return this.#client.listTemplatingExtensions(\n options ? await this.#getOptions(options) : {},\n );\n }\n\n async getLogs(\n request: {\n taskId: string;\n after?: number;\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<LogEvent[]> {\n const { token } = await this.#getOptions(options);\n const baseUrl = await this.#discovery.getBaseUrl('scaffolder');\n\n const params = new URLSearchParams();\n if (request.after !== undefined) {\n params.set('after', String(request.after));\n }\n\n const query = params.toString();\n const taskId = encodeURIComponent(request.taskId);\n const url = `${baseUrl}/v2/tasks/${taskId}/events${\n query ? `?${query}` : ''\n }`;\n\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(token && { Authorization: `Bearer ${token}` }),\n },\n });\n\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n return response.json();\n }\n\n async dryRun(\n request: ScaffolderDryRunOptions,\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderDryRunResponse> {\n return this.#client.dryRun(request, await this.#getOptions(options));\n }\n\n async autocomplete(\n request: {\n token: string;\n provider: string;\n resource: string;\n context: Record<string, string>;\n },\n options: ScaffolderServiceRequestOptions,\n ): Promise<{ results: { title?: string; id: string }[] }> {\n return this.#client.autocomplete(request, await this.#getOptions(options));\n }\n\n async #getOptions(\n options: ScaffolderServiceRequestOptions,\n ): Promise<ScaffolderRequestOptions> {\n return this.#auth.getPluginRequestToken({\n onBehalfOf: options.credentials,\n targetPluginId: 'scaffolder',\n });\n }\n}\n\n/**\n * A service ref for the scaffolder client, to be used by backend plugins\n * and modules that need to interact with the scaffolder API.\n *\n * @public\n */\nexport const scaffolderServiceRef = createServiceRef<ScaffolderService>({\n id: 'scaffolder-client',\n defaultFactory: async service =>\n createServiceFactory({\n service,\n deps: {\n auth: coreServices.auth,\n discovery: coreServices.discovery,\n config: coreServices.rootConfig,\n },\n async factory({ auth, discovery, config }) {\n const integrations = ScmIntegrations.fromConfig(config);\n const client = new ScaffolderClient({\n discoveryApi: discovery,\n fetchApi: { fetch },\n scmIntegrationsApi: integrations,\n });\n return new DefaultScaffolderService({\n auth,\n client,\n discovery,\n });\n },\n }),\n});\n"],"names":["ResponseError","createServiceRef","createServiceF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AAM,OAAA,KACpBC,qCAAA,CAAqB;AAAA,IACnB,OAAA;AAAA,IACA,IAAA,EAAM;AAAA,MACJ,MAAMC,6BAAA,CAAa,IAAA;AAAA,MACnB,WAAWA,6BAAA,CAAa,SAAA;AAAA,MACxB,QAAQA,6BAAA,CAAa;AAAA,KACvB;AAAA,IACA,MAAM,OAAA,CAAQ,EAAE,IAAA,EAAM,SAAA,EAAW,QAAO,EAAG;AACzC,MAAA,MAAM,YAAA,GAAeC,2BAAA,CAAgB,UAAA,CAAW,MAAM,CAAA;AACtD,MAAA,MAAM,MAAA,GAAS,IAAIC,uCAAA,CAAiB;AAAA,QAClC,YAAA,EAAc,SAAA;AAAA,QACd,QAAA,EAAU,EAAE,KAAA,EAAM;AAAA,QAClB,kBAAA,EAAoB;AAAA,OACrB,CAAA;AACD,MAAA,OAAO,IAAI,wBAAA,CAAyB;AAAA,QAClC,IAAA;AAAA,QACA,MAAA;AAAA,QACA;AAAA,OACD,CAAA;AAAA,IACH;AAAA,GACD;AACL,CAAC;;"}
|
package/dist/scm/git.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.cjs.js","sources":["../../src/scm/git.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport git, {\n AuthCallback,\n MergeResult,\n ProgressCallback,\n ReadCommitResult,\n} from 'isomorphic-git';\nimport http from 'isomorphic-git/http/node';\nimport fs from 'fs-extra';\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { isError } from '@backstage/errors';\n// @ts-ignore\nimport { pgp } from '@isomorphic-git/pgp-plugin';\n\nfunction isAuthCallbackOptions(\n options: StaticAuthOptions | AuthCallbackOptions,\n): options is AuthCallbackOptions {\n return 'onAuth' in options;\n}\n\n/**\n * Configure static credential for authentication\n *\n * @public\n */\nexport type StaticAuthOptions = {\n username?: string;\n password?: string;\n token?: string;\n logger?: LoggerService;\n};\n\n/**\n * Configure an authentication callback that can provide credentials on demand\n *\n * @public\n */\nexport type AuthCallbackOptions = {\n onAuth: AuthCallback;\n logger?: LoggerService;\n};\n\n/*\nprovider username password\nAzure 'notempty' token\nBitbucket Cloud 'x-token-auth' token\nBitbucket Server username password or token\nGitHub 'x-access-token' token\nGitLab 'oauth2' token\n\nFrom : https://isomorphic-git.org/docs/en/onAuth with fix for GitHub\n\nOr token provided as `token` for Bearer auth header\ninstead of Basic Auth (e.g., Bitbucket Server).\n*/\n\n/**\n * A convenience wrapper around the `isomorphic-git` library.\n *\n * @public\n */\n\nexport class Git {\n private readonly headers: {\n [x: string]: string;\n };\n\n private readonly config: {\n onAuth: AuthCallback;\n token?: string;\n logger?: LoggerService;\n };\n\n private constructor(config: {\n onAuth: AuthCallback;\n token?: string;\n logger?: LoggerService;\n }) {\n this.config = config;\n this.onAuth = config.onAuth;\n\n this.headers = {\n 'user-agent': 'git/@isomorphic-git',\n ...(config.token ? { Authorization: `Bearer ${config.token}` } : {}),\n };\n }\n\n async add(options: { dir: string; filepath: string }): Promise<void> {\n const { dir, filepath } = options;\n this.config.logger?.info(`Adding file {dir=${dir},filepath=${filepath}}`);\n\n return git.add({ fs, dir, filepath });\n }\n\n async addRemote(options: {\n dir: string;\n remote: string;\n url: string;\n force?: boolean;\n }): Promise<void> {\n const { dir, url, remote, force } = options;\n this.config.logger?.info(\n `Creating new remote {dir=${dir},remote=${remote},url=${url}}`,\n );\n return git.addRemote({ fs, dir, remote, url, force });\n }\n\n async deleteRemote(options: { dir: string; remote: string }): Promise<void> {\n const { dir, remote } = options;\n this.config.logger?.info(`Deleting remote {dir=${dir},remote=${remote}}`);\n return git.deleteRemote({ fs, dir, remote });\n }\n\n async checkout(options: { dir: string; ref: string }): Promise<void> {\n const { dir, ref } = options;\n this.config.logger?.info(`Checking out branch {dir=${dir},ref=${ref}}`);\n\n return git.checkout({ fs, dir, ref });\n }\n\n async branch(options: { dir: string; ref: string }): Promise<void> {\n const { dir, ref } = options;\n this.config.logger?.info(`Creating branch {dir=${dir},ref=${ref}`);\n\n return git.branch({ fs, dir, ref });\n }\n\n async commit(options: {\n dir: string;\n message: string;\n author: { name: string; email: string };\n committer: { name: string; email: string };\n signingKey?: string;\n }): Promise<string> {\n const { dir, message, author, committer, signingKey } = options;\n this.config.logger?.info(\n `Committing file to repo {dir=${dir},message=${message}}`,\n );\n return git.commit({\n fs,\n dir,\n message,\n author,\n committer,\n signingKey,\n onSign: signingKey ? pgp.sign : undefined,\n });\n }\n\n /** https://isomorphic-git.org/docs/en/clone */\n async clone(options: {\n url: string;\n dir: string;\n ref?: string;\n depth?: number;\n noCheckout?: boolean;\n }): Promise<void> {\n const { url, dir, ref, depth, noCheckout } = options;\n this.config.logger?.info(`Cloning repo {dir=${dir},url=${url}}`);\n\n try {\n return await git.clone({\n fs,\n http,\n url,\n dir,\n ref,\n singleBranch: true,\n depth: depth ?? 1,\n noCheckout,\n onProgress: this.onProgressHandler(),\n headers: this.headers,\n onAuth: this.onAuth,\n });\n } catch (ex) {\n this.config.logger?.error(`Failed to clone repo {dir=${dir},url=${url}}`);\n if (ex.data) {\n throw new Error(`${ex.message} {data=${JSON.stringify(ex.data)}}`);\n }\n throw ex;\n }\n }\n\n /** https://isomorphic-git.org/docs/en/currentBranch */\n async currentBranch(options: {\n dir: string;\n fullName?: boolean;\n }): Promise<string | undefined> {\n const { dir, fullName = false } = options;\n return git.currentBranch({ fs, dir, fullname: fullName }) as Promise<\n string | undefined\n >;\n }\n\n /** https://isomorphic-git.org/docs/en/fetch */\n async fetch(options: {\n dir: string;\n remote?: string;\n tags?: boolean;\n }): Promise<void> {\n const { dir, remote = 'origin', tags = false } = options;\n this.config.logger?.info(\n `Fetching remote=${remote} for repository {dir=${dir}}`,\n );\n\n try {\n await git.fetch({\n fs,\n http,\n dir,\n remote,\n tags,\n onProgress: this.onProgressHandler(),\n headers: this.headers,\n onAuth: this.onAuth,\n });\n } catch (ex) {\n this.config.logger?.error(\n `Failed to fetch repo {dir=${dir},remote=${remote}}`,\n );\n if (ex.data) {\n throw new Error(`${ex.message} {data=${JSON.stringify(ex.data)}}`);\n }\n throw ex;\n }\n }\n\n async init(options: { dir: string; defaultBranch?: string }): Promise<void> {\n const { dir, defaultBranch = 'master' } = options;\n this.config.logger?.info(`Init git repository {dir=${dir}}`);\n\n return git.init({\n fs,\n dir,\n defaultBranch,\n });\n }\n\n /** https://isomorphic-git.org/docs/en/merge */\n async merge(options: {\n dir: string;\n theirs: string;\n ours?: string;\n author: { name: string; email: string };\n committer: { name: string; email: string };\n signingKey?: string;\n }): Promise<MergeResult> {\n const { dir, theirs, ours, author, committer, signingKey } = options;\n this.config.logger?.info(\n `Merging branch '${theirs}' into '${ours}' for repository {dir=${dir}}`,\n );\n\n // If ours is undefined, current branch is used.\n return git.merge({\n fs,\n dir,\n ours,\n theirs,\n author,\n committer,\n signingKey,\n onSign: signingKey ? pgp.sign : undefined,\n });\n }\n\n async push(options: {\n dir: string;\n remote: string;\n remoteRef?: string;\n url?: string;\n force?: boolean;\n }) {\n const { dir, remote, url, remoteRef, force } = options;\n this.config.logger?.info(\n `Pushing directory to remote {dir=${dir},remote=${remote}}`,\n );\n try {\n return await this.retryOnTransientError({\n name: 'Git push',\n fn: () =>\n git.push({\n fs,\n dir,\n http,\n onProgress: this.onProgressHandler(),\n remoteRef,\n force,\n headers: this.headers,\n remote,\n url,\n onAuth: this.onAuth,\n corsProxy: '',\n }),\n });\n } catch (ex) {\n this.config.logger?.error(\n `Failed to push to repo {dir=${dir}, remote=${remote}}`,\n );\n if (isError(ex) && 'data' in ex) {\n let serializedData: string;\n try {\n serializedData = JSON.stringify(ex.data);\n } catch {\n serializedData = '[unserializable data]';\n }\n throw new Error(`${ex.message} {data=${serializedData}}`);\n }\n throw ex;\n }\n }\n\n /** https://isomorphic-git.org/docs/en/readCommit */\n async readCommit(options: {\n dir: string;\n sha: string;\n }): Promise<ReadCommitResult> {\n const { dir, sha } = options;\n return git.readCommit({ fs, dir, oid: sha });\n }\n\n /** https://isomorphic-git.org/docs/en/remove */\n async remove(options: { dir: string; filepath: string }): Promise<void> {\n const { dir, filepath } = options;\n this.config.logger?.info(\n `Removing file from git index {dir=${dir},filepath=${filepath}}`,\n );\n return git.remove({ fs, dir, filepath });\n }\n\n /** https://isomorphic-git.org/docs/en/resolveRef */\n async resolveRef(options: { dir: string; ref: string }): Promise<string> {\n const { dir, ref } = options;\n return git.resolveRef({ fs, dir, ref });\n }\n\n /** https://isomorphic-git.org/docs/en/log */\n async log(options: {\n dir: string;\n ref?: string;\n }): Promise<ReadCommitResult[]> {\n const { dir, ref } = options;\n return git.log({\n fs,\n dir,\n ref: ref ?? 'HEAD',\n });\n }\n\n private onAuth: AuthCallback;\n\n private static readonly nonTransientPatterns = [\n /auth/i,\n /permission/i,\n /forbidden/i,\n /401/,\n /403/,\n ];\n\n private async retryOnTransientError<T>(operation: {\n /** The name of the operation */\n name: string;\n /** The operation to be executed */\n fn: () => Promise<T>;\n }): Promise<T> {\n const maxRetries = 5;\n const baseDelayMs = 2000;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await operation.fn();\n } catch (ex) {\n const errorMsg = isError(ex) ? ex.message : String(ex);\n let errorData = '';\n if (isError(ex) && 'data' in ex) {\n try {\n errorData = JSON.stringify(ex.data);\n } catch {\n errorData = '[unserializable data]';\n }\n }\n const fullError = `${errorMsg} ${errorData}`;\n const isNonTransient = Git.nonTransientPatterns.some(p =>\n p.test(fullError),\n );\n\n if (isNonTransient || attempt >= maxRetries) {\n throw ex;\n }\n\n const delayMs = baseDelayMs * Math.pow(2, attempt);\n const jitterMs = Math.floor(\n Math.random() * Math.max(1, Math.floor(delayMs * 0.1)),\n );\n this.config.logger?.warn(\n `${operation.name} failed (attempt ${attempt + 1}/${\n maxRetries + 1\n }), retrying in ${delayMs + jitterMs}ms: ${errorMsg}`,\n );\n await new Promise(resolve => setTimeout(resolve, delayMs + jitterMs));\n }\n }\n\n throw new Error(\n `${operation.name} failed after ${maxRetries + 1} attempts`,\n );\n }\n\n private onProgressHandler = (): ProgressCallback => {\n let currentPhase = '';\n\n return event => {\n if (currentPhase !== event.phase) {\n currentPhase = event.phase;\n this.config.logger?.info(event.phase);\n }\n const total = event.total\n ? `${Math.round((event.loaded / event.total) * 100)}%`\n : event.loaded;\n this.config.logger?.debug(`status={${event.phase},total={${total}}}`);\n };\n };\n\n static fromAuth = (options: StaticAuthOptions | AuthCallbackOptions) => {\n if (isAuthCallbackOptions(options)) {\n const { onAuth, logger } = options;\n return new Git({ onAuth, logger });\n }\n\n const { username, password, token, logger } = options;\n return new Git({ onAuth: () => ({ username, password }), token, logger });\n };\n}\n"],"names":["git","fs","pgp","http","isError","logger"],"mappings":";;;;;;;;;;;;;;AA6BA,SAAS,sBACP,OAAA,EACgC;AAChC,EAAA,OAAO,QAAA,IAAY,OAAA;AACrB;AA4CO,MAAM,GAAA,CAAI;AAAA,EACE,OAAA;AAAA,EAIA,MAAA;AAAA,EAMT,YAAY,MAAA,EAIjB;AACD,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,SAAS,MAAA,CAAO,MAAA;AAErB,IAAA,IAAA,CAAK,OAAA,GAAU;AAAA,MACb,YAAA,EAAc,qBAAA;AAAA,MACd,GAAI,MAAA,CAAO,KAAA,GAAQ,EAAE,aAAA,EAAe,UAAU,MAAA,CAAO,KAAK,CAAA,CAAA,EAAG,GAAI;AAAC,KACpE;AAAA,EACF;AAAA,EAEA,MAAM,IAAI,OAAA,EAA2D;AACnE,IAAA,MAAM,EAAE,GAAA,EAAK,QAAA,EAAS,GAAI,OAAA;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AA,EAEA,OAAO,QAAA,GAAW,CAAC,OAAA,KAAqD;AACtE,IAAA,IAAI,qBAAA,CAAsB,OAAO,CAAA,EAAG;AAClC,MAAA,MAAM,EAAE,MAAA,EAAQ,MAAA,EAAAC,OAAAA,EAAO,GAAI,OAAA;AAC3B,MAAA,OAAO,IAAI,GAAA,CAAI,EAAE,MAAA,EAAQ,MAAA,EAAAA,SAAQ,CAAA;AAAA,IACnC;AAEA,IAAA,MAAM,EAAE,QAAA,EAAU,QAAA,EAAU,KAAA,EAAO,QAAO,GAAI,OAAA;AAC9C,IAAA,OAAO,IAAI,GAAA,CAAI,EAAE,MAAA,EAAQ,OAAO,EAAE,QAAA,EAAU,QAAA,EAAS,CAAA,EAAI,KAAA,EAAO,MAAA,EAAQ,CAAA;AAAA,EAC1E,CAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"git.cjs.js","sources":["../../src/scm/git.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport git, {\n AuthCallback,\n MergeResult,\n ProgressCallback,\n ReadCommitResult,\n} from 'isomorphic-git';\nimport http from 'isomorphic-git/http/node';\nimport fs from 'fs-extra';\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { isError } from '@backstage/errors';\n// @ts-ignore\nimport { pgp } from '@isomorphic-git/pgp-plugin';\n\nfunction isAuthCallbackOptions(\n options: StaticAuthOptions | AuthCallbackOptions,\n): options is AuthCallbackOptions {\n return 'onAuth' in options;\n}\n\n/**\n * Configure static credential for authentication\n *\n * @public\n */\nexport type StaticAuthOptions = {\n username?: string;\n password?: string;\n token?: string;\n logger?: LoggerService;\n};\n\n/**\n * Configure an authentication callback that can provide credentials on demand\n *\n * @public\n */\nexport type AuthCallbackOptions = {\n onAuth: AuthCallback;\n logger?: LoggerService;\n};\n\n/*\nprovider username password\nAzure 'notempty' token\nBitbucket Cloud 'x-token-auth' token\nBitbucket Server username password or token\nGitHub 'x-access-token' token\nGitLab 'oauth2' token\n\nFrom : https://isomorphic-git.org/docs/en/onAuth with fix for GitHub\n\nOr token provided as `token` for Bearer auth header\ninstead of Basic Auth (e.g., Bitbucket Server).\n*/\n\n/**\n * A convenience wrapper around the `isomorphic-git` library.\n *\n * @public\n */\n\nexport class Git {\n private readonly headers: {\n [x: string]: string;\n };\n\n private readonly config: {\n onAuth: AuthCallback;\n token?: string;\n logger?: LoggerService;\n };\n\n private constructor(config: {\n onAuth: AuthCallback;\n token?: string;\n logger?: LoggerService;\n }) {\n this.config = config;\n this.onAuth = config.onAuth;\n\n this.headers = {\n 'user-agent': 'git/@isomorphic-git',\n ...(config.token ? { Authorization: `Bearer ${config.token}` } : {}),\n };\n }\n\n async add(options: { dir: string; filepath: string }): Promise<void> {\n const { dir, filepath } = options;\n this.config.logger?.info(`Adding file {dir=${dir},filepath=${filepath}}`);\n\n return git.add({ fs, dir, filepath });\n }\n\n async addRemote(options: {\n dir: string;\n remote: string;\n url: string;\n force?: boolean;\n }): Promise<void> {\n const { dir, url, remote, force } = options;\n this.config.logger?.info(\n `Creating new remote {dir=${dir},remote=${remote},url=${url}}`,\n );\n return git.addRemote({ fs, dir, remote, url, force });\n }\n\n async deleteRemote(options: { dir: string; remote: string }): Promise<void> {\n const { dir, remote } = options;\n this.config.logger?.info(`Deleting remote {dir=${dir},remote=${remote}}`);\n return git.deleteRemote({ fs, dir, remote });\n }\n\n async checkout(options: { dir: string; ref: string }): Promise<void> {\n const { dir, ref } = options;\n this.config.logger?.info(`Checking out branch {dir=${dir},ref=${ref}}`);\n\n return git.checkout({ fs, dir, ref });\n }\n\n async branch(options: { dir: string; ref: string }): Promise<void> {\n const { dir, ref } = options;\n this.config.logger?.info(`Creating branch {dir=${dir},ref=${ref}`);\n\n return git.branch({ fs, dir, ref });\n }\n\n async commit(options: {\n dir: string;\n message: string;\n author: { name: string; email: string };\n committer: { name: string; email: string };\n signingKey?: string;\n }): Promise<string> {\n const { dir, message, author, committer, signingKey } = options;\n this.config.logger?.info(\n `Committing file to repo {dir=${dir},message=${message}}`,\n );\n return git.commit({\n fs,\n dir,\n message,\n author,\n committer,\n signingKey,\n onSign: signingKey ? pgp.sign : undefined,\n });\n }\n\n /** https://isomorphic-git.org/docs/en/clone */\n async clone(options: {\n url: string;\n dir: string;\n ref?: string;\n depth?: number;\n noCheckout?: boolean;\n }): Promise<void> {\n const { url, dir, ref, depth, noCheckout } = options;\n this.config.logger?.info(`Cloning repo {dir=${dir},url=${url}}`);\n\n try {\n return await git.clone({\n fs,\n http,\n url,\n dir,\n ref,\n singleBranch: true,\n depth: depth ?? 1,\n noCheckout,\n onProgress: this.onProgressHandler(),\n headers: this.headers,\n onAuth: this.onAuth,\n });\n } catch (ex) {\n this.config.logger?.error(`Failed to clone repo {dir=${dir},url=${url}}`);\n if (ex.data) {\n throw new Error(`${ex.message} {data=${JSON.stringify(ex.data)}}`);\n }\n throw ex;\n }\n }\n\n /** https://isomorphic-git.org/docs/en/currentBranch */\n async currentBranch(options: {\n dir: string;\n fullName?: boolean;\n }): Promise<string | undefined> {\n const { dir, fullName = false } = options;\n return git.currentBranch({ fs, dir, fullname: fullName }) as Promise<\n string | undefined\n >;\n }\n\n /** https://isomorphic-git.org/docs/en/fetch */\n async fetch(options: {\n dir: string;\n remote?: string;\n tags?: boolean;\n }): Promise<void> {\n const { dir, remote = 'origin', tags = false } = options;\n this.config.logger?.info(\n `Fetching remote=${remote} for repository {dir=${dir}}`,\n );\n\n try {\n await git.fetch({\n fs,\n http,\n dir,\n remote,\n tags,\n onProgress: this.onProgressHandler(),\n headers: this.headers,\n onAuth: this.onAuth,\n });\n } catch (ex) {\n this.config.logger?.error(\n `Failed to fetch repo {dir=${dir},remote=${remote}}`,\n );\n if (ex.data) {\n throw new Error(`${ex.message} {data=${JSON.stringify(ex.data)}}`);\n }\n throw ex;\n }\n }\n\n async init(options: { dir: string; defaultBranch?: string }): Promise<void> {\n const { dir, defaultBranch = 'master' } = options;\n this.config.logger?.info(`Init git repository {dir=${dir}}`);\n\n return git.init({\n fs,\n dir,\n defaultBranch,\n });\n }\n\n /** https://isomorphic-git.org/docs/en/merge */\n async merge(options: {\n dir: string;\n theirs: string;\n ours?: string;\n author: { name: string; email: string };\n committer: { name: string; email: string };\n signingKey?: string;\n }): Promise<MergeResult> {\n const { dir, theirs, ours, author, committer, signingKey } = options;\n this.config.logger?.info(\n `Merging branch '${theirs}' into '${ours}' for repository {dir=${dir}}`,\n );\n\n // If ours is undefined, current branch is used.\n return git.merge({\n fs,\n dir,\n ours,\n theirs,\n author,\n committer,\n signingKey,\n onSign: signingKey ? pgp.sign : undefined,\n });\n }\n\n async push(options: {\n dir: string;\n remote: string;\n remoteRef?: string;\n url?: string;\n force?: boolean;\n }) {\n const { dir, remote, url, remoteRef, force } = options;\n this.config.logger?.info(\n `Pushing directory to remote {dir=${dir},remote=${remote}}`,\n );\n try {\n return await this.retryOnTransientError({\n name: 'Git push',\n fn: () =>\n git.push({\n fs,\n dir,\n http,\n onProgress: this.onProgressHandler(),\n remoteRef,\n force,\n headers: this.headers,\n remote,\n url,\n onAuth: this.onAuth,\n corsProxy: '',\n }),\n });\n } catch (ex) {\n this.config.logger?.error(\n `Failed to push to repo {dir=${dir}, remote=${remote}}`,\n );\n if (isError(ex) && 'data' in ex) {\n let serializedData: string;\n try {\n serializedData = JSON.stringify(ex.data);\n } catch {\n serializedData = '[unserializable data]';\n }\n throw new Error(`${ex.message} {data=${serializedData}}`);\n }\n throw ex;\n }\n }\n\n /** https://isomorphic-git.org/docs/en/readCommit */\n async readCommit(options: {\n dir: string;\n sha: string;\n }): Promise<ReadCommitResult> {\n const { dir, sha } = options;\n return git.readCommit({ fs, dir, oid: sha });\n }\n\n /** https://isomorphic-git.org/docs/en/remove */\n async remove(options: { dir: string; filepath: string }): Promise<void> {\n const { dir, filepath } = options;\n this.config.logger?.info(\n `Removing file from git index {dir=${dir},filepath=${filepath}}`,\n );\n return git.remove({ fs, dir, filepath });\n }\n\n /** https://isomorphic-git.org/docs/en/resolveRef */\n async resolveRef(options: { dir: string; ref: string }): Promise<string> {\n const { dir, ref } = options;\n return git.resolveRef({ fs, dir, ref });\n }\n\n /** https://isomorphic-git.org/docs/en/log */\n async log(options: {\n dir: string;\n ref?: string;\n }): Promise<ReadCommitResult[]> {\n const { dir, ref } = options;\n return git.log({\n fs,\n dir,\n ref: ref ?? 'HEAD',\n });\n }\n\n private onAuth: AuthCallback;\n\n private static readonly nonTransientPatterns = [\n /auth/i,\n /permission/i,\n /forbidden/i,\n /401/,\n /403/,\n ];\n\n private async retryOnTransientError<T>(operation: {\n /** The name of the operation */\n name: string;\n /** The operation to be executed */\n fn: () => Promise<T>;\n }): Promise<T> {\n const maxRetries = 5;\n const baseDelayMs = 2000;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await operation.fn();\n } catch (ex) {\n const errorMsg = isError(ex) ? ex.message : String(ex);\n let errorData = '';\n if (isError(ex) && 'data' in ex) {\n try {\n errorData = JSON.stringify(ex.data);\n } catch {\n errorData = '[unserializable data]';\n }\n }\n const fullError = `${errorMsg} ${errorData}`;\n const isNonTransient = Git.nonTransientPatterns.some(p =>\n p.test(fullError),\n );\n\n if (isNonTransient || attempt >= maxRetries) {\n throw ex;\n }\n\n const delayMs = baseDelayMs * Math.pow(2, attempt);\n const jitterMs = Math.floor(\n Math.random() * Math.max(1, Math.floor(delayMs * 0.1)),\n );\n this.config.logger?.warn(\n `${operation.name} failed (attempt ${attempt + 1}/${\n maxRetries + 1\n }), retrying in ${delayMs + jitterMs}ms: ${errorMsg}`,\n );\n await new Promise(resolve => setTimeout(resolve, delayMs + jitterMs));\n }\n }\n\n throw new Error(\n `${operation.name} failed after ${maxRetries + 1} attempts`,\n );\n }\n\n private onProgressHandler = (): ProgressCallback => {\n let currentPhase = '';\n\n return event => {\n if (currentPhase !== event.phase) {\n currentPhase = event.phase;\n this.config.logger?.info(event.phase);\n }\n const total = event.total\n ? `${Math.round((event.loaded / event.total) * 100)}%`\n : event.loaded;\n this.config.logger?.debug(`status={${event.phase},total={${total}}}`);\n };\n };\n\n static fromAuth = (options: StaticAuthOptions | AuthCallbackOptions) => {\n if (isAuthCallbackOptions(options)) {\n const { onAuth, logger } = options;\n return new Git({ onAuth, logger });\n }\n\n const { username, password, token, logger } = options;\n return new Git({ onAuth: () => ({ username, password }), token, logger });\n };\n}\n"],"names":["git","fs","pgp","http","isError","logger"],"mappings":";;;;;;;;;;;;;;AA6BA,SAAS,sBACP,OAAA,EACgC;AAChC,EAAA,OAAO,QAAA,IAAY,OAAA;AACrB;AA4CO,MAAM,GAAA,CAAI;AAAA,EACE,OAAA;AAAA,EAIA,MAAA;AAAA,EAMT,YAAY,MAAA,EAIjB;AACD,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,SAAS,MAAA,CAAO,MAAA;AAErB,IAAA,IAAA,CAAK,OAAA,GAAU;AAAA,MACb,YAAA,EAAc,qBAAA;AAAA,MACd,GAAI,MAAA,CAAO,KAAA,GAAQ,EAAE,aAAA,EAAe,UAAU,MAAA,CAAO,KAAK,CAAA,CAAA,EAAG,GAAI;AAAC,KACpE;AAAA,EACF;AAAA,EAEA,MAAM,IAAI,OAAA,EAA2D;AACnE,IAAA,MAAM,EAAE,GAAA,EAAK,QAAA,EAAS,GAAI,OAAA;AAC1B,IAAA,IAAA,CAAK,OAAO,MAAA,EAAQ,IAAA,CAAK,oBAAoB,GAAG,CAAA,UAAA,EAAa,QAAQ,CAAA,CAAA,CAAG,CAAA;AAExE,IAAA,OAAOA,qBAAI,GAAA,CAAI,MAAEC,mBAAA,EAAI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B,MAAA,OAAO,IAAI,GAAA,CAAI,EAAE,MAAA,EAAQ,MAAA,EAAAA,SAAQ,CAAA;AAAA,IACnC;AAEA,IAAA,MAAM,EAAE,QAAA,EAAU,QAAA,EAAU,KAAA,EAAO,QAAO,GAAI,OAAA;AAC9C,IAAA,OAAO,IAAI,GAAA,CAAI,EAAE,MAAA,EAAQ,OAAO,EAAE,QAAA,EAAU,QAAA,EAAS,CAAA,EAAI,KAAA,EAAO,MAAA,EAAQ,CAAA;AAAA,EAC1E,CAAA;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.cjs.js","sources":["../../src/tasks/serializer.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport * as tar from 'tar';\nimport concatStream from 'concat-stream';\nimport { promisify } from 'node:util';\nimport { pipeline as pipelineCb, Readable } from 'node:stream';\n\nconst pipeline = promisify(pipelineCb);\n/**\n * Serializes provided path into tar archive\n *\n * @alpha\n */\nexport const serializeWorkspace = async (opts: {\n path: string;\n}): Promise<{ contents: Buffer }> => {\n return new Promise<{ contents: Buffer }>(async resolve => {\n await pipeline(\n tar.create({ cwd: opts.path }, ['']),\n concatStream(buffer => {\n return resolve({ contents: buffer });\n }),\n );\n });\n};\n\n/**\n * Rehydrates the provided buffer of tar archive into the provide destination path\n *\n * @alpha\n */\nexport const restoreWorkspace = async (opts: {\n path: string;\n buffer?: Buffer;\n}): Promise<void> => {\n const { buffer, path } = opts;\n if (buffer) {\n await pipeline(\n Readable.from(buffer),\n tar.extract({\n C: path,\n }),\n );\n }\n};\n"],"names":["promisify","pipelineCb","tar","concatStream","Readable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,QAAA,GAAWA,oBAAUC,oBAAU,CAAA;AAM9B,MAAM,kBAAA,GAAqB,OAAO,IAAA,KAEJ;AACnC,EAAA,OAAO,IAAI,OAAA,CAA8B,OAAM,OAAA,KAAW;AACxD,IAAA,MAAM,QAAA;AAAA,MACJC,cAAA,CAAI,OAAO,EAAE,GAAA,EAAK,KAAK,IAAA,EAAK,EAAG,CAAC,EAAE,CAAC,CAAA;AAAA,MACnCC,8BAAa,CAAA,MAAA,KAAU;AACrB,QAAA,OAAO,OAAA,CAAQ,EAAE,QAAA,EAAU,MAAA,EAAQ,CAAA;AAAA,MACrC,CAAC;AAAA,KACH;AAAA,EACF,CAAC,CAAA;AACH;AAOO,MAAM,gBAAA,GAAmB,OAAO,IAAA,KAGlB;AACnB,EAAA,MAAM,EAAE,MAAA,EAAQ,IAAA,EAAK,GAAI,IAAA;AACzB,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,MAAM,QAAA;AAAA,MACJC,oBAAA,CAAS,KAAK,MAAM,CAAA;AAAA,MACpBF,eAAI,OAAA,CAAQ;AAAA,QACV,CAAA,EAAG;AAAA,OACJ;AAAA,KACH;AAAA,EACF;AACF
|
|
1
|
+
{"version":3,"file":"serializer.cjs.js","sources":["../../src/tasks/serializer.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport * as tar from 'tar';\nimport concatStream from 'concat-stream';\nimport { promisify } from 'node:util';\nimport { pipeline as pipelineCb, Readable } from 'node:stream';\n\nconst pipeline = promisify(pipelineCb);\n/**\n * Serializes provided path into tar archive\n *\n * @alpha\n */\nexport const serializeWorkspace = async (opts: {\n path: string;\n}): Promise<{ contents: Buffer }> => {\n return new Promise<{ contents: Buffer }>(async resolve => {\n await pipeline(\n tar.create({ cwd: opts.path }, ['']),\n concatStream(buffer => {\n return resolve({ contents: buffer });\n }),\n );\n });\n};\n\n/**\n * Rehydrates the provided buffer of tar archive into the provide destination path\n *\n * @alpha\n */\nexport const restoreWorkspace = async (opts: {\n path: string;\n buffer?: Buffer;\n}): Promise<void> => {\n const { buffer, path } = opts;\n if (buffer) {\n await pipeline(\n Readable.from(buffer),\n tar.extract({\n C: path,\n }),\n );\n }\n};\n"],"names":["promisify","pipelineCb","tar","concatStream","Readable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,QAAA,GAAWA,oBAAUC,oBAAU,CAAA;AAM9B,MAAM,kBAAA,GAAqB,OAAO,IAAA,KAEJ;AACnC,EAAA,OAAO,IAAI,OAAA,CAA8B,OAAM,OAAA,KAAW;AACxD,IAAA,MAAM,QAAA;AAAA,MACJC,cAAA,CAAI,OAAO,EAAE,GAAA,EAAK,KAAK,IAAA,EAAK,EAAG,CAAC,EAAE,CAAC,CAAA;AAAA,MACnCC,8BAAa,CAAA,MAAA,KAAU;AACrB,QAAA,OAAO,OAAA,CAAQ,EAAE,QAAA,EAAU,MAAA,EAAQ,CAAA;AAAA,MACrC,CAAC;AAAA,KACH;AAAA,EACF,CAAC,CAAA;AACH;AAOO,MAAM,gBAAA,GAAmB,OAAO,IAAA,KAGlB;AACnB,EAAA,MAAM,EAAE,MAAA,EAAQ,IAAA,EAAK,GAAI,IAAA;AACzB,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,MAAM,QAAA;AAAA,MACJC,oBAAA,CAAS,KAAK,MAAM,CAAA;AAAA,MACpBF,eAAI,OAAA,CAAQ;AAAA,QACV,CAAA,EAAG;AAAA,OACJ;AAAA,KACH;AAAA,EACF;AACF;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffolderServiceMock.cjs.js","sources":["../../src/testUtils/scaffolderServiceMock.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\n\nimport { createServiceMock } from '@backstage/backend-test-utils';\nimport { scaffolderServiceRef, ScaffolderService } from '../scaffolderService';\n\n/**\n * A collection of mock functionality for the scaffolder service.\n *\n * @public\n */\nexport namespace scaffolderServiceMock {\n /**\n * Creates a scaffolder service whose methods are mock functions, possibly with\n * some of them overloaded by the caller.\n */\n export const mock = createServiceMock<ScaffolderService>(\n scaffolderServiceRef,\n () => ({\n getTemplateParameterSchema: jest.fn(),\n scaffold: jest.fn(),\n getTask: jest.fn(),\n cancelTask: jest.fn(),\n retry: jest.fn(),\n listTasks: jest.fn(),\n listActions: jest.fn(),\n listTemplatingExtensions: jest.fn(),\n getLogs: jest.fn(),\n dryRun: jest.fn(),\n autocomplete: jest.fn(),\n }),\n );\n}\n"],"names":["scaffolderServiceMock","createServiceMock","scaffolderServiceRef"],"mappings":";;;;;AAwBiBA;AAAA,CAAV,CAAUA,sBAAAA,KAAV;AAKE,EAAMA,uBAAA,IAAA,GAAOC,kCAAA;AAAA,IAClBC,sCAAA;AAAA,IACA,OAAO;AAAA,MACL,0BAAA,EAA4B,KAAK,EAAA,EAAG;AAAA,MACpC,QAAA,EAAU,KAAK,EAAA,EAAG;AAAA,MAClB,OAAA,EAAS,KAAK,EAAA,EAAG;AAAA,MACjB,UAAA,EAAY,KAAK,EAAA,EAAG;AAAA,MACpB,KAAA,EAAO,KAAK,EAAA,EAAG;AAAA,MACf,SAAA,EAAW,KAAK,EAAA,EAAG;AAAA,MACnB,WAAA,EAAa,KAAK,EAAA,EAAG;AAAA,MACrB,wBAAA,EAA0B,KAAK,EAAA,EAAG;AAAA,MAClC,OAAA,EAAS,KAAK,EAAA,EAAG;AAAA,MACjB,MAAA,EAAQ,KAAK,EAAA,EAAG;AAAA,MAChB,YAAA,EAAc,KAAK,EAAA;AAAG,KACxB;AAAA,GACF;AAAA,CAAA,EApBeF,6BAAA,KAAAA,6BAAA,GAAA,EAAA,CAAA,CAAA
|
|
1
|
+
{"version":3,"file":"scaffolderServiceMock.cjs.js","sources":["../../src/testUtils/scaffolderServiceMock.ts"],"sourcesContent":["/*\n * Copyright 2025 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 */\n\nimport { createServiceMock } from '@backstage/backend-test-utils';\nimport { scaffolderServiceRef, ScaffolderService } from '../scaffolderService';\n\n/**\n * A collection of mock functionality for the scaffolder service.\n *\n * @public\n */\nexport namespace scaffolderServiceMock {\n /**\n * Creates a scaffolder service whose methods are mock functions, possibly with\n * some of them overloaded by the caller.\n */\n export const mock = createServiceMock<ScaffolderService>(\n scaffolderServiceRef,\n () => ({\n getTemplateParameterSchema: jest.fn(),\n scaffold: jest.fn(),\n getTask: jest.fn(),\n cancelTask: jest.fn(),\n retry: jest.fn(),\n listTasks: jest.fn(),\n listActions: jest.fn(),\n listTemplatingExtensions: jest.fn(),\n getLogs: jest.fn(),\n dryRun: jest.fn(),\n autocomplete: jest.fn(),\n }),\n );\n}\n"],"names":["scaffolderServiceMock","createServiceMock","scaffolderServiceRef"],"mappings":";;;;;AAwBiBA;AAAA,CAAV,CAAUA,sBAAAA,KAAV;AAKE,EAAMA,uBAAA,IAAA,GAAOC,kCAAA;AAAA,IAClBC,sCAAA;AAAA,IACA,OAAO;AAAA,MACL,0BAAA,EAA4B,KAAK,EAAA,EAAG;AAAA,MACpC,QAAA,EAAU,KAAK,EAAA,EAAG;AAAA,MAClB,OAAA,EAAS,KAAK,EAAA,EAAG;AAAA,MACjB,UAAA,EAAY,KAAK,EAAA,EAAG;AAAA,MACpB,KAAA,EAAO,KAAK,EAAA,EAAG;AAAA,MACf,SAAA,EAAW,KAAK,EAAA,EAAG;AAAA,MACnB,WAAA,EAAa,KAAK,EAAA,EAAG;AAAA,MACrB,wBAAA,EAA0B,KAAK,EAAA,EAAG;AAAA,MAClC,OAAA,EAAS,KAAK,EAAA,EAAG;AAAA,MACjB,MAAA,EAAQ,KAAK,EAAA,EAAG;AAAA,MAChB,YAAA,EAAc,KAAK,EAAA;AAAG,KACxB;AAAA,GACF;AAAA,CAAA,EApBeF,6BAAA,KAAAA,6BAAA,GAAA,EAAA,CAAA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-scaffolder-node",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.8-next.0",
|
|
4
4
|
"description": "The plugin-scaffolder-node module for @backstage/plugin-scaffolder-backend",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library",
|
|
@@ -70,13 +70,13 @@
|
|
|
70
70
|
"test": "backstage-cli package test"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@backstage/backend-plugin-api": "1.10.
|
|
74
|
-
"@backstage/catalog-model": "1.10.0",
|
|
75
|
-
"@backstage/errors": "1.3.
|
|
76
|
-
"@backstage/integration": "2.1.
|
|
77
|
-
"@backstage/plugin-permission-common": "0.9.
|
|
78
|
-
"@backstage/plugin-permission-node": "0.11.
|
|
79
|
-
"@backstage/plugin-scaffolder-common": "2.3.
|
|
73
|
+
"@backstage/backend-plugin-api": "1.10.2-next.0",
|
|
74
|
+
"@backstage/catalog-model": "1.10.2-next.0",
|
|
75
|
+
"@backstage/errors": "1.3.2-next.0",
|
|
76
|
+
"@backstage/integration": "2.1.3-next.0",
|
|
77
|
+
"@backstage/plugin-permission-common": "0.9.12-next.0",
|
|
78
|
+
"@backstage/plugin-permission-node": "0.11.5-next.0",
|
|
79
|
+
"@backstage/plugin-scaffolder-common": "2.3.1-next.0",
|
|
80
80
|
"@backstage/types": "1.2.2",
|
|
81
81
|
"@isomorphic-git/pgp-plugin": "^0.0.7",
|
|
82
82
|
"concat-stream": "^2.0.0",
|
|
@@ -93,14 +93,14 @@
|
|
|
93
93
|
"zod-to-json-schema": "^3.25.1"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
|
-
"@backstage/backend-test-utils": "1.11.
|
|
97
|
-
"@backstage/cli": "0.36.
|
|
98
|
-
"@backstage/config": "1.3.
|
|
96
|
+
"@backstage/backend-test-utils": "1.11.8-next.0",
|
|
97
|
+
"@backstage/cli": "0.36.7-next.0",
|
|
98
|
+
"@backstage/config": "1.3.10-next.0",
|
|
99
99
|
"@types/lodash": "^4.14.151",
|
|
100
100
|
"msw": "^2.0.0"
|
|
101
101
|
},
|
|
102
102
|
"peerDependencies": {
|
|
103
|
-
"@backstage/backend-test-utils": "1.11.
|
|
103
|
+
"@backstage/backend-test-utils": "1.11.8-next.0"
|
|
104
104
|
},
|
|
105
105
|
"peerDependenciesMeta": {
|
|
106
106
|
"@backstage/backend-test-utils": {
|