1 | (function (factory) {
|
---|
2 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
3 | var v = factory(require, exports);
|
---|
4 | if (v !== undefined) module.exports = v;
|
---|
5 | }
|
---|
6 | else if (typeof define === "function" && define.amd) {
|
---|
7 | define("@angular/compiler-cli/ngcc/src/locking/sync_locker", ["require", "exports"], factory);
|
---|
8 | }
|
---|
9 | })(function (require, exports) {
|
---|
10 | "use strict";
|
---|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
12 | exports.SyncLocker = void 0;
|
---|
13 | /**
|
---|
14 | * SyncLocker is used to prevent more than one instance of ngcc executing at the same time,
|
---|
15 | * when being called in a synchronous context.
|
---|
16 | *
|
---|
17 | * * When ngcc starts executing, it creates a file in the `compiler-cli/ngcc` folder.
|
---|
18 | * * If it finds one is already there then it fails with a suitable error message.
|
---|
19 | * * When ngcc completes executing, it removes the file so that future ngcc executions can start.
|
---|
20 | */
|
---|
21 | var SyncLocker = /** @class */ (function () {
|
---|
22 | function SyncLocker(lockFile) {
|
---|
23 | this.lockFile = lockFile;
|
---|
24 | }
|
---|
25 | /**
|
---|
26 | * Run the given function guarded by the lock file.
|
---|
27 | *
|
---|
28 | * @param fn the function to run.
|
---|
29 | * @returns the value returned from the `fn` call.
|
---|
30 | */
|
---|
31 | SyncLocker.prototype.lock = function (fn) {
|
---|
32 | this.create();
|
---|
33 | try {
|
---|
34 | return fn();
|
---|
35 | }
|
---|
36 | finally {
|
---|
37 | this.lockFile.remove();
|
---|
38 | }
|
---|
39 | };
|
---|
40 | /**
|
---|
41 | * Write a lock file to disk, or error if there is already one there.
|
---|
42 | */
|
---|
43 | SyncLocker.prototype.create = function () {
|
---|
44 | try {
|
---|
45 | this.lockFile.write();
|
---|
46 | }
|
---|
47 | catch (e) {
|
---|
48 | if (e.code !== 'EEXIST') {
|
---|
49 | throw e;
|
---|
50 | }
|
---|
51 | this.handleExistingLockFile();
|
---|
52 | }
|
---|
53 | };
|
---|
54 | /**
|
---|
55 | * The lock-file already exists so raise a helpful error.
|
---|
56 | */
|
---|
57 | SyncLocker.prototype.handleExistingLockFile = function () {
|
---|
58 | var pid = this.lockFile.read();
|
---|
59 | throw new Error("ngcc is already running at process with id " + pid + ".\n" +
|
---|
60 | "If you are running multiple builds in parallel then you might try pre-processing your node_modules via the command line ngcc tool before starting the builds.\n" +
|
---|
61 | ("(If you are sure no ngcc process is running then you should delete the lock-file at " + this.lockFile.path + ".)"));
|
---|
62 | };
|
---|
63 | return SyncLocker;
|
---|
64 | }());
|
---|
65 | exports.SyncLocker = SyncLocker;
|
---|
66 | });
|
---|
67 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3luY19sb2NrZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb21waWxlci1jbGkvbmdjYy9zcmMvbG9ja2luZy9zeW5jX2xvY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7SUFTQTs7Ozs7OztPQU9HO0lBQ0g7UUFDRSxvQkFBb0IsUUFBa0I7WUFBbEIsYUFBUSxHQUFSLFFBQVEsQ0FBVTtRQUFHLENBQUM7UUFFMUM7Ozs7O1dBS0c7UUFDSCx5QkFBSSxHQUFKLFVBQVEsRUFBVztZQUNqQixJQUFJLENBQUMsTUFBTSxFQUFFLENBQUM7WUFDZCxJQUFJO2dCQUNGLE9BQU8sRUFBRSxFQUFFLENBQUM7YUFDYjtvQkFBUztnQkFDUixJQUFJLENBQUMsUUFBUSxDQUFDLE1BQU0sRUFBRSxDQUFDO2FBQ3hCO1FBQ0gsQ0FBQztRQUVEOztXQUVHO1FBQ08sMkJBQU0sR0FBaEI7WUFDRSxJQUFJO2dCQUNGLElBQUksQ0FBQyxRQUFRLENBQUMsS0FBSyxFQUFFLENBQUM7YUFDdkI7WUFBQyxPQUFPLENBQUMsRUFBRTt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