@foldkit/vite-plugin 0.20.0-canary.65afa5c34cc0 → 0.20.0-canary.786d77603597

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.
@@ -1 +1 @@
1
- {"version":3,"file":"devToolsOverlay.d.ts","sourceRoot":"","sources":["../src/devToolsOverlay.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAmGlC;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,YAC7B,OAAO,GAAG,OAAO,QACpB,MAAM,KACX,OAQF,CAAA;AAED,+EAA+E;AAC/E,eAAO,MAAM,qBAAqB,QAAO,MA6CxC,CAAA"}
1
+ {"version":3,"file":"devToolsOverlay.d.ts","sourceRoot":"","sources":["../src/devToolsOverlay.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAoJlC;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,YAC7B,OAAO,GAAG,OAAO,QACpB,MAAM,KACX,OAQF,CAAA;AAED,+EAA+E;AAC/E,eAAO,MAAM,qBAAqB,QAAO,MA+DxC,CAAA"}
@@ -1,13 +1,29 @@
1
- import { Option, Record, Schema as S } from 'effect';
2
- import { existsSync, readFileSync } from 'node:fs';
3
- import { dirname, join, resolve } from 'node:path';
1
+ import { Array, Option, Record, Schema as S } from 'effect';
2
+ import { existsSync, readFileSync, realpathSync } from 'node:fs';
3
+ import { dirname, join, resolve, sep } from 'node:path';
4
4
  const DEV_TOOLS_PACKAGE_NAME = '@foldkit/devtools';
5
+ const FOLDKIT_PACKAGE_NAME = 'foldkit';
5
6
  const DEV_TOOLS_VITE_EXPORT = './vite';
6
7
  const DEV_TOOLS_OVERLAY_MODULE_ID = 'virtual:foldkit-devtools-overlay';
7
8
  const RESOLVED_DEV_TOOLS_OVERLAY_MODULE_ID = `\0${DEV_TOOLS_OVERLAY_MODULE_ID}`;
9
+ const DEV_TOOLS_VITE_IMPORT_SPECIFIER = `${DEV_TOOLS_PACKAGE_NAME}${DEV_TOOLS_VITE_EXPORT.slice(1)}`;
10
+ const DEV_TOOLS_HOST_IMPORT_SPECIFIER = 'foldkit/devtools-host';
11
+ // NOTE: Vite's dependency scan cannot discover this virtual module's imports.
12
+ // Declaring registry-installed imports before the first request avoids a
13
+ // mid-session reoptimization and page reload.
14
+ const DEV_TOOLS_OVERLAY_IMPORTS = [
15
+ {
16
+ specifier: DEV_TOOLS_VITE_IMPORT_SPECIFIER,
17
+ packageName: DEV_TOOLS_PACKAGE_NAME,
18
+ },
19
+ {
20
+ specifier: DEV_TOOLS_HOST_IMPORT_SPECIFIER,
21
+ packageName: FOLDKIT_PACKAGE_NAME,
22
+ },
23
+ ];
8
24
  const DEV_TOOLS_OVERLAY_MODULE_SOURCE = `
9
- import { overlay } from '@foldkit/devtools/vite'
10
- import { __setDevToolsOverlay } from 'foldkit/devtools-host'
25
+ import { overlay } from '${DEV_TOOLS_VITE_IMPORT_SPECIFIER}'
26
+ import { __setDevToolsOverlay } from '${DEV_TOOLS_HOST_IMPORT_SPECIFIER}'
11
27
 
12
28
  __setDevToolsOverlay(overlay)
13
29
  `;
@@ -46,8 +62,9 @@ const findDirectoryUpward = (directory, isMatch) => {
46
62
  // package is installed, and `resolve.paths` appends this module's own lookup
47
63
  // chain, which under pnpm includes the hoisted virtual store. Both would make
48
64
  // the answer depend on something other than what the application installed.
49
- const devToolsPackageJsonPath = (directory) => join(directory, 'node_modules', DEV_TOOLS_PACKAGE_NAME, 'package.json');
50
- const findDevToolsPackageJsonPath = (root) => findDirectoryUpward(resolve(root), directory => existsSync(devToolsPackageJsonPath(directory))).pipe(Option.map(devToolsPackageJsonPath));
65
+ const installedPackageJsonPath = (directory, packageName) => join(directory, 'node_modules', packageName, 'package.json');
66
+ const findInstalledPackageJsonPath = (root, packageName) => findDirectoryUpward(resolve(root), directory => existsSync(installedPackageJsonPath(directory, packageName))).pipe(Option.map(directory => installedPackageJsonPath(directory, packageName)));
67
+ const findDevToolsPackageJsonPath = (root) => findInstalledPackageJsonPath(root, DEV_TOOLS_PACKAGE_NAME);
51
68
  // NOTE: the virtual module imports `@foldkit/devtools/vite` statically, so an
52
69
  // installed copy that predates that export point would fail the build rather
53
70
  // than quietly skip the overlay. Injecting only when the export exists lets
@@ -58,6 +75,13 @@ const hasDevToolsViteExport = (root) => findDevToolsPackageJsonPath(root).pipe(O
58
75
  // nearest manifest keeps dependency placement meaningful for those layouts.
59
76
  const applicationPackageJsonPath = (directory) => join(directory, 'package.json');
60
77
  const findApplicationPackageJsonPath = (root) => findDirectoryUpward(resolve(root), directory => existsSync(applicationPackageJsonPath(directory))).pipe(Option.map(applicationPackageJsonPath));
78
+ const resolvePackageDirectory = Option.liftThrowable((packageJsonPath) => realpathSync(dirname(packageJsonPath)));
79
+ // NOTE: Vite serves linked packages from source rather than pre-bundling them.
80
+ // A registry-installed package has a real path under `node_modules`, while a
81
+ // workspace link resolves to its source checkout; force-including a link would
82
+ // cache its current source and hide edits. Each owner is checked independently
83
+ // because one package may be linked while the other is installed.
84
+ const isPackageResolvedIntoNodeModules = (root, packageName) => findInstalledPackageJsonPath(root, packageName).pipe(Option.flatMap(resolvePackageDirectory), Option.exists(packageDirectory => packageDirectory.split(sep).includes('node_modules')));
61
85
  const isDevToolsProductionDependency = (root) => findApplicationPackageJsonPath(root).pipe(Option.flatMap(packageJsonPath => readPackageJson(decodeApplicationPackageJson, packageJsonPath)), Option.flatMapNullishOr(packageJson => packageJson.dependencies), Option.exists(Record.has(DEV_TOOLS_PACKAGE_NAME)));
62
86
  /**
63
87
  * Determines whether the Vite integration should include the DevTools overlay.
@@ -81,6 +105,18 @@ export const devToolsOverlayPlugin = () => {
81
105
  let isInjectionEnabled = false;
82
106
  return {
83
107
  name: 'foldkit:devtools-overlay',
108
+ config: (userConfig, environment) => {
109
+ const root = userConfig.root ?? process.cwd();
110
+ if (environment.command !== 'serve' ||
111
+ !shouldInjectDevToolsOverlay(environment.command, root)) {
112
+ return undefined;
113
+ }
114
+ const include = DEV_TOOLS_OVERLAY_IMPORTS.filter(({ packageName }) => isPackageResolvedIntoNodeModules(root, packageName)).map(({ specifier }) => specifier);
115
+ return Array.match(include, {
116
+ onEmpty: () => undefined,
117
+ onNonEmpty: () => ({ optimizeDeps: { include } }),
118
+ });
119
+ },
84
120
  configResolved: config => {
85
121
  isInjectionEnabled = shouldInjectDevToolsOverlay(config.command, config.root);
86
122
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldkit/vite-plugin",
3
- "version": "0.20.0-canary.65afa5c34cc0",
3
+ "version": "0.20.0-canary.786d77603597",
4
4
  "description": "Vite plugin for Foldkit hot module reloading with state preservation",
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-rc.112",
20
- "foldkit": "0.156.0-canary.65afa5c34cc0",
20
+ "foldkit": "0.156.0-canary.786d77603597",
21
21
  "vite": "^7.0.0 || ^8.0.0"
22
22
  },
23
23
  "dependencies": {
@@ -34,7 +34,7 @@
34
34
  "vite": "^8.2.2",
35
35
  "vite7": "npm:vite@^7.3.6",
36
36
  "vitest": "^4.1.11",
37
- "foldkit": "0.156.0-canary.65afa5c34cc0"
37
+ "foldkit": "0.156.0-canary.786d77603597"
38
38
  },
39
39
  "keywords": [
40
40
  "vite",