Socket
Socket
Sign inDemoInstall

esbuild-plugin-ts-references

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.1.0

63

index.js

@@ -15,3 +15,34 @@ const fs = require('fs');

const resolveRefPackages = (entrypoint) => {
const resolveRefPackages = (baseDir, tsconfig, processedDirs) => {
if (processedDirs.includes(baseDir)) {
return {};
}
processedDirs.push(baseDir);
return (tsconfig.references || []).reduce((acc, r) => {
const refPath = path.resolve(baseDir, r.path);
const refPackage = parseJSONFile(path.join(refPath, 'package.json'));
const refTsconfig = parseJSONFile(
path.join(refPath, 'tsconfig.json'),
true
);
if (!refTsconfig.compilerOptions?.rootDir) {
throw new Error(
`rootDir is not defined in tsconfig.json of package '${refPackage.name}'`
);
}
acc[refPackage.name] = path.resolve(
refPath,
refTsconfig.compilerOptions.rootDir
);
Object.assign(acc, resolveRefPackages(refPath, refTsconfig, processedDirs));
return acc;
}, {});
};
const resolveEntrypoint = (entrypoint) => {
// look for the closest tsconfig

@@ -35,16 +66,5 @@ const rootDir = path.parse(entrypoint).root;

const tsconfig = parseJSONFile(tsconfigPath, true);
return (tsconfig.references || []).reduce((acc, r) => {
const refPath = path.resolve(baseDir, r.path);
const refPackage = parseJSONFile(path.join(refPath, 'package.json'));
const refTsconfig = parseJSONFile(
path.join(refPath, 'tsconfig.json'),
true
);
acc[refPackage.name] = path.resolve(
refPath,
refTsconfig.compilerOptions.rootDir
);
return acc;
}, {});
// avoid infinite loop for circular dependencies
const processedDirs = [];
return resolveRefPackages(baseDir, tsconfig, processedDirs);
};

@@ -58,9 +78,8 @@

const entryPointOptions = build.initialOptions.entryPoints;
const entryPoints = Array.isArray(entryPointOptions) ? entryPointOptions : Object.values(entryPointOptions);
const refPackages = entryPoints.reduce(
(acc, entrypoint) => {
return Object.assign(acc, resolveRefPackages(entrypoint));
},
{}
);
const entryPoints = Array.isArray(entryPointOptions)
? entryPointOptions
: Object.values(entryPointOptions);
const refPackages = entryPoints.reduce((acc, entrypoint) => {
return Object.assign(acc, resolveEntrypoint(entrypoint));
}, {});

@@ -67,0 +86,0 @@ // resolve packages

{
"name": "esbuild-plugin-ts-references",
"version": "0.0.3",
"version": "0.1.0",
"description": "esbuild plugin for typescript references",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc