Skip to content

Commit

Permalink
feat: Dual export (#944)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
GrosSacASac authored Jun 28, 2023
1 parent d90b69d commit 009d3f2
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### 3.5.0

* feature: ([#944](https://github.com/node-formidable/formidable/pull/944)) Dual package: Can be imported as ES module and required as commonjs module


### 3.4.0

* feature: ([#940](https://github.com/node-formidable/formidable/pull/940)) form.parse returns a promise if no callback is provided
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ rules, like enabling Two-Factor Auth in your npm and GitHub accounts.

## Install

This package is a dual ESM/commonjs package.

This project requires `Node.js >= 10.13`. Install it using
[yarn](https://yarnpkg.com) or [npm](https://npmjs.com).<br /> _We highly
recommend to use Yarn when you think to contribute to this project._
Expand Down
40 changes: 37 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,51 @@
{
"name": "formidable",
"version": "3.4.0",
"version": "3.5.0",
"license": "MIT",
"description": "A node.js module for parsing form data, especially file uploads.",
"homepage": "https://github.com/node-formidable/formidable",
"funding": "https://ko-fi.com/tunnckoCore/commissions",
"repository": "node-formidable/formidable",
"type": "module",
"main": "./src/index.js",
"main": "./dist/index.cjs",
"exports": {
".": {
"import": {
"default": "./src/index.js"
},
"require": {
"default": "./dist/index.cjs"
},
"default": "./dist/index.cjs"
},
"./src/helpers/*.js": {
"import": {
"default": "./src/helpers/*.js"
},
"require": {
"default": "./dist/helpers/*.cjs"
}
},
"./src/parsers/*.js": {
"import": {
"default": "./src/parsers/*.js"
},
"require": {
"default": "./dist/index.cjs"
}
}
},
"files": [
"src"
"src",
"dist"
],
"publishConfig": {
"access": "public",
"tag": "latest"
},
"scripts": {
"build-package": "rollup --config ./tool/rollup.config.js",
"prepublishOnly": "npm t && npm run clean && npm run build",
"bench": "node benchmark",
"bench2prep": "node benchmark/server.js",
"bench2": "bombardier --body-file=\"./README.md\" --method=POST --duration=10s --connections=100 http://localhost:3000/api/upload",
Expand All @@ -27,6 +57,7 @@
"postreinstall": "yarn setup",
"setup": "yarn",
"pretest": "del-cli ./test/tmp && make-dir ./test/tmp",
"test-specific": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=test/standalone/keep-alive-error.test.js",
"test": "npm run test-jest && npm run test-node",
"test-jest": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=test/ --coverage",
"test-node": "node --test test-node/",
Expand All @@ -41,6 +72,8 @@
"devDependencies": {
"@commitlint/cli": "8.3.5",
"@commitlint/config-conventional": "8.3.4",
"@rollup/plugin-commonjs": "^25.0.2",
"@rollup/plugin-node-resolve": "^15.1.0",
"@sindresorhus/slugify": "^2.1.0",
"@tunnckocore/prettier-config": "1.3.8",
"del-cli": "3.0.0",
Expand All @@ -59,6 +92,7 @@
"nyc": "15.1.0",
"prettier": "2.0.5",
"prettier-plugin-pkgjson": "0.2.8",
"rollup": "^3.25.3",
"supertest": "6.1.6"
},
"jest": {
Expand Down
105 changes: 105 additions & 0 deletions tool/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* eslint-disable */
import cjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import packageJson from '../package.json' assert {type: "json"};;

const {dependencies} = packageJson;
const plugins = [nodeResolve(), cjs()];
const cjsOptions = {
format: `cjs`,
exports: `named`,
}

const external = [...Object.keys(dependencies)];

export default [
{
input: `src/index.js`,
output: [
{
file: `dist/index.cjs`,
...cjsOptions,
},
],
external,
plugins,
},
{
input: `src/helpers/firstValues.js`,
output: [
{
file: `dist/helpers/firstValues.cjs`,
...cjsOptions,
},
],
external,
plugins,
},
{
input: `src/helpers/readBooleans.js`,
output: [
{
file: `dist/helpers/readBooleans.cjs`,
...cjsOptions,
},
],
external,
plugins,
},
{
input: `src/parsers/JSON.js`,
output: [
{
file: `dist/parsers/JSON.cjs`,
...cjsOptions,
},
],
external,
plugins,
},
{
input: `src/parsers/Multipart.js`,
output: [
{
file: `dist/parsers/Multipart.cjs`,
...cjsOptions,
},
],
external,
plugins,
},
{
input: `src/parsers/Querystring.js`,
output: [
{
file: `dist/parsers/Querystring.cjs`,
...cjsOptions,
},
],
external,
plugins,
},
{
input: `src/parsers/OctetStream.js`,
output: [
{
file: `dist/parsers/OctetStream.cjs`,
...cjsOptions,
},
],
external,
plugins,
},
{
input: `src/parsers/StreamingQuerystring.js`,
output: [
{
file: `dist/parsers/StreamingQuerystring.cjs`,
...cjsOptions,
},
],
external,
plugins,
},
];

Loading

0 comments on commit 009d3f2

Please sign in to comment.