mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
refactor: simplify App_Resource exclusions
This commit is contained in:
@ -15,7 +15,7 @@ exports[`base configuration for android 1`] = `
|
|||||||
watchOptions: {
|
watchOptions: {
|
||||||
ignored: [
|
ignored: [
|
||||||
'__jest__/platforms/**',
|
'__jest__/platforms/**',
|
||||||
'__jest__/App_Resources/**'
|
'__jest__/custom_app_resources/**'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
ignoreWarnings: [
|
ignoreWarnings: [
|
||||||
@ -255,7 +255,9 @@ exports[`base configuration for android 1`] = `
|
|||||||
noErrorOnMissing: true,
|
noErrorOnMissing: true,
|
||||||
globOptions: {
|
globOptions: {
|
||||||
dot: false,
|
dot: false,
|
||||||
ignore: []
|
ignore: [
|
||||||
|
'**/custom_app_resources/**'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -264,7 +266,9 @@ exports[`base configuration for android 1`] = `
|
|||||||
noErrorOnMissing: true,
|
noErrorOnMissing: true,
|
||||||
globOptions: {
|
globOptions: {
|
||||||
dot: false,
|
dot: false,
|
||||||
ignore: []
|
ignore: [
|
||||||
|
'**/custom_app_resources/**'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -273,7 +277,9 @@ exports[`base configuration for android 1`] = `
|
|||||||
noErrorOnMissing: true,
|
noErrorOnMissing: true,
|
||||||
globOptions: {
|
globOptions: {
|
||||||
dot: false,
|
dot: false,
|
||||||
ignore: []
|
ignore: [
|
||||||
|
'**/custom_app_resources/**'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -308,7 +314,7 @@ exports[`base configuration for ios 1`] = `
|
|||||||
watchOptions: {
|
watchOptions: {
|
||||||
ignored: [
|
ignored: [
|
||||||
'__jest__/platforms/**',
|
'__jest__/platforms/**',
|
||||||
'__jest__/App_Resources/**'
|
'__jest__/custom_app_resources/**'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
ignoreWarnings: [
|
ignoreWarnings: [
|
||||||
@ -548,7 +554,9 @@ exports[`base configuration for ios 1`] = `
|
|||||||
noErrorOnMissing: true,
|
noErrorOnMissing: true,
|
||||||
globOptions: {
|
globOptions: {
|
||||||
dot: false,
|
dot: false,
|
||||||
ignore: []
|
ignore: [
|
||||||
|
'**/custom_app_resources/**'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -557,7 +565,9 @@ exports[`base configuration for ios 1`] = `
|
|||||||
noErrorOnMissing: true,
|
noErrorOnMissing: true,
|
||||||
globOptions: {
|
globOptions: {
|
||||||
dot: false,
|
dot: false,
|
||||||
ignore: []
|
ignore: [
|
||||||
|
'**/custom_app_resources/**'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -566,7 +576,9 @@ exports[`base configuration for ios 1`] = `
|
|||||||
noErrorOnMissing: true,
|
noErrorOnMissing: true,
|
||||||
globOptions: {
|
globOptions: {
|
||||||
dot: false,
|
dot: false,
|
||||||
ignore: []
|
ignore: [
|
||||||
|
'**/custom_app_resources/**'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -3,8 +3,8 @@ import fs from 'fs';
|
|||||||
|
|
||||||
import base from '../../src/configuration/base';
|
import base from '../../src/configuration/base';
|
||||||
import { init } from '../../src';
|
import { init } from '../../src';
|
||||||
import { applyFileReplacements } from "../../src/helpers/fileReplacements";
|
import { applyFileReplacements } from '../../src/helpers/fileReplacements';
|
||||||
import { additionalCopyRules } from "../../src/helpers/copyRules";
|
import { additionalCopyRules } from '../../src/helpers/copyRules';
|
||||||
|
|
||||||
describe('base configuration', () => {
|
describe('base configuration', () => {
|
||||||
const platforms = ['ios', 'android'];
|
const platforms = ['ios', 'android'];
|
||||||
@ -13,14 +13,18 @@ describe('base configuration', () => {
|
|||||||
it(`for ${platform}`, () => {
|
it(`for ${platform}`, () => {
|
||||||
init({
|
init({
|
||||||
[platform]: true,
|
[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();
|
expect(base(new Config()).toString()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('supports dotenv', () => {
|
it('supports dotenv', () => {
|
||||||
const fsSpy = jest.spyOn(fs, "existsSync")
|
const fsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
fsSpy.mockReturnValue(true)
|
fsSpy.mockReturnValue(true);
|
||||||
|
|
||||||
init({
|
init({
|
||||||
ios: true,
|
ios: true,
|
||||||
@ -33,12 +37,12 @@ describe('base configuration', () => {
|
|||||||
return args;
|
return args;
|
||||||
});
|
});
|
||||||
|
|
||||||
fsSpy.mockRestore()
|
fsSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports env specific dotenv', () => {
|
it('supports env specific dotenv', () => {
|
||||||
const fsSpy = jest.spyOn(fs, "existsSync")
|
const fsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
fsSpy.mockReturnValue(true)
|
fsSpy.mockReturnValue(true);
|
||||||
|
|
||||||
init({
|
init({
|
||||||
ios: true,
|
ios: true,
|
||||||
@ -46,22 +50,19 @@ describe('base configuration', () => {
|
|||||||
});
|
});
|
||||||
const config = base(new Config());
|
const config = base(new Config());
|
||||||
|
|
||||||
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env.prod')
|
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env.prod');
|
||||||
expect(fsSpy).toHaveBeenCalledTimes(1)
|
expect(fsSpy).toHaveBeenCalledTimes(1);
|
||||||
expect(config.plugin('DotEnvPlugin')).toBeDefined();
|
expect(config.plugin('DotEnvPlugin')).toBeDefined();
|
||||||
config.plugin('DotEnvPlugin').tap((args) => {
|
config.plugin('DotEnvPlugin').tap((args) => {
|
||||||
expect(args[0].path).toEqual('__jest__/.env.prod');
|
expect(args[0].path).toEqual('__jest__/.env.prod');
|
||||||
return args;
|
return args;
|
||||||
});
|
});
|
||||||
fsSpy.mockRestore()
|
fsSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('falls back to default .env', () => {
|
it('falls back to default .env', () => {
|
||||||
const fsSpy = jest.spyOn(fs, "existsSync")
|
const fsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
fsSpy
|
fsSpy.mockReturnValueOnce(false).mockReturnValueOnce(true);
|
||||||
.mockReturnValueOnce(false)
|
|
||||||
.mockReturnValueOnce(true)
|
|
||||||
|
|
||||||
|
|
||||||
init({
|
init({
|
||||||
ios: true,
|
ios: true,
|
||||||
@ -69,15 +70,15 @@ describe('base configuration', () => {
|
|||||||
});
|
});
|
||||||
const config = base(new Config());
|
const config = base(new Config());
|
||||||
|
|
||||||
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env.prod')
|
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env.prod');
|
||||||
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env')
|
expect(fsSpy).toHaveBeenCalledWith('__jest__/.env');
|
||||||
expect(fsSpy).toHaveBeenCalledTimes(2)
|
expect(fsSpy).toHaveBeenCalledTimes(2);
|
||||||
expect(config.plugin('DotEnvPlugin')).toBeDefined();
|
expect(config.plugin('DotEnvPlugin')).toBeDefined();
|
||||||
config.plugin('DotEnvPlugin').tap((args) => {
|
config.plugin('DotEnvPlugin').tap((args) => {
|
||||||
expect(args[0].path).toEqual('__jest__/.env');
|
expect(args[0].path).toEqual('__jest__/.env');
|
||||||
return args;
|
return args;
|
||||||
});
|
});
|
||||||
fsSpy.mockRestore()
|
fsSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies file replacements', () => {
|
it('applies file replacements', () => {
|
||||||
@ -88,16 +89,16 @@ describe('base configuration', () => {
|
|||||||
'bar.js': 'bar.replaced.js',
|
'bar.js': 'bar.replaced.js',
|
||||||
|
|
||||||
// should apply as a file replacement using the copy plugin
|
// 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('foo.ts')).toBe('foo.replaced.ts');
|
||||||
expect(config.resolve.alias.get('bar.js')).toBe('bar.replaced.js')
|
expect(config.resolve.alias.get('bar.js')).toBe('bar.replaced.js');
|
||||||
expect(additionalCopyRules.length).toBe(1)
|
expect(additionalCopyRules.length).toBe(1);
|
||||||
expect(additionalCopyRules[0]).toEqual({
|
expect(additionalCopyRules[0]).toEqual({
|
||||||
from: 'foo.replaced.json',
|
from: 'foo.replaced.json',
|
||||||
to: 'foo.json',
|
to: 'foo.json',
|
||||||
force: true,
|
force: true,
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
||||||
import { relative, resolve } from 'path';
|
import { basename, relative, resolve } from 'path';
|
||||||
import Config from 'webpack-chain';
|
import Config from 'webpack-chain';
|
||||||
|
|
||||||
import { getProjectRootPath } from './project';
|
import { getProjectRootPath } from './project';
|
||||||
@ -61,13 +61,10 @@ export function applyCopyRules(config: Config) {
|
|||||||
// todo: do we need to handle empty appResourcesPath?
|
// todo: do we need to handle empty appResourcesPath?
|
||||||
// (the CLI should always pass the path - maybe not required)
|
// (the CLI should always pass the path - maybe not required)
|
||||||
if (env.appResourcesPath) {
|
if (env.appResourcesPath) {
|
||||||
const appResourcesFullPath = resolve(
|
const appResourcesFolderName = basename(env.appResourcesPath);
|
||||||
getProjectRootPath(),
|
|
||||||
env.appResourcesPath
|
|
||||||
);
|
|
||||||
|
|
||||||
// ignore everything in App_Resources (regardless where they are located)
|
// 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, [
|
config.plugin('CopyWebpackPlugin').use(CopyWebpackPlugin, [
|
||||||
|
Reference in New Issue
Block a user