lcd-router-webpack-plugin 9.0.0-alpha.9 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Generator.d.ts.map +1 -1
- package/lib/Generator.js.map +1 -1
- package/lib/ReducersGenerator.d.ts.map +1 -1
- package/lib/ReducersGenerator.js +4 -1
- package/lib/ReducersGenerator.js.map +1 -1
- package/lib/RoutersGenerator.d.ts.map +1 -1
- package/lib/RoutersGenerator.js.map +1 -1
- package/lib/SagasGenerator.d.ts.map +1 -1
- package/lib/SagasGenerator.js.map +1 -1
- package/lib/babel/plugins/enhance-reducer.d.ts.map +1 -1
- package/lib/babel/plugins/enhance-reducer.js +21 -11
- package/lib/babel/plugins/enhance-reducer.js.map +1 -1
- package/lib/babel/plugins/external-wrap.d.ts.map +1 -1
- package/lib/babel/plugins/external-wrap.js +18 -13
- package/lib/babel/plugins/external-wrap.js.map +1 -1
- package/lib/babel/plugins/replace-source.d.ts.map +1 -1
- package/lib/babel/plugins/replace-source.js +5 -4
- package/lib/babel/plugins/replace-source.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/resolver.d.ts.map +1 -1
- package/lib/utils/resolver.js.map +1 -1
- package/lib/utils/types.d.ts +14 -3
- package/lib/utils/types.d.ts.map +1 -1
- package/lib/utils/types.js.map +1 -1
- package/package.json +1 -1
package/lib/Generator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Generator.d.ts","sourceRoot":"","sources":["../src/Generator.ts"],"names":[],"mappings":"AACA,qBAAa,SAAS,CAAC,CAAC;IACtB,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;;IAKhC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAI1B,SAAS,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM;IAItC,SAAS,CAAC,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"Generator.d.ts","sourceRoot":"","sources":["../src/Generator.ts"],"names":[],"mappings":"AACA,qBAAa,SAAS,CAAC,CAAC;IACtB,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;;IAKhC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAI1B,SAAS,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM;IAItC,SAAS,CAAC,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAI/D;;;;;;OAMG;IACH,SAAS,CAAC,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM;CAUtG"}
|
package/lib/Generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Generator.js","names":["_core","require","Generator","cache","constructor","Map","set","name","value","identifierString","arg","replace","importDefaultDeclaration","source","types","importDeclaration","importDefaultSpecifier","identifier","stringLiteral","importNamedDeclaration","names","map","x","importSpecifier","exports"],"sources":["../Generator.ts"],"sourcesContent":["import { types } from '@babel/core';\nexport class Generator<T> {\n protected cache: Map<string, T>;\n constructor() {\n this.cache = new Map<string, T>();\n }\n\n set(name: string, value: T) {\n this.cache.set(name, value);\n }\n\n protected identifierString(arg: string) {\n return arg.replace(/(\\/|-)/g, '_');\n }\n\n protected importDefaultDeclaration(name: string, source: string) {\n return types.importDeclaration(
|
|
1
|
+
{"version":3,"file":"Generator.js","names":["_core","require","Generator","cache","constructor","Map","set","name","value","identifierString","arg","replace","importDefaultDeclaration","source","types","importDeclaration","importDefaultSpecifier","identifier","stringLiteral","importNamedDeclaration","names","map","x","importSpecifier","exports"],"sources":["../Generator.ts"],"sourcesContent":["import { types } from '@babel/core';\nexport class Generator<T> {\n protected cache: Map<string, T>;\n constructor() {\n this.cache = new Map<string, T>();\n }\n\n set(name: string, value: T) {\n this.cache.set(name, value);\n }\n\n protected identifierString(arg: string) {\n return arg.replace(/(\\/|-)/g, '_');\n }\n\n protected importDefaultDeclaration(name: string, source: string) {\n return types.importDeclaration([types.importDefaultSpecifier(types.identifier(this.identifierString(name)))], types.stringLiteral(source));\n }\n\n /**\n * 创建一条 import 语句, 例如:\n * importNamedDeclaration(['a', 'b'], 'xxx/c') 会生成 import {a, b} from 'xxx/c'\n *\n * 也支持 alias, 例如:\n * importNamedDeclaration([['a', 'aliasName'], 'b'], 'xxx/c') 会生成 import {a as aliasName, b} from 'xxx/c'\n */\n protected importNamedDeclaration(names: Array<string | [name: string, alias: string]>, source: string) {\n return types.importDeclaration(\n names.map((x) =>\n typeof x === 'string'\n ? types.importSpecifier(types.identifier(x), types.identifier(x))\n : types.importSpecifier(types.identifier(this.identifierString(x[1])), types.identifier(x[0])),\n ),\n types.stringLiteral(source),\n );\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACO,MAAMC,SAAS,CAAI;EACdC,KAAK;EACfC,WAAWA,CAAA,EAAG;IACZ,IAAI,CAACD,KAAK,GAAG,IAAIE,GAAG,EAAa;EACnC;EAEAC,GAAGA,CAACC,IAAY,EAAEC,KAAQ,EAAE;IAC1B,IAAI,CAACL,KAAK,CAACG,GAAG,CAACC,IAAI,EAAEC,KAAK,CAAC;EAC7B;EAEUC,gBAAgBA,CAACC,GAAW,EAAE;IACtC,OAAOA,GAAG,CAACC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;EACpC;EAEUC,wBAAwBA,CAACL,IAAY,EAAEM,MAAc,EAAE;IAC/D,OAAOC,WAAK,CAACC,iBAAiB,CAAC,CAACD,WAAK,CAACE,sBAAsB,CAACF,WAAK,CAACG,UAAU,CAAC,IAAI,CAACR,gBAAgB,CAACF,IAAI,CAAC,CAAC,CAAC,CAAC,EAAEO,WAAK,CAACI,aAAa,CAACL,MAAM,CAAC,CAAC;EAC5I;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACYM,sBAAsBA,CAACC,KAAoD,EAAEP,MAAc,EAAE;IACrG,OAAOC,WAAK,CAACC,iBAAiB,CAC5BK,KAAK,CAACC,GAAG,CAAEC,CAAC,IACV,OAAOA,CAAC,KAAK,QAAQ,GACjBR,WAAK,CAACS,eAAe,CAACT,WAAK,CAACG,UAAU,CAACK,CAAC,CAAC,EAAER,WAAK,CAACG,UAAU,CAACK,CAAC,CAAC,CAAC,GAC/DR,WAAK,CAACS,eAAe,CAACT,WAAK,CAACG,UAAU,CAAC,IAAI,CAACR,gBAAgB,CAACa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAER,WAAK,CAACG,UAAU,CAACK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACjG,EACDR,WAAK,CAACI,aAAa,CAACL,MAAM,CAAC,CAC5B;EACH;AACF;AAACW,OAAA,CAAAtB,SAAA,GAAAA,SAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReducersGenerator.d.ts","sourceRoot":"","sources":["../src/ReducersGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,0BAA0B;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AACD,qBAAa,iBAAkB,SAAQ,SAAS,CAAC,0BAA0B,CAAC;;IAM1E,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG;
|
|
1
|
+
{"version":3,"file":"ReducersGenerator.d.ts","sourceRoot":"","sources":["../src/ReducersGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,0BAA0B;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AACD,qBAAa,iBAAkB,SAAQ,SAAS,CAAC,0BAA0B,CAAC;;IAM1E,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG;IAY/E,eAAe,CAAC,OAAO,EAAE,MAAM;CA0ChC"}
|
package/lib/ReducersGenerator.js
CHANGED
|
@@ -28,6 +28,7 @@ class ReducersGenerator extends _Generator.Generator {
|
|
|
28
28
|
writeCodeToFile(absPath) {
|
|
29
29
|
const items = Array.from(this.cache.values());
|
|
30
30
|
const code = (0, _core.transformSync)('', {
|
|
31
|
+
babelrc: false,
|
|
31
32
|
plugins: [() => {
|
|
32
33
|
return {
|
|
33
34
|
name: 'babel-plugin-replace-react-redux',
|
|
@@ -35,7 +36,9 @@ class ReducersGenerator extends _Generator.Generator {
|
|
|
35
36
|
Program: {
|
|
36
37
|
enter: path => {
|
|
37
38
|
const codes = [this.importDefaultDeclaration('decorate', 'rrc-loader-helper/lib/reducer-decorate')];
|
|
38
|
-
items.filter(x => x.meJSON.sync || x.isExternal)
|
|
39
|
+
items.filter(x => x.meJSON.sync || x.isExternal)
|
|
40
|
+
// 创建一个 import 语句,从 me.json 中导入 reducer 函数
|
|
41
|
+
.map(x => this.importNamedDeclaration([['reducer', x.namespace]], x.meJSONPath)).forEach(x => codes.push(x));
|
|
39
42
|
const properties = items.map(x => {
|
|
40
43
|
if (x.isExternal || x.meJSON.sync) {
|
|
41
44
|
if (x.meJSON.mobx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReducersGenerator.js","names":["_fs","_interopRequireDefault","require","_core","_Generator","obj","__esModule","default","ReducersGenerator","Generator","constructor","objectPropertyValue","type","value","types","callExpression","identifier","identifierString","stringLiteral","writeCodeToFile","absPath","items","Array","from","cache","values","code","transformSync","plugins","name","visitor","Program","enter","path","codes","importDefaultDeclaration","filter","x","meJSON","sync","isExternal","map","importNamedDeclaration","namespace","meJSONPath","forEach","push","properties","mobx","objectProperty","exportDefaultDeclaration","objectExpression","pushContainer","fs","writeFileSync","encoding","exports"],"sources":["../ReducersGenerator.ts"],"sourcesContent":["import fs from 'fs';\nimport babelCore, { transformSync, types } from '@babel/core';\nimport type { MeJSON } from './utils';\nimport { Generator } from './Generator';\n\ninterface GetReducersBabelPluginItem {\n meJSON: MeJSON;\n namespace: string;\n isExternal: boolean;\n meJSONPath: string;\n}\nexport class ReducersGenerator extends Generator<GetReducersBabelPluginItem> {\n constructor() {\n super();\n }\n\n // TODO: 这里类型 加了个 any, 不太希望写else, 所以导致的问题,ts类型推导似乎不合理\n objectPropertyValue(type: 'call' | 'string' | 'identifier', value: string): any {\n if (type === 'call') {\n return types.callExpression(types.identifier('decorate'), [
|
|
1
|
+
{"version":3,"file":"ReducersGenerator.js","names":["_fs","_interopRequireDefault","require","_core","_Generator","obj","__esModule","default","ReducersGenerator","Generator","constructor","objectPropertyValue","type","value","types","callExpression","identifier","identifierString","stringLiteral","writeCodeToFile","absPath","items","Array","from","cache","values","code","transformSync","babelrc","plugins","name","visitor","Program","enter","path","codes","importDefaultDeclaration","filter","x","meJSON","sync","isExternal","map","importNamedDeclaration","namespace","meJSONPath","forEach","push","properties","mobx","objectProperty","exportDefaultDeclaration","objectExpression","pushContainer","fs","writeFileSync","encoding","exports"],"sources":["../ReducersGenerator.ts"],"sourcesContent":["import fs from 'fs';\nimport babelCore, { transformSync, types } from '@babel/core';\nimport type { MeJSON } from './utils';\nimport { Generator } from './Generator';\n\ninterface GetReducersBabelPluginItem {\n meJSON: MeJSON;\n namespace: string;\n isExternal: boolean;\n meJSONPath: string;\n}\nexport class ReducersGenerator extends Generator<GetReducersBabelPluginItem> {\n constructor() {\n super();\n }\n\n // TODO: 这里类型 加了个 any, 不太希望写else, 所以导致的问题,ts类型推导似乎不合理\n objectPropertyValue(type: 'call' | 'string' | 'identifier', value: string): any {\n if (type === 'call') {\n return types.callExpression(types.identifier('decorate'), [types.identifier(this.identifierString(value)), types.stringLiteral(value)]);\n }\n if (type === 'string') {\n return types.stringLiteral('');\n }\n if (type === 'identifier') {\n return types.identifier(this.identifierString(value));\n }\n }\n\n writeCodeToFile(absPath: string) {\n const items = Array.from(this.cache.values());\n const code = transformSync('', {\n babelrc: false,\n plugins: [\n () => {\n return {\n name: 'babel-plugin-replace-react-redux',\n visitor: {\n Program: {\n enter: (path) => {\n const codes: (babelCore.types.ImportDeclaration | babelCore.types.ExportDefaultDeclaration)[] = [\n this.importDefaultDeclaration('decorate', 'rrc-loader-helper/lib/reducer-decorate'),\n ];\n items\n .filter((x) => x.meJSON.sync || x.isExternal)\n // 创建一个 import 语句,从 me.json 中导入 reducer 函数\n .map((x) => this.importNamedDeclaration([['reducer', x.namespace]], x.meJSONPath))\n .forEach((x) => codes.push(x));\n\n const properties = items.map((x) => {\n if (x.isExternal || x.meJSON.sync) {\n if (x.meJSON.mobx) {\n return types.objectProperty(types.stringLiteral(x.namespace), this.objectPropertyValue('call', x.namespace));\n }\n return types.objectProperty(types.stringLiteral(x.namespace), this.objectPropertyValue('identifier', x.namespace));\n }\n return types.objectProperty(types.stringLiteral(x.namespace), this.objectPropertyValue('string', x.namespace));\n });\n\n codes.push(types.exportDefaultDeclaration(types.objectExpression(properties)));\n\n path.pushContainer('body', codes);\n },\n },\n },\n };\n },\n ],\n });\n fs.writeFileSync(absPath, code?.code!, { encoding: 'utf8' });\n }\n}\n"],"mappings":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,UAAU,CAAC,CAAC,CAAC;gBAE9Ed,IAAI,CAACmB,aAAa,CAAC,MAAM,EAAElB,KAAK,CAAC;cACnC;YACF;UACF;QACF,CAAC;MACH,CAAC;IAEL,CAAC,CAAC;IACFmB,WAAE,CAACC,aAAa,CAACnC,OAAO,EAAEM,IAAI,EAAEA,IAAI,EAAG;MAAE8B,QAAQ,EAAE;IAAO,CAAC,CAAC;EAC9D;AACF;AAACC,OAAA,CAAAjD,iBAAA,GAAAA,iBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RoutersGenerator.d.ts","sourceRoot":"","sources":["../src/RoutersGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,IAAI;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AAID,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,IAAI,CAAC;IACnD,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,WAAW,CAAC;gBAEb,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW;IAMrD,OAAO,CAAC,iCAAiC;
|
|
1
|
+
{"version":3,"file":"RoutersGenerator.d.ts","sourceRoot":"","sources":["../src/RoutersGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,IAAI;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AAID,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,IAAI,CAAC;IACnD,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,WAAW,CAAC;gBAEb,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW;IAMrD,OAAO,CAAC,iCAAiC;IAyCzC,OAAO,CAAC,0BAA0B;IAYlC,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,SAAS;IAuBjB,OAAO,CAAC,oBAAoB;IA2B5B,OAAO,CAAC,sBAAsB;IAyB9B,eAAe,CAAC,OAAO,EAAE,MAAM;CAqEhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RoutersGenerator.js","names":["_fs","_interopRequireDefault","require","_core","_Generator","obj","__esModule","default","RoutersGenerator","Generator","config","pathService","constructor","errorComponentVariableDeclaration","types","variableDeclaration","variableDeclarator","identifier","arrowFunctionExpression","blockStatement","returnStatement","jsxElement","jsxOpeningElement","jsxIdentifier","jsxClosingElement","jsxText","jsxExpressionContainer","optionalMemberExpression","memberExpression","loadingVariableDeclaration","jsxFragment","jsxOpeningFragment","jsxClosingFragment","createDowngradeValue","meJSON","name","defaultValue","transform","item","downgradeValue","route","keepAlive","retain","title","undefined","linkExtendable","injectStore","pageImportExpression","returnObjectProperties","objectProperty","sync","push","booleanLiteral","sourceAst","stringLiteral","meJSONPath","enablePreFetch","addComment","callExpression","import","objectExpression","loadableCallExpression","nullLiteral","page","JSON","stringify","writeCodeToFile","absPath","items","Array","from","cache","values","code","transformSync","plugins","visitor","Program","enter","path","ast","importNamedDeclaration","importDefaultDeclaration","loading","errorComponent","theme","hash","getThemeJSCacheFileAbs","expressionStatement","optionalCallExpression","_","filter","x","isExternal","map","dangerousRoute","exact","exportDefaultDeclaration","arrayExpression","pushContainer","fs","writeFileSync","keys","length","join","encoding","exports"],"sources":["../RoutersGenerator.ts"],"sourcesContent":["import fs from 'fs';\nimport { transformSync, types } from '@babel/core';\nimport type { Options, MeJSON, PathService } from './utils';\nimport { Generator } from './Generator';\n\ninterface Item {\n meJSONPath: string;\n meJSON: MeJSON;\n isExternal: boolean;\n path: string;\n page: string;\n exact: boolean;\n}\n\ninterface TransformItem extends Item, MeJSON {}\n\nexport class RoutersGenerator extends Generator<Item> {\n config: Options;\n pathService: PathService;\n\n constructor(config: Options, pathService: PathService) {\n super();\n this.config = config;\n this.pathService = pathService;\n }\n\n private errorComponentVariableDeclaration() {\n return types.variableDeclaration('const', [\n types.variableDeclarator(\n types.identifier('ErrorComponent'),\n types.arrowFunctionExpression(\n [types.identifier('props')],\n types.blockStatement([\n types.returnStatement(\n types.jsxElement(\n types.jsxOpeningElement(types.jsxIdentifier('div'), [], false),\n types.jsxClosingElement(types.jsxIdentifier('div')),\n [\n types.jsxElement(\n types.jsxOpeningElement(types.jsxIdentifier('h1'), [], false),\n types.jsxClosingElement(types.jsxIdentifier('h1')),\n [types.jsxText('页面渲染发生异常')],\n ),\n types.jsxElement(\n types.jsxOpeningElement(types.jsxIdentifier('span'), [], false),\n types.jsxClosingElement(types.jsxIdentifier('span')),\n [\n types.jsxExpressionContainer(\n types.optionalMemberExpression(\n types.memberExpression(\n types.identifier('props'),\n types.identifier('errorStack'),\n ),\n types.identifier('message'),\n false,\n true,\n ),\n ),\n ],\n ),\n ],\n false,\n ),\n ),\n ]),\n ),\n ),\n ]);\n }\n\n private loadingVariableDeclaration() {\n return types.variableDeclaration('const', [\n types.variableDeclarator(\n types.identifier('Loading'),\n types.arrowFunctionExpression(\n [],\n types.blockStatement([\n types.returnStatement(\n types.jsxFragment(types.jsxOpeningFragment(), types.jsxClosingFragment(), []),\n ),\n ]),\n ),\n ),\n ]);\n }\n\n private createDowngradeValue(meJSON: MeJSON) {\n return <T extends keyof MeJSON>(name: T, defaultValue: MeJSON[T]) => {\n /** @ts-ignore */\n return meJSON[name] ?? this.config[name] ?? defaultValue;\n };\n }\n\n private transform(item: Item): TransformItem {\n const downgradeValue = this.createDowngradeValue(item.meJSON);\n // 路由参数\n let route = item.meJSON.route ?? '';\n const keepAlive = downgradeValue('keepAlive', false);\n const retain = downgradeValue('retain', false);\n const title = downgradeValue('title', undefined);\n // FUCK keep-alive 特性的坑, 为了兼容同一个页面多次打开 动态拓展 redux 的reducer 节点\n const linkExtendable = downgradeValue('linkExtendable', false);\n route = linkExtendable ? `${route}/:id?` : route;\n let injectStore = downgradeValue('injectStore', false);\n if (injectStore === true) injectStore = 'store';\n return {\n ...item,\n route,\n keepAlive,\n retain,\n title,\n linkExtendable,\n injectStore,\n };\n }\n\n private pageImportExpression(item: TransformItem) {\n const returnObjectProperties = [\n types.objectProperty(types.identifier('module'), types.identifier('module')),\n ];\n if (item.meJSON.sync) {\n returnObjectProperties.push(\n types.objectProperty(types.identifier('sync'), types.booleanLiteral(true)),\n );\n } else {\n returnObjectProperties.push(\n types.objectProperty(types.identifier('sync'), types.booleanLiteral(false)),\n types.objectProperty(types.identifier('reducers'), types.identifier('reducers')),\n );\n }\n const sourceAst = types.stringLiteral(item.meJSONPath);\n\n if (this.config.enablePreFetch) {\n types.addComment(sourceAst, 'leading', 'webpackPrefetch: true');\n }\n\n return types.callExpression(\n types.memberExpression(\n types.callExpression(types.import(), [sourceAst]),\n types.identifier('then'),\n ),\n [\n types.arrowFunctionExpression(\n [types.identifier('module')],\n types.blockStatement([\n // TODO\n types.returnStatement(types.objectExpression(returnObjectProperties)),\n ]),\n ),\n ],\n );\n }\n\n private loadableCallExpression(item: TransformItem) {\n return types.callExpression(types.identifier('Loadable'), [\n types.objectExpression([\n types.objectProperty(\n types.identifier('title'),\n item.title ? types.stringLiteral(item.title) : types.nullLiteral(),\n ),\n types.objectProperty(types.identifier('keepAlive'), types.booleanLiteral(item.keepAlive!)),\n types.objectProperty(types.identifier('route'), types.stringLiteral(item.route!)),\n types.objectProperty(types.identifier('retain'), types.booleanLiteral(item.retain!)),\n types.objectProperty(\n types.identifier('injectStore'),\n typeof item.injectStore === 'boolean'\n ? types.booleanLiteral(item.injectStore)\n : types.stringLiteral(item.injectStore!),\n ),\n types.objectProperty(types.identifier('page'), types.stringLiteral(item.page)),\n types.objectProperty(types.identifier('loading'), types.identifier('Loading')),\n types.objectProperty(\n types.identifier('errorComponent'),\n types.identifier('ErrorComponent'),\n ),\n types.objectProperty(\n types.identifier('metaInfo'),\n types.callExpression(\n types.memberExpression(types.identifier('JSON'), types.identifier('parse')),\n [types.stringLiteral(JSON.stringify(item.meJSON))],\n ),\n ),\n types.objectProperty(\n types.identifier('loader'),\n types.arrowFunctionExpression([], this.pageImportExpression(item)),\n ),\n ]),\n ]);\n }\n\n writeCodeToFile(absPath: string) {\n const items = Array.from(this.cache.values());\n const code = transformSync('', {\n plugins: [\n () => {\n return {\n name: 'babel-plugin-replace-react-redux',\n visitor: {\n Program: {\n enter: (path) => {\n const ast: (\n | types.ImportDeclaration\n | types.VariableDeclaration\n | types.ExportDefaultDeclaration\n | types.ExpressionStatement\n )[] = [\n this.importNamedDeclaration([], 'rrc-loader-helper/lib/fake-react'),\n this.importDefaultDeclaration('Loadable', 'rrc-loader-helper/lib/loadable'),\n this.importDefaultDeclaration('React', 'react'),\n ];\n\n /** 如果用户没有指定loading组件,那么自动生成一个空 loading */\n if (this.config.loading) {\n ast.push(this.importDefaultDeclaration('Loading', this.config.loading));\n } else {\n ast.push(this.loadingVariableDeclaration());\n }\n\n if (this.config.errorComponent) {\n ast.push(\n this.importDefaultDeclaration('ErrorComponent', this.config.errorComponent),\n );\n } else {\n ast.push(this.errorComponentVariableDeclaration());\n }\n\n if (this.config.theme?.hash) {\n ast.push(\n this.importNamedDeclaration(\n ['toGlobalTheme'],\n this.pathService.getThemeJSCacheFileAbs(this.config.theme?.hash),\n ),\n );\n ast.push(\n types.expressionStatement(\n types.optionalCallExpression(types.identifier('toGlobalTheme'), [], true),\n ),\n );\n }\n\n const _ = items\n .filter((x) => !x.isExternal)\n .map((x) => this.transform(x))\n .map((x) => {\n const path =\n this.config.dangerousRoute || !x.exact\n ? `/${x.path}${x.route}`\n : `/${x.path}`;\n return types.objectExpression([\n types.objectProperty(\n types.identifier('exact'),\n types.booleanLiteral(x.exact),\n ),\n types.objectProperty(\n types.identifier('keepAlive'),\n types.booleanLiteral(x.keepAlive!),\n ),\n types.objectProperty(types.identifier('key'), types.stringLiteral(path)),\n types.objectProperty(types.identifier('path'), types.stringLiteral(path)),\n types.objectProperty(\n types.identifier('component'),\n this.loadableCallExpression(x),\n ),\n ]);\n });\n ast.push(\n types.exportDefaultDeclaration(\n types.arrowFunctionExpression(\n [types.identifier('reducers')],\n types.blockStatement([types.returnStatement(types.arrayExpression(_))]),\n ),\n ),\n );\n\n path.pushContainer('body', ast);\n },\n },\n },\n };\n },\n ],\n });\n\n fs.writeFileSync(\n absPath,\n [\n JSON.stringify(`👹 pages total count is ${Array.from(this.cache.keys()).length}`),\n code?.code!,\n ].join(';\\r\\n'),\n {\n encoding: 'utf8',\n },\n );\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAAwC,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAajC,MAAMG,gBAAgB,SAASC,oBAAS,CAAO;EACpDC,MAAM;EACNC,WAAW;EAEXC,WAAWA,CAACF,MAAe,EAAEC,WAAwB,EAAE;IACrD,KAAK,EAAE;IACP,IAAI,CAACD,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,WAAW,GAAGA,WAAW;EAChC;EAEQE,iCAAiCA,CAAA,EAAG;IAC1C,OAAOC,WAAK,CAACC,mBAAmB,CAAC,OAAO,EAAE,CACxCD,WAAK,CA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C,CAAC,EAC9BH,WAAK,CAACK,cAAc,CAAC,CAACL,WAAK,CAACM,eAAe,CAACN,WAAK,CAACoF,eAAe,CAACR,CAAC,CAAC,CAAC,CAAC,CAAC,CACxE,CACF,CACF;gBAEDX,IAAI,CAACoB,aAAa,CAAC,MAAM,EAAEnB,GAAG,CAAC;cACjC;YACF;UACF;QACF,CAAC;MACH,CAAC;IAEL,CAAC,CAAC;IAEFoB,WAAE,CAACC,aAAa,CACdlC,OAAO,EACP,CACEH,IAAI,CAACC,SAAS,CAAE,2BAA0BI,KAAK,CAACC,IAAI,CAAC,IAAI,CAACC,KAAK,CAAC+B,IAAI,EAAE,CAAC,CAACC,MAAO,EAAC,CAAC,EACjF9B,IAAI,EAAEA,IAAI,CACX,CAAC+B,IAAI,CAAC,OAAO,CAAC,EACf;MACEC,QAAQ,EAAE;IACZ,CAAC,CACF;EACH;AACF;AAACC,OAAA,CAAAlG,gBAAA,GAAAA,gBAAA"}
|
|
1
|
+
{"version":3,"file":"RoutersGenerator.js","names":["_fs","_interopRequireDefault","require","_core","_Generator","obj","__esModule","default","RoutersGenerator","Generator","config","pathService","constructor","errorComponentVariableDeclaration","types","variableDeclaration","variableDeclarator","identifier","arrowFunctionExpression","blockStatement","returnStatement","jsxElement","jsxOpeningElement","jsxIdentifier","jsxClosingElement","jsxText","jsxExpressionContainer","optionalMemberExpression","memberExpression","loadingVariableDeclaration","jsxFragment","jsxOpeningFragment","jsxClosingFragment","createDowngradeValue","meJSON","name","defaultValue","transform","item","downgradeValue","route","keepAlive","retain","title","undefined","linkExtendable","injectStore","pageImportExpression","returnObjectProperties","objectProperty","sync","push","booleanLiteral","sourceAst","stringLiteral","meJSONPath","enablePreFetch","addComment","callExpression","import","objectExpression","loadableCallExpression","nullLiteral","page","JSON","stringify","writeCodeToFile","absPath","items","Array","from","cache","values","code","transformSync","plugins","visitor","Program","enter","path","ast","importNamedDeclaration","importDefaultDeclaration","loading","errorComponent","theme","hash","getThemeJSCacheFileAbs","expressionStatement","optionalCallExpression","_","filter","x","isExternal","map","dangerousRoute","exact","exportDefaultDeclaration","arrayExpression","pushContainer","fs","writeFileSync","keys","length","join","encoding","exports"],"sources":["../RoutersGenerator.ts"],"sourcesContent":["import fs from 'fs';\nimport { transformSync, types } from '@babel/core';\nimport type { Options, MeJSON, PathService } from './utils';\nimport { Generator } from './Generator';\n\ninterface Item {\n meJSONPath: string;\n meJSON: MeJSON;\n isExternal: boolean;\n path: string;\n page: string;\n exact: boolean;\n}\n\ninterface TransformItem extends Item, MeJSON {}\n\nexport class RoutersGenerator extends Generator<Item> {\n config: Options;\n pathService: PathService;\n\n constructor(config: Options, pathService: PathService) {\n super();\n this.config = config;\n this.pathService = pathService;\n }\n\n private errorComponentVariableDeclaration() {\n return types.variableDeclaration('const', [\n types.variableDeclarator(\n types.identifier('ErrorComponent'),\n types.arrowFunctionExpression(\n [types.identifier('props')],\n types.blockStatement([\n types.returnStatement(\n types.jsxElement(\n types.jsxOpeningElement(types.jsxIdentifier('div'), [], false),\n types.jsxClosingElement(types.jsxIdentifier('div')),\n [\n types.jsxElement(\n types.jsxOpeningElement(types.jsxIdentifier('h1'), [], false),\n types.jsxClosingElement(types.jsxIdentifier('h1')),\n [types.jsxText('页面渲染发生异常')],\n ),\n types.jsxElement(\n types.jsxOpeningElement(types.jsxIdentifier('span'), [], false),\n types.jsxClosingElement(types.jsxIdentifier('span')),\n [\n types.jsxExpressionContainer(\n types.optionalMemberExpression(\n types.memberExpression(types.identifier('props'), types.identifier('errorStack')),\n types.identifier('message'),\n false,\n true,\n ),\n ),\n ],\n ),\n ],\n false,\n ),\n ),\n ]),\n ),\n ),\n ]);\n }\n\n private loadingVariableDeclaration() {\n return types.variableDeclaration('const', [\n types.variableDeclarator(\n types.identifier('Loading'),\n types.arrowFunctionExpression(\n [],\n types.blockStatement([types.returnStatement(types.jsxFragment(types.jsxOpeningFragment(), types.jsxClosingFragment(), []))]),\n ),\n ),\n ]);\n }\n\n private createDowngradeValue(meJSON: MeJSON) {\n return <T extends keyof MeJSON>(name: T, defaultValue: MeJSON[T]) => {\n /** @ts-ignore */\n return meJSON[name] ?? this.config[name] ?? defaultValue;\n };\n }\n\n private transform(item: Item): TransformItem {\n const downgradeValue = this.createDowngradeValue(item.meJSON);\n // 路由参数\n let route = item.meJSON.route ?? '';\n const keepAlive = downgradeValue('keepAlive', false);\n const retain = downgradeValue('retain', false);\n const title = downgradeValue('title', undefined);\n // FUCK keep-alive 特性的坑, 为了兼容同一个页面多次打开 动态拓展 redux 的reducer 节点\n const linkExtendable = downgradeValue('linkExtendable', false);\n route = linkExtendable ? `${route}/:id?` : route;\n let injectStore = downgradeValue('injectStore', false);\n if (injectStore === true) injectStore = 'store';\n return {\n ...item,\n route,\n keepAlive,\n retain,\n title,\n linkExtendable,\n injectStore,\n };\n }\n\n private pageImportExpression(item: TransformItem) {\n const returnObjectProperties = [types.objectProperty(types.identifier('module'), types.identifier('module'))];\n if (item.meJSON.sync) {\n returnObjectProperties.push(types.objectProperty(types.identifier('sync'), types.booleanLiteral(true)));\n } else {\n returnObjectProperties.push(\n types.objectProperty(types.identifier('sync'), types.booleanLiteral(false)),\n types.objectProperty(types.identifier('reducers'), types.identifier('reducers')),\n );\n }\n const sourceAst = types.stringLiteral(item.meJSONPath);\n\n if (this.config.enablePreFetch) {\n types.addComment(sourceAst, 'leading', 'webpackPrefetch: true');\n }\n\n return types.callExpression(types.memberExpression(types.callExpression(types.import(), [sourceAst]), types.identifier('then')), [\n types.arrowFunctionExpression(\n [types.identifier('module')],\n types.blockStatement([\n // TODO\n types.returnStatement(types.objectExpression(returnObjectProperties)),\n ]),\n ),\n ]);\n }\n\n private loadableCallExpression(item: TransformItem) {\n return types.callExpression(types.identifier('Loadable'), [\n types.objectExpression([\n types.objectProperty(types.identifier('title'), item.title ? types.stringLiteral(item.title) : types.nullLiteral()),\n types.objectProperty(types.identifier('keepAlive'), types.booleanLiteral(item.keepAlive!)),\n types.objectProperty(types.identifier('route'), types.stringLiteral(item.route!)),\n types.objectProperty(types.identifier('retain'), types.booleanLiteral(item.retain!)),\n types.objectProperty(\n types.identifier('injectStore'),\n typeof item.injectStore === 'boolean' ? types.booleanLiteral(item.injectStore) : types.stringLiteral(item.injectStore!),\n ),\n types.objectProperty(types.identifier('page'), types.stringLiteral(item.page)),\n types.objectProperty(types.identifier('loading'), types.identifier('Loading')),\n types.objectProperty(types.identifier('errorComponent'), types.identifier('ErrorComponent')),\n types.objectProperty(\n types.identifier('metaInfo'),\n types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('parse')), [\n types.stringLiteral(JSON.stringify(item.meJSON)),\n ]),\n ),\n types.objectProperty(types.identifier('loader'), types.arrowFunctionExpression([], this.pageImportExpression(item))),\n ]),\n ]);\n }\n\n writeCodeToFile(absPath: string) {\n const items = Array.from(this.cache.values());\n const code = transformSync('', {\n plugins: [\n () => {\n return {\n name: 'babel-plugin-replace-react-redux',\n visitor: {\n Program: {\n enter: (path) => {\n const ast: (types.ImportDeclaration | types.VariableDeclaration | types.ExportDefaultDeclaration | types.ExpressionStatement)[] = [\n this.importNamedDeclaration([], 'rrc-loader-helper/lib/fake-react'),\n this.importDefaultDeclaration('Loadable', 'rrc-loader-helper/lib/loadable'),\n this.importDefaultDeclaration('React', 'react'),\n ];\n\n /** 如果用户没有指定loading组件,那么自动生成一个空 loading */\n if (this.config.loading) {\n ast.push(this.importDefaultDeclaration('Loading', this.config.loading));\n } else {\n ast.push(this.loadingVariableDeclaration());\n }\n\n if (this.config.errorComponent) {\n ast.push(this.importDefaultDeclaration('ErrorComponent', this.config.errorComponent));\n } else {\n ast.push(this.errorComponentVariableDeclaration());\n }\n\n if (this.config.theme?.hash) {\n ast.push(this.importNamedDeclaration(['toGlobalTheme'], this.pathService.getThemeJSCacheFileAbs(this.config.theme?.hash)));\n ast.push(types.expressionStatement(types.optionalCallExpression(types.identifier('toGlobalTheme'), [], true)));\n }\n\n const _ = items\n .filter((x) => !x.isExternal)\n .map((x) => this.transform(x))\n .map((x) => {\n const path = this.config.dangerousRoute || !x.exact ? `/${x.path}${x.route}` : `/${x.path}`;\n return types.objectExpression([\n types.objectProperty(types.identifier('exact'), types.booleanLiteral(x.exact)),\n types.objectProperty(types.identifier('keepAlive'), types.booleanLiteral(x.keepAlive!)),\n types.objectProperty(types.identifier('key'), types.stringLiteral(path)),\n types.objectProperty(types.identifier('path'), types.stringLiteral(path)),\n types.objectProperty(types.identifier('component'), this.loadableCallExpression(x)),\n ]);\n });\n ast.push(\n types.exportDefaultDeclaration(\n types.arrowFunctionExpression(\n [types.identifier('reducers')],\n types.blockStatement([types.returnStatement(types.arrayExpression(_))]),\n ),\n ),\n );\n\n path.pushContainer('body', ast);\n },\n },\n },\n };\n },\n ],\n });\n\n fs.writeFileSync(absPath, [JSON.stringify(`👹 pages total count is ${Array.from(this.cache.keys()).length}`), code?.code!].join(';\\r\\n'), {\n encoding: 'utf8',\n });\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAAwC,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAajC,MAAMG,gBAAgB,SAASC,oBAAS,CAAO;EACpDC,MAAM;EACNC,WAAW;EAEXC,WAAWA,CAACF,MAAe,EAAEC,WAAwB,EAAE;IACrD,KAAK,EAAE;IACP,IAAI,CAACD,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,WAAW,GAAGA,WAAW;EAChC;EAEQE,iCAAiCA,CAAA,EAAG;IAC1C,OAAOC,WAAK,CAACC,mBAAmB,CAAC,OAAO,EAAE,CACxCD,WAAK,CAACE,kBAAkB,CACtBF,WAAK,CAACG,UAAU,CAAC,gBAAgB,CAAC,EAClCH,WAAK,CAACI,uBAAuB,CAC3B,CAACJ,WAAK,CAACG,UAA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C,CAAC,CAAC,CAAC,CACxE,CACF,CACF;gBAEDX,IAAI,CAACoB,aAAa,CAAC,MAAM,EAAEnB,GAAG,CAAC;cACjC;YACF;UACF;QACF,CAAC;MACH,CAAC;IAEL,CAAC,CAAC;IAEFoB,WAAE,CAACC,aAAa,CAAClC,OAAO,EAAE,CAACH,IAAI,CAACC,SAAS,CAAE,2BAA0BI,KAAK,CAACC,IAAI,CAAC,IAAI,CAACC,KAAK,CAAC+B,IAAI,EAAE,CAAC,CAACC,MAAO,EAAC,CAAC,EAAE9B,IAAI,EAAEA,IAAI,CAAE,CAAC+B,IAAI,CAAC,OAAO,CAAC,EAAE;MACxIC,QAAQ,EAAE;IACZ,CAAC,CAAC;EACJ;AACF;AAACC,OAAA,CAAAlG,gBAAA,GAAAA,gBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SagasGenerator.d.ts","sourceRoot":"","sources":["../src/SagasGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,UAAU,IAAI;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,qBAAa,cAAe,SAAQ,SAAS,CAAC,IAAI,CAAC;;IAKjD,OAAO,CAAC,yBAAyB;IAcjC,OAAO,CAAC,uBAAuB;
|
|
1
|
+
{"version":3,"file":"SagasGenerator.d.ts","sourceRoot":"","sources":["../src/SagasGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,UAAU,IAAI;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,qBAAa,cAAe,SAAQ,SAAS,CAAC,IAAI,CAAC;;IAKjD,OAAO,CAAC,yBAAyB;IAcjC,OAAO,CAAC,uBAAuB;IAU/B,eAAe,CAAC,OAAO,EAAE,MAAM;CA+ChC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SagasGenerator.js","names":["_Generator","require","_core","_fs","_interopRequireDefault","obj","__esModule","default","SagasGenerator","Generator","constructor","setCtxExpressionStatement","namespace","types","expressionStatement","yieldExpression","callExpression","identifier","objectExpression","objectProperty","booleanLiteral","stringLiteral","callExpressionStatement","memberExpression","identifierString","writeCodeToFile","absPath","items","Array","from","cache","values","code","transformSync","plugins","visitor","Program","enter","path","ast","importNamedDeclaration","filter","x","meJSON","sync","isExternal","forEach","push","mobx","meJSONPath","arrayItem","map","functionExpression","blockStatement","exportDefaultDeclaration","arrayExpression","pushContainer","fs","writeFileSync","encoding","exports"],"sources":["../SagasGenerator.ts"],"sourcesContent":["import { Generator } from './Generator';\nimport type { MeJSON } from './utils';\nimport { transformSync, types } from '@babel/core';\nimport fs from 'fs';\ninterface Item {\n namespace: string;\n meJSONPath: string;\n isExternal: boolean;\n meJSON: MeJSON;\n}\nexport class SagasGenerator extends Generator<Item> {\n constructor() {\n super();\n }\n\n private setCtxExpressionStatement(namespace: string) {\n return types.expressionStatement(\n types.yieldExpression(\n types.callExpression(types.identifier('setCtx'), [\n types.objectExpression([\n types.objectProperty(types.identifier('mobxStyle'), types.booleanLiteral(true)),\n types.objectProperty(types.identifier('page'), types.stringLiteral(namespace)),\n types.objectProperty(types.identifier('url'), types.stringLiteral('')),\n ]),\n ]),\n ),\n );\n }\n\n private callExpressionStatement(namespace: string) {\n return types.expressionStatement(\n types.yieldExpression(\n types.callExpression(types.identifier('call'), [\n types.memberExpression(
|
|
1
|
+
{"version":3,"file":"SagasGenerator.js","names":["_Generator","require","_core","_fs","_interopRequireDefault","obj","__esModule","default","SagasGenerator","Generator","constructor","setCtxExpressionStatement","namespace","types","expressionStatement","yieldExpression","callExpression","identifier","objectExpression","objectProperty","booleanLiteral","stringLiteral","callExpressionStatement","memberExpression","identifierString","writeCodeToFile","absPath","items","Array","from","cache","values","code","transformSync","plugins","visitor","Program","enter","path","ast","importNamedDeclaration","filter","x","meJSON","sync","isExternal","forEach","push","mobx","meJSONPath","arrayItem","map","functionExpression","blockStatement","exportDefaultDeclaration","arrayExpression","pushContainer","fs","writeFileSync","encoding","exports"],"sources":["../SagasGenerator.ts"],"sourcesContent":["import { Generator } from './Generator';\nimport type { MeJSON } from './utils';\nimport { transformSync, types } from '@babel/core';\nimport fs from 'fs';\ninterface Item {\n namespace: string;\n meJSONPath: string;\n isExternal: boolean;\n meJSON: MeJSON;\n}\nexport class SagasGenerator extends Generator<Item> {\n constructor() {\n super();\n }\n\n private setCtxExpressionStatement(namespace: string) {\n return types.expressionStatement(\n types.yieldExpression(\n types.callExpression(types.identifier('setCtx'), [\n types.objectExpression([\n types.objectProperty(types.identifier('mobxStyle'), types.booleanLiteral(true)),\n types.objectProperty(types.identifier('page'), types.stringLiteral(namespace)),\n types.objectProperty(types.identifier('url'), types.stringLiteral('')),\n ]),\n ]),\n ),\n );\n }\n\n private callExpressionStatement(namespace: string) {\n return types.expressionStatement(\n types.yieldExpression(\n types.callExpression(types.identifier('call'), [\n types.memberExpression(types.identifier(this.identifierString(namespace)), types.identifier('saga')),\n ]),\n ),\n );\n }\n\n writeCodeToFile(absPath: string) {\n const items = Array.from(this.cache.values());\n const code = transformSync('', {\n plugins: [\n () => {\n return {\n visitor: {\n Program: {\n enter: (path) => {\n const ast: (types.ImportDeclaration | types.ExportDefaultDeclaration)[] = [\n this.importNamedDeclaration(['setCtx'], 'rrc-loader-helper/lib/retain'),\n this.importNamedDeclaration(['call'], 'rrc-loader-helper/lib/sagas/redux-saga/effects'),\n ];\n\n items\n .filter((x) => x.meJSON.sync || x.isExternal)\n .forEach((x) =>\n // 如果是mobx, 取 reducer, 否则取 saga\n ast.push(this.importNamedDeclaration([[x.meJSON.mobx ? 'reducer' : 'saga', x.namespace]], x.meJSONPath)),\n );\n\n const arrayItem = items.map((x) => {\n if (!x.isExternal && !x.meJSON.sync) {\n return types.stringLiteral('');\n }\n if (x.meJSON.mobx) {\n return types.functionExpression(\n null,\n [],\n types.blockStatement([this.setCtxExpressionStatement(x.namespace), this.callExpressionStatement(x.namespace)]),\n true,\n false,\n );\n }\n return types.identifier(this.identifierString(x.namespace));\n });\n ast.push(types.exportDefaultDeclaration(types.arrayExpression(arrayItem)));\n path.pushContainer('body', ast);\n },\n },\n },\n };\n },\n ],\n });\n fs.writeFileSync(absPath, code?.code!, { encoding: 'utf8' });\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,GAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAoB,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAOb,MAAMG,cAAc,SAASC,oBAAS,CAAO;EAClDC,WAAWA,CAAA,EAAG;IACZ,KAAK,EAAE;EACT;EAEQC,yBAAyBA,CAACC,SAAiB,EAAE;IACnD,OAAOC,WAAK,CAACC,mBAAmB,CAC9BD,WAAK,CAACE,eAAe,CACnBF,WAAK,CAACG,cAAc,CAACH,WAAK,CAACI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAC/CJ,WAAK,CAACK,gBAAgB,CAAC,CACrBL,WAAK,CAACM,cAAc,CAACN,WAAK,CAACI,UAAU,CAAC,WAAW,CAAC,EAAEJ,WAAK,CAACO,cAAc,CAAC,IAAI,CAAC,CAAC,EAC/EP,WAAK,CAACM,cAAc,CAACN,WAAK,CAACI,UAAU,CAAC,MAAM,CAAC,EAAEJ,WAAK,CAACQ,aAAa,CAACT,SAA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sources":["../../../src/babel/plugins/enhance-reducer.ts"],"names":[],"mappings":";AAWA,
|
|
1
|
+
{"version":3,"file":"enhance-reducer.d.ts","sourceRoot":"","sources":["../../../src/babel/plugins/enhance-reducer.ts"],"names":[],"mappings":";AAWA,wBA8DG"}
|
|
@@ -19,30 +19,38 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
|
|
19
19
|
name: 'babel-plugin-enhance-reducer',
|
|
20
20
|
visitor: {
|
|
21
21
|
ExportDefaultDeclaration: (babelPath, ops) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
22
|
+
// 这里校验一下文件名, 仅处理 reducer 文件
|
|
23
|
+
if (!new RegExp(`${options.pageRootAbs}\/.*${options.reducerName}\.(j|t)s`).test(ops.filename)) return;
|
|
25
24
|
const filename = _nodePath.default.basename(ops.filename);
|
|
25
|
+
// 获取包含 me.json 的目录,用于获取当前页面的 namespace
|
|
26
26
|
function getMeJson(dir) {
|
|
27
27
|
if (_fsExtra.default.existsSync(_nodePath.default.join(dir, 'me.json'))) {
|
|
28
28
|
return dir;
|
|
29
29
|
}
|
|
30
|
+
// 向上递归到 pageRootAbs 后终止,返回false
|
|
31
|
+
if (dir === options.pageRootAbs) return false;
|
|
30
32
|
return getMeJson(_nodePath.default.dirname(dir));
|
|
31
33
|
}
|
|
34
|
+
|
|
35
|
+
// 当前页面不包含 me.json,不处理
|
|
32
36
|
const baseDir = getMeJson(_nodePath.default.dirname(ops.filename));
|
|
33
|
-
if (!baseDir)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const meJSON =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
if (!baseDir) return;
|
|
38
|
+
|
|
39
|
+
// 读取 me.json
|
|
40
|
+
const meJSON = _fsExtra.default.readJSONSync(_nodePath.default.join(baseDir, 'me.json'), 'utf8');
|
|
41
|
+
|
|
42
|
+
// 仅处理 mobx 模式。
|
|
43
|
+
if (!meJSON.mobx) return;
|
|
44
|
+
|
|
45
|
+
// 当前页面的 相对路径作为唯一key,这里是 lcd 内部的一个约定,与生成路由插件 传递的 page 参数一致
|
|
40
46
|
let namespace = baseDir.replace(`${options.pageRootAbs}/`, '');
|
|
41
47
|
const isChild = !isMainRegex.test(filename);
|
|
42
48
|
if (isChild) {
|
|
43
|
-
namespace += `&&${filename.replace(new RegExp(`(.*)\.
|
|
49
|
+
namespace += `&&${filename.replace(new RegExp(`(.*)\.${options.reducerName}\.(j|t)s`), '$1')}`;
|
|
44
50
|
}
|
|
45
51
|
const declaration = babelPath.get('declaration');
|
|
52
|
+
// 这里判断 declaration.isIdentifier() 是为了兼容 export default state 这种情况
|
|
53
|
+
// 但是实际上,无法判断 state 这个变量 是否为 对象,所以这里并不是非常严格的判断
|
|
46
54
|
if (declaration.isObjectExpression() || declaration.isIdentifier()) {
|
|
47
55
|
const program = babelPath.findParent(x => x.isProgram());
|
|
48
56
|
if (program.isProgram()) {
|
|
@@ -51,7 +59,9 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
|
|
51
59
|
program.unshiftContainer('body', importMobxAdapter);
|
|
52
60
|
const expression = types.callExpression(uid, [declaration.node, types.stringLiteral(namespace)]);
|
|
53
61
|
declaration.replaceWith(expression);
|
|
62
|
+
/* c8 ignore next 3 */
|
|
54
63
|
} else {
|
|
64
|
+
/* c8 ignore next 3 */
|
|
55
65
|
throw babelPath.buildCodeFrameError('语法解析错误,没有成功的探寻到 Program');
|
|
56
66
|
}
|
|
57
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enhance-reducer.js","names":["_helperPluginUtils","require","_nodePath","_interopRequireDefault","_fsExtra","obj","__esModule","default","_default","declare","api","options","assertVersion","types","isMainRegex","RegExp","reducerName","name","visitor","ExportDefaultDeclaration","babelPath","ops","pageRootAbs","test","filename","path","basename","getMeJson","dir","fse","existsSync","join","dirname","baseDir","meJSON","
|
|
1
|
+
{"version":3,"file":"enhance-reducer.js","names":["_helperPluginUtils","require","_nodePath","_interopRequireDefault","_fsExtra","obj","__esModule","default","_default","declare","api","options","assertVersion","types","isMainRegex","RegExp","reducerName","name","visitor","ExportDefaultDeclaration","babelPath","ops","pageRootAbs","test","filename","path","basename","getMeJson","dir","fse","existsSync","join","dirname","baseDir","meJSON","readJSONSync","mobx","namespace","replace","isChild","declaration","get","isObjectExpression","isIdentifier","program","findParent","x","isProgram","uid","scope","generateUidIdentifier","importMobxAdapter","importDeclaration","importDefaultSpecifier","stringLiteral","unshiftContainer","expression","callExpression","node","replaceWith","buildCodeFrameError","exports"],"sources":["../../../enhance-reducer.ts"],"sourcesContent":["import type * as __babel__core from '@babel/core';\nimport { declare } from '@babel/helper-plugin-utils';\nimport path from 'node:path';\nimport fse from 'fs-extra';\nimport type { MeJSON } from '../../utils/types';\n\ninterface Options {\n pageRootAbs: string;\n reducerName: string;\n}\n\nexport default declare<Options>((api, options) => {\n const { assertVersion, types } = api;\n assertVersion(7);\n const isMainRegex = new RegExp(`^${options.reducerName}.(j|t)s$`);\n return {\n name: 'babel-plugin-enhance-reducer',\n visitor: {\n ExportDefaultDeclaration: (babelPath, ops) => {\n // 这里校验一下文件名, 仅处理 reducer 文件\n if (!new RegExp(`${options.pageRootAbs}\\/.*${options.reducerName}\\.(j|t)s`).test(ops.filename)) return;\n\n const filename = path.basename(ops.filename);\n // 获取包含 me.json 的目录,用于获取当前页面的 namespace\n function getMeJson(dir: string) {\n if (fse.existsSync(path.join(dir, 'me.json'))) {\n return dir;\n }\n // 向上递归到 pageRootAbs 后终止,返回false\n if (dir === options.pageRootAbs) return false;\n return getMeJson(path.dirname(dir));\n }\n\n // 当前页面不包含 me.json,不处理\n const baseDir = getMeJson(path.dirname(ops.filename));\n if (!baseDir) return;\n\n // 读取 me.json\n const meJSON: MeJSON = fse.readJSONSync(path.join(baseDir, 'me.json'), 'utf8');\n\n // 仅处理 mobx 模式。\n if (!meJSON.mobx) return;\n\n // 当前页面的 相对路径作为唯一key,这里是 lcd 内部的一个约定,与生成路由插件 传递的 page 参数一致\n let namespace = baseDir.replace(`${options.pageRootAbs}/`, '');\n const isChild = !isMainRegex.test(filename);\n\n if (isChild) {\n namespace += `&&${filename.replace(new RegExp(`(.*)\\.${options.reducerName}\\.(j|t)s`), '$1')}`;\n }\n const declaration = babelPath.get('declaration');\n // 这里判断 declaration.isIdentifier() 是为了兼容 export default state 这种情况\n // 但是实际上,无法判断 state 这个变量 是否为 对象,所以这里并不是非常严格的判断\n if (declaration.isObjectExpression() || declaration.isIdentifier()) {\n const program = babelPath.findParent((x) => x.isProgram());\n if (program.isProgram()) {\n const uid = program.scope.generateUidIdentifier('storeHoc');\n const importMobxAdapter = types.importDeclaration(\n [types.importDefaultSpecifier(uid)],\n isChild ? types.stringLiteral('rrc-loader-helper/lib/store') : types.stringLiteral('rrc-loader-helper/lib/mobx-adapter'),\n );\n program.unshiftContainer('body', importMobxAdapter);\n const expression = types.callExpression(uid, [declaration.node, types.stringLiteral(namespace)]);\n declaration.replaceWith(expression);\n /* c8 ignore next 3 */\n } else {\n /* c8 ignore next 3 */\n throw babelPath.buildCodeFrameError('语法解析错误,没有成功的探寻到 Program');\n }\n }\n },\n },\n };\n});\n"],"mappings":";;;;;;AACA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAD,sBAAA,CAAAF,OAAA;AAA2B,SAAAE,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,IAAAG,QAAA,GAQZ,IAAAC,0BAAO,EAAU,CAACC,GAAG,EAAEC,OAAO,KAAK;EAChD,MAAM;IAAEC,aAAa;IAAEC;EAAM,CAAC,GAAGH,GAAG;EACpCE,aAAa,CAAC,CAAC,CAAC;EAChB,MAAME,WAAW,GAAG,IAAIC,MAAM,CAAE,IAAGJ,OAAO,CAACK,WAAY,UAAS,CAAC;EACj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AM,CAAE,SAAQJ,OAAO,CAACK,WAAY,UAAS,CAAC,EAAE,IAAI,CAAE,EAAC;QAChG;QACA,MAAMwB,WAAW,GAAGpB,SAAS,CAACqB,GAAG,CAAC,aAAa,CAAC;QAChD;QACA;QACA,IAAID,WAAW,CAACE,kBAAkB,EAAE,IAAIF,WAAW,CAACG,YAAY,EAAE,EAAE;UAClE,MAAMC,OAAO,GAAGxB,SAAS,CAACyB,UAAU,CAAEC,CAAC,IAAKA,CAAC,CAACC,SAAS,EAAE,CAAC;UAC1D,IAAIH,OAAO,CAACG,SAAS,EAAE,EAAE;YACvB,MAAMC,GAAG,GAAGJ,OAAO,CAACK,KAAK,CAACC,qBAAqB,CAAC,UAAU,CAAC;YAC3D,MAAMC,iBAAiB,GAAGtC,KAAK,CAACuC,iBAAiB,CAC/C,CAACvC,KAAK,CAACwC,sBAAsB,CAACL,GAAG,CAAC,CAAC,EACnCT,OAAO,GAAG1B,KAAK,CAACyC,aAAa,CAAC,6BAA6B,CAAC,GAAGzC,KAAK,CAACyC,aAAa,CAAC,oCAAoC,CAAC,CACzH;YACDV,OAAO,CAACW,gBAAgB,CAAC,MAAM,EAAEJ,iBAAiB,CAAC;YACnD,MAAMK,UAAU,GAAG3C,KAAK,CAAC4C,cAAc,CAACT,GAAG,EAAE,CAACR,WAAW,CAACkB,IAAI,EAAE7C,KAAK,CAACyC,aAAa,CAACjB,SAAS,CAAC,CAAC,CAAC;YAChGG,WAAW,CAACmB,WAAW,CAACH,UAAU,CAAC;YACnC;UACF,CAAC,MAAM;YACL;YACA,MAAMpC,SAAS,CAACwC,mBAAmB,CAAC,yBAAyB,CAAC;UAChE;QACF;MACF;IACF;EACF,CAAC;AACH,CAAC,CAAC;AAAAC,OAAA,CAAAtD,OAAA,GAAAC,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-wrap.d.ts","sourceRoot":"","sources":["../../../src/babel/plugins/external-wrap.ts"],"names":[],"mappings":";AASA,
|
|
1
|
+
{"version":3,"file":"external-wrap.d.ts","sourceRoot":"","sources":["../../../src/babel/plugins/external-wrap.ts"],"names":[],"mappings":";AASA,wBAiDG"}
|
|
@@ -16,22 +16,27 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
|
|
16
16
|
return {
|
|
17
17
|
name: 'babel-plugin-external-wrap',
|
|
18
18
|
visitor: {
|
|
19
|
-
Program: {
|
|
20
|
-
enter: (nodePath, ops) => {
|
|
21
|
-
const externalsAbs = options.externals?.map?.(x => _path.default.join(options.pageRootAbs, x, 'view')) ?? [];
|
|
22
|
-
const isExternalView = externalsAbs.some(x => ops.filename.startsWith(x));
|
|
23
|
-
if (isExternalView) {
|
|
24
|
-
nodePath.scope.setData('isExternalView', true);
|
|
25
|
-
nodePath.pushContainer('body', [types.importDeclaration([types.importDefaultSpecifier(types.identifier('PvWrapExternalPage'))], types.stringLiteral('rrc-loader-helper/lib/page/external-page'))]);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
19
|
ExportDefaultDeclaration: (nodePath, ops) => {
|
|
30
|
-
|
|
20
|
+
const externalsAbs = options.externals?.map?.(x => _path.default.join(options.pageRootAbs, x, 'view.')) ?? [];
|
|
21
|
+
const isExternalView = externalsAbs.some(x => ops.filename.startsWith(x));
|
|
22
|
+
if (isExternalView) {
|
|
31
23
|
const pageName = _path.default.dirname(_path.default.relative(options.pageRootAbs, ops.filename));
|
|
32
24
|
const declarationPath = nodePath.get('declaration');
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
|
|
26
|
+
// TODO: 后期可以考虑加上 ClassDeclaration 的兼容。
|
|
27
|
+
// 希望尽量少的兼容,因为这种情况少见,而且推荐使用函数组件
|
|
28
|
+
if (types.isCallExpression(declarationPath.node) || types.isIdentifier(declarationPath.node) || types.isFunctionDeclaration(declarationPath.node) || types.isArrowFunctionExpression(declarationPath.node)) {
|
|
29
|
+
const program = nodePath.findParent(x => x.isProgram());
|
|
30
|
+
program.unshiftContainer('body', [types.importDeclaration([types.importDefaultSpecifier(types.identifier('PvWrapExternalPage'))], types.stringLiteral('rrc-loader-helper/lib/page/external-page'))]);
|
|
31
|
+
let targetNode = declarationPath.node;
|
|
32
|
+
// https://www.babeljs.cn/docs/babel-types#callexpression
|
|
33
|
+
// 处理函数声明,types.callExpression arguments 不支持函数类型, 需要转成函数表达式
|
|
34
|
+
if (types.isFunctionDeclaration(declarationPath.node)) {
|
|
35
|
+
const uniqueId = nodePath.scope.generateUidIdentifier();
|
|
36
|
+
const functionExpression = types.functionExpression(uniqueId, nodePath.node.declaration.params, nodePath.node.declaration.body, nodePath.node.declaration.generator, nodePath.node.declaration.async);
|
|
37
|
+
targetNode = functionExpression;
|
|
38
|
+
}
|
|
39
|
+
const call = types.callExpression(types.identifier('PvWrapExternalPage'), [targetNode, types.stringLiteral(pageName)]);
|
|
35
40
|
nodePath.get('declaration').replaceWith(call);
|
|
36
41
|
}
|
|
37
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-wrap.js","names":["_helperPluginUtils","require","_path","_interopRequireDefault","obj","__esModule","default","_default","declare","api","options","assertVersion","types","name","visitor","
|
|
1
|
+
{"version":3,"file":"external-wrap.js","names":["_helperPluginUtils","require","_path","_interopRequireDefault","obj","__esModule","default","_default","declare","api","options","assertVersion","types","name","visitor","ExportDefaultDeclaration","nodePath","ops","externalsAbs","externals","map","x","path","join","pageRootAbs","isExternalView","some","filename","startsWith","pageName","dirname","relative","declarationPath","get","isCallExpression","node","isIdentifier","isFunctionDeclaration","isArrowFunctionExpression","program","findParent","isProgram","unshiftContainer","importDeclaration","importDefaultSpecifier","identifier","stringLiteral","targetNode","uniqueId","scope","generateUidIdentifier","functionExpression","declaration","params","body","generator","async","call","callExpression","replaceWith","exports"],"sources":["../../../external-wrap.ts"],"sourcesContent":["import type * as __babel__core from '@babel/core';\nimport { declare } from '@babel/helper-plugin-utils';\nimport path from 'path';\n\ninterface Options {\n externals: string[];\n pageRootAbs: string;\n}\n\nexport default declare<Options>((api, options) => {\n const { assertVersion, types } = api;\n assertVersion(7);\n return {\n name: 'babel-plugin-external-wrap',\n visitor: {\n ExportDefaultDeclaration: (nodePath, ops) => {\n const externalsAbs = options.externals?.map?.((x) => path.join(options.pageRootAbs, x, 'view.')) ?? [];\n const isExternalView = externalsAbs.some((x) => ops.filename.startsWith(x));\n if (isExternalView) {\n const pageName = path.dirname(path.relative(options.pageRootAbs, ops.filename));\n const declarationPath = nodePath.get('declaration');\n\n // TODO: 后期可以考虑加上 ClassDeclaration 的兼容。\n // 希望尽量少的兼容,因为这种情况少见,而且推荐使用函数组件\n if (\n types.isCallExpression(declarationPath.node) ||\n types.isIdentifier(declarationPath.node) ||\n types.isFunctionDeclaration(declarationPath.node) ||\n types.isArrowFunctionExpression(declarationPath.node)\n ) {\n const program = nodePath.findParent((x) => x.isProgram());\n program.unshiftContainer('body', [\n types.importDeclaration(\n [types.importDefaultSpecifier(types.identifier('PvWrapExternalPage'))],\n types.stringLiteral('rrc-loader-helper/lib/page/external-page'),\n ),\n ]);\n let targetNode = declarationPath.node;\n // https://www.babeljs.cn/docs/babel-types#callexpression\n // 处理函数声明,types.callExpression arguments 不支持函数类型, 需要转成函数表达式\n if (types.isFunctionDeclaration(declarationPath.node)) {\n const uniqueId = nodePath.scope.generateUidIdentifier();\n const functionExpression = types.functionExpression(\n uniqueId,\n nodePath.node.declaration.params,\n nodePath.node.declaration.body,\n nodePath.node.declaration.generator,\n nodePath.node.declaration.async,\n );\n targetNode = functionExpression;\n }\n const call = types.callExpression(types.identifier('PvWrapExternalPage'), [targetNode, types.stringLiteral(pageName)]);\n nodePath.get('declaration').replaceWith(call);\n }\n }\n },\n },\n };\n});\n"],"mappings":";;;;;;AACA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAwB,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAA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MAAM,EAAE,CAC/B9B,KAAK,CAAC+B,iBAAiB,CACrB,CAAC/B,KAAK,CAACgC,sBAAsB,CAAChC,KAAK,CAACiC,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,EACtEjC,KAAK,CAACkC,aAAa,CAAC,0CAA0C,CAAC,CAChE,CACF,CAAC;YACF,IAAIC,UAAU,GAAGf,eAAe,CAACG,IAAI;YACrC;YACA;YACA,IAAIvB,KAAK,CAACyB,qBAAqB,CAACL,eAAe,CAACG,IAAI,CAAC,EAAE;cACrD,MAAMa,QAAQ,GAAGhC,QAAQ,CAACiC,KAAK,CAACC,qBAAqB,EAAE;cACvD,MAAMC,kBAAkB,GAAGvC,KAAK,CAACuC,kBAAkB,CACjDH,QAAQ,EACRhC,QAAQ,CAACmB,IAAI,CAACiB,WAAW,CAACC,MAAM,EAChCrC,QAAQ,CAACmB,IAAI,CAACiB,WAAW,CAACE,IAAI,EAC9BtC,QAAQ,CAACmB,IAAI,CAACiB,WAAW,CAACG,SAAS,EACnCvC,QAAQ,CAACmB,IAAI,CAACiB,WAAW,CAACI,KAAK,CAChC;cACDT,UAAU,GAAGI,kBAAkB;YACjC;YACA,MAAMM,IAAI,GAAG7C,KAAK,CAAC8C,cAAc,CAAC9C,KAAK,CAACiC,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAACE,UAAU,EAAEnC,KAAK,CAACkC,aAAa,CAACjB,QAAQ,CAAC,CAAC,CAAC;YACtHb,QAAQ,CAACiB,GAAG,CAAC,aAAa,CAAC,CAAC0B,WAAW,CAACF,IAAI,CAAC;UAC/C;QACF;MACF;IACF;EACF,CAAC;AACH,CAAC,CAAC;AAAAG,OAAA,CAAAtD,OAAA,GAAAC,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace-source.d.ts","sourceRoot":"","sources":["../../../src/babel/plugins/replace-source.ts"],"names":[],"mappings":";AAQA,
|
|
1
|
+
{"version":3,"file":"replace-source.d.ts","sourceRoot":"","sources":["../../../src/babel/plugins/replace-source.ts"],"names":[],"mappings":";AAQA,wBAuEG"}
|
|
@@ -18,11 +18,12 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
|
|
18
18
|
const fromPath = nodePath.get('source');
|
|
19
19
|
const fromValue = fromPath.node.value;
|
|
20
20
|
const isSource = ops.filename.startsWith(options.srcAbs);
|
|
21
|
-
if (
|
|
21
|
+
if (!isSource) return;
|
|
22
|
+
if (fromValue.startsWith('react-redux')) {
|
|
22
23
|
nodePath.set('source', types.stringLiteral(`rrc-loader-helper/lib/reducers/${fromValue}`));
|
|
23
|
-
} else if (fromValue.startsWith('react-router-dom') && !options.disableBuiltInRoute
|
|
24
|
+
} else if (fromValue.startsWith('react-router-dom') && !options.disableBuiltInRoute) {
|
|
24
25
|
nodePath.set('source', types.stringLiteral('rrc-loader-helper/router'));
|
|
25
|
-
} else if (fromValue.startsWith('redux-saga')
|
|
26
|
+
} else if (fromValue.startsWith('redux-saga')) {
|
|
26
27
|
nodePath.set('source', types.stringLiteral(`rrc-loader-helper/lib/sagas/${fromValue}`));
|
|
27
28
|
}
|
|
28
29
|
},
|
|
@@ -44,7 +45,7 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
|
|
44
45
|
program.unshiftContainer('body', [types.importDeclaration([types.importSpecifier(types.identifier('setReducers'), types.identifier('setReducers'))], types.stringLiteral('rrc-loader-helper/lib/imp')), types.expressionStatement(types.callExpression(types.identifier('setReducers'), [types.identifier('reducers')]))]);
|
|
45
46
|
const routers = nodePath.scope.generateUidIdentifier('routers');
|
|
46
47
|
program.unshiftContainer('body', [types.importDeclaration([types.importDefaultSpecifier(routers)], types.stringLiteral('@@/lessCoding/routers'))]);
|
|
47
|
-
nodePath.replaceWith(types.callExpression(types.memberExpression(types.callExpression(routers, [types.identifier('reducers')]), types.identifier('map')), [types.arrowFunctionExpression([types.identifier('x')], types.blockStatement([types.returnStatement(types.jsxElement(types.jsxOpeningElement(types.jsxIdentifier('Route'), [types.jsxSpreadAttribute(types.identifier('x'))]), null, [], true))]))]));
|
|
48
|
+
nodePath.replaceWith(types.callExpression(types.memberExpression(types.callExpression(routers, [types.identifier('reducers')]), types.identifier('map')), [types.arrowFunctionExpression([types.identifier('x')], types.blockStatement([types.returnStatement(types.jsxElement(types.jsxOpeningElement(types.jsxIdentifier('Route'), [types.jsxSpreadAttribute(types.identifier('x'))], true), null, [], true))]))]));
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace-source.js","names":["_helperPluginUtils","require","_default","declare","api","options","assertVersion","types","name","visitor","ImportDeclaration","nodePath","ops","fromPath","get","fromValue","node","value","isSource","filename","startsWith","srcAbs","set","stringLiteral","disableBuiltInRoute","Identifier","program","findParent","x","isProgram","reducersIdentifier","scope","generateUidIdentifier","unshiftContainer","importDeclaration","importDefaultSpecifier","replaceWith","rootSaga","importSpecifier","identifier","expressionStatement","callExpression","routers","memberExpression","arrowFunctionExpression","blockStatement","returnStatement","jsxElement","jsxOpeningElement","jsxIdentifier","jsxSpreadAttribute","exports","default"],"sources":["../../../replace-source.ts"],"sourcesContent":["import type * as __babel__core from '@babel/core';\nimport { declare } from '@babel/helper-plugin-utils';\n\ninterface Options {\n srcAbs: string;\n disableBuiltInRoute: boolean;\n}\n\nexport default declare<Options>((api, options) => {\n const { assertVersion, types } = api;\n assertVersion(7);\n return {\n name: 'babel-plugin-replace-source',\n visitor: {\n ImportDeclaration(nodePath, ops) {\n const fromPath = nodePath.get('source');\n const fromValue = fromPath.node.value;\n const isSource = ops.filename.startsWith(options.srcAbs);\n if (fromValue.startsWith('react-redux')
|
|
1
|
+
{"version":3,"file":"replace-source.js","names":["_helperPluginUtils","require","_default","declare","api","options","assertVersion","types","name","visitor","ImportDeclaration","nodePath","ops","fromPath","get","fromValue","node","value","isSource","filename","startsWith","srcAbs","set","stringLiteral","disableBuiltInRoute","Identifier","program","findParent","x","isProgram","reducersIdentifier","scope","generateUidIdentifier","unshiftContainer","importDeclaration","importDefaultSpecifier","replaceWith","rootSaga","importSpecifier","identifier","expressionStatement","callExpression","routers","memberExpression","arrowFunctionExpression","blockStatement","returnStatement","jsxElement","jsxOpeningElement","jsxIdentifier","jsxSpreadAttribute","exports","default"],"sources":["../../../replace-source.ts"],"sourcesContent":["import type * as __babel__core from '@babel/core';\nimport { declare } from '@babel/helper-plugin-utils';\n\ninterface Options {\n srcAbs: string;\n disableBuiltInRoute: boolean;\n}\n\nexport default declare<Options>((api, options) => {\n const { assertVersion, types } = api;\n assertVersion(7);\n return {\n name: 'babel-plugin-replace-source',\n visitor: {\n ImportDeclaration(nodePath, ops) {\n const fromPath = nodePath.get('source');\n const fromValue = fromPath.node.value;\n const isSource = ops.filename.startsWith(options.srcAbs);\n if (!isSource) return;\n if (fromValue.startsWith('react-redux')) {\n nodePath.set('source', types.stringLiteral(`rrc-loader-helper/lib/reducers/${fromValue}`));\n } else if (fromValue.startsWith('react-router-dom') && !options.disableBuiltInRoute) {\n nodePath.set('source', types.stringLiteral('rrc-loader-helper/router'));\n } else if (fromValue.startsWith('redux-saga')) {\n nodePath.set('source', types.stringLiteral(`rrc-loader-helper/lib/sagas/${fromValue}`));\n }\n },\n Identifier: (nodePath, ops) => {\n const program = nodePath.findParent((x) => x.isProgram());\n if (!program?.isProgram()) {\n return;\n }\n if (nodePath.node.name === '__ROOT_REDUCER__') {\n const reducersIdentifier = nodePath.scope.generateUidIdentifier('reducers');\n program.unshiftContainer('body', [\n types.importDeclaration([types.importDefaultSpecifier(reducersIdentifier)], types.stringLiteral('@@/lessCoding/reducers')),\n ]);\n nodePath.replaceWith(reducersIdentifier);\n } else if (nodePath.node.name === '__ROOT_SAGA__') {\n const rootSaga = nodePath.scope.generateUidIdentifier('sagas');\n program.unshiftContainer('body', [\n types.importDeclaration([types.importDefaultSpecifier(rootSaga)], types.stringLiteral('@@/lessCoding/sagas')),\n ]);\n nodePath.replaceWith(rootSaga);\n } else if (nodePath.node.name === '__ROOT_ROUTE__') {\n // FUCK\n program.unshiftContainer('body', [\n types.importDeclaration(\n [types.importSpecifier(types.identifier('setReducers'), types.identifier('setReducers'))],\n types.stringLiteral('rrc-loader-helper/lib/imp'),\n ),\n types.expressionStatement(types.callExpression(types.identifier('setReducers'), [types.identifier('reducers')])),\n ]);\n\n const routers = nodePath.scope.generateUidIdentifier('routers');\n program.unshiftContainer('body', [\n types.importDeclaration([types.importDefaultSpecifier(routers)], types.stringLiteral('@@/lessCoding/routers')),\n ]);\n nodePath.replaceWith(\n types.callExpression(types.memberExpression(types.callExpression(routers, [types.identifier('reducers')]), types.identifier('map')), [\n types.arrowFunctionExpression(\n [types.identifier('x')],\n types.blockStatement([\n types.returnStatement(\n types.jsxElement(\n types.jsxOpeningElement(types.jsxIdentifier('Route'), [types.jsxSpreadAttribute(types.identifier('x'))], true),\n null,\n [],\n true,\n ),\n ),\n ]),\n ),\n ]),\n );\n }\n },\n },\n };\n});\n"],"mappings":";;;;;;AACA,IAAAA,kBAAA,GAAAC,OAAA;AAAqD,IAAAC,QAAA,GAOtC,IAAAC,0BAAO,EAAU,CAACC,GAAG,EAAEC,OAAO,KAAK;EAChD,MAAM;IAAEC,aAAa;IAAEC;EAAM,CAAC,GAAGH,GAAG;EACpCE,aAAa,CAAC,CAAC,CAAC;EAChB,OAAO;IACLE,IAAI,EAAE,6BAA6B;IACnCC,OAAO,EAAE;MACPC,iBAAiBA,CAACC,QAAQ,EAAEC,GAAG,EAAE;QAC/B,MAAMC,QAAQ,GAAGF,QAAQ,CAACG,GAAG,CAAC,QAAQ,CAAC;QACvC,MAAMC,SAAS,GAAGF,QAAQ,CAACG,IAAI,CAACC,KAAK;QACrC,MAAMC,QAAQ,GAAGN,GAAG,CAACO,QAAQ,CAACC,UAAU,CAACf,OAAO,CAACgB,MAAM,CAAC;QACxD,IAAI,CAACH,QAAQ,EAAE;QACf,IAAIH,SAAS,CAACK,UAAU,CAAC,aAAa,CAAC,EAAE;UACvC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,OAAO,EAAE,CAACnC,KAAK,CAACgC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,EAAEhC,KAAK,CAACgC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CACnIhC,KAAK,CAACqC,uBAAuB,CAC3B,CAACrC,KAAK,CAACgC,UAAU,CAAC,GAAG,CAAC,CAAC,EACvBhC,KAAK,CAACsC,cAAc,CAAC,CACnBtC,KAAK,CAACuC,eAAe,CACnBvC,KAAK,CAACwC,UAAU,CACdxC,KAAK,CAACyC,iBAAiB,CAACzC,KAAK,CAAC0C,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC1C,KAAK,CAAC2C,kBAAkB,CAAC3C,KAAK,CAACgC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAC9G,IAAI,EACJ,EAAE,EACF,IAAI,CACL,CACF,CACF,CAAC,CACH,CACF,CAAC,CACH;QACH;MACF;IACF;EACF,CAAC;AACH,CAAC,CAAC;AAAAY,OAAA,CAAAC,OAAA,GAAAlD,QAAA"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
2
|
-
import { Options } from './utils';
|
|
2
|
+
import { type Options } from './utils';
|
|
3
|
+
export { Options };
|
|
3
4
|
export default class LcdRouterWebpackPlugin implements WebpackPluginInstance {
|
|
4
5
|
options: Options;
|
|
5
6
|
constructor(options: Options);
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAI/D,OAAO,EAAyB,OAAO,EAAe,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAI/D,OAAO,EAAyB,KAAK,OAAO,EAAe,MAAM,SAAS,CAAC;AAO3E,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,MAAM,CAAC,OAAO,OAAO,sBAAuB,YAAW,qBAAqB;IAC1E,OAAO,EAAE,OAAO,CAAC;gBACL,OAAO,EAAE,OAAO;IAI5B,KAAK,CAAC,QAAQ,EAAE,QAAQ;IAoOxB,YAAY,CAAC,QAAQ,EAAE,QAAQ;CAYhC"}
|
package/lib/index.js
CHANGED
|
@@ -212,7 +212,7 @@ class LcdRouterWebpackPlugin {
|
|
|
212
212
|
index: 'list',
|
|
213
213
|
externals: [],
|
|
214
214
|
pageDir: 'component',
|
|
215
|
-
reducerName: '
|
|
215
|
+
reducerName: 'reducer',
|
|
216
216
|
disableBuiltInRoute: false
|
|
217
217
|
};
|
|
218
218
|
this.options = (0, _deepmerge.default)(defaultOptions, this.options);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_globby","_interopRequireDefault","require","_chokidar","_deepmerge","_utils","_ReducersGenerator","_SagasGenerator","_RoutersGenerator","_nodePath","obj","__esModule","default","LcdRouterWebpackPlugin","options","constructor","apply","compiler","mergeOptions","hooks","afterPlugins","tap","pathService","PathService","resolver","Resolver","fileService","FileService","reducersGenerator","ReducersGenerator","sagasGenerator","SagasGenerator","routersGenerator","RoutersGenerator","isDev","mode","process","env","NODE_ENV","writeCode","writeCodeToFile","getReducersCacheFileAbs","getSagasCacheFileAbs","getRoutersCacheFileAbs","resolveFile","filepath","absFilePath","getCurrentFileAbs","currentDir","path","dirname","absCurrentDir","chunkCode","meJSON","readJSONSync","reducerPath","getReducerFile","push","e","mobx","Error","viewPath","getViewFile","theme","hash","sagaPath","getSagaFile","errorComponent","errorCompPath","getErrorComFile","themePath","getThemeJSCacheFileAbs","writeThemeFile","meJSONPath","getMeJSONCacheFileAbs","writeMeJSONFile","isExternal","externals","some","x","hasChildStore","globby","sync","reducerName","cwd","length","set","namespace","page","exact","RegExp","index","test","_key","replace","list","getPageRootAbs","console","warn","sortedList","map","sort","a","b","startsWith","localeCompare","dir","forEach","watcher","chokidar","watch","ignoreInitial","fn","on","environment","module","rules","exclude","use","loader","resolve","presets","babelrc","parserOpts","plugins","defaultOptions","context","enablePreFetch","pageDir","disableBuiltInRoute","deepmerge","exports"],"sources":["../index.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport globby from 'globby';\nimport chokidar from 'chokidar';\nimport deepmerge from 'deepmerge';\nimport { PathService, Resolver, Options, FileService } from './utils';\nimport { ReducersGenerator } from './ReducersGenerator';\nimport { SagasGenerator } from './SagasGenerator';\nimport { RoutersGenerator } from './RoutersGenerator';\n\nimport path from 'node:path';\n\nexport default class LcdRouterWebpackPlugin implements WebpackPluginInstance {\n options: Options;\n constructor(options: Options) {\n this.options = options;\n }\n\n apply(compiler: Compiler) {\n this.mergeOptions(compiler);\n\n // 处理 lcd 中的路由体系\n compiler.hooks.afterPlugins.tap('LcdRouterWebpackPlugin', (compiler) => {\n const options = this.options;\n\n const pathService = new PathService(options);\n const resolver = new Resolver(compiler, options);\n const fileService = new FileService(pathService);\n\n const reducersGenerator = new ReducersGenerator();\n const sagasGenerator = new SagasGenerator();\n const routersGenerator = new RoutersGenerator(options, pathService);\n\n function isDev(compiler) {\n if (compiler.options.mode === 'production' || process.env.NODE_ENV === 'production') return false;\n return true;\n }\n\n function writeCode() {\n reducersGenerator.writeCodeToFile(pathService.getReducersCacheFileAbs());\n sagasGenerator.writeCodeToFile(pathService.getSagasCacheFileAbs());\n routersGenerator.writeCodeToFile(pathService.getRoutersCacheFileAbs());\n }\n\n function resolveFile(filepath: string) {\n const absFilePath = pathService.getCurrentFileAbs(filepath);\n const currentDir = path.dirname(filepath);\n const absCurrentDir = path.dirname(absFilePath);\n\n const chunkCode = [] as string[];\n const meJSON = fileService.readJSONSync(absFilePath);\n try {\n const reducerPath = resolver.getReducerFile(absCurrentDir);\n chunkCode.push(`export { default as reducer } from '${reducerPath}';`);\n } catch (e) {\n // feat: reducers 可以不存在, 方便结合reactive 和 ak,默认创建一个reducers\n if (meJSON.mobx) {\n /**\n * mobx 模式下, 需要垫一个被 mobx-adapter 包裹的 reducer 函数\n * 如果存在reducer文件,是默认会被 babel-plugin-enhance-reducer 处理的\n *\n * import storeHoc from 'rrc-loader-helper/lib/mobx-adapter';\n * export const reducer = storeHoc({\n * state: {},\n * }, 'report/other-table')\n *\n * 不太方便去垫一个 reducer 函数,reducer 的路径计算比较复杂, 所以直接报错\n * 同时,从逻辑上讲,如果开启了 mobx,那么必须要有 reducer 文件\n */\n throw Error(`开启 mobx 后,reducer 文件必须存在 ${absFilePath}`);\n }\n chunkCode.push(`export function reducer(){ return {} }`);\n }\n\n const viewPath = resolver.getViewFile(absCurrentDir);\n chunkCode.push(`export { default as view } from '${viewPath}';`);\n\n if (meJSON.theme && !options.theme?.hash) {\n throw Error(`开启页面级主题之前,请优先开启全局主题 ${absFilePath}`);\n }\n\n if (!meJSON.mobx) {\n try {\n const sagaPath = resolver.getSagaFile(absCurrentDir);\n chunkCode.push(`export { default as saga } from '${sagaPath}';`);\n } catch (e) {\n // feat: saga 也可以不存在, 方便结合reactive 和 ak,默认创建一个reducers\n chunkCode.push(`export function* saga(){ return {} }`);\n }\n }\n\n if (meJSON.errorComponent) {\n const errorCompPath = resolver.getErrorComFile(absCurrentDir, meJSON.errorComponent);\n chunkCode.push(`export { default as ErrorComponent } from '${errorCompPath}';`);\n }\n\n if (options.theme?.hash) {\n const themePath = pathService.getThemeJSCacheFileAbs(options.theme?.hash);\n chunkCode.push(`export * from '${themePath}';`);\n }\n\n if (meJSON.theme) {\n fileService.writeThemeFile(meJSON.theme, 'toGlobalTheme');\n const themePath = pathService.getThemeJSCacheFileAbs(meJSON.theme);\n chunkCode.push(`export * from '${themePath}';`);\n }\n\n const meJSONPath = pathService.getMeJSONCacheFileAbs(filepath);\n\n fileService.writeMeJSONFile(meJSONPath, chunkCode);\n\n const isExternal = options.externals?.some?.((x) => x === path.dirname(filepath)) ?? false;\n\n // 处理是否存在多store的场景\n const hasChildStore = globby.sync(`**/*.${options.reducerName}.{t,j}s`, { cwd: absCurrentDir }).length > 0;\n if (hasChildStore && (meJSON.sync || isExternal)) {\n throw Error(`如果开启了Sync模式或当前页面存在于LCD的external中,那么则不支持多Store功能,${absCurrentDir}`);\n }\n\n /** reducers.js */\n reducersGenerator.set(filepath, {\n meJSON,\n isExternal,\n namespace: currentDir,\n meJSONPath: meJSONPath,\n });\n\n /** saga.js */\n sagasGenerator.set(currentDir, {\n meJSON,\n isExternal,\n namespace: currentDir,\n meJSONPath: meJSONPath,\n });\n\n /** router */\n routersGenerator.set(currentDir, {\n meJSON,\n isExternal,\n page: currentDir,\n path: currentDir,\n exact: false,\n meJSONPath: meJSONPath,\n });\n\n /** 处理 /list 的路由 */\n if (new RegExp(`\\/${options.index}$`).test(absCurrentDir)) {\n const _key = absCurrentDir.replace(new RegExp(`\\/${options.index}$`), '');\n routersGenerator.set(_key, {\n meJSON,\n isExternal,\n page: absCurrentDir,\n path: _key,\n exact: true,\n meJSONPath: meJSONPath,\n });\n }\n }\n\n if (options.theme?.hash) {\n fileService.writeThemeFile(options.theme.hash, 'toGlobalTheme');\n }\n\n const list = globby.sync('**/me.json', {\n cwd: pathService.getPageRootAbs(),\n });\n\n if (list.length === 0) {\n console.warn('没有找到me.json文件');\n }\n\n /**\n * glob 的排序 是包含文件名 me.json 的完整路径,存在问题\n * 比如 会将 /xx/ss/me.json 排到 /xx/ss/zz/me.json 前面\n * glob 的 noSort option 会将 文件夹排到前面, 因此需要手动排序, 并且统一成 globby, 速度更快\n */\n const sortedList = list\n .map((filepath) => filepath?.replace(/me.json$/, ''))\n .sort((a, b) => {\n if (a?.startsWith(b)) return -1;\n return a.localeCompare(b, 'en');\n })\n .map((dir) => `${dir}me.json`);\n\n sortedList.forEach((filepath) => {\n resolveFile(filepath);\n });\n\n writeCode();\n\n if (isDev(compiler)) {\n const watcher = chokidar.watch('**/me.json', {\n cwd: pathService.getPageRootAbs(),\n ignoreInitial: true,\n });\n const fn = async (filepath) => {\n await resolveFile(filepath);\n writeCode();\n };\n watcher.on('add', fn);\n watcher.on('addDir', fn);\n watcher.on('change', fn);\n watcher.on('unlink', fn);\n watcher.on('unlinkDir', fn);\n watcher.on('error', fn);\n }\n });\n\n // lcd 中包含一些语法转换处理\n compiler.hooks.environment.tap('lcd-preset', () => {\n compiler.options.module.rules.push({\n test: /\\.(js|ts)x?$/,\n exclude: /node_modules/,\n use: [\n {\n loader: require.resolve('babel-loader'),\n options: {\n presets: [[require.resolve('./babel/index'), this.options]],\n babelrc: false,\n // 需要支持语法解析, 但不需要做转换\n parserOpts: {\n plugins: [\n 'jsx',\n 'typescript',\n 'asyncDoExpressions',\n 'decimal',\n 'decorators-legacy',\n 'decoratorAutoAccessors',\n 'destructuringPrivate',\n 'doExpressions',\n 'exportDefaultFrom',\n 'functionBind',\n 'functionSent',\n 'importAssertions',\n 'moduleBlocks',\n 'partialApplication',\n 'throwExpressions',\n ],\n },\n },\n },\n ],\n });\n });\n }\n\n mergeOptions(compiler: Compiler) {\n const defaultOptions = {\n context: compiler.context,\n enablePreFetch: false,\n index: 'list',\n externals: [],\n pageDir: 'component',\n reducerName: 'reducers',\n disableBuiltInRoute: false,\n };\n this.options = deepmerge(defaultOptions, this.options);\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAEA,IAAAO,SAAA,G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,CAAC/G,OAAO,CAAC;EACxD;AACF;AAACqH,OAAA,CAAAvH,OAAA,GAAAC,sBAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_globby","_interopRequireDefault","require","_chokidar","_deepmerge","_utils","_ReducersGenerator","_SagasGenerator","_RoutersGenerator","_nodePath","obj","__esModule","default","LcdRouterWebpackPlugin","options","constructor","apply","compiler","mergeOptions","hooks","afterPlugins","tap","pathService","PathService","resolver","Resolver","fileService","FileService","reducersGenerator","ReducersGenerator","sagasGenerator","SagasGenerator","routersGenerator","RoutersGenerator","isDev","mode","process","env","NODE_ENV","writeCode","writeCodeToFile","getReducersCacheFileAbs","getSagasCacheFileAbs","getRoutersCacheFileAbs","resolveFile","filepath","absFilePath","getCurrentFileAbs","currentDir","path","dirname","absCurrentDir","chunkCode","meJSON","readJSONSync","reducerPath","getReducerFile","push","e","mobx","Error","viewPath","getViewFile","theme","hash","sagaPath","getSagaFile","errorComponent","errorCompPath","getErrorComFile","themePath","getThemeJSCacheFileAbs","writeThemeFile","meJSONPath","getMeJSONCacheFileAbs","writeMeJSONFile","isExternal","externals","some","x","hasChildStore","globby","sync","reducerName","cwd","length","set","namespace","page","exact","RegExp","index","test","_key","replace","list","getPageRootAbs","console","warn","sortedList","map","sort","a","b","startsWith","localeCompare","dir","forEach","watcher","chokidar","watch","ignoreInitial","fn","on","environment","module","rules","exclude","use","loader","resolve","presets","babelrc","parserOpts","plugins","defaultOptions","context","enablePreFetch","pageDir","disableBuiltInRoute","deepmerge","exports"],"sources":["../index.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport globby from 'globby';\nimport chokidar from 'chokidar';\nimport deepmerge from 'deepmerge';\nimport { PathService, Resolver, type Options, FileService } from './utils';\nimport { ReducersGenerator } from './ReducersGenerator';\nimport { SagasGenerator } from './SagasGenerator';\nimport { RoutersGenerator } from './RoutersGenerator';\n\nimport path from 'node:path';\n\nexport { Options };\n\nexport default class LcdRouterWebpackPlugin implements WebpackPluginInstance {\n options: Options;\n constructor(options: Options) {\n this.options = options;\n }\n\n apply(compiler: Compiler) {\n this.mergeOptions(compiler);\n\n // 处理 lcd 中的路由体系\n compiler.hooks.afterPlugins.tap('LcdRouterWebpackPlugin', (compiler) => {\n const options = this.options;\n\n const pathService = new PathService(options);\n const resolver = new Resolver(compiler, options);\n const fileService = new FileService(pathService);\n\n const reducersGenerator = new ReducersGenerator();\n const sagasGenerator = new SagasGenerator();\n const routersGenerator = new RoutersGenerator(options, pathService);\n\n function isDev(compiler) {\n if (compiler.options.mode === 'production' || process.env.NODE_ENV === 'production') return false;\n return true;\n }\n\n function writeCode() {\n reducersGenerator.writeCodeToFile(pathService.getReducersCacheFileAbs());\n sagasGenerator.writeCodeToFile(pathService.getSagasCacheFileAbs());\n routersGenerator.writeCodeToFile(pathService.getRoutersCacheFileAbs());\n }\n\n function resolveFile(filepath: string) {\n const absFilePath = pathService.getCurrentFileAbs(filepath);\n const currentDir = path.dirname(filepath);\n const absCurrentDir = path.dirname(absFilePath);\n\n const chunkCode = [] as string[];\n const meJSON = fileService.readJSONSync(absFilePath);\n try {\n const reducerPath = resolver.getReducerFile(absCurrentDir);\n chunkCode.push(`export { default as reducer } from '${reducerPath}';`);\n } catch (e) {\n // feat: reducers 可以不存在, 方便结合reactive 和 ak,默认创建一个reducers\n if (meJSON.mobx) {\n /**\n * mobx 模式下, 需要垫一个被 mobx-adapter 包裹的 reducer 函数\n * 如果存在reducer文件,是默认会被 babel-plugin-enhance-reducer 处理的\n *\n * import storeHoc from 'rrc-loader-helper/lib/mobx-adapter';\n * export const reducer = storeHoc({\n * state: {},\n * }, 'report/other-table')\n *\n * 不太方便去垫一个 reducer 函数,reducer 的路径计算比较复杂, 所以直接报错\n * 同时,从逻辑上讲,如果开启了 mobx,那么必须要有 reducer 文件\n */\n throw Error(`开启 mobx 后,reducer 文件必须存在 ${absFilePath}`);\n }\n chunkCode.push(`export function reducer(){ return {} }`);\n }\n\n const viewPath = resolver.getViewFile(absCurrentDir);\n chunkCode.push(`export { default as view } from '${viewPath}';`);\n\n if (meJSON.theme && !options.theme?.hash) {\n throw Error(`开启页面级主题之前,请优先开启全局主题 ${absFilePath}`);\n }\n\n if (!meJSON.mobx) {\n try {\n const sagaPath = resolver.getSagaFile(absCurrentDir);\n chunkCode.push(`export { default as saga } from '${sagaPath}';`);\n } catch (e) {\n // feat: saga 也可以不存在, 方便结合reactive 和 ak,默认创建一个reducers\n chunkCode.push(`export function* saga(){ return {} }`);\n }\n }\n\n if (meJSON.errorComponent) {\n const errorCompPath = resolver.getErrorComFile(absCurrentDir, meJSON.errorComponent);\n chunkCode.push(`export { default as ErrorComponent } from '${errorCompPath}';`);\n }\n\n if (options.theme?.hash) {\n const themePath = pathService.getThemeJSCacheFileAbs(options.theme?.hash);\n chunkCode.push(`export * from '${themePath}';`);\n }\n\n if (meJSON.theme) {\n fileService.writeThemeFile(meJSON.theme, 'toGlobalTheme');\n const themePath = pathService.getThemeJSCacheFileAbs(meJSON.theme);\n chunkCode.push(`export * from '${themePath}';`);\n }\n\n const meJSONPath = pathService.getMeJSONCacheFileAbs(filepath);\n\n fileService.writeMeJSONFile(meJSONPath, chunkCode);\n\n const isExternal = options.externals?.some?.((x) => x === path.dirname(filepath)) ?? false;\n\n // 处理是否存在多store的场景\n const hasChildStore = globby.sync(`**/*.${options.reducerName}.{t,j}s`, { cwd: absCurrentDir }).length > 0;\n if (hasChildStore && (meJSON.sync || isExternal)) {\n throw Error(`如果开启了Sync模式或当前页面存在于LCD的external中,那么则不支持多Store功能,${absCurrentDir}`);\n }\n\n /** reducers.js */\n reducersGenerator.set(filepath, {\n meJSON,\n isExternal,\n namespace: currentDir,\n meJSONPath: meJSONPath,\n });\n\n /** saga.js */\n sagasGenerator.set(currentDir, {\n meJSON,\n isExternal,\n namespace: currentDir,\n meJSONPath: meJSONPath,\n });\n\n /** router */\n routersGenerator.set(currentDir, {\n meJSON,\n isExternal,\n page: currentDir,\n path: currentDir,\n exact: false,\n meJSONPath: meJSONPath,\n });\n\n /** 处理 /list 的路由 */\n if (new RegExp(`\\/${options.index}$`).test(absCurrentDir)) {\n const _key = absCurrentDir.replace(new RegExp(`\\/${options.index}$`), '');\n routersGenerator.set(_key, {\n meJSON,\n isExternal,\n page: absCurrentDir,\n path: _key,\n exact: true,\n meJSONPath: meJSONPath,\n });\n }\n }\n\n if (options.theme?.hash) {\n fileService.writeThemeFile(options.theme.hash, 'toGlobalTheme');\n }\n\n const list = globby.sync('**/me.json', {\n cwd: pathService.getPageRootAbs(),\n });\n\n if (list.length === 0) {\n console.warn('没有找到me.json文件');\n }\n\n /**\n * glob 的排序 是包含文件名 me.json 的完整路径,存在问题\n * 比如 会将 /xx/ss/me.json 排到 /xx/ss/zz/me.json 前面\n * glob 的 noSort option 会将 文件夹排到前面, 因此需要手动排序, 并且统一成 globby, 速度更快\n */\n const sortedList = list\n .map((filepath) => filepath?.replace(/me.json$/, ''))\n .sort((a, b) => {\n if (a?.startsWith(b)) return -1;\n return a.localeCompare(b, 'en');\n })\n .map((dir) => `${dir}me.json`);\n\n sortedList.forEach((filepath) => {\n resolveFile(filepath);\n });\n\n writeCode();\n\n if (isDev(compiler)) {\n const watcher = chokidar.watch('**/me.json', {\n cwd: pathService.getPageRootAbs(),\n ignoreInitial: true,\n });\n const fn = async (filepath) => {\n await resolveFile(filepath);\n writeCode();\n };\n watcher.on('add', fn);\n watcher.on('addDir', fn);\n watcher.on('change', fn);\n watcher.on('unlink', fn);\n watcher.on('unlinkDir', fn);\n watcher.on('error', fn);\n }\n });\n\n // lcd 中包含一些语法转换处理\n compiler.hooks.environment.tap('lcd-preset', () => {\n compiler.options.module.rules.push({\n test: /\\.(js|ts)x?$/,\n exclude: /node_modules/,\n use: [\n {\n loader: require.resolve('babel-loader'),\n options: {\n presets: [[require.resolve('./babel/index'), this.options]],\n babelrc: false,\n // 需要支持语法解析, 但不需要做转换\n parserOpts: {\n plugins: [\n 'jsx',\n 'typescript',\n 'asyncDoExpressions',\n 'decimal',\n 'decorators-legacy',\n 'decoratorAutoAccessors',\n 'destructuringPrivate',\n 'doExpressions',\n 'exportDefaultFrom',\n 'functionBind',\n 'functionSent',\n 'importAssertions',\n 'moduleBlocks',\n 'partialApplication',\n 'throwExpressions',\n ],\n },\n },\n },\n ],\n });\n });\n }\n\n mergeOptions(compiler: Compiler) {\n const defaultOptions = {\n context: compiler.context,\n enablePreFetch: false,\n index: 'list',\n externals: [],\n pageDir: 'component',\n reducerName: 'reducer',\n disableBuiltInRoute: false,\n };\n this.options = deepmerge(defaultOptions, this.options);\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAEA,IAAAO,SAAA,GAAAR,sBAAA,CAAAC,OAAA;AAA6B,SAAAD,uBAAAS,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAId,MAAMG,sBAAsB,CAAkC;EAC3EC,OAAO;EACPC,WAAWA,CAACD,OAAgB,EAAE;IAC5B,IAAI,CAACA,OAAO,GAAGA,OAAO;EACxB;EAEAE,KAAKA,CAACC,QAAkB,EAAE;IACxB,IAAI,CAACC,YAAY,CAACD,QAAQ,CAAC;;IAE3B;IACAA,QAAQ,CAACE,KAAK,CAACC,YAAY,CAACC,GAAG,CAAC,wBAAwB,EAAGJ,QAAQ,IAAK;MACtE,MAAMH,OAAO,GAAG,IAAI,CAACA,OAAO;MAE5B,MAAMQ,WAAW,GAAG,IAAIC,kBAAW,CAACT,OAAO,CAAC;MAC5C,MAAMU,QAAQ,GAAG,IAAIC,eAAQ,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AC3D4G,OAAO,EAAE,KAAK;YACd;YACAC,UAAU,EAAE;cACVC,OAAO,EAAE,CACP,KAAK,EACL,YAAY,EACZ,oBAAoB,EACpB,SAAS,EACT,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,kBAAkB;YAEtB;UACF;QACF,CAAC;MAEL,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EAEA1G,YAAYA,CAACD,QAAkB,EAAE;IAC/B,MAAM4G,cAAc,GAAG;MACrBC,OAAO,EAAE7G,QAAQ,CAAC6G,OAAO;MACzBC,cAAc,EAAE,KAAK;MACrBpC,KAAK,EAAE,MAAM;MACbd,SAAS,EAAE,EAAE;MACbmD,OAAO,EAAE,WAAW;MACpB7C,WAAW,EAAE,SAAS;MACtB8C,mBAAmB,EAAE;IACvB,CAAC;IACD,IAAI,CAACnH,OAAO,GAAG,IAAAoH,kBAAS,EAACL,cAAc,EAAE,IAAI,CAAC/G,OAAO,CAAC;EACxD;AACF;AAACqH,OAAA,CAAAvH,OAAA,GAAAC,sBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/utils/resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,qBAAa,QAAQ;IACnB,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;gBACL,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO;IAQhD;;OAEG;IACH,cAAc,wBAAwE;IAEtF;;OAEG;IACH,WAAW,wBAAiD;IAE5D;;;OAGG;IACH,WAAW,0BAAsB,OAAO,
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/utils/resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,qBAAa,QAAQ;IACnB,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;gBACL,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO;IAQhD;;OAEG;IACH,cAAc,wBAAwE;IAEtF;;OAEG;IACH,WAAW,wBAAiD;IAE5D;;;OAGG;IACH,WAAW,0BAAsB,OAAO,SAAgF;IAExH;;OAEG;IACH,eAAe,6CAAuE;CACvF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.js","names":["_enhancedResolve","require","Resolver","resolver","options","constructor","compiler","create","sync","extensions","resolve","alias","getReducerFile","dirname","reducerName","getViewFile","getSagaFile","isMobx","getErrorComFile","errorComponent","exports"],"sources":["../../resolver.ts"],"sourcesContent":["import { create } from 'enhanced-resolve';\nimport type { Compiler } from 'webpack';\nimport type { Options } from './types';\n\nexport class Resolver {\n resolver: any;\n options: Options;\n constructor(compiler: Compiler, options: Options) {\n this.options = options;\n this.resolver = create.sync({\n extensions: compiler.options.resolve.extensions,\n alias: compiler.options.resolve.alias,\n });\n }\n\n /**\n * 获取 当前目录下 reducer文件的路径\n */\n getReducerFile = (dirname) => this.resolver(dirname, `./${this.options.reducerName}`);\n\n /**\n * 获取 当前目录下 view文件的路径\n */\n getViewFile = (dirname) => this.resolver(dirname, `./view`);\n\n /**\n * 获取 当前目录下 saga 文件的路径\n * @param isMobx 如果是 mobx 则返回 reducers 的地址\n */\n getSagaFile = (dirname, isMobx?: boolean)
|
|
1
|
+
{"version":3,"file":"resolver.js","names":["_enhancedResolve","require","Resolver","resolver","options","constructor","compiler","create","sync","extensions","resolve","alias","getReducerFile","dirname","reducerName","getViewFile","getSagaFile","isMobx","getErrorComFile","errorComponent","exports"],"sources":["../../resolver.ts"],"sourcesContent":["import { create } from 'enhanced-resolve';\nimport type { Compiler } from 'webpack';\nimport type { Options } from './types';\n\nexport class Resolver {\n resolver: any;\n options: Options;\n constructor(compiler: Compiler, options: Options) {\n this.options = options;\n this.resolver = create.sync({\n extensions: compiler.options.resolve.extensions,\n alias: compiler.options.resolve.alias,\n });\n }\n\n /**\n * 获取 当前目录下 reducer文件的路径\n */\n getReducerFile = (dirname) => this.resolver(dirname, `./${this.options.reducerName}`);\n\n /**\n * 获取 当前目录下 view文件的路径\n */\n getViewFile = (dirname) => this.resolver(dirname, `./view`);\n\n /**\n * 获取 当前目录下 saga 文件的路径\n * @param isMobx 如果是 mobx 则返回 reducers 的地址\n */\n getSagaFile = (dirname, isMobx?: boolean) => (isMobx ? this.getReducerFile(dirname) : this.resolver(dirname, `./saga`));\n\n /**\n * 获取 me.json 配置的 errorComponent 地址\n */\n getErrorComFile = (dirname, errorComponent) => this.resolver(dirname, errorComponent);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AAIO,MAAMC,QAAQ,CAAC;EACpBC,QAAQ;EACRC,OAAO;EACPC,WAAWA,CAACC,QAAkB,EAAEF,OAAgB,EAAE;IAChD,IAAI,CAACA,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACD,QAAQ,GAAGI,uBAAM,CAACC,IAAI,CAAC;MAC1BC,UAAU,EAAEH,QAAQ,CAACF,OAAO,CAACM,OAAO,CAACD,UAAU;MAC/CE,KAAK,EAAEL,QAAQ,CAACF,OAAO,CAACM,OAAO,CAACC;IAClC,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;EACEC,cAAc,GAAIC,OAAO,IAAK,IAAI,CAACV,QAAQ,CAACU,OAAO,EAAG,KAAI,IAAI,CAACT,OAAO,CAACU,WAAY,EAAC,CAAC;;EAErF;AACF;AACA;EACEC,WAAW,GAAIF,OAAO,IAAK,IAAI,CAACV,QAAQ,CAACU,OAAO,EAAG,QAAO,CAAC;;EAE3D;AACF;AACA;AACA;EACEG,WAAW,GAAGA,CAACH,OAAO,EAAEI,MAAgB,KAAMA,MAAM,GAAG,IAAI,CAACL,cAAc,CAACC,OAAO,CAAC,GAAG,IAAI,CAACV,QAAQ,CAACU,OAAO,EAAG,QAAO,CAAE;;EAEvH;AACF;AACA;EACEK,eAAe,GAAGA,CAACL,OAAO,EAAEM,cAAc,KAAK,IAAI,CAAChB,QAAQ,CAACU,OAAO,EAAEM,cAAc,CAAC;AACvF;AAACC,OAAA,CAAAlB,QAAA,GAAAA,QAAA"}
|
package/lib/utils/types.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface Options {
|
|
|
25
25
|
* 页面目录
|
|
26
26
|
* @default component
|
|
27
27
|
*/
|
|
28
|
-
pageDir
|
|
28
|
+
pageDir?: string;
|
|
29
29
|
/**
|
|
30
30
|
* shineout 主题
|
|
31
31
|
*/
|
|
@@ -34,9 +34,9 @@ export interface Options {
|
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* reducer 文件名称
|
|
37
|
-
* @default
|
|
37
|
+
* @default reducer
|
|
38
38
|
*/
|
|
39
|
-
reducerName
|
|
39
|
+
reducerName?: string;
|
|
40
40
|
/**
|
|
41
41
|
* loading 组件路径
|
|
42
42
|
*/
|
|
@@ -64,10 +64,21 @@ export interface Options {
|
|
|
64
64
|
export interface MeJSON {
|
|
65
65
|
theme?: string;
|
|
66
66
|
sync?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* mobx 模式
|
|
69
|
+
* 未开启时, reducer 文件导出为纯函数,用来处理状态修改。 saga 文件用来处理副作用逻辑。
|
|
70
|
+
* 开启后,reducer 文件导出为对象,包含 state 以及方法, 普通函数作为reducer修改状态, generator 函数处理副作用逻辑。
|
|
71
|
+
* @default false
|
|
72
|
+
*/
|
|
67
73
|
mobx?: boolean;
|
|
68
74
|
keepAlive?: boolean;
|
|
69
75
|
retain?: boolean;
|
|
70
76
|
title?: string;
|
|
77
|
+
/**
|
|
78
|
+
* @description 为了兼容同一个页面多次打开 动态拓展 redux 的reducer 节点
|
|
79
|
+
* @description 在路由配置中添加 /:id?,不推荐使用, 仅极少场景需要
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
71
82
|
linkExtendable?: boolean;
|
|
72
83
|
injectStore?: boolean | string;
|
|
73
84
|
route?: string;
|
package/lib/utils/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
package/lib/utils/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../types.ts"],"sourcesContent":["export interface Options {\n /**\n * 组件上下文, 默认取 compiler.context\n * @default compiler.context\n */\n context?: string;\n /**\n * 是否禁用内置路由\n * 默认会将 react-router-dom 转换到 rrc-loader-helper/router\n * 如果你是新项目,建议将该配置配置为true,因为内置路由针对react-router做了大量的改动,可能会引起一些无法预测的故障\n * @default false\n */\n disableBuiltInRoute?: boolean;\n /**\n * 是否开启 webpack prefetch预加载\n * @default false\n */\n enablePreFetch?: boolean;\n /**\n * 指定页面路径 不进行注册路由\n * @default []\n */\n externals?: string[];\n /**\n * 页面目录\n * @default component\n */\n pageDir
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../types.ts"],"sourcesContent":["export interface Options {\n /**\n * 组件上下文, 默认取 compiler.context\n * @default compiler.context\n */\n context?: string;\n /**\n * 是否禁用内置路由\n * 默认会将 react-router-dom 转换到 rrc-loader-helper/router\n * 如果你是新项目,建议将该配置配置为true,因为内置路由针对react-router做了大量的改动,可能会引起一些无法预测的故障\n * @default false\n */\n disableBuiltInRoute?: boolean;\n /**\n * 是否开启 webpack prefetch预加载\n * @default false\n */\n enablePreFetch?: boolean;\n /**\n * 指定页面路径 不进行注册路由\n * @default []\n */\n externals?: string[];\n /**\n * 页面目录\n * @default component\n */\n pageDir?: string;\n /**\n * shineout 主题\n */\n theme?: {\n hash: string;\n };\n /**\n * reducer 文件名称\n * @default reducer\n */\n reducerName?: string;\n /**\n * loading 组件路径\n */\n loading?: string;\n /**\n * 一个神奇的属性,用于处理 /xxx/order/list 这种路由过长的问题\n * 也可以用来作为父路由的默认路由目录\n * 会生成一个新路由 /xxx/order,实际目录指向为 /xxx/order/list\n * @default list\n */\n index?: string;\n /**\n * 渲染出错时的组件地址\n */\n errorComponent?: string;\n\n /**\n * 是否允许页面内生成自定义路由\n * 例如在 component/order/detail/me.json 中 配置 route: '/:id',此时会生成动态路由 /order/detail/:id\n * 非常不推荐使用的一个属性,因为此功能受 me.json 中 exact 属性影响, 仅当 exact: true 时候,才不会拼接路由\n * 当开启 dangerousRoute 后, 不再受 exact 影响, 都会生成 拼接路由 /order/detail/:id\n * @default false\n */\n dangerousRoute?: boolean;\n}\n\nexport interface MeJSON {\n theme?: string;\n sync?: boolean;\n /**\n * mobx 模式\n * 未开启时, reducer 文件导出为纯函数,用来处理状态修改。 saga 文件用来处理副作用逻辑。\n * 开启后,reducer 文件导出为对象,包含 state 以及方法, 普通函数作为reducer修改状态, generator 函数处理副作用逻辑。\n * @default false\n */\n mobx?: boolean;\n keepAlive?: boolean;\n retain?: boolean;\n title?: string;\n /**\n * @description 为了兼容同一个页面多次打开 动态拓展 redux 的reducer 节点\n * @description 在路由配置中添加 /:id?,不推荐使用, 仅极少场景需要\n * @default false\n */\n linkExtendable?: boolean;\n injectStore?: boolean | string;\n route?: string;\n}\n"],"mappings":""}
|