swipl-wasm 3.3.0 → 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 +35 -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 +13 -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);
|
|
@@ -173,8 +205,8 @@ Dynamic imports are also available with the `dynamic-import.js` import name and
|
|
|
173
205
|
|
|
174
206
|
## Build
|
|
175
207
|
|
|
176
|
-
The package can be built using npm
|
|
177
|
-
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
|
|
178
210
|
version is currently built inside Docker with Emscripten.
|
|
179
211
|
|
|
180
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) {
|