Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package Config, ts 5.3, & fixes #138

Merged
merged 14 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ _Migrating from ttypescript is easy! See: [Method 1: Live Compiler](#method-1-li
* [Program Transformer Entry Point](#program-transformer-entry-point)
* [Configuring Program Transformers](#configuring-program-transformers)
* [Program Transformer Example](#program-transformer-example)
* [Plugin Package Configuration](#plugin-package-configuration)
* [Example](#example)
* [Resources](#resources)
* [Recommended Reading](#recommended-reading)
* [Recommended Tools](#recommended-tools)
Expand Down Expand Up @@ -263,6 +265,29 @@ export default function (

[`{ transform: "@typescript-virtual-barrel/compiler-plugin", transformProgram: true }`](https://github.com/zaguiini/typescript-virtual-barrel)

## Plugin Package Configuration

The plugin package configuration allows you to specify custom options for your TypeScript plugin.
This configuration is defined in the `package.json` of your plugin under the `tsp` property.

An example use case is enabling `parseAllJsDoc` if you require full JSDoc parsing in tsc for your transformer in TS v5.3+. (see: [5.3 JSDoc parsing changes](https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/#optimizations-by-skipping-jsdoc-parsing))

For all available options, see the `PluginPackageConfig` type in [plugin-types.ts](https://github.com/nonara/ts-patch/blob/master/projects/core/shared/plugin-types.ts)

### Example

```jsonc
{
"name": "your-plugin-name",
"version": "1.0.0",
"tsp": {
"tscOptions": {
"parseAllJsDoc": true
}
}
}
```

## Resources

### Recommended Reading
Expand Down Expand Up @@ -314,7 +339,7 @@ Cleans patch cache & lockfiles

## Help Wanted

If you're interested in helping and have a _high level_ of skill with the TS compiler API, please reach out!
If you're interested in helping and are knowledgeable with the TS compiler codebase, feel free to reach out!

# License

Expand Down
6 changes: 2 additions & 4 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ const config: Config.InitialOptions = {
roots: [ '<rootDir>/test/tests' ],
testRegex: '.*(test|spec)\\.tsx?$',
moduleFileExtensions: [ 'ts', 'tsx', 'js', 'jsx', 'json', 'node' ],
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json'
}
transform: {
'^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: './test/tsconfig.json' }],
},
modulePaths: [ "<rootDir>/node_modules" ],
// coveragePathIgnorePatterns: [
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@
"global-prefix": "^3.0.0",
"minimist": "^1.2.8",
"resolve": "^1.22.2",
"semver": "^7.5.2",
"semver": "^7.5.4",
"strip-ansi": "^6.0.1"
},
"bin": {
"ts-patch": "./dist/bin/ts-patch.js",
"tspc": "./dist/bin/tspc.js"
},
"devDependencies": {
"@types/esm": "^3.2.0",
"@types/jest": "^28.1.6",
"@types/esm": "^3.2.2",
"@types/jest": "^29.5.10",
"@types/minimist": "^1.2.2",
"@types/mock-fs": "^4.13.1",
"@types/node": "^16.11.5",
Expand All @@ -66,16 +66,15 @@
"@types/shelljs": "^0.8.9",
"esm": "^3.2.25",
"glob": "^7.1.7",
"jest": "^28.1.3",
"jest-mock-process": "^1.4.1",
"jest": "^29.7.0",
"rimraf": "^3.0.2",
"shelljs": "^0.8.5",
"standard-version": "^9.5.0",
"ts-jest": "^28.0.7",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"ts-patch": "3.0.0",
"ts-patch": "3.0.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.0.4"
"typescript": "^5.3.2"
},
"directories": {
"resources": "./dist/resources"
Expand Down
27 changes: 23 additions & 4 deletions projects/core/shared/plugin-types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* NOTE: This file is used during the build process for patch as well
*/
import type ts from 'typescript';
// Note: Leave as import-star, since we don't ship built file with esModuleInterop
import type * as ts from 'typescript';


/* ****************************************************************************************************************** */
Expand Down Expand Up @@ -71,9 +72,9 @@ export type PluginFactory =
LSPattern | ProgramPattern | ConfigPattern | CompilerOptionsPattern | TypeCheckerPattern | RawPattern;

export interface TransformerBasePlugin {
before?: ts.TransformerFactory<ts.SourceFile>;
after?: ts.TransformerFactory<ts.SourceFile>;
afterDeclarations?: ts.TransformerFactory<ts.SourceFile | ts.Bundle>;
before?: ts.TransformerFactory<ts.SourceFile> | ts.TransformerFactory<ts.SourceFile>[];
after?: ts.TransformerFactory<ts.SourceFile> | ts.TransformerFactory<ts.SourceFile>[];
afterDeclarations?: ts.TransformerFactory<ts.SourceFile | ts.Bundle> | ts.TransformerFactory<ts.SourceFile | ts.Bundle>[];
}

// endregion
Expand Down Expand Up @@ -138,3 +139,21 @@ export type RawPattern = (
) => ts.Transformer<ts.SourceFile>;

// endregion

/* ****************************************************************************************************************** */
// region: Plugin Package
/* ****************************************************************************************************************** */

export interface PluginPackageConfig {
tscOptions?: {
/**
* Sets the JSDocParsingMode to ParseAll
*
* @see https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/#optimizations-by-skipping-jsdoc-parsing
* @default false
*/
parseAllJsDoc?: boolean;
}
}

// endregion
2 changes: 2 additions & 0 deletions projects/core/src/patch/patch-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ export function patchModule(tsModule: TsModule, skipDts: boolean = false): { js:
}

/* Get JS */
const libraryName = tsModule.moduleName.replace(/\.js$/, '');
const patchDetail = PatchDetail.fromModule(tsModule, printedJs);
const js =
patchDetail.toHeader() + '\n' +
jsPatchSrc + '\n' +
`tsp.currentLibrary = '${libraryName}';\n`+
printedJs;

return { dts, js };
Expand Down
Loading
Loading