source: trip-planner-front/node_modules/@schematics/angular/migrations/update-12/update-zonejs.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10const core_1 = require("@angular-devkit/core");
11const tasks_1 = require("@angular-devkit/schematics/tasks");
12const dependencies_1 = require("../../utility/dependencies");
13const fileExtensionRegexp = /\.(([cm]?j|t)sx?)$/;
14function* visitJavaScriptFiles(directory) {
15 for (const path of directory.subfiles) {
16 if (!fileExtensionRegexp.test(path)) {
17 continue;
18 }
19 yield core_1.join(directory.path, path);
20 }
21 for (const path of directory.subdirs) {
22 if (path === 'node_modules' || path.startsWith('.') || path === 'dist') {
23 continue;
24 }
25 yield* visitJavaScriptFiles(directory.dir(path));
26 }
27}
28function default_1() {
29 return (tree, context) => {
30 const current = dependencies_1.getPackageJsonDependency(tree, 'zone.js');
31 if (current && current.version !== '~0.11.4') {
32 dependencies_1.addPackageJsonDependency(tree, {
33 type: current.type,
34 name: 'zone.js',
35 version: '~0.11.4',
36 overwrite: true,
37 });
38 context.addTask(new tasks_1.NodePackageInstallTask());
39 }
40 for (const path of visitJavaScriptFiles(tree.root)) {
41 const buffer = tree.read(path);
42 if (!buffer) {
43 return;
44 }
45 const content = buffer.toString();
46 if (!content.includes('zone.js/dist/')) {
47 continue;
48 }
49 // RegExp that replaces
50 // - import 'zone.js/dist/zone-testing' -> import 'zone.js/testing'
51 // - require('zone.js/dist/zone-testing') -> require('zone.js/testing')
52 // - import 'zone.js/dist/zone' -> import 'zone.js'
53 // - require('zone.js/dist/zone') -> require('zone.js')
54 // - import 'zone.js/dist/zone-error' -> import 'zone.js/plugins/zone-error'
55 // - require('zone.js/dist/zone-error') -> require('zone.js/plugins/zone-error')
56 tree.overwrite(path, content.replace(/(?<=(?:require\s*\(|import\s+)['"]zone\.js)\/dist\/zone-?\w*(?=['"]\)?)/g, (match) => {
57 switch (match) {
58 case '/dist/zone':
59 case '/dist/zone-evergreen':
60 return '';
61 case '/dist/zone-testing':
62 case '/dist/zone-evergreen-testing':
63 return '/testing';
64 case '/dist/zone-node':
65 return '/node';
66 case '/dist/zone-mix':
67 return '/mix';
68 default:
69 return `/plugins${match.substr(5)}`;
70 }
71 }));
72 }
73 };
74}
75exports.default = default_1;
Note: See TracBrowser for help on using the repository browser.