Skip to content

Commit

Permalink
awesome
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBurger committed Feb 8, 2025
1 parent a0cf2b9 commit 958da25
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
41 changes: 23 additions & 18 deletions packages/.monorepo/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,30 @@ const sortObject = (obj: Record<string, string>) => {

type FormatAction = 'do-nothing' | 'build' | 'use-tsc';

type EntryPoint = {
target: 'node' | 'browser';
path: string;
};

export const buildPackage = async ({
formats,
external,
target,
entrypoints,
}: {
formats: {
esm: FormatAction;
cjs: FormatAction;
};
external: 'dependencies' | string[];
target: 'node' | 'browser';
entrypoints: string[];
entrypoints: EntryPoint[];
}) => {
console.time(`Generated.`);
const pkg = await Bun.file(path.join(process.cwd(), 'package.json')).json();
const newExports = {};
const versions = {};

const firstNames = entrypoints.map((e) => {
const splittedBySlash = e.split('/');
const firstNames = entrypoints.map(({path, target}) => {
const splittedBySlash = path.split('/');
const last = splittedBySlash[splittedBySlash.length - 1];
return last.split('.')[0];
});
Expand All @@ -60,23 +63,25 @@ export const buildPackage = async ({
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 {path: p, target} of entrypoints) {
const output = await build({
entrypoints: [p],
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);
}
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions packages/eslint-plugin/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ await buildPackage({
esm: 'build',
},
external: ['@typescript-eslint/utils'],
target: 'node',
entrypoints: ['src/index.ts'],
entrypoints: [
{
path: 'src/index.ts',
target: 'node',
},
],
});
13 changes: 11 additions & 2 deletions packages/lambda-client/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ await buildPackage({
esm: 'build',
},
external: 'dependencies',
target: 'node',
entrypoints: ['src/index.ts', 'src/constants.ts', 'src/regions.ts'],
entrypoints: [
{
path: 'src/index.ts',
target: 'node',
},
{
path: 'src/constants.ts',
target: 'browser',
},
{path: 'src/regions.ts', target: 'browser'},
],
});
8 changes: 6 additions & 2 deletions packages/serverless-client/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ await buildPackage({
esm: 'build',
},
external: [],
target: 'node',
entrypoints: ['src/index.ts'],
entrypoints: [
{
path: 'src/index.ts',
target: 'node',
},
],
});

0 comments on commit 958da25

Please sign in to comment.