fix: remove cjs build & update min node to 20 (#3687)

BREAKING CHANGE:
- minify ./lib/marked.esm.js and ./lib/marked.umd.js
- remove ./marked.min.js use ./lib/marked.umd.js instead
- remove ./lib/marked.cjs
- update minimum supported node version to 20 to support require('marked.esm.js'). see nodejs.org/docs/latest-v20.x/api/modules.html#loading-ecmascript-modules-using-require
This commit is contained in:
Tony Brix
2025-06-26 22:44:11 -06:00
committed by GitHub
parent 4fc639e053
commit 0a35d8f28b
17 changed files with 1981 additions and 1273 deletions
-1
View File
@@ -1,4 +1,3 @@
* eol=lf
test/* linguist-vendored
lib/* linguist-generated
marked.min.js linguist-generated
+2 -2
View File
@@ -12,8 +12,8 @@ jobs:
UnitTests:
strategy:
matrix:
# lowest verison here should also be in `engines` field
node_version: [18, "lts/*", "latest"]
# lowest version here should also be in `engines` field
node_version: [20, "lts/*", "latest"]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
-1
View File
@@ -8,5 +8,4 @@ lib
docs/LICENSE.md
vuln.js
man/marked.1
marked.min.js
test.js
+1 -1
View File
@@ -83,7 +83,7 @@ $ marked --help
</head>
<body>
<div id="content"></div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
<script>
document.getElementById('content').innerHTML =
marked.parse('# Marked in the browser\n\nRendered by **marked**.');
+2 -2
View File
@@ -177,7 +177,7 @@ export async function main(nodeProcess) {
try {
// try require for json
markedConfig = require(configFile);
} catch (err) {
} catch(err) {
if (err.code !== 'ERR_REQUIRE_ESM') {
throw err;
}
@@ -271,7 +271,7 @@ export async function main(nodeProcess) {
try {
await start(nodeProcess.argv.slice());
nodeProcess.exit(0);
} catch (err) {
} catch(err) {
if (err.code === 'ENOENT') {
nodeProcess.stderr.write('marked: ' + err.path + ': No such file or directory');
} else {
+1 -1
View File
@@ -109,7 +109,7 @@ $ marked -s 'line1\nline2' -c config.json
</head>
<body>
<div id="content"></div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
<script>
document.getElementById('content').innerHTML =
marked.parse('# Marked in browser\n\nRendered by **marked**.');
+1 -1
View File
@@ -171,7 +171,7 @@ markedWorker.postMessage(markdownString);
```js
// markedWorker.js
importScripts('path/to/marked.min.js');
importScripts('path/to/marked.umd.js');
onmessage = (e) => {
const markdownString = e.data
+10 -3
View File
@@ -1,5 +1,5 @@
/* global marked */
import '../marked.min.js';
import '../lib/marked.umd.js';
import { promises } from 'fs';
import { join, dirname, parse, format } from 'path';
import { fileURLToPath } from 'url';
@@ -48,10 +48,17 @@ async function init() {
console.log('Cleaning up output directory ' + outputDir);
await rm(outputDir, { force: true, recursive: true });
await mkdir(outputDir);
await mkdir(join(outputDir, 'lib'));
console.log(`Copying file ${join(inputDir, 'LICENSE.md')}`);
await copyFile(join(cwd, 'LICENSE.md'), join(inputDir, 'LICENSE.md'));
console.log(`Copying file ${join(outputDir, 'marked.min.js')}`);
await copyFile(join(cwd, 'marked.min.js'), join(outputDir, 'marked.min.js'));
console.log(`Copying file ${join(outputDir, 'lib/marked.umd.js')}`);
await copyFile(join(cwd, 'lib/marked.umd.js'), join(outputDir, 'lib/marked.umd.js'));
console.log(`Copying file ${join(outputDir, 'lib/marked.umd.js.map')}`);
await copyFile(join(cwd, 'lib/marked.umd.js.map'), join(outputDir, 'lib/marked.umd.js.map'));
console.log(`Copying file ${join(outputDir, 'lib/marked.esm.js')}`);
await copyFile(join(cwd, 'lib/marked.esm.js'), join(outputDir, 'lib/marked.esm.js'));
console.log(`Copying file ${join(outputDir, 'lib/marked.esm.js.map')}`);
await copyFile(join(cwd, 'lib/marked.esm.js.map'), join(outputDir, 'lib/marked.esm.js.map'));
const tmpl = await readFile(templateFile, 'utf8');
console.log('Building markdown...');
const [original, commonmark, gfm] = await getTests([
+1
View File
@@ -135,6 +135,7 @@ function loadVersion(ver) {
} else {
promise = import(ver + '/lib/marked.esm.js')
.catch(fetchMarked(ver + '/marked.min.js'))
.catch(fetchMarked(ver + '/lib/marked.umd.js'))
.catch(fetchMarked(ver + '/lib/marked.js'))
.then((marked) => {
if (!marked) {
+1 -13
View File
@@ -26,7 +26,7 @@ function config(options) {
},
sourcemap: true,
bundle: true,
minify: false,
minify: true,
...(options.format === 'umd'
? {
plugins: [umdWrapper({
@@ -43,19 +43,7 @@ await esbuild.build(config({
outfile: 'lib/marked.esm.js',
}));
await esbuild.build(config({
format: 'cjs',
outfile: 'lib/marked.cjs',
}));
await esbuild.build(config({
format: 'umd',
outfile: 'lib/marked.umd.js',
}));
await esbuild.build(config({
sourcemap: false,
minify: true,
format: 'umd',
outfile: 'marked.min.js',
}));
+1 -1
View File
@@ -2,7 +2,7 @@ import markedEslintConfig from '@markedjs/eslint-config';
export default [
{
ignores: ['**/lib', '**/*.min.js', '**/public'],
ignores: ['**/lib', '**/public'],
},
...markedEslintConfig,
];
+1939 -1201
View File
File diff suppressed because it is too large Load Diff
+11 -19
View File
@@ -4,7 +4,7 @@
"author": "Christopher Jeffrey",
"version": "15.0.12",
"type": "module",
"main": "./lib/marked.cjs",
"main": "./lib/marked.esm.js",
"module": "./lib/marked.esm.js",
"browser": "./lib/marked.umd.js",
"types": "./lib/marked.d.ts",
@@ -15,22 +15,14 @@
"files": [
"bin/",
"lib/",
"man/",
"marked.min.js"
"man/"
],
"exports": {
".": {
"import": {
"types": "./lib/marked.d.ts",
"default": "./lib/marked.esm.js"
},
"default": {
"types": "./lib/marked.d.cts",
"default": "./lib/marked.cjs"
}
"types": "./lib/marked.d.ts",
"default": "./lib/marked.esm.js"
},
"./bin/marked": "./bin/marked.js",
"./marked.min.js": "./marked.min.js",
"./package.json": "./package.json"
},
"publishConfig": {
@@ -58,7 +50,7 @@
"devDependencies": {
"@arethetypeswrong/cli": "^0.18.2",
"@markedjs/eslint-config": "^1.0.12",
"@markedjs/testutils": "14.1.1-0",
"@markedjs/testutils": "15.0.11-0",
"@semantic-release/commit-analyzer": "^13.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^11.0.3",
@@ -76,6 +68,7 @@
"marked-highlight": "^2.2.1",
"marked-man": "^2.1.0",
"recheck": "^4.5.0",
"rimraf": "^6.0.1",
"semantic-release": "^24.2.5",
"titleize": "^4.0.0",
"tslib": "^2.8.1",
@@ -87,25 +80,24 @@
"build:docs": "npm run build && node docs/build.js",
"build:esbuild": "node esbuild.config.js",
"build:man": "marked-man man/marked.1.md > man/marked.1",
"build:reset": "git checkout upstream/master lib/marked.cjs lib/marked.umd.js lib/marked.esm.js marked.min.js",
"build:types": "tsc && dts-bundle-generator --export-referenced-types --project tsconfig.json -o lib/marked.d.ts src/marked.ts && dts-bundle-generator --export-referenced-types --project tsconfig.json -o lib/marked.d.cts src/marked.ts",
"build:reset": "rimraf ./lib ./public",
"build:types": "tsc && dts-bundle-generator --export-referenced-types --project tsconfig.json -o lib/marked.d.ts src/marked.ts",
"lint": "eslint --fix",
"rules": "node test/rules.js",
"test": "npm run build && npm run test:specs && npm run test:unit",
"test:all": "npm test && npm run test:umd && npm run test:cjs && npm run test:types && npm run test:lint",
"test": "npm run build:reset && npm run build:docs && npm run test:specs && npm run test:unit && npm run test:umd && npm run test:cjs && npm run test:types && npm run test:lint",
"test:cjs": "node test/cjs-test.cjs",
"test:lint": "eslint",
"test:only": "npm run build && npm run test:specs:only && npm run test:unit:only",
"test:redos": "node test/recheck.js > vuln.js",
"test:specs:only": "node --test --test-only --test-reporter=spec test/run-spec-tests.js",
"test:specs": "node --test --test-reporter=spec test/run-spec-tests.js",
"test:types": "tsc --project tsconfig-type-test.json && attw -P --exclude-entrypoints ./bin/marked ./marked.min.js",
"test:types": "tsc --project tsconfig-type-test.json && attw -P --entrypoints . --profile esm-only",
"test:umd": "node test/umd-test.js",
"test:unit:only": "node --test --test-only --test-reporter=spec test/unit/*.test.js",
"test:unit": "node --test --test-reporter=spec test/unit/*.test.js",
"test:update": "node test/update-specs.js"
},
"engines": {
"node": ">= 18"
"node": ">= 20"
}
}
+1 -1
View File
@@ -323,7 +323,7 @@ export class Marked {
html = opt.hooks.postprocess(html) as string;
}
return html;
} catch (e) {
} catch(e) {
return throwError(e as Error);
}
};
+7 -23
View File
@@ -2,13 +2,10 @@ import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { htmlIsEqual, getTests } from '@markedjs/testutils';
import { marked as cjsMarked } from '../lib/marked.cjs';
import { marked as esmMarked } from '../lib/marked.esm.js';
import { marked } from '../lib/marked.esm.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
let marked;
/**
* Load specs
*/
@@ -32,26 +29,15 @@ export async function runBench(options) {
const specs = await load();
const tests = {};
// Non-GFM, Non-pedantic
cjsMarked.setOptions({
marked.setOptions({
gfm: false,
breaks: false,
pedantic: false,
});
if (options.marked) {
cjsMarked.setOptions(options.marked);
marked.setOptions(options.marked);
}
tests['cjs marked'] = cjsMarked.parse;
esmMarked.setOptions({
gfm: false,
breaks: false,
pedantic: false,
});
if (options.marked) {
esmMarked.setOptions(options.marked);
}
tests['esm marked'] = esmMarked.parse;
tests.marked = marked.parse;
try {
tests.commonmark = await (async() => {
@@ -62,7 +48,7 @@ export async function runBench(options) {
return writer.render(parser.parse(text));
};
})();
} catch (e) {
} catch(e) {
console.error('Could not bench commonmark. (Error: %s)', e.message);
}
@@ -72,7 +58,7 @@ export async function runBench(options) {
const md = new MarkdownIt();
return md.render.bind(md);
})();
} catch (e) {
} catch(e) {
console.error('Could not bench markdown-it. (Error: %s)', e.message);
}
@@ -120,7 +106,7 @@ export async function bench(tests, specs) {
}
const percentSlower = ((
prettyElapsedTime(stats['esm marked'].elapsed)
prettyElapsedTime(stats.marked.elapsed)
/ prettyElapsedTime(stats.commonmark.elapsed)
) - 1) * 100;
@@ -208,8 +194,6 @@ function camelize(text) {
* Main
*/
export default async function main(argv) {
marked = cjsMarked;
const opt = parseArg(argv);
await runBench(opt);
+1 -1
View File
@@ -1,5 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { marked } = require('../lib/marked.cjs');
const { marked } = require('../lib/marked.esm.js');
if (!marked.parse('# test').includes('<h1')) {
throw new Error('Invalid markdown');
+2 -2
View File
@@ -31,7 +31,7 @@ async function updateCommonmark(dir, options) {
}));
writeFileSync(resolve(dir, `./commonmark.${version}.json`), JSON.stringify(specs, null, 2) + '\n');
console.log(`Saved CommonMark v${version} specs`);
} catch (ex) {
} catch(ex) {
console.log(ex);
}
}
@@ -72,7 +72,7 @@ async function updateGfm(dir) {
}));
writeFileSync(resolve(dir, `./gfm.${version}.json`), JSON.stringify(specs, null, 2) + '\n');
console.log(`Saved GFM v${version} specs.`);
} catch (ex) {
} catch(ex) {
console.log(ex);
}
}