|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import { JsonValue, Path, basename, join, normalize } from '@angular-devkit/core'; |
| 9 | +import { JsonValue, Path, basename, dirname, join, normalize } from '@angular-devkit/core'; |
10 | 10 | import { |
11 | 11 | Rule, |
12 | 12 | SchematicContext, |
@@ -77,18 +77,15 @@ function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): R |
77 | 77 | } |
78 | 78 |
|
79 | 79 | const mainPath = options.main as string; |
| 80 | + const sourceRoot = clientProject.sourceRoot ?? join(normalize(clientProject.root), 'src'); |
80 | 81 | const serverTsConfig = join(tsConfigDirectory, 'tsconfig.server.json'); |
81 | 82 | clientProject.targets.add({ |
82 | 83 | name: 'server', |
83 | 84 | builder: Builders.Server, |
84 | 85 | defaultConfiguration: 'production', |
85 | 86 | options: { |
86 | 87 | outputPath: `dist/${options.project}/server`, |
87 | | - main: join( |
88 | | - normalize(clientProject.root), |
89 | | - 'src', |
90 | | - mainPath.endsWith('.ts') ? mainPath : mainPath + '.ts', |
91 | | - ), |
| 88 | + main: join(normalize(sourceRoot), mainPath.endsWith('.ts') ? mainPath : mainPath + '.ts'), |
92 | 89 | tsConfig: serverTsConfig, |
93 | 90 | ...(buildTarget?.options ? getServerOptions(buildTarget?.options) : {}), |
94 | 91 | }, |
@@ -147,12 +144,12 @@ function wrapBootstrapCall(mainFile: string): Rule { |
147 | 144 | `\n${triviaWidth > 2 ? ' '.repeat(triviaWidth - 1) : ''}};\n` + |
148 | 145 | ` |
149 | 146 |
|
150 | | -if (document.readyState === 'complete') { |
151 | | - bootstrap(); |
152 | | -} else { |
153 | | - document.addEventListener('DOMContentLoaded', bootstrap); |
154 | | -} |
155 | | -`; |
| 147 | + if (document.readyState === 'complete') { |
| 148 | + bootstrap(); |
| 149 | + } else { |
| 150 | + document.addEventListener('DOMContentLoaded', bootstrap); |
| 151 | + } |
| 152 | + `; |
156 | 153 |
|
157 | 154 | // in some cases we need to cater for a trailing semicolon such as; |
158 | 155 | // bootstrap().catch(err => console.log(err)); |
@@ -252,35 +249,31 @@ export default function (options: UniversalOptions): Rule { |
252 | 249 | const clientBuildOptions = (clientBuildTarget.options || |
253 | 250 | {}) as unknown as BrowserBuilderOptions; |
254 | 251 |
|
255 | | - const clientTsConfig = normalize(clientBuildOptions.tsConfig); |
256 | | - const tsConfigExtends = basename(clientTsConfig); |
257 | | - // this is needed because prior to version 8, tsconfig might have been in 'src' |
258 | | - // and we don't want to break the 'ng add @nguniversal/express-engine schematics' |
259 | | - const rootInSrc = clientProject.root === '' && clientTsConfig.includes('src/'); |
260 | | - const tsConfigDirectory = join(normalize(clientProject.root), rootInSrc ? 'src' : ''); |
261 | | - |
262 | 252 | if (!options.skipInstall) { |
263 | 253 | context.addTask(new NodePackageInstallTask()); |
264 | 254 | } |
265 | 255 |
|
266 | 256 | const templateSource = apply(url('./files/src'), [ |
267 | 257 | applyTemplates({ |
268 | 258 | ...strings, |
269 | | - ...(options as object), |
| 259 | + ...options, |
270 | 260 | stripTsExtension: (s: string) => s.replace(/\.ts$/, ''), |
271 | 261 | hasLocalizePackage: !!getPackageJsonDependency(host, '@angular/localize'), |
272 | 262 | }), |
273 | 263 | move(join(normalize(clientProject.root), 'src')), |
274 | 264 | ]); |
275 | 265 |
|
| 266 | + const clientTsConfig = normalize(clientBuildOptions.tsConfig); |
| 267 | + const tsConfigExtends = basename(clientTsConfig); |
| 268 | + const tsConfigDirectory = dirname(clientTsConfig); |
| 269 | + |
276 | 270 | const rootSource = apply(url('./files/root'), [ |
277 | 271 | applyTemplates({ |
278 | 272 | ...strings, |
279 | | - ...(options as object), |
| 273 | + ...options, |
280 | 274 | stripTsExtension: (s: string) => s.replace(/\.ts$/, ''), |
281 | 275 | tsConfigExtends, |
282 | 276 | relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(tsConfigDirectory), |
283 | | - rootInSrc, |
284 | 277 | }), |
285 | 278 | move(tsConfigDirectory), |
286 | 279 | ]); |
|
0 commit comments