refactor: simplify App_Resource exclusions

This commit is contained in:
Igor Randjelovic
2021-04-14 15:09:33 +02:00
parent 582f161dd9
commit 4f8522f5d4
3 changed files with 50 additions and 40 deletions

View File

@ -15,7 +15,7 @@ exports[`base configuration for android 1`] = `
watchOptions: {
ignored: [
'__jest__/platforms/**',
'__jest__/App_Resources/**'
'__jest__/custom_app_resources/**'
]
},
ignoreWarnings: [
@ -255,7 +255,9 @@ exports[`base configuration for android 1`] = `
noErrorOnMissing: true,
globOptions: {
dot: false,
ignore: []
ignore: [
'**/custom_app_resources/**'
]
}
},
{
@ -264,7 +266,9 @@ exports[`base configuration for android 1`] = `
noErrorOnMissing: true,
globOptions: {
dot: false,
ignore: []
ignore: [
'**/custom_app_resources/**'
]
}
},
{
@ -273,7 +277,9 @@ exports[`base configuration for android 1`] = `
noErrorOnMissing: true,
globOptions: {
dot: false,
ignore: []
ignore: [
'**/custom_app_resources/**'
]
}
}
]
@ -308,7 +314,7 @@ exports[`base configuration for ios 1`] = `
watchOptions: {
ignored: [
'__jest__/platforms/**',
'__jest__/App_Resources/**'
'__jest__/custom_app_resources/**'
]
},
ignoreWarnings: [
@ -548,7 +554,9 @@ exports[`base configuration for ios 1`] = `
noErrorOnMissing: true,
globOptions: {
dot: false,
ignore: []
ignore: [
'**/custom_app_resources/**'
]
}
},
{
@ -557,7 +565,9 @@ exports[`base configuration for ios 1`] = `
noErrorOnMissing: true,
globOptions: {
dot: false,
ignore: []
ignore: [
'**/custom_app_resources/**'
]
}
},
{
@ -566,7 +576,9 @@ exports[`base configuration for ios 1`] = `
noErrorOnMissing: true,
globOptions: {
dot: false,
ignore: []
ignore: [
'**/custom_app_resources/**'
]
}
}
]

View File

@ -3,8 +3,8 @@ import fs from 'fs';
import base from '../../src/configuration/base';
import { init } from '../../src';
import { applyFileReplacements } from "../../src/helpers/fileReplacements";
import { additionalCopyRules } from "../../src/helpers/copyRules";
import { applyFileReplacements } from '../../src/helpers/fileReplacements';
import { additionalCopyRules } from '../../src/helpers/copyRules';
describe('base configuration', () => {
const platforms = ['ios', 'android'];
@ -13,14 +13,18 @@ describe('base configuration', () => {
it(`for ${platform}`, () => {
init({
[platform]: true,
// only test in base config to make sure App_Resources
// are properly excluded from the copy-rules
appResourcesPath: '__jest__/custom_app_resources',
});
expect(base(new Config()).toString()).toMatchSnapshot();
});
}
it('supports dotenv', () => {
const fsSpy = jest.spyOn(fs, "existsSync")
fsSpy.mockReturnValue(true)
const fsSpy = jest.spyOn(fs, 'existsSync');
fsSpy.mockReturnValue(true);
init({
ios: true,
@ -33,12 +37,12 @@ describe('base configuration', () => {
return args;
});
fsSpy.mockRestore()
fsSpy.mockRestore();
});
it('supports env specific dotenv', () => {
const fsSpy = jest.spyOn(fs, "existsSync")
fsSpy.mockReturnValue(true)
const fsSpy = jest.spyOn(fs, 'existsSync');
fsSpy.mockReturnValue(true);
init({
ios: true,
@ -46,22 +50,19 @@ describe('base configuration', () => {
});
const config = base(new Config());
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env.prod')
expect(fsSpy).toHaveBeenCalledTimes(1)
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env.prod');
expect(fsSpy).toHaveBeenCalledTimes(1);
expect(config.plugin('DotEnvPlugin')).toBeDefined();
config.plugin('DotEnvPlugin').tap((args) => {
expect(args[0].path).toEqual('__jest__/.env.prod');
return args;
});
fsSpy.mockRestore()
fsSpy.mockRestore();
});
it('falls back to default .env', () => {
const fsSpy = jest.spyOn(fs, "existsSync")
fsSpy
.mockReturnValueOnce(false)
.mockReturnValueOnce(true)
const fsSpy = jest.spyOn(fs, 'existsSync');
fsSpy.mockReturnValueOnce(false).mockReturnValueOnce(true);
init({
ios: true,
@ -69,15 +70,15 @@ describe('base configuration', () => {
});
const config = base(new Config());
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env.prod')
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env')
expect(fsSpy).toHaveBeenCalledTimes(2)
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env.prod');
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env');
expect(fsSpy).toHaveBeenCalledTimes(2);
expect(config.plugin('DotEnvPlugin')).toBeDefined();
config.plugin('DotEnvPlugin').tap((args) => {
expect(args[0].path).toEqual('__jest__/.env');
return args;
});
fsSpy.mockRestore()
fsSpy.mockRestore();
});
it('applies file replacements', () => {
@ -88,16 +89,16 @@ describe('base configuration', () => {
'bar.js': 'bar.replaced.js',
// should apply as a file replacement using the copy plugin
'foo.json': 'foo.replaced.json'
})
'foo.json': 'foo.replaced.json',
});
expect(config.resolve.alias.get('foo.ts')).toBe('foo.replaced.ts')
expect(config.resolve.alias.get('bar.js')).toBe('bar.replaced.js')
expect(additionalCopyRules.length).toBe(1)
expect(config.resolve.alias.get('foo.ts')).toBe('foo.replaced.ts');
expect(config.resolve.alias.get('bar.js')).toBe('bar.replaced.js');
expect(additionalCopyRules.length).toBe(1);
expect(additionalCopyRules[0]).toEqual({
from: 'foo.replaced.json',
to: 'foo.json',
force: true,
})
})
});
});
});

View File

@ -1,5 +1,5 @@
import CopyWebpackPlugin from 'copy-webpack-plugin';
import { relative, resolve } from 'path';
import { basename, relative, resolve } from 'path';
import Config from 'webpack-chain';
import { getProjectRootPath } from './project';
@ -61,13 +61,10 @@ export function applyCopyRules(config: Config) {
// todo: do we need to handle empty appResourcesPath?
// (the CLI should always pass the path - maybe not required)
if (env.appResourcesPath) {
const appResourcesFullPath = resolve(
getProjectRootPath(),
env.appResourcesPath
);
const appResourcesFolderName = basename(env.appResourcesPath);
// ignore everything in App_Resources (regardless where they are located)
globOptions.ignore.push(`**/${relative(entryDir, appResourcesFullPath)}/**`);
globOptions.ignore.push(`**/${appResourcesFolderName}/**`);
}
config.plugin('CopyWebpackPlugin').use(CopyWebpackPlugin, [