From 8a2ec518deb57699163bd5eb7a5d2f4d54f71135 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 12 Jun 2023 08:42:40 -0700 Subject: [PATCH] Use .mjs for ESM Modules and use .cjs for CommonJS PiperOrigin-RevId: 539664711 --- mediapipe/tasks/web/audio/BUILD | 28 +++++++++++++++++++++++++--- mediapipe/tasks/web/package.json | 7 ++++--- mediapipe/tasks/web/text/BUILD | 28 +++++++++++++++++++++++++--- mediapipe/tasks/web/vision/BUILD | 28 +++++++++++++++++++++++++--- 4 files changed, 79 insertions(+), 12 deletions(-) diff --git a/mediapipe/tasks/web/audio/BUILD b/mediapipe/tasks/web/audio/BUILD index 4dd5a2f6b..3338d17be 100644 --- a/mediapipe/tasks/web/audio/BUILD +++ b/mediapipe/tasks/web/audio/BUILD @@ -38,7 +38,7 @@ mediapipe_files(srcs = [ ]) rollup_bundle( - name = "audio_bundle", + name = "audio_bundle_mjs", config_file = "//mediapipe/tasks/web:rollup.config.mjs", entry_point = "index.ts", format = "esm", @@ -69,6 +69,29 @@ rollup_bundle( ], ) +genrule( + name = "audio_sources", + srcs = [ + ":audio_bundle_cjs", + ":audio_bundle_mjs", + ], + outs = [ + "audio_bundle.cjs", + "audio_bundle.cjs.map", + "audio_bundle.mjs", + "audio_bundle.mjs.map", + ], + cmd = ( + "for FILE in $(SRCS); do " + + " OUT_FILE=$(GENDIR)/mediapipe/tasks/web/audio/$$(" + + " basename $$FILE | sed -E 's/_([cm])js\\.js/.\\1js/'" + + " ); " + + " echo $$FILE ; echo $$OUT_FILE ; " + + " cp $$FILE $$OUT_FILE ; " + + "done;" + ), +) + genrule( name = "package_json", srcs = ["//mediapipe/tasks/web:package.json"], @@ -91,8 +114,7 @@ pkg_npm( "wasm/audio_wasm_internal.wasm", "wasm/audio_wasm_nosimd_internal.js", "wasm/audio_wasm_nosimd_internal.wasm", - ":audio_bundle", - ":audio_bundle_cjs", + ":audio_sources", ":package_json", ], ) diff --git a/mediapipe/tasks/web/package.json b/mediapipe/tasks/web/package.json index 3f495d151..4a42018f0 100644 --- a/mediapipe/tasks/web/package.json +++ b/mediapipe/tasks/web/package.json @@ -2,11 +2,12 @@ "name": "@mediapipe/tasks-__NAME__", "version": "__VERSION__", "description": "__DESCRIPTION__", - "main": "__NAME___bundle_cjs.js", - "browser": "__NAME___bundle.js", - "module": "__NAME___bundle.js", + "main": "__NAME___bundle.cjs", + "browser": "__NAME___bundle.mjs", + "module": "__NAME___bundle.mjs", "author": "mediapipe@google.com", "license": "Apache-2.0", + "type": "module", "types": "__TYPES__", "homepage": "http://mediapipe.dev", "keywords": [ "AR", "ML", "Augmented", "MediaPipe", "MediaPipe Tasks" ] diff --git a/mediapipe/tasks/web/text/BUILD b/mediapipe/tasks/web/text/BUILD index f68a8c9f5..76d875ba5 100644 --- a/mediapipe/tasks/web/text/BUILD +++ b/mediapipe/tasks/web/text/BUILD @@ -39,7 +39,7 @@ mediapipe_ts_library( ) rollup_bundle( - name = "text_bundle", + name = "text_bundle_mjs", config_file = "//mediapipe/tasks/web:rollup.config.mjs", entry_point = "index.ts", format = "esm", @@ -70,6 +70,29 @@ rollup_bundle( ], ) +genrule( + name = "text_sources", + srcs = [ + ":text_bundle_cjs", + ":text_bundle_mjs", + ], + outs = [ + "text_bundle.cjs", + "text_bundle.cjs.map", + "text_bundle.mjs", + "text_bundle.mjs.map", + ], + cmd = ( + "for FILE in $(SRCS); do " + + " OUT_FILE=$(GENDIR)/mediapipe/tasks/web/text/$$(" + + " basename $$FILE | sed -E 's/_([cm])js\\.js/.\\1js/'" + + " ); " + + " echo $$FILE ; echo $$OUT_FILE ; " + + " cp $$FILE $$OUT_FILE ; " + + "done;" + ), +) + genrule( name = "package_json", srcs = ["//mediapipe/tasks/web:package.json"], @@ -93,7 +116,6 @@ pkg_npm( "wasm/text_wasm_nosimd_internal.js", "wasm/text_wasm_nosimd_internal.wasm", ":package_json", - ":text_bundle", - ":text_bundle_cjs", + ":text_sources", ], ) diff --git a/mediapipe/tasks/web/vision/BUILD b/mediapipe/tasks/web/vision/BUILD index a7767fe53..58795b166 100644 --- a/mediapipe/tasks/web/vision/BUILD +++ b/mediapipe/tasks/web/vision/BUILD @@ -50,7 +50,7 @@ mediapipe_ts_library( ) rollup_bundle( - name = "vision_bundle", + name = "vision_bundle_mjs", config_file = "//mediapipe/tasks/web:rollup.config.mjs", entry_point = "index.ts", format = "esm", @@ -81,6 +81,29 @@ rollup_bundle( ], ) +genrule( + name = "vision_sources", + srcs = [ + ":vision_bundle_cjs", + ":vision_bundle_mjs", + ], + outs = [ + "vision_bundle.cjs", + "vision_bundle.cjs.map", + "vision_bundle.mjs", + "vision_bundle.mjs.map", + ], + cmd = ( + "for FILE in $(SRCS); do " + + " OUT_FILE=$(GENDIR)/mediapipe/tasks/web/vision/$$(" + + " basename $$FILE | sed -E 's/_([cm])js\\.js/.\\1js/'" + + " ); " + + " echo $$FILE ; echo $$OUT_FILE ; " + + " cp $$FILE $$OUT_FILE ; " + + "done;" + ), +) + genrule( name = "package_json", srcs = ["//mediapipe/tasks/web:package.json"], @@ -104,7 +127,6 @@ pkg_npm( "wasm/vision_wasm_nosimd_internal.js", "wasm/vision_wasm_nosimd_internal.wasm", ":package_json", - ":vision_bundle", - ":vision_bundle_cjs", + ":vision_sources", ], )