Skip to content

🎥 Make videos programmatically with React

require

Jonny Burger108a4f102d6f
diff --git a/packages/.monorepo/builder.ts b/packages/.monorepo/builder.ts
index 792cac99ff..918961009a 100644
--- a/packages/.monorepo/builder.ts
+++ b/packages/.monorepo/builder.ts
@@ -27,59 +27,82 @@ const sortObject = (obj: Record<string, string>) => {
};
};
+type FormatAction = 'do-nothing' | 'build' | 'use-tsc';
+
export const buildPackage = async ({
formats,
external,
target,
entrypoints,
}: {
- formats: Format[];
+ formats: {
+ esm: FormatAction;
+ cjs: FormatAction;
+ };
external: 'dependencies' | string[];
target: 'node' | 'browser';
entrypoints: string[];
}) => {
- console.time(`Generated ${formats.join(', ')}.`);
+ console.time(`Generated.`);
const pkg = await Bun.file(path.join(process.cwd(), 'package.json')).json();
const newExports = {};
const versions = {};
- for (const format of formats) {
- const output = await build({
- entrypoints: entrypoints.map((e) => path.join(process.cwd(), e)),
- naming: `[name].${format === 'esm' ? 'mjs' : 'js'}`,
- external: getExternal(external),
- target,
- format,
- });
+ const firstNames = entrypoints.map((e) => {
+ const splittedBySlash = e.split('/');
+ const last = splittedBySlash[splittedBySlash.length - 1];
+ return last.split('.')[0];
+ });
+
+ for (const format of ['cjs', 'esm'] as Format[]) {
+ const action = formats[format];
+ if (action === 'do-nothing') {
+ continue;
+ } else if (action === 'use-tsc') {
+ } else if (action === 'build') {
+ const output = await build({
+ entrypoints: entrypoints.map((e) => path.join(process.cwd(), e)),
+ naming: `[name].${format === 'esm' ? 'mjs' : 'js'}`,
+ external: getExternal(external),
+ target,
+ format,
+ });
- for (const file of output.outputs) {
- const text = await file.text();
+ for (const file of output.outputs) {
+ const text = await file.text();
- const outputPath = `./${path.join('./dist', format, file.path)}`;
+ const outputPath = `./${path.join('./dist', format, file.path)}`;
- await Bun.write(path.join(process.cwd(), outputPath), text);
+ await Bun.write(path.join(process.cwd(), outputPath), text);
- if (text.includes('jonathanburger')) {
- throw new Error('Absolute path was included, see ' + outputPath);
+ if (text.includes('jonathanburger')) {
+ throw new Error('Absolute path was included, see ' + outputPath);
+ }
}
+ }
- const firstName = file.path.split('.')[1].slice(1);
+ for (const firstName of firstNames) {
const exportName = firstName === 'index' ? '.' : './' + firstName;
+ const outputName =
+ action === 'use-tsc'
+ ? `./dist/${firstName}.js`
+ : `./dist/${format}/${firstName}.${format === 'cjs' ? 'js' : 'mjs'}`;
newExports[exportName] = sortObject({
types: `./dist/${firstName}.d.ts`,
...(format === 'cjs'
? {
- require: outputPath,
+ require: outputName,
}
: {}),
...(format === 'esm'
? {
- import: outputPath,
- module: outputPath,
+ import: outputName,
+ module: outputName,
}
: {}),
...(newExports[exportName] ?? {}),
});
+
if (firstName !== 'index') {
versions[firstName] = [`dist/${firstName}.d.ts`];
}
@@ -100,5 +123,5 @@ export const buildPackage = async ({
'\t',
) + '\n',
);
- console.timeEnd(`Generated ${formats.join(', ')}.`);
+ console.timeEnd(`Generated.`);
};
diff --git a/packages/eslint-plugin/bundle.ts b/packages/eslint-plugin/bundle.ts
index 2d3b5d39a0..963d906f03 100644
--- a/packages/eslint-plugin/bundle.ts
+++ b/packages/eslint-plugin/bundle.ts
@@ -1,7 +1,10 @@
import {buildPackage} from '../.monorepo/builder';
await buildPackage({
- formats: ['cjs', 'esm'],
+ formats: {
+ cjs: 'build',
+ esm: 'build',
+ },
external: ['@typescript-eslint/utils'],
target: 'node',
entrypoints: ['src/index.ts'],
diff --git a/packages/lambda-client/bundle.ts b/packages/lambda-client/bundle.ts
index dacec41c63..486c75bbe4 100644
--- a/packages/lambda-client/bundle.ts
+++ b/packages/lambda-client/bundle.ts
@@ -1,7 +1,10 @@
import {buildPackage} from '../.monorepo/builder';
await buildPackage({
- formats: ['cjs', 'esm'],
+ formats: {
+ cjs: 'use-tsc',
+ esm: 'build',
+ },
external: 'dependencies',
target: 'node',
entrypoints: ['src/index.ts', 'src/constants.ts', 'src/regions.ts'],
diff --git a/packages/lambda-client/package.json b/packages/lambda-client/package.json
index 0de79c281a..594504bed7 100644
--- a/packages/lambda-client/package.json
+++ b/packages/lambda-client/package.json
@@ -41,19 +41,19 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
- "require": "./dist/cjs/index.js",
+ "require": "./dist/index.js",
"module": "./dist/esm/index.mjs",
"import": "./dist/esm/index.mjs"
},
"./constants": {
"types": "./dist/constants.d.ts",
- "require": "./dist/cjs/constants.js",
+ "require": "./dist/constants.js",
"module": "./dist/esm/constants.mjs",
"import": "./dist/esm/constants.mjs"
},
"./regions": {
"types": "./dist/regions.d.ts",
- "require": "./dist/cjs/regions.js",
+ "require": "./dist/regions.js",
"module": "./dist/esm/regions.mjs",
"import": "./dist/esm/regions.mjs"
}
diff --git a/packages/serverless-client/bundle.ts b/packages/serverless-client/bundle.ts
index 040852e379..df3f2f9290 100644
--- a/packages/serverless-client/bundle.ts
+++ b/packages/serverless-client/bundle.ts
@@ -1,7 +1,10 @@
import {buildPackage} from '../.monorepo/builder';
await buildPackage({
- formats: ['cjs', 'esm'],
+ formats: {
+ cjs: 'use-tsc',
+ esm: 'build',
+ },
external: [],
target: 'node',
entrypoints: ['src/index.ts'],
diff --git a/packages/serverless-client/package.json b/packages/serverless-client/package.json
index f4aef0ff5d..e49a1841be 100644
--- a/packages/serverless-client/package.json
+++ b/packages/serverless-client/package.json
@@ -33,7 +33,7 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
- "require": "./dist/cjs/index.js",
+ "require": "./dist/index.js",
"module": "./dist/esm/index.mjs",
"import": "./dist/esm/index.mjs"
}