Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
IN-3365 Generate server/index.d.t.s \w typedefs for index.server.ts (#35
Browse files Browse the repository at this point in the history
)

instead of typedefs for index.ts (mismatch)
  • Loading branch information
sethidden authored Sep 19, 2023
1 parent 0904332 commit bbccaa0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/rollup-config/src/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import nodeResolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import commonjs from '@rollup/plugin-commonjs';
import { OutputBundle, OutputOptions } from 'rollup';

const extensions = ['.ts', '.js'];
// TODO add debug mode with advanced sourcemaps
Expand Down Expand Up @@ -29,7 +30,29 @@ export function generateServerConfig(pkg: any) {
}),
nodeResolve({
extensions
})
}),
/**
* output: { file: pkg.server } in this file above always boils down to { file: 'server/index.js' }
*
* The output will be:
* - server/index.js (JS output of compiling index.server.ts, as per "output" property in this file)
* - server/index.d.ts (WRONG! This contains typedefs for the index.ts file, not the index.server.ts file)
* - server/index.server.d.ts (This contains typedefs for index.server.ts, but should be named index.d.ts to match the server/index.js file)
*
* The issue with the above outputs is that importing `@vsf-enterprise/someintegration-api/server` will throw errors,
* because you're using server/index.js with typedefs (server/index.d.ts) of a totally different file
*/
{
name: "RemoveIndexTypedefMismatch",
generateBundle: (options: OutputOptions, bundle: OutputBundle) => {
// these files are for the src/index.ts file, not for src/index.server.ts, so we can remove them.
delete bundle["index.d.ts"];
delete bundle["index.d.ts.map"];
// The object keys being file names is just a decoration, the actual name of the output file is in the .fileName property
bundle["index.server.d.ts"].fileName = "index.d.ts";
bundle["index.server.d.ts.map"].fileName = "index.d.ts.map";
},
},
]
};
}

0 comments on commit bbccaa0

Please sign in to comment.