swipl-wasm 3.2.2 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -3
- package/dist/generateImage.js +2 -2
- package/dist/swipl/swipl-bundle-no-data.js +1 -1
- package/dist/swipl/swipl-bundle.js +1 -1
- package/dist/swipl/swipl-web.data +0 -0
- package/dist/swipl/swipl-web.js +1 -1
- package/dist/swipl/swipl-web.wasm +0 -0
- package/dist/swipl/swipl.js +1 -1
- package/package.json +43 -14
package/README.md
CHANGED
|
@@ -4,6 +4,38 @@ SWI-Prolog WebAssembly build as a NPM package. Please see this page
|
|
|
4
4
|
for ongoing progress and information:
|
|
5
5
|
<https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650>
|
|
6
6
|
|
|
7
|
+
## Quickly Getting Started
|
|
8
|
+
|
|
9
|
+
The easiest way to get started is my importing swipl-wasm into your npm project.
|
|
10
|
+
It imported for both node and browser builds as follows:
|
|
11
|
+
|
|
12
|
+
script.js
|
|
13
|
+
```js
|
|
14
|
+
import SWIPL from "swipl-wasm";
|
|
15
|
+
|
|
16
|
+
async function main() {
|
|
17
|
+
const swipl = await SWIPL({ arguments: ["-q"] });
|
|
18
|
+
console.log(swipl.prolog.query("member(X, [a, b, c]).").once().X);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
main();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For those who have not done this before you will first need to [install node and npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
|
|
25
|
+
After doing this you can make a new project as follows:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Make the project directory
|
|
29
|
+
mkdir my-swipl-project && cd ./my-swipl-project
|
|
30
|
+
# Initialise the project
|
|
31
|
+
npm init
|
|
32
|
+
# Install swipl-wasm
|
|
33
|
+
npm i swipl-wasm
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
After this place the above code in `script.js` in the root of your directory and run `node script.js`
|
|
37
|
+
to run the script.
|
|
38
|
+
|
|
7
39
|
## Usage
|
|
8
40
|
|
|
9
41
|
In browser:
|
|
@@ -38,7 +70,7 @@ visiting <http://localhost:8080/examples/browser.html>.
|
|
|
38
70
|
In Nodejs:
|
|
39
71
|
|
|
40
72
|
```js
|
|
41
|
-
const SWIPL = require("swipl-wasm
|
|
73
|
+
const SWIPL = require("swipl-wasm");
|
|
42
74
|
|
|
43
75
|
const swipl = await SWIPL({ arguments: ["-q"] });
|
|
44
76
|
console.log(swipl.prolog.query("member(X, [a, b, c]).").once().X);
|
|
@@ -123,10 +155,58 @@ npm run server
|
|
|
123
155
|
and visit <http://127.0.0.1:8080>. You should see the message "Hello world from
|
|
124
156
|
Prolog".
|
|
125
157
|
|
|
158
|
+
|
|
159
|
+
## Browser Builds
|
|
160
|
+
|
|
161
|
+
For convenience we provide deploy bundled versions of the SWI-Prolog on github pages which can be directly used in an HTML document.
|
|
162
|
+
|
|
163
|
+
There is a bundled version for each release - which can be found at the url:
|
|
164
|
+
<p align=center>
|
|
165
|
+
https://SWI-Prolog.github.io/npm-swipl-wasm/vMajor/vMinor/vPatch/index.js
|
|
166
|
+
|
|
167
|
+
for instance v3.3.0 has the url https://SWI-Prolog.github.io/npm-swipl-wasm/3/3/0/index.js. We also have shortcuts for:
|
|
168
|
+
- the latest version https://SWI-Prolog.github.io/npm-swipl-wasm/latest/index.js,
|
|
169
|
+
- the latest of each major version https://SWI-Prolog.github.io/npm-swipl-wasm/vMajor/latest/index.js, and
|
|
170
|
+
- the latest of each minor version https://SWI-Prolog.github.io/npm-swipl-wasm/vMajor/vMinor/latest/index.js
|
|
171
|
+
|
|
172
|
+
Available versions can be browsed at https://github.com/SWI-Prolog/npm-swipl-wasm/tree/pages.
|
|
173
|
+
|
|
174
|
+
With this approach the following script will work
|
|
175
|
+
|
|
176
|
+
```html
|
|
177
|
+
<div id="solution"></div>
|
|
178
|
+
<script src="https://SWI-Prolog.github.io/npm-swipl-wasm/3/3/0/index.js"></script>
|
|
179
|
+
<script>
|
|
180
|
+
(async () => {
|
|
181
|
+
const swipl = await SWIPL({ arguments: ["-q"] });
|
|
182
|
+
const query = "member(X, [a, b, c]).";
|
|
183
|
+
const solutionElement = document.getElementById("solution");
|
|
184
|
+
const firstSolution = swipl.prolog.query(query).once().X;
|
|
185
|
+
solutionElement.textContent = firstSolution;
|
|
186
|
+
})();
|
|
187
|
+
</script>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Dynamic imports are also available with the `dynamic-import.js` import name and can be used as follows:
|
|
191
|
+
|
|
192
|
+
```html
|
|
193
|
+
<div id="solution"></div>
|
|
194
|
+
<script>
|
|
195
|
+
(async () => {
|
|
196
|
+
const { SWIPL } = await import("https://SWI-Prolog.github.io/npm-swipl-wasm/3/3/0/dynamic-import.js");
|
|
197
|
+
const swipl = await SWIPL({ arguments: ["-q"] });
|
|
198
|
+
const query = "member(X, [a, b, c]).";
|
|
199
|
+
const solutionElement = document.getElementById("solution");
|
|
200
|
+
const firstSolution = swipl.prolog.query(query).once().X;
|
|
201
|
+
solutionElement.textContent = firstSolution;
|
|
202
|
+
})();
|
|
203
|
+
</script>
|
|
204
|
+
```
|
|
205
|
+
|
|
126
206
|
## Build
|
|
127
207
|
|
|
128
|
-
The package can be built using npm
|
|
129
|
-
add new dependencies and update
|
|
208
|
+
The package can be built using npm. Please use npm to
|
|
209
|
+
add new dependencies and update package-lock.json file. SWI-Prolog WebAssembly
|
|
130
210
|
version is currently built inside Docker with Emscripten.
|
|
131
211
|
|
|
132
212
|
## Versioning
|
package/dist/generateImage.js
CHANGED
|
@@ -16,7 +16,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.generateLoadedImageFile = exports.generateImageFile = exports.generateLoadedImageFileString = exports.generateImageFileString = exports.generateImageString = exports.generateImageBuffer = void 0;
|
|
17
17
|
const swipl_bundle_1 = __importDefault(require("./swipl/swipl-bundle"));
|
|
18
18
|
const fs_1 = __importDefault(require("fs"));
|
|
19
|
-
const
|
|
19
|
+
const universal_fetch_1 = require("@inrupt/universal-fetch");
|
|
20
20
|
function Uint8ToString(u8a) {
|
|
21
21
|
const CHUNK_SZ = 0x8000;
|
|
22
22
|
const c = [];
|
|
@@ -61,7 +61,7 @@ function generateLoadedImageFileString(prolog) {
|
|
|
61
61
|
exports.generateLoadedImageFileString = generateLoadedImageFileString;
|
|
62
62
|
function dereference(prologPath) {
|
|
63
63
|
return (prologPath.startsWith('http://') || prologPath.startsWith('https://'))
|
|
64
|
-
? (0,
|
|
64
|
+
? (0, universal_fetch_1.fetch)(prologPath).then((res) => res.text())
|
|
65
65
|
: fs_1.default.readFileSync(prologPath);
|
|
66
66
|
}
|
|
67
67
|
function generateImageFile(prologPath, jsPath) {
|