@next-community/adapter-vercel 0.0.1-beta.14 → 0.0.1-beta.16
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.
- package/dist/index.js +57 -2
- package/dist/node-handler.js +12 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9645,6 +9645,7 @@ async function handleStaticOutputs(outputs, {
|
|
|
9645
9645
|
);
|
|
9646
9646
|
}
|
|
9647
9647
|
var vercelConfig = JSON.parse(process.env.NEXT_ADAPTER_VERCEL_CONFIG || "{}");
|
|
9648
|
+
var hasWarnedAboutDotEnv = false;
|
|
9648
9649
|
function isGeneratedStep(routeName) {
|
|
9649
9650
|
return routeName.includes(".well-known/workflow/v1/step") || routeName.includes("api/generated/steps");
|
|
9650
9651
|
}
|
|
@@ -9688,6 +9689,30 @@ async function writeDeterministicRoutesManifest(distDir) {
|
|
|
9688
9689
|
await import_promises.default.writeFile(outputManifestPath, JSON.stringify(manifest));
|
|
9689
9690
|
return outputManifestPath;
|
|
9690
9691
|
}
|
|
9692
|
+
async function getProjectEnvFiles(projectDir) {
|
|
9693
|
+
const envFiles = [];
|
|
9694
|
+
const projectFiles = (await import_promises.default.readdir(projectDir).catch(() => [])).sort();
|
|
9695
|
+
for (const file of projectFiles) {
|
|
9696
|
+
const isEnv = file === ".env" || file.startsWith(".env.");
|
|
9697
|
+
if (!isEnv) {
|
|
9698
|
+
continue;
|
|
9699
|
+
}
|
|
9700
|
+
const statResult = await import_promises.default.lstat(import_node_path.default.join(projectDir, file)).catch(() => {
|
|
9701
|
+
return void 0;
|
|
9702
|
+
});
|
|
9703
|
+
if (statResult?.isFile()) {
|
|
9704
|
+
envFiles.push(file);
|
|
9705
|
+
}
|
|
9706
|
+
}
|
|
9707
|
+
return envFiles;
|
|
9708
|
+
}
|
|
9709
|
+
function resolveNextEnvLoaderPath(projectDir) {
|
|
9710
|
+
const { createRequire } = require("module");
|
|
9711
|
+
const projectRequire = createRequire(import_node_path.default.join(projectDir, "package.json"));
|
|
9712
|
+
const nextPackagePath = projectRequire.resolve("next/package.json");
|
|
9713
|
+
const requireFromNext = createRequire(nextPackagePath);
|
|
9714
|
+
return requireFromNext.resolve("@next/env");
|
|
9715
|
+
}
|
|
9691
9716
|
async function handleNodeOutputs(nodeOutputs, {
|
|
9692
9717
|
config,
|
|
9693
9718
|
distDir,
|
|
@@ -9698,7 +9723,12 @@ async function handleNodeOutputs(nodeOutputs, {
|
|
|
9698
9723
|
prerenderFallbackFalseMap,
|
|
9699
9724
|
vercelOutputDir
|
|
9700
9725
|
}) {
|
|
9701
|
-
const nodeVersion = await (0, import_build_utils.getNodeVersion)(
|
|
9726
|
+
const nodeVersion = await (0, import_build_utils.getNodeVersion)(
|
|
9727
|
+
projectDir,
|
|
9728
|
+
void 0,
|
|
9729
|
+
vercelConfig,
|
|
9730
|
+
{}
|
|
9731
|
+
);
|
|
9702
9732
|
const fsSema = new import_async_sema.Sema(16, { capacity: nodeOutputs.length });
|
|
9703
9733
|
const functionsDir = import_node_path.default.join(vercelOutputDir, "functions");
|
|
9704
9734
|
const handlerRelativeDir = import_node_path.default.posix.relative(repoRoot, projectDir);
|
|
@@ -9723,6 +9753,27 @@ async function handleNodeOutputs(nodeOutputs, {
|
|
|
9723
9753
|
import_node_path.default.posix.relative(repoRoot, distDir),
|
|
9724
9754
|
"routes-manifest.json"
|
|
9725
9755
|
);
|
|
9756
|
+
const envFiles = await getProjectEnvFiles(projectDir);
|
|
9757
|
+
const hasProjectEnvFiles = envFiles.length > 0;
|
|
9758
|
+
const envFilePathMap = {};
|
|
9759
|
+
let nextEnvLoaderPathRelativeToProjectDir;
|
|
9760
|
+
for (const envFile of envFiles) {
|
|
9761
|
+
envFilePathMap[import_node_path.default.posix.join(import_node_path.default.posix.relative(repoRoot, projectDir), envFile)] = import_node_path.default.posix.relative(repoRoot, import_node_path.default.join(projectDir, envFile));
|
|
9762
|
+
}
|
|
9763
|
+
if (hasProjectEnvFiles) {
|
|
9764
|
+
if (!hasWarnedAboutDotEnv) {
|
|
9765
|
+
console.warn(
|
|
9766
|
+
"Detected .env file, it is strongly recommended to use Vercel's env handling instead"
|
|
9767
|
+
);
|
|
9768
|
+
hasWarnedAboutDotEnv = true;
|
|
9769
|
+
}
|
|
9770
|
+
const nextEnvLoaderPath = resolveNextEnvLoaderPath(projectDir);
|
|
9771
|
+
envFilePathMap[import_node_path.default.posix.relative(repoRoot, nextEnvLoaderPath)] = import_node_path.default.posix.relative(repoRoot, nextEnvLoaderPath);
|
|
9772
|
+
nextEnvLoaderPathRelativeToProjectDir = import_node_path.default.posix.relative(
|
|
9773
|
+
projectDir,
|
|
9774
|
+
nextEnvLoaderPath
|
|
9775
|
+
);
|
|
9776
|
+
}
|
|
9726
9777
|
await Promise.all(
|
|
9727
9778
|
nodeOutputs.map(async (output) => {
|
|
9728
9779
|
await fsSema.acquire();
|
|
@@ -9736,6 +9787,9 @@ async function handleNodeOutputs(nodeOutputs, {
|
|
|
9736
9787
|
files[relPath] = import_node_path.default.posix.relative(repoRoot, fsPath);
|
|
9737
9788
|
}
|
|
9738
9789
|
files[import_node_path.default.posix.relative(repoRoot, output.filePath)] = import_node_path.default.posix.relative(repoRoot, output.filePath);
|
|
9790
|
+
if (hasProjectEnvFiles) {
|
|
9791
|
+
Object.assign(files, envFilePathMap);
|
|
9792
|
+
}
|
|
9739
9793
|
if (output.type === import_constants.AdapterOutputType.PAGES) {
|
|
9740
9794
|
const notFoundOutput = pages404Output || pagesErrorOutput;
|
|
9741
9795
|
if (notFoundOutput) {
|
|
@@ -9762,7 +9816,8 @@ async function handleNodeOutputs(nodeOutputs, {
|
|
|
9762
9816
|
projectRelativeDistDir: import_node_path.default.posix.relative(projectDir, distDir),
|
|
9763
9817
|
prerenderFallbackFalseMap,
|
|
9764
9818
|
isMiddleware,
|
|
9765
|
-
nextConfig: config
|
|
9819
|
+
nextConfig: config,
|
|
9820
|
+
nextEnvLoaderPathRelativeToProjectDir
|
|
9766
9821
|
})
|
|
9767
9822
|
);
|
|
9768
9823
|
const operationType = output.type === import_constants.AdapterOutputType.APP_PAGE || import_constants.AdapterOutputType.PAGES ? "PAGE" : "API";
|
package/dist/node-handler.js
CHANGED
|
@@ -24,8 +24,15 @@ module.exports = __toCommonJS(node_handler_exports);
|
|
|
24
24
|
const getHandlerSource = (ctx) => `
|
|
25
25
|
process.env.NODE_ENV = 'production';
|
|
26
26
|
process.chdir(__dirname);
|
|
27
|
-
|
|
28
|
-
require('next/setup-node-env')
|
|
27
|
+
|
|
28
|
+
require('next/setup-node-env');
|
|
29
|
+
|
|
30
|
+
if (process.env.__PRIVATE_NEXT_ENV_LOADER_PATH) {
|
|
31
|
+
const { loadEnvConfig } = require(
|
|
32
|
+
'./' + process.env.__PRIVATE_NEXT_ENV_LOADER_PATH
|
|
33
|
+
);
|
|
34
|
+
loadEnvConfig('.', process.env.NODE_ENV === 'development');
|
|
35
|
+
}
|
|
29
36
|
|
|
30
37
|
const _n_handler = (${ctx.isMiddleware ? () => {
|
|
31
38
|
const path = require("path");
|
|
@@ -289,6 +296,9 @@ const getHandlerSource = (ctx) => `
|
|
|
289
296
|
).replaceAll(
|
|
290
297
|
"process.env.__PRIVATE_NEXT_CONFIG",
|
|
291
298
|
JSON.stringify(ctx.nextConfig)
|
|
299
|
+
).replaceAll(
|
|
300
|
+
"process.env.__PRIVATE_NEXT_ENV_LOADER_PATH",
|
|
301
|
+
JSON.stringify(ctx.nextEnvLoaderPathRelativeToProjectDir || "")
|
|
292
302
|
);
|
|
293
303
|
// Annotate the CommonJS export names for ESM import in node:
|
|
294
304
|
0 && (module.exports = {
|