@foldkit/vite-plugin 0.26.1-canary.fe2701c2fa4b → 0.27.0

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/README.md CHANGED
@@ -98,19 +98,20 @@ The standalone build plugin takes `foldkitBuild(serverEntry, { clientEntry, ...o
98
98
  Each module graph must load one Foldkit copy. The plugin configures Vite for that:
99
99
 
100
100
  - `resolve.dedupe` lists `foldkit`, `@foldkit/ui`, and `@foldkit/devtools`, each only when it resolves from the application root.
101
- - Server builds and the dev server's server render bundle those three packages, plus every installed package whose `dependencies` or `peerDependencies` include `foldkit` or an `@foldkit/*` package, such as `@foldkit/markdown`. In the dev server, these `ssr.noExternal` packages run through Vite's module runner instead of Node's own import. An explicit `ssr.external` entry still keeps a package external.
101
+ - In server builds and in every server environment of the dev server, the plugin bundles those three packages, plus every installed package whose `dependencies` or `peerDependencies` include `foldkit` or an `@foldkit/*` package, such as `@foldkit/markdown`. The plugin lists them in `resolve.noExternal`, which Vite applies to every environment, and in `ssr.noExternal`. In a Node server environment of the dev server, these packages run through Vite's module runner instead of Node's own import. An explicit `ssr.external` or `resolve.external` entry still keeps a package external.
102
102
  - The plugin finds these packages by crawling from the application's `package.json`. It follows the application's `dependencies` and `devDependencies`, then the `dependencies` of each package it bundles, plus the `devDependencies` of a bundled package that is a private workspace package.
103
+ - The plugin excludes `foldkit` from dependency pre-bundling in every environment, so the build id transform runs on it. It also pre-bundles the Effect entries Foldkit imports in every environment whose optimizer is enabled, for example a Cloudflare Worker environment, so Foldkit and the application share one Effect instance. Applications need no `optimizeDeps` settings for Foldkit.
103
104
 
104
- A package the crawl does not reach stays external. For example: a peer the application does not declare, or a package reached only through a package that does not depend on Foldkit. Such a package loads a second Foldkit copy from `node_modules` at runtime. Declare it in the application's `package.json`, or add it to `ssr.noExternal`:
105
+ A package the crawl does not reach stays external. For example: a peer the application does not declare, or a package reached only through a package that does not depend on Foldkit. Such a package loads a second Foldkit copy from `node_modules` at runtime. Declare it in the application's `package.json`, or add it to `resolve.noExternal`, which Vite applies to every environment:
105
106
 
106
107
  ```typescript
107
108
  export default defineConfig({
108
109
  plugins: [foldkit()],
109
- ssr: { noExternal: ['foldkit-component-library'] },
110
+ resolve: { noExternal: ['foldkit-component-library'] },
110
111
  })
111
112
  ```
112
113
 
113
- Vitest copies SSR `noExternal` into `server.deps.inline`. A Vitest config that includes `foldkit()` therefore also inlines the crawled packages in tests.
114
+ Vitest copies each environment's `resolve.noExternal` into `server.deps.inline`. A Vitest config that includes `foldkit()` therefore also inlines the crawled packages in tests.
114
115
 
115
116
  ## Completed build metadata
116
117
 
@@ -12,6 +12,6 @@ export declare const isFoldkitSingletonPackageSpecifier: (specifier: string) =>
12
12
  */
13
13
  export declare const crawlFoldkitPackages: (root: string, isBuild: boolean, viteUserConfig: UserConfig) => Promise<Readonly<{
14
14
  dedupe: Array<string>;
15
- ssrNoExternal: Array<string>;
15
+ noExternal: Array<string>;
16
16
  }>>;
17
17
  //# sourceMappingURL=foldkitPackages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"foldkitPackages.d.ts","sourceRoot":"","sources":["../src/foldkitPackages.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,UAAU,EAA0B,MAAM,MAAM,CAAA;AAS9D;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,cAClC,MAAM,KAChB,OAKA,CAAA;AA8CH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,SACzB,MAAM,WACH,OAAO,kBACA,UAAU,KACzB,OAAO,CACR,QAAQ,CAAC;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CAqClE,CAAA"}
1
+ {"version":3,"file":"foldkitPackages.d.ts","sourceRoot":"","sources":["../src/foldkitPackages.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,UAAU,EAA0B,MAAM,MAAM,CAAA;AAS9D;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,cAClC,MAAM,KAChB,OAKA,CAAA;AA8CH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,SACzB,MAAM,WACH,OAAO,kBACA,UAAU,KACzB,OAAO,CAAC,QAAQ,CAAC;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CAoCxE,CAAA"}
@@ -58,11 +58,11 @@ export const crawlFoldkitPackages = async (root, isBuild, viteUserConfig) => {
58
58
  viteUserConfig,
59
59
  isSemiFrameworkPkgByJson: dependsOnFoldkit,
60
60
  });
61
- const ssrNoExternal = Array.dedupe([
61
+ const noExternal = Array.dedupe([
62
62
  ...FOLDKIT_SINGLETON_PACKAGES,
63
63
  ...crawl.ssr.noExternal,
64
64
  ]);
65
65
  const maybeResolvableSingletons = await Promise.all(Array.map(FOLDKIT_SINGLETON_PACKAGES, async (packageName) => pipe(await findDepPkgJsonPath(packageName, crawlRoot), Option.fromUndefinedOr, Option.as(packageName))));
66
66
  const dedupe = Array.getSomes(maybeResolvableSingletons);
67
- return { dedupe, ssrNoExternal };
67
+ return { dedupe, noExternal };
68
68
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA6CA,OAAO,KAAK,EAEV,MAAM,EAIP,MAAM,MAAM,CAAA;AAOb,OAAO,EAAE,KAAK,mBAAmB,EAAgB,MAAM,YAAY,CAAA;AAKnE,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,UAAU,CAAA;AAG7D,OAAO,EAAE,KAAK,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,YAAY,G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Metadata, fo
19
19
  export { foldkitSsr } from './ssr.js';
20
20
  export { foldkitViewIdentity, transformViewIdentity, } from './viewIdentity.js';
21
21
  // NOTE: Vite does not scan imports through `foldkit` because the plugin
22
- // excludes the package from optimization. A consumer can import only Effect
23
- // subpaths while Foldkit's compiled distribution imports the bare barrel, so
24
- // include both the barrel and every top-level namespace Foldkit imports. This
25
- // keeps them in one optimized dependency graph. Over-inclusion is harmless;
26
- // under-inclusion is the bug. `scripts/check-effect-prebundle.ts` keeps the
27
- // entries in sync with Foldkit's source and runs in `pnpm check`.
22
+ // excludes the package from optimization in every environment. A consumer can
23
+ // import only Effect subpaths while Foldkit's compiled distribution imports the
24
+ // bare barrel, so include both the barrel and every top-level namespace Foldkit
25
+ // imports. This keeps them in one optimized dependency graph. Over-inclusion is
26
+ // harmless; under-inclusion is the bug. `scripts/check-effect-prebundle.ts`
27
+ // keeps the entries in sync with Foldkit's source and runs in `pnpm check`.
28
28
  const FORCE_INCLUDED_EFFECT_ENTRIES = [
29
29
  'effect',
30
30
  'effect/Array',
@@ -70,6 +70,16 @@ const FORCE_INCLUDED_EFFECT_ENTRIES = [
70
70
  'effect/SubscriptionRef',
71
71
  'effect/Types',
72
72
  ];
73
+ // NOTE: Adding includes to an environment whose optimizer is otherwise disabled
74
+ // turns on Vite's explicit optimizer, which would pre-bundle Effect in Vite's
75
+ // default Node `ssr` environment.
76
+ const shouldForceEffectEntries = (name, config) => {
77
+ const consumer = config.consumer ?? (name === 'client' ? 'client' : 'server');
78
+ const isClientEnvironment = consumer === 'client';
79
+ const isDiscoveryEnabled = config.optimizeDeps?.noDiscovery === false;
80
+ const isExplicitOptimizationEnabled = Array.isArrayNonEmpty(config.optimizeDeps?.include ?? []);
81
+ return (isClientEnvironment || isDiscoveryEnabled || isExplicitOptimizationEnabled);
82
+ };
73
83
  const Event = Data.taggedEnum();
74
84
  const makeState = Effect.gen(function* () {
75
85
  const preservedModels = yield* Ref.make(HashMap.empty());
@@ -492,11 +502,15 @@ export const foldkit = (options = {}) => {
492
502
  const reloadPlugin = {
493
503
  name: 'foldkit',
494
504
  apply: 'serve',
495
- config: () => ({
496
- optimizeDeps: {
497
- include: [...FORCE_INCLUDED_EFFECT_ENTRIES],
498
- },
499
- }),
505
+ // NOTE: The `post` order runs this hook after every default-order
506
+ // `configEnvironment` hook, so the predicate sees discovery or includes
507
+ // that another plugin turns on there.
508
+ configEnvironment: {
509
+ order: 'post',
510
+ handler: (name, config) => shouldForceEffectEntries(name, config)
511
+ ? { optimizeDeps: { include: [...FORCE_INCLUDED_EFFECT_ENTRIES] } }
512
+ : undefined,
513
+ },
500
514
  configureServer: server => {
501
515
  const events = Effect.runSync(Queue.unbounded());
502
516
  // NOTE: The default ConfigProvider snapshots the environment. Create a
@@ -526,24 +540,27 @@ export const foldkit = (options = {}) => {
526
540
  config: async (userConfig, { command }) => {
527
541
  const foldkitPackages = await crawlFoldkitPackages(userConfig.root ?? process.cwd(), command === 'build', userConfig);
528
542
  return {
529
- optimizeDeps: {
530
- exclude: ['foldkit'],
531
- },
532
543
  resolve: {
533
544
  dedupe: foldkitPackages.dedupe,
545
+ noExternal: foldkitPackages.noExternal,
534
546
  },
535
547
  ssr: {
536
- noExternal: foldkitPackages.ssrNoExternal,
548
+ noExternal: foldkitPackages.noExternal,
537
549
  },
538
550
  environments: {
539
551
  ssr: {
540
552
  resolve: {
541
- noExternal: foldkitPackages.ssrNoExternal,
553
+ noExternal: foldkitPackages.noExternal,
542
554
  },
543
555
  },
544
556
  },
545
557
  };
546
558
  },
559
+ configEnvironment: () => ({
560
+ optimizeDeps: {
561
+ exclude: ['foldkit'],
562
+ },
563
+ }),
547
564
  };
548
565
  const shared = [
549
566
  resolutionPlugin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldkit/vite-plugin",
3
- "version": "0.26.1-canary.fe2701c2fa4b",
3
+ "version": "0.27.0",
4
4
  "description": "Vite plugin for Foldkit with state-preserving live reload",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "peerDependencies": {
19
19
  "effect": "4.0.0",
20
- "foldkit": "0.166.0-canary.fe2701c2fa4b",
20
+ "foldkit": ">=0.167.0",
21
21
  "vite": "^8.0.0"
22
22
  },
23
23
  "dependencies": {
@@ -32,13 +32,13 @@
32
32
  "@types/ws": "^8.18.1",
33
33
  "@vitejs/plugin-basic-ssl": "^2.3.0",
34
34
  "effect": "4.0.0",
35
+ "foldkit": "0.167.0",
35
36
  "happy-dom": "^20.14.5",
36
37
  "rimraf": "^6.1.3",
37
38
  "typescript": "^7.0.2",
38
39
  "vite": "^8.3.1",
39
40
  "vite-host": "npm:vite@8.2.1",
40
- "vitest": "^4.1.11",
41
- "foldkit": "0.166.0-canary.fe2701c2fa4b"
41
+ "vitest": "^4.1.11"
42
42
  },
43
43
  "keywords": [
44
44
  "vite",