Repository: dotnet/runtime
File: src/native/rollup.config.plugins.js (JavaScript)

Code before:
                .replace(/}\({}\);/, "};") // }({}); ->};
                .replace(/}\)\({}\);/, "});"); // })({}); ->});
        }
    };
}

// Drop _ems_ symbol from emscripten libraries
export function emsAmbient() {
    return {
        name: "emsAmbient",
        generateBundle: (options, bundle) => {
            const name = Object.keys(bundle)[0];
            if (name.endsWith(".map")) return;
            const asset = bundle[name];
            const code = asset.code;
            //throw new Error("iife2fe " + code);
            asset.code = code
                .replace(/_ems_\./g, "");
        }
    };
}


// force always unix line ending
export const alwaysLF = () => ({
    name: "writeOnChange",
    generateBundle: (options, bundle) => {
        const name = Object.keys(bundle)[0];
        const asset = bundle[name];
        const code = asset.code;
        asset.code = code.replace(/\r/g, "");
    }
});

async function writeWhenChanged(options, bundle) {
    try {
        const name = Object.keys(bundle)[0];
        const asset = bundle[name];
        const code = asset.code;
        const hashFileName = options.file + ".sha256";
        const oldHashExists = await checkFileExists(hashFileName);
        const oldFileExists = await checkFileExists(options.file);

        const newHash = createHash("sha256").update(code).digest("hex");

        let isOutputChanged = true;
        if (oldHashExists && oldFileExists) {
            const oldHash = await readFile(hashFileName, { encoding: "ascii" });
            isOutputChanged = oldHash !== newHash;
        }
        if (isOutputChanged) {

Review comment (suggestion):
The plugin name is set to "writeOnChange" but this plugin is called "alwaysLF". This creates confusion and potential naming conflicts since the writeOnChangePlugin function also has a plugin named "writeOnChange". The name property should be "alwaysLF" to match the function name and purpose.
```suggestion
    name: "alwaysLF",
```

Code after:
                .replace(/}\({}\);/, "};") // }({}); ->};
                .replace(/}\)\({}\);/, "});"); // })({}); ->});
        }
    };
}

// Drop _ems_ symbol from emscripten libraries
export function emsAmbient() {
    return {
        name: "emsAmbient",
        generateBundle: (options, bundle) => {
            const name = Object.keys(bundle)[0];
            if (name.endsWith(".map")) return;
            const asset = bundle[name];
            const code = asset.code;
            //throw new Error("iife2fe " + code);
            asset.code = code
                .replace(/_ems_\./g, "");
        }
    };
}


// force always unix line ending
export const alwaysLF = () => ({
    name: "alwaysLF",
    generateBundle: (options, bundle) => {
        const name = Object.keys(bundle)[0];
        const asset = bundle[name];
        const code = asset.code;
        asset.code = code.replace(/\r/g, "");
    }
});

async function writeWhenChanged(options, bundle) {
    try {
        const name = Object.keys(bundle)[0];
        const asset = bundle[name];
        const code = asset.code;
        const hashFileName = options.file + ".sha256";
        const oldHashExists = await checkFileExists(hashFileName);
        const oldFileExists = await checkFileExists(options.file);

        const newHash = createHash("sha256").update(code).digest("hex");

        let isOutputChanged = true;
        if (oldHashExists && oldFileExists) {
            const oldHash = await readFile(hashFileName, { encoding: "ascii" });
            isOutputChanged = oldHash !== newHash;
        }
        if (isOutputChanged) {