Skip to content

Commit

Permalink
[polymer-bundler] Fix issue where excludes that are redirected are ig…
Browse files Browse the repository at this point in the history
…nored (#3320)

* Renamed polymer-bundler_test.ts to cli_test.ts because that makes it clearer what the file is actually testing.
* Resolve exclude URLs when polymer-bundler is constructed.
* Separated assertions around the --redirect and --exclude features of the CLI.
  • Loading branch information
usergenic authored Jan 8, 2019
1 parent 096f3da commit 054c375
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/bundler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
* Fixed issue where excluded URLs were not resolved by the analyzer when bundler was initialized, resulting in some imports not being treated as excluded.
* Removed non-essential files from published package, such as tests.
<!-- Add new, unreleased changes here. -->

Expand Down
4 changes: 3 additions & 1 deletion packages/bundler/src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export class Bundler {
this.analyzer = new Analyzer({urlLoader: this._overlayUrlLoader});
}

this.excludes = Array.isArray(opts.excludes) ? opts.excludes : [];
this.excludes = Array.isArray(opts.excludes) ?
opts.excludes.map((url) => this.analyzer.resolveUrl(url)!) :
[];
this.stripComments = Boolean(opts.stripComments);
this.enableCssInlining =
opts.inlineCss === undefined ? true : opts.inlineCss;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ suite('polymer-bundler CLI', () => {
});

suite('--redirect', () => {
const projectRoot =
resolvePath(__dirname, '../../test/html')
// Force forward-slashes so quoting works with Windows paths.
.replace(/\\/g, '/');
const tempdir = getTempDir();
const manifestPath = resolvePath(tempdir, 'bundle-manifest.json');

test('handles URLs with arbitrary protocols and hosts', async () => {
const projectRoot =
resolvePath(__dirname, '../../test/html')
// Force forward-slashes so quoting works with Windows paths.
.replace(/\\/g, '/');
const tempdir = getTempDir();
const manifestPath = resolvePath(tempdir, 'bundle-manifest.json');
const stdout =
execSync([
`cd ${projectRoot}`,
Expand All @@ -171,8 +172,7 @@ suite('polymer-bundler CLI', () => {
assert.include(stdout, 'This is an external dependency');
assert.include(stdout, 'id="home-page"');
assert.include(stdout, 'id="settings-page"');
const manifestJson = fs.readFileSync(manifestPath).toString();
const manifest = JSON.parse(manifestJson);
const manifest = JSON.parse(fs.readFileSync(manifestPath).toString());
assert.deepEqual(manifest, {
'myapp://app/index.html': [
'myapp://app/index.html',
Expand All @@ -182,5 +182,52 @@ suite('polymer-bundler CLI', () => {
],
});
});

test('handles redirection to folders outside project root', async () => {
const stdout = execSync([
`cd ${projectRoot}/complicated`,
`node ${cliPath} myapp://app/index.html ` +
`--redirect="myapp://app/|../url-redirection/" ` +
`--redirect="vendor://|../bower_components/" ` +
`--manifest-out ${manifestPath}`
].join(' && '))
.toString();
assert.include(stdout, 'This is an external dependency');
assert.include(stdout, 'id="home-page"');
assert.include(stdout, 'id="settings-page"');
const manifest = JSON.parse(fs.readFileSync(manifestPath).toString());
assert.deepEqual(manifest, {
'myapp://app/index.html': [
'myapp://app/index.html',
'myapp://app/home.html',
'vendor://external-dependency/external-dependency.html',
'myapp://app/settings.html'
],
});
});

test('handles excludes which are redirected URLs', async () => {
const stdout =
execSync([
`cd ${projectRoot}`,
`node ${cliPath} myapp://app/index.html ` +
`--redirect="myapp://app/|${projectRoot}/url-redirection/" ` +
`--redirect="vendor://|${projectRoot}/bower_components/" ` +
`--exclude="myapp://app/settings.html" ` +
`--manifest-out ${manifestPath}`
].join(' && '))
.toString();
assert.include(stdout, 'This is an external dependency');
assert.include(stdout, 'id="home-page"');
assert.notInclude(stdout, 'id="settings-page"');
const manifest = JSON.parse(fs.readFileSync(manifestPath).toString());
assert.deepEqual(manifest, {
'myapp://app/index.html': [
'myapp://app/index.html',
'myapp://app/home.html',
'vendor://external-dependency/external-dependency.html'
],
});
});
});
});

0 comments on commit 054c375

Please sign in to comment.