-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from zama-ai/update-bundle-06
[release] Update bundle 06
- Loading branch information
Showing
12 changed files
with
2,597 additions
and
580 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
on: | ||
release: | ||
types: [released] | ||
|
||
jobs: | ||
publish: | ||
permissions: | ||
id-token: 'write' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20.x | ||
- run: npm ci | ||
- run: npm test | ||
- run: BASE_PATH=https://cdn.zama.ai/fhevmjs/$(node -p "require('./package.json').version")/ npm run build | ||
# todo push on S3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
!lib/**/* | ||
!web.d.ts | ||
!web.js | ||
!bundle.d.ts | ||
!bundle.js | ||
!node.d.ts | ||
!node.js | ||
!package.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lib/web'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const waitForFunction = | ||
(functionName) => | ||
async (...params) => { | ||
if (window && window.fhevmjs) { | ||
return window.fhevmjs[functionName](...params); | ||
} | ||
}; | ||
|
||
const initFhevm = waitForFunction('initFhevm'); | ||
const createInstance = waitForFunction('createInstance'); | ||
|
||
export { initFhevm, createInstance }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { defineConfig } from 'vite'; | ||
import { nodePolyfills } from 'vite-plugin-node-polyfills'; | ||
import { viteStaticCopy } from 'vite-plugin-static-copy'; | ||
import { ignoreURL, changeLoadingWorker } from './vite.replace'; | ||
|
||
const basePath = process.env.BASE_PATH || '/'; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
base: basePath, | ||
build: { | ||
lib: { | ||
name: 'fhevmjs', | ||
fileName: 'fhevmjs', | ||
entry: ['lib/web.js'], | ||
}, | ||
outDir: 'bundle', | ||
}, | ||
plugins: [ | ||
changeLoadingWorker(basePath), | ||
ignoreURL(basePath), | ||
nodePolyfills(), | ||
viteStaticCopy({ | ||
targets: [ | ||
{ | ||
src: 'lib/tfhe_bg.wasm', | ||
dest: '.', | ||
}, | ||
{ | ||
src: 'lib/kms_lib_bg.wasm', | ||
dest: '.', | ||
}, | ||
], | ||
}), | ||
], | ||
worker: { | ||
format: 'iife', | ||
plugins: [ignoreURL(basePath)], | ||
rollupOptions: { | ||
output: { | ||
entryFileNames: '[name].js', | ||
}, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
export const changeLoadingWorker = (basePath) => ({ | ||
name: 'regex-replace', // name of the plugin | ||
enforce: 'pre', // run before other plugins | ||
transform(code, id) { | ||
// Only apply transformations to .js files (or other specific conditions) | ||
if (id.endsWith('.js')) { | ||
const searchValue = | ||
/const worker = new Worker\(\s*new URL\(['"]\.?\/?workerHelpers\.worker\.js['"],\s*import\.meta\.url\),\s*\{\s*type:\s*'module',?\s*\},?\s*\);/; | ||
|
||
const replacement = `let worker; | ||
try { | ||
worker = new Worker( | ||
new URL('./workerHelpers.worker.js', import.meta.url), | ||
{ | ||
type: 'module' | ||
} | ||
); | ||
} catch (e) { | ||
const r = await fetch('${basePath}workerHelpers.worker.js'); | ||
const blob = await r.blob(); | ||
const blobUrl = URL.createObjectURL(blob); | ||
worker = new Worker(blobUrl); | ||
}`; | ||
|
||
// Check that the worker change works. | ||
if (id.match('lib/web.js')) { | ||
const match = code.match(searchValue); | ||
if (!match) | ||
throw new Error( | ||
'Impossible to replace Worker with iife implementation. Source code (lib/web.js) changed.', | ||
); | ||
} | ||
|
||
// Replace occurrences according to the regex pattern | ||
const newCode = code.replace(searchValue, replacement); | ||
|
||
return { | ||
code: newCode, | ||
map: null, // provide source map if available or required | ||
}; | ||
} | ||
// Return null to signify no transformation for non-JS files or uninterested files | ||
return null; | ||
}, | ||
}); | ||
|
||
const wasmPattern = /'([a-zA-Z0-9_]+)\.wasm'/g; | ||
|
||
export const ignoreURL = (basePath) => ({ | ||
name: 'regex-replace', // name of the plugin | ||
enforce: 'pre', // run before other plugins | ||
transform(code, id) { | ||
// Only apply transformations to .js files (or other specific conditions) | ||
if (id.endsWith('.js')) { | ||
const pattern = wasmPattern; // Your regex pattern here | ||
const replacement = `/* @vite-ignore */ '${basePath}$1.wasm'`; // Your replacement string here | ||
|
||
// Replace occurrences according to the regex pattern | ||
// const newCode = code.replace(pattern, replacement); | ||
const newCode = code.replace(wasmPattern, replacement); | ||
|
||
return { | ||
code: newCode, | ||
map: null, // provide source map if available or required | ||
}; | ||
} | ||
// Return null to signify no transformation for non-JS files or uninterested files | ||
return null; | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.