react-code-dataset / next.js /packages /next-codemod /transforms /app-dir-runtime-config-experimental-edge.ts
Download next.js/packages/next-codemod/transforms/app-dir-runtime-config-experimental-edge.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 914 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next-codemod/transforms/app-dir-runtime-config-experimental-edge.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next-codemod/transforms/app-dir-runtime-config-experimental-edge.ts
-
curl -L -o app-dir-runtime-config-experimental-edge.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next-codemod/transforms/app-dir-runtime-config-experimental-edge.ts
914 Bytes
| import type { API, FileInfo } from 'jscodeshift' | |
| import { createParserFromPath } from '../lib/parser' | |
| export default function transformer(file: FileInfo, _api: API) { | |
| if ( | |
| process.env.NODE_ENV !== 'test' && | |
| !/[/\\]app[/\\].*?(page|layout|route)\.[^/\\]+$/.test(file.path) | |
| ) { | |
| return file.source | |
| } | |
| const j = createParserFromPath(file.path) | |
| const root = j(file.source) | |
| const runtimeExport = root.find(j.ExportNamedDeclaration, { | |
| declaration: { | |
| type: 'VariableDeclaration', | |
| declarations: [ | |
| { | |
| id: { name: 'runtime' }, | |
| }, | |
| ], | |
| }, | |
| }) | |
| if (runtimeExport.size() !== 1) { | |
| return file.source | |
| } | |
| const runtimeValue = runtimeExport.find(j.StringLiteral, { | |
| value: 'experimental-edge', | |
| }) | |
| if (runtimeValue.size() !== 1) { | |
| return file.source | |
| } | |
| runtimeValue.replaceWith(j.stringLiteral('edge')) | |
| return root.toSource() | |
| } | |