🎥 Make videos programmatically with React
CLi and API for cache, delete cache if disables
Jonny Burgerecd5b3dbbb15
diff --git a/packages/bundler/src/bundler.ts b/packages/bundler/src/bundler.tsindex c0e1f0feb9..dea04513b5 100644--- a/packages/bundler/src/bundler.ts+++ b/packages/bundler/src/bundler.ts@@ -25,6 +25,7 @@ export const bundle = async (options?: {webpackOverride?: WebpackOverrideFn;outDir?: string;+ enableCaching?: boolean;}): Promise<string> => {const outDir = await prepareOutDir(options?.outDir ?? null);@@ -37,6 +38,8 @@ export const bundle = async (webpackOverride:options?.webpackOverride ?? Internals.getWebpackOverrideFn(),onProgressUpdate,+ enableCaching:+ options?.enableCaching ?? Internals.DEFAULT_WEBPACK_CACHE_ENABLED,}),]);if (!output) {diff --git a/packages/bundler/src/index.ts b/packages/bundler/src/index.tsindex 5e429db922..26df5a97b0 100644--- a/packages/bundler/src/index.ts+++ b/packages/bundler/src/index.ts@@ -68,5 +68,5 @@ export const startServer = async (};export * from './bundler';-export {cacheExists} from './webpack-cache';+export {cacheExists, clearCache} from './webpack-cache';export {overrideWebpackConfig};diff --git a/packages/bundler/src/webpack-cache.ts b/packages/bundler/src/webpack-cache.tsindex 6c89f36199..1c6c57f807 100644--- a/packages/bundler/src/webpack-cache.ts+++ b/packages/bundler/src/webpack-cache.ts@@ -40,12 +40,20 @@ export const getWebpackCacheDir = () => {}};+const remotionCacheLocation = (environment: Environment) => {+ return path.join(getWebpackCacheDir(), getWebpackCacheName(environment));+};++export const clearCache = (environment: Environment) => {+ return fs.promises.rmdir(remotionCacheLocation(environment), {+ recursive: true,+ });+};+export const getWebpackCacheName = (environment: Environment) => {return `remotion-${environment}`;};export const cacheExists = (environment: Environment) => {- return fs.existsSync(- path.join(getWebpackCacheDir(), getWebpackCacheName(environment))- );+ return fs.existsSync(remotionCacheLocation(environment));};diff --git a/packages/bundler/src/webpack-config.ts b/packages/bundler/src/webpack-config.tsindex 5d303c891d..fc8c8fbd24 100644--- a/packages/bundler/src/webpack-config.ts+++ b/packages/bundler/src/webpack-config.ts@@ -1,5 +1,5 @@import path from 'path';-import {WebpackConfiguration, WebpackOverrideFn} from 'remotion';+import {Internals, WebpackConfiguration, WebpackOverrideFn} from 'remotion';import webpack, {ProgressPlugin} from 'webpack';import {getWebpackCacheName} from './webpack-cache';@@ -27,7 +27,7 @@ export const webpackConfig = ({environment,webpackOverride = (f) => f,onProgressUpdate,- enableCaching = true,+ enableCaching = Internals.DEFAULT_WEBPACK_CACHE_ENABLED,}: {entry: string;userDefinedComponent: string;diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.tsindex c3b3be3df8..47f7bb4f7d 100644--- a/packages/cli/src/parse-command-line.ts+++ b/packages/cli/src/parse-command-line.ts@@ -12,6 +12,7 @@ export type CommandLineOptions = {['browser-executable']: BrowserExecutable;['pixel-format']: PixelFormat;['image-format']: ImageFormat;+ ['bundle-cache']: string;codec: Codec;concurrency: number;config: string;@@ -37,6 +38,11 @@ export const parseCommandLine = () => {if (parsedCli['browser-executable']) {Config.Puppeteer.setBrowserExecutable(parsedCli['browser-executable']);}+ if (typeof parsedCli['bundle-cache'] !== 'undefined') {+ Config.Bundling.setCachingEnabled(+ parsedCli['bundle-cache'] === 'false' ? false : true+ );+ }if (parsedCli.concurrency) {Config.Rendering.setConcurrency(parsedCli.concurrency);}diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex f8c72ff574..f2a49cabf0 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -1,4 +1,4 @@-import {bundle, cacheExists} from '@remotion/bundler';+import {bundle, cacheExists, clearCache} from '@remotion/bundler';import {ensureLocalBrowser,ffmpegHasFeature,@@ -140,11 +140,22 @@ export const render = async () => {cliProgress.Presets.shades_grey);+ const shouldCache = Internals.getWebpackCaching();const cacheExistedBefore = cacheExists('production');+ if (cacheExistedBefore && !shouldCache) {+ await clearCache('production');+ console.log('🧹 Cache disabled but found. Deleting...');+ }bundlingProgress.start(100, 0);- const bundled = await bundle(fullPath, (progress) => {- bundlingProgress.update(progress);- });+ const bundled = await bundle(+ fullPath,+ (progress) => {+ bundlingProgress.update(progress);+ },+ {+ enableCaching: shouldCache,+ }+ );bundlingProgress.stop();const cacheExistedAfter = cacheExists('production');if (cacheExistedAfter && !cacheExistedBefore) {diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.tsindex bad4c635c0..23feb5ee30 100644--- a/packages/core/src/config/index.ts+++ b/packages/core/src/config/index.ts@@ -14,6 +14,7 @@ import {import {setOverwriteOutput} from './overwrite';import {PixelFormat, setPixelFormat} from './pixel-format';import {setQuality} from './quality';+import {setWebpackCaching} from './webpack-caching';export const Config = {Bundling: {@@ -23,6 +24,11 @@ export const Config = {* Docs: http://remotion.dev/docs/webpack*/overrideWebpackConfig,+ /**+ * Whether Webpack bundles should be cached to make+ * subsequent renders faster. Default: true+ */+ setCachingEnabled: setWebpackCaching,},Puppeteer: {/**diff --git a/packages/core/src/config/webpack-caching.ts b/packages/core/src/config/webpack-caching.tsnew file mode 100644index 0000000000..08bcb3aa2b--- /dev/null+++ b/packages/core/src/config/webpack-caching.ts@@ -0,0 +1,14 @@+export const DEFAULT_WEBPACK_CACHE_ENABLED = true;++let webpackCaching = DEFAULT_WEBPACK_CACHE_ENABLED;++export const setWebpackCaching = (flag: boolean) => {+ if (typeof flag !== 'boolean') {+ throw new TypeError('Caching flag must be a boolean.');+ }+ webpackCaching = flag;+};++export const getWebpackCaching = () => {+ return webpackCaching;+};diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.tsindex a84b2579f1..b0c70c9cae 100644--- a/packages/core/src/internals.ts+++ b/packages/core/src/internals.ts@@ -42,6 +42,10 @@ import {validateSelectedPixelFormatAndCodecCombination,} from './config/pixel-format';import {getQuality} from './config/quality';+import {+ DEFAULT_WEBPACK_CACHE_ENABLED,+ getWebpackCaching,+} from './config/webpack-caching';import * as perf from './perf';import {getCompositionName, getIsEvaluation, getRoot} from './register-root';import {RemotionRoot} from './RemotionRoot';@@ -75,6 +79,7 @@ export const Internals = {DEFAULT_CODEC,DEFAULT_PIXEL_FORMAT,FEATURE_FLAG_FIREFOX_SUPPORT,+ DEFAULT_WEBPACK_CACHE_ENABLED,getBrowser,DEFAULT_BROWSER,getDefaultCrfForCodec,@@ -84,6 +89,7 @@ export const Internals = {validateSelectedPixelFormatAndImageFormatCombination,validateSelectedPixelFormatAndCodecCombination,validateFrameRange,+ getWebpackCaching,};export type {