From bf84b79e7d327f8e47ffc1d75c5df35f79fc4b37 Mon Sep 17 00:00:00 2001 From: Matthew Soulanille Date: Thu, 17 Nov 2022 12:39:46 -0800 Subject: [PATCH] Make tfjs-tfdf work with bundlers (#7054) Set the ESM entrypoint to the flat ESM bundle. Set the cjs entrypoint to the node (cjs) bundle. Prevent node-specific 'require's in the emscripten bundle from being hoisted to the top of the file. Now, it checks if it's running in node before requiring node-specific things like 'fs' or 'path'. --- tfjs-tfdf/BUILD.bazel | 8 +++++--- tfjs-tfdf/package.json | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tfjs-tfdf/BUILD.bazel b/tfjs-tfdf/BUILD.bazel index 97296d1fbb0..5f39e913f38 100644 --- a/tfjs-tfdf/BUILD.bazel +++ b/tfjs-tfdf/BUILD.bazel @@ -29,13 +29,16 @@ tfjs_bundle( "@tensorflow/tfjs-converter", "path", "fs", - "jszip", ], globals = { "@tensorflow/tfjs-converter": "tf", "@tensorflow/tfjs-core": "tf", - "jszip": "JSZip", }, + leave_as_require = [ + "path", + "fs", + "crypto", + ], umd_name = "tfdf", deps = [ "//tfjs-tfdf/src:tfdf_web_api_client_js", @@ -92,7 +95,6 @@ pkg_npm( ":copy_bundles", ":copy_src_to_dist", ":copy_wasm_files", - "//tfjs-tfdf/wasm:wasm_files", ], ) diff --git a/tfjs-tfdf/package.json b/tfjs-tfdf/package.json index a7583241533..a51434c2f8b 100644 --- a/tfjs-tfdf/package.json +++ b/tfjs-tfdf/package.json @@ -3,10 +3,16 @@ "version": "0.0.1", "description": "TensorFlow Decision Forests support for TensorFlow.js", "main": "dist/tf-tfdf.node.js", - "module": "dist/index.js", + "module": "dist/tf-tfdf.fesm.js", "jsdelivr": "dist/tf-tfdf.min.js", "unpkg": "dist/tf-tfdf.min.js", "types": "dist/index.d.ts", + "exports": { + ".": { + "import": "./dist/tf-tfdf.fesm.js", + "require": "./dist/tf-tfdf.node.js" + } + }, "repository": { "type": "git", "url": "https://github.com/tensorflow/tfjs.git",