From 0fd53e3abbbb035dd11914663c0f92de97717c95 Mon Sep 17 00:00:00 2001 From: Adam Bird Date: Tue, 13 Jul 2021 09:58:04 -0400 Subject: [PATCH] fix(webpack5): change .d.ts filter regex (#9470) --- .../__snapshots__/typescript.spec.ts.snap | 4 +-- .../configuration/typescript.spec.ts | 34 +++++++++++++++++++ .../webpack5/src/configuration/typescript.ts | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap index d1634f7e5..b63248635 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap @@ -313,7 +313,7 @@ exports[`typescript configuration for android 1`] = ` /* config.plugin('VirtualModulesPlugin') */ new VirtualModulesPlugin( { - '__jest__/src/__@nativescript_webpack_virtual_entry_typescript__': '// VIRTUAL ENTRY START\\\\nrequire(\\\\'@nativescript/core/bundle-entry-points\\\\')\\\\nconst context = require.context(\\"~/\\", /* deep: */ true, /* filter: */ /\\\\\\\\.(xml|js|(? { expect(typescript(new Config()).toString()).toMatchSnapshot(); }); } + + it('filter typescript declaration files', () => { + init({ + ios: true, + }); + + const tsConfig = typescript(new Config()); + let regex: RegExp; + + // Get the filterRE from the typescript configuration + tsConfig.plugin('VirtualModulesPlugin').tap((args) => { + const options = args[0]; + const virtualConfig: string = options[Object.keys(options)[0]]; + const filterLine = virtualConfig + .split('\n') + .find((v) => v.includes('filter')); + const matches = filterLine.match(/\/(?\S+)\//); + + if (matches) { + regex = new RegExp(matches.groups.filter); + } + + return args; + }); + + expect(regex).toBeDefined(); + + expect('test.ts').toMatch(regex); + expect('test.d.ts').not.toMatch(regex); + expect('tested.ts').toMatch(regex); + expect('tested.d.ts').not.toMatch(regex); + expect('test.d.tested.ts').toMatch(regex); + expect('test.d.tested.d.ts').not.toMatch(regex); + }); }); diff --git a/packages/webpack5/src/configuration/typescript.ts b/packages/webpack5/src/configuration/typescript.ts index 17ce9b2f6..71f1d7e4b 100644 --- a/packages/webpack5/src/configuration/typescript.ts +++ b/packages/webpack5/src/configuration/typescript.ts @@ -8,7 +8,7 @@ import base from './base'; export default function (config: Config, env: IWebpackEnv = _env): Config { base(config, env); const entryPath = getEntryPath(); - const filterRE = '/\\.(xml|js|(?