Skip to content

Commit

Permalink
Unblock react native support when using corev2 packages (#17783)
Browse files Browse the repository at this point in the history
~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.
  • Loading branch information
chradek authored Sep 29, 2021
1 parent 5d9f840 commit fd3faee
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sdk/core/core-client-paging-rest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions sdk/core/core-client-paging-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/core-client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-crypto/src/sha256.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function computeSha256Hash(
encoding: "base64" | "hex"
): Promise<string> {
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":
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/core-lro/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-lro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/core-rest-pipeline/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions sdk/core/core-rest-pipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
23 changes: 23 additions & 0 deletions sdk/core/core-rest-pipeline/src/util/userAgentPlatform.native.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>): 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`);
}
2 changes: 2 additions & 0 deletions sdk/core/core-tracing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-tracing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-util/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/logger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions sdk/core/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit fd3faee

Please sign in to comment.