Socket
Socket
Sign inDemoInstall

load-tsconfig

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

load-tsconfig - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

dist/index.cjs

81

dist/index.js

@@ -20,2 +20,9 @@ var __defProp = Object.defineProperty;

var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
return require.apply(this, arguments);
throw new Error('Dynamic require of "' + x + '" is not supported');
});

@@ -27,7 +34,73 @@ // src/index.ts

// 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 " + strip(data).trim())();
return new Function("return " + stripJsonComments(data).trim())();
} catch (_) {

@@ -39,3 +112,3 @@ return {};

// src/index.ts
var require2 = createRequire(import.meta.url);
var req = typeof __require === "function" ? __require : createRequire(import.meta.url);
var findUp = (name, startDir, stopDir = path.parse(startDir).root) => {

@@ -61,3 +134,3 @@ let dir = startDir;

return findUp(name, cwd);
const id = require2.resolve(name, { paths: [cwd] });
const id = req.resolve(name, { paths: [cwd] });
return id;

@@ -64,0 +137,0 @@ };

19

package.json
{
"name": "load-tsconfig",
"version": "0.2.1",
"version": "0.2.2",
"description": "Load tsconfig.json",

@@ -12,6 +12,11 @@ "publishConfig": {

"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"default": "./dist/index.cjs"
}
},
"scripts": {
"build-fast": "tsup src/index.ts --format esm --target node14",
"build-fast": "tsup src/index.ts --format esm,cjs --target node12.20.0",
"build": "pnpm build-fast -- --dts-resolve",

@@ -27,12 +32,10 @@ "test": "npm run build-fast && vitest run",

"prettier": "2.5.1",
"strip-json-comments": "4.0.0",
"tsup": "5.11.11",
"typescript": "4.5.5",
"vitest": "0.2.3"
"vitest": "0.2.5"
},
"dependencies": {
"strip-json-comments": "4.0.0"
},
"engines": {
"node": ">=14"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
}

@@ -33,3 +33,3 @@ **💛 You can help the author become a full-time open-source maintainer by [sponsoring him on GitHub](https://github.com/sponsors/egoist).**

```ts
loadTsConfig(".", "./tsconfig.build.json")
loadTsConfig(".", "tsconfig.build.json")
```

@@ -36,0 +36,0 @@

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