From 57649d1839a3310df614ad9aaa15bfb548bc1f28 Mon Sep 17 00:00:00 2001 From: Jeff Cross Date: Tue, 13 Oct 2015 14:35:31 -0700 Subject: [PATCH] fix(publish): emit type declarations with CJS build Closes #4706 Closes #4708 --- gulpfile.js | 2 +- tools/broccoli/trees/node_tree.ts | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 4797a7a8a9..cdd97f67e5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -831,7 +831,7 @@ gulp.task('test.typings', ['!pre.test.typings'], function() { var tmpdir = path.join(os.tmpdir(), 'test.typings', new Date().getTime().toString()); gulp.task('!pre.test.typings.layoutNodeModule', function() { return gulp - .src(['dist/js/dev/es5/angular2/**/*'], {base: 'dist/js/dev/es5'}) + .src(['dist/js/cjs/angular2/**/*'], {base: 'dist/js/cjs'}) .pipe(gulp.dest(path.join(tmpdir, 'node_modules'))); }); gulp.task('!pre.test.typings.copyTypingsSpec', function() { diff --git a/tools/broccoli/trees/node_tree.ts b/tools/broccoli/trees/node_tree.ts index cbcb3a566c..d68f61e8ea 100644 --- a/tools/broccoli/trees/node_tree.ts +++ b/tools/broccoli/trees/node_tree.ts @@ -36,7 +36,8 @@ module.exports = function makeNodeTree(destinationPath) { allowNonTsExtensions: false, emitDecoratorMetadata: true, experimentalDecorators: true, - declaration: false, + declaration: true, + stripInternal: true, mapRoot: '', /* force sourcemaps to use relative path */ module: 'CommonJS', moduleResolution: 1 /* classic */, @@ -77,7 +78,10 @@ module.exports = function makeNodeTree(destinationPath) { packageJsons = renderLodashTemplate(packageJsons, {context: {'packageJson': COMMON_PACKAGE_JSON}}); - var nodeTree = mergeTrees([typescriptTree, docs, packageJsons]); + var typingsTree = new Funnel( + 'modules', + {include: ['angular2/typings/**/*.d.ts', 'angular2/manual_typings/*.d.ts'], destDir: '/'}); + var nodeTree = mergeTrees([typescriptTree, docs, packageJsons, typingsTree]); // Transform all tests to make them runnable in node nodeTree = replace(nodeTree, { @@ -101,5 +105,21 @@ module.exports = function makeNodeTree(destinationPath) { patterns: [{match: /^/, replacement: function() { return `'use strict';` }}] }); + // Add a line to the end of our top-level .d.ts file. + // This HACK for transitive typings is a workaround for + // https://github.com/Microsoft/TypeScript/issues/5097 + // + // This allows users to get our top-level dependencies like es6-shim.d.ts + // to appear when they compile against angular2. + // + // This carries the risk that the user brings their own copy of that file + // (or any other symbols exported here) and they will get a compiler error + // because of the duplicate definitions. + // TODO(alexeagle): remove this when typescript releases a fix + nodeTree = replace(nodeTree, { + files: ['angular2/angular2.d.ts'], + patterns: [{match: /$/, replacement: 'import "./manual_typings/globals.d.ts";\n'}] + }); + return destCopy(nodeTree, destinationPath); };