Skip to content

Commit

Permalink
fix: dedup non-exclusive external dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Apr 15, 2024
1 parent 73694e2 commit 8929482
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions rollup/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,9 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
},
'./vscode/*': {
default: './vscode/src/*.js'
},
'./external/*': {
default: './external/*'
}
},
typesVersions: {
Expand Down Expand Up @@ -883,9 +886,16 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {

const isVscodeFile = resolved.startsWith(VSCODE_SRC_DIST_DIR)
const isServiceOverride = path.dirname(resolved) === DIST_SERVICE_OVERRIDE_DIR_MAIN
const isNotExclusive = (isVscodeFile || isServiceOverride) && !exclusiveModules.has(resolvedWithExtension)
const isExclusive = exclusiveModules.has(resolvedWithExtension)
const pathFromRoot = path.relative(DIST_DIR_MAIN, resolvedWithExtension)
const shouldBeShared = SHARED_ROOT_FILES_BETWEEN_PACKAGES.includes(path.relative(DIST_DIR_MAIN, resolvedWithExtension))
if (isNotExclusive || shouldBeShared) {
if (pathFromRoot.startsWith('external/') && !isExclusive) {
return {
external: true,
id: `vscode/${pathFromRoot}`
}
}
if (((isVscodeFile || isServiceOverride) && !isExclusive) || shouldBeShared) {
// Those modules will be imported from external monaco-vscode-api
let externalResolved = resolved.startsWith(VSCODE_SRC_DIST_DIR) ? `vscode/vscode/${path.relative(VSCODE_SRC_DIST_DIR, resolved)}` : `vscode/${path.relative(DIST_DIR_MAIN, resolved)}`
if (externalResolved.endsWith('.js')) {
Expand Down Expand Up @@ -1032,10 +1042,17 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {

const isVscodeFile = resolved.startsWith(VSCODE_SRC_DIST_DIR)
const isServiceOverride = path.dirname(resolved) === DIST_SERVICE_OVERRIDE_DIR_MAIN
const isNotExclusive = (isVscodeFile || isServiceOverride) && !exclusiveModules.has(resolvedWithExtension)
const isExclusive = exclusiveModules.has(resolvedWithExtension)
const pathFromRoot = path.relative(DIST_DIR_MAIN, resolvedWithExtension)
const shouldBeShared = SHARED_ROOT_FILES_BETWEEN_PACKAGES.includes(path.relative(DIST_DIR_MAIN, resolvedWithExtension))
if (pathFromRoot.startsWith('external/') && !isExclusive) {
return {
external: true,
id: `vscode/${pathFromRoot}`
}
}

if (isNotExclusive || shouldBeShared) {
if (((isVscodeFile || isServiceOverride) && !isExclusive) || shouldBeShared) {
// Those modules will be imported from external monaco-vscode-api
let externalResolved = resolved.startsWith(VSCODE_SRC_DIST_DIR) ? `vscode/vscode/${path.relative(VSCODE_SRC_DIST_DIR, resolved)}` : `vscode/${path.relative(DIST_DIR_MAIN, resolved)}`
if (externalResolved.endsWith('.js')) {
Expand Down

0 comments on commit 8929482

Please sign in to comment.