2017-04-16 15:48:22 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2017-04-16 15:48:22 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
const Package = require('dgeni').Package;
|
2017-04-21 08:10:52 -04:00
|
|
|
const apiPackage = require('../angular-api-package');
|
|
|
|
const { API_SOURCE_PATH } = require('../config');
|
2021-01-20 05:13:59 -05:00
|
|
|
const baseAuthoringPackage = require('./base-authoring-package');
|
2017-04-21 08:10:52 -04:00
|
|
|
|
2017-04-16 15:48:22 -04:00
|
|
|
const packageMap = {
|
2017-04-26 14:02:28 -04:00
|
|
|
animations: ['animations/index.ts', 'animations/browser/index.ts', 'animations/browser/testing/index.ts'],
|
2019-05-20 13:54:40 -04:00
|
|
|
common: ['common/index.ts', 'common/testing/index.ts', 'common/upgrade/index.ts', 'common/http/index.ts', 'common/http/testing/index.ts'],
|
2017-04-16 15:48:22 -04:00
|
|
|
core: ['core/index.ts', 'core/testing/index.ts'],
|
2018-02-28 12:45:11 -05:00
|
|
|
elements: ['elements/index.ts'],
|
2017-04-16 15:48:22 -04:00
|
|
|
forms: ['forms/index.ts'],
|
2017-04-26 14:02:28 -04:00
|
|
|
'platform-browser': ['platform-browser/index.ts', 'platform-browser/animations/index.ts', 'platform-browser/testing/index.ts'],
|
2017-04-16 15:48:22 -04:00
|
|
|
'platform-browser-dynamic': ['platform-browser-dynamic/index.ts', 'platform-browser-dynamic/testing/index.ts'],
|
feat(platform-server): allow shimming the global env sooner (#40559)
`@angular/platform-server` provides the foundation for rendering an
Angular app on the server. In order to achieve that, it uses a
server-side DOM implementation (currently [domino][1]).
For rendering on the server to work as closely as possible to running
the app on the browser, we need to make DOM globals (such as `Element`,
`HTMLElement`, etc.), which are normally provided by the browser,
available as globals on the server as well.
Currently, `@angular/platform-server` achieves this by extending the
`global` object with the DOM implementation provided by `domino`. This
assignment happens in the [setDomTypes()][2] function, which is
[called in a `PLATFORM_INITIALIZER`][3]. While this works in most cases,
there are some scenarios where the DOM globals are needed sooner (i.e.
before initializing the platform). See, for example, #24551 and #39950
for more details on such issues.
This commit provides a way to solve this problem by exposing a
side-effect-ful entry-point (`@angular/platform-server/init`), that
shims the `global` object with DOM globals. People will be able to
import this entry-point in their server-rendered apps before
bootstrapping the app (for example, in their `main.server.ts` file).
(See also [#39950 (comment)][4].)
In a future update, the [`universal` schematics][5] will include such an
import by default in newly generated projects.
[1]: https://www.npmjs.com/package/domino
[2]: https://github.com/angular/angular/blob/0fc8466f1be392917e0c/packages/platform-server/src/domino_adapter.ts#L17-L21
[3]: https://github.com/angular/angular/blob/0fc8466f1be392917e0c/packages/platform-server/src/server.ts#L33
[4]: https://github.com/angular/angular/issues/39950#issuecomment-747598403
[5]: https://github.com/angular/angular-cli/blob/cc51432661eb4ab4b6a3/packages/schematics/angular/universal
PR Close #40559
2021-02-11 12:24:52 -05:00
|
|
|
'platform-server': ['platform-server/index.ts', 'platform-server/init/index.ts', 'platform-server/testing/index.ts'],
|
2017-04-26 14:02:28 -04:00
|
|
|
router: ['router/index.ts', 'router/testing/index.ts', 'router/upgrade/index.ts'],
|
2017-10-23 12:47:49 -04:00
|
|
|
'service-worker': ['service-worker/index.ts'],
|
2019-03-22 05:42:52 -04:00
|
|
|
upgrade: ['upgrade/index.ts', 'upgrade/static/index.ts', 'upgrade/static/testing/index.ts']
|
2017-04-16 15:48:22 -04:00
|
|
|
};
|
2017-04-21 08:10:52 -04:00
|
|
|
|
|
|
|
|
2017-04-16 15:48:22 -04:00
|
|
|
function createPackage(packageName) {
|
|
|
|
|
2021-01-20 05:13:59 -05:00
|
|
|
return new Package('author-api', [baseAuthoringPackage, apiPackage])
|
|
|
|
.config(function(readTypeScriptModules) {
|
|
|
|
readTypeScriptModules.sourceFiles = packageMap[packageName];
|
|
|
|
})
|
|
|
|
.config(function(readFilesProcessor) {
|
|
|
|
readFilesProcessor.sourceFiles = [
|
|
|
|
{
|
|
|
|
basePath: API_SOURCE_PATH,
|
|
|
|
include: `${API_SOURCE_PATH}/examples/${packageName}/**/*`,
|
|
|
|
fileReader: 'exampleFileReader'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
});
|
2017-04-16 15:48:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
createPackage
|
|
|
|
};
|