Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A9T9 RPA resolveIncludes

From Leeroopedia
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 }]

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment