ck-node24-wrapper
v1.0.3
Published
A wrapper NPM module to abstract os-specific dependencies on @chilkat/ck-node24-* modules
Readme
A Wrapper NPM module to abstract os-specific dependencies on the NodeJS Chilkat libraries (@chilkat/ck-node24*).
About The Project
This is a node module to provide an os-independent wrapper for the os-specific @chilkat/ck-node24-* modules.
So you can have this:
With Wrapper:
import chilkat from "ck-node24-wrapper";
Instead of this:
Without Wrapper:
const os = require('os'); let chilkat; if (os.platform() == 'win32') { if (os.arch() == 'ia32') { chilkat = require('@chilkat/ck-node11-win-ia32'); } else { chilkat = require('@chilkat/ck-node11-win64'); } } else if (os.platform() == 'linux') { if (os.arch() == 'arm') { chilkat = require('@chilkat/ck-node11-arm'); } else if (os.arch() == 'x86') { chilkat = require('@chilkat/ck-node11-linux32'); } else { chilkat = require('@chilkat/ck-node11-linux64'); } } else if (os.platform() == 'darwin') { chilkat = require('@chilkat/ck-node11-macosx'); }
It requires nodejs 24 or later.
NOTE : This is an ESM-only module.
Built With
Getting Started
Install this module into your project directory:
npm install ck-node24-wrapper --saveAdd ck-install as a "prepare" script in your package.json:
"scripts": {
"prepare": "ck-install"
}Then import the module in your code:
import chilkat from "ck-node24-wrapper";and use the chilkat object as you would normally; e.g.:
import chilkat from "ck-node24-wrapper";
const cert = new chilkat.Cert();
// Load any type of certificate (.cer, .p7b, .pem, etc.) by calling LoadFromFile.
const success = cert.LoadFromFile("qa_data/certs/sample_cert_a.cer");
if (success) {
console.log("SubjectDN:" + cert.SubjectDN);
console.log("Common Name:" + cert.SubjectCN);
console.log("Issuer Common Name:" + cert.IssuerCN);
console.log("Serial Number:" + cert.SerialNumber);
console.log(cert.ExportCertPem());
} else {
console.error("failed to load cert");
}Issues When Updating Other Packages
When you use NPM (and probably yarn, pnpm etc) to add or update your dependencies, the package manager unfortunately will automatically remove your os-dependent installation of the chilkat library.
If that has happened, then when you run your program you'll see an error like this:
Error: Cannot find module '@chilkat/ck-node24-mac-universal'This happens because this wrapper installs the appropriate library using the --no-save flag, which means that the package manager (NPM) will not add the library to your package.json file. Then, when the package manager performs another update, it notices the installed library that isn't in the package.json file, and removes it.
This wrapper avoids updating your package.json file, and does not make the assumption that your deployment OS environment is the same as your development OS environment (or even that you are using NPM to manage your other packages).
For example, you might be:
- Authoring a NodeJS package that uses this wrapper. In that case, you want the consumers of your package to download the appropriate chilkat library for their environment. So
you don't want the os-specific chilkat library in the
dependenciessection of yourpackage.json. - Bundling a server application using webpack, parcel, tar, zip or some other packaging tool. The target environment might be different from your development environment, so
we want the chilkat installer to run (via
npm ci) in the target environment. For example, if your development machine is MacOS and your target machine is Linux, we don't want to include the @chilkat/ck-node24-mac-universal library and omit the appropriate linux one.
Solutions
Solution 1: Manually use the prepare script
If you've added a "prepare" script as per the Getting Started section, then you can rerun the ck-install script manually:
npm run prepareSolution 2: Use the --save-optional flag
You can explicitly add the os-specific dependency for use on your own machine via the --save-optional flag:
npm install @chilkat/ck-node24-mac-universal --save-optionalThat will add it to the optionalDependencies section of your package.json file, which will prevent the package manager from removing it. This will allow NPM to proceed if installation fails. You should note, however, that consumers of your package will be attempting to install that os-specific chilkat library without necessarily using it.
See the optionalDependencies section of the NPM website for more information.
Roadmap
See the open issues for a full list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Top contributors:
License
Distributed under the MIT. See LICENSE.txt for more information.
Contact
Project Link: https://github.com/cunneen/ck-node24-wrapper
