fix: use rollup to output js files (#2916)

This commit is contained in:
Tony Brix 2023-08-07 16:50:43 -06:00 committed by GitHub
parent 9c5721ecd0
commit 610bc45d96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 8982 additions and 16996 deletions

View File

@ -29,6 +29,10 @@ jobs:
run: npm run test:unit
- name: Run Spec Tests 👩🏽‍💻
run: npm run test:specs
- name: Run UMD Tests 👩🏽‍💻
run: npm run test:umd
- name: Run Types Tests 👩🏽‍💻
run: npm run test:types
Lint:
runs-on: ubuntu-latest

4651
lib/marked.cjs generated

File diff suppressed because it is too large Load Diff

2
lib/marked.cjs.map generated

File diff suppressed because one or more lines are too long

1324
lib/marked.d.ts generated vendored

File diff suppressed because it is too large Load Diff

4588
lib/marked.esm.js generated

File diff suppressed because it is too large Load Diff

2
lib/marked.esm.js.map generated

File diff suppressed because one or more lines are too long

4829
lib/marked.umd.js generated

File diff suppressed because it is too large Load Diff

2
lib/marked.umd.js.map generated

File diff suppressed because one or more lines are too long

4
marked.min.js generated vendored

File diff suppressed because one or more lines are too long

10430
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -46,6 +46,7 @@
],
"devDependencies": {
"@markedjs/html-differ": "^4.0.2",
"@rollup/plugin-typescript": "^11.1.2",
"@semantic-release/commit-analyzer": "^10.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^9.0.4",
@ -67,31 +68,32 @@
"markdown-it": "13.0.1",
"node-fetch": "^3.3.2",
"recheck": "^4.4.5",
"rollup": "^3.27.0",
"semantic-release": "^21.0.7",
"titleize": "^3.0.0",
"ts-expect": "^1.3.0",
"ts-node": "^10.9.1",
"tsup": "^7.1.0",
"typescript": "5.1.6",
"uglify-js": "^3.17.4",
"vuln-regex-detector": "^1.3.0"
"uglify-js": "^3.17.4"
},
"scripts": {
"test": "cross-env NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine.json",
"test:all": "npm test && npm run test:lint",
"test:all": "npm test && npm run test:umd && npm run test:types && npm run test:lint",
"test:unit": "npm test -- test/unit/**/*-spec.js",
"test:specs": "npm test -- test/specs/**/*-spec.js",
"test:lint": "eslint .",
"test:redos": "node test/recheck.js > vuln.js",
"test:types": "tsc --project tsconfig-type-test.json",
"test:umd": "node test/umd-test.js",
"test:update": "node test/update-specs.js",
"rules": "node test/rules.js",
"bench": "npm run build && node test/bench.js",
"lint": "eslint --fix .",
"type-check": "tsc",
"build:reset": "git checkout upstream/master lib/marked.cjs lib/marked.umd.js lib/marked.esm.js marked.min.js",
"build": "npm run type-check && tsup && npm run build:verify && npm run minify",
"build": "npm run rollup && npm run minify",
"build:docs": "node build-docs.js",
"build:verify": "tsc --project tsconfig-type-test.json",
"build:types": "tsc --project tsconfig-types.json",
"rollup": "rollup -c rollup.config.js",
"minify": "uglifyjs lib/marked.umd.js -cm --comments /Copyright/ -o marked.min.js"
},
"engines": {

49
rollup.config.js Normal file
View File

@ -0,0 +1,49 @@
import typescript from '@rollup/plugin-typescript';
import { defineConfig } from 'rollup';
import fs from 'fs';
const pkg = JSON.parse(fs.readFileSync('./package.json'));
const version = process.env.SEMANTIC_RELEASE_NEXT_VERSION || pkg.version;
console.log('building version:', version);
const banner = `/**
* marked v${version} - a markdown parser
* Copyright (c) 2011-${new Date().getFullYear()}, Christopher Jeffrey. (MIT Licensed)
* https://github.com/markedjs/marked
*/
/**
* DO NOT EDIT THIS FILE
* The code in this file is generated from files in ./src/
*/
`;
export default defineConfig([
{
input: 'src/marked.ts',
output: [{
file: 'lib/marked.esm.js',
format: 'esm',
sourcemap: true,
banner
},
{
file: 'lib/marked.umd.js',
format: 'umd',
name: 'marked',
sourcemap: true,
banner
},
{
file: 'lib/marked.cjs',
format: 'cjs',
name: 'marked',
sourcemap: true,
banner
}],
plugins: [
typescript()
]
}
]);

View File

@ -1,5 +1,5 @@
import type { MarkedOptions } from './MarkedOptions.ts';
import type { ResultCallback } from './marked.ts';
import type { ResultCallback } from './Instance.ts';
import type { Rule } from './rules.ts';
/**

View File

@ -13,8 +13,7 @@ import {
} from './defaults.ts';
import type { MarkedExtension, MarkedOptions } from './MarkedOptions.ts';
import type { Token, TokensList } from './Tokens.ts';
export type ResultCallback = (error: Error | null, parseResult?: string) => undefined | void;
import type { ResultCallback } from './Instance.ts';
const markedInstance = new Marked();

6
test/umd-test.js vendored Normal file
View File

@ -0,0 +1,6 @@
import '../lib/marked.umd.js';
// eslint-disable-next-line no-undef
if (!marked.parse('# test').includes('<h1')) {
throw new Error('Invalid markdown');
}

17
tsconfig-types.json Normal file
View File

@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2022",
"module": "NodeNext",
"strict": true,
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "NodeNext",
"noImplicitAny": false,
"allowImportingTsExtensions": true,
"outFile": "lib/marked.d.ts"
},
"include": [
"src/*.ts"
]
}

View File

@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es2021",
"target": "es2022",
"module": "NodeNext",
"isolatedModules": true,
"strict": true,

View File

@ -1,47 +0,0 @@
import { defineConfig } from 'tsup';
import fs from 'fs';
const pkg = JSON.parse(String(fs.readFileSync('./package.json')));
const version = process.env.SEMANTIC_RELEASE_NEXT_VERSION || pkg.version;
console.log('building version:', version);
const banner = `/**
* marked v${version} - a markdown parser
* Copyright (c) 2011-${new Date().getFullYear()}, Christopher Jeffrey. (MIT Licensed)
* https://github.com/markedjs/marked
*/
/**
* DO NOT EDIT THIS FILE
* The code in this file is generated from files in ./src/
*/
`;
export default defineConfig({
entry: ['src/marked.ts'],
splitting: false,
sourcemap: true,
clean: true,
format: ['cjs', 'esm', 'iife'],
globalName: 'marked',
banner: {
js: banner
},
outDir: 'lib',
outExtension({ format }) {
if (format === 'cjs') {
return {
js: '.cjs'
};
} else if (format === 'iife') {
return {
js: '.umd.js'
};
}
return {
js: `.${format}.js`
};
},
dts: true
});