### Installing mkdirp via npm Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/mkdirp/readme.markdown Shows the npm commands for installing the mkdirp package. It covers installation for local project use and global installation for command-line access. ```bash npm install mkdirp ``` ```bash npm install -g mkdirp ``` -------------------------------- ### Install Dependencies and Run Tests (Bash) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/CONTRIBUTING.md Installs project dependencies using yarn and runs all defined tests to ensure code quality. This is a standard setup step for development. ```bash yarn install yarn test ``` -------------------------------- ### Chainsaw: Installation using npm and git (Shell) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/chainsaw/README.markdown Provides instructions for installing the Chainsaw module using npm and cloning the project from GitHub. It also includes a command to run tests using the 'expresso' test runner. ```bash npm install chainsaw ``` ```bash git clone http://github.com/substack/node-chainsaw.git ``` ```bash expresso ``` -------------------------------- ### Install require-directory Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/require-directory/README.markdown Installs the 'require-directory' package using npm. This is the first step to using the library in a Node.js project. ```bash npm install require-directory ``` -------------------------------- ### Install object-inspect via npm Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/object-inspect/readme.markdown Provides the command to install the object-inspect package using npm, the Node Package Manager. This is the standard way to add the library to a project. ```bash npm install object-inspect ``` -------------------------------- ### Installing node-concat-map with npm Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/concat-map/README.markdown Instructions for installing the node-concat-map module using npm, the Node Package Manager. ```bash npm install concat-map ``` -------------------------------- ### Parsing Binary Data from Streams Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/binary/README.markdown This example demonstrates how to use the binary module to create a writable stream that unpacks binary data with specified endianness and signedness. ```APIDOC ## POST /api/stream ### Description Unpacks multibyte binary values from input streams based on defined formats. ### Method POST ### Endpoint /api/stream ### Parameters #### Query Parameters - **format** (string) - Required - Specifies the format for unpacking data (e.g., 'word32lu', 'word16bs'). Multiple formats can be chained. #### Request Body - **data** (Buffer) - Required - The binary data to be processed. ### Request Example ```js var binary = require('binary'); var ws = binary() .word32lu('x') .word16bs('y') .word16bu('z') .tap(function (vars) { console.dir(vars); }); process.stdin.pipe(ws); process.stdin.resume(); ``` ### Response #### Success Response (200) - **vars** (object) - Contains the unpacked binary values keyed by the specified names. #### Response Example ```json { "x": 1684234849, "y": 25958, "z": 26472 } ``` ``` -------------------------------- ### Parsing Binary Data from Buffers Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/binary/README.markdown This example shows how to parse binary data directly from a static buffer using the binary.parse() method. ```APIDOC ## POST /api/parse ### Description Parses binary data from a static buffer in a single pass. ### Method POST ### Endpoint /api/parse ### Parameters #### Request Body - **buffer** (Buffer) - Required - The buffer containing the binary data to parse. - **format** (string) - Required - Specifies the format for unpacking data (e.g., 'word16ls', 'word32bu', 'word8'). Multiple formats can be chained. ### Request Example ```js var buf = new Buffer([ 97, 98, 99, 100, 101, 102, 0 ]); var binary = require('binary'); var vars = binary.parse(buf) .word16ls('ab') .word32bu('cf') .word8('x') .vars; console.dir(vars); ``` ### Response #### Success Response (200) - **vars** (object) - Contains the unpacked binary values keyed by the specified names. #### Response Example ```json { "ab": 25185, "cf": 1667523942, "x": 0 } ``` ``` -------------------------------- ### Run Lighthouse CI with a Plugin (YAML) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This workflow demonstrates how to set up Lighthouse CI to run audits with a specific plugin (lighthouse-plugin-field-performance). It includes checking out the repository, installing dependencies, and configuring the action with URLs and a config path. ```yaml name: Lighthouse CI with a plugin on: push jobs: lighthouse: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: npm install # install dependencies, that includes Lighthouse plugins - name: Audit URLs with Field Performance Plugin uses: treosh/lighthouse-ci-action@v12 with: urls: | https://www.example.com/ configPath: '.lighthouserc.json' temporaryPublicStorage: true ``` -------------------------------- ### Configure Lighthouse CI URLs Input (YAML) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This example shows how to provide a list of URLs to the Lighthouse CI action, separated by newlines. Each URL will be audited using the latest versions of Lighthouse and Chrome available in the environment. ```yaml urls: | https://example.com/ https://example.com/blog https://example.com/pricing ``` -------------------------------- ### Create a through stream with emit Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/through/readme.markdown This example shows an alternative way to create a through stream by directly emitting 'data' and 'end' events. This approach bypasses the module's internal buffering on pause. The `write` function emits received data, and the `end` function emits the end event. ```javascript var through = require('through') through(function write(data) { this.emit('data', data) //this.pause() }, function end () { //optional this.emit('end') }) ``` -------------------------------- ### Add Plugin Dependency (JSON) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This package.json snippet shows how to add 'lighthouse-plugin-field-performance' as a development dependency, ensuring it is installed locally for the action to use. ```json { "devDependencies": { "lighthouse-plugin-field-performance": "^2.0.1" } } ``` -------------------------------- ### Get Buffer Element Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/buffers/README.markdown Retrieves a single element (byte) at a specified index. ```APIDOC ## .get(i) ### Description Get a single element at index `i`. ### Method Get ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters - **i** (number) - Required - The index of the element to retrieve. #### Request Body None ### Request Example ```json { "index": 3 } ``` ### Response #### Success Response (200) - **Element Value** - The byte value at the specified index. #### Response Example ```json { "value": 4 } ``` ``` -------------------------------- ### Example Usage of concat-map in JavaScript Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/concat-map/README.markdown Demonstrates how to use the concatMap function from the node-concat-map module. It maps over an array and conditionally returns new arrays or empty arrays, then concatenates the results. ```javascript var concatMap = require('concat-map'); var xs = [ 1, 2, 3, 4, 5, 6 ]; var ys = concatMap(xs, function (x) { return x % 2 ? [ x - 0.1, x, x + 0.1 ] : []; }); console.dir(ys); ``` -------------------------------- ### Slice Buffer Collection in Node.js Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/buffers/README.markdown Demonstrates how to slice a portion of a collection of Buffers as if it were a single contiguous buffer. It takes a start and end index for the slice operation. Dependencies: 'buffers' library. ```javascript var Buffers = require('buffers'); var bufs = Buffers(); bufs.push(new Buffer([1,2,3])); bufs.push(new Buffer([4,5,6,7])); bufs.push(new Buffer([8,9,10])); console.dir(bufs.slice(2,8)) ``` -------------------------------- ### Transform negative numbers in-place with traverse Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/traverse/README.markdown This example demonstrates how to traverse an object and update negative numbers in-place by adding 128 to them using the `forEach` method. It requires the 'traverse' module. ```javascript var traverse = require('traverse'); var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ]; traverse(obj).forEach(function (x) { if (x < 0) this.update(x + 128); }); console.dir(obj); ``` -------------------------------- ### Get and Set Elements in Node.js Buffers Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/buffers/README.markdown Illustrates accessing and modifying individual byte values within a 'buffers' collection. The `.get(i)` method retrieves the byte at index `i`, and `.set(i, x)` sets the byte at index `i` to value `x`. ```javascript var Buffers = require('buffers'); var bufs = Buffers([new Buffer([1, 2, 3])]); console.log(bufs.get(1)); // Output: 2 bufs.set(1, 255); console.log(bufs.slice()); // Output: ``` -------------------------------- ### Inspect Circular Object (JavaScript) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/object-inspect/readme.markdown Demonstrates how to use object-inspect to get a string representation of an object with a circular reference. It requires the 'object-inspect' module. ```javascript var inspect = require('object-inspect'); var obj = { a: 1, b: [3,4] }; obj.c = obj; console.log(inspect(obj)); ``` -------------------------------- ### Collect leaf nodes from an object with traverse Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/traverse/README.markdown This example shows how to collect all leaf nodes from a nested object using the `reduce` method. The `isLeaf` property in the context is used to identify leaf nodes, and they are accumulated into an array. ```javascript var traverse = require('traverse'); var obj = { a : [1,2,3], b : 4, c : [5,6], d : { e : [7,8], f : 9 }, }; var leaves = traverse(obj).reduce(function (acc, x) { if (this.isLeaf) acc.push(x); return acc; }, []); console.dir(leaves); ``` -------------------------------- ### Find Needle in Buffer Collection in Node.js Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/buffers/README.markdown Demonstrates searching for a 'needle' (string or Buffer) within a 'buffers' collection. The `.indexOf()` method returns the starting index of the first occurrence or -1 if not found. It handles needles spanning multiple internal buffers and supports an offset. ```javascript var Buffers = require('buffers'); var bufs = Buffers([ new Buffer('hello '), new Buffer('world!') ]); console.log(bufs.indexOf('world')); // Output: 6 console.log(bufs.indexOf('o w')); // Output: 4 ``` -------------------------------- ### mkdirp Command-Line Usage Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/mkdirp/readme.markdown Provides information on how to use the `mkdirp` command from the terminal. It explains the command's purpose for creating multiple directories and the available options, such as setting the mode for newly created directories. ```bash usage: mkdirp [DIR1,DIR2..] {OPTIONS} Create each supplied directory including any necessary parent directories that don't yet exist. If the directory already exists, do nothing. OPTIONS are: -m, --mode If a directory needs to be created, set the mode as an octal permission string. ``` -------------------------------- ### Run Local Tests with Various Configurations (Node.js) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/CONTRIBUTING.md Executes the Lighthouse CI action locally using Node.js. Demonstrates passing different environment variables for URLs, budget paths, configuration files, and upload artifacts. Also shows debugging custom headers and using environment variable interpolation. ```bash # run locally, use INPUT_* notation to pass arguments INPUT_URLS="https://example.com/" node src/index.js # run many urls INPUT_URLS="https://example.com/ https://example.com/blog" node src/index.js # run with performance budget INPUT_URLS="https://treo.sh/" INPUT_BUDGETPATH=".github/lighthouse/budget.json" INPUT_TEMPORARYPUBLICSTORAGE=true node src/index.js # fail with assertions, custom config, or chrome flags INPUT_URLS="https://exterkamp.codes/" INPUT_CONFIGPATH=".github/lighthouse/lighthouserc-assertions.json" INPUT_UPLOADARTIFACTS=true node src/index.js # debug custom headers python script/simple-server.py # start basic server in a separate tab INPUT_URLS="http://localhost:3000/" INPUT_CONFIGPATH=".github/lighthouse/lighthouserc-extra-headers.json" node src/index.js # run and see headers output # run locally, with env var interpolation python script/simple-server.py # start basic server in a separate tab PAGE="src/" INPUT_URLS="http://localhost:3000/$PAGE" node src/index.js # run with a static dist dir INPUT_CONFIGPATH=".github/lighthouse/lighthouserc-static-dist-dir.yml" node src/index.js ``` -------------------------------- ### Synchronous Directory Creation with mkdirp.sync Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/mkdirp/readme.markdown Illustrates the synchronous version of directory creation using `mkdirp.sync`. This method is useful when asynchronous operations are not desired or suitable. It returns the name of the first directory that was created. ```javascript var mkdirp = require('mkdirp'); // Example usage (assuming dir and opts are defined elsewhere) // var made = mkdirp.sync(dir, opts); ``` -------------------------------- ### Async Directory Creation with mkdirp Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/mkdirp/readme.markdown Demonstrates how to asynchronously create a nested directory structure using the mkdirp function. It requires the 'mkdirp' module and takes the target directory path and a callback function as arguments. The callback handles potential errors or logs success. ```javascript var mkdirp = require('mkdirp'); mkdirp('/tmp/foo/bar/baz', function (err) { if (err) console.error(err) else console.log('pow!') }); ``` -------------------------------- ### Importing the mkdirp Module Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/mkdirp/readme.markdown Shows the basic import statement required to use the mkdirp library in a Node.js project. This line makes the mkdirp functionality available for use. ```javascript var mkdirp = require('mkdirp'); ``` -------------------------------- ### Run Unit Tests Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/require-directory/README.markdown Commands to execute the linters and run the unit tests for the 'require-directory' package. ```bash npm run lint npm test ``` -------------------------------- ### Integrate Lighthouse CI with Netlify (YAML) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This workflow integrates Lighthouse CI with Netlify previews. It first waits for a Netlify preview build to complete, then audits the provided URLs using the Lighthouse CI Action. ```yaml name: Lighthouse CI for Netlify sites on: pull_request jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Wait for the Netlify Preview uses: jakepartusch/wait-for-netlify-action@v1.4 id: netlify with: site_name: 'gallant-panini-bc8593' - name: Audit URLs using Lighthouse uses: treosh/lighthouse-ci-action@v12 with: urls: | ${{ steps.netlify.outputs.url }} ${{ steps.netlify.outputs.url }}/products/ budgetPath: ./budget.json uploadArtifacts: true ``` -------------------------------- ### Create and Push Buffers in Node.js Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/buffers/README.markdown Shows the basic usage of the 'buffers' library to create a buffer collection and push new Buffers onto it. The `Buffers()` constructor can initialize with an array of Buffers or be empty. The `.push()` method appends one or more Buffers. ```javascript var Buffers = require('buffers'); var bufs = Buffers(); bufs.push(new Buffer([1,2,3])); bufs.push(new Buffer([4,5,6,7])); bufs.push(new Buffer([8,9,10])); ``` -------------------------------- ### Buffers Initialization Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/buffers/README.markdown Initializes a new Buffers instance. It can be initialized with an array of Buffers or as an empty collection. ```APIDOC ## Buffers(buffers) ### Description Create a Buffers with an array of `Buffer`s if specified, else `[]`. ### Method Constructor ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **buffers** (Array) - Optional - An array of Buffer objects to initialize the collection. ### Request Example ```json { "buffers": [ "", "" ] } ``` ### Response #### Success Response (200) - **Buffers Instance** - A new instance of the Buffers collection. #### Response Example ```json { "buffers": "" } ``` ``` -------------------------------- ### Buffer Manipulation Methods Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/binary/README.markdown Details the chainable methods available for manipulating binary data streams and buffers. ```APIDOC ## API Methods ### `binary()` Creates a new writable stream for buffering binary input. ### `binary.parse(buf)` Parses a static buffer in one pass, returning a chainable interface. ### `b.word{8,16,32,64}{l,b}{e,u,s}(key)` Parses bytes from the buffer or stream with specified bits, endianness, and signedness. Assigns the result to `key` in the variable stash. ### `b.buffer(key, size)` Takes `size` bytes from the stream and stores the resulting buffer slice in the variable stash at `key`. ### `b.scan(key, buffer)` Searches for a `buffer` in the stream and stores intervening data in the stash at `key`. ### `b.tap(cb)` Executes a callback `cb` with the variable stash after previous actions complete. ### `b.into(key, cb)` Similar to `tap`, but nested actions assign into a `key` within the `vars` stash. ### `b.loop(cb)` Enables looping for nested parsing, terminating when `end` is called within the callback. ### `b.flush()` Clears the variable stash entirely. ``` -------------------------------- ### Test static sites with Lighthouse CI (YAML) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This GitHub Actions workflow audits a static website served from a local directory. It uses the Lighthouse CI Action and a lighthouserc.json file configured with staticDistDir. ```yaml name: Lighthouse on: push jobs: static-dist-dir: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run Lighthouse against a static dist dir uses: treosh/lighthouse-ci-action@v12 with: # no urls needed, since it uses local folder to scan .html files configPath: './lighthouserc.json' ``` -------------------------------- ### Stream Parsing with Binary Module Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/binary/README.markdown Demonstrates how to use the 'binary' module to parse binary data from a readable stream. It defines a parsing chain with unsigned 32-bit little-endian, signed 16-bit big-endian, and unsigned 16-bit big-endian words, and then taps the parsed variables to the console. Requires the 'binary' module. ```javascript var binary = require('binary'); var ws = binary() .word32lu('x') .word16bs('y') .word16bu('z') .tap(function (vars) { console.dir(vars); }); process.stdin.pipe(ws); process.stdin.resume(); ``` -------------------------------- ### Lighthouse CI configuration for static site testing (JSON) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This JSON configuration enables Lighthouse CI to test a static website by specifying the directory containing the site's HTML files using staticDistDir. ```json { "ci": { "collect": { "staticDistDir": "./dist" } } } ``` -------------------------------- ### Static Buffer Parsing with Binary Module Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/binary/README.markdown Illustrates parsing a static buffer using the 'binary' module. It defines a parsing sequence including a 16-bit little-endian word, a 32-bit big-endian word, and an 8-bit word, storing the results in the 'vars' object. Requires the 'binary' module. ```javascript var buf = new Buffer([ 97, 98, 99, 100, 101, 102, 0 ]); var binary = require('binary'); var vars = binary.parse(buf) .word16ls('ab') .word32bu('cf') .word8('x') .vars; console.dir(vars); ``` -------------------------------- ### Test Annotations with Node.js Source: https://github.com/treosh/lighthouse-ci-action/blob/main/CONTRIBUTING.md A Node.js snippet to directly set failed annotations for Lighthouse reports. It requires the `.lighthouseci` folder to be present from a previous manual run. ```javascript node -e "require('./src/utils/annotations').setFailedAnnotations('.lighthouseci')" ``` -------------------------------- ### Chainsaw: Prompt for user input with a chainable interface (JavaScript) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/chainsaw/README.markdown Illustrates using Chainsaw to build a chainable interface for interacting with stdin. It leverages `node-lazy` for line processing and allows chaining methods like `do` and `getline` to prompt the user and process input. ```javascript var Chainsaw = require('chainsaw'); var Lazy = require('lazy'); module.exports = Prompt; function Prompt (stream) { var waiting = []; var lines = []; var lazy = Lazy(stream).lines.map(String) .forEach(function (line) { if (waiting.length) { var w = waiting.shift(); w(line); } else lines.push(line); }); var vars = {}; return Chainsaw(function (saw) { this.getline = function (f) { var g = function (line) { saw.nest(f, line, vars); }; if (lines.length) g(lines.shift()); else waiting.push(g); }; this.do = function (cb) { saw.nest(cb, vars); }; }); } var util = require('util'); var stdin = process.openStdin(); Prompt(stdin) .do(function () { util.print('x = '); }) .getline(function (line, vars) { vars.x = parseInt(line, 10); }) .do(function () { util.print('y = '); }) .getline(function (line, vars) { vars.y = parseInt(line, 10); }) .do(function (vars) { if (vars.x + vars.y < 10) { util.print('z = '); this.getline(function (line) { vars.z = parseInt(line, 10); }) } else { vars.z = 0; } }) .do(function (vars) { console.log('x + y + z = ' + (vars.x + vars.y + vars.z)); process.exit(); }); ``` -------------------------------- ### Create a through stream with queueing Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/through/readme.markdown This snippet demonstrates creating a through stream using the 'through' module. It pipes data directly to the next stream using `this.queue(data)` and signals the end of the stream by calling `this.queue(null)`. This method handles internal pause/resume logic automatically. ```javascript var through = require('through') through(function write(data) { this.queue(data) //data *must* not be null }, function end () { //optional this.queue(null) }) ``` -------------------------------- ### Dynamically Generate URLs for Lighthouse CI (YAML) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This workflow demonstrates how to dynamically generate a list of URLs to audit using the `actions/github-script` action. It finds HTML files, extracts names, constructs URLs, and then passes these generated URLs to the Lighthouse CI action. ```yaml jobs: lighthouse: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Generate URLs id: urls uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const globber = await glob.create('elements/*/demo/*.html'); const files = await globber.glob(); const urls = files .map(x => x.match(/([\w-]+)/)[1]) .map(x => `${${{ env.DOMAIN }}}/components/${x}/demo/`) .join('\n'); core.setOutput('urls', urls); - name: Lighthouse CI Action id: lighthouse uses: treosh/lighthouse-ci-action@v8 with: urls: | ${{ steps.urls.outputs.urls }} ``` -------------------------------- ### Basic Usage of require-directory Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/require-directory/README.markdown Demonstrates the fundamental usage of 'require-directory' to recursively load modules from the current directory. It's commonly used in an index file to create a hash of exports. ```javascript var requireDirectory = require('require-directory'); module.exports = requireDirectory(module); ``` -------------------------------- ### Run Lighthouse CI on Self-Hosted Runner (YAML) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This workflow configures Lighthouse CI to run on a self-hosted GitHub runner. It specifies a custom runner label and includes steps for checking out code, setting up Chrome and Node.js, and then running the Lighthouse audit. ```yaml name: Lighthouse CI on: push jobs: lighthouse: runs-on: [self-hosted, your-custom-label] steps: - uses: actions/checkout@v4 - name: install Node.js - uses: browser-actions/setup-chrome@latest - run: chrome --version uses: actions/setup-node@v3 with: node-version: ${{YOUR_REQUIRED_NODE_JS_VERSION}} - name: Audit URLs using Lighthouse uses: treosh/lighthouse-ci-action@v12 with: urls: | https://example.com/ https://example.com/blog [...] ``` -------------------------------- ### Scanning for Delimiters in Streams Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/binary/README.markdown Shows how to use the 'scan' method to find a delimiter (\r\n) in a stream and capture the data preceding it. The captured data is stored in the 'line' variable in the stash and then logged to the console. Requires the 'binary' module. ```javascript var b = binary() .scan('line', new Buffer('\r\n')) .tap(function (vars) { console.log(vars.line); }); stream.pipe(b); ``` -------------------------------- ### Use Lighthouse CI Output with Webhook Action (YAML) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This workflow showcases how to capture the output from the Lighthouse CI action (specifically links and manifest data) and send it to an external API using a webhook action. It requires checkout, running the Lighthouse CI action, and then a separate webhook action. ```yaml # Example of output usage name: LHCI-output-webhook on: push jobs: output-webhook: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Use output for sending data to API. id: LHCIAction uses: ./ with: urls: | https://treo.sh/ - name: Webhook uses: denar90/webhook-action@0.1.1 with: webhookUrl: ${{secrets.ACTION_WEBHOOK_URL}} data: '{ "links": ${{steps.LHCIAction.outputs.links}}, "manifest": ${{steps.LHCIAction.outputs.manifest}} }' ``` -------------------------------- ### Unshift Buffers Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/buffers/README.markdown Prepends one or more Buffers to the beginning of the collection. ```APIDOC ## .unshift(buf1, buf2...) ### Description Unshift buffers onto the head. Just like `Array.prototype.unshift`. ### Method Unshift ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **buf1, buf2...** (Buffer) - One or more Buffer objects to prepend. ### Request Example ```json { "buffersToUnshift": [ "", "" ] } ``` ### Response #### Success Response (200) - **Buffers Instance** - The updated Buffers collection. #### Response Example ```json { "buffers": "" } ``` ``` -------------------------------- ### Specify Directory for require-directory Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/require-directory/README.markdown Shows how to specify a different directory to load modules from. If no path is provided, it defaults to the current directory (`__dirname`). ```javascript var requireDirectory = require('require-directory'); module.exports = requireDirectory(module, './some/subdirectory'); ``` -------------------------------- ### Run Lighthouse and validate against LHCI assertions Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This workflow audits URLs and validates performance against Lighthouse CI assertions defined in a `lighthouserc.json` file. It requires checking out the repository and configuring the action with the `configPath`. ```yaml name: Lighthouse on: push jobs: lighthouse: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run Lighthouse on urls and validate with lighthouserc uses: treosh/lighthouse-ci-action@v12 with: urls: 'https://exterkamp.codes/' configPath: './lighthouserc.json' ``` -------------------------------- ### Configure Basic Authentication for LHCI Server Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md Sets the username and password for basic authentication on an LHCI server. These credentials are used to authenticate uploads to a protected server. Store the username and password securely as GitHub secrets. ```yaml basicAuthUsername: ${{ secrets.LHCI_SERVER_BASIC_AUTH_USERNAME }} basicAuthPassword: ${{ secrets.LHCI_SERVER_BASIC_AUTH_PASSWORD }} ``` -------------------------------- ### Set Performance Budget Path Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md Configures Lighthouse CI Action to use a performance budget file. The action will fail the build if any of the analyzed URLs exceed the defined budget. This helps maintain page performance and size. ```yaml budgetPath: ./budget.json ``` -------------------------------- ### Custom Lighthouse configuration (JavaScript) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This JavaScript file defines custom Lighthouse settings, extending the default configuration and specifying audits for metrics like First Contentful Paint with custom score thresholds. ```javascript module.exports = { extends: 'lighthouse:default', settings: { emulatedFormFactor: 'desktop', audits: [{ path: 'metrics/first-contentful-paint', options: { scorePODR: 800, scoreMedian: 1600 } }], }, } ``` -------------------------------- ### Lighthouse CI Action Output: Links to Reports Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md Outputs a JSON string mapping analyzed URLs to their corresponding HTML report URLs in the storage location. This provides direct links to view the Lighthouse reports. ```json { 'https://treo.sh/': 'https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/1593981455963-59854.report.html' ... } ``` -------------------------------- ### Configure Lighthouse CI uploadExtraArgs Input (YAML) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This input allows you to pass additional arguments to the Lighthouse CI 'upload' command. It's useful for configuring things like authentication headers or other custom parameters for the upload process. ```yaml uploadExtraArgs: "--extraHeaders.Authorization='Bearer X92sEo3n1J1F0k1E9' --extraHeaders.Foo='Bar'" ``` -------------------------------- ### Configure LHCI assertions using lighthouserc.json Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This JSON configuration file specifies Lighthouse CI assertions. It defines an error threshold for the 'first-contentful-paint' metric. ```json { "ci": { "assert": { "assertions": { "first-contentful-paint": ["error", { "minScore": 0.6 }] } } } } ``` -------------------------------- ### Run Lighthouse and save results as artifacts Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This workflow audits specified URLs using Lighthouse and saves the results as action artifacts. It also uploads the reports to temporary public storage for easy access. Requires checkout action. ```yaml name: Lighthouse CI on: push jobs: lighthouse: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Audit URLs using Lighthouse uses: treosh/lighthouse-ci-action@v12 with: urls: | https://example.com/ https://example.com/blog budgetPath: ./budget.json # test performance budgets uploadArtifacts: true # save results as an action artifacts temporaryPublicStorage: true # upload lighthouse report to the temporary storage ``` -------------------------------- ### Update Git Tags for Versioning (Bash) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/CONTRIBUTING.md Commands to update Git tags according to semantic versioning practices. This includes creating a new tag, force-updating an existing tag (like 'v12'), and pushing the changes to the remote repository. ```bash git tag 12.6.1 git tag -fa v12 -m "Update v12 tag" git push origin v12 --force ``` -------------------------------- ### Custom Visitor Function Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/require-directory/README.markdown Defines a visitor function that is executed for each module loaded. This function can perform actions like logging or transforming the loaded module. ```javascript var requireDirectory = require('require-directory'), visitor = function(obj) { console.log(obj); // will be called for every module that is loaded }, hash = requireDirectory(module, {visit: visitor}); ``` -------------------------------- ### Unshift Buffers in Node.js Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/buffers/README.markdown Demonstrates adding Buffers to the beginning of a 'buffers' collection using the `.unshift()` method. This operation is similar to `Array.prototype.unshift`, prepending elements to the collection. ```javascript var Buffers = require('buffers'); var bufs = Buffers([new Buffer([4,5,6])]); bufs.unshift(new Buffer([1,2,3])); console.dir(bufs.slice()); ``` -------------------------------- ### Define performance budget using budget.json Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This JSON file defines performance budgets for Lighthouse audits. It specifies resource sizes and their corresponding budgets for different paths. ```json [ { "path": "/*", "resourceSizes": [ { "resourceType": "document", "budget": 18 }, { "resourceType": "total", "budget": 200 } ] } ] ``` -------------------------------- ### Blacklisting Files with RegExp Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/require-directory/README.markdown Applies a regular expression to exclude specific files. All files not matching the regex will be loaded. ```javascript var requireDirectory = require('require-directory'), blacklist = /dontinclude\.js$/, hash = requireDirectory(module, {exclude: blacklist}); ``` -------------------------------- ### Whitelisting Files with RegExp Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/require-directory/README.markdown Uses a regular expression to include only specific files that match the pattern. Files not matching the regex will be excluded from being loaded. ```javascript var requireDirectory = require('require-directory'), whitelist = /onlyinclude.js$/, hash = requireDirectory(module, {include: whitelist}); ``` -------------------------------- ### Lighthouse CI Action Output: Manifest Data Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md Provides a JSON string containing manifest data for each analyzed URL, including its representative run status, paths to HTML and JSON reports, and a summary of performance metrics. This output can be used for further processing or reporting. ```json [ { "url": "https://treo.sh/", "isRepresentativeRun": true, "htmlPath": "/Users/lighthouse-ci-action/.lighthouseci/treo_sh-_-2020_07_05_20_37_18.report.html", "jsonPath": "/Users/lighthouse-ci-action/.lighthouseci/treo_sh-_-2020_07_05_20_37_18.report.json", "summary": { "performance": 0.99, "accessibility": 0.98, "best-practices": 1, "seo": 0.96, "pwa": 0.71 } } ] ``` -------------------------------- ### Import object-inspect (JavaScript) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/object-inspect/readme.markdown A basic snippet showing the import statement for the object-inspect library, essential for using its inspection capabilities. ```javascript var inspect = require('object-inspect') ``` -------------------------------- ### Renaming Keys with a Function Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/require-directory/README.markdown Applies a renaming function to the keys (filenames) of the loaded modules. This allows for custom naming conventions in the resulting hash. ```javascript var requireDirectory = require('require-directory'), renamer = function(name) { return name.toUpperCase(); }, hash = requireDirectory(module, {rename: renamer}); ``` -------------------------------- ### Chainsaw: Add values with a chainable interface (JavaScript) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/chainsaw/README.markdown Demonstrates creating a chainable interface to add numbers using Chainsaw. It defines a constructor `AddDo` that returns a Chainsaw instance. Methods like `add` and `do` are provided to manipulate a sum and execute callbacks within the chain. ```javascript var Chainsaw = require('chainsaw'); function AddDo (sum) { return Chainsaw(function (saw) { this.add = function (n) { sum += n; saw.next(); }; this.do = function (cb) { saw.nest(cb, sum); }; }); } AddDo(0) .add(5) .add(10) .do(function (sum) { if (sum > 12) this.add(-10); }) .do(function (sum) { console.log('Sum: ' + sum); }); ``` -------------------------------- ### Configure Private LHCI Server Upload Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md Specifies the base URL and token for uploading Lighthouse results to a private LHCI server. This replaces the default temporary public storage. Ensure the server token is stored securely as a GitHub secret. ```yaml serverBaseUrl: ${{ secrets.LHCI_SERVER_BASE_URL }} serverToken: ${{ secrets.LHCI_SERVER_TOKEN }} ``` -------------------------------- ### Chainsaw: Enabling Light Mode (JavaScript) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/chainsaw/README.markdown Shows how to enable 'light mode' for Chainsaw, which disables action recording to save memory for long-lived chains. This is achieved by using `Chainsaw.light()` instead of the default `Chainsaw()` constructor. ```javascript var saw = Chainsaw.light(); ``` -------------------------------- ### Lighthouse CI Action Output: Results Path Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md Provides the file system path to the directory containing the Lighthouse CI results. This output is useful for subsequent actions that need to access the generated report files. ```text /Users/lighthouse-ci-action/.lighthouseci ``` -------------------------------- ### Configure Lighthouse with a Custom File Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md Sets a path to a custom Lighthouse configuration file (e.g., .lighthouserc.json). This file allows for detailed control over Lighthouse data collection, Chrome flags, and CI assertions, providing flexibility beyond action parameters. ```yaml configPath: ./lighthouserc.json ``` -------------------------------- ### Transforming Loaded Modules with Visitor Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/require-directory/README.markdown Shows how a visitor function can transform the loaded modules by returning a modified value. This allows for altering the exports before they are added to the hash. ```javascript var requireDirectory = require('require-directory'), visitor = function(obj) { return obj(new Date()); }, hash = requireDirectory(module, {visit: visitor}); ``` -------------------------------- ### Importing concat-map in JavaScript Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/concat-map/README.markdown Shows how to import the concatMap function from the node-concat-map module in a JavaScript environment. ```javascript var concatMap = require('concat-map') ``` -------------------------------- ### To Buffer Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/buffers/README.markdown Converts the entire Buffers collection into a single, contiguous Buffer. ```APIDOC ## .toBuffer() ### Description Convert the buffer collection to a single buffer, equivalent with `.slice(0, buffers.length)`. ### Method ToBuffer ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **Single Buffer** - A Buffer containing all the data from the collection. #### Response Example ```json { "buffer": "" } ``` ``` -------------------------------- ### Lighthouse CI configuration with Chrome flags (JSON) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This JSON configuration defines settings for Lighthouse CI. It specifies the number of runs and custom Chrome flags to be used during the collection phase. ```json { "ci": { "collect": { "numberOfRuns": 1, "settings": { "chromeFlags": "--disable-gpu --no-sandbox --no-zygote" } } } } ``` -------------------------------- ### Whitelisting Files with a Function Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/require-directory/README.markdown Employs a custom function to determine which files to include. The function receives the file path and should return true to include or false to exclude. ```javascript var requireDirectory = require('require-directory'), check = function(path){ if(/onlyinclude.js$/.test(path)){ return true; // don't include }else{ return false; // go ahead and include } }, hash = requireDirectory(module, {include: check}); ``` -------------------------------- ### Run Lighthouse CI with custom config (YAML) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This workflow uses the Lighthouse CI Action to audit a specified URL. It references a local lighthouserc.json file for configuration, which can include custom Chrome flags. ```yaml name: Lighthouse on: push jobs: lighthouse: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run Lighthouse on urls with lighthouserc uses: treosh/lighthouse-ci-action@v12 with: urls: 'https://example.com/' configPath: './lighthouserc.json' ``` -------------------------------- ### Lighthouse CI Configuration with Plugin (JSON) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This JSON configuration specifies that the Lighthouse CI action should use the 'lighthouse-plugin-field-performance' plugin during its collection phase. ```json { "ci": { "collect": { "settings": { "plugins": ["lighthouse-plugin-field-performance"] } } } } ``` -------------------------------- ### Use URL interpolation with environment variables (YAML) Source: https://github.com/treosh/lighthouse-ci-action/blob/main/README.md This workflow demonstrates using environment variables for URL interpolation in Lighthouse CI. It audits staging URLs based on the pull request number, passing secrets securely. ```yaml name: Lighthouse CI on: push jobs: lighthouse: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run Lighthouse and test budgets uses: treosh/lighthouse-ci-action@v12 with: urls: | https://pr-$PR_NUMBER.staging-example.com/ https://pr-$PR_NUMBER.staging-example.com/blog budgetPath: ./budgets.json temporaryPublicStorage: true env: PR_NUMBER: ${{ github.event.pull_request.number }} ``` -------------------------------- ### To String Source: https://github.com/treosh/lighthouse-ci-action/blob/main/node_modules/buffers/README.markdown Decodes and returns a string from the buffer collection using a specified encoding. ```APIDOC ## .toString(encoding, start, end) ### Description Decodes and returns a string from the buffer collection. Works just like `Buffer.prototype.toString`. ### Method ToString ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters - **encoding** (string) - Optional - The character encoding (defaults to 'utf8'). - **start** (number) - Optional - The offset in the Buffers collection from which to start decoding. - **end** (number) - Optional - The offset in the Buffers collection at which to end decoding. #### Request Body ```json { "encoding": "utf8", "start": 1, "end": 5 } ``` ### Response #### Success Response (200) - **Decoded String** - The string decoded from the buffer collection. #### Response Example ```json { "string": "\x02\x03\x04\x05" } ``` ```