@esri/arcgis-rest-fetch 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # `@esri/arcgis-rest-request`
2
+
3
+ This package exists to expose the `node-fetch` package in a consistent way for both Node JS 12.16+ and various bundlers with consistent TypeScript types based on the browser types.
4
+
5
+ This exposes a `getFetch()` method that returns a Promise that resolves with `fetch`, `Headers`, `Request` and `Response`. This is async because it uses `import("node-fetch")` under to hood to load `node-fetch@3.0.0` which is ESM only. The only way to load an ESM module in CommonJS in Node is to use the async `import()`.
6
+
7
+ The `package.json` contains fields for the following:
8
+
9
+ - `main` - `undefined`, Node JS should use the `exports` field and [conditional exports](https://nodejs.org/api/packages.html#packages_conditional_exports).
10
+ - `module` - Exposes a ESM module. Used by Rollup and Parcel v2.
11
+ - `browser` - Exposes a CJS module. Used by Parcel v1 and Browserify.
12
+ - `exports` - exposes [conditional exports](https://nodejs.org/api/packages.html#packages_conditional_exports) config with the following conditions. Used by Webpack and [soon to be others](https://github.com/parcel-bundler/parcel/issues/4155#issuecomment-756457121):
13
+ - `module` - ESM module exposing browser globals.
14
+ - `browser` - CJS module exposing browser globals.
15
+ - `import` - ESM module exposing `node-fetch`.
16
+ - `require` - CJS module exposing `node-fetch`.
17
+ - `default` - ESM module exposing browser globals.
@@ -0,0 +1,8 @@
1
+ module.exports.getFetch = function getFetch() {
2
+ return Promise.resolve({
3
+ fetch: globalThis.fetch,
4
+ Headers: globalThis.Headers,
5
+ Response: globalThis.Response,
6
+ Request: globalThis.request
7
+ });
8
+ };
@@ -0,0 +1,8 @@
1
+ export function getFetch() {
2
+ return Promise.resolve({
3
+ fetch: globalThis.fetch,
4
+ Headers: globalThis.Headers,
5
+ Response: globalThis.Response,
6
+ Request: globalThis.Request
7
+ });
8
+ }
@@ -0,0 +1,8 @@
1
+ declare module "@esri/arcgis-rest-fetch" {
2
+ export function getFetch(): Promise<{
3
+ fetch: typeof fetch;
4
+ Request: typeof Request;
5
+ Response: typeof Response;
6
+ Headers: typeof Headers;
7
+ }>;
8
+ }
@@ -0,0 +1,10 @@
1
+ module.exports.getFetch = function getFetch() {
2
+ return import("node-fetch").then((module) => {
3
+ return {
4
+ fetch: module.default,
5
+ Headers: module.Headers,
6
+ Request: module.Request,
7
+ Response: module.Response,
8
+ };
9
+ });
10
+ };
@@ -0,0 +1,10 @@
1
+ import * as nodeFetch from "node-fetch";
2
+
3
+ export function getFetch() {
4
+ return Promise.resolve({
5
+ fetch: nodeFetch.default,
6
+ Headers: nodeFetch.Headers,
7
+ Response: nodeFetch.Responese,
8
+ Request: nodeFetch.request,
9
+ });
10
+ }
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@esri/arcgis-rest-fetch",
3
+ "version": "4.0.0-beta.1",
4
+ "type": "commonjs",
5
+ "module": "./browser-ponyfill.mjs",
6
+ "browser": "./browser-ponyfill.js",
7
+ "exports": {
8
+ ".": {
9
+ "module": "./browser-ponyfill.mjs",
10
+ "browser": "./browser-ponyfill.js",
11
+ "import": "./node-ponyfill.mjs",
12
+ "require": "./node-ponyfill.js",
13
+ "default": "./browser-ponyfill.mjs"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "types": "index.types.d.ts",
18
+ "dependencies": {
19
+ "node-fetch": "^3.0.0"
20
+ }
21
+ }