Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "stayte", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "The persistent state library for the modern web", | ||
@@ -18,3 +18,3 @@ "exports": { | ||
"scripts": { | ||
"postinstall": "node scripts/patch.js", | ||
"postinstall": "node scripts/patch.js > file", | ||
"dev": "rollup --config rollup.config.mjs --watch", | ||
@@ -21,0 +21,0 @@ "build": "rm -rf dist && rollup --config rollup.config.mjs" |
const fs = require('fs') | ||
const path = require('path') | ||
@@ -25,2 +26,4 @@ const init_cwd = process.env.INIT_CWD | ||
const scannedPackages = getScannedPackages() | ||
// Loop over the patch object and check if the package is already patched | ||
@@ -31,2 +34,9 @@ // if not, we apply the patch in the current directory where statye will be installed | ||
// If the package is not installed on every project, we skip it | ||
const packageName = name.split('@')[0] | ||
if (!scannedPackages.find((packageJson) => packageJson.dependencies[packageName])) { | ||
continue | ||
} | ||
if (!packageJson.patchedDependencies[name]) { | ||
@@ -44,2 +54,39 @@ const patchPath = `${cwd}/${patch}` | ||
fs.writeFileSync(`${init_cwd}/package.json`, JSON.stringify(packageJson, null, 2), 'utf-8') | ||
fs.writeFileSync(`${init_cwd}/package.json`, JSON.stringify(packageJson, null, 2), 'utf-8') | ||
function getScannedPackages() { | ||
const packages = searchFiles(init_cwd, 'package.json') | ||
return packages.map((packageJson) => { | ||
const packageJsonContent = fs.readFileSync(packageJson, 'utf-8') | ||
const packageJsonObject = JSON.parse(packageJsonContent) | ||
return packageJsonObject | ||
}) | ||
} | ||
function searchFiles(dir, fileName) { | ||
let foundedFiles = [] | ||
try { | ||
// read the contents of the directory | ||
const files = fs.readdirSync(dir) | ||
// search through the files | ||
for (const file of files) { | ||
// build the full path of the file | ||
const filePath = path.join(dir, file); | ||
// get the file stats | ||
const fileStat = fs.statSync(filePath); | ||
// if the file is a directory, recursively search the directory | ||
if (fileStat.isDirectory() && !file.match(/node_modules|.git|.turbo|\./)) { | ||
foundedFiles.push(...searchFiles(filePath, fileName)) | ||
} else if (file.endsWith(fileName)) { | ||
foundedFiles.push(filePath); | ||
} | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
return foundedFiles; | ||
} |
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
130548
1394