Skip to content

Commit fcd8334

Browse files
committed
New tests
1 parent 3fbafba commit fcd8334

File tree

4 files changed

+70
-102
lines changed

4 files changed

+70
-102
lines changed

.github/workflows/graaljs-gradle-webpack-guide.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/graaljs-maven-webpack-guide.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test GraalJS Gradle and Maven Webpack Guide
2+
3+
on:
4+
push:
5+
paths:
6+
- 'graaljs/graaljs-webpack-guide/**'
7+
- '.github/workflows/graaljs-webpack-guide.yml'
8+
pull_request:
9+
paths:
10+
- 'graaljs/graaljs-webpack-guide/**'
11+
- '.github/workflows/graaljs-webpack-guide.yml'
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
jobs:
17+
run:
18+
name: 'graaljs-webpack-guide'
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 15
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: graalvm/setup-graalvm@v1
24+
with:
25+
java-version: '24.0.1'
26+
distribution: 'graalvm'
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
cache: 'gradle'
29+
- name: Build and run Gradle example
30+
run: |
31+
cd graaljs/graaljs-webpack-guide
32+
./gradlew build
33+
./gradlew run --args="https://www.graalvm.org/javascript"
34+
- uses: graalvm/setup-graalvm@v1
35+
with:
36+
java-version: '24.0.1'
37+
distribution: 'graalvm'
38+
github-token: ${{ secrets.GITHUB_TOKEN }}
39+
cache: 'maven'
40+
- name: Build and run Maven example
41+
run: |
42+
./mvnw --no-transfer-progress package
43+
./mvnw --no-transfer-progress exec:java -Dexec.mainClass=com.example.App -Dexec.args="https://www.graalvm.org/javascript"

graaljs/graaljs-webpack-guide/README.md

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
55
- [Introduction](#introduction)
66
- [Prerequisites](#prerequisites)
7-
- [1. Setting Up the Java Project](#1-setting-up-the-java-project)
8-
- [Create a new Gradle Java Project](#create-a-new-gradle-java-project)
9-
- [Create a new Maven Java Project](#create-a-new-maven-java-project)
10-
- [2. Setting Up the JavaScript Build](#2-setting-up-the-javascript-build)
11-
- [3. Using the JavaScript Library from Java](#3-using-the-javascript-library-from-java)
12-
- [4. Building and Running the Application](#4-building-and-running-the-application)
7+
- [1. Set Up the Java Project](#1-set-up-the-java-project)
8+
- [Create a New Gradle Java Project](#create-a-new-gradle-java-project)
9+
- [Create a New Maven Java Project](#create-a-new-maven-java-project)
10+
- [2. Set Up the JavaScript Build](#2-set-up-the-javascript-build)
11+
- [3. Use the JavaScript Library from Java](#3-use-the-javascript-library-from-java)
12+
- [4. Build and Run the Application](#4-build-and-run-the-application)
1313
- [Conclusion](#conclusion)
1414

1515
## Introduction
@@ -34,18 +34,15 @@ You will need:
3434
- Gradle 8.0 or later, or Maven 3.6.3 or later
3535
- A decent text editor or IDE
3636

37-
---
3837

39-
## 1. Setting Up the Java Project
38+
## 1. Set Up the Java Project
4039

4140
You can use either **Gradle** or **Maven** to set up your Java project:
4241

4342
- for Gradle projects, navigate to the Gradle folder with `cd gradle`
4443
- for Maven projects, navigate to the Maven folder with `cd maven`
4544

46-
Create a New Gradle Java Project
47-
48-
You can start with any Gradle Java project.
45+
### Create a New Gradle Java Project
4946

5047
Run the following command to create a new project with Gradle:
5148

@@ -55,9 +52,9 @@ gradle init --type java-application
5552

5653
#### Add the GraalJS Dependencies
5754

58-
Add the following required GraalJS dependencies to the `dependencies` block of your `build.gradle` file:
55+
Add the following required GraalJS dependencies to the `dependencies` block of your _build.gradle_ file:
5956

60-
`build.gradle`
57+
_build.gradle_
6158

6259
```gradle
6360
dependencies {
@@ -77,9 +74,9 @@ The Node.js ecosystem has conventions about the filesystem layout of installed p
7774
Use a bundler to repackage all dependencies into a single file and simplify integration.
7875
You can use the [`com.github.node-gradle.node`](https://github.com/node-gradle/gradle-node-plugin) plugin to manage the download, installation, and bundling for you.
7976

80-
Configure the Gradle Node plugin in the `build.gradle` with the following:
77+
Configure the Gradle Node plugin in the _build.gradle_ file with the following:
8178

82-
`build.gradle`
79+
_build.gradle_
8380

8481
```gradle
8582
plugins {
@@ -111,11 +108,11 @@ processResources.dependsOn tasks.webpackBuild // ④
111108

112109
❷ Configures Node.js and npm versions, download settings, and working directories.
113110

114-
❸ Registers a 'webpackBuild' task to run 'npm run build' in the frontend directory. It ensures dependencies are installed first and sets the output directory.
111+
❸ Registers a `webpackBuild` task to run `npm run build` in the frontend directory. It ensures dependencies are installed first and sets the output directory.
115112

116113
❹ Ensures that the `webpackBuild` task is executed before the processResources task, so the bundled JavaScript is included in your JAR file.
117114

118-
### Create a new Maven Java Project
115+
### Create a New Maven Java Project
119116

120117
You can start with any Maven application that runs on JDK 21 or newer.
121118
To follow this guide, generating the application from the [Maven Quickstart Archetype](https://maven.apache.org/archetypes/maven-archetype-quickstart/) is sufficient:
@@ -125,11 +122,11 @@ mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -Darchetyp
125122
cd qrdemo
126123
```
127124

128-
#### Adding the GraalJS Dependencies
125+
#### Add the GraalJS Dependencies
129126

130127
Add the following required GraalJS dependencies to the `<dependencies>` section of your POM file:
131128

132-
`pom.xml`
129+
_pom.xml_
133130

134131
```xml
135132
<!-- <dependencies> -->
@@ -161,9 +158,9 @@ The Node.js ecosystem has conventions about the filesystem layout of installed p
161158
Use a bundler to repackage all dependencies into a single file and simplify integration.
162159
You can use the [`frontend-maven-plugin`](https://github.com/eirslett/frontend-maven-plugin) plugin to manage the download, installation, and bundling for you.
163160

164-
Configure the Maven Frontend plugin in your `pom.xml` file to automate Node.js and JavaScript bundling steps:
161+
Configure the Maven Frontend plugin in your _pom.xml_ file to automate Node.js and JavaScript bundling steps:
165162

166-
`pom.xml`
163+
_pom.xml_
167164

168165
```xml
169166
<!-- <build> -->
@@ -215,9 +212,7 @@ Configure the Maven Frontend plugin in your `pom.xml` file to automate Node.js a
215212

216213
❸ Runs `webpack` to build a bundle of the JS sources in _target/classes/bundle_, which will be later included in the application's JAR file and can be loaded as a resource.
217214

218-
---
219-
220-
## 2. Setting Up the JavaScript Build
215+
## 2. Set Up the JavaScript Build
221216

222217
Create the directory for your JavaScript sources:
223218

@@ -234,9 +229,9 @@ You can manually set up the build environment with these steps:
234229
4. Run `npm install --save qrcode` to install and add the `qrcode` dependency.
235230
5. Run `npm install --save assert util stream-browserify browserify-zlib fast-text-encoding` to install the polyfill packages to build with the webpack configuration below.
236231

237-
Alternatively, you can use the following `package.json` file to define your dependencies and build scripts:
232+
Alternatively, you can use the following _package.json_ file to define your dependencies and build scripts:
238233

239-
`package.json`
234+
_package.json_
240235

241236
```json
242237
{
@@ -270,9 +265,9 @@ Alternatively, you can use the following `package.json` file to define your depe
270265
}
271266
```
272267

273-
Create a `webpack.config.js` file, or open the one created by `webpack-cli init`, and fill it with the following contents:
268+
Create a _webpack.config.js_ file, or open the one created by `webpack-cli init`, and fill it with the following contents:
274269

275-
`webpack.config.js`
270+
_webpack.config.js_
276271

277272
```js
278273
const path = require('path');
@@ -326,9 +321,7 @@ import 'fast-text-encoding';
326321
export * as QRCode from 'qrcode';
327322
```
328323

329-
---
330-
331-
## 3. Using the JavaScript Library from Java
324+
## 3. Use the JavaScript Library from Java
332325

333326
After reading the [qrcode](https://www.npmjs.com/package/qrcode) docs, you can write Java interfaces that match the [JavaScript types](https://www.npmjs.com/package/@types/qrcode) you want to use and methods you want to call on them.
334327
GraalJS makes it easy to access JavaScript objects via these interfaces.
@@ -421,9 +414,7 @@ You can cast the exported `QRCode` object to the declared `QRCode` interface so
421414

422415
❹ Invoke the `then` method of the `Promise` to eventually obtain the QRCode string and print it to `stdout`.
423416

424-
---
425-
426-
## 4. Building and Running the Application
417+
## 4. Build and Run the Application
427418

428419
If using Gradle, run the following commands to build and run your application:
429420

@@ -459,14 +450,12 @@ Successfully generated QR code for "https://www.graalvm.org/".
459450
▀▀▀▀▀▀▀ ▀ ▀▀▀▀ ▀▀▀▀▀▀
460451
```
461452

462-
---
463-
464453
## Conclusion
465454

466455
By following this guide, you've learned how to:
467456

468457
- Use GraalJS and the GraalVM Polyglot API to embed a JavaScript library in your Java application.
469-
- Use Webpack to bundle an NPM package into a self-contained _.mjs_ file, including its dependencies and polyfills for Node.js core modules that may be required to run on GraalJS.
458+
- Use Webpack to bundle an NPM package into a self-contained _.mjs_ file, including its dependencies and `polyfills` for Node.js core modules that may be required to run on GraalJS.
470459
- Integrate the JavaScript build into your Java project using either Gradle or Maven.
471460

472-
Feel free to use this demo as inspiration and a starting point for your own applications!
461+
Feel free to use this demo as inspiration or as a starting point for your own applications!

0 commit comments

Comments
 (0)