experimental-prisma-webpack-plugin
Advanced tools
Comparing version 0.0.4 to 0.0.5
44
index.js
@@ -38,7 +38,7 @@ // @ts-check | ||
apply(compiler) { | ||
const { webpack } = compiler; | ||
const { Compilation, sources } = webpack; | ||
const { webpack } = compiler | ||
const { Compilation, sources } = webpack | ||
let schemaCount = 0 | ||
const fromDestPrismaMap = [] // [from, dest][] | ||
const fromDestPrismaMap = {} // { [from]: dest } | ||
@@ -69,20 +69,24 @@ // read bundles to find which prisma files to copy (for all users) | ||
const fromDestFileMap = prismaFiles.map((f) => { | ||
prismaFiles.forEach((f) => { | ||
const from = path.join(prismaDir, f) | ||
if (f === 'schema.prisma') { | ||
f += ++schemaCount // to be able to handle multiple schema.prisma | ||
// if we have multiple schema.prisma files, we need to rename them | ||
if (f === 'schema.prisma' && fromDestPrismaMap[from] === undefined) { | ||
f += ++schemaCount | ||
} | ||
// if we already have renamed it, we need to get its "renamed" name | ||
if (f.includes('schema.prisma') && fromDestPrismaMap[from] !== undefined) { | ||
f = path.basename(fromDestPrismaMap[from]) | ||
} | ||
if (f.includes('schema.prisma')) { | ||
// update "schema.prisma" to "schema.prisma{number}" in the sources | ||
const newSourceString = oldSourceContents.replace(/schema\.prisma/g, f) | ||
const newRawSource = new sources.RawSource(newSourceString) | ||
compilation.updateAsset(assetName, newRawSource); | ||
compilation.updateAsset(assetName, newRawSource) | ||
} | ||
const dest = path.join(assetDir, f) | ||
return [from, dest] | ||
fromDestPrismaMap[from] = path.join(assetDir, f) | ||
}) | ||
fromDestPrismaMap.push(...fromDestFileMap) | ||
} | ||
@@ -93,4 +97,4 @@ }) | ||
} | ||
); | ||
}); | ||
) | ||
}) | ||
@@ -118,3 +122,3 @@ // update nft.json files to include prisma files (only for vercel) | ||
// update sources | ||
fromDestPrismaMap.forEach(([from, dest]) => { | ||
Object.entries(fromDestPrismaMap).forEach(([from, dest]) => { | ||
ntfLoadedAsJson.files.push(path.relative(assetDir, dest)) | ||
@@ -126,3 +130,3 @@ }) | ||
const newRawSource = new sources.RawSource(newSourceString) | ||
compilation.updateAsset(assetName, newRawSource); | ||
compilation.updateAsset(assetName, newRawSource) | ||
}) | ||
@@ -132,8 +136,8 @@ | ||
} | ||
); | ||
}); | ||
) | ||
}) | ||
// copy prisma files to output as the final step (for all users) | ||
compiler.hooks.done.tapPromise('PrismaPlugin', async () => { | ||
const asyncActions = fromDestPrismaMap.map(async ([from, dest]) => { | ||
const asyncActions = Object.entries(fromDestPrismaMap).map(async ([from, dest]) => { | ||
// only copy if file doesn't exist, necessary for watch mode | ||
@@ -146,3 +150,3 @@ if (await fs.access(dest).catch(() => false) === false) { | ||
await Promise.all(asyncActions) | ||
}); | ||
}) | ||
} | ||
@@ -149,0 +153,0 @@ } |
{ | ||
"name": "experimental-prisma-webpack-plugin", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Ensures that your Prisma files are copied", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6500
122