@backstage/plugin-scaffolder-node 0.12.3 → 0.12.4-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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @backstage/plugin-scaffolder-node
2
2
 
3
+ ## 0.12.4-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 7455dae: Use node prefix on native imports
8
+ - 4fc7bf0: Bump to tar v7
9
+ - 69d880e: Bump to latest zod to ensure it has the latest features
10
+ - Updated dependencies
11
+ - @backstage/backend-plugin-api@1.7.0-next.0
12
+ - @backstage/integration@1.19.3-next.0
13
+ - @backstage/plugin-permission-common@0.9.5-next.0
14
+ - @backstage/catalog-model@1.7.6
15
+ - @backstage/errors@1.2.7
16
+ - @backstage/types@1.2.2
17
+ - @backstage/plugin-scaffolder-common@1.7.6-next.0
18
+
3
19
  ## 0.12.3
4
20
 
5
21
  ### Patch Changes
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var child_process = require('child_process');
4
- var stream = require('stream');
3
+ var node_child_process = require('node:child_process');
4
+ var node_stream = require('node:stream');
5
5
 
6
6
  async function executeShellCommand(options) {
7
7
  const {
@@ -9,10 +9,10 @@ async function executeShellCommand(options) {
9
9
  args,
10
10
  options: spawnOptions,
11
11
  logger,
12
- logStream = new stream.PassThrough()
12
+ logStream = new node_stream.PassThrough()
13
13
  } = options;
14
14
  await new Promise((resolve, reject) => {
15
- const process = child_process.spawn(command, args, spawnOptions);
15
+ const process = node_child_process.spawn(command, args, spawnOptions);
16
16
  process.stdout.on("data", (chunk) => {
17
17
  logStream?.write(chunk);
18
18
  logger?.info(
@@ -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 'child_process';\nimport { PassThrough, Writable } from '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,MAA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AA,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;;;;"}
@@ -3,7 +3,7 @@
3
3
  var backendPluginApi = require('@backstage/backend-plugin-api');
4
4
  var errors = require('@backstage/errors');
5
5
  var fs = require('fs-extra');
6
- var path = require('path');
6
+ var path = require('node:path');
7
7
 
8
8
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
9
9
 
@@ -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 '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,UAAA,CAAW,QAAA,EAAU,OAAA,EAAS,YAAY,CAAA;AAE1D,IAAA,MAAM,MAAM,MAAM,MAAA,CAAO,SAAS,OAAA,EAAS,EAAE,OAAO,CAAA;AACpD,IAAA,MAAMD,mBAAA,CAAG,UAAU,UAAU,CAAA;AAC7B,IAAA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AAA,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,MAAA,EAAQ,GAAG;AAAA,KACvC,CAAA;AAAA,EACH,CAAA,MAAO;AACL,IAAA,MAAM,OAAA,GAAU,UAAA,CAAW,QAAA,EAAU,OAAA,EAAS,YAAY,CAAA;AAE1D,IAAA,MAAM,MAAM,MAAM,MAAA,CAAO,SAAS,OA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,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;;;;;"}
@@ -2,7 +2,7 @@
2
2
 
3
3
  var errors = require('@backstage/errors');
4
4
  var backendPluginApi = require('@backstage/backend-plugin-api');
5
- var path = require('path');
5
+ var path = require('node:path');
6
6
  var zodToJsonSchema = require('zod-to-json-schema');
7
7
  var zod = require('zod');
8
8
  var lodash = require('lodash');
@@ -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 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { TemplateActionOptions } from './createTemplateAction';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { z } from 'zod';\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 'bitbucket': {\n if (host === 'www.bitbucket.org') {\n checkRequiredParams(parsed, 'workspace');\n }\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,MAAMC,MAAA,GAAOC,SAAA,CAAS,aAAA,EAAe,UAAU,CAAA;AAC/C,IAAA,IAAI,CAACC,4BAAA,CAAY,aAAA,EAAeF,MAAI,CAAA,EAAG;AACrC,MAAA,MAAM,IAAI,MAAM,qBAAqB,CAAA;AAAA,IACvC;AACA,IAAA,OAAOA,MAAA;AAAA,EACT;AACA,EAAA,OAAO,aAAA;AACT;AAKO,MAAM,YAAA,GAAe,CAC1B,OAAA,EACA,YAAA,KAQG;AACH,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAI,GAAA,CAAI,CAAA,QAAA,EAAW,OAAO,CAAA,CAAE,CAAA;AAAA,EACvC,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAIG,iBAAA;AAAA,MACR,CAAA,0CAAA,EAA6C,OAAO,CAAA,EAAA,EAAK,KAAK,CAAA;AAAA,KAChE;AAAA,EACF;AACA,EAAA,MAAM,OAAO,MAAA,CAAO,IAAA;AACpB,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,CAAO,IAAI,CAAA,EAAG,IAAA;AAExC,EAAA,IAAI,CAAC,IAAA,EAAM;AACT,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR,kDAAkD,IAAI,CAAA,uCAAA;AAAA,KACxD;AAAA,EACF;AACA,EAA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AC,CAAC,CAAC;AAAA;AAC/D,KACF;AAEA,IAAA,OAAO;AAAA,MACL,WAAA,EAAaC,iCAAgB,KAAK,CAAA;AAAA,MAClC,YAAA,EAAc,qBAAA,CAAsB,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA,GACnDA,gCAAA;AAAA,QACCD,KAAA,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,KAAC,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,KAAC,CAAC,CAAA;AAAA,MACnD,YAAA,EAAc,uBAAA,CAAwB,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA,GACrDC,gCAAA,CAAgB,MAAA,CAAO,MAAA,CAAO,MAAA,CAAOD,KAAC,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';\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 'bitbucket': {\n if (host === 'www.bitbucket.org') {\n checkRequiredParams(parsed, 'workspace');\n }\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,MAAMC,MAAA,GAAOC,SAAA,CAAS,aAAA,EAAe,UAAU,CAAA;AAC/C,IAAA,IAAI,CAACC,4BAAA,CAAY,aAAA,EAAeF,MAAI,CAAA,EAAG;AACrC,MAAA,MAAM,IAAI,MAAM,qBAAqB,CAAA;AAAA,IACvC;AACA,IAAA,OAAOA,MAAA;AAAA,EACT;AACA,EAAA,OAAO,aAAA;AACT;AAKO,MAAM,YAAA,GAAe,CAC1B,OAAA,EACA,YAAA,KAQG;AACH,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAI,GAAA,CAAI,CAAA,QAAA,EAAW,OAAO,CAAA,CAAE,CAAA;AAAA,EACvC,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAIG,iBAAA;AAAA,MACR,CAAA,0CAAA,EAA6C,OAAO,CAAA,EAAA,EAAK,KAAK,CAAA;AAAA,KAChE;AAAA,EACF;AACA,EAAA,MAAM,OAAO,MAAA,CAAO,IAAA;AACpB,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,MAAA,CAAO,IAAI,CAAA,EAAG,IA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
 
3
3
  var fs = require('fs-extra');
4
- var path = require('path');
4
+ var path = require('node:path');
5
5
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
6
 
7
7
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
@@ -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 '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,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var fs = require('fs');
3
+ var node_fs = require('node:fs');
4
4
  var globby = require('globby');
5
5
  var limiterFactory = require('p-limit');
6
6
  var backendPluginApi = require('@backstage/backend-plugin-api');
@@ -42,7 +42,7 @@ async function serializeDirectoryContents(sourcePath, options) {
42
42
  if (!dirent.isSymbolicLink()) return true;
43
43
  const safePath = backendPluginApi.resolveSafeChildPath(sourcePath, path);
44
44
  try {
45
- await fs.promises.stat(safePath);
45
+ await node_fs.promises.stat(safePath);
46
46
  return false;
47
47
  } catch (e) {
48
48
  return errors.isError(e) && e.code === "ENOENT";
@@ -54,9 +54,9 @@ async function serializeDirectoryContents(sourcePath, options) {
54
54
  content: await limiter(async () => {
55
55
  const absFilePath = backendPluginApi.resolveSafeChildPath(sourcePath, path);
56
56
  if (dirent.isSymbolicLink()) {
57
- return fs.promises.readlink(absFilePath, "buffer");
57
+ return node_fs.promises.readlink(absFilePath, "buffer");
58
58
  }
59
- return fs.promises.readFile(absFilePath);
59
+ return node_fs.promises.readFile(absFilePath);
60
60
  }),
61
61
  executable: isExecutable(stats?.mode),
62
62
  symlink: dirent.isSymbolicLink()
@@ -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 '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;A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,IACT,SAAS,CAAA,EAAG;AACV,MAAA,OAAOC,cAAA,CAAQ,CAAC,CAAA,IAAK,CAAA,CAAE,IAAA,KAAS,QAAA;AAAA,IAClC;AAAA,EACF,CAAC,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,WAAA,CAAG,QAAA,CAAS,WAAA,EAAa,QAAQ,CAAA;AAAA,QAC1C;AACA,QAAA,OAAOA,WAAA,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,CA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A,OAAO,KAAA;AAAA,IACT,SAAS,CAAA,EAAG;AACV,MAAA,OAAOC,cAAA,CAAQ,CAAC,CAAA,IAAK,CAAA,CAAE,IAAA,KAAS,QAAA;AAAA,IAClC;AAAA,EACF,CAAC,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;;;;;"}
package/dist/index.d.ts CHANGED
@@ -7,8 +7,8 @@ import { UpdateTaskCheckpointOptions, CheckpointContext } from '@backstage/plugi
7
7
  import { UserEntity } from '@backstage/catalog-model';
8
8
  import { Schema } from 'jsonschema';
9
9
  import { z } from 'zod';
10
- import { SpawnOptionsWithoutStdio } from 'child_process';
11
- import { Writable } from 'stream';
10
+ import { SpawnOptionsWithoutStdio } from 'node:child_process';
11
+ import { Writable } from 'node:stream';
12
12
  import { ScmIntegrations, ScmIntegrationRegistry } from '@backstage/integration';
13
13
  export { T as TemplateFilter, a as TemplateGlobal } from './types/types.d-C0fXdKnD.js';
14
14
 
@@ -2,19 +2,37 @@
2
2
 
3
3
  var tar = require('tar');
4
4
  var concatStream = require('concat-stream');
5
- var util = require('util');
6
- var stream = require('stream');
5
+ var node_util = require('node:util');
6
+ var node_stream = require('node:stream');
7
7
 
8
8
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
9
9
 
10
- var tar__default = /*#__PURE__*/_interopDefaultCompat(tar);
10
+ function _interopNamespaceCompat(e) {
11
+ if (e && typeof e === 'object' && 'default' in e) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var tar__namespace = /*#__PURE__*/_interopNamespaceCompat(tar);
11
29
  var concatStream__default = /*#__PURE__*/_interopDefaultCompat(concatStream);
12
30
 
13
- const pipeline = util.promisify(stream.pipeline);
31
+ const pipeline = node_util.promisify(node_stream.pipeline);
14
32
  const serializeWorkspace = async (opts) => {
15
33
  return new Promise(async (resolve) => {
16
34
  await pipeline(
17
- tar__default.default.create({ cwd: opts.path }, [""]),
35
+ tar__namespace.create({ cwd: opts.path }, [""]),
18
36
  concatStream__default.default((buffer) => {
19
37
  return resolve({ contents: buffer });
20
38
  })
@@ -25,8 +43,8 @@ const restoreWorkspace = async (opts) => {
25
43
  const { buffer, path } = opts;
26
44
  if (buffer) {
27
45
  await pipeline(
28
- stream.Readable.from(buffer),
29
- tar__default.default.extract({
46
+ node_stream.Readable.from(buffer),
47
+ tar__namespace.extract({
30
48
  C: path
31
49
  })
32
50
  );
@@ -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 tar from 'tar';\nimport concatStream from 'concat-stream';\nimport { promisify } from 'util';\nimport { pipeline as pipelineCb, Readable } from '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,eAAUC,eAAU,CAAA;AAM9B,MAAM,kBAAA,GAAqB,OAAO,IAAA,KAEJ;AACnC,EAAA,OAAO,IAAI,OAAA,CAA8B,OAAM,OAAA,KAAW;AACxD,IAAA,MAAM,QAAA;AAAA,MACJC,oBAAA,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,eAAA,CAAS,KAAK,MAAM,CAAA;AAAA,MACpBF,qBAAI,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;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-node",
3
- "version": "0.12.3",
3
+ "version": "0.12.4-next.0",
4
4
  "description": "The plugin-scaffolder-node module for @backstage/plugin-scaffolder-backend",
5
5
  "backstage": {
6
6
  "role": "node-library",
@@ -62,13 +62,13 @@
62
62
  "test": "backstage-cli package test"
63
63
  },
64
64
  "dependencies": {
65
- "@backstage/backend-plugin-api": "^1.6.1",
66
- "@backstage/catalog-model": "^1.7.6",
67
- "@backstage/errors": "^1.2.7",
68
- "@backstage/integration": "^1.19.2",
69
- "@backstage/plugin-permission-common": "^0.9.4",
70
- "@backstage/plugin-scaffolder-common": "^1.7.5",
71
- "@backstage/types": "^1.2.2",
65
+ "@backstage/backend-plugin-api": "1.7.0-next.0",
66
+ "@backstage/catalog-model": "1.7.6",
67
+ "@backstage/errors": "1.2.7",
68
+ "@backstage/integration": "1.19.3-next.0",
69
+ "@backstage/plugin-permission-common": "0.9.5-next.0",
70
+ "@backstage/plugin-scaffolder-common": "1.7.6-next.0",
71
+ "@backstage/types": "1.2.2",
72
72
  "@isomorphic-git/pgp-plugin": "^0.0.7",
73
73
  "concat-stream": "^2.0.0",
74
74
  "fs-extra": "^11.2.0",
@@ -77,16 +77,16 @@
77
77
  "jsonschema": "^1.5.0",
78
78
  "lodash": "^4.17.21",
79
79
  "p-limit": "^3.1.0",
80
- "tar": "^6.1.12",
80
+ "tar": "^7.5.6",
81
81
  "winston": "^3.2.1",
82
82
  "winston-transport": "^4.7.0",
83
- "zod": "^3.22.4",
83
+ "zod": "^3.25.76",
84
84
  "zod-to-json-schema": "^3.25.1"
85
85
  },
86
86
  "devDependencies": {
87
- "@backstage/backend-test-utils": "^1.10.3",
88
- "@backstage/cli": "^0.35.2",
89
- "@backstage/config": "^1.3.6",
87
+ "@backstage/backend-test-utils": "1.10.4-next.0",
88
+ "@backstage/cli": "0.35.3-next.0",
89
+ "@backstage/config": "1.3.6",
90
90
  "@types/lodash": "^4.14.151"
91
91
  }
92
92
  }