Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-patch

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-patch - npm Package Compare versions

Comparing version 1.2.2 to 1.2.4

plugin-types.d.ts

7

CHANGELOG.md

@@ -11,6 +11,8 @@ # Changelog

- Possible recursion issue with program transformer
- Older TS versions, tsc wasn't passing diagnostics array
- In some older TS versions, tsc wasn't passing diagnostics array
- Various CLI bugs
### Added
- Added 'library' to TspExtras
- install and patch actions now will proceed to run if already patched but current version is out-dated

@@ -30,3 +32,4 @@ ### Code

While the option name has been updated for clarity, the old `beforeEmit` will still work, so this is not a breaking change.
While the option name has been updated to reflect the new behaviour, the old `beforeEmit` can still function as an alias
to the new behaviour, so this is not a breaking change.

@@ -33,0 +36,0 @@ ### Added: Inspect or alter diagnostics

export { getTSPackage, getTSModule, TSPackage, TSModule } from './lib/file-utils';
export { TSPOptions } from './lib/system/options';
export { install, uninstall, patch, setOptions } from './lib/actions';
export * from './plugin-types';
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -11,2 +21,3 @@ var file_utils_1 = require("./lib/file-utils");

Object.defineProperty(exports, "setOptions", { enumerable: true, get: function () { return actions_1.setOptions; } });
__exportStar(require("./plugin-types"), exports);
//# sourceMappingURL=index.js.map

@@ -45,3 +45,3 @@ "use strict";

var system_1 = require("./system");
var resolve = require("resolve");
var resolve_1 = __importDefault(require("resolve"));
/* ********************************************************************************************************************

@@ -165,3 +165,3 @@ * Config

try {
location = resolve.sync(name + "/package.json", { basedir: tsPackage.packageDir });
location = resolve_1.default.sync(name + "/package.json", { basedir: tsPackage.packageDir });
version = require(location).version;

@@ -381,3 +381,3 @@ }

try {
tspPath = path.dirname(resolve.sync('ts-patch/package.json', { basedir: packageDir }));
tspPath = path.dirname(resolve_1.default.sync('ts-patch/package.json', { basedir: packageDir }));
}

@@ -384,0 +384,0 @@ catch (e) { }

@@ -21,3 +21,3 @@ "use strict";

var system_1 = require("./system");
var resolve = require("resolve");
var resolve_1 = __importDefault(require("resolve"));
/* ********************************************************************************************************************

@@ -71,3 +71,3 @@ * Helpers

throw new system_1.PackageError(basedir + " is not a valid directory");
var packageDir = path_1.default.dirname(resolve.sync('typescript/package.json', { basedir: basedir }));
var packageDir = path_1.default.dirname(resolve_1.default.sync('typescript/package.json', { basedir: basedir }));
if (!packageDir)

@@ -74,0 +74,0 @@ throw new system_1.PackageError("Could not find typescript package in " + packageDir);

@@ -12,2 +12,9 @@ "use strict";

var actions_1 = require("./actions");
/* ****************************************************************************************************************** */
// region: Constants
/* ****************************************************************************************************************** */
var dtsPatchSrc = '\n' +
fs_1.default.readFileSync(path_1.default.resolve(system_1.appRoot, system_1.tspPackageJSON.directories.resources, 'module-patch.d.ts'), 'utf-8');
var jsPatchSrc = fs_1.default.readFileSync(path_1.default.resolve(system_1.appRoot, system_1.tspPackageJSON.directories.resources, 'module-patch.js'), 'utf-8');
// endregion
/* ********************************************************************************************************************

@@ -20,6 +27,5 @@ * Helpers

var generatePatch = function (isTSC) {
return fs_1.default
.readFileSync(path_1.default.resolve(system_1.appRoot, system_1.tspPackageJSON.directories.resources, 'module-patch.js'), 'utf-8')
.replace(/(^\s*Object\.assign\(ts,\s*{[\s\S]*tspVersion,[\s\S]+?}\);?$)/m, "var tspVersion = '" + system_1.tspPackageJSON.version + "';\r\n" +
("var isTSC = " + isTSC + ";\r\n") +
return jsPatchSrc
.replace(/(^\s*Object\.assign\(ts,\s*{[\s\S]*tspVersion,[\s\S]+?}\);?$)/m, "var tspVersion = '" + system_1.tspPackageJSON.version + "';\n" +
("var isTSC = " + isTSC + ";\n") +
"$1");

@@ -110,5 +116,10 @@ };

/* Patch d.ts with types (if module is typescript.ts) */
if (filename === 'typescript.js')
if (filename === 'typescript.js') {
var targetFile = path_1.default.join(dir, 'typescript.d.ts');
var backupFile = path_1.default.join(tsPackage.packageDir, actions_1.BACKUP_DIRNAME, 'typescript.d.ts');
try {
fs_1.default.appendFileSync(path_1.default.join(dir, 'typescript.d.ts'), '\r\n' + fs_1.default.readFileSync(path_1.default.resolve(system_1.appRoot, system_1.tspPackageJSON.directories.resources, 'module-patch.d.ts')));
if (fs_1.default.existsSync(backupFile))
fs_1.default.writeFileSync(targetFile, fs_1.default.readFileSync(backupFile, 'utf-8') + dtsPatchSrc);
else
fs_1.default.appendFileSync(targetFile, dtsPatchSrc);
}

@@ -118,4 +129,5 @@ catch (e) {

}
}
}
exports.patchTSModule = patchTSModule;
//# sourceMappingURL=patcher.js.map
{
"name": "ts-patch",
"version": "1.2.2",
"version": "1.2.4",
"description": "Patch typescript to support custom transformers in tsconfig.json",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -68,3 +68,3 @@ [![npm version](https://badge.fury.io/js/ts-patch.svg)](https://badge.fury.io/js/ts-patch)

| afterDeclarations | Apply transformer to declaration (*.d.ts) files _(TypeScript 2.9+)_. |
| transformProgram | Transform `Program` before `program.emit()` is called _(see: [Transforming Program](#transforming-program))_ |
| transformProgram | Transform `Program` during `ts.createProgram()` _(see: [Transforming Program](#transforming-program))_ |
| _..._ | Provide your own custom options, which will be passed to the transformer |

@@ -75,20 +75,13 @@

### Type Signatures
`ts.TransformerFactory` >>> `(context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile`
`TspExtras` >>>
```
{
ts: typeof ts; // The typescript instance
addDiagnostic: (diag: Diagnostic) => number,
removeDiagnostic: (index: number) => void,
diagnostics: readonly Diagnostic[],
library: string // Originating library ('tsc' | typescript' | 'tsserverlibrary' | 'tsserver')
}
```
_ts.TransformerFactory_ >>> `(context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile`
#### program (default)
Signature with `ts.Program` instance:
```ts
(program: ts.Program, config: PluginConfig | undefined, extras: TspExtras) => ts.TransformerFactory
(program: ts.Program, config: PluginConfig, extras: TransformerExtras) => ts.TransformerFactory
```
_TransformerExtras_ >>> [See Type Declaration](https://github.com/nonara/ts-patch/blob/master/src/installer/plugin-types.ts#L76)
#### config

@@ -103,3 +96,3 @@ Signature with transformer's config:

```ts
(checker: ts.TypeChecker, config?: PluginConfig) => ts.TransformerFactory
(checker: ts.TypeChecker, config: PluginConfig) => ts.TransformerFactory
```

@@ -116,3 +109,3 @@

```ts
(compilerOpts: ts.CompilerOptions, config?: PluginConfig) => ts.TransformerFactory
(compilerOpts: ts.CompilerOptions, config: PluginConfig) => ts.TransformerFactory
```

@@ -206,5 +199,7 @@

```TS
(program: ts.Program, host?: ts.CompilerHost, options?: PluginConfig) => ts.Program
(program: ts.Program, host: ts.CompilerHost | undefined, options: PluginConfig, extras: ProgramTransformerExtras) => ts.Program
```
_ProgramTransformerExtras_ >>> [See Type Declaration](https://github.com/nonara/ts-patch/blob/master/src/installer/plugin-types.ts#L90)
#### Example Program Transformer

@@ -231,3 +226,4 @@ ```TypeScript

#### Notes
A Program transformer is _not_ a Node Transformer. This means the following options will not apply when `transformProgram: true` is specified:
A Program transformer is _not_ a Node Transformer. This means the following options will not apply when
`transformProgram: true` is specified:
- `type`

@@ -239,3 +235,4 @@ - `before`

To alter diagnostics, use the [program type signature](#program-default), and use the following properties from the `TspExtras` parameter
To alter diagnostics, use the [program type signature](#program-default), and use the following properties from the
`TransformerExtras` parameter

@@ -242,0 +239,0 @@ | property | description |

declare namespace ts {
const diagnosticMap: WeakMap<Program, Diagnostic[]>;
interface PluginConfig {

@@ -47,3 +48,3 @@ /**

}
type TspExtras = {
type TransformerExtras = {
/**

@@ -61,5 +62,9 @@ * Originating TypeScript instance

};
type ProgramTransformer = (program: Program, host: CompilerHost | undefined, config: PluginConfig | undefined, extras: {
type ProgramTransformerExtras = {
/**
* Originating TypeScript instance
*/
ts: typeof ts;
}) => Program;
};
type ProgramTransformer = (program: Program, host: CompilerHost | undefined, config: PluginConfig, extras: ProgramTransformerExtras) => Program;
type LSPattern = (ls: LanguageService, config: {}) => TransformerPlugin;

@@ -69,3 +74,3 @@ type CompilerOptionsPattern = (compilerOpts: CompilerOptions, config: {}) => TransformerPlugin;

type TypeCheckerPattern = (checker: TypeChecker, config: {}) => TransformerPlugin;
type ProgramPattern = (program: Program, config: {}, extras?: TspExtras) => TransformerPlugin;
type ProgramPattern = (program: Program, config: {}, extras: TransformerExtras) => TransformerPlugin;
type RawPattern = (context: TransformationContext, program: Program, config: {}) => Transformer<SourceFile>;

@@ -72,0 +77,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc