Shoutout to @User for guiding me on the importance of adhering to the guidelines for publishing types
Here's a breakdown:
I structured my development code in the src
folder and built code in the build
folder using tsc
The contents of tsconfig.json
are as follows:
{
/* Visit https://aka.ms/tsconfig to read more about this file */
"compilerOptions": {
/* Language and Environment */
"target": "es5",
"lib": ["es6"],
"experimentalDecorators": true,
/* Modules */
"module": "commonjs",
"moduleResolution": "node",
"baseUrl": "./src",
"rootDir": "./src",
"types": ["node"],
"resolveJsonModule": true,
"declaration": true,
/* JavaScript Support */
"allowJs": true,
/* Emit */
"sourceMap": true,
"outDir": "build",
"removeComments": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
/* Type Checking */
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"useUnknownInCatchVariables": false
},
"ts-node": {
"files": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
- The
package.json
must define the following values:
{
...
"main": "build/index.js",
"types": "build/index.d.ts",
...
}
- I utilized the ctix module for automatically generating an index file with exports.
In the project's root directory, I included a .ctic
file with the specified content:
// common configuration
// tsconfig.json path: you must pass path with filename, like this "./tsconfig.json"
"project": "./tsconfig.json",
// create, single command configuration
// add ctix comment at first line of creted index.ts file, that remark created from ctix
"useSemicolon": true,
// timestamp write on ctix comment right-side, only works in useComment option set true
"useTimestamp": false,
// add ctix comment at first line of creted index.ts file, that remark created from ctix
"useComment": true,
// quote mark " or '
"quote": "'",
// overwrite index.ts file also index.ts file already exist that create backup file
"overwrite": true,
// keep file extension in export statement path
"keepFileExt": false,
// only create command configuration
// If set true this option, skip empty directory
"skipEmptyDir": true,
// only single command configuration
// Output directory. It works only single mode.
"output": "./src",
// Use rootDir or rootDirs configuration in tsconfig.json.
"useRootDir": false,
// only remove command configuration
// remove with backup file
"includeBackup": true
}
Included in package.json
is the script:
{
...
"scripts": {
...
"build": "ctix single && npm run clean && tsc --build",
"clean": "rm -fr build",
...
}
...
}
- To apply these changes, execute
npm run build
Subsequently, commit and push your code to git along with the build folder