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 4.0.0-beta.9 to 4.0.0-beta.10

4

dist/load.interfaces.d.ts

@@ -12,2 +12,3 @@ import * as tsc from 'typescript';

allowConfigurationWithComments?: boolean;
compiledJsExtension?: string;
useCache?: boolean;

@@ -24,2 +25,3 @@ transpileOptions: {

allowConfigurationWithComments?: boolean;
compiledJsExtension?: string;
useCache?: boolean;

@@ -30,3 +32,3 @@ compileOptions: {

}
export type LoadOptions = RecursivePartial<LoadTranspileOptions | LoadCompileOptions>;
export type LoadOptions = RecursivePartial<LoadCompileOptions | LoadTranspileOptions>;
export {};

@@ -6,2 +6,3 @@ import { LoadMode, LoadOptions } from './load.interfaces';

useCache: boolean;
compiledJsExtension: string;
};

@@ -8,0 +9,0 @@ export declare const load: (tsRelativePath: string, options?: LoadOptions) => Promise<any>;

@@ -16,2 +16,3 @@ "use strict";

useCache: true,
compiledJsExtension: `.js`,
};

@@ -25,9 +26,9 @@ const load = async (tsRelativePath, options) => {

const loadConfig = (0, options_defaults_1.defaults)(exports.defaultLoadOptions, options);
const providers = providers_1.providersMap[loadConfig.mode];
const config = providers.getConfig(loadConfig);
const provider = providers_1.providersMap[loadConfig.mode];
const config = provider.getConfig(loadConfig);
const cwd = process.cwd();
const cacheDir = providers.getCacheDir(config);
const cacheDir = provider.getCacheDir(config);
const tsPath = path.resolve(cwd, tsRelativePath);
const jsAfterCachePath = crossPlatform.getJsAfterCachePath(tsPath);
const jsPath = path.join(cacheDir, jsAfterCachePath).replace(/\.[^/.]+$/u, `.js`);
const jsPath = path.join(cacheDir, jsAfterCachePath).replace(/\.[^/.]+$/u, loadConfig.compiledJsExtension);
if (loadConfig.useCache) {

@@ -44,3 +45,3 @@ const [tsFileExists, jsFileExists] = await Promise.all([

}
await providers.load(Object.assign({ tsPath,
await provider.load(Object.assign({ tsPath,
jsPath }, config));

@@ -57,9 +58,9 @@ const loaded = await (_b = jsPath, Promise.resolve().then(() => require(_b)));

const loadConfig = (0, options_defaults_1.defaults)(exports.defaultLoadOptions, options);
const providers = providers_1.providersMap[loadConfig.mode];
const config = providers.getConfig(loadConfig);
const provider = providers_1.providersMap[loadConfig.mode];
const config = provider.getConfig(loadConfig);
const cwd = process.cwd();
const cacheDir = providers.getCacheDir(config);
const cacheDir = provider.getCacheDir(config);
const tsPath = path.resolve(cwd, tsRelativePath);
const jsAfterCachePath = crossPlatform.getJsAfterCachePath(tsPath);
const jsPath = path.join(cacheDir, jsAfterCachePath).replace(/\.[^/.]+$/u, `.js`);
const jsPath = path.join(cacheDir, jsAfterCachePath).replace(/\.[^/.]+$/u, loadConfig.compiledJsExtension);
if (loadConfig.useCache) {

@@ -78,3 +79,3 @@ const tsFileExists = utils.checkIfFileExistsSync(tsPath);

}
providers.loadSync(Object.assign({ tsPath,
provider.loadSync(Object.assign({ tsPath,
jsPath }, config));

@@ -81,0 +82,0 @@ const loaded = require(jsPath);

import * as tsc from 'typescript';
export interface CompileOptions {
tsPath: string;
jsPath: string;
compilerOptions: tsc.CompilerOptions;
}
export declare const compile: (options: CompileOptions) => void;

@@ -8,7 +8,8 @@ "use strict";

const getDefaultCompilerOptions = () => {
const cwd = process.cwd();
const defaultsForPlatform = {
outDir: path.resolve(__dirname, `..`, `..`, `..`, `cache`),
outDir: path.join(cwd, `.cache`, `ts-import`),
};
if (process.platform === `win32`) {
const driveLetter = process.cwd().charAt(0);
const driveLetter = cwd.charAt(0);
defaultsForPlatform.outDir = path.join(defaultsForPlatform.outDir, driveLetter);

@@ -15,0 +16,0 @@ defaultsForPlatform.rootDir = `${driveLetter}:/`;

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

const compiler = require("../../modules/compiler");
const fs = require("node:fs");
const loadSync = (options) => {
return compiler.compile(options);
compiler.compile(options);
const jsWithNormalExtensionPath = options.jsPath.replace(/\.[^/.]+$/u, `.js`);
fs.renameSync(jsWithNormalExtensionPath, options.jsPath);
};
exports.loadSync = loadSync;
//# sourceMappingURL=load-sync.js.map

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

const compiler = require("../../modules/compiler");
const fs = require("node:fs");
const load = async (options) => {
return compiler.compile(options);
compiler.compile(options);
const jsWithNormalExtensionPath = options.jsPath.replace(/\.[^/.]+$/u, `.js`);
await fs.promises.rename(jsWithNormalExtensionPath, options.jsPath);
};
exports.load = load;
//# sourceMappingURL=load.js.map
import * as compiler from '../modules/compiler';
import { LoadCompileOptions, LoadMode, LoadOptions, LoadTranspileOptions } from '../load.interfaces';
export interface Providers {
getCacheDir: (options: LoadTranspileOptions[`transpileOptions`] | LoadCompileOptions[`compileOptions`]) => string;
getConfig: (options: Partial<LoadOptions>) => LoadTranspileOptions['transpileOptions'] | LoadCompileOptions['compileOptions'];
getCacheDir: (options: LoadCompileOptions[`compileOptions`] | LoadTranspileOptions[`transpileOptions`]) => string;
getConfig: (options: Partial<LoadOptions>) => LoadCompileOptions['compileOptions'] | LoadTranspileOptions['transpileOptions'];
load: (options: compiler.CompileOptions | compiler.TranspileOptions) => Promise<void>;

@@ -7,0 +7,0 @@ loadSync: (options: compiler.CompileOptions | compiler.TranspileOptions) => void;

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

const getConfig = (options) => {
const cwd = process.cwd();
const defaultTranspileOptions = {
cache: {
dir: path.resolve(__dirname, `..`, `..`, `..`, `cache`),
dir: path.join(cwd, `.cache`, `ts-import`),
},

@@ -15,3 +16,3 @@ transpileOptions: {},

if (process.platform === `win32`) {
const driveLetter = process.cwd().charAt(0);
const driveLetter = cwd.charAt(0);
defaultTranspileOptions.cache.dir = path.join(defaultTranspileOptions.cache.dir, driveLetter);

@@ -18,0 +19,0 @@ }

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

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -35,2 +35,3 @@ <p align="center">

### allowConfigurationWithComments
You can define if file should be imported in the default `transpile` mode or `compile` mode by placing a comment on top of the specific file.

@@ -56,3 +57,3 @@

- **Asynchronous and synchronous version** - uses **import** for async and **require** for sync.
- **Caches JavaScript** files into directory inside **node_modules/ts-import/cache** (pretty much like **typescript-require**). Removing node_modules removes cache as well.
- **Caches JavaScript** files into directory inside **.cache/ts-import**.
- **Fast** - I've benchmarked ways to compare detecting file changes with **fs** module and checking mtimeMs turned out to be fastest (https://jsperf.com/fs-stat-mtime-vs-mtimems). Also, compilation in version 3 is approximately 10x faster than in version 2.

@@ -59,0 +60,0 @@ - **Highly flexible and configurable** - all compilerOptions are available under transpileOptions parameter.

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

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