Skip to content

🎥 Make videos programmatically with React

`create-video`: Respect npm registry configuration instead of hardcoding registry.npmjs.org

Boseok Kang08d0da99c97c
diff --git a/packages/create-video/src/latest-remotion-version.ts b/packages/create-video/src/latest-remotion-version.ts
index eeadbbd9b1..95e887f39d 100644
--- a/packages/create-video/src/latest-remotion-version.ts
+++ b/packages/create-video/src/latest-remotion-version.ts
@@ -1,9 +1,35 @@
-import http from 'https';
+import {execSync} from 'node:child_process';
+import http from 'node:http';
+import https from 'node:https';
+
+const DEFAULT_REGISTRY = 'https://registry.npmjs.org';
+
+const getRegistry = (): string => {
+ try {
+ const registry = execSync('npm config get registry', {
+ encoding: 'utf-8',
+ timeout: 10_000,
+ stdio: ['pipe', 'pipe', 'pipe'],
+ }).trim();
+
+ if (registry && registry !== 'undefined') {
+ return registry.replace(/\/$/, '');
+ }
+ } catch {
+ // Fall through to default
+ }
+
+ return DEFAULT_REGISTRY;
+};
const getPackageJsonForRemotion = (): Promise<string> => {
+ const registry = getRegistry();
+ const url = `${registry}/remotion`;
+ const client = url.startsWith('https') ? https : http;
+
return new Promise<string>((resolve, reject) => {
- const req = http.get(
- 'https://registry.npmjs.org/remotion',
+ const req = client.get(
+ url,
{
headers: {
accept:
@@ -31,5 +57,15 @@ const getPackageJsonForRemotion = (): Promise<string> => {
export const getLatestRemotionVersion = async () => {
const pkgJson = await getPackageJsonForRemotion();
- return JSON.parse(pkgJson)['dist-tags'].latest;
+ try {
+ return JSON.parse(pkgJson)['dist-tags'].latest;
+ } catch {
+ const registry = getRegistry();
+ throw new Error(
+ `Failed to fetch the latest Remotion version from ${registry}. ` +
+ `The response was not valid JSON. ` +
+ `If you are behind a corporate proxy, make sure your npm registry is configured correctly ` +
+ `(npm config set registry <your-registry-url>).`,
+ );
+ }
};