react-cosmos 7.4.1 → 7.4.2-canary.b4cc31d.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.
@@ -32,7 +32,10 @@ async function createFixtureItems(config, mode) {
32
32
  return {
33
33
  filePath: relPath,
34
34
  cleanPath: cleanFixturePath(relPath, fixturesDir, fixtureFileSuffix),
35
- rendererUrl: createRendererUrl(rendererUrl, fixtureId, true),
35
+ rendererUrl: createRendererUrl(rendererUrl, {
36
+ fixtureId,
37
+ detached: true,
38
+ }),
36
39
  };
37
40
  });
38
41
  return {
@@ -27,7 +27,10 @@ export async function getFixtures(config, options = {}) {
27
27
  playgroundUrl: getPlaygroundFixtureUrl(config, fixtureId),
28
28
  relativeFilePath: fixtureId.path,
29
29
  rendererUrl: options.rendererUrl
30
- ? createRendererUrl(options.rendererUrl, fixtureId)
30
+ ? createRendererUrl(options.rendererUrl, {
31
+ fixtureId,
32
+ detached: true,
33
+ })
31
34
  : null,
32
35
  treePath,
33
36
  });
@@ -1,20 +1,42 @@
1
+ import path from 'node:path';
1
2
  import { watch } from 'chokidar';
3
+ import micromatch from 'micromatch';
4
+ import { slash } from '../utils/slash.js';
2
5
  import { getDecoratorPatterns, getFixturePatterns } from './shared.js';
3
6
  const DEBOUNCE_INTERVAL = 50;
4
7
  export async function startFixtureWatcher(config, event, callback) {
5
- const { fixturesDir, fixtureFileSuffix, ignore } = config;
8
+ const { rootDir, fixturesDir, fixtureFileSuffix, ignore } = config;
6
9
  const FILE_PATTERNS = [
7
10
  ...getFixturePatterns(fixturesDir, fixtureFileSuffix),
8
11
  ...getDecoratorPatterns(),
9
12
  ];
13
+ // 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 })));
25
+ }
26
+ // Dirs pass the filter to stay watchable, so only file events call back: a
27
+ // dir event alone would trigger a needless rescan. Removing a dir also emits
28
+ // `unlink` for each tracked file in it.
29
+ const onChange = debounce(() => callback(), DEBOUNCE_INTERVAL);
30
+ const fileEvents = event === 'all'
31
+ ? ['add', 'change', 'unlink']
32
+ : ['add'];
10
33
  return new Promise(resolve => {
11
- const watcher = watch(FILE_PATTERNS, {
12
- ignored: ignore,
34
+ const watcher = watch('.', {
35
+ ignored,
13
36
  ignoreInitial: true,
14
- cwd: config.rootDir,
15
- })
16
- .on('ready', () => resolve(watcher))
17
- .on(event, debounce(() => callback(), DEBOUNCE_INTERVAL));
37
+ cwd: rootDir,
38
+ }).on('ready', () => resolve(watcher));
39
+ fileEvents.forEach(e => watcher.on(e, onChange));
18
40
  });
19
41
  }
20
42
  function debounce(fn, delay) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos",
3
- "version": "7.4.1",
3
+ "version": "7.4.2-canary.b4cc31d.0+b4cc31d",
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.0",
19
- "react-cosmos-renderer": "^7.4.0",
20
- "react-cosmos-ui": "^7.4.0",
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",
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": "aa2d7824289241837bd1eabf981f29db2e675b74"
33
+ "gitHead": "b4cc31d90e423c1a2146e86cb9855ab88a23ca58"
34
34
  }