Get ready for publishing Typescript SDK with credentials client

This commit is contained in:
Mark Sinclair
2024-01-12 16:36:18 +00:00
committed by Jędrzej Stuczyński
parent d5cc31b7f0
commit 6cd59124a2
9 changed files with 72 additions and 48 deletions
+1
View File
@@ -103,6 +103,7 @@ sdk-wasm: sdk-wasm-build sdk-wasm-test sdk-wasm-lint
sdk-wasm-build:
$(MAKE) -C nym-browser-extension/storage wasm-pack
$(MAKE) -C wasm/client
$(MAKE) -C wasm/credentials
$(MAKE) -C wasm/node-tester
$(MAKE) -C wasm/mix-fetch
#$(MAKE) -C wasm/full-nym-wasm
+3 -1
View File
@@ -13,7 +13,8 @@
"scripts": {
"build": "scripts/build-prod.sh",
"build:dev": "scripts/build.sh",
"build:dev:esm": "scripts/build-dev-esm.sh",
"build:dev:esm": "SDK_DEV_MODE=true scripts/build-dev-esm.sh",
"build:dev:esm:no-inline": "scripts/build-dev-esm.sh",
"build:worker": "rollup -c rollup-worker.config.mjs",
"clean": "rimraf dist",
"docs:dev": "run-p docs:watch docs:serve ",
@@ -32,6 +33,7 @@
},
"dependencies": {
"@nymproject/nym-client-wasm": ">=1.2.4-rc.2 || ^1",
"@nymproject/nym-credential-client-wasm": ">=1.2.0-rc.9 || ^1",
"comlink": "^4.3.1"
},
"devDependencies": {
@@ -0,0 +1,7 @@
import { getConfig } from './rollup/worker.mjs';
export default {
...getConfig('src/coconut/worker.ts', 'nym_credential_client_wasm_bg.wasm'),
inlineWasm: true,
format: 'cjs',
};
@@ -1,26 +1,7 @@
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import { wasm } from '@rollup/plugin-wasm';
import replace from '@rollup/plugin-replace';
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
import { getConfig } from './rollup/worker.mjs';
export default {
input: 'src/coconut/worker.ts',
output: {
dir: 'dist',
format: 'cjs',
},
plugins: [
resolve({ extensions }),
// this is some nasty monkey patching that removes the WASM URL (because it is handled by the `wasm` plugin)
replace({
values: { "input = new URL('nym_credential_client_wasm_bg.wasm', import.meta.url);": 'input = undefined;' },
delimiters: ['', ''],
preventAssignment: true,
}),
// force the wasm plugin to embed the wasm bundle - this means no downstream bundlers have to worry about handling it
wasm({ maxFileSize: 10000000, targetEnv: 'browser' }),
typescript({ compilerOptions: { declaration: false, target: 'es5' } }),
],
...getConfig('src/coconut/worker.ts', 'nym_credential_client_wasm_bg.wasm', {
inlineWasm: process.env.SDK_DEV_MODE === 'true',
}),
};
@@ -2,6 +2,6 @@ import { getConfig } from './rollup/esm.mjs';
export default {
...getConfig({
inline: false,
inline: process.env.SDK_DEV_MODE === 'true',
}),
};
@@ -0,0 +1,8 @@
import { getConfig } from './rollup/worker.mjs';
export default {
...getConfig('src/mixnet/wasm/worker.ts', 'nym_client_wasm_bg.wasm', {
inlineWasm: true,
format: 'cjs',
}),
};
@@ -1,26 +1,7 @@
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import { wasm } from '@rollup/plugin-wasm';
import replace from '@rollup/plugin-replace';
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
import { getConfig } from './rollup/worker.mjs';
export default {
input: 'src/mixnet/wasm/worker.ts',
output: {
dir: 'dist',
format: 'cjs',
},
plugins: [
resolve({ extensions }),
// this is some nasty monkey patching that removes the WASM URL (because it is handled by the `wasm` plugin)
replace({
values: { "input = new URL('nym_client_wasm_bg.wasm', import.meta.url);": 'input = undefined;' },
delimiters: ['', ''],
preventAssignment: true,
}),
// force the wasm plugin to embed the wasm bundle - this means no downstream bundlers have to worry about handling it
wasm({ maxFileSize: 10000000, targetEnv: 'browser' }),
typescript({ compilerOptions: { declaration: false, target: 'es5' } }),
],
...getConfig('src/mixnet/wasm/worker.ts', 'nym_client_wasm_bg.wasm', {
inlineWasm: process.env.SDK_DEV_MODE === 'true',
}),
};
@@ -0,0 +1,43 @@
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import { wasm } from '@rollup/plugin-wasm';
import replace from '@rollup/plugin-replace';
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
/**
* Configure worker output
*
* @param opts
* `format`: `es` or `cjs`,
* `inlineWasm`: true or false,
* `tsTarget`: `es5` or `es6`
*/
export const getConfig = (input, wasmFilename, opts) => ({
input,
output: {
dir: 'dist',
format: opts?.format || 'es',
},
plugins: [
resolve({ extensions }),
// this is some nasty monkey patching that removes the WASM URL (because it is handled by the `wasm` plugin)
replace({
values: { [`input = new URL('${wasmFilename}', import.meta.url);`]: 'input = undefined;' },
delimiters: ['', ''],
preventAssignment: true,
}),
opts?.inlineWasm === true
? wasm({ maxFileSize: 10_000_000, targetEnv: 'browser' }) // force the wasm plugin to embed the wasm bundle - this means no downstream bundlers have to worry about handling it
: wasm({
targetEnv: 'browser',
fileName: '[name].wasm',
}),
typescript({
compilerOptions: {
declaration: false,
target: opts?.tsTarget || 'es6',
},
}),
],
});
@@ -27,6 +27,7 @@ rm dist/worker.js || true
rollup -c rollup-coconut-worker.config.mjs
# move it next to the Typescript `src/index.ts` so it can be inlined by rollup
mkdir dist/esm || true
cp dist/worker.js src/coconut/worker.js || true
rm dist/worker.js || true