fix(exports): Fixed duplicate file compilation in compileGlobStringObject, fixes #1
This commit is contained in:
parent
1f9870ffbb
commit
289421206c
@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-03-04 - 2.2.3 - fix(exports)
|
||||
Fixed duplicate file compilation in compileGlobStringObject
|
||||
|
||||
- Enhanced type safety checks for glob pattern compilation keys.
|
||||
- Ensured file list transformations include type checks.
|
||||
- Fixed issue with duplicate compilation results in compileGlobStringObject.
|
||||
|
||||
## 2025-01-28 - 2.2.2 - fix(ci)
|
||||
Remove GitLab CI configuration
|
||||
|
||||
|
@ -9,9 +9,23 @@
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "gitzone",
|
||||
"gitrepo": "tsbuild",
|
||||
"description": "TypeScript nightly to easily make use of latest features",
|
||||
"description": "A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.",
|
||||
"npmPackagename": "@gitzone/tsbuild",
|
||||
"license": "MIT"
|
||||
}
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"TypeScript",
|
||||
"compilation",
|
||||
"nightly features",
|
||||
"CLI tool",
|
||||
"file compilation",
|
||||
"glob patterns",
|
||||
"compiler options",
|
||||
"development",
|
||||
"API"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis 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. \n\n**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.\n\n### Trademarks\n\nThis 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.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy 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.\n"
|
||||
}
|
||||
}
|
12
package.json
12
package.json
@ -2,7 +2,7 @@
|
||||
"name": "@git.zone/tsbuild",
|
||||
"version": "2.2.2",
|
||||
"private": false,
|
||||
"description": "TypeScript nightly to easily make use of latest features",
|
||||
"description": "A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
@ -19,7 +19,15 @@
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/tsn.git"
|
||||
},
|
||||
"keywords": [
|
||||
"TypeScript"
|
||||
"TypeScript",
|
||||
"compilation",
|
||||
"nightly features",
|
||||
"CLI tool",
|
||||
"file compilation",
|
||||
"glob patterns",
|
||||
"compiler options",
|
||||
"development",
|
||||
"API"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
|
255
readme.md
255
readme.md
@ -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 | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](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
|
||||
```
|
||||
|
||||
[](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.
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tsbuild',
|
||||
version: '2.2.2',
|
||||
description: 'TypeScript nightly to easily make use of latest features'
|
||||
version: '2.2.3',
|
||||
description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.'
|
||||
}
|
||||
|
@ -25,35 +25,52 @@ export let compileFileArray = (
|
||||
* }
|
||||
*/
|
||||
export let compileGlobStringObject = async (
|
||||
globStringObjectArg: any,
|
||||
globStringObjectArg: Record<string, string>,
|
||||
tsOptionsArg: CompilerOptions = {},
|
||||
cwdArg: string = process.cwd(),
|
||||
argvArg?: any
|
||||
) => {
|
||||
let compiledFiles: plugins.smartfile.SmartFile[] = [];
|
||||
let compiledFiles: any[] = [];
|
||||
|
||||
for (const keyArg in globStringObjectArg) {
|
||||
if (globStringObjectArg[keyArg]) {
|
||||
// Type safety check for key
|
||||
if (keyArg && typeof keyArg === 'string' && globStringObjectArg[keyArg]) {
|
||||
console.log(
|
||||
`TypeScript assignment: transpile from ${keyArg} to ${globStringObjectArg[keyArg]}`
|
||||
);
|
||||
|
||||
// Get files matching the glob pattern
|
||||
const fileTreeArray = await plugins.smartfile.fs.listFileTree(cwdArg, keyArg);
|
||||
const absoluteFilePathArray: string[] = plugins.smartpath.transform.toAbsolute(
|
||||
fileTreeArray,
|
||||
|
||||
// Ensure fileTreeArray contains only strings before transforming
|
||||
const stringFileTreeArray = Array.isArray(fileTreeArray)
|
||||
? fileTreeArray.filter((item): item is string => typeof item === 'string')
|
||||
: [];
|
||||
|
||||
// Transform to absolute paths
|
||||
const absoluteFilePathArray = plugins.smartpath.transform.toAbsolute(
|
||||
stringFileTreeArray,
|
||||
cwdArg
|
||||
) as string[];
|
||||
|
||||
// Get destination directory as absolute path
|
||||
const destDir: string = plugins.smartpath.transform.toAbsolute(
|
||||
globStringObjectArg[keyArg],
|
||||
cwdArg
|
||||
) as string;
|
||||
tsOptionsArg = {
|
||||
|
||||
// Update compiler options with the output directory
|
||||
const updatedTsOptions: CompilerOptions = {
|
||||
...tsOptionsArg,
|
||||
outDir: destDir,
|
||||
};
|
||||
compiledFiles = compiledFiles.concat(
|
||||
compiledFiles,
|
||||
await compileFileArray(absoluteFilePathArray, tsOptionsArg, argvArg)
|
||||
);
|
||||
|
||||
// Compile the files and correctly concat the results
|
||||
// Fixed: removed duplicating compiledFiles in the concat operation
|
||||
const newlyCompiledFiles = await compileFileArray(absoluteFilePathArray, updatedTsOptions, argvArg);
|
||||
compiledFiles = compiledFiles.concat(newlyCompiledFiles);
|
||||
}
|
||||
}
|
||||
|
||||
return compiledFiles;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user