@remotion/bundler 3.1.6 → 3.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.d.ts CHANGED
@@ -1,11 +1,17 @@
1
1
  import type { WebpackOverrideFn } from 'remotion';
2
2
  import webpack from 'webpack';
3
- declare type Options = {
3
+ export declare type BundleOptions = {
4
4
  webpackOverride?: WebpackOverrideFn;
5
5
  outDir?: string;
6
6
  enableCaching?: boolean;
7
7
  publicPath?: string;
8
+ rootDir?: string;
8
9
  };
9
- export declare const getConfig: (outDir: string, entryPoint: string, onProgressUpdate?: ((progress: number) => void) | undefined, options?: Options) => [string, webpack.Configuration];
10
- export declare const bundle: (entryPoint: string, onProgressUpdate?: ((progress: number) => void) | undefined, options?: Options) => Promise<string>;
11
- export {};
10
+ export declare const getConfig: ({ entryPoint, outDir, resolvedRemotionRoot, onProgressUpdate, options, }: {
11
+ outDir: string;
12
+ entryPoint: string;
13
+ resolvedRemotionRoot: string;
14
+ onProgressUpdate?: ((progress: number) => void) | undefined;
15
+ options?: BundleOptions | undefined;
16
+ }) => [string, webpack.Configuration];
17
+ export declare const bundle: (entryPoint: string, onProgressUpdate?: ((progress: number) => void) | undefined, options?: BundleOptions) => Promise<string>;
package/dist/bundle.js CHANGED
@@ -7,9 +7,9 @@ exports.bundle = exports.getConfig = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const path_1 = __importDefault(require("path"));
10
- const remotion_1 = require("remotion");
11
10
  const util_1 = require("util");
12
11
  const webpack_1 = __importDefault(require("webpack"));
12
+ const worker_threads_1 = require("worker_threads");
13
13
  const copy_dir_1 = require("./copy-dir");
14
14
  const index_html_1 = require("./index-html");
15
15
  const webpack_config_1 = require("./webpack-config");
@@ -34,28 +34,46 @@ const trimTrailingSlash = (p) => {
34
34
  }
35
35
  return p;
36
36
  };
37
- const getConfig = (outDir, entryPoint, onProgressUpdate, options) => {
37
+ const getConfig = ({ entryPoint, outDir, resolvedRemotionRoot, onProgressUpdate, options, }) => {
38
38
  var _a, _b;
39
39
  return (0, webpack_config_1.webpackConfig)({
40
40
  entry,
41
41
  userDefinedComponent: entryPoint,
42
42
  outDir,
43
43
  environment: 'production',
44
- webpackOverride: (_a = options === null || options === void 0 ? void 0 : options.webpackOverride) !== null && _a !== void 0 ? _a : remotion_1.Internals.defaultOverrideFunction,
44
+ webpackOverride: (_a = options === null || options === void 0 ? void 0 : options.webpackOverride) !== null && _a !== void 0 ? _a : ((f) => f),
45
45
  onProgressUpdate,
46
- enableCaching: (_b = options === null || options === void 0 ? void 0 : options.enableCaching) !== null && _b !== void 0 ? _b : remotion_1.Internals.DEFAULT_WEBPACK_CACHE_ENABLED,
46
+ enableCaching: (_b = options === null || options === void 0 ? void 0 : options.enableCaching) !== null && _b !== void 0 ? _b : true,
47
47
  maxTimelineTracks: 15,
48
48
  // For production, the variables are set dynamically
49
49
  envVariables: {},
50
50
  entryPoints: [],
51
+ remotionRoot: resolvedRemotionRoot,
51
52
  });
52
53
  };
53
54
  exports.getConfig = getConfig;
54
55
  const bundle = async (entryPoint, onProgressUpdate, options) => {
55
- var _a, _b;
56
- const outDir = await prepareOutDir((_a = options === null || options === void 0 ? void 0 : options.outDir) !== null && _a !== void 0 ? _a : null);
57
- const [, config] = (0, exports.getConfig)(outDir, entryPoint, onProgressUpdate, options);
56
+ var _a, _b, _c;
57
+ const resolvedRemotionRoot = (_a = options === null || options === void 0 ? void 0 : options.rootDir) !== null && _a !== void 0 ? _a : process.cwd();
58
+ const outDir = await prepareOutDir((_b = options === null || options === void 0 ? void 0 : options.outDir) !== null && _b !== void 0 ? _b : null);
59
+ // The config might use an override which might use
60
+ // `process.cwd()`. The context should always be the Remotion root.
61
+ // This is not supported in worker threads (used for tests)
62
+ const currentCwd = process.cwd();
63
+ if (worker_threads_1.isMainThread) {
64
+ process.chdir(resolvedRemotionRoot);
65
+ }
66
+ const [, config] = (0, exports.getConfig)({
67
+ outDir,
68
+ entryPoint,
69
+ resolvedRemotionRoot,
70
+ onProgressUpdate,
71
+ options,
72
+ });
58
73
  const output = await promisified([config]);
74
+ if (worker_threads_1.isMainThread) {
75
+ process.chdir(currentCwd);
76
+ }
59
77
  if (!output) {
60
78
  throw new Error('Expected webpack output');
61
79
  }
@@ -63,17 +81,24 @@ const bundle = async (entryPoint, onProgressUpdate, options) => {
63
81
  if (errors !== undefined && errors.length > 0) {
64
82
  throw new Error(errors[0].message + '\n' + errors[0].details);
65
83
  }
66
- const baseDir = (_b = options === null || options === void 0 ? void 0 : options.publicPath) !== null && _b !== void 0 ? _b : '/';
67
- const publicDir = '/' +
84
+ const baseDir = (_c = options === null || options === void 0 ? void 0 : options.publicPath) !== null && _c !== void 0 ? _c : '/';
85
+ const staticHash = '/' +
68
86
  [trimTrailingSlash(trimLeadingSlash(baseDir)), 'public']
69
87
  .filter(Boolean)
70
88
  .join('/');
71
- const from = path_1.default.join(process.cwd(), 'public');
89
+ // TODO: Unhardcode public directory
90
+ const from = path_1.default.join(resolvedRemotionRoot, 'public');
72
91
  const to = path_1.default.join(outDir, 'public');
73
92
  if (fs_1.default.existsSync(from)) {
74
93
  await (0, copy_dir_1.copyDir)(from, to);
75
94
  }
76
- const html = (0, index_html_1.indexHtml)(publicDir, baseDir, null, null);
95
+ const html = (0, index_html_1.indexHtml)({
96
+ staticHash,
97
+ baseDir,
98
+ editorName: null,
99
+ inputProps: null,
100
+ remotionRoot: resolvedRemotionRoot,
101
+ });
77
102
  fs_1.default.writeFileSync(path_1.default.join(outDir, 'index.html'), html);
78
103
  return outDir;
79
104
  };
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const esbuild_1 = require("esbuild");
7
7
  const path_1 = __importDefault(require("path"));
8
- const tsConfigPath = path_1.default.join(process.cwd(), 'tsconfig.json');
9
8
  const isTsExtensionPtrn = /\.ts$/i;
10
9
  const isTypescriptInstalled = () => {
11
10
  try {
@@ -22,6 +21,7 @@ async function ESBuildLoader(source) {
22
21
  this.getOptions();
23
22
  const options = this.getOptions();
24
23
  const { implementation, ...esbuildTransformOptions } = options;
24
+ const tsConfigPath = path_1.default.join(this.context, 'tsconfig.json');
25
25
  if (implementation && typeof implementation.transform !== 'function') {
26
26
  done(new TypeError(`esbuild-loader: options.implementation.transform must be an ESBuild transform function. Received ${typeof implementation.transform}`));
27
27
  return;
@@ -1 +1,7 @@
1
- export declare const indexHtml: (staticHash: string, baseDir: string, editorName: string | null, inputProps: object | null) => string;
1
+ export declare const indexHtml: ({ baseDir, editorName, inputProps, staticHash, remotionRoot, }: {
2
+ staticHash: string;
3
+ baseDir: string;
4
+ editorName: string | null;
5
+ inputProps: object | null;
6
+ remotionRoot: string;
7
+ }) => string;
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.indexHtml = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
- const indexHtml = (staticHash, baseDir, editorName, inputProps) => `
8
+ const indexHtml = ({ baseDir, editorName, inputProps, staticHash, remotionRoot, }) => `
9
9
  <!DOCTYPE html>
10
10
  <html lang="en">
11
11
  <head>
@@ -22,8 +22,8 @@ const indexHtml = (staticHash, baseDir, editorName, inputProps) => `
22
22
  ${editorName
23
23
  ? `<script>window.remotion_editorName = "${editorName}";</script>`
24
24
  : '<script>window.remotion_editorName = null;</script>'}
25
- <script>window.remotion_projectName = ${JSON.stringify(path_1.default.basename(process.cwd()))};</script>
26
- <script>window.remotion_cwd = ${JSON.stringify(process.cwd())};</script>
25
+ <script>window.remotion_projectName = ${JSON.stringify(path_1.default.basename(remotionRoot))};</script>
26
+ <script>window.remotion_cwd = ${JSON.stringify(remotionRoot)};</script>
27
27
  ${inputProps
28
28
  ? ` <script>window.remotion_inputProps = ${JSON.stringify(JSON.stringify(inputProps))};</script>
29
29
  `
package/dist/index.d.ts CHANGED
@@ -2,27 +2,36 @@ import esbuild = require('esbuild');
2
2
  import webpack = require('webpack');
3
3
  export declare const BundlerInternals: {
4
4
  esbuild: typeof esbuild;
5
- webpackConfig: ({ entry, userDefinedComponent, outDir, environment, webpackOverride, onProgressUpdate, enableCaching, envVariables, maxTimelineTracks, entryPoints, }: {
5
+ webpackConfig: ({ entry, userDefinedComponent, outDir, environment, webpackOverride, onProgressUpdate, enableCaching, envVariables, maxTimelineTracks, entryPoints, remotionRoot, }: {
6
6
  entry: string;
7
7
  userDefinedComponent: string;
8
8
  outDir: string;
9
9
  environment: "development" | "production";
10
- webpackOverride: import("remotion").WebpackOverrideFn;
10
+ webpackOverride: import("remotion/dist/internals").WebpackOverrideFn;
11
11
  onProgressUpdate?: ((f: number) => void) | undefined;
12
12
  enableCaching?: boolean | undefined;
13
13
  envVariables: Record<string, string>;
14
14
  maxTimelineTracks: number;
15
15
  entryPoints: string[];
16
+ remotionRoot: string;
17
+ }) => [string, webpack.Configuration];
18
+ indexHtml: ({ baseDir, editorName, inputProps, staticHash, remotionRoot, }: {
19
+ staticHash: string;
20
+ baseDir: string;
21
+ editorName: string | null;
22
+ inputProps: object | null;
23
+ remotionRoot: string;
24
+ }) => string;
25
+ cacheExists: (remotionRoot: string, environment: "development" | "production", hash: string) => "exists" | "other-exists" | "does-not-exist";
26
+ clearCache: (remotionRoot: string) => Promise<void>;
27
+ getConfig: ({ entryPoint, outDir, resolvedRemotionRoot, onProgressUpdate, options, }: {
28
+ outDir: string;
29
+ entryPoint: string;
30
+ resolvedRemotionRoot: string;
31
+ onProgressUpdate?: ((progress: number) => void) | undefined;
32
+ options?: import("./bundle").BundleOptions | undefined;
16
33
  }) => [string, webpack.Configuration];
17
- indexHtml: (staticHash: string, baseDir: string, editorName: string | null, inputProps: object | null) => string;
18
- cacheExists: (environment: "development" | "production", hash: string) => "exists" | "other-exists" | "does-not-exist";
19
- clearCache: () => Promise<void>;
20
- getConfig: (outDir: string, entryPoint: string, onProgressUpdate?: ((progress: number) => void) | undefined, options?: {
21
- webpackOverride?: import("remotion").WebpackOverrideFn | undefined;
22
- outDir?: string | undefined;
23
- enableCaching?: boolean | undefined;
24
- publicPath?: string | undefined;
25
- } | undefined) => [string, webpack.Configuration];
26
34
  };
27
- export { bundle } from './bundle';
35
+ export { bundle, BundleOptions } from './bundle';
28
36
  export { webpack };
37
+ export declare type WebpackConfiguration = webpack.Configuration;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const remotion_1 = require("remotion");
4
4
  remotion_1.Internals.setupEnvVariables();
5
- remotion_1.Internals.setupPuppeteerTimeout();
6
5
  remotion_1.Internals.CSSUtils.injectCSS(`
7
6
  .css-reset * {
8
7
  font-size: 16px;
@@ -7,7 +7,7 @@ declare global {
7
7
  }
8
8
  }
9
9
  }
10
- export declare const clearCache: () => Promise<void>;
10
+ export declare const clearCache: (remotionRoot: string) => Promise<void>;
11
11
  export declare const getWebpackCacheName: (environment: Environment, hash: string) => string;
12
- export declare const cacheExists: (environment: Environment, hash: string) => CacheState;
12
+ export declare const cacheExists: (remotionRoot: string, environment: Environment, hash: string) => CacheState;
13
13
  export {};
@@ -8,9 +8,8 @@ const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  // Inlined from https://github.com/webpack/webpack/blob/4c2ee7a4ddb8db2362ca83b6c4190523387ba7ee/lib/config/defaults.js#L265
10
10
  // An algorithm to determine where Webpack will cache the depencies
11
- const getWebpackCacheDir = () => {
12
- const cwd = process.cwd();
13
- let dir = cwd;
11
+ const getWebpackCacheDir = (remotionRoot) => {
12
+ let dir = remotionRoot;
14
13
  for (;;) {
15
14
  try {
16
15
  if (fs_1.default.statSync(path_1.default.join(dir, 'package.json')).isFile()) {
@@ -27,7 +26,7 @@ const getWebpackCacheDir = () => {
27
26
  dir = parent;
28
27
  }
29
28
  if (!dir) {
30
- return path_1.default.resolve(cwd, '.cache/webpack');
29
+ return path_1.default.resolve(remotionRoot, '.cache/webpack');
31
30
  }
32
31
  if (process.versions.pnp === '1') {
33
32
  return path_1.default.resolve(dir, '.pnp/.cache/webpack');
@@ -37,12 +36,12 @@ const getWebpackCacheDir = () => {
37
36
  }
38
37
  return path_1.default.resolve(dir, 'node_modules/.cache/webpack');
39
38
  };
40
- const remotionCacheLocation = (environment, hash) => {
41
- return path_1.default.join(getWebpackCacheDir(), (0, exports.getWebpackCacheName)(environment, hash));
39
+ const remotionCacheLocation = (remotionRoot, environment, hash) => {
40
+ return path_1.default.join(getWebpackCacheDir(remotionRoot), (0, exports.getWebpackCacheName)(environment, hash));
42
41
  };
43
- const clearCache = () => {
42
+ const clearCache = (remotionRoot) => {
44
43
  var _a;
45
- return ((_a = fs_1.default.promises.rm) !== null && _a !== void 0 ? _a : fs_1.default.promises.rmdir)(getWebpackCacheDir(), {
44
+ return ((_a = fs_1.default.promises.rm) !== null && _a !== void 0 ? _a : fs_1.default.promises.rmdir)(getWebpackCacheDir(remotionRoot), {
46
45
  recursive: true,
47
46
  });
48
47
  };
@@ -59,8 +58,8 @@ const getWebpackCacheName = (environment, hash) => {
59
58
  return `${getPrefix(environment)}-${hash}`;
60
59
  };
61
60
  exports.getWebpackCacheName = getWebpackCacheName;
62
- const hasOtherCache = (environment) => {
63
- const cacheDir = fs_1.default.readdirSync(getWebpackCacheDir());
61
+ const hasOtherCache = ({ remotionRoot, environment, }) => {
62
+ const cacheDir = fs_1.default.readdirSync(getWebpackCacheDir(remotionRoot));
64
63
  if (cacheDir.find((c) => {
65
64
  return c.startsWith(getPrefix(environment));
66
65
  })) {
@@ -68,14 +67,14 @@ const hasOtherCache = (environment) => {
68
67
  }
69
68
  return false;
70
69
  };
71
- const cacheExists = (environment, hash) => {
72
- if (fs_1.default.existsSync(remotionCacheLocation(environment, hash))) {
70
+ const cacheExists = (remotionRoot, environment, hash) => {
71
+ if (fs_1.default.existsSync(remotionCacheLocation(remotionRoot, environment, hash))) {
73
72
  return 'exists';
74
73
  }
75
- if (!fs_1.default.existsSync(getWebpackCacheDir())) {
74
+ if (!fs_1.default.existsSync(getWebpackCacheDir(remotionRoot))) {
76
75
  return 'does-not-exist';
77
76
  }
78
- if (hasOtherCache(environment)) {
77
+ if (hasOtherCache({ remotionRoot, environment })) {
79
78
  return 'other-exists';
80
79
  }
81
80
  return 'does-not-exist';
@@ -1,5 +1,5 @@
1
1
  import type { WebpackConfiguration, WebpackOverrideFn } from 'remotion';
2
- export declare const webpackConfig: ({ entry, userDefinedComponent, outDir, environment, webpackOverride, onProgressUpdate, enableCaching, envVariables, maxTimelineTracks, entryPoints, }: {
2
+ export declare const webpackConfig: ({ entry, userDefinedComponent, outDir, environment, webpackOverride, onProgressUpdate, enableCaching, envVariables, maxTimelineTracks, entryPoints, remotionRoot, }: {
3
3
  entry: string;
4
4
  userDefinedComponent: string;
5
5
  outDir: string;
@@ -10,4 +10,5 @@ export declare const webpackConfig: ({ entry, userDefinedComponent, outDir, envi
10
10
  envVariables: Record<string, string>;
11
11
  maxTimelineTracks: number;
12
12
  entryPoints: string[];
13
+ remotionRoot: string;
13
14
  }) => [string, WebpackConfiguration];
@@ -50,7 +50,7 @@ const esbuildLoaderOptions = {
50
50
  function truthy(value) {
51
51
  return Boolean(value);
52
52
  }
53
- const webpackConfig = ({ entry, userDefinedComponent, outDir, environment, webpackOverride = (f) => f, onProgressUpdate, enableCaching = remotion_1.Internals.DEFAULT_WEBPACK_CACHE_ENABLED, envVariables, maxTimelineTracks, entryPoints, }) => {
53
+ const webpackConfig = ({ entry, userDefinedComponent, outDir, environment, webpackOverride = (f) => f, onProgressUpdate, enableCaching = true, envVariables, maxTimelineTracks, entryPoints, remotionRoot, }) => {
54
54
  const conf = webpackOverride({
55
55
  optimization: {
56
56
  minimize: false,
@@ -183,6 +183,7 @@ const webpackConfig = ({ entry, userDefinedComponent, outDir, environment, webpa
183
183
  ...conf.output,
184
184
  path: outDir,
185
185
  },
186
+ context: remotionRoot,
186
187
  },
187
188
  ];
188
189
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/bundler",
3
- "version": "3.1.6",
3
+ "version": "3.1.7",
4
4
  "description": "Bundler for Remotion",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,
@@ -26,7 +26,7 @@
26
26
  "css-loader": "5.2.7",
27
27
  "esbuild": "0.14.19",
28
28
  "react-refresh": "0.9.0",
29
- "remotion": "3.1.6",
29
+ "remotion": "3.1.7",
30
30
  "style-loader": "2.0.0",
31
31
  "webpack": "5.72.0"
32
32
  },
@@ -63,5 +63,5 @@
63
63
  "publishConfig": {
64
64
  "access": "public"
65
65
  },
66
- "gitHead": "188460243a533e1511b3f83fa8c77cd4c445553d"
66
+ "gitHead": "599379fef6043a7125d1979766f915580ec1cf77"
67
67
  }