Skip to content

Commit

Permalink
fix: undici as peerDependency (QwikDev#2548)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat authored Jan 3, 2023
1 parent 473a7ac commit 61400ce
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ body:
id: system-info
attributes:
label: System Info
description: Output of `npx envinfo --system --npmPackages '{vite,@builder.io/*}' --binaries --browsers`
description: Output of `npx envinfo --system --npmPackages '{vite,undici,@builder.io/*}' --binaries --browsers`
render: shell
placeholder: System, Binaries, Browsers
validations:
Expand Down
22 changes: 0 additions & 22 deletions packages/create-qwik/create-interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { getPackageManager } from '../qwik/src/cli/utils/utils';
import { loadIntegrations } from '../qwik/src/cli/utils/integrations';

export async function runCreateInteractiveCli() {
checkNodeVersion();
console.log(``);
console.clear();
console.log(``);
Expand Down Expand Up @@ -141,24 +140,3 @@ export async function runCreateInteractiveCli() {

return result;
}

function checkNodeVersion() {
const version = process.version;
const [majorVersion, minorVersion] = version.replace('v', '').split('.');
if (Number(majorVersion) < 16) {
console.error(
color.red(
`Qwik requires Node.js 16.8 or higher. You are currently running Node.js ${version}.`
)
);
process.exit(1);
} else if (Number(majorVersion) === 16) {
if (Number(minorVersion) < 8) {
console.warn(
color.yellow(
`Node.js 16.8 or higher is recommended. You are currently running Node.js ${version}.`
)
);
}
}
}
24 changes: 24 additions & 0 deletions packages/create-qwik/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { createApp, runCreateCli } from './create-app';
import { panic } from '../qwik/src/cli/utils/utils';
import { runCreateInteractiveCli } from './create-interactive';
import color from 'kleur';

export async function runCli() {
checkNodeVersion();

try {
const args = process.argv.slice(2);

Expand All @@ -18,4 +21,25 @@ export async function runCli() {
}
}

function checkNodeVersion() {
const version = process.version;
const [majorVersion, minorVersion] = version.replace('v', '').split('.');
if (Number(majorVersion) < 16) {
console.error(
color.red(
`Qwik requires Node.js 16.8 or higher. You are currently running Node.js ${version}.`
)
);
process.exit(1);
} else if (Number(majorVersion) === 16) {
if (Number(minorVersion) < 8) {
console.warn(
color.yellow(
`Node.js 16.8 or higher is recommended. You are currently running Node.js ${version}.`
)
);
}
}
}

export { createApp, runCreateCli, runCreateInteractiveCli };
4 changes: 1 addition & 3 deletions packages/qwik-city/middleware/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export async function fromNodeHttp(
res: ServerResponse,
mode: ServerRequestMode
) {
const { Request, Headers } = await import('undici');

const requestHeaders = new Headers();
const nodeRequestHeaders = req.headers;
for (const key in nodeRequestHeaders) {
Expand All @@ -41,7 +39,7 @@ export async function fromNodeHttp(
const serverRequestEv: ServerRequestEvent<boolean> = {
mode,
url,
request: new Request(url.href, {
request: new (Request as any)(url.href, {
method: req.method,
headers: requestHeaders,
body,
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/middleware/node/node-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export async function patchGlobalFetch() {
typeof process !== 'undefined' &&
process.versions.node
) {
const { fetch, Headers, Request, Response, FormData } = await import('undici');
if (!globalThis.fetch) {
const { fetch, Headers, Request, Response, FormData } = await import('undici');
globalThis.fetch = fetch as any;
globalThis.Headers = Headers as any;
globalThis.Request = Request as any;
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@
"Builder.io"
],
"engines": {
"node": ">=16"
"node": ">=16.8.0"
}
}
2 changes: 1 addition & 1 deletion scripts/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function generatePackageJson(config: BuildConfig) {
qwik: './qwik.cjs',
},
type: 'module',
dependencies: {
peerDependencies: {
undici: '^5.14.0',
},
exports: {
Expand Down
2 changes: 1 addition & 1 deletion starters/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ async function patchGlobalFetch() {
typeof process !== 'undefined' &&
process.versions.node
) {
const { fetch, Headers, Request, Response, FormData } = await import('undici');
if (!globalThis.fetch) {
const { fetch, Headers, Request, Response, FormData } = await import('undici');
globalThis.fetch = fetch as any;
globalThis.Headers = Headers as any;
globalThis.Request = Request as any;
Expand Down
2 changes: 1 addition & 1 deletion tsm.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if (
typeof process !== 'undefined' &&
process.versions.node
) {
const { fetch, Headers, Request, Response, FormData } = require('undici');
if (!globalThis.fetch) {
const { fetch, Headers, Request, Response, FormData } = require('undici');
globalThis.fetch = fetch;
globalThis.Headers = Headers;
globalThis.Request = Request;
Expand Down

0 comments on commit 61400ce

Please sign in to comment.