Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webxdc-dev

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webxdc-dev - npm Package Compare versions

Comparing version 0.5.2 to 0.6.0

dist/backend/unpack.js

9

dist/backend/app.js

@@ -33,3 +33,3 @@ "use strict";

exports.createFrontend = createFrontend;
function createPeer(webXdcDescription, injectSim) {
function createPeer(location, injectSim) {
const expressApp = (0, express_1.default)();

@@ -40,3 +40,2 @@ const wsInstance = (0, express_ws_1.default)(expressApp);

injectSim(wsInstance.app);
const location = webXdcDescription.location;
if (location.startsWith("http://")) {

@@ -74,4 +73,4 @@ // serve webxdc project from URL by proxying

class Instances {
constructor(webXdcDescription, injectSim, basePort) {
this.webXdcDescription = webXdcDescription;
constructor(location, injectSim, basePort) {
this.location = location;
this.basePort = basePort;

@@ -89,3 +88,3 @@ this.currentPort = basePort;

}
const app = createPeer(this.webXdcDescription, this.injectSim);
const app = createPeer(this.location, this.injectSim);
const instance = new Instance(app, port, this.processor.createClient(port.toString()));

@@ -92,0 +91,0 @@ app.ws("/webxdc", (ws, req) => {

@@ -11,5 +11,5 @@ "use strict";

.command("run")
.argument("<location>", "Webxdc directory or URL to proxy")
.option("-p, --port <port>", "start port for controller, instance ports are incremented by one each", "7000")
.description("Run Webxdc from directory")
.argument("<location>", "URL with dev server, path to .xdc file, or path to webxdc dist directory")
.option("-p, --port <port>", "start port for webxdc-dev UI, instance ports are incremented by one each", "7000")
.description("Run webxdc-dev simulator with webxdc from dev server URL, .xdc file or dist directory")
.action((location, portString) => {

@@ -22,4 +22,5 @@ const port = Number(portString.port);

});
program.showHelpAfterError();
return program;
}
exports.createProgram = createProgram;

@@ -7,16 +7,14 @@ "use strict";

exports.run = void 0;
const process_1 = __importDefault(require("process"));
const fs_1 = __importDefault(require("fs"));
const open_1 = __importDefault(require("open"));
const app_1 = require("./app");
const open_1 = __importDefault(require("open"));
function run(location, start_port, inject) {
console.log("Starting Webxdc project in: ", location);
const webXdcDescription = {
name: "My App",
location: location,
};
const unpack_1 = require("./unpack");
function actualRun(location, basePort, inject) {
const { injectFrontend, injectSim } = inject;
const instances = new app_1.Instances(webXdcDescription, injectSim, start_port);
const instances = new app_1.Instances(location, injectSim, basePort);
const peer0 = instances.add();
const peer1 = instances.add();
const frontend = (0, app_1.createFrontend)(instances, injectFrontend);
frontend.listen(start_port, () => {
frontend.listen(basePort, () => {
console.log("Starting webxdc-dev frontend");

@@ -26,4 +24,22 @@ });

peer1.start();
(0, open_1.default)("http://localhost:" + start_port);
(0, open_1.default)("http://localhost:" + basePort);
}
function run(location, basePort, inject) {
console.log("Starting webxdc project in: ", location);
if ((0, unpack_1.isXdcFile)(location)) {
const tmpDir = (0, unpack_1.createTempDir)();
console.log("TEMP DIR", tmpDir);
(0, unpack_1.unpack)(location, tmpDir);
actualRun(tmpDir, basePort, inject);
for (const signal in ["SIGINT", "SIGTERM"]) {
process_1.default.on(signal, () => {
console.log("clean up");
fs_1.default.rmSync(tmpDir, { recursive: true });
});
}
}
else {
actualRun(location, basePort, inject);
}
}
exports.run = run;
{
"name": "webxdc-dev",
"version": "0.5.2",
"version": "0.6.0",
"description": "A dev tool for Webxdc",

@@ -22,2 +22,5 @@ "homepage": "https://github.com/webxdc/webxdc-dev#readme",

],
"files": [
"dist"
],
"scripts": {

@@ -45,2 +48,3 @@ "dev": "ts-node-dev --project tsconfig-backend.json backend/dev-cli.ts",

"@tsconfig/recommended": "^1.0.1",
"@types/adm-zip": "^0.5.0",
"@types/express": "^4.17.13",

@@ -57,3 +61,2 @@ "@types/express-ws": "^3.0.1",

"jest": "^28.1.1",
"nodemon": "^2.0.16",
"prettier": "^2.7.1",

@@ -69,2 +72,3 @@ "rimraf": "^3.0.2",

"dependencies": {
"adm-zip": "^0.5.9",
"commander": "^9.3.0",

@@ -71,0 +75,0 @@ "express": "^4.18.1",

# webxdc-dev
webxdc-dev is a development tool for [webxdc](https://webxdc.org). It allows
you to open multiple independent instances of a webxdc application in different
browser tabs or windows. The purpose is to help you test and debug webxdc
projects, including communication between differences instances of the same
application.
webxdc-dev is a development server for [webxdc apps](https://webxdc.org). It
allows you to open multiple independent instances of a webxdc application in
different browser tabs or indows. It simulates how your app will run when
"shared in a chat" and allows you to test and debug webxdc with very fast
turn-around times. Each webxdc browser app instance is connected to a different
port number of the webxdc-dev server so that it gets its own isolated state
(for example localstorage).
Each webxdc application has a different port number so they don't share
anything, including `localstorage`.
Messages sent using the [Webxdc
API](https://docs.webxdc.org/spec.html#webxdc-api) `sendUpdate` function are
automatically distributed to all other instances of the application. This
allows you to simulate multiple users using the same application.
automatically received via the `setUpdateListener` callback of other instances.
This allows you to simulate multiple users using the same application.

@@ -25,3 +24,3 @@ ## Installation

This makes the `webxdc-dev` available on your command line. Alternatively you
This makes `webxdc-dev` available on your command line. Alternatively you
can also install `webxdc-dev` in just your development project as a

@@ -36,19 +35,34 @@ `package.json` script; see below for more information.

To now run webxdc projects with the dev tool, do the following:
### With vite, webpack-dev-server, etc
When you are developing your webxdc application, you may be using a development
server like `vite` or `webpack` that supports hot reloading. You can run
`webxdc-dev` against such a dev server directly. For instance if you have your
project under development running on `http://localhost:3000`, this is how you
can run it:
```shell
webxdc-dev run /path/to/webxdc/project
webxdc-dev run http://localhost:3000
```
When you are developing your webxdc application, you may be using a development
server like vite or webpack that supports hot reloading. You can also run
`webxdc-dev` against such a server directly. For instance if you have your
project under development running on `http://localhost:8000`, this is how you
can run it:
### Running an .xdc file
You can run an `.xdc` file:
```shell
webxdc-dev run http://localhost:8000
webxdc-dev run /path/to/my.xdc
```
By default the dev tool is opened on port 3000 and following. You can change
### Running a directory
You can also run an directory that contains an webxdc project (the equivalent
of an unpacked zip file):
```shell
webxdc-dev run /path/to/webxdc/project
```
### Controlling the port number
By default the dev tool is opened on port 7000 and following. You can change
the base port number using `--port`, so for instance:

@@ -72,3 +86,3 @@

If your project already has a `dev` or `start` script that starts a local
development server on port 8000, you can integrate `webxdc-dev` with that as
development server on port 3000, you can integrate `webxdc-dev` with that as
follows in the `scripts` section of your `package.json`:

@@ -79,3 +93,3 @@

"scripts": {
"webxdc-dev": "concurrently \"npm run dev\" && \"webxdc-dev run http://localhost:8000\""
"webxdc-dev": "concurrently \"npm run dev\" && \"webxdc-dev run http://localhost:3000\""
}

@@ -85,3 +99,3 @@ }

To run this you also need the `concurrently` dev dependency:
To run this you need the `concurrently` dev dependency:

@@ -98,7 +112,5 @@ ```shell

### Testing the build
### Testing the .xdc build
If you want to test the final build of your package and you have a `build`
script to produce it in a directory such as `dist`, you can integrate
it like this:
If your build script produces an `.xdc` file you can test this:

@@ -108,3 +120,3 @@ ```json

"scripts": {
"webxdc-dev-build": "npm run build && webxdc-dev run dist"
"webxdc-dev-xdc": "npm run build && webxdc-dev run dist/app.xdc"
}

@@ -114,10 +126,28 @@ }

Note that this requires `npm run build` to put a complete set of build
artifacts in `dist` including required resources; in other words it needs to be
what you are going to pack into a `.xdc` file.
This is assuming your `build` command produces a `dist/app.xdc`.
You can run it like this:
```shell
npm run webxdc-dev-dist
```
### Testing a build directory
If you have a `dist` directory that contains the complete contents of
what will be zipped up into an `.xdc` file you can also run against it
directly:
```json
{
"scripts": {
"webxdc-dev-dist": "npm run build && webxdc-dev run dist"
}
}
```
You can run the script like this:
```shell
npm run webxdc-dev-build
npm run webxdc-dev-dist
```

@@ -124,0 +154,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc