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

@ts-liveserver/ts-transpiler

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-liveserver/ts-transpiler - npm Package Compare versions

Comparing version 0.0.21 to 0.0.22

8

dist/transformers/ResolveTransformer.js

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

typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
const resolvedName = new DependencyResolver_1.default(sourceFile.fileName, this.context).resolveRelativeDependency(node.moduleSpecifier.text);
const resolvedName = new DependencyResolver_1.default(sourceFile.fileName).resolveRelativeDependency(node.moduleSpecifier.text);
return typescript_1.default.factory.updateImportDeclaration(node, node.decorators, node.modifiers, node.importClause, typescript_1.default.factory.createStringLiteral(resolvedName));

@@ -30,3 +30,3 @@ }

typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
const resolvedName = new DependencyResolver_1.default(sourceFile.fileName, this.context).resolveRelativeDependency(node.moduleSpecifier.text);
const resolvedName = new DependencyResolver_1.default(sourceFile.fileName).resolveRelativeDependency(node.moduleSpecifier.text);
return typescript_1.default.factory.updateExportDeclaration(node, undefined, undefined, node.isTypeOnly, undefined, typescript_1.default.factory.createStringLiteral(resolvedName));

@@ -45,3 +45,3 @@ }

node === node.parent.arguments[0]) {
return typescript_1.default.factory.createStringLiteral(new DependencyResolver_1.default(sourceFile.fileName, this.context).resolveRelativeDependency(node.text));
return typescript_1.default.factory.createStringLiteral(new DependencyResolver_1.default(sourceFile.fileName).resolveRelativeDependency(node.text));
}

@@ -63,3 +63,3 @@ return typescript_1.default.visitEachChild(node, visit, this.context);

node.parent.moduleSpecifier) {
return typescript_1.default.factory.createStringLiteral(new DependencyResolver_1.default(node.getSourceFile().fileName, this.context).resolveRelativeDependency(node.text));
return typescript_1.default.factory.createStringLiteral(new DependencyResolver_1.default(node.getSourceFile().fileName).resolveRelativeDependency(node.text));
}

@@ -66,0 +66,0 @@ return node;

@@ -1,6 +0,5 @@

import TypeScript from 'typescript';
export default class DependencyResolver {
private context;
private resolver;
private fileName;
constructor(fileName: string, context: TypeScript.TransformationContext);
constructor(fileName: string);
resolveRelativeDependency(dependencyFileName: string): string;

@@ -7,0 +6,0 @@ private resolveDependencyName;

@@ -6,8 +6,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const typescript_1 = __importDefault(require("typescript"));
const path_1 = __importDefault(require("path"));
const enhanced_resolve_1 = __importDefault(require("enhanced-resolve"));
const RESOLVE_EXTENSIONS = ['.js', '.ts', '.tsx', '.jsx', '.json'];
class DependencyResolver {
constructor(fileName, context) {
constructor(fileName) {
this.resolver = enhanced_resolve_1.default.create.sync({
extensions: RESOLVE_EXTENSIONS,
});
this.fileName = fileName;
this.context = context;
}

@@ -18,4 +21,4 @@ resolveRelativeDependency(dependencyFileName) {

// Return e.g. ./hello/module.js
resolveDependencyName(parentPath, dendencyName) {
const absolutePath = this.resolveDependencyPath(parentPath, dendencyName);
resolveDependencyName(parentPath, dependencyName) {
const absolutePath = this.resolveDependencyPath(parentPath, dependencyName);
const pathObj = path_1.default.parse(absolutePath);

@@ -30,17 +33,9 @@ const relativeDir = path_1.default.relative(path_1.default.dirname(parentPath), pathObj.dir) || '.';

// Return an aboslute path e.g. /tmp/a-apath/node_modules/hello/module.js
resolveDependencyPath(parentPath, dendencyName) {
const resolveResults = typescript_1.default.resolveModuleName(dendencyName, parentPath, this.context.getCompilerOptions(), typescript_1.default.createCompilerHost(this.context.getCompilerOptions()));
if (resolveResults?.resolvedModule?.isExternalLibraryImport) {
const nodeResolve = require.resolve(dendencyName, {
paths: [path_1.default.dirname(parentPath)],
});
if (nodeResolve) {
return nodeResolve;
}
resolveDependencyPath(parentPath, dependencyName) {
const withoutExtension = dependencyName.replace(path_1.default.extname(dependencyName), '');
const result = this.resolver({}, path_1.default.dirname(parentPath), withoutExtension);
if (result === false) {
throw new Error('Could not resolve ' + dependencyName + ' from ' + parentPath);
}
const resolvedFileName = resolveResults?.resolvedModule?.resolvedFileName;
if (!resolvedFileName) {
throw new Error('Could not resolve' + dendencyName + 'from module' + parentPath);
}
return resolvedFileName;
return result;
}

@@ -47,0 +42,0 @@ }

{
"name": "@ts-liveserver/ts-transpiler",
"version": "0.0.21",
"version": "0.0.22",
"main": "dist/index.js",

@@ -19,4 +19,5 @@ "scripts": {

"dependencies": {
"typescript": "4.x.x"
"typescript": "4.x.x",
"enhanced-resolve": "5.x.x"
}
}

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