wrangler 0.0.0-ece06ea → 0.0.0-eebdb6c

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 (39) hide show
  1. package/package.json +22 -15
  2. package/pages/functions/buildWorker.ts +57 -0
  3. package/pages/functions/filepath-routing.test.ts +32 -0
  4. package/pages/functions/filepath-routing.ts +225 -0
  5. package/pages/functions/identifiers.ts +78 -0
  6. package/pages/functions/routes.ts +158 -0
  7. package/pages/functions/template-worker.ts +135 -0
  8. package/src/__tests__/index.test.ts +254 -120
  9. package/src/__tests__/jest.setup.ts +22 -0
  10. package/src/__tests__/kv.test.ts +1098 -0
  11. package/src/__tests__/mock-cfetch.ts +171 -0
  12. package/src/__tests__/mock-dialogs.ts +65 -0
  13. package/src/__tests__/run-in-tmp.ts +19 -0
  14. package/src/__tests__/run-wrangler.ts +32 -0
  15. package/src/api/form_data.ts +70 -97
  16. package/src/api/inspect.ts +0 -11
  17. package/src/api/preview.ts +29 -24
  18. package/src/api/worker.ts +34 -40
  19. package/src/cfetch/index.ts +103 -0
  20. package/src/cfetch/internal.ts +69 -0
  21. package/src/cli.ts +6 -7
  22. package/src/config.ts +14 -7
  23. package/src/dev.tsx +274 -131
  24. package/src/dialogs.tsx +4 -12
  25. package/src/index.tsx +304 -245
  26. package/src/kv.tsx +101 -45
  27. package/src/module-collection.ts +64 -0
  28. package/src/pages.tsx +681 -104
  29. package/src/proxy.ts +103 -0
  30. package/src/publish.ts +54 -58
  31. package/src/sites.tsx +5 -6
  32. package/src/tail.tsx +5 -3
  33. package/src/user.tsx +9 -16
  34. package/wrangler-dist/cli.js +36633 -49770
  35. package/wrangler-dist/cli.js.map +3 -3
  36. package/src/__tests__/fixtures/init/.gitkeep +0 -0
  37. package/src/__tests__/mock-cfetch.js +0 -46
  38. package/src/cfetch.ts +0 -72
  39. package/src/util/fetch.ts +0 -74
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.0-ece06ea",
3
+ "version": "0.0.0-eebdb6c",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -36,51 +36,54 @@
36
36
  "cli"
37
37
  ],
38
38
  "dependencies": {
39
- "@cloudflare/pages-functions-compiler": "0.3.7",
40
39
  "esbuild": "0.14.1",
41
- "miniflare": "2.0.0-rc.2",
42
- "semiver": "^1.1.0",
43
- "serve": "^13.0.2",
44
- "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
45
- "@esbuild-plugins/node-modules-polyfill": "^0.1.2"
40
+ "miniflare": "2.0.0-rc.5",
41
+ "path-to-regexp": "^6.2.0",
42
+ "semiver": "^1.1.0"
46
43
  },
47
44
  "optionalDependencies": {
48
45
  "fsevents": "~2.3.2"
49
46
  },
50
47
  "devDependencies": {
48
+ "@babel/types": "^7.16.0",
51
49
  "@iarna/toml": "^2.2.5",
52
- "@types/cloudflare": "^2.7.6",
53
- "@types/express": "^4.17.13",
50
+ "@types/mime": "^2.0.3",
51
+ "@types/estree": "^0.0.50",
54
52
  "@types/react": "^17.0.37",
53
+ "@types/serve-static": "^1.13.10",
55
54
  "@types/signal-exit": "^3.0.1",
56
55
  "@types/ws": "^8.2.1",
57
56
  "@types/yargs": "^17.0.7",
57
+ "acorn": "^8.6.0",
58
+ "acorn-walk": "^8.2.0",
59
+ "chokidar": "^3.5.2",
58
60
  "clipboardy": "^3.0.0",
59
61
  "command-exists": "^1.2.9",
60
62
  "execa": "^6.0.0",
61
- "express": "^4.17.1",
63
+ "faye-websocket": "^0.11.4",
62
64
  "finalhandler": "^1.1.2",
63
65
  "find-up": "^6.2.0",
64
66
  "formdata-node": "^4.3.1",
65
- "http-proxy": "^1.18.1",
66
- "http-proxy-middleware": "^2.0.1",
67
67
  "ink": "^3.2.0",
68
68
  "ink-select-input": "^4.2.1",
69
69
  "ink-table": "^3.0.0",
70
70
  "ink-text-input": "^4.0.2",
71
+ "mime": "^3.0.0",
71
72
  "node-fetch": "^3.1.0",
72
73
  "open": "^8.4.0",
73
- "path-to-regexp": "^6.2.0",
74
74
  "react": "^17.0.2",
75
+ "react-error-boundary": "^3.1.4",
75
76
  "serve-static": "^1.14.1",
76
77
  "signal-exit": "^3.0.6",
77
78
  "tmp-promise": "^3.0.3",
79
+ "undici": "^4.11.1",
78
80
  "ws": "^8.3.0",
79
81
  "yargs": "^17.3.0"
80
82
  },
81
83
  "files": [
82
84
  "src",
83
85
  "bin",
86
+ "pages",
84
87
  "miniflare-config-stubs",
85
88
  "wrangler-dist",
86
89
  "static-asset-facade.js",
@@ -98,6 +101,7 @@
98
101
  "node": ">=16.7.0"
99
102
  },
100
103
  "jest": {
104
+ "restoreMocks": true,
101
105
  "testRegex": ".*.(test|spec)\\.[jt]sx?$",
102
106
  "transformIgnorePatterns": [
103
107
  "node_modules/(?!node-fetch|fetch-blob|find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|data-uri-to-buffer|formdata-polyfill|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)"
@@ -112,6 +116,9 @@
112
116
  "sourcemap": true
113
117
  }
114
118
  ]
115
- }
119
+ },
120
+ "setupFilesAfterEnv": [
121
+ "<rootDir>/src/__tests__/jest.setup.ts"
122
+ ]
116
123
  }
117
- }
124
+ }
@@ -0,0 +1,57 @@
1
+ import path from "path";
2
+ import { build } from "esbuild";
3
+
4
+ type Options = {
5
+ routesModule: string;
6
+ outfile: string;
7
+ minify?: boolean;
8
+ sourcemap?: boolean;
9
+ watch?: boolean;
10
+ onEnd?: () => void;
11
+ };
12
+
13
+ export function buildWorker({
14
+ routesModule,
15
+ outfile = "bundle.js",
16
+ minify = false,
17
+ sourcemap = false,
18
+ watch = false,
19
+ onEnd = () => {},
20
+ }: Options) {
21
+ return build({
22
+ entryPoints: [
23
+ path.resolve(__dirname, "../pages/functions/template-worker.ts"),
24
+ ],
25
+ inject: [routesModule],
26
+ bundle: true,
27
+ format: "esm",
28
+ target: "esnext",
29
+ outfile,
30
+ minify,
31
+ sourcemap,
32
+ watch,
33
+ allowOverwrite: true,
34
+ plugins: [
35
+ {
36
+ name: "wrangler notifier and monitor",
37
+ setup(pluginBuild) {
38
+ pluginBuild.onEnd((result) => {
39
+ if (result.errors.length > 0) {
40
+ console.error(
41
+ `${result.errors.length} error(s) and ${result.warnings.length} warning(s) when compiling Worker.`
42
+ );
43
+ } else if (result.warnings.length > 0) {
44
+ console.warn(
45
+ `${result.warnings.length} warning(s) when compiling Worker.`
46
+ );
47
+ onEnd();
48
+ } else {
49
+ console.log("Compiled Worker successfully.");
50
+ onEnd();
51
+ }
52
+ });
53
+ },
54
+ },
55
+ ],
56
+ });
57
+ }
@@ -0,0 +1,32 @@
1
+ import { compareRoutes } from "./filepath-routing";
2
+
3
+ describe("compareRoutes()", () => {
4
+ test("routes with fewer segments come after those with more segments", () => {
5
+ expect(compareRoutes("/foo", "/foo/bar")).toBe(1);
6
+ });
7
+
8
+ test("routes with wildcard segments come after those without", () => {
9
+ expect(compareRoutes("/:foo*", "/foo")).toBe(1);
10
+ expect(compareRoutes("/:foo*", "/:foo")).toBe(1);
11
+ });
12
+
13
+ test("routes with dynamic segments come after those without", () => {
14
+ expect(compareRoutes("/:foo", "/foo")).toBe(1);
15
+ });
16
+
17
+ test("routes with dynamic segments occuring earlier come after those with dynamic segments in later positions", () => {
18
+ expect(compareRoutes("/foo/:id/bar", "/foo/bar/:id")).toBe(1);
19
+ });
20
+
21
+ test("routes with no HTTP method come after those specifying a method", () => {
22
+ expect(compareRoutes("/foo", "GET /foo")).toBe(1);
23
+ });
24
+
25
+ test("two equal routes are sorted according to their original position in the list", () => {
26
+ expect(compareRoutes("GET /foo", "GET /foo")).toBe(0);
27
+ });
28
+
29
+ test("it returns -1 if the first argument should appear first in the list", () => {
30
+ expect(compareRoutes("GET /foo", "/foo")).toBe(-1);
31
+ });
32
+ });
@@ -0,0 +1,225 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ import path from "path";
4
+ import fs from "fs/promises";
5
+ import { transform } from "esbuild";
6
+ import * as acorn from "acorn";
7
+ import * as acornWalk from "acorn-walk";
8
+ import type { Config } from "./routes";
9
+ import type { Identifier } from "estree";
10
+ import type { ExportNamedDeclaration } from "@babel/types";
11
+
12
+ type Arguments = {
13
+ baseDir: string;
14
+ baseURL: string;
15
+ };
16
+
17
+ export async function generateConfigFromFileTree({
18
+ baseDir,
19
+ baseURL,
20
+ }: Arguments) {
21
+ let routeEntries: [
22
+ string,
23
+ { [key in "module" | "middleware"]?: string[] }
24
+ ][] = [] as any;
25
+
26
+ if (!baseURL.startsWith("/")) {
27
+ baseURL = `/${baseURL}`;
28
+ }
29
+
30
+ if (baseURL.endsWith("/")) {
31
+ baseURL = baseURL.slice(0, -1);
32
+ }
33
+
34
+ await forEachFile(baseDir, async (filepath) => {
35
+ const ext = path.extname(filepath);
36
+ if (/\.(mjs|js|ts)/.test(ext)) {
37
+ // transform the code to ensure we're working with vanilla JS + ESM
38
+ const { code } = await transform(await fs.readFile(filepath, "utf-8"), {
39
+ loader: ext === ".ts" ? "ts" : "js",
40
+ });
41
+
42
+ // parse each file into an AST and search for module exports that match "onRequest" and friends
43
+ const ast = acorn.parse(code, {
44
+ ecmaVersion: "latest",
45
+ sourceType: "module",
46
+ });
47
+ acornWalk.simple(ast, {
48
+ ExportNamedDeclaration(_node) {
49
+ const node: ExportNamedDeclaration = _node as any;
50
+
51
+ // this is an array because multiple things can be exported from a single statement
52
+ // i.e. `export {foo, bar}` or `export const foo = "f", bar = "b"`
53
+ const exportNames: string[] = [];
54
+
55
+ if (node.declaration) {
56
+ const declaration = node.declaration;
57
+
58
+ // `export async function onRequest() {...}`
59
+ if (declaration.type === "FunctionDeclaration") {
60
+ exportNames.push(declaration.id.name);
61
+ }
62
+
63
+ // `export const onRequestGet = () => {}, onRequestPost = () => {}`
64
+ if (declaration.type === "VariableDeclaration") {
65
+ exportNames.push(
66
+ ...declaration.declarations.map(
67
+ (variableDeclarator) =>
68
+ (variableDeclarator.id as unknown as Identifier).name
69
+ )
70
+ );
71
+ }
72
+ }
73
+
74
+ // `export {foo, bar}`
75
+ if (node.specifiers.length) {
76
+ exportNames.push(
77
+ ...node.specifiers.map(
78
+ (exportSpecifier) =>
79
+ (exportSpecifier.exported as unknown as Identifier).name
80
+ )
81
+ );
82
+ }
83
+
84
+ for (const exportName of exportNames) {
85
+ const [match, method] =
86
+ exportName.match(
87
+ /^onRequest(Get|Post|Put|Patch|Delete|Options|Head)?$/
88
+ ) ?? [];
89
+
90
+ if (match) {
91
+ const basename = path.basename(filepath).slice(0, -ext.length);
92
+
93
+ const isIndexFile = basename === "index";
94
+ // TODO: deprecate _middleware_ in favor of _middleware
95
+ const isMiddlewareFile =
96
+ basename === "_middleware" || basename === "_middleware_";
97
+
98
+ let routePath = path
99
+ .relative(baseDir, filepath)
100
+ .slice(0, -ext.length);
101
+
102
+ if (isIndexFile || isMiddlewareFile) {
103
+ routePath = path.dirname(routePath);
104
+ }
105
+
106
+ if (routePath === ".") {
107
+ routePath = "";
108
+ }
109
+
110
+ routePath = `${baseURL}/${routePath}`;
111
+
112
+ routePath = routePath.replace(/\[\[(.+)]]/g, ":$1*"); // transform [[id]] => :id*
113
+ routePath = routePath.replace(/\[(.+)]/g, ":$1"); // transform [id] => :id
114
+
115
+ if (method) {
116
+ routePath = `${method.toUpperCase()} ${routePath}`;
117
+ }
118
+
119
+ routeEntries.push([
120
+ routePath,
121
+ {
122
+ [isMiddlewareFile ? "middleware" : "module"]: [
123
+ `${path.relative(baseDir, filepath)}:${exportName}`,
124
+ ],
125
+ },
126
+ ]);
127
+ }
128
+ }
129
+ },
130
+ });
131
+ }
132
+ });
133
+
134
+ // Combine together any routes (index routes) which contain both a module and a middleware
135
+ routeEntries = routeEntries.reduce(
136
+ (acc: typeof routeEntries, [routePath, routeHandler]) => {
137
+ const existingRouteEntry = acc.find(
138
+ (routeEntry) => routeEntry[0] === routePath
139
+ );
140
+ if (existingRouteEntry !== undefined) {
141
+ existingRouteEntry[1] = {
142
+ ...existingRouteEntry[1],
143
+ ...routeHandler,
144
+ };
145
+ } else {
146
+ acc.push([routePath, routeHandler]);
147
+ }
148
+ return acc;
149
+ },
150
+ []
151
+ );
152
+
153
+ routeEntries.sort(([pathA], [pathB]) => compareRoutes(pathA, pathB));
154
+
155
+ return { routes: Object.fromEntries(routeEntries) } as Config;
156
+ }
157
+
158
+ // Ensure routes are produced in order of precedence so that
159
+ // more specific routes aren't occluded from matching due to
160
+ // less specific routes appearing first in the route list.
161
+ export function compareRoutes(a: string, b: string) {
162
+ function parseRoutePath(routePath: string) {
163
+ let [method, segmentedPath] = routePath.split(" ");
164
+ if (!segmentedPath) {
165
+ segmentedPath = method;
166
+ method = null;
167
+ }
168
+
169
+ const segments = segmentedPath.slice(1).split("/");
170
+ return [method, segments];
171
+ }
172
+
173
+ const [methodA, segmentsA] = parseRoutePath(a);
174
+ const [methodB, segmentsB] = parseRoutePath(b);
175
+
176
+ // sort routes with fewer segments after those with more segments
177
+ if (segmentsA.length !== segmentsB.length) {
178
+ return segmentsB.length - segmentsA.length;
179
+ }
180
+
181
+ for (let i = 0; i < segmentsA.length; i++) {
182
+ const isWildcardA = segmentsA[i].includes("*");
183
+ const isWildcardB = segmentsB[i].includes("*");
184
+ const isParamA = segmentsA[i].includes(":");
185
+ const isParamB = segmentsB[i].includes(":");
186
+
187
+ // sort wildcard segments after non-wildcard segments
188
+ if (isWildcardA && !isWildcardB) return 1;
189
+ if (!isWildcardA && isWildcardB) return -1;
190
+
191
+ // sort dynamic param segments after non-param segments
192
+ if (isParamA && !isParamB) return 1;
193
+ if (!isParamA && isParamB) return -1;
194
+ }
195
+
196
+ // sort routes that specify an HTTP before those that don't
197
+ if (methodA && !methodB) return -1;
198
+ if (!methodA && methodB) return 1;
199
+
200
+ // all else equal, just sort them lexicographically
201
+ return a.localeCompare(b);
202
+ }
203
+
204
+ async function forEachFile<T>(
205
+ baseDir: string,
206
+ fn: (filepath: string) => T | Promise<T>
207
+ ) {
208
+ const searchPaths = [baseDir];
209
+ const returnValues: T[] = [];
210
+
211
+ while (searchPaths.length) {
212
+ const cwd = searchPaths.shift();
213
+ const dir = await fs.readdir(cwd, { withFileTypes: true });
214
+ for (const entry of dir) {
215
+ const pathname = path.join(cwd, entry.name);
216
+ if (entry.isDirectory()) {
217
+ searchPaths.push(pathname);
218
+ } else if (entry.isFile()) {
219
+ returnValues.push(await fn(pathname));
220
+ }
221
+ }
222
+ }
223
+
224
+ return returnValues;
225
+ }
@@ -0,0 +1,78 @@
1
+ export const RESERVED_KEYWORDS = [
2
+ "do",
3
+ "if",
4
+ "in",
5
+ "for",
6
+ "let",
7
+ "new",
8
+ "try",
9
+ "var",
10
+ "case",
11
+ "else",
12
+ "enum",
13
+ "eval",
14
+ "null",
15
+ "this",
16
+ "true",
17
+ "void",
18
+ "with",
19
+ "await",
20
+ "break",
21
+ "catch",
22
+ "class",
23
+ "const",
24
+ "false",
25
+ "super",
26
+ "throw",
27
+ "while",
28
+ "yield",
29
+ "delete",
30
+ "export",
31
+ "import",
32
+ "public",
33
+ "return",
34
+ "static",
35
+ "switch",
36
+ "typeof",
37
+ "default",
38
+ "extends",
39
+ "finally",
40
+ "package",
41
+ "private",
42
+ "continue",
43
+ "debugger",
44
+ "function",
45
+ "arguments",
46
+ "interface",
47
+ "protected",
48
+ "implements",
49
+ "instanceof",
50
+ "NaN",
51
+ "Infinity",
52
+ "undefined",
53
+ ];
54
+
55
+ export const reservedKeywordRegex = new RegExp(
56
+ `^${RESERVED_KEYWORDS.join("|")}$`
57
+ );
58
+
59
+ export const identifierStartRegex = /[$_\p{ID_Start}]/u;
60
+
61
+ export const identifierPartRegex = /[$_\u200C\u200D\p{ID_Continue}]/u;
62
+
63
+ export const identifierNameRegex =
64
+ /^(?:[$_\p{ID_Start}])(?:[$_\u200C\u200D\p{ID_Continue}])*$/u;
65
+
66
+ export const validIdentifierRegex = new RegExp(
67
+ `(?!(${reservedKeywordRegex.source})$)${identifierNameRegex.source}`,
68
+ "u"
69
+ );
70
+
71
+ export const isValidIdentifer = (identifier: string) =>
72
+ validIdentifierRegex.test(identifier);
73
+
74
+ export const normalizeIdentifier = (identifier: string) =>
75
+ identifier.replace(
76
+ /(?:^[^$_\p{ID_Start}])|[^$_\u200C\u200D\p{ID_Continue}]/gu,
77
+ "_"
78
+ );
@@ -0,0 +1,158 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ import path from "path";
4
+ import fs from "fs/promises";
5
+ import { isValidIdentifer, normalizeIdentifier } from "./identifiers";
6
+
7
+ export const HTTP_METHODS = [
8
+ "HEAD",
9
+ "OPTIONS",
10
+ "GET",
11
+ "POST",
12
+ "PUT",
13
+ "PATCH",
14
+ "DELETE",
15
+ ] as const;
16
+ export type HTTPMethod = typeof HTTP_METHODS[number];
17
+ export function isHTTPMethod(
18
+ maybeHTTPMethod: string
19
+ ): maybeHTTPMethod is HTTPMethod {
20
+ return HTTP_METHODS.includes(maybeHTTPMethod as any);
21
+ }
22
+
23
+ export type RoutesCollection = Array<{
24
+ routePath: string;
25
+ methods: HTTPMethod[];
26
+ modules: string[];
27
+ middlewares: string[];
28
+ }>;
29
+
30
+ export type Config = {
31
+ routes?: RoutesConfig;
32
+ schedules?: any;
33
+ };
34
+
35
+ export type RoutesConfig = {
36
+ [route: string]: {
37
+ middleware?: string | string[];
38
+ module?: string | string[];
39
+ };
40
+ };
41
+
42
+ type ImportMap = Map<
43
+ string,
44
+ {
45
+ filepath: string;
46
+ name: string;
47
+ identifier: string;
48
+ }
49
+ >;
50
+
51
+ type Arguments = {
52
+ config: Config;
53
+ outfile: string;
54
+ srcDir: string;
55
+ };
56
+
57
+ export async function writeRoutesModule({
58
+ config,
59
+ srcDir,
60
+ outfile = "_routes.js",
61
+ }: Arguments) {
62
+ const { importMap, routes } = parseConfig(config, srcDir);
63
+ const routesModule = generateRoutesModule(importMap, routes);
64
+
65
+ await fs.writeFile(outfile, routesModule);
66
+
67
+ return outfile;
68
+ }
69
+
70
+ export function parseConfig(config: Config, baseDir: string) {
71
+ const routes: RoutesCollection = [];
72
+ const importMap: ImportMap = new Map();
73
+ const identifierCount = new Map<string, number>(); // to keep track of identifier collisions
74
+
75
+ function parseModuleIdentifiers(paths: string | string[] | undefined) {
76
+ if (typeof paths === "undefined") {
77
+ paths = [];
78
+ }
79
+
80
+ if (typeof paths === "string") {
81
+ paths = [paths];
82
+ }
83
+
84
+ return paths.map((modulePath) => {
85
+ const [filepath, name = "default"] = modulePath.split(":");
86
+ let { identifier } = importMap.get(modulePath) ?? {};
87
+
88
+ const resolvedPath = path.resolve(baseDir, filepath);
89
+
90
+ // ensure the filepath isn't attempting to resolve to anything outside of the project
91
+ if (path.relative(baseDir, resolvedPath).startsWith("..")) {
92
+ throw new Error(`Invalid module path "${filepath}"`);
93
+ }
94
+
95
+ // ensure the module name (if provided) is a valid identifier to guard against injection attacks
96
+ if (name !== "default" && !isValidIdentifer(name)) {
97
+ throw new Error(`Invalid module identifier "${name}"`);
98
+ }
99
+
100
+ if (!identifier) {
101
+ identifier = normalizeIdentifier(`__${filepath}_${name}`);
102
+
103
+ let count = identifierCount.get(identifier) ?? 0;
104
+ identifierCount.set(identifier, ++count);
105
+
106
+ if (count > 1) {
107
+ identifier += `_${count}`;
108
+ }
109
+
110
+ importMap.set(modulePath, { filepath: resolvedPath, name, identifier });
111
+ }
112
+
113
+ return identifier;
114
+ });
115
+ }
116
+
117
+ for (const [route, props] of Object.entries(config.routes)) {
118
+ let [_methods, routePath] = route.split(" ");
119
+ if (!routePath) {
120
+ routePath = _methods;
121
+ _methods = "";
122
+ }
123
+
124
+ routes.push({
125
+ routePath,
126
+ methods: _methods.split("|").filter(isHTTPMethod),
127
+ middlewares: parseModuleIdentifiers(props.middleware),
128
+ modules: parseModuleIdentifiers(props.module),
129
+ });
130
+ }
131
+
132
+ return { routes, importMap };
133
+ }
134
+
135
+ export function generateRoutesModule(
136
+ importMap: ImportMap,
137
+ routes: RoutesCollection
138
+ ) {
139
+ return `${[...importMap.values()]
140
+ .map(
141
+ ({ filepath, name, identifier }) =>
142
+ `import { ${name} as ${identifier} } from ${JSON.stringify(filepath)}`
143
+ )
144
+ .join("\n")}
145
+
146
+ export const routes = [
147
+ ${routes
148
+ .map(
149
+ (route) => ` {
150
+ routePath: "${route.routePath}",
151
+ methods: ${JSON.stringify(route.methods)},
152
+ middlewares: [${route.middlewares.join(", ")}],
153
+ modules: [${route.modules.join(", ")}],
154
+ },`
155
+ )
156
+ .join("\n")}
157
+ ]`;
158
+ }