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

als-require

Package Overview
Dependencies
Maintainers
0
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

als-require - npm Package Compare versions

Comparing version 1.5.2 to 1.5.4

lib/get-node-modules.js

4

lib/bundle.js
const UglifyJS = require("uglify-js");
const {stringify,parse} = require('als-object-serializer')
const { stringify, parse } = require('als-object-serializer')
const parseError = require('./parse-error')

@@ -9,3 +9,3 @@ const getFns = require('./get-fns')

obj.getContent()
const { fn, modulesLines, curLastLine } = getFns(contextName,obj)
const { fn, modulesLines, curLastLine } = getFns(contextName, obj)
const contents = {}

@@ -12,0 +12,0 @@ for (const path of obj.keys) {

@@ -5,4 +5,4 @@ const rootPath = process.cwd()

const getFullPath = require('./get-full-path')
const getNodeModules = require('./get-node-modules')
const packageJsonCache = {}
function getContents({contents,fullPath},Require) {

@@ -15,33 +15,8 @@ const getContent = (path) => {

content = content.replace(/^(?!\/\/|\/\*.*\*\/).*require\(["'`](.*)["'`]\)/gm, (match, modulePath) => {
let fullPath,relativePath,filename,moduleDir = modulePath
let fullPath
const r = new RegExp(`require\\((["'\`])${modulePath}["'\`]\\)`)
if (modulePath.startsWith('.')) fullPath = getFullPath(modulePath, path)
else {
if(modulePath.includes('/')) {
const arr = modulePath.split('/')
moduleDir = arr.shift()
relativePath = arr.join('/')
}
let pckgJsonPath = join(rootPath, 'node_modules', moduleDir, 'package.json')
if (!fs.existsSync(pckgJsonPath)) {
console.warn(`The module "${modulePath}" can't be imported and will be replaced with {}`)
return match.replace(r, '{}')
}
if(packageJsonCache[pckgJsonPath]) filename = packageJsonCache[pckgJsonPath]
else {
const packageJsonRaw = fs.readFileSync(pckgJsonPath, 'utf-8')
filename = JSON.parse(packageJsonRaw).main || 'index.js'
packageJsonCache[pckgJsonPath] = filename
}
if(relativePath) {
const relativeDir = filename.split('/')
relativeDir.pop()
fullPath = `/node_modules/${moduleDir}/${relativeDir.join('/')}/${relativePath}`
} else {
fullPath = `/node_modules/${moduleDir}/${filename}`
}
fullPath = fullPath.replace(/\/\.?\//g,'/')
if(!fullPath.endsWith('.js')) fullPath += '.js'
fullPath = getNodeModules(modulePath,rootPath)
if(fullPath === false) return match.replace(r, '{}')
}

@@ -48,0 +23,0 @@ if (Require.contents[fullPath] && Require.contents[fullPath].children.includes(path)) {

{
"name": "als-require",
"version": "1.5.2",
"version": "1.5.4",
"main": "index.js",

@@ -5,0 +5,0 @@ "scripts": {

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