Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vue-ray

permafrost-dev5.3kMIT2.0.3TypeScript support: included

Debug Vue code with Ray to fix problems faster

vue, ray, debug, javascript, typescript, permafrost, spatie

readme

vue-ray

vue-ray

npm version npm downloads license test status

tech debt

vue-ray

Debug Vue code with Ray to fix problems faster

Install this package in any Vue 3 project to send messages to the Ray app.

Installation

Install with npm:

npm install vue-ray

or bun:

bun add vue-ray

Installing

When using in a Vue 3 project, you may optionally install the plugin globally in your main.js or app.js file. This is primarily useful if you want to cusomize the connection settings for the package.

import { RayPlugin } from 'vue-ray';
import { createApp } from 'vue';
import App from './App.vue';

const app = createApp(App);

app.use(RayPlugin, { 
    port: 23500,
    host: 'localhost',
    interceptErrors: true,
    nodeRaySettings: { 
        interceptConsoleLog: true,
    },
});

Installation options

Name Type Default Description
host string localhost host to connect to the Ray app on
scheme string http URI scheme to use to connect to host
interceptErrors boolean false send Vue errors to Ray
port number 23517 port to connect to the Ray app on
nodeRaySettings object {} pass additional settings for node-ray (reference)

Usage

To access the ray() function, import raySetup() from the vue-ray library:

<script setup>
import { raySetup } from 'vue-ray'
const ray = raySetup(); // `ray` is a ref, so you must use `ray.value` within the script tags
</script>

The raySetup() function accepts an optional options object, defined as:

interface RaySetupOptions {
    connection?: {
        host?: string;
        port?: number;
    }
    lifecycleEvents?: {
        beforeCreate?: boolean;
        beforeMount?: boolean;
        created?: boolean;
        mounted?: boolean;
        unmounted?: boolean;
        updated?: boolean;
        all?: boolean;
    }
}

The lifecycleEvents object can be used to enable or disable sending of the component's lifecycle events to Ray. Use the all property to enable all lifecycle events.

The following example will send the created and mounted events to Ray for the component:

<script setup>
import { raySetup } from 'vue-ray'
const ray = raySetup({
    lifecycleEvents: {
        created: true,
        mounted: true,
    },
});
</script>

The connection object can be used to specify the host and port to connect to the Ray app. The default values are localhost and 23517, respectively.

Sending data to Ray

Once you have called raySetup(), you may use the ray function in the Vue SFC as normal (see node-ray) to send data to Ray:

<template>
    <div>
        <button @click="ray('Hello from Vue!')">Send message to Ray</button>
        <button @click="() => ray().html('<strong>hello with html!</strong>')">Send html message to Ray</button>
    </div>
</template>

See the node-ray reference for a complete list of available methods.

Vue-specific methods

Name Description
ray().data() show the component data
ray().props() show the component props
ray().element(refName: string) render the HTML of an element with a ref of refName
ray().track(name: string) display changes to a component's data variable (best used when not using script setup)
ray().untrack(name: string) stop displaying changes to a component's data variable
ray().watch(name: string, ref: Ref) watch a ref's value and send changes to Ray (best used in script setup)
ray().unwatch(name: string) stop watching a ref's value and stop sending changes to Ray

Watching refs

When using the script setup syntax, you can use the ray().watch(name, ref) method to watch a ref's value and send changes to Ray. Here's an example SFC using the script setup syntax:

<script setup>
import { ref } from 'vue';
import { raySetup } from 'vue-ray';

const one = ref(100);
const two = ref(22);
const ray = raySetup().value;

ray().watch('one', one);
ray().watch('two', two);
</script>

<template>
    <div>
        <div>{{ one }}</div>
        <div>{{ two }}</div>
        <button @click="one += 3">Increment one</button>
        <button @click="two += 3">Increment two</button>
    </div>
</template>

Tracking component data

When not using the script setup syntax, you can use the ray().track(name) method to track changes to a component's data variable. Here's an example SFC:

<script>
import { raySetup } from 'vue-ray';
let ray;

export default {
    props: ['title'],
    data() {
        return {
            one: 100,
            two: 22,
        };
    },
    created() {
        // must call raySetup() in the created() lifecycle hook so it can access the current component
        ray = raySetup().value;
        ray().track('one');
    },
    methods: {
        sendToRay() {
            ray().element('div1');
        },
        increment() {
            this.one += 3;
            this.two += 5;
        }
    }
};
</script>

<template>
    <div class="flex-col border-r border-gray-200 bg-white overflow-y-auto w-100">
        <div ref="div1" class="w-full flex flex-wrap">
            <div ref="div1a" class="w-4/12 inline-flex">{{ one }}</div>
            <div ref="div1b" class="w-4/12 inline-flex">{{ two }}</divr>
        </div>
        <div class="about">
            <h1>{{ title }}</h1>
            <a @click="sendToRay()">send ref to ray</a><br>
            <a @click="increment()">increment data var</a><br>
        </div>
    </div>
</template>

When either tracking data or watching a ref, you will notice that the entry in Ray updates in real-time as the data changes, instead of creating a new entry each time the >data changes.

Intercepting errors

Use the interceptErrors option to intercept errors and send them to Ray:

app.use(RayPlugin, { interceptErrors: true });

Development setup

npm install
npm run test

Development Builds

npm run build:dev

This will build the package in development mode, and writes to the dist-temp directory.

Production Builds

npm run build:dist

This will build the package in production mode, and writes to the dist directory.

Code Coverage Details

codecov graph
codecov graph

Testing

vue-ray uses Vitest for unit tests. To run the test suite, run the following command:

npm run test

...or run with coverage:

npm run test:coverage

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

v2.0.3

  • RayPlugin was not exported #245
  • Bump dependabot/fetch-metadata from 2.0.0 to 2.1.0 #243
  • RayPlugin exported via index.ts b8f100b
  • Update README.md 61a5a8d

v2.0.0

6 April 2024

  • v2 refactor #239
  • Bump dependabot/fetch-metadata from 1.7.0 to 2.0.0 #236
  • Bump dependabot/fetch-metadata from 1.6.0 to 1.7.0 #235
  • Bump github/codeql-action from 2 to 3 #198
  • Bump actions/cache from 3 to 4 #219
  • Bump stefanzweifel/git-auto-commit-action from 4 to 5 #166
  • Bump actions/setup-node from 3 to 4 #172
  • npm(deps-dev): bump lint-staged from 13.3.0 to 14.0.1 #151
  • Bump actions/checkout from 3 to 4 #155
  • Bump dependabot/fetch-metadata from 1.5.1 to 1.6.0 #139
  • Bump dependabot/fetch-metadata from 1.5.0 to 1.5.1 #137
  • Bump dependabot/fetch-metadata from 1.4.0 to 1.5.0 #136
  • Add support for Node.js version 18 in test workflow #135
  • wip f36ea4e
  • wip 99f8250
  • updates ce6659d

v1.17.4

18 May 2023

  • Add typescript definitions #134
  • Update dependencies #133
  • Bump dependabot/fetch-metadata from 1.3.5 to 1.4.0 #132
  • npm(deps-dev): bump @rollup/plugin-commonjs from 24.1.0 to 25.0.0 #131
  • npm(deps-dev): bump @types/node from 18.16.5 to 20.1.0 #130
  • npm(deps-dev): bump concurrently from 7.6.0 to 8.0.1 #126
  • npm(deps-dev): bump typescript from 4.9.5 to 5.0.4 #128
  • npm(deps-dev): bump @rollup/plugin-typescript from 10.0.1 to 11.0.0 #120
  • npm(deps-dev): bump @rollup/plugin-commonjs from 23.0.7 to 24.0.0 #119
  • bump dep versions #118
  • Bump dependabot/fetch-metadata from 1.3.4 to 1.3.5 #110
  • Bump actions/cache from 3.0.8 to 3.0.11 #102
  • Bump dependabot/fetch-metadata from 1.3.3 to 1.3.4 #94
  • Bump actions/cache from 3.0.7 to 3.0.8 #83
  • Bump actions/cache from 3.0.6 to 3.0.7 #81
  • Bump actions/cache from 3.0.5 to 3.0.6 #80
  • Bump actions/cache from 3.0.4 to 3.0.5 #78
  • npm(deps-dev): bump @types/node from 17.0.45 to 18.0.1 #76
  • Bump dependabot/fetch-metadata from 1.3.1 to 1.3.3 #75
  • npm(deps-dev): bump lint-staged from 12.5.0 to 13.0.0 #66
  • Bump actions/cache from 3.0.3 to 3.0.4 #69
  • Bump actions/cache from 3.0.2 to 3.0.3 #65
  • npm(deps-dev): bump husky from 7.0.4 to 8.0.1 #63
  • npm(deps-dev): bump @rollup/plugin-commonjs from 21.1.0 to 22.0.0 #58
  • Bump github/codeql-action from 1 to 2 #59
  • Bump dependabot/fetch-metadata from 1.3.0 to 1.3.1 #56
  • Bump actions/cache from 3.0.1 to 3.0.2 #55
  • Bump codecov/codecov-action from 2 to 3 #54
  • Bump actions/cache from 2 to 3.0.1 #52
  • Added scheme to Installation options to avoid #51 #53
  • Bump dependabot/fetch-metadata from 1.2.1 to 1.3.0 #49
  • Bump actions/checkout from 2 to 3 #47
  • npm(deps-dev): bump eslint from 7.32.0 to 8.10.0 #45
  • npm(deps-dev): bump @rollup/plugin-commonjs from 19.0.2 to 21.0.2 #44
  • npm(deps-dev): bump @rollup/plugin-replace from 2.4.2 to 4.0.0 #43
  • npm(deps-dev): bump lint-staged from 11.2.6 to 12.3.5 #46
  • npm(deps-dev): bump concurrently from 6.5.1 to 7.0.0 #42
  • npm(deps-dev): bump @types/node from 16.11.25 to 17.0.18 #41
  • npm(deps-dev): bump @types/jest from 26.0.24 to 27.4.0 #36
  • npm(deps-dev): bump husky from 6.0.0 to 7.0.4 #32
  • npm(deps-dev): bump @types/node from 15.14.1 to 16.0.0 #19
  • Add auto-changelog to generate CHANGELOG.md on version bump f299c3e
  • Fix rollup build command to include bundle config as CommonJS in package.json fcfbd80
  • Add typescript definitions to build process for Vue2 and Vue3Added typescript definitions generation to build process for Vue2 and Vue3 using the dts-bundle-generator package 628c74c

v1.17.3

2 June 2021

v1.17.2

27 April 2021

  • update named export helper files abde067

v1.17.1

27 April 2021

v1.17.0

27 April 2021

  • update changelog becf16b
  • update readme with nodeRaySettings config option and examples 00885ec
  • add nodeRaySettings plugin config option to pass options directly to the node-ray instance (#9) 5f23aea

v1.16.0

2 April 2021

  • update changelog dadc2aa
  • update test snapshot 15813f9
  • add enabled_callback, sending_payload_callback and sent_payload_callback options 864bd59

v1.15.0

12 March 2021

  • update changelog 5f3778d
  • attempt to guess the correct component name when displaying component events instead of showing "unknown" 64d018f

v1.14.0

12 March 2021

  • update changelog 1b92477
  • fix issue with an error during event interception; don't display component events for unknown components bea1d3c
  • don't display component events for unknown components c621ded

v1.13.5

12 March 2021

v1.13.4

12 March 2021

  • update changelog 3ca3733
  • fix issue with conditionallyDisplayEvent() not being able to access this.$ray 9cf4f08
  • add ts-ignore directives 89479eb

v1.13.3

11 March 2021

v1.13.2

11 March 2021

  • update changelog 7a0d4b1
  • remove multimatch package and use custom pattern matching function instead 1c9df49

v1.13.1

11 March 2021

v1.13.0

11 March 2021

  • update changelog 5e1b3b5
  • add tests for vue 3 event intercepts b6019a4
  • make mixin code for conditional events more testable 70a7c4e

v1.12.0

10 March 2021

  • update readme with info/examples on filtering tracked state props aeff678
  • update changelog 1308b9e
  • add support for filtering displayed state props when tracking state 1c628e6

v1.11.0

10 March 2021

  • update changelog a1b0455
  • add support for specifying the url scheme in plugin options fc98219
  • add test for showComponentEvents option d62cdbb

v1.10.0

2 March 2021

  • send logged events as collapsed 4b37ec0
  • update changelog 49f62b0
  • add updated info/examples for vuex plugin ed05a40

v1.9.0

2 March 2021

  • update changelog e86705f
  • add section on using the Vuex plugin 3cc2a0c
  • update component prop, add ray() function export 77d4f37

v1.8.0

12 February 2021

  • update tests + snapshots 04fe495
  • add ts-nocheck directive 577721e
  • add html encoding helper function d3c686d

v1.7.1

11 February 2021

  • fix data var tracking call to watch() 30a5e61

v1.7.0

11 February 2021

  • add vue to external modules 162fe8b
  • add additional tests 45a1e1e
  • add data var tracking, reorganized code, moved duplicate code to shared modules c1dd4ae

v1.6.1

11 February 2021

  • move duplicated options init code to shared lib, add host, port options for configuring the Ray connection 8a08822
  • update changelog, add host, port options to readme 70cecf8
  • code cleanup 9f3fe6b

v1.6.0

11 February 2021

  • disable unused plugins and options 11d2a54
  • reorganize src layout, move package info to shared file f9df498
  • remove unused script b012819

v1.5.1

11 February 2021

  • update changelog 3693517
  • add error reporting with pretty-printing 5952bfa

v1.5.0

10 February 2021

  • add interceptErrors boolean option to toggle display of Vue errors in Ray 5293505
  • update changelog 7ddc3a5
  • add configuration options section d58ee79

v1.4.2

9 February 2021

v1.4.1

9 February 2021

  • update vue2/3 exports, update changelog 64a7764

v1.4.0

9 February 2021

  • update changelog f059e68
  • remove replacements, add commonjs d148ae6
  • use Ray.create().send(...) instead of ray() de1a435

v1.3.0

9 February 2021

v1.2.0

9 February 2021

  • revert node-ray import method a8301f0
  • update changelog 5762d41
  • change the vue2 plugin format/setup d932829

v1.1.0

8 February 2021