Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 56 additions & 28 deletions component-playground/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path, { join, dirname } from "path";

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
Expand All @@ -12,13 +11,38 @@ function getAbsolutePath(value) {
const config = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
getAbsolutePath("@storybook/addon-webpack5-compiler-swc"),
getAbsolutePath("@storybook/addon-onboarding"),
getAbsolutePath("@storybook/addon-links"),
getAbsolutePath("@storybook/addon-essentials"),
getAbsolutePath("@chromatic-com/storybook"),
getAbsolutePath("@storybook/addon-interactions"),
"@storybook/addon-styling-webpack"
getAbsolutePath("@storybook/addon-webpack5-compiler-swc"),
getAbsolutePath("@storybook/addon-onboarding"),
getAbsolutePath("@storybook/addon-links"),
getAbsolutePath("@storybook/addon-essentials"),
getAbsolutePath("@chromatic-com/storybook"),
getAbsolutePath("@storybook/addon-interactions"),
{
name: "@storybook/addon-styling-webpack",
options: {
rules: [
{
test: /\.css$/,
sideEffects: true,
use: [
require.resolve("style-loader"),
{
loader: require.resolve("css-loader"),
options: {
importLoaders: 1,
},
},
{
loader: require.resolve("postcss-loader"),
options: {
implementation: require.resolve("postcss"),
},
},
],
},
],
},
},
],
framework: {
name: getAbsolutePath("@storybook/react-webpack5"),
Expand All @@ -27,50 +51,54 @@ const config = {
docs: {
autodocs: "tag",
},
webpackFinal: async (config) => {
webpackFinal: async config => {
config.resolve.alias = {
...config.resolve.alias,
"react-native": "react-native-web",
"@limio/design-system": path.resolve(
__dirname,
path.join("..", "packages", "design-system", "default")
__dirname,
path.join("..", "packages", "design-system", "default")
),
"@limio/currency": path.resolve(
__dirname,
path.join("..", "packages", "limio", "currency")
__dirname,
path.join("..", "packages", "limio", "currency")
),
"@limio/resources": path.resolve(
__dirname,
path.join("..", "packages", "limio", "resources")
__dirname,
path.join("..", "packages", "limio", "resources")
),
"@limio/sdk": path.resolve(
__dirname,
path.join("..", "packages", "limio", "sdk")
__dirname,
path.join("..", "packages", "limio", "sdk")
),
"@limio/sdk/components": path.resolve(
__dirname,
path.join("..", "packages", "limio", "sdk", "src", "components")
__dirname,
path.join("..", "packages", "limio", "sdk", "src", "components")
),
"@limio/internal-checkout-sdk": path.resolve(
__dirname,
path.join("..", "packages", "limio", "internal-checkout-sdk")
__dirname,
path.join("..", "packages", "limio", "internal-checkout-sdk")
),
"@limio/shop": path.resolve(
__dirname,
path.join("..", "packages", "limio", "shop")
__dirname,
path.join("..", "packages", "limio", "shop")
),
"@limio/utils": path.resolve(
__dirname,
path.join("..", "packages", "limio", "utils")
__dirname,
path.join("..", "packages", "limio", "utils")
),
"@limio/ui": path.resolve(
__dirname,
path.join("..", "packages", "limio", "ui")
__dirname,
path.join("..", "packages", "limio", "ui")
),
"@limio/crypto": path.resolve(
__dirname,
path.join("..", "packages", "limio", "crypto")
),
};

return config;
}
},
};

export default config;
50 changes: 33 additions & 17 deletions component-playground/config/paths.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,52 @@
"use strict"

const path = require("path")
const fs = require("fs")
const getPublicUrlOrPath = require("react-dev-utils/getPublicUrlOrPath")
const path = require("path");
const fs = require("fs");
const getPublicUrlOrPath = require("react-dev-utils/getPublicUrlOrPath");

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebook/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd())
const resolveApp = relativePath => path.resolve(appDirectory, relativePath)
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);

// We use `PUBLIC_URL` environment variable or "homepage" field to infer
// "public path" at which the app is served.
// webpack needs to know it to put the right <script> hrefs into HTML even in
// single-page apps that may serve index.html for nested URLs like /todos/42.
// We can't use a relative path in HTML because we don't want to load something
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
const publicUrlOrPath = getPublicUrlOrPath(process.env.NODE_ENV === "development", require(resolveApp("package.json")).homepage, process.env.PUBLIC_URL)
const publicUrlOrPath = getPublicUrlOrPath(
process.env.NODE_ENV === "development",
require(resolveApp("package.json")).homepage,
process.env.PUBLIC_URL
);

const buildPath = process.env.BUILD_PATH || "build"
const buildPath = process.env.BUILD_PATH || "build";

const moduleFileExtensions = ["web.mjs", "mjs", "web.js", "js", "web.ts", "ts", "web.tsx", "tsx", "json", "web.jsx", "jsx"]
const moduleFileExtensions = [
"web.mjs",
"mjs",
"web.js",
"js",
"web.ts",
"ts",
"web.tsx",
"tsx",
"json",
"web.jsx",
"jsx",
];

// Resolve file paths in the same order as webpack
const resolveModule = (resolveFn, filePath) => {
const extension = moduleFileExtensions.find(extension => fs.existsSync(resolveFn(`${filePath}.${extension}`)))
const extension = moduleFileExtensions.find(extension =>
fs.existsSync(resolveFn(`${filePath}.${extension}`))
);

if (extension) {
return resolveFn(`${filePath}.${extension}`)
return resolveFn(`${filePath}.${extension}`);
}

return resolveFn(`${filePath}.js`)
}
return resolveFn(`${filePath}.js`);
};

// config after eject: we're in ./config/
module.exports = {
Expand All @@ -51,7 +67,7 @@ module.exports = {
appWebpackCache: resolveApp("node_modules/.cache"),
appTsBuildInfoFile: resolveApp("node_modules/.cache/tsconfig.tsbuildinfo"),
swSrc: resolveModule(resolveApp, "src/service-worker"),
publicUrlOrPath
}
publicUrlOrPath,
};

module.exports.moduleFileExtensions = moduleFileExtensions
module.exports.moduleFileExtensions = moduleFileExtensions;
32 changes: 17 additions & 15 deletions component-playground/config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

const fs = require("fs");
const path = require("path");
const webpack = require("webpack");
Expand Down Expand Up @@ -94,8 +92,8 @@ module.exports = function (webpackEnv) {
const designSystem = process.argv.includes("--which")
? "which"
: process.argv.includes("--economist")
? "economist"
: "default";
? "economist"
: "default";
// Variable used for enabling profiling in Production
// passed into alias object. Uses a flag if passed into the build command
const isEnvProductionProfile =
Expand Down Expand Up @@ -131,6 +129,7 @@ module.exports = function (webpackEnv) {
// package.json
loader: require.resolve("postcss-loader"),
options: {
implementation: require.resolve("postcss"),
postcssOptions: {
// Necessary for external CSS imports to work
// https://github.com/facebook/create-react-app/issues/2677
Expand Down Expand Up @@ -223,13 +222,12 @@ module.exports = function (webpackEnv) {
publicPath: paths.publicUrlOrPath,
// Point sourcemap entries to original disk location (format as URL on Windows)
devtoolModuleFilenameTemplate: isEnvProduction
? (info) =>
? info =>
path
.relative(paths.appSrc, info.absoluteResourcePath)
.replace(/\\/g, "/")
: isEnvDevelopment &&
((info) =>
path.resolve(info.absoluteResourcePath).replace(/\\/g, "/")),
(info => path.resolve(info.absoluteResourcePath).replace(/\\/g, "/")),
},
cache: {
type: "filesystem",
Expand All @@ -239,7 +237,7 @@ module.exports = function (webpackEnv) {
buildDependencies: {
defaultWebpack: ["webpack/lib/"],
config: [__filename],
tsconfig: [paths.appTsConfig, paths.appJsConfig].filter((f) =>
tsconfig: [paths.appTsConfig, paths.appJsConfig].filter(f =>
fs.existsSync(f)
),
},
Expand Down Expand Up @@ -309,8 +307,8 @@ module.exports = function (webpackEnv) {
// `web` extension prefixes have been added for better support
// for React Native Web.
extensions: paths.moduleFileExtensions
.map((ext) => `.${ext}`)
.filter((ext) => useTypeScript || !ext.includes("ts")),
.map(ext => `.${ext}`)
.filter(ext => useTypeScript || !ext.includes("ts")),
alias: {
// Support React Native Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
Expand All @@ -332,12 +330,12 @@ module.exports = function (webpackEnv) {
path.join("..", "packages", "limio", "sdk")
),
"@limio/internal-checkout-sdk": path.resolve(
__dirname,
path.join("..", "packages", "limio", "internal-checkout-sdk")
__dirname,
path.join("..", "packages", "limio", "internal-checkout-sdk")
),
"@limio/shop": path.resolve(
__dirname,
path.join("..", "packages", "limio", "shop")
__dirname,
path.join("..", "packages", "limio", "shop")
),
"@limio/utils": path.resolve(
__dirname,
Expand All @@ -347,6 +345,10 @@ module.exports = function (webpackEnv) {
__dirname,
path.join("..", "packages", "limio", "ui")
),
"@limio/crypto": path.resolve(
__dirname,
path.join("..", "packages", "limio", "crypto")
),
...(isEnvProductionProfile && {
"react-dom$": "react-dom/profiling",
"scheduler/tracing": "scheduler/tracing-profiling",
Expand Down Expand Up @@ -699,7 +701,7 @@ module.exports = function (webpackEnv) {
return manifest;
}, seed);
const entrypointFiles = entrypoints.main.filter(
(fileName) => !fileName.endsWith(".map")
fileName => !fileName.endsWith(".map")
);

return {
Expand Down
2 changes: 2 additions & 0 deletions component-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"browserslist": "^4.18.1",
"camelcase": "^6.2.1",
"case-sensitive-paths-webpack-plugin": "^2.4.0",
"clsx": "^2.1.0",
"cookie": "^0.4.1",
"crypto-js": "^4.2.0",
"css-loader": "^6.5.1",
"css-minimizer-webpack-plugin": "^3.2.0",
"dotenv": "^10.0.0",
Expand Down
Loading