@backstage/plugin-scaffolder-backend 4.0.3-next.1 → 4.0.3-next.2

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.
Files changed (25) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/ScaffolderPlugin.cjs.js +1 -1
  3. package/dist/scaffolder/actions/builtin/fetch/template.cjs.js +3 -1
  4. package/dist/scaffolder/actions/builtin/fetch/template.cjs.js.map +1 -1
  5. package/dist/scaffolder/actions/builtin/fetch/templateActionHandler.cjs.js +70 -68
  6. package/dist/scaffolder/actions/builtin/fetch/templateActionHandler.cjs.js.map +1 -1
  7. package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js +4 -1
  8. package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js.map +1 -1
  9. package/dist/scaffolder/actions/builtin/fetch/templateFileActionHandler.cjs.js +14 -30
  10. package/dist/scaffolder/actions/builtin/fetch/templateFileActionHandler.cjs.js.map +1 -1
  11. package/dist/scaffolder/dryrun/createDryRunner.cjs.js +6 -0
  12. package/dist/scaffolder/dryrun/createDryRunner.cjs.js.map +1 -1
  13. package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js +79 -95
  14. package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js.map +1 -1
  15. package/dist/scaffolder/tasks/TaskWorker.cjs.js +5 -2
  16. package/dist/scaffolder/tasks/TaskWorker.cjs.js.map +1 -1
  17. package/dist/service/router.cjs.js +1 -1
  18. package/dist/util/templating.cjs.js +12 -0
  19. package/dist/util/templating.cjs.js.map +1 -1
  20. package/package.json +9 -14
  21. package/assets/nunjucks.js.txt +0 -10385
  22. package/dist/lib/templating/SecureTemplater.cjs.js +0 -188
  23. package/dist/lib/templating/SecureTemplater.cjs.js.map +0 -1
  24. package/dist/lib/templating/helpers.cjs.js +0 -13
  25. package/dist/lib/templating/helpers.cjs.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
+ ## 4.0.3-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 943687f: Removed the native addon requirement from scaffolder template rendering. Templates now run through a TypeScript interpreter, and the backend no longer needs the `--no-node-snapshot` Node.js option.
8
+ - Updated dependencies
9
+ - @backstage/plugin-scaffolder-node@0.13.6-next.2
10
+ - @backstage/backend-plugin-api@1.10.0-next.1
11
+
3
12
  ## 4.0.3-next.1
4
13
 
5
14
  ### Patch Changes
@@ -28,9 +28,9 @@ require('@backstage/config');
28
28
  require('p-queue');
29
29
  require('./scaffolder/tasks/NunjucksWorkflowRunner.cjs.js');
30
30
  require('node:timers/promises');
31
+ var templating = require('./util/templating.cjs.js');
31
32
  var router = require('./service/router.cjs.js');
32
33
  var loggerToWinstonLogger = require('./util/loggerToWinstonLogger.cjs.js');
33
- var templating = require('./util/templating.cjs.js');
34
34
  var alpha$1 = require('@backstage/backend-plugin-api/alpha');
35
35
  var index = require('./actions/index.cjs.js');
36
36
 
@@ -6,6 +6,7 @@ var template_examples = require('./template.examples.cjs.js');
6
6
  var templateActionHandler = require('./templateActionHandler.cjs.js');
7
7
 
8
8
  function createFetchTemplateAction(options) {
9
+ const templateCapabilities = templateActionHandler.collectActionTemplateCapabilities(options);
9
10
  return pluginScaffolderNode.createTemplateAction({
10
11
  id: "fetch:template",
11
12
  description: "Downloads a skeleton, templates variables into file and directory names and content, and places the result in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.",
@@ -63,7 +64,8 @@ function createFetchTemplateAction(options) {
63
64
  });
64
65
  return templateDir;
65
66
  },
66
- ...options
67
+ ...options,
68
+ templateCapabilities
67
69
  })
68
70
  });
69
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"template.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/template.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 {\n resolveSafeChildPath,\n UrlReaderService,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n createTemplateAction,\n fetchContents,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './template.examples';\nimport { createTemplateActionHandler } from './templateActionHandler';\n\n/**\n * Downloads a skeleton, templates variables into file and directory names and content.\n * Then places the result in the workspace, or optionally in a subdirectory\n * specified by the 'targetPath' input option.\n *\n * @public\n */\nexport function createFetchTemplateAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n return createTemplateAction({\n id: 'fetch:template',\n description:\n 'Downloads a skeleton, templates variables into file and directory names and content, and places the result in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.',\n examples,\n schema: {\n input: {\n url: z =>\n z.string({\n description:\n 'Relative path or absolute URL pointing to the directory tree to fetch',\n }),\n targetPath: z =>\n z\n .string({\n description:\n 'Target path within the working directory to download the contents to. Defaults to the working directory root.',\n })\n .optional(),\n values: z =>\n z\n .record(z.any(), {\n description: 'Values to pass on to the templating engine',\n })\n .optional(),\n copyWithoutRender: z =>\n z\n .array(z.string(), {\n description:\n 'An array of glob patterns. Any files or directories which match are copied without being processed as templates.',\n })\n .optional(),\n copyWithoutTemplating: z =>\n z\n .array(z.string(), {\n description:\n 'An array of glob patterns. Contents of matched files or directories are copied without being processed, but paths are subject to rendering.',\n })\n .optional(),\n cookiecutterCompat: z =>\n z\n .boolean({\n description:\n 'Enable features to maximise compatibility with templates built for fetch:cookiecutter',\n })\n .optional(),\n templateFileExtension: z =>\n z\n .union([z.string(), z.boolean()], {\n description:\n 'If set, only files with the given extension will be templated. If set to `true`, the default extension `.njk` is used.',\n })\n .optional(),\n replace: z =>\n z\n .boolean({\n description:\n 'If set, replace files in targetPath instead of skipping existing ones.',\n })\n .optional(),\n trimBlocks: z =>\n z\n .boolean({\n description:\n 'If set, the first newline after a block is removed (block, not variable tag).',\n })\n .optional(),\n lstripBlocks: z =>\n z\n .boolean({\n description:\n 'If set, leading spaces and tabs are stripped from the start of a line to a block.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'An optional token to use for authentication when reading the resources.',\n })\n .optional(),\n },\n },\n supportsDryRun: true,\n handler: ctx =>\n createTemplateActionHandler({\n ctx,\n resolveTemplate: async () => {\n ctx.logger.info('Fetching template content from remote URL');\n\n const workDir = await ctx.createTemporaryDirectory();\n const templateDir = resolveSafeChildPath(workDir, 'template');\n\n await fetchContents({\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath: templateDir,\n token: ctx.input.token,\n ...options,\n });\n\n return templateDir;\n },\n ...options,\n }),\n });\n}\n"],"names":["createTemplateAction","examples","createTemplateActionHandler","resolveSafeChildPath","fetchContents"],"mappings":";;;;;;;AAqCO,SAAS,0BAA0B,OAAA,EAKvC;AACD,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,gBAAA;AAAA,IACJ,WAAA,EACE,0MAAA;AAAA,cACFC,0BAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,GAAA,EAAK,CAAA,CAAA,KACH,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CACG,MAAA,CAAO;AAAA,UACN,WAAA,EACE;AAAA,SACH,EACA,QAAA,EAAS;AAAA,QACd,QAAQ,CAAA,CAAA,KAC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AAAA,MACA,iBAAiB,YAAY;AAC3B,QAAA,GAAA,CAAI,MAAA,CAAO,KAAK,2CAA2C,CAAA;AAE3D,QAAA,MAAM,OAAA,GAAU,MAAM,GAAA,CAAI,wBAAA,EAAyB;AACnD,QAAA,MAAM,WAAA,GAAcC,qCAAA,CAAqB,OAAA,EAAS,UAAU,CAAA;AAE5D,QAAA,MAAMC,kCAAA,CAAc;AAAA,UAClB,OAAA,EAAS,IAAI,YAAA,EAAc,OAAA;AAAA,UAC3B,QAAA,EAAU,IAAI,KAAA,CAAM,GAAA;AAAA,UACpB,UAAA,EAAY,WAAA;AAAA,UACZ,KAAA,EAAO,IAAI,KAAA,CAAM,KAAA;AAAA,UACjB,GAAG;AAAA,SACJ,CAAA;AAED,QAAA,OAAO,WAAA;AAAA,MACT,CAAA;AAAA,MACA,GAAG;AAAA,KACJ;AAAA,GACJ,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"template.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/template.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 {\n resolveSafeChildPath,\n UrlReaderService,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n createTemplateAction,\n fetchContents,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './template.examples';\nimport {\n collectActionTemplateCapabilities,\n createTemplateActionHandler,\n} from './templateActionHandler';\n\n/**\n * Downloads a skeleton, templates variables into file and directory names and content.\n * Then places the result in the workspace, or optionally in a subdirectory\n * specified by the 'targetPath' input option.\n *\n * @public\n */\nexport function createFetchTemplateAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n const templateCapabilities = collectActionTemplateCapabilities(options);\n\n return createTemplateAction({\n id: 'fetch:template',\n description:\n 'Downloads a skeleton, templates variables into file and directory names and content, and places the result in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.',\n examples,\n schema: {\n input: {\n url: z =>\n z.string({\n description:\n 'Relative path or absolute URL pointing to the directory tree to fetch',\n }),\n targetPath: z =>\n z\n .string({\n description:\n 'Target path within the working directory to download the contents to. Defaults to the working directory root.',\n })\n .optional(),\n values: z =>\n z\n .record(z.any(), {\n description: 'Values to pass on to the templating engine',\n })\n .optional(),\n copyWithoutRender: z =>\n z\n .array(z.string(), {\n description:\n 'An array of glob patterns. Any files or directories which match are copied without being processed as templates.',\n })\n .optional(),\n copyWithoutTemplating: z =>\n z\n .array(z.string(), {\n description:\n 'An array of glob patterns. Contents of matched files or directories are copied without being processed, but paths are subject to rendering.',\n })\n .optional(),\n cookiecutterCompat: z =>\n z\n .boolean({\n description:\n 'Enable features to maximise compatibility with templates built for fetch:cookiecutter',\n })\n .optional(),\n templateFileExtension: z =>\n z\n .union([z.string(), z.boolean()], {\n description:\n 'If set, only files with the given extension will be templated. If set to `true`, the default extension `.njk` is used.',\n })\n .optional(),\n replace: z =>\n z\n .boolean({\n description:\n 'If set, replace files in targetPath instead of skipping existing ones.',\n })\n .optional(),\n trimBlocks: z =>\n z\n .boolean({\n description:\n 'If set, the first newline after a block is removed (block, not variable tag).',\n })\n .optional(),\n lstripBlocks: z =>\n z\n .boolean({\n description:\n 'If set, leading spaces and tabs are stripped from the start of a line to a block.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'An optional token to use for authentication when reading the resources.',\n })\n .optional(),\n },\n },\n supportsDryRun: true,\n handler: ctx =>\n createTemplateActionHandler({\n ctx,\n resolveTemplate: async () => {\n ctx.logger.info('Fetching template content from remote URL');\n\n const workDir = await ctx.createTemporaryDirectory();\n const templateDir = resolveSafeChildPath(workDir, 'template');\n\n await fetchContents({\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath: templateDir,\n token: ctx.input.token,\n ...options,\n });\n\n return templateDir;\n },\n ...options,\n templateCapabilities,\n }),\n });\n}\n"],"names":["collectActionTemplateCapabilities","createTemplateAction","examples","createTemplateActionHandler","resolveSafeChildPath","fetchContents"],"mappings":";;;;;;;AAwCO,SAAS,0BAA0B,OAAA,EAKvC;AACD,EAAA,MAAM,oBAAA,GAAuBA,wDAAkC,OAAO,CAAA;AAEtE,EAAA,OAAOC,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,gBAAA;AAAA,IACJ,WAAA,EACE,0MAAA;AAAA,cACFC,0BAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,GAAA,EAAK,CAAA,CAAA,KACH,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CACG,MAAA,CAAO;AAAA,UACN,WAAA,EACE;AAAA,SACH,EACA,QAAA,EAAS;AAAA,QACd,QAAQ,CAAA,CAAA,KACN,CAAA,CACG,MAAA,CAAO,CAAA,CAAE,KAAI,EAAG;AAAA,UACf,WAAA,EAAa;AAAA,SACd,EACA,QAAA,EAAS;AAAA,QACd,mBAAmB,CAAA,CAAA,KACjB,CAAA,CACG,KAAA,CAAM,CAAA,CAAE,QAAO,EAAG;AAAA,UACjB,WAAA,EACE;AAAA,SACH,EACA,QAAA,EAAS;AAAA,QACd,uBAAuB,CAAA,CAAA,KACrB,CAAA,CACG,KAAA,CAAM,CAAA,CAAE,QAAO,EAAG;AAAA,UACjB,WAAA,EACE;AAAA,SACH,EACA,QAAA,E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,EAAY,WAAA;AAAA,UACZ,KAAA,EAAO,IAAI,KAAA,CAAM,KAAA;AAAA,UACjB,GAAG;AAAA,SACJ,CAAA;AAED,QAAA,OAAO,WAAA;AAAA,MACT,CAAA;AAAA,MACA,GAAG,OAAA;AAAA,MACH;AAAA,KACD;AAAA,GACJ,CAAA;AACH;;;;"}
@@ -5,9 +5,9 @@ var errors = require('@backstage/errors');
5
5
  var fs = require('fs-extra');
6
6
  var globby = require('globby');
7
7
  var isbinaryfile = require('isbinaryfile');
8
+ var nunjitsu = require('nunjitsu');
8
9
  var createDefaultFilters = require('../../../../lib/templating/filters/createDefaultFilters.cjs.js');
9
10
  var templating = require('../../../../util/templating.cjs.js');
10
- var SecureTemplater = require('../../../../lib/templating/SecureTemplater.cjs.js');
11
11
  var path = require('node:path');
12
12
 
13
13
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
@@ -15,18 +15,20 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
15
15
  var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
16
16
  var globby__default = /*#__PURE__*/_interopDefaultCompat(globby);
17
17
 
18
+ function collectActionTemplateCapabilities(options) {
19
+ return templating.collectTemplateCapabilities({
20
+ filters: {
21
+ ...templating.convertFiltersToRecord(
22
+ createDefaultFilters.createDefaultFilters({ integrations: options.integrations })
23
+ ),
24
+ ...options.additionalTemplateFilters
25
+ },
26
+ globals: options.additionalTemplateGlobals
27
+ });
28
+ }
18
29
  async function createTemplateActionHandler(options) {
19
- const {
20
- resolveTemplate,
21
- integrations,
22
- additionalTemplateFilters,
23
- additionalTemplateGlobals: templateGlobals,
24
- ctx
25
- } = options;
26
- const templateFilters = {
27
- ...templating.convertFiltersToRecord(createDefaultFilters.createDefaultFilters({ integrations })),
28
- ...additionalTemplateFilters
29
- };
30
+ const { resolveTemplate, ctx } = options;
31
+ const templateCapabilities = options.templateCapabilities ?? collectActionTemplateCapabilities(options);
30
32
  const { outputDir, copyOnlyPatterns, renderFilename, extension } = resolveTemplateActionSettings(ctx);
31
33
  const templateDir = await resolveTemplate();
32
34
  if (backendPluginApi.isChildPath(templateDir, outputDir)) {
@@ -57,72 +59,71 @@ async function createTemplateActionHandler(options) {
57
59
  `Processing ${allEntriesInTemplate.length} template files/directories with input values`,
58
60
  ctx.input.values
59
61
  );
60
- const { render: renderTemplate, dispose } = await SecureTemplater.SecureTemplater.loadRenderer({
62
+ const templateRenderer = nunjitsu.createTemplateRenderer({
63
+ ...templateCapabilities,
64
+ allowRegexExecution: true,
61
65
  cookiecutterCompat: ctx.input.cookiecutterCompat,
62
- templateFilters,
63
- templateGlobals,
64
- nunjucksConfigs: {
65
- trimBlocks: ctx.input.trimBlocks,
66
- lstripBlocks: ctx.input.lstripBlocks
67
- }
66
+ trimBlocks: ctx.input.trimBlocks,
67
+ lstripBlocks: ctx.input.lstripBlocks
68
68
  });
69
- try {
70
- for (const location of allEntriesInTemplate) {
71
- let renderContents;
72
- let localOutputPath = location;
73
- if (extension) {
74
- renderContents = path.extname(localOutputPath) === extension;
75
- if (renderContents) {
76
- localOutputPath = localOutputPath.slice(0, -extension.length);
77
- }
78
- localOutputPath = renderTemplate(localOutputPath, context);
79
- } else {
80
- renderContents = !nonTemplatedEntries.has(location);
81
- if (renderFilename) {
82
- localOutputPath = renderTemplate(localOutputPath, context);
83
- }
84
- }
85
- if (containsSkippedContent(localOutputPath)) {
86
- continue;
69
+ const preparedContext = templateRenderer.prepareContext(context);
70
+ for (const location of allEntriesInTemplate) {
71
+ let renderContents;
72
+ let localOutputPath = location;
73
+ if (extension) {
74
+ renderContents = path.extname(localOutputPath) === extension;
75
+ if (renderContents) {
76
+ localOutputPath = localOutputPath.slice(0, -extension.length);
87
77
  }
88
- const outputPath = backendPluginApi.resolveSafeChildPath(outputDir, localOutputPath);
89
- if (fs__default.default.existsSync(outputPath) && !ctx.input.replace) {
90
- continue;
91
- }
92
- if (!renderContents && !extension) {
93
- ctx.logger.info(
94
- `Copying file/directory ${location} without processing.`
78
+ localOutputPath = templateRenderer.render(
79
+ localOutputPath,
80
+ preparedContext
81
+ );
82
+ } else {
83
+ renderContents = !nonTemplatedEntries.has(location);
84
+ if (renderFilename) {
85
+ localOutputPath = templateRenderer.render(
86
+ localOutputPath,
87
+ preparedContext
95
88
  );
89
+ } else {
90
+ localOutputPath = renderContents ? templateRenderer.render(localOutputPath, preparedContext) : localOutputPath;
96
91
  }
97
- if (location.endsWith("/")) {
92
+ }
93
+ if (containsSkippedContent(localOutputPath)) {
94
+ continue;
95
+ }
96
+ const outputPath = backendPluginApi.resolveSafeChildPath(outputDir, localOutputPath);
97
+ if (fs__default.default.existsSync(outputPath) && !ctx.input.replace) {
98
+ continue;
99
+ }
100
+ if (!renderContents && !extension) {
101
+ ctx.logger.info(`Copying file/directory ${location} without processing.`);
102
+ }
103
+ if (location.endsWith("/")) {
104
+ ctx.logger.info(`Writing directory ${location} to template output path.`);
105
+ await fs__default.default.ensureDir(outputPath);
106
+ } else {
107
+ const inputFilePath = backendPluginApi.resolveSafeChildPath(templateDir, location);
108
+ const stats = await fs__default.default.promises.lstat(inputFilePath);
109
+ if (stats.isSymbolicLink() || await isbinaryfile.isBinaryFile(inputFilePath)) {
98
110
  ctx.logger.info(
99
- `Writing directory ${location} to template output path.`
111
+ `Copying file binary or symbolic link at ${location}, to template output path.`
100
112
  );
101
- await fs__default.default.ensureDir(outputPath);
113
+ await fs__default.default.copy(inputFilePath, outputPath);
102
114
  } else {
103
- const inputFilePath = backendPluginApi.resolveSafeChildPath(templateDir, location);
104
- const stats = await fs__default.default.promises.lstat(inputFilePath);
105
- if (stats.isSymbolicLink() || await isbinaryfile.isBinaryFile(inputFilePath)) {
106
- ctx.logger.info(
107
- `Copying file binary or symbolic link at ${location}, to template output path.`
108
- );
109
- await fs__default.default.copy(inputFilePath, outputPath);
110
- } else {
111
- const statsObj = await fs__default.default.stat(inputFilePath);
112
- ctx.logger.info(
113
- `Writing file ${location} to template output path with mode ${statsObj.mode}.`
114
- );
115
- const inputFileContents = await fs__default.default.readFile(inputFilePath, "utf-8");
116
- await fs__default.default.outputFile(
117
- outputPath,
118
- renderContents ? renderTemplate(inputFileContents, context) : inputFileContents,
119
- { mode: statsObj.mode }
120
- );
121
- }
115
+ const statsObj = await fs__default.default.stat(inputFilePath);
116
+ ctx.logger.info(
117
+ `Writing file ${location} to template output path with mode ${statsObj.mode}.`
118
+ );
119
+ const inputFileContents = await fs__default.default.readFile(inputFilePath, "utf-8");
120
+ await fs__default.default.outputFile(
121
+ outputPath,
122
+ renderContents ? templateRenderer.render(inputFileContents, preparedContext) : inputFileContents,
123
+ { mode: statsObj.mode }
124
+ );
122
125
  }
123
126
  }
124
- } finally {
125
- dispose();
126
127
  }
127
128
  ctx.logger.info(`Template result written to ${outputDir}`);
128
129
  }
@@ -159,5 +160,6 @@ function containsSkippedContent(localOutputPath) {
159
160
  return localOutputPath === "" || localOutputPath.startsWith("/") || localOutputPath.includes("//");
160
161
  }
161
162
 
163
+ exports.collectActionTemplateCapabilities = collectActionTemplateCapabilities;
162
164
  exports.createTemplateActionHandler = createTemplateActionHandler;
163
165
  //# sourceMappingURL=templateActionHandler.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"templateActionHandler.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateActionHandler.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 {\n isChildPath,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ActionContext,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport globby from 'globby';\nimport { isBinaryFile } from 'isbinaryfile';\nimport { createDefaultFilters } from '../../../../lib/templating/filters/createDefaultFilters';\nimport { convertFiltersToRecord } from '../../../../util/templating';\nimport { SecureTemplater } from '../../../../lib/templating/SecureTemplater';\nimport { extname } from 'node:path';\n\nexport type TemplateActionInput = {\n targetPath?: string;\n values: any;\n templateFileExtension?: string | boolean;\n copyWithoutTemplating?: string[];\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n};\n\nexport async function createTemplateActionHandler<\n I extends TemplateActionInput,\n>(options: {\n ctx: ActionContext<I, any, any>;\n resolveTemplate: () => Promise<string>;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n const {\n resolveTemplate,\n integrations,\n additionalTemplateFilters,\n additionalTemplateGlobals: templateGlobals,\n ctx,\n } = options;\n\n const templateFilters = {\n ...convertFiltersToRecord(createDefaultFilters({ integrations })),\n ...additionalTemplateFilters,\n };\n\n const { outputDir, copyOnlyPatterns, renderFilename, extension } =\n resolveTemplateActionSettings(ctx);\n\n const templateDir = await resolveTemplate();\n\n if (isChildPath(templateDir, outputDir)) {\n throw new InputError('targetPath must not be within template path');\n }\n\n ctx.logger.info('Listing files and directories in template');\n const allEntriesInTemplate = await globby(`**/*`, {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n });\n\n const nonTemplatedEntries = new Set(\n await globby(copyOnlyPatterns || [], {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n }),\n );\n\n // Cookiecutter prefixes all parameters in templates with\n // `cookiecutter.`. To replicate this, we wrap our parameters\n // in an object with a `cookiecutter` property when compat\n // mode is enabled.\n const { cookiecutterCompat, values } = ctx.input;\n const context = {\n [cookiecutterCompat ? 'cookiecutter' : 'values']: values,\n };\n\n ctx.logger.info(\n `Processing ${allEntriesInTemplate.length} template files/directories with input values`,\n ctx.input.values,\n );\n\n const { render: renderTemplate, dispose } =\n await SecureTemplater.loadRenderer({\n cookiecutterCompat: ctx.input.cookiecutterCompat,\n templateFilters,\n templateGlobals,\n nunjucksConfigs: {\n trimBlocks: ctx.input.trimBlocks,\n lstripBlocks: ctx.input.lstripBlocks,\n },\n });\n try {\n for (const location of allEntriesInTemplate) {\n let renderContents: boolean;\n\n let localOutputPath = location;\n if (extension) {\n renderContents = extname(localOutputPath) === extension;\n if (renderContents) {\n localOutputPath = localOutputPath.slice(0, -extension.length);\n }\n // extension is mutual exclusive with copyWithoutRender/copyWithoutTemplating,\n // therefore the output path is always rendered.\n localOutputPath = renderTemplate(localOutputPath, context);\n } else {\n renderContents = !nonTemplatedEntries.has(location);\n // The logic here is a bit tangled because it depends on two variables.\n // If renderFilename is true, which means copyWithoutTemplating is used,\n // then the path is always rendered.\n // If renderFilename is false, which means copyWithoutRender is used,\n // then matched file/directory won't be processed, same as before.\n if (renderFilename) {\n localOutputPath = renderTemplate(localOutputPath, context);\n } else {\n localOutputPath = renderContents\n ? renderTemplate(localOutputPath, context)\n : localOutputPath;\n }\n }\n\n if (containsSkippedContent(localOutputPath)) {\n continue;\n }\n\n const outputPath = resolveSafeChildPath(outputDir, localOutputPath);\n if (fs.existsSync(outputPath) && !ctx.input.replace) {\n continue;\n }\n\n if (!renderContents && !extension) {\n ctx.logger.info(\n `Copying file/directory ${location} without processing.`,\n );\n }\n\n if (location.endsWith('/')) {\n ctx.logger.info(\n `Writing directory ${location} to template output path.`,\n );\n await fs.ensureDir(outputPath);\n } else {\n const inputFilePath = resolveSafeChildPath(templateDir, location);\n const stats = await fs.promises.lstat(inputFilePath);\n\n if (stats.isSymbolicLink() || (await isBinaryFile(inputFilePath))) {\n ctx.logger.info(\n `Copying file binary or symbolic link at ${location}, to template output path.`,\n );\n await fs.copy(inputFilePath, outputPath);\n } else {\n const statsObj = await fs.stat(inputFilePath);\n ctx.logger.info(\n `Writing file ${location} to template output path with mode ${statsObj.mode}.`,\n );\n const inputFileContents = await fs.readFile(inputFilePath, 'utf-8');\n await fs.outputFile(\n outputPath,\n renderContents\n ? renderTemplate(inputFileContents, context)\n : inputFileContents,\n { mode: statsObj.mode },\n );\n }\n }\n }\n } finally {\n dispose();\n }\n ctx.logger.info(`Template result written to ${outputDir}`);\n}\n\nfunction resolveTemplateActionSettings<I extends TemplateActionInput>(\n ctx: ActionContext<I, any, any>,\n): {\n outputDir: string;\n copyOnlyPatterns?: string[];\n renderFilename: boolean;\n extension: string | false;\n} {\n const targetPath = ctx.input.targetPath ?? './';\n const outputDir = resolveSafeChildPath(ctx.workspacePath, targetPath);\n\n const copyOnlyPatterns = ctx.input.copyWithoutTemplating;\n const renderFilename = true;\n\n if (copyOnlyPatterns && !Array.isArray(copyOnlyPatterns)) {\n throw new InputError(\n 'Fetch action input copyWithoutTemplating must be an Array',\n );\n }\n if (\n ctx.input.templateFileExtension &&\n (copyOnlyPatterns || ctx.input.cookiecutterCompat)\n ) {\n throw new InputError(\n 'Fetch action input extension incompatible with copyWithoutTemplating and cookiecutterCompat',\n );\n }\n let extension: string | false = false;\n if (ctx.input.templateFileExtension) {\n extension =\n ctx.input.templateFileExtension === true\n ? '.njk'\n : ctx.input.templateFileExtension;\n if (!extension.startsWith('.')) {\n extension = `.${extension}`;\n }\n }\n return {\n outputDir,\n copyOnlyPatterns,\n renderFilename,\n extension,\n };\n}\n\nfunction containsSkippedContent(localOutputPath: string): boolean {\n // if the path is empty means that there is a file skipped in the root\n // if the path starts with a separator it means that the root directory has been skipped\n // if the path includes // means that there is a subdirectory skipped\n // All paths returned are considered with / separator because of globby returning the linux separator for all os'.\n return (\n localOutputPath === '' ||\n localOutputPath.startsWith('/') ||\n localOutputPath.includes('//')\n );\n}\n"],"names":["convertFiltersToRecord","createDefaultFilters","isChildPath","InputError","globby","SecureTemplater","extname","resolveSafeChildPath","fs","isBinaryFile"],"mappings":";;;;;;;;;;;;;;;;;AA6CA,eAAsB,4BAEpB,OAAA,EAMC;AACD,EAAA,MAAM;AAAA,IACJ,eAAA;AAAA,IACA,YAAA;AAAA,IACA,yBAAA;AAAA,IACA,yBAAA,EAA2B,eAAA;AAAA,IAC3B;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,eAAA,GAAkB;AAAA,IACtB,GAAGA,iCAAA,CAAuBC,yCAAA,CAAqB,EAAE,YAAA,EAAc,CAAC,CAAA;AAAA,IAChE,GAAG;AAAA,GACL;AAEA,EAAA,MAAM,EAAE,SAAA,EAAW,gBAAA,EAAkB,gBAAgB,SAAA,EAAU,GAC7D,8BAA8B,GAAG,CAAA;AAEnC,EAAA,MAAM,WAAA,GAAc,MAAM,eAAA,EAAgB;AAE1C,EAAA,IAAIC,4BAAA,CAAY,WAAA,EAAa,SAAS,CAAA,EAAG;AACvC,IAAA,MAAM,IAAIC,kBAAW,6CAA6C,CAAA;AAAA,EACpE;AAEA,EAAA,GAAA,CAAI,MAAA,CAAO,KAAK,2CAA2C,CAAA;AAC3D,EAAA,MAAM,oBAAA,GAAuB,MAAMC,uBAAA,CAAO,CAAA,IAAA,CAAA,EAAQ;AAAA,IAChD,GAAA,EAAK,WAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,SAAA,EAAW,KAAA;AAAA,IACX,eAAA,EAAiB,IAAA;AAAA,IACjB,mBAAA,EAAqB;AAAA,GACtB,CAAA;AAED,EAAA,MAAM,sBAAsB,IAAI,GAAA;AAAA,IAC9B,MAAMA,uBAAA,CAAO,gBAAA,IAAoB,EAAC,EAAG;AAAA,MACnC,GAAA,EAAK,WAAA;AAAA,MACL,GAAA,EAAK,IAAA;AAAA,MACL,SAAA,EAAW,KAAA;AAAA,MACX,eAAA,EAAiB,IAAA;AAAA,MACjB,mBAAA,EAAqB;AA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B;AACnC,IAAA,SAAA,GACE,IAAI,KAAA,CAAM,qBAAA,KAA0B,IAAA,GAChC,MAAA,GACA,IAAI,KAAA,CAAM,qBAAA;AAChB,IAAA,IAAI,CAAC,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,EAAG;AAC9B,MAAA,SAAA,GAAY,IAAI,SAAS,CAAA,CAAA;AAAA,IAC3B;AAAA,EACF;AACA,EAAA,OAAO;AAAA,IACL,SAAA;AAAA,IACA,gBAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF;AACF;AAEA,SAAS,uBAAuB,eAAA,EAAkC;AAKhE,EAAA,OACE,eAAA,KAAoB,MACpB,eAAA,CAAgB,UAAA,CAAW,GAAG,CAAA,IAC9B,eAAA,CAAgB,SAAS,IAAI,CAAA;AAEjC;;;;"}
1
+ {"version":3,"file":"templateActionHandler.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateActionHandler.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 {\n isChildPath,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ActionContext,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport globby from 'globby';\nimport { isBinaryFile } from 'isbinaryfile';\nimport { createTemplateRenderer, TemplateCapabilities } from 'nunjitsu';\nimport { createDefaultFilters } from '../../../../lib/templating/filters/createDefaultFilters';\nimport {\n collectTemplateCapabilities,\n convertFiltersToRecord,\n} from '../../../../util/templating';\nimport { extname } from 'node:path';\n\nexport type TemplateActionInput = {\n targetPath?: string;\n values: any;\n templateFileExtension?: string | boolean;\n copyWithoutTemplating?: string[];\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n};\n\nexport function collectActionTemplateCapabilities(options: {\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n return collectTemplateCapabilities({\n filters: {\n ...convertFiltersToRecord(\n createDefaultFilters({ integrations: options.integrations }),\n ),\n ...options.additionalTemplateFilters,\n },\n globals: options.additionalTemplateGlobals,\n });\n}\n\nexport async function createTemplateActionHandler<\n I extends TemplateActionInput,\n>(options: {\n ctx: ActionContext<I, any, any>;\n resolveTemplate: () => Promise<string>;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n templateCapabilities?: TemplateCapabilities;\n}) {\n const { resolveTemplate, ctx } = options;\n const templateCapabilities =\n options.templateCapabilities ?? collectActionTemplateCapabilities(options);\n\n const { outputDir, copyOnlyPatterns, renderFilename, extension } =\n resolveTemplateActionSettings(ctx);\n\n const templateDir = await resolveTemplate();\n\n if (isChildPath(templateDir, outputDir)) {\n throw new InputError('targetPath must not be within template path');\n }\n\n ctx.logger.info('Listing files and directories in template');\n const allEntriesInTemplate = await globby(`**/*`, {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n });\n\n const nonTemplatedEntries = new Set(\n await globby(copyOnlyPatterns || [], {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n }),\n );\n\n // Cookiecutter prefixes all parameters in templates with\n // `cookiecutter.`. To replicate this, we wrap our parameters\n // in an object with a `cookiecutter` property when compat\n // mode is enabled.\n const { cookiecutterCompat, values } = ctx.input;\n const context = {\n [cookiecutterCompat ? 'cookiecutter' : 'values']: values,\n };\n\n ctx.logger.info(\n `Processing ${allEntriesInTemplate.length} template files/directories with input values`,\n ctx.input.values,\n );\n\n const templateRenderer = createTemplateRenderer({\n ...templateCapabilities,\n allowRegexExecution: true,\n cookiecutterCompat: ctx.input.cookiecutterCompat,\n trimBlocks: ctx.input.trimBlocks,\n lstripBlocks: ctx.input.lstripBlocks,\n });\n const preparedContext = templateRenderer.prepareContext(context);\n\n for (const location of allEntriesInTemplate) {\n let renderContents: boolean;\n\n let localOutputPath = location;\n if (extension) {\n renderContents = extname(localOutputPath) === extension;\n if (renderContents) {\n localOutputPath = localOutputPath.slice(0, -extension.length);\n }\n // extension is mutual exclusive with copyWithoutRender/copyWithoutTemplating,\n // therefore the output path is always rendered.\n localOutputPath = templateRenderer.render(\n localOutputPath,\n preparedContext,\n );\n } else {\n renderContents = !nonTemplatedEntries.has(location);\n // The logic here is a bit tangled because it depends on two variables.\n // If renderFilename is true, which means copyWithoutTemplating is used,\n // then the path is always rendered.\n // If renderFilename is false, which means copyWithoutRender is used,\n // then matched file/directory won't be processed, same as before.\n if (renderFilename) {\n localOutputPath = templateRenderer.render(\n localOutputPath,\n preparedContext,\n );\n } else {\n localOutputPath = renderContents\n ? templateRenderer.render(localOutputPath, preparedContext)\n : localOutputPath;\n }\n }\n\n if (containsSkippedContent(localOutputPath)) {\n continue;\n }\n\n const outputPath = resolveSafeChildPath(outputDir, localOutputPath);\n if (fs.existsSync(outputPath) && !ctx.input.replace) {\n continue;\n }\n\n if (!renderContents && !extension) {\n ctx.logger.info(`Copying file/directory ${location} without processing.`);\n }\n\n if (location.endsWith('/')) {\n ctx.logger.info(`Writing directory ${location} to template output path.`);\n await fs.ensureDir(outputPath);\n } else {\n const inputFilePath = resolveSafeChildPath(templateDir, location);\n const stats = await fs.promises.lstat(inputFilePath);\n\n if (stats.isSymbolicLink() || (await isBinaryFile(inputFilePath))) {\n ctx.logger.info(\n `Copying file binary or symbolic link at ${location}, to template output path.`,\n );\n await fs.copy(inputFilePath, outputPath);\n } else {\n const statsObj = await fs.stat(inputFilePath);\n ctx.logger.info(\n `Writing file ${location} to template output path with mode ${statsObj.mode}.`,\n );\n const inputFileContents = await fs.readFile(inputFilePath, 'utf-8');\n await fs.outputFile(\n outputPath,\n renderContents\n ? templateRenderer.render(inputFileContents, preparedContext)\n : inputFileContents,\n { mode: statsObj.mode },\n );\n }\n }\n }\n ctx.logger.info(`Template result written to ${outputDir}`);\n}\n\nfunction resolveTemplateActionSettings<I extends TemplateActionInput>(\n ctx: ActionContext<I, any, any>,\n): {\n outputDir: string;\n copyOnlyPatterns?: string[];\n renderFilename: boolean;\n extension: string | false;\n} {\n const targetPath = ctx.input.targetPath ?? './';\n const outputDir = resolveSafeChildPath(ctx.workspacePath, targetPath);\n\n const copyOnlyPatterns = ctx.input.copyWithoutTemplating;\n const renderFilename = true;\n\n if (copyOnlyPatterns && !Array.isArray(copyOnlyPatterns)) {\n throw new InputError(\n 'Fetch action input copyWithoutTemplating must be an Array',\n );\n }\n if (\n ctx.input.templateFileExtension &&\n (copyOnlyPatterns || ctx.input.cookiecutterCompat)\n ) {\n throw new InputError(\n 'Fetch action input extension incompatible with copyWithoutTemplating and cookiecutterCompat',\n );\n }\n let extension: string | false = false;\n if (ctx.input.templateFileExtension) {\n extension =\n ctx.input.templateFileExtension === true\n ? '.njk'\n : ctx.input.templateFileExtension;\n if (!extension.startsWith('.')) {\n extension = `.${extension}`;\n }\n }\n return {\n outputDir,\n copyOnlyPatterns,\n renderFilename,\n extension,\n };\n}\n\nfunction containsSkippedContent(localOutputPath: string): boolean {\n // if the path is empty means that there is a file skipped in the root\n // if the path starts with a separator it means that the root directory has been skipped\n // if the path includes // means that there is a subdirectory skipped\n // All paths returned are considered with / separator because of globby returning the linux separator for all os'.\n return (\n localOutputPath === '' ||\n localOutputPath.startsWith('/') ||\n localOutputPath.includes('//')\n );\n}\n"],"names":["collectTemplateCapabilities","convertFiltersToRecord","createDefaultFilters","isChildPath","InputError","globby","createTemplateRenderer","extname","resolveSafeChildPath","fs","isBinaryFile"],"mappings":";;;;;;;;;;;;;;;;;AAgDO,SAAS,kCAAkC,OAAA,EAI/C;AACD,EAAA,OAAOA,sCAAA,CAA4B;AAAA,IACjC,OAAA,EAAS;AAAA,MACP,GAAGC,iCAAA;AAAA,QACDC,yCAAA,CAAqB,EAAE,YAAA,EAAc,OAAA,CAAQ,cAAc;AAAA,OAC7D;AAAA,MACA,GAAG,OAAA,CAAQ;AAAA,KACb;AAAA,IACA,SAAS,OAAA,CAAQ;AAAA,GAClB,CAAA;AACH;AAEA,eAAsB,4BAEpB,OAAA,EAOC;AACD,EAAA,MAAM,EAAE,eAAA,EAAiB,GAAA,EAAI,GAAI,OAAA;AACjC,EAAA,MAAM,oBAAA,GACJ,OAAA,CAAQ,oBAAA,IAAwB,iCAAA,CAAkC,OAAO,CAAA;AAE3E,EAAA,MAAM,EAAE,SAAA,EAAW,gBAAA,EAAkB,gBAAgB,SAAA,EAAU,GAC7D,8BAA8B,GAAG,CAAA;AAEnC,EAAA,MAAM,WAAA,GAAc,MAAM,eAAA,EAAgB;AAE1C,EAAA,IAAIC,4BAAA,CAAY,WAAA,EAAa,SAAS,CAAA,EAAG;AACvC,IAAA,MAAM,IAAIC,kBAAW,6CAA6C,CAAA;AAAA,EACpE;AAEA,EAAA,GAAA,CAAI,MAAA,CAAO,KAAK,2CAA2C,CAAA;AAC3D,EAAA,MAAM,oBAAA,GAAuB,MAAMC,uBAAA,CAAO,CAAA,IAAA,CAAA,EAAQ;AAAA,IAChD,GAAA,EAAK,WAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,SAAA,EAAW,KAAA;AAAA,IACX,eAAA,EAAiB,IAAA;AAAA,IACjB,mBAAA,EAAqB;AAAA,GACtB,CAAA;AAED,EAAA,MAAM,sBAAsB,IAAI,GAAA;AAAA,IAC9B,MAAMA,uBAAA,CAAO,gBAAA,IAAoB,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IAAA,MAAM,IAAIJ,iBAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,IACE,IAAI,KAAA,CAAM,qBAAA,KACT,gBAAA,IAAoB,GAAA,CAAI,MAAM,kBAAA,CAAA,EAC/B;AACA,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,IAAI,SAAA,GAA4B,KAAA;AAChC,EAAA,IAAI,GAAA,CAAI,MAAM,qBAAA,EAAuB;AACnC,IAAA,SAAA,GACE,IAAI,KAAA,CAAM,qBAAA,KAA0B,IAAA,GAChC,MAAA,GACA,IAAI,KAAA,CAAM,qBAAA;AAChB,IAAA,IAAI,CAAC,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,EAAG;AAC9B,MAAA,SAAA,GAAY,IAAI,SAAS,CAAA,CAAA;AAAA,IAC3B;AAAA,EACF;AACA,EAAA,OAAO;AAAA,IACL,SAAA;AAAA,IACA,gBAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF;AACF;AAEA,SAAS,uBAAuB,eAAA,EAAkC;AAKhE,EAAA,OACE,eAAA,KAAoB,MACpB,eAAA,CAAgB,UAAA,CAAW,GAAG,CAAA,IAC9B,eAAA,CAAgB,SAAS,IAAI,CAAA;AAEjC;;;;;"}
@@ -4,12 +4,14 @@ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
4
4
  var path = require('node:path');
5
5
  var templateFile_examples = require('./templateFile.examples.cjs.js');
6
6
  var templateFileActionHandler = require('./templateFileActionHandler.cjs.js');
7
+ var templateActionHandler = require('./templateActionHandler.cjs.js');
7
8
 
8
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
9
10
 
10
11
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
11
12
 
12
13
  function createFetchTemplateFileAction(options) {
14
+ const templateCapabilities = templateActionHandler.collectActionTemplateCapabilities(options);
13
15
  return pluginScaffolderNode.createTemplateAction({
14
16
  id: "fetch:template:file",
15
17
  description: "Downloads single file and places it in the workspace.",
@@ -58,7 +60,8 @@ function createFetchTemplateFileAction(options) {
58
60
  });
59
61
  return tmpFilePath;
60
62
  },
61
- ...options
63
+ ...options,
64
+ templateCapabilities
62
65
  })
63
66
  });
64
67
  }
@@ -1 +1 @@
1
- {"version":3,"file":"templateFile.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateFile.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { UrlReaderService } from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n createTemplateAction,\n fetchFile,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport path from 'node:path';\nimport { examples } from './templateFile.examples';\nimport { createTemplateFileActionHandler } from './templateFileActionHandler';\n\n/**\n * Downloads a single file and templates variables into file.\n * Then places the result in the workspace, or optionally in a subdirectory\n * specified by the 'targetPath' input option.\n * @public\n */\nexport function createFetchTemplateFileAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n return createTemplateAction({\n id: 'fetch:template:file',\n description: 'Downloads single file and places it in the workspace.',\n examples,\n schema: {\n input: {\n url: z =>\n z.string({\n description:\n 'Relative path or absolute URL pointing to the single file to fetch.',\n }),\n targetPath: z =>\n z.string({\n description:\n 'Target path within the working directory to download the file as.',\n }),\n values: z =>\n z\n .record(z.any(), {\n description: 'Values to pass on to the templating engine',\n })\n .optional(),\n cookiecutterCompat: z =>\n z\n .boolean({\n description:\n 'Enable features to maximise compatibility with templates built for fetch:cookiecutter',\n })\n .optional(),\n replace: z =>\n z\n .boolean({\n description:\n 'If set, replace file in targetPath instead of overwriting existing one.',\n })\n .optional(),\n trimBlocks: z =>\n z\n .boolean({\n description:\n 'If set, the first newline after a block is removed (block, not variable tag).',\n })\n .optional(),\n lstripBlocks: z =>\n z\n .boolean({\n description:\n 'If set, leading spaces and tabs are stripped from the start of a line to a block.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'An optional token to use for authentication when reading the resources.',\n })\n .optional(),\n },\n },\n supportsDryRun: true,\n handler: ctx =>\n createTemplateFileActionHandler({\n ctx,\n resolveTemplateFile: async () => {\n ctx.logger.info('Fetching template file content from remote URL');\n\n const workDir = await ctx.createTemporaryDirectory();\n // Write to a tmp file, render the template, then copy to workspace.\n const tmpFilePath = path.join(workDir, 'tmp');\n\n await fetchFile({\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath: tmpFilePath,\n token: ctx.input.token,\n ...options,\n });\n return tmpFilePath;\n },\n ...options,\n }),\n });\n}\n"],"names":["createTemplateAction","examples","createTemplateFileActionHandler","path","fetchFile"],"mappings":";;;;;;;;;;;AAkCO,SAAS,8BAA8B,OAAA,EAK3C;AACD,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,qBAAA;AAAA,IACJ,WAAA,EAAa,uDAAA;AAAA,cACbC,8BAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,GAAA,EAAK,CAAA,CAAA,KACH,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,QAAQ,CAAA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GAAG;AAAA,SACJ,CAAA;AACD,QAAA,OAAO,WAAA;AAAA,MACT,CAAA;AAAA,MACA,GAAG;AAAA,KACJ;AAAA,GACJ,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"templateFile.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateFile.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { UrlReaderService } from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n createTemplateAction,\n fetchFile,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport path from 'node:path';\nimport { examples } from './templateFile.examples';\nimport { createTemplateFileActionHandler } from './templateFileActionHandler';\nimport { collectActionTemplateCapabilities } from './templateActionHandler';\n\n/**\n * Downloads a single file and templates variables into file.\n * Then places the result in the workspace, or optionally in a subdirectory\n * specified by the 'targetPath' input option.\n * @public\n */\nexport function createFetchTemplateFileAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n const templateCapabilities = collectActionTemplateCapabilities(options);\n\n return createTemplateAction({\n id: 'fetch:template:file',\n description: 'Downloads single file and places it in the workspace.',\n examples,\n schema: {\n input: {\n url: z =>\n z.string({\n description:\n 'Relative path or absolute URL pointing to the single file to fetch.',\n }),\n targetPath: z =>\n z.string({\n description:\n 'Target path within the working directory to download the file as.',\n }),\n values: z =>\n z\n .record(z.any(), {\n description: 'Values to pass on to the templating engine',\n })\n .optional(),\n cookiecutterCompat: z =>\n z\n .boolean({\n description:\n 'Enable features to maximise compatibility with templates built for fetch:cookiecutter',\n })\n .optional(),\n replace: z =>\n z\n .boolean({\n description:\n 'If set, replace file in targetPath instead of overwriting existing one.',\n })\n .optional(),\n trimBlocks: z =>\n z\n .boolean({\n description:\n 'If set, the first newline after a block is removed (block, not variable tag).',\n })\n .optional(),\n lstripBlocks: z =>\n z\n .boolean({\n description:\n 'If set, leading spaces and tabs are stripped from the start of a line to a block.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'An optional token to use for authentication when reading the resources.',\n })\n .optional(),\n },\n },\n supportsDryRun: true,\n handler: ctx =>\n createTemplateFileActionHandler({\n ctx,\n resolveTemplateFile: async () => {\n ctx.logger.info('Fetching template file content from remote URL');\n\n const workDir = await ctx.createTemporaryDirectory();\n // Write to a tmp file, render the template, then copy to workspace.\n const tmpFilePath = path.join(workDir, 'tmp');\n\n await fetchFile({\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath: tmpFilePath,\n token: ctx.input.token,\n ...options,\n });\n return tmpFilePath;\n },\n ...options,\n templateCapabilities,\n }),\n });\n}\n"],"names":["collectActionTemplateCapabilities","createTemplateAction","examples","createTemplateFileActionHandler","path","fetchFile"],"mappings":";;;;;;;;;;;;AAmCO,SAAS,8BAA8B,OAAA,EAK3C;AACD,EAAA,MAAM,oBAAA,GAAuBA,wDAAkC,OAAO,CAAA;AAEtE,EAAA,OAAOC,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,qBAAA;AAAA,IACJ,WAAA,EAAa,uDAAA;AAAA,cACbC,8BAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,GAAA,EAAK,CAAA,CAAA,KACH,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,C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UAAA,EAAY,WAAA;AAAA,UACZ,KAAA,EAAO,IAAI,KAAA,CAAM,KAAA;AAAA,UACjB,GAAG;AAAA,SACJ,CAAA;AACD,QAAA,OAAO,WAAA;AAAA,MACT,CAAA;AAAA,MACA,GAAG,OAAA;AAAA,MACH;AAAA,KACD;AAAA,GACJ,CAAA;AACH;;;;"}
@@ -3,9 +3,8 @@
3
3
  var backendPluginApi = require('@backstage/backend-plugin-api');
4
4
  var fs = require('fs-extra');
5
5
  var path = require('node:path');
6
- var createDefaultFilters = require('../../../../lib/templating/filters/createDefaultFilters.cjs.js');
7
- var SecureTemplater = require('../../../../lib/templating/SecureTemplater.cjs.js');
8
- var templating = require('../../../../util/templating.cjs.js');
6
+ var nunjitsu = require('nunjitsu');
7
+ var templateActionHandler = require('./templateActionHandler.cjs.js');
9
8
 
10
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
11
10
 
@@ -13,17 +12,8 @@ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
13
12
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
14
13
 
15
14
  async function createTemplateFileActionHandler(options) {
16
- const {
17
- resolveTemplateFile,
18
- integrations,
19
- additionalTemplateFilters,
20
- additionalTemplateGlobals: templateGlobals,
21
- ctx
22
- } = options;
23
- const templateFilters = {
24
- ...templating.convertFiltersToRecord(createDefaultFilters.createDefaultFilters({ integrations })),
25
- ...additionalTemplateFilters
26
- };
15
+ const { resolveTemplateFile, ctx } = options;
16
+ const templateCapabilities = options.templateCapabilities ?? templateActionHandler.collectActionTemplateCapabilities(options);
27
17
  const outputPath = backendPluginApi.resolveSafeChildPath(
28
18
  ctx.workspacePath,
29
19
  ctx.input.targetPath
@@ -43,24 +33,18 @@ async function createTemplateFileActionHandler(options) {
43
33
  `Processing template file with input values`,
44
34
  ctx.input.values
45
35
  );
46
- const { render: renderTemplate, dispose } = await SecureTemplater.SecureTemplater.loadRenderer({
36
+ const templateRenderer = nunjitsu.createTemplateRenderer({
37
+ ...templateCapabilities,
38
+ allowRegexExecution: true,
47
39
  cookiecutterCompat,
48
- templateFilters,
49
- templateGlobals,
50
- nunjucksConfigs: {
51
- trimBlocks: ctx.input.trimBlocks,
52
- lstripBlocks: ctx.input.lstripBlocks
53
- }
40
+ trimBlocks: ctx.input.trimBlocks,
41
+ lstripBlocks: ctx.input.lstripBlocks
54
42
  });
55
- try {
56
- const contents = await fs__default.default.readFile(filePath, "utf-8");
57
- const result = renderTemplate(contents, context);
58
- await fs__default.default.ensureDir(path__default.default.dirname(outputPath));
59
- await fs__default.default.outputFile(outputPath, result);
60
- ctx.logger.info(`Template file has been written to ${outputPath}`);
61
- } finally {
62
- dispose();
63
- }
43
+ const contents = await fs__default.default.readFile(filePath, "utf-8");
44
+ const result = templateRenderer.render(contents, context);
45
+ await fs__default.default.ensureDir(path__default.default.dirname(outputPath));
46
+ await fs__default.default.outputFile(outputPath, result);
47
+ ctx.logger.info(`Template file has been written to ${outputPath}`);
64
48
  }
65
49
 
66
50
  exports.createTemplateFileActionHandler = createTemplateFileActionHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"templateFileActionHandler.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateFileActionHandler.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 { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ActionContext,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport path from 'node:path';\nimport { createDefaultFilters } from '../../../../lib/templating/filters/createDefaultFilters';\nimport { SecureTemplater } from '../../../../lib/templating/SecureTemplater';\nimport { convertFiltersToRecord } from '../../../../util/templating';\n\nexport type TemplateFileActionInput = {\n targetPath: string;\n values: any;\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n};\n\nexport async function createTemplateFileActionHandler<\n I extends TemplateFileActionInput = TemplateFileActionInput,\n>(options: {\n ctx: ActionContext<I, any, any>;\n resolveTemplateFile: () => Promise<string>;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n const {\n resolveTemplateFile,\n integrations,\n additionalTemplateFilters,\n additionalTemplateGlobals: templateGlobals,\n ctx,\n } = options;\n\n const templateFilters = {\n ...convertFiltersToRecord(createDefaultFilters({ integrations })),\n ...additionalTemplateFilters,\n };\n\n const outputPath = resolveSafeChildPath(\n ctx.workspacePath,\n ctx.input.targetPath,\n );\n\n if (fs.existsSync(outputPath) && !ctx.input.replace) {\n ctx.logger.info(\n `File ${ctx.input.targetPath} already exists in workspace, not replacing.`,\n );\n return;\n }\n const filePath = await resolveTemplateFile();\n\n const { cookiecutterCompat, values } = ctx.input;\n const context = {\n [cookiecutterCompat ? 'cookiecutter' : 'values']: values,\n };\n\n ctx.logger.info(\n `Processing template file with input values`,\n ctx.input.values,\n );\n\n const { render: renderTemplate, dispose } =\n await SecureTemplater.loadRenderer({\n cookiecutterCompat,\n templateFilters,\n templateGlobals,\n nunjucksConfigs: {\n trimBlocks: ctx.input.trimBlocks,\n lstripBlocks: ctx.input.lstripBlocks,\n },\n });\n\n try {\n const contents = await fs.readFile(filePath, 'utf-8');\n const result = renderTemplate(contents, context);\n await fs.ensureDir(path.dirname(outputPath));\n await fs.outputFile(outputPath, result);\n\n ctx.logger.info(`Template file has been written to ${outputPath}`);\n } finally {\n dispose();\n }\n}\n"],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,IACA,eAAA,EAAiB;AAAA,MACf,UAAA,EAAY,IAAI,KAAA,CAAM,UAAA;AAAA,MACtB,YAAA,EAAc,IAAI,KAAA,CAAM;AAAA;AAC1B,GACD,CAAA;AAEH,EAAA,IAAI;AACF,IAAA,MAAM,QAAA,GAAW,MAAMD,mBAAA,CAAG,QAAA,CAAS,UAAU,OAAO,CAAA;AACpD,IAAA,MAAM,MAAA,GAAS,cAAA,CAAe,QAAA,EAAU,OAAO,CAAA;AAC/C,IAAA,MAAMA,mBAAA,CAAG,SAAA,CAAUE,qBAAA,CAAK,OAAA,CAAQ,UAAU,CAAC,CAAA;AAC3C,IAAA,MAAMF,mBAAA,CAAG,UAAA,CAAW,UAAA,EAAY,MAAM,CAAA;AAEtC,IAAA,GAAA,CAAI,MAAA,CAAO,IAAA,CAAK,CAAA,kCAAA,EAAqC,UAAU,CAAA,CAAE,CAAA;AAAA,EACnE,CAAA,SAAE;AACA,IAAA,OAAA,EAAQ;AAAA,EACV;AACF;;;;"}
1
+ {"version":3,"file":"templateFileActionHandler.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateFileActionHandler.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 { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ActionContext,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport path from 'node:path';\nimport { createTemplateRenderer, TemplateCapabilities } from 'nunjitsu';\nimport { collectActionTemplateCapabilities } from './templateActionHandler';\n\nexport type TemplateFileActionInput = {\n targetPath: string;\n values: any;\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n};\n\nexport async function createTemplateFileActionHandler<\n I extends TemplateFileActionInput = TemplateFileActionInput,\n>(options: {\n ctx: ActionContext<I, any, any>;\n resolveTemplateFile: () => Promise<string>;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n templateCapabilities?: TemplateCapabilities;\n}) {\n const { resolveTemplateFile, ctx } = options;\n const templateCapabilities =\n options.templateCapabilities ?? collectActionTemplateCapabilities(options);\n\n const outputPath = resolveSafeChildPath(\n ctx.workspacePath,\n ctx.input.targetPath,\n );\n\n if (fs.existsSync(outputPath) && !ctx.input.replace) {\n ctx.logger.info(\n `File ${ctx.input.targetPath} already exists in workspace, not replacing.`,\n );\n return;\n }\n const filePath = await resolveTemplateFile();\n\n const { cookiecutterCompat, values } = ctx.input;\n const context = {\n [cookiecutterCompat ? 'cookiecutter' : 'values']: values,\n };\n\n ctx.logger.info(\n `Processing template file with input values`,\n ctx.input.values,\n );\n\n const templateRenderer = createTemplateRenderer({\n ...templateCapabilities,\n allowRegexExecution: true,\n cookiecutterCompat,\n trimBlocks: ctx.input.trimBlocks,\n lstripBlocks: ctx.input.lstripBlocks,\n });\n\n const contents = await fs.readFile(filePath, 'utf-8');\n const result = templateRenderer.render(contents, context);\n await fs.ensureDir(path.dirname(outputPath));\n await fs.outputFile(outputPath, result);\n\n ctx.logger.info(`Template file has been written to ${outputPath}`);\n}\n"],"names":["collectActionTemplateCapabilities","resolveSafeChildPath","fs","createTemplateRenderer","path"],"mappings":";;;;;;;;;;;;;AAoCA,eAAsB,gCAEpB,OAAA,EAOC;AACD,EAAA,MAAM,EAAE,mBAAA,EAAqB,GAAA,EAAI,GAAI,OAAA;AACrC,EAAA,MAAM,oBAAA,GACJ,OAAA,C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,mBAAA,CAAG,UAAA,CAAW,UAAA,EAAY,MAAM,CAAA;AAEtC,EAAA,GAAA,CAAI,MAAA,CAAO,IAAA,CAAK,CAAA,kCAAA,EAAqC,UAAU,CAAA,CAAE,CAAA;AACnE;;;;"}
@@ -6,6 +6,7 @@ var path = require('node:path');
6
6
  var node_url = require('node:url');
7
7
  var node_crypto = require('node:crypto');
8
8
  var NunjucksWorkflowRunner = require('../tasks/NunjucksWorkflowRunner.cjs.js');
9
+ var templating = require('../../util/templating.cjs.js');
9
10
  var DecoratedActionsRegistry = require('./DecoratedActionsRegistry.cjs.js');
10
11
 
11
12
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
@@ -14,10 +15,15 @@ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
14
15
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
15
16
 
16
17
  function createDryRunner(options) {
18
+ const templateCapabilities = templating.collectTemplateCapabilities({
19
+ filters: options.additionalTemplateFilters,
20
+ globals: options.additionalTemplateGlobals
21
+ });
17
22
  return async function dryRun(input) {
18
23
  let contentPromise;
19
24
  const workflowRunner = new NunjucksWorkflowRunner.NunjucksWorkflowRunner({
20
25
  ...options,
26
+ templateCapabilities,
21
27
  actionRegistry: new DecoratedActionsRegistry.DecoratedActionsRegistry(options.actionRegistry, [
22
28
  pluginScaffolderNode.createTemplateAction({
23
29
  id: "dry-run:extract",
@@ -1 +1 @@
1
- {"version":3,"file":"createDryRunner.cjs.js","sources":["../../../src/scaffolder/dryrun/createDryRunner.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 {\n AuditorService,\n BackstageCredentials,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport type { MetricsService } from '@backstage/backend-plugin-api/alpha';\nimport type { UserEntity } from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { PermissionEvaluator } from '@backstage/plugin-permission-common';\nimport {\n ScaffolderTaskStatus,\n TaskSpec,\n TemplateInfo,\n} from '@backstage/plugin-scaffolder-common';\nimport {\n createTemplateAction,\n deserializeDirectoryContents,\n SerializedFile,\n serializeDirectoryContents,\n TaskSecrets,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { JsonObject } from '@backstage/types';\nimport fs from 'fs-extra';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { randomUUID as uuid } from 'node:crypto';\nimport { NunjucksWorkflowRunner } from '../tasks/NunjucksWorkflowRunner';\nimport { DecoratedActionsRegistry } from './DecoratedActionsRegistry';\nimport { TemplateActionRegistry } from '../actions';\n\ninterface DryRunInput {\n spec: TaskSpec;\n templateInfo: TemplateInfo;\n secrets?: TaskSecrets;\n directoryContents: SerializedFile[];\n credentials: BackstageCredentials;\n user?: {\n entity?: UserEntity;\n ref?: string;\n };\n}\n\ninterface DryRunResult {\n log: Array<{\n body: {\n message: string;\n stepId?: string;\n status?: ScaffolderTaskStatus;\n };\n }>;\n directoryContents: SerializedFile[];\n output: JsonObject;\n}\n\n/** @internal */\nexport type TemplateTesterCreateOptions = {\n logger: LoggerService;\n auditor?: AuditorService;\n integrations: ScmIntegrations;\n actionRegistry: TemplateActionRegistry;\n workingDirectory: string;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n permissions?: PermissionEvaluator;\n config?: Config;\n metrics: MetricsService;\n};\n\n/**\n * Executes a dry-run of the provided template.\n *\n * The provided content will be extracted into a temporary directory\n * which is then use as the base for any relative file fetch paths.\n *\n * @internal\n */\nexport function createDryRunner(options: TemplateTesterCreateOptions) {\n return async function dryRun(input: DryRunInput): Promise<DryRunResult> {\n let contentPromise;\n\n const workflowRunner = new NunjucksWorkflowRunner({\n ...options,\n actionRegistry: new DecoratedActionsRegistry(options.actionRegistry, [\n createTemplateAction({\n id: 'dry-run:extract',\n supportsDryRun: true,\n async handler(ctx) {\n contentPromise = serializeDirectoryContents(ctx.workspacePath);\n await contentPromise.catch(() => {});\n },\n }),\n ]),\n config: options.config,\n });\n\n // Extracting contentsPath and dryRunId from the baseUrl\n const baseUrl = input.templateInfo.baseUrl;\n if (!baseUrl) {\n throw new Error('baseUrl is required');\n }\n const basePath = fileURLToPath(new URL(baseUrl));\n const contentsPath = path.dirname(basePath);\n const dryRunId = uuid();\n\n const log = new Array<{\n body: {\n message: string;\n stepId?: string;\n status?: ScaffolderTaskStatus;\n };\n }>();\n\n try {\n await deserializeDirectoryContents(contentsPath, input.directoryContents);\n\n const abortSignal = new AbortController().signal;\n const result = await workflowRunner.execute({\n taskId: dryRunId,\n spec: {\n ...input.spec,\n steps: [\n ...input.spec.steps,\n {\n id: dryRunId,\n name: 'dry-run:extract',\n action: 'dry-run:extract',\n },\n ],\n templateInfo: input.templateInfo,\n },\n secrets: input.secrets,\n getInitiatorCredentials: () => Promise.resolve(input.credentials),\n // No need to update this at the end of the run, so just hard-code it\n done: false,\n isDryRun: true,\n getWorkspaceName: async () => `dry-run-${dryRunId}`,\n cancelSignal: abortSignal,\n async emitLog(message: string, logMetadata?: JsonObject) {\n if (logMetadata?.stepId === dryRunId) {\n return;\n }\n log.push({\n body: {\n ...logMetadata,\n message,\n },\n });\n },\n complete: async () => {\n throw new Error('Not implemented');\n },\n });\n\n if (!contentPromise) {\n throw new Error('Content extraction step was skipped');\n }\n const directoryContents = await contentPromise;\n\n return {\n log,\n directoryContents,\n output: result.output,\n };\n } finally {\n await fs.remove(contentsPath);\n }\n };\n}\n"],"names":["NunjucksWorkflowRunner","DecoratedActionsRegistry","createTemplateAction","serializeDirectoryContents","fileURLToPath","path","uuid","deserializeDirectoryContents","fs"],"mappings":";;;;;;;;;;;;;;;AA+FO,SAAS,gBAAgB,OAAA,EAAsC;AACpE,EAAA,OAAO,eAAe,OAAO,KAAA,EAA2C;AACtE,IAAA,IAAI,cAAA;AAEJ,IAAA,MAAM,cAAA,GAAiB,IAAIA,6CAAA,CAAuB;AAAA,MAChD,GAAG,OAAA;AAAA,MACH,cAAA,EAAgB,IAAIC,iDAAA,CAAyB,OAAA,CAAQ,cAAA,EAAgB;AAAA,QACnEC,yCAAA,CAAqB;AAAA,UACnB,EAAA,EAAI,iBAAA;AAAA,UACJ,cAAA,EAAgB,IAAA;AAAA,UAChB,MAAM,QAAQ,GAAA,EAAK;AACjB,YAAA,cAAA,GAAiBC,+CAAA,CAA2B,IAAI,aAAa,CAAA;AAC7D,YAAA,MAAM,cAAA,CAAe,MAAM,MAAM;AAAA,YAAC,CAAC,CAAA;AAAA,UACrC;AAAA,SACD;AAAA,OACF,CAAA;AAAA,MACD,QAAQ,OAAA,CAAQ;AAAA,KACjB,CAAA;AAGD,IAAA,MAAM,OAAA,GAAU,MAAM,YAAA,CAAa,OAAA;AACnC,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,MAAM,qBAAqB,CAAA;AAAA,IACvC;AACA,IAAA,MAAM,QAAA,GAAWC,sBAAA,CAAc,IAAI,GAAA,CAAI,OAAO,CAAC,CAAA;AAC/C,IAAA,MAAM,YAAA,GAAeC,qBAAA,CAAK,OAAA,CAAQ,QAAQ,CAAA;AAC1C,IAAA,MAAM,WAAWC,sBAAA,EAAK;AAEtB,IAAA,MAAM,GAAA,GAAM,IAAI,KAAA,EAMb;AAEH,IAAA,IAAI;AACF,MAAA,MAAMC,iDAAA,CAA6B,YAAA,EAAc,KAAA,CAAM,iBAAiB,CAAA;AAExE,MAAA,MAAM,WAAA,GAAc,IAAI,eAAA,EAAgB,CAAE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;AAAA,IACF,CAAA,SAAE;AACA,MAAA,MAAMC,mBAAA,CAAG,OAAO,YAAY,CAAA;AAAA,IAC9B;AAAA,EACF,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"createDryRunner.cjs.js","sources":["../../../src/scaffolder/dryrun/createDryRunner.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 {\n AuditorService,\n BackstageCredentials,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport type { MetricsService } from '@backstage/backend-plugin-api/alpha';\nimport type { UserEntity } from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { PermissionEvaluator } from '@backstage/plugin-permission-common';\nimport {\n ScaffolderTaskStatus,\n TaskSpec,\n TemplateInfo,\n} from '@backstage/plugin-scaffolder-common';\nimport {\n createTemplateAction,\n deserializeDirectoryContents,\n SerializedFile,\n serializeDirectoryContents,\n TaskSecrets,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { JsonObject } from '@backstage/types';\nimport fs from 'fs-extra';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { randomUUID as uuid } from 'node:crypto';\nimport { NunjucksWorkflowRunner } from '../tasks/NunjucksWorkflowRunner';\nimport { collectTemplateCapabilities } from '../../util/templating';\nimport { DecoratedActionsRegistry } from './DecoratedActionsRegistry';\nimport { TemplateActionRegistry } from '../actions';\n\ninterface DryRunInput {\n spec: TaskSpec;\n templateInfo: TemplateInfo;\n secrets?: TaskSecrets;\n directoryContents: SerializedFile[];\n credentials: BackstageCredentials;\n user?: {\n entity?: UserEntity;\n ref?: string;\n };\n}\n\ninterface DryRunResult {\n log: Array<{\n body: {\n message: string;\n stepId?: string;\n status?: ScaffolderTaskStatus;\n };\n }>;\n directoryContents: SerializedFile[];\n output: JsonObject;\n}\n\n/** @internal */\nexport type TemplateTesterCreateOptions = {\n logger: LoggerService;\n auditor?: AuditorService;\n integrations: ScmIntegrations;\n actionRegistry: TemplateActionRegistry;\n workingDirectory: string;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n permissions?: PermissionEvaluator;\n config?: Config;\n metrics: MetricsService;\n};\n\n/**\n * Executes a dry-run of the provided template.\n *\n * The provided content will be extracted into a temporary directory\n * which is then use as the base for any relative file fetch paths.\n *\n * @internal\n */\nexport function createDryRunner(options: TemplateTesterCreateOptions) {\n const templateCapabilities = collectTemplateCapabilities({\n filters: options.additionalTemplateFilters,\n globals: options.additionalTemplateGlobals,\n });\n\n return async function dryRun(input: DryRunInput): Promise<DryRunResult> {\n let contentPromise;\n\n const workflowRunner = new NunjucksWorkflowRunner({\n ...options,\n templateCapabilities,\n actionRegistry: new DecoratedActionsRegistry(options.actionRegistry, [\n createTemplateAction({\n id: 'dry-run:extract',\n supportsDryRun: true,\n async handler(ctx) {\n contentPromise = serializeDirectoryContents(ctx.workspacePath);\n await contentPromise.catch(() => {});\n },\n }),\n ]),\n config: options.config,\n });\n\n // Extracting contentsPath and dryRunId from the baseUrl\n const baseUrl = input.templateInfo.baseUrl;\n if (!baseUrl) {\n throw new Error('baseUrl is required');\n }\n const basePath = fileURLToPath(new URL(baseUrl));\n const contentsPath = path.dirname(basePath);\n const dryRunId = uuid();\n\n const log = new Array<{\n body: {\n message: string;\n stepId?: string;\n status?: ScaffolderTaskStatus;\n };\n }>();\n\n try {\n await deserializeDirectoryContents(contentsPath, input.directoryContents);\n\n const abortSignal = new AbortController().signal;\n const result = await workflowRunner.execute({\n taskId: dryRunId,\n spec: {\n ...input.spec,\n steps: [\n ...input.spec.steps,\n {\n id: dryRunId,\n name: 'dry-run:extract',\n action: 'dry-run:extract',\n },\n ],\n templateInfo: input.templateInfo,\n },\n secrets: input.secrets,\n getInitiatorCredentials: () => Promise.resolve(input.credentials),\n // No need to update this at the end of the run, so just hard-code it\n done: false,\n isDryRun: true,\n getWorkspaceName: async () => `dry-run-${dryRunId}`,\n cancelSignal: abortSignal,\n async emitLog(message: string, logMetadata?: JsonObject) {\n if (logMetadata?.stepId === dryRunId) {\n return;\n }\n log.push({\n body: {\n ...logMetadata,\n message,\n },\n });\n },\n complete: async () => {\n throw new Error('Not implemented');\n },\n });\n\n if (!contentPromise) {\n throw new Error('Content extraction step was skipped');\n }\n const directoryContents = await contentPromise;\n\n return {\n log,\n directoryContents,\n output: result.output,\n };\n } finally {\n await fs.remove(contentsPath);\n }\n };\n}\n"],"names":["collectTemplateCapabilities","NunjucksWorkflowRunner","DecoratedActionsRegistry","createTemplateAction","serializeDirectoryContents","fileURLToPath","path","uuid","deserializeDirectoryContents","fs"],"mappings":";;;;;;;;;;;;;;;;AAgGO,SAAS,gBAAgB,OAAA,EAAsC;AACpE,EAAA,MAAM,uBAAuBA,sCAAA,CAA4B;AAAA,IACvD,SAAS,OAAA,CAAQ,yBAAA;AAAA,IACjB,SAAS,OAAA,CAAQ;AAAA,GAClB,CAAA;AAED,EAAA,OAAO,eAAe,OAAO,KAAA,EAA2C;AACtE,IAAA,IAAI,cAAA;AAEJ,IAAA,MAAM,cAAA,GAAiB,IAAIC,6CAAA,CAAuB;AAAA,MAChD,GAAG,OAAA;AAAA,MACH,oBAAA;AAAA,MACA,cAAA,EAAgB,IAAIC,iDAAA,CAAyB,OAAA,CAAQ,cAAA,EAAgB;AAAA,QACnEC,yCAAA,CAAqB;AAAA,UACnB,EAAA,EAAI,iBAAA;AAAA,UACJ,cAAA,EAAgB,IAAA;AAAA,UAChB,MAAM,QAAQ,GAAA,EAAK;AACjB,YAAA,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