mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
test: add merge tests
This commit is contained in:
@@ -24,7 +24,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
||||
config.plugin('DefinePlugin').tap((args) => {
|
||||
args[0] = merge(args[0], {
|
||||
/** For various libraries in the React ecosystem. */
|
||||
__TEST__: 'false',
|
||||
__TEST__: false,
|
||||
/**
|
||||
* Primarily for React Fast Refresh plugin, but technically the allowHmrInProduction option could be used instead.
|
||||
* Worth including anyway, as there are plenty of Node libraries that use this flag.
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
import { existsSync } from 'fs';
|
||||
import { getPackageJson } from './project';
|
||||
import { resolve } from 'path';
|
||||
|
||||
// todo: get rid of these or reduce them to their simplest form
|
||||
// no need to do magical string replacements, loops etc...
|
||||
|
||||
/**
|
||||
* Function to ensure the app directory exists
|
||||
*
|
||||
* @param appDirectory
|
||||
*/
|
||||
function verifyEntryModuleDirectory(appDirectory: string) {
|
||||
if (!appDirectory) {
|
||||
throw new Error('Path to app directory is not specified. Unable to find entry module.');
|
||||
}
|
||||
|
||||
if (!existsSync(appDirectory)) {
|
||||
throw new Error(`The specified path to app directory ${appDirectory} does not exist. Unable to find entry module.`);
|
||||
}
|
||||
}
|
||||
|
||||
function getPackageJsonEntry() {
|
||||
const packageJsonSource = getPackageJson();
|
||||
const entry = packageJsonSource.main;
|
||||
|
||||
if (!entry) {
|
||||
throw new Error(`package.json must contain a 'main' attribute!`);
|
||||
}
|
||||
|
||||
return entry.replace(/\.js$/i, '');
|
||||
}
|
||||
|
||||
export function getEntryModule(appDirectory: string, platform: 'android' | 'ios') {
|
||||
verifyEntryModuleDirectory(appDirectory);
|
||||
|
||||
const entry = getPackageJsonEntry();
|
||||
|
||||
const tsEntryPath = resolve(appDirectory, `${entry}.ts`);
|
||||
const jsEntryPath = resolve(appDirectory, `${entry}.js`);
|
||||
let entryExists = existsSync(tsEntryPath) || existsSync(jsEntryPath);
|
||||
if (!entryExists && platform) {
|
||||
const platformTsEntryPath = resolve(appDirectory, `${entry}.${platform}.ts`);
|
||||
const platformJsEntryPath = resolve(appDirectory, `${entry}.${platform}.js`);
|
||||
entryExists = existsSync(platformTsEntryPath) || existsSync(platformJsEntryPath);
|
||||
}
|
||||
|
||||
if (!entryExists) {
|
||||
throw new Error(`The entry module ${entry} specified in ` + `${appDirectory}/package.json doesn't exist!`);
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
@@ -18,14 +18,14 @@ export default function loader(content, map) {
|
||||
|
||||
const hmrCode = this.hot
|
||||
? dedent`
|
||||
if(module.hot) {
|
||||
module.hot.accept()
|
||||
module.hot.dispose(() => {
|
||||
const { removeTaggedAdditionalCSS } = require("@nativescript/core/ui/styling/style-scope");
|
||||
removeTaggedAdditionalCSS(${tag})
|
||||
})
|
||||
}
|
||||
`
|
||||
if(module.hot) {
|
||||
module.hot.accept()
|
||||
module.hot.dispose(() => {
|
||||
const { removeTaggedAdditionalCSS } = require("@nativescript/core/ui/styling/style-scope");
|
||||
removeTaggedAdditionalCSS(${tag})
|
||||
})
|
||||
}
|
||||
`
|
||||
: ``;
|
||||
|
||||
if (hasLoader('apply-css-loader')) {
|
||||
|
||||
Reference in New Issue
Block a user