New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-cosmos

Package Overview
Dependencies
Maintainers
0
Versions
519
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-cosmos - npm Package Compare versions

Comparing version 6.1.2-canary.0d0e717.0 to 6.1.2-canary.15db638.0

dist/vitest.d.ts

3

dist/client.d.ts

@@ -1,1 +0,2 @@

export { FixtureContext, Viewport, useFixtureInput, useFixtureSelect, useFixtureState, useSelect, useValue, } from 'react-cosmos-renderer/client';
export { DecoratorProps } from 'react-cosmos-core';
export { ClassStateMock, FixtureContext, Viewport, useFixtureInput, useFixtureSelect, useFixtureState, useSelect, useValue, } from 'react-cosmos-renderer/client';

@@ -1,1 +0,1 @@

export { FixtureContext, Viewport, useFixtureInput, useFixtureSelect, useFixtureState, useSelect, useValue, } from 'react-cosmos-renderer/client';
export { ClassStateMock, FixtureContext, Viewport, useFixtureInput, useFixtureSelect, useFixtureState, useSelect, useValue, } from 'react-cosmos-renderer/client';

@@ -0,1 +1,2 @@

import { sortBy } from 'lodash-es';
import fs from 'node:fs/promises';

@@ -9,4 +10,4 @@ import path from 'node:path';

devServer({ cosmosConfig, expressApp }) {
expressApp.get('/cosmos.fixtures.json', (req, res) => {
res.json(createFixtureItems(cosmosConfig, 'dev'));
expressApp.get('/cosmos.fixtures.json', async (req, res) => {
res.json(await createFixtureItems(cosmosConfig, 'dev'));
});

@@ -16,7 +17,7 @@ },

const { exportPath } = cosmosConfig;
const json = createFixtureItems(cosmosConfig, 'export');
const json = await createFixtureItems(cosmosConfig, 'export');
await fs.writeFile(path.join(exportPath, 'cosmos.fixtures.json'), JSON.stringify(json, null, 2));
},
};
function createFixtureItems(cosmosConfig, command) {
async function createFixtureItems(cosmosConfig, command) {
const rendererUrl = pickRendererUrl(cosmosConfig.rendererUrl, command);

@@ -30,14 +31,15 @@ if (!rendererUrl) {

const { fixturesDir, fixtureFileSuffix } = cosmosConfig;
const { fixturePaths } = findUserModulePaths(cosmosConfig);
const { fixturePaths } = await findUserModulePaths(cosmosConfig);
const fixtures = fixturePaths.map(filePath => {
const relPath = importKeyPath(filePath, cosmosConfig.rootDir);
const fixtureId = { path: relPath };
return {
filePath: relPath,
cleanPath: cleanFixturePath(relPath, fixturesDir, fixtureFileSuffix),
rendererUrl: createRendererUrl(rendererUrl, fixtureId, true),
};
});
return {
rendererUrl,
fixtures: fixturePaths.map(filePath => {
const relPath = importKeyPath(filePath, cosmosConfig.rootDir);
const fixtureId = { path: relPath };
return {
filePath: relPath,
cleanPath: cleanFixturePath(relPath, fixturesDir, fixtureFileSuffix),
rendererUrl: createRendererUrl(rendererUrl, fixtureId, true),
};
}),
fixtures: sortBy(fixtures, f => f.cleanPath.join('-')),
};

@@ -44,0 +46,0 @@ }

@@ -15,7 +15,7 @@ import fs from 'node:fs/promises';

if (exposeImports) {
const modulePaths = findUserModulePaths(cosmosConfig);
const modulePaths = await findUserModulePaths(cosmosConfig);
await generateImportsFile(cosmosConfig, 'dev', modulePaths);
}
const watcher = await startFixtureWatcher(cosmosConfig, 'all', () => {
const modulePaths = findUserModulePaths(cosmosConfig);
const watcher = await startFixtureWatcher(cosmosConfig, 'all', async () => {
const modulePaths = await findUserModulePaths(cosmosConfig);
updateFixtureListCache(cosmosConfig.rootDir, modulePaths.fixturePaths);

@@ -32,3 +32,3 @@ if (exposeImports) {

if (shouldExposeImports('web', cosmosConfig)) {
const modulePaths = findUserModulePaths(cosmosConfig);
const modulePaths = await findUserModulePaths(cosmosConfig);
await generateImportsFile(cosmosConfig, 'export', modulePaths);

@@ -35,0 +35,0 @@ }

@@ -14,5 +14,5 @@ import { fixtureWatcherPlugin } from './fixtureWatcherPlugin.js';

];
// Omit starting chokidar in Jest tests for performance reasons
if (process.env.JEST_WORKER_ID === undefined) {
// Omit starting chokidar in unit tests for performance reasons
if (process.env.VITEST_WORKER_ID === undefined) {
coreServerPlugins.push(fixtureWatcherPlugin);
}

@@ -1,2 +0,1 @@

/// <reference types="node" />
import express from 'express';

@@ -3,0 +2,0 @@ import http from 'http';

@@ -1,3 +0,1 @@

/// <reference types="node" />
/// <reference types="node" />
import http from 'http';

@@ -4,0 +2,0 @@ import https from 'https';

@@ -1,2 +0,1 @@

/// <reference types="node" />
import http from 'http';

@@ -3,0 +2,0 @@ import { ServerMessage } from 'react-cosmos-core';

@@ -17,3 +17,3 @@ import { ReactElement } from 'react';

};
export declare function getFixtures(cosmosConfig: CosmosConfig, options?: Options): FixtureApi[];
export declare function getFixtures(cosmosConfig: CosmosConfig, options?: Options): Promise<FixtureApi[]>;
export {};

@@ -7,4 +7,4 @@ import { mapValues } from 'lodash-es';

import { importUserModules } from './importUserModules.js';
export function getFixtures(cosmosConfig, options = {}) {
const { fixtures, decorators } = importUserModules(cosmosConfig);
export async function getFixtures(cosmosConfig, options = {}) {
const { fixtures, decorators } = await importUserModules(cosmosConfig);
const fixtureExports = mapValues(fixtures, f => f.default);

@@ -15,2 +15,3 @@ const decoratorExports = mapValues(decorators, f => f.default);

const fixtureExport = fixtures[fixtureId.path].default;
const fixtureOptions = fixtures[fixtureId.path].options ?? {};
const fixture = getFixtureFromExport(fixtureExport, fixtureId.name);

@@ -26,3 +27,3 @@ if (!fixture) {

fileName,
getElement: createFixtureElementGetter(fixture, fixtureId.path, decoratorExports),
getElement: createFixtureElementGetter(fixture, fixtureOptions, fixtureId.path, decoratorExports),
name,

@@ -53,5 +54,5 @@ parents,

}
function createFixtureElementGetter(fixture, fixturePath, decoratorsByPath) {
function createFixtureElementGetter(fixture, fixtureOptions, fixturePath, decoratorsByPath) {
const decorators = getSortedDecoratorsForFixturePath(fixturePath, decoratorsByPath);
return () => decorateFixture(createFixtureNode(fixture), decorators);
return () => decorateFixture(createFixtureNode(fixture), fixtureOptions, decorators);
}

@@ -7,3 +7,3 @@ import { ByPath, ReactDecoratorModule, ReactFixtureModule } from 'react-cosmos-core';

};
export declare function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: CosmosConfig): UserModules;
export declare function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: CosmosConfig): Promise<UserModules>;
export {};
import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
import { importKeyPath } from '../userModules/shared.js';
export function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
const { fixturePaths, decoratorPaths } = findUserModulePaths({
export async function importUserModules({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
const { fixturePaths, decoratorPaths } = await findUserModulePaths({
rootDir,

@@ -11,11 +11,11 @@ fixturesDir,

return {
fixtures: importModules(fixturePaths, rootDir),
decorators: importModules(decoratorPaths, rootDir),
fixtures: await importModules(fixturePaths, rootDir),
decorators: await importModules(decoratorPaths, rootDir),
};
}
function importModules(paths, rootDir) {
const modules = paths.map(p => {
async function importModules(paths, rootDir) {
const modules = await Promise.all(paths.map(async (p) => {
const relPath = importKeyPath(p, rootDir);
return { relPath, module: require(p) };
});
return { relPath, module: await import(p) };
}));
return modules.reduce((acc, { relPath, module }) => ({

@@ -22,0 +22,0 @@ ...acc,

@@ -19,3 +19,2 @@ export { CosmosFixtureJson, CosmosFixturesJson, } from './corePlugins/fixturesJsonPlugin.js';

export * from './utils/fs.js';
export * from './utils/requireSilent.js';
export * from './utils/resolve.js';

@@ -22,0 +21,0 @@ export * from './utils/resolveLoose.js';

@@ -18,3 +18,2 @@ export * from './cosmosConfig/createCosmosConfig.js';

export * from './utils/fs.js';
export * from './utils/requireSilent.js';
export * from './utils/resolve.js';

@@ -21,0 +20,0 @@ export * from './utils/resolveLoose.js';

@@ -15,3 +15,3 @@ import fs from 'fs';

rendererCore: {
fixtures: getServerFixtureList(cosmosConfig),
fixtures: await getServerFixtureList(cosmosConfig),
rendererUrl: platform === 'web'

@@ -32,3 +32,3 @@ ? pickRendererUrl(cosmosConfig.rendererUrl, 'dev')

rendererCore: {
fixtures: getServerFixtureList(cosmosConfig),
fixtures: await getServerFixtureList(cosmosConfig),
rendererUrl: pickRendererUrl(cosmosConfig.rendererUrl, 'export'),

@@ -35,0 +35,0 @@ },

import { FixtureList } from 'react-cosmos-core';
import { CosmosConfig } from '../cosmosConfig/types.js';
export declare function getServerFixtureList(cosmosConfig: CosmosConfig): FixtureList;
export declare function getServerFixtureList(cosmosConfig: CosmosConfig): Promise<FixtureList>;
export declare function updateFixtureListCache(rootDir: string, fixturePaths: string[]): void;
import { findUserModulePaths } from '../userModules/findUserModulePaths.js';
import { importKeyPath } from '../userModules/shared.js';
let fixtureListCache = null;
export function getServerFixtureList(cosmosConfig) {
export async function getServerFixtureList(cosmosConfig) {
if (!fixtureListCache) {
const { fixturePaths } = findUserModulePaths(cosmosConfig);
const { fixturePaths } = await findUserModulePaths(cosmosConfig);
fixtureListCache = createFixtureList(cosmosConfig.rootDir, fixturePaths);

@@ -8,0 +8,0 @@ }

@@ -1,4 +0,11 @@

import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
export function getStaticPath(relPath) {
return fileURLToPath(new URL(`../static/${relPath}`, import.meta.url));
// baseUrl is stored in a variable to bypass Vite's regex-based replacement
// of `import.meta.url` with self.location in jsdom environments.
// https://github.com/vitest-dev/vitest/issues/3988#issuecomment-1686450535
// Why would this code be running in a jsdom environment? Some server tests
// use a jsdom environment in order to simulate WebSocket connections.
// This code only runs on the server in production.
const baseUrl = import.meta.url;
return fileURLToPath(new URL(`../static/${relPath}`, baseUrl));
}

@@ -0,5 +1,6 @@

import { vi } from 'vitest';
export async function mockConsole(cb) {
const expectedLogs = [];
const origConsoleLog = console.log;
console.log = jest.fn((...args) => {
console.log = vi.fn((...args) => {
if (typeof args[0] !== 'string' || !expectedLogs.includes(args[0])) {

@@ -6,0 +7,0 @@ origConsoleLog(...args);

@@ -1,2 +0,2 @@

/// <reference types="jest" />
export declare function mockFetch(httpStatus: number, cb: (fetchMock: jest.Mock) => Promise<unknown>): Promise<void>;
import { Mock } from 'vitest';
export declare function mockFetch(httpStatus: number, cb: (fetchMock: Mock) => Promise<unknown>): Promise<void>;

@@ -0,7 +1,8 @@

import { vi } from 'vitest';
export async function mockFetch(httpStatus, cb) {
const w = window;
const origFetch = window.fetch;
w.fetch = jest.fn(async () => ({ status: httpStatus }));
w.fetch = vi.fn(async () => ({ status: httpStatus }));
await cb(w.fetch);
w.fetch = origFetch;
}
import { CosmosConfig } from '../cosmosConfig/types.js';
export declare function mockFile(filePath: string, fileMock: {}): void;
export declare function mockCosmosConfig(cosmosConfigPath: string, cosmosConfig: Partial<CosmosConfig>): void;
export declare function mockCwdModuleDefault(filePath: string, fileMock: {}): void;
export declare function resetFsMock(): void;
export declare function mockFile(filePath: string, fileMock: {}): Promise<void>;
export declare function mockCosmosConfig(cosmosConfigPath: string, cosmosConfig: Partial<CosmosConfig>): Promise<void>;
export declare function mockCwdModuleDefault(filePath: string, fileMock: {}): Promise<void>;
export declare function resetFsMock(): Promise<void>;
import path from 'node:path';
import { vi } from 'vitest';
import { getCwdPath } from './cwd.js';
jest.mock('../utils/fs', () => {
const actual = jest.requireActual('../utils/fs');
vi.mock('../utils/fs', async () => {
const actual = (await vi.importActual('../utils/fs'));
let mocked = false;

@@ -65,19 +66,19 @@ let fileMocks = {};

});
export function mockFile(filePath, fileMock) {
requireMocked().__mockFile(filePath, fileMock);
requireMocked().__mockDir(path.dirname(filePath));
export async function mockFile(filePath, fileMock) {
(await importMocked()).__mockFile(filePath, fileMock);
(await importMocked()).__mockDir(path.dirname(filePath));
}
export function mockCosmosConfig(cosmosConfigPath, cosmosConfig) {
export async function mockCosmosConfig(cosmosConfigPath, cosmosConfig) {
const absPath = getCwdPath(cosmosConfigPath);
mockFile(absPath, cosmosConfig);
await mockFile(absPath, cosmosConfig);
}
export function mockCwdModuleDefault(filePath, fileMock) {
export async function mockCwdModuleDefault(filePath, fileMock) {
const absPath = getCwdPath(filePath);
mockFile(absPath, { default: fileMock });
await mockFile(absPath, { default: fileMock });
}
export function resetFsMock() {
requireMocked().__resetMock();
export async function resetFsMock() {
(await importMocked()).__resetMock();
}
function requireMocked() {
return require('../utils/fs.js');
async function importMocked() {
return import('../utils/fs.js');
}

@@ -1,2 +0,2 @@

export declare function mockCliArgs(cliArgs: {}): void;
export declare function unmockCliArgs(): void;
export declare function mockCliArgs(cliArgs: {}): Promise<void>;
export declare function unmockCliArgs(): Promise<void>;

@@ -0,4 +1,8 @@

import { vi } from 'vitest';
// Secondary role of mocking yargs: Prevent Cosmos from intercepting the
// --config arg passed to Jest
jest.mock('yargs/yargs', () => {
// --config arg passed to Jest.
// Update: This doesn't seem to be the case with Vitest. The Vitest -c arg is
// not returned by yargs while running the tests, but I'll keep this commment
// in case this changes in the future.
vi.mock('yargs/yargs', () => {
let argv = {};

@@ -12,12 +16,12 @@ const yargs = () => ({

};
return yargs;
return { default: yargs };
});
export function mockCliArgs(cliArgs) {
requireMocked().__mockArgsv(cliArgs);
export async function mockCliArgs(cliArgs) {
(await importMocked()).default.__mockArgsv(cliArgs);
}
export function unmockCliArgs() {
requireMocked().__mockArgsv({});
export async function unmockCliArgs() {
(await importMocked()).default.__mockArgsv({});
}
function requireMocked() {
return require('yargs/yargs');
async function importMocked() {
return import('yargs/yargs');
}

@@ -8,3 +8,3 @@ import { UserModulePaths } from './shared.js';

};
export declare function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: FindUserModulePathsArgs): UserModulePaths;
export declare function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }: FindUserModulePathsArgs): Promise<UserModulePaths>;
export {};

@@ -1,6 +0,6 @@

import { globSync } from 'glob';
import { glob } from 'glob';
import micromatch from 'micromatch';
import { getDecoratorPatterns, getFixturePatterns, } from './shared.js';
export function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
const paths = globSync('**/*', {
export async function findUserModulePaths({ rootDir, fixturesDir, fixtureFileSuffix, ignore, }) {
const paths = await glob('**/*', {
cwd: rootDir,

@@ -7,0 +7,0 @@ absolute: true,

@@ -1,2 +0,1 @@

/// <reference types="node" />
export declare function isNodeError(err: any): err is NodeJS.ErrnoException;
export declare function requireModule(moduleId: string): any;
export declare function requireFrom(fromDirectory: string, moduleId: string): any;
import { createRequire } from 'node:module';
import path from 'path';
// NOTE: This is ESM code that can't run in Jest yet, which means that this
// module always needs to be mocked in tests until Jest adds ESM support.
export function requireModule(moduleId) {

@@ -9,6 +6,1 @@ const require = createRequire(import.meta.url);

}
export function requireFrom(fromDirectory, moduleId) {
// Inspired by https://github.com/sindresorhus/import-from
const require = createRequire(path.resolve(fromDirectory, 'noop.js'));
return require(moduleId);
}
import { createRequire } from 'node:module';
// NOTE: This is ESM code that can't run in Jest yet, which means that this
// module always needs to be mocked in tests until Jest adds ESM support.
// One day this code will be replaced by import.meta.resolve

@@ -5,0 +3,0 @@ // https://nodejs.org/api/esm.html#importmetaresolvespecifier-parent

{
"name": "react-cosmos",
"version": "6.1.2-canary.0d0e717.0+0d0e717",
"version": "6.1.2-canary.15db638.0+15db638",
"description": "Sandbox for developing and testing UI components in isolation",

@@ -11,14 +11,14 @@ "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos",

"@skidding/launch-editor": "2.2.3",
"chokidar": "3.5.3",
"express": "4.18.2",
"glob": "10.3.10",
"chokidar": "3.6.0",
"express": "4.19.2",
"glob": "10.4.5",
"http-proxy-middleware": "2.0.6",
"lodash-es": "4.17.21",
"micromatch": "4.0.5",
"open": "8.4.2",
"micromatch": "4.0.7",
"open": "10.1.0",
"pem": "1.14.8",
"react-cosmos-core": "6.1.2-canary.0d0e717.0+0d0e717",
"react-cosmos-renderer": "6.1.2-canary.0d0e717.0+0d0e717",
"react-cosmos-ui": "6.1.2-canary.0d0e717.0+0d0e717",
"ws": "8.16.0",
"react-cosmos-core": "6.1.2-canary.15db638.0+15db638",
"react-cosmos-renderer": "6.1.2-canary.15db638.0+15db638",
"react-cosmos-ui": "6.1.2-canary.15db638.0+15db638",
"ws": "8.18.0",
"yargs": "17.7.2"

@@ -31,3 +31,3 @@ },

},
"gitHead": "0d0e717b5045febfbaf2bc8e9c840094859d49a4"
"gitHead": "15db6389056d322dd3df5012262cfd620867e49b"
}

@@ -29,7 +29,7 @@ <p align="center">

Our [Code of Conduct](/CODE_OF_CONDUCT.md) applies to all React Cosmos community channels.
Our [Code of Conduct](/.github/CODE_OF_CONDUCT.md) applies to all React Cosmos community channels.
## Contributing
Please see our [CONTRIBUTING.md](/CONTRIBUTING.md).
Please see our [CONTRIBUTING.md](/.github/CONTRIBUTING.md).

@@ -36,0 +36,0 @@ [Become a Sponsor](https://github.com/sponsors/ovidiuch) to support the ongoing development of React Cosmos.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc