react-cosmos 7.4.2-canary.aae77c6.0 → 7.4.2-canary.bee4e70.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.
@@ -15,7 +15,7 @@ export const fixtureWatcherPlugin = {
15
15
  const modulePaths = await findUserModulePaths(config);
16
16
  await generateImportsFile(platform, config, 'dev', modulePaths);
17
17
  }
18
- const watcher = await startFixtureWatcher(config, 'all', async () => {
18
+ const watcher = await startFixtureWatcher(config, async () => {
19
19
  const modulePaths = await findUserModulePaths(config);
20
20
  updateFixtureListCache(config.rootDir, modulePaths.fixturePaths);
21
21
  if (exposeImports) {
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export * from './testHelpers/cwd.js';
17
17
  export * from './userModules/findUserModulePaths.js';
18
18
  export * from './userModules/fixtureWatcher.js';
19
19
  export * from './userModules/generateUserImports.js';
20
+ export * from './userModules/userModulePath.js';
20
21
  export * from './utils/cli.js';
21
22
  export * from './utils/fs.js';
22
23
  export * from './utils/resolve.js';
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ export * from './testHelpers/cwd.js';
16
16
  export * from './userModules/findUserModulePaths.js';
17
17
  export * from './userModules/fixtureWatcher.js';
18
18
  export * from './userModules/generateUserImports.js';
19
+ export * from './userModules/userModulePath.js';
19
20
  export * from './utils/cli.js';
20
21
  export * from './utils/fs.js';
21
22
  export * from './utils/resolve.js';
@@ -1,9 +1,2 @@
1
- import type { UserModulePaths } from './shared.js';
2
- type FindUserModulePathsArgs = {
3
- rootDir: string;
4
- fixturesDir: string;
5
- fixtureFileSuffix: string;
6
- ignore: string[];
7
- };
8
- export declare function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: FindUserModulePathsArgs): Promise<UserModulePaths>;
9
- export {};
1
+ import type { UserModuleConfig, UserModulePaths } from './shared.js';
2
+ export declare function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: UserModuleConfig): Promise<UserModulePaths>;
@@ -1,3 +1,3 @@
1
1
  import type { FSWatcher } from 'chokidar';
2
2
  import type { CosmosConfig } from '../cosmosConfig/types.js';
3
- export declare function startFixtureWatcher(config: CosmosConfig, event: 'all' | 'add', callback: () => unknown): Promise<FSWatcher>;
3
+ export declare function startFixtureWatcher(config: CosmosConfig, callback: () => unknown): Promise<FSWatcher>;
@@ -1,20 +1,31 @@
1
1
  import { watch } from 'chokidar';
2
- import { getDecoratorPatterns, getFixturePatterns } from './shared.js';
2
+ import { isIgnoredPath, isUserModulePath } from './userModulePath.js';
3
3
  const DEBOUNCE_INTERVAL = 50;
4
- export async function startFixtureWatcher(config, event, callback) {
5
- const { fixturesDir, fixtureFileSuffix, ignore } = config;
6
- const FILE_PATTERNS = [
7
- ...getFixturePatterns(fixturesDir, fixtureFileSuffix),
8
- ...getDecoratorPatterns(),
9
- ];
4
+ export async function startFixtureWatcher(config, callback) {
5
+ // Chokidar 4 removed glob support, so the root dir is watched and paths are
6
+ // filtered here instead. Files are watched only if they're user modules.
7
+ // Dirs can't be user modules, so they're only skipped if they're ignored, in
8
+ // which case chokidar doesn't descend into them. Chokidar also calls this
9
+ // before it has stats, when it can't tell files and dirs apart yet.
10
+ function ignored(absPath, stats) {
11
+ return stats?.isFile()
12
+ ? !isUserModulePath(config, absPath)
13
+ : isIgnoredPath(config, absPath);
14
+ }
15
+ // Dirs pass the filter to stay watchable, so only file events call back: a
16
+ // dir event alone would trigger a needless rescan. Removing a dir also emits
17
+ // `unlink` for each tracked file in it.
18
+ const onChange = debounce(() => callback(), DEBOUNCE_INTERVAL);
10
19
  return new Promise(resolve => {
11
- const watcher = watch(FILE_PATTERNS, {
12
- ignored: ignore,
20
+ const watcher = watch('.', {
21
+ ignored,
13
22
  ignoreInitial: true,
14
23
  cwd: config.rootDir,
15
24
  })
16
25
  .on('ready', () => resolve(watcher))
17
- .on(event, debounce(() => callback(), DEBOUNCE_INTERVAL));
26
+ .on('add', onChange)
27
+ .on('change', onChange)
28
+ .on('unlink', onChange);
18
29
  });
19
30
  }
20
31
  function debounce(fn, delay) {
@@ -1,4 +1,6 @@
1
1
  import type { RendererConfig } from 'react-cosmos-core';
2
+ import type { CosmosConfig } from '../cosmosConfig/types.js';
3
+ export type UserModuleConfig = Pick<CosmosConfig, 'rootDir' | 'fixturesDir' | 'fixtureFileSuffix' | 'ignore'>;
2
4
  export type UserModulePaths = {
3
5
  fixturePaths: string[];
4
6
  decoratorPaths: string[];
@@ -0,0 +1,3 @@
1
+ import type { UserModuleConfig } from './shared.js';
2
+ export declare function isIgnoredPath({ rootDir, ignore }: UserModuleConfig, absPath: string): boolean;
3
+ export declare function isUserModulePath(config: UserModuleConfig, absPath: string): boolean;
@@ -0,0 +1,27 @@
1
+ import path from 'node:path';
2
+ import micromatch from 'micromatch';
3
+ import { slash } from '../utils/slash.js';
4
+ import { getDecoratorPatterns, getFixturePatterns } from './shared.js';
5
+ // These check single paths for watchers, which see dirs and files one by one.
6
+ // Like findUserModulePaths, they answer two questions: whether a path is
7
+ // skipped (a skipped dir has no user modules inside), and whether a file that
8
+ // isn't skipped matches the fixture and decorator patterns.
9
+ export function isIgnoredPath({ rootDir, ignore }, absPath) {
10
+ const relPath = slash(path.relative(rootDir, absPath));
11
+ return (
12
+ // On Windows, paths on another drive stay absolute
13
+ path.isAbsolute(relPath) ||
14
+ // Dot entries, which also covers paths outside the root dir (../)
15
+ relPath.split('/').some(segment => segment.startsWith('.')) ||
16
+ micromatch.isMatch(relPath, ignore, { dot: true }));
17
+ }
18
+ export function isUserModulePath(config, absPath) {
19
+ const { rootDir, fixturesDir, fixtureFileSuffix } = config;
20
+ const relPath = slash(path.relative(rootDir, absPath));
21
+ const patterns = [
22
+ ...getFixturePatterns(fixturesDir, fixtureFileSuffix),
23
+ ...getDecoratorPatterns(),
24
+ ];
25
+ return (!isIgnoredPath(config, absPath) &&
26
+ micromatch.isMatch(relPath, patterns, { dot: true }));
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos",
3
- "version": "7.4.2-canary.aae77c6.0+aae77c6",
3
+ "version": "7.4.2-canary.bee4e70.0+bee4e70",
4
4
  "description": "Sandbox for developing and testing UI components in isolation",
5
5
  "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos",
6
6
  "license": "MIT",
@@ -15,9 +15,9 @@
15
15
  "micromatch": "4.0.8",
16
16
  "open": "11.0.0",
17
17
  "pem": "1.14.8",
18
- "react-cosmos-core": "7.4.2-canary.aae77c6.0+aae77c6",
19
- "react-cosmos-renderer": "7.4.2-canary.aae77c6.0+aae77c6",
20
- "react-cosmos-ui": "7.4.2-canary.aae77c6.0+aae77c6",
18
+ "react-cosmos-core": "7.4.2-canary.bee4e70.0+bee4e70",
19
+ "react-cosmos-renderer": "7.4.2-canary.bee4e70.0+bee4e70",
20
+ "react-cosmos-ui": "7.4.2-canary.bee4e70.0+bee4e70",
21
21
  "ws": "8.21.3",
22
22
  "yargs": "18.1.0"
23
23
  },
@@ -30,5 +30,5 @@
30
30
  "cosmos-export": "./bin/cosmos-export.js",
31
31
  "cosmos-native": "./bin/cosmos-native.js"
32
32
  },
33
- "gitHead": "aae77c654b9b437ea5f6e635e6df7fc28924e606"
33
+ "gitHead": "bee4e7021eee5daccdd45e7ca16988b52a20ba2c"
34
34
  }