Skip to content

Commit

Permalink
Fix isomorphic build (#1367)
Browse files Browse the repository at this point in the history
* Fix isomorphic build

* Prettify

* Bump

* Prettify
  • Loading branch information
lukecaan authored Dec 10, 2024
1 parent 2992c6c commit cf7c198
Showing 1 changed file with 51 additions and 28 deletions.
79 changes: 51 additions & 28 deletions sdk/scripts/postbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,75 @@ environments.forEach((environment) => {
console.log(``);

isomorphicPackages.forEach((package) => {
const isomorphPath = path.join(

// We want to overwrite the base isomorphic files (the "target" files) with the concrete implementation code and definition files (the "source" files).

const isomorphicFolderPath = path.join(
__dirname,
'..',
'lib',
environment,
'isomorphic',
package + '.js'
'isomorphic'
);

const targetEnv = forceEnv ? forceEnv : environment;

const targetPath = path.join(
__dirname,
'..',
'lib',
environment,
'isomorphic',
`${package}.${targetEnv}.js`
);
const filesToSwap = [
{
source: `${package}.${targetEnv}.js`,
target: `${package}.js`,
},
{
source: `${package}.${targetEnv}.d.ts`,
target: `${package}.d.ts`,
},
];

try {
const content = fs.readFileSync(targetPath, 'utf8');
fs.writeFileSync(isomorphPath, content);
} catch (error) {
console.error(
`Error processing isomophic package : ${package} :: ${error.message}`
for (const file of filesToSwap) {
const sourcePath = path.join(
isomorphicFolderPath,
file.source
);

const targetPath = path.join(
isomorphicFolderPath,
file.target
);

try {
const sourceContent = fs.readFileSync(sourcePath, 'utf8');
fs.writeFileSync(targetPath, sourceContent);
} catch (error) {
console.error(
`Error processing isomophic package : ${package} :: ${error.message}`
);
}
}

// Delete other environment files for safety
environments.forEach((otherEnvironment) => {
if (otherEnvironment === environment) {
if (otherEnvironment === targetEnv) {
return;
}

const otherTargetPath = path.join(
__dirname,
'..',
'lib',
environment,
'isomorphic',
`${package}.${otherEnvironment}.js`
);
const otherTargetFiles = [
`${package}.${otherEnvironment}.js`,
`${package}.${otherEnvironment}.d.ts`,
];

for (const otherTargetFile of otherTargetFiles) {
const otherTargetPath = path.join(
__dirname,
'..',
'lib',
environment,
'isomorphic',
otherTargetFile
);

if (fs.existsSync(otherTargetPath)) {
fs.unlinkSync(otherTargetPath);
if (fs.existsSync(otherTargetPath)) {
fs.unlinkSync(otherTargetPath);
}
}
});
});
Expand Down

0 comments on commit cf7c198

Please sign in to comment.