diff --git a/CHANGELOG.md b/CHANGELOG.md
index b9c860f..0aa9445 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,24 @@
+
+# [3.0.0](https://github.com/kwonoj/cld3-asm/compare/v2.0.1...v3.0.0) (2019-06-13)
+
+
+### build
+
+* **tsconfig:** update target ([f619336](https://github.com/kwonoj/cld3-asm/commit/f619336))
+
+
+### Features
+
+* **loadmodule:** no longer accepts environment ([4a6ecdc](https://github.com/kwonoj/cld3-asm/commit/4a6ecdc))
+
+
+### BREAKING CHANGES
+
+* **tsconfig:** runtime requires es2018
+* **loadmodule:** do not support environment override
+
+
+
## [2.0.1](https://github.com/kwonoj/cld3-asm/compare/v2.0.0...v2.0.1) (2019-06-10)
diff --git a/README.md b/README.md
index c08ace9..bc782d1 100644
--- a/README.md
+++ b/README.md
@@ -29,10 +29,10 @@ const cldFactory = await loadModule();
`loadModule` loads wasm binary, initialize it, and returns factory function to create instance of cld3 [language identifier.](https://github.com/kwonoj/cld3-asm/blob/1a86bb67abcebc2cd0e90a83149292eb044e4122/src/cldAsmModule.ts#L70-L97)
```js
-loadModule({timeout?: number, environment?: ENVIRONMENT}): Promise
+loadModule({ timeout?: number }): Promise
```
-It allows to specify timeout to wait until wasm binary compliation & load. By default `cld3-asm` tries to detect running environment, but for some cases (i.e electron) it is possible to override.
+It allows to specify timeout to wait until wasm binary compliation & load.
## Creating language identifier
diff --git a/bootstrap.ts b/bootstrap.ts
index 6617b1d..c0663ab 100644
--- a/bootstrap.ts
+++ b/bootstrap.ts
@@ -60,9 +60,11 @@ const validateBinaries = async (binaryFiles: Array<{ url: string; localBinaryPat
* Actually download binary from remote. This is direct invocation to wget, need local wget installation.
*
*/
-const downloadSingleBinary = async (libPath: string, binaryFile: { url: string; localBinaryPath: string }) => {
- const { url } = binaryFile;
- await asyncExec(`wget -q --directory-prefix=${libPath} ${url}`);
+const downloadSingleBinary = async (libPath: string, binaryFile: { url: string; binaryType: string; localBinaryPath: string }) => {
+ const { url, binaryType, localBinaryPath } = binaryFile;
+ const outPath = path.join(libPath, binaryType);
+ mkdir(outPath);
+ await asyncExec(`wget -O ${localBinaryPath} ${url}`);
if (!validateBinaries([binaryFile])) {
throw new Error(`Downloaded binary checksum mismatch, cannot complete bootstrap`);
@@ -74,11 +76,16 @@ const downloadSingleBinary = async (libPath: string, binaryFile: { url: string;
*/
(async () => {
const libPath = path.resolve('./src/lib');
- const binaryFiles = ['cld3.js'].map(fileName => ({
- url: `https://github.com/kwonoj/docker-cld3-wasm/releases/download/${version}/${fileName}`,
- localBinaryPath: path.join(libPath, fileName),
- type: path.extname(fileName) === '.js' ? 'hex' : ('binary' as crypto.HexBase64Latin1Encoding)
- }));
+ const binaryFiles = ['node', 'browser'].map(binaryType => {
+ const fileName = `cld3_${binaryType}.js`;
+
+ return {
+ url: `https://github.com/kwonoj/docker-cld3-wasm/releases/download/${version}/${fileName}`,
+ localBinaryPath: path.join(libPath, binaryType, 'cld3.js'),
+ binaryType,
+ type: path.extname(fileName) === '.js' ? 'hex' : ('binary' as crypto.HexBase64Latin1Encoding)
+ };
+ });
const isBinaryValid = await validateBinaries(binaryFiles);
diff --git a/package-lock.json b/package-lock.json
index f1cccae..60fae1f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "cld3-asm",
- "version": "2.0.1",
+ "version": "3.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -801,9 +801,9 @@
}
},
"@types/jest": {
- "version": "24.0.13",
- "resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.13.tgz",
- "integrity": "sha512-3m6RPnO35r7Dg+uMLj1+xfZaOgIHHHut61djNjzwExXN4/Pm9has9C6I1KMYSfz7mahDhWUOVg4HW/nZdv5Pww==",
+ "version": "24.0.14",
+ "resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.14.tgz",
+ "integrity": "sha512-IxS2AO0nOr4zrpKfRCxobQUb1bSK6ejodZ7odCzHXMjsASCI8J10N8qVQhrCjvJTc3bUjGGeuD+ytKZqyhajqQ==",
"dev": true,
"requires": {
"@types/jest-diff": "*"
@@ -828,9 +828,9 @@
"dev": true
},
"@types/node": {
- "version": "12.0.7",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.7.tgz",
- "integrity": "sha512-1YKeT4JitGgE4SOzyB9eMwO0nGVNkNEsm9qlIt1Lqm/tG2QEiSMTD4kS3aO6L+w5SClLVxALmIBESK6Mk5wX0A==",
+ "version": "12.0.8",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.8.tgz",
+ "integrity": "sha512-b8bbUOTwzIY3V5vDTY1fIJ+ePKDUBqt2hC2woVGotdQQhG/2Sh62HOKHrT7ab+VerXAcPyAiTEipPu/FsreUtg==",
"dev": true
},
"@types/normalize-package-data": {
@@ -2533,13 +2533,12 @@
"dev": true
},
"emscripten-wasm-loader": {
- "version": "2.2.3",
- "resolved": "https://registry.npmjs.org/emscripten-wasm-loader/-/emscripten-wasm-loader-2.2.3.tgz",
- "integrity": "sha512-//gI0afvtVnY7smttrPOW/BM+pTJLmdIcXAQV3fgRdQ0o6wm2vdSI0kjLYVOeo/rbtRsGgVuMLu6fT+O//EfaA==",
+ "version": "3.0.2",
+ "resolved": "https://registry.npmjs.org/emscripten-wasm-loader/-/emscripten-wasm-loader-3.0.2.tgz",
+ "integrity": "sha512-PF9YGrpMPcd7q/EUdZlLwVyxEeS1EBxNzXpjgIi/08OoB9rMACbNZEXEwIWR/i1JBh1Vd+FjkgvPz3BewcE7uA==",
"requires": {
"getroot": "^1.0.0",
- "nanoid": "^1.3.4",
- "tslib": "^1.9.3",
+ "nanoid": "^2.0.3",
"unixify": "^1.0.0"
}
},
@@ -4147,9 +4146,9 @@
}
},
"husky": {
- "version": "2.4.0",
- "resolved": "https://registry.npmjs.org/husky/-/husky-2.4.0.tgz",
- "integrity": "sha512-3k1wuZU20gFkphNWMjh2ISCFaqfbaLY7R9FST2Mj9HeRhUK9ydj9qQR8qfXlog3EctVGsyeilcZkIT7uBZDDVA==",
+ "version": "2.4.1",
+ "resolved": "https://registry.npmjs.org/husky/-/husky-2.4.1.tgz",
+ "integrity": "sha512-ZRwMWHr7QruR22dQ5l3rEGXQ7rAQYsJYqaeCd+NyOsIFczAtqaApZQP3P4HwLZjCtFbm3SUNYoKuoBXX3AYYfw==",
"dev": true,
"requires": {
"cosmiconfig": "^5.2.0",
@@ -4238,9 +4237,9 @@
}
},
"resolve": {
- "version": "1.11.1",
- "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz",
- "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==",
+ "version": "1.11.0",
+ "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.0.tgz",
+ "integrity": "sha512-WL2pBDjqT6pGUNSUzMw00o4T7If+z4H2x3Gz893WoUQ5KW8Vr9txp00ykiP16VBaZF5+j/OcXJHZ9+PCvdiDKw==",
"dev": true,
"requires": {
"path-parse": "^1.0.6"
@@ -6506,9 +6505,9 @@
"optional": true
},
"nanoid": {
- "version": "1.3.4",
- "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-1.3.4.tgz",
- "integrity": "sha512-4ug4BsuHxiVHoRUe1ud6rUFT3WUMmjXt1W0quL0CviZQANdan7D8kqN5/maw53hmAApY/jfzMRkC57BNNs60ZQ=="
+ "version": "2.0.3",
+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.0.3.tgz",
+ "integrity": "sha512-NbaoqdhIYmY6FXDRB4eYtDVC9Z9eCbn8TyaiC16LNKtpPv/aqa0tOPD8y6gNE4yUNnaZ7LLhYtXOev/6+cBtfw=="
},
"nanomatch": {
"version": "1.2.13",
@@ -8811,7 +8810,7 @@
},
"strip-ansi": {
"version": "3.0.1",
- "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
+ "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true,
"requires": {
diff --git a/package.json b/package.json
index 15cf1fd..b53a176 100644
--- a/package.json
+++ b/package.json
@@ -1,19 +1,22 @@
{
"name": "cld3-asm",
- "version": "2.0.1",
+ "version": "3.0.0",
"description": "WebAssembly based Javascript bindings for google compact language detector 3",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
+ "browser": {
+ "./dist/cjs/lib/node/cld3.js": "./dist/cjs/lib/browser/cld3.js",
+ "./dist/esm/lib/node/cld3.js": "./dist/esm/lib/browser/cld3.js"
+ },
"engines": {
- "npm": ">=3.0.0",
- "node": ">=8.0.0"
+ "node": ">=10"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
},
- "cld3-version": "c536440-190202"
+ "cld3-version": "ade8819-190613"
},
"lint-staged": {
"*.{ts,js}": [
@@ -56,16 +59,16 @@
"@commitlint/cli": "^8.0.0",
"@commitlint/config-angular": "^8.0.0",
"@types/chai": "^4.1.7",
- "@types/jest": "^24.0.13",
+ "@types/jest": "^24.0.14",
"@types/lodash": "^4.14.134",
- "@types/node": "^12.0.7",
+ "@types/node": "^12.0.8",
"@types/shelljs": "^0.8.5",
"@types/utf8": "^2.1.6",
"chai": "^4.2.0",
"commitizen": "^3.1.1",
"conventional-changelog-cli": "^2.0.21",
"cz-conventional-changelog": "2.1.0",
- "husky": "^2.4.0",
+ "husky": "^2.4.1",
"jest": "^24.8.0",
"jest-spin-reporter": "^1.0.2",
"lint-staged": "^8.2.0",
@@ -82,7 +85,7 @@
"utf8": "^3.0.0"
},
"dependencies": {
- "emscripten-wasm-loader": "^2.2.3"
+ "emscripten-wasm-loader": "^3.0.2"
},
"husky": {
"hooks": {
diff --git a/spec/cld-asm/cldLoader-spec.ts b/spec/cld-asm/cldLoader-spec.ts
index 219e1e3..d73d3de 100644
--- a/spec/cld-asm/cldLoader-spec.ts
+++ b/spec/cld-asm/cldLoader-spec.ts
@@ -10,7 +10,7 @@ const getAsmModule = (): CldAsmModule =>
(({
cwrap: jest.fn(),
getValue: jest.fn(),
- Pointer_stringify: jest.fn(() => LanguageCode.UNKNOWN),
+ UTF8ToString: jest.fn(() => LanguageCode.UNKNOWN),
allocateUTF8: jest.fn(),
setValue: jest.fn(),
initializeRuntime: jest.fn(),
diff --git a/spec/cld-asm/loadModule-spec.ts b/spec/cld-asm/loadModule-spec.ts
index 911f597..b9bc273 100644
--- a/spec/cld-asm/loadModule-spec.ts
+++ b/spec/cld-asm/loadModule-spec.ts
@@ -2,9 +2,9 @@ import { expect } from 'chai';
import { getModuleLoader as getModuleLoaderMock, isNode } from 'emscripten-wasm-loader';
import { loadModule } from '../../src/loadModule';
-const cld3Mock = require('../../src/lib/cld3'); //tslint:disable-line:no-require-imports no-var-requires
+const cld3Mock = require('../../src/lib/node/cld3'); //tslint:disable-line:no-require-imports no-var-requires
-jest.mock('../../src/lib/cld3', () => jest.fn());
+jest.mock('../../src/lib/node/cld3', () => jest.fn());
jest.mock('../../src/cldLoader');
jest.mock('emscripten-wasm-loader', () => ({
isWasmEnabled: jest.fn(),
diff --git a/src/ambient.d.ts b/src/ambient.d.ts
new file mode 100644
index 0000000..04166a7
--- /dev/null
+++ b/src/ambient.d.ts
@@ -0,0 +1 @@
+declare module '*/lib/node/cld3';
diff --git a/src/cldLoader.ts b/src/cldLoader.ts
index 07946ae..629e005 100644
--- a/src/cldLoader.ts
+++ b/src/cldLoader.ts
@@ -1,4 +1,3 @@
-import { ENVIRONMENT } from 'emscripten-wasm-loader';
import { CldAsmModule, LanguageResult } from './cldAsmModule';
import { CldFactory } from './cldFactory';
import { LanguageCode } from './languageCode';
@@ -17,8 +16,8 @@ const PTR_SIZE = 4;
*
* @returns {CldFactory} Factory function manages lifecycle of cld3 language identifier.
*/
-export const cldLoader = (asmModule: CldAsmModule, _environment?: ENVIRONMENT): CldFactory => {
- const { cwrap, _free, allocateUTF8, _malloc, getValue, Pointer_stringify, setValue } = asmModule;
+export const cldLoader = (asmModule: CldAsmModule): CldFactory => {
+ const { cwrap, _free, allocateUTF8, _malloc, getValue, UTF8ToString, setValue } = asmModule;
const cldInterface = wrapCldInterface(cwrap);
/**
@@ -35,7 +34,7 @@ export const cldLoader = (asmModule: CldAsmModule, _environment?: ENVIRONMENT):
};
// grab constant values from cld3 library
- const unknownIdentifier = Pointer_stringify(cldInterface.getUnknownIdentifier());
+ const unknownIdentifier = UTF8ToString(cldInterface.getUnknownIdentifier());
const minBytesDefault = cldInterface.getMinNumBytesDefault();
const maxBytesDefault = cldInterface.getMaxNumBytesDefault();
const maxBytesInput = cldInterface.getMaxNumBytesInput();
@@ -66,7 +65,7 @@ export const cldLoader = (asmModule: CldAsmModule, _environment?: ENVIRONMENT):
// be careful to match order of properties to match pointer to struct field.
const ret: LanguageResult = {
- language: Pointer_stringify(languageStringPtr) as LanguageCode,
+ language: UTF8ToString(languageStringPtr) as LanguageCode,
probability: getValue(structPtr + PTR_SIZE * 1, 'float'),
is_reliable: !!getValue(structPtr + PTR_SIZE * 2, 'i8'),
proportion: getValue(structPtr + PTR_SIZE * 3, 'float')
diff --git a/src/index.ts b/src/index.ts
index c47b877..211c627 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -3,4 +3,3 @@ export { log, enableLogger } from './util/logger';
export { LanguageIdentifier, CldFactory } from './cldFactory';
export { LanguageResult } from './cldAsmModule';
export { LanguageCode } from './languageCode';
-export { ENVIRONMENT } from 'emscripten-wasm-loader';
diff --git a/src/loadModule.ts b/src/loadModule.ts
index b861d28..8965e91 100644
--- a/src/loadModule.ts
+++ b/src/loadModule.ts
@@ -1,16 +1,18 @@
-import { ENVIRONMENT, getModuleLoader, isNode } from 'emscripten-wasm-loader';
+import { getModuleLoader } from 'emscripten-wasm-loader';
import { CldAsmModule } from './cldAsmModule';
import { CldFactory } from './cldFactory';
import { cldLoader } from './cldLoader';
import { log } from './util/logger';
+//imports MODULARIZED emscripten preamble
+import * as runtime from './lib/node/cld3';
+
/**
* Load, initialize wasm binary to use actual cld wasm instances.
*
* @param [InitOptions] Options to initialize cld3 wasm binary.
* @param {number} [InitOptions.timeout] - timeout to wait wasm binary compilation & load.
* @param {string | object} [InitOptions.locateBinary] - custom resolution logic for wasm binary. (not supported)
- * @param {ENVIRONMENT} [InitOptions.environment] For overriding running environment
* It could be either remote endpoint url, or loader-returned object for bundler. Check examples/browser_* for references.
*
* @returns {() => Promise} Function to load module
@@ -18,27 +20,16 @@ import { log } from './util/logger';
const loadModule = async (
initOptions: Partial<{
timeout: number;
- environment?: ENVIRONMENT;
}> = {}
) => {
- //imports MODULARIZED emscripten preamble
- //tslint:disable-next-line:no-require-imports no-var-requires
- const runtime = require(`./lib/cld3`);
-
- const { environment, timeout } = initOptions;
- const env = environment ? environment : isNode() ? ENVIRONMENT.NODE : ENVIRONMENT.WEB;
+ const { timeout } = initOptions;
log(`loadModule: loading cld3 wasm binary`, { initOptions });
- //https://github.com/kwonoj/docker-hunspell-wasm/issues/63
- //Build module object to construct wasm binary module via emscripten preamble.
- //apply overridden environment values to custom patched hunspell preamble.
- const overriddenModule = { ENVIRONMENT: env };
-
const moduleLoader = await getModuleLoader(
- (runtime: CldAsmModule) => cldLoader(runtime, env),
+ (runtime: CldAsmModule) => cldLoader(runtime),
runtime,
- overriddenModule,
+ undefined,
{ timeout }
);
diff --git a/tsconfig.json b/tsconfig.json
index 6864284..13e6801 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -12,7 +12,7 @@
"module": "commonjs",
"moduleResolution": "node",
"noEmit": true,
- "target": "es5",
+ "target": "es2018",
"outDir": "dist",
"lib": [
"es2016"