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

@batijs/build

Package Overview
Dependencies
Maintainers
0
Versions
311
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@batijs/build - npm Package Compare versions

Comparing version 0.0.282 to 0.0.286

113

dist/index.js

@@ -183,2 +183,76 @@ // src/index.ts

// src/relations.ts
import { extname } from "node:path";
var RelationFile = class _RelationFile {
constructor(pathAbsolute, includeIfImported) {
this.pathAbsolute = pathAbsolute;
this.includeIfImported = includeIfImported;
_RelationFile.allPathAbsolute.set(pathAbsolute, this);
if (includeIfImported) {
_RelationFile.allIncludeIfImported.push(this);
}
}
static allPathAbsolute = /* @__PURE__ */ new Map();
static allIncludeIfImported = [];
};
var RelationImport = class _RelationImport {
constructor(source, importTarget) {
this.source = source;
this.importTarget = importTarget;
_RelationImport.allImports.push(this);
}
static allImports = [];
get importTargetRelationFile() {
const potentialTargets = importToPotentialTargets(this.importTarget);
for (const target of potentialTargets) {
if (RelationFile.allPathAbsolute.has(target)) {
return RelationFile.allPathAbsolute.get(target);
}
}
}
static computeUnimportedFiles() {
const unimportedFiles = [];
const importedByVolatileFile = [];
for (const file of RelationFile.allIncludeIfImported) {
const importedFile = _RelationImport.allImports.find((ai) => ai.importTargetRelationFile === file);
if (!importedFile) {
unimportedFiles.push(file);
} else if (importedFile.source.includeIfImported) {
importedByVolatileFile.push(importedFile);
}
}
return computeDeepUnimportedFiles(importedByVolatileFile, unimportedFiles);
}
};
function computeDeepUnimportedFiles(importedByVolatileFile, unimportedFiles) {
const copyImportedByVolatileFile = Array.from(importedByVolatileFile);
let redo = false;
for (const relationImport of copyImportedByVolatileFile) {
const found = unimportedFiles.find((uf) => uf === relationImport.source);
if (found) {
redo = true;
unimportedFiles.push(relationImport.importTargetRelationFile);
importedByVolatileFile = importedByVolatileFile.filter((i) => i !== relationImport);
}
}
if (redo) {
computeDeepUnimportedFiles(importedByVolatileFile, unimportedFiles);
}
return unimportedFiles;
}
function importToPotentialTargets(imp) {
let subject = imp;
const ext = extname(imp);
const targets = [];
if (ext.match(/^\.[jt]sx?$/)) {
subject = subject.replace(/^\.[jt]sx?$/, "");
}
if (!ext || subject !== imp) {
targets.push(...[".js", ".jsx", ".ts", ".tsx", ".cjs", ".mjs"].map((e) => `${subject}${e}`));
} else {
targets.push(imp);
}
return targets;
}
// src/index.ts

@@ -228,28 +302,12 @@ var reIgnoreFile = /^(chunk-|asset-|#)/gi;

}
function importToPotentialTargets(imp) {
let subject = imp;
const ext = path.extname(imp);
const targets = [];
if (ext.match(/^\.[jt]sx?$/)) {
subject = subject.replace(/^\.[jt]sx?$/, "");
}
if (!ext || subject !== imp) {
targets.push(...[".js", ".jsx", ".ts", ".tsx", ".cjs", ".mjs"].map((e) => `${subject}${e}`));
} else {
targets.push(imp);
}
return targets;
}
async function main(options, meta) {
const sources = Array.isArray(options.source) ? options.source : [options.source];
const allImports = /* @__PURE__ */ new Set();
const allImports = /* @__PURE__ */ new Map();
const filesContainingIncludeIfImported = /* @__PURE__ */ new Set();
function updateAllImports(target, imports) {
function updateAllImports(target, imports, includeIfImported) {
const rf = new RelationFile(target, includeIfImported);
if (!imports) return;
for (const imp of imports.values()) {
const importTarget = path.resolve(path.dirname(target), imp);
const importTargets = importToPotentialTargets(importTarget);
for (const imp2 of importTargets) {
allImports.add(imp2);
}
new RelationImport(rf, importTarget);
}

@@ -304,3 +362,7 @@ }

});
updateAllImports(op.destinationAbsolute, report.context?.imports);
updateAllImports(
op.destinationAbsolute,
report.context?.imports,
Boolean(report.context?.flags.has("include-if-imported"))
);
} else if (op.kind === "transform") {

@@ -315,5 +377,2 @@ report = await executeOperationTransform(op, {

}
if (report.context?.flags.has("include-if-imported")) {
filesContainingIncludeIfImported.add(op.destinationAbsolute);
}
previousOp = {

@@ -324,6 +383,4 @@ ...op,

}
for (const target of filesContainingIncludeIfImported) {
if (!allImports.has(target)) {
await safeRmFile(target, { removeEmptyDir: true });
}
for (const target of RelationImport.computeUnimportedFiles()) {
await safeRmFile(target.pathAbsolute, { removeEmptyDir: true });
}

@@ -330,0 +387,0 @@ }

{
"name": "@batijs/build",
"version": "0.0.282",
"version": "0.0.286",
"description": "",

@@ -13,6 +13,6 @@ "type": "module",

"tsup": "^8.3.0",
"@batijs/compile": "0.0.282"
"@batijs/compile": "0.0.286"
},
"dependencies": {
"@batijs/core": "0.0.282"
"@batijs/core": "0.0.286"
},

@@ -19,0 +19,0 @@ "main": "./dist/index.js",

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