Skip to content

Commit b00905f

Browse files
committed
Compile application sources and NgFactory files into a temporary directory instead of the process cwd
1 parent a023934 commit b00905f

File tree

14 files changed

+76
-81
lines changed

14 files changed

+76
-81
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ssr",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"description": "Angular server-side rendering implementation",
55
"main": "build/index.js",
66
"typings": "build/index.d.ts",
@@ -65,7 +65,7 @@
6565
"babel-plugin-transform-strict-mode": "^6.22.0",
6666
"codependency": "0.1.4",
6767
"commander": "2.9.0",
68-
"domino": "git://github.com/clbond/domino.git#0c16ed953edf3a9a741b435e7359f6acfe2363bb",
68+
"domino": "https://github.com/clbond/domino/archive/1.0.29.tar.gz",
6969
"mock-local-storage": "^1.0.2",
7070
"node-fetch": "^1.6.3",
7171
"reflect-metadata": "0.1.9",

source/application/builder/tests/from-source.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import {ApplicationFromSource} from '../from-source';
22

3-
import {
4-
templateDocument,
5-
getApplicationProject,
6-
getTemporaryWorkingPath,
7-
} from '../../../test/fixtures';
3+
import {templateDocument, getApplicationProject} from '../../../test/fixtures';
84

95
describe('ApplicationFromSource', () => {
106
it('can compile a project from source and load a NgFactory module', async () => {
11-
const project = getApplicationProject(
12-
'source/test/fixtures/application-basic-inline',
13-
'BasicInlineModule',
14-
getTemporaryWorkingPath());
7+
const project = getApplicationProject('source/test/fixtures/application-basic-inline', 'BasicInlineModule');
158

169
const application = new ApplicationFromSource(project);
1710

source/application/compiler/tests/compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getApplicationProject, getTemporaryWorkingPath} from '../../../test/fixtures';
1+
import {getApplicationProject} from '../../../test/fixtures';
22

33
import {getCompilableProgram} from '../factory';
44

@@ -9,7 +9,7 @@ describe('program compilation', () => {
99

1010
beforeAll(() => { // reuse the same compiled program for each test
1111
program = getCompilableProgram(
12-
getApplicationProject('source/test/fixtures/application-basic-inline', 'BasicInlineModule', getTemporaryWorkingPath()));
12+
getApplicationProject('source/test/fixtures/application-basic-inline', 'BasicInlineModule'));
1313
});
1414

1515
afterAll(() => {

source/application/project.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import {PathReference} from '../filesystem';
1+
import {join} from 'path';
2+
3+
import {tmpdir} from 'os';
4+
5+
import {pathFromString, PathReference} from '../filesystem';
26

37
export interface ApplicationModuleDescriptor {
48
source: string;
@@ -11,3 +15,11 @@ export interface Project {
1115
workingPath?: PathReference;
1216
applicationModule?: ApplicationModuleDescriptor;
1317
}
18+
19+
const randomId = (): string => Math.random().toString(16).slice(2);
20+
21+
export const getTemporaryWorkingPath = (): PathReference => {
22+
const path = pathFromString(join(tmpdir(), randomId()));
23+
path.mkdir();
24+
return path;
25+
};

source/application/render.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export class ApplicationRenderer {
1717
output.write(snapshot);
1818
},
1919
exception => {
20-
reject(new Error(`Fatal render exception: ${exception.stack}`));
20+
reject(new Error(`Fatal render exception: ${exception}`));
2121
},
2222
() => resolve());
2323
})
2424
.catch(exception => {
25-
reject(new Error(`Failed to render application: ${exception.stack}`));
25+
reject(new Error(`Failed to render application: ${exception}`));
2626
});
2727
});
2828
}

source/bin/options.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ import commander = require('commander');
22

33
import {dirname, join} from 'path';
44

5-
import {Project} from '../application';
6-
7-
import {ConfigurationException} from '../exception';
8-
9-
import {tsconfig} from '../identifiers';
10-
115
import {
126
FileType,
137
PathReference,
8+
ConfigurationException,
9+
Project,
10+
getTemporaryWorkingPath,
1411
fileFromString,
1512
pathFromString,
16-
} from '../filesystem';
13+
tsconfig,
14+
} from '../index';
1715

1816
const {version} = require('../../package.json');
1917

@@ -40,6 +38,7 @@ export const commandLineToOptions = (): CommandLineOptions => {
4038
const project: Project = {
4139
basePath: dirname(tsconfig),
4240
tsconfig,
41+
workingPath: getTemporaryWorkingPath(),
4342
applicationModule: {source, symbol},
4443
};
4544

source/bin/render.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import 'reflect-metadata';
22

3-
import '../dependencies';
3+
import {
4+
ApplicationRenderer,
5+
ApplicationFromSource,
6+
HtmlOutput,
7+
logger,
8+
} from '../index';
49

5-
import {ApplicationRenderer, ApplicationFromSource} from '../application';
6-
import {HtmlOutput, logger} from '../output';
710
import {commandLineToOptions} from './options';
811

912
const options = commandLineToOptions();
1013

11-
logger.info('Starting application render process');
14+
logger.info(`Rendering application from source (working path: ${options.project.workingPath}`);
1215

1316
const application = new ApplicationFromSource(options.project);
1417
application.templateDocument(options.templateDocument);
@@ -17,10 +20,16 @@ const output = new HtmlOutput(options.output);
1720

1821
const applicationRenderer = new ApplicationRenderer(application);
1922

20-
applicationRenderer.renderTo(output)
21-
.catch(exception => {
22-
logger.error(`Failed to render application: ${exception.stack}`);
23-
})
24-
.then(() => {
23+
const execute = async () => {
24+
try {
25+
await applicationRenderer.renderTo(output);
26+
}
27+
catch (exception) {
28+
logger.error(`Failed to render application: ${exception}`);
29+
}
30+
finally {
2531
application.dispose();
26-
});
32+
}
33+
};
34+
35+
execute();

source/exception.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {EOL} from 'os';
22

33
export class Exception extends Error {
44
constructor(msg: string, public innerException?: Error) {
5-
super(innerException ? `${msg} -> ${innerException.stack}` : msg);
5+
super(innerException ? `${msg} -> ${innerException.toString()}` : msg);
66
}
77
}
88

source/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import './dependencies';
22
export * from './application';
33
export * from './filesystem';
4+
export * from './identifiers';
45
export * from './output';
56
export * from './platform';
67
export * from './route';

source/platform/runtime-loader.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import {Injectable} from '@angular/core';
2+
3+
@Injectable()
14
export abstract class RuntimeModuleLoader {
25
abstract load<T>(moduleId: string): Promise<T>;
36
}

0 commit comments

Comments
 (0)