Skip to content

Commit

Permalink
build(bindgen): only warn when esm module is not present for python-e…
Browse files Browse the repository at this point in the history
…mscripten
  • Loading branch information
thewtex committed Nov 9, 2023
1 parent 884a48c commit 723a13a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/bindgen/python/emscripten/emscripten-package.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs-extra'
import path from 'path'

import mkdirP from '../../mkdir-p.js'
Expand All @@ -13,6 +14,14 @@ import emscriptenFunctionModule from './emscripten-function-module.js'
import wasmBinaryInterfaceJson from '../../wasm-binary-interface-json.js'

function emscriptenPackage(outputDir, buildDir, wasmBinaries, options) {
const defaultJsModulePath = path.join(outputDir, '..', 'typescript', 'dist', 'bundle', 'index-worker-embedded.min.js')
const moduleUrl = options.jsModulePath ?? defaultJsModulePath
if (!fs.existsSync(moduleUrl)) {
console.warn(`Could not find ${moduleUrl}: skipping python emscripten package`)
return
}
const jsModuleContent = btoa(fs.readFileSync(moduleUrl, { encoding: 'utf8', flag: 'r' }))

const packageName = `${options.packageName}-emscripten`
const packageDir = path.join(outputDir, packageName)
const packageDescription = `${options.packageDescription} Emscripten implementation.`
Expand All @@ -28,7 +37,7 @@ function emscriptenPackage(outputDir, buildDir, wasmBinaries, options) {
const async = true
const sync = false
packageDunderInit(outputDir, buildDir, wasmBinaries, packageName, packageDescription, packageDir, pypackage, async, sync)
emscriptenPyodideModule(outputDir, packageDir, pypackage, options)
emscriptenPyodideModule(jsModuleContent, packageDir, pypackage)
emscriptenTestModule(packageDir, pypackage)

const wasmModulesDir = path.join(packageDir, pypackage, 'wasm_modules')
Expand Down
11 changes: 1 addition & 10 deletions src/bindgen/python/emscripten/emscripten-pyodide-module.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import fs from 'fs-extra'
import path from 'path'

import writeIfOverrideNotPresent from '../../write-if-override-not-present.js'

function emscriptenPyodideModule(outputDir, packageDir, pypackage, options) {
const defaultJsModulePath = path.join(outputDir, '..', 'typescript', 'dist', 'bundle', 'index-worker-embedded.min.js')
const moduleUrl = options.jsModulePath ?? defaultJsModulePath
if (!fs.existsSync(moduleUrl)) {
console.error(`Could not find ${moduleUrl}`)
process.exit(1)
}
const jsModuleContent = btoa(fs.readFileSync(moduleUrl, { encoding: 'utf8', flag: 'r' }))

function emscriptenPyodideModule(jsModuleContent, packageDir, pypackage) {
const moduleContent = `from itkwasm.pyodide import JsPackageConfig, JsPackage
from ._version import __version__
Expand Down

0 comments on commit 723a13a

Please sign in to comment.