Skip to content
This repository was archived by the owner on Sep 14, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions custom_typings/fs-extra.d.ts

This file was deleted.

151 changes: 0 additions & 151 deletions custom_typings/node.d.ts

This file was deleted.

15 changes: 0 additions & 15 deletions custom_typings/vinyl-fs.d.ts

This file was deleted.

43 changes: 19 additions & 24 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,22 @@ const tslint = require('gulp-tslint');
const typescript = require('gulp-typescript');
const typings = require('gulp-typings');

const tsProject = typescript.createProject('tsconfig.json');

// WTF gulp-typescript
class Rebase extends stream.Transform {
constructor() {
super({objectMode: true});
}

_transform(file, enc, callback) {
let oldPath = file.path;
if (oldPath.startsWith('lib/src')) {
file.path = 'lib' + oldPath.substring('lib/src'.length);
}
callback(null, file);
}
}
const tsProject = typescript.createProject('tsconfig.json', {
typescript: require('typescript')
});

gulp.task('init', () => gulp.src("./typings.json").pipe(typings()));

gulp.task('lint', ['tslint', 'eslint', 'depcheck']);

gulp.task('build', () =>
tsProject.src()
.pipe(typescript(tsProject))
.pipe(new Rebase())
.pipe(gulp.dest('lib'))
);
gulp.task('build', () => {
const tsResult = tsProject.src().pipe(typescript(tsProject));

return mergeStream(
tsResult.dts.pipe(gulp.dest('lib')),
tsResult.js.pipe(gulp.dest('lib'))
);
});

gulp.task('clean', (done) => {
fs.remove(path.join(__dirname, 'lib'), done);
Expand All @@ -71,8 +60,9 @@ gulp.task('tslint', () =>
gulp.src('src/**/*.ts')
.pipe(tslint({
configuration: 'tslint.json',
formatter: 'verbose'
}))
.pipe(tslint.report('verbose')));
.pipe(tslint.report()));

gulp.task('eslint', () =>
gulp.src('test/**/*.js')
Expand All @@ -81,7 +71,12 @@ gulp.task('eslint', () =>
.pipe(eslint.failAfterError()));

gulp.task('depcheck', () =>
depcheck(__dirname, {})
depcheck(__dirname, {
// "@types/*" dependencies are type declarations that are automatically
// loaded by TypeScript during build. depcheck can't detect this
// so we ignore them here.
ignoreMatches: ['@types/*']
})
.then((result) => {
let invalidFiles = Object.keys(result.invalidFiles) || [];
let invalidJsFiles = invalidFiles.filter((f) => f.endsWith('.js'));
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
},
"homepage": "https://github.com/Polymer/polymer-build#readme",
"dependencies": {
"@types/fs-extra": "0.0.32",
"@types/vinyl-fs": "0.0.28",
"dom5": "^1.3.1",
"fs-extra": "^0.30.0",
"gulp": "^3.9.1",
Expand All @@ -42,12 +44,13 @@
"depcheck": "^0.6.3",
"gulp-eslint": "^2.0.0",
"gulp-mocha": "^2.2.0",
"gulp-tslint": "^5.0.0",
"gulp-tslint": "^6.1.1",
"gulp-typescript": "^2.13.4",
"gulp-typings": "^2.0.0",
"run-sequence": "^1.2.0",
"temp": "^0.8.3",
"tslint": "^3.10.2",
"tslint": "^3.15.1",
"typescript": "^2.0.2",
"vinyl-fs-fake": "^1.1.0"
}
}
119 changes: 58 additions & 61 deletions src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,68 +104,65 @@ export class Bundler extends Transform {
return this.allFragments.indexOf(file.path) !== -1;
}

_buildBundles(): Promise<Map<string, string>> {
return this._getBundles().then((bundles) => {
let sharedDepsBundle = (this.shell)
? urlFromPath(this.root, this.shell)
: this.sharedBundleUrl;
let sharedDeps = bundles.get(sharedDepsBundle) || [];
let promises: Promise<any>[] = [];

if (this.shell) {
let shellFile = this.analyzer.getFile(this.shell);
console.assert(shellFile != null);
let newShellContent = this._addSharedImportsToShell(bundles);
shellFile.contents = new Buffer(newShellContent);
}
async _buildBundles(): Promise<Map<string, string>> {
let bundles = await this._getBundles();
Copy link
Contributor

@rictic rictic Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere: preferred style is const by default, let only when necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I'd like to keep the scope of this PR small for now. I'll make a separate PR to address this across the repo once this has been merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed w/ the agree. In the future, just do the async/await in another PR also :)

let sharedDepsBundle = (this.shell)
? urlFromPath(this.root, this.shell)
: this.sharedBundleUrl;
let sharedDeps = bundles.get(sharedDepsBundle) || [];
let promises: Promise<any>[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimize use of any, it's usually a code smell. Would this work?

const promises: Promise<{url: string, contents: string}>[] = []

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I'd like to keep the scope of this PR small for now. This diff was only a indentation change due to a move over to async-await above. I'll make a separate PR to address this.


if (this.shell) {
let shellFile = this.analyzer.getFile(this.shell);
console.assert(shellFile != null);
let newShellContent = this._addSharedImportsToShell(bundles);
shellFile.contents = new Buffer(newShellContent);
}

for (let fragment of this.allFragments) {
let fragmentUrl = urlFromPath(this.root, fragment);
let addedImports = (fragment === this.shell && this.shell)
? []
: [posixPath.relative(posixPath.dirname(fragmentUrl), sharedDepsBundle)];
let excludes = (fragment === this.shell && this.shell)
? []
: sharedDeps.concat(sharedDepsBundle);

promises.push(new Promise((resolve, reject) => {
let vulcanize = new Vulcanize({
abspath: null,
fsResolver: this.analyzer.resolver,
addedImports: addedImports,
stripExcludes: excludes,
inlineScripts: true,
inlineCss: true,
inputUrl: fragmentUrl,
});
vulcanize.process(null, (err: any, doc: string) => {
if (err) {
reject(err);
} else {
resolve({
url: fragment,
contents: doc,
});
}
});
}));
}
// vulcanize the shared bundle
if (!this.shell && sharedDeps && sharedDeps.length !== 0) {
logger.info(`generating shared bundle...`);
promises.push(this._generateSharedBundle(sharedDeps));
}
return Promise.all(promises).then((bundles) => {
// TODO(justinfagnani): remove at TypeScript 2.0
let _bundles = <any[]>bundles;
// convert {url,contents}[] into a Map
let contentsMap = new Map();
for (let bundle of _bundles) {
contentsMap.set(bundle.url, bundle.contents);
}
return contentsMap;
});
});
for (let fragment of this.allFragments) {
let fragmentUrl = urlFromPath(this.root, fragment);
let addedImports = (fragment === this.shell && this.shell)
? []
: [posixPath.relative(posixPath.dirname(fragmentUrl), sharedDepsBundle)];
let excludes = (fragment === this.shell && this.shell)
? []
: sharedDeps.concat(sharedDepsBundle);

promises.push(new Promise((resolve, reject) => {
let vulcanize = new Vulcanize({
abspath: null,
fsResolver: this.analyzer.resolver,
addedImports: addedImports,
stripExcludes: excludes,
inlineScripts: true,
inlineCss: true,
inputUrl: fragmentUrl,
});
vulcanize.process(null, (err: any, doc: string) => {
if (err) {
reject(err);
} else {
resolve({
url: fragment,
contents: doc,
});
}
});
}));
}

// vulcanize the shared bundle
if (!this.shell && sharedDeps && sharedDeps.length !== 0) {
logger.info(`generating shared bundle...`);
promises.push(this._generateSharedBundle(sharedDeps));
}

let vulcanizedBundles = await Promise.all(promises);
let contentsMap = new Map();
for (let bundle of vulcanizedBundles) {
contentsMap.set(bundle.url, bundle.contents);
}
return contentsMap;
}

_addSharedImportsToShell(bundles: Map<string, string[]>): string {
Expand Down
Loading