load-tsconfig
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -1,9 +0,5 @@ | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
@@ -24,98 +20,13 @@ var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __export = (target, all) => { | ||
__markAsModule(target); | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __reExport = (target, module2, desc) => { | ||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
for (let key of __getOwnPropNames(module2)) | ||
if (!__hasOwnProp.call(target, key) && key !== "default") | ||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); | ||
} | ||
return target; | ||
}; | ||
var __toModule = (module2) => { | ||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2); | ||
}; | ||
// src/index.ts | ||
__export(exports, { | ||
loadTsConfig: () => loadTsConfig | ||
}); | ||
var import_path = __toModule(require("path")); | ||
var import_fs = __toModule(require("fs")); | ||
import path from "path"; | ||
import fs from "fs"; | ||
import { createRequire } from "module"; | ||
// node_modules/.pnpm/strip-json-comments@4.0.0/node_modules/strip-json-comments/index.js | ||
var singleComment = Symbol("singleComment"); | ||
var multiComment = Symbol("multiComment"); | ||
var stripWithoutWhitespace = () => ""; | ||
var stripWithWhitespace = (string, start, end) => string.slice(start, end).replace(/\S/g, " "); | ||
var isEscaped = (jsonString, quotePosition) => { | ||
let index = quotePosition - 1; | ||
let backslashCount = 0; | ||
while (jsonString[index] === "\\") { | ||
index -= 1; | ||
backslashCount += 1; | ||
} | ||
return Boolean(backslashCount % 2); | ||
}; | ||
function stripJsonComments(jsonString, { whitespace = true } = {}) { | ||
if (typeof jsonString !== "string") { | ||
throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``); | ||
} | ||
const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace; | ||
let isInsideString = false; | ||
let isInsideComment = false; | ||
let offset = 0; | ||
let result = ""; | ||
for (let index = 0; index < jsonString.length; index++) { | ||
const currentCharacter = jsonString[index]; | ||
const nextCharacter = jsonString[index + 1]; | ||
if (!isInsideComment && currentCharacter === '"') { | ||
const escaped = isEscaped(jsonString, index); | ||
if (!escaped) { | ||
isInsideString = !isInsideString; | ||
} | ||
} | ||
if (isInsideString) { | ||
continue; | ||
} | ||
if (!isInsideComment && currentCharacter + nextCharacter === "//") { | ||
result += jsonString.slice(offset, index); | ||
offset = index; | ||
isInsideComment = singleComment; | ||
index++; | ||
} else if (isInsideComment === singleComment && currentCharacter + nextCharacter === "\r\n") { | ||
index++; | ||
isInsideComment = false; | ||
result += strip(jsonString, offset, index); | ||
offset = index; | ||
continue; | ||
} else if (isInsideComment === singleComment && currentCharacter === "\n") { | ||
isInsideComment = false; | ||
result += strip(jsonString, offset, index); | ||
offset = index; | ||
} else if (!isInsideComment && currentCharacter + nextCharacter === "/*") { | ||
result += jsonString.slice(offset, index); | ||
offset = index; | ||
isInsideComment = multiComment; | ||
index++; | ||
continue; | ||
} else if (isInsideComment === multiComment && currentCharacter + nextCharacter === "*/") { | ||
index++; | ||
isInsideComment = false; | ||
result += strip(jsonString, offset, index + 1); | ||
offset = index + 1; | ||
continue; | ||
} | ||
} | ||
return result + (isInsideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset)); | ||
} | ||
// src/utils.ts | ||
import strip from "strip-json-comments"; | ||
function jsoncParse(data) { | ||
try { | ||
return new Function("return " + stripJsonComments(data).trim())(); | ||
return new Function("return " + strip(data).trim())(); | ||
} catch (_) { | ||
@@ -127,9 +38,10 @@ return {}; | ||
// src/index.ts | ||
var findUp = (name, startDir, stopDir = import_path.default.parse(startDir).root) => { | ||
var require2 = createRequire(import.meta.url); | ||
var findUp = (name, startDir, stopDir = path.parse(startDir).root) => { | ||
let dir = startDir; | ||
while (dir !== stopDir) { | ||
const file = import_path.default.join(dir, name); | ||
if (import_fs.default.existsSync(file)) | ||
const file = path.join(dir, name); | ||
if (fs.existsSync(file)) | ||
return file; | ||
dir = import_path.default.dirname(dir); | ||
dir = path.dirname(dir); | ||
} | ||
@@ -139,7 +51,7 @@ return null; | ||
var resolveTsConfig = (cwd, name) => { | ||
if (import_path.default.isAbsolute(name)) | ||
return import_fs.default.existsSync(name) ? name : null; | ||
if (path.isAbsolute(name)) | ||
return fs.existsSync(name) ? name : null; | ||
if (name.startsWith(".")) | ||
return findUp(name, cwd); | ||
const id = require.resolve(name, { paths: [cwd] }); | ||
const id = require2.resolve(name, { paths: [cwd] }); | ||
return id; | ||
@@ -149,10 +61,10 @@ }; | ||
var _a; | ||
const id = resolveTsConfig(import_path.default.resolve(dir), name); | ||
const id = resolveTsConfig(path.resolve(dir), name); | ||
if (!id) | ||
return null; | ||
const data = jsoncParse(import_fs.default.readFileSync(id, "utf-8")); | ||
const data = jsoncParse(fs.readFileSync(id, "utf-8")); | ||
__files.unshift(id); | ||
const configDir = import_path.default.dirname(id); | ||
const configDir = path.dirname(id); | ||
if ((_a = data.compilerOptions) == null ? void 0 : _a.baseUrl) { | ||
data.compilerOptions.baseUrl = import_path.default.join(configDir, data.compilerOptions.baseUrl); | ||
data.compilerOptions.baseUrl = path.join(configDir, data.compilerOptions.baseUrl); | ||
} | ||
@@ -170,5 +82,4 @@ if (data.extends) { | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
export { | ||
loadTsConfig | ||
}); | ||
}; |
{ | ||
"name": "load-tsconfig", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "Load tsconfig.json", | ||
@@ -11,8 +11,9 @@ "publishConfig": { | ||
], | ||
"type": "module", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build-fast": "tsup src/index.ts --format cjs --target node14", | ||
"build-fast": "tsup src/index.ts --format esm --target node14", | ||
"build": "pnpm build-fast -- --dts-resolve", | ||
"test": "vitest run", | ||
"test": "npm run build-fast && vitest run", | ||
"prepublishOnly": "pnpm build" | ||
@@ -26,3 +27,2 @@ }, | ||
"prettier": "2.5.1", | ||
"strip-json-comments": "4.0.0", | ||
"tsup": "5.11.11", | ||
@@ -32,2 +32,5 @@ "typescript": "4.5.5", | ||
}, | ||
"dependencies": { | ||
"strip-json-comments": "4.0.0" | ||
}, | ||
"engines": { | ||
@@ -34,0 +37,0 @@ "node": ">=14" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
7
Yes
6061
1
87
+ Addedstrip-json-comments@4.0.0
+ Addedstrip-json-comments@4.0.0(transitive)