![New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions](https://cdn.sanity.io/images/cgdhsj6q/production/86e6ebdea652d20da070ebbda20134b839972db7-1024x1024.webp?w=800&fit=max&auto=format)
Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
@saithodev/ts-appversion
Advanced tools
Readme
This package extracts version information from your package.json and Git (if configured) and saves it into a TypeScript file. You can then access that TypeScript file from your application and display the version in your app.
The examples below illustrate the usage of this package for the Angular framework. However it should work similarly for any other JavaScript framework that is using TypeScript.
The package comes with a script that has to be run before your application is built. You might want to use prestart and prebuild inside your package.json for that:
{
scripts: [
"prestart": "ts-appversion",
"start": "ng serve",
"prebuild": "ts-appversion",
"build": "ng build",
]
}
With that setup the file is updated when npm start
and npm build
are run.
Note: You won't be able to run ng build
anymore as the script will not be executed. Use npm build
instead.
Argument | Meaning | Default |
---|---|---|
--root | root directory where your package.json is located | . |
--file | relative location of the output file (based on the root directory) | ./src/_version.ts |
--git | relative location of the folder containing the .git folder (based on the root directory) | . |
--pnpm | PNPM has a different folder structure, resulting in a different root level. Add this if you use PNPM to install your dependencies. If package.json is not found at the expected PNPM path, it will fall back to the default one. This setting is ignored if --root is an absolute path. | false |
The script generates a TypeScript file at the location ./src/_versions.ts
if you haven't provided a different location.
You'll be able to import the values just like any other package:
import versions from '../_versions';
The file will export an object with following variables:
Note: The variables starting with "git" and the variable "versionLong" will only be available for Git repositories.
In some cases it might be better to not display the version number or only the short notation. You can use the environments to display different version informations.
In the following example:
environments/environment.ts
import versions from '../_versions';
export const environment = {
production: false,
version: versions.versionDate,
};
environments/environment.staging.ts
import versions from '../_versions';
export const environment = {
production: false,
version: versions.versionLong,
};
environments/environment.prod.ts
import versions from '../_versions';
export const environment = {
production: true,
version: versions.version,
};
From there you can access the version inside the Component which should display the version, e.g.:
import { Component } from '@angular/core';
import { environment } from '../environments/environment';
@Component({
selector: 'app-root',
template: '{{title}} {{version}}'
})
export class AppComponent {
title = 'app';
version = environment.version ? 'v' + environment.version : '';
}
Check out the example/ directory for a working example Angular application.
FAQs
Reads the version from your packages.json and saves it in a .ts file you can include into your application.
The npm package @saithodev/ts-appversion receives a total of 343 weekly downloads. As such, @saithodev/ts-appversion popularity was classified as not popular.
We found that @saithodev/ts-appversion demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.