diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7261d4..ea73e5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - bundler: [browserify, webpack] + bundler: [browserify, webpack, "webpack:node"] steps: - name: checkout uses: actions/checkout@master diff --git a/fetch-node.js b/fetch-node.js index 3aa705a..bf88d1f 100644 --- a/fetch-node.js +++ b/fetch-node.js @@ -15,17 +15,20 @@ function wrapFetchForNode(fetch) { } module.exports = function (context) { + // Support webpack module import weirdness. + var fetchFn = fetch.default ? fetch.default : fetch; + // This modifies the global `node-fetch` object, which isn't great, since // different callers to `fetch-ponyfill` which pass a different Promise // implementation would each expect to have their implementation used. But, // given the way `node-fetch` is implemented, this is the only way to make // it work at all. if (context && context.Promise) { - fetch.Promise = context.Promise; + fetchFn.Promise = context.Promise; } return { - fetch: wrapFetchForNode(fetch), + fetch: wrapFetchForNode(fetchFn), Headers: fetch.Headers, Request: fetch.Request, Response: fetch.Response diff --git a/package.json b/package.json index 57e185a..f7aff9f 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ "test:browserify": "testem ci", "pretest:webpack": "npm run build && webpack --mode development tests/fetch-browser.spec.js -o build/browser-test-bundle.js", "test:webpack": "testem ci", + "pretest:webpack:node": "webpack --mode development --target node tests/fetch-node.spec.js -o build/node-test-bundle.js", + "test:webpack:node": "mocha build/node-test-bundle.js", "build": "rimraf build && mkdirp build && node build.js > build/fetch-browser.js", "prepublishOnly": "npm run build" },