Skip to content

Commit

Permalink
feat: [DX-3075] Update SDK Bundling process (#2066)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaidarain1 authored Aug 6, 2024
1 parent 46d112b commit 5ffece5
Showing 1 changed file with 39 additions and 27 deletions.
66 changes: 39 additions & 27 deletions sdk/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,41 @@ const getFilesToBuild = () => {
return [...files, ...returnModules];
};

const getFileBuild = (inputFilename) => [
{
input: `./src/${inputFilename}.ts`,
output: {
dir: 'dist',
format: 'es',
},
plugins: [
nodeResolve({
resolveOnly: getPackages(),
}),
json(),
commonJs(),
typescript({
declaration: true,
declarationDir: './dist/types',
}),
replace({
exclude: 'node_modules/**',
preventAssignment: true,
__SDK_VERSION__: pkg.version,
}),
],
},

const buildJS = () => {
const filesToBuild = getFilesToBuild();
// generate a single object that contains all the files under input
const [inputs] = filesToBuild.reduce((acc, f) => {
return [{...acc[0], [f] : `./src/${f}.ts`}]
}, [{}])

return {
input: inputs,
output: {
dir: 'dist',
format: 'es',
},
plugins: [
nodeResolve({
resolveOnly: getPackages(),
}),
json(),
commonJs(),
typescript({
declaration: true,
declarationDir: './dist/types',
}),
replace({
exclude: 'node_modules/**',
preventAssignment: true,
__SDK_VERSION__: pkg.version,
}),
],
external: ['pg']
}
};

const getTypesBuild = (inputFilename) => [
{
input: `./dist/types/${inputFilename}.d.ts`,
output: {
Expand All @@ -84,11 +95,11 @@ const getFileBuild = (inputFilename) => [
},
];

const buildBundles = () => {
const buildTypes = () => {
const modules = [];
const filesToBuild = getFilesToBuild();
for (const file of filesToBuild) {
modules.push(...getFileBuild(file));
modules.push(...getTypesBuild(file));
}
return modules;
};
Expand Down Expand Up @@ -155,5 +166,6 @@ export default [
},

// Export ES Modules
...buildBundles(),
buildJS(),
...buildTypes(),
];

0 comments on commit 5ffece5

Please sign in to comment.