@timber-js/app 0.2.0-alpha.223 → 0.2.0-alpha.224

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.
@@ -83,6 +83,24 @@ export interface TimberUserConfig {
83
83
  stripSensitiveFields?: boolean | readonly string[];
84
84
  };
85
85
  pageExtensions?: string[];
86
+ /**
87
+ * Import specifiers whose barrel imports timber rewrites to the
88
+ * modules that define the imported names, so `import { Play } from
89
+ * 'lucide-react'` compiles one icon instead of every icon the package
90
+ * re-exports. Applies to production builds, and in dev to server rendering
91
+ * of packages Vite compiles itself: those with a `react` peer dependency
92
+ * (icon sets, component libraries). Dev hands other packages to Node, and
93
+ * the dev client pre-bundles them.
94
+ *
95
+ * Merged with a built-in list (the same one Next.js uses: lucide-react,
96
+ * date-fns, lodash-es, @heroicons/react/*, react-icons/*, …); entries here
97
+ * add to it. Only list a package if its modules do not rely on each other's
98
+ * import-time side effects: the modules not imported no longer load. Entries
99
+ * are exact specifiers: list `react-icons/fa`, not `react-icons`.
100
+ *
101
+ * See design/21-dev-server.md §"Barrel Import Optimization".
102
+ */
103
+ optimizePackageImports?: string[];
86
104
  /**
87
105
  * Slow request threshold in milliseconds. Requests exceeding this emit
88
106
  * a warning via the logger. Set to 0 to disable. Default: 3000.
@@ -1 +1 @@
1
- {"version":3,"file":"config-types.d.ts","sourceRoot":"","sources":["../src/config-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uDAAuD;AACvD,MAAM,WAAW,sBAAsB;IACrC,yEAAyE;IACzE,QAAQ,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC7B;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CAAC,EA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,EAAE,OAAO,CAAC;KAC5B,CAAC;IACF;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;OAEG;IACH,KAAK,CAAC,EAAE;QACN;;;;;;;;;;;WAWG;QACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;KAC/B,CAAC;IACF,SAAS,CAAC,EAAE;QACV,wDAAwD;QACxD,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,qCAAqC;QACrC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,wCAAwC;QACxC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,qDAAqD;QACrD,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,kFAAkF;QAClF,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,kCAAkC;QAClC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"config-validation.d.ts","sourceRoot":"","sources":["../src/config-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,KAAK,CAAC,EAAE,IAAI,CAAC;CACd;AAsCD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,gBAAgB,GAAG,WAAW,EAAE,CAuMtE;AA+ED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,WAAW,EAAE,EACrB,EAAE,KAAY,EAAE,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GACzC,MAA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,IAA2C,GACnE,IAAI,CAKN;AAeD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOpE;AAID,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,IAAI,GAAG,SAAS,CAAC;CAC1B;AAOD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,EAAE,CAmB1E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,MAAM,CAgBnE"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,MAAM,CAAC;AA2CjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAa1D,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAQ1D,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAElG;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,MAAM;CAAG;AAE1B;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAEvE;AAyGD,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,YAAY,EAAE,CAsXhE;eAEc,MAAM"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,MAAM,CAAC;AA4CjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAa1D,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAQ1D,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAElG;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,MAAM;CAAG;AAE1B;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAEvE;AAyGD,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,YAAY,EAAE,CAuXhE;eAEc,MAAM"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as formatMissingPeers, i as checkPeerDependencies, n as timberDevServer, o as reportConfigErrors, s as validateConfig } from "./_chunks/dev-server-C61GWpGg.js";
1
+ import { a as formatMissingPeers, i as checkPeerDependencies, n as timberDevServer, o as reportConfigErrors, s as validateConfig } from "./_chunks/dev-server-B7o4As0l.js";
2
2
  import { i as resolveRenderTimeoutMs } from "./_chunks/render-timeout-MrrqD1wd.js";
3
3
  import { t as writeFileAtomic } from "./_chunks/write-file-atomic-DW8m_Atv.js";
4
4
  import { d as collectInterceptionRewrites, l as getPrerenderExport, n as scanRoutes } from "./_chunks/scanner-CJC-ScJU.js";
@@ -6893,7 +6893,7 @@ function addToMapSet(map, key, value) {
6893
6893
  if (existing) existing.add(value);
6894
6894
  else map.set(key, /* @__PURE__ */ new Set([value]));
6895
6895
  }
6896
- function nameOf(node) {
6896
+ function nameOf$1(node) {
6897
6897
  if (!node) return null;
6898
6898
  if (node.type === "Identifier") return node.name;
6899
6899
  if (node.type === "Literal" && typeof node.value === "string") return node.value;
@@ -6911,7 +6911,7 @@ function collectImportDeclaration(stmt, facts) {
6911
6911
  const source = stmt.source?.value;
6912
6912
  if (typeof source !== "string") return;
6913
6913
  for (const spec of stmt.specifiers ?? []) {
6914
- const local = nameOf(spec.local);
6914
+ const local = nameOf$1(spec.local);
6915
6915
  if (!local) continue;
6916
6916
  if (spec.type === "ImportNamespaceSpecifier") facts.importedBindings.set(local, {
6917
6917
  source,
@@ -6923,7 +6923,7 @@ function collectImportDeclaration(stmt, facts) {
6923
6923
  });
6924
6924
  else if (spec.type === "ImportSpecifier") facts.importedBindings.set(local, {
6925
6925
  source,
6926
- imported: nameOf(spec.imported) ?? local
6926
+ imported: nameOf$1(spec.imported) ?? local
6927
6927
  });
6928
6928
  }
6929
6929
  }
@@ -6942,8 +6942,8 @@ function collectExportNamed(stmt, facts) {
6942
6942
  const specifiers = stmt.specifiers ?? [];
6943
6943
  if (typeof source === "string") {
6944
6944
  for (const spec of specifiers) {
6945
- const imported = nameOf(spec.imported) ?? nameOf(spec.local);
6946
- const exported = nameOf(spec.exported);
6945
+ const imported = nameOf$1(spec.imported) ?? nameOf$1(spec.local);
6946
+ const exported = nameOf$1(spec.exported);
6947
6947
  if (imported && exported) facts.reExports.set(exported, {
6948
6948
  source,
6949
6949
  imported
@@ -6952,8 +6952,8 @@ function collectExportNamed(stmt, facts) {
6952
6952
  return;
6953
6953
  }
6954
6954
  for (const spec of specifiers) {
6955
- const local = nameOf(spec.local);
6956
- const exported = nameOf(spec.exported);
6955
+ const local = nameOf$1(spec.local);
6956
+ const exported = nameOf$1(spec.exported);
6957
6957
  if (local && exported) facts.localExports.set(exported, local);
6958
6958
  }
6959
6959
  const declaration = stmt.declaration;
@@ -6966,7 +6966,7 @@ function collectExportNamed(stmt, facts) {
6966
6966
  function collectExportAll(stmt, facts) {
6967
6967
  const source = stmt.source?.value;
6968
6968
  if (typeof source !== "string") return;
6969
- const exported = nameOf(stmt.exported);
6969
+ const exported = nameOf$1(stmt.exported);
6970
6970
  if (exported) facts.reExports.set(exported, {
6971
6971
  source,
6972
6972
  imported: "*"
@@ -7546,6 +7546,429 @@ function walkSegmentTree(node, fn) {
7546
7546
  if (node.children) for (const child of node.children) walkSegmentTree(child, fn);
7547
7547
  if (node.slots) for (const slot of Object.values(node.slots)) walkSegmentTree(slot, fn);
7548
7548
  }
7549
+ // src/plugins/optimize-package-imports-defaults.ts
7550
+ /**
7551
+ * Import specifiers whose barrel imports timber rewrites by default.
7552
+ *
7553
+ * Copied from Next.js's built-in `optimizePackageImports` list
7554
+ * (packages/next/src/server/config.ts, vercel/next.js@50bf604f2), so an app
7555
+ * moving from Next gets the same set without configuring it. Entries are exact
7556
+ * import specifiers, not package names: a package with several icon entry
7557
+ * points (`react-icons/fa`, `@heroicons/react/24/solid`) lists each one.
7558
+ *
7559
+ * See design/21-dev-server.md §"Barrel Import Optimization".
7560
+ */
7561
+ var DEFAULT_OPTIMIZE_PACKAGE_IMPORTS = [
7562
+ "lucide-react",
7563
+ "date-fns",
7564
+ "lodash-es",
7565
+ "ramda",
7566
+ "antd",
7567
+ "react-bootstrap",
7568
+ "ahooks",
7569
+ "@ant-design/icons",
7570
+ "@headlessui/react",
7571
+ "@headlessui-float/react",
7572
+ "@heroicons/react/20/solid",
7573
+ "@heroicons/react/24/solid",
7574
+ "@heroicons/react/24/outline",
7575
+ "@visx/visx",
7576
+ "@tremor/react",
7577
+ "rxjs",
7578
+ "@mui/material",
7579
+ "@mui/icons-material",
7580
+ "recharts",
7581
+ "react-use",
7582
+ "effect",
7583
+ "@effect/schema",
7584
+ "@effect/platform",
7585
+ "@effect/platform-node",
7586
+ "@effect/platform-browser",
7587
+ "@effect/platform-bun",
7588
+ "@effect/sql",
7589
+ "@effect/sql-mssql",
7590
+ "@effect/sql-mysql2",
7591
+ "@effect/sql-pg",
7592
+ "@effect/sql-sqlite-node",
7593
+ "@effect/sql-sqlite-bun",
7594
+ "@effect/sql-sqlite-wasm",
7595
+ "@effect/sql-sqlite-react-native",
7596
+ "@effect/rpc",
7597
+ "@effect/rpc-http",
7598
+ "@effect/typeclass",
7599
+ "@effect/experimental",
7600
+ "@effect/opentelemetry",
7601
+ "@material-ui/core",
7602
+ "@material-ui/icons",
7603
+ "@tabler/icons-react",
7604
+ "mui-core",
7605
+ "react-icons/ai",
7606
+ "react-icons/bi",
7607
+ "react-icons/bs",
7608
+ "react-icons/cg",
7609
+ "react-icons/ci",
7610
+ "react-icons/di",
7611
+ "react-icons/fa",
7612
+ "react-icons/fa6",
7613
+ "react-icons/fc",
7614
+ "react-icons/fi",
7615
+ "react-icons/gi",
7616
+ "react-icons/go",
7617
+ "react-icons/gr",
7618
+ "react-icons/hi",
7619
+ "react-icons/hi2",
7620
+ "react-icons/im",
7621
+ "react-icons/io",
7622
+ "react-icons/io5",
7623
+ "react-icons/lia",
7624
+ "react-icons/lib",
7625
+ "react-icons/lu",
7626
+ "react-icons/md",
7627
+ "react-icons/pi",
7628
+ "react-icons/ri",
7629
+ "react-icons/rx",
7630
+ "react-icons/si",
7631
+ "react-icons/sl",
7632
+ "react-icons/tb",
7633
+ "react-icons/tfi",
7634
+ "react-icons/ti",
7635
+ "react-icons/vsc",
7636
+ "react-icons/wi"
7637
+ ];
7638
+ // src/plugins/optimize-package-imports.ts
7639
+ /**
7640
+ * timber-optimize-package-imports — rewrites named imports from a listed
7641
+ * barrel package into imports of only the modules that define those names.
7642
+ *
7643
+ * In dev, `@vitejs/plugin-rsc` keeps packages with a `react` peer dependency
7644
+ * in the rsc and ssr module graphs without pre-bundling them, so on the server
7645
+ * `import { Play } from 'lucide-react'` enters lucide's barrel and Vite
7646
+ * transforms all ~2,000 icon modules it re-exports, once per environment. A
7647
+ * build loads all of them too, before tree-shaking. The
7648
+ * rewrite turns that import into one of the icon's own file:
7649
+ *
7650
+ * import { Play } from 'lucide-react'
7651
+ * → import { default as Play } from "/…/lucide-react/dist/esm/icons/play.mjs";
7652
+ *
7653
+ * Next.js does the same for its `optimizePackageImports` list
7654
+ * (next-barrel-loader.ts, optimize_barrel.rs). It applies to every environment
7655
+ * in builds; in dev, to the server environments and only for packages Vite
7656
+ * compiles itself (the client environment pre-bundles them; the server
7657
+ * environments hand most other packages to Node). See design/21-dev-server.md
7658
+ * §"Barrel Import Optimization".
7659
+ *
7660
+ * Every rule here leans toward leaving the import alone. A missed rewrite costs
7661
+ * compile time; a wrong one breaks the app. An import is rewritten only when
7662
+ * the barrel is a pure barrel (nothing but imports and re-exports) and every
7663
+ * imported name is in its export map with a target that resolves to a file.
7664
+ */
7665
+ /**
7666
+ * Merge the user's list with the defaults (Next's semantics: the user list
7667
+ * adds, never replaces). Config validation reports invalid entries without
7668
+ * stopping the dev server, so only the valid ones (non-empty strings) are used
7669
+ * here; a string list is not spread into characters, and an empty entry does
7670
+ * not match every quoted empty string.
7671
+ */
7672
+ function resolveOptimizedPackages(user) {
7673
+ const extra = Array.isArray(user) ? user.filter((entry) => typeof entry === "string" && entry.trim() !== "") : [];
7674
+ return /* @__PURE__ */ new Set([...DEFAULT_OPTIMIZE_PACKAGE_IMPORTS, ...extra]);
7675
+ }
7676
+ function nameOf(node) {
7677
+ return node.type === "Literal" ? node.value : node.name;
7678
+ }
7679
+ /**
7680
+ * Read a barrel's export map, or null when the file is not a pure barrel.
7681
+ *
7682
+ * A pure barrel holds only imports, re-exports, and `export { local }` of an
7683
+ * imported binding (`import * as icons from './icons'; export { icons }`, which
7684
+ * lucide-react's barrel opens with). Anything that runs code of its own, a
7685
+ * declaration, an expression, a bare side-effect import, makes it not a barrel:
7686
+ * importing past it would skip that code. So does any directive except
7687
+ * `'use strict'`: a `'use client'` or `'use server'` barrel is a boundary
7688
+ * plugin-rsc draws around the barrel module itself, and importing past it would
7689
+ * load the re-exported files on the wrong side of it.
7690
+ *
7691
+ * `export default local` is not followed even when `local` is imported: it
7692
+ * exports the value `local` held when the barrel ran, not a live binding, so
7693
+ * importing `local` directly would see later reassignments the barrel's
7694
+ * default never does. `export { local as default }` is live and is followed.
7695
+ *
7696
+ * A source-phase or deferred import, or import attributes, change what the
7697
+ * barrel's binding is, so a barrel using them is not followed. An
7698
+ * `export {} from` with no names only runs the module, like a bare import.
7699
+ *
7700
+ * `export * from` adds no entries. A name it might supply is not in the map, so
7701
+ * an import of that name falls back; explicit exports shadow star exports, so
7702
+ * every name that is in the map is exact.
7703
+ */
7704
+ function readBarrelExportMap(code, lang) {
7705
+ let program;
7706
+ try {
7707
+ program = parseAst(code, { lang });
7708
+ } catch {
7709
+ return null;
7710
+ }
7711
+ const imported = /* @__PURE__ */ new Map();
7712
+ for (const item of program.body) {
7713
+ if (item.type !== "ImportDeclaration" || item.importKind === "type") continue;
7714
+ const source = item.source.value;
7715
+ for (const spec of item.specifiers) if (spec.type === "ImportSpecifier") {
7716
+ if (spec.importKind === "type") continue;
7717
+ imported.set(spec.local.name, {
7718
+ source,
7719
+ imported: nameOf(spec.imported)
7720
+ });
7721
+ } else if (spec.type === "ImportDefaultSpecifier") imported.set(spec.local.name, {
7722
+ source,
7723
+ imported: "default"
7724
+ });
7725
+ else imported.set(spec.local.name, {
7726
+ source,
7727
+ imported: "*"
7728
+ });
7729
+ }
7730
+ const exports = /* @__PURE__ */ new Map();
7731
+ for (const item of program.body) switch (item.type) {
7732
+ case "ExpressionStatement":
7733
+ if ("directive" in item && item.directive === "use strict") continue;
7734
+ return null;
7735
+ case "ImportDeclaration":
7736
+ if (item.importKind === "type") continue;
7737
+ if (item.specifiers.length === 0 || item.phase !== null || item.attributes.length > 0) return null;
7738
+ continue;
7739
+ case "ExportAllDeclaration":
7740
+ if (item.exportKind === "type") continue;
7741
+ if (item.attributes.length > 0) return null;
7742
+ if (item.exported) exports.set(nameOf(item.exported), {
7743
+ source: item.source.value,
7744
+ imported: "*"
7745
+ });
7746
+ continue;
7747
+ case "ExportNamedDeclaration":
7748
+ if (item.exportKind === "type") continue;
7749
+ if (item.declaration || item.attributes.length > 0) return null;
7750
+ if (item.source && item.specifiers.length === 0) return null;
7751
+ for (const spec of item.specifiers) {
7752
+ if (spec.exportKind === "type") continue;
7753
+ const local = nameOf(spec.local);
7754
+ const origin = item.source ? {
7755
+ source: item.source.value,
7756
+ imported: local
7757
+ } : imported.get(local);
7758
+ if (!origin) return null;
7759
+ exports.set(nameOf(spec.exported), origin);
7760
+ }
7761
+ continue;
7762
+ case "TSInterfaceDeclaration":
7763
+ case "TSTypeAliasDeclaration": continue;
7764
+ default: return null;
7765
+ }
7766
+ return exports;
7767
+ }
7768
+ var IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
7769
+ /** An export name as it must be written in an import or export clause. */
7770
+ function clauseName(name) {
7771
+ return IDENTIFIER_RE.test(name) ? name : JSON.stringify(name);
7772
+ }
7773
+ /**
7774
+ * The bindings a statement takes from `source`, or null when the statement is
7775
+ * not a candidate: a namespace import, `import type`, an import attribute, a
7776
+ * source phase import, or a statement with no value bindings.
7777
+ */
7778
+ function statementBindings(item) {
7779
+ if (item.attributes.length > 0) return null;
7780
+ const bindings = [];
7781
+ if (item.type === "ImportDeclaration") {
7782
+ if (item.importKind === "type" || item.phase !== null) return null;
7783
+ for (const spec of item.specifiers) {
7784
+ if (spec.type === "ImportNamespaceSpecifier") return null;
7785
+ if (spec.type === "ImportDefaultSpecifier") bindings.push({
7786
+ barrelName: "default",
7787
+ as: spec.local.name
7788
+ });
7789
+ else if (spec.importKind !== "type") bindings.push({
7790
+ barrelName: nameOf(spec.imported),
7791
+ as: spec.local.name
7792
+ });
7793
+ }
7794
+ } else {
7795
+ if (item.exportKind === "type" || item.declaration) return null;
7796
+ for (const spec of item.specifiers) {
7797
+ if (spec.exportKind === "type") continue;
7798
+ bindings.push({
7799
+ barrelName: nameOf(spec.local),
7800
+ as: nameOf(spec.exported)
7801
+ });
7802
+ }
7803
+ }
7804
+ return bindings.length > 0 ? bindings : null;
7805
+ }
7806
+ /** The replacement statements for one candidate, or null to leave it alone. */
7807
+ async function rewriteStatement(item, barrel) {
7808
+ const bindings = statementBindings(item);
7809
+ if (!bindings) return null;
7810
+ const out = [];
7811
+ for (const { barrelName, as } of bindings) {
7812
+ const origin = barrel.exports.get(barrelName);
7813
+ if (!origin) return null;
7814
+ const target = await barrel.resolveTarget(origin.source);
7815
+ if (!target) return null;
7816
+ const from = JSON.stringify(target);
7817
+ if (item.type === "ImportDeclaration") out.push(origin.imported === "*" ? `import * as ${as} from ${from};` : `import { ${clauseName(origin.imported)} as ${as} } from ${from};`);
7818
+ else out.push(origin.imported === "*" ? `export * as ${clauseName(as)} from ${from};` : `export { ${clauseName(origin.imported)} as ${clauseName(as)} } from ${from};`);
7819
+ }
7820
+ return out.join(" ");
7821
+ }
7822
+ /**
7823
+ * Rewrite every import and `export { … } from` of a listed specifier whose
7824
+ * names the barrel's export map covers. Returns null when nothing changed.
7825
+ *
7826
+ * Replacements stay on the statement's own lines, so positions after it keep
7827
+ * their line numbers even before the source map is applied.
7828
+ */
7829
+ async function rewriteBarrelImports(code, packages, loadBarrel) {
7830
+ let program;
7831
+ try {
7832
+ program = parseAst(code, { lang: "js" });
7833
+ } catch {
7834
+ return null;
7835
+ }
7836
+ let s = null;
7837
+ const barrels = /* @__PURE__ */ new Map();
7838
+ for (const item of program.body) {
7839
+ if (item.type !== "ImportDeclaration" && item.type !== "ExportNamedDeclaration") continue;
7840
+ const specifier = item.source?.value;
7841
+ if (specifier === void 0 || !packages.has(specifier)) continue;
7842
+ let barrel = barrels.get(specifier);
7843
+ if (barrel === void 0) {
7844
+ barrel = await loadBarrel(specifier);
7845
+ barrels.set(specifier, barrel);
7846
+ }
7847
+ if (!barrel) continue;
7848
+ const replacement = await rewriteStatement(item, barrel);
7849
+ if (replacement === null) continue;
7850
+ s ??= new MagicString(code);
7851
+ const lineBreaks = code.slice(item.start, item.end).split("\n").length - 1;
7852
+ s.overwrite(item.start, item.end, replacement + "\n".repeat(lineBreaks));
7853
+ }
7854
+ return s;
7855
+ }
7856
+ /** The npm package a bare specifier names: `@scope/pkg/sub` → `@scope/pkg`. */
7857
+ function packageNameOf(specifier) {
7858
+ const parts = specifier.split("/");
7859
+ return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
7860
+ }
7861
+ /**
7862
+ * Whether the environment loads `specifier` through Vite rather than handing
7863
+ * it to Node. Only those imports are rewritten.
7864
+ *
7865
+ * A server environment externalizes most of node_modules in dev: Node loads
7866
+ * the package natively, so its barrel costs nothing to compile. Rewriting such
7867
+ * an import to a file path would pull that file into Vite's module graph
7868
+ * while any other import of the package stayed external, two instances of one
7869
+ * module. In dev, plugin-rsc keeps packages with a `react` peer dependency
7870
+ * (lucide-react, the icon sets, the component libraries) out of
7871
+ * externalization, and timber's production build sets `noExternal: true`.
7872
+ *
7873
+ * Vite's own check is internal, so this is its conservative subset: the
7874
+ * package must match `resolve.noExternal` exactly (a string or a RegExp) and
7875
+ * `resolve.external` must not name it. A glob string in `noExternal` does
7876
+ * not match here, which only costs the optimization.
7877
+ */
7878
+ function isLoadedThroughVite(specifier, config) {
7879
+ const pkg = packageNameOf(specifier);
7880
+ const { noExternal, external } = config;
7881
+ if (external === true || external.includes(specifier) || external.includes(pkg)) return false;
7882
+ if (noExternal === true) return true;
7883
+ return (Array.isArray(noExternal) ? noExternal : [noExternal]).some((p) => typeof p === "string" ? p === pkg : p.test(pkg));
7884
+ }
7885
+ function langForFile(file) {
7886
+ if (file.endsWith(".tsx")) return "tsx";
7887
+ if (/\.[mc]?ts$/.test(file)) return "ts";
7888
+ if (file.endsWith(".jsx")) return "jsx";
7889
+ return "js";
7890
+ }
7891
+ /**
7892
+ * A resolved id as a plain file import, or null when it is not one (virtual,
7893
+ * relative, or carrying a query that changes what the module is).
7894
+ *
7895
+ * Vite's dev resolver appends `?v=<hash>` to files under node_modules, in the
7896
+ * server environments too, and appends the same query again when it resolves
7897
+ * the absolute path this rewrite emits. So the query is dropped, never copied:
7898
+ * the emitted path resolves to the same id the barrel's own import would, which
7899
+ * keeps one module instance per file.
7900
+ */
7901
+ function asFilePath(id) {
7902
+ const path = id.replace(/\?v=[\w.-]+$/, "");
7903
+ return isAbsolute(path) && !path.includes("?") && !path.includes("\0") ? path : null;
7904
+ }
7905
+ function escapeRegExp(text) {
7906
+ return text.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
7907
+ }
7908
+ function timberOptimizePackageImports(ctx) {
7909
+ let packages = /* @__PURE__ */ new Set();
7910
+ let isDev = false;
7911
+ let mentionsListed = /(?!)/;
7912
+ const exportMaps = /* @__PURE__ */ new Map();
7913
+ const targets = /* @__PURE__ */ new Map();
7914
+ const isInstalled = (path) => path.includes("/node_modules/");
7915
+ function exportMapFor(barrelPath) {
7916
+ const cached = exportMaps.get(barrelPath);
7917
+ if (cached !== void 0) return cached;
7918
+ let code;
7919
+ try {
7920
+ code = readFileSync(barrelPath, "utf8");
7921
+ } catch {
7922
+ return null;
7923
+ }
7924
+ const map = readBarrelExportMap(code, langForFile(barrelPath));
7925
+ if (isInstalled(barrelPath)) exportMaps.set(barrelPath, map);
7926
+ return map;
7927
+ }
7928
+ return {
7929
+ name: "timber-optimize-package-imports",
7930
+ configResolved(config) {
7931
+ isDev = config.command === "serve";
7932
+ packages = resolveOptimizedPackages(ctx.config.optimizePackageImports);
7933
+ const alternatives = [...packages].map(escapeRegExp).join("|");
7934
+ mentionsListed = new RegExp(`(["'])(?:${alternatives})\\1`);
7935
+ },
7936
+ async transform(code, id) {
7937
+ if (isDev && this.environment.config.consumer !== "server") return null;
7938
+ if (id.startsWith("\0") || !mentionsListed.test(code)) return null;
7939
+ const envName = this.environment.name;
7940
+ const { consumer, resolve } = this.environment.config;
7941
+ const s = await rewriteBarrelImports(code, packages, async (specifier) => {
7942
+ if (consumer === "server" && !isLoadedThroughVite(specifier, resolve)) return null;
7943
+ const resolved = await this.resolve(specifier, id);
7944
+ const barrelPath = resolved && !resolved.external ? asFilePath(resolved.id) : null;
7945
+ if (!barrelPath) return null;
7946
+ const installed = isInstalled(barrelPath);
7947
+ if (!installed) this.addWatchFile(barrelPath);
7948
+ const exports = exportMapFor(barrelPath);
7949
+ if (!exports) return null;
7950
+ return {
7951
+ exports,
7952
+ resolveTarget: async (source) => {
7953
+ if (!source.startsWith("./") && !source.startsWith("../")) return null;
7954
+ const key = `${envName}\0${barrelPath}\0${source}`;
7955
+ const cached = targets.get(key);
7956
+ if (cached !== void 0) return cached;
7957
+ const target = await this.resolve(source, barrelPath);
7958
+ const path = target && !target.external ? asFilePath(target.id) : null;
7959
+ if (installed) targets.set(key, path);
7960
+ return path;
7961
+ }
7962
+ };
7963
+ });
7964
+ if (!s) return null;
7965
+ return {
7966
+ code: s.toString(),
7967
+ map: s.generateMap({ hires: "boundary" })
7968
+ };
7969
+ }
7970
+ };
7971
+ }
7549
7972
  // src/plugins/callsite-jsx.ts
7550
7973
  /**
7551
7974
  * Try to extract a static JSON-safe value from an AST expression node.
@@ -9827,6 +10250,7 @@ function timber(config) {
9827
10250
  timberBuildManifest(ctx),
9828
10251
  fonts,
9829
10252
  timberMdx(ctx),
10253
+ timberOptimizePackageImports(ctx),
9830
10254
  timberRequestDep(ctx),
9831
10255
  timberCacheTransform(ctx),
9832
10256
  timberPrerenderSugar(ctx),