Skip to content

Commit

Permalink
chore(merge): merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed Sep 28, 2021
2 parents edc4626 + 4893bf5 commit 4606fc3
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 192 deletions.
15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@
"scripts": {
"dev": "npx cross-env TEST_ENV=true node scripts/dev.js",
"dev:docs": "pnpm run start --filter garfish-docs",
"build": "pnpm run build --parallel --filter @garfish/* --filter garfish",
"build:docs": "pnpm run build --filter garfish-docs",
"build:watch": "cross-env WATCH=true pnpm build",
"test:e2e": "zx scripts/e2e.js",
"test:e2e:open": "cross-env TEST_ENV_OPEN=true zx scripts/e2e.js",
"test": "node scripts/jestTest.js",
"test:cover": "node scripts/jestTest.js --coverage",
"test": "node scripts/unit.js",
"test:cover": "node scripts/unit.js --coverage",
"cy:open": "cypress open",
"cy:run": "cypress run",
"changeset": "npx changeset",
"build": "pnpm run build --parallel --filter @garfish/* --filter garfish",
"build:docs": "pnpm run build --filter garfish-docs",
"build:watch": "cross-env WATCH=true pnpm build",
"reset": "pnpm -r exec -- rm -rf node_modules && rm -rf node_modules",
"setup": "pnpm install",
"prepublishOnly": "pnpm test && pnpm build",
"postpublish": "node scripts/asyncBnpm.js",
"ls-lint": "ls-lint",
"lint": "eslint --ext .ts packages/*/*/src/**",
"reset-gittag": "git tag -l | xargs git tag -d && git fetch --prune",
"format": "prettier --write --parser typescript \"packages/**/*.ts?(x)\"",
"format:js": "prettier --write --parser typescript \"(packages|scripts)/**/*.js\"",
"format:md": "prettier --write \"**/*.md\"",
"bump": "node ./scripts/versionBump.js",
"release": "node ./scripts/release.js",
"release:canary": "node ./scripts/release.js --canary"
},
Expand Down Expand Up @@ -92,5 +89,5 @@
"workspace-tools": "^0.16.2",
"zx": "^4.2.0"
},
"version": "0.1.15"
"version": "0.1.16"
}
2 changes: 1 addition & 1 deletion packages/browser-snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@garfish/browser-snapshot",
"version": "0.1.15",
"version": "0.1.16",
"description": "browser-snapshot module.",
"keywords": [
"garfish",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-vm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@garfish/browser-vm",
"version": "0.1.15",
"version": "0.1.16",
"description": "vm-sandbox module.",
"keywords": [
"garfish",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@garfish/core",
"version": "0.1.15",
"version": "0.1.16",
"description": "core module.",
"keywords": [
"garfish",
Expand Down
84 changes: 40 additions & 44 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,28 @@ import {
error,
assert,
hasOwn,
isObject,
deepMerge,
getRenderNode,
isPlainObject,
} from '@garfish/utils';
import { AppInfo } from './module/app';
import { interfaces } from './interface';
import { appLifecycle } from './lifecycle';

const appConfigList: Array<keyof interfaces.AppInfo | 'activeWhen'> = [
'name',
'entry',
'activeWhen',
'basename',
'domGetter',
'props',
'sandbox',
'cache',
'nested',
'noCheckProvider',
'customLoader',
...appLifecycle().lifecycleKeys,
];

const invalidNestedAttrs = [
'sandbox',
Expand Down Expand Up @@ -48,32 +64,6 @@ export const filterNestedConfig = (
return config;
};

const appConfigList: Array<keyof interfaces.AppConfig | 'activeWhen'> = [
'name',
'entry',
'activeWhen',
'basename',
'domGetter',
'props',
'sandbox',
'cache',
'nested',
'noCheckProvider',
];

const appHooksList: Array<keyof interfaces.AppLifecycle> = [
'beforeEval',
'afterEval',
'beforeMount',
'afterMount',
'errorMountApp',
'beforeUnmount',
'afterUnmount',
'errorUnmountApp',
'errorExecCode',
'customLoader',
];

// `props` may be responsive data
export const deepMergeConfig = <T>(globalConfig, localConfig) => {
const globalProps = globalConfig.props;
Expand All @@ -93,13 +83,12 @@ export const deepMergeConfig = <T>(globalConfig, localConfig) => {
export const getAppConfig = <T>(globalConfig, localConfig) => {
// TODO: Automatically retrieve configuration in the type declaration
const mergeConfig = deepMergeConfig(globalConfig, localConfig);
const filterConfigList = [...appConfigList, ...appHooksList];
Object.keys(mergeConfig).forEach((mergeKey) => {
Object.keys(mergeConfig).forEach((key) => {
if (
filterConfigList.indexOf(mergeKey as any) === -1 ||
typeof mergeConfig[mergeKey] === 'undefined'
!appConfigList.includes(key as any) ||
typeof mergeConfig[key] === 'undefined'
) {
delete mergeConfig[mergeKey];
delete mergeConfig[key];
}
});
return mergeConfig as T;
Expand All @@ -113,28 +102,35 @@ export const generateAppOptions = (
let appInfo = garfish.appInfos[appName];
// Load the unregistered applications
// `Garfish.loadApp('appName', 'https://xx.html');`
if (!appInfo && typeof appOptionsOrUrl === 'string') {
appInfo = {
name: appName,
basename: '/',
entry: appOptionsOrUrl,
};
if (typeof appOptionsOrUrl === 'string') {
if (appInfo) {
appInfo = {
...appInfo,
entry: appOptionsOrUrl,
};
} else {
appInfo = {
name: appName,
basename: '/',
entry: appOptionsOrUrl,
};
}
}

// merge register appInfo config and loadApp config
if (appOptionsOrUrl && typeof appOptionsOrUrl === 'object') {
appInfo = getAppConfig(appInfo, appOptionsOrUrl);
// Merge register appInfo config and loadApp config
if (isObject(appOptionsOrUrl)) {
appInfo = getAppConfig(appInfo || {}, appOptionsOrUrl);
}

// merge globalConfig with localConfig
appInfo = getAppConfig(garfish.options, appInfo);
// Merge globalConfig with localConfig
appInfo = getAppConfig(garfish.options, appInfo || {});
appInfo.name = appName;

assert(
appInfo.entry,
`Can't load unexpected child app "${appName}", ` +
'Please provide the entry parameters or registered in advance of the app.',
);
appInfo.name = appName;
return appInfo;
};

Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/garfish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
generateAppOptions,
createDefaultOptions,
} from './config';
import { App, AppInfo } from './module/app';
import { App } from './module/app';
import { interfaces } from './interface';
import { globalLifecycle } from './lifecycle';
import { processAppResources } from './module/resource';
Expand Down Expand Up @@ -157,10 +157,6 @@ export class Garfish extends EventEmitter {
appInfo.entry,
`${appInfo.name} application entry is not url: ${appInfo.entry}`,
);
// Deep merge this.options
// if (!appInfo.nested) {
// appInfo = deepMergeConfig(this.options, appInfo);
// }
currentAdds[appInfo.name] = appInfo;
this.appInfos[appInfo.name] = appInfo;
} else if (__DEV__) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/module/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
transformUrl,
__MockBody__,
__MockHead__,
getRenderNode,
sourceListTags,
parseContentType,
createAppContainer,
setDocCurrentScript,
getRenderNode,
} from '@garfish/utils';
import { Garfish } from '../garfish';
import { interfaces } from '../interface';
Expand Down
2 changes: 1 addition & 1 deletion packages/garfish/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "garfish",
"version": "0.1.15",
"version": "0.1.16",
"description": "garfish module.",
"keywords": [
"garfish",
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@garfish/hooks",
"version": "0.1.15",
"version": "0.1.16",
"description": "hooks module.",
"keywords": [
"garfish",
Expand Down
2 changes: 1 addition & 1 deletion packages/loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@garfish/loader",
"version": "0.1.15",
"version": "0.1.16",
"description": "loader module.",
"keywords": [
"garfish",
Expand Down
2 changes: 1 addition & 1 deletion packages/remote-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@garfish/remote-module",
"version": "0.1.15",
"version": "0.1.16",
"description": "remote-module module.",
"keywords": [
"garfish",
Expand Down
2 changes: 1 addition & 1 deletion packages/router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@garfish/router",
"version": "0.1.15",
"version": "0.1.16",
"description": "router module.",
"keywords": [
"garfish",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@garfish/utils",
"version": "0.1.15",
"version": "0.1.16",
"description": "utils module.",
"keywords": [
"garfish",
Expand Down
30 changes: 0 additions & 30 deletions scripts/publish.js

This file was deleted.

1 change: 0 additions & 1 deletion scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async function test() {

async function bumpVersion() {
return await bumpPrompt({
// commit: 'chore(publish): release v',
files: ['package.json', 'packages/*/package.json'],
release: args.tag || '',
push: false,
Expand Down
2 changes: 1 addition & 1 deletion scripts/runExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function runAllExample() {
.then(() => {
if (!process.env.CI_TEST_ENV) {
step('\n run dev project...');
return $`npx cross-env TEST_ENV=true pnpm start --filter "@garfish-dev/*" --parallel`;
return $`npx cross-env TEST_ENV=true pnpm start --filter "@garfish-dev/*" --parallel`;
}
})
// build all demo
Expand Down
Loading

0 comments on commit 4606fc3

Please sign in to comment.