@cedarjs/cli-helpers 5.0.4-next.167 → 5.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 (58) hide show
  1. package/dist/auth/authTasks.d.ts.map +1 -1
  2. package/dist/auth/authTasks.js +4 -11
  3. package/dist/cjs/auth/authFiles.d.ts +44 -0
  4. package/dist/cjs/auth/authFiles.d.ts.map +1 -0
  5. package/dist/cjs/auth/authFiles.js +109 -0
  6. package/dist/cjs/auth/authTasks.d.ts +49 -0
  7. package/dist/cjs/auth/authTasks.d.ts.map +1 -0
  8. package/dist/cjs/auth/authTasks.js +384 -0
  9. package/dist/cjs/auth/setupHelpers.d.ts +27 -0
  10. package/dist/cjs/auth/setupHelpers.d.ts.map +1 -0
  11. package/dist/cjs/auth/setupHelpers.js +141 -0
  12. package/dist/cjs/index.d.ts +12 -0
  13. package/dist/cjs/index.d.ts.map +1 -0
  14. package/dist/cjs/index.js +52 -0
  15. package/dist/cjs/lib/colors.d.ts +24 -0
  16. package/dist/cjs/lib/colors.d.ts.map +1 -0
  17. package/dist/cjs/lib/colors.js +52 -0
  18. package/dist/cjs/lib/index.d.ts +22 -0
  19. package/dist/cjs/lib/index.d.ts.map +1 -0
  20. package/dist/cjs/lib/index.js +147 -0
  21. package/dist/cjs/lib/installHelpers.d.ts +17 -0
  22. package/dist/cjs/lib/installHelpers.d.ts.map +1 -0
  23. package/dist/cjs/lib/installHelpers.js +65 -0
  24. package/dist/cjs/lib/loadEnvFiles.d.ts +5 -0
  25. package/dist/cjs/lib/loadEnvFiles.d.ts.map +1 -0
  26. package/dist/cjs/lib/loadEnvFiles.js +99 -0
  27. package/dist/cjs/lib/paths.d.ts +6 -0
  28. package/dist/cjs/lib/paths.d.ts.map +1 -0
  29. package/dist/cjs/lib/paths.js +42 -0
  30. package/dist/cjs/lib/project.d.ts +44 -0
  31. package/dist/cjs/lib/project.d.ts.map +1 -0
  32. package/dist/cjs/lib/project.js +268 -0
  33. package/dist/cjs/lib/version.d.ts +17 -0
  34. package/dist/cjs/lib/version.d.ts.map +1 -0
  35. package/dist/cjs/lib/version.js +107 -0
  36. package/dist/cjs/package.json +1 -0
  37. package/dist/cjs/packageManager/display.d.ts +90 -0
  38. package/dist/cjs/packageManager/display.d.ts.map +1 -0
  39. package/dist/cjs/packageManager/display.js +139 -0
  40. package/dist/cjs/packageManager/exec.d.ts +77 -0
  41. package/dist/cjs/packageManager/exec.d.ts.map +1 -0
  42. package/dist/cjs/packageManager/exec.js +152 -0
  43. package/dist/cjs/packageManager/index.d.ts +13 -0
  44. package/dist/cjs/packageManager/index.d.ts.map +1 -0
  45. package/dist/cjs/packageManager/index.js +73 -0
  46. package/dist/cjs/packageManager/packages.d.ts +39 -0
  47. package/dist/cjs/packageManager/packages.d.ts.map +1 -0
  48. package/dist/cjs/packageManager/packages.js +91 -0
  49. package/dist/cjs/packageManager/workspaces.d.ts +4 -0
  50. package/dist/cjs/packageManager/workspaces.d.ts.map +1 -0
  51. package/dist/cjs/packageManager/workspaces.js +93 -0
  52. package/dist/cjs/telemetry/index.d.ts +20 -0
  53. package/dist/cjs/telemetry/index.d.ts.map +1 -0
  54. package/dist/cjs/telemetry/index.js +64 -0
  55. package/dist/lib/project.d.ts.map +1 -1
  56. package/dist/lib/project.js +1 -2
  57. package/dist/package.json +1 -0
  58. package/package.json +50 -18
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../../src/lib/paths.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,wBAAgB,QAAQ,4CAUvB"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var paths_exports = {};
20
+ __export(paths_exports, {
21
+ getPaths: () => getPaths
22
+ });
23
+ module.exports = __toCommonJS(paths_exports);
24
+ var import_project_config = require("@cedarjs/project-config");
25
+ var import_colors = require("./colors.js");
26
+ function isErrorWithMessage(e) {
27
+ return !!e.message;
28
+ }
29
+ function getPaths() {
30
+ try {
31
+ return (0, import_project_config.getPaths)();
32
+ } catch (e) {
33
+ if (isErrorWithMessage(e)) {
34
+ console.error(import_colors.colors.error(e.message));
35
+ }
36
+ process.exit(1);
37
+ }
38
+ }
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ getPaths
42
+ });
@@ -0,0 +1,44 @@
1
+ import type { Config } from '@cedarjs/project-config';
2
+ export declare const getGraphqlPath: () => string | null;
3
+ export declare const graphFunctionDoesExist: () => boolean | "" | null;
4
+ export declare const isTypeScriptProject: () => boolean;
5
+ export declare const getInstalledRedwoodVersion: () => any;
6
+ /**
7
+ * Updates the project's cedar.toml file to include the specified packages
8
+ * plugin
9
+ *
10
+ * Uses toml parsing to determine if the plugin is already included in the file
11
+ * and only adds it if it is not.
12
+ *
13
+ * Writes the updated config to the file system by appending strings, not
14
+ * stringify-ing the toml.
15
+ */
16
+ export declare const updateTomlConfig: (packageName: string) => void;
17
+ export declare const updateTomlConfigTask: (packageName: string) => {
18
+ title: string;
19
+ task: () => void;
20
+ };
21
+ export declare const addEnvVarTask: (name: string, value: string, comment: string) => {
22
+ title: string;
23
+ task: () => void;
24
+ };
25
+ export declare const addEnvVar: (name: string, value: string, comment: string) => string | void;
26
+ /**
27
+ * This sets the `CEDAR_CWD` env var to the redwood project directory. This is typically required for internal
28
+ * redwood packages to work correctly. For example, `@cedarjs/project-config` uses this when reading config
29
+ * or paths.
30
+ *
31
+ * @param cwd Explicitly set the redwood cwd. If not set, we'll try to determine it automatically. You likely
32
+ * only want to set this based on some specific input, like a CLI flag.
33
+ */
34
+ export declare function setRedwoodCWD(cwd?: string): void;
35
+ /**
36
+ * Create or update the given setting, in the given section, with the given value.
37
+ *
38
+ * If the section already exists it adds the new setting last
39
+ * If the section, and the setting, already exists, the setting is updated
40
+ * If the section does not exist it is created at the end of the file and the setting is added
41
+ * If the setting exists in the section, but is commented out, it will be uncommented and updated
42
+ */
43
+ export declare function setTomlSetting(section: keyof Config, setting: string, value: string | boolean | number): void;
44
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/lib/project.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAWrD,eAAO,MAAM,cAAc,qBAE1B,CAAA;AAED,eAAO,MAAM,sBAAsB,2BAGlC,CAAA;AAED,eAAO,MAAM,mBAAmB,eAM/B,CAAA;AAED,eAAO,MAAM,0BAA0B,WAQtC,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,GAAI,aAAa,MAAM,SAkDnD,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,aAAa,MAAM;;;CAOvD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,SAAS,MAAM;;;CAOzE,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,SAAS,MAAM,kBAqCrE,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,QAmCzC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,QA0HjC"}
@@ -0,0 +1,268 @@
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 configTomlPath = (0, import_project_config.getConfigPath)();
72
+ const originalTomlContent = fs.readFileSync(configTomlPath, "utf-8");
73
+ let tomlToAppend = {};
74
+ const config = (0, import_project_config.getConfig)();
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(configTomlPath, newConfig, "utf-8");
109
+ };
110
+ const updateTomlConfigTask = (packageName) => {
111
+ return {
112
+ title: `Updating config file 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
+ function setRedwoodCWD(cwd) {
157
+ const configFiles = ["cedar.toml", "redwood.toml"];
158
+ cwd ??= process.env.CEDAR_CWD;
159
+ cwd ??= process.env.RWJS_CWD;
160
+ if (cwd) {
161
+ const absCwd = path.resolve(process.cwd(), cwd);
162
+ const found = configFiles.some((f) => fs.existsSync(path.join(absCwd, f)));
163
+ if (!found) {
164
+ const tomls = configFiles.join('" or "');
165
+ throw new Error(`Couldn't find a "${tomls}" file in ${absCwd}`);
166
+ }
167
+ } else {
168
+ const configTomlPath = (0, import_project_config.findUp)("cedar.toml", process.cwd()) || (0, import_project_config.findUp)("redwood.toml", process.cwd());
169
+ if (!configTomlPath) {
170
+ throw new Error(
171
+ `Couldn't find up a "cedar.toml" or "redwood.toml" file from ${process.cwd()}`
172
+ );
173
+ }
174
+ cwd = path.dirname(configTomlPath);
175
+ }
176
+ process.env.CEDAR_CWD = cwd;
177
+ }
178
+ function setTomlSetting(section, setting, value) {
179
+ const cedarTomlPath = (0, import_project_config.getConfigPath)();
180
+ const originalTomlContent = fs.readFileSync(cedarTomlPath, "utf-8");
181
+ const cedarTomlObject = toml.parse(originalTomlContent);
182
+ const sectionValue = cedarTomlObject[section];
183
+ const existingValue = (
184
+ // I don't like this type cast, but I couldn't come up with a much better
185
+ // solution
186
+ sectionValue?.[setting]
187
+ );
188
+ if (existingValue === value) {
189
+ return;
190
+ }
191
+ let newTomlContent = originalTomlContent.replace(/\n$/, "") + `
192
+
193
+ [${section}]
194
+ ${setting} = ${value}`;
195
+ const hasExistingSettingSection = !!cedarTomlObject?.[section];
196
+ if (hasExistingSettingSection) {
197
+ const existingSectionSettings = Object.keys(cedarTomlObject[section]);
198
+ let inSection = false;
199
+ let indentation = "";
200
+ let insertionIndex = 1;
201
+ let updateExistingValue = false;
202
+ let updateExistingCommentedValue = false;
203
+ const tomlLines = originalTomlContent.split("\n");
204
+ tomlLines.forEach((line, index) => {
205
+ if (line.startsWith(`[${section}]`)) {
206
+ inSection = true;
207
+ insertionIndex = index + 1;
208
+ } else {
209
+ if (/^\s*\[/.test(line)) {
210
+ inSection = false;
211
+ }
212
+ if (inSection && !updateExistingValue) {
213
+ for (const existingSectionSetting of existingSectionSettings) {
214
+ const matches = line.match(
215
+ new RegExp(`^(\\s*)${existingSectionSetting}\\s*=`, "i")
216
+ );
217
+ if (!updateExistingValue && matches) {
218
+ if (!updateExistingCommentedValue) {
219
+ indentation = matches[1];
220
+ }
221
+ if (existingSectionSetting === setting) {
222
+ updateExistingValue = true;
223
+ insertionIndex = index;
224
+ indentation = matches[1];
225
+ }
226
+ }
227
+ if (!updateExistingValue && !updateExistingCommentedValue && /^\s*\w+\s*=/.test(line)) {
228
+ insertionIndex = index + 1;
229
+ }
230
+ }
231
+ if (!updateExistingValue) {
232
+ const matchesComment = line.match(
233
+ new RegExp(`^(\\s*)#(\\s*)${setting}\\s*=`, "i")
234
+ );
235
+ if (matchesComment) {
236
+ const commentIndentation = matchesComment[1].length > matchesComment[2].length ? matchesComment[1] : matchesComment[2];
237
+ if (commentIndentation.length - 1 > indentation.length) {
238
+ indentation = commentIndentation;
239
+ }
240
+ updateExistingCommentedValue = true;
241
+ insertionIndex = index;
242
+ }
243
+ }
244
+ }
245
+ }
246
+ });
247
+ tomlLines.splice(
248
+ insertionIndex,
249
+ updateExistingValue || updateExistingCommentedValue ? 1 : 0,
250
+ `${indentation}${setting} = ${value}`
251
+ );
252
+ newTomlContent = tomlLines.join("\n");
253
+ }
254
+ fs.writeFileSync(cedarTomlPath, newTomlContent);
255
+ }
256
+ // Annotate the CommonJS export names for ESM import in node:
257
+ 0 && (module.exports = {
258
+ addEnvVar,
259
+ addEnvVarTask,
260
+ getGraphqlPath,
261
+ getInstalledRedwoodVersion,
262
+ graphFunctionDoesExist,
263
+ isTypeScriptProject,
264
+ setRedwoodCWD,
265
+ setTomlSetting,
266
+ updateTomlConfig,
267
+ updateTomlConfigTask
268
+ });
@@ -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_node_fs = __toESM(require("node: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_node_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,90 @@
1
+ /**
2
+ * Returns the formatted install command for the detected package manager.
3
+ *
4
+ * yarn → `yarn install`
5
+ * npm → `npm install`
6
+ * pnpm → `pnpm install`
7
+ */
8
+ export declare function formatInstallCommand(): string;
9
+ /**
10
+ * Returns a formatted string for running a Cedar CLI command via the detected
11
+ * package manager.
12
+ *
13
+ * npm → `npx cedar <args>`
14
+ * yarn → `yarn cedar <args>`
15
+ * pnpm → `pnpm cedar <args>`
16
+ */
17
+ export declare function formatCedarCommand(args: string[]): string;
18
+ /**
19
+ * Returns a formatted string for running a package.json script via the
20
+ * detected package manager.
21
+ *
22
+ * npm → `npm run <script>[ -- args]`
23
+ * yarn → `yarn <script> [args]`
24
+ * pnpm → `pnpm <script> [args]`
25
+ */
26
+ export declare function formatRunScriptCommand(script: string, args?: string[]): string;
27
+ /**
28
+ * Returns a formatted string for running a package.json script in a workspace
29
+ * via the detected package manager.
30
+ *
31
+ * yarn → `yarn workspace <workspace> <script> [args]`
32
+ * npm → `npm run <script> -w <workspace>[ -- args]`
33
+ * pnpm → `pnpm <script> --filter <workspace>[-- args]`
34
+ */
35
+ export declare function formatRunWorkspaceScriptCommand(workspace: string, script: string, args?: string[]): string;
36
+ /**
37
+ * Returns a formatted string for running a local binary (from
38
+ * node_modules/.bin) via the detected package manager.
39
+ *
40
+ * yarn → `yarn <bin> [args]` (PnP-safe)
41
+ * npm → `npx <bin> [args]`
42
+ * pnpm → `pnpm exec <bin> [args]`
43
+ */
44
+ export declare function formatRunBinCommand(bin: string, args?: string[]): string;
45
+ /**
46
+ * Returns a formatted string for running a local binary in a workspace context
47
+ * via the detected package manager.
48
+ *
49
+ * yarn → `yarn workspace <workspace> <bin> [args]`
50
+ * npm → `npm exec -w <workspace> -- <bin> [args]`
51
+ * pnpm → `pnpm exec --filter <workspace> <bin> [args]`
52
+ */
53
+ export declare function formatRunWorkspaceBinCommand(workspace: string, bin: string, args?: string[]): string;
54
+ /**
55
+ * Returns a formatted string for a one-off package execution via the detected
56
+ * package manager.
57
+ *
58
+ * yarn → `yarn dlx <command> [args]`
59
+ * npm → `npx <command> [args]`
60
+ * pnpm → `pnpm dlx <command> [args]`
61
+ */
62
+ export declare function formatDlxCommand(command: string, args?: string[]): string;
63
+ /**
64
+ * Returns a formatted string for adding packages to the project root via the
65
+ * detected package manager.
66
+ *
67
+ * yarn → `yarn add [-D] <packages>`
68
+ * npm → `npm install [-D] <packages>`
69
+ * pnpm → `pnpm add [-D] <packages>`
70
+ */
71
+ export declare function formatAddRootPackagesCommand(packages: string[], dev?: boolean): string;
72
+ /**
73
+ * Returns a formatted string for adding packages to a workspace via the
74
+ * detected package manager.
75
+ *
76
+ * yarn → `yarn workspace <workspace> add [-D] <packages>`
77
+ * npm → `npm install [-D] <packages> -w <workspace>`
78
+ * pnpm → `pnpm add [-D] <packages> --filter <workspace>`
79
+ */
80
+ export declare function formatAddWorkspacePackagesCommand(workspace: string, packages: string[], dev?: boolean): string;
81
+ /**
82
+ * Returns a formatted string for removing packages from a workspace via the
83
+ * detected package manager.
84
+ *
85
+ * yarn → `yarn workspace <workspace> remove <packages>`
86
+ * npm → `npm uninstall <packages> -w <workspace>`
87
+ * pnpm → `pnpm remove <packages> --filter <workspace>`
88
+ */
89
+ export declare function formatRemoveWorkspacePackagesCommand(workspace: string, packages: string[]): string;
90
+ //# sourceMappingURL=display.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../../../src/packageManager/display.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CASzD;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,MAAM,EAAO,GAClB,MAAM,CAUR;AAED;;;;;;;GAOG;AACH,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,MAAM,EAAO,GAClB,MAAM,CAgBR;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,EAAO,GAAG,MAAM,CAa5E;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,MAAM,EAAO,GAClB,MAAM,CAcR;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,EAAO,GAAG,MAAM,CAS7E;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,EAAE,EAClB,GAAG,UAAQ,GACV,MAAM,CAOR;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAAE,EAClB,GAAG,UAAQ,GACV,MAAM,CAeR;AAED;;;;;;;GAOG;AACH,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAAE,GACjB,MAAM,CAcR"}