1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-23 02:04:34 +02:00
video.js/build/rollup-exclude-lines.js

42 lines
1.4 KiB
JavaScript
Raw Normal View History

fix(types): Add has|usingPlugin to typedef by adding stubs which are removed from builds (#8811) ## Description tsc doesn't understand mixins and ignores jsdoc not followed by code. The jsdoc for the plugin methods `usingPlugin()` and `hasPlugin()` in Player are being ignored. To get them included in type outputs we need to have otherwise unnecessary stubs codes, as we already have for `on()` etc, which adds unnecessary, even if a small amount of, code to the outputs. ## Specific Changes proposed * Slight refactor of Player to include those stubs. * Adds a rollup plugin to delete lines between certain comments, so those stubs are deleted from the outputs. * Applies those comments to the `on()` etc stubs in Component and the new plugin stubs in Player. Any code surrounded by these comments, and the comments themselves, is deleted from the dist and test builds: ```js /* start-delete-from-build */ console.log('hi'); /* start-delete-from-build */ ``` Compared to main, video.min.js is 53 bytes smaller. ## Requirements Checklist - [ ] Feature implemented / Bug fixed - [ ] If necessary, more likely in a feature request than a bug fix - [ ] Change has been verified in an actual browser (Chrome, Firefox, IE) - [ ] Unit Tests updated or fixed - [ ] Docs/guides updated - [ ] Example created ([starter template on JSBin](https://codepen.io/gkatsev/pen/GwZegv?editors=1000#0)) - [ ] Has no DOM changes which impact accessiblilty or trigger warnings (e.g. Chrome issues tab) - [ ] Has no changes to JSDoc which cause `npm run docs:api` to error - [ ] Reviewed by Two Core Contributors
2024-08-12 21:47:47 +02:00
/**
* Remove parts of files from outputs. Everything between a pair of `/* start-delete-from-build *\u002f`
* and `/* end-delete-from-build *\u002f` comments
*
* Based on https://github.com/se-panfilov/rollup-plugin-strip-code
*/
import { createFilter } from '@rollup/pluginutils';
const START_COMMENT = 'start-delete-from-build';
const END_COMMENT = 'end-delete-from-build';
/**
* Remove lines of code surrounded by comments
*
* @param {Object} [options] Options
* @param {string} [options.include] Files to inlcude
* @param {string} [options.exclude] Files to exclude
* @param {string} [options.startComment] Starting keywork, default start-delete-from-build
* @param {string} [options.endComment] Eding keywork, default end-delete-from-build
* @param {RegExp} [options.pattern] Custom regex
* @return void
*/
export default function excludeLines(options = {}) {
// assume that the myPlugin accepts options of `options.include` and `options.exclude`
const filter = createFilter(options.include, options.exclude);
return {
transform(code, id) {
if (!filter(id)) {
return;
}
const startComment = options.startComment || START_COMMENT;
const endComment = options.endComment || END_COMMENT;
const defaultPattern = new RegExp(`([\\t ]*\\/\\* ?${startComment} ?\\*\\/)[\\s\\S]*?(\\/\\* ?${endComment} ?\\*\\/[\\t ]*\\n?)`, 'g');
return code.replace(options.pattern || defaultPattern, '');
}
};
}