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 | */
|
---|
9 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
---|
10 | if (k2 === undefined) k2 = k;
|
---|
11 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
---|
12 | }) : (function(o, m, k, k2) {
|
---|
13 | if (k2 === undefined) k2 = k;
|
---|
14 | o[k2] = m[k];
|
---|
15 | }));
|
---|
16 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
---|
17 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
18 | }) : function(o, v) {
|
---|
19 | o["default"] = v;
|
---|
20 | });
|
---|
21 | var __importStar = (this && this.__importStar) || function (mod) {
|
---|
22 | if (mod && mod.__esModule) return mod;
|
---|
23 | var result = {};
|
---|
24 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
---|
25 | __setModuleDefault(result, mod);
|
---|
26 | return result;
|
---|
27 | };
|
---|
28 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
29 | exports.createWebpackSystem = void 0;
|
---|
30 | const ts = __importStar(require("typescript"));
|
---|
31 | const paths_1 = require("./paths");
|
---|
32 | function shouldNotWrite() {
|
---|
33 | throw new Error('Webpack TypeScript System should not write.');
|
---|
34 | }
|
---|
35 | function createWebpackSystem(input, currentDirectory) {
|
---|
36 | // Webpack's CachedInputFileSystem uses the default directory separator in the paths it uses
|
---|
37 | // for keys to its cache. If the keys do not match then the file watcher will not purge outdated
|
---|
38 | // files and cause stale data to be used in the next rebuild. TypeScript always uses a `/` (POSIX)
|
---|
39 | // directory separator internally which is also supported with Windows system APIs. However,
|
---|
40 | // if file operations are performed with the non-default directory separator, the Webpack cache
|
---|
41 | // will contain a key that will not be purged. `externalizePath` ensures the paths are as expected.
|
---|
42 | const system = {
|
---|
43 | ...ts.sys,
|
---|
44 | readFile(path) {
|
---|
45 | let data;
|
---|
46 | try {
|
---|
47 | data = input.readFileSync(paths_1.externalizePath(path));
|
---|
48 | }
|
---|
49 | catch {
|
---|
50 | return undefined;
|
---|
51 | }
|
---|
52 | // Strip BOM if present
|
---|
53 | let start = 0;
|
---|
54 | if (data.length > 3 && data[0] === 0xef && data[1] === 0xbb && data[2] === 0xbf) {
|
---|
55 | start = 3;
|
---|
56 | }
|
---|
57 | return data.toString('utf8', start);
|
---|
58 | },
|
---|
59 | getFileSize(path) {
|
---|
60 | try {
|
---|
61 | return input.statSync(paths_1.externalizePath(path)).size;
|
---|
62 | }
|
---|
63 | catch {
|
---|
64 | return 0;
|
---|
65 | }
|
---|
66 | },
|
---|
67 | fileExists(path) {
|
---|
68 | try {
|
---|
69 | return input.statSync(paths_1.externalizePath(path)).isFile();
|
---|
70 | }
|
---|
71 | catch {
|
---|
72 | return false;
|
---|
73 | }
|
---|
74 | },
|
---|
75 | directoryExists(path) {
|
---|
76 | try {
|
---|
77 | return input.statSync(paths_1.externalizePath(path)).isDirectory();
|
---|
78 | }
|
---|
79 | catch {
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 | },
|
---|
83 | getModifiedTime(path) {
|
---|
84 | try {
|
---|
85 | return input.statSync(paths_1.externalizePath(path)).mtime;
|
---|
86 | }
|
---|
87 | catch {
|
---|
88 | return undefined;
|
---|
89 | }
|
---|
90 | },
|
---|
91 | getCurrentDirectory() {
|
---|
92 | return currentDirectory;
|
---|
93 | },
|
---|
94 | writeFile: shouldNotWrite,
|
---|
95 | createDirectory: shouldNotWrite,
|
---|
96 | deleteFile: shouldNotWrite,
|
---|
97 | setModifiedTime: shouldNotWrite,
|
---|
98 | };
|
---|
99 | return system;
|
---|
100 | }
|
---|
101 | exports.createWebpackSystem = createWebpackSystem;
|
---|