Socket
Socket
Sign inDemoInstall

ts-purify

Package Overview
Dependencies
13
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.0.2

1

dist/command.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.main = void 0;
const _1 = require(".");

@@ -4,0 +5,0 @@ async function doMain() {

2

dist/index.d.ts

@@ -7,2 +7,2 @@ export interface Options {

export declare function cleanAllFiles(srcDir: string, destDir: string, options?: Options): Promise<void[]>;
export declare function watchSourceAndCleanDest(srcDir: string, destDir: string, options?: Options): Promise<void>;
export declare function watchSourceAndCleanDest(srcDir: string, destDir: string, options?: Options): Promise<never>;

@@ -6,10 +6,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.watchSourceAndCleanDest = exports.cleanAllFiles = void 0;
const cousin_harris_1 = __importDefault(require("cousin-harris"));
const minimatch_1 = __importDefault(require("minimatch"));
const util_1 = require("util");
const fb_watchman_1 = require("fb-watchman");
const fs_1 = require("fs");
const path_1 = require("path");
const goodUnlink = util_1.promisify(fs_1.unlink);
const goodExists = util_1.promisify(fs_1.exists);
const goodRealpath = util_1.promisify(fs_1.realpath);
const walkSync = function (dir, select, append) {

@@ -59,61 +58,25 @@ const files = fs_1.readdirSync(dir);

function watchSourceAndCleanDest(srcDir, destDir, options = {}) {
const client = new fb_watchman_1.Client();
return new Promise((_, reject) => {
client.capabilityCheck({ optional: [], required: ['relative_root'] }, async (error) => {
const endAndReject = (message) => {
client.end();
reject(new Error(message));
};
if (error) {
return endAndReject(`Could not confirm capabilities: ${error.message}`);
}
const fullSrcDir = await goodRealpath(srcDir);
client.command([options.watchProject ? 'watch-project' : 'watch', fullSrcDir], (error, watchResp) => {
if (error) {
return endAndReject(`Could not initiate watch: ${error.message}`);
}
const sub = {
expression: ['allof', ['match', '*.ts']],
fields: ['name', 'exists'],
};
const relativePath = watchResp.relative_path;
if (relativePath) {
// eslint-disable-next-line @typescript-eslint/camelcase
sub.relative_root = relativePath;
}
client.command(['subscribe', watchResp.watch, 'sub-name', sub], (error) => {
if (error) {
return endAndReject(`Could not subscribe to changes: ${error.message}`);
return cousin_harris_1.default([srcDir], ({ path, removal }) => {
if (!removal) {
return;
}
const fileRoot = path.replace(/\.ts$/, '');
const toDelete = [path_1.join(destDir, `${fileRoot}.js`), path_1.join(destDir, `${fileRoot}.js.map`)];
// don't map/await these, just log on failure
toDelete.forEach(async (file) => {
if (fs_1.existsSync(file) &&
!(options.ignorePattern && minimatch_1.default(file, options.ignorePattern))) {
fs_1.unlink(file, (err) => {
if (err) {
console.warn(`Failed to remove ${file}`);
}
client.on('subscription', (change) => {
change.files.forEach((fileChange) => {
if (!fileChange.exists) {
const fileRoot = fileChange.name.replace(/\.ts$/, '');
const toDelete = [
path_1.join(destDir, `${fileRoot}.js`),
path_1.join(destDir, `${fileRoot}.js.map`),
];
// don't map/await these, just log on failure
toDelete.forEach(async (file) => {
if ((await goodExists(file)) &&
!(options.ignorePattern && minimatch_1.default(file, options.ignorePattern))) {
fs_1.unlink(file, (err) => {
if (err) {
console.warn(`Failed to remove ${file}`);
}
else if (options.verbose) {
console.info(`Removed ${file}`);
}
});
}
});
}
});
});
else if (options.verbose) {
console.info(`Removed ${file}`);
}
});
});
}
});
});
}, { watchProject: options.watchProject });
}
exports.watchSourceAndCleanDest = watchSourceAndCleanDest;
//# sourceMappingURL=index.js.map
{
"name": "ts-purify",
"version": "2.0.1",
"version": "2.0.2",
"description": "ensure compiled typescript files are removed when the corresponding source files are",

@@ -35,18 +35,17 @@ "author": "insidewhy <github@chilon.net>",

"dependencies": {
"fb-watchman": "^2.0.1",
"cousin-harris": "^1.0.0",
"minimatch": "^3.0.4"
},
"devDependencies": {
"@types/fb-watchman": "2.0.0",
"@types/node": "12.12.37",
"@typescript-eslint/eslint-plugin": "2.34.0",
"@typescript-eslint/parser": "2.34.0",
"eslint": "7.1.0",
"eslint-config-prettier": "6.11.0",
"husky": "4.2.5",
"prettier": "2.0.5",
"pretty-quick": "2.0.1",
"@types/node": "12.20.4",
"@typescript-eslint/eslint-plugin": "4.16.1",
"@typescript-eslint/parser": "4.16.1",
"eslint": "7.21.0",
"eslint-config-prettier": "8.1.0",
"husky": "5.1.3",
"prettier": "2.2.1",
"pretty-quick": "3.1.0",
"rimraf": "3.0.2",
"typescript": "3.9.3"
"typescript": "4.2.2"
}
}

@@ -0,10 +1,8 @@

import cousinHarris from 'cousin-harris'
import minimatch from 'minimatch'
import { promisify } from 'util'
import { Client } from 'fb-watchman'
import { readdirSync, statSync, unlink, realpath, exists } from 'fs'
import { readdirSync, statSync, unlink, existsSync } from 'fs'
import { join } from 'path'
const goodUnlink = promisify(unlink)
const goodExists = promisify(exists)
const goodRealpath = promisify(realpath)

@@ -84,71 +82,30 @@ const walkSync = function (

options: Options = {},
): Promise<void> {
const client = new Client()
return new Promise((_, reject) => {
client.capabilityCheck({ optional: [], required: ['relative_root'] }, async (error) => {
const endAndReject = (message: string): void => {
client.end()
reject(new Error(message))
): Promise<never> {
return cousinHarris(
[srcDir],
({ path, removal }) => {
if (!removal) {
return
}
const fileRoot = path.replace(/\.ts$/, '')
const toDelete = [join(destDir, `${fileRoot}.js`), join(destDir, `${fileRoot}.js.map`)]
if (error) {
return endAndReject(`Could not confirm capabilities: ${error.message}`)
}
const fullSrcDir = await goodRealpath(srcDir)
client.command(
[options.watchProject ? 'watch-project' : 'watch', fullSrcDir],
(error, watchResp) => {
if (error) {
return endAndReject(`Could not initiate watch: ${error.message}`)
}
const sub: any = {
expression: ['allof', ['match', '*.ts']],
fields: ['name', 'exists'],
}
const relativePath = watchResp.relative_path
if (relativePath) {
// eslint-disable-next-line @typescript-eslint/camelcase
sub.relative_root = relativePath
}
client.command(['subscribe', watchResp.watch, 'sub-name', sub], (error) => {
if (error) {
return endAndReject(`Could not subscribe to changes: ${error.message}`)
// don't map/await these, just log on failure
toDelete.forEach(async (file) => {
if (
existsSync(file) &&
!(options.ignorePattern && minimatch(file, options.ignorePattern))
) {
unlink(file, (err) => {
if (err) {
console.warn(`Failed to remove ${file}`)
} else if (options.verbose) {
console.info(`Removed ${file}`)
}
client.on('subscription', (change) => {
change.files.forEach((fileChange: any) => {
if (!fileChange.exists) {
const fileRoot = fileChange.name.replace(/\.ts$/, '')
const toDelete = [
join(destDir, `${fileRoot}.js`),
join(destDir, `${fileRoot}.js.map`),
]
// don't map/await these, just log on failure
toDelete.forEach(async (file) => {
if (
(await goodExists(file)) &&
!(options.ignorePattern && minimatch(file, options.ignorePattern))
) {
unlink(file, (err) => {
if (err) {
console.warn(`Failed to remove ${file}`)
} else if (options.verbose) {
console.info(`Removed ${file}`)
}
})
}
})
}
})
})
})
},
)
})
})
}
})
},
{ watchProject: options.watchProject },
)
}

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc