Skip to content

Commit 009d3f2

Browse files
authored
feat: Dual export (#944)
* feat: add rollup export dual package * test: command to run a specific test * feat: export more, make it work without having to write const formidable = require('formidable/index.cjs'); * doc: changelog and version * doc: add note to readme
1 parent d90b69d commit 009d3f2

File tree

5 files changed

+293
-5
lines changed

5 files changed

+293
-5
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### 3.5.0
4+
5+
* feature: ([#944](https://github.com/node-formidable/formidable/pull/944)) Dual package: Can be imported as ES module and required as commonjs module
6+
7+
38
### 3.4.0
49

510
* feature: ([#940](https://github.com/node-formidable/formidable/pull/940)) form.parse returns a promise if no callback is provided

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ rules, like enabling Two-Factor Auth in your npm and GitHub accounts.
6868

6969
## Install
7070

71+
This package is a dual ESM/commonjs package.
72+
7173
This project requires `Node.js >= 10.13`. Install it using
7274
[yarn](https://yarnpkg.com) or [npm](https://npmjs.com).<br /> _We highly
7375
recommend to use Yarn when you think to contribute to this project._

package.json

+37-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
11
{
22
"name": "formidable",
3-
"version": "3.4.0",
3+
"version": "3.5.0",
44
"license": "MIT",
55
"description": "A node.js module for parsing form data, especially file uploads.",
66
"homepage": "https://github.com/node-formidable/formidable",
77
"funding": "https://ko-fi.com/tunnckoCore/commissions",
88
"repository": "node-formidable/formidable",
99
"type": "module",
10-
"main": "./src/index.js",
10+
"main": "./dist/index.cjs",
11+
"exports": {
12+
".": {
13+
"import": {
14+
"default": "./src/index.js"
15+
},
16+
"require": {
17+
"default": "./dist/index.cjs"
18+
},
19+
"default": "./dist/index.cjs"
20+
},
21+
"./src/helpers/*.js": {
22+
"import": {
23+
"default": "./src/helpers/*.js"
24+
},
25+
"require": {
26+
"default": "./dist/helpers/*.cjs"
27+
}
28+
},
29+
"./src/parsers/*.js": {
30+
"import": {
31+
"default": "./src/parsers/*.js"
32+
},
33+
"require": {
34+
"default": "./dist/index.cjs"
35+
}
36+
}
37+
},
1138
"files": [
12-
"src"
39+
"src",
40+
"dist"
1341
],
1442
"publishConfig": {
1543
"access": "public",
1644
"tag": "latest"
1745
},
1846
"scripts": {
47+
"build-package": "rollup --config ./tool/rollup.config.js",
48+
"prepublishOnly": "npm t && npm run clean && npm run build",
1949
"bench": "node benchmark",
2050
"bench2prep": "node benchmark/server.js",
2151
"bench2": "bombardier --body-file=\"./README.md\" --method=POST --duration=10s --connections=100 http://localhost:3000/api/upload",
@@ -27,6 +57,7 @@
2757
"postreinstall": "yarn setup",
2858
"setup": "yarn",
2959
"pretest": "del-cli ./test/tmp && make-dir ./test/tmp",
60+
"test-specific": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=test/standalone/keep-alive-error.test.js",
3061
"test": "npm run test-jest && npm run test-node",
3162
"test-jest": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=test/ --coverage",
3263
"test-node": "node --test test-node/",
@@ -41,6 +72,8 @@
4172
"devDependencies": {
4273
"@commitlint/cli": "8.3.5",
4374
"@commitlint/config-conventional": "8.3.4",
75+
"@rollup/plugin-commonjs": "^25.0.2",
76+
"@rollup/plugin-node-resolve": "^15.1.0",
4477
"@sindresorhus/slugify": "^2.1.0",
4578
"@tunnckocore/prettier-config": "1.3.8",
4679
"del-cli": "3.0.0",
@@ -59,6 +92,7 @@
5992
"nyc": "15.1.0",
6093
"prettier": "2.0.5",
6194
"prettier-plugin-pkgjson": "0.2.8",
95+
"rollup": "^3.25.3",
6296
"supertest": "6.1.6"
6397
},
6498
"jest": {

tool/rollup.config.js

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/* eslint-disable */
2+
import cjs from '@rollup/plugin-commonjs';
3+
import { nodeResolve } from '@rollup/plugin-node-resolve';
4+
import packageJson from '../package.json' assert {type: "json"};;
5+
6+
const {dependencies} = packageJson;
7+
const plugins = [nodeResolve(), cjs()];
8+
const cjsOptions = {
9+
format: `cjs`,
10+
exports: `named`,
11+
}
12+
13+
const external = [...Object.keys(dependencies)];
14+
15+
export default [
16+
{
17+
input: `src/index.js`,
18+
output: [
19+
{
20+
file: `dist/index.cjs`,
21+
...cjsOptions,
22+
},
23+
],
24+
external,
25+
plugins,
26+
},
27+
{
28+
input: `src/helpers/firstValues.js`,
29+
output: [
30+
{
31+
file: `dist/helpers/firstValues.cjs`,
32+
...cjsOptions,
33+
},
34+
],
35+
external,
36+
plugins,
37+
},
38+
{
39+
input: `src/helpers/readBooleans.js`,
40+
output: [
41+
{
42+
file: `dist/helpers/readBooleans.cjs`,
43+
...cjsOptions,
44+
},
45+
],
46+
external,
47+
plugins,
48+
},
49+
{
50+
input: `src/parsers/JSON.js`,
51+
output: [
52+
{
53+
file: `dist/parsers/JSON.cjs`,
54+
...cjsOptions,
55+
},
56+
],
57+
external,
58+
plugins,
59+
},
60+
{
61+
input: `src/parsers/Multipart.js`,
62+
output: [
63+
{
64+
file: `dist/parsers/Multipart.cjs`,
65+
...cjsOptions,
66+
},
67+
],
68+
external,
69+
plugins,
70+
},
71+
{
72+
input: `src/parsers/Querystring.js`,
73+
output: [
74+
{
75+
file: `dist/parsers/Querystring.cjs`,
76+
...cjsOptions,
77+
},
78+
],
79+
external,
80+
plugins,
81+
},
82+
{
83+
input: `src/parsers/OctetStream.js`,
84+
output: [
85+
{
86+
file: `dist/parsers/OctetStream.cjs`,
87+
...cjsOptions,
88+
},
89+
],
90+
external,
91+
plugins,
92+
},
93+
{
94+
input: `src/parsers/StreamingQuerystring.js`,
95+
output: [
96+
{
97+
file: `dist/parsers/StreamingQuerystring.cjs`,
98+
...cjsOptions,
99+
},
100+
],
101+
external,
102+
plugins,
103+
},
104+
];
105+

0 commit comments

Comments
 (0)