Skip to content

🎥 Make videos programmatically with React

tweak bundle command

Jonny Burger9a4e26ae9e89
diff --git a/packages/google-fonts/bundle.ts b/packages/google-fonts/bundle.ts
index 59e0602249..c4b1b1e95a 100644
--- a/packages/google-fonts/bundle.ts
+++ b/packages/google-fonts/bundle.ts
@@ -1,23 +1,19 @@
-// TODO: Not yet used, waiting for Windows support
-// https://github.com/oven-sh/bun/issues/9974
import { build } from "bun";
import path from "path";
import { filteredFonts } from "./scripts/filtered-fonts";
import { removeWhitespace } from "./scripts/utils";
+import { readFileSync, writeFileSync } from "fs";
+import { $ } from "bun";
+import { equal } from "assert";
const output = await build({
- entrypoints: [
- "src/index.ts",
- "src/base.ts",
- ...filteredFonts.map((p) => `src/${removeWhitespace(p.family)}.ts`),
- ],
+ entrypoints: filteredFonts.map((p) => `src/${removeWhitespace(p.family)}.ts`),
external: [
"remotion",
"remotion/no-react",
"react",
"react/jsx-runtime",
"react/jsx-dev-runtime",
- "*",
],
naming: "[name].mjs",
});
@@ -27,11 +23,7 @@ for (const file of output.outputs) {
const newStr = str
.replace(/jsxDEV/g, "jsx")
.replace(/react\/jsx-dev-runtime/g, "react/jsx-runtime")
- .replace(/import\(\"(.*)\"\)/g, 'import("$1.mjs")')
- .replace(
- `import {loadFonts} from "./base";`,
- `import {loadFonts} from "./base.mjs";`
- );
+ .replace(/import\(\"(.*)\"\)/g, 'import("$1.mjs")');
if (newStr.includes(`import("./ABeeZee")`)) {
throw new Error("not compiled correctly");
@@ -39,3 +31,28 @@ for (const file of output.outputs) {
Bun.write(path.join("dist", "esm", file.path), newStr);
}
+
+// Bun does not yet support * external on Windows,
+// so manually making a transpilation
+
+const entry = path.join("src", "index.ts");
+const contents = readFileSync(entry, "utf-8");
+const startMark = contents.indexOf("export const getAvailable");
+if (startMark === -1) {
+ throw new Error("Could not find start mark");
+}
+
+const start = contents.substring(startMark);
+
+const withoutTypes = start.replace(/\sas\sPromise\<GoogleFont\>/g, "");
+
+writeFileSync(path.join("dist", "esm", "index.mjs"), withoutTypes);
+
+// We manually transpiled the script by removing TypeScript types
+
+// Use Node.js because it does not support TypeScript
+// and the goal of this script is to get rid of the TypeScript types
+const length =
+ await $`node --input-type=module -e "import {getAvailableFonts} from './dist/esm/index.mjs'; console.log(getAvailableFonts().length)"`.text();
+
+equal(length.trim(), "1575");
diff --git a/packages/google-fonts/package.json b/packages/google-fonts/package.json
index a8969686fb..03f66988de 100644
--- a/packages/google-fonts/package.json
+++ b/packages/google-fonts/package.json
@@ -5,7 +5,7 @@
"main": "dist/cjs/index.js",
"module": "dist/esm/index.mjs",
"scripts": {
- "build": "pnpm run generate && rollup --config rollup.config.js",
+ "build": "pnpm run generate && bun bundle.ts",
"generate": "bun scripts/generate.ts && bun scripts/generate-index.ts",
"prepublishOnly": "bun ensure-generation.ts"
},
@@ -14,15 +14,12 @@
"remotion": "workspace:*"
},
"devDependencies": {
- "@rollup/plugin-typescript": "^8.2.0",
"@types/css-font-loading-module": "^0.0.7",
"@types/node": "18.14.6",
"@types/prettier": "^2.7.1",
"got": "^11",
"postcss": "^8.4.31",
- "prettier": "3.2.5",
- "rollup": "^2.70.1",
- "ts-node": "10.9.2"
+ "prettier": "3.2.5"
},
"files": [
"dist"
diff --git a/packages/google-fonts/rollup.config.js b/packages/google-fonts/rollup.config.js
deleted file mode 100644
index 9ff84b1c70..0000000000
--- a/packages/google-fonts/rollup.config.js
+++ /dev/null
@@ -1,25 +0,0 @@
-// rollup.config.js
-import typescript from "@rollup/plugin-typescript";
-
-export default [
- {
- input: "src/index.ts",
- output: [
- {
- dir: "dist/esm",
- format: "es",
- sourcemap: false,
- chunkFileNames: `[name].mjs`,
- entryFileNames: `[name].mjs`,
- },
- ],
- external: ["remotion"],
- plugins: [
- typescript({
- tsconfig: "tsconfig-esm.json",
- sourceMap: false,
- outputToFilesystem: true,
- }),
- ],
- },
-];
diff --git a/packages/google-fonts/tsconfig-esm.json b/packages/google-fonts/tsconfig-esm.json
deleted file mode 100644
index a87d2f291c..0000000000
--- a/packages/google-fonts/tsconfig-esm.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "extends": "../tsconfig.settings.json",
- "compilerOptions": {
- "noEmit": true,
- "rootDir": "./src",
- "skipLibCheck": true,
- "noUnusedLocals": true,
- "outDir": "./dist/esm"
- },
- "include": ["./src"],
- "references": [{ "path": "../core" }]
-}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 2bf7703bad..c64ae77d37 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1116,9 +1116,6 @@ importers:
specifier: workspace:*
version: link:../core
devDependencies:
- '@rollup/plugin-typescript':
- specifier: ^8.2.0
'@types/css-font-loading-module':
specifier: ^0.0.7
version: 0.0.7
@@ -1137,12 +1134,6 @@ importers:
prettier:
specifier: 3.2.5
version: 3.2.5
- rollup:
- specifier: ^2.70.1
- version: 2.79.1
- ts-node:
- specifier: 10.9.2
- version: 10.9.2(@types/[email protected])([email protected])
packages/install-whisper-cpp:
dependencies:
@@ -8724,23 +8715,6 @@ packages:
typescript: 5.3.3
dev: true
- resolution: {integrity: sha512-wMv1/scv0m/rXx21wD2IsBbJFba8wGF3ErJIr6IKRfRj49S85Lszbxb4DCo8iILpluTjk2GAAu9CoZt4G3ppgQ==}
- engines: {node: '>=8.0.0'}
- peerDependencies:
- rollup: ^2.14.0
- tslib: '*'
- typescript: '>=3.7.0'
- peerDependenciesMeta:
- tslib:
- optional: true
- dependencies:
- '@rollup/pluginutils': 3.1.0([email protected])
- resolve: 1.22.1
- rollup: 2.79.1
- typescript: 5.3.3
- dev: true
-
resolution: {integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==}
engines: {node: '>= 8.0.0'}
@@ -8753,18 +8727,6 @@ packages:
rollup: 2.76.0
dev: true
- resolution: {integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==}
- engines: {node: '>= 8.0.0'}
- peerDependencies:
- rollup: ^1.20.0||^2.0.0
- dependencies:
- '@types/estree': 0.0.39
- estree-walker: 1.0.1
- picomatch: 2.3.1
- rollup: 2.79.1
- dev: true
-
resolution: {integrity: sha512-YlDNJXTCstlOmyJxeQjaTaef8ACLuEPMDrSgEichQM3ELlWuU1HTSVbpXW2x4LbbEDPXwu/aF/16MUN8pzzcmA==}
hasBin: true