Skip to content

Commit

Permalink
deprecate cjs and add warning similar to vite
Browse files Browse the repository at this point in the history
  • Loading branch information
olsonpm committed Dec 1, 2023
1 parent d899e47 commit 18d9787
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ import { extract } from 'https://esm.sh/@extractus/feed-extractor'

Please check [the examples](https://github.com/extractus/feed-extractor/tree/main/examples) for reference.

## CJS Deprecated

CJS is deprecated for this package. When calling `require('@extractus/feed-extractor')` a deprecation warning is now logged. You should update your code to use the ESM export.

- You can ignore this warning via the environment variable `FEED_EXTRACTOR_CJS_IGNORE_WARNING=true`
- To see where the warning is coming from you can set the environment variable `FEED_EXTRACTOR_CJS_TRACE_WARNING=true`


## APIs

Expand Down
2 changes: 1 addition & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const externalDeps = Object.keys(dependencies)
.filter(dep => !esmDependencies.has(dep))

build({
entryPoints: ['./src/main.js'],
entryPoints: ['./src/cjs-entry.js'],
bundle: true,
platform: 'node',
target: 'node16',
Expand Down
14 changes: 14 additions & 0 deletions src/cjs-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function warnCjsUsage () {
if (process.env.FEED_EXTRACTOR_CJS_IGNORE_WARNING?.toLowerCase() === 'true') return
const yellow = (str) => `\u001b[33m${str}\u001b[39m`
const log = process.env.FEED_EXTRACTOR_CJS_TRACE_WARNING?.toLowerCase() === 'true' ? console.trace : console.warn
log(
yellow(
'The CJS build of @extractus/feed-extractor is deprecated. See https://github.com/extractus/feed-extractor#cjs-deprecated for details.'
)
)
}

warnCjsUsage()

export * from './main'

0 comments on commit 18d9787

Please sign in to comment.