Skip to content

Commit

Permalink
fix: resolve AEM import path
Browse files Browse the repository at this point in the history
The hashsum of the generated file was incorrectly calculated for some files
  • Loading branch information
cshawaus committed Jan 20, 2022
1 parent 4a34255 commit bca085c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 8 additions & 13 deletions src/bundles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,17 @@ export function bundlesImportRewriter(options: BundlesImportRewriterOptions): Pl
const mainEntryPath = getMainEntryPath()
const mainEntryAEMPath = getAEMImportFilePath(mainEntryPath, options)

const mainEntryAEMPathWithHash = getAEMImportFilePath(
mainEntryPath,
options,
true,
rollupOptions as NormalizedOutputOptions,
)

for (const [fileName, chunk] of Object.entries(bundles)) {
if (!isOutputChunk(chunk) || !chunk.code) {
continue
}

let aemImportPath = mainEntryAEMPath

if (options.caching && options.caching.enabled) {
aemImportPath = getAEMImportFilePath(mainEntryPath, options, true, rollupOptions as NormalizedOutputOptions)
}

const source = chunk.code

await init
Expand Down Expand Up @@ -141,11 +140,7 @@ export function bundlesImportRewriter(options: BundlesImportRewriterOptions): Pl
importPath &&
importPath.substring(importPath.lastIndexOf('/') + 1) === mainEntryAEMPath
) {
str().overwrite(
start,
end,
importPath.substring(0, importPath.lastIndexOf('/') + 1) + mainEntryAEMPathWithHash,
)
str().overwrite(start, end, importPath.substring(0, importPath.lastIndexOf('/') + 1) + aemImportPath)
}

// Dynamic imports
Expand All @@ -166,7 +161,7 @@ export function bundlesImportRewriter(options: BundlesImportRewriterOptions): Pl
let newSource = (s && s.toString()) || source

// Ensure all entry file imports are replaced with the correct AEM ClientLib path
newSource = newSource.replace(new RegExp(mainEntryPath, 'g'), mainEntryAEMPathWithHash)
newSource = newSource.replace(new RegExp(mainEntryPath, 'g'), aemImportPath)

writeFileSync(join(rollupOptions.dir as string, fileName), newSource)
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function getAEMImportFilePath(
if (mainEntryPath && mainEntryPath === path) {
path = `${path.substring(0, path.indexOf('/'))}.js`

if (withCacheChecksum && options.caching && options.caching.enabled && rollupOptions) {
if (withCacheChecksum && options.caching && options.caching.enabled && rollupOptions !== undefined) {
const entryPath = join(rollupOptions.dir as string, mainEntryPath)

// Remove '.js'
Expand Down

0 comments on commit bca085c

Please sign in to comment.