Skip to content

Commit

Permalink
Add named exports for classes and enums in ESM output
Browse files Browse the repository at this point in the history
Resolves #5630
  • Loading branch information
robwalch committed Oct 25, 2023
1 parent ef81686 commit d84e9a8
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
5 changes: 4 additions & 1 deletion build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,13 @@ const buildRollupConfig = ({
includeCoverage,
sourcemap = true,
outputFile = null,
input = './src/exports-default.ts',
}) => {
const outputName = buildTypeToOutputName[type];
const extension = format === FORMAT.esm ? 'mjs' : 'js';

return {
input: './src/hls.ts',
input,
onwarn: (e) => {
if (allowCircularDeps && e.code === 'CIRCULAR_DEPENDENCY') return;

Expand Down Expand Up @@ -307,6 +308,7 @@ const configs = Object.entries({
minified: true,
}),
fullEsm: buildRollupConfig({
input: './src/exports-named.ts',
type: BUILD_TYPE.full,
format: FORMAT.esm,
minified: false,
Expand All @@ -322,6 +324,7 @@ const configs = Object.entries({
minified: true,
}),
lightEsm: buildRollupConfig({
input: './src/exports-named.ts',
type: BUILD_TYPE.light,
format: FORMAT.esm,
minified: false,
Expand Down
2 changes: 1 addition & 1 deletion src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type { ComponentAPI } from '../types/component-api';
import type { ChunkMetadata } from '../types/transmuxer';
import type Hls from '../hls';
import type { LevelDetails } from '../loader/level-details';
import type { HlsConfig } from '../hls';
import type { HlsConfig } from '../config';

const VIDEO_CODEC_PROFILE_REPLACE =
/(avc[1234]|hvc1|hev1|dvh[1e]|vp09|av01)(?:\.[^.,]+)+/;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/error-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { RetryConfig } from '../config';
import type { NetworkComponentAPI } from '../types/component-api';
import type { ErrorData } from '../types/events';
import type { Fragment } from '../loader/fragment';
import type { LevelDetails } from '../hls';
import type { LevelDetails } from '../loader/level-details';

const RENDITION_PENALTY_DURATION_MS = 300000;

Expand Down
3 changes: 3 additions & 0 deletions src/exports-default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Hls from './hls';

export default Hls;
55 changes: 55 additions & 0 deletions src/exports-named.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Hls from './hls';
import { Events } from './events';
import { ErrorTypes, ErrorDetails } from './errors';
import { Level } from './types/level';
import AbrController from './controller/abr-controller';
import AudioTrackController from './controller/audio-track-controller';
import AudioStreamController from './controller/audio-stream-controller';
import BasePlaylistController from './controller/base-playlist-controller';
import BaseStreamController from './controller/base-stream-controller';
import BufferController from './controller/buffer-controller';
import CapLevelController from './controller/cap-level-controller';
import CMCDController from './controller/cmcd-controller';
import ContentSteeringController from './controller/content-steering-controller';
import EMEController from './controller/eme-controller';
import ErrorController from './controller/error-controller';
import FPSController from './controller/fps-controller';
import SubtitleTrackController from './controller/subtitle-track-controller';

export {
Hls,
ErrorDetails,
ErrorTypes,
Events,
Level,
AbrController,
AudioStreamController,
AudioTrackController,
BasePlaylistController,
BaseStreamController,
BufferController,
CapLevelController,
CMCDController,
ContentSteeringController,
EMEController,
ErrorController,
FPSController,
SubtitleTrackController,
};
export { SubtitleStreamController } from './controller/subtitle-stream-controller';
export { TimelineController } from './controller/timeline-controller';
export { KeySystems, KeySystemFormats } from './utils/mediakeys-helper';
export { DateRange } from './loader/date-range';
export { LoadStats } from './loader/load-stats';
export { LevelKey } from './loader/level-key';
export { LevelDetails } from './loader/level-details';
export { MetadataSchema } from './types/demuxer';
export { HlsSkip, HlsUrlParameters } from './types/level';
export { PlaylistLevelType } from './types/loader';
export { ChunkMetadata } from './types/transmuxer';
export { BaseSegment, Fragment, Part } from './loader/fragment';
export {
NetworkErrorAction,
ErrorActionFlags,
} from './controller/error-controller';
export { AttrList } from './utils/attr-list';
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"src/**/*",
"tests/**/*",
"demo/**/*",
"tests/**/.eslintrc.js" /* needed for eslint to work for some reason ¯\_(ツ)_/¯ */
/* needed for eslint to work for some reason ¯\_(ツ)_/¯ */
"tests/**/.eslintrc.js",
"rollup.config.js",
"build-config.js"
]
}

0 comments on commit d84e9a8

Please sign in to comment.