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

experimental-prisma-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

experimental-prisma-webpack-plugin - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

58

index.js

@@ -7,5 +7,6 @@ // @ts-check

// if client is bundled this gets its output path
const prismaPathRegex = /"?output"?:\s*{\s*"?value"?:\s*"(.*?)",\s*"?fromEnvVar"?/g
// regex works both on escaped and non-escaped code
const prismaDirRegex = /\\?"?output\\?"?:\s*{(?:\\n?|\s)*\\?"?value\\?"?:(?:\\n?|\s)*\\?"(.*?)\\?",(?:\\n?|\s)*\\?"?fromEnvVar\\?"?/g
function getPrismaPath(from) {
function getPrismaDir(from) {
try {

@@ -20,5 +21,5 @@ return path.dirname(require.resolve('.prisma/client', { paths: [from] }))

async function getPrismaFiles(from) {
const prismaPath = getPrismaPath(from)
const prismaDir = getPrismaDir(from)
const filterRegex = /schema\.prisma|.*?engine.*?/
const prismaFiles = await fs.readdir(prismaPath)
const prismaFiles = await fs.readdir(prismaDir)

@@ -51,14 +52,20 @@ return prismaFiles.filter(file => file.match(filterRegex))

const jsAssetNames = Object.keys(assets).filter((k) => k.endsWith('.js'))
const jsAsyncActions = jsAssetNames.map(async (assetName) => {
const oldSourceAsset = compilation.getAsset(assetName)
const oldSourceContents = oldSourceAsset.source.source() + ''
// prepare paths
const outputDir = compiler.outputPath
const assetPath = path.resolve(outputDir, assetName)
const assetDir = path.dirname(assetPath)
for (const match of oldSourceContents.matchAll(prismaPathRegex)) {
const prismaPath = getPrismaPath(match[1])
// get sources
const sourceAsset = compilation.getAsset(assetName)
const sourceContents = sourceAsset.source.source() + ''
// update files to copy
for (const match of sourceContents.matchAll(prismaDirRegex)) {
const prismaDir = getPrismaDir(match[1])
const prismaFiles = await getPrismaFiles(match[1])
const fromDestFileMap = prismaFiles.map((f) => [
path.join(prismaPath, f), // from
path.join(compiler.outputPath, f) // dest
path.join(prismaDir, f), // from
path.join(assetDir, f) // dest
])

@@ -84,10 +91,9 @@

const nftAssetNames = Object.keys(assets).filter((k) => k.endsWith('.nft.json'))
const nftAsyncActions = nftAssetNames.map(async (assetName) => {
// paths
const outputPath = compiler.outputPath
const assetPath = path.resolve(outputPath, assetName)
// prepare paths
const outputDir = compiler.outputPath
const assetPath = path.resolve(outputDir, assetName)
const assetDir = path.dirname(assetPath)
// data
// get sources
const oldSourceAsset = compilation.getAsset(assetName)

@@ -97,3 +103,3 @@ const oldSourceContents = oldSourceAsset.source.source() + ''

// update
// update sources
fromDestPrismaMap.forEach(([from, dest]) => {

@@ -103,3 +109,3 @@ ntfLoadedAsJson.files.push(path.relative(assetDir, dest))

// persist
// persist sources
const newSourceString = JSON.stringify(ntfLoadedAsJson)

@@ -116,8 +122,12 @@ const newRawSource = new sources.RawSource(newSourceString)

// copy prisma files to output as the final step (for all users)
compiler.hooks.done.tapPromise(
'PrismaPlugin',
async () => {
await Promise.all(fromDestPrismaMap.map(([from, dest]) => fs.copyFile(from, dest)))
}
);
compiler.hooks.done.tapPromise('PrismaPlugin', async () => {
const asyncActions = fromDestPrismaMap.map(async ([from, dest]) => {
// only copy if file doesn't exist, necessary for watch mode
if (await fs.access(dest).catch(() => false) === false) {
return fs.copyFile(from, dest)
}
})
await Promise.all(asyncActions)
});
}

@@ -124,0 +134,0 @@ }

{
"name": "experimental-prisma-webpack-plugin",
"version": "0.0.1",
"version": "0.0.2",
"description": "Ensures that your Prisma files are copied",

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

# Experimental Prisma Webpack Plugin
Ensures that your Prisma files are copied
## Next.js

@@ -4,0 +6,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