fix: fix test result

This commit is contained in:
春希 2020-09-13 23:19:11 +08:00
parent 584b4c25ee
commit 7f6fbe8939
10 changed files with 58 additions and 39 deletions

View File

@ -12,7 +12,8 @@
], ],
"scripts": { "scripts": {
"start": "ava --watch", "start": "ava --watch",
"build": "rimraf lib && build-scripts build --skip-demo", "build": "npm run build:tsc",
"build:bs": "rimraf lib && rimraf es && build-scripts build --skip-demo",
"build:tsc": "rimraf lib && tsc", "build:tsc": "rimraf lib && tsc",
"demo": "node ./demo/demo.js", "demo": "node ./demo/demo.js",
"test": "ava", "test": "ava",

View File

@ -208,7 +208,13 @@ class SchemaParser implements ISchemaParser {
const p = (con.deps || []) const p = (con.deps || [])
.map((dep) => (dep.dependencyType === DependencyType.External ? dep : null)) .map((dep) => (dep.dependencyType === DependencyType.External ? dep : null))
.filter((dep) => dep !== null); .filter((dep) => dep !== null);
npms.push(...((p as unknown) as INpmPackage[])); const npmInfos: INpmPackage[] = p
.filter((i) => Boolean(i))
.map((i) => ({
package: (i as IExternalDependency).package,
version: (i as IExternalDependency).version,
}));
npms.push(...npmInfos);
}); });
npms = uniqueArray<INpmPackage>(npms, (i) => i.package); npms = uniqueArray<INpmPackage>(npms, (i) => i.package);
@ -227,6 +233,7 @@ class SchemaParser implements ISchemaParser {
css: schema.css, css: schema.css,
constants: schema.constants, constants: schema.constants,
config: schema.config || {}, config: schema.config || {},
meta: schema.meta || {},
i18n: schema.i18n, i18n: schema.i18n,
containersDeps, containersDeps,
utilsDeps, utilsDeps,

View File

@ -28,22 +28,17 @@ function groupDepsByPack(deps: IDependency[]): Record<string, IDependency[]> {
}; };
// TODO: main 这个信息到底怎么用,是不是外部包不需要使用? // TODO: main 这个信息到底怎么用,是不是外部包不需要使用?
// deps.forEach(dep => { const depMainBlackList = ['lib', 'lib/index', 'es', 'es/index', 'main'];
// if (dep.dependencyType === DependencyType.Internal) {
// addDep(
// `${(dep as IInternalDependency).moduleName}${`/${dep.main}` || ''}`,
// dep,
// );
// } else {
// addDep(`${(dep as IExternalDependency).package}${`/${dep.main}` || ''}`, dep);
// }
// });
deps.forEach((dep) => { deps.forEach((dep) => {
if (dep.dependencyType === DependencyType.Internal) { if (dep.dependencyType === DependencyType.Internal) {
addDep(`${(dep as IInternalDependency).moduleName}`, dep); addDep(`${(dep as IInternalDependency).moduleName}${dep.main ? `/${dep.main}` : ''}`, dep);
} else { } else {
addDep(`${(dep as IExternalDependency).package}`, dep); let depMain = '';
// TODO: 部分类型的 main 暂时认为没用
if (dep.main && depMainBlackList.indexOf(dep.main) < 0) {
depMain = dep.main;
}
addDep(`${(dep as IExternalDependency).package}${depMain ? `/${depMain}` : ''}`, dep);
} }
}); });

View File

@ -304,7 +304,8 @@ function generateEventHandlerAttrForRax(
return [ return [
{ {
type: PIECE_TYPE.ATTR, type: PIECE_TYPE.ATTR,
value: `${attrName}={${valueExpr}}`, name: attrName,
value: valueExpr,
}, },
]; ];
} }
@ -316,7 +317,8 @@ function generateEventHandlerAttrForRax(
return [ return [
{ {
type: PIECE_TYPE.ATTR, type: PIECE_TYPE.ATTR,
value: `${attrName}={${valueExpr}}`, name: attrName,
value: valueExpr,
}, },
]; ];
} }
@ -336,11 +338,13 @@ function generateEventHandlerAttrForRax(
return [ return [
...referencedLocalVariables.map((localVar) => ({ ...referencedLocalVariables.map((localVar) => ({
type: PIECE_TYPE.ATTR, type: PIECE_TYPE.ATTR,
value: `data-${changeCase.snake(localVar)}={${localVar}}`, name: `data-${changeCase.snake(localVar)}`,
value: localVar,
})), })),
{ {
type: PIECE_TYPE.ATTR, type: PIECE_TYPE.ATTR,
value: `${attrName}={${wrappedAttrValueExpr}}`, name: attrName,
value: wrappedAttrValueExpr,
}, },
]; ];
} }

View File

@ -6,7 +6,6 @@ import {
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
IContainerInfo,
} from '../../../types'; } from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => { const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {

View File

@ -85,7 +85,7 @@ function getNpmDependencies(project: IProjectInfo): NpmInfo[] {
const npmDeps: NpmInfo[] = []; const npmDeps: NpmInfo[] = [];
const npmNameToPkgMap = new Map<string, NpmInfo>(); const npmNameToPkgMap = new Map<string, NpmInfo>();
const allDeps = [...(project.containersDeps || []), ...(project.utilsDeps || [])]; const allDeps = project.packages;
allDeps.forEach((dep) => { allDeps.forEach((dep) => {
if (!isNpmInfo(dep)) { if (!isNpmInfo(dep)) {

View File

@ -38,10 +38,7 @@ export interface IProjectInfo {
constants?: JSONObject; constants?: JSONObject;
i18n?: I18nMap; i18n?: I18nMap;
packages: INpmPackage[]; packages: INpmPackage[];
meta?: { meta?: { name?: string; title?: string } | Record<string, any>;
name?: string;
title?: string;
};
config?: Record<string, any>; config?: Record<string, any>;
} }

View File

@ -43,6 +43,14 @@ function mergeNodeGeneratorConfig(cfg1: NodeGeneratorConfig, cfg2: NodeGenerator
return resCfg; return resCfg;
} }
export function isPureString(v: string) {
return v[0] === "'" && v[v.length - 1] === "'";
}
export function getPureStringContent(v: string) {
return v.substring(1, v.length - 1);
}
function generateAttrValue( function generateAttrValue(
attrData: { attrName: string; attrValue: CompositeValue }, attrData: { attrName: string; attrValue: CompositeValue },
scope: IScope, scope: IScope,
@ -84,8 +92,9 @@ function generateAttr(
// FIXME: 在经过 generateCompositeType 处理过之后,其实已经无法通过传入值的类型判断传出值是否为纯字面值字符串了(可能包裹了加工函数之类的) // FIXME: 在经过 generateCompositeType 处理过之后,其实已经无法通过传入值的类型判断传出值是否为纯字面值字符串了(可能包裹了加工函数之类的)
// 因此这个处理最好的方式是对传出值做语法分析,判断以哪种模版产出 Attr 值 // 因此这个处理最好的方式是对传出值做语法分析,判断以哪种模版产出 Attr 值
let newValue: string; let newValue: string;
if (p.value && p.value[0] === "'" && p.value[p.value.length - 1] === "'") { if (p.value && isPureString(p.value)) {
newValue = `"${p.value.substring(1, p.value.length - 1)}"`; const content = getPureStringContent(p.value);
newValue = `"${content}"`;
} else { } else {
newValue = `{${p.value}}`; newValue = `{${p.value}}`;
} }
@ -139,8 +148,17 @@ function generateBasicNode(nodeItem: NodeSchema, scope: IScope, config?: NodeGen
function generateSimpleNode(nodeItem: NodeSchema, scope: IScope, config?: NodeGeneratorConfig): CodePiece[] { function generateSimpleNode(nodeItem: NodeSchema, scope: IScope, config?: NodeGeneratorConfig): CodePiece[] {
const basicParts = generateBasicNode(nodeItem, scope, config) || []; const basicParts = generateBasicNode(nodeItem, scope, config) || [];
const attrParts = generateAttrs(nodeItem, scope, config) || []; const attrParts = generateAttrs(nodeItem, scope, config) || [];
const childrenParts: CodePiece[] = [];
if (nodeItem.children && config?.self) {
const childrenStr = config.self(nodeItem.children, scope);
return [...basicParts, ...attrParts]; childrenParts.push({
type: PIECE_TYPE.CHILDREN,
value: childrenStr,
});
}
return [...basicParts, ...attrParts, ...childrenParts];
} }
function linkPieces(pieces: CodePiece[]): string { function linkPieces(pieces: CodePiece[]): string {
@ -194,15 +212,6 @@ function generateNodeSchema(nodeItem: NodeSchema, scope: IScope, config?: NodeGe
pieces.push(...generateSimpleNode(nodeItem, scope, config)); pieces.push(...generateSimpleNode(nodeItem, scope, config));
} }
if (nodeItem.children && config?.self) {
const childrenStr = config.self(nodeItem.children, scope);
pieces.push({
type: PIECE_TYPE.CHILDREN,
value: childrenStr,
});
}
return linkPieces(pieces); return linkPieces(pieces);
} }
@ -331,10 +340,16 @@ export function createNodeGenerator(cfg: NodeGeneratorConfig = {}): NodeGenerato
}); });
} }
return generateCompositeType(nodeItem, scope, { const valueStr = generateCompositeType(nodeItem, scope, {
handlers: cfg.handlers, handlers: cfg.handlers,
nodeGenerator: generateNode, nodeGenerator: generateNode,
}); });
if (isPureString(valueStr)) {
return getPureStringContent(valueStr);
}
return `{${valueStr}}`;
}; };
return generateNode; return generateNode;

View File

@ -99,6 +99,7 @@ export interface ProjectSchema {
css?: string; css?: string;
dataSource?: DataSource; dataSource?: DataSource;
config?: Record<string, any>; config?: Record<string, any>;
meta?: Record<string, any>;
} }
export function isNodeSchema(data: any): data is NodeSchema { export function isNodeSchema(data: any): data is NodeSchema {

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
tnpm i -g lerna @ali/tyarn tnpm i -g lerna @ali/tyarn tsc
rm -rf node_modules package-lock.json yarn.lock rm -rf node_modules package-lock.json yarn.lock
lerna clean -y lerna clean -y