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

ts-import

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-import - npm Package Compare versions

Comparing version 0.0.41 to 0.0.42

2

cache/home/radrat/workspace/radarsu-pnpm/@radrat/@/cli/scripts.js

@@ -13,3 +13,5 @@ "use strict";

const package_1 = require("@radrat-scripts/package");
const jest = require("jest");
const scripts = (cli) => __awaiter(void 0, void 0, void 0, function* () {
console.log(jest);
yield cli.command({

@@ -16,0 +18,0 @@ name: `link`,

3

dist/index.d.ts

@@ -20,3 +20,4 @@ export interface ICompilerOptions {

*/
compile(tsPath?: string): Promise<any>;
compile(tsPath?: string, changeDirectory?: boolean): Promise<any>;
import(cachedFilePath: string, changeDirectory?: boolean): Promise<any>;
buildCachedScripts(absoluteTsPath: string): Promise<unknown>;

@@ -23,0 +24,0 @@ wasModified(tsFilePath: string, jsFilePath: string): Promise<boolean>;

@@ -73,6 +73,7 @@ "use strict";

*/
Compiler.prototype.compile = function (tsPath) {
Compiler.prototype.compile = function (tsPath, changeDirectory) {
if (tsPath === void 0) { tsPath = ""; }
if (changeDirectory === void 0) { changeDirectory = false; }
return __awaiter(this, void 0, void 0, function () {
var _a, cacheDir, logger, absoluteTsPath, absoluteTsDir, tsFileName, jsFileName, cachedDir, cachedFile, tsWasModified;
var _a, cacheDir, logger, absoluteTsPath, absoluteTsDir, tsFileName, jsFileName, cachedDir, cachedFilePath, tsWasModified;
return __generator(this, function (_b) {

@@ -87,7 +88,7 @@ switch (_b.label) {

cachedDir = path.resolve(cacheDir, "." + absoluteTsDir);
cachedFile = path.resolve(cachedDir, jsFileName);
cachedFilePath = path.resolve(cachedDir, jsFileName);
// Check if cached scripts.js exist.
logger.debug("Looking for cached file at " + cachedFile);
if (!fs.existsSync(cachedFile)) return [3 /*break*/, 3];
return [4 /*yield*/, this.wasModified(absoluteTsPath, cachedFile)];
logger.debug("Looking for cached file at " + cachedFilePath);
if (!fs.existsSync(cachedFilePath)) return [3 /*break*/, 3];
return [4 /*yield*/, this.wasModified(absoluteTsPath, cachedFilePath)];
case 1:

@@ -97,3 +98,3 @@ tsWasModified = _b.sent();

logger.debug("File was not modified, importing.");
return [2 /*return*/, Promise.resolve().then(function () { return require(cachedFile); })];
return [2 /*return*/, this["import"](cachedFilePath)];
}

@@ -105,3 +106,3 @@ // Cache is incorrect, rebuild.

_b.sent();
return [2 /*return*/, Promise.resolve().then(function () { return require(cachedFile); })];
return [2 /*return*/, this["import"](cachedFilePath)];
case 3:

@@ -120,3 +121,3 @@ // Create cache directory if it does not exist.

_b.sent();
return [2 /*return*/, Promise.resolve().then(function () { return require(cachedFile); })];
return [2 /*return*/, this["import"](cachedFilePath)];
}

@@ -126,2 +127,25 @@ });

};
Compiler.prototype["import"] = function (cachedFilePath, changeDirectory) {
if (changeDirectory === void 0) { changeDirectory = false; }
return __awaiter(this, void 0, void 0, function () {
var cwd, cachedFileDir, imported;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
cwd = process.cwd();
cachedFileDir = path.dirname(cachedFilePath);
if (changeDirectory) {
process.chdir(cachedFileDir);
}
return [4 /*yield*/, Promise.resolve().then(function () { return require(cachedFilePath); })];
case 1:
imported = _a.sent();
if (changeDirectory) {
process.chdir(cwd);
}
return [2 /*return*/, imported];
}
});
});
};
Compiler.prototype.buildCachedScripts = function (absoluteTsPath) {

@@ -128,0 +152,0 @@ var _a = this.options, flags = _a.flags, cacheDir = _a.cacheDir, logger = _a.logger;

{
"name": "ts-import",
"version": "0.0.41",
"version": "0.0.42",
"description": "Import (compile and cache on the fly) TypeScript files dynamically with ease.",

@@ -24,3 +24,3 @@ "keywords": [

"@radrat-scripts/readme": "0.0.41",
"@radrat/cli": "0.0.41",
"@radrat/cli": "0.0.54",
"@types/node": "^14.6.0",

@@ -27,0 +27,0 @@ "typescript": "^3.9.7"

@@ -42,3 +42,3 @@ import * as childProcess from 'child_process';

*/
async compile(tsPath: string = ``): Promise<any> {
async compile(tsPath: string = ``, changeDirectory = false): Promise<any> {
const { cacheDir, logger } = this.options;

@@ -53,12 +53,12 @@

const cachedDir = path.resolve(cacheDir, `.${absoluteTsDir}`);
const cachedFile = path.resolve(cachedDir, jsFileName);
const cachedFilePath = path.resolve(cachedDir, jsFileName);
// Check if cached scripts.js exist.
logger.debug(`Looking for cached file at ${cachedFile}`);
if (fs.existsSync(cachedFile)) {
logger.debug(`Looking for cached file at ${cachedFilePath}`);
if (fs.existsSync(cachedFilePath)) {
// Cache is correct, do nothing.
const tsWasModified = await this.wasModified(absoluteTsPath, cachedFile);
const tsWasModified = await this.wasModified(absoluteTsPath, cachedFilePath);
if (!tsWasModified) {
logger.debug(`File was not modified, importing.`);
return import(cachedFile);
return this.import(cachedFilePath);
}

@@ -69,3 +69,3 @@

await this.buildCachedScripts(absoluteTsPath);
return import(cachedFile);
return this.import(cachedFilePath);
}

@@ -84,5 +84,22 @@

await this.buildCachedScripts(absoluteTsPath);
return import(cachedFile);
return this.import(cachedFilePath);
}
async import(cachedFilePath: string, changeDirectory = false) {
const cwd = process.cwd();
const cachedFileDir = path.dirname(cachedFilePath);
if (changeDirectory) {
process.chdir(cachedFileDir);
}
const imported = await import(cachedFilePath);
if (changeDirectory) {
process.chdir(cwd);
}
return imported;
}
buildCachedScripts(absoluteTsPath: string) {

@@ -89,0 +106,0 @@ const { flags, cacheDir, logger } = this.options;

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