Skip to content

Commit

Permalink
Revert "[core-rest-pipeline] Add conditional exports (#22804)" (#23699)
Browse files Browse the repository at this point in the history
This reverts commit 02f6ad6.


### Packages impacted by this PR
`@azure/core-rest-pipeline`

### Describe the problem that is addressed by this PR
Making core-rest-pipeline ESM with conditional exports broke notification-hubs.  Reverting the change while investigating.
  • Loading branch information
jeremymeng authored and mpodwysocki committed Nov 3, 2022
1 parent 8b0b97b commit 237be34
Show file tree
Hide file tree
Showing 72 changed files with 718 additions and 850 deletions.
1,009 changes: 487 additions & 522 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions common/tools/dev-tool/src/commands/run/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,9 @@ export default leafCommand(commandInfo, async (options) => {

try {
const bundle = await rollup.rollup(baseConfig);
const cjsFilename = info.packageJson.main;
if (!cjsFilename) {
throw new Error("Expecting valid main entry");
}

await bundle.write({
file: cjsFilename,
file: "dist/index.js",
format: "cjs",
sourcemap: true,
exports: "named",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ts-package-json-main-is-cjs

Requires `main` in `package.json` to be point to a CommonJS or UMD module. In this case, its assumed that it points to `"dist/index.js"` or `"dist/index.cjs"`.
Requires `main` in `package.json` to be point to a CommonJS or UMD module. In this case, its assumed that it points to `"dist/index.js"`.

This rule is fixable using the `--fix` option.

Expand All @@ -14,14 +14,6 @@ This rule is fixable using the `--fix` option.
}
```

### Good

```json
{
"main": "dist/index.cjs"
}
```

### Bad

```json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export = {
const nodeValue = node.value as Literal;
const main = nodeValue.value as string;

if (!/^(\.\/)?dist\/index\.(c)?js$/.test(main)) {
if (!/^(\.\/)?dist\/index\.js$/.test(main)) {
context.report({
node: nodeValue,
message: `main is set to ${main} when it should be set to dist/index.js or dist/index.cjs`,
message: `main is set to ${main} when it should be set to dist/index.js`,
fix: (fixer: Rule.RuleFixer): Rule.Fix =>
fixer.replaceText(nodeValue, `"dist/index.js"`),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,6 @@ ruleTester.run("ts-package-json-main-is-cjs", rule, {
code: '{"main": "./dist/index.js"}',
filename: "package.json",
},
{
// correct format #1
code: '{"main": "dist/index.cjs"}',
filename: "package.json",
},
{
// correct format #2
code: '{"main": "./dist/index.cjs"}',
filename: "package.json",
},
{
// a full example package.json (taken from https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/eventhub/event-hubs/package.json with "scripts" removed for testing purposes)
code: examplePackageGood,
Expand Down Expand Up @@ -310,8 +300,7 @@ ruleTester.run("ts-package-json-main-is-cjs", rule, {
filename: "package.json",
errors: [
{
message:
"main is set to dist//index.js when it should be set to dist/index.js or dist/index.cjs",
message: "main is set to dist//index.js when it should be set to dist/index.js",
},
],
output: '{"main": "dist/index.js"}',
Expand All @@ -321,8 +310,7 @@ ruleTester.run("ts-package-json-main-is-cjs", rule, {
filename: "package.json",
errors: [
{
message:
"main is set to .dist/index.js when it should be set to dist/index.js or dist/index.cjs",
message: "main is set to .dist/index.js when it should be set to dist/index.js",
},
],
output: '{"main": "dist/index.js"}',
Expand All @@ -332,8 +320,7 @@ ruleTester.run("ts-package-json-main-is-cjs", rule, {
filename: "package.json",
errors: [
{
message:
"main is set to /dist/index.js when it should be set to dist/index.js or dist/index.cjs",
message: "main is set to /dist/index.js when it should be set to dist/index.js",
},
],
output: '{"main": "dist/index.js"}',
Expand All @@ -344,7 +331,7 @@ ruleTester.run("ts-package-json-main-is-cjs", rule, {
filename: "package.json",
errors: [
{
message: "main is set to dist when it should be set to dist/index.js or dist/index.cjs",
message: "main is set to dist when it should be set to dist/index.js",
},
],
output: '{"main": "dist/index.js"}',
Expand All @@ -354,8 +341,7 @@ ruleTester.run("ts-package-json-main-is-cjs", rule, {
filename: "package.json",
errors: [
{
message:
"main is set to index.js when it should be set to dist/index.js or dist/index.cjs",
message: "main is set to index.js when it should be set to dist/index.js",
},
],
output: '{"main": "dist/index.js"}',
Expand All @@ -365,8 +351,7 @@ ruleTester.run("ts-package-json-main-is-cjs", rule, {
filename: "package.json",
errors: [
{
message:
"main is set to dist/src/index.js when it should be set to dist/index.js or dist/index.cjs",
message: "main is set to dist/src/index.js when it should be set to dist/index.js",
},
],
output: '{"main": "dist/index.js"}',
Expand All @@ -377,8 +362,7 @@ ruleTester.run("ts-package-json-main-is-cjs", rule, {
filename: "package.json",
errors: [
{
message:
"main is set to index.js when it should be set to dist/index.js or dist/index.cjs",
message: "main is set to index.js when it should be set to dist/index.js",
},
],
output: examplePackageGood,
Expand Down
4 changes: 1 addition & 3 deletions sdk/core/core-rest-pipeline/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Release History

## 1.10.0 (Unreleased)
## 1.9.3 (Unreleased)

### Features Added

- Added conditional exports for CommonJS and ESM. [#22804](https://github.com/Azure/azure-sdk-for-js/pull/22804)

### Breaking Changes

### Bugs Fixed
Expand Down
12 changes: 0 additions & 12 deletions sdk/core/core-rest-pipeline/core-rest-pipeline.d.cts

This file was deleted.

12 changes: 0 additions & 12 deletions sdk/core/core-rest-pipeline/core-rest-pipeline.shims-3_1.d.cts

This file was deleted.

File renamed without changes.
36 changes: 7 additions & 29 deletions sdk/core/core-rest-pipeline/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
{
"name": "@azure/core-rest-pipeline",
"version": "1.10.0",
"version": "1.9.3",
"description": "Isomorphic client library for making HTTP requests in node.js and browser.",
"sdk-type": "client",
"main": "dist/index.cjs",
"main": "dist/index.js",
"module": "dist-esm/src/index.js",
"type": "module",
"export": {
".": {
"require": {
"types": "core-rest-pipeline.shims.d.ts",
"default": "./dist/index.cjs"
},
"import": {
"types": "core-rest-pipeline.shims.d.cts",
"default": "./dist-esm/src/index.js"
}
}
},
"browser": {
"./dist-esm/src/defaultHttpClient.js": "./dist-esm/src/defaultHttpClient.browser.js",
"./dist-esm/src/policies/decompressResponsePolicy.js": "./dist-esm/src/policies/decompressResponsePolicy.browser.js",
Expand All @@ -27,7 +14,7 @@
"./dist-esm/src/util/userAgentPlatform.js": "./dist-esm/src/util/userAgentPlatform.browser.js"
},
"react-native": {
"./dist/index.cjs": "./dist-esm/src/index.js",
"./dist/index.js": "./dist-esm/src/index.js",
"./dist-esm/src/defaultHttpClient.js": "./dist-esm/src/defaultHttpClient.native.js",
"./dist-esm/src/util/userAgentPlatform.js": "./dist-esm/src/util/userAgentPlatform.native.js"
},
Expand All @@ -36,9 +23,6 @@
"<3.6": {
"core-rest-pipeline.shims.d.ts": [
"core-rest-pipeline.shims-3_1.d.ts"
],
"core-rest-pipeline.shims.d.cts": [
"core-rest-pipeline.shims-3_1.d.cts"
]
}
},
Expand All @@ -62,16 +46,14 @@
"test:browser": "npm run clean && npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
"test:node": "npm run clean && tsc -p . && npm run unit-test:node && npm run integration-test:node",
"test": "npm run clean && tsc -p . && npm run unit-test:node && dev-tool run bundle && npm run unit-test:browser && npm run integration-test",
"unit-test:browser": "karma start karma.conf.cjs --single-run",
"unit-test:node": "mocha --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace --exclude \"test/**/browser/*.spec.ts\" \"test/**/*.spec.ts\"",
"unit-test:browser": "karma start --single-run",
"unit-test:node": "mocha -r esm -r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace --exclude \"test/**/browser/*.spec.ts\" \"test/**/*.spec.ts\"",
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
},
"files": [
"dist/",
"dist-esm/src/",
"types/3.1/src/",
"types/3.1/core-rest-pipeline.d.ts",
"types/latest/src/",
"types/latest/core-rest-pipeline.d.ts",
"core-rest-pipeline.shims.d.ts",
"core-rest-pipeline.shims-3_1.d.ts",
Expand Down Expand Up @@ -143,19 +125,15 @@
"karma-sourcemap-loader": "^0.3.8",
"karma": "^6.3.0",
"mocha-junit-reporter": "^2.0.0",
"mocha": "^10.0.0",
"mocha": "^7.1.1",
"prettier": "^2.5.1",
"puppeteer": "^14.0.0",
"rimraf": "^3.0.0",
"sinon": "^9.0.2",
"source-map-support": "^0.5.9",
"ts-node": "^10.0.0",
"typescript": "~4.7.0",
"typescript": "~4.6.0",
"util": "^0.12.1"
},
"mocha": {
"loader": "ts-node/esm"
},
"//sampleConfiguration": {
"skipFolder": true,
"disableDocsMs": true,
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-rest-pipeline/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export const SDK_VERSION: string = "1.10.0";
export const SDK_VERSION: string = "1.9.3";

export const DEFAULT_RETRY_POLICY_COUNT = 3;
26 changes: 13 additions & 13 deletions sdk/core/core-rest-pipeline/src/createPipelineFromOptions.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { LogPolicyOptions, logPolicy } from "./policies/logPolicy.js";
import { Pipeline, createEmptyPipeline } from "./pipeline.js";
import { PipelineRetryOptions, TlsSettings } from "./interfaces.js";
import { RedirectPolicyOptions, redirectPolicy } from "./policies/redirectPolicy.js";
import { UserAgentPolicyOptions, userAgentPolicy } from "./policies/userAgentPolicy.js";
import { LogPolicyOptions, logPolicy } from "./policies/logPolicy";
import { Pipeline, createEmptyPipeline } from "./pipeline";
import { PipelineRetryOptions, TlsSettings } from "./interfaces";
import { RedirectPolicyOptions, redirectPolicy } from "./policies/redirectPolicy";
import { UserAgentPolicyOptions, userAgentPolicy } from "./policies/userAgentPolicy";

import { ProxySettings } from "./interfaces.js";
import { decompressResponsePolicy } from "./policies/decompressResponsePolicy.js";
import { defaultRetryPolicy } from "./policies/defaultRetryPolicy.js";
import { formDataPolicy } from "./policies/formDataPolicy.js";
import { ProxySettings } from ".";
import { decompressResponsePolicy } from "./policies/decompressResponsePolicy";
import { defaultRetryPolicy } from "./policies/defaultRetryPolicy";
import { formDataPolicy } from "./policies/formDataPolicy";
import { isNode } from "@azure/core-util";
import { proxyPolicy } from "./policies/proxyPolicy.js";
import { setClientRequestIdPolicy } from "./policies/setClientRequestIdPolicy.js";
import { tlsPolicy } from "./policies/tlsPolicy.js";
import { tracingPolicy } from "./policies/tracingPolicy.js";
import { proxyPolicy } from "./policies/proxyPolicy";
import { setClientRequestIdPolicy } from "./policies/setClientRequestIdPolicy";
import { tlsPolicy } from "./policies/tlsPolicy";
import { tracingPolicy } from "./policies/tracingPolicy";

/**
* Defines options that are used to configure the HTTP pipeline for
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/core-rest-pipeline/src/defaultHttpClient.browser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { HttpClient } from "./interfaces.js";
import { createFetchHttpClient } from "./fetchHttpClient.js";
import { HttpClient } from "./interfaces";
import { createFetchHttpClient } from "./fetchHttpClient";

/**
* Create the correct HttpClient for the current environment.
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/core-rest-pipeline/src/defaultHttpClient.native.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { HttpClient } from "./interfaces.js";
import { createXhrHttpClient } from "./xhrHttpClient.js";
import { HttpClient } from "./interfaces";
import { createXhrHttpClient } from "./xhrHttpClient";

/**
* Create the correct HttpClient for the current environment.
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/core-rest-pipeline/src/defaultHttpClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { HttpClient } from "./interfaces.js";
import { createNodeHttpClient } from "./nodeHttpClient.js";
import { HttpClient } from "./interfaces";
import { createNodeHttpClient } from "./nodeHttpClient";

/**
* Create the correct HttpClient for the current environment.
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/core-rest-pipeline/src/fetchHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
PipelineRequest,
PipelineResponse,
TransferProgressEvent,
} from "./interfaces.js";
import { RestError } from "./restError.js";
import { createHttpHeaders } from "./httpHeaders.js";
} from "./interfaces";
import { RestError } from "./restError";
import { createHttpHeaders } from "./httpHeaders";

/**
* Checks if the body is a NodeReadable stream which is not supported in Browsers
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-rest-pipeline/src/httpHeaders.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { HttpHeaders, RawHttpHeaders, RawHttpHeadersInput } from "./interfaces.js";
import { HttpHeaders, RawHttpHeaders, RawHttpHeadersInput } from "./interfaces";

interface HeaderEntry {
name: string;
Expand Down
Loading

0 comments on commit 237be34

Please sign in to comment.