Updated the project.

This commit is contained in:
Batuhan Berk Başoğlu 2024-06-03 15:44:25 -04:00
parent 5dfe9f128d
commit 7919556077
1550 changed files with 17063 additions and 40183 deletions

View file

@ -227,7 +227,10 @@ class HostTree {
return decoder.decode(data);
}
catch (e) {
if (e instanceof TypeError) {
// The second part should not be needed. But Jest does not support instanceof correctly.
// See: https://github.com/jestjs/jest/issues/2549
if (e instanceof TypeError ||
e.code === 'ERR_ENCODING_INVALID_ENCODED_DATA') {
throw new Error(`Failed to decode "${path}" as UTF-8 text.`);
}
throw e;

View file

@ -75,6 +75,10 @@ export interface Tree {
apply(action: Action, strategy?: MergeStrategy): void;
readonly actions: Action[];
}
export interface TreeConstructor {
isTree(maybeTree: object): maybeTree is Tree;
}
export declare const Tree: TreeConstructor;
export interface UpdateRecorder {
insertLeft(index: number, content: Buffer | string): UpdateRecorder;
insertRight(index: number, content: Buffer | string): UpdateRecorder;

View file

@ -7,7 +7,7 @@
* found in the LICENSE file at https://angular.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreeSymbol = exports.FileVisitorCancelToken = exports.MergeStrategy = void 0;
exports.Tree = exports.TreeSymbol = exports.FileVisitorCancelToken = exports.MergeStrategy = void 0;
var MergeStrategy;
(function (MergeStrategy) {
MergeStrategy[MergeStrategy["AllowOverwriteConflict"] = 2] = "AllowOverwriteConflict";
@ -37,11 +37,8 @@ exports.TreeSymbol = (function () {
}
return globalSymbol.schematicTree;
})();
// eslint-disable-next-line @typescript-eslint/no-namespace
var Tree;
(function (Tree) {
function isTree(maybeTree) {
exports.Tree = Object.freeze({
isTree(maybeTree) {
return exports.TreeSymbol in maybeTree;
}
Tree.isTree = isTree;
})(Tree || (Tree = {}));
},
});

View file

@ -5,24 +5,23 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { UpdateBufferBase } from '../utility/update-buffer';
import { BaseException } from '@angular-devkit/core';
import MagicString from 'magic-string';
import { FileEntry, UpdateRecorder } from './interface';
export declare class IndexOutOfBoundException extends BaseException {
constructor(index: number, min: number, max?: number);
}
export declare class UpdateRecorderBase implements UpdateRecorder {
private readonly data;
private readonly bom;
protected _path: string;
protected _original: Buffer;
protected _content: UpdateBufferBase;
constructor(entry: FileEntry);
protected content: MagicString;
constructor(data: Uint8Array, path: string, encoding?: string, bom?: boolean);
static createFromFileEntry(entry: FileEntry): UpdateRecorderBase;
get path(): string;
protected _assertIndex(index: number): void;
insertLeft(index: number, content: Buffer | string): UpdateRecorder;
insertRight(index: number, content: Buffer | string): UpdateRecorder;
remove(index: number, length: number): UpdateRecorder;
apply(content: Buffer): Buffer;
}
export declare class UpdateRecorderBom extends UpdateRecorderBase {
private _delta;
constructor(entry: FileEntry, _delta?: number);
insertLeft(index: number, content: Buffer | string): UpdateRecorder;
insertRight(index: number, content: Buffer | string): UpdateRecorder;
remove(index: number, length: number): UpdateRecorder;
}

View file

@ -6,18 +6,40 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpdateRecorderBom = exports.UpdateRecorderBase = void 0;
exports.UpdateRecorderBase = exports.IndexOutOfBoundException = void 0;
const core_1 = require("@angular-devkit/core");
const magic_string_1 = __importDefault(require("magic-string"));
const exception_1 = require("../exception/exception");
const update_buffer_1 = require("../utility/update-buffer");
class IndexOutOfBoundException extends core_1.BaseException {
constructor(index, min, max = Infinity) {
super(`Index ${index} outside of range [${min}, ${max}].`);
}
}
exports.IndexOutOfBoundException = IndexOutOfBoundException;
class UpdateRecorderBase {
data;
bom;
_path;
_original;
_content;
constructor(entry) {
this._original = Buffer.from(entry.content);
this._content = update_buffer_1.UpdateBufferBase.create(entry.path, entry.content);
this._path = entry.path;
content;
constructor(data, path, encoding = 'utf-8', bom = false) {
this.data = data;
this.bom = bom;
let text;
try {
text = new TextDecoder(encoding, { fatal: true, ignoreBOM: false }).decode(data);
}
catch (e) {
if (e instanceof TypeError) {
throw new Error(`Failed to decode "${path}" as ${encoding} text.`);
}
throw e;
}
this._path = path;
this.content = new magic_string_1.default(text);
}
static createFromFileEntry(entry) {
const c0 = entry.content.byteLength > 0 && entry.content.readUInt8(0);
@ -25,54 +47,47 @@ class UpdateRecorderBase {
const c2 = entry.content.byteLength > 2 && entry.content.readUInt8(2);
// Check if we're BOM.
if (c0 == 0xef && c1 == 0xbb && c2 == 0xbf) {
return new UpdateRecorderBom(entry);
return new UpdateRecorderBase(entry.content, entry.path, 'utf-8', true);
}
else if (c0 === 0xff && c1 == 0xfe) {
return new UpdateRecorderBom(entry);
return new UpdateRecorderBase(entry.content, entry.path, 'utf-16le', true);
}
else if (c0 === 0xfe && c1 == 0xff) {
return new UpdateRecorderBom(entry);
return new UpdateRecorderBase(entry.content, entry.path, 'utf-16be', true);
}
return new UpdateRecorderBase(entry);
return new UpdateRecorderBase(entry.content, entry.path);
}
get path() {
return this._path;
}
_assertIndex(index) {
if (index < 0 || index > this.content.original.length) {
throw new IndexOutOfBoundException(index, 0, this.content.original.length);
}
}
// These just record changes.
insertLeft(index, content) {
this._content.insertLeft(index, typeof content == 'string' ? Buffer.from(content) : content);
this._assertIndex(index);
this.content.appendLeft(index, content.toString());
return this;
}
insertRight(index, content) {
this._content.insertRight(index, typeof content == 'string' ? Buffer.from(content) : content);
this._assertIndex(index);
this.content.appendRight(index, content.toString());
return this;
}
remove(index, length) {
this._content.remove(index, length);
this._assertIndex(index);
this.content.remove(index, index + length);
return this;
}
apply(content) {
if (!content.equals(this._content.original)) {
if (!content.equals(this.data)) {
throw new exception_1.ContentHasMutatedException(this.path);
}
return this._content.generate();
// Schematics only support writing UTF-8 text
const result = Buffer.from((this.bom ? '\uFEFF' : '') + this.content.toString(), 'utf-8');
return result;
}
}
exports.UpdateRecorderBase = UpdateRecorderBase;
class UpdateRecorderBom extends UpdateRecorderBase {
_delta;
constructor(entry, _delta = 1) {
super(entry);
this._delta = _delta;
}
insertLeft(index, content) {
return super.insertLeft(index + this._delta, content);
}
insertRight(index, content) {
return super.insertRight(index + this._delta, content);
}
remove(index, length) {
return super.remove(index + this._delta, length);
}
}
exports.UpdateRecorderBom = UpdateRecorderBom;