mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
fix(webpack5): change .d.ts filter regex (#9470)
This commit is contained in:
@ -313,7 +313,7 @@ exports[`typescript configuration for android 1`] = `
|
|||||||
/* config.plugin('VirtualModulesPlugin') */
|
/* config.plugin('VirtualModulesPlugin') */
|
||||||
new 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|(?<!d\\\\\\\\.)ts|s?css)$/);\\\\nglobal.registerWebpackModules(context);\\\\n// VIRTUAL ENTRY END'
|
'__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|(?<!\\\\\\\\.d\\\\\\\\.)ts|s?css)$/);\\\\nglobal.registerWebpackModules(context);\\\\n// VIRTUAL ENTRY END'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@ -642,7 +642,7 @@ exports[`typescript configuration for ios 1`] = `
|
|||||||
/* config.plugin('VirtualModulesPlugin') */
|
/* config.plugin('VirtualModulesPlugin') */
|
||||||
new 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|(?<!d\\\\\\\\.)ts|s?css)$/);\\\\nglobal.registerWebpackModules(context);\\\\n// VIRTUAL ENTRY END'
|
'__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|(?<!\\\\\\\\.d\\\\\\\\.)ts|s?css)$/);\\\\nglobal.registerWebpackModules(context);\\\\n// VIRTUAL ENTRY END'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
@ -14,4 +14,38 @@ describe('typescript configuration', () => {
|
|||||||
expect(typescript(new Config()).toString()).toMatchSnapshot();
|
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(/\/(?<filter>\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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -8,7 +8,7 @@ import base from './base';
|
|||||||
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||||
base(config, env);
|
base(config, env);
|
||||||
const entryPath = getEntryPath();
|
const entryPath = getEntryPath();
|
||||||
const filterRE = '/\\.(xml|js|(?<!d\\.)ts|s?css)$/';
|
const filterRE = '/\\.(xml|js|(?<!\\.d\\.)ts|s?css)$/';
|
||||||
const virtualEntryPath = addVirtualEntry(
|
const virtualEntryPath = addVirtualEntry(
|
||||||
config,
|
config,
|
||||||
'typescript',
|
'typescript',
|
||||||
|
Reference in New Issue
Block a user