api #

Declarations
#

task runner and toolkit extending SvelteKit

327 declarations

afterNavigate
#

analyze_gen_result
#

analyze_gen_results
#

gen.ts view source

(gen_results: GenResults): Promise<AnalyzedGenResult[]>

gen_results

returns

Promise<AnalyzedGenResult[]>

AnalyzedGenResult
#

applyAction
#

sveltekit_shim_app_forms.ts view source

<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: ActionResult<Success, Failure>) => Promise<void>

Args
#

args.ts view source

Args

These extend the CLI args for tasks. Anything can be assigned to a task's args. It's just a mutable POJO dictionary. Downstream tasks will see args that upstream events mutate, unless invoke_task is called with modified args. Upstream tasks can use listeners to respond to downstream events and values. It's a beautiful mutable spaghetti mess. cant get enough The raw CLI args are handled by mri - https://github.com/lukeed/mri

_

type Array<string>

help

type boolean

ArgSchema
#

ArgValue
#

asset
#

sveltekit_shim_app_paths.ts view source

(file: "/CNAME" | "/favicon.png" | "/logo.svg" | "/robots.txt" | (string & {})): string

file

type "/CNAME" | "/favicon.png" | "/logo.svg" | "/robots.txt" | (string & {})

returns

string

assets
#

base
#

base_path_to_path_id
#

paths.ts view source

(base_path: string, p?: Paths): PathId

base_path

type string

p

type Paths
default infer_paths(base_path)

returns

PathId

beforeNavigate
#

browser
#

BUILD_CACHE_METADATA_FILENAME
#

BUILD_CACHE_VERSION
#

BuildCacheMetadata
#

build_cache.ts view source

ZodObject<{ version: ZodString; git_commit: ZodNullable<ZodString>; build_cache_config_hash: ZodString; timestamp: ZodString; outputs: ZodArray<...>; }, $strict>

Metadata stored in .gro/ directory to track build cache validity. Schema validates structure at load time to catch corrupted cache files.

building
#

BuildOutputEntry
#

build_cache.ts view source

ZodObject<{ path: ZodString; hash: ZodString; size: ZodNumber; mtime: ZodNumber; ctime: ZodNumber; mode: ZodNumber; }, $strict>

Metadata about a single build output file. Includes cryptographic hash for validation plus filesystem stats for debugging and optimization.

CHANGESET_CLI
#

CHANGESET_DIR
#

CHANGESET_PUBLIC_ACCESS
#

CHANGESET_RESTRICTED_ACCESS
#

ChangesetAccess
#

ChangesetBump
#

clean_fs
#

clean_fs.ts view source

({ build, build_dev, build_dist, sveltekit, nodemodules, }: { build?: boolean | undefined; build_dev?: boolean | undefined; build_dist?: boolean | undefined; sveltekit?: boolean | undefined; nodemodules?: boolean | undefined; }, rm_options?: RmOptions): Promise<...>

__0

type { build?: boolean | undefined; build_dev?: boolean | undefined; build_dist?: boolean | undefined; sveltekit?: boolean | undefined; nodemodules?: boolean | undefined; }

rm_options

type RmOptions
default {force: true, recursive: true}

returns

Promise<void>

Cli
#

collect_build_outputs
#

build_cache.ts view source

(build_dirs: string[]): Promise<{ path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]>

Collects information about all files in build output directories. Returns an array of entries with path, hash, size, mtime, ctime, and mode.

Files are hashed in parallel for performance. For very large builds (10k+ files), this may take several seconds but ensures complete cache validation.

build_dirs

Array of output directories to scan (e.g., ['build', 'dist', 'dist_server'])

type string[]

returns

Promise<{ path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]>

compute_build_cache_key
#

build_cache.ts view source

(config: GroConfig, log: Logger, git_commit?: string | null | undefined): Promise<{ git_commit: string | null; build_cache_config_hash: string; }>

Computes the cache key components for a build. This determines whether a cached build can be reused.

config

Gro config (build_cache_config_hash is already computed during config load)

log

Logger

type Logger

git_commit?

Optional pre-computed git commit hash (optimization to avoid re-reading)

type string | null | undefined
optional

returns

Promise<{ git_commit: string | null; build_cache_config_hash: string; }>

configure_colored_output_with_path_replacement
#

child_process_logging.ts view source

(child_process: ChildProcess, replacement?: string, cwd?: string): void

Configures process output handling with path replacements while preserving ANSI colors.

child_process

type ChildProcess

replacement

type string
default '.'

cwd

type string
default process.cwd()

returns

void

cook_gro_config
#

gro_config.ts view source

(raw_config: RawGroConfig): Promise<GroConfig>

Transforms a RawGroConfig to the more strict GroConfig. This allows users to provide a more relaxed config. Hashes the build_cache_config and deletes the raw value for security.

raw_config

returns

Promise<GroConfig>

CopyFileFilter
#

create_build_cache_metadata
#

build_cache.ts view source

(config: GroConfig, log: Logger, git_commit?: string | null | undefined, build_dirs?: string[] | undefined): Promise<{ version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { ...; }[]; }>

Creates build cache metadata after a successful build. Automatically discovers all build output directories (build/, dist/, dist_*).

config

Gro config

log

Logger

type Logger

git_commit?

Optional pre-computed git commit hash (optimization)

type string | null | undefined
optional

build_dirs?

Optional pre-discovered build directories (optimization to avoid redundant filesystem scans)

type string[] | undefined
optional

returns

Promise<{ version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; }>

create_empty_gro_config
#

create_paths
#

CreateConfigPlugins
#

CreateGroConfig
#

CreateOutpaths
#

CSS_MATCHER
#

Declaration
#

default_svelte_config
#

default_ts_transform_options
#

deserialize
#

sveltekit_shim_app_forms.ts view source

<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: string): ActionResult<Success, Failure>

result

type string

returns

ActionResult<Success, Failure>

dev
#

DevTask_Context
#

disableScrollHandling
#

discover_build_output_dirs
#

build_cache.ts view source

(): Promise<string[]>

Discovers all build output directories in the current working directory. Returns an array of directory names that exist: build/, dist/, dist_*

returns

Promise<string[]>

Disknode
#

disknode.ts view source

Disknode

id

type PathId

contents

null contents means it doesn't exist. We create the file in memory to track its dependents regardless of its existence on disk.

type string | null

external

Is the source file outside of the root_dir or excluded by watch_dir_options.filter?

type boolean

ctime

type number | null

mtime

type number | null

dependents

type Map<PathId, Disknode>

dependencies

type Map<PathId, Disknode>

EMPTY_BUILD_CACHE_CONFIG_HASH
#

gro_config.ts view source

"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"

SHA-256 hash of empty string, used for configs without build_cache_config. This ensures consistent cache behavior when no custom config is provided.

EMPTY_PACKAGE_JSON
#

package_json.ts view source

{ [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }

enhance
#

sveltekit_shim_app_forms.ts view source

<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(form_element: HTMLFormElement, submit?: SubmitFunction<Success, Failure> | undefined): { ...; }

form_element

type HTMLFormElement

submit?

type SubmitFunction<Success, Failure> | undefined
optional

returns

{ destroy(): void; }

esbuild_plugin_external_worker
#

esbuild_plugin_svelte
#

esbuild_plugin_sveltekit_local_imports
#

esbuild_plugin_sveltekit_local_imports.ts view source

(): Plugin

Adds support for imports to both .ts and .js, as well as imports without extensions that resolve to .js or .ts. Prefers .ts over any .js, and falls back to .ts if no file is found.

returns

Plugin

esbuild_plugin_sveltekit_shim_alias
#

esbuild_plugin_sveltekit_shim_app
#

esbuild_plugin_sveltekit_shim_env
#

EsbuildPluginExternalWorkerOptions
#

esbuild_plugin_external_worker.ts view source

EsbuildPluginExternalWorkerOptions

dev

type boolean

build_options

type esbuild.BuildOptions

dir

type string

svelte_compile_options

type CompileOptions

svelte_compile_module_options

type ModuleCompileOptions

svelte_preprocessors

type PreprocessorGroup | Array<PreprocessorGroup>

alias

type Record<string, string>

base_url

type ParsedSvelteConfig['base_url']

assets_url

type ParsedSvelteConfig['assets_url']

public_prefix

type string

private_prefix

type string

env_dir

type string

env_files

type Array<string>

ambient_env

type Record<string, string>

log

type Logger

EsbuildPluginSveltekitShimAliasOptions
#

EsbuildPluginSveltekitShimAppOptions
#

EsbuildPluginSveltekitShimEnvOptions
#

esbuild_plugin_sveltekit_shim_env.ts view source

EsbuildPluginSveltekitShimEnvOptions

dev

type boolean

public_prefix

type string

private_prefix

type string

env_dir

type string

env_files

type Array<string>

ambient_env

type Record<string, string>

EsbuildPluginSvelteOptions
#

esbuild_plugin_svelte.ts view source

EsbuildPluginSvelteOptions

dev

type boolean

base_url

type ParsedSvelteConfig['base_url']

dir

type string

svelte_compile_options

type CompileOptions

svelte_compile_module_options

type ModuleCompileOptions

svelte_preprocessors

type PreprocessorGroup | Array<PreprocessorGroup>

ts_transform_options

type esbuild.TransformOptions

is_ts

type (filename: string) => boolean

EVERYTHING_MATCHER
#

ExportDeclaration
#

EXPORTS_EXCLUDER_DEFAULT
#

extract_deps
#

package_json.ts view source

(package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }): PackageJsonDep[]

package_json

type { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }

returns

PackageJsonDep[]

Filer
#

filer.ts view source

root_dir

type PathId

readonly

files

type Map<PathId, Disknode>

readonly

constructor

type new (options?: FilerOptions): Filer

options
default EMPTY_OBJECT

get_by_id

get_or_create

filter

type (predicate: (disknode: Disknode) => boolean): Disknode[] | null

predicate
type (disknode: Disknode) => boolean
returns Disknode[] | null

init

Initialize the filer to populate files without watching. Safe to call multiple times - subsequent calls are no-ops. Used by gen files to access the file graph.

type (): Promise<void>

returns Promise<void>

watch

type (listener: OnFilerChange): Promise<() => void>

listener
returns Promise<() => void>

close

type (): Promise<void>

returns Promise<void>

FilerOptions
#

filer.ts view source

FilerOptions

watch_dir

type typeof watch_dir

watch_dir_options

type Partial<OmitStrict<WatchDirOptions, 'on_change'>>

package_json_cache

type Record<string, PackageJson>

log

type Logger

filter_dependents
#

filer.ts view source

(disknode: Disknode, get_by_id: (id: PathId) => Disknode | undefined, filter?: FileFilter | undefined, results?: Set<PathId>, searched?: Set<...>, log?: Logger | undefined): Set<...>

disknode

get_by_id

type (id: PathId) => Disknode | undefined

filter?

type FileFilter | undefined
optional

results

type Set<PathId>
default new Set()

searched

type Set<PathId>
default new Set()

log?

type Logger | undefined
optional

returns

Set<PathId>

find_cli
#

cli.ts view source

(name: string, cwd?: string | URL, options?: SpawnOptions | undefined): Promise<Cli | null>

Searches the filesystem for the CLI name, first local to the cwd and then globally.

name

type string

cwd

type string | URL
default process.cwd()

options?

type SpawnOptions | undefined
optional

returns

Promise<Cli | null>

null if not found locally or globally

find_genfiles
#

gen.ts view source

(input_paths: InputPath[], root_dirs: PathId[], config: GroConfig, timings?: Timings | undefined): Promise<FindGenfilesResult>

Finds modules from input paths. (see src/lib/input_path.ts for more)

input_paths

type InputPath[]

root_dirs

type PathId[]

config

timings?

type Timings | undefined
optional

returns

Promise<FindGenfilesResult>

find_tasks
#

task.ts view source

(input_paths: InputPath[], task_root_dirs: PathId[], config: GroConfig, timings?: Timings | undefined): Promise<FindTasksResult>

Finds modules from input paths. (see src/lib/input_path.ts for more)

input_paths

type InputPath[]

task_root_dirs

type PathId[]

config

timings?

type Timings | undefined
optional

returns

Promise<FindTasksResult>

FindGenfilesFailure
#

FindGenfilesResult
#

FindModulesFailure
#

FindTasksResult
#

format_directory
#

format_directory.ts view source

(log: Logger, dir: string, check?: boolean, extensions?: string, root_paths?: string, prettier_cli?: string | Cli, pm_cli?: string): Promise<SpawnResult>

Formats a directory on the filesystem. If the source directory is given, it also formats all of the root directory files. This is separated from ./format_file to avoid importing all of the prettier code inside modules that import this one. (which has a nontrivial cost)

log

type Logger

dir

type string

check

type boolean
default false

extensions

type string
default EXTENSIONS_DEFAULT

root_paths

type string
default ROOT_PATHS_DEFAULT

prettier_cli

type string | Cli
default PRETTIER_CLI_DEFAULT

pm_cli

type string
default PM_CLI_DEFAULT

returns

Promise<SpawnResult>

format_file
#

format_file.ts view source

(content: string, options: Options, base_options?: Options | null | undefined): Promise<string>

Formats a file with Prettier.

content

type string

options

type Options

base_options

- defaults to the the cwd's package.json prettier value

type Options | null | undefined
default cached_base_options

returns

Promise<string>

FoundGenfiles
#

gen.ts view source

FoundGenfiles

resolved_input_files

type Array<ResolvedInputFile>

resolved_input_files_by_root_dir

type Map<PathId, Array<ResolvedInputFile>>

resolved_input_paths

type Array<ResolvedInputPath>

FoundTask
#

FoundTasks
#

task.ts view source

FoundTasks

resolved_input_files

type Array<ResolvedInputFile>

resolved_input_files_by_root_dir

type Map<PathId, Array<ResolvedInputFile>>

resolved_input_paths

type Array<ResolvedInputPath>

input_paths

type Array<InputPath>

task_root_dirs

type Array<PathId>

Gen
#

GEN_FILE_PATTERN
#

GEN_FILE_PATTERN_TEXT
#

GEN_NO_PROD_MESSAGE
#

GenConfig
#

GenContext
#

gen.ts view source

GenContext

config

svelte_config

filer

type Filer

log

type Logger

timings

type Timings

invoke_task

origin_id

Same as import.meta.url but in path form.

type PathId

origin_path

The origin_id relative to the root dir.

type string

changed_file_id

The file that triggered dependency checking. Only available when resolving dependencies dynamically. undefined during actual generation.

type PathId | undefined

GenDependencies
#

GenDependenciesConfig
#

gen.ts view source

GenDependenciesConfig

patterns

type Array<RegExp>

files

type Array<PathId>

GenDependenciesResolver
#

GenFile
#

gen.ts view source

GenFile

id

type PathId

content

type string

origin_id

type PathId

format

type boolean

GenfileModule
#

GenfileModuleMeta
#

GenfileModuleResult
#

GenfileModuleResultFailure
#

gen.ts view source

GenfileModuleResultFailure

ok

type false

id

type PathId

reason

type string

error

type Error

elapsed

type number

GenfileModuleResultSuccess
#

gen.ts view source

GenfileModuleResultSuccess

ok

type true

id

type PathId

files

type Array<GenFile>

elapsed

type number

GenFunction
#

GenResult
#

GenResults
#

gen.ts view source

GenResults

results

type Array<GenfileModuleResult>

successes

type Array<GenfileModuleResultSuccess>

failures

type Array<GenfileModuleResultFailure>

input_count

type number

output_count

type number

elapsed

type number

get_possible_paths
#

input_path.ts view source

(input_path: InputPath, root_dirs: PathId[], extensions: string[]): Promise<PossiblePath[]>

Gets a list of possible source ids for each input path with extensions, duplicating each under root_dirs, without checking the filesystem.

input_path

root_dirs

type PathId[]

extensions

type string[]

returns

Promise<PossiblePath[]>

GIT_DIRNAME
#

GIT_SHORT_HASH_LENGTH
#

GITHUB_DIRNAME
#

github_fetch_commit_prs
#

github.ts view source

(owner: string, repo: string, commit_sha: string, token?: string | undefined, log?: Logger | undefined, cache?: Map<string, { key: string; url: string; params: any; value: any; etag: string | null; last_modified: string | null; }> | undefined, api_version?: string | undefined): Promise<...>

owner

type string

repo

type string

commit_sha

type string

token?

type string | undefined
optional

log?

type Logger | undefined
optional

cache?

type Map<string, { key: string; url: string; params: any; value: any; etag: string | null; last_modified: string | null; }> | undefined
optional

api_version?

type string | undefined
optional

returns

Promise<{ [x: string]: unknown; url: string; id: number; html_url: string; number: number; user: { [x: string]: unknown; login: string; }; }[] | null>

see also

GITHUB_REPO_MATCHER
#

GithubPullRequest
#

github.ts view source

ZodObject<{ url: ZodString; id: ZodNumber; html_url: ZodString; number: ZodNumber; user: ZodObject<{ login: ZodString; }, $loose>; }, $loose>

goto
#

sveltekit_shim_app_navigation.ts view source

(url: string | URL, opts?: { replaceState?: boolean | undefined; noScroll?: boolean | undefined; keepFocus?: boolean | undefined; invalidateAll?: boolean | undefined; invalidate?: (string | ... 1 more ... | ((url: URL) => boolean))[] | undefined; state?: PageState | undefined; } | undefined) => Promise<...>

GRO_CONFIG_FILENAME
#

GRO_DEV_DIR
#

GRO_DEV_DIRNAME
#

GRO_DIR
#

GRO_DIRNAME
#

GRO_DIST_DIR
#

GRO_DIST_PREFIX
#

GRO_PACKAGE_DIR
#

gro_paths
#

gro_plugin_gen
#

gro_plugin_server
#

gro_plugin_server.ts view source

({ entry_points, dir, outpaths, env_files, ambient_env, svelte_config, target, esbuild_build_options, rebuild_throttle_delay, cli_command, run, }?: GroPluginServerOptions): Plugin<PluginContext<object>>

__0

default {}

returns

Plugin<PluginContext<object>>

gro_plugin_sveltekit_app
#

gro_plugin_sveltekit_library
#

GroConfig
#

gro_config.ts view source

GroConfig

The config that users can extend via gro.config.ts. This is exposed to users in places like tasks and genfiles.

inheritance

extends:

see also

plugins

map_package_json

Maps the project's package.json before writing it to the filesystem. The package_json argument may be mutated, but the return value is what's used by the caller. Returning null is a no-op for the caller.

type PackageJsonMapper | null

task_root_dirs

The root directories to search for tasks given implicit relative input paths. Defaults to ./src/lib, then the cwd, then the Gro package dist.

type Array<PathId>

search_filters

When searching the filsystem for tasks and genfiles, directories and files are included if they pass all of these filters.

type Array<PathFilter>

js_cli

The CLI to use that's compatible with node.

type string

pm_cli

The CLI to use that's compatible with npm install and npm link. Defaults to 'npm'.

type string

svelte_config_filename

type string

build_cache_config_hash

SHA-256 hash of the user's build_cache_config from gro.config.ts. This is computed during config normalization and the raw value is immediately deleted. If no build_cache_config was provided, this is the hash of an empty string.

type string

GroConfigModule
#

GroPluginGenOptions
#

gro_plugin_gen.ts view source

GroPluginGenOptions

input_paths

type Array<string>

root_dirs

type Array<string>

flush_debounce_delay

type number

GroPluginServerOptions
#

gro_plugin_server.ts view source

GroPluginServerOptions

entry_points

same as esbuild's entryPoints

type Array<string>

dir

type string

outpaths

Returns the Outpaths given a dev param. Decoupling this from plugin creation allows it to be created generically, so the build and dev tasks can be the source of truth for dev.

env_files

type Array<string>

ambient_env

type Record<string, string>

svelte_config

type SvelteConfig

target

type string

esbuild_build_options

Optionally map the esbuild options.

type (base_options: esbuild.BuildOptions) => esbuild.BuildOptions

rebuild_throttle_delay

Milliseconds to throttle rebuilds. Should be longer than it takes to build to avoid backpressure.

type number

cli_command

The CLI command to run the server, like 'node' or 'bun' or 'deno'. Receives the path to the server js file as its argument.

type string

run

Whether to run the server or not after building.

type boolean

GroPluginSveltekitAppOptions
#

gro_plugin_sveltekit_app.ts view source

GroPluginSveltekitAppOptions

host_target

Used for finalizing a SvelteKit build like adding a .nojekyll file for GitHub Pages.

well_known_package_json

If truthy, adds /.well-known/package.json to the static output. If a function, maps the value.

type boolean | PackageJsonMapper

well_known_source_json

If truthy, adds /.well-known/source.json and /.well-known/src/ to the static output. If a function, maps the value.

type boolean | SourceJsonMapper

well_known_src_files

If truthy, copies src/ to /.well-known/src/ to the static output. Pass a function to customize which files get copied.

type boolean | CopyFileFilter

vite_cli

The Vite CLI to use.

type string

GroPluginSveltekitLibraryOptions
#

has_dep
#

package_json.ts view source

(dep_name: string, package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; ... 25 more ...; exports?: string | ... 2 more ... | undefined; }): boolean

dep_name

type string

package_json

type { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }

returns

boolean

has_server
#

gro_plugin_server.ts view source

(path?: PathId): Promise<Result<object, { message: string; }>>

path

type PathId
default SERVER_SOURCE_ID

returns

Promise<Result<object, { message: string; }>>

has_sveltekit_app
#

sveltekit_helpers.ts view source

(svelte_config_path?: string): Promise<Result<object, { message: string; }>>

svelte_config_path

type string
default SVELTE_CONFIG_FILENAME

returns

Promise<Result<object, { message: string; }>>

has_sveltekit_library
#

sveltekit_helpers.ts view source

(package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }, svelte_config?: ParsedSvelteConfig, dep_name?: string): Promise<...>

package_json

type { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }

svelte_config

default default_svelte_config

dep_name

type string
default SVELTE_PACKAGE_DEP_NAME

returns

Promise<Result<object, { message: string; }>>

HostTarget
#

ImportSpecifier
#

infer_declarations_from_file_type
#

parse_exports.ts view source

(file_path: PathId, declarations?: ExportDeclaration[]): ExportDeclaration[]

file_path

type PathId

declarations

type ExportDeclaration[]
default []

returns

ExportDeclaration[]

infer_paths
#

InputPath
#

invalidate
#

invalidateAll
#

invoke_task
#

invoke_task.ts view source

(task_name: RawInputPath, args: Args | undefined, config: GroConfig, initial_filer?: Filer | undefined, initial_timings?: Timings | null | undefined, parent_log?: Logger | undefined): Promise<...>

Invokes Gro tasks by name using the filesystem as the source.

When a task is invoked, Gro first searches for tasks in the current working directory. and falls back to searching Gro's directory, if the two are different. See src/lib/input_path.ts for info about what "task_name" can refer to. If it matches a directory, all of the tasks within it are logged, both in the current working directory and Gro.

This code is particularly hairy because we're accepting a wide range of user input and trying to do the right thing. Precise error messages are especially difficult and there are some subtle differences in the complex logical branches. The comments describe each condition.

task_name

- The name of the task to invoke.

args

- The CLI args to pass to the task.

type Args | undefined

config

- The Gro configuration.

initial_filer?

type Filer | undefined
optional

initial_timings?

- The timings to use for the top-level task, null for composed tasks.

type Timings | null | undefined
optional

parent_log?

type Logger | undefined
optional

returns

Promise<void>

InvokeTask
#

is_build_cache_valid
#

build_cache.ts view source

(config: GroConfig, log: Logger, git_commit?: string | null | undefined): Promise<boolean>

Main function to check if the build cache is valid. Returns true if the cached build can be used, false if a fresh build is needed.

config

Gro config

log

Logger

type Logger

git_commit?

Optional pre-computed git commit hash (optimization)

type string | null | undefined
optional

returns

Promise<boolean>

is_external_module
#

is_gen_path
#

is_gro_id
#

is_private_env
#

env.ts view source

(key: string, public_prefix: string, private_prefix: string): boolean

key

type string

public_prefix

type string

private_prefix

type string

returns

boolean

is_public_env
#

env.ts view source

(key: string, public_prefix: string, private_prefix: string): boolean

key

type string

public_prefix

type string

private_prefix

type string

returns

boolean

is_task_path
#

IS_THIS_GRO
#

JS_CLI_DEFAULT
#

JS_MATCHER
#

JSON_MATCHER
#

LIB_DIR
#

LIB_DIRNAME
#

LIB_PATH
#

load_build_cache_metadata
#

build_cache.ts view source

(): Promise<{ version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; } | null>

Loads build cache metadata from .gro/ directory. Invalid or corrupted cache files are automatically deleted.

returns

Promise<{ version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; } | null>

load_env
#

env.ts view source

(dev: boolean, visibility: "public" | "private", public_prefix: string, private_prefix: string, env_dir?: string | undefined, env_files?: string[], ambient_env?: ProcessEnv): Record<...>

dev

type boolean

visibility

type "public" | "private"

public_prefix

type string

private_prefix

type string

env_dir?

type string | undefined
optional

env_files

type string[]
default ['.env', '.env.' + (dev ? 'development' : 'production')]

ambient_env

type ProcessEnv
default process.env

returns

Record<string, string>

load_from_env
#

env.ts view source

(key: string, paths?: string[]): string | undefined

Loads a single env value without merging it into process.env. By default searches process.env, then a local .env if one exists, then ../.env if it exists. Empty strings are semantically the same as undefined for more ergonomic fallbacks.

key

type string

paths

type string[]
default ['.env', '../.env']

returns

string | undefined

load_genfiles
#

gen.ts view source

(found_genfiles: FoundGenfiles, timings?: Timings | undefined): Promise<LoadGenfilesResult>

found_genfiles

timings?

type Timings | undefined
optional

returns

Promise<LoadGenfilesResult>

load_gro_config
#

gro_config.ts view source

(dir?: string): Promise<GroConfig>

dir

type string
default paths.root

returns

Promise<GroConfig>

load_gro_package_json
#

package_json.ts view source

(): Promise<{ [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }>

returns

Promise<{ [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }>

load_module
#

modules.ts view source

<TModule extends Record<string, any>>(id: PathId, validate?: ((mod: Record<string, any>) => mod is TModule) | undefined, bust_cache?: boolean | undefined): Promise<LoadModuleResult<TModule>>

id

type PathId

validate?

type ((mod: Record<string, any>) => mod is TModule) | undefined
optional

bust_cache?

type boolean | undefined
optional

returns

Promise<LoadModuleResult<TModule>>

load_modules
#

modules.ts view source

<TModule extends Record<string, any>, TModuleMeta extends ModuleMeta<TModule>>(resolved_input_files: ResolvedInputFile[], validate: (mod: any) => mod is TModule, map_module_meta: (resolved_input_file: ResolvedInputFile, mod: TModule) => TModuleMeta, timings?: Timings | undefined): Promise<...>

resolved_input_files

type ResolvedInputFile[]

validate

type (mod: any) => mod is TModule

map_module_meta

type (resolved_input_file: ResolvedInputFile, mod: TModule) => TModuleMeta

timings?

type Timings | undefined
optional

returns

Promise<LoadModulesResult<TModuleMeta>>

load_package_json
#

package_json.ts view source

(dir?: string, cache?: Record<string, { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; ... 25 more ...; exports?: string | ... 2 more ... | undefined; }> | undefined, parse?: boolean, log?: Logger | undefined): Promise<...>

dir

type string
default IS_THIS_GRO ? gro_paths.root : paths.root

cache?

type Record<string, { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }> | undefined
optional

parse

type boolean
default true

log?

type Logger | undefined
optional

returns

Promise<{ [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }>

load_svelte_config
#

svelte_config.ts view source

({ dir, config_filename, }?: { dir?: string | undefined; config_filename?: string | undefined; }): Promise<Config | null>

Loads a SvelteKit config at dir.

__0

type { dir?: string | undefined; config_filename?: string | undefined; }
default EMPTY_OBJECT

returns

Promise<Config | null>

null if no config is found

load_tasks
#

task.ts view source

(found_tasks: FoundTasks, root_path?: PathId): Promise<LoadTasksResult>

found_tasks

root_path

type PathId
default process.cwd()

returns

Promise<LoadTasksResult>

LoadedGenfiles
#

LoadedTasks
#

LoadGenfilesFailure
#

LoadGenfilesResult
#

LoadModuleFailure
#

LoadModuleResult
#

LoadModulesFailure
#

modules.ts view source

LoadModulesFailure<TModuleMeta>

generics

TModuleMeta

constraint ModuleMeta

type

type 'load_module_failures'

load_module_failures

type Array<LoadModuleFailure>

reasons

type Array<string>

modules

type Array<TModuleMeta>

LoadModulesResult
#

LoadTasksFailure
#

LoadTasksResult
#

LOCKFILE_FILENAME
#

log_error_reasons
#

log_task_help
#

log_tasks
#

task_logging.ts view source

(log: Logger, loaded_tasks: LoadedTasks, log_intro?: boolean): void

log

type Logger

loaded_tasks

log_intro

type boolean
default true

returns

void

map_child_process_output
#

child_process_logging.ts view source

(child_process: ChildProcess, transform: (data: string) => string): void

Maps child process output through a transform function.

child_process

type ChildProcess

transform

type (data: string) => string

returns

void

map_sveltekit_aliases
#

sveltekit_helpers.ts view source

(specifier: string, aliases: [string, string][]): string

Map an import specifier with the SvelteKit aliases.

specifier

type string

aliases

type [string, string][]

returns

string

merge_envs
#

env.ts view source

(envs: Record<string, string | undefined>[], visibility: "public" | "private", public_prefix: string, private_prefix: string): Record<string, string>

envs

type Record<string, string | undefined>[]

visibility

type "public" | "private"

public_prefix

type string

private_prefix

type string

returns

Record<string, string>

MODULE_PATH_LIB_PREFIX
#

MODULE_PATH_SRC_PREFIX
#

ModuleMeta
#

modules.ts view source

ModuleMeta<TModule>

generics

TModule

constraint Record<string, any>
default Record<string, any>

id

type PathId

mod

type TModule

navigating
#

NODE_MODULES_DIRNAME
#

normalize_gen_config
#

OnFilerChange
#

Outpaths
#

PACKAGE_JSON_FILENAME
#

PackageJsonDep
#

PackageJsonMapper
#

page
#

sveltekit_shim_app_state.ts view source

Page<{ module_path?: string | undefined; }, "/" | "/about" | "/docs" | "/docs/api" | "/docs/api/[...module_path]" | "/docs/library" | "/history" | null>

parse_args
#

args.ts view source

<TOutput extends Record<string, ArgValue> = Args, TInput extends Record<string, ArgValue> = Args>(unparsed_args: TInput, schema: ZodType<TOutput, TInput, $ZodTypeInternals<TOutput, TInput>>): ZodSafeParseResult<...>

Parses user input args with a Zod schema. Sets the correct source of truth for no- versions of args, to the opposite of the unprefixed versions when not included in unparsed_args. This is needed because CLI args don't have a normal way of setting falsy values, so instead the args parser mri will pass through the truthy versions of args without the no- prefix. When we declare task args schemas, we need include both versions with their defaults to get correct --help output. Parsing like this also ensures data consistency for both versions because mri only creates one. A simpler implementation could replace mri, but it handles some finicky details well.

unparsed_args

type TInput

schema

type ZodType<TOutput, TInput, $ZodTypeInternals<TOutput, TInput>>

returns

ZodSafeParseResult<TOutput>

parse_exports
#

parse_exports.ts view source

(id: PathId, program?: Program | undefined, declarations?: ExportDeclaration[], log?: Logger | undefined): ExportDeclaration[]

Parse exports from a file based on its file type and content.

id

type PathId

program?

type Program | undefined
optional

declarations

type ExportDeclaration[]
default []

log?

type Logger | undefined
optional

returns

ExportDeclaration[]

parse_imports
#

parse_imports.ts view source

(id: PathId, contents: string, ignore_types?: boolean): ImportSpecifier[]

id

type PathId

contents

type string

ignore_types

type boolean
default true

returns

ImportSpecifier[]

parse_repo_url
#

package_json.ts view source

(package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }): { ...; } | undefined

package_json

type { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }

returns

{ owner: string; repo: string; } | undefined

parse_svelte_config
#

svelte_config.ts view source

({ dir_or_config, config_filename, }?: { dir_or_config?: string | Config | undefined; config_filename?: string | undefined; }): Promise<ParsedSvelteConfig>

Returns Gro-relevant properties of a SvelteKit config as a convenience wrapper around load_svelte_config. Needed because SvelteKit doesn't expose its config resolver.

__0

type { dir_or_config?: string | Config | undefined; config_filename?: string | undefined; }
default EMPTY_OBJECT

returns

Promise<ParsedSvelteConfig>

ParsedSvelteConfig
#

svelte_config.ts view source

ParsedSvelteConfig

A subset of SvelteKit's config in a form that Gro uses because SvelteKit doesn't expose its config resolver. Flattens things out to keep them simple and easy to pass around, and doesn't deal with most properties, but includes the full svelte_config. The base and assets in particular are renamed for clarity with Gro's internal systems, so these properties become first-class vocabulary inside Gro.

svelte_config

type SvelteConfig | null

alias

type Record<string, string>

base_url

type '' | `/${string}` | undefined

assets_url

type '' | `http://${string}` | `https://${string}` | undefined

assets_path

Same as the SvelteKit files.assets.

type string

lib_path

Same as the SvelteKit files.lib.

type string

routes_path

Same as the SvelteKit files.routes.

type string

env_dir

type string | undefined

private_prefix

type string | undefined

public_prefix

type string | undefined

svelte_compile_options

type CompileOptions

svelte_compile_module_options

type ModuleCompileOptions

svelte_preprocessors

type PreprocessorGroup | Array<PreprocessorGroup> | undefined

ParseExportsContext
#

parse_exports_context.ts view source

A class to track export context and determine export kinds.

log

type Logger | undefined

readonly

debug

constructor

type new (program: Program, log?: Logger | undefined): ParseExportsContext

program
type Program
log?
type Logger | undefined
optional

analyze_source_file

Analyze a source file to prepare for export processing.

type (source_file: SourceFile): void

source_file
type SourceFile
returns void

process_exports

Process a list of exported symbols and identify their kinds.

type (source_file: SourceFile, exports: Symbol[], declarations?: ExportDeclaration[]): ExportDeclaration[]

source_file
type SourceFile
exports
type Symbol[]
declarations
type ExportDeclaration[]
default []
returns ExportDeclaration[]

path_id_to_base_path
#

paths.ts view source

(path_id: PathId, p?: Paths): string

path_id

type PathId

p

type Paths
default infer_paths(path_id)

returns

string

paths
#

Paths
#

paths.ts view source

Paths

root

type string

source

type string

lib

type string

build

type string

build_dev

type string

config

type string

Plugin
#

plugin.ts view source

Plugin<TPluginContext>

Gro Plugins enable custom behavior during gro dev and gro build. In contrast, Adapters use the results of gro build to produce final artifacts.

generics

TPluginContext

constraint PluginContext

name

type string

setup

type (ctx: TPluginContext) => void | Promise<void>

adapt

type (ctx: TPluginContext) => void | Promise<void>

teardown

type (ctx: TPluginContext) => void | Promise<void>

PluginContext
#

plugin.ts view source

PluginContext<TArgs>

generics

TArgs

default object

inheritance

extends:
  • TaskContext<TArgs>

dev

type boolean

watch

type boolean

Plugins
#

plugin.ts view source

See Plugins.create for a usage example.

generics

TPluginContext

constraint PluginContext

ctx

type TPluginContext

readonly

instances

type Array<Plugin<TPluginContext>>

readonly

constructor

type new <TPluginContext extends PluginContext>(ctx: TPluginContext, instances: Plugin<PluginContext<object>>[]): Plugins<TPluginContext>

ctx
type TPluginContext
instances
type Plugin<PluginContext<object>>[]

create

type <TPluginContext extends PluginContext>(ctx: TPluginContext): Promise<Plugins<TPluginContext>>

static
ctx
type TPluginContext
returns Promise<Plugins<TPluginContext>>

setup

type (): Promise<void>

returns Promise<void>

adapt

type (): Promise<void>

returns Promise<void>

teardown

type (): Promise<void>

returns Promise<void>

PM_CLI_DEFAULT
#

PossiblePath
#

preloadCode
#

preloadData
#

PRETTIER_CLI_DEFAULT
#

print_build_result
#

print_command_args
#

print_path
#

process_ts_exports
#

parse_exports.ts view source

(source_file: SourceFile, program: Program, exports: Symbol[], declarations?: ExportDeclaration[], log?: Logger | undefined): ExportDeclaration[]

Process TypeScript exports, identifying their kinds.

source_file

type SourceFile

program

type Program

exports

type Symbol[]

declarations

type ExportDeclaration[]
default []

log?

type Logger | undefined
optional

returns

ExportDeclaration[]

RawGenFile
#

gen.ts view source

RawGenFile

content

type string

filename

type string

format

type boolean

RawGenResult
#

RawGroConfig
#

gro_config.ts view source

RawGroConfig

The relaxed variant of GroConfig that users can provide via gro.config.ts. Superset of GroConfig.

see also

plugins

map_package_json

type PackageJsonMapper | null

task_root_dirs

type Array<string>

search_filters

type PathFilter | Array<PathFilter> | null

js_cli

type string

pm_cli

type string

build_cache_config

Optional object defining custom build inputs for cache invalidation. This value is hashed during config normalization and used to detect when builds need to be regenerated due to non-source changes.

Use cases: - Environment variables baked into build: {api_url: process.env.PUBLIC_API_URL} - External data files: {data: fs.readFileSync('data.json', 'utf-8')} - Build feature flags: {enable_analytics: true}

Can be a static object or an async function that returns an object.

IMPORTANT: It's safe to include secrets here because they are hashed and deleted during config normalization. The raw value is never logged or persisted.

type | Record<string, unknown> | (() => Record<string, unknown> | Promise<Record<string, unknown>>)

RawInputPath
#

README_FILENAME
#

render_env_shim_module
#

sveltekit_shim_env.ts view source

(dev: boolean, mode: "static" | "dynamic", visibility: "public" | "private", public_prefix?: string, private_prefix?: string, env_dir?: string | undefined, env_files?: string[] | undefined, ambient_env?: Record<...> | undefined): string

Generates a module shim for SvelteKit's $env imports.

dev

type boolean

mode

type "static" | "dynamic"

visibility

type "public" | "private"

public_prefix

type string
default 'PUBLIC_'

private_prefix

type string
default ''

env_dir?

type string | undefined
optional

env_files?

type string[] | undefined
optional

ambient_env?

type Record<string, string | undefined> | undefined
optional

returns

string

render_sveltekit_shim_app_environment
#

render_sveltekit_shim_app_paths
#

sveltekit_shim_app.ts view source

(base_url?: "" | `/${string}` | undefined, assets_url?: "" | `http://${string}` | `https://${string}` | undefined): string

base_url

type "" | `/${string}` | undefined
default ''

assets_url

type "" | `http://${string}` | `https://${string}` | undefined
default ''

returns

string

replace_extension
#

paths.ts view source

(path: string, new_extension: string): string

path

type string

new_extension

type string

returns

string

replace_plugin
#

plugin.ts view source

(plugins: Plugin<PluginContext<object>>[], new_plugin: Plugin<PluginContext<object>>, name?: string): Plugin<PluginContext<object>>[]

Replaces a plugin by name in plugins without mutating the param. Throws if the plugin name cannot be found.

plugins

- accepts the same types as the return value of CreateConfigPlugins

type Plugin<PluginContext<object>>[]

new_plugin

type Plugin<PluginContext<object>>

name

-

type string
default new_plugin.name

returns

Plugin<PluginContext<object>>[]

plugins with new_plugin at the index of the plugin with name

resolve
#

sveltekit_shim_app_paths.ts view source

<T extends RouteId | Pathname>(...args: ResolveArgs<T>): "/" | "/about" | "/docs" | "/docs/api" | "/docs/library" | "/history" | `${`/docs/api/${string}` & {}}` | `${`/docs/api/${string}/` & {}}` | ... 12 more ... | `/${string}/history/`

args

type ResolveArgs<T>

returns

"/" | "/about" | "/docs" | "/docs/api" | "/docs/library" | "/history" | `${`/docs/api/${string}` & {}}` | `${`/docs/api/${string}/` & {}}` | `/${string}/` | `/${string}/about` | `/${string}/docs` | `/${string}/docs/api` | `/${string}/docs/library` | `/${string}/history` | ... 6 more ... | `/${string}/history/`

resolve_cli
#

cli.ts view source

(name_or_cli: string | Cli, args: string[] | undefined, cwd: string | URL | undefined, log?: Logger | undefined, options?: SpawnOptions | undefined): Promise<...>

name_or_cli

type string | Cli

args

type string[]
default []

cwd

type string | URL | undefined

log?

type Logger | undefined
optional

options?

type SpawnOptions | undefined
optional

returns

Promise<Cli | undefined>

resolve_gro_module_path
#

gro_helpers.ts view source

(path?: string): string

Resolves a path to an internal Gro file. Prefers any local installation of Gro and falls back to the current CLI context.

Uses heuristics to find path, so may fail in some rare corner cases. Currently looks for gro.js as a sibling to the path arg for detection. If this fails for your usecases, rename gro.js or open an issue/PR!

Used by the CLI and gro run.

case 1:

We're in a directory that has a local installation of Gro at node_modules/.bin/gro. Use this local version instead of the global.

case 2:

We're running Gro inside the Gro repo itself.

In this case, we use the build directory instead of dist. There's a paradox here for using Gro inside itself - ideally we use the dist directory because that's what's shipped, but the build directory has all of the tests, and loading two instances of its modules causes problems like instanceof checks failing. For now we'll just run from build and see if it causes any problems. There's probably a better design in here somewhere.

case 3:

Fall back to invoking Gro from wherever the CLI is being executed. When using the global CLI, this uses the global Gro installation.

path

type string
default ''

returns

string

resolve_input_files
#

input_path.ts view source

(resolved_input_paths: ResolvedInputPath[], search?: (dir: string) => Promise<ResolvedPath[]>): Promise<ResolvedInputFiles>

Finds all of the matching files for the given input paths. De-dupes source ids.

resolved_input_paths

type ResolvedInputPath[]

search

type (dir: string) => Promise<ResolvedPath[]>
default fs_search

returns

Promise<ResolvedInputFiles>

resolve_input_paths
#

input_path.ts view source

(input_paths: InputPath[], root_dirs: PathId[], extensions: string[]): Promise<ResolvedInputPaths>

Gets the path data for each input path, checking the filesystem for the possibilities and stopping at the first existing file or falling back to the first existing directory. If none is found for an input path, it's added to unmapped_input_paths.

input_paths

type InputPath[]

root_dirs

type PathId[]

extensions

type string[]

returns

Promise<ResolvedInputPaths>

resolve_specifier
#

resolve_specifier.ts view source

(specifier: string, dir: string): Promise<ResolvedSpecifier>

Maps an import specifier relative to dir, and infer the correct extension following Vite conventions. If no .js file is found for the specifier on the filesystem, it assumes .ts.

specifier

type string

dir

type string

returns

Promise<ResolvedSpecifier>

ResolvedInputFile
#

ResolvedInputFiles
#

input_path.ts view source

ResolvedInputFiles

resolved_input_files

type Array<ResolvedInputFile>

resolved_input_files_by_root_dir

type Map<PathId, Array<ResolvedInputFile>>

input_directories_with_no_files

type Array<InputPath>

ResolvedInputPath
#

ResolvedInputPaths
#

input_path.ts view source

ResolvedInputPaths

resolved_input_paths

type Array<ResolvedInputPath>

possible_paths_by_input_path

type Map<InputPath, Array<PossiblePath>>

unmapped_input_paths

type Array<InputPath>

ResolvedSpecifier
#

resolve_specifier.ts view source

ResolvedSpecifier

path_id

The resolved filesystem path for the specifier.

type PathId

path_id_with_querystring

Same as path_id but includes ?raw and other querystrings. (currently none)

type string

specifier

type string

mapped_specifier

type string

namespace

type undefined | 'sveltekit_local_imports_ts' | 'sveltekit_local_imports_js'

raw

type boolean

resolveRoute
#

sveltekit_shim_app_paths.ts view source

<T extends RouteId | Pathname>(...args: ResolveArgs<T>) => "/" | "/about" | "/docs" | "/docs/api" | "/docs/library" | "/history" | `${`/docs/api/${string}` & {}}` | `${`/docs/api/${string}/` & {}}` | ... 12 more ... | `/${string}/history/`

ROUTES_DIRNAME
#

run_gen
#

run_gen.ts view source

(gen_modules: GenfileModuleMeta[], config: GroConfig, filer: Filer, log: Logger, timings: Timings, invoke_task: InvokeTask, format_file?: ((content: string, options: Options, base_options?: Options | ... 1 more ... | undefined) => Promise<...>) | undefined): Promise<...>

gen_modules

type GenfileModuleMeta[]

config

filer

type Filer

log

type Logger

timings

type Timings

invoke_task

format_file?

type ((content: string, options: Options, base_options?: Options | null | undefined) => Promise<string>) | undefined
optional

returns

Promise<GenResults>

run_svelte_package
#

sveltekit_helpers.ts view source

(package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }, options: SveltePackageOptions | undefined, cli: string | Cli, log: Logger, pm_cli: string): Promise<...>

package_json

type { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }

options

type SveltePackageOptions | undefined

cli

type string | Cli

log

type Logger

pm_cli

type string

returns

Promise<void>

run_task
#

run_task.ts view source

(task_meta: TaskModuleMeta, unparsed_args: Args, invoke_task: (task_name: RawInputPath, args: Args | undefined, config: GroConfig, initial_filer?: Filer | undefined, initial_timings?: Timings | ... 1 more ... | undefined, parent_log?: Logger | undefined) => Promise<...>, config: GroConfig, filer: Filer, log: Logger, timings: Timings): Promise<...>

task_meta

unparsed_args

type Args

invoke_task

type (task_name: RawInputPath, args: Args | undefined, config: GroConfig, initial_filer?: Filer | undefined, initial_timings?: Timings | null | undefined, parent_log?: Logger | undefined) => Promise<...>

config

filer

type Filer

log

type Logger

timings

type Timings

returns

Promise<RunTaskResult>

RunTaskResult
#

save_build_cache_metadata
#

build_cache.ts view source

(metadata: { version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; }, log?: Logger | undefined): Promise<...>

Saves build cache metadata to .gro/ directory. Errors are logged but don't fail the build (cache is optional).

metadata

type { version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; }

log?

type Logger | undefined
optional

returns

Promise<void>

SEARCH_EXCLUDER_DEFAULT
#

gro_config.ts view source

RegExp

The regexp used by default to exclude directories and files when searching the filesystem for tasks and genfiles. Customize via search_filters in the GroConfig. See the test cases for the exact behavior.

serialize_args
#

serialize_package_json
#

package_json.ts view source

(package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }): string

package_json

type { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }

returns

string

SERVER_DIST_PATH
#

SERVER_SOURCE_ID
#

should_trigger_gen
#

gen_helpers.ts view source

(gen_file_id: PathId, changed_file_id: PathId, config: GroConfig, filer: Filer, log: Logger, timings: Timings, invoke_task: InvokeTask): Promise<...>

Check if a file change should trigger a gen file.

gen_file_id

type PathId

changed_file_id

type PathId

config

filer

type Filer

log

type Logger

timings

type Timings

invoke_task

returns

Promise<boolean>

SilentError
#

task.ts view source

This is used to tell Gro to exit silently, usually still with with a non-zero exit code. Using it means error logging is handled by the code that threw it.

inheritance

extends:
  • Error

SOURCE_DIR
#

SOURCE_DIRNAME
#

source_json_create
#

source_json.ts view source

(package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }, lib_path?: string | undefined, log?: Logger | undefined): Promise<...>

package_json

type { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }

lib_path?

type string | undefined
optional

log?

type Logger | undefined
optional

returns

Promise<{ [x: string]: unknown; name: string; version: string; modules?: { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }[] | ...

source_json_serialize
#

source_json.ts view source

(source_json: { [x: string]: unknown; name: string; version: string; modules?: { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: string | undefined; dependencies?: string[] | undefined; dependents?: string[] | undefined; }[] | undefined; }): string

source_json

type { [x: string]: unknown; name: string; version: string; modules?: { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }[] | undefine...

returns

string

source_modules_create
#

source_json.ts view source

(exports: string | Record<string, unknown> | null | undefined, lib_path?: string, log?: Logger | undefined): Promise<{ [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; ... 21 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: string | undefined; dependencies?: string[] | undefined; dependents?: string[] | undefined; }[] | undefined>

exports

type string | Record<string, unknown> | null | undefined

lib_path

type string
default paths.lib

log?

type Logger | undefined
optional

returns

Promise<{ [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; ... 18 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: str...

SourceJsonMapper
#

spawn_cli
#

cli.ts view source

(name_or_cli: string | Cli, args?: string[], log?: Logger | undefined, options?: SpawnOptions | undefined): Promise<SpawnResult | undefined>

Spawns a CLI if available using Belt's spawn. If a string is provided for name_or_cli, it checks first local to the cwd and then globally.

name_or_cli

type string | Cli

args

type string[]
default []

log?

type Logger | undefined
optional

options?

type SpawnOptions | undefined
optional

returns

Promise<SpawnResult | undefined>

undefined if no CLI is found, or the spawn result

spawn_cli_process
#

cli.ts view source

(name_or_cli: string | Cli, args?: string[], log?: Logger | undefined, options?: SpawnOptions | undefined): Promise<SpawnedProcess | undefined>

Spawns a CLI if available using Belt's spawn_process. If a string is provided for name_or_cli, it checks first local to the cwd and then globally.

name_or_cli

type string | Cli

args

type string[]
default []

log?

type Logger | undefined
optional

options?

type SpawnOptions | undefined
optional

returns

Promise<SpawnedProcess | undefined>

undefined if no CLI is found, or the spawn result

spawn_with_loader
#

gro_helpers.ts view source

(loader_path: string, invoke_path: string, argv: string[], js_cli?: string): Promise<SpawnResult>

Runs a file using the Gro loader.

Uses conditional exports to correctly set up esm-env as development by default, so if you want production set NODE_ENV=production.

loader_path

path to loader

type string

invoke_path

path to file to spawn with node

type string

argv

type string[]

js_cli

type string
default JS_CLI_DEFAULT

returns

Promise<SpawnResult>

see also

SVELTE_CHECK_CLI
#

SVELTE_CONFIG_FILENAME
#

SVELTE_MATCHER
#

SVELTE_PACKAGE_CLI
#

SVELTE_PACKAGE_DEP_NAME
#

SVELTE_RUNES_MATCHER
#

SVELTE_SCRIPT_MATCHER
#

SVELTEKIT_BUILD_DIRNAME
#

SVELTEKIT_CLI
#

SVELTEKIT_DEV_DIRNAME
#

SVELTEKIT_DIST_DIRNAME
#

SVELTEKIT_ENV_MATCHER
#

SVELTEKIT_GLOBAL_SPECIFIER
#

SVELTEKIT_SHIM_APP_ENVIRONMENT_MATCHER
#

SVELTEKIT_SHIM_APP_PATHS_MATCHER
#

sveltekit_shim_app_specifiers
#

sveltekit_sync
#

sveltekit_helpers.ts view source

(sveltekit_cli?: string | Cli, pm_cli?: string): Promise<void>

sveltekit_cli

type string | Cli
default SVELTEKIT_CLI

pm_cli

type string
default PM_CLI_DEFAULT

returns

Promise<void>

sveltekit_sync_if_available
#

sveltekit_helpers.ts view source

(sveltekit_cli?: string | Cli): Promise<void>

If the SvelteKit CLI is found and its .svelte-kit directory is not, run svelte-kit sync.

sveltekit_cli

type string | Cli
default SVELTEKIT_CLI

returns

Promise<void>

sveltekit_sync_if_obviously_needed
#

sveltekit_helpers.ts view source

(sveltekit_cli?: string | Cli): Promise<void>

If the SvelteKit CLI is found and its .svelte-kit directory is not, run svelte-kit sync.

sveltekit_cli

type string | Cli
default SVELTEKIT_CLI

returns

Promise<void>

SVELTEKIT_VITE_CACHE_PATH
#

SveltePackageOptions
#

sveltekit_helpers.ts view source

SveltePackageOptions

Options to the SvelteKit packaging CLI.

see also

watch

Watch files in src/lib for changes and rebuild the package

type boolean

w

Alias for watch.

type boolean

input

The input directory which contains all the files of the package. Defaults to src/lib

type string

i

Alias for input.

type string

output

The output directory where the processed files are written to. Your package.json's exports should point to files inside there, and the files array should include that folder. Defaults to dist

type string

o

Alias for output.

type string

types

Whether or not to create type definitions (d.ts files). We strongly recommend doing this as it fosters ecosystem library quality. Defaults to true

type boolean

t

Alias for types.

type boolean

tsconfig

The path to a tsconfig or jsconfig. When not provided, searches for the next upper tsconfig/jsconfig in the workspace path.

type string

sync_package_json
#

package_json.ts view source

(map_package_json: PackageJsonMapper, log: Logger, write?: boolean, dir?: string, exports_dir?: string): Promise<{ package_json: { [x: string]: unknown; name: string; version: string; ... 29 more ...; exports?: string | ... 2 more ... | undefined; } | null; changed: boolean; }>

map_package_json

log

type Logger

write

type boolean
default true

dir

type string
default paths.root

exports_dir

type string
default paths.lib

returns

Promise<{ package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; ... 25 more ...; exports?: string | ... 2 more ... | undefined; } | null; changed: boolean; }>

Task
#

task.ts view source

Task<TArgs, TArgsSchema, TReturn>

generics

TArgs

default Args

TArgsSchema

constraint z.ZodType<Args, Args>
default z.ZodType<Args, Args>

TReturn

default unknown

run

type (ctx: TaskContext<TArgs>) => TReturn | Promise<TReturn>

summary

type string

Args

type TArgsSchema

TASK_FILE_SUFFIX_JS
#

TASK_FILE_SUFFIX_TS
#

TASK_FILE_SUFFIXES
#

TaskArgs
#

TaskContext
#

TaskError
#

task.ts view source

This is used by tasks to signal a known failure. It's useful for cleaning up logging because we usually don't need their stack trace.

inheritance

extends:
  • Error

TaskModule
#

TaskModuleMeta
#

task.ts view source

TaskModuleMeta

inheritance

extends:
  • ModuleMeta<TaskModule>

name

type string

to_cli_name
#

to_default_compile_module_options
#

svelte_config.ts view source

({ dev, generate, filename, rootDir, warningFilter, }: CompileOptions): ModuleCompileOptions

__0

type CompileOptions

returns

ModuleCompileOptions

to_define_import_meta_env
#

esbuild_helpers.ts view source

(dev: boolean, base_url: "" | `/${string}` | undefined, ssr?: boolean, mode?: string): Record<string, string>

Creates an esbuild define shim for Vite's import.meta\.env.

dev

type boolean

base_url

- best-effort shim from SvelteKit's base to Vite's import.meta\.env.BASE_URL

type "" | `/${string}` | undefined

ssr

type boolean
default true

mode

type string
default dev ? 'development' : 'production'

returns

Record<string, string>

see also

to_forwarded_args
#

args.ts view source

(command: string, raw_rest_args?: string[] | undefined, cache?: Record<string, Args | undefined>): Args

Parses process.argv for the specified command, so given gro taskname arg1 --arg2 -- eslint eslintarg1 --eslintarg2 -- tsc --tscarg1 --tscarg2 the command 'eslint' returns eslintarg1 --eslintarg2 and 'tsc' returns --tscarg1 and --tscarg2.

command

type string

raw_rest_args?

type string[] | undefined
optional

cache

type Record<string, Args | undefined>
default to_forwarded_args_by_command(raw_rest_args)

returns

Args

to_forwarded_args_by_command
#

args.ts view source

(raw_rest_args?: string[]): Record<string, Args | undefined>

raw_rest_args

type string[]
default to_raw_rest_args()

returns

Record<string, Args | undefined>

to_gen_result
#

gen.ts view source

(origin_id: PathId, raw_result: RawGenResult): GenResult

origin_id

type PathId

raw_result

returns

GenResult

to_hash
#

to_implicit_forwarded_args
#

args.ts view source

(command_to_strip?: string | undefined, raw_rest_args?: string[]): Args

Gets all args after the first -- without assuming a command name. This is useful for tasks that want to forward args directly to a tool without requiring users to specify the tool name explicitly. Optionally strips a specific command name if present for backward compatibility.

command_to_strip?

type string | undefined
optional

raw_rest_args

type string[]
default to_raw_rest_args()

returns

Args

examples

Example 1

to_input_path
#

input_path.ts view source

(raw_input_path: RawInputPath, root_path?: string): InputPath

Raw input paths are paths that users provide to Gro to reference files for tasks and gen.

A raw input path can be to a file or directory in the following forms:

- an absolute path, preserved - an explicit relative path, e.g. ./src/foo, resolved to root_path which defaults to the cwd - an implicit relative path, e.g. src/foo, preserved - an implicit relative path prefixed with gro/, transformed to absolute in the Gro directory

Thus, input paths are either absolute or implicitly relative.

raw_input_path

root_path

type string
default process.cwd()

returns

InputPath

to_input_paths
#

input_path.ts view source

(raw_input_paths: RawInputPath[], root_path?: string | undefined): InputPath[]

raw_input_paths

type RawInputPath[]

root_path?

type string | undefined
optional

returns

InputPath[]

to_output_file_name
#

to_package_exports
#

package_json.ts view source

(paths: string[]): string | Record<string, unknown> | null

paths

type string[]

returns

string | Record<string, unknown> | null

to_raw_rest_args
#

args.ts view source

(argv?: string[]): string[]

Gets the array of raw string args starting with the first --, if any.

argv

type string[]
default process.argv

returns

string[]

to_root_path
#

paths.ts view source

(id: PathId, p?: Paths): string

id

type PathId

p

type Paths
default infer_paths(id)

returns

string

to_task_args
#

args.ts view source

(argv?: string[]): { task_name: string; args: Args; }

Parses task_name and args from process.argv using mri, ignoring anything after any --.

argv

type string[]
default process.argv

returns

{ task_name: string; args: Args; }

to_task_name
#

task.ts view source

(id: PathId, task_root_dir: PathId, input_path: InputPath, root_path: PathId): string

id

type PathId

task_root_dir

type PathId

input_path

root_path

type PathId

returns

string

TS_MATCHER
#

TSCONFIG_FILENAME
#

update_changelog
#

changelog.ts view source

(owner: string, repo: string, path?: string, token?: string | undefined, log?: Logger | undefined, cache?: Map<string, { key: string; url: string; params: any; value: any; etag: string | null; last_modified: string | null; }>): Promise<...>

Updates a changelog produced by @changesets/changelog-git with better links and formatting. It's similar to @changesets/changelog-github but doesn't require a token for light usage. This may be better implemented as a standalone dependency as an alternative to @changesets/changelog-git.

owner

type string

repo

type string

path

type string
default 'CHANGELOG.md'

token?

type string | undefined
optional

log?

type Logger | undefined
optional

cache

type Map<string, { key: string; url: string; params: any; value: any; etag: string | null; last_modified: string | null; }>
default new Map()

returns

Promise<boolean>

boolean indicating if the changelog changed

update_package_json
#

package_json.ts view source

(update: (package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }) => { ...; } | ... 1 more ... | null, dir?: string, write?: boolean): Promise<...>

Updates package.json. Writes to the filesystem only when contents change.

update

type (package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }) => { ...; } | ... 1 more ... ...

dir

type string
default paths.root

write

type boolean
default true

returns

Promise<{ package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; ... 25 more ...; exports?: string | ... 2 more ... | undefined; } | null; changed: boolean; }>

updated
#

validate_build_cache
#

build_cache.ts view source

(metadata: { version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; }): Promise<...>

Validates that a cached build is still valid by checking stats and hashing outputs. Uses size as a fast negative check before expensive hashing. This is comprehensive validation to catch manual tampering or corruption.

metadata

type { version: string; git_commit: string | null; build_cache_config_hash: string; timestamp: string; outputs: { path: string; hash: string; size: number; mtime: number; ctime: number; mode: number; }[]; }

returns

Promise<boolean>

validate_gen_module
#

gen.ts view source

(mod: Record<string, any>): mod is GenfileModule

mod

type Record<string, any>

returns

boolean

validate_gro_config_module
#

gro_config.ts view source

(config_module: any, config_path: string): asserts config_module is GroConfigModule

config_module

type any

config_path

type string

returns

void

validate_task_module
#

task.ts view source

(mod: Record<string, any>): mod is TaskModule

mod

type Record<string, any>

returns

boolean

version
#

VITE_CLI
#

VITE_CONFIG_FILENAME
#

VITEST_CLI
#

watch_dir
#

watch_dir.ts view source

({ dir, on_change, filter, absolute, chokidar, ignored, }: WatchDirOptions): WatchNodeFs

Watch for changes on the filesystem using chokidar.

__0

returns

WatchNodeFs

WatchDirOptions
#

watch_dir.ts view source

WatchDirOptions

dir

type string

on_change

filter

type PathFilter | null | undefined

chokidar

type ChokidarOptions

absolute

When false, returns the path relative to dir.

type boolean

ignored

Pattern to ignore files, merged into chokidar.ignored if also provided. - undefined (default) ignores files matching .tmp. pattern - null sets no default ignore pattern - or some custom pattern

type Matcher | null

WatcherChange
#

WatcherChangeCallback
#

WatcherChangeType
#

WatchNodeFs
#

write_gen_results
#

gen.ts view source

(gen_results: GenResults, analyzed_gen_results: AnalyzedGenResult[], log: Logger): Promise<void>

gen_results

analyzed_gen_results

type AnalyzedGenResult[]

log

type Logger

returns

Promise<void>

write_package_json
#

package_json.ts view source

(serialized_package_json: string): Promise<void>

serialized_package_json

type string

returns

Promise<void>