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.3.4 to 1.4.0

10

bin/cli.js

@@ -51,5 +51,5 @@ #!/usr/bin/env node

persist: {
caption: 'Enable automatic persistence. (If TypeScript is updated/reinstalled, it will automatically re-patch)'
caption: "Enable persistence for npm " + chalk_1.default.yellow("(deprecated - prefer 'prepare' script)")
},
'no-persist': { caption: 'Disable automatic persistence.' },
'no-persist': { caption: 'Disable npm persistence ' + chalk_1.default.yellow("(deprecated - prefer 'prepare' script)") },
color: { inverse: true, caption: 'Strip ansi colours from output' }

@@ -65,6 +65,6 @@ };

patch: {
short: void 0, paramCaption: '<module_file> | <glob>', caption: 'Patch specific module(s) ' + chalk_1.default.yellow('(Not recommended. Use install instead)')
short: void 0, paramCaption: '<module_file> | <glob>', caption: 'Patch specific module(s) ' + chalk_1.default.yellow('(advanced)')
},
unpatch: {
short: void 0, paramCaption: '<module_file> | <glob>', caption: 'Un-patch specific module(s) ' + chalk_1.default.yellow('(Not recommended. Use uninstall instead)')
short: void 0, paramCaption: '<module_file> | <glob>', caption: 'Un-patch specific module(s) ' + chalk_1.default.yellow('(advanced)')
},

@@ -125,3 +125,3 @@ version: { short: 'v', caption: 'Show version' },

var n = _a[0], short = _a[1].short;
return n && (short == cmd);
return n && (short === cmd);
}) || [])[0];

@@ -128,0 +128,0 @@ /* Parse options (convert short-code to long) */

@@ -5,2 +5,14 @@ # Changelog

## [1.4.0](https://github.com/nonara/ts-patch/compare/v1.3.4...v1.4.0) (2021-07-13)
### Features
* Add tsserver.js to supported libraries ([08262ed](https://github.com/nonara/ts-patch/commit/08262ede07c6e69b178751013988da772661ef02))
### Bug Fixes
* Require ts-node installation to be handled by user (fixes [#51](https://github.com/nonara/ts-patch/issues/51)) ([979338c](https://github.com/nonara/ts-patch/commit/979338ca5f0642b233de46dd6d293daa7f552ac4))
### [1.3.4](https://github.com/nonara/ts-patch/compare/v1.3.3...v1.3.4) (2021-06-30)

@@ -7,0 +19,0 @@

import { TSModule } from './file-utils';
import { TSPOptions } from './system';
export declare const tsDependencies: string[];
export declare const SRC_FILES: string[];

@@ -5,0 +4,0 @@ export declare const BACKUP_DIRNAME = "lib-backup";

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

@@ -36,3 +25,3 @@ if (k2 === undefined) k2 = k;

Object.defineProperty(exports, "__esModule", { value: true });
exports.disablePersistence = exports.enablePersistence = exports.unpatch = exports.patch = exports.check = exports.uninstall = exports.install = exports.setOptions = exports.parseFiles = exports.HOOKS_FILES = exports.RESOURCES_PATH = exports.BACKUP_DIRNAME = exports.SRC_FILES = exports.tsDependencies = void 0;
exports.disablePersistence = exports.enablePersistence = exports.unpatch = exports.patch = exports.check = exports.uninstall = exports.install = exports.setOptions = exports.parseFiles = exports.HOOKS_FILES = exports.RESOURCES_PATH = exports.BACKUP_DIRNAME = exports.SRC_FILES = void 0;
var path = __importStar(require("path"));

@@ -51,5 +40,4 @@ var fs = __importStar(require("fs"));

// region Config
exports.tsDependencies = ['ts-node'];
shell.config.silent = true;
exports.SRC_FILES = ['tsc.js', 'tsserverlibrary.js', 'typescript.js', 'typescriptServices.js'];
exports.SRC_FILES = ['tsc.js', 'tsserverlibrary.js', 'typescript.js', 'typescriptServices.js', 'tsserver.js'];
exports.BACKUP_DIRNAME = 'lib-backup';

@@ -129,87 +117,2 @@ exports.RESOURCES_PATH = path.join(system_1.appRoot, system_1.tspPackageJSON.directories.resources);

}
/**
* Remove tsNode from devDependencies in typescript's package.json
*/
function removeDependencies(tsPackage) {
var pkgFile = path.join(tsPackage.packageDir, 'package.json');
try {
var pkgData = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
for (var _i = 0, tsDependencies_1 = exports.tsDependencies; _i < tsDependencies_1.length; _i++) {
var d = tsDependencies_1[_i];
delete pkgData.devDependencies[d];
}
fs.writeFileSync(pkgFile, JSON.stringify(pkgData, null, 2));
}
catch (e) {
throw new system_1.PatchError(e.message);
}
}
/**
* Add tsNode to typescript's devDependencies
*/
function installDependencies(tsPackage) {
var pkgFile = path.join(tsPackage.packageDir, 'package.json');
/* Read TS package json */
var pkgData;
try {
pkgData = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
}
catch (e) {
throw new system_1.PatchError(e.message);
}
/* Find existing installations of dependencies */
var getDependenciesDetail = function () {
return exports.tsDependencies
.map(function (name) {
var location;
var version;
try {
location = resolve_1.default.sync(name + "/package.json", { basedir: tsPackage.packageDir });
version = require(location).version;
}
catch (e) { }
return ({ name: name, location: location, version: version });
});
};
/* Install missing dependencies */
var missingDeps = getDependenciesDetail().filter(function (_a) {
var version = _a.version;
return !version;
});
if (missingDeps.length > 0) {
system_1.Log(['~', "Installing dependencies: " + missingDeps.map(function (_a) {
var name = _a.name;
return name;
}).join(', ') + " (via npm)..."], system_1.Log.verbose);
/*
* Note: The environment variable is used here to compensate for an issue within istanbuljs/spawn-wrap
* When nyc coverage is run, spawn-wrap replaces any instance of the word 'node' in command string with an absolute
* path to its node installation. As a result, ts-node cannot install.
*
* This workaround will be replaced shortly.
*/
shell.exec("npm i -D --no-audit " + (process.platform === 'win32' ? '%PACKAGES%' : '$PACKAGES'), {
cwd: path.resolve(tsPackage.packageDir, '..'),
env: __assign(__assign({}, process.env), { PACKAGES: missingDeps.map(function (_a) {
var name = _a.name;
return name;
}).join(' ') })
});
if (shell.error())
throw new system_1.NPMError("Error while installing dependencies: " + shell.error());
}
/* Write versions to TS dependencies */
for (var _i = 0, _a = getDependenciesDetail(); _i < _a.length; _i++) {
var _b = _a[_i], name = _b.name, version = _b.version;
if (!pkgData.hasOwnProperty('dependencies'))
pkgData.dependencies = {};
pkgData.dependencies[name] = "^" + version;
}
try {
fs.writeFileSync(pkgFile, JSON.stringify(pkgData, null, 2));
}
catch (e) {
throw new system_1.PatchError(e.message);
}
}
// endregion

@@ -301,3 +204,2 @@ /* ********************************************************************************************************************

tsPackage.config.save();
installDependencies(tsPackage);
if (modules.unPatchable.length > 1) {

@@ -343,4 +245,2 @@ system_1.Log(['!', "Some files can't be patched! Try updating to a newer version of ts-patch. The following files are unable to be " +

shell.rm('-rf', tsPackage.config.file);
// Remove ts-node from package.json
removeDependencies(tsPackage);
}

@@ -356,3 +256,3 @@ /* Handle errors */

system_1.Log('');
throw new system_1.RestoreError("[" + Object.keys(errors).join(', ') + "]", 'Try reinstalling typescript via npm.' +
throw new system_1.RestoreError("[" + Object.keys(errors).join(', ') + "]", 'Try reinstalling typescript.' +
(!verbose ? ' (Or, run uninstall again with --verbose for specific error detail)' : ''));

@@ -359,0 +259,0 @@ }

{
"name": "ts-patch",
"version": "1.3.4",
"version": "1.4.0",
"description": "Patch typescript to support custom transformers in tsconfig.json",

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

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

- Plugins are specified in `tsconfig.json`, or provided programmatically in `CompilerOptions`.
- Logic based on [ttypescript](https://github.com/cevek/ttypescript) - 100% compatibility with `ttypescript` configuration + transformers.
- Based on [ttypescript](https://github.com/cevek/ttypescript) - 100% compatibility in configuration & transformers.
## Features
* Easy to patch or unpatch any version of typescript (2.7+)
* One step setup - no complicated install process
* Optionally, enable **persistence**, which re-patches typescript automatically if it is updated
* Advanced options for patching individual files, specific locations, etc. (see `ts-patch /?`)
* Patch / unpatch any version of typescript (2.7+)
* Advanced options for patching individual libraries, specific locations, etc. (see `ts-patch /?`)
* _(New)_ Supports 'transforming' the `Program` instance during creation. (see: [Transforming Program](#transforming-program))
* _(New)_ Add, remove, or modify diagnostics! (see: [Altering Diagnostics](#altering-diagnostics))
## Installation
## Setup
1. Install package
```sh
<yarn|npm|pnpm> add -D ts-patch
```
$ npm i ts-patch -D
$ ts-patch install
2. Patch typescript
```shell
ts-patch install
# For advanced options, see: ts-patch /?
```
For more options, use: ```ts-patch /?```
3. Add `prepare` script (keeps patch persisted after npm installations)
`package.json`
```jsonc
{
/* ... */
"scripts": {
"prepare": "ts-patch install -s"
}
}
```
## V2 Coming Soon...
With a couple years of hindsight, it's time for a much needed redesign to make a more complete plugin ecosystem that is
more multi-package manager friendly. The development of v2 is underway. To follow that progress, see
[this discussion](https://github.com/nonara/ts-patch/discussions/40).
In the mean time, v1 will still be maintained and patched for any issues, and its end of life will be no earlier than 2023.
## Table of Contents

@@ -163,8 +187,2 @@ - [Configuring](#configuring)

[`{ transform: "ts-transformer-keys/transformer" }`](https://github.com/kimamula/ts-transformer-keys)
[`{ transform: "ts-transformer-enumerate/transformer" }`](https://github.com/kimamula/ts-transformer-enumerate)
[`{ transform: "ts-transform-graphql-tag/dist/transformer" }`](https://github.com/firede/ts-transform-graphql-tag)
[`{ transform: "ts-transform-img/dist/transform", type: "config" }`](https://github.com/longlho/ts-transform-img)

@@ -182,8 +200,4 @@

[`{ transform: "typescript-transform-macros" }`](https://github.com/LeDDGroup/typescript-transform-macros)
[`{ transform: "ts-transformer-minify-privates" }`](https://github.com/timocov/ts-transformer-minify-privates)
[`{ transform: "typescript-plugin-styled-components", type: "config" }`](https://github.com/Igorbek/typescript-plugin-styled-components#ttypescript-compiler)
### Transforming Program

@@ -290,5 +304,5 @@

- If you're new to this sort of thing, please be sure to go through the [Recommended Reading](#recommended-reading).
- A good place to ask questions is [StackOverflow](https://stackoverflow.com/questions/tagged/typescript-compiler-api) (with the `#typescript-compiler-api` tag).
- Read the handbook and still stuck? [Ask in Discussions](https://github.com/nonara/ts-patch/discussions), and I or someone else may help when they have some time!
- Start here: [Recommended Reading](#recommended-reading)
- Ask on [StackOverflow](https://stackoverflow.com/questions/tagged/typescript-compiler-api) with the `#typescript-compiler-api` tag
- Read the handbook and still stuck? [Ask in Discussions](https://github.com/nonara/ts-patch/discussions) - someone may answer if they have time.
- Check out the `#compiler` room on the [TypeScript Discord Server](https://discord.com/invite/typescript).

@@ -295,0 +309,0 @@

@@ -1344,9 +1344,18 @@ (function () {

/* Register tsNode */
require('ts-node').register(__assign(__assign({ transpileOnly: true }, (tsConfig ? { project: tsConfig } : { skipProject: true })), { compilerOptions: {
target: 'ES2018',
jsx: 'react',
esModuleInterop: true,
module: 'commonjs',
} }));
tsNodeIncluded = true;
try {
require('ts-node').register(__assign(__assign({ transpileOnly: true }, (tsConfig ? { project: tsConfig } : { skipProject: true })), { compilerOptions: {
target: 'ES2018',
jsx: 'react',
esModuleInterop: true,
module: 'commonjs',
} }));
tsNodeIncluded = true;
}
catch (e) {
if (e.code === 'MODULE_NOT_FOUND')
throw new Error("Cannot use a typescript-based transformer without ts-node installed. " +
"Either add ts-node as a (dev)-dependency or install globally.");
else
throw e;
}
}

@@ -1353,0 +1362,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

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