Skip to content

Commit

Permalink
feat: add node prefix import for Deno support
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Sep 3, 2024
1 parent 08a6f63 commit 16ca929
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bench/native.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const http = require('http');
const http = require('node:http');

http.createServer((req, res) => {
if (req.url === '/favicon.ico') return;
Expand Down
14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import n from 'eslint-plugin-n'

export default [
{ files: ['**/*.js'] },
{
plugins: { n },
rules: {
'n/prefer-node-protocol': 'error'
}
},
{
ignores: ['examples/']
}
];
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
},
"scripts": {
"build": "bun run scripts/build.ts",
"lint": "eslint",
"test": "uvu -r esm -i util -i bench packages test"
},
"devDependencies": {
"bump": "1.0.0-next.1",
"bundt": "1.1.2",
"eslint": "^9.9.1",
"eslint-plugin-n": "^17.10.2",
"esm": "3.2.25",
"httpie": "1.1.2",
"uvu": "0.5.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/cluster/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cpus } from 'os';
import cluster from 'cluster';
import { createServer } from 'http';
import { cpus } from 'node:os';
import cluster from 'node:cluster';
import { createServer } from 'node:http';

export default function (app, num) {
if (cluster.isMaster) {
Expand Down
2 changes: 1 addition & 1 deletion packages/compression/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// NOTE: supports Node 6.x

import zlib from 'zlib';
import zlib from 'node:zlib';

const NOOP = () => {};
const MIMES = /text|javascript|\/json|xml/i;
Expand Down
6 changes: 3 additions & 3 deletions packages/compression/test/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { suite } from 'uvu';
import * as assert from 'uvu/assert';

import fs from 'fs';
import * as zlib from 'zlib';
import { join } from 'path';
import fs from 'node:fs';
import * as zlib from 'node:zlib';
import { join } from 'node:path';

import { prepare, toAscii } from './util/index';
import compression from '../index';
Expand Down
2 changes: 1 addition & 1 deletion packages/compression/test/util/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IncomingMessage, ServerResponse } from 'http';
import { IncomingMessage, ServerResponse } from 'node:http';

// IncomingMessage
class Request {
Expand Down
2 changes: 1 addition & 1 deletion packages/parse/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decode } from 'querystring';
import { decode } from 'node:querystring';

const noop = x => x;

Expand Down
2 changes: 1 addition & 1 deletion packages/polka/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import http from 'http';
import http from 'node:http';
import { Trouter } from 'trouter';
import { parse } from '@polka/url';

Expand Down
2 changes: 1 addition & 1 deletion packages/polka/test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import http from 'http';
import http from 'node:http';
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { get, send, post } from 'httpie';
Expand Down
2 changes: 1 addition & 1 deletion packages/redirect/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'url';
import { resolve } from 'node:url';

export default function (res, code=302, location='') {
if (!location && typeof code === 'string') {
Expand Down
4 changes: 2 additions & 2 deletions packages/send/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { STATUS_CODES } from 'http';
import { createHash } from 'crypto';
import { STATUS_CODES } from 'node:http';
import { createHash } from 'node:crypto';

const TYPE = 'Content-Type';
const LENGTH = 'Content-Length';
Expand Down
4 changes: 2 additions & 2 deletions packages/send/test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import fs from 'node:fs';
import { join } from 'node:path';
import { suite } from 'uvu';
import { join } from 'path';
import * as assert from 'uvu/assert';
import { Response, toStatusText } from './util';
import send from '../index';
Expand Down
2 changes: 1 addition & 1 deletion packages/send/test/util/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { STATUS_CODES } from 'http';
import { STATUS_CODES } from 'node:http';

export const toStatusText = code => STATUS_CODES[code];

Expand Down
2 changes: 1 addition & 1 deletion packages/url/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as qs from 'querystring';
import * as qs from 'node:querystring';

/**
* @typedef ParsedURL
Expand Down

0 comments on commit 16ca929

Please sign in to comment.