Skip to content

Commit

Permalink
Improve Component Integration With Content
Browse files Browse the repository at this point in the history
This commit ensures that Storybook, Jest and a preact project render the
components/contents correctly.

Previously a variety of mistakes were made that now are rectified:
* Jest does not honour .babelrc, so we gave up on JSX and pragma
niceties
* Previous tests were not actually rendering the component from the
bundle
* package.json specified an incorrect bundle entry
* dist/ folder was made part of version control
* Hidayah implementation was leveraging react-markdown to render the
contents. While this works for storybook, bundling this code implied
that react-markdown tries to mutate the content that Rollup marks as
immutable: rollup/rollup#1771

In addition to the above:
* Abstract out the implementation of markdown_plugin so Rollup and Vite
can reuse.
  • Loading branch information
Khalil Johnson authored and Ajwah committed Jan 7, 2024
1 parent f805144 commit 76ed459
Show file tree
Hide file tree
Showing 25 changed files with 291 additions and 1,465 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,5 @@
node_modules/
npm-debug.log
storybook-static/
.DS_Store
dist/
12 changes: 7 additions & 5 deletions .storybook/main.js
@@ -1,7 +1,8 @@
/** @type { import('@storybook/preact-vite').StorybookConfig } */
import fs from 'fs/promises';
import fsPromise from 'fs/promises';
import { StorybookConfig } from '@storybook/preact-vite';
import path from 'path'
import markdown from '../plugins/markdown_plugin'

const config = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
Expand Down Expand Up @@ -35,22 +36,23 @@ const config = {
setup(build) {
build.onLoad({ filter: /src\/.*\.js$/ }, async (args) => ({
loader: 'jsx',
contents: await fs.readFile(args.path, 'utf8'),
contents: await fsPromise.readFile(args.path, 'utf8'),
}));
},
},
],
};
};

config.plugins.push(markdown());
return {
...config,
resolve: {

alias: [
{ find: '@hanafi', replacement: path.resolve(__dirname, 'contents/hanafi/') },
{ find: '@components', replacement: path.resolve(__dirname, 'src/components/') },
{ find: '@utils', replacement: path.resolve(__dirname, 'src/utils/') },
{ find: '@hanafi', replacement: path.resolve(__dirname, '../contents/hanafi/') },
{ find: '@components', replacement: path.resolve(__dirname, '../src/components/') },
{ find: '@utils', replacement: path.resolve(__dirname, '../src/utils/') },
{ find: '@al-mabsut/muslimah', replacement: path.resolve(__dirname, '../node_modules/@al-mabsut/muslimah/dist/esm/bundle.js') }
]
},
Expand Down
43 changes: 0 additions & 43 deletions dist/cjs/bundle.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/cjs/bundle.js.map

This file was deleted.

41 changes: 0 additions & 41 deletions dist/esm/bundle.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/esm/bundle.js.map

This file was deleted.

18 changes: 9 additions & 9 deletions jest.config.common.js
Expand Up @@ -98,7 +98,7 @@ const commonConfig = {
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
preset: 'jest-preset-preact'
preset: 'jest-preset-preact',

// Run tests from one or more projects
// projects: null,
Expand Down Expand Up @@ -178,21 +178,21 @@ const commonConfig = {

// A map from regular expressions to paths to transformers
// transform: null,
// transform: {
// '^.+\\.js?$': 'babel-jest',
// '\\.(jpg|jpeg|png|svg|webp|)$': './fileMock.js',
// },
transform: {
// '^.+\\.js?$': 'babel-jest'
// '\\.(jpg|jpeg|png|svg|webp|)$': './fileMock.js'
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip
// transformation
// transformIgnorePatterns: [
// "/node_modules/"
// ],

// transformIgnorePatterns: [
// // This is needed to solve: SyntaxError: Unexpected token 'export'
// "node_modules/(?!@ngrx|(?!deck.gl)|ng-dynamic)"
// ],
transformIgnorePatterns: [
// This is needed to solve: SyntaxError: Unexpected token 'export'
'node_modules/(?!@ngrx|(?!deck.gl)|ng-dynamic)'
]

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically
// return a mock for them
Expand Down

0 comments on commit 76ed459

Please sign in to comment.