Skip to content

Commit b2576c0

Browse files
authored
1 parent 177137c commit b2576c0

18 files changed

Lines changed: 68 additions & 99 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ src/**/*.d.ts
1212
!src/formstream.d.ts
1313
.DS_Store
1414
test/fixtures/ts/*.js
15+
test/fixtures/ts-esm/*.js
1516
.eslintcache
17+
.tshy/

package.json

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,28 @@
1919
"author": "fengmk2 <[email protected]> (https://github.com/fengmk2)",
2020
"homepage": "https://github.com/node-modules/urllib",
2121
"type": "module",
22+
"tshy": {
23+
"exports": {
24+
".": "./src/index.ts",
25+
"./package.json": "./package.json"
26+
}
27+
},
2228
"exports": {
2329
".": {
2430
"import": {
25-
"types": "./src/esm/index.d.ts",
26-
"default": "./src/esm/index.js"
31+
"types": "./dist/esm/index.d.ts",
32+
"default": "./dist/esm/index.js"
2733
},
2834
"require": {
29-
"types": "./src/cjs/index.d.ts",
30-
"default": "./src/cjs/index.js"
35+
"types": "./dist/commonjs/index.d.ts",
36+
"default": "./dist/commonjs/index.js"
3137
}
32-
}
38+
},
39+
"./package.json": "./package.json"
3340
},
34-
"types": "./src/esm/index.d.ts",
35-
"main": "./src/cjs/index.js",
41+
"typings": "./dist/commonjs/index.d.ts",
3642
"files": [
43+
"dist",
3744
"src"
3845
],
3946
"repository": {
@@ -43,24 +50,22 @@
4350
"scripts": {
4451
"lint": "eslint src test --ext .ts --cache",
4552
"prebuild": "npm run clean",
46-
"build": "tsc --version && npm run build:cjs && npm run build:esm && npm run build:version",
47-
"postbuild": "rm -rf src/*.tsbuildinfo",
48-
"build:cjs": "tsc -p ./tsconfig.build.cjs.json",
49-
"build:esm": "tsc -p ./tsconfig.build.esm.json && node ./scripts/esm_import_fix.js",
53+
"build": "tsc --version && tshy && npm run build:version",
54+
"postbuild": "rm -rf *.tsbuildinfo",
5055
"build:version": "node ./scripts/replace_urllib_version.js",
5156
"build:cjs:test": "cd test/cjs && rm -rf node_modules && npm link ../.. && node index.js",
5257
"build:esm:test": "cd test/esm && rm -rf node_modules && npm link ../.. && node index.js",
5358
"build:mts:test": "cd test/mts && rm -rf node_modules && npm link ../.. && tsc",
5459
"build:test": "npm run build && npm run build:cjs:test && npm run build:esm:test && npm run build:mts:test && npm run test-tsc",
55-
"test-tsc": "npm run test-tsc:cjs",
56-
"test-tsc:cjs": "tsc -p ./test/fixtures/ts/tsconfig.json",
57-
"test-tsc:esm": "tsc -p ./test/fixtures/ts-esm/tsconfig.json",
60+
"test-tsc": "npm run test-tsc:cjs && npm run test-tsc:esm",
61+
"test-tsc:cjs": "cd test/fixtures/ts && rm -rf node_modules && npm link ../../.. && npm run build",
62+
"test-tsc:esm": "cd test/fixtures/ts-esm && rm -rf node_modules && npm link ../../.. && npm run build",
5863
"test": "npm run lint && vitest run",
5964
"test-keepalive": "cross-env TEST_KEEPALIVE_COUNT=50 vitest run --test-timeout 180000 keep-alive-header.test.ts",
6065
"cov": "vitest run --coverage",
61-
"ci": "npm run lint && npm run cov && npm run build:test",
66+
"ci": "npm run lint && npm run cov && node scripts/build_test.js",
6267
"contributor": "git-contributor",
63-
"clean": "rm -rf src/*.tsbuildinfo src/cjs/*.ts src/cjs/*.js src/esm/*.ts src/esm/*.js",
68+
"clean": "rm -rf dist",
6469
"prepublishOnly": "npm run build"
6570
},
6671
"dependencies": {
@@ -76,6 +81,8 @@
7681
"ylru": "^1.3.2"
7782
},
7883
"devDependencies": {
84+
"@tsconfig/node18": "^18.2.1",
85+
"@tsconfig/strictest": "^2.0.2",
7986
"@types/busboy": "^1.5.0",
8087
"@types/default-user-agent": "^1.0.0",
8188
"@types/mime-types": "^2.1.1",
@@ -85,8 +92,6 @@
8592
"@types/selfsigned": "^2.0.1",
8693
"@types/tar-stream": "^2.2.2",
8794
"@vitest/coverage-v8": "^0.32.0",
88-
"@tsconfig/node18": "^18.2.1",
89-
"@tsconfig/strictest": "^2.0.2",
9095
"busboy": "^1.6.0",
9196
"cross-env": "^7.0.3",
9297
"eslint": "^8.25.0",
@@ -96,6 +101,7 @@
96101
"proxy": "^1.0.2",
97102
"selfsigned": "^2.0.1",
98103
"tar-stream": "^2.2.0",
104+
"tshy": "^1.0.0-3",
99105
"typescript": "^5.0.4",
100106
"vitest": "^0.32.0"
101107
},

scripts/build_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { execSync } from 'child_process';
2+
3+
function main() {
4+
if (process.version.startsWith('v14.')) {
5+
console.log(`ignore build:test on Node.js ${process.version}`);
6+
return;
7+
}
8+
const cwd = process.cwd()
9+
execSync('npm run build:test', {
10+
cwd,
11+
stdio: [ 'inherit', 'inherit', 'inherit' ],
12+
});
13+
}
14+
15+
main();

scripts/esm_import_fix.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

scripts/replace_urllib_version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ async function main() {
77
const root = process.cwd();
88
const pkg = JSON.parse(await fs.readFile(path.join(root, 'package.json')));
99
const files = [
10-
path.join(root, 'src/cjs/HttpClient.js'),
11-
path.join(root, 'src/esm/HttpClient.js'),
10+
path.join(root, 'dist/commonjs/HttpClient.js'),
11+
path.join(root, 'dist/esm/HttpClient.js'),
1212
];
1313
for (const file of files) {
1414
const content = await fs.readFile(file, 'utf-8');

settings.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/HttpClient.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ import qs from 'qs';
3030
import pump from 'pump';
3131
// Compatible with old style formstream
3232
import FormStream from 'formstream';
33-
import { HttpAgent, CheckAddressFunction } from './HttpAgent';
34-
import { RequestURL, RequestOptions, HttpMethod, RequestMeta } from './Request';
35-
import { RawResponseWithMeta, HttpClientResponse, SocketInfo } from './Response';
36-
import { parseJSON, sleep, digestAuthHeader, globalId, performanceTime, isReadable } from './utils';
37-
import symbols from './symbols';
38-
import { initDiagnosticsChannel } from './diagnosticsChannel';
33+
import { HttpAgent, CheckAddressFunction } from './HttpAgent.js';
34+
import { RequestURL, RequestOptions, HttpMethod, RequestMeta } from './Request.js';
35+
import { RawResponseWithMeta, HttpClientResponse, SocketInfo } from './Response.js';
36+
import { parseJSON, sleep, digestAuthHeader, globalId, performanceTime, isReadable } from './utils.js';
37+
import symbols from './symbols.js';
38+
import { initDiagnosticsChannel } from './diagnosticsChannel.js';
3939

4040
type Exists<T> = T extends undefined ? never : T;
4141
type UndiciRequestOption = Exists<Parameters<typeof undiciRequest>[1]>;

src/Request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { IncomingHttpHeaders } from 'node:http';
33
import type { Dispatcher } from 'undici';
44
import type {
55
HttpClientResponse,
6-
} from './Response';
6+
} from './Response.js';
77

88
export type HttpMethod = Dispatcher.HttpMethod;
99

src/cjs/package.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/diagnosticsChannel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { performance } from 'node:perf_hooks';
33
import { debuglog } from 'node:util';
44
import { Socket } from 'node:net';
55
import { DiagnosticsChannel } from 'undici';
6-
import symbols from './symbols';
7-
import { globalId, performanceTime } from './utils';
6+
import symbols from './symbols.js';
7+
import { globalId, performanceTime } from './utils.js';
88

99
const debug = debuglog('urllib:DiagnosticsChannel');
1010
let initedDiagnosticsChannel = false;

0 commit comments

Comments
 (0)