From 07bb3b0c6961f7f43761cc34667486137e3e0ed2 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Sat, 6 Apr 2019 09:27:43 -0700 Subject: [PATCH] Preserve symlinks when resolving in rollup_bundle and ensure it does not resolve outside of execroot sandbox --- internal/rollup/rollup.config.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/rollup/rollup.config.js b/internal/rollup/rollup.config.js index e8a9da74de..a4527dd61b 100644 --- a/internal/rollup/rollup.config.js +++ b/internal/rollup/rollup.config.js @@ -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}'`); @@ -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. @@ -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; } @@ -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'. @@ -177,6 +185,7 @@ const config = { module: true, jsnext: true, main: true, + jail: process.cwd(), customResolveOptions: {moduleDirectory: nodeModulesRoot} }), amd({ @@ -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) {