| 
									
										
										
										
											2019-12-28 16:37:59 -08:00
										 |  |  | load("//tools:defaults.bzl", "pkg_npm", "ts_library") | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 10:19:01 +01:00
										 |  |  | package(default_visibility = ["//visibility:public"]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-28 14:43:37 -06:00
										 |  |  | ts_library( | 
					
						
							|  |  |  |     name = "api", | 
					
						
							|  |  |  |     srcs = [ | 
					
						
							|  |  |  |         "api.ts", | 
					
						
							| 
									
										
										
										
											2021-02-23 10:51:23 -08:00
										 |  |  |         "index.ts", | 
					
						
							| 
									
										
										
										
											2021-01-28 14:43:37 -06:00
										 |  |  |     ], | 
					
						
							| 
									
										
											  
											
												build(language-service): use 'export =' syntax for default export (#41165)
Tsserver expects `@angular/language-service` to provide a factory function
as the default export (commonjs-style) of the package.
The current implementation side steps TypeScript's import syntax by using
`module.exports = factory`.
This allows the code to incorrectly re-export other symbols:
```ts
export * from './api';
```
which transpiles to:
```js
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("@angular/language-service/api"), exports);
```
Doing this meant that the package now has a runtime dependency on `tslib`,
which is totally unnecessary.
With the proper `export =` syntax, `tslib` is removed, and no other exports
are allowed.
Output:
```js
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define("@angular/language-service", ["require", "exports"], factory);
    }
})(function (require, exports) {
    "use strict";
    return function factory(tsModule) {
        var plugin;
        return {
            create: function (info) {
                var config = info.config;
                var bundleName = config.ivy ? 'ivy.js' : 'language-service.js';
                plugin = require("./bundles/" + bundleName)(tsModule);
                return plugin.create(info);
            },
            getExternalFiles: function (project) {
                var _a, _b;
                return (_b = (_a = plugin === null || plugin === void 0 ? void 0 : plugin.getExternalFiles) === null || _a === void 0 ? void 0 : _a.call(plugin, project)) !== null && _b !== void 0 ? _b : [];
            },
            onConfigurationChanged: function (config) {
                var _a;
                (_a = plugin === null || plugin === void 0 ? void 0 : plugin.onConfigurationChanged) === null || _a === void 0 ? void 0 : _a.call(plugin, config);
            },
        };
    };
});
```
PR Close #41165
											
										 
											2021-03-10 16:06:09 -08:00
										 |  |  |     prodmode_module = "commonjs", | 
					
						
							| 
									
										
										
										
											2021-01-28 14:43:37 -06:00
										 |  |  |     deps = [ | 
					
						
							| 
									
										
										
										
											2021-02-23 10:51:23 -08:00
										 |  |  |         "@npm//@types/node", | 
					
						
							| 
									
										
										
										
											2021-01-28 14:43:37 -06:00
										 |  |  |         "@npm//typescript", | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  | ts_library( | 
					
						
							|  |  |  |     name = "language-service", | 
					
						
							| 
									
										
										
										
											2021-02-23 10:51:23 -08:00
										 |  |  |     srcs = glob( | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  |         [ | 
					
						
							|  |  |  |             "src/**/*.ts", | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-05-07 08:55:33 -07:00
										 |  |  |         exclude = [ | 
					
						
							|  |  |  |             "src/ts_utils.ts", | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  |     ), | 
					
						
							|  |  |  |     deps = [ | 
					
						
							| 
									
										
										
										
											2021-01-28 14:43:37 -06:00
										 |  |  |         ":api", | 
					
						
							| 
									
										
										
										
											2020-05-07 08:55:33 -07:00
										 |  |  |         ":ts_utils", | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  |         "//packages:types", | 
					
						
							|  |  |  |         "//packages/compiler", | 
					
						
							|  |  |  |         "//packages/compiler-cli", | 
					
						
							|  |  |  |         "//packages/core", | 
					
						
							| 
									
										
										
										
											2019-02-20 09:54:42 -08:00
										 |  |  |         "@npm//@types/node", | 
					
						
							|  |  |  |         "@npm//typescript", | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  |     ], | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2018-03-13 11:00:53 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-07 08:55:33 -07:00
										 |  |  | ts_library( | 
					
						
							|  |  |  |     name = "ts_utils", | 
					
						
							|  |  |  |     srcs = ["src/ts_utils.ts"], | 
					
						
							|  |  |  |     deps = [ | 
					
						
							|  |  |  |         "@npm//typescript", | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-28 16:37:59 -08:00
										 |  |  | pkg_npm( | 
					
						
							| 
									
										
										
										
											2018-03-13 11:00:53 -07:00
										 |  |  |     name = "npm_package", | 
					
						
							|  |  |  |     srcs = ["package.json"], | 
					
						
							| 
									
										
										
										
											2018-03-30 13:48:47 -07:00
										 |  |  |     tags = [ | 
					
						
							| 
									
										
										
										
											2018-04-03 16:12:25 -07:00
										 |  |  |         "release-with-framework", | 
					
						
							|  |  |  |     ], | 
					
						
							| 
									
										
										
										
											2018-12-11 16:53:42 -08:00
										 |  |  |     # Do not add more to this list. | 
					
						
							|  |  |  |     # Dependencies on the full npm_package cause long re-builds. | 
					
						
							| 
									
										
										
										
											2020-02-04 11:45:40 -08:00
										 |  |  |     visibility = [ | 
					
						
							|  |  |  |         "//integration:__pkg__", | 
					
						
							|  |  |  |     ], | 
					
						
							| 
									
										
										
										
											2018-04-03 16:12:25 -07:00
										 |  |  |     deps = [ | 
					
						
							| 
									
										
										
										
											2021-02-23 10:51:23 -08:00
										 |  |  |         ":api", | 
					
						
							| 
									
										
										
										
											2019-10-29 14:21:30 -07:00
										 |  |  |         # min bundle is not used at the moment; omit from package to speed up build | 
					
						
							| 
									
										
										
										
											2020-07-15 13:58:03 -07:00
										 |  |  |         "//packages/language-service/bundles:language-service.js", | 
					
						
							|  |  |  |         "//packages/language-service/bundles:ivy.js", | 
					
						
							| 
									
										
										
										
											2018-03-30 13:48:47 -07:00
										 |  |  |     ], | 
					
						
							| 
									
										
										
										
											2018-03-13 11:00:53 -07:00
										 |  |  | ) |