Skip to content

Commit

Permalink
Preserve symlinks when resolving in rollup_bundle and ensure it does …
Browse files Browse the repository at this point in the history
…not resolve outside of execroot sandbox
  • Loading branch information
gregmagolan committed Apr 6, 2019
1 parent 61e35d3 commit 07bb3b0
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions internal/rollup/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function fileExists(filePath) {
// This resolver mimics the TypeScript Path Mapping feature, which lets us resolve
// modules based on a mapping of short names to paths.
function resolveBazel(importee, importer, baseDir = process.cwd(), resolve = require.resolve, root = rootDir) {
if (DEBUG) console.error(`\nRollup: resolving '${importee}' from ${importer}`);

function resolveInRootDir(importee) {
var candidate = path.join(baseDir, root, importee);
if (DEBUG) console.error(`Rollup: try to resolve '${importee}' at '${candidate}'`);
Expand All @@ -54,8 +56,6 @@ function resolveBazel(importee, importer, baseDir = process.cwd(), resolve = req
}
}

if (DEBUG) console.error(`Rollup: resolving '${importee}' from ${importer}`);

// Since mappings are always in POSIX paths, when comparing the importee to mappings
// we should normalize the importee.
// Having it normalized is also useful to determine relative paths.
Expand Down Expand Up @@ -113,8 +113,13 @@ function resolveBazel(importee, importer, baseDir = process.cwd(), resolve = req
resolved = resolveInRootDir(userWorkspacePath.startsWith('..') ? importee : userWorkspacePath);
}

if (DEBUG && !resolved)
console.error(`Rollup: allowing rollup to resolve '${importee}' with node module resolution`);
if (DEBUG) {
if (resolved) {
console.error(`Rollup: resolved to ${resolved}`);
} else {
console.error(`Rollup: allowing rollup to resolve '${importee}' with node module resolution`);
}
}

return resolved;
}
Expand Down Expand Up @@ -168,7 +173,10 @@ const config = {
throw new Error(warning.message);
},
plugins: [TMPL_additional_plugins].concat([
{resolveId: resolveBazel},
{
name: 'resolveBazel',
resolveId: resolveBazel,
},
// Use custom rollup-plugin-node-resolve dist which supports
// the 'es2015' option for rollup to prioritize the 'es2015' entry point
// with fallback to 'module' and 'main'.
Expand All @@ -177,6 +185,7 @@ const config = {
module: true,
jsnext: true,
main: true,
jail: process.cwd(),
customResolveOptions: {moduleDirectory: nodeModulesRoot}
}),
amd({
Expand All @@ -186,13 +195,17 @@ const config = {
include: /\.ngfactory\.js$/i,
}),
commonjs(),
{resolveId: notResolved},
{
name: 'notResolved',
resolveId: notResolved,
},
sourcemaps(),
]),
output: {
banner,
format: 'TMPL_output_format',
},
preserveSymlinks: true,
}

if (enableCodeSplitting) {
Expand Down

0 comments on commit 07bb3b0

Please sign in to comment.