Skip to content

Commit

Permalink
adopt native fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Nov 24, 2022
1 parent bf74562 commit 222bf2f
Show file tree
Hide file tree
Showing 14 changed files with 5 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "cross-env __GWD_ROLLUP_MODE__=strict node . build",
"serve": "node . serve",
"develop": "node . develop",
"test": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict c8 mocha --exclude \"./packages/**/test/cases/exp-*/**\" \"./packages/**/**/*.spec.js\"",
"test": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 c8 mocha --exclude \"./packages/**/test/cases/exp-*/**\" \"./packages/**/**/*.spec.js\"",
"test:exp": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 node --experimental-loader $(pwd)/test/test-loader.js ./node_modules/mocha/bin/mocha \"./packages/**/**/*.spec.js\"",
"test:exp:win": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 node --experimental-loader file:\\\\%cd%\\test\\test-loader.js ./node_modules/mocha/bin/mocha --exclude \"./packages/init/test/cases/**\" \"./packages/**/**/*.spec.js\"",
"test:tdd": "yarn test --watch",
Expand Down
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"koa": "^2.13.0",
"livereload": "^0.9.1",
"markdown-toc": "^1.2.0",
"node-fetch": "^2.6.1",
"node-html-parser": "^1.2.21",
"rehype-raw": "^5.0.0",
"rehype-stringify": "^8.0.0",
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Node ^16.17.0
import path from 'path';
import { readAndMergeConfig as initConfig } from './lifecycles/config.js';
import { URL, fileURLToPath } from 'url';
Expand All @@ -10,12 +9,11 @@ const plugins = config.plugins.filter(plugin => plugin.type === 'resource' && !p
}
}));

// TODO need to polyfill original URL header instead of extensions?
function getCustomLoaderPlugins(url, body, headers) {
return plugins.filter(plugin => plugin.extensions.includes(path.extname(url)) && (plugin.shouldServe(url, body, headers) || plugin.shouldIntercept(url, body, headers)));
}

// https://nodejs.org/docs/latest-v16.x/api/esm.html#resolvespecifier-context-nextresolve
// https://nodejs.org/docs/latest-v18.x/api/esm.html#resolvespecifier-context-nextresolve
export function resolve(specifier, context, defaultResolve) {
const { baseURL } = context;

Expand All @@ -29,7 +27,7 @@ export function resolve(specifier, context, defaultResolve) {
return defaultResolve(specifier, context, defaultResolve);
}

// https://nodejs.org/docs/latest-v16.x/api/esm.html#loadurl-context-nextload
// https://nodejs.org/docs/latest-v18.x/api/esm.html#loadurl-context-nextload
export async function load(source, context, defaultLoad) {
const resourcePlugins = getCustomLoaderPlugins(source);
const extension = path.extname(source).replace('.', '');
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/plugins/resource/plugin-dev-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Manages routing devServer.proxy entries to their destination.
*
*/
import fetch from 'node-fetch';
import { ResourceInterface } from '../../lib/resource-interface.js';

class DevProxyResource extends ResourceInterface {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fetch from 'node-fetch';

async function getTemplate(compilation, route) {
return `
<html>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fetch from 'node-fetch';

async function getTemplate(compilation, route) {
return `
<html>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import '../components/card.js';

export default class UsersPage extends HTMLElement {
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/test/cases/develop.ssr/src/pages/artists.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fetch from 'node-fetch';

async function getTemplate(compilation, route) {
return `
<html>
Expand Down
1 change: 0 additions & 1 deletion packages/init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"chalk": "^4.1.2",
"commander": "^8.2.0",
"inquirer": "^8.2.0",
"node-fetch": "^2.6.7",
"simple-git": "^2.48.0"
}
}
1 change: 0 additions & 1 deletion packages/init/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import chalk from 'chalk';
import simpleGit from 'simple-git';
import commander from 'commander';
import { copyFolder } from './copy-folder.js';
import fetch from 'node-fetch';
import fs from 'fs';
import inquirer from 'inquirer';
import os from 'os';
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"@rollup/plugin-alias": "^3.1.2",
"apollo-server": "^2.21.0",
"graphql": "^15.5.0",
"graphql-tag": "^2.10.1",
"node-fetch": "^2.6.1"
"graphql-tag": "^2.10.1"
},
"devDependencies": {
"@greenwood/cli": "^0.27.0"
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-graphql/src/core/cache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ApolloCore from '@apollo/client/core/core.cjs.js';
import fetch from 'node-fetch';
import fs from 'fs';
import { gql } from 'apollo-server';
import { getQueryHash } from './common.js';
Expand Down
1 change: 0 additions & 1 deletion www/pages/docs/server-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export {
When using `export default`, Greenwood supports providing a custom element as the export for your page content. It uses [**WCC**](https://github.com/ProjectEvergreen/wcc) by default which also includes support for rendering [Declarative Shadow DOM](https://web.dev/declarative-shadow-dom/).

```js
import fetch from 'node-fetch';
import '../components/card/card.js'; // <wc-card></wc-card>

export default class UsersPage extends HTMLElement {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8192,7 +8192,7 @@ node-fetch-npm@^2.0.2:
json-parse-better-errors "^1.0.0"
safe-buffer "^5.1.1"

[email protected], node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.7:
[email protected], node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
Expand Down

0 comments on commit 222bf2f

Please sign in to comment.