Implementation:A9T9 RPA resolveIncludes
| Knowledge Sources | |
|---|---|
| Domains | Scripting_API, Code_Includes |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for resolving `// @include` directives in JS macro source files, provided by the Ui.Vision include resolver module.
Description
The findIncludes and resolveIncludes functions (`src/modules/js_includes.js`) implement the `// @include` directive system for JS script macros. A user can add `// @include lib/forms.js` to splice another stored JS macro's source into the current script before transpilation.
`findIncludes` scans the raw source for include directives (must start a line to avoid matching inside strings/comments). `resolveIncludes` recursively visits each include, reads the included macro's source from macro storage, splices it depth-first (each file included at most once to avoid redeclaration), detects circular includes, and returns the merged program plus a segment table mapping merged lines back to their source files.
Usage
Call `resolveIncludes` before `transpileScript` to merge all `@include` directives into a single source string. The segment table enables error line attribution across included files.
Code Reference
Source Location
- Repository: A9T9/RPA
- File: src/modules/js_includes.js
- Lines: L33-L73 (findIncludes), L74-L133 (resolveIncludes)
Signature
export function findIncludes(source: string): Array<{ path: string, line: number }>
export async function resolveIncludes(
mainSource: string,
mainPath?: string
): Promise<{
source: string, // Merged program
segments: Array<{ // Which merged line came from which file
path: string,
startLine: number,
lineCount: number,
isMain: boolean
}>
}>
Import
import { findIncludes, resolveIncludes } from '@/modules/js_includes'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| mainSource | string | Yes | JS macro source with optional `// @include` directives |
| mainPath | string | No | Base path for the main file (for segment table) |
Outputs
| Name | Type | Description |
|---|---|---|
| source | string | Merged program with all includes spliced in |
| segments | object[] | Per-file segment table for line attribution |
Usage Examples
Resolve Includes Before Transpilation
import { resolveIncludes } from '@/modules/js_includes'
import { transpileScript } from '@/modules/js_transpile'
// User script with an include directive:
// // @include lib/forms.js
// uiv.page.fill(uiv.getByLabel('Email'), 'user@example.com')
const { source, segments } = await resolveIncludes(userCode, 'main.js')
const { code } = await transpileScript(source)
Detect Include Directives
import { findIncludes } from '@/modules/js_includes'
const includes = findIncludes(source)
// [{ path: 'lib/forms.js', line: 1 }]