|
1 | | -import type fsMod from 'node:fs'; |
2 | | -import * as eslexer from 'es-module-lexer'; |
3 | 1 | import type { APIContext } from '../types/public/context.js'; |
4 | 2 | import { deserializeActionResult, getActionQueryString } from './runtime/client.js'; |
5 | 3 | import { ACTION_API_CONTEXT_SYMBOL } from './runtime/server.js'; |
@@ -28,54 +26,3 @@ export function createCallAction(context: ActionAPIContext): APIContext['callAct |
28 | 26 | return action(input) as any; |
29 | 27 | }; |
30 | 28 | } |
31 | | - |
32 | | -let didInitLexer = false; |
33 | | - |
34 | | -/** |
35 | | - * Check whether the Actions config file is present. |
36 | | - */ |
37 | | -export async function isActionsFilePresent(fs: typeof fsMod, srcDir: URL) { |
38 | | - if (!didInitLexer) await eslexer.init; |
39 | | - |
40 | | - const actionsFile = search(fs, srcDir); |
41 | | - if (!actionsFile) return false; |
42 | | - |
43 | | - let contents: string; |
44 | | - try { |
45 | | - contents = fs.readFileSync(actionsFile.url, 'utf-8'); |
46 | | - } catch { |
47 | | - return false; |
48 | | - } |
49 | | - |
50 | | - // Check if `server` export is present. |
51 | | - // If not, the user may have an empty `actions` file, |
52 | | - // or may be using the `actions` file for another purpose |
53 | | - // (possible since actions are non-breaking for v4.X). |
54 | | - const [, exports] = eslexer.parse(contents, actionsFile.url.pathname); |
55 | | - for (const exp of exports) { |
56 | | - if (exp.n === 'server') { |
57 | | - return actionsFile.filename; |
58 | | - } |
59 | | - } |
60 | | - return false; |
61 | | -} |
62 | | - |
63 | | -function search(fs: typeof fsMod, srcDir: URL) { |
64 | | - const filenames = [ |
65 | | - 'actions.mjs', |
66 | | - 'actions.js', |
67 | | - 'actions.mts', |
68 | | - 'actions.ts', |
69 | | - 'actions/index.mjs', |
70 | | - 'actions/index.js', |
71 | | - 'actions/index.mts', |
72 | | - 'actions/index.ts', |
73 | | - ]; |
74 | | - for (const filename of filenames) { |
75 | | - const url = new URL(filename, srcDir); |
76 | | - if (fs.existsSync(url)) { |
77 | | - return { filename, url }; |
78 | | - } |
79 | | - } |
80 | | - return undefined; |
81 | | -} |
0 commit comments