@vercel/h3 0.1.3 → 0.1.5

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 (2) hide show
  1. package/dist/index.js +8 -169
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -41,166 +31,15 @@ __export(src_exports, {
41
31
  module.exports = __toCommonJS(src_exports);
42
32
 
43
33
  // src/build.ts
44
- var import_build_utils = require("@vercel/build-utils");
45
34
  var import_node = require("@vercel/node");
46
- var import_module = require("module");
47
- var import_path = require("path");
48
- var import_fs = __toESM(require("fs"));
49
- var frameworkName = "h3";
50
- var REGEX = /(?:from|require|import)\s*(?:\(\s*)?["']h3["']\s*(?:\))?/g;
51
- var validFilenames = [
52
- "app",
53
- "index",
54
- "server",
55
- "src/app",
56
- "src/index",
57
- "src/server"
58
- ];
59
- var require_ = (0, import_module.createRequire)(__filename);
60
- var validExtensions = ["js", "cjs", "mjs", "ts", "cts", "mts"];
61
- var entrypointsForMessage = validFilenames.map((filename) => `- ${filename}.{${validExtensions.join(",")}}`).join("\n");
62
- var build = async (args) => {
63
- process.env.EXPERIMENTAL_NODE_TYPESCRIPT_ERRORS = "1";
64
- const includeFiles = ["views/**/*"];
65
- const includeFilesFromConfig = args.config.includeFiles;
66
- if (includeFilesFromConfig) {
67
- includeFiles.push(...includeFilesFromConfig);
68
- }
69
- const res = await (0, import_node.build)({
70
- ...args,
71
- config: {
72
- ...args.config,
73
- includeFiles
74
- },
75
- // this is package.json, but we'll replace it with the return value of the entrypointCallback
76
- // after install and build scripts have had a chance to run
77
- entrypoint: "package.json",
78
- considerBuildCommand: true,
79
- entrypointCallback: async () => {
80
- return entrypointCallback(args);
81
- }
82
- });
83
- let version2 = void 0;
84
- try {
85
- const resolved = require_.resolve(`${frameworkName}/package.json`, {
86
- paths: [args.workPath]
87
- });
88
- const h3Version = require_(resolved).version;
89
- if (h3Version) {
90
- version2 = h3Version;
91
- }
92
- } catch (e) {
93
- }
94
- res.output.framework = {
95
- slug: frameworkName,
96
- version: version2
97
- };
98
- return res;
99
- };
100
- var entrypointCallback = async (args) => {
101
- const mainPackageEntrypoint = findMainPackageEntrypoint(args.files);
102
- const entrypointGlob = `{${validFilenames.map((entrypoint) => `${entrypoint}`).join(",")}}.{${validExtensions.join(",")}}`;
103
- const dir = args.config.projectSettings?.outputDirectory?.replace(
104
- /^\/+|\/+$/g,
105
- ""
106
- );
107
- if (dir) {
108
- const { entrypoint: entrypointFromOutputDir, entrypointsNotMatchingRegex: entrypointsNotMatchingRegex2 } = findEntrypoint(await (0, import_build_utils.glob)(entrypointGlob, (0, import_path.join)(args.workPath, dir)));
109
- if (entrypointFromOutputDir) {
110
- return (0, import_path.join)(dir, entrypointFromOutputDir);
111
- }
112
- if (entrypointsNotMatchingRegex2.length > 0) {
113
- throw new Error(
114
- `No entrypoint found which imports h3. Found possible ${pluralize("entrypoint", entrypointsNotMatchingRegex2.length)}: ${entrypointsNotMatchingRegex2.join(", ")}`
115
- );
116
- }
117
- throw new Error(
118
- `No entrypoint found in output directory: "${dir}". Searched for:
119
- ${entrypointsForMessage}`
120
- );
121
- }
122
- const files = await (0, import_build_utils.glob)(entrypointGlob, args.workPath);
123
- const { entrypoint: entrypointFromRoot, entrypointsNotMatchingRegex } = findEntrypoint(files);
124
- if (entrypointFromRoot) {
125
- return entrypointFromRoot;
126
- }
127
- if (mainPackageEntrypoint) {
128
- const entrypointFromPackageJson = await (0, import_build_utils.glob)(
129
- mainPackageEntrypoint,
130
- args.workPath
131
- );
132
- if (entrypointFromPackageJson[mainPackageEntrypoint]) {
133
- if (checkMatchesRegex(entrypointFromPackageJson[mainPackageEntrypoint])) {
134
- return mainPackageEntrypoint;
135
- }
136
- }
137
- }
138
- if (entrypointsNotMatchingRegex.length > 0) {
139
- throw new Error(
140
- `No entrypoint found which imports h3. Found possible ${pluralize("entrypoint", entrypointsNotMatchingRegex.length)}: ${entrypointsNotMatchingRegex.join(", ")}`
141
- );
142
- }
143
- throw new Error(
144
- `No entrypoint found. Searched for:
145
- ${entrypointsForMessage}`
146
- );
147
- };
148
- function pluralize(word, count) {
149
- return count === 1 ? word : `${word}s`;
150
- }
151
- var findEntrypoint = (files) => {
152
- const allEntrypoints = validFilenames.flatMap(
153
- (filename) => validExtensions.map((extension) => `${filename}.${extension}`)
154
- );
155
- const possibleEntrypointsInFiles = allEntrypoints.filter((entrypoint2) => {
156
- return files[entrypoint2] !== void 0;
157
- });
158
- const entrypointsMatchingRegex = possibleEntrypointsInFiles.filter(
159
- (entrypoint2) => {
160
- const file = files[entrypoint2];
161
- return checkMatchesRegex(file);
162
- }
163
- );
164
- const entrypointsNotMatchingRegex = possibleEntrypointsInFiles.filter(
165
- (entrypoint2) => {
166
- const file = files[entrypoint2];
167
- return !checkMatchesRegex(file);
168
- }
169
- );
170
- const entrypoint = entrypointsMatchingRegex[0];
171
- if (entrypointsMatchingRegex.length > 1) {
172
- console.warn(
173
- `Multiple entrypoints found: ${entrypointsMatchingRegex.join(", ")}. Using ${entrypoint}.`
174
- );
175
- }
176
- return {
177
- entrypoint,
178
- entrypointsNotMatchingRegex
179
- };
180
- };
181
- var checkMatchesRegex = (file) => {
182
- const content = import_fs.default.readFileSync(file.fsPath, "utf-8");
183
- const matchesContent = content.match(REGEX);
184
- return matchesContent !== null;
185
- };
186
- var findMainPackageEntrypoint = (files) => {
187
- const packageJson = files["package.json"];
188
- if (packageJson) {
189
- if (packageJson.type === "FileFsRef") {
190
- const packageJsonContent = import_fs.default.readFileSync(packageJson.fsPath, "utf-8");
191
- let packageJsonJson;
192
- try {
193
- packageJsonJson = JSON.parse(packageJsonContent);
194
- } catch (_e) {
195
- packageJsonJson = {};
196
- }
197
- if ("main" in packageJsonJson && typeof packageJsonJson.main === "string") {
198
- return packageJsonJson.main;
199
- }
200
- }
201
- }
202
- return null;
203
- };
35
+ var import_build_utils = require("@vercel/build-utils");
36
+ var { build, entrypointCallback, findEntrypoint, require_ } = (0, import_build_utils.generateNodeBuilderFunctions)(
37
+ "h3",
38
+ /(?:from|require|import)\s*(?:\(\s*)?["']h3["']\s*(?:\))?/g,
39
+ ["app", "index", "server", "src/app", "src/index", "src/server"],
40
+ ["js", "cjs", "mjs", "ts", "cts", "mts"],
41
+ import_node.build
42
+ );
204
43
 
205
44
  // src/index.ts
206
45
  var import_node2 = require("@vercel/node");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/h3",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "homepage": "https://vercel.com/docs",
@@ -18,12 +18,12 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "@vercel/static-config": "3.1.2",
21
- "@vercel/node": "5.3.25"
21
+ "@vercel/node": "5.4.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/jest": "27.5.1",
25
25
  "@types/node": "14.18.33",
26
- "@vercel/build-utils": "12.1.1",
26
+ "@vercel/build-utils": "12.1.3",
27
27
  "execa": "3.2.0",
28
28
  "fs-extra": "11.1.0",
29
29
  "jest-junit": "16.0.0",