Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert: #529 #571

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/rollup/plugins/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export function externals (opts: NodeExternalsOptions): Plugin {
const isNewer = semver.gt(v2, v1)

// Warn about major version differences
const getMajor = (v: string) => v.split('.').filter(s => s !== '0')[0]
const getMajor = v => v.split('.').filter(s => s !== '0')[0]
if (getMajor(v1) !== getMajor(v2)) {
const warn = `Multiple major versions of package \`${pkgName}\` are being externalized. Picking latest version:\n\n` + [
` ${isNewer ? '-' : '+'} ` + existingPkgDir + '@' + v1,
Expand All @@ -195,14 +195,13 @@ export function externals (opts: NodeExternalsOptions): Plugin {
}
}

const [newerDir, olderDir] = isNewer ? [pkgDir, existingPkgDir] : [existingPkgDir, pkgDir]
// Try to map traced files from one package to another for minor/patch versions
if (getMajor(v1) === getMajor(v2)) {
tracedFiles = tracedFiles.map(f => f.startsWith(olderDir + '/') ? f.replace(olderDir, newerDir) : f)
}
// Exclude older version files
ignoreDirs.push(olderDir + '/')
pkgDir = newerDir // Update for tracedPackages
if (isNewer) {
ignoreDirs.push(existingPkgDir)
} else {
ignoreDirs.push(pkgDir)
pkgDir = existingPkgDir // Update for tracedPackages
}
}

// Add to traced packages
Expand All @@ -225,13 +224,9 @@ export function externals (opts: NodeExternalsOptions): Plugin {
if (!await isFile(file)) { return }
const src = resolve(opts.traceOptions.base, file)
const { pkgName, subpath } = parseNodeModulePath(file)
const dst = resolve(opts.outDir, `node_modules/${pkgName + subpath}`)
const dst = resolve(opts.outDir, `node_modules/${pkgName}/${subpath}`)
await fsp.mkdir(dirname(dst), { recursive: true })
try {
await fsp.copyFile(src, dst)
} catch (err) {
consola.warn(`Could not resolve \`${src}\`. Skipping.`)
}
await fsp.copyFile(src, dst)
}

// Write traced files
Expand Down