Skip to content

Commit

Permalink
Merge branch 'release/0.17.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pmlopes committed Jan 20, 2022
2 parents e3d8c83 + 43b5643 commit 1ad0450
Show file tree
Hide file tree
Showing 127 changed files with 577 additions and 448 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.17.0] - 2022-01-20
* Bump vert.x to 4.2.4
* Bump graaljs to 22.0.0
* bare specifiers are now resolved using es4x rules, not relative to working dir
* verticle start run on event loop to avoid threading issues
* Debug manual updated to reflect current state of debugging on vscode
* Manual now includes section on hot-reload

## [0.16.3] - 2022-01-05
* Bump vert.x to 4.2.3
* CI runs and passes on Windows, MacOS and Linux
Expand Down
6 changes: 3 additions & 3 deletions codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<parent>
<groupId>io.reactiverse</groupId>
<artifactId>es4x-parent</artifactId>
<version>0.16.3</version>
<relativePath>..</relativePath>
<version>0.17.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>es4x-codegen</artifactId>
<version>0.16.3</version>
<version>0.17.0</version>

<properties>
<tools.jar>${java.home}/../lib/tools.jar</tools.jar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import io.vertx.codegen.*;
import io.vertx.codegen.type.ClassKind;
import io.vertx.codegen.type.ClassTypeInfo;
import io.vertx.codegen.type.TypeInfo;
import io.vertx.core.json.JsonObject;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.*;

import static io.reactiverse.es4x.codegen.generator.Util.*;
import static io.reactiverse.es4x.codegen.generator.Util.getNPMScope;

public class OptionsDTS extends Generator<DataObjectModel> {

Expand Down Expand Up @@ -113,6 +115,17 @@ public String render(DataObjectModel model, int index, int size, Map<String, Obj
}
}

// address extends outside the module
if (model.getSuperType() != null) {
String selfScope = getNPMScope(model.getModule());
String superScope = getNPMScope(model.getSuperType().getModule());
if (!selfScope.equals(superScope)) {
TypeInfo referencedType = model.getSuperType();
importType(writer, session, referencedType, referencedType.getSimpleName(), getNPMScope(referencedType.getRaw().getModule()));
imports = true;
}
}

if (imports) {
writer.print("\n");
}
Expand Down
1 change: 1 addition & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ module.exports = {
'esm',
'globals',
'vertx',
'hot-reload',
'worker',
'jars',
'security',
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ In order to generate an `es4x` module for this component all we need is a `pom.x
<groupId>io.reactiverse.es4x</groupId>
<artifactId>es4x-generator</artifactId>
<version>0.16.0</version>
<relativePath>../..</relativePath>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>hot-reload</artifactId>
Expand Down
126 changes: 126 additions & 0 deletions docs/advanced/hot-reload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Hot Reload

To speed the development cycles, `es4x` supports simple `hot-reload`. The functionality is very basic.
On a file change, the application will be stopped abruptly and restarted. This feature is not `es4x`
specific, in fact it just relies on `vertx` core functionality.

## Walk-through

Imagine the following application composed from 4 source `js` files:

1. index.js
2. m/a.js
3. m/b.js
4. m/c.js

The content of these files is as follows:

### index.js

```js
const a = require('./m/a');
a();
```

Call a function defined on a relative module `a`.

### m/a.js

```js
const b = require('./b');

function a() {
print('Hello from A');
b();
}

module.exports = a;
```

Prints a message and calls another module `b`.

### m/b.js

```js
const c = require('./c');

// changed B
function b() {
print('Hello from B');
c();
}

module.exports = b;
```

Prints a message and calls another module `c`.

### m/c.js

```js
function c() {
print('Hello from C');
}

module.exports = c;
```

Prints the final message.

## Running

In order to run an application with `hot-reload` all you need is to use the `vert.x` **redeploy** command.

In this example one would execute:

```bash
es4x run --redeploy "m/*" index.js
```

It is important to know that the redeploy watch list works with files, so in order to watch a directory, one needs to
watch a **wildcard**.

```
$ ./node_modules/.bin/es4x --redeploy "m/*"
Watched paths: [/home/hello/./m]
Starting the vert.x application in redeploy mode
Starting vert.x application...
ec467de2-ca71-43c6-98d8-9da0cc0d24f8-redeploy
Hello from A
Hello from B
Hello from C
Succeeded in deploying verticle
```

When any of the files under `m` are touched you will see a similar message in the console:

```
Redeploying!
Stopping vert.x application 'ec467de2-ca71-43c6-98d8-9da0cc0d24f8-redeploy'
Application 'ec467de2-ca71-43c6-98d8-9da0cc0d24f8-redeploy' terminated with status 0
Starting vert.x application...
ec467de2-ca71-43c6-98d8-9da0cc0d24f8-redeploy
Redeployment done in 66 ms.
Hello from A
Hello from B
Hello from C
Succeeded in deploying verticle
```

This will happen for **each** file you touch.

## Running a task before redeploy

While re-deploy is already a time saver, there are usually steps required to be executed before the re-deploy happens.
For example a build step, like compile typescript to javascript, by running `tsc`. For this we can run the application
as:

```bash
es4x run --redeploy "m/*" --on-redeploy "tsc" index.js
```

For more information read the all the options on the `run` command:

```bash
es4x run --help
```
24 changes: 8 additions & 16 deletions docs/get-started/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ You will be able to set breakpoints, debug etc...
## Debug from VSCode

The usage of Chrome devtools is not a hard requirement. You can also debug the application using
[Visual Studio Code](https://code.visualstudio.com). Create a runner configuration as:
[Visual Studio Code](https://code.visualstudio.com).

::: warning
Before you can debug from the IDE, you need to install the extension: [GraalVM Tools for Java](https://marketplace.visualstudio.com/items?itemName=oracle-labs-graalvm.graalvm) and create a runner configuration.

To create the attach configuration either use the helper command, or use the template bellow:

```
es4x vscode
Expand All @@ -41,25 +45,13 @@ This will create a `launcher.json` similar to this:
"version" : "0.2.0",
"configurations" : [ {
"name" : "Launch empty-project",
"type" : "node",
"request" : "launch",
"cwd" : "${workspaceFolder}",
"runtimeExecutable" : "${workspaceFolder}/node_modules/.bin/es4x-launcher",
"runtimeArgs" : [ "-Dinspect=5858" ],
"port" : 5858,
"outputCapture" : "std",
"serverReadyAction" : {
"pattern" : "started on port ([0-9]+)",
"uriFormat" : "http://localhost:%s",
"action" : "openExternally"
}
"type" : "graalvm",
"request" : "attach",
"port" : 9229
} ]
}
```

And attach your debugger.

![vscode-chrome-inspector](./res/vscode-debug.png)

If you print the message `Server started on port 8000` it will be captured by visual studio and a browser window will
open the url in question.
6 changes: 3 additions & 3 deletions es4x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<parent>
<groupId>io.reactiverse</groupId>
<artifactId>es4x-parent</artifactId>
<version>0.16.3</version>
<relativePath>..</relativePath>
<version>0.17.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>es4x</artifactId>
<version>0.16.3</version>
<version>0.17.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
13 changes: 9 additions & 4 deletions es4x/src/main/java/io/reactiverse/es4x/ES4X.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public final class ES4X extends Launcher {
@Override
public void beforeStartingVertx(VertxOptions options) {
processProperty("inspect", inspect -> {
System.setProperty("polyglot.inspect", inspect.toString());
System.setProperty("polyglot.inspect", inspect);
System.setProperty("polyglot.inspect.Suspend", "false");
options.setBlockedThreadCheckInterval(1000000);
});

processProperty("inspect-brk", inspect -> {
System.setProperty("polyglot.inspect", inspect.toString());
System.setProperty("polyglot.inspect", inspect);
System.setProperty("polyglot.inspect.Suspend", "true");
options.setBlockedThreadCheckInterval(1000000);
});
Expand Down Expand Up @@ -94,12 +94,17 @@ public static void main(String... args) {
}
}

private static void processProperty(String name, Consumer<Integer> consumer) {
private static void processProperty(String name, Consumer<String> consumer) {

if (System.getProperties().containsKey(name)) {
try {
consumer.accept(Integer.getInteger(name));
String addr = System.getProperty(name);
if ("".equals(addr)) {
addr = "9229";
}
consumer.accept(addr);
} catch (RuntimeException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Expand Down
20 changes: 7 additions & 13 deletions es4x/src/main/java/io/reactiverse/es4x/impl/JSVerticleFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,13 @@ public void start(Promise<Void> startFuture) {
runtime.put("global", runtime.eval(Source.create("js", "this")));
}

// wrap the deployment in a execute blocking as blocking io can happen during deploy
vertx
.<Void>executeBlocking(deploy -> {
try {
module.invokeMember("runMain", fsVerticleName);
deploy.complete();
} catch (RuntimeException e) {
deploy.fail(e);
}
})
.onFailure(startFuture::fail)
.onSuccess(v ->
waitFor(runtime, "deploy").onComplete(startFuture));
try {
module.invokeMember("runMain", fsVerticleName);
waitFor(runtime, "deploy")
.onComplete(startFuture);
} catch (RuntimeException e) {
startFuture.fail(e);
}
} catch (RuntimeException e) {
startFuture.fail(e);
}
Expand Down
44 changes: 19 additions & 25 deletions es4x/src/main/java/io/reactiverse/es4x/impl/MJSVerticleFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,27 @@ public void start(Promise<Void> startFuture) {
} else {
runtime.put("global", runtime.eval(Source.create("js", "this")));
}
// wrap the deployment in a execute blocking as blocking net/io can happen during deploy
vertx
.<Void>executeBlocking(deploy -> {
try {
// the main script buffer
final Buffer buffer = vertx.fileSystem().readFileBlocking(fsVerticleName);
final Source source = Source
.newBuilder("js", new File(fsVerticleName))
// strip the shebang if present
.content(ESModuleIO.stripShebang(buffer.toString()))
.cached(true)
.interactive(false)
.mimeType("application/javascript+module")
.buildLiteral();

runtime.eval(source);
deploy.complete();
} catch (InvalidPathException e) {
deploy.fail("File Not Found: " + fsVerticleName);
} catch (RuntimeException e) {
deploy.fail(e);
}
}, true)
.onFailure(startFuture::fail)
.onSuccess(v ->
waitFor(runtime, "deploy").onComplete(startFuture));
try {
// the main script buffer
final Buffer buffer = vertx.fileSystem().readFileBlocking(fsVerticleName);
final Source source = Source
.newBuilder("js", new File(fsVerticleName))
// strip the shebang if present
.content(ESModuleIO.stripShebang(buffer.toString()))
.cached(true)
.interactive(false)
.mimeType("application/javascript+module")
.buildLiteral();

runtime.eval(source);
waitFor(runtime, "deploy")
.onComplete(startFuture);
} catch (InvalidPathException e) {
startFuture.fail("File Not Found: " + fsVerticleName);
} catch (RuntimeException e) {
startFuture.fail(e);
}
} catch (RuntimeException e) {
startFuture.fail(e);
}
Expand Down

0 comments on commit 1ad0450

Please sign in to comment.