Skip to content

Add support for run-time package version #23

@dmg-aimmerman

Description

@dmg-aimmerman

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}" };`
		);
	}
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions