How to use mainFields method in storybook-root

Best JavaScript code snippet using storybook-root

match-path-async.js

Source:match-path-async.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3var path = require("path");4var TryPath = require("./try-path");5var MappingEntry = require("./mapping-entry");6var Filesystem = require("./filesystem");7/**8 * See the sync version for docs.9 */10function createMatchPathAsync(absoluteBaseUrl, paths, mainFields, addMatchAll) {11 if (mainFields === void 0) { mainFields = ["main"]; }12 if (addMatchAll === void 0) { addMatchAll = true; }13 var absolutePaths = MappingEntry.getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll);14 return function (requestedModule, readJson, fileExists, extensions, callback) {15 return matchFromAbsolutePathsAsync(absolutePaths, requestedModule, readJson, fileExists, extensions, callback, mainFields);16 };17}18exports.createMatchPathAsync = createMatchPathAsync;19/**20 * See the sync version for docs.21 */22function matchFromAbsolutePathsAsync(absolutePathMappings, requestedModule, readJson, fileExists, extensions, callback, mainFields) {23 if (readJson === void 0) { readJson = Filesystem.readJsonFromDiskAsync; }24 if (fileExists === void 0) { fileExists = Filesystem.fileExistsAsync; }25 if (extensions === void 0) { extensions = Object.keys(require.extensions); }26 if (mainFields === void 0) { mainFields = ["main"]; }27 var tryPaths = TryPath.getPathsToTry(extensions, absolutePathMappings, requestedModule);28 if (!tryPaths) {29 return callback();30 }31 findFirstExistingPath(tryPaths, readJson, fileExists, callback, 0, mainFields);32}33exports.matchFromAbsolutePathsAsync = matchFromAbsolutePathsAsync;34function findFirstExistingMainFieldMappedFile(packageJson, mainFields, packageJsonPath, fileExistsAsync, doneCallback, index) {35 if (index === void 0) { index = 0; }36 if (index >= mainFields.length) {37 return doneCallback(undefined, undefined);38 }39 var tryNext = function () {40 return findFirstExistingMainFieldMappedFile(packageJson, mainFields, packageJsonPath, fileExistsAsync, doneCallback, index + 1);41 };42 var mainFieldMapping = packageJson[mainFields[index]];43 if (typeof mainFieldMapping !== "string") {44 // Skip mappings that are not pointers to replacement files45 return tryNext();46 }47 var mappedFilePath = path.join(path.dirname(packageJsonPath), mainFieldMapping);48 fileExistsAsync(mappedFilePath, function (err, exists) {49 if (err) {50 return doneCallback(err);51 }52 if (exists) {53 return doneCallback(undefined, mappedFilePath);54 }55 return tryNext();56 });57}58// Recursive loop to probe for physical files59function findFirstExistingPath(tryPaths, readJson, fileExists, doneCallback, index, mainFields) {60 if (index === void 0) { index = 0; }61 if (mainFields === void 0) { mainFields = ["main"]; }62 var tryPath = tryPaths[index];63 if (tryPath.type === "file" ||64 tryPath.type === "extension" ||65 tryPath.type === "index") {66 fileExists(tryPath.path, function (err, exists) {67 if (err) {68 return doneCallback(err);69 }70 if (exists) {71 // Not sure why we don't just return the full path? Why strip it?72 return doneCallback(undefined, TryPath.getStrippedPath(tryPath));73 }74 if (index === tryPaths.length - 1) {75 return doneCallback();76 }77 // Continue with the next path78 return findFirstExistingPath(tryPaths, readJson, fileExists, doneCallback, index + 1, mainFields);79 });80 }81 else if (tryPath.type === "package") {82 readJson(tryPath.path, function (err, packageJson) {83 if (err) {84 return doneCallback(err);85 }86 if (packageJson) {87 return findFirstExistingMainFieldMappedFile(packageJson, mainFields, tryPath.path, fileExists, function (mainFieldErr, mainFieldMappedFile) {88 if (mainFieldErr) {89 return doneCallback(mainFieldErr);90 }91 if (mainFieldMappedFile) {92 // Not sure why we don't just return the full path? Why strip it?93 return doneCallback(undefined, Filesystem.removeExtension(mainFieldMappedFile));94 }95 // No field in package json was a valid option. Continue with the next path.96 return findFirstExistingPath(tryPaths, readJson, fileExists, doneCallback, index + 1, mainFields);97 });98 }99 // This is async code, we need to return unconditionally, otherwise the code still falls100 // through and keeps recursing. While this might work in general, libraries that use neo-async101 // like Webpack will actually not allow you to call the same callback twice.102 //103 // An example of where this caused issues:104 // https://github.com/dividab/tsconfig-paths-webpack-plugin/issues/11105 //106 // Continue with the next path107 return findFirstExistingPath(tryPaths, readJson, fileExists, doneCallback, index + 1, mainFields);108 });109 }110 else {111 TryPath.exhaustiveTypeException(tryPath.type);112 }...

Full Screen

Full Screen

match-path-sync.js

Source:match-path-sync.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3var path = require("path");4var Filesystem = require("./filesystem");5var MappingEntry = require("./mapping-entry");6var TryPath = require("./try-path");7/**8 * Creates a function that can resolve paths according to tsconfig paths property.9 * @param absoluteBaseUrl Absolute version of baseUrl as specified in tsconfig.10 * @param paths The paths as specified in tsconfig.11 * @param mainFields A list of package.json field names to try when resolving module files.12 * @param addMatchAll Add a match-all "*" rule if none is present13 * @returns a function that can resolve paths.14 */15function createMatchPath(absoluteBaseUrl, paths, mainFields, addMatchAll) {16 if (mainFields === void 0) { mainFields = ["main"]; }17 if (addMatchAll === void 0) { addMatchAll = true; }18 var absolutePaths = MappingEntry.getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll);19 return function (requestedModule, readJson, fileExists, extensions) {20 return matchFromAbsolutePaths(absolutePaths, requestedModule, readJson, fileExists, extensions, mainFields);21 };22}23exports.createMatchPath = createMatchPath;24/**25 * Finds a path from tsconfig that matches a module load request.26 * @param absolutePathMappings The paths to try as specified in tsconfig but resolved to absolute form.27 * @param requestedModule The required module name.28 * @param readJson Function that can read json from a path (useful for testing).29 * @param fileExists Function that checks for existance of a file at a path (useful for testing).30 * @param extensions File extensions to probe for (useful for testing).31 * @param mainFields A list of package.json field names to try when resolving module files.32 * @returns the found path, or undefined if no path was found.33 */34function matchFromAbsolutePaths(absolutePathMappings, requestedModule, readJson, fileExists, extensions, mainFields) {35 if (readJson === void 0) { readJson = Filesystem.readJsonFromDiskSync; }36 if (fileExists === void 0) { fileExists = Filesystem.fileExistsSync; }37 if (extensions === void 0) { extensions = Object.keys(require.extensions); }38 if (mainFields === void 0) { mainFields = ["main"]; }39 var tryPaths = TryPath.getPathsToTry(extensions, absolutePathMappings, requestedModule);40 if (!tryPaths) {41 return undefined;42 }43 return findFirstExistingPath(tryPaths, readJson, fileExists, mainFields);44}45exports.matchFromAbsolutePaths = matchFromAbsolutePaths;46function findFirstExistingMainFieldMappedFile(packageJson, mainFields, packageJsonPath, fileExists) {47 for (var index = 0; index < mainFields.length; index++) {48 var mainFieldName = mainFields[index];49 var candidateMapping = packageJson[mainFieldName];50 if (candidateMapping && typeof candidateMapping === "string") {51 var candidateFilePath = path.join(path.dirname(packageJsonPath), candidateMapping);52 if (fileExists(candidateFilePath)) {53 return candidateFilePath;54 }55 }56 }57 return undefined;58}59function findFirstExistingPath(tryPaths, readJson, fileExists, mainFields) {60 if (readJson === void 0) { readJson = Filesystem.readJsonFromDiskSync; }61 if (mainFields === void 0) { mainFields = ["main"]; }62 for (var _i = 0, tryPaths_1 = tryPaths; _i < tryPaths_1.length; _i++) {63 var tryPath = tryPaths_1[_i];64 if (tryPath.type === "file" ||65 tryPath.type === "extension" ||66 tryPath.type === "index") {67 if (fileExists(tryPath.path)) {68 // Not sure why we don't just return the full path? Why strip it?69 return TryPath.getStrippedPath(tryPath);70 }71 }72 else if (tryPath.type === "package") {73 var packageJson = readJson(tryPath.path);74 if (packageJson) {75 var mainFieldMappedFile = findFirstExistingMainFieldMappedFile(packageJson, mainFields, tryPath.path, fileExists);76 if (mainFieldMappedFile) {77 // Not sure why we don't just return the full path? Why strip it?78 return Filesystem.removeExtension(mainFieldMappedFile);79 }80 }81 }82 else {83 TryPath.exhaustiveTypeException(tryPath.type);84 }85 }86 return undefined;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2const req = require.context('../src', true, /.stories.js$/);3function loadStories() {4 req.keys().forEach(filename => req(filename));5}6configure(loadStories, module);7{8 "scripts": {9 },10 "devDependencies": {11 "eslint-import-resolver-webpack": "^0.8.4",12 "eslint-plugin-import": "^2.11.0",

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2const req = require.context('../src', true, /.stories.js$/);3function loadStories() {4 req.keys().forEach(filename => req(filename));5}6configure(loadStories, module);7const path = require('path');8const rootImportOptions = {9};10module.exports = {11 module: {12 {13 {14 loader: require.resolve('@storybook/addon-storysource/loader'),15 options: { parser: 'javascript' },16 },17 },18 {19 loaders: [require.resolve('@storybook/addon-storysource/loader')],20 },21 {22 {23 },24 {25 loader: 'storybook-addon-root-import',26 },27 },28 },29};30{31 "compilerOptions": {32 "paths": {33 }34 }35}36{37 "scripts": {38 },39 "dependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { mainFields } = require('storybook-root-alias');2module.exports = {3 webpackFinal: async (config, { configType }) => {4 config.resolve.mainFields = mainFields;5 return config;6 },7};8const path = require('path');9const rootAlias = require('storybook-root-alias');10module.exports = {11 stories: ['../src/**/*.stories.(js|mdx)'],12 webpackFinal: async (config, { configType }) => {13 config.resolve.alias = {14 };15 return config;16 },17};18import { addDecorator } from '@storybook/react';19import { withA11y } from '@storybook/addon-a11y';20import { withKnobs } from '@storybook/addon-knobs';21import { withTests } from '@storybook/addon-jest';22import { withInfo } from '@storybook/addon-info';23import { withPerformance } from 'storybook-addon-performance';24import { withConsole } from '@storybook/addon-console';25import { withCssResources } from '@storybook/addon-cssresources';26import { withContexts } from '@storybook/addon-contexts/react';27import { contexts } from './contexts';28import { withViewport } from '@storybook/addon-viewport';29import { withDesign } from 'storybook-addon-designs';30import { withNextRouter } from 'storybook-addon-next-router';31import { withNextRouterDecorator } from './withNextRouterDecorator';32import { withNextRouterDecorator as withNextRouterDecoratorV6 } from '@storybook/addon-next-router';33import { withNextRouterDecorator as withNextRouterDecoratorV7 } from '@storybook/addon-next-router/dist/next-router-decorator';34import { withNextRouterDecorator as withNextRouterDecoratorV8 } from '@storybook/addon-next-router/dist/next-router-decorator.cjs';35import { withNextRouterDecorator as withNextRouterDecoratorV9 } from '@storybook/addon-next-router/dist/next-router-decorator.esm';36import { withNextRouterDecorator as withNextRouterDecoratorV10 } from '@storybook/addon-next-router/dist/next-router-decorator.umd';37import { withNextRouterDecorator as withNextRouterDecoratorV11 } from '@storybook/addon

Full Screen

Using AI Code Generation

copy

Full Screen

1import { mainFields } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3import MyComponent from './MyComponent';4storiesOf('MyComponent', module)5 .addDecorator(mainFields())6 .add('with default props', () => <MyComponent />);7import React from 'react';8import PropTypes from 'prop-types';9import { FormattedMessage } from 'react-intl';10const MyComponent = ({ title }) => (11 <FormattedMessage id={title} />12);13MyComponent.propTypes = {14};15export default MyComponent;16import { defineMessages } from 'react-intl';17export default defineMessages({18 title: {19 },20});21import React from 'react';22import { IntlProvider } from 'react-intl';23import messages from './messages';24import MyComponent from './MyComponent';25export default {26};27const Template = (args) => (28 <IntlProvider locale="en" messages={messages}>29 <MyComponent {...args} />30);31export const Default = Template.bind({});32Default.args = {33};34import { addDecorator } from '@storybook/react';35import { withIntl } from 'storybook-addon-intl';36import { withRootDecorator } from 'storybook-root-decorator';37const withProviders = withRootDecorator({38});39addDecorator(withProviders);40module.exports = {41 stories: ['../**/*.stories.(js|mdx)'],42};43import { addParameters } from '@storybook/react';44import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';45addParameters({46 viewport: {47 },48});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { addDecorator } from '@storybook/react';2import { withRootDecorator } from 'storybook-root-decorator';3addDecorator(withRootDecorator(['src']));4import { addDecorator } from '@storybook/react';5import { withRootDecorator } from 'storybook-root-decorator';6addDecorator(withRootDecorator(['src']));7import { addDecorator } from '@storybook/react';8import { withRootDecorator } from 'storybook-root-decorator';9addDecorator(withRootDecorator(['src']));10import { addDecorator } from '@storybook/react';11import { withRootDecorator } from 'storybook-root-decorator';12addDecorator(withRootDecorator(['src']));13import { addDecorator } from '@storybook/react';14import { withRootDecorator } from 'storybook-root-decorator';15addDecorator(withRootDecorator(['src']));16import { addDecorator } from '@storybook/react';17import { withRootDecorator } from 'storybook-root-decorator';18addDecorator(withRootDecorator(['src']));19import { addDecorator } from '@storybook/react';20import { withRootDecorator } from 'storybook-root-decorator';21addDecorator(withRootDecorator(['src']));22import { addDecorator } from '@storybook/react';23import { withRootDecorator } from 'storybook-root-decorator';24addDecorator(withRootDecorator(['src']));25import { addDecorator } from '@storybook/react';26import { withRootDecorator } from 'storybook-root-decorator';27addDecorator(withRootDecorator(['src']));28import { addDecorator } from '@storybook/react';29import { withRootDecorator } from 'storybook-root-decorator';30addDecorator(withRootDecorator(['src']));31import { addDecorator } from '@storybook/react';32import { withRootDecorator }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from 'storybook-root-alias';2configure(function () {3 require('./stories');4}, module);5import React from 'react';6import { storiesOf } from '@storybook/react';7import { Button } from 'components/Button';8storiesOf('Button', module)9 .add('with text', () => (10 .add('with some emoji', () => (11 ));12import React from 'react';13import './style.css';14export const Button = ({ children }) => (15 <button className="button">{children}</button>16);17.button {18 background-color: red;19}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful