Skip to content

Commit e98b0f1

Browse files
JeanMechepkozlowski-opensource
authored andcommitted
docs(docs-infra): Check for files without using / as root. (angular#59726)
In certain circonstances, a leading slash in the file paths created a incorrect unarchived project. fixes angular#57075 PR Close angular#59726
1 parent 97897ee commit e98b0f1

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

adev/shared-docs/testing/testing-helper.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,16 @@ class FakeFileSystemAPI implements FileSystemAPI {
144144
): Promise<DirEnt<string>[]>;
145145
readdir(
146146
path: unknown,
147-
options?: unknown,
147+
options?: {encoding?: string | null | undefined; withFileTypes?: boolean} | string | null,
148148
):
149149
| Promise<Uint8Array[]>
150150
| Promise<string[]>
151151
| Promise<DirEnt<Uint8Array>[]>
152152
| Promise<DirEnt<string>[]> {
153+
if (typeof options === 'object' && options?.withFileTypes === true) {
154+
return Promise.resolve([{name: 'fake-file', isFile: () => true, isDirectory: () => false}]);
155+
}
156+
153157
return Promise.resolve(['/fake-dirname']);
154158
}
155159

adev/shared-docs/utils/zip.utils.ts

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import {zip, strToU8} from 'fflate';
1414
export async function generateZip(files: FileAndContent[]): Promise<Uint8Array> {
1515
const filesObj: Record<string, Uint8Array> = {};
1616
files.forEach(({path, content}) => {
17-
if (path.startsWith('/')) {
18-
path = path.slice(1);
19-
}
2017
filesObj[path] = typeof content === 'string' ? strToU8(content) : content;
2118
});
2219

adev/src/app/editor/node-runtime-sandbox.service.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,18 @@ describe('NodeRuntimeSandbox', () => {
300300
expect(deleteFileSpy).toHaveBeenCalledWith(fileToDelete);
301301
}
302302
});
303+
304+
it('should not have any filePath starting with "/" in solutions files', async () => {
305+
service['webContainerPromise'] = Promise.resolve(
306+
new FakeWebContainer() as unknown as WebContainer,
307+
);
308+
setValuesToInitializeProject();
309+
310+
await service.init();
311+
312+
const files = await service.getSolutionFiles();
313+
314+
expect(files.length).toBe(1);
315+
expect(files[0].path).toBe('fake-file');
316+
});
303317
});

adev/src/app/editor/node-runtime-sandbox.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class NodeRuntimeSandbox {
146146
const excludeFolders = ['node_modules', '.angular', 'dist'];
147147

148148
return await checkFilesInDirectory(
149-
'/',
149+
'',
150150
webContainer.fs,
151151
(path?: string) => !!path && !excludeFolders.includes(path),
152152
);

0 commit comments

Comments
 (0)