Skip to content

Commit

Permalink
Merge pull request #2143 from ing-bank/feature/start-using-patch-package
Browse files Browse the repository at this point in the history
chore: start using patch-package
  • Loading branch information
okadurin authored Nov 20, 2023
2 parents 4205c15 + c75e361 commit 27ffa1c
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 378 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
"format": "npm run format:eslint && npm run format:prettier",
"format:eslint": "eslint --ext .js,.html . --fix",
"format:prettier": "prettier \"**/*.{js,md}\" \"packages/*/package.json\" \"package.json\" --write",
"postinstall": "npx patch-package && npm run custom-elements-manifest && npm run patch-node-modules",
"postinstall": "npx patch-package && npm run custom-elements-manifest",
"lint": "run-p lint:*",
"lint:eslint": "eslint --ext .js,.html .",
"lint:markdownlint": "git ls-files '*.md' | xargs markdownlint --ignore '{.github/**/*.md,.changeset/*.md,**/CHANGELOG.md,packages/ui/_legacy-changelogs/*.md}'",
"lint:prettier": "prettier \"**/*.js\" --list-different || (echo '↑↑ these files are not prettier formatted ↑↑' && exit 1)",
"lint:types": "npm run types",
"lint:versions": "node ./scripts/lint-versions.js",
"patch-node-modules": "./src/utils/patches/patch.sh",
"prepare": "husky install",
"preview": "astro preview",
"release": "changeset publish",
Expand Down
275 changes: 275 additions & 0 deletions patches/@mdjs+core+0.20.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
diff --git a/node_modules/@mdjs/core/src/mdjsParse.js b/node_modules/@mdjs/core/src/mdjsParse.js
index 730e32a..5d6f3f5 100644
--- a/node_modules/@mdjs/core/src/mdjsParse.js
+++ b/node_modules/@mdjs/core/src/mdjsParse.js
@@ -5,13 +5,12 @@ import { remove } from 'unist-util-remove';
/** @typedef {import('unist').Node} Node */

export function mdjsParse() {
- let jsCode = '';
-
/**
* @param {Node} tree
* @param {VFileOptions} file
*/
function transformer(tree, file) {
+ let jsCode = '';
visit(
tree,
'code',
diff --git a/node_modules/@mdjs/core/src/mdjsSetupCode.js b/node_modules/@mdjs/core/src/mdjsSetupCode.js
index 02a7c56..db3e466 100644
--- a/node_modules/@mdjs/core/src/mdjsSetupCode.js
+++ b/node_modules/@mdjs/core/src/mdjsSetupCode.js
@@ -76,10 +76,6 @@ export function mdjsSetupCode({
` Object.assign(storyEl, ${JSON.stringify(simulationSettings)});`,
' }',
`};`,
- 'if (needsMdjsElements) {',
- ` if (!customElements.get('mdjs-preview')) { import('@mdjs/mdjs-preview/define'); }`,
- ` if (!customElements.get('mdjs-story')) { import('@mdjs/mdjs-story/define'); }`,
- '}',
].join('\n');
}

diff --git a/node_modules/@mdjs/core/src/mdjsStoryParse.js b/node_modules/@mdjs/core/src/mdjsStoryParse.js
index fe734a3..3ddd3a1 100644
--- a/node_modules/@mdjs/core/src/mdjsStoryParse.js
+++ b/node_modules/@mdjs/core/src/mdjsStoryParse.js
@@ -54,132 +54,130 @@ export function mdjsStoryParse({
storyTag = defaultStoryTag,
previewStoryTag = defaultPreviewStoryTag,
} = {}) {
- /** @type {Story[]} */
- const stories = [];
- let htmlIndex = 0;
-
- /* eslint-disable no-param-reassign */
-
/**
- * @param {UnistNode} _node
- * @param {number} index
- * @param {UnistParent} parent
+ * @param {Node} tree
+ * @param {VFileOptions} file
*/
- const nodeCodeVisitor = (_node, index, parent) => {
- let node = /** @type {UnistNode & {[key: string]: unknown}} */ (_node);
- if (node.lang === 'js' && node.meta === 'story' && typeof node.value === 'string') {
- const storyData = extractStoryData(node.value);
- node.type = 'html';
- node.value = storyTag(storyData.name);
- stories.push(storyData);
- }
- if (node.lang === 'js' && node.meta === 'preview-story' && typeof node.value === 'string') {
- const storyData = extractStoryData(node.value);
- const newValue = previewStoryTag(storyData.name);
- if (newValue.includes('[[CODE SLOT]]')) {
- const tagParts = newValue.split('[[CODE SLOT]]');
-
- const inside = [node];
- let skipAmount = 1;
+ async function transformer(tree, file) {
+ /** @type {Story[]} */
+ const stories = [];
+ let htmlIndex = 0;
+
+ /**
+ * @param {UnistNode} _node
+ * @param {number} index
+ * @param {UnistParent} parent
+ */
+ const nodeCodeVisitor = (_node, index, parent) => {
+ let node = /** @type {UnistNode & {[key: string]: unknown}} */ (_node);
+ if (node.lang === 'js' && node.meta === 'story' && typeof node.value === 'string') {
+ const storyData = extractStoryData(node.value);
+ node.type = 'html';
+ node.value = storyTag(storyData.name);
+ stories.push(storyData);
+ }
+ if (node.lang === 'js' && node.meta === 'preview-story' && typeof node.value === 'string') {
+ const storyData = extractStoryData(node.value);
+ const newValue = previewStoryTag(storyData.name);
+ if (newValue.includes('[[CODE SLOT]]')) {
+ const tagParts = newValue.split('[[CODE SLOT]]');

- const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
- parent.children[index + 1]
- );
- if (next && next.type === 'code' && next.meta === 'story-code') {
- inside.push(next);
- skipAmount += 1;
+ const inside = [node];
+ let skipAmount = 1;

- const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
- parent.children[index + 2]
+ const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
+ parent.children[index + 1]
);
- if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
- inside.push(next2);
+ if (next && next.type === 'code' && next.meta === 'story-code') {
+ inside.push(next);
skipAmount += 1;
+
+ const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
+ parent.children[index + 2]
+ );
+ if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
+ inside.push(next2);
+ skipAmount += 1;
+ }
}
+
+ node = {
+ type: 'root',
+ children: [
+ { type: 'html', value: tagParts[0] },
+ { type: 'text', value: '\n\n' },
+ ...inside,
+ { type: 'text', value: '\n\n' },
+ { type: 'html', value: tagParts[1] },
+ ],
+ };
+ parent.children.splice(index, skipAmount, node);
+ } else {
+ node.type = 'html';
+ node.value = previewStoryTag(storyData.name);
}

- node = {
- type: 'root',
- children: [
- { type: 'html', value: tagParts[0] },
- { type: 'text', value: '\n\n' },
- ...inside,
- { type: 'text', value: '\n\n' },
- { type: 'html', value: tagParts[1] },
- ],
- };
- parent.children.splice(index, skipAmount, node);
- } else {
- node.type = 'html';
- node.value = previewStoryTag(storyData.name);
+ stories.push(storyData);
}

- stories.push(storyData);
- }
-
- if (node.lang === 'html' && node.meta === 'story') {
- const storyData = extractStoryData(
- `export const HtmlStory${htmlIndex} = () => html\`${node.value}\`;`,
- { type: 'html' },
- );
- node.type = 'html';
- node.value = storyTag(storyData.name);
- stories.push(storyData);
- htmlIndex += 1;
- }
- if (node.lang === 'html' && node.meta === 'preview-story') {
- const storyData = extractStoryData(
- `export const HtmlStory${htmlIndex} = () => html\`${node.value}\`;`,
- { type: 'html' },
- );
-
- const newValue = previewStoryTag(storyData.name);
- if (newValue.includes('[[CODE SLOT]]')) {
- const tagParts = newValue.split('[[CODE SLOT]]');
- const inside = [node];
- let skipAmount = 1;
- const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
- parent.children[index + 1]
+ if (node.lang === 'html' && node.meta === 'story') {
+ const storyData = extractStoryData(
+ `export const HtmlStory${htmlIndex} = () => html\`${node.value}\`;`,
+ { type: 'html' },
+ );
+ node.type = 'html';
+ node.value = storyTag(storyData.name);
+ stories.push(storyData);
+ htmlIndex += 1;
+ }
+ if (node.lang === 'html' && node.meta === 'preview-story') {
+ const storyData = extractStoryData(
+ `export const HtmlStory${htmlIndex} = () => html\`${node.value}\`;`,
+ { type: 'html' },
);
- if (next && next.type === 'code' && next.meta === 'story-code') {
- inside.push(next);
- skipAmount += 1;

- const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
- parent.children[index + 2]
+ const newValue = previewStoryTag(storyData.name);
+ if (newValue.includes('[[CODE SLOT]]')) {
+ const tagParts = newValue.split('[[CODE SLOT]]');
+ const inside = [node];
+ let skipAmount = 1;
+ const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
+ parent.children[index + 1]
);
- if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
- inside.push(next2);
+ if (next && next.type === 'code' && next.meta === 'story-code') {
+ inside.push(next);
skipAmount += 1;
+
+ const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
+ parent.children[index + 2]
+ );
+ if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
+ inside.push(next2);
+ skipAmount += 1;
+ }
}
+
+ node = {
+ type: 'root',
+ children: [
+ { type: 'html', value: tagParts[0] },
+ { type: 'text', value: '\n\n' },
+ ...inside,
+ { type: 'text', value: '\n\n' },
+ { type: 'html', value: tagParts[1] },
+ ],
+ };
+ parent.children.splice(index, skipAmount, node);
+ } else {
+ node.type = 'html';
+ node.value = previewStoryTag(storyData.name);
}

- node = {
- type: 'root',
- children: [
- { type: 'html', value: tagParts[0] },
- { type: 'text', value: '\n\n' },
- ...inside,
- { type: 'text', value: '\n\n' },
- { type: 'html', value: tagParts[1] },
- ],
- };
- parent.children.splice(index, skipAmount, node);
- } else {
- node.type = 'html';
- node.value = previewStoryTag(storyData.name);
+ stories.push(storyData);
+ htmlIndex += 1;
}
+ };

- stories.push(storyData);
- htmlIndex += 1;
- }
- };
-
- /**
- * @param {Node} tree
- * @param {VFileOptions} file
- */
- async function transformer(tree, file) {
// unifiedjs expects node changes to be made on the given node...
await init;
// @ts-ignore
8 changes: 8 additions & 0 deletions patches/lit+2.8.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
diff --git a/node_modules/lit/index.js b/node_modules/lit/index.js
index 599d7d0..68a9dcb 100644
--- a/node_modules/lit/index.js
+++ b/node_modules/lit/index.js
@@ -1,2 +1,2 @@
-import"@lit/reactive-element";import"lit-html";export*from"lit-element/lit-element.js";export*from"lit-html/is-server.js";
+import"@lit/reactive-element";import"lit-html";export { nothing } from 'lit-html';export*from"lit-element/lit-element.js";export*from"lit-html/is-server.js";
//# sourceMappingURL=index.js.map
32 changes: 0 additions & 32 deletions src/utils/patches/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions src/utils/patches/assets/index.txt

This file was deleted.

51 changes: 0 additions & 51 deletions src/utils/patches/assets/mdjsParse.js

This file was deleted.

Loading

0 comments on commit 27ffa1c

Please sign in to comment.