Skip to content

Commit

Permalink
cleanup and update npm dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Jul 14, 2017
1 parent 88c29aa commit 4176c6c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 45 deletions.
3 changes: 0 additions & 3 deletions externs/webcomponents-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ let ShadyDOM = {

window.ShadyDOM = ShadyDOM;

/** @type {function(this:ShadowRoot)} */
ShadowRoot.prototype.forceRender;

let WebComponents = {};
window.WebComponents = WebComponents;

Expand Down
8 changes: 4 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const lazypipe = require('lazypipe');
const closure = require('google-closure-compiler').gulp();
const minimalDocument = require('./util/minimalDocument.js')
const dom5 = require('dom5');
const parse5 = require('parse5');

const DIST_DIR = 'dist';
const BUNDLED_DIR = path.join(DIST_DIR, 'bundled');
Expand Down Expand Up @@ -76,15 +77,16 @@ class AddClosureTypeImport extends Transform {
_transform(file, enc, cb) {
if (file.path === this.target) {
let contents = file.contents.toString();
let html = dom5.parse(contents, {locationInfo: true});
let html = parse5.parse(contents, {locationInfo: true});
let firstImport = dom5.query(html, firstImportFinder);
if (firstImport) {
let importPath = path.relative(path.dirname(this.target), this.importPath);
let importLink = dom5.constructors.element('link');
dom5.setAttribute(importLink, 'rel', 'import');
dom5.setAttribute(importLink, 'href', importPath);
dom5.insertBefore(firstImport.parentNode, firstImport, importLink);
file.contents = Buffer(dom5.serialize(html));
dom5.removeFakeRootElements(html);
file.contents = Buffer(parse5.serialize(html));
}
}
cb(null, file);
Expand All @@ -105,7 +107,6 @@ gulp.task('closure', ['clean'], () => {
}

config('polymer.html');
// config('lib/mixins/property-effects.html');

const project = new PolymerProject({
shell: `./${entry}`,
Expand Down Expand Up @@ -146,7 +147,6 @@ gulp.task('closure', ['clean'], () => {
new_type_inf: true,
checks_only: CLOSURE_LINT_ONLY,
polymer_version: 2,
// tracer_mode: 'TIMING_ONLY',
externs: [
'bower_components/shadycss/externs/shadycss-externs.js',
'externs/webcomponents-externs.js',
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"@webcomponents/webcomponentsjs": "^1.0.0",
"babel-preset-babili": "^0.1.4",
"del": "^3.0.0",
"dom5": "^1.3.1",
"dom5": "^2.3.0",
"eslint-plugin-html": "^2.0.1",
"google-closure-compiler": "^20170521.0.0",
"google-closure-compiler": "^20170626.0.0",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-eslint": "^3.0.1",
Expand All @@ -24,7 +24,8 @@
"gulp-vulcanize": "^6.0.1",
"lazypipe": "^1.0.1",
"merge-stream": "^1.0.1",
"polymer-build": "^1.5.0",
"parse5": "^3.0.2",
"polymer-build": "^1.6.0",
"run-sequence": "^1.1.0",
"through2": "^2.0.0",
"web-component-tester": "^6.0.0-prerelease.4"
Expand Down
48 changes: 13 additions & 35 deletions util/minimalDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,11 @@
'use strict';

const dom5 = require('dom5');
const parse5 = require('parse5');
const {Transform} = require('stream');

const p = dom5.predicates;

function isBlankTextNode(node) {
return node && dom5.isTextNode(node) && !/\S/.test(dom5.getTextContent(node));
}

function replaceWithChildren(node) {
if (!node) {
return;
}
let parent = node.parentNode;
let idx = parent.childNodes.indexOf(node);
let children = node.childNodes;
children.forEach(function(n) {
n.parentNode = parent;
});
let til = idx + 1;
let next = parent.childNodes[til];
// remove newline text node as well
while (isBlankTextNode(next)) {
til++;
next = parent.childNodes[til];
}
parent.childNodes = parent.childNodes.slice(0, idx).concat(children, parent.childNodes.slice(til));
}

function onlyOneLicense(doc) {
let comments = dom5.nodeWalkAll(doc, dom5.isCommentNode);
let hasLicense = false;
Expand All @@ -54,24 +31,24 @@ function onlyOneLicense(doc) {
}
}

const blankRx = /^\s+$/;

const isBlankNode = p.AND(dom5.isTextNode, (t) => blankRx.test(dom5.getTextContent(t)));

class MinimalDocTransform extends Transform {
constructor() {
super({objectMode: true});
}
_transform(file, enc, cb) {
let doc = dom5.parse(String(file.contents));
let head = dom5.query(doc, p.hasTagName('head'));
let body = dom5.query(doc, p.hasTagName('body'));
let vulc = dom5.query(body, p.AND(p.hasTagName('div'), p.hasAttr('by-polymer-bundler'), p.hasAttr('hidden')));
let doc = parse5.parse(String(file.contents), {locationInfo: true});
let vulc = dom5.query(doc, p.AND(p.hasTagName('div'), p.hasAttr('by-polymer-bundler'), p.hasAttr('hidden')));
let charset = dom5.query(doc, p.AND(p.hasTagName('meta'), p.hasAttrValue('charset', 'UTF-8')));

if (charset) {
dom5.remove(charset);
}

replaceWithChildren(head);
replaceWithChildren(vulc);
replaceWithChildren(body);
dom5.removeNodeSaveChildren(vulc);

let scripts = dom5.queryAll(doc, p.hasTagName('script'));
let collector = scripts[0];
Expand All @@ -83,12 +60,13 @@ class MinimalDocTransform extends Transform {
}
dom5.setTextContent(collector, contents.join(''));

let html = dom5.query(doc, p.hasTagName('html'));
replaceWithChildren(html);

onlyOneLicense(doc);

file.contents = new Buffer(dom5.serialize(doc));
dom5.removeFakeRootElements(doc);

dom5.nodeWalkAll(doc, isBlankNode).forEach((t) => dom5.remove(t));

file.contents = new Buffer(parse5.serialize(doc));

cb(null, file);
}
Expand Down

0 comments on commit 4176c6c

Please sign in to comment.