Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions goldens/public-api/angular_devkit/core/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ type FileBuffer = ArrayBuffer;
// @public (undocumented)
type FileBufferLike = ArrayBufferLike;

// @public (undocumented)
// @public @deprecated (undocumented)
function fileBufferToString(fileBuffer: FileBuffer): string;

// @public (undocumented)
Expand Down Expand Up @@ -1012,7 +1012,7 @@ declare namespace strings {
}
export { strings }

// @public (undocumented)
// @public @deprecated (undocumented)
function stringToFileBuffer(str: string): FileBuffer;

// @public (undocumented)
Expand Down
10 changes: 5 additions & 5 deletions packages/angular_devkit/architect/testing/test-project-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class TestProjectHost extends NodeJsSyncHost {
Object.keys(files).forEach((fileName) => {
let content = files[fileName];
if (typeof content == 'string') {
content = virtualFs.stringToFileBuffer(content);
content = new TextEncoder().encode(content).buffer;
} else if (content instanceof Buffer) {
content = content.buffer.slice(content.byteOffset, content.byteOffset + content.byteLength);
}
Expand All @@ -127,16 +127,16 @@ export class TestProjectHost extends NodeJsSyncHost {
}

replaceInFile(path: string, match: RegExp | string, replacement: string): void {
const content = virtualFs.fileBufferToString(this.scopedSync().read(normalize(path)));
const content = new TextDecoder().decode(this.scopedSync().read(normalize(path)));
this.scopedSync().write(
normalize(path),
virtualFs.stringToFileBuffer(content.replace(match, replacement)),
new TextEncoder().encode(content.replace(match, replacement)).buffer,
);
}

appendToFile(path: string, str: string): void {
const content = virtualFs.fileBufferToString(this.scopedSync().read(normalize(path)));
this.scopedSync().write(normalize(path), virtualFs.stringToFileBuffer(content.concat(str)));
const content = new TextDecoder().decode(this.scopedSync().read(normalize(path)));
this.scopedSync().write(normalize(path), new TextEncoder().encode(content.concat(str)).buffer);
}

fileMatchExists(dir: string, regex: RegExp): PathFragment | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Architect } from '@angular-devkit/architect';
import { normalize, virtualFs } from '@angular-devkit/core';
import { normalize } from '@angular-devkit/core';
import { createArchitect, host } from '../../testing/test-utils';

describe('AppShell Builder', () => {
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('AppShell Builder', () => {
expect(output.success).toBe(true);

const fileName = 'dist/index.html';
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
const content = new TextDecoder().decode(host.scopedSync().read(normalize(fileName)));
expect(content).toMatch('Welcome to app');
});

Expand All @@ -147,7 +147,7 @@ describe('AppShell Builder', () => {

expect(output.success).toBe(true);
const fileName = 'dist/index.html';
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
const content = new TextDecoder().decode(host.scopedSync().read(normalize(fileName)));
expect(content).toContain('app-shell works!');
});

Expand All @@ -164,7 +164,7 @@ describe('AppShell Builder', () => {

expect(output.success).toBe(true);
const fileName = 'dist/index.html';
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
const content = new TextDecoder().decode(host.scopedSync().read(normalize(fileName)));

expect(content).toContain('app-shell works!');
expect(content).toContain('p{color:#000}');
Expand All @@ -187,7 +187,7 @@ describe('AppShell Builder', () => {

expect(output.success).toBe(true);
const fileName = 'dist/index.html';
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
const content = new TextDecoder().decode(host.scopedSync().read(normalize(fileName)));

expect(content).toContain('app-shell works!');
expect(content).toContain('<style nonce="{% nonce %}">p{color:#000}</style>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Architect } from '@angular-devkit/architect';

import { join, normalize, relative, virtualFs } from '@angular-devkit/core';
import { join, normalize, relative } from '@angular-devkit/core';
import { Observable, lastValueFrom, take, tap } from 'rxjs';
import { createArchitect, host } from '../../../testing/test-utils';
import { BrowserBuilderOutput } from '../index';
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('Browser Builder allow js', () => {
const output = await run.result;
expect(output.success).toBe(true);

const content = virtualFs.fileBufferToString(
const content = new TextDecoder().decode(
await lastValueFrom(host.read(join(normalize(output.outputs[0].path), 'main.js'))),
);

Expand All @@ -66,7 +66,7 @@ describe('Browser Builder allow js', () => {
const output = await run.result;
expect(output.success).toBe(true);

const content = virtualFs.fileBufferToString(
const content = new TextDecoder().decode(
await lastValueFrom(host.read(join(normalize(output.outputs[0].path), 'main.js'))),
);

Expand Down Expand Up @@ -96,7 +96,7 @@ describe('Browser Builder allow js', () => {
run.output.pipe(
tap((output) => {
const path = relative(host.root(), join(normalize(output.outputs[0].path), 'main.js'));
const content = virtualFs.fileBufferToString(host.scopedSync().read(path));
const content = new TextDecoder().decode(host.scopedSync().read(path));

switch (buildCount) {
case 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Architect } from '@angular-devkit/architect';
import { join, normalize, tags, virtualFs } from '@angular-devkit/core';
import { join, normalize, tags } from '@angular-devkit/core';
import { lastValueFrom } from 'rxjs';
import { createArchitect, host } from '../../../testing/test-utils';

Expand Down Expand Up @@ -39,7 +39,7 @@ describe('Browser Builder base href', () => {

expect(output.success).toBe(true);
const fileName = join(normalize(output.outputs[0].path), 'index.html');
const content = virtualFs.fileBufferToString(await lastValueFrom(host.read(fileName)));
const content = new TextDecoder().decode(await lastValueFrom(host.read(fileName)));
expect(content).toMatch(/<base href="\/myUrl">/);

await run.stop();
Expand All @@ -60,7 +60,7 @@ describe('Browser Builder base href', () => {

expect(output.success).toBeTrue();
const fileName = join(normalize(output.outputs[0].path), 'index.html');
const content = virtualFs.fileBufferToString(await lastValueFrom(host.read(fileName)));
const content = new TextDecoder().decode(await lastValueFrom(host.read(fileName)));
expect(content).toContain(`<base href=".">`);

await run.stop();
Expand All @@ -79,9 +79,7 @@ describe('Browser Builder base href', () => {
const output = await run.result;
expect(output.success).toBe(true);
const fileName = join(normalize(output.outputs[0].path), 'index.html');
const content = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content).toContain('<head><base href="/myUrl"><meta charset="UTF-8">');
await run.stop();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Architect } from '@angular-devkit/architect';
import { join, normalize, virtualFs } from '@angular-devkit/core';
import { join, normalize } from '@angular-devkit/core';
import { lastValueFrom } from 'rxjs';
import { createArchitect, host } from '../../../testing/test-utils';
import { BrowserBuilderOutput } from '../index';
Expand Down Expand Up @@ -37,9 +37,7 @@ describe('Browser Builder crossOrigin', () => {
const output = await run.result;
expect(output.success).toBe(true);
const fileName = join(normalize(output.outputs[0].path), 'index.html');
const content = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content).toBe(
`<html><head><base href="/"><link rel="stylesheet" href="styles.css" crossorigin="use-credentials"></head>` +
`<body><app-root></app-root>` +
Expand All @@ -57,9 +55,7 @@ describe('Browser Builder crossOrigin', () => {
const output = await run.result;
expect(output.success).toBe(true);
const fileName = join(normalize(output.outputs[0].path), 'index.html');
const content = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content).toBe(
`<html><head><base href="/">` +
`<link rel="stylesheet" href="styles.css" crossorigin="anonymous"></head>` +
Expand All @@ -78,9 +74,7 @@ describe('Browser Builder crossOrigin', () => {
const output = await run.result;
expect(output.success).toBe(true);
const fileName = join(normalize(output.outputs[0].path), 'index.html');
const content = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content).toBe(
`<html><head><base href="/">` +
`<link rel="stylesheet" href="styles.css"></head>` +
Expand All @@ -105,9 +99,7 @@ describe('Browser Builder crossOrigin', () => {
expect(output.success).toBe(true);

const fileName = join(normalize(output.outputs[0].path), 'runtime.js');
const content = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content).toContain('script.crossOrigin = "use-credentials"');
await run.stop();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Architect } from '@angular-devkit/architect';
import { join, normalize, virtualFs } from '@angular-devkit/core';
import { join, normalize } from '@angular-devkit/core';
import { lastValueFrom } from 'rxjs';
import { createArchitect, host } from '../../../testing/test-utils';
import { BrowserBuilderOutput } from '../index';
Expand Down Expand Up @@ -41,11 +41,9 @@ describe('Browser Builder deploy url', () => {

const fileName = join(outputPath, 'index.html');
const runtimeFileName = join(outputPath, 'runtime.js');
const content = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content).toContain('deployUrl/main.js');
const runtimeContent = virtualFs.fileBufferToString(
const runtimeContent = new TextDecoder().decode(
await lastValueFrom(host.read(normalize(runtimeFileName))),
);
expect(runtimeContent).toContain('deployUrl/');
Expand All @@ -54,9 +52,7 @@ describe('Browser Builder deploy url', () => {
const output2 = await run2.result;
expect(output2.outputs[0].path).toEqual(outputPath); // These should be the same.

const content2 = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content2 = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content2).toContain('http://example.com/some/path/main.js');

await run.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Architect } from '@angular-devkit/architect';
import { join, normalize, tags, virtualFs, workspaces } from '@angular-devkit/core';
import { join, normalize, tags, workspaces } from '@angular-devkit/core';
import { lastValueFrom } from 'rxjs';
import { createArchitect, host } from '../../../testing/test-utils';
import { BrowserBuilderOutput } from '../index';
Expand All @@ -34,9 +34,7 @@ describe('Browser Builder index HTML processing', () => {
const output = await run.result;
expect(output.success).toBe(true);
const fileName = join(normalize(output.outputs[0].path), 'index.html');
const content = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content).toBe(
`<html><head><base href="/"><link rel="stylesheet" href="styles.css"></head>` +
`<body><app-root></app-root><script src="runtime.js" type="module"></script>` +
Expand All @@ -59,9 +57,7 @@ describe('Browser Builder index HTML processing', () => {
const output = await run.result;
expect(output.success).toBe(true);
const fileName = join(normalize(output.outputs[0].path), 'index.html');
const content = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content).toBe(
`<html><head><base href="/"><link rel="stylesheet" href="styles.css"></head>` +
`<body><app-root></app-root>` +
Expand All @@ -84,9 +80,7 @@ describe('Browser Builder index HTML processing', () => {
const output = await run.result;
expect(output.success).toBe(true);
const fileName = join(normalize(output.outputs[0].path), 'index.html');
const content = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content).toBe(
`<html><head><title>&iacute;</title><base href="/"><link rel="stylesheet" href="styles.css"></head> ` +
`<body><app-root></app-root><script src="runtime.js" type="module"></script>` +
Expand All @@ -108,9 +102,7 @@ describe('Browser Builder index HTML processing', () => {
const output = await run.result;
expect(output.success).toBe(true);
const fileName = join(normalize(output.outputs[0].path), 'index.html');
const content = virtualFs.fileBufferToString(
await lastValueFrom(host.read(normalize(fileName))),
);
const content = new TextDecoder().decode(await lastValueFrom(host.read(normalize(fileName))));
expect(content).toBe(
`<html><head><base href="/"><%= csrf_meta_tags %><link rel="stylesheet" href="styles.css"></head> ` +
`<body><app-root></app-root><script src="runtime.js" type="module"></script>` +
Expand Down Expand Up @@ -159,7 +151,7 @@ describe('Browser Builder index HTML processing', () => {

const outputIndexPath = join(host.root(), 'dist', 'index.html');
const content = await lastValueFrom(host.read(normalize(outputIndexPath)));
expect(virtualFs.fileBufferToString(content)).toBe(
expect(new TextDecoder().decode(content)).toBe(
`<html><head><base href="/"><%= csrf_meta_tags %><link rel="stylesheet" href="styles.css"></head> ` +
`<body><app-root></app-root><script src="runtime.js" type="module"></script>` +
`<script src="polyfills.js" type="module"></script>` +
Expand Down Expand Up @@ -206,7 +198,7 @@ describe('Browser Builder index HTML processing', () => {

const outputIndexPath = join(host.root(), 'dist', 'main.html');
const content = await lastValueFrom(host.read(normalize(outputIndexPath)));
expect(virtualFs.fileBufferToString(content)).toBe(
expect(new TextDecoder().decode(content)).toBe(
`<html><head><base href="/"><link rel="stylesheet" href="styles.css"></head> ` +
`<body><app-root></app-root><script src="runtime.js" type="module"></script>` +
`<script src="polyfills.js" type="module"></script>` +
Expand Down Expand Up @@ -253,7 +245,7 @@ describe('Browser Builder index HTML processing', () => {

const outputIndexPath = join(host.root(), 'dist', 'extra', 'main.html');
const content = await lastValueFrom(host.read(normalize(outputIndexPath)));
expect(virtualFs.fileBufferToString(content)).toBe(
expect(new TextDecoder().decode(content)).toBe(
`<html><head><base href="/"><link rel="stylesheet" href="styles.css"></head> ` +
`<body><app-root></app-root><script src="runtime.js" type="module"></script>` +
`<script src="polyfills.js" type="module"></script>` +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Architect } from '@angular-devkit/architect';
import { getSystemPath, join, virtualFs } from '@angular-devkit/core';
import { getSystemPath, join } from '@angular-devkit/core';
import * as fs from 'node:fs';
import { browserBuild, createArchitect, host } from '../../../testing/test-utils';

Expand All @@ -24,7 +24,7 @@ describe('Browser Builder output path', () => {
it('deletes output path content', async () => {
// Write a file to the output path to later verify it was deleted.
await host
.write(join(host.root(), 'dist/file.txt'), virtualFs.stringToFileBuffer('file'))
.write(join(host.root(), 'dist/file.txt'), new TextEncoder().encode('file').buffer)
.toPromise();

// Delete an app file to force a failed compilation.
Expand All @@ -42,7 +42,7 @@ describe('Browser Builder output path', () => {
// Write a file to the output path to later verify it was deleted.
host.writeMultipleFiles({
'src-link/a.txt': '',
'dist/file.txt': virtualFs.stringToFileBuffer('file'),
'dist/file.txt': new TextEncoder().encode('file').buffer,
});

const distLinked = join(host.root(), 'dist', 'linked');
Expand Down
Loading
Loading