microsoft / microsoft/TypeScript-Website

CRITICAL: createFile from createVirtualTypeScriptEnvironment does not create a file detectable by it's own updateFile

Open
#2,972 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.6k
Forks
1.5k
Avg merge
2d 2h
Merged PRs (30d)
7

Description

Page URL: https://github.com/microsoft/TypeScript-Website/blob/v2/packages/typescript-vfs/src/index.ts#L72

Issue: When calling updateFile on a newly created file, an error is thrown, stating Error: Did not find a source file for X. I believe the internal fs mapping does not get updated with the newly created files.

Here's an example:


    import {
        createDefaultMapFromCDN,
        createSystem,
        createVirtualTypeScriptEnvironment
    } from '@typescript/vfs';
    import ts from 'typescript';

    const compilerOpts = {
        target: ts.ScriptTarget.ES2021,
        module: ts.ScriptTarget.ES2020,
        lib: ['es2021', 'es2020', 'dom', 'webworker'],
        esModuleInterop: true
    };

    const fsMap = await createDefaultMapFromCDN(
        compilerOpts,
        ts.version,
        false,
        ts
    );
    const ENTRY_POINT = 'index.ts';
    fsMap.set(ENTRY_POINT, 'Hello World');

    const system = createSystem(fsMap);
    const env = createVirtualTypeScriptEnvironment(
        system,
        [ENTRY_POINT],
        ts,
        compilerOpts
    );

    env.createFile('test.js', 'test')
    env.updateFile('test.js', 'hello world') // throws error

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at packages/typescript-vfs/src/index.ts around line 72 and reproduce the example using createVirtualTypeScriptEnvironment, createFile, and updateFile. Trace why the newly created test.js is not found, then verify that updating it no longer throws the reported source-file error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.