diff --git a/packages/build/CHANGELOG.md b/packages/build/CHANGELOG.md index 5b790d6c5..8bc1af7bd 100644 --- a/packages/build/CHANGELOG.md +++ b/packages/build/CHANGELOG.md @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). - +## Unreleased +* Fix incorrect relative paths to the component directory in push manifests. +* Fix push manifest generation crash with ES module projects. ## [3.0.1] - 2018-05-14 diff --git a/packages/build/src/push-manifest.ts b/packages/build/src/push-manifest.ts index 93473d2ba..0e5f4cbb8 100644 --- a/packages/build/src/push-manifest.ts +++ b/packages/build/src/push-manifest.ts @@ -13,7 +13,7 @@ */ import * as path from 'path'; -import {Analyzer, Import, PackageRelativeUrl, ResolvedUrl} from 'polymer-analyzer'; +import {Analyzer, FsUrlResolver, Import, PackageRelativeUrl, ResolvedUrl} from 'polymer-analyzer'; import {buildDepsIndex} from 'polymer-bundler/lib/deps-index'; import {ProjectConfig} from 'polymer-project-config'; @@ -181,7 +181,10 @@ export class AddPushManifest extends AsyncTransformStream { super({objectMode: true}); this.files = new Map(); this.config = config; - this.analyzer = new Analyzer({urlLoader: new FileMapUrlLoader(this.files)}); + this.analyzer = new Analyzer({ + urlLoader: new FileMapUrlLoader(this.files), + urlResolver: new FsUrlResolver(config.root), + }); this.outPath = path.join(this.config.root, outPath || 'push-manifest.json') as LocalFsPath; @@ -212,13 +215,15 @@ export class AddPushManifest extends AsyncTransformStream { // Bundler's buildDepsIndex code generates an index with all fragments and // all lazy-imports encountered are the keys, so we'll use that function to // produce the set of all fragments to generate push-manifest entries for. - const allFragments = new Set( - (await buildDepsIndex( - this.config.allFragments.map( - (path) => this.analyzer.resolveUrl(urlFromPath( - this.config.root as LocalFsPath, path as LocalFsPath))!), - this.analyzer)) - .keys()); + const depsIndex = await buildDepsIndex( + this.config.allFragments.map( + (path) => this.analyzer.resolveUrl(urlFromPath( + this.config.root as LocalFsPath, path as LocalFsPath))!), + this.analyzer); + // Don't include bundler's fake "sub-bundle" URLs (e.g. + // "foo.html>external#1>bar.js"). + const allFragments = + new Set([...depsIndex.keys()].filter((url) => !url.includes('>'))); // If an app-shell exists, use that as our main push URL because it has a // reliable URL. Otherwise, support the single entrypoint URL. diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index c88999b40..c82588391 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog - - +## Unreleased +* Fix incorrect relative paths to the component directory in push manifests. +* Fix push manifest generation crash with ES module projects. ## v1.7.3 [06-11-2018] diff --git a/packages/cli/src/test/integration/build_test.ts b/packages/cli/src/test/integration/build_test.ts index bcc66c2c5..a972b4a2b 100644 --- a/packages/cli/src/test/integration/build_test.ts +++ b/packages/cli/src/test/integration/build_test.ts @@ -139,6 +139,18 @@ suite('polymer build', function() { path.join(fixtureDir, 'polymer-2-project', 'expected/default')); }); + test('handles polymer 2.x push manifest', async () => { + const tmpDir = tmp.dirSync(); + copyDir(path.join(fixtureDir, 'polymer-2-project', 'source'), tmpDir.name); + + await runCommand(binPath, ['build', '--name=push', '--add-push-manifest'], { + cwd: tmpDir.name + }); + assertDirsEqual( + path.join(tmpDir.name, 'build/push'), + path.join(fixtureDir, 'polymer-2-project', 'expected/push')); + }); + test('handles bundle tagged-template literals in ES5', async () => { const tmpDir = tmp.dirSync(); copyDir( diff --git a/packages/cli/test/fixtures/build-modules/expected/polymer.json b/packages/cli/test/fixtures/build-modules/expected/polymer.json index aefafe47c..ae33b0bea 100644 --- a/packages/cli/test/fixtures/build-modules/expected/polymer.json +++ b/packages/cli/test/fixtures/build-modules/expected/polymer.json @@ -11,7 +11,8 @@ "builds": [ { "name": "unbundled-es", - "bundle": false + "bundle": false, + "addPushManifest": true }, { "name": "unbundled-amd", diff --git a/packages/cli/test/fixtures/build-modules/expected/unbundled-es/push-manifest.json b/packages/cli/test/fixtures/build-modules/expected/unbundled-es/push-manifest.json new file mode 100644 index 000000000..e5bc603db --- /dev/null +++ b/packages/cli/test/fixtures/build-modules/expected/unbundled-es/push-manifest.json @@ -0,0 +1,16 @@ +{ + "index.html": { + "mod1.js": { + "type": "script", + "weight": 1 + }, + "mod2.js": { + "type": "script", + "weight": 1 + }, + "node_modules/dep1/dep1.js": { + "type": "script", + "weight": 1 + } + } +} \ No newline at end of file diff --git a/packages/cli/test/fixtures/build-modules/source/polymer.json b/packages/cli/test/fixtures/build-modules/source/polymer.json index 998250402..73d24ea0b 100644 --- a/packages/cli/test/fixtures/build-modules/source/polymer.json +++ b/packages/cli/test/fixtures/build-modules/source/polymer.json @@ -4,7 +4,8 @@ "builds": [ { "name": "unbundled-es", - "bundle": false + "bundle": false, + "addPushManifest": true }, { "name": "unbundled-amd", diff --git a/packages/cli/test/fixtures/polymer-2-project/expected/push/bower_components/polymer/polymer.html b/packages/cli/test/fixtures/polymer-2-project/expected/push/bower_components/polymer/polymer.html new file mode 100644 index 000000000..7d5134a24 --- /dev/null +++ b/packages/cli/test/fixtures/polymer-2-project/expected/push/bower_components/polymer/polymer.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/cli/test/fixtures/polymer-2-project/expected/push/index.html b/packages/cli/test/fixtures/polymer-2-project/expected/push/index.html new file mode 100644 index 000000000..63786d5b2 --- /dev/null +++ b/packages/cli/test/fixtures/polymer-2-project/expected/push/index.html @@ -0,0 +1 @@ + diff --git a/packages/cli/test/fixtures/polymer-2-project/expected/push/push-manifest.json b/packages/cli/test/fixtures/polymer-2-project/expected/push/push-manifest.json new file mode 100644 index 000000000..24ef8d444 --- /dev/null +++ b/packages/cli/test/fixtures/polymer-2-project/expected/push/push-manifest.json @@ -0,0 +1,16 @@ +{ + "index.html": { + "src/my-app.html": { + "type": "document", + "weight": 1 + }, + "bower_components/polymer/polymer.html": { + "type": "document", + "weight": 1 + }, + "src/elements/my-element.html": { + "type": "document", + "weight": 1 + } + } +} diff --git a/packages/cli/test/fixtures/polymer-2-project/expected/push/src/elements/my-element.html b/packages/cli/test/fixtures/polymer-2-project/expected/push/src/elements/my-element.html new file mode 100644 index 000000000..32e8b29ca --- /dev/null +++ b/packages/cli/test/fixtures/polymer-2-project/expected/push/src/elements/my-element.html @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/packages/cli/test/fixtures/polymer-2-project/expected/push/src/my-app.html b/packages/cli/test/fixtures/polymer-2-project/expected/push/src/my-app.html new file mode 100644 index 000000000..1d470f2bc --- /dev/null +++ b/packages/cli/test/fixtures/polymer-2-project/expected/push/src/my-app.html @@ -0,0 +1,3 @@ + + +