react-cosmos 7.4.2-canary.b4cc31d.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,42 +1,31 @@
1
- import path from 'node:path';
2
1
  import { watch } from 'chokidar';
3
- import micromatch from 'micromatch';
4
- import { slash } from '../utils/slash.js';
5
- import { getDecoratorPatterns, getFixturePatterns } from './shared.js';
2
+ import { isIgnoredPath, isUserModulePath } from './userModulePath.js';
6
3
  const DEBOUNCE_INTERVAL = 50;
7
- export async function startFixtureWatcher(config, event, callback) {
8
- const { rootDir, fixturesDir, fixtureFileSuffix, ignore } = config;
9
- const FILE_PATTERNS = [
10
- ...getFixturePatterns(fixturesDir, fixtureFileSuffix),
11
- ...getDecoratorPatterns(),
12
- ];
4
+ export async function startFixtureWatcher(config, callback) {
13
5
  // Chokidar 4 removed glob support, so the root dir is watched and paths are
14
- // filtered here instead. This mirrors findUserModulePaths: dot entries and
15
- // ignored paths are skipped (chokidar checks a dir before its contents, so it
16
- // never descends into them), and only files matching the fixture and
17
- // decorator patterns are watched. Chokidar passes absolute paths when `cwd`
18
- // is set.
19
- function ignored(filePath, stats) {
20
- const relPath = slash(path.relative(rootDir, filePath));
21
- return (path.basename(relPath).startsWith('.') ||
22
- micromatch.isMatch(relPath, ignore, { dot: true }) ||
23
- (stats?.isFile() === true &&
24
- !micromatch.isMatch(relPath, FILE_PATTERNS, { dot: true })));
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);
25
14
  }
26
15
  // Dirs pass the filter to stay watchable, so only file events call back: a
27
16
  // dir event alone would trigger a needless rescan. Removing a dir also emits
28
17
  // `unlink` for each tracked file in it.
29
18
  const onChange = debounce(() => callback(), DEBOUNCE_INTERVAL);
30
- const fileEvents = event === 'all'
31
- ? ['add', 'change', 'unlink']
32
- : ['add'];
33
19
  return new Promise(resolve => {
34
20
  const watcher = watch('.', {
35
21
  ignored,
36
22
  ignoreInitial: true,
37
- cwd: rootDir,
38
- }).on('ready', () => resolve(watcher));
39
- fileEvents.forEach(e => watcher.on(e, onChange));
23
+ cwd: config.rootDir,
24
+ })
25
+ .on('ready', () => resolve(watcher))
26
+ .on('add', onChange)
27
+ .on('change', onChange)
28
+ .on('unlink', onChange);
40
29
  });
41
30
  }
42
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.b4cc31d.0+b4cc31d",
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.b4cc31d.0+b4cc31d",
19
- "react-cosmos-renderer": "7.4.2-canary.b4cc31d.0+b4cc31d",
20
- "react-cosmos-ui": "7.4.2-canary.b4cc31d.0+b4cc31d",
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": "b4cc31d90e423c1a2146e86cb9855ab88a23ca58"
33
+ "gitHead": "bee4e7021eee5daccdd45e7ca16988b52a20ba2c"
34
34
  }