Skip to content

Commit

Permalink
chore: upgrade esbuild + add logging to JS api
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Dec 5, 2023
1 parent a7c4948 commit b96c27d
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 301 deletions.
2 changes: 1 addition & 1 deletion examples/vanilla-ts-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build": "yarn esbuild --minify"
},
"devDependencies": {
"esbuild": "^0.19.4",
"esbuild": "^0.19.8",
"typescript": "^4.9.4"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/mux-active-viewer-count/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@web/dev-server-import-maps": "^0.0.6",
"@web/test-runner": "^0.13.26",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"eslint": "^8.24.0",
"hls.js": "^1.4.12",
"mux-embed": "^4.30.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/mux-audio-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"eslint": "^8.24.0",
"npm-run-all": "^4.1.5",
"react": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/mux-audio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@web/dev-server-import-maps": "^0.0.6",
"@web/test-runner": "^0.13.26",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"eslint": "^8.24.0",
"hls.js": "^1.4.12",
"mux-embed": "^4.30.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/mux-elements-codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"eslint": "^8.24.0",
"npm-run-all": "^4.1.5",
"replace": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/mux-player-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"npm-run-all": "^4.1.5",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/mux-player/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"@web/test-runner": "^0.13.26",
"@web/test-runner-playwright": "^0.9.0",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"eslint": "^8.24.0",
"hls.js": "^1.4.12",
"mux-embed": "^4.30.0",
Expand Down
44 changes: 34 additions & 10 deletions packages/mux-player/scripts/build-themes.mjs
Original file line number Diff line number Diff line change
@@ -1,46 +1,70 @@
#!/usr/bin/env node
import { build } from 'esbuild';
import esbuild from 'esbuild';

const themes = ['classic', 'microvideo', 'minimal', 'gerwig'];
const devMode = process.argv.includes('--dev');

const shared = {
bundle: true,
target: 'es2019',
logLevel: 'info',
loader: {
'.html': 'text',
'.css': 'text',
'.svg': 'text',
},
watch: devMode,
};

// entryPoints doesn't support glob patterns so we iterate over known themes
themes.forEach((theme) => {
for (const theme of themes) {
//@ts-ignore
build({
const esm = {
...shared,
entryPoints: [`./src/themes/${theme}/index.ts`],
format: 'esm',
outExtension: { '.js': '.mjs' },
outdir: `./dist/themes/${theme}`,
});
};

if (devMode) {
const context = await esbuild.context(esm);
await context.rebuild();
await context.watch();
} else {
await esbuild.build(esm);
}

//@ts-ignore
build({
const cjs = {
...shared,
entryPoints: [`./src/themes/${theme}/index.ts`],
format: 'cjs',
outExtension: { '.js': '.cjs.js' },
outdir: `./dist/themes/${theme}`,
});
};

if (devMode) {
const context = await esbuild.context(cjs);
await context.rebuild();
await context.watch();
} else {
await esbuild.build(cjs);
}

//@ts-ignore
build({
const iife = {
...shared,
entryPoints: [`./src/themes/${theme}/index.ts`],
format: 'iife',
globalName: `mediaTheme${theme[0].toUpperCase() + theme.slice(1)}`,
outdir: `./dist/themes/${theme}`,
});
});
};

if (devMode) {
const context = await esbuild.context(iife);
await context.rebuild();
await context.watch();
} else {
await esbuild.build(iife);
}
}
2 changes: 1 addition & 1 deletion packages/mux-uploader-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"npm-run-all": "^4.1.5",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/mux-uploader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@web/dev-server-import-maps": "^0.0.6",
"copyfiles": "^2.4.1",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"hls.js": "^1.4.12",
"mux-embed": "^4.30.0",
"npm-run-all": "^4.1.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/mux-video-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"eslint": "^8.24.0",
"npm-run-all": "^4.1.5",
"react": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/mux-video/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@web/dev-server-import-maps": "^0.0.6",
"@web/test-runner": "^0.13.26",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"eslint": "^8.24.0",
"hls.js": "^1.4.12",
"mux-embed": "^4.30.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/playback-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@web/dev-server-import-maps": "^0.0.6",
"@web/test-runner": "^0.13.26",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"eslint": "^8.24.0",
"npm-run-all": "^4.1.5",
"shx": "^0.3.4",
Expand Down
49 changes: 24 additions & 25 deletions scripts/esbuilder/esbuilder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env node
import path from 'path';
import { build } from 'esbuild';
import fs from 'fs';
import * as process from 'node:process';
import * as fs from 'node:fs';
import * as path from 'node:path';
import esbuild from 'esbuild';

const camelCase = (name) => {
return name.replace(/[-_]([a-z])/g, ($0, $1) => $1.toUpperCase());
Expand Down Expand Up @@ -35,6 +36,17 @@ const i18nPlugin = {
},
};

const onBuildEnd = {
name: 'on-build-end',
setup(build) {
build.onEnd((result) => {
const name = esmScriptModule ? 'module' : options.format;
// write-out the metafile
fs.writeFileSync(`./dist/${name}.json`, JSON.stringify(result.metafile));
});
},
};

const esmScriptModule = args.format === 'esm-module';

const options = {
Expand All @@ -45,15 +57,10 @@ const options = {
target: 'es2019',
minify: args.minify,
format: args.format,
watch: !!args.watch && {
onRebuild(error, result) {
if (error) console.error('[watch] build failed:', error);
else console.log('[watch] build finished');
},
},
outExtension: args.outExtension,
metafile: true,
plugins: [i18nPlugin],
logLevel: 'info',
plugins: [i18nPlugin, onBuildEnd],
loader: {
'.html': 'text',
'.css': 'text',
Expand All @@ -77,18 +84,10 @@ if (esmScriptModule) {
options.format = 'esm';
}

build(options).then(
(result) => {
let name = options.format;

if (esmScriptModule) {
name = 'module';
}

// write-out the metafile
fs.writeFileSync(`./dist/${name}.json`, JSON.stringify(result.metafile));

if (!!args.watch) console.log('[watch] build finished, watching for changes...');
},
() => process.exit(1)
);
if (args.watch) {
const context = await esbuild.context(options);
await context.rebuild();
await context.watch();
} else {
await esbuild.build(options);
}
2 changes: 1 addition & 1 deletion scripts/esbuilder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"esbuilder": "./esbuilder.js"
},
"dependencies": {
"esbuild": "^0.15.7"
"esbuild": "^0.19.8"
}
}
2 changes: 1 addition & 1 deletion shared/test-esm-exports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"mux-embed": "*"
},
"devDependencies": {
"esbuild": "^0.15.7",
"esbuild": "^0.19.8",
"hls.js": "^1.4.12",
"mux-embed": "^4.30.0"
}
Expand Down
Loading

0 comments on commit b96c27d

Please sign in to comment.