Home / File/ nft.ts — astro Source File

nft.ts — astro Source File

Architecture documentation for nft.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.

File typescript CoreAstro CoreMiddleware 6 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  35f5d0e1_dc37_d4f0_e5da_891565ac4eda["nft.ts"]
  a459313a_22e8_effe_2583_cd7902f93327["./searchRoot.js"]
  35f5d0e1_dc37_d4f0_e5da_891565ac4eda --> a459313a_22e8_effe_2583_cd7902f93327
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  35f5d0e1_dc37_d4f0_e5da_891565ac4eda --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"]
  35f5d0e1_dc37_d4f0_e5da_891565ac4eda --> d9a92db9_c95e_9165_13ac_24b3d859d946
  6834f085_c14f_61e4_3720_10435d7dac98["fs"]
  35f5d0e1_dc37_d4f0_e5da_891565ac4eda --> 6834f085_c14f_61e4_3720_10435d7dac98
  e4df8f29_fb2f_3d70_a962_fdf6a3670b22["path"]
  35f5d0e1_dc37_d4f0_e5da_891565ac4eda --> e4df8f29_fb2f_3d70_a962_fdf6a3670b22
  f16d8c76_2866_6150_bd14_0347b59abfe9["astro"]
  35f5d0e1_dc37_d4f0_e5da_891565ac4eda --> f16d8c76_2866_6150_bd14_0347b59abfe9
  style 35f5d0e1_dc37_d4f0_e5da_891565ac4eda fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { relative as relativePath } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { copyFilesToFolder } from '@astrojs/internal-helpers/fs';
import { appendForwardSlash } from '@astrojs/internal-helpers/path';
import type { AstroIntegrationLogger } from 'astro';
import { searchForWorkspaceRoot } from './searchRoot.js';

export async function copyDependenciesToFunction(
	{
		entry,
		outDir,
		includeFiles,
		excludeFiles,
		logger,
		root,
	}: {
		entry: URL;
		outDir: URL;
		includeFiles: URL[];
		excludeFiles: URL[];
		logger: AstroIntegrationLogger;
		root: URL;
	},
	// we want to pass the caching by reference, and not by value
	cache: object,
): Promise<{
	handler: string;
}> {
	const entryPath = fileURLToPath(entry);
	logger.info(`Bundling function ${relativePath(fileURLToPath(outDir), entryPath)}`);

	// Set the base to the workspace root
	const base = pathToFileURL(appendForwardSlash(searchForWorkspaceRoot(fileURLToPath(root))));

	// The Vite bundle includes an import to `@vercel/nft` for some reason,
	// and that trips up `@vercel/nft` itself during the adapter build. Using a
	// dynamic import helps prevent the issue.
	// TODO: investigate why
	const { nodeFileTrace } = await import('@vercel/nft');
	const result = await nodeFileTrace([entryPath], {
		base: fileURLToPath(base),
		cache,
	});

	for (const error of result.warnings) {
		if (error.message.startsWith('Failed to resolve dependency')) {
			const [, module, file] = /Cannot find module '(.+?)' loaded from (.+)/.exec(error.message)!;

			// The import(astroRemark) sometimes fails to resolve, but it's not a problem
			if (module === '@astrojs/') continue;

			// Sharp is always external and won't be able to be resolved, but that's also not a problem
			if (module === 'sharp') continue;

			if (entryPath === file) {
				logger.debug(
					`[@astrojs/vercel] The module "${module}" couldn't be resolved. This may not be a problem, but it's worth checking.`,
				);
			} else {
				logger.debug(
					`[@astrojs/vercel] The module "${module}" inside the file "${file}" couldn't be resolved. This may not be a problem, but it's worth checking.`,
				);
			}
		}
		// parse errors are likely not js and can safely be ignored,
		// such as this html file in "main" meant for nw instead of node:
		// https://github.com/vercel/nft/issues/311
		else if (error.message.startsWith('Failed to parse')) {
			continue;
		} else {
			throw error;
		}
	}

	const commonAncestor = await copyFilesToFolder(
		[...result.fileList].map((file) => new URL(file, base)).concat(includeFiles),
		outDir,
		excludeFiles,
	);

	return {
		// serverEntry location inside the outDir
		handler: relativePath(commonAncestor, entryPath),
	};
}

Domain

Subdomains

Dependencies

  • ./searchRoot.js
  • astro
  • fs
  • node:path
  • node:url
  • path

Frequently Asked Questions

What does nft.ts do?
nft.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in nft.ts?
nft.ts defines 1 function(s): copyDependenciesToFunction.
What does nft.ts depend on?
nft.ts imports 6 module(s): ./searchRoot.js, astro, fs, node:path, node:url, path.
Where is nft.ts in the architecture?
nft.ts is located at packages/integrations/vercel/src/lib/nft.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/integrations/vercel/src/lib).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free