@tanstack/router-plugin 1.167.1 → 1.167.3
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/dist/cjs/core/code-splitter/compilers.cjs +63 -34
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs +7 -1
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/react-refresh-ignored-route-exports.cjs +49 -0
- package/dist/cjs/core/code-splitter/plugins/react-refresh-ignored-route-exports.cjs.map +1 -0
- package/dist/cjs/core/code-splitter/plugins/react-refresh-ignored-route-exports.d.cts +2 -0
- package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs +24 -12
- package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/react-stable-hmr-split-route-components.cjs +41 -0
- package/dist/cjs/core/code-splitter/plugins/react-stable-hmr-split-route-components.cjs.map +1 -0
- package/dist/cjs/core/code-splitter/plugins/react-stable-hmr-split-route-components.d.cts +2 -0
- package/dist/cjs/core/code-splitter/plugins.d.cts +13 -0
- package/dist/cjs/core/code-splitter/types.d.cts +9 -0
- package/dist/cjs/core/route-hmr-statement.cjs +58 -15
- package/dist/cjs/core/route-hmr-statement.cjs.map +1 -1
- package/dist/cjs/core/route-hmr-statement.d.cts +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.cjs +3 -3
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +2 -2
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
- package/dist/cjs/core/utils.cjs +9 -1
- package/dist/cjs/core/utils.cjs.map +1 -1
- package/dist/cjs/core/utils.d.cts +1 -0
- package/dist/esm/core/code-splitter/compilers.js +64 -35
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js +7 -1
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/react-refresh-ignored-route-exports.d.ts +2 -0
- package/dist/esm/core/code-splitter/plugins/react-refresh-ignored-route-exports.js +46 -0
- package/dist/esm/core/code-splitter/plugins/react-refresh-ignored-route-exports.js.map +1 -0
- package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js +25 -13
- package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/react-stable-hmr-split-route-components.d.ts +2 -0
- package/dist/esm/core/code-splitter/plugins/react-stable-hmr-split-route-components.js +38 -0
- package/dist/esm/core/code-splitter/plugins/react-stable-hmr-split-route-components.js.map +1 -0
- package/dist/esm/core/code-splitter/plugins.d.ts +13 -0
- package/dist/esm/core/code-splitter/types.d.ts +9 -0
- package/dist/esm/core/route-hmr-statement.d.ts +1 -1
- package/dist/esm/core/route-hmr-statement.js +58 -15
- package/dist/esm/core/route-hmr-statement.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.js +3 -3
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.js +3 -3
- package/dist/esm/core/router-hmr-plugin.js.map +1 -1
- package/dist/esm/core/utils.d.ts +1 -0
- package/dist/esm/core/utils.js +9 -2
- package/dist/esm/core/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/core/code-splitter/compilers.ts +118 -62
- package/src/core/code-splitter/plugins/framework-plugins.ts +7 -1
- package/src/core/code-splitter/plugins/react-refresh-ignored-route-exports.ts +65 -0
- package/src/core/code-splitter/plugins/react-refresh-route-components.ts +68 -39
- package/src/core/code-splitter/plugins/react-stable-hmr-split-route-components.ts +56 -0
- package/src/core/code-splitter/plugins.ts +18 -0
- package/src/core/code-splitter/types.ts +11 -0
- package/src/core/route-hmr-statement.ts +141 -25
- package/src/core/router-code-splitter-plugin.ts +2 -2
- package/src/core/router-hmr-plugin.ts +7 -6
- package/src/core/utils.ts +27 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_constants = require("../constants.cjs");
|
|
3
3
|
const require_route_hmr_statement = require("../route-hmr-statement.cjs");
|
|
4
|
+
const require_utils = require("../utils.cjs");
|
|
4
5
|
const require_path_ids = require("./path-ids.cjs");
|
|
5
6
|
const require_framework_options = require("./framework-options.cjs");
|
|
6
7
|
let _tanstack_router_utils = require("@tanstack/router-utils");
|
|
@@ -166,10 +167,12 @@ function computeSharedBindings(opts) {
|
|
|
166
167
|
const splitGroupsPresent = /* @__PURE__ */ new Set();
|
|
167
168
|
let hasNonSplit = false;
|
|
168
169
|
for (const prop of routeOptions.properties) {
|
|
169
|
-
if (!_babel_types.isObjectProperty(prop)
|
|
170
|
-
|
|
170
|
+
if (!_babel_types.isObjectProperty(prop)) continue;
|
|
171
|
+
const key = require_utils.getObjectPropertyKeyName(prop);
|
|
172
|
+
if (!key) continue;
|
|
173
|
+
if (key === "codeSplitGroupings") continue;
|
|
171
174
|
if (_babel_types.isIdentifier(prop.value) && prop.value.name === "undefined") continue;
|
|
172
|
-
const groupIndex = findIndexForSplitNode(
|
|
175
|
+
const groupIndex = findIndexForSplitNode(key);
|
|
173
176
|
if (groupIndex === -1) hasNonSplit = true;
|
|
174
177
|
else splitGroupsPresent.add(groupIndex);
|
|
175
178
|
}
|
|
@@ -181,8 +184,9 @@ function computeSharedBindings(opts) {
|
|
|
181
184
|
const fullDepGraph = buildDependencyGraph(declMap, allLocalBindings);
|
|
182
185
|
const refsByGroup = /* @__PURE__ */ new Map();
|
|
183
186
|
for (const prop of routeOptions.properties) {
|
|
184
|
-
if (!_babel_types.isObjectProperty(prop)
|
|
185
|
-
const key = prop
|
|
187
|
+
if (!_babel_types.isObjectProperty(prop)) continue;
|
|
188
|
+
const key = require_utils.getObjectPropertyKeyName(prop);
|
|
189
|
+
if (!key) continue;
|
|
186
190
|
if (key === "codeSplitGroupings") continue;
|
|
187
191
|
const groupIndex = findIndexForSplitNode(key);
|
|
188
192
|
const directRefs = collectModuleLevelRefsFromNode(prop.value, localModuleLevelBindings);
|
|
@@ -362,6 +366,7 @@ function compileCodeSplitReferenceRoute(opts) {
|
|
|
362
366
|
const PACKAGE = frameworkOptions.package;
|
|
363
367
|
const LAZY_ROUTE_COMPONENT_IDENT = frameworkOptions.idents.lazyRouteComponent;
|
|
364
368
|
const LAZY_FN_IDENT = frameworkOptions.idents.lazyFn;
|
|
369
|
+
const stableRouteOptionKeys = [...new Set((opts.compilerPlugins ?? []).flatMap((plugin) => plugin.getStableRouteOptionKeys?.() ?? []))];
|
|
365
370
|
let createRouteFn;
|
|
366
371
|
let modified = false;
|
|
367
372
|
let hmrAdded = false;
|
|
@@ -385,20 +390,35 @@ function compileCodeSplitReferenceRoute(opts) {
|
|
|
385
390
|
const hasImportedOrDefinedIdentifier = (name) => {
|
|
386
391
|
return programPath.scope.hasBinding(name);
|
|
387
392
|
};
|
|
393
|
+
const addRouteHmr = (insertionPath, routeOptions) => {
|
|
394
|
+
if (!opts.addHmr || hmrAdded) return;
|
|
395
|
+
opts.compilerPlugins?.forEach((plugin) => {
|
|
396
|
+
if ((plugin.onAddHmr?.({
|
|
397
|
+
programPath,
|
|
398
|
+
callExpressionPath: path,
|
|
399
|
+
insertionPath,
|
|
400
|
+
routeOptions,
|
|
401
|
+
createRouteFn,
|
|
402
|
+
opts
|
|
403
|
+
}))?.modified) modified = true;
|
|
404
|
+
});
|
|
405
|
+
programPath.pushContainer("body", require_route_hmr_statement.createRouteHmrStatement(stableRouteOptionKeys));
|
|
406
|
+
modified = true;
|
|
407
|
+
hmrAdded = true;
|
|
408
|
+
};
|
|
388
409
|
if (_babel_types.isObjectExpression(routeOptions)) {
|
|
410
|
+
const insertionPath = path.getStatementParent() ?? path;
|
|
389
411
|
if (opts.deleteNodes && opts.deleteNodes.size > 0) routeOptions.properties = routeOptions.properties.filter((prop) => {
|
|
390
412
|
if (_babel_types.isObjectProperty(prop)) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
413
|
+
const key = require_utils.getObjectPropertyKeyName(prop);
|
|
414
|
+
if (key && opts.deleteNodes.has(key)) {
|
|
415
|
+
modified = true;
|
|
416
|
+
return false;
|
|
396
417
|
}
|
|
397
418
|
}
|
|
398
419
|
return true;
|
|
399
420
|
});
|
|
400
421
|
if (!splittableCreateRouteFns.includes(createRouteFn)) {
|
|
401
|
-
const insertionPath = path.getStatementParent() ?? path;
|
|
402
422
|
opts.compilerPlugins?.forEach((plugin) => {
|
|
403
423
|
if ((plugin.onUnsplittableRoute?.({
|
|
404
424
|
programPath,
|
|
@@ -409,17 +429,13 @@ function compileCodeSplitReferenceRoute(opts) {
|
|
|
409
429
|
opts
|
|
410
430
|
}))?.modified) modified = true;
|
|
411
431
|
});
|
|
412
|
-
|
|
413
|
-
programPath.pushContainer("body", require_route_hmr_statement.routeHmrStatement);
|
|
414
|
-
modified = true;
|
|
415
|
-
hmrAdded = true;
|
|
416
|
-
}
|
|
432
|
+
addRouteHmr(insertionPath, routeOptions);
|
|
417
433
|
return programPath.stop();
|
|
418
434
|
}
|
|
419
435
|
routeOptions.properties.forEach((prop) => {
|
|
420
436
|
if (_babel_types.isObjectProperty(prop)) {
|
|
421
|
-
|
|
422
|
-
|
|
437
|
+
const key = require_utils.getObjectPropertyKeyName(prop);
|
|
438
|
+
if (key) {
|
|
423
439
|
const codeSplitGroupingByKey = findIndexForSplitNode(key);
|
|
424
440
|
if (codeSplitGroupingByKey === -1) return;
|
|
425
441
|
const codeSplitGroup = [...new Set(opts.codeSplitGroupings[codeSplitGroupingByKey])];
|
|
@@ -442,12 +458,26 @@ function compileCodeSplitReferenceRoute(opts) {
|
|
|
442
458
|
modified = true;
|
|
443
459
|
if (!hasImportedOrDefinedIdentifier(LAZY_ROUTE_COMPONENT_IDENT)) programPath.unshiftContainer("body", [_babel_template.statement(`import { ${LAZY_ROUTE_COMPONENT_IDENT} } from '${PACKAGE}'`)()]);
|
|
444
460
|
if (!hasImportedOrDefinedIdentifier(splitNodeMeta.localImporterIdent)) programPath.unshiftContainer("body", [_babel_template.statement(`const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`)()]);
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
461
|
+
const insertionPath = path.getStatementParent() ?? path;
|
|
462
|
+
let splitPropValue;
|
|
463
|
+
for (const plugin of opts.compilerPlugins ?? []) {
|
|
464
|
+
const pluginPropValue = plugin.onSplitRouteProperty?.({
|
|
465
|
+
programPath,
|
|
466
|
+
callExpressionPath: path,
|
|
467
|
+
insertionPath,
|
|
468
|
+
routeOptions,
|
|
469
|
+
prop,
|
|
470
|
+
splitNodeMeta,
|
|
471
|
+
lazyRouteComponentIdent: LAZY_ROUTE_COMPONENT_IDENT
|
|
472
|
+
});
|
|
473
|
+
if (!pluginPropValue) continue;
|
|
448
474
|
modified = true;
|
|
449
|
-
|
|
475
|
+
splitPropValue = pluginPropValue;
|
|
476
|
+
break;
|
|
450
477
|
}
|
|
478
|
+
if (splitPropValue) prop.value = splitPropValue;
|
|
479
|
+
else prop.value = _babel_template.expression(`${LAZY_ROUTE_COMPONENT_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`)();
|
|
480
|
+
addRouteHmr(insertionPath, routeOptions);
|
|
451
481
|
} else {
|
|
452
482
|
const value = prop.value;
|
|
453
483
|
let shouldSplit = true;
|
|
@@ -469,6 +499,7 @@ function compileCodeSplitReferenceRoute(opts) {
|
|
|
469
499
|
}
|
|
470
500
|
programPath.scope.crawl();
|
|
471
501
|
});
|
|
502
|
+
addRouteHmr(insertionPath, routeOptions);
|
|
472
503
|
}
|
|
473
504
|
}
|
|
474
505
|
if (_babel_types.isCallExpression(path.parentPath.node)) babelHandleReference(resolveIdentifier(path, path.parentPath.node.arguments[0]));
|
|
@@ -544,7 +575,7 @@ function compileCodeSplitVirtualRoute(opts) {
|
|
|
544
575
|
if (_babel_types.isObjectExpression(options)) {
|
|
545
576
|
options.properties.forEach((prop) => {
|
|
546
577
|
if (_babel_types.isObjectProperty(prop)) KNOWN_SPLIT_ROUTE_IDENTS.forEach((splitType) => {
|
|
547
|
-
if (
|
|
578
|
+
if (require_utils.getObjectPropertyKeyName(prop) !== splitType) return;
|
|
548
579
|
const value = prop.value;
|
|
549
580
|
if (_babel_types.isIdentifier(value) && value.name === "undefined") return;
|
|
550
581
|
let isExported = false;
|
|
@@ -738,18 +769,16 @@ function detectCodeSplitGroupingsFromRoute(opts) {
|
|
|
738
769
|
function babelHandleSplittingGroups(routeOptions) {
|
|
739
770
|
if (_babel_types.isObjectExpression(routeOptions)) routeOptions.properties.forEach((prop) => {
|
|
740
771
|
if (_babel_types.isObjectProperty(prop)) {
|
|
741
|
-
if (
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
if (_babel_types.isArrayExpression(
|
|
745
|
-
if (_babel_types.
|
|
746
|
-
|
|
747
|
-
return node.value;
|
|
748
|
-
});
|
|
749
|
-
throw new Error("You must provide arrays with codeSplitGroupings options.");
|
|
772
|
+
if (require_utils.getObjectPropertyKeyName(prop) === "codeSplitGroupings") {
|
|
773
|
+
const value = prop.value;
|
|
774
|
+
if (_babel_types.isArrayExpression(value)) codeSplitGroupings = value.elements.map((group) => {
|
|
775
|
+
if (_babel_types.isArrayExpression(group)) return group.elements.map((node) => {
|
|
776
|
+
if (!_babel_types.isStringLiteral(node)) throw new Error("You must provide a string literal for the codeSplitGroupings");
|
|
777
|
+
return node.value;
|
|
750
778
|
});
|
|
751
|
-
|
|
752
|
-
}
|
|
779
|
+
throw new Error("You must provide arrays with codeSplitGroupings options.");
|
|
780
|
+
});
|
|
781
|
+
else throw new Error("You must provide an array of arrays for the codeSplitGroupings.");
|
|
753
782
|
}
|
|
754
783
|
}
|
|
755
784
|
});
|