Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maki-q opened this issue Nov 7, 2023 · 0 comments

Comments

@maki-q
Copy link

maki-q commented Nov 7, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant