From fd3faee55500545b5cc87d4fedad71f6308c1623 Mon Sep 17 00:00:00 2001 From: chradek <51000525+chradek@users.noreply.github.com> Date: Wed, 29 Sep 2021 15:47:45 -0700 Subject: [PATCH] Unblock react native support when using corev2 packages (#17783) ~This is a WIP. Currently these changes, along with a shims file, allows our packages that depend on core-client to run in react native.~ ~ToDo: I've created expo and react-native cli projects that illustrate what shims are needed to get this working. Currently working on getting those samples into this PR.~ This PR has been updated to just include making the changes needed for the corev2 packages to run in react native, assuming that the requisite browser APIs are pollyfilled. --- sdk/core/core-client-paging-rest/CHANGELOG.md | 2 ++ sdk/core/core-client-paging-rest/package.json | 3 +++ sdk/core/core-client/CHANGELOG.md | 2 ++ sdk/core/core-client/package.json | 3 +++ sdk/core/core-crypto/package.json | 3 +++ sdk/core/core-crypto/src/sha256.browser.ts | 2 +- sdk/core/core-lro/CHANGELOG.md | 2 ++ sdk/core/core-lro/package.json | 3 +++ sdk/core/core-rest-pipeline/CHANGELOG.md | 2 ++ sdk/core/core-rest-pipeline/package.json | 4 ++++ .../src/util/userAgentPlatform.native.ts | 23 +++++++++++++++++++ sdk/core/core-tracing/CHANGELOG.md | 2 ++ sdk/core/core-tracing/package.json | 3 +++ sdk/core/core-util/CHANGELOG.md | 3 +++ sdk/core/core-util/package.json | 3 +++ sdk/core/logger/CHANGELOG.md | 3 +++ sdk/core/logger/package.json | 3 +++ 17 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 sdk/core/core-rest-pipeline/src/util/userAgentPlatform.native.ts diff --git a/sdk/core/core-client-paging-rest/CHANGELOG.md b/sdk/core/core-client-paging-rest/CHANGELOG.md index 263bd102cac5..c2c4c45ff2d7 100644 --- a/sdk/core/core-client-paging-rest/CHANGELOG.md +++ b/sdk/core/core-client-paging-rest/CHANGELOG.md @@ -10,6 +10,8 @@ ### Other Changes +- Updates package to work with the react native bundler. Browser APIs may still need to be pollyfilled for this package to run in react native. [PR #17783](https://github.com/Azure/azure-sdk-for-js/pull/17783) + ## 1.0.0-beta.1 (2021-08-05) - First release of package, see README.md for details. diff --git a/sdk/core/core-client-paging-rest/package.json b/sdk/core/core-client-paging-rest/package.json index 1ed916031ac8..b49c9fac60f4 100644 --- a/sdk/core/core-client-paging-rest/package.json +++ b/sdk/core/core-client-paging-rest/package.json @@ -9,6 +9,9 @@ "browser": { "./dist-esm/src/url.js": "./dist-esm/src/url.browser.js" }, + "react-native": { + "./dist/index.js": "./dist-esm/src/index.js" + }, "scripts": { "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", "build:samples": "echo Obsolete", diff --git a/sdk/core/core-client/CHANGELOG.md b/sdk/core/core-client/CHANGELOG.md index 7d69d2c97a50..fa2738cd0390 100644 --- a/sdk/core/core-client/CHANGELOG.md +++ b/sdk/core/core-client/CHANGELOG.md @@ -10,6 +10,8 @@ ### Other Changes +- Updates package to work with the react native bundler. Browser APIs may still need to be pollyfilled for this package to run in react native. [PR #17783](https://github.com/Azure/azure-sdk-for-js/pull/17783) + ## 1.3.0 (2021-08-04) ### Features Added diff --git a/sdk/core/core-client/package.json b/sdk/core/core-client/package.json index f270079c66c6..9caaa96ea62c 100644 --- a/sdk/core/core-client/package.json +++ b/sdk/core/core-client/package.json @@ -8,6 +8,9 @@ "browser": { "./dist-esm/src/base64.js": "./dist-esm/src/base64.browser.js" }, + "react-native": { + "./dist/index.js": "./dist-esm/src/index.js" + }, "types": "types/latest/core-client.d.ts", "typesVersions": { "<3.6": { diff --git a/sdk/core/core-crypto/package.json b/sdk/core/core-crypto/package.json index b7f01ffffc47..a911ac5bfc30 100644 --- a/sdk/core/core-crypto/package.json +++ b/sdk/core/core-crypto/package.json @@ -8,6 +8,9 @@ "browser": { "./dist-esm/src/sha256.js": "./dist-esm/src/sha256.browser.js" }, + "react-native": { + "./dist/index.js": "./dist-esm/src/index.js" + }, "types": "types/latest/core-crypto.d.ts", "typesVersions": { "<3.6": { diff --git a/sdk/core/core-crypto/src/sha256.browser.ts b/sdk/core/core-crypto/src/sha256.browser.ts index 26653fc90a80..926933b46660 100644 --- a/sdk/core/core-crypto/src/sha256.browser.ts +++ b/sdk/core/core-crypto/src/sha256.browser.ts @@ -67,7 +67,7 @@ export async function computeSha256Hash( encoding: "base64" | "hex" ): Promise { const contentBytes = utf8ToBytes(content); - const digest = await getCrypto().digest("SHA-256", contentBytes); + const digest = await getCrypto().digest({ name: "SHA-256" }, contentBytes); switch (encoding) { case "base64": diff --git a/sdk/core/core-lro/CHANGELOG.md b/sdk/core/core-lro/CHANGELOG.md index be150c94ef51..57b40649223f 100644 --- a/sdk/core/core-lro/CHANGELOG.md +++ b/sdk/core/core-lro/CHANGELOG.md @@ -12,6 +12,8 @@ ### Other Changes +- Updates package to work with the react native bundler. [PR #17783](https://github.com/Azure/azure-sdk-for-js/pull/17783) + ## 2.2.0 (2021-08-05) ### Features Added diff --git a/sdk/core/core-lro/package.json b/sdk/core/core-lro/package.json index 15bb28d8ea21..dd55e120cc3b 100644 --- a/sdk/core/core-lro/package.json +++ b/sdk/core/core-lro/package.json @@ -41,6 +41,9 @@ "os": false, "process": false }, + "react-native": { + "./dist/index.js": "./dist-esm/src/index.js" + }, "license": "MIT", "homepage": "https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-lro/README.md", "repository": "github:Azure/azure-sdk-for-js", diff --git a/sdk/core/core-rest-pipeline/CHANGELOG.md b/sdk/core/core-rest-pipeline/CHANGELOG.md index 076f0b89217f..68ae8bcaac5e 100644 --- a/sdk/core/core-rest-pipeline/CHANGELOG.md +++ b/sdk/core/core-rest-pipeline/CHANGELOG.md @@ -10,6 +10,8 @@ ### Other Changes +- Updates package to work with the react native bundler. Browser APIs such as `URL` will still need to be pollyfilled for this package to run in react native. [PR #17783](https://github.com/Azure/azure-sdk-for-js/pull/17783) + ## 1.3.0 (2021-09-02) ### Bugs Fixed diff --git a/sdk/core/core-rest-pipeline/package.json b/sdk/core/core-rest-pipeline/package.json index 769a30e6eb61..e83a78ecd522 100644 --- a/sdk/core/core-rest-pipeline/package.json +++ b/sdk/core/core-rest-pipeline/package.json @@ -14,6 +14,10 @@ "./dist-esm/src/util/url.js": "./dist-esm/src/util/url.browser.js", "./dist-esm/src/util/userAgentPlatform.js": "./dist-esm/src/util/userAgentPlatform.browser.js" }, + "react-native": { + "./dist/index.js": "./dist-esm/src/index.js", + "./dist-esm/src/util/userAgentPlatform.js": "./dist-esm/src/util/userAgentPlatform.native.js" + }, "types": "core-rest-pipeline.shims.d.ts", "typesVersions": { "<3.6": { diff --git a/sdk/core/core-rest-pipeline/src/util/userAgentPlatform.native.ts b/sdk/core/core-rest-pipeline/src/util/userAgentPlatform.native.ts new file mode 100644 index 000000000000..23fbb519cbbd --- /dev/null +++ b/sdk/core/core-rest-pipeline/src/util/userAgentPlatform.native.ts @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +/* + * NOTE: When moving this file, please update "react-native" section in package.json. + */ + +/** + * @internal + */ +export function getHeaderName(): string { + return "x-ms-useragent"; +} + +/** + * @internal + */ +export function setPlatformSpecificData(map: Map): void { + // TODO: Investigate using `import { Platform } from "react-native"` to get "OS" and "Version". + // This may bring in a lot of overhead if we have to use this package directly, perhaps we can shim + // types. + map.set("OS", `react-native`); +} diff --git a/sdk/core/core-tracing/CHANGELOG.md b/sdk/core/core-tracing/CHANGELOG.md index 763648882303..43a39aa57f24 100644 --- a/sdk/core/core-tracing/CHANGELOG.md +++ b/sdk/core/core-tracing/CHANGELOG.md @@ -13,6 +13,8 @@ ### Other Changes +- Updates package to work with the react native bundler. [PR #17783](https://github.com/Azure/azure-sdk-for-js/pull/17783) + ## 1.0.0-preview.13 (2021-07-15) ### Features Added diff --git a/sdk/core/core-tracing/package.json b/sdk/core/core-tracing/package.json index da6f929ce675..7e00510cfc35 100644 --- a/sdk/core/core-tracing/package.json +++ b/sdk/core/core-tracing/package.json @@ -8,6 +8,9 @@ "browser": { "./dist-esm/src/utils/global.js": "./dist-esm/src/utils/global.browser.js" }, + "react-native": { + "./dist/index.js": "./dist-esm/src/index.js" + }, "types": "types/core-tracing.d.ts", "scripts": { "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", diff --git a/sdk/core/core-util/CHANGELOG.md b/sdk/core/core-util/CHANGELOG.md index e5b7d209778d..08c2ea314e40 100644 --- a/sdk/core/core-util/CHANGELOG.md +++ b/sdk/core/core-util/CHANGELOG.md @@ -2,6 +2,9 @@ ## 1.0.0-beta.2 (Unreleased) +### Other Changes + +- Updates package to work with the react native bundler. [PR #17783](https://github.com/Azure/azure-sdk-for-js/pull/17783) ## 1.0.0-beta.1 (2021-05-06) diff --git a/sdk/core/core-util/package.json b/sdk/core/core-util/package.json index f86c881c4eb0..f625aaf9338f 100644 --- a/sdk/core/core-util/package.json +++ b/sdk/core/core-util/package.json @@ -8,6 +8,9 @@ "browser": { "./dist-esm/src/isNode.js": "./dist-esm/src/isNode.browser.js" }, + "react-native": { + "./dist/index.js": "./dist-esm/src/index.js" + }, "types": "types/latest/core-util.d.ts", "typesVersions": { "<3.6": { diff --git a/sdk/core/logger/CHANGELOG.md b/sdk/core/logger/CHANGELOG.md index 7fb0bdfbdde3..035d2441720a 100644 --- a/sdk/core/logger/CHANGELOG.md +++ b/sdk/core/logger/CHANGELOG.md @@ -2,6 +2,9 @@ ## 1.0.3 (Unreleased) +### Other Changes + +- Updates package to work with the react native bundler. [PR #17783](https://github.com/Azure/azure-sdk-for-js/pull/17783) ## 1.0.2 (2021-03-04) diff --git a/sdk/core/logger/package.json b/sdk/core/logger/package.json index 843fe6aa62c7..61c13e7062f6 100644 --- a/sdk/core/logger/package.json +++ b/sdk/core/logger/package.json @@ -9,6 +9,9 @@ "./dist-esm/src/log.js": "./dist-esm/src/log.browser.js", "process": false }, + "react-native": { + "./dist/index.js": "./dist-esm/src/index.js" + }, "engines": { "node": ">=12.0.0" },