@backstage/cli-common 0.1.14 → 0.1.15

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,17 @@
1
1
  # @backstage/cli-common
2
2
 
3
+ ## 0.1.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 702f41d: Bumped dev dependencies `@types/node`
8
+
9
+ ## 0.1.15-next.0
10
+
11
+ ### Patch Changes
12
+
13
+ - 702f41d: Bumped dev dependencies `@types/node`
14
+
3
15
  ## 0.1.14
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -1,103 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var fs = require('fs');
4
- var path = require('path');
3
+ var paths = require('./paths.cjs.js');
4
+ var isChildPath = require('./isChildPath.cjs.js');
5
5
 
6
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
7
6
 
8
- var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
9
7
 
10
- function findRootPath(searchDir, filterFunc) {
11
- let path$1 = searchDir;
12
- for (let i = 0; i < 1e3; i++) {
13
- const packagePath = path.resolve(path$1, "package.json");
14
- const exists = fs__default.default.existsSync(packagePath);
15
- if (exists && filterFunc(packagePath)) {
16
- return path$1;
17
- }
18
- const newPath = path.dirname(path$1);
19
- if (newPath === path$1) {
20
- return void 0;
21
- }
22
- path$1 = newPath;
23
- }
24
- throw new Error(
25
- `Iteration limit reached when searching for root package.json at ${searchDir}`
26
- );
27
- }
28
- function findOwnDir(searchDir) {
29
- const path = findRootPath(searchDir, () => true);
30
- if (!path) {
31
- throw new Error(
32
- `No package.json found while searching for package root of ${searchDir}`
33
- );
34
- }
35
- return path;
36
- }
37
- function findOwnRootDir(ownDir) {
38
- const isLocal = fs__default.default.existsSync(path.resolve(ownDir, "src"));
39
- if (!isLocal) {
40
- throw new Error(
41
- "Tried to access monorepo package root dir outside of Backstage repository"
42
- );
43
- }
44
- return path.resolve(ownDir, "../..");
45
- }
46
- function findPaths(searchDir) {
47
- const ownDir = findOwnDir(searchDir);
48
- const targetDir = fs__default.default.realpathSync(process.cwd()).replace(/^[a-z]:/, (str) => str.toLocaleUpperCase("en-US"));
49
- let ownRoot = "";
50
- const getOwnRoot = () => {
51
- if (!ownRoot) {
52
- ownRoot = findOwnRootDir(ownDir);
53
- }
54
- return ownRoot;
55
- };
56
- let targetRoot = "";
57
- const getTargetRoot = () => {
58
- if (!targetRoot) {
59
- targetRoot = findRootPath(targetDir, (path) => {
60
- try {
61
- const content = fs__default.default.readFileSync(path, "utf8");
62
- const data = JSON.parse(content);
63
- return Boolean(data.workspaces);
64
- } catch (error) {
65
- throw new Error(
66
- `Failed to parse package.json file while searching for root, ${error}`
67
- );
68
- }
69
- }) ?? targetDir;
70
- }
71
- return targetRoot;
72
- };
73
- return {
74
- ownDir,
75
- get ownRoot() {
76
- return getOwnRoot();
77
- },
78
- targetDir,
79
- get targetRoot() {
80
- return getTargetRoot();
81
- },
82
- resolveOwn: (...paths) => path.resolve(ownDir, ...paths),
83
- resolveOwnRoot: (...paths) => path.resolve(getOwnRoot(), ...paths),
84
- resolveTarget: (...paths) => path.resolve(targetDir, ...paths),
85
- resolveTargetRoot: (...paths) => path.resolve(getTargetRoot(), ...paths)
86
- };
87
- }
88
- const BACKSTAGE_JSON = "backstage.json";
89
-
90
- function isChildPath(base, path$1) {
91
- const relativePath = path.relative(base, path$1);
92
- if (relativePath === "") {
93
- return true;
94
- }
95
- const outsideBase = relativePath.startsWith("..");
96
- const differentDrive = path.isAbsolute(relativePath);
97
- return !outsideBase && !differentDrive;
98
- }
99
-
100
- exports.BACKSTAGE_JSON = BACKSTAGE_JSON;
101
- exports.findPaths = findPaths;
102
- exports.isChildPath = isChildPath;
8
+ exports.BACKSTAGE_JSON = paths.BACKSTAGE_JSON;
9
+ exports.findPaths = paths.findPaths;
10
+ exports.isChildPath = isChildPath.isChildPath;
103
11
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/paths.ts","../src/isChildPath.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs';\nimport { dirname, resolve as resolvePath } from 'path';\n\n/**\n * A function that takes a set of path fragments and resolves them into a\n * single complete path, relative to some root.\n *\n * @public\n */\nexport type ResolveFunc = (...paths: string[]) => string;\n\n/**\n * Common paths and resolve functions used by the cli.\n * Currently assumes it is being executed within a monorepo.\n *\n * @public\n */\nexport type Paths = {\n // Root dir of the cli itself, containing package.json\n ownDir: string;\n\n // Monorepo root dir of the cli itself. Only accessible when running inside Backstage repo.\n ownRoot: string;\n\n // The location of the app that the cli is being executed in\n targetDir: string;\n\n // The monorepo root package of the app that the cli is being executed in.\n targetRoot: string;\n\n // Resolve a path relative to own repo\n resolveOwn: ResolveFunc;\n\n // Resolve a path relative to own monorepo root. Only accessible when running inside Backstage repo.\n resolveOwnRoot: ResolveFunc;\n\n // Resolve a path relative to the app\n resolveTarget: ResolveFunc;\n\n // Resolve a path relative to the app repo root\n resolveTargetRoot: ResolveFunc;\n};\n\n// Looks for a package.json with a workspace config to identify the root of the monorepo\nexport function findRootPath(\n searchDir: string,\n filterFunc: (pkgJsonPath: string) => boolean,\n): string | undefined {\n let path = searchDir;\n\n // Some confidence check to avoid infinite loop\n for (let i = 0; i < 1000; i++) {\n const packagePath = resolvePath(path, 'package.json');\n const exists = fs.existsSync(packagePath);\n if (exists && filterFunc(packagePath)) {\n return path;\n }\n\n const newPath = dirname(path);\n if (newPath === path) {\n return undefined;\n }\n path = newPath;\n }\n\n throw new Error(\n `Iteration limit reached when searching for root package.json at ${searchDir}`,\n );\n}\n\n// Finds the root of a given package\nexport function findOwnDir(searchDir: string) {\n const path = findRootPath(searchDir, () => true);\n if (!path) {\n throw new Error(\n `No package.json found while searching for package root of ${searchDir}`,\n );\n }\n return path;\n}\n\n// Finds the root of the monorepo that the package exists in. Only accessible when running inside Backstage repo.\nexport function findOwnRootDir(ownDir: string) {\n const isLocal = fs.existsSync(resolvePath(ownDir, 'src'));\n if (!isLocal) {\n throw new Error(\n 'Tried to access monorepo package root dir outside of Backstage repository',\n );\n }\n\n return resolvePath(ownDir, '../..');\n}\n\n/**\n * Find paths related to a package and its execution context.\n *\n * @public\n * @example\n *\n * const paths = findPaths(__dirname)\n */\nexport function findPaths(searchDir: string): Paths {\n const ownDir = findOwnDir(searchDir);\n // Drive letter can end up being lowercased here on Windows, bring back to uppercase for consistency\n const targetDir = fs\n .realpathSync(process.cwd())\n .replace(/^[a-z]:/, str => str.toLocaleUpperCase('en-US'));\n\n // Lazy load this as it will throw an error if we're not inside the Backstage repo.\n let ownRoot = '';\n const getOwnRoot = () => {\n if (!ownRoot) {\n ownRoot = findOwnRootDir(ownDir);\n }\n return ownRoot;\n };\n\n // We're not always running in a monorepo, so we lazy init this to only crash commands\n // that require a monorepo when we're not in one.\n let targetRoot = '';\n const getTargetRoot = () => {\n if (!targetRoot) {\n targetRoot =\n findRootPath(targetDir, path => {\n try {\n const content = fs.readFileSync(path, 'utf8');\n const data = JSON.parse(content);\n return Boolean(data.workspaces);\n } catch (error) {\n throw new Error(\n `Failed to parse package.json file while searching for root, ${error}`,\n );\n }\n }) ?? targetDir; // We didn't find any root package.json, assume we're not in a monorepo\n }\n return targetRoot;\n };\n\n return {\n ownDir,\n get ownRoot() {\n return getOwnRoot();\n },\n targetDir,\n get targetRoot() {\n return getTargetRoot();\n },\n resolveOwn: (...paths) => resolvePath(ownDir, ...paths),\n resolveOwnRoot: (...paths) => resolvePath(getOwnRoot(), ...paths),\n resolveTarget: (...paths) => resolvePath(targetDir, ...paths),\n resolveTargetRoot: (...paths) => resolvePath(getTargetRoot(), ...paths),\n };\n}\n\n/**\n * The name of the backstage's config file\n *\n * @public\n */\nexport const BACKSTAGE_JSON = 'backstage.json';\n","/*\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 { relative, isAbsolute } from 'path';\n\n/**\n * Checks if path is the same as or a child path of base.\n *\n * @public\n */\nexport function isChildPath(base: string, path: string): boolean {\n const relativePath = relative(base, path);\n if (relativePath === '') {\n // The same directory\n return true;\n }\n\n const outsideBase = relativePath.startsWith('..'); // not outside base\n const differentDrive = isAbsolute(relativePath); // on Windows, this means dir is on a different drive from base.\n\n return !outsideBase && !differentDrive;\n}\n"],"names":["path","resolvePath","fs","dirname","relative","isAbsolute"],"mappings":";;;;;;;;;AA4DgB,SAAA,YAAA,CACd,WACA,UACoB,EAAA;AACpB,EAAA,IAAIA,MAAO,GAAA,SAAA,CAAA;AAGX,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,GAAA,EAAM,CAAK,EAAA,EAAA;AAC7B,IAAM,MAAA,WAAA,GAAcC,YAAY,CAAAD,MAAA,EAAM,cAAc,CAAA,CAAA;AACpD,IAAM,MAAA,MAAA,GAASE,mBAAG,CAAA,UAAA,CAAW,WAAW,CAAA,CAAA;AACxC,IAAI,IAAA,MAAA,IAAU,UAAW,CAAA,WAAW,CAAG,EAAA;AACrC,MAAO,OAAAF,MAAA,CAAA;AAAA,KACT;AAEA,IAAM,M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I,GAAA,KAAA,KAAUA,aAAY,aAAc,EAAA,EAAG,GAAG,KAAK,CAAA;AAAA,GACxE,CAAA;AACF,CAAA;AAOO,MAAM,cAAiB,GAAA;;ACxJd,SAAA,WAAA,CAAY,MAAcD,MAAuB,EAAA;AAC/D,EAAM,MAAA,YAAA,GAAeI,aAAS,CAAA,IAAA,EAAMJ,MAAI,CAAA,CAAA;AACxC,EAAA,IAAI,iBAAiB,EAAI,EAAA;AAEvB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAM,MAAA,WAAA,GAAc,YAAa,CAAA,UAAA,CAAW,IAAI,CAAA,CAAA;AAChD,EAAM,MAAA,cAAA,GAAiBK,gBAAW,YAAY,CAAA,CAAA;AAE9C,EAAO,OAAA,CAAC,eAAe,CAAC,cAAA,CAAA;AAC1B;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+
5
+ function isChildPath(base, path$1) {
6
+ const relativePath = path.relative(base, path$1);
7
+ if (relativePath === "") {
8
+ return true;
9
+ }
10
+ const outsideBase = relativePath.startsWith("..");
11
+ const differentDrive = path.isAbsolute(relativePath);
12
+ return !outsideBase && !differentDrive;
13
+ }
14
+
15
+ exports.isChildPath = isChildPath;
16
+ //# sourceMappingURL=isChildPath.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isChildPath.cjs.js","sources":["../src/isChildPath.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 { relative, isAbsolute } from 'path';\n\n/**\n * Checks if path is the same as or a child path of base.\n *\n * @public\n */\nexport function isChildPath(base: string, path: string): boolean {\n const relativePath = relative(base, path);\n if (relativePath === '') {\n // The same directory\n return true;\n }\n\n const outsideBase = relativePath.startsWith('..'); // not outside base\n const differentDrive = isAbsolute(relativePath); // on Windows, this means dir is on a different drive from base.\n\n return !outsideBase && !differentDrive;\n}\n"],"names":["path","relative","isAbsolute"],"mappings":";;;;AAuBgB,SAAA,WAAA,CAAY,MAAcA,MAAuB,EAAA;AAC/D,EAAM,MAAA,YAAA,GAAeC,aAAS,CAAA,IAAA,EAAMD,MAAI,CAAA;AACxC,EAAA,IAAI,iBAAiB,EAAI,EAAA;AAEvB,IAAO,OAAA,IAAA;AAAA;AAGT,EAAM,MAAA,WAAA,GAAc,YAAa,CAAA,UAAA,CAAW,IAAI,CAAA;AAChD,EAAM,MAAA,cAAA,GAAiBE,gBAAW,YAAY,CAAA;AAE9C,EAAO,OAAA,CAAC,eAAe,CAAC,cAAA;AAC1B;;;;"}
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+
6
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
7
+
8
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
9
+
10
+ function findRootPath(searchDir, filterFunc) {
11
+ let path$1 = searchDir;
12
+ for (let i = 0; i < 1e3; i++) {
13
+ const packagePath = path.resolve(path$1, "package.json");
14
+ const exists = fs__default.default.existsSync(packagePath);
15
+ if (exists && filterFunc(packagePath)) {
16
+ return path$1;
17
+ }
18
+ const newPath = path.dirname(path$1);
19
+ if (newPath === path$1) {
20
+ return void 0;
21
+ }
22
+ path$1 = newPath;
23
+ }
24
+ throw new Error(
25
+ `Iteration limit reached when searching for root package.json at ${searchDir}`
26
+ );
27
+ }
28
+ function findOwnDir(searchDir) {
29
+ const path = findRootPath(searchDir, () => true);
30
+ if (!path) {
31
+ throw new Error(
32
+ `No package.json found while searching for package root of ${searchDir}`
33
+ );
34
+ }
35
+ return path;
36
+ }
37
+ function findOwnRootDir(ownDir) {
38
+ const isLocal = fs__default.default.existsSync(path.resolve(ownDir, "src"));
39
+ if (!isLocal) {
40
+ throw new Error(
41
+ "Tried to access monorepo package root dir outside of Backstage repository"
42
+ );
43
+ }
44
+ return path.resolve(ownDir, "../..");
45
+ }
46
+ function findPaths(searchDir) {
47
+ const ownDir = findOwnDir(searchDir);
48
+ const targetDir = fs__default.default.realpathSync(process.cwd()).replace(/^[a-z]:/, (str) => str.toLocaleUpperCase("en-US"));
49
+ let ownRoot = "";
50
+ const getOwnRoot = () => {
51
+ if (!ownRoot) {
52
+ ownRoot = findOwnRootDir(ownDir);
53
+ }
54
+ return ownRoot;
55
+ };
56
+ let targetRoot = "";
57
+ const getTargetRoot = () => {
58
+ if (!targetRoot) {
59
+ targetRoot = findRootPath(targetDir, (path) => {
60
+ try {
61
+ const content = fs__default.default.readFileSync(path, "utf8");
62
+ const data = JSON.parse(content);
63
+ return Boolean(data.workspaces);
64
+ } catch (error) {
65
+ throw new Error(
66
+ `Failed to parse package.json file while searching for root, ${error}`
67
+ );
68
+ }
69
+ }) ?? targetDir;
70
+ }
71
+ return targetRoot;
72
+ };
73
+ return {
74
+ ownDir,
75
+ get ownRoot() {
76
+ return getOwnRoot();
77
+ },
78
+ targetDir,
79
+ get targetRoot() {
80
+ return getTargetRoot();
81
+ },
82
+ resolveOwn: (...paths) => path.resolve(ownDir, ...paths),
83
+ resolveOwnRoot: (...paths) => path.resolve(getOwnRoot(), ...paths),
84
+ resolveTarget: (...paths) => path.resolve(targetDir, ...paths),
85
+ resolveTargetRoot: (...paths) => path.resolve(getTargetRoot(), ...paths)
86
+ };
87
+ }
88
+ const BACKSTAGE_JSON = "backstage.json";
89
+
90
+ exports.BACKSTAGE_JSON = BACKSTAGE_JSON;
91
+ exports.findOwnDir = findOwnDir;
92
+ exports.findOwnRootDir = findOwnRootDir;
93
+ exports.findPaths = findPaths;
94
+ exports.findRootPath = findRootPath;
95
+ //# sourceMappingURL=paths.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.cjs.js","sources":["../src/paths.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs';\nimport { dirname, resolve as resolvePath } from 'path';\n\n/**\n * A function that takes a set of path fragments and resolves them into a\n * single complete path, relative to some root.\n *\n * @public\n */\nexport type ResolveFunc = (...paths: string[]) => string;\n\n/**\n * Common paths and resolve functions used by the cli.\n * Currently assumes it is being executed within a monorepo.\n *\n * @public\n */\nexport type Paths = {\n // Root dir of the cli itself, containing package.json\n ownDir: string;\n\n // Monorepo root dir of the cli itself. Only accessible when running inside Backstage repo.\n ownRoot: string;\n\n // The location of the app that the cli is being executed in\n targetDir: string;\n\n // The monorepo root package of the app that the cli is being executed in.\n targetRoot: string;\n\n // Resolve a path relative to own repo\n resolveOwn: ResolveFunc;\n\n // Resolve a path relative to own monorepo root. Only accessible when running inside Backstage repo.\n resolveOwnRoot: ResolveFunc;\n\n // Resolve a path relative to the app\n resolveTarget: ResolveFunc;\n\n // Resolve a path relative to the app repo root\n resolveTargetRoot: ResolveFunc;\n};\n\n// Looks for a package.json with a workspace config to identify the root of the monorepo\nexport function findRootPath(\n searchDir: string,\n filterFunc: (pkgJsonPath: string) => boolean,\n): string | undefined {\n let path = searchDir;\n\n // Some confidence check to avoid infinite loop\n for (let i = 0; i < 1000; i++) {\n const packagePath = resolvePath(path, 'package.json');\n const exists = fs.existsSync(packagePath);\n if (exists && filterFunc(packagePath)) {\n return path;\n }\n\n const newPath = dirname(path);\n if (newPath === path) {\n return undefined;\n }\n path = newPath;\n }\n\n throw new Error(\n `Iteration limit reached when searching for root package.json at ${searchDir}`,\n );\n}\n\n// Finds the root of a given package\nexport function findOwnDir(searchDir: string) {\n const path = findRootPath(searchDir, () => true);\n if (!path) {\n throw new Error(\n `No package.json found while searching for package root of ${searchDir}`,\n );\n }\n return path;\n}\n\n// Finds the root of the monorepo that the package exists in. Only accessible when running inside Backstage repo.\nexport function findOwnRootDir(ownDir: string) {\n const isLocal = fs.existsSync(resolvePath(ownDir, 'src'));\n if (!isLocal) {\n throw new Error(\n 'Tried to access monorepo package root dir outside of Backstage repository',\n );\n }\n\n return resolvePath(ownDir, '../..');\n}\n\n/**\n * Find paths related to a package and its execution context.\n *\n * @public\n * @example\n *\n * const paths = findPaths(__dirname)\n */\nexport function findPaths(searchDir: string): Paths {\n const ownDir = findOwnDir(searchDir);\n // Drive letter can end up being lowercased here on Windows, bring back to uppercase for consistency\n const targetDir = fs\n .realpathSync(process.cwd())\n .replace(/^[a-z]:/, str => str.toLocaleUpperCase('en-US'));\n\n // Lazy load this as it will throw an error if we're not inside the Backstage repo.\n let ownRoot = '';\n const getOwnRoot = () => {\n if (!ownRoot) {\n ownRoot = findOwnRootDir(ownDir);\n }\n return ownRoot;\n };\n\n // We're not always running in a monorepo, so we lazy init this to only crash commands\n // that require a monorepo when we're not in one.\n let targetRoot = '';\n const getTargetRoot = () => {\n if (!targetRoot) {\n targetRoot =\n findRootPath(targetDir, path => {\n try {\n const content = fs.readFileSync(path, 'utf8');\n const data = JSON.parse(content);\n return Boolean(data.workspaces);\n } catch (error) {\n throw new Error(\n `Failed to parse package.json file while searching for root, ${error}`,\n );\n }\n }) ?? targetDir; // We didn't find any root package.json, assume we're not in a monorepo\n }\n return targetRoot;\n };\n\n return {\n ownDir,\n get ownRoot() {\n return getOwnRoot();\n },\n targetDir,\n get targetRoot() {\n return getTargetRoot();\n },\n resolveOwn: (...paths) => resolvePath(ownDir, ...paths),\n resolveOwnRoot: (...paths) => resolvePath(getOwnRoot(), ...paths),\n resolveTarget: (...paths) => resolvePath(targetDir, ...paths),\n resolveTargetRoot: (...paths) => resolvePath(getTargetRoot(), ...paths),\n };\n}\n\n/**\n * The name of the backstage's config file\n *\n * @public\n */\nexport const BACKSTAGE_JSON = 'backstage.json';\n"],"names":["path","resolvePath","fs","dirname"],"mappings":";;;;;;;;;AA4DgB,SAAA,YAAA,CACd,WACA,UACoB,EAAA;AACpB,EAAA,IAAIA,MAAO,GAAA,SAAA;AAGX,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,GAAA,EAAM,CAAK,EAAA,EAAA;AAC7B,IAAM,MAAA,WAAA,GAAcC,YAAY,CAAAD,MAAA,EAAM,cAAc,CAAA;AACpD,IAAM,MAAA,MAAA,GAASE,mBAAG,CAAA,UAAA,CAAW,WAAW,CAAA;AACxC,IAAI,IAAA,MAAA,IAAU,UAAW,CAAA,WAAW,CAAG,EAAA;AACrC,MAAO,OAAAF,MAAA;AAAA;AAGT,IAAM,MAAA,OAAA,GAAUG,aAAQH,MAAI,CAAA;AAC5B,IAAA,IAAI,YAAYA,MAAM,EAAA;AACpB,MAAO,OAAA,KAAA,CAAA;AAAA;AAET,IAAOA,MAAA,GAAA,OAAA;AAAA;AAGT,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,mEAAmE,SAAS,CAAA;AAAA,GAC9E;AACF;AAGO,SAAS,WAAW,SAAmB,EAAA;AAC5C,EAAA,MAAM,IAAO,GAAA,YAAA,CAAa,SAAW,EAAA,MAAM,IAAI,CAAA;AAC/C,EAAA,IAAI,CAAC,IAAM,EAAA;AACT,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,6DAA6D,SAAS,CAAA;AAAA,KACxE;AAAA;AAEF,EAAO,OAAA,IAAA;AACT;AAGO,SAAS,eAAe,MAAgB,EA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AA,UAAA;AAAA,GACT;AAEA,EAAO,OAAA;AAAA,IACL,MAAA;AAAA,IACA,IAAI,OAAU,GAAA;AACZ,MAAA,OAAO,UAAW,EAAA;AAAA,KACpB;AAAA,IACA,SAAA;AAAA,IACA,IAAI,UAAa,GAAA;AACf,MAAA,OAAO,aAAc,EAAA;AAAA,KACvB;AAAA,IACA,YAAY,CAAI,GAAA,KAAA,KAAUD,YAAY,CAAA,MAAA,EAAQ,GAAG,KAAK,CAAA;AAAA,IACtD,gBAAgB,CAAI,GAAA,KAAA,KAAUA,aAAY,UAAW,EAAA,EAAG,GAAG,KAAK,CAAA;AAAA,IAChE,eAAe,CAAI,GAAA,KAAA,KAAUA,YAAY,CAAA,SAAA,EAAW,GAAG,KAAK,CAAA;AAAA,IAC5D,mBAAmB,CAAI,GAAA,KAAA,KAAUA,aAAY,aAAc,EAAA,EAAG,GAAG,KAAK;AAAA,GACxE;AACF;AAOO,MAAM,cAAiB,GAAA;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/cli-common",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "Common functionality used by cli, backend, and create-app",
5
5
  "backstage": {
6
6
  "role": "node-library"
@@ -35,7 +35,14 @@
35
35
  "test": "backstage-cli package test"
36
36
  },
37
37
  "devDependencies": {
38
- "@backstage/cli": "^0.26.7",
39
- "@types/node": "^18.17.8"
38
+ "@backstage/cli": "^0.29.0",
39
+ "@types/node": "^20.16.0"
40
+ },
41
+ "typesVersions": {
42
+ "*": {
43
+ "index": [
44
+ "dist/index.d.ts"
45
+ ]
46
+ }
40
47
  }
41
48
  }