Socket
Socket
Sign inDemoInstall

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.4.2 to 1.4.3

3

bin/cli.js

@@ -60,4 +60,3 @@ #!/usr/bin/env node

check: {
short: 'c',
caption: "Check patch status (use with " + chalk_1.default.cyanBright('--basedir') + " to specify TS package location)"
short: 'c', caption: "Check patch status (use with " + chalk_1.default.cyanBright('--basedir') + " to specify TS package location)"
},

@@ -64,0 +63,0 @@ patch: {

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

### [1.4.3](https://github.com/nonara/ts-patch/compare/v1.4.2...v1.4.3) (2021-08-23)
### Bug Fixes
* Relative transform paths do not resolve from project root dir with compiler API (fixes [#59](https://github.com/nonara/ts-patch/issues/59)) ([e38655a](https://github.com/nonara/ts-patch/commit/e38655ac20f3905e61bcf8bfc03b97a5386b76f8))
* ts 3.6.5 does not patch properly (fixes [#55](https://github.com/nonara/ts-patch/issues/55)) ([1babac9](https://github.com/nonara/ts-patch/commit/1babac9284d330983a9658794680a5058e7c64c0))
### [1.4.2](https://github.com/nonara/ts-patch/compare/v1.4.1...v1.4.2) (2021-08-01)

@@ -7,0 +15,0 @@

@@ -159,3 +159,4 @@ "use strict";

if (patchVersion)
system_1.Log(['+', chalk_1.default.blueBright(filename) + " is patched with ts-patch version " +
system_1.Log(['+',
chalk_1.default.blueBright(filename) + " is patched with ts-patch version " +
(chalk_1.default[outOfDate ? 'redBright' : 'blueBright'](patchVersion) + " " + (outOfDate ? '(out of date)' : ''))

@@ -182,3 +183,4 @@ ]);

if (!modules.canUpdateOrPatch.length) {
system_1.Log(['!', "File" + (modules.length - 1 ? 's' : '') + " already patched with the latest version. For details, run: " +
system_1.Log(['!',
"File" + (modules.length - 1 ? 's' : '') + " already patched with the latest version. For details, run: " +
chalk_1.default.bgBlackBright('ts-patch check')

@@ -205,3 +207,4 @@ ]);

if (modules.unPatchable.length > 1) {
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 " +
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 " +
("patched. [" + modules.unPatchable.map(function (f) { return f.filename; }).join(', ') + "]")

@@ -208,0 +211,0 @@ ]);

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

}
var patchModule = function (tsModule, source) {
var patchModule = function (tsModule, tsPackage, source) {
var src = source || tsModule.moduleSrc;

@@ -59,18 +59,16 @@ var funcPos = src.search(/function emitFilesAndReportErrors\(/);

var restCode = src.substr(funcPos);
/* Modern TS */
var pos = restCode.search(/^\s*?var emitResult =/m);
if (pos >= 0) {
return startCode +
restCode.substr(0, pos) +
"\nts.diagnosticMap.set(program, allDiagnostics);\n" +
restCode.substr(pos);
}
/* TS 2.7 - 3.5 */
pos = restCode.search(/^\s*?var [_\w]+? = program.emit\(/m);
if (pos < 0)
throw new Error("Could not recognize diagnostics signature in emitFilesAndReportErrors(). Please open an issue with your TS version #.");
/* Find emit call position */
var emitPos = restCode.search(/^\s*?var emitResult =/m);
if (emitPos < 0)
emitPos = restCode.search(/^\s*?var [_\w]+? = program.emit\(/m); // TS 2.7 - 3.5
if (emitPos < 0)
throw new Error("Could not determine emit call. Please file an issue with your TS version!");
var ver = tsPackage.version.split('.');
var majorVer = +ver[0];
var minorVer = +ver[1];
var diagnosticsArrName = (majorVer > 3 || (majorVer === 3 && minorVer > 7)) ? 'allDiagnostics' : 'diagnostics';
return startCode +
restCode.substr(0, pos) +
"\nts.diagnosticMap.set(program, diagnostics);\n" +
restCode.substr(pos);
restCode.substr(0, emitPos) +
("\nts.diagnosticMap.set(program, " + diagnosticsArrName + ");\n") +
restCode.substr(emitPos);
};

@@ -90,3 +88,3 @@ /* ********************************************************************************************************************

/* Add diagnostic modification support */
var moduleSrc = patchModule(tsModule);
var moduleSrc = patchModule(tsModule, tsPackage);
try {

@@ -102,3 +100,3 @@ if (isTSC) {

fs_1.default.writeFileSync(file, Buffer.concat([
Buffer.from(patchModule(tsModule, fs_1.default.readFileSync(tsFile, 'utf-8'))),
Buffer.from(patchModule(tsModule, tsPackage, fs_1.default.readFileSync(tsFile, 'utf-8'))),
Buffer.from(!file_utils_1.getTSModule(tsFile).patchVersion ? patchSrc : ''),

@@ -105,0 +103,0 @@ Buffer.from(moduleSrc.replace(/^[\s\S]+(\(function \(ts\) {\s+function countLines[\s\S]+)$/, '$1'))

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

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

[![npm version](https://badge.fury.io/js/ts-patch.svg)](https://badge.fury.io/js/ts-patch)
[![NPM Downloads](https://img.shields.io/npm/dm/ts-patch.svg?style=flat)](https://npmjs.org/package/ts-patch)
![Build Status](https://github.com/nonara/ts-patch/workflows/Build%20(CI)/badge.svg)

@@ -3,0 +4,0 @@ [![Coverage Status](https://coveralls.io/repos/github/nonara/ts-patch/badge.svg?branch=master)](https://coveralls.io/github/nonara/ts-patch?branch=master)

@@ -128,25 +128,10 @@ (function () {

// Regex to split a windows path into three parts: [*, device, slash,
// tail] windows-only
var splitDeviceRe =
/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
// Regex to split a windows path into into [dir, root, basename, name, ext]
var splitWindowsRe =
/^(((?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?[\\\/]?)(?:[^\\\/]*[\\\/])*)((\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))[\\\/]*$/;
// Regex to split the tail part of the above into [*, dir, basename, ext]
var splitTailRe =
/^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
var win32 = {};
// Function to split a filename into [root, dir, basename, ext]
function win32SplitPath(filename) {
// Separate device+slash from tail
var result = splitDeviceRe.exec(filename),
device = (result[1] || '') + (result[2] || ''),
tail = result[3] || '';
// Split the tail into dir, basename and extension
var result2 = splitTailRe.exec(tail),
dir = result2[1],
basename = result2[2],
ext = result2[3];
return [device, dir, basename, ext];
return splitWindowsRe.exec(filename).slice(1);
}

@@ -161,11 +146,11 @@

var allParts = win32SplitPath(pathString);
if (!allParts || allParts.length !== 4) {
if (!allParts || allParts.length !== 5) {
throw new TypeError("Invalid path '" + pathString + "'");
}
return {
root: allParts[0],
dir: allParts[0] + allParts[1].slice(0, -1),
root: allParts[1],
dir: allParts[0] === allParts[1] ? allParts[0] : allParts[0].slice(0, -1),
base: allParts[2],
ext: allParts[3],
name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
ext: allParts[4],
name: allParts[3]
};

@@ -176,6 +161,6 @@ };

// Split a filename into [root, dir, basename, ext], unix version
// Split a filename into [dir, root, basename, name, ext], unix version
// 'root' is just a slash, or nothing.
var splitPathRe =
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
/^((\/?)(?:[^\/]*\/)*)((\.{1,2}|[^\/]+?|)(\.[^.\/]*|))[\/]*$/;
var posix = {};

@@ -196,15 +181,12 @@

var allParts = posixSplitPath(pathString);
if (!allParts || allParts.length !== 4) {
if (!allParts || allParts.length !== 5) {
throw new TypeError("Invalid path '" + pathString + "'");
}
allParts[1] = allParts[1] || '';
allParts[2] = allParts[2] || '';
allParts[3] = allParts[3] || '';
return {
root: allParts[0],
dir: allParts[0] + allParts[1].slice(0, -1),
root: allParts[1],
dir: allParts[0].slice(0, -1),
base: allParts[2],
ext: allParts[3],
name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
ext: allParts[4],
name: allParts[3],
};

@@ -1465,16 +1447,21 @@ };

/* ****************************************************************************************************************** */
function getConfig(compilerOptions, rootFileNames, defaultDir) {
if (compilerOptions.configFilePath === undefined) {
var dir = (rootFileNames.length > 0) ? dirname(rootFileNames[0]) : defaultDir;
var tsconfigPath = ts.findConfigFile(dir, ts.sys.fileExists);
if (tsconfigPath) {
var projectDir = dirname(tsconfigPath);
var config = readConfig(tsconfigPath, dirname(tsconfigPath));
function getProjectDir(compilerOptions) {
return compilerOptions.configFilePath && dirname(compilerOptions.configFilePath);
}
function getProjectConfig(compilerOptions, rootFileNames) {
var configFilePath = compilerOptions.configFilePath;
var projectDir = getProjectDir(compilerOptions);
if (configFilePath === undefined) {
var baseDir = (rootFileNames.length > 0) ? dirname(rootFileNames[0]) : projectDir !== null && projectDir !== void 0 ? projectDir : process.cwd;
configFilePath = ts.findConfigFile(baseDir, ts.sys.fileExists);
if (configFilePath) {
var config = readConfig(configFilePath);
compilerOptions = __assign(__assign({}, config.options), compilerOptions);
return ({ projectDir: projectDir, compilerOptions: compilerOptions });
projectDir = getProjectDir(compilerOptions);
}
}
return ({ projectDir: dirname(compilerOptions.configFilePath), compilerOptions: compilerOptions });
return ({ projectDir: projectDir, compilerOptions: compilerOptions });
}
function readConfig(configFileNamePath, projectDir) {
function readConfig(configFileNamePath) {
var projectDir = dirname(configFileNamePath);
var result = ts.readConfigFile(configFileNamePath, ts.sys.readFile);

@@ -1501,5 +1488,4 @@ if (result.error)

var e_1, _a, e_2, _b;
var _c;
var rootNames;
// TODO - Replace all process.cwd with attempting to first resolve from tsConfigFile dir & bump major version
var projectDir = process.cwd();
/* Determine options */

@@ -1519,8 +1505,7 @@ var createOpts = !Array.isArray(rootNamesOrOptions) ? rootNamesOrOptions : void 0;

/* Get Config */
var projectConfig = getProjectConfig(options, rootNames);
if (isTSC) {
var info = getConfig(options, rootNames, projectDir);
options = info.compilerOptions;
options = projectConfig.compilerOptions;
if (createOpts)
createOpts.options = options;
projectDir = info.projectDir;
}

@@ -1533,8 +1518,8 @@ /* Invoke TS createProgram */

var plugins = preparePluginsFromCompilerOptions(options.plugins);
var pluginCreator = new PluginCreator(plugins, projectDir);
var pluginCreator = new PluginCreator(plugins, (_c = projectConfig.projectDir) !== null && _c !== void 0 ? _c : process.cwd());
/* Prevent recursion in Program transformers */
var programTransformers = new Map(pluginCreator.getProgramTransformers());
try {
for (var _c = __values(pluginCreator.getProgramTransformers()), _d = _c.next(); !_d.done; _d = _c.next()) {
var _e = __read(_d.value, 1), transformer = _e[0];
for (var _d = __values(pluginCreator.getProgramTransformers()), _e = _d.next(); !_e.done; _e = _d.next()) {
var _f = __read(_e.value, 1), transformer = _f[0];
if (activeProgramTransformers.has(transformer))

@@ -1549,3 +1534,3 @@ programTransformers.delete(transformer);

try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
}

@@ -1557,3 +1542,3 @@ finally { if (e_1) throw e_1.error; }

for (var programTransformers_1 = __values(programTransformers), programTransformers_1_1 = programTransformers_1.next(); !programTransformers_1_1.done; programTransformers_1_1 = programTransformers_1.next()) {
var _f = __read(programTransformers_1_1.value, 2), programTransformer = _f[0], config = _f[1];
var _g = __read(programTransformers_1_1.value, 2), programTransformer = _g[0], config = _g[1];
var newProgram = programTransformer(program, host, config, { ts: ts });

@@ -1560,0 +1545,0 @@ if (typeof (newProgram === null || newProgram === void 0 ? void 0 : newProgram['emit']) === 'function')

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