-
Notifications
You must be signed in to change notification settings - Fork 33
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 #119 from olsonpm/support-cjs
Support cjs
- Loading branch information
Showing
5 changed files
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,6 @@ pnpm-lock.yaml | |
|
||
output.json | ||
deno.lock | ||
|
||
bundle.cjs | ||
bundle.cjs.map |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { build } from 'esbuild' | ||
import fs from 'fs' | ||
|
||
const { dependencies } = JSON.parse(fs.readFileSync('./package.json', 'utf8')) | ||
// we need esbuild to process esm dependencies while leaving cjs compatible ones | ||
// out of the bundle | ||
const esmDependencies = new Set(['bellajs']) | ||
const externalDeps = Object.keys(dependencies) | ||
.filter(dep => !esmDependencies.has(dep)) | ||
|
||
build({ | ||
entryPoints: ['./src/cjs-entry.js'], | ||
bundle: true, | ||
platform: 'node', | ||
target: 'node16', | ||
outfile: 'bundle.cjs', | ||
minify: true, | ||
sourcemap: true, | ||
external: externalDeps, | ||
}) |
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 |
---|---|---|
@@ -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' |