Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(router): loader params 修改适配 multi 模式 fix #12417 #12503

Merged
merged 8 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions packages/taro-cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
const { jsWithTs: tsjPreset } = require('ts-jest/presets')

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx', 'node'],
testMatch: ['**/__tests__/?(*.)+(spec|test).[jt]s?(x)'],
globals: {
'ts-jest': {
diagnostics: false
}
}
},
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx', 'node'],
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/__tests__/?(*.)+(spec|test).[jt]s?(x)'],
testTimeout: 60000,
transform: {
'^.+\\.jsx?$': [ require.resolve('babel-jest'), { rootMode: 'upward' } ],
'^.+\\.tsx?$': 'ts-jest',
...tsjPreset.transform
},
transformIgnorePatterns: [
'node_modules',
],
}
4 changes: 2 additions & 2 deletions packages/taro-loader/src/h5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function (this: webpack.LoaderContext<any>) {
const pxTransformConfig = options.pxTransformConfig

const pathDirname = dirname(this.resourcePath)
const pageName = isMultiRouterMode ? join(pathDirname, options.name).replace(options.sourceDir + '/', '') : ''
const pageName = isMultiRouterMode ? join(pathDirname, options.filename).replace(options.sourceDir + '/', '') : ''
if (options.bootstrap) {
/** NOTE: Webpack Virtual Module plugin doesn't support triggering a rebuild for webpack5,
* which can cause "module not found" error when webpack5 cache is enabled.
Expand Down Expand Up @@ -83,7 +83,7 @@ applyPolyfills().then(function () {

const components = options.useHtmlComponents ? compatComponentImport || '' : webComponents
const routesConfig = isMultiRouterMode ? `config.routes = []
config.route = ${genResource(pageName, pages, this, options.name)}
config.route = ${genResource(pageName, pages, this, options.filename)}
config.pageName = "${pageName}"` : `config.routes = [
${config.pages?.map(path => genResource(path, pages, this)).join(',')}
]`
Expand Down
3 changes: 3 additions & 0 deletions packages/taro-router/src/router/mpa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export async function createMultiRouter (
let element
try {
element = await pageConfig.load?.()
if (element instanceof Array) {
element = element[0]
}
} catch (error) {
throw new Error(error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3857,22 +3857,25 @@ exports[`babel should convert do expressions 2`] = `

case 10:
element = _context.sent;
_context.next = 16;
if (element instanceof Array) {
element = element[0];
}
_context.next = 17;
break;

case 13:
_context.prev = 13;
case 14:
_context.prev = 14;
_context.t0 = _context[\\"catch\\"](7);
throw new Error(_context.t0);

case 16:
case 17:
if (element) {
_context.next = 18;
_context.next = 19;
break;
}
return _context.abrupt(\\"return\\");

case 18:
case 19:
enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
undefined.trigger(\\"__taroRouterChange\\", {
\\"toLocation\\": {
Expand All @@ -3893,12 +3896,12 @@ exports[`babel should convert do expressions 2`] = `
handler.load(page, pageConfig);
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);

case 28:
case 29:
case \\"end\\":
return _context.stop();
}
}
}), _callee, null, [ [ 7, 13 ] ]);
}), _callee, null, [ [ 7, 14 ] ]);
})));
}
var path_to_regexp = __webpack_require__(8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3852,22 +3852,25 @@ exports[`compiler-macros - defineAppConfig and definePageConfig should read app

case 10:
element = _context.sent;
_context.next = 16;
if (element instanceof Array) {
element = element[0];
}
_context.next = 17;
break;

case 13:
_context.prev = 13;
case 14:
_context.prev = 14;
_context.t0 = _context[\\"catch\\"](7);
throw new Error(_context.t0);

case 16:
case 17:
if (element) {
_context.next = 18;
_context.next = 19;
break;
}
return _context.abrupt(\\"return\\");

case 18:
case 19:
enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
undefined.trigger(\\"__taroRouterChange\\", {
\\"toLocation\\": {
Expand All @@ -3888,12 +3891,12 @@ exports[`compiler-macros - defineAppConfig and definePageConfig should read app
handler.load(page, pageConfig);
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);

case 28:
case 29:
case \\"end\\":
return _context.stop();
}
}
}), _callee, null, [ [ 7, 13 ] ]);
}), _callee, null, [ [ 7, 14 ] ]);
})));
}
var path_to_regexp = __webpack_require__(8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3864,22 +3864,25 @@ exports[`config should build from origin and pipe to output 2`] = `

case 10:
element = _context.sent;
_context.next = 16;
if (element instanceof Array) {
element = element[0];
}
_context.next = 17;
break;

case 13:
_context.prev = 13;
case 14:
_context.prev = 14;
_context.t0 = _context[\\"catch\\"](7);
throw new Error(_context.t0);

case 16:
case 17:
if (element) {
_context.next = 18;
_context.next = 19;
break;
}
return _context.abrupt(\\"return\\");

case 18:
case 19:
enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
undefined.trigger(\\"__taroRouterChange\\", {
\\"toLocation\\": {
Expand All @@ -3900,12 +3903,12 @@ exports[`config should build from origin and pipe to output 2`] = `
handler.load(page, pageConfig);
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);

case 28:
case 29:
case \\"end\\":
return _context.stop();
}
}
}), _callee, null, [ [ 7, 13 ] ]);
}), _callee, null, [ [ 7, 14 ] ]);
})));
}
var path_to_regexp = __webpack_require__(8);
Expand Down Expand Up @@ -8637,22 +8640,25 @@ I m irrelevant.

case 10:
element = _context.sent;
_context.next = 16;
if (element instanceof Array) {
element = element[0];
}
_context.next = 17;
break;

case 13:
_context.prev = 13;
case 14:
_context.prev = 14;
_context.t0 = _context[\\"catch\\"](7);
throw new Error(_context.t0);

case 16:
case 17:
if (element) {
_context.next = 18;
_context.next = 19;
break;
}
return _context.abrupt(\\"return\\");

case 18:
case 19:
enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
undefined.trigger(\\"__taroRouterChange\\", {
\\"toLocation\\": {
Expand All @@ -8673,12 +8679,12 @@ I m irrelevant.
handler.load(page, pageConfig);
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);

case 28:
case 29:
case \\"end\\":
return _context.stop();
}
}
}), _callee, null, [ [ 7, 13 ] ]);
}), _callee, null, [ [ 7, 14 ] ]);
})));
}
var path_to_regexp = __webpack_require__(8);
Expand Down Expand Up @@ -13410,22 +13416,25 @@ exports[`config should resolved alias 2`] = `

case 10:
element = _context.sent;
_context.next = 16;
if (element instanceof Array) {
element = element[0];
}
_context.next = 17;
break;

case 13:
_context.prev = 13;
case 14:
_context.prev = 14;
_context.t0 = _context[\\"catch\\"](7);
throw new Error(_context.t0);

case 16:
case 17:
if (element) {
_context.next = 18;
_context.next = 19;
break;
}
return _context.abrupt(\\"return\\");

case 18:
case 19:
enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
undefined.trigger(\\"__taroRouterChange\\", {
\\"toLocation\\": {
Expand All @@ -13446,12 +13455,12 @@ exports[`config should resolved alias 2`] = `
handler.load(page, pageConfig);
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);

case 28:
case 29:
case \\"end\\":
return _context.stop();
}
}
}), _callee, null, [ [ 7, 13 ] ]);
}), _callee, null, [ [ 7, 14 ] ]);
})));
}
var path_to_regexp = __webpack_require__(8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3881,22 +3881,25 @@ exports[`css modules should use css modules with global mode 2`] = `

case 10:
element = _context.sent;
_context.next = 16;
if (element instanceof Array) {
element = element[0];
}
_context.next = 17;
break;

case 13:
_context.prev = 13;
case 14:
_context.prev = 14;
_context.t0 = _context[\\"catch\\"](7);
throw new Error(_context.t0);

case 16:
case 17:
if (element) {
_context.next = 18;
_context.next = 19;
break;
}
return _context.abrupt(\\"return\\");

case 18:
case 19:
enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
undefined.trigger(\\"__taroRouterChange\\", {
\\"toLocation\\": {
Expand All @@ -3917,12 +3920,12 @@ exports[`css modules should use css modules with global mode 2`] = `
handler.load(page, pageConfig);
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);

case 28:
case 29:
case \\"end\\":
return _context.stop();
}
}
}), _callee, null, [ [ 7, 13 ] ]);
}), _callee, null, [ [ 7, 14 ] ]);
})));
}
var path_to_regexp = __webpack_require__(8);
Expand Down Expand Up @@ -8663,22 +8666,25 @@ exports[`css modules should use css modules with module mode 2`] = `

case 10:
element = _context.sent;
_context.next = 16;
if (element instanceof Array) {
element = element[0];
}
_context.next = 17;
break;

case 13:
_context.prev = 13;
case 14:
_context.prev = 14;
_context.t0 = _context[\\"catch\\"](7);
throw new Error(_context.t0);

case 16:
case 17:
if (element) {
_context.next = 18;
_context.next = 19;
break;
}
return _context.abrupt(\\"return\\");

case 18:
case 19:
enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
undefined.trigger(\\"__taroRouterChange\\", {
\\"toLocation\\": {
Expand All @@ -8699,12 +8705,12 @@ exports[`css modules should use css modules with module mode 2`] = `
handler.load(page, pageConfig);
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);

case 28:
case 29:
case \\"end\\":
return _context.stop();
}
}
}), _callee, null, [ [ 7, 13 ] ]);
}), _callee, null, [ [ 7, 14 ] ]);
})));
}
var path_to_regexp = __webpack_require__(8);
Expand Down
Loading