From 75bb12320569a75b983d9e47985584c81f807aff Mon Sep 17 00:00:00 2001 From: Hanbyul Jo Date: Wed, 10 Jul 2024 13:40:03 -0400 Subject: [PATCH 1/6] Update parcel type for compability --- package.json | 2 +- yarn.lock | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 24696f78d..38b58bb47 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "@parcel/resolver-glob": "^2.0.1", "@parcel/transformer-mdx": "^2.0.1", "@parcel/transformer-sass": "2.7.0", - "@parcel/transformer-typescript-types": "2.7.0", + "@parcel/transformer-typescript-types": "2.12.0", "@parcel/transformer-webmanifest": "2.7.0", "@testing-library/jest-dom": "^5.16.2", "@testing-library/react": "^12.1.2", diff --git a/yarn.lock b/yarn.lock index 401fdab8a..73f9bdf8f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3274,16 +3274,16 @@ posthtml-render "^3.0.0" semver "^7.5.2" -"@parcel/transformer-typescript-types@2.7.0": - version "2.7.0" - resolved "http://verdaccio.ds.io:4873/@parcel%2ftransformer-typescript-types/-/transformer-typescript-types-2.7.0.tgz#a3e35c1f5030ce772d82d6ae18311dfab36d96b4" - integrity sha512-7eZFJH+0ZOZoh+4ZUKVnP79LI8h45hGAAqCI1UG8l7ZEf6q9yy8lwF9cREu4dUih70TDUHnHkxoNHfZWOjkDSg== +"@parcel/transformer-typescript-types@2.12.0": + version "2.12.0" + resolved "http://verdaccio.ds.io:4873/@parcel%2ftransformer-typescript-types/-/transformer-typescript-types-2.12.0.tgz#63e3fc4d1c5d61e1d3a2d56ff58454cf58b514ca" + integrity sha512-uxF4UBMYvbjiV3zHTWMrZX8cFD92VUvD3ArcGi5WEtuVROUm9Sc47o0mOzxKfMFlJu2KOfZVHYlzK9f/UKA2kQ== dependencies: - "@parcel/diagnostic" "2.7.0" - "@parcel/plugin" "2.7.0" - "@parcel/source-map" "^2.0.0" - "@parcel/ts-utils" "2.7.0" - "@parcel/utils" "2.7.0" + "@parcel/diagnostic" "2.12.0" + "@parcel/plugin" "2.12.0" + "@parcel/source-map" "^2.1.1" + "@parcel/ts-utils" "2.12.0" + "@parcel/utils" "2.12.0" nullthrows "^1.1.1" "@parcel/transformer-webmanifest@2.7.0": @@ -3296,10 +3296,10 @@ "@parcel/plugin" "2.7.0" "@parcel/utils" "2.7.0" -"@parcel/ts-utils@2.7.0": - version "2.7.0" - resolved "http://verdaccio.ds.io:4873/@parcel%2fts-utils/-/ts-utils-2.7.0.tgz#b5abe7eb5f977c238e11178bbf9a481481d60d1e" - integrity sha512-hxgWu9p9+zo9OvllYy12DRrAEyAGGLQysI6PyNvYvsZSmb7sQg9YQ7spD1QmWIQUC1H6BkyzQsowpK0hvPK1xg== +"@parcel/ts-utils@2.12.0": + version "2.12.0" + resolved "http://verdaccio.ds.io:4873/@parcel%2fts-utils/-/ts-utils-2.12.0.tgz#47878a6f3baff77d2fa6f9878fe235c9c5d75da8" + integrity sha512-zou+W6dcqnXXUOfN5zGM+ePIWbYOhGp8bVB2jICoNkoKmNAHd4l4zeHl5yQXnbZfynVw88cZVqxtXS8tYebelg== dependencies: nullthrows "^1.1.1" From ddcb11d185a4893410010010d64915afa17cfbba Mon Sep 17 00:00:00 2001 From: Hanbyul Jo Date: Wed, 10 Jul 2024 13:41:22 -0400 Subject: [PATCH 2/6] Add alias resolver --- .parcelrc-lib | 4 +++ parcel-resolver-alias/index.js | 62 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 .parcelrc-lib create mode 100644 parcel-resolver-alias/index.js diff --git a/.parcelrc-lib b/.parcelrc-lib new file mode 100644 index 000000000..d8ad865bf --- /dev/null +++ b/.parcelrc-lib @@ -0,0 +1,4 @@ +{ + "extends": ["./.parcelrc"], + "resolvers": ["parcel-resolver-alias", "..."] +} diff --git a/parcel-resolver-alias/index.js b/parcel-resolver-alias/index.js new file mode 100644 index 000000000..25d0d933b --- /dev/null +++ b/parcel-resolver-alias/index.js @@ -0,0 +1,62 @@ +const path = require('path'); +const fs = require('fs-extra'); +const { Resolver } = require('@parcel/plugin'); + +const fileExtensions = ['.js', '.ts', '.jsx', '.tsx']; +const indexFileExtensions = fileExtensions.map((e) => `index${e}`); + +function findMatchingFile(filePath) { + const filePathParts = filePath.split('/'); + const fileName = filePathParts[filePathParts.length - 1]; + // If the file name includes extension ex. panel.jsx or panel.css + if (fileName.includes('.')) { + if (fs.existsSync(filePath)) return filePath; + } + + for (const extension of fileExtensions) { + if (fs.existsSync(`${filePath}${extension}`)) + return `${filePath}${extension}`; + } + + for (const extension of indexFileExtensions) { + if (fs.existsSync(`${filePath}/${extension}`)) + return `${filePath}/${extension}`; + } + + for (const extension of indexFileExtensions) { + if (fs.existsSync(`${filePath}${extension}`)) + return `${filePath}${extension}`; + } + return null; +} + +module.exports = new Resolver({ + async resolve({ specifier }) { + let toReturn; + const aliases = { + $components: '/app/scripts/components', + $styles: '/app/scripts/styles', + $utils: '/app/scripts/utils', + $types: '/app/scripts/types', + $context: '/app/scripts/context', + '$data-layer': '/app/scripts/data-layer', + $test: '/test' + }; + for (let aliasKey in aliases) { + if (specifier.startsWith(aliasKey)) { + const replaced = specifier.replace(aliasKey, aliases[aliasKey]); + const rPath = path.join(__dirname, '..', replaced); + const fileP = findMatchingFile(rPath); + toReturn = { + filePath: fileP + }; + break; + } + } + if (toReturn) return toReturn; + else return null; + // Let the next resolver in the pipeline handle + // this dependency. + // return null; + } +}); From bf13832a19c980a7100a7a299d64ca6cbede2573 Mon Sep 17 00:00:00 2001 From: Hanbyul Jo Date: Wed, 10 Jul 2024 13:46:29 -0400 Subject: [PATCH 3/6] Update buidllib command and packages for compability --- package.json | 7 ++++--- yarn.lock | 14 +++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 38b58bb47..70c8eff45 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "scripts": { "serve": "NODE_ENV=development gulp serve", "build": "NODE_ENV=production gulp", - "buildlib": "gulp clean && parcel build 'app/scripts/index.ts' --dist-dir='lib'", - "stage": "NODE_ENV=staging gulp", + "buildlib": "gulp clean && parcel build 'app/scripts/index.ts' --dist-dir='lib' --config '.parcelrc-lib'", + "stage": "yarn buildlib && NODE_ENV=staging gulp", "clean": "gulp clean", "lint": "yarn lint:scripts && yarn lint:css", "lint:scripts": "eslint app/scripts/", @@ -47,7 +47,7 @@ "@mdx-js/mdx": "^2.0.0", "@parcel/bundler-experimental": "^2.7.0", "@parcel/packager-raw-url": "2.7.0", - "@parcel/packager-ts": "2.7.0", + "@parcel/packager-ts": "2.12.0", "@parcel/reporter-bundle-analyzer": "^2.0.0", "@parcel/reporter-bundle-buddy": "^2.0.0", "@parcel/resolver-glob": "^2.0.1", @@ -88,6 +88,7 @@ "lint-staged": "14.0.1", "parcel": "^2.12.0", "parcel-resolver-ignore": "^2.1.3", + "parcel-resolver-alias": "link:./parcel-resolver-alias", "parcel-resolver-veda": "link:./parcel-resolver-veda", "parcel-transformer-mdx": "link:./parcel-transformer-mdx", "parcel-transformer-mdx-frontmatter": "link:./parcel-transformer-mdx-frontmatter", diff --git a/yarn.lock b/yarn.lock index 73f9bdf8f..6bc8248aa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2952,12 +2952,12 @@ "@parcel/utils" "2.12.0" posthtml "^0.16.4" -"@parcel/packager-ts@2.7.0": - version "2.7.0" - resolved "http://verdaccio.ds.io:4873/@parcel%2fpackager-ts/-/packager-ts-2.7.0.tgz#631c3918fe475a1f69fc82628bebe99d73bae921" - integrity sha512-XT46njOHQCYmubQRbtjQOLT9RbXgxQ8aTxCOeO9jEay6snDnY6k+HdMXHAD6qZNyVgm85HJzjmDFDUeJQt9LKw== +"@parcel/packager-ts@2.12.0": + version "2.12.0" + resolved "http://verdaccio.ds.io:4873/@parcel%2fpackager-ts/-/packager-ts-2.12.0.tgz#7422c07ff3a327fdb592f6d707d31bc146590a17" + integrity sha512-8wR0BNN2NBD+IIU0tjioK+lRD4p2Qi/fKxDH5ixEW912tRV+Vd4kE8k++U6YQIpSlK4FRnjFod5zYYhNSLuiXg== dependencies: - "@parcel/plugin" "2.7.0" + "@parcel/plugin" "2.12.0" "@parcel/packager-wasm@2.12.0": version "2.12.0" @@ -11776,6 +11776,10 @@ papaparse@^5.3.2: resolved "http://verdaccio.ds.io:4873/papaparse/-/papaparse-5.3.2.tgz#d1abed498a0ee299f103130a6109720404fbd467" integrity sha512-6dNZu0Ki+gyV0eBsFKJhYr+MdQYAzFUGlBMNj3GNrmHxmz1lfRa24CjFObPXtjcetlOv5Ad299MhIK0znp3afw== +"parcel-resolver-alias@link:./parcel-resolver-alias": + version "0.0.0" + uid "" + parcel-resolver-ignore@^2.1.3: version "2.1.3" resolved "http://verdaccio.ds.io:4873/parcel-resolver-ignore/-/parcel-resolver-ignore-2.1.3.tgz#869673c40ccab1985af74020cd28b360b149155f" From 135776d4bc7bdceb928a635a9efb46ff51466a6a Mon Sep 17 00:00:00 2001 From: Hanbyul Jo Date: Wed, 10 Jul 2024 14:08:50 -0400 Subject: [PATCH 4/6] Remove exiperimental bundler --- .parcelrc | 1 - package.json | 1 - 2 files changed, 2 deletions(-) diff --git a/.parcelrc b/.parcelrc index b235e288c..1673ea43f 100644 --- a/.parcelrc +++ b/.parcelrc @@ -1,6 +1,5 @@ { "extends": ["@parcel/config-default"], - "bundler": "@parcel/bundler-experimental", "reporters": ["...", "@parcel/reporter-bundle-analyzer"], "resolvers": ["parcel-resolver-ignore", "parcel-resolver-veda", "@parcel/resolver-glob", "..."], "transformers": { diff --git a/package.json b/package.json index 70c8eff45..7eff907a5 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "@babel/preset-react": "^7.16.0", "@babel/preset-typescript": "^7.18.6", "@mdx-js/mdx": "^2.0.0", - "@parcel/bundler-experimental": "^2.7.0", "@parcel/packager-raw-url": "2.7.0", "@parcel/packager-ts": "2.12.0", "@parcel/reporter-bundle-analyzer": "^2.0.0", From 545e7eb9d5a1041dda833cd4d1282b20bd3524cb Mon Sep 17 00:00:00 2001 From: Hanbyul Jo Date: Wed, 10 Jul 2024 14:46:36 -0400 Subject: [PATCH 5/6] Remove redundant logic --- parcel-resolver-alias/index.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/parcel-resolver-alias/index.js b/parcel-resolver-alias/index.js index 25d0d933b..3feaf4d76 100644 --- a/parcel-resolver-alias/index.js +++ b/parcel-resolver-alias/index.js @@ -2,31 +2,33 @@ const path = require('path'); const fs = require('fs-extra'); const { Resolver } = require('@parcel/plugin'); +// Resolver for resolving aliases in library building +// Related issue in Parcel repo: https://github.com/parcel-bundler/parcel/issues/9519 + +// Files with redundant extensions ex. $components/panel (components/panel.d.ts.ts) const fileExtensions = ['.js', '.ts', '.jsx', '.tsx']; +// Index files with a trailing slash ex. $components/panel/ (components/panel/index.jsx) const indexFileExtensions = fileExtensions.map((e) => `index${e}`); +// Index files without a trailing slash ex. $components/panel (components/panel/index.jsx) +const pathIndexExtensions = fileExtensions.map((e) => `/index${e}`); function findMatchingFile(filePath) { const filePathParts = filePath.split('/'); const fileName = filePathParts[filePathParts.length - 1]; - // If the file name includes extension ex. panel.jsx or panel.css + // Files ex. $components/panel.jsx or $components/panel.css if (fileName.includes('.')) { if (fs.existsSync(filePath)) return filePath; } - for (const extension of fileExtensions) { + for (const extension of [ + ...fileExtensions, + ...indexFileExtensions, + ...pathIndexExtensions + ]) { if (fs.existsSync(`${filePath}${extension}`)) return `${filePath}${extension}`; } - for (const extension of indexFileExtensions) { - if (fs.existsSync(`${filePath}/${extension}`)) - return `${filePath}/${extension}`; - } - - for (const extension of indexFileExtensions) { - if (fs.existsSync(`${filePath}${extension}`)) - return `${filePath}${extension}`; - } return null; } @@ -54,9 +56,7 @@ module.exports = new Resolver({ } } if (toReturn) return toReturn; + // Let the next resolver in the pipeline handle this dependency else return null; - // Let the next resolver in the pipeline handle - // this dependency. - // return null; } }); From d11c69e37cf42a976659b69d0137f42b2ccf7562 Mon Sep 17 00:00:00 2001 From: Hanbyul Jo Date: Thu, 11 Jul 2024 08:58:59 -0400 Subject: [PATCH 6/6] Get alias from package.json --- parcel-resolver-alias/index.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/parcel-resolver-alias/index.js b/parcel-resolver-alias/index.js index 3feaf4d76..032039f51 100644 --- a/parcel-resolver-alias/index.js +++ b/parcel-resolver-alias/index.js @@ -1,9 +1,16 @@ +// Resolver for resolving aliases in library building +// Related issue in Parcel repo: https://github.com/parcel-bundler/parcel/issues/9519 + const path = require('path'); const fs = require('fs-extra'); const { Resolver } = require('@parcel/plugin'); +const { alias } = require('../package.json'); -// Resolver for resolving aliases in library building -// Related issue in Parcel repo: https://github.com/parcel-bundler/parcel/issues/9519 +const aliases = Object.keys(alias).reduce((acc, key) => { + const value = alias[key].replace('~', ''); + acc[`${key}`] = `${value}`; + return acc; +}, {}); // Files with redundant extensions ex. $components/panel (components/panel.d.ts.ts) const fileExtensions = ['.js', '.ts', '.jsx', '.tsx']; @@ -35,15 +42,6 @@ function findMatchingFile(filePath) { module.exports = new Resolver({ async resolve({ specifier }) { let toReturn; - const aliases = { - $components: '/app/scripts/components', - $styles: '/app/scripts/styles', - $utils: '/app/scripts/utils', - $types: '/app/scripts/types', - $context: '/app/scripts/context', - '$data-layer': '/app/scripts/data-layer', - $test: '/test' - }; for (let aliasKey in aliases) { if (specifier.startsWith(aliasKey)) { const replaced = specifier.replace(aliasKey, aliases[aliasKey]);