mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge branch 'master' into feat/webpack5-polyfills
This commit is contained in:
@@ -147,7 +147,7 @@ export interface NativeScriptConfig {
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* App's main entry file (currently ignored - set it in package.json main field)
|
||||
* App's main entry file - this setting overrides the value set in package.json
|
||||
*/
|
||||
main?: string;
|
||||
/**
|
||||
|
||||
@@ -331,6 +331,10 @@ exports[`angular configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@@ -748,6 +752,10 @@ exports[`angular configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
||||
@@ -242,6 +242,10 @@ exports[`base configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@@ -556,6 +560,10 @@ exports[`base configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@@ -628,3 +636,9 @@ exports[`base configuration for ios 1`] = `
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`base configuration support env.watchNodeModules 1`] = `
|
||||
Object {
|
||||
"managedPaths": Array [],
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -242,6 +242,10 @@ exports[`javascript configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@@ -565,6 +569,10 @@ exports[`javascript configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
||||
@@ -264,6 +264,10 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@@ -589,6 +593,10 @@ exports[`react configuration > android > base config 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@@ -921,6 +929,10 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@@ -1247,6 +1259,10 @@ exports[`react configuration > ios > base config 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
||||
@@ -269,6 +269,10 @@ exports[`svelte configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@@ -604,6 +608,10 @@ exports[`svelte configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
||||
@@ -242,6 +242,10 @@ exports[`typescript configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@@ -565,6 +569,10 @@ exports[`typescript configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
||||
@@ -282,6 +282,10 @@ exports[`vue configuration for android 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(ios)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
@@ -630,6 +634,10 @@ exports[`vue configuration for ios 1`] = `
|
||||
new ContextExclusionPlugin(
|
||||
/(.*)App_Resources(.*)/
|
||||
),
|
||||
/* config.plugin('ContextExclusionPlugin|Other_Platforms') */
|
||||
new ContextExclusionPlugin(
|
||||
/\\\\.(android)\\\\.(\\\\w+)$/
|
||||
),
|
||||
/* config.plugin('DefinePlugin') */
|
||||
new DefinePlugin(
|
||||
{
|
||||
|
||||
@@ -22,6 +22,14 @@ describe('base configuration', () => {
|
||||
});
|
||||
}
|
||||
|
||||
it('support env.watchNodeModules', () => {
|
||||
init({
|
||||
ios: true,
|
||||
watchNodeModules: true,
|
||||
});
|
||||
expect(base(new Config()).get('snapshot')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('supports dotenv', () => {
|
||||
const fsSpy = jest.spyOn(fs, 'existsSync');
|
||||
fsSpy.mockReturnValue(true);
|
||||
|
||||
49
packages/webpack5/__tests__/helpers/platform.spec.ts
Normal file
49
packages/webpack5/__tests__/helpers/platform.spec.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { env } from '../../src/';
|
||||
import { addPlatform, getEntryPath } from '../../src/helpers/platform';
|
||||
|
||||
import { getValue } from '../../src/helpers/config';
|
||||
|
||||
describe('getEntryPath', () => {
|
||||
it('uses platform getEntryPath if the platform specifies it', () => {
|
||||
env.platform = 'testPlatform';
|
||||
addPlatform('testPlatform', {
|
||||
getEntryPath() {
|
||||
return 'custom-entry-path';
|
||||
},
|
||||
});
|
||||
|
||||
const res = getEntryPath();
|
||||
expect(res).toEqual('custom-entry-path');
|
||||
|
||||
// cleanup env
|
||||
delete env.platform;
|
||||
});
|
||||
|
||||
it('uses main from nativescript.config.ts if set', () => {
|
||||
env.ios = true;
|
||||
|
||||
// mock getValue
|
||||
const getValueMock = getValue as jest.Mock;
|
||||
const getValueMockImpl = getValueMock.getMockImplementation();
|
||||
|
||||
getValueMock.mockImplementation((key) => {
|
||||
if (key === 'main') {
|
||||
return 'main-from-config';
|
||||
}
|
||||
});
|
||||
|
||||
const res = getEntryPath();
|
||||
expect(res).toEqual('__jest__/main-from-config');
|
||||
|
||||
// reset mock implementation
|
||||
getValueMock.mockImplementation(getValueMockImpl);
|
||||
});
|
||||
|
||||
it('uses main from package.json', () => {
|
||||
env.ios = true;
|
||||
|
||||
const res = getEntryPath();
|
||||
// set in jest.setup.ts mock for package.json...
|
||||
expect(res).toEqual('__jest__/src/app.js');
|
||||
});
|
||||
});
|
||||
@@ -13,10 +13,10 @@ jest.mock('cosmiconfig', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const getValueMock = jest.fn();
|
||||
getValueMock.mockImplementation((key, defaultValue) => defaultValue);
|
||||
jest.mock('../src/helpers/config.ts', () => ({
|
||||
getValue(key, defaultValue) {
|
||||
return defaultValue;
|
||||
},
|
||||
getValue: getValueMock,
|
||||
}));
|
||||
|
||||
jest.mock('os', () => {
|
||||
|
||||
@@ -23,8 +23,9 @@ import { env as _env, IWebpackEnv } from '../index';
|
||||
import { getValue } from '../helpers/config';
|
||||
import { getIPS } from '../helpers/host';
|
||||
import {
|
||||
getPlatformName,
|
||||
getAvailablePlatforms,
|
||||
getAbsoluteDistPath,
|
||||
getPlatformName,
|
||||
getEntryDirPath,
|
||||
getEntryPath,
|
||||
} from '../helpers/platform';
|
||||
@@ -124,6 +125,13 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
],
|
||||
});
|
||||
|
||||
// allow watching node_modules
|
||||
config.when(env.watchNodeModules, (config) => {
|
||||
config.set('snapshot', {
|
||||
managedPaths: [],
|
||||
});
|
||||
});
|
||||
|
||||
// Set up Terser options
|
||||
config.optimization.minimizer('TerserPlugin').use(TerserPlugin, [
|
||||
{
|
||||
@@ -366,6 +374,18 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
.plugin('ContextExclusionPlugin|App_Resources')
|
||||
.use(ContextExclusionPlugin, [new RegExp(`(.*)App_Resources(.*)`)]);
|
||||
|
||||
// Makes sure that require.context will never include code from
|
||||
// another platform (ie .android.ts when building for ios)
|
||||
const otherPlatformsRE = getAvailablePlatforms()
|
||||
.filter((platform) => platform !== getPlatformName())
|
||||
.join('|');
|
||||
|
||||
config
|
||||
.plugin('ContextExclusionPlugin|Other_Platforms')
|
||||
.use(ContextExclusionPlugin, [
|
||||
new RegExp(`\\.(${otherPlatformsRE})\\.(\\w+)$`),
|
||||
]);
|
||||
|
||||
// Filter common undesirable warnings
|
||||
config.set(
|
||||
'ignoreWarnings',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { warnOnce } from './log';
|
||||
import { env } from '../index';
|
||||
import { error, warnOnce } from './log';
|
||||
|
||||
function getCLILib() {
|
||||
if (!env.nativescriptLibPath) {
|
||||
@@ -28,7 +28,9 @@ export function getValue<T = any>(key: string, defaultValue?: any): T {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return (lib.projectConfigService as {
|
||||
getValue(key: string, defaultValue?: any): T;
|
||||
}).getValue(key, defaultValue);
|
||||
return (
|
||||
lib.projectConfigService as {
|
||||
getValue(key: string, defaultValue?: any): T;
|
||||
}
|
||||
).getValue(key, defaultValue);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { dirname, resolve } from 'path';
|
||||
|
||||
import { getPackageJson, getProjectRootPath } from './project';
|
||||
import { error, info, warnOnce } from './log';
|
||||
import { getValue } from './config';
|
||||
import { env } from '../';
|
||||
|
||||
import AndroidPlatform from '../platforms/android';
|
||||
@@ -40,6 +41,13 @@ export function getPlatform(): INativeScriptPlatform {
|
||||
return platforms[getPlatformName()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to get all registered/available platforms
|
||||
*/
|
||||
export function getAvailablePlatforms(): string[] {
|
||||
return Object.keys(platforms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to get the currently targeted platform name
|
||||
*/
|
||||
@@ -61,7 +69,7 @@ export function getPlatformName(): Platform {
|
||||
throw error(`
|
||||
Invalid platform: ${env.platform}
|
||||
|
||||
Valid platforms: ${Object.keys(platforms).join(', ')}
|
||||
Valid platforms: ${getAvailablePlatforms().join(', ')}
|
||||
`);
|
||||
}
|
||||
|
||||
@@ -92,6 +100,13 @@ export function getEntryPath() {
|
||||
return platform.getEntryPath();
|
||||
}
|
||||
|
||||
// try main from nativescript.config.ts
|
||||
const main = getValue('main');
|
||||
|
||||
if (main) {
|
||||
return resolve(getProjectRootPath(), main);
|
||||
}
|
||||
|
||||
// fallback to main field in package.json
|
||||
const packageJson = getPackageJson();
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ export interface IWebpackEnv {
|
||||
|
||||
// misc
|
||||
replace?: string[] | string;
|
||||
watchNodeModules?: boolean;
|
||||
}
|
||||
|
||||
interface IChainEntry {
|
||||
|
||||
Reference in New Issue
Block a user