### Clone and Build Wireit Source: https://github.com/google/wireit/blob/main/CONTRIBUTING.md Clone the repository, install dependencies, and build the project. This is the initial setup step for development. ```sh git clone https://github.com/google/wireit.git cd wireit npm ci npm run build ``` -------------------------------- ### Install VSCode Extension Source: https://github.com/google/wireit/blob/main/README.md Install the Wireit VSCode extension from the marketplace using the command line. ```sh code --install-extension google.wireit ``` -------------------------------- ### Install Wireit Source: https://github.com/google/wireit/blob/main/README.md Install Wireit as a development dependency using npm. ```sh npm i -D wireit ``` -------------------------------- ### Wireit CLI Orchestration Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/cli.md Demonstrates the basic orchestration flow for the Wireit CLI, including getting options, running tasks, and handling errors. ```typescript const optionsResult = await getOptions() if (!optionsResult.ok) { // Log error and exit process.exit(1) } const options = optionsResult.value const result = await run(options) if (!result.ok) { for (const failure of result.error) { options.logger.log(failure) } process.exitCode = 1 } ``` -------------------------------- ### ServiceConfig Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/config.md An example of how to configure service readiness detection using a regex pattern to match output lines. ```typescript { readyWhen: { lineMatches: /listening on port \d+/ } } ``` -------------------------------- ### Example GitHub Actions Workflow with Wireit Caching Source: https://github.com/google/wireit/blob/main/README.md A complete GitHub Actions workflow demonstrating the setup for Node.js, Wireit caching, and running npm tests. Wireit automatically leverages the GitHub Actions cache. ```yaml # File: .github/workflows/tests.yml name: Tests on: [push, pull_request] jobs: tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: 24 cache: npm # Set up GitHub Actions caching for Wireit. - uses: google/wireit@setup-github-actions-caching/v2 # Install npm dependencies. - run: npm ci # Run tests. Wireit will automatically use # the GitHub Actions cache whenever possible. - run: npm test ``` -------------------------------- ### Example Output for SpawnError Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Provides an example of the user-facing message when a script process fails to spawn. ```text ❌ mypackage:build — spawn error: command not found ``` -------------------------------- ### NoCommandScriptConfig Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/config.md An example of how to configure a script with no command in Wireit's configuration file. This script acts as a dependency container. ```json { "wireit": { "build": { "dependencies": ["build:compile", "build:types"] } } } ``` -------------------------------- ### Service Script Configuration Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/config.md An example of a service script configuration in Wireit. This configures a Node.js server to run and specifies a 'readyWhen' condition based on log output. ```json { "wireit": { "server": { "command": "node server.js", "service": { "readyWhen": { "lineMatches": "listening on port" } } } } } ``` -------------------------------- ### StandardScriptConfig Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/config.md An example of a standard script configuration in Wireit. This script executes a command, caches its output, and cleans previous outputs if specified. ```json { "wireit": { "build": { "command": "tsc", "files": ["src/**/*.ts"], "output": ["lib/**"], "clean": true } } } ``` -------------------------------- ### SimpleLogger Usage Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/logger.md Demonstrates how to instantiate and use the SimpleLogger. Ensure Console and SimpleLogger are imported correctly. ```typescript import {SimpleLogger} from './logging/simple-logger.js' import {Console} from './logging/logger.js' const console = new Console(process.stdout, process.stderr) const logger = new SimpleLogger(process.cwd(), console) ``` -------------------------------- ### Wireit Configuration Example Source: https://github.com/google/wireit/blob/main/_autodocs/README.md A sample Wireit configuration defining a 'build' script with command, dependencies, files, output, and clean options. ```json { "scripts": { "build": "wireit" }, "wireit": { "build": { "command": "tsc", "dependencies": ["lint"], "files": ["src/**/*.ts"], "output": ["lib/**"], "clean": true } } } ``` -------------------------------- ### DependencyOnMissingScript Example Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Shows an example error message for DependencyOnMissingScript, indicating a specified script was not found in a dependent package. ```text ❌ package.json:8:5 — Script "nonexistent" not found in ./components ``` -------------------------------- ### LocalCache Usage Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/cache.md Demonstrates how to use the LocalCache to get cached script outputs or set new ones if a cache miss occurs. Ensure the 'script' and 'fingerprint' variables are defined before use. ```typescript import {LocalCache} from './caching/local-cache.js' import {Fingerprint} from './fingerprint.js' const cache = new LocalCache() // Check cache const hit = await cache.get(script, fingerprint) if (hit) { console.log('Cache hit!') await hit.apply() } else { console.log('Cache miss, running script...') // ... run script and capture output // Save output const files = [ {absolute: '/path/to/lib/index.js', relative: 'lib/index.js'}, {absolute: '/path/to/lib/index.d.ts', relative: 'lib/index.d.ts'}, ] await cache.set(script, fingerprint, files) } ``` -------------------------------- ### Wireit Configuration Example Source: https://github.com/google/wireit/blob/main/_autodocs/index.md This JSON object demonstrates a typical Wireit configuration within a package.json file, defining scripts, commands, dependencies, and file watching. ```json { "scripts": { "build": "wireit", "test": "wireit" }, "wireit": { "build": { "command": "tsc", "dependencies": ["lint"], "files": ["src/**/*.ts", "tsconfig.json"], "output": ["lib/**"], "clean": true }, "test": { "command": "jest", "dependencies": ["build"], "files": ["test/**/*.ts", "lib/**"], "env": {"NODE_ENV": "test"} }, "lint": { "command": "eslint src", "files": ["src/**/*.ts", ".eslintrc.json"] } } } ``` -------------------------------- ### QuietLogger Usage Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/logger.md Shows how to create an instance of QuietLogger. It requires the package root and a Console object. ```typescript const logger = new QuietLogger(process.cwd(), console) ``` -------------------------------- ### Example Output for MissingPackageJson Error Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Illustrates the message when Wireit cannot find a package.json file. ```text ❌ /some/path — package.json not found ``` -------------------------------- ### Instantiate QuietCiLogger Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/logger.md Example of how to instantiate the QuietCiLogger. This logger is automatically selected in CI environments. ```typescript const logger = new QuietCiLogger(process.cwd(), console) ``` -------------------------------- ### Change Script to Wireit Example Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Shows how to fix a ScriptNotWireit error by changing the script command to 'wireit' in package.json. ```json { "scripts": { "build": "wireit" } } ``` -------------------------------- ### Instantiate MetricsLogger Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/logger.md Example of how to instantiate the MetricsLogger. This logger is used to track performance metrics. ```typescript const logger = new MetricsLogger(process.cwd(), console) ``` -------------------------------- ### CombinationLogger Usage Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/logger.md Demonstrates how to instantiate and use CombinationLogger to combine multiple loggers for dual-logging purposes. ```typescript const mainLogger = new QuietLogger(pkg, console) const debugLogger = new DebugLogger(pkg, debugConsole) const combined = new CombinationLogger( [mainLogger, debugLogger], console ) ``` -------------------------------- ### InvalidUsage Example Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Shows an example of an InvalidUsage error message, specifically related to an incorrect value for the WIREIT_PARALLEL environment variable. ```text ❌ — Expected WIREIT_PARALLEL to be a positive integer, got "abc" ``` -------------------------------- ### Wireit Example Error Object Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/cli.md An example of an error object returned by getOptions() for invalid usage scenarios. ```typescript { ok: false, error: { type: 'failure', reason: 'invalid-usage', message: 'Expected WIREIT_PARALLEL to be a positive integer, got "abc"', script: {packageDir, name: 'build'}, } } ``` -------------------------------- ### Compute Fingerprint Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/fingerprint.md Demonstrates how to use the static `Fingerprint.get` method to compute a script's fingerprint and handle success or failure. ```typescript const fingerprint = await Fingerprint.get(scriptConfig) if (fingerprint.ok) { console.log('Fingerprint:', fingerprint.value.hash) } else { console.error('Failed to compute fingerprint:', fingerprint.error) } ``` -------------------------------- ### DependencyOnMissingPackageJson Example Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Illustrates an error message for DependencyOnMissingPackageJson, showing a dependency pointing to a non-existent package path. ```text ❌ package.json:8:5 — Dependency refers to missing package at ./missing ``` -------------------------------- ### Instantiate DebugLogger Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/logger.md Example of how to instantiate the DebugLogger. This logger is enabled by setting the WIREIT_DEBUG_LOG_FILE environment variable. ```typescript const debugStream = await fs.createWriteStream( '/tmp/wireit-debug.log' ) const debugConsole = new Console(debugStream, debugStream, true) const logger = new DebugLogger(process.cwd(), debugConsole) ``` -------------------------------- ### Monorepo Configuration Example Source: https://github.com/google/wireit/blob/main/_autodocs/configuration.md This JSON snippet shows how to configure Wireit for a monorepo using npm workspaces. It defines build dependencies across packages. ```json { "workspaces": ["packages/*"], "scripts": { "build": "wireit" }, "wireit": { "build": { "dependencies": ["./packages/*:build"] } } } ``` -------------------------------- ### ArrayNode Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/config.md An example illustrating the structure of an ArrayNode, showing its value, offset, length, and individual elements with their locations. ```typescript { value: ['src/**/*.ts', 'tsconfig.json'], offset: 100, length: 45, elements: [ {value: 'src/**/*.ts', offset: 101, length: 12}, {value: 'tsconfig.json', offset: 114, length: 16}, ] } ``` -------------------------------- ### Wireit Logger Usage Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/logger.md Demonstrates how to import logger options, log various event types, print metrics, and clean up logger resources using the Disposable interface. ```typescript import {getOptions} from './cli-options.js' const optionsResult = await getOptions() const {logger} = optionsResult.value // Log events logger.log({ type: 'success', reason: 'exit-zero', script: {packageDir: '/path', name: 'build'}, }) // Print metrics logger.printMetrics() // Clean up using _ = logger // Calls [Symbol.dispose]() ``` -------------------------------- ### Add Script to Scripts Section Example Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Provides an example of how to fix a WireitScriptNotInScriptsSection error by adding the script to the 'scripts' section in package.json. ```json { "scripts": { "build": "wireit" }, "wireit": { "build": {} } } ``` -------------------------------- ### UnknownErrorThrown Example Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Provides an example of an UnknownErrorThrown error message, indicating an unexpected runtime error during script execution. ```text ❌ mypackage:build — Unexpected error: Cannot read property 'x' of undefined ``` -------------------------------- ### Use GitHub Cache for Build Source: https://github.com/google/wireit/blob/main/_autodocs/configuration.md Runs the build script using the GitHub Actions cache. This example demonstrates how to override the default local cache. ```bash WIREIT_CACHE=github npm run build ``` -------------------------------- ### Executor Usage Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/executor.md Demonstrates how to instantiate and use the Executor to execute scripts. Handles potential errors and prepares for persistent services. ```typescript import {Executor} from './executor.js' import {WorkerPool} from './util/worker-pool.js' import {LocalCache} from './caching/local-cache.js' const executor = new Executor( config, logger, new WorkerPool(4), new LocalCache(), 'no-new', undefined, false ) const {persistentServices, errors} = await executor.execute() if (errors.length > 0) { console.error('Execution failed:', errors) process.exit(1) } // Wait for persistent services in watch mode, etc. ``` -------------------------------- ### Analyzer Usage Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/analyzer.md Demonstrates how to instantiate and use the Analyzer to analyze a script. Handles both successful analysis and failure cases. ```typescript import {Analyzer} from './analyzer.js' import {SimpleLogger} from './logging/simple-logger.js' import {Console} from './logging/logger.js' const analyzer = new Analyzer('npm', logger) const result = await analyzer.analyze( {packageDir: '/path/to/pkg', name: 'build'}, undefined ) if (result.config.ok) { console.log('Script config:', result.config.value) } else { console.error('Analysis failures:', result.config.error) } ``` -------------------------------- ### Example Output for ExitNonZero Error Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Illustrates the user-facing message when a script fails due to a non-zero exit code. ```text ❌ mypackage:build — script exited with status code 1 ``` -------------------------------- ### Example Output for StartCancelled Error Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Illustrates the message shown when a script is cancelled due to an upstream failure. ```text ❌ mypackage:test — not started (dependency failed) ``` -------------------------------- ### QuietLogger getWatchLogger Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/logger.md Provides an example implementation of the getWatchLogger method for QuietLogger. This resets state between iterations while maintaining the logger type. ```typescript getWatchLogger(): Logger { return new QuietLogger(this.#packageRoot, this.#console) } ``` -------------------------------- ### Example Output for NoScriptsSectionInPackageJson Error Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Illustrates the message when a package.json file does not contain a 'scripts' section. ```text ❌ mypackage — No "scripts" section in package.json ``` -------------------------------- ### Example Output for Killed Error Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Illustrates the message when Wireit kills a running script. ```text ❌ mypackage:build — killed by wireit ``` -------------------------------- ### InvalidConfigSyntax Example Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Illustrates an InvalidConfigSyntax error message, showing a specific validation failure related to the 'files' property. ```text ❌ package.json:10:20 — "files" must be an array, got string ``` -------------------------------- ### Initialize and Run Watcher Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/watcher.md Instantiates a Watcher with specified options and starts the watch process. Handles SIGINT signal to abort the watcher gracefully. ```typescript import {Watcher} from './watcher.js' import {LocalCache} from './caching/local-cache.js' import {QuietLogger} from './logging/quiet-logger.js' const watcher = new Watcher( {packageDir: '/path', name: 'build'}, undefined, logger, new WorkerPool(4), new LocalCache(), 'no-new', 'npm', {strategy: 'event'} ) process.on('SIGINT', () => { watcher.abort() }) await watcher.watch() console.log('Watch ended') ``` -------------------------------- ### GitHubActionsCache Usage Example Source: https://github.com/google/wireit/blob/main/_autodocs/api-reference/cache.md Demonstrates how to create and use the GitHubActionsCache, including handling potential errors during initialization and falling back to no caching if the cache is unavailable. ```typescript const result = await GitHubActionsCache.create(logger) if (!result.ok) { console.error('GitHub cache unavailable:', result.error) // Fall back to no caching } else { const cache = result.value const hit = await cache.get(script, fingerprint) // ... use cache } ``` -------------------------------- ### Example Output for LaunchedIncorrectly Error Source: https://github.com/google/wireit/blob/main/_autodocs/errors.md Shows the user-facing message when Wireit is launched incorrectly, advising on the correct usage. ```text ❌ /path/to/package — Launching Wireit with npx is not supported. Use: npm run