🎥 Make videos programmatically with React
remotion
Jonny Burgere3867e305666
diff --git a/packages/bundler/src/dev-middleware/get-filename-from-url.ts b/packages/bundler/src/dev-middleware/get-filename-from-url.tsdeleted file mode 100644index 6e7f2f6395..0000000000--- a/packages/bundler/src/dev-middleware/get-filename-from-url.ts+++ /dev/null@@ -1,115 +0,0 @@-import path from 'path';-// eslint-disable-next-line no-restricted-imports-import querystring from 'querystring';-import {parse} from 'url';-import {getPaths} from './get-paths';-import {DevMiddlewareContext} from './types';--const cacheStore = new WeakMap();--const mem = (fn: Function, {cache = new Map()} = {}) => {- const memoized = (...arguments_: unknown[]) => {- const [key] = arguments_;- const cacheItem = cache.get(key);-- if (cacheItem) {- return cacheItem.data;- }-- const result = fn.apply(this, arguments_);-- cache.set(key, {- data: result,- });-- return result;- };-- cacheStore.set(memoized, cache);-- return memoized;-};--const memoizedParse = mem(parse);--export function getFilenameFromUrl(- context: DevMiddlewareContext,- url: string | undefined-) {- const paths = getPaths(context);-- let foundFilename;- let urlObject;-- try {- // The `url` property of the `request` is contains only `pathname`, `search` and `hash`- urlObject = memoizedParse(url, false, true);- } catch (_ignoreError) {- return;- }-- for (const {publicPath, outputPath} of paths) {- let filename: string;- let publicPathObject;-- try {- publicPathObject = memoizedParse(- publicPath !== 'auto' && publicPath ? publicPath : '/',- false,- true- );- } catch (_ignoreError) {- continue;- }-- if (urlObject.pathname?.startsWith(publicPathObject.pathname)) {- filename = outputPath;-- // Strip the `pathname` property from the `publicPath` option from the start of requested url- // `/complex/foo.js` => `foo.js`- const pathname = urlObject.pathname.substr(- publicPathObject.pathname.length- );-- if (pathname) {- filename = path.join(outputPath, querystring.unescape(pathname));- }-- if (!context.outputFileSystem) {- continue;- }-- try {- let fsStats = context.outputFileSystem?.statSync(filename);-- if (fsStats.isFile()) {- foundFilename = filename;-- break;- } else if (fsStats.isDirectory()) {- const indexValue = 'index.html';-- filename = path.join(filename, indexValue);-- // eslint-disable-next-line max-depth- try {- fsStats = context.outputFileSystem.statSync(filename);- } catch (__ignoreError) {- continue;- }-- // eslint-disable-next-line max-depth- if (fsStats.isFile()) {- foundFilename = filename;-- break;- }- }- } catch (_ignoreError) {- continue;- }- }- }-- return foundFilename;-}diff --git a/packages/bundler/src/dev-middleware/index.ts b/packages/bundler/src/dev-middleware/index.tsindex e41c5e2d97..ae42ce2276 100644--- a/packages/bundler/src/dev-middleware/index.ts+++ b/packages/bundler/src/dev-middleware/index.ts@@ -11,7 +11,7 @@ export const wdm = (compiler: webpack.Compiler): MiddleWare => {callbacks: [],compiler,watching: undefined as Watching | undefined,- logger: compiler.getInfrastructureLogger('webpack-dev-middleware'),+ logger: compiler.getInfrastructureLogger('remotion'),outputFileSystem: undefined,};diff --git a/packages/bundler/src/dev-middleware/middleware.ts b/packages/bundler/src/dev-middleware/middleware.tsindex 532bd8ab27..9a29d746d6 100644--- a/packages/bundler/src/dev-middleware/middleware.ts+++ b/packages/bundler/src/dev-middleware/middleware.ts@@ -9,10 +9,122 @@ import {send,setHeaderForResponse,} from './compatible-api';-import {getFilenameFromUrl} from './get-filename-from-url';import {parseRange} from './range-parser';import {ready} from './ready';import {DevMiddlewareContext} from './types';+// eslint-disable-next-line no-restricted-imports+import querystring from 'querystring';+import {parse} from 'url';+import {getPaths} from './get-paths';++const cacheStore = new WeakMap();++const mem = (fn: Function, {cache = new Map()} = {}) => {+ const memoized = (...arguments_: unknown[]) => {+ const [key] = arguments_;+ const cacheItem = cache.get(key);++ if (cacheItem) {+ return cacheItem.data;+ }++ const result = fn.apply(this, arguments_);++ cache.set(key, {+ data: result,+ });++ return result;+ };++ cacheStore.set(memoized, cache);++ return memoized;+};++const memoizedParse = mem(parse);++export function getFilenameFromUrl(+ context: DevMiddlewareContext,+ url: string | undefined+) {+ const paths = getPaths(context);++ let foundFilename;+ let urlObject;++ try {+ // The `url` property of the `request` is contains only `pathname`, `search` and `hash`+ urlObject = memoizedParse(url, false, true);+ } catch (_ignoreError) {+ return;+ }++ for (const {publicPath, outputPath} of paths) {+ let filename: string;+ let publicPathObject;++ try {+ publicPathObject = memoizedParse(+ publicPath !== 'auto' && publicPath ? publicPath : '/',+ false,+ true+ );+ } catch (_ignoreError) {+ continue;+ }++ if (urlObject.pathname?.startsWith(publicPathObject.pathname)) {+ filename = outputPath;++ // Strip the `pathname` property from the `publicPath` option from the start of requested url+ // `/complex/foo.js` => `foo.js`+ const pathname = urlObject.pathname.substr(+ publicPathObject.pathname.length+ );++ if (pathname) {+ filename = path.join(outputPath, querystring.unescape(pathname));+ }++ if (!context.outputFileSystem) {+ continue;+ }++ try {+ let fsStats = context.outputFileSystem?.statSync(filename);++ if (fsStats.isFile()) {+ foundFilename = filename;++ break;+ } else if (fsStats.isDirectory()) {+ const indexValue = 'index.html';++ filename = path.join(filename, indexValue);++ // eslint-disable-next-line max-depth+ try {+ fsStats = context.outputFileSystem.statSync(filename);+ } catch (__ignoreError) {+ continue;+ }++ // eslint-disable-next-line max-depth+ if (fsStats.isFile()) {+ foundFilename = filename;++ break;+ }+ }+ } catch (_ignoreError) {+ continue;+ }+ }+ }++ return foundFilename;+}export function getValueContentRangeHeader(type: string,diff --git a/packages/bundler/src/dev-middleware/setup-hooks.ts b/packages/bundler/src/dev-middleware/setup-hooks.tsindex 5e93480d33..fbb429b2f2 100644--- a/packages/bundler/src/dev-middleware/setup-hooks.ts+++ b/packages/bundler/src/dev-middleware/setup-hooks.ts@@ -48,7 +48,7 @@ export function setupHooks(context: DevMiddlewareContext) {});}- context.compiler.hooks.watchRun.tap('webpack-dev-middleware', invalid);- context.compiler.hooks.invalid.tap('webpack-dev-middleware', invalid);- context.compiler.hooks.done.tap('webpack-dev-middleware', done);+ context.compiler.hooks.watchRun.tap('remotion', invalid);+ context.compiler.hooks.invalid.tap('remotion', invalid);+ context.compiler.hooks.done.tap('remotion', done);}