fix(exports): Fixed duplicate file compilation in compileGlobStringObject, fixes #1

This commit is contained in:
2025-03-04 19:41:05 +00:00
parent 1f9870ffbb
commit 289421206c
6 changed files with 245 additions and 92 deletions

255
readme.md
View File

@ -1,84 +1,191 @@
# @gitzone/tsbuild
TypeScript nightly to easily make use of latest features
# @git.zone/tsbuild
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@gitzone/tsbuild)
* [gitlab.com (source)](https://gitlab.com/gitzone/tsbuild)
* [github.com (source mirror)](https://github.com/gitzone/tsbuild)
* [docs (typedoc)](https://gitzone.gitlab.io/tsbuild/)
A flexible TypeScript compiler that leverages the latest TypeScript features to streamline your build process.
## Status for master
## Install
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/gitzone/tsbuild/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/gitzone/tsbuild/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@gitzone/tsbuild)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/gitzone/tsbuild)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@gitzone/tsbuild)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@gitzone/tsbuild)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@gitzone/tsbuild)](https://lossless.cloud)
Add `@git.zone/tsbuild` to your project using npm or yarn:
## Usage
Tsn uses the **next** tagged npm version of typescript
```typescript
import * as tsn from 'tsn';
let myGlobStringObject = {
'./myTsFolder/**/*.ts': './myDestinationFolder/',
'./someOtherTsFolder/**/*.ts': './myOtherDestinationFolder/',
};
let tsOptions = {
target: tsn.ScriptTarget.ES2015,
module: tsn.ModuleKind.CommonJS,
};
/*
note: since this only works in code, here are the target numbers
enum ScriptTarget {
ES3 = 0,
ES5 = 1,
ES2015 = 2,
ES2016 = 3,
ES2017 = 4,
ESNext = 5,
Latest = 5,
}
and here are the module kinds
enum ModuleKind {
None = 0,
CommonJS = 1,
AMD = 2,
UMD = 3,
System = 4,
ES2015 = 5,
}
*/
let myCwd = process.cwd();
tsn.compileGlobStringObject(
myGlobStringObject, // the glob string object describing from where to compile what to where
tsOptions, // the options for TypeScript
myCwd // a custom cwd, optional, defaults to process.cwd()
);
```bash
npm install @git.zone/tsbuild
```
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)
or
## Contribution
```bash
yarn add @git.zone/tsbuild
```
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
## Key Features
For further information read the linked docs at the top of this readme.
- Utilize the latest TypeScript features
- Flexible API for customized compilation processes
- Intuitive CLI for common build tasks
- Support for glob patterns to easily target files
- Ordered compilation to respect module dependencies
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
## API Reference
### Core Compilation Functions
#### `compileFileArray(fileStringArrayArg: string[], compilerOptionsArg?: CompilerOptions, argvArg?: any): Promise<any[]>`
Compiles an array of TypeScript files with customizable compiler options.
```typescript
import { compileFileArray } from '@git.zone/tsbuild';
const files = [
'./src/file1.ts',
'./src/file2.ts',
];
const options = {
target: "ES2020",
module: "CommonJS"
};
compileFileArray(files, options)
.then(compiledFiles => {
console.log('Compiled Files:', compiledFiles);
})
.catch(error => {
console.error('Compilation Error:', error);
});
```
#### `compileGlobStringObject(globStringObjectArg: Record<string, string>, tsOptionsArg?: CompilerOptions, cwdArg?: string, argvArg?: any): Promise<any[]>`
Compiles files matching glob patterns to specified output directories.
```typescript
import { compileGlobStringObject } from '@git.zone/tsbuild';
const globPattern = {
'./src/**/*.ts': './dist',
};
const compilerOptions = {
target: "ESNext",
module: "ESNext",
};
compileGlobStringObject(globPattern, compilerOptions)
.then(compiledFiles => {
console.log('Compilation complete:', compiledFiles);
})
.catch(error => {
console.error('Error during compilation:', error);
});
```
## Command Line Interface
The CLI provides convenient commands for common compilation tasks.
### Standard Command
Compiles all TypeScript files in the `ts/` directory to the `dist_ts` directory:
```bash
npx tsbuild
```
### Custom Command
Compile specific directories to corresponding `dist_` directories:
```bash
npx tsbuild custom <Dir1> <Dir2> ...
```
Example: `npx tsbuild custom src utils` compiles:
- `./src/**/*.ts``./dist_src`
- `./utils/**/*.ts``./dist_utils`
### TSFolders Command
Compiles TypeScript folders in a specific order based on dependencies:
```bash
npx tsbuild tsfolders
```
This command:
1. Identifies all folders starting with `ts` in the current directory
2. Prioritizes `ts_interfaces` and `ts_shared` to be compiled first
3. Orders other folders based on the `order` property in their `tspublish.json` files (if available)
4. Compiles each folder to its corresponding `dist_` folder
Example compilation order output:
```
compiling in this order:
[ 'ts_interfaces', 'ts_shared', 'ts_core', 'ts_utils', 'ts_modules' ]
```
## Compiler Options
Additional flags can be passed to any command to modify the compilation behavior:
- `--skiplibcheck`: Skip type checking of declaration files (shows warning)
- `--allowimplicitany`: Allow variables to be implicitly typed as `any`
- `--commonjs`: Use CommonJS module format instead of ESNext
Example:
```bash
npx tsbuild --skiplibcheck --allowimplicitany
```
## Default Compiler Options
By default, `@git.zone/tsbuild` uses the following compiler options:
```typescript
{
declaration: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
inlineSourceMap: true,
noEmitOnError: true,
outDir: 'dist_ts/',
module: ModuleKind.NodeNext,
target: ScriptTarget.ESNext,
moduleResolution: ModuleResolutionKind.NodeNext,
lib: ['lib.dom.d.ts', 'lib.es2022.d.ts'],
noImplicitAny: true,
esModuleInterop: true,
useDefineForClassFields: false,
verbatimModuleSyntax: true,
baseUrl: './',
}
```
These options can be overridden by providing a custom `CompilerOptions` object.
## Path Resolution
The package automatically detects and applies path mappings from your `tsconfig.json`. When it finds path mappings, it adjusts them to work with the compiled output by replacing `./ts_` with `./dist_ts_` in path aliases.
## Notes and Best Practices
- Each glob pattern compilation runs in its own pass, which may cause duplicate error messages if shared files are included in multiple patterns
- Use the `--skiplibcheck` option cautiously as it will pause for 5 seconds with a warning before continuing
- If you need different output configurations for different file sets, use multiple calls to `compileGlobStringObject`
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.