@vercel/introspection 0.0.2 → 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.
@@ -90,14 +90,22 @@ const handle$1 = (expressModule) => {
90
90
  return expressModule;
91
91
  };
92
92
  setupCloseHandlers(() => {
93
- const routes = extractRoutes();
93
+ const { routes, additionalFolders, additionalDeps } = extractRoutes();
94
94
  if (routes.length > 0) return {
95
95
  frameworkSlug: "express",
96
- routes
96
+ routes,
97
+ additionalFolders,
98
+ additionalDeps
97
99
  };
98
100
  });
99
101
  const extractRoutes = () => {
100
- if (!app) return [];
102
+ if (!app) return {
103
+ routes: [],
104
+ additionalFolders: [],
105
+ additionalDeps: []
106
+ };
107
+ const additionalFolders = [];
108
+ const additionalDeps = [];
101
109
  const routes = [];
102
110
  const methods = [
103
111
  "all",
@@ -110,6 +118,10 @@ const extractRoutes = () => {
110
118
  "head"
111
119
  ];
112
120
  const router = app._router || app.router;
121
+ if ("settings" in app) {
122
+ if ("views" in app.settings && typeof app.settings.views === "string") additionalFolders.push(app.settings.views);
123
+ if ("view engine" in app.settings && typeof app.settings["view engine"] === "string") additionalDeps.push(app.settings["view engine"]);
124
+ }
113
125
  for (const route of router.stack) if (route.route) {
114
126
  const m = [];
115
127
  for (const method of methods) if (route.route.methods[method]) m.push(method.toUpperCase());
@@ -121,7 +133,11 @@ const extractRoutes = () => {
121
133
  methods: m
122
134
  });
123
135
  }
124
- return routes;
136
+ return {
137
+ routes,
138
+ additionalFolders,
139
+ additionalDeps
140
+ };
125
141
  };
126
142
 
127
143
  //#endregion
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,7 +1,7 @@
1
1
  import { register } from "node:module";
2
2
 
3
3
  //#region src/loaders/esm.ts
4
- register(new URL("./hooks.js", import.meta.url), import.meta.url);
4
+ register(new URL("./hooks.mjs", import.meta.url), import.meta.url);
5
5
 
6
6
  //#endregion
7
7
  export { };
@@ -0,0 +1,5 @@
1
+ //#region src/loaders/hooks.d.ts
2
+ declare function resolve(specifier: string, context: any, nextResolve: any): Promise<any>;
3
+ declare function load(url: string, context: any, nextLoad: (url: string, context: any) => Promise<any>): Promise<any>;
4
+ //#endregion
5
+ export { load, resolve };
@@ -10,7 +10,7 @@ async function resolve(specifier, context, nextResolve) {
10
10
  async function load(url, context, nextLoad) {
11
11
  const result = await nextLoad(url, context);
12
12
  if (expressUrl === url) {
13
- const pathToExpressExtract = new URL("../express.js", import.meta.url);
13
+ const pathToExpressExtract = new URL("../express.mjs", import.meta.url);
14
14
  return {
15
15
  format: "module",
16
16
  source: `
@@ -26,7 +26,7 @@ export default extendedExpress;
26
26
  };
27
27
  }
28
28
  if (honoUrl === url) {
29
- const pathToHonoExtract = new URL("../hono.js", import.meta.url);
29
+ const pathToHonoExtract = new URL("../hono.mjs", import.meta.url);
30
30
  return {
31
31
  format: "module",
32
32
  source: `
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@vercel/introspection",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "Apache-2.0",
5
- "main": "./dist/index.js",
6
5
  "homepage": "https://vercel.com/docs",
7
6
  "type": "module",
8
7
  "publishConfig": {
9
8
  "access": "public"
10
9
  },
11
10
  "exports": {
12
- ".": "./dist/index.js",
11
+ ".": {
12
+ "import": "./dist/index.mjs",
13
+ "types": "./dist/index.d.mts"
14
+ },
13
15
  "./loaders/cjs": "./dist/loaders/cjs.js",
14
16
  "./loaders/esm": "./dist/loaders/esm.js",
15
17
  "./loaders/hooks": "./dist/loaders/hooks.js"
@@ -31,17 +33,17 @@
31
33
  "@types/fs-extra": "11",
32
34
  "@types/jest": "27.5.1",
33
35
  "@vercel/static-config": "3.1.2",
34
- "@vercel/nft": "0.30.1",
36
+ "@vercel/nft": "1.1.0",
35
37
  "@types/node": "22",
36
38
  "fs-extra": "11.1.0",
37
- "@vercel/build-utils": "12.2.4",
39
+ "@vercel/build-utils": "13.2.0",
38
40
  "execa": "3.2.0",
39
41
  "hono": "4.10.1",
40
42
  "jest-junit": "16.0.0",
41
- "tsdown": "0.15.6",
43
+ "tsdown": "0.16.3",
42
44
  "vite": "^5.1.6",
43
45
  "vitest": "^2.0.1",
44
- "@vercel/cervel": "0.0.3"
46
+ "@vercel/cervel": "0.0.6"
45
47
  },
46
48
  "scripts": {
47
49
  "build": "tsdown",
package/dist/index.js DELETED
@@ -1,103 +0,0 @@
1
- import { spawn } from "child_process";
2
- import { existsSync } from "fs";
3
- import { dirname, join } from "path";
4
- import { createRequire } from "module";
5
- import { fileURLToPath } from "url";
6
- import { z } from "zod";
7
-
8
- //#region src/index.ts
9
- const require = createRequire(import.meta.url);
10
- const introspectApp = async (args) => {
11
- const cjsLoaderPath = fileURLToPath(new URL("loaders/cjs.cjs", import.meta.url));
12
- const esmLoaderPath = new URL("loaders/esm.js", import.meta.url).href;
13
- const handlerPath = join(args.dir, args.handler);
14
- let introspectionResult = {
15
- frameworkSlug: "",
16
- routes: []
17
- };
18
- await new Promise((resolvePromise) => {
19
- try {
20
- const child = spawn("node", [
21
- "-r",
22
- cjsLoaderPath,
23
- "--import",
24
- esmLoaderPath,
25
- handlerPath
26
- ], {
27
- stdio: [
28
- "pipe",
29
- "pipe",
30
- "pipe"
31
- ],
32
- cwd: args.dir,
33
- env: {
34
- ...process.env,
35
- ...args.env
36
- }
37
- });
38
- child.stdout?.on("data", (data) => {
39
- try {
40
- const introspection = JSON.parse(data.toString());
41
- introspectionResult = z.object({
42
- frameworkSlug: z.string(),
43
- routes: z.array(z.object({
44
- src: z.string(),
45
- dest: z.string(),
46
- methods: z.array(z.string())
47
- }))
48
- }).parse(introspection);
49
- } catch (error) {}
50
- });
51
- const timeout = setTimeout(() => {
52
- child.kill("SIGTERM");
53
- }, 2e3);
54
- const timeout2 = setTimeout(() => {
55
- child.kill("SIGKILL");
56
- }, 3e3);
57
- child.on("error", (err) => {
58
- clearTimeout(timeout);
59
- clearTimeout(timeout2);
60
- console.log(`Loader error: ${err.message}`);
61
- resolvePromise(void 0);
62
- });
63
- child.on("close", () => {
64
- clearTimeout(timeout);
65
- clearTimeout(timeout2);
66
- resolvePromise(void 0);
67
- });
68
- } catch (error) {
69
- resolvePromise(void 0);
70
- }
71
- });
72
- const routes = [
73
- { handle: "filesystem" },
74
- ...introspectionResult.routes,
75
- {
76
- src: "/(.*)",
77
- dest: "/"
78
- }
79
- ];
80
- let version;
81
- if (introspectionResult.frameworkSlug) {
82
- const frameworkLibPath = require.resolve(`${introspectionResult.frameworkSlug}`, { paths: [args.dir] });
83
- const findNearestPackageJson = (dir) => {
84
- const packageJsonPath = join(dir, "package.json");
85
- if (existsSync(packageJsonPath)) return packageJsonPath;
86
- const parentDir = dirname(dir);
87
- if (parentDir === dir) return;
88
- return findNearestPackageJson(parentDir);
89
- };
90
- const nearestPackageJsonPath = findNearestPackageJson(frameworkLibPath);
91
- if (nearestPackageJsonPath) version = require(nearestPackageJsonPath).version;
92
- }
93
- return {
94
- routes,
95
- framework: {
96
- slug: introspectionResult.frameworkSlug,
97
- version
98
- }
99
- };
100
- };
101
-
102
- //#endregion
103
- export { introspectApp };
File without changes