-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #721 from aryaemami59/fix-treeshakeability
- Loading branch information
Showing
8 changed files
with
1,377 additions
and
1,375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,15 @@ | |
"name": "reselect", | ||
"version": "5.1.1", | ||
"description": "Selectors for Redux.", | ||
"main": "./dist/cjs/reselect.cjs", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/reselect.legacy-esm.js", | ||
"types": "./dist/reselect.d.ts", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"types": "./dist/reselect.d.ts", | ||
"import": "./dist/reselect.mjs", | ||
"default": "./dist/cjs/reselect.cjs" | ||
"default": "./dist/cjs/index.js" | ||
} | ||
}, | ||
"files": [ | ||
|
@@ -22,7 +22,7 @@ | |
"url": "https://github.com/reduxjs/reselect/issues" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"build": "yarn clean && tsup", | ||
"clean": "rimraf dist", | ||
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" \"docs/**/*.md\"", | ||
"lint": "eslint src test", | ||
|
@@ -80,9 +80,12 @@ | |
"react-redux": "^9.0.4", | ||
"rimraf": "^3.0.2", | ||
"shelljs": "^0.8.5", | ||
"tsup": "^6.7.0", | ||
"tsup": "^8.2.4", | ||
"typescript": "^5.4.2", | ||
"vitest": "^1.6.0" | ||
}, | ||
"resolutions": { | ||
"esbuild": "0.23.0" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,103 @@ | ||
import { defineConfig, Options } from 'tsup' | ||
import fs from 'fs' | ||
import sh from 'shelljs' | ||
import type { ExecOptions } from 'shelljs' | ||
import fs from 'node:fs/promises' | ||
import path from 'node:path' | ||
import type { Options } from 'tsup' | ||
import { defineConfig } from 'tsup' | ||
|
||
function execAsync(cmd: string, opts: ExecOptions = {}) { | ||
return new Promise(function (resolve, reject) { | ||
// Execute the command, reject if we exit non-zero (i.e. error) | ||
sh.exec(cmd, opts, function (code, stdout, stderr) { | ||
if (code !== 0) return reject(new Error(stderr)) | ||
return resolve(stdout) | ||
}) | ||
}) | ||
async function writeCommonJSEntry() { | ||
await fs.writeFile( | ||
path.join('dist/cjs/', 'index.js'), | ||
`'use strict' | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./reselect.production.min.cjs') | ||
} else { | ||
module.exports = require('./reselect.development.cjs') | ||
}` | ||
) | ||
} | ||
|
||
export default defineConfig(options => { | ||
const commonOptions: Partial<Options> = { | ||
export default defineConfig((options): Options[] => { | ||
const commonOptions: Options = { | ||
entry: { | ||
reselect: 'src/index.ts' | ||
}, | ||
sourcemap: true, | ||
target: ['esnext'], | ||
clean: true, | ||
...options | ||
} | ||
|
||
return [ | ||
// Modern ESM | ||
{ | ||
...commonOptions, | ||
name: 'Modern ESM', | ||
target: ['esnext'], | ||
format: ['esm'], | ||
outExtension: () => ({ js: '.mjs' }), | ||
dts: true, | ||
clean: true | ||
outExtension: () => ({ js: '.mjs' }) | ||
}, | ||
|
||
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension | ||
// and optional chaining compiled away | ||
{ | ||
...commonOptions, | ||
name: 'Legacy ESM, Webpack 4', | ||
entry: { | ||
'reselect.legacy-esm': 'src/index.ts' | ||
}, | ||
format: ['esm'], | ||
outExtension: () => ({ js: '.js' }), | ||
target: 'es2017' | ||
target: ['es2017'] | ||
}, | ||
// Browser-ready ESM, production + minified | ||
|
||
// Meant to be served up via CDNs like `unpkg`. | ||
{ | ||
...commonOptions, | ||
name: 'Browser-ready ESM', | ||
entry: { | ||
'reselect.browser': 'src/index.ts' | ||
}, | ||
define: { | ||
'process.env.NODE_ENV': JSON.stringify('production') | ||
platform: 'browser', | ||
env: { | ||
NODE_ENV: 'production' | ||
}, | ||
format: ['esm'], | ||
outExtension: () => ({ js: '.mjs' }), | ||
minify: true | ||
}, | ||
{ | ||
...commonOptions, | ||
format: 'cjs', | ||
name: 'CJS Development', | ||
entry: { | ||
'reselect.development': 'src/index.ts' | ||
}, | ||
env: { | ||
NODE_ENV: 'development' | ||
}, | ||
format: ['cjs'], | ||
outDir: './dist/cjs/', | ||
outExtension: () => ({ js: '.cjs' }) | ||
}, | ||
{ | ||
...commonOptions, | ||
name: 'CJS production', | ||
entry: { | ||
'reselect.production.min': 'src/index.ts' | ||
}, | ||
env: { | ||
NODE_ENV: 'production' | ||
}, | ||
format: ['cjs'], | ||
outDir: './dist/cjs/', | ||
outExtension: () => ({ js: '.cjs' }), | ||
minify: true, | ||
onSuccess: async () => { | ||
await writeCommonJSEntry() | ||
} | ||
}, | ||
{ | ||
...commonOptions, | ||
name: 'CJS Type Definitions', | ||
format: ['cjs'], | ||
dts: { only: true } | ||
} | ||
] | ||
}) |
Oops, something went wrong.