trigger.dev
Version:
A Command-Line Interface for Trigger.dev projects
101 lines (100 loc) • 5.04 kB
TypeScript
import { ResolvedConfig } from "@trigger.dev/core/v3/build";
import { BuildManifest, BuildTarget } from "@trigger.dev/core/v3/schemas";
import * as esbuild from "esbuild";
export { packageNameForImportPath as packageNameForSpecifier } from "./externals.js";
export type CreateRequireSpecifier = {
specifier: string;
/** 1-based, matching esbuild message locations */
line: number;
/** 0-based, matching esbuild message locations */
column: number;
lineText: string;
};
export type CreateRequireUsage = CreateRequireSpecifier & {
file: string;
packageName: string;
};
/**
* Finds string-literal package specifiers loaded through `createRequire`, e.g.
* `createRequire(import.meta.url)("mssql")` or
* `const req = createRequire(import.meta.url); req("mssql")`.
*
* esbuild treats `createRequire` as an opaque call: nothing it loads is ever
* resolved, so such packages are neither bundled nor collected as externals
* and are missing from deployed images. The source is parsed with
* `@babel/parser`, so comments, strings, templates, regex literals and JSX
* can never confuse the scan; a file that fails to parse is skipped
* (diagnostics must never fail a build). Binding tracking is name-based,
* module-level, and per-file: computed specifiers, shadowed names, and a
* require function imported from another file are not followed.
*/
export declare function scanSourceForCreateRequire(source: string): CreateRequireSpecifier[];
export declare const NODE_MODULES_SEGMENT_REGEX: RegExp;
/**
* Scans the bundle's input files for packages loaded through `createRequire`.
* Only files outside `node_modules` are scanned: bundled libraries commonly
* use optional-require patterns that would drown real findings in noise.
* Each file is scanned independently; results are cached per file by mtime
* and size so dev rebuilds only re-read changed files.
*/
export declare class CreateRequireCollector {
private readonly workingDir;
private _usages;
private _cache;
private _plugin;
constructor(workingDir: string);
get usages(): ReadonlyArray<CreateRequireUsage>;
get plugin(): esbuild.Plugin;
private collect;
}
export type ExtensionInstalledPackages = {
matchers: RegExp[];
/**
* True when what extensions install can't be determined in a way that
* makes false warnings likely: an extension hook threw, or an
* additionalPackages extension predates the installedPackagesForTarget
* hook (the exact extension the warning's own fix advice prescribes).
* Dev-mode warnings stay silent in that case; deploy-mode warnings are
* unaffected because the manifest externals capture layer dependencies
* there. Extensions that declare nothing are assumed to install nothing:
* package-installing extensions are the rare case and declare themselves.
*/
incomplete: boolean;
};
/**
* Package-name matchers for everything the configured build extensions
* declare they install into or externalize for the deployed image. Reads
* only the user's configured extensions; call it before internal extensions
* (e.g. the externals collector) are prepended to the build context, and it
* skips them by name as a second guard. Never throws: diagnostics must not
* fail a build.
*/
export declare function extensionInstalledPackageMatchers(config: ResolvedConfig): ExtensionInstalledPackages;
/**
* Filters collected usages down to the ones that will actually be missing at
* runtime in the deployed image: not in the resolved externals (the installed
* dependencies) and not declared as installed by a build extension.
*/
export declare function unavailableCreateRequireUsages(usages: ReadonlyArray<CreateRequireUsage>, installedPackages: Set<string>, externalMatchers: RegExp[]): CreateRequireUsage[];
/**
* Package names installed by build-layer commands (`RUN npm install pkg`
* etc.). Such installs never reach the manifest externals, so the packages
* they name must not warn; commands that install nothing specific (npm ci,
* bun run) contribute nothing.
*/
export declare function packagesInstalledByCommands(commands: ReadonlyArray<string>): string[];
/**
* The shared dev/deploy warning pipeline: suppress usages that will be
* available in the image (manifest externals, extension-declared packages,
* packages named in build-layer install commands), render the rest. Returns
* [] instead of throwing on any internal failure, and stays silent for dev
* when extension-installed packages can't be determined (see
* ExtensionInstalledPackages.incomplete).
*/
export declare function collectCreateRequireWarningMessages({ usages, buildManifest, extensionPackages, target, }: {
usages: ReadonlyArray<CreateRequireUsage>;
buildManifest: BuildManifest;
extensionPackages: ExtensionInstalledPackages;
target: BuildTarget;
}): esbuild.PartialMessage[];
export declare function createRequireUsageToWarning(usage: CreateRequireUsage, target: BuildTarget): esbuild.PartialMessage;