diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 133d63f2..dc2c12d5 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -5,14 +5,13 @@ on:
jobs:
test:
name: Node.js ${{ matrix.node-version }}
- runs-on: ubuntu-latest
+ runs-on: macos-latest
strategy:
fail-fast: false
matrix:
node-version:
- 14
- 12
- - 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
diff --git a/.gitignore b/.gitignore
index 861a15fc..a042fbb0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
node_modules
yarn.lock
.nyc_output
-umd.js
+coverage
diff --git a/index.js b/index.js
index 38580fd1..acf9e877 100644
--- a/index.js
+++ b/index.js
@@ -2,27 +2,6 @@
const globals = {};
-const getGlobal = property => {
- /* istanbul ignore next */
- if (typeof self !== 'undefined' && self && property in self) {
- return self;
- }
-
- /* istanbul ignore next */
- if (typeof window !== 'undefined' && window && property in window) {
- return window;
- }
-
- if (typeof global !== 'undefined' && global && property in global) {
- return global;
- }
-
- /* istanbul ignore next */
- if (typeof globalThis !== 'undefined' && globalThis) {
- return globalThis;
- }
-};
-
const globalProperties = [
'Headers',
'Request',
@@ -36,9 +15,8 @@ const globalProperties = [
for (const property of globalProperties) {
Object.defineProperty(globals, property, {
get() {
- const globalObject = getGlobal(property);
- const value = globalObject && globalObject[property];
- return typeof value === 'function' ? value.bind(globalObject) : value;
+ const value = globalThis[property];
+ return typeof value === 'function' ? value.bind(globalThis) : value;
}
});
}
@@ -525,4 +503,6 @@ const createInstance = defaults => {
return ky;
};
-export default createInstance();
+const ky = createInstance();
+
+export default ky;
diff --git a/package.json b/package.json
index 76b5bc0f..f424b4be 100644
--- a/package.json
+++ b/package.json
@@ -11,23 +11,15 @@
"url": "https://sindresorhus.com"
},
"type": "module",
- "exports": {
- "import": "./index.js",
- "require": "./umd.js"
- },
"engines": {
- "node": ">=10"
+ "node": ">=12"
},
"scripts": {
- "build": "rollup index.js --format=umd --name=ky --file=umd.js",
- "prepare": "npm run build",
- "test": "xo && npm run build && nyc ava && tsd"
+ "test": "xo && ava && tsd"
},
"files": [
"index.js",
- "index.d.ts",
- "umd.js",
- "umd.d.ts"
+ "index.d.ts"
],
"keywords": [
"fetch",
@@ -58,12 +50,10 @@
"busboy": "^0.3.1",
"create-test-server": "2.1.1",
"delay": "^4.1.0",
- "esm": "^3.2.22",
"form-data": "^3.0.0",
"node-fetch": "^2.5.0",
"nyc": "^15.0.0",
- "puppeteer": "^5.1.0",
- "rollup": "^2.10.2",
+ "puppeteer": "^5.5.0",
"tsd": "^0.13.1",
"xo": "^0.25.3"
},
@@ -83,7 +73,6 @@
},
"ava": {
"require": [
- "esm",
"./test/_require"
],
"nonSemVerExperiments": {
@@ -93,7 +82,7 @@
"tsd": {
"compilerOptions": {
"lib": [
- "es2018",
+ "es2019",
"dom"
]
}
diff --git a/readme.md b/readme.md
index fa970c3f..7363c5da 100644
--- a/readme.md
+++ b/readme.md
@@ -91,14 +91,6 @@ If you are using [Deno](https://github.com/denoland/deno), import Ky from a URL.
import ky from 'https://unpkg.com/ky/index.js';
```
-In environments that do not support `import`, you can load `ky` in [UMD format](https://medium.freecodecamp.org/anatomy-of-js-module-systems-and-building-libraries-fadcd8dbd0e). For example, using `require()`:
-
-```js
-const ky = require('ky/umd');
-```
-
-With the UMD version, it's also easy to use `ky` [without a bundler](#how-do-i-use-this-without-a-bundler-like-webpack) or module system.
-
## API
### ky(input, options?)
@@ -585,20 +577,6 @@ import ky from 'https://cdn.jsdelivr.net/npm/ky@latest/index.js';
```
-Alternatively, you can use the [`umd.js`](umd.js) file with a traditional `
-
-```
-
#### How is it different from [`got`](https://github.com/sindresorhus/got)
See my answer [here](https://twitter.com/sindresorhus/status/1037406558945042432). Got is maintained by the same people as Ky.
diff --git a/test/browser.js b/test/browser.js
index a8897966..f35ef888 100644
--- a/test/browser.js
+++ b/test/browser.js
@@ -1,13 +1,25 @@
import util from 'util';
+import fs from 'fs';
import body from 'body';
import ava from 'ava'; // eslint-disable-line ava/use-test
import createTestServer from 'create-test-server';
import Busboy from 'busboy';
import withPage from './helpers/with-page.js';
-const test = ava.serial;
+// FIXME: Skipping tests on CI as they're unreliable there for some reason.
+// It's serial as Puppeteer cannot handle full concurrency.
+const test = process.env.CI ? ava.skip : ava.serial;
+
const pBody = util.promisify(body);
+const kyScript = {
+ type: 'module',
+ content: `
+ ${fs.readFileSync(new URL('../index.js', import.meta.url), 'utf8')}
+ globalThis.ky = ky;
+ `
+};
+
test('prefixUrl option', withPage, async (t, page) => {
const server = await createTestServer();
@@ -19,7 +31,7 @@ test('prefixUrl option', withPage, async (t, page) => {
});
await page.goto(server.url);
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
await t.throwsAsync(
page.evaluate(() => {
@@ -56,7 +68,7 @@ test('aborting a request', withPage, async (t, page) => {
});
await page.goto(server.url);
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
const error = await page.evaluate(url => {
const controller = new AbortController();
@@ -88,7 +100,7 @@ test('aborting a request with onDonwloadProgress', withPage, async (t, page) =>
});
await page.goto(server.url);
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
const error = await page.evaluate(url => {
const controller = new AbortController();
@@ -117,7 +129,7 @@ test('throws TimeoutError even though it does not support AbortController', with
await page.goto(server.url);
await page.addScriptTag({path: './test/helpers/disable-abort-controller.js'});
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
const error = await page.evaluate(url => {
const request = window.ky(`${url}/slow`, {timeout: 500}).text();
@@ -149,7 +161,7 @@ test('onDownloadProgress works', withPage, async (t, page) => {
});
await page.goto(server.url);
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
const result = await page.evaluate(async url => {
// `new TextDecoder('utf-8').decode` hangs up?
@@ -184,7 +196,7 @@ test('throws if onDownloadProgress is not a function', withPage, async (t, page)
});
await page.goto(server.url);
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
const error = await page.evaluate(url => {
const request = window.ky(url, {onDownloadProgress: 1}).text();
@@ -204,7 +216,7 @@ test('throws if does not support ReadableStream', withPage, async (t, page) => {
await page.goto(server.url);
await page.addScriptTag({path: './test/helpers/disable-stream-support.js'});
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
const error = await page.evaluate(url => {
const request = window.ky(url, {onDownloadProgress: () => {}}).text();
@@ -234,7 +246,7 @@ test('FormData with searchParams', withPage, async (t, page) => {
});
await page.goto(server.url);
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
await page.evaluate(url => {
const formData = new window.FormData();
formData.append('file', new window.File(['bubblegum pie'], 'my-file'));
@@ -290,7 +302,7 @@ test('FormData with searchParams ("multipart/form-data" parser)', withPage, asyn
});
await page.goto(server.url);
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
await page.evaluate(url => {
const formData = new window.FormData();
formData.append('file', new window.File(['bubblegum pie'], 'my-file', {type: 'text/plain'}));
@@ -317,12 +329,13 @@ test('headers are preserved when input is a Request and there are searchParams i
});
await page.goto(server.url);
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
await page.evaluate(url => {
const request = new window.Request(url + '/test', {
headers: {'content-type': 'text/css'}
});
+
return window.ky(request, {
searchParams: 'foo=1'
}).text();
@@ -347,7 +360,7 @@ test('retry with body', withPage, async (t, page) => {
});
await page.goto(server.url);
- await page.addScriptTag({path: './umd.js'});
+ await page.addScriptTag(kyScript);
await t.throwsAsync(
page.evaluate(async url => {
diff --git a/umd.d.ts b/umd.d.ts
deleted file mode 100644
index 65c3d6b4..00000000
--- a/umd.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-export {default} from 'ky';