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

@ -42,7 +42,10 @@ function applyContentTemplate(options) {
};
}
catch (e) {
if (e.code === 'ERR_ENCODING_INVALID_ENCODED_DATA') {
// 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') {
return entry;
}
throw e;

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;

View file

@ -1,50 +0,0 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* 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 { BaseException } from '@angular-devkit/core';
import MagicString from 'magic-string';
export declare class IndexOutOfBoundException extends BaseException {
constructor(index: number, min: number, max?: number);
}
/**
* Base class for an update buffer implementation that allows buffers to be inserted to the _right
* or _left, or deleted, while keeping indices to the original buffer.
*/
export declare abstract class UpdateBufferBase {
protected _originalContent: Buffer;
constructor(_originalContent: Buffer);
abstract get length(): number;
abstract get original(): Buffer;
abstract toString(encoding?: string): string;
abstract generate(): Buffer;
abstract insertLeft(index: number, content: Buffer, assert?: boolean): void;
abstract insertRight(index: number, content: Buffer, assert?: boolean): void;
abstract remove(index: number, length: number): void;
/**
* Creates an UpdateBufferBase instance.
*
* @param contentPath The path of the update buffer instance.
* @param originalContent The original content of the update buffer instance.
* @returns An UpdateBufferBase instance.
*/
static create(contentPath: string, originalContent: Buffer): UpdateBufferBase;
}
/**
* An utility class that allows buffers to be inserted to the _right or _left, or deleted, while
* keeping indices to the original buffer.
*/
export declare class UpdateBuffer extends UpdateBufferBase {
protected _mutatableContent: MagicString;
protected _assertIndex(index: number): void;
get length(): number;
get original(): Buffer;
toString(): string;
generate(): Buffer;
insertLeft(index: number, content: Buffer): void;
insertRight(index: number, content: Buffer): void;
remove(index: number, length: number): void;
}

View file

@ -1,90 +0,0 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* 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.UpdateBuffer = exports.UpdateBufferBase = exports.IndexOutOfBoundException = void 0;
const core_1 = require("@angular-devkit/core");
const magic_string_1 = __importDefault(require("magic-string"));
const node_util_1 = require("node:util");
class IndexOutOfBoundException extends core_1.BaseException {
constructor(index, min, max = Infinity) {
super(`Index ${index} outside of range [${min}, ${max}].`);
}
}
exports.IndexOutOfBoundException = IndexOutOfBoundException;
/**
* Base class for an update buffer implementation that allows buffers to be inserted to the _right
* or _left, or deleted, while keeping indices to the original buffer.
*/
class UpdateBufferBase {
_originalContent;
constructor(_originalContent) {
this._originalContent = _originalContent;
}
/**
* Creates an UpdateBufferBase instance.
*
* @param contentPath The path of the update buffer instance.
* @param originalContent The original content of the update buffer instance.
* @returns An UpdateBufferBase instance.
*/
static create(contentPath, originalContent) {
try {
// We only support utf8 encoding.
new node_util_1.TextDecoder('utf8', { fatal: true }).decode(originalContent);
return new UpdateBuffer(originalContent);
}
catch (e) {
if (e instanceof TypeError) {
throw new Error(`Failed to decode "${contentPath}" as UTF-8 text.`);
}
throw e;
}
}
}
exports.UpdateBufferBase = UpdateBufferBase;
/**
* An utility class that allows buffers to be inserted to the _right or _left, or deleted, while
* keeping indices to the original buffer.
*/
class UpdateBuffer extends UpdateBufferBase {
_mutatableContent = new magic_string_1.default(this._originalContent.toString());
_assertIndex(index) {
if (index < 0 || index > this._originalContent.length) {
throw new IndexOutOfBoundException(index, 0, this._originalContent.length);
}
}
get length() {
return this._mutatableContent.length();
}
get original() {
return this._originalContent;
}
toString() {
return this._mutatableContent.toString();
}
generate() {
return Buffer.from(this.toString());
}
insertLeft(index, content) {
this._assertIndex(index);
this._mutatableContent.appendLeft(index, content.toString());
}
insertRight(index, content) {
this._assertIndex(index);
this._mutatableContent.appendRight(index, content.toString());
}
remove(index, length) {
this._assertIndex(index);
this._mutatableContent.remove(index, index + length);
}
}
exports.UpdateBuffer = UpdateBuffer;