Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for run-time package version #23

Open
dmg-aimmerman opened this issue Jul 20, 2022 · 0 comments
Open

Add support for run-time package version #23

dmg-aimmerman opened this issue Jul 20, 2022 · 0 comments

Comments

@dmg-aimmerman
Copy link
Contributor

Typically, reading the package.json version is done dynamically. However, in a packaged build that is installed as a node module, it is unfeasible to read the package.json of the package. Add support for compiling the package.json version to the build

Proposed Solution
The user would add a version.ts file to the source folder. This file would dynamically load the package.json for development. The user would also add an entry to their BundleMap to compile the package.version into the output version of this file

src/version.ts

// IMPORTANT: This file will be overridden at compile time
//	to export the current package.json's version as a string,
//	since this package.json won't be loaded dynamically by the
//	translator server. This code is in place for development
import { getPackageJson } from 'ts-packager';

export const version = getPackageJson().version;

ts-package-config.ts

...
export const files: BundleMap = {
	...
	'src/version.ts': (filename: string, outdir: string) => {
		writeFileSync(
			joinPath(outdir, 'version.js'),
			`module.exports = { version: "${getPackageJson().version}" };`
		);
	}
};
dmg-aimmerman added a commit to dmg-aimmerman/ts-packager that referenced this issue Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant