Socket
Socket
Sign inDemoInstall

typescript-to-lua

Package Overview
Dependencies
Maintainers
2
Versions
157
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-to-lua - npm Package Compare versions

Comparing version 1.11.1 to 1.12.0

dist/transpilation/find-lua-requires.d.ts

42

dist/transpilation/resolve.js

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

const CompilerOptions_1 = require("../CompilerOptions");
const find_lua_requires_1 = require("./find-lua-requires");
const resolver = resolve.ResolverFactory.createResolver({

@@ -36,8 +37,9 @@ extensions: [".lua"],

this.resolvedFiles.set(file.fileName, file);
for (const required of findRequiredPaths(file.code)) {
// Do this backwards so the replacements do not mess with the positions of the previous requires
for (const required of (0, find_lua_requires_1.findLuaRequires)(file.code).reverse()) {
// Do not resolve noResolution paths
if (required.startsWith("@NoResolution:")) {
if (required.requirePath.startsWith("@NoResolution:")) {
// Remove @NoResolution prefix if not building in library mode
if (!isBuildModeLibrary(this.program)) {
const path = required.replace("@NoResolution:", "");
const path = required.requirePath.replace("@NoResolution:", "");
replaceRequireInCode(file, required, path);

@@ -55,17 +57,17 @@ replaceRequireInSourceMap(file, required, path);

// Do no resolve lualib - always use the lualib of the application entry point, not the lualib from external packages
if (required === "lualib_bundle") {
if (required.requirePath === "lualib_bundle") {
this.resolvedFiles.set("lualib_bundle", { fileName: "lualib_bundle", code: "" });
return;
}
if (this.noResolvePaths.has(required)) {
if (this.noResolvePaths.has(required.requirePath)) {
if (this.options.tstlVerbose) {
console.log(`Skipping module resolution of ${required} as it is in the tsconfig noResolvePaths.`);
console.log(`Skipping module resolution of ${required.requirePath} as it is in the tsconfig noResolvePaths.`);
}
return;
}
const dependencyPath = this.resolveDependencyPath(file, required);
const dependencyPath = this.resolveDependencyPath(file, required.requirePath);
if (!dependencyPath)
return this.couldNotResolveImport(required, file);
if (this.options.tstlVerbose) {
console.log(`Resolved ${required} to ${(0, utils_1.normalizeSlashes)(dependencyPath)}`);
console.log(`Resolved ${required.requirePath} to ${(0, utils_1.normalizeSlashes)(dependencyPath)}`);
}

@@ -102,3 +104,3 @@ this.processDependency(dependencyPath);

replaceRequireInSourceMap(file, required, fallbackRequire);
this.diagnostics.push((0, diagnostics_1.couldNotResolveRequire)(required, path.relative((0, transpiler_1.getProjectRoot)(this.program), file.fileName)));
this.diagnostics.push((0, diagnostics_1.couldNotResolveRequire)(required.requirePath, path.relative((0, transpiler_1.getProjectRoot)(this.program), file.fileName)));
}

@@ -268,18 +270,8 @@ resolveDependencyPath(requiringFile, dependency) {

}
function findRequiredPaths(code) {
// Find all require("<path>") paths in a lua code string
const paths = [];
const pattern = /(^|\s|;|=|\()require\s*\(?(["|'])(.+?)\2\)?/g;
// eslint-disable-next-line @typescript-eslint/ban-types
let match;
while ((match = pattern.exec(code))) {
paths.push(match[3]);
}
return paths;
}
function replaceRequireInCode(file, originalRequire, newRequire) {
const requirePath = (0, utils_1.formatPathToLuaPath)(newRequire.replace(".lua", ""));
// Escape special characters to prevent the regex from breaking...
const escapedRequire = originalRequire.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
file.code = file.code.replace(new RegExp(`(^|\\s|;|=|\\()require\\s*\\(?["|']${escapedRequire}["|']\\)?`), `$1require("${requirePath}")`);
file.code = file.code =
file.code.substring(0, originalRequire.from) +
`require("${requirePath}")` +
file.code.substring(originalRequire.to + 1);
}

@@ -289,3 +281,3 @@ function replaceRequireInSourceMap(file, originalRequire, newRequire) {

if (file.sourceMapNode) {
replaceInSourceMap(file.sourceMapNode, file.sourceMapNode, `"${originalRequire}"`, `"${requirePath}"`);
replaceInSourceMap(file.sourceMapNode, file.sourceMapNode, `"${originalRequire.requirePath}"`, `"${requirePath}"`);
}

@@ -325,3 +317,3 @@ }

return (0, utils_1.formatPathToLuaPath)(path
.normalize(path.join(path.relative(sourceRootDir, fileDir), required))
.normalize(path.join(path.relative(sourceRootDir, fileDir), required.requirePath))
.split(path.sep)

@@ -328,0 +320,0 @@ .filter(s => s !== "." && s !== "..")

{
"name": "typescript-to-lua",
"version": "1.11.1",
"version": "1.12.0",
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",

@@ -5,0 +5,0 @@ "repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",

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