swipl-wasm 1.0.1 → 1.1.0

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/package.json CHANGED
@@ -1,17 +1,42 @@
1
1
  {
2
2
  "name": "swipl-wasm",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "exports": {
5
5
  "./swipl": "./dist/swipl/swipl.js",
6
- "./swipl-web": "./dist/swipl/swipl-web.js"
6
+ "./swipl-web": "./dist/swipl/swipl-web.js",
7
+ ".": "./dist/index.js"
7
8
  },
8
- "author": "Raivo Laanemets",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "contributors": [
12
+ "Raivo Laanemets",
13
+ "Jesse Wright"
14
+ ],
9
15
  "license": "BSD-2-Clause",
10
16
  "type": "commonjs",
11
17
  "devDependencies": {
18
+ "@types/emscripten": "^1.39.6",
19
+ "@types/jest": "^29.0.0",
20
+ "@types/node": "^18.7.14",
21
+ "@typescript-eslint/eslint-plugin": "^5.36.1",
22
+ "@typescript-eslint/parser": "^5.36.1",
23
+ "copyfiles": "^2.4.1",
24
+ "eslint": "^8.23.0",
25
+ "http-server": "^14.1.1",
26
+ "jest": "28",
27
+ "jest-environment-jsdom": "^29.0.1",
12
28
  "npm-run-all": "^4.1.5",
13
- "http-server": "^14.1.1"
29
+ "pre-commit": "^1.2.2",
30
+ "ts-jest": "^28.0.8",
31
+ "typescript": "^4.8.2"
14
32
  },
33
+ "browser": {
34
+ "./dist/locateFile.js": "./dist/locateFile-browser.js",
35
+ "./dist/swipl/swipl.js": "./dist/swipl/swipl-web.js"
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
15
40
  "scripts": {
16
41
  "build:wasm-docker:build": "docker build -t swipl-wasm-image docker",
17
42
  "build:wasm-docker:create": "docker create --name swipl-wasm swipl-wasm-image",
@@ -22,7 +47,34 @@
22
47
  "build:wasm-docker:extract:node": "docker cp swipl-wasm:/swipl-devel/swipl.wasm/src/swipl-web.js dist/swipl/swipl.js",
23
48
  "build:wasm-docker:extract": "run-s build:wasm-docker:extract:*",
24
49
  "build:wasm-docker": "run-s build:wasm-docker:build build:wasm-docker:create build:wasm-docker:extract build:wasm-docker:remove",
25
- "build": "run-s build:wasm-docker",
26
- "test:serve-http": "http-server . -c-1"
27
- }
50
+ "build:tsc:compile": "tsc",
51
+ "build:tsc:copy": "copyfiles -u 1 \"src/**/*.d.ts\" dist",
52
+ "build:tsc": "run-s build:tsc:*",
53
+ "build": "run-s build:*",
54
+ "prepare": "yarn run build",
55
+ "test:serve-http": "http-server . -c-1",
56
+ "test": "yarn run build && jest",
57
+ "lint": "eslint . --ext .ts"
58
+ },
59
+ "jest": {
60
+ "preset": "ts-jest",
61
+ "collectCoverage": true,
62
+ "coverageReporters": [
63
+ "json-summary",
64
+ "text",
65
+ "lcov"
66
+ ],
67
+ "coverageThreshold": {
68
+ "global": {
69
+ "branches": 10,
70
+ "functions": 10,
71
+ "lines": 10,
72
+ "statements": 10
73
+ }
74
+ }
75
+ },
76
+ "pre-commit": [
77
+ "lint",
78
+ "test"
79
+ ]
28
80
  }
package/docker/Dockerfile DELETED
@@ -1,53 +0,0 @@
1
- # Builds SWI-Prolog WebAssembly version.
2
- # https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650
3
-
4
- FROM debian:bullseye
5
-
6
- # Installs build dependencies.
7
-
8
- ENV DEBIAN_FRONTEND noninteractive
9
-
10
- RUN apt-get update && apt-get install -y \
11
- bzip2 \
12
- cmake \
13
- git \
14
- ninja-build \
15
- python3 \
16
- wget \
17
- xz-utils
18
-
19
- RUN git config --global pull.ff only
20
-
21
- # Installs Emscripten.
22
- # See https://emscripten.org/docs/getting_started/downloads.html
23
-
24
- ENV EMSDK_VERSION 3.1.20
25
-
26
- RUN git clone https://github.com/emscripten-core/emsdk.git /emsdk
27
- WORKDIR /emsdk
28
- RUN git pull
29
- RUN ./emsdk install $EMSDK_VERSION
30
- RUN ./emsdk activate $EMSDK_VERSION
31
-
32
- # Downloads ZLIB.
33
-
34
- RUN wget --no-verbose https://zlib.net/zlib-1.2.12.tar.gz -O /zlib-1.2.12.tar.gz
35
- RUN tar -xf /zlib-1.2.12.tar.gz --directory /
36
-
37
- # Clones SWI-Prolog.
38
-
39
- RUN git clone https://github.com/SWI-Prolog/swipl-devel.git /swipl-devel
40
- WORKDIR /swipl-devel
41
-
42
- # Uncomment the following to build a specific commit.
43
- # ENV SWIPL_COMMIT 5c7d1f8352b27d45cb8066eac5af95cf925a05b7
44
- # RUN git checkout $SWIPL_COMMIT -b local-wasm
45
-
46
- RUN git fetch
47
- RUN git submodule update --init
48
-
49
- # Compiles everything.
50
-
51
- COPY build-all.sh /build-all.sh
52
- RUN chmod +x /build-all.sh
53
- RUN /build-all.sh
@@ -1,29 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -o errexit
4
- set -o xtrace
5
-
6
- source /emsdk/emsdk_env.sh
7
-
8
- # ZLIB
9
-
10
- cd /zlib-1.2.12
11
- emconfigure ./configure
12
- EMCC_CFLAGS=-Wno-deprecated-non-prototype emmake make
13
-
14
- # SWI-Prolog
15
-
16
- mkdir /swipl-devel/swipl.wasm
17
- cd /swipl-devel/swipl.wasm
18
- cmake -DCMAKE_TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \
19
- -DCMAKE_BUILD_TYPE=Release \
20
- -DZLIB_LIBRARY=/zlib-1.2.12/libz.a \
21
- -DZLIB_INCLUDE_DIR=/zlib-1.2.12 \
22
- -DINSTALL_DOCUMENTATION=OFF \
23
- -DMULTI_THREADED=OFF \
24
- -DUSE_SIGNALS=OFF \
25
- -DUSE_GMP=OFF \
26
- -DBUILD_SWIPL_LD=OFF \
27
- -DSWIPL_PACKAGES=OFF \
28
- -G Ninja ..
29
- ninja
@@ -1,32 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF8">
5
- <title>SWI-Prolog WebAssembly browser test</title>
6
- </head>
7
- <body>
8
- <div id="solution"></div>
9
- <script src="/dist/swipl/swipl-web.js"></script>
10
- <script>
11
- (async () => {
12
- const swipl = await SWIPL({
13
- noInitialRun: true,
14
- arguments: ['-q'],
15
- locateFile: (url) => {
16
- if (url === 'swipl-web.data') {
17
- return '/dist/swipl/swipl-web.data';
18
- } else if (url === 'swipl-web.wasm') {
19
- return '/dist/swipl/swipl-web.wasm';
20
- }
21
- return url;
22
- }
23
- });
24
- const query = "member(X, [a, b, c]).";
25
- const solutionElement = document.getElementById('solution');
26
- // See https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650/1
27
- const firstSolution = swipl.prolog.query(query).once().X;
28
- solutionElement.textContent = firstSolution;
29
- })();
30
- </script>
31
- </body>
32
- </html>
@@ -1,23 +0,0 @@
1
- const path = require('path');
2
- const SWIPL = require('swipl-wasm/swipl');
3
-
4
- (async () => {
5
- // This helps to find the correct locations of the
6
- // .data and .wasm files.
7
- const swiplModuleLocation = require.resolve('swipl-wasm/swipl');
8
- const swipl = await SWIPL({
9
- noInitialRun: true,
10
- arguments: ['-q'],
11
- locateFile: (url) => {
12
- // These are common with the web version.
13
- if (url === 'swipl-web.data') {
14
- return path.join(path.dirname(swiplModuleLocation), 'swipl-web.data');
15
- } else if (url === 'swipl-web.wasm') {
16
- return path.join(path.dirname(swiplModuleLocation), 'swipl-web.wasm');
17
- }
18
- return url;
19
- }
20
- });
21
- // See https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650/1
22
- console.log(swipl.prolog.query("member(X, [a, b, c]).").once().X);
23
- })();