Skip to content

Commit

Permalink
WIP: handle module concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Mar 1, 2023
1 parent bfe3ab0 commit 507fff7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ class CompartmentMapPlugin {
parser = 'pre-cjs-json'
// parser = 'cjs'
} else if (module.type === 'javascript/esm') {
parser = 'pre-mjs-json'
parser = module.constructor.name === 'ConcatenatedModule'
? 'pre-cjs-json'
: 'pre-mjs-json'
// parser = 'mjs'
} else if (module.type === 'runtime') {
parser = 'pre-cjs-json'
Expand All @@ -140,7 +142,7 @@ class CompartmentMapPlugin {
}
compartmentDescriptor.modules[moduleLabel] = moduleDescriptor

let moduleSource = source ? source.source() : 'source missing'
let moduleSource = source ? source.source() : (module.rootModule.originalSource()?.source || 'source missing')
moduleSource = evadeHtmlCommentTest(moduleSource)
moduleSource = evadeImportExpressionTest(moduleSource)
const moduleSourceBytes = Buffer.from(moduleSource, 'utf8')
Expand Down Expand Up @@ -253,11 +255,15 @@ async function processModuleSource (
}

function getModuleLocationRelativeToPackage (module, packageLocation) {
if (module.resource === undefined) {
const id = module.identifier()
return { plain: id, relative: id }
let p = module.resource;
if(!p) {
p = module.identifier();
if (!p.startsWith('javascript/esm|')) {
return { plain: id, relative: id };
}
p = p.split('|')[1];
}
const locPlain = relative(packageLocation, module.resource)
const locPlain = relative(packageLocation, p)
const locRelative = locPlain.startsWith('.') ? locPlain : `./${locPlain}`
return { plain: locPlain, relative: locRelative }
}
Expand Down

0 comments on commit 507fff7

Please sign in to comment.