@cedarjs/codemods 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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +297 -0
  3. package/dist/codemods/list.yargs.js +67 -0
  4. package/dist/codemods/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.js +74 -0
  5. package/dist/codemods/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.yargs.js +51 -0
  6. package/dist/codemods/v2.x.x/configureFastify/configureFastify.js +43 -0
  7. package/dist/codemods/v2.x.x/configureFastify/configureFastify.yargs.js +83 -0
  8. package/dist/codemods/v2.x.x/updateResolverTypes/updateResolverTypes.js +77 -0
  9. package/dist/codemods/v2.x.x/updateResolverTypes/updateResolverTypes.yargs.js +62 -0
  10. package/dist/codemods/v4.2.x/updateClerkGetCurrentUser/updateClerkGetCurrentUser.js +71 -0
  11. package/dist/codemods/v4.2.x/updateClerkGetCurrentUser/updateClerkGetCurrentUser.yargs.js +58 -0
  12. package/dist/codemods/v4.x.x/useArmor/useArmor.js +63 -0
  13. package/dist/codemods/v4.x.x/useArmor/useArmor.yargs.js +62 -0
  14. package/dist/codemods/v5.x.x/cellQueryResult/cellQueryResult.js +110 -0
  15. package/dist/codemods/v5.x.x/cellQueryResult/cellQueryResult.yargs.js +58 -0
  16. package/dist/codemods/v5.x.x/detectEmptyCells/detectEmptyCells.js +88 -0
  17. package/dist/codemods/v5.x.x/detectEmptyCells/detectEmptyCells.yargs.js +59 -0
  18. package/dist/codemods/v5.x.x/renameValidateWith/renameValidateWith.js +32 -0
  19. package/dist/codemods/v5.x.x/renameValidateWith/renameValidateWith.yargs.js +65 -0
  20. package/dist/codemods/v5.x.x/updateAuth0ToV2/updateAuth0ToV2.js +48 -0
  21. package/dist/codemods/v5.x.x/updateAuth0ToV2/updateAuth0ToV2.yargs.js +68 -0
  22. package/dist/codemods/v5.x.x/updateNodeEngineTo18/updateNodeEngineTo18.js +46 -0
  23. package/dist/codemods/v5.x.x/updateNodeEngineTo18/updateNodeEngineTo18.yargs.js +57 -0
  24. package/dist/codemods/v5.x.x/upgradeToReact18/upgradeToReact18.js +135 -0
  25. package/dist/codemods/v5.x.x/upgradeToReact18/upgradeToReact18.yargs.js +56 -0
  26. package/dist/codemods/v6.x.x/changeGlobalToGlobalThis/changeGlobalToGlobalThis.js +29 -0
  27. package/dist/codemods/v6.x.x/changeGlobalToGlobalThis/changeGlobalToGlobalThis.yargs.js +60 -0
  28. package/dist/codemods/v6.x.x/convertJsToJsx/convertJsToJsx.js +45 -0
  29. package/dist/codemods/v6.x.x/convertJsToJsx/convertJsToJsx.yargs.js +59 -0
  30. package/dist/codemods/v6.x.x/entryClientNullCheck/entryClientNullCheck.js +51 -0
  31. package/dist/codemods/v6.x.x/entryClientNullCheck/entryClientNullCheck.yargs.js +60 -0
  32. package/dist/codemods/v6.x.x/processEnvDotNotation/processEnvDotNotation.js +44 -0
  33. package/dist/codemods/v6.x.x/processEnvDotNotation/processEnvDotNotation.yargs.js +60 -0
  34. package/dist/codemods/v6.x.x/replaceComponentSvgs/replaceComponentSvgs.js +154 -0
  35. package/dist/codemods/v6.x.x/replaceComponentSvgs/replaceComponentSvgs.yargs.js +61 -0
  36. package/dist/codemods/v6.x.x/updateDevFatalErrorPage/updateDevFatalErrorPage.js +58 -0
  37. package/dist/codemods/v6.x.x/updateDevFatalErrorPage/updateDevFatalErrorPage.yargs.js +50 -0
  38. package/dist/codemods/v6.x.x/updateThemeConfig/updateThemeConfig.js +51 -0
  39. package/dist/codemods/v6.x.x/updateThemeConfig/updateThemeConfig.yargs.js +61 -0
  40. package/dist/codemods/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.js +51 -0
  41. package/dist/codemods/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.yargs.js +50 -0
  42. package/dist/codemods.js +45 -0
  43. package/dist/lib/cells.js +230 -0
  44. package/dist/lib/fetchFileFromTemplate.js +29 -0
  45. package/dist/lib/getFilesWithPattern.js +51 -0
  46. package/dist/lib/getRootPackageJSON.js +44 -0
  47. package/dist/lib/isTSProject.js +39 -0
  48. package/dist/lib/prettify.js +55 -0
  49. package/dist/lib/runTransform.js +76 -0
  50. package/dist/lib/ts2js.js +57 -0
  51. package/package.json +67 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Cedar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,297 @@
1
+ # Codemods
2
+
3
+ - [Codemods](#codemods)
4
+ - [Purpose and Vision](#purpose-and-vision)
5
+ - [Package Leads](#package-leads)
6
+ - [Contributing](#contributing)
7
+
8
+ ## Purpose and Vision
9
+
10
+ This package contains codemods that automate upgrading a Redwood project.
11
+
12
+ ## Package Leads
13
+
14
+ - Daniel Choudhury (@dac09)
15
+ - Dominic Saadi (@jtoar)
16
+
17
+ ## Usage
18
+
19
+ Listing available codemods:
20
+
21
+ ```shell
22
+ npx @redwoodjs/codemods list v0.38.x
23
+ ```
24
+
25
+ Applying a single one:
26
+
27
+ ```shell
28
+ npx @redwoodjs/codemods add-directives
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Contributing
34
+
35
+ > **Note** that this is a CLI—that is, it's meant to be executed with `npx`. This means the normal contribution flow (using `rwfw`) doesn't apply.
36
+
37
+ You should be familiar with [jscodeshift](https://github.com/facebook/jscodeshift).
38
+ Its API isn't documented too well so we'll try to explain some of it here.
39
+
40
+ Like Babel and ESLint, jscodeshift is all about ASTs.
41
+ The difference is that it's overwriting files.
42
+ That means things that Babel doesn't care about, like spaces, styling (single quotes or double quotes, etc.), all of a sudden matter a lot.
43
+ The parser jscodeshift uses, [recast](https://github.com/benjamn/recast), knows how to preserve these details as much as possible.
44
+
45
+ ### Generating a new Codemod
46
+
47
+ ```shell
48
+ cd packages/codemods
49
+ yarn generate:codemod
50
+ ```
51
+
52
+ Follow the interactive guide to specify the Redwood framework version for the codemod and type of codemod.
53
+
54
+ ### Structure of this package
55
+
56
+ The root of the CLI is run from `src/codemods.ts`, which loads all the available codemods from the `src/codemods/*` folder.
57
+
58
+ Codemods are organised by version. For example, for upgrading from v0.37.x -> v0.38.x, the codemods are in the `src/codemods/v0.38.x` folder.
59
+
60
+ Each codemod has the following files:
61
+
62
+ - README.md—to explain what this codemod does
63
+ - {codemodName}.ts—this is the actual implementation of the codemod. You can export whatever you like here, and use it in the yargs handler
64
+ - {codemodName}.yargs.ts—this is the yargs (CLI) handler that actually invokes your codemod. Each of the yargs handlers should export: `command`, `description` and `handler` at least. More info on how this is handled with yargs `commandDir` here: [Yargs advanced docs](https://github.com/yargs/yargs/blob/main/docs/advanced.md#commanddirdirectory-opts)
65
+ - {codemodName}.test.ts—all jscodeshift codemods should implement a test. They're fairly simple to write. Have a look at the testing section for more details
66
+
67
+ ### Different types of codemods
68
+
69
+ Codemods are sometimes really simple, e.g. just normal string replace or updating a package.json. But other times we use jscodeshift to change code on a redwood project
70
+
71
+ Here are a few different examples to help you get familiarised:
72
+
73
+ - [Rename config in Redwood.toml](packages/codemods/src/codemods/v0.38.x/renameApiProxyPath)—
74
+ Simple string replace on the user's `redwood.toml`. No ASTs, no complications!
75
+
76
+ - [Add Directives](packages/codemods/src/codemods/v0.37.x/addDirectives)—
77
+ Download files from the RedwoodJS template because we've added new files that are needed in a user's project. No ASTs involved
78
+
79
+ - [Update GraphQL Function](packages/codemods/src/codemods/v0.37.x/updateGraphQLFunction)—
80
+ A more complex example, which uses `jscodeshift` and ASTs to update code in a user's project
81
+
82
+ The rest of the docs will focus on the more complex cases (the third example).
83
+
84
+ ### A Typical Transform
85
+
86
+ A typical transform looks something like this:
87
+
88
+ ```typescript
89
+ // fooToBar.ts
90
+
91
+ import type { FileInfo, API } from 'jscodeshift'
92
+
93
+ export default function transform(file: FileInfo, api: API) {
94
+ const j = api.jscodeshift
95
+
96
+ const root = j(file.source)
97
+
98
+ return root.findVariableDeclarators('foo').renameTo('bar').toSource()
99
+ }
100
+ ```
101
+
102
+ You can then run this transform on files via the CLI:
103
+
104
+ ```
105
+ yarn run jscodeshift -t fooToBar.ts foo.js
106
+ ```
107
+
108
+ In this way, jscodeshift is similar to Jest in that it's a runner.
109
+
110
+ > 💡 **Tip**
111
+ >
112
+ > An extremely useful tool to write the actual transform is [ASTExplorer](https://astexplorer.net/).
113
+ > This lets you see how your codemods change input source, in real time!
114
+
115
+ #### The API
116
+
117
+ In the example above, `file` is the file it's running the transformation on
118
+ and `jscodeshift` itself is actually a property of `api`.
119
+ Since it's used so much, you'll see this pattern a lot:
120
+
121
+ ```javascript
122
+ const j = api.jscodeshift
123
+ ```
124
+
125
+ `j` exposes the whole api, but it's also a function—it parses its argument into a `Collection`, jscodeshift's major type. It's similar to a javascript array and has many of the same methods (`forEach`, `map`, etc.).
126
+ The best way to familiarize yourself with its methods is to either 1) look at a bunch of examples or 2) [skim the source](https://github.com/facebook/jscodeshift/blob/main/src/Collection.js).
127
+
128
+ ### Writing a transform
129
+
130
+ When beginning to write a transform, your best bet is to start by pasting the code you want to transform into [AST Explorer](https://astexplorer.net/). Use it to figure out what node you want, and then use one of `jscodeshift`'s `find` methods to find it:
131
+
132
+ ````typescript
133
+ import type { FileInfo, API } from 'jscodeshift'
134
+
135
+ export default function transform(file: FileInfo, api: API) {
136
+ const j = api.jscodeshift
137
+
138
+ const root = j(file.source)
139
+
140
+ /**
141
+ * This finds the line:
142
+ *
143
+ * ```
144
+ * import { ... } from '@cedarjs/router'
145
+ * ```
146
+ */
147
+ return root.find(j.ImportDeclaration, {
148
+ source: {
149
+ type: 'Literal',
150
+ value: '@redwoodjs/router',
151
+ },
152
+ })
153
+ }
154
+ ````
155
+
156
+ Sometimes `jscodeshift` has a more-specific find method than `find`, like `findVariableDeclarators`. Use it when you can—it makes things a lot easier.
157
+ But note that these find methods aren't on `Collection`.
158
+ They're in the extensions:
159
+
160
+ - [Node](https://github.com/facebook/jscodeshift/blob/main/src/collections/Node.js)
161
+ - [JSXElement](https://github.com/facebook/jscodeshift/blob/main/src/collections/JSXElement.js)
162
+ - etc.
163
+
164
+ After you find what you're looking for, you usually want to replace it with something else.
165
+ Again, use AST Explorer to find out what the AST of that something else is.
166
+ Then, instead of using a type (like `j.ImportDeclaration`) to find it, use a builder (like `j.importDeclaration`—it's just the type camelcased) to make it.
167
+
168
+ Again, sometimes jscodeshift has a method that makes this trivial, especially for simple operations, like renaming or removing something (just use `renameTo` or `remove`).
169
+ But sometimes you'll just have to use one of the more generic methods: `replaceWith`, `insertBefore`, `insertAfter`, etc.
170
+
171
+ ## Testing
172
+
173
+ Although jscodeshift has a built-in way of doing testing, we have a slightly different way of testing.
174
+
175
+ There are 3 key test utils you need to be aware of (located in [packages/codemods/testUtils/index.ts](https://github.com/redwoodjs/redwood/blob/main/packages/codemods/testUtils/index.ts)).
176
+
177
+ 1. `matchTransformSnapshot`—this lets you give it a transformName (i.e. the transform you're writing), and a fixtureName. The fixtures should be located in `__testfixtures__`, and have `{fixtureName}.input.{js,ts}` and `{fixtureName}.output.{js,ts}` files.
178
+
179
+ Note that the fixtureName can be anything you want, and you can have multiple fixtures.
180
+
181
+ ```js
182
+ describe('Update API Imports', () => {
183
+ it('Updates @redwoodjs/api imports', async () => {
184
+ await matchTransformSnapshot('updateApiImports', 'apiImports')
185
+ })
186
+ })
187
+ ```
188
+
189
+ 2. `matchInlineTransformSnapshot`—very similar to above, but use this in case you want to just provide your fixtures inline
190
+
191
+ ```js
192
+ it('Modifies imports (inline)', async () => {
193
+ await matchInlineTransformSnapshot(
194
+ 'updateGraphQLFunction', // <--- transform name, so we know which transform to apply
195
+ `import {
196
+ createGraphQLHandler, // <-- input source
197
+ makeMergedSchema,
198
+ } from '@cedarjs/api'`,
199
+ `import { createGraphQLHandler } from '@cedarjs/graphql-server'`, // <-- expected output
200
+ )
201
+ })
202
+ ```
203
+
204
+ 3. `matchFolderTransform` - use this, when you're modifying contents of multiple files, and adding/deleting files from the user's project during the codemod.
205
+
206
+ ```js
207
+ test('Removes babel config for default setup', async () => {
208
+ import transform from '../updateBabelConfig'
209
+
210
+ // pass in your transform here 👇
211
+ await matchFolderTransform(transform, 'my-default-fixture')
212
+ // and tell it which folder to use as fixture here ☝️
213
+ })
214
+ ```
215
+
216
+ In the above example, it will run the transform from `updateBabelConfig` against a fixture located in the `__testfixtures__/my-default-fixture/input` folder and compare with the `__testfixtures__/my-default-fixture/output` folder.
217
+
218
+ The `matchFolderTransform` helper will check
219
+ a) If the files in the output fixture folder are present after transform
220
+ b) If their contents match
221
+
222
+ ## How to run your changes on a test redwood project
223
+
224
+ 1. Clean all your other packages, and rebuild once:
225
+
226
+ ```shell
227
+ # root of framework
228
+ yarn build:clean
229
+ yarn build
230
+ ```
231
+
232
+ 2. Build the codemods package
233
+
234
+ ```shell
235
+ cd packages/codemods
236
+ yarn build
237
+ ```
238
+
239
+ 3. Running the updated CLI
240
+
241
+ The CLI is meant to be run on a redwood project (i.e. it expects you to be cd'd into a redwood project), but you can provide it as an environment variable too!
242
+
243
+ ```shell
244
+ RWJS_CWD=/path/to/rw-project node "./packages/codemods/dist/codemods.js" {your-codemod-name}
245
+ # ☝️ this is the path to your rw project (not the framework!)
246
+ ```
247
+
248
+ > **💡 Tip**
249
+ >
250
+ > If you're making changes, and want to watch your source and build on changes, you can use the [watch cli](https://www.npmjs.com/package/watch-cli)
251
+ >
252
+ > ```shell
253
+ > # Assuming in packages/codemods/
254
+ > watch -p "./src/**/*" -c "yarn build"
255
+ > ```
256
+
257
+ 4. Debugging
258
+
259
+ If you have a node and want to see/confirm what you're working with you can
260
+ pass it to jscodeshift and then call `.toSource()` on it.
261
+
262
+ **Example**
263
+
264
+ ```js
265
+ const j = api.jscodeshift
266
+ const root = j(file.source)
267
+
268
+ const graphQLClientConfig = j.jsxAttribute(
269
+ j.jsxIdentifier('graphQLClientConfig'),
270
+ j.jsxExpressionContainer(j.objectExpression([])),
271
+ )
272
+
273
+ console.log('graphQLClientConfig prop', j(graphQLClientConfig).toSource())
274
+ // Will log:
275
+ // graphQLClientConfig={{}}
276
+ ```
277
+
278
+ If you have a collection of nodes you first need to get just one of the
279
+ collection items, and then get the node out of that.
280
+
281
+ **Example**
282
+
283
+ ```js
284
+ const j = api.jscodeshift
285
+ const root = j(file.source)
286
+
287
+ const redwoodApolloProvider = root.findJSXElements('RedwoodApolloProvider')
288
+
289
+ console.log(
290
+ '<RedwoodApolloProvider>',
291
+ j(redwoodApolloProvider.get(0).node).toSource(),
292
+ )
293
+ // Will log:
294
+ // <RedwoodApolloProvider useAuth={useAuth}>
295
+ // <Routes />
296
+ // </RedwoodApolloProvider>
297
+ ```
@@ -0,0 +1,67 @@
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 list_yargs_exports = {};
30
+ __export(list_yargs_exports, {
31
+ aliases: () => aliases,
32
+ builder: () => builder,
33
+ command: () => command,
34
+ description: () => description,
35
+ handler: () => handler
36
+ });
37
+ module.exports = __toCommonJS(list_yargs_exports);
38
+ var import_fs = __toESM(require("fs"));
39
+ var import_path = __toESM(require("path"));
40
+ var import_yargs_parser = require("yargs-parser");
41
+ const command = "list <rwVersion>";
42
+ const description = "List available codemods for a specific version";
43
+ const aliases = ["ls"];
44
+ const builder = (yargs) => {
45
+ yargs.positional("rwVersion", {
46
+ type: "string",
47
+ required: true,
48
+ choices: import_fs.default.readdirSync(__dirname).filter((file) => !import_fs.default.statSync(import_path.default.join(__dirname, file)).isFile())
49
+ // Only list the folders
50
+ });
51
+ };
52
+ const handler = ({ rwVersion }) => {
53
+ console.log("Listing codemods for", rwVersion);
54
+ console.log();
55
+ const modsForVersion = import_fs.default.readdirSync(import_path.default.join(__dirname, rwVersion));
56
+ modsForVersion.forEach((codemod) => {
57
+ console.log(`- npx @cedarjs/codemods ${(0, import_yargs_parser.decamelize)(codemod)}`);
58
+ });
59
+ };
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ aliases,
63
+ builder,
64
+ command,
65
+ description,
66
+ handler
67
+ });
@@ -0,0 +1,74 @@
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 tsconfigForRouteHooks_exports = {};
30
+ __export(tsconfigForRouteHooks_exports, {
31
+ default: () => addApiAliasToTsConfig
32
+ });
33
+ module.exports = __toCommonJS(tsconfigForRouteHooks_exports);
34
+ var import_project_config = require("@cedarjs/project-config");
35
+ var import_prettify = __toESM(require("../../../lib/prettify"));
36
+ async function addApiAliasToTsConfig() {
37
+ const ts = await import("typescript");
38
+ const webConfigPath = ts.findConfigFile(
39
+ (0, import_project_config.getPaths)().web.base,
40
+ ts.sys.fileExists
41
+ );
42
+ if (!webConfigPath) {
43
+ throw new Error(
44
+ "Could not find tsconfig.json in your web side. Please follow release notes to update your config manually."
45
+ );
46
+ }
47
+ const { config: webConfig } = ts.parseConfigFileTextToJson(
48
+ webConfigPath,
49
+ ts.sys.readFile(webConfigPath)
50
+ // If file exists, it has contents
51
+ );
52
+ if (webConfig?.compilerOptions) {
53
+ const newPathAliases = {
54
+ ...webConfig.compilerOptions.paths,
55
+ "$api/*": ["../api/*"]
56
+ };
57
+ const updatedConfig = {
58
+ ...webConfig,
59
+ compilerOptions: {
60
+ ...webConfig.compilerOptions,
61
+ paths: newPathAliases
62
+ }
63
+ };
64
+ ts.sys.writeFile(
65
+ webConfigPath,
66
+ // @NOTE: prettier will remove trailing commas, but whatever
67
+ await (0, import_prettify.default)(JSON.stringify(updatedConfig), { parser: "json" })
68
+ );
69
+ } else {
70
+ throw new Error(
71
+ "Could not read your web/tsconfig.json. Please follow release notes to update your config manually."
72
+ );
73
+ }
74
+ }
@@ -0,0 +1,51 @@
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 tsconfigForRouteHooks_yargs_exports = {};
30
+ __export(tsconfigForRouteHooks_yargs_exports, {
31
+ command: () => command,
32
+ description: () => description,
33
+ handler: () => handler
34
+ });
35
+ module.exports = __toCommonJS(tsconfigForRouteHooks_yargs_exports);
36
+ var import_tasuku = __toESM(require("tasuku"));
37
+ var import_tsconfigForRouteHooks = __toESM(require("./tsconfigForRouteHooks"));
38
+ const command = "tsconfig-for-route-hooks";
39
+ const description = "(v2.3.x->v2.3.x) Allow $api imports in *.routesHooks.ts files";
40
+ const handler = () => {
41
+ (0, import_tasuku.default)("Tsconfig For Route Hooks", async ({ setOutput }) => {
42
+ (0, import_tsconfigForRouteHooks.default)();
43
+ setOutput("All done! Run `yarn rw lint --fix` to prettify your code");
44
+ });
45
+ };
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ command,
49
+ description,
50
+ handler
51
+ });
@@ -0,0 +1,43 @@
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 configureFastify_exports = {};
20
+ __export(configureFastify_exports, {
21
+ default: () => transform
22
+ });
23
+ module.exports = __toCommonJS(configureFastify_exports);
24
+ function transform(file, api) {
25
+ const j = api.jscodeshift;
26
+ const ast = j(file.source);
27
+ ast.find(j.AssignmentExpression).forEach((path) => {
28
+ const lhs = path.value.left;
29
+ const rhs = path.value.right;
30
+ if (lhs && rhs.type === "Identifier" && rhs.name === "config") {
31
+ j(path).replaceWith(
32
+ j.expressionStatement(
33
+ j.assignmentExpression(
34
+ "=",
35
+ j.identifier("module.exports"),
36
+ j.identifier("{ config }")
37
+ )
38
+ )
39
+ );
40
+ }
41
+ });
42
+ return ast.toSource();
43
+ }
@@ -0,0 +1,83 @@
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 configureFastify_yargs_exports = {};
30
+ __export(configureFastify_yargs_exports, {
31
+ command: () => command,
32
+ description: () => description,
33
+ handler: () => handler
34
+ });
35
+ module.exports = __toCommonJS(configureFastify_yargs_exports);
36
+ var import_fs = __toESM(require("fs"));
37
+ var import_path = __toESM(require("path"));
38
+ var import_fetch = require("@whatwg-node/fetch");
39
+ var import_fast_glob = __toESM(require("fast-glob"));
40
+ var import_tasuku = __toESM(require("tasuku"));
41
+ var import_project_config = require("@cedarjs/project-config");
42
+ var import_prettify = __toESM(require("../../../lib/prettify"));
43
+ var import_runTransform = __toESM(require("../../../lib/runTransform"));
44
+ const command = "configure-fastify";
45
+ const description = "(v2.x.x->v2.x.x) Updates api side\u2019s server.config.js to configure Fastify";
46
+ const handler = () => {
47
+ (0, import_tasuku.default)("Configure Fastify", async ({ setOutput }) => {
48
+ const [API_SERVER_CONFIG_PATH] = import_fast_glob.default.sync("server.config.{js,ts}", {
49
+ cwd: (0, import_project_config.getPaths)().api.base,
50
+ absolute: true
51
+ });
52
+ if (import_fs.default.existsSync(API_SERVER_CONFIG_PATH)) {
53
+ await (0, import_runTransform.default)({
54
+ transformPath: import_path.default.join(__dirname, "configureFastify.js"),
55
+ targetPaths: [API_SERVER_CONFIG_PATH]
56
+ });
57
+ import_fs.default.writeFileSync(
58
+ API_SERVER_CONFIG_PATH,
59
+ await (0, import_prettify.default)(import_fs.default.readFileSync(API_SERVER_CONFIG_PATH, "utf-8"))
60
+ );
61
+ setOutput("All done!");
62
+ } else {
63
+ const res = await (0, import_fetch.fetch)(
64
+ "https://raw.githubusercontent.com/cedarjs/cedar/main/packages/create-cedar-app/template/api/server.config.js"
65
+ );
66
+ const text = await res.text();
67
+ const NEW_API_SERVER_CONFIG_PATH = import_path.default.join(
68
+ (0, import_project_config.getPaths)().api.base,
69
+ "server.config.js"
70
+ );
71
+ import_fs.default.writeFileSync(NEW_API_SERVER_CONFIG_PATH, await (0, import_prettify.default)(text));
72
+ setOutput(
73
+ "Done! No server.config.js found, so we updated your project to use the latest version."
74
+ );
75
+ }
76
+ });
77
+ };
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ command,
81
+ description,
82
+ handler
83
+ });