Add patch for enabling new TS plugins on web approach (#149186)

* Add patch for enabling new TS plugins on web approach

https://github.com/microsoft/TypeScript/pull/47377

To run plugins on web, we need to shim out `dynamicImport`. This is done in a file call `tsserverWeb.js`, which is added by the linked PR

* Update for new files names
This commit is contained in:
Matt Bierner
2022-08-02 11:00:22 -07:00
committed by GitHub
parent 2d5a77a478
commit 424fe151f1

View File

@@ -8,6 +8,8 @@
'use strict';
const CopyPlugin = require('copy-webpack-plugin');
const Terser = require('terser');
const fs = require('fs');
const path = require('path');
const defaultConfig = require('../shared.webpack.config');
const withBrowserDefaults = defaultConfig.browser;
@@ -64,9 +66,12 @@ module.exports = withBrowserDefaults({
{
from: '../node_modules/typescript/lib/tsserver.js',
to: 'typescript/tsserver.web.js',
transform: (content) => {
return Terser.minify(content.toString()).then(output => output.code);
transform: async (content) => {
const dynamicImportCompatPath = path.join(__dirname, '..', 'node_modules', 'typescript', 'lib', 'dynamicImportCompat.js');
const prefix = fs.existsSync(dynamicImportCompatPath) ? fs.readFileSync(dynamicImportCompatPath) : undefined;
const output = await Terser.minify(content.toString());
return prefix + '\n' + output.code;
},
transformPath: (targetPath) => {
return targetPath.replace('tsserver.js', 'tsserver.web.js');