@cedarjs/cli-helpers 0.0.4

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 (124) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/auth/authFiles.d.ts +44 -0
  4. package/dist/auth/authFiles.d.ts.map +1 -0
  5. package/dist/auth/authFiles.js +74 -0
  6. package/dist/auth/authTasks.d.ts +49 -0
  7. package/dist/auth/authTasks.d.ts.map +1 -0
  8. package/dist/auth/authTasks.js +345 -0
  9. package/dist/auth/setupHelpers.d.ts +26 -0
  10. package/dist/auth/setupHelpers.d.ts.map +1 -0
  11. package/dist/auth/setupHelpers.js +127 -0
  12. package/dist/build.d.ts +2 -0
  13. package/dist/build.d.ts.map +1 -0
  14. package/dist/cjs/auth/authFiles.d.ts +44 -0
  15. package/dist/cjs/auth/authFiles.d.ts.map +1 -0
  16. package/dist/cjs/auth/authFiles.js +109 -0
  17. package/dist/cjs/auth/authTasks.d.ts +49 -0
  18. package/dist/cjs/auth/authTasks.d.ts.map +1 -0
  19. package/dist/cjs/auth/authTasks.js +384 -0
  20. package/dist/cjs/auth/setupHelpers.d.ts +26 -0
  21. package/dist/cjs/auth/setupHelpers.d.ts.map +1 -0
  22. package/dist/cjs/auth/setupHelpers.js +151 -0
  23. package/dist/cjs/index.d.ts +12 -0
  24. package/dist/cjs/index.d.ts.map +1 -0
  25. package/dist/cjs/index.js +52 -0
  26. package/dist/cjs/lib/colors.d.ts +23 -0
  27. package/dist/cjs/lib/colors.d.ts.map +1 -0
  28. package/dist/cjs/lib/colors.js +52 -0
  29. package/dist/cjs/lib/index.d.ts +21 -0
  30. package/dist/cjs/lib/index.d.ts.map +1 -0
  31. package/dist/cjs/lib/index.js +140 -0
  32. package/dist/cjs/lib/installHelpers.d.ts +17 -0
  33. package/dist/cjs/lib/installHelpers.d.ts.map +1 -0
  34. package/dist/cjs/lib/installHelpers.js +72 -0
  35. package/dist/cjs/lib/loadEnvFiles.d.ts +5 -0
  36. package/dist/cjs/lib/loadEnvFiles.d.ts.map +1 -0
  37. package/dist/cjs/lib/loadEnvFiles.js +101 -0
  38. package/dist/cjs/lib/paths.d.ts +6 -0
  39. package/dist/cjs/lib/paths.d.ts.map +1 -0
  40. package/dist/cjs/lib/paths.js +42 -0
  41. package/dist/cjs/lib/project.d.ts +42 -0
  42. package/dist/cjs/lib/project.d.ts.map +1 -0
  43. package/dist/cjs/lib/project.js +265 -0
  44. package/dist/cjs/lib/version.d.ts +17 -0
  45. package/dist/cjs/lib/version.d.ts.map +1 -0
  46. package/dist/cjs/lib/version.js +107 -0
  47. package/dist/cjs/package.json +1 -0
  48. package/dist/cjs/telemetry/index.d.ts +20 -0
  49. package/dist/cjs/telemetry/index.d.ts.map +1 -0
  50. package/dist/cjs/telemetry/index.js +62 -0
  51. package/dist/index.d.ts +12 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +20 -0
  54. package/dist/lib/colors.d.ts +23 -0
  55. package/dist/lib/colors.d.ts.map +1 -0
  56. package/dist/lib/colors.js +18 -0
  57. package/dist/lib/index.d.ts +21 -0
  58. package/dist/lib/index.d.ts.map +1 -0
  59. package/dist/lib/index.js +102 -0
  60. package/dist/lib/installHelpers.d.ts +17 -0
  61. package/dist/lib/installHelpers.d.ts.map +1 -0
  62. package/dist/lib/installHelpers.js +35 -0
  63. package/dist/lib/loadEnvFiles.d.ts +5 -0
  64. package/dist/lib/loadEnvFiles.d.ts.map +1 -0
  65. package/dist/lib/loadEnvFiles.js +64 -0
  66. package/dist/lib/paths.d.ts +6 -0
  67. package/dist/lib/paths.d.ts.map +1 -0
  68. package/dist/lib/paths.js +18 -0
  69. package/dist/lib/project.d.ts +42 -0
  70. package/dist/lib/project.d.ts.map +1 -0
  71. package/dist/lib/project.js +227 -0
  72. package/dist/lib/version.d.ts +17 -0
  73. package/dist/lib/version.d.ts.map +1 -0
  74. package/dist/lib/version.js +73 -0
  75. package/dist/package.json +1 -0
  76. package/dist/src/auth/__tests__/authFiles.test.d.ts +2 -0
  77. package/dist/src/auth/__tests__/authFiles.test.d.ts.map +1 -0
  78. package/dist/src/auth/__tests__/authTasks.test.d.ts +2 -0
  79. package/dist/src/auth/__tests__/authTasks.test.d.ts.map +1 -0
  80. package/dist/src/auth/__tests__/mockFsFiles.d.ts +14 -0
  81. package/dist/src/auth/__tests__/mockFsFiles.d.ts.map +1 -0
  82. package/dist/src/auth/__tests__/setupHelpers.test.d.ts +2 -0
  83. package/dist/src/auth/__tests__/setupHelpers.test.d.ts.map +1 -0
  84. package/dist/src/auth/authFiles.d.ts +44 -0
  85. package/dist/src/auth/authFiles.d.ts.map +1 -0
  86. package/dist/src/auth/authTasks.d.ts +49 -0
  87. package/dist/src/auth/authTasks.d.ts.map +1 -0
  88. package/dist/src/auth/setupHelpers.d.ts +26 -0
  89. package/dist/src/auth/setupHelpers.d.ts.map +1 -0
  90. package/dist/src/index.d.ts +12 -0
  91. package/dist/src/index.d.ts.map +1 -0
  92. package/dist/src/lib/__tests__/index.test.d.ts +2 -0
  93. package/dist/src/lib/__tests__/index.test.d.ts.map +1 -0
  94. package/dist/src/lib/__tests__/loadEnvFiles.test.d.ts +2 -0
  95. package/dist/src/lib/__tests__/loadEnvFiles.test.d.ts.map +1 -0
  96. package/dist/src/lib/__tests__/project.addTomlSetting.test.d.ts +2 -0
  97. package/dist/src/lib/__tests__/project.addTomlSetting.test.d.ts.map +1 -0
  98. package/dist/src/lib/__tests__/project.test.d.ts +2 -0
  99. package/dist/src/lib/__tests__/project.test.d.ts.map +1 -0
  100. package/dist/src/lib/__tests__/version.test.d.ts +2 -0
  101. package/dist/src/lib/__tests__/version.test.d.ts.map +1 -0
  102. package/dist/src/lib/colors.d.ts +23 -0
  103. package/dist/src/lib/colors.d.ts.map +1 -0
  104. package/dist/src/lib/index.d.ts +21 -0
  105. package/dist/src/lib/index.d.ts.map +1 -0
  106. package/dist/src/lib/installHelpers.d.ts +17 -0
  107. package/dist/src/lib/installHelpers.d.ts.map +1 -0
  108. package/dist/src/lib/loadEnvFiles.d.ts +5 -0
  109. package/dist/src/lib/loadEnvFiles.d.ts.map +1 -0
  110. package/dist/src/lib/paths.d.ts +6 -0
  111. package/dist/src/lib/paths.d.ts.map +1 -0
  112. package/dist/src/lib/project.d.ts +42 -0
  113. package/dist/src/lib/project.d.ts.map +1 -0
  114. package/dist/src/lib/version.d.ts +17 -0
  115. package/dist/src/lib/version.d.ts.map +1 -0
  116. package/dist/src/telemetry/index.d.ts +20 -0
  117. package/dist/src/telemetry/index.d.ts.map +1 -0
  118. package/dist/telemetry/index.d.ts +20 -0
  119. package/dist/telemetry/index.d.ts.map +1 -0
  120. package/dist/telemetry/index.js +27 -0
  121. package/dist/tsconfig.tsbuildinfo +1 -0
  122. package/dist/vitest.config.d.mts +3 -0
  123. package/dist/vitest.config.d.mts.map +1 -0
  124. package/package.json +91 -0
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var project_exports = {};
30
+ __export(project_exports, {
31
+ addEnvVar: () => addEnvVar,
32
+ addEnvVarTask: () => addEnvVarTask,
33
+ getGraphqlPath: () => getGraphqlPath,
34
+ getInstalledRedwoodVersion: () => getInstalledRedwoodVersion,
35
+ graphFunctionDoesExist: () => graphFunctionDoesExist,
36
+ isTypeScriptProject: () => isTypeScriptProject,
37
+ setRedwoodCWD: () => setRedwoodCWD,
38
+ setTomlSetting: () => setTomlSetting,
39
+ updateTomlConfig: () => updateTomlConfig,
40
+ updateTomlConfigTask: () => updateTomlConfigTask
41
+ });
42
+ module.exports = __toCommonJS(project_exports);
43
+ var fs = __toESM(require("node:fs"), 1);
44
+ var path = __toESM(require("node:path"), 1);
45
+ var import_dotenv = __toESM(require("dotenv"), 1);
46
+ var toml = __toESM(require("smol-toml"), 1);
47
+ var import_project_config = require("@cedarjs/project-config");
48
+ var import_colors = require("./colors.js");
49
+ var import_paths = require("./paths.js");
50
+ const getGraphqlPath = () => {
51
+ return (0, import_project_config.resolveFile)(path.join((0, import_paths.getPaths)().api.functions, "graphql"));
52
+ };
53
+ const graphFunctionDoesExist = () => {
54
+ const graphqlPath = getGraphqlPath();
55
+ return graphqlPath && fs.existsSync(graphqlPath);
56
+ };
57
+ const isTypeScriptProject = () => {
58
+ const paths = (0, import_paths.getPaths)();
59
+ return fs.existsSync(path.join(paths.web.base, "tsconfig.json")) || fs.existsSync(path.join(paths.api.base, "tsconfig.json"));
60
+ };
61
+ const getInstalledRedwoodVersion = () => {
62
+ try {
63
+ const packageJson = require("../../package.json");
64
+ return packageJson.version;
65
+ } catch {
66
+ console.error(import_colors.colors.error("Could not find installed Cedar version"));
67
+ process.exit(1);
68
+ }
69
+ };
70
+ const updateTomlConfig = (packageName) => {
71
+ const redwoodTomlPath = (0, import_project_config.getConfigPath)();
72
+ const originalTomlContent = fs.readFileSync(redwoodTomlPath, "utf-8");
73
+ let tomlToAppend = {};
74
+ const config = (0, import_project_config.getConfig)(redwoodTomlPath);
75
+ const cliSection = config.experimental?.cli;
76
+ if (!cliSection) {
77
+ tomlToAppend = {
78
+ experimental: {
79
+ cli: {
80
+ autoInstall: true,
81
+ plugins: [{ package: packageName, enabled: true }]
82
+ }
83
+ }
84
+ };
85
+ } else if (cliSection.plugins) {
86
+ const packageExists = cliSection.plugins.some(
87
+ (plugin) => plugin.package === packageName
88
+ );
89
+ if (!packageExists) {
90
+ tomlToAppend = {
91
+ experimental: {
92
+ cli: {
93
+ plugins: [{ package: packageName, enabled: true }]
94
+ }
95
+ }
96
+ };
97
+ }
98
+ } else {
99
+ tomlToAppend = {
100
+ experimental: {
101
+ cli: {
102
+ plugins: [{ package: packageName, enabled: true }]
103
+ }
104
+ }
105
+ };
106
+ }
107
+ const newConfig = originalTomlContent + "\n" + (Object.keys(tomlToAppend).length > 0 ? toml.stringify(tomlToAppend) + "\n" : "");
108
+ return fs.writeFileSync(redwoodTomlPath, newConfig, "utf-8");
109
+ };
110
+ const updateTomlConfigTask = (packageName) => {
111
+ return {
112
+ title: `Updating redwood.toml to configure ${packageName} ...`,
113
+ task: () => {
114
+ updateTomlConfig(packageName);
115
+ }
116
+ };
117
+ };
118
+ const addEnvVarTask = (name, value, comment) => {
119
+ return {
120
+ title: `Adding ${name} var to .env...`,
121
+ task: () => {
122
+ addEnvVar(name, value, comment);
123
+ }
124
+ };
125
+ };
126
+ const addEnvVar = (name, value, comment) => {
127
+ const envPath = path.join((0, import_paths.getPaths)().base, ".env");
128
+ let envFile = "";
129
+ const newEnvironmentVariable = [
130
+ comment && `# ${comment}`,
131
+ `${name}=${value}`,
132
+ ""
133
+ ].flat().join("\n");
134
+ if (fs.existsSync(envPath)) {
135
+ envFile = fs.readFileSync(envPath).toString();
136
+ const existingEnvVars = import_dotenv.default.parse(envFile);
137
+ if (existingEnvVars[name] && existingEnvVars[name] === value) {
138
+ return envFile;
139
+ }
140
+ if (existingEnvVars[name]) {
141
+ const p = [
142
+ `# Note: The existing environment variable ${name} was not overwritten. Uncomment to use its new value.`,
143
+ comment && `# ${comment}`,
144
+ `# ${name}=${value}`,
145
+ ""
146
+ ].flat().join("\n");
147
+ envFile += "\n" + p;
148
+ } else {
149
+ envFile += "\n" + newEnvironmentVariable;
150
+ }
151
+ } else {
152
+ envFile = newEnvironmentVariable;
153
+ }
154
+ return fs.writeFileSync(envPath, envFile);
155
+ };
156
+ const setRedwoodCWD = (cwd) => {
157
+ cwd ??= process.env.RWJS_CWD;
158
+ if (cwd) {
159
+ if (!fs.existsSync(path.join(cwd, "redwood.toml"))) {
160
+ throw new Error(`Couldn't find a "redwood.toml" file in ${cwd}`);
161
+ }
162
+ } else {
163
+ const redwoodTOMLPath = (0, import_project_config.findUp)("redwood.toml", process.cwd());
164
+ if (!redwoodTOMLPath) {
165
+ throw new Error(
166
+ `Couldn't find up a "redwood.toml" file from ${process.cwd()}`
167
+ );
168
+ }
169
+ if (redwoodTOMLPath) {
170
+ cwd = path.dirname(redwoodTOMLPath);
171
+ }
172
+ }
173
+ process.env.RWJS_CWD = cwd;
174
+ };
175
+ function setTomlSetting(section, setting, value) {
176
+ const redwoodTomlPath = (0, import_project_config.getConfigPath)();
177
+ const originalTomlContent = fs.readFileSync(redwoodTomlPath, "utf-8");
178
+ const redwoodTomlObject = toml.parse(originalTomlContent);
179
+ const sectionValue = redwoodTomlObject[section];
180
+ const existingValue = (
181
+ // I don't like this type cast, but I couldn't come up with a much better
182
+ // solution
183
+ sectionValue?.[setting]
184
+ );
185
+ if (existingValue === value) {
186
+ return;
187
+ }
188
+ let newTomlContent = originalTomlContent.replace(/\n$/, "") + `
189
+
190
+ [${section}]
191
+ ${setting} = ${value}`;
192
+ const hasExistingSettingSection = !!redwoodTomlObject?.[section];
193
+ if (hasExistingSettingSection) {
194
+ const existingSectionSettings = Object.keys(redwoodTomlObject[section]);
195
+ let inSection = false;
196
+ let indentation = "";
197
+ let insertionIndex = 1;
198
+ let updateExistingValue = false;
199
+ let updateExistingCommentedValue = false;
200
+ const tomlLines = originalTomlContent.split("\n");
201
+ tomlLines.forEach((line, index) => {
202
+ if (line.startsWith(`[${section}]`)) {
203
+ inSection = true;
204
+ insertionIndex = index + 1;
205
+ } else {
206
+ if (/^\s*\[/.test(line)) {
207
+ inSection = false;
208
+ }
209
+ if (inSection && !updateExistingValue) {
210
+ for (const existingSectionSetting of existingSectionSettings) {
211
+ const matches = line.match(
212
+ new RegExp(`^(\\s*)${existingSectionSetting}\\s*=`, "i")
213
+ );
214
+ if (!updateExistingValue && matches) {
215
+ if (!updateExistingCommentedValue) {
216
+ indentation = matches[1];
217
+ }
218
+ if (existingSectionSetting === setting) {
219
+ updateExistingValue = true;
220
+ insertionIndex = index;
221
+ indentation = matches[1];
222
+ }
223
+ }
224
+ if (!updateExistingValue && !updateExistingCommentedValue && /^\s*\w+\s*=/.test(line)) {
225
+ insertionIndex = index + 1;
226
+ }
227
+ }
228
+ if (!updateExistingValue) {
229
+ const matchesComment = line.match(
230
+ new RegExp(`^(\\s*)#(\\s*)${setting}\\s*=`, "i")
231
+ );
232
+ if (matchesComment) {
233
+ const commentIndentation = matchesComment[1].length > matchesComment[2].length ? matchesComment[1] : matchesComment[2];
234
+ if (commentIndentation.length - 1 > indentation.length) {
235
+ indentation = commentIndentation;
236
+ }
237
+ updateExistingCommentedValue = true;
238
+ insertionIndex = index;
239
+ }
240
+ }
241
+ }
242
+ }
243
+ });
244
+ tomlLines.splice(
245
+ insertionIndex,
246
+ updateExistingValue || updateExistingCommentedValue ? 1 : 0,
247
+ `${indentation}${setting} = ${value}`
248
+ );
249
+ newTomlContent = tomlLines.join("\n");
250
+ }
251
+ fs.writeFileSync(redwoodTomlPath, newTomlContent);
252
+ }
253
+ // Annotate the CommonJS export names for ESM import in node:
254
+ 0 && (module.exports = {
255
+ addEnvVar,
256
+ addEnvVarTask,
257
+ getGraphqlPath,
258
+ getInstalledRedwoodVersion,
259
+ graphFunctionDoesExist,
260
+ isTypeScriptProject,
261
+ setRedwoodCWD,
262
+ setTomlSetting,
263
+ updateTomlConfig,
264
+ updateTomlConfigTask
265
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Check if the package at the given version is compatible with the current version of the user's RedwoodJS project. This is
3
+ * determined by checking if the package's engines.redwoodjs field intersects with the user's RedwoodJS version.
4
+ *
5
+ * If the preferred version is not compatible, the latest compatible version will be returned if one exists.
6
+ */
7
+ export declare function getCompatibilityData(packageName: string, preferredVersionOrTag: string): Promise<{
8
+ preferred: {
9
+ tag: string | undefined;
10
+ version: string;
11
+ };
12
+ compatible: {
13
+ tag: string | undefined;
14
+ version: string;
15
+ };
16
+ }>;
17
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,MAAM,EACnB,qBAAqB,EAAE,MAAM;;;;;;;;;GA2F9B"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var version_exports = {};
30
+ __export(version_exports, {
31
+ getCompatibilityData: () => getCompatibilityData
32
+ });
33
+ module.exports = __toCommonJS(version_exports);
34
+ var import_fs = __toESM(require("fs"), 1);
35
+ var import_path = __toESM(require("path"), 1);
36
+ var import_semver = __toESM(require("semver"), 1);
37
+ var import_project_config = require("@cedarjs/project-config");
38
+ function getCorrespondingTag(version, distTags) {
39
+ return Object.entries(distTags).find(([_, v]) => v === version)?.[0];
40
+ }
41
+ async function getCompatibilityData(packageName, preferredVersionOrTag) {
42
+ const projectPackageJson = JSON.parse(
43
+ import_fs.default.readFileSync(import_path.default.join((0, import_project_config.getPaths)().base, "package.json"), {
44
+ encoding: "utf8"
45
+ })
46
+ );
47
+ const projectRedwoodVersion = projectPackageJson.devDependencies["@cedarjs/core"];
48
+ const semverVersion = import_semver.default.parse(preferredVersionOrTag);
49
+ const isUsingTag = semverVersion === null;
50
+ const res = await fetch(`https://registry.npmjs.org/${packageName}`);
51
+ const packument = await res.json();
52
+ if (packument.error !== void 0) {
53
+ throw new Error(packument.error);
54
+ }
55
+ if (isUsingTag) {
56
+ if (packument["dist-tags"][preferredVersionOrTag] === void 0) {
57
+ throw new Error(
58
+ `The package '${packageName}' does not have a tag '${preferredVersionOrTag}'`
59
+ );
60
+ }
61
+ } else {
62
+ if (packument.versions[preferredVersionOrTag] === void 0) {
63
+ throw new Error(
64
+ `The package '${packageName}' does not have a version '${preferredVersionOrTag}'`
65
+ );
66
+ }
67
+ }
68
+ const preferredVersion = isUsingTag ? packument["dist-tags"][preferredVersionOrTag] : preferredVersionOrTag;
69
+ const packageRedwoodSpecification = packument.versions[preferredVersion].engines?.redwoodjs;
70
+ if (packageRedwoodSpecification !== void 0 && import_semver.default.intersects(projectRedwoodVersion, packageRedwoodSpecification)) {
71
+ const tag = getCorrespondingTag(preferredVersion, packument["dist-tags"]);
72
+ return {
73
+ preferred: {
74
+ tag,
75
+ version: preferredVersion
76
+ },
77
+ compatible: {
78
+ tag,
79
+ version: preferredVersion
80
+ }
81
+ };
82
+ }
83
+ const versions = import_semver.default.sort(Object.keys(packument.versions));
84
+ for (let i = versions.length - 1; i >= 0; i--) {
85
+ const redwoodVersionRequired = packument.versions[versions[i]].engines?.redwoodjs;
86
+ if (redwoodVersionRequired === void 0) {
87
+ continue;
88
+ }
89
+ if (import_semver.default.intersects(projectRedwoodVersion, redwoodVersionRequired)) {
90
+ return {
91
+ preferred: {
92
+ tag: getCorrespondingTag(preferredVersion, packument["dist-tags"]),
93
+ version: preferredVersion
94
+ },
95
+ compatible: {
96
+ tag: getCorrespondingTag(versions[i], packument["dist-tags"]),
97
+ version: versions[i]
98
+ }
99
+ };
100
+ }
101
+ }
102
+ throw new Error(`No compatible version of '${packageName}' was found`);
103
+ }
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ getCompatibilityData
107
+ });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,20 @@
1
+ import type { AttributeValue, Span } from '@opentelemetry/api';
2
+ type TelemetryAttributes = {
3
+ [key: string]: AttributeValue;
4
+ };
5
+ /**
6
+ * Safely records attributes to the opentelemetry span
7
+ *
8
+ * @param attributes An object of key-value pairs to be individually recorded as attributes
9
+ * @param span An optional span to record the attributes to. If not provided, the current active span will be used
10
+ */
11
+ export declare function recordTelemetryAttributes(attributes: TelemetryAttributes, span?: Span): void;
12
+ /**
13
+ * Safely records an error to the opentelemetry span
14
+ *
15
+ * @param error An error to record to the span
16
+ * @param span An optional span to record the error to. If not provided, the current active span will be used
17
+ */
18
+ export declare function recordTelemetryError(error: any, span?: Span): void;
19
+ export {};
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/telemetry/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AAG9D,KAAK,mBAAmB,GAAG;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;CAC9B,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,mBAAmB,EAC/B,IAAI,CAAC,EAAE,IAAI,QASZ;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,IAAI,QAe3D"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var telemetry_exports = {};
30
+ __export(telemetry_exports, {
31
+ recordTelemetryAttributes: () => recordTelemetryAttributes,
32
+ recordTelemetryError: () => recordTelemetryError
33
+ });
34
+ module.exports = __toCommonJS(telemetry_exports);
35
+ var import_api = __toESM(require("@opentelemetry/api"), 1);
36
+ function recordTelemetryAttributes(attributes, span) {
37
+ const spanToRecord = span ?? import_api.default.trace.getActiveSpan();
38
+ if (spanToRecord === void 0) {
39
+ return;
40
+ }
41
+ for (const [key, value] of Object.entries(attributes)) {
42
+ spanToRecord.setAttribute(key, value);
43
+ }
44
+ }
45
+ function recordTelemetryError(error, span) {
46
+ const spanToRecord = span ?? import_api.default.trace.getActiveSpan();
47
+ if (spanToRecord === void 0) {
48
+ return;
49
+ }
50
+ const message = error?.message ?? error?.toString() ?? "Unknown error";
51
+ const firstLineOfError = message.split("\n")[0];
52
+ spanToRecord.setStatus({
53
+ code: import_api.SpanStatusCode.ERROR,
54
+ message: firstLineOfError
55
+ });
56
+ spanToRecord.recordException(error ?? new Error(firstLineOfError));
57
+ }
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ recordTelemetryAttributes,
61
+ recordTelemetryError
62
+ });
@@ -0,0 +1,12 @@
1
+ export * from './lib/index.js';
2
+ export * from './lib/colors.js';
3
+ export { loadEnvFiles } from './lib/loadEnvFiles.js';
4
+ export { loadDefaultEnvFiles, loadNodeEnvDerivedEnvFile, loadUserSpecifiedEnvFiles, } from './lib/loadEnvFiles.js';
5
+ export * from './lib/paths.js';
6
+ export * from './lib/project.js';
7
+ export * from './lib/version.js';
8
+ export * from './auth/setupHelpers.js';
9
+ export type { AuthHandlerArgs } from './auth/setupHelpers.js';
10
+ export * from './lib/installHelpers.js';
11
+ export * from './telemetry/index.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,cAAc,yBAAyB,CAAA;AAEvC,cAAc,sBAAsB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ export * from "./lib/index.js";
2
+ export * from "./lib/colors.js";
3
+ import { loadEnvFiles } from "./lib/loadEnvFiles.js";
4
+ import {
5
+ loadDefaultEnvFiles,
6
+ loadNodeEnvDerivedEnvFile,
7
+ loadUserSpecifiedEnvFiles
8
+ } from "./lib/loadEnvFiles.js";
9
+ export * from "./lib/paths.js";
10
+ export * from "./lib/project.js";
11
+ export * from "./lib/version.js";
12
+ export * from "./auth/setupHelpers.js";
13
+ export * from "./lib/installHelpers.js";
14
+ export * from "./telemetry/index.js";
15
+ export {
16
+ loadDefaultEnvFiles,
17
+ loadEnvFiles,
18
+ loadNodeEnvDerivedEnvFile,
19
+ loadUserSpecifiedEnvFiles
20
+ };
@@ -0,0 +1,23 @@
1
+ import chalk from 'chalk';
2
+ /**
3
+ * To keep a consistent color/style palette between cli packages, such as
4
+ * @redwood/cli and @redwood/create-cedar-app, please only use the colors
5
+ * defined here. If you *really* can't find a color that fits your needs,
6
+ * it's better to add it here than to introduce a new one-off color in whatever
7
+ * package you're going to use it in.
8
+ */
9
+ export declare const colors: {
10
+ error: chalk.Chalk;
11
+ warning: chalk.Chalk;
12
+ highlight: chalk.Chalk;
13
+ success: chalk.Chalk;
14
+ info: chalk.Chalk;
15
+ bold: chalk.Chalk;
16
+ underline: chalk.Chalk;
17
+ note: chalk.Chalk;
18
+ tip: chalk.Chalk;
19
+ important: chalk.Chalk;
20
+ caution: chalk.Chalk;
21
+ link: chalk.Chalk;
22
+ };
23
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/lib/colors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB;;;;;;GAMG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;CAalB,CAAA"}
@@ -0,0 +1,18 @@
1
+ import chalk from "chalk";
2
+ const colors = {
3
+ error: chalk.bold.red,
4
+ warning: chalk.hex("#ffa500"),
5
+ highlight: chalk.hex("#ffa500"),
6
+ success: chalk.green,
7
+ info: chalk.grey,
8
+ bold: chalk.bold,
9
+ underline: chalk.underline,
10
+ note: chalk.blue,
11
+ tip: chalk.green,
12
+ important: chalk.magenta,
13
+ caution: chalk.red,
14
+ link: chalk.underline
15
+ };
16
+ export {
17
+ colors
18
+ };
@@ -0,0 +1,21 @@
1
+ import type { ListrTaskWrapper, ListrRenderer } from 'listr2';
2
+ import { Listr } from 'listr2';
3
+ export declare const transformTSToJS: (filename: string, content: string) => string | Promise<string>;
4
+ /**
5
+ * This returns the config present in `prettier.config.js` of a Redwood project.
6
+ */
7
+ export declare const getPrettierOptions: () => Promise<any>;
8
+ export declare const prettify: (templateFilename: string, renderedTemplate: string) => Promise<string>;
9
+ export type ExistingFiles = 'OVERWRITE' | 'SKIP' | 'FAIL';
10
+ export declare const writeFile: <Renderer extends typeof ListrRenderer>(target: string, contents: string, { existingFiles }?: {
11
+ existingFiles?: ExistingFiles;
12
+ }, task?: ListrTaskWrapper<never, Renderer, Renderer>) => void;
13
+ /**
14
+ * Creates a list of tasks that write files to the disk.
15
+ *
16
+ * @param files - {[filepath]: contents}
17
+ */
18
+ export declare const writeFilesTask: <Renderer extends typeof ListrRenderer>(files: Record<string, string>, options: {
19
+ existingFiles: ExistingFiles;
20
+ }) => Listr<never, Renderer, "simple">;
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EAEd,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAU9B,eAAO,MAAM,eAAe,aAAc,MAAM,WAAW,MAAM,6BA8BhE,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,oBAkB9B,CAAA;AAED,eAAO,MAAM,QAAQ,qBACD,MAAM,oBACN,MAAM,KACvB,OAAO,CAAC,MAAM,CAqBhB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,CAAA;AAEzD,eAAO,MAAM,SAAS,GAAI,QAAQ,SAAS,OAAO,aAAa,UACrD,MAAM,YACJ,MAAM,sBACY;IAAE,aAAa,CAAC,EAAE,aAAa,CAAA;CAAE,SAGvD,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,SAwBlD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,SAAS,OAAO,aAAa,SAC3D,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WACpB;IAAE,aAAa,EAAE,aAAa,CAAA;CAAE,qCAuB1C,CAAA"}