@aussieljk/forkbook 0.0.0-stage → 0.0.1-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +77 -2
- package/assets/addon-vitest/templates/vitest.config.4.template.ts +36 -0
- package/assets/browser/favicon-wrapper.svg +46 -0
- package/assets/browser/favicon.svg +1 -0
- package/assets/browser/nunito-sans-bold-italic.woff2 +0 -0
- package/assets/browser/nunito-sans-bold.woff2 +0 -0
- package/assets/browser/nunito-sans-italic.woff2 +0 -0
- package/assets/browser/nunito-sans-regular.woff2 +0 -0
- package/assets/builder-vite/iframe.html +99 -0
- package/assets/create/rendererAssets/.eslintrc.json +16 -0
- package/assets/create/rendererAssets/common/Configure.mdx +388 -0
- package/assets/create/rendererAssets/common/assets/accessibility.png +0 -0
- package/assets/create/rendererAssets/common/assets/accessibility.svg +1 -0
- package/assets/create/rendererAssets/common/assets/addon-library.png +0 -0
- package/assets/create/rendererAssets/common/assets/assets.png +0 -0
- package/assets/create/rendererAssets/common/assets/avif-test-image.avif +0 -0
- package/assets/create/rendererAssets/common/assets/context.png +0 -0
- package/assets/create/rendererAssets/common/assets/discord.svg +1 -0
- package/assets/create/rendererAssets/common/assets/docs.png +0 -0
- package/assets/create/rendererAssets/common/assets/figma-plugin.png +0 -0
- package/assets/create/rendererAssets/common/assets/github.svg +1 -0
- package/assets/create/rendererAssets/common/assets/share.png +0 -0
- package/assets/create/rendererAssets/common/assets/styling.png +0 -0
- package/assets/create/rendererAssets/common/assets/testing.png +0 -0
- package/assets/create/rendererAssets/common/assets/theming.png +0 -0
- package/assets/create/rendererAssets/common/assets/tutorials.svg +1 -0
- package/assets/create/rendererAssets/common/assets/youtube.svg +1 -0
- package/assets/create/rendererAssets/common/button.css +30 -0
- package/assets/create/rendererAssets/common/header.css +32 -0
- package/assets/create/rendererAssets/common/page.css +68 -0
- package/assets/create/templates/react-native/index.expo.js +20 -0
- package/assets/create/templates/react-native/index.js +25 -0
- package/assets/docs/addon-backgrounds.gif +0 -0
- package/assets/docs/addon-controls-args-annotated.png +0 -0
- package/assets/docs/addon-controls-args-background-color.png +0 -0
- package/assets/docs/addon-controls-args-background-string.png +0 -0
- package/assets/docs/addon-controls-args-docs.png +0 -0
- package/assets/docs/addon-controls-args-logging.png +0 -0
- package/assets/docs/addon-controls-args-no-annotation.png +0 -0
- package/assets/docs/addon-controls-args-reflow-slider.png +0 -0
- package/assets/docs/addon-controls-args-reflow.png +0 -0
- package/assets/docs/addon-controls-args-template.png +0 -0
- package/assets/docs/addon-controls-expanded.png +0 -0
- package/assets/docs/addon-controls-hero.gif +0 -0
- package/assets/docs/addon-controls-install.png +0 -0
- package/assets/docs/hero.gif +0 -0
- package/assets/docs/highlight.png +0 -0
- package/assets/docs/message-reference.png +0 -0
- package/assets/docs/viewport.png +0 -0
- package/assets/react-native/metro-env.d.ts +69 -0
- package/assets/server/addon.tsconfig.json +6 -0
- package/assets/server/base-preview-body.html +116 -0
- package/assets/server/base-preview-head.html +494 -0
- package/assets/server/openBrowser.applescript +94 -0
- package/assets/server/template.ejs +87 -0
- package/dist/.build-stamp +0 -0
- package/dist/_browser-chunks/Color-PCLE2J36.js +1025 -0
- package/dist/_browser-chunks/DocsRenderer-JXND3PVQ.js +10 -0
- package/dist/_browser-chunks/WithTooltip-XSQFTBMB.js +1619 -0
- package/dist/_browser-chunks/chunk-2JDQ35OA.js +247 -0
- package/dist/_browser-chunks/chunk-2JT76G3E.js +104 -0
- package/dist/_browser-chunks/chunk-2MEPHP35.js +17 -0
- package/dist/_browser-chunks/chunk-2SCZVUKW.js +24 -0
- package/dist/_browser-chunks/chunk-46Z7NGAS.js +41 -0
- package/dist/_browser-chunks/chunk-4ATQOMJB.js +30 -0
- package/dist/_browser-chunks/chunk-52CW7FF7.js +49 -0
- package/dist/_browser-chunks/chunk-5I7E4GMO.js +62 -0
- package/dist/_browser-chunks/chunk-5P4QA6MY.js +20 -0
- package/dist/_browser-chunks/chunk-5WMXI5GW.js +816 -0
- package/dist/_browser-chunks/chunk-66OCZ54D.js +2604 -0
- package/dist/_browser-chunks/chunk-6SXYJQST.js +253 -0
- package/dist/_browser-chunks/chunk-AYRF6EJB.js +36 -0
- package/dist/_browser-chunks/chunk-B4AUNNU4.js +156 -0
- package/dist/_browser-chunks/chunk-BCP2FFXF.js +369 -0
- package/dist/_browser-chunks/chunk-C3D4HEFY.js +3396 -0
- package/dist/_browser-chunks/chunk-CFAOWGL7.js +43 -0
- package/dist/_browser-chunks/chunk-CFWWCCZV.js +223 -0
- package/dist/_browser-chunks/chunk-CNED6RYH.js +18 -0
- package/dist/_browser-chunks/chunk-DRQKCCAG.js +136 -0
- package/dist/_browser-chunks/chunk-ECQ75MKQ.js +0 -0
- package/dist/_browser-chunks/chunk-EIYAKDGP.js +302 -0
- package/dist/_browser-chunks/chunk-ENKK74N4.js +12 -0
- package/dist/_browser-chunks/chunk-FENFYI4X.js +698 -0
- package/dist/_browser-chunks/chunk-FJGWSWL5.js +155 -0
- package/dist/_browser-chunks/chunk-FVSEPWWX.js +2810 -0
- package/dist/_browser-chunks/chunk-GNZY6LOW.js +10116 -0
- package/dist/_browser-chunks/chunk-IE4ULIOQ.js +14 -0
- package/dist/_browser-chunks/chunk-IMSF75WX.js +42 -0
- package/dist/_browser-chunks/chunk-IWQGIXJS.js +14 -0
- package/dist/_browser-chunks/chunk-JMC7AIKT.js +108 -0
- package/dist/_browser-chunks/chunk-JPUOQJUI.js +8 -0
- package/dist/_browser-chunks/chunk-JSBKXXXF.js +218 -0
- package/dist/_browser-chunks/chunk-JWSKPMPC.js +73 -0
- package/dist/_browser-chunks/chunk-JYVGARBG.js +2943 -0
- package/dist/_browser-chunks/chunk-KBK7GKBN.js +35 -0
- package/dist/_browser-chunks/chunk-KQ7CRO2B.js +108 -0
- package/dist/_browser-chunks/chunk-LAWXTSXK.js +18 -0
- package/dist/_browser-chunks/chunk-LE2LTDW3.js +14 -0
- package/dist/_browser-chunks/chunk-LEVSOOLQ.js +48 -0
- package/dist/_browser-chunks/chunk-LV5PIKV4.js +93 -0
- package/dist/_browser-chunks/chunk-MDOL7KML.js +56 -0
- package/dist/_browser-chunks/chunk-MFMDGWP6.js +34 -0
- package/dist/_browser-chunks/chunk-MLBOOZL4.js +67 -0
- package/dist/_browser-chunks/chunk-NQUD4B7H.js +91 -0
- package/dist/_browser-chunks/chunk-NULBREPZ.js +43 -0
- package/dist/_browser-chunks/chunk-NZMVUW5T.js +7 -0
- package/dist/_browser-chunks/chunk-OD6IBQCC.js +117 -0
- package/dist/_browser-chunks/chunk-ODVJ3XZJ.js +157 -0
- package/dist/_browser-chunks/chunk-OQWFVDIN.js +386 -0
- package/dist/_browser-chunks/chunk-OVH3USFB.js +20 -0
- package/dist/_browser-chunks/chunk-OZZPSYQR.js +14 -0
- package/dist/_browser-chunks/chunk-P6PK47TQ.js +1970 -0
- package/dist/_browser-chunks/chunk-PFRNG3UC.js +22 -0
- package/dist/_browser-chunks/chunk-PJSMZ27A.js +13 -0
- package/dist/_browser-chunks/chunk-QC4HFS6K.js +41 -0
- package/dist/_browser-chunks/chunk-QDXFODK4.js +274 -0
- package/dist/_browser-chunks/chunk-RBCHTR7C.js +28 -0
- package/dist/_browser-chunks/chunk-RMYQ3QN3.js +294 -0
- package/dist/_browser-chunks/chunk-RNTIV5CE.js +411 -0
- package/dist/_browser-chunks/chunk-RSPAQWVJ.js +80 -0
- package/dist/_browser-chunks/chunk-S6TK43XQ.js +836 -0
- package/dist/_browser-chunks/chunk-SC67XZST.js +18 -0
- package/dist/_browser-chunks/chunk-SFVA4SBT.js +683 -0
- package/dist/_browser-chunks/chunk-SZYFOQMT.js +25 -0
- package/dist/_browser-chunks/chunk-TBJCJXK4.js +18 -0
- package/dist/_browser-chunks/chunk-UMDO3KB7.js +205 -0
- package/dist/_browser-chunks/chunk-V2G23FV7.js +11 -0
- package/dist/_browser-chunks/chunk-V5M7Q4HT.js +88 -0
- package/dist/_browser-chunks/chunk-W5M6NPS3.js +198 -0
- package/dist/_browser-chunks/chunk-W7NE2JXW.js +84 -0
- package/dist/_browser-chunks/chunk-WGVAAM43.js +1110 -0
- package/dist/_browser-chunks/chunk-WHQRNHXD.js +8 -0
- package/dist/_browser-chunks/chunk-WOSOWBCA.js +12 -0
- package/dist/_browser-chunks/chunk-WZ7KR7SH.js +85 -0
- package/dist/_browser-chunks/chunk-YEKO6BHJ.js +20 -0
- package/dist/_browser-chunks/chunk-YI2IBIQS.js +7 -0
- package/dist/_browser-chunks/chunk-YTIT5NA5.js +1966 -0
- package/dist/_browser-chunks/chunk-ZEHRUHTA.js +6 -0
- package/dist/_browser-chunks/chunk-ZTQ5MEJ5.js +203 -0
- package/dist/_browser-chunks/matchers-YLBYSYAF.js +1263 -0
- package/dist/_browser-chunks/react-dom-client-4OHE3QDV.js +9 -0
- package/dist/_node-chunks/attached-runtime-I2G4WLJI.js +282 -0
- package/dist/_node-chunks/builder-manager-VVHYQXCH.js +1661 -0
- package/dist/_node-chunks/chunk-2BUPBPFB.js +82 -0
- package/dist/_node-chunks/chunk-2DSIDINN.js +884 -0
- package/dist/_node-chunks/chunk-2RU7BKEW.js +23 -0
- package/dist/_node-chunks/chunk-34EO2PUT.js +26 -0
- package/dist/_node-chunks/chunk-3BKIBF5S.js +3008 -0
- package/dist/_node-chunks/chunk-3SDUYDXH.js +98 -0
- package/dist/_node-chunks/chunk-3T4ZSNPH.js +662 -0
- package/dist/_node-chunks/chunk-3W7F2B7P.js +79 -0
- package/dist/_node-chunks/chunk-3Y6AAY5H.js +80 -0
- package/dist/_node-chunks/chunk-42UWAGPW.js +1193 -0
- package/dist/_node-chunks/chunk-4FEANXWU.js +1986 -0
- package/dist/_node-chunks/chunk-5DQFEZEA.js +40 -0
- package/dist/_node-chunks/chunk-6KEHV53S.js +1218 -0
- package/dist/_node-chunks/chunk-6LMWA44H.js +3837 -0
- package/dist/_node-chunks/chunk-6YKBRP72.js +20 -0
- package/dist/_node-chunks/chunk-7GUDZVRQ.js +110 -0
- package/dist/_node-chunks/chunk-B5J7Q7J4.js +21 -0
- package/dist/_node-chunks/chunk-BS2WMZMR.js +90 -0
- package/dist/_node-chunks/chunk-BSKFCWQD.js +47 -0
- package/dist/_node-chunks/chunk-BXVYT7SB.js +36 -0
- package/dist/_node-chunks/chunk-CCOTJ4FC.js +688 -0
- package/dist/_node-chunks/chunk-CQKMLL5J.js +33 -0
- package/dist/_node-chunks/chunk-CXRU72ET.js +63 -0
- package/dist/_node-chunks/chunk-DC7DKR5K.js +20 -0
- package/dist/_node-chunks/chunk-DHJFTB4K.js +25 -0
- package/dist/_node-chunks/chunk-DUR55DJJ.js +1094 -0
- package/dist/_node-chunks/chunk-E6YESGLX.js +7032 -0
- package/dist/_node-chunks/chunk-EHUNOMDD.js +52345 -0
- package/dist/_node-chunks/chunk-ET7PWEO7.js +298 -0
- package/dist/_node-chunks/chunk-EWOX7HPJ.js +20 -0
- package/dist/_node-chunks/chunk-F3ZFKBHY.js +844 -0
- package/dist/_node-chunks/chunk-FK7KGTV7.js +26 -0
- package/dist/_node-chunks/chunk-FPZB5OI7.js +35 -0
- package/dist/_node-chunks/chunk-FW2HQUBQ.js +25 -0
- package/dist/_node-chunks/chunk-FY6UXW6G.js +11 -0
- package/dist/_node-chunks/chunk-GEFQN7K3.js +499 -0
- package/dist/_node-chunks/chunk-GRBLDJCR.js +989 -0
- package/dist/_node-chunks/chunk-H32DYT6P.js +87 -0
- package/dist/_node-chunks/chunk-H4PPVMP5.js +23 -0
- package/dist/_node-chunks/chunk-HMP2G23X.js +25 -0
- package/dist/_node-chunks/chunk-ICPBH3E7.js +59 -0
- package/dist/_node-chunks/chunk-IDEL2J23.js +23 -0
- package/dist/_node-chunks/chunk-IK4FGZLR.js +223 -0
- package/dist/_node-chunks/chunk-JDXXX6LB.js +68 -0
- package/dist/_node-chunks/chunk-JGGFYIG5.js +5468 -0
- package/dist/_node-chunks/chunk-JPAZLYJ3.js +29 -0
- package/dist/_node-chunks/chunk-JZOO7GGC.js +48 -0
- package/dist/_node-chunks/chunk-KISMCCP5.js +4744 -0
- package/dist/_node-chunks/chunk-LCK4ZQKG.js +115 -0
- package/dist/_node-chunks/chunk-LO56I6E2.js +132 -0
- package/dist/_node-chunks/chunk-LXBD4UL4.js +104 -0
- package/dist/_node-chunks/chunk-MA24JW6C.js +7162 -0
- package/dist/_node-chunks/chunk-MK2KYAI6.js +5414 -0
- package/dist/_node-chunks/chunk-NDWKJ4CL.js +2102 -0
- package/dist/_node-chunks/chunk-NIBT7XDZ.js +168 -0
- package/dist/_node-chunks/chunk-NPO45IMH.js +33 -0
- package/dist/_node-chunks/chunk-OISX4AGQ.js +414 -0
- package/dist/_node-chunks/chunk-OUW6R7C3.js +26 -0
- package/dist/_node-chunks/chunk-OWNFOGTA.js +194 -0
- package/dist/_node-chunks/chunk-Q7QNUM5H.js +49 -0
- package/dist/_node-chunks/chunk-QEQLR22M.js +1877 -0
- package/dist/_node-chunks/chunk-RRN2V55B.js +45 -0
- package/dist/_node-chunks/chunk-RWFIFGO5.js +144 -0
- package/dist/_node-chunks/chunk-RXNJDRGO.js +209 -0
- package/dist/_node-chunks/chunk-RZMQ7S3L.js +92 -0
- package/dist/_node-chunks/chunk-SIEXZVCR.js +51 -0
- package/dist/_node-chunks/chunk-SLWQNBGO.js +2034 -0
- package/dist/_node-chunks/chunk-SVTBJ7Q3.js +35 -0
- package/dist/_node-chunks/chunk-SWO5CDYU.js +32 -0
- package/dist/_node-chunks/chunk-TD5PLLQG.js +121 -0
- package/dist/_node-chunks/chunk-TEQGGSP7.js +33 -0
- package/dist/_node-chunks/chunk-TFCEV2XX.js +155 -0
- package/dist/_node-chunks/chunk-TFEWM4E3.js +1073 -0
- package/dist/_node-chunks/chunk-TINO74G5.js +21 -0
- package/dist/_node-chunks/chunk-TNJIXE37.js +40 -0
- package/dist/_node-chunks/chunk-TWI4GVH7.js +19 -0
- package/dist/_node-chunks/chunk-U5W53R2J.js +1011 -0
- package/dist/_node-chunks/chunk-UBOGWBEA.js +148 -0
- package/dist/_node-chunks/chunk-UMUBKI6E.js +3787 -0
- package/dist/_node-chunks/chunk-UVINFLGY.js +56 -0
- package/dist/_node-chunks/chunk-V2DY426G.js +1133 -0
- package/dist/_node-chunks/chunk-VLOXOXXE.js +45 -0
- package/dist/_node-chunks/chunk-W4OMYLSP.js +1297 -0
- package/dist/_node-chunks/chunk-WAXVSN3O.js +18 -0
- package/dist/_node-chunks/chunk-WCULS5TP.js +3767 -0
- package/dist/_node-chunks/chunk-WNZ2UMFM.js +153 -0
- package/dist/_node-chunks/chunk-WZJF2OUH.js +74 -0
- package/dist/_node-chunks/chunk-XGIUVY52.js +611 -0
- package/dist/_node-chunks/chunk-XHL2LVBM.js +415 -0
- package/dist/_node-chunks/chunk-XI6B6P47.js +59 -0
- package/dist/_node-chunks/chunk-XLP2ZKXV.js +60 -0
- package/dist/_node-chunks/chunk-YCMRA6RX.js +95 -0
- package/dist/_node-chunks/chunk-YZFWBA5L.js +2700 -0
- package/dist/_node-chunks/chunk-ZMAMXQKP.js +4731 -0
- package/dist/_node-chunks/chunk-ZWBCQ4MJ.js +110 -0
- package/dist/_node-chunks/dist-VTSTZKUB.js +16 -0
- package/dist/_node-chunks/globby-OEMHPBFY.js +2884 -0
- package/dist/_node-chunks/jiti-NFX6UU74.js +3848 -0
- package/dist/_node-chunks/lib-MDVARD7W.js +366 -0
- package/dist/_node-chunks/local-runtime-NTKIN2QT.js +78 -0
- package/dist/_node-chunks/mdx-plugin-MWISDWDQ.js +5680 -0
- package/dist/_node-chunks/monorepo-LIRFMQXE.js +121 -0
- package/dist/_node-chunks/monorepo-optimized-tests-relaxed-limits-no-story-deletion-CPDW4XTW.js +121 -0
- package/dist/_node-chunks/optimized-tests-HDOLR3EY.js +22 -0
- package/dist/_node-chunks/pattern-copy-play-EKHIUAU2.js +807 -0
- package/dist/_node-chunks/postinstallAddon-GYGMWDL6.js +20 -0
- package/dist/_node-chunks/rehype-external-links-BUN3HUCO.js +121 -0
- package/dist/_node-chunks/rehype-slug-PLADX223.js +52 -0
- package/dist/_node-chunks/relaxed-limits-GBHW6KIQ.js +117 -0
- package/dist/_node-chunks/run-KDTIZNSY.js +103 -0
- package/dist/_node-chunks/run-NL66VTNR.js +4532 -0
- package/dist/_node-chunks/session-id-KIIVOQLR.js +23 -0
- package/dist/_node-chunks/setup-MGC7BQO6.js +278 -0
- package/dist/_node-chunks/vitest.config.4.template-JH2THZFG.js +54 -0
- package/dist/actions/decorator.d.ts +7 -0
- package/dist/actions/decorator.js +43 -0
- package/dist/actions/index.d.ts +67 -0
- package/dist/actions/index.js +28 -0
- package/dist/addon-a11y/index.d.ts +52 -0
- package/dist/addon-a11y/index.js +16 -0
- package/dist/addon-a11y/manager.js +1429 -0
- package/dist/addon-a11y/preset.js +18 -0
- package/dist/addon-a11y/preview.d.ts +17 -0
- package/dist/addon-a11y/preview.js +15 -0
- package/dist/addon-docs/blocks.d.ts +1061 -0
- package/dist/addon-docs/blocks.js +2461 -0
- package/dist/addon-docs/index.d.ts +236 -0
- package/dist/addon-docs/index.js +16 -0
- package/dist/addon-docs/manager.js +90 -0
- package/dist/addon-docs/mdx-react-shim.d.ts +1 -0
- package/dist/addon-docs/mdx-react-shim.js +2 -0
- package/dist/addon-docs/preset.js +378 -0
- package/dist/addon-docs/preview.d.ts +4 -0
- package/dist/addon-docs/preview.js +7 -0
- package/dist/addon-links/index.d.ts +22 -0
- package/dist/addon-links/index.js +20 -0
- package/dist/addon-links/manager.js +14 -0
- package/dist/addon-links/preview.d.ts +6 -0
- package/dist/addon-links/preview.js +9 -0
- package/dist/addon-links/react/index.d.ts +25 -0
- package/dist/addon-links/react/index.js +52 -0
- package/dist/addon-mcp/preset.js +1345 -0
- package/dist/addon-mcp/preview.js +29 -0
- package/dist/addon-mcp/tools/preview-stories/preview-stories-app-script.js +1153 -0
- package/dist/addon-ondevice-actions/index.d.ts +4 -0
- package/dist/addon-ondevice-actions/index.js +7 -0
- package/dist/addon-ondevice-actions/register.js +7 -0
- package/dist/addon-ondevice-controls/index.d.ts +6 -0
- package/dist/addon-ondevice-controls/index.js +14 -0
- package/dist/addon-ondevice-controls/register.js +10 -0
- package/dist/addon-pseudo-states/index.d.ts +35 -0
- package/dist/addon-pseudo-states/index.js +15 -0
- package/dist/addon-pseudo-states/manager.js +53 -0
- package/dist/addon-pseudo-states/preview.d.ts +9 -0
- package/dist/addon-pseudo-states/preview.js +10 -0
- package/dist/addon-themes/index.d.ts +80 -0
- package/dist/addon-themes/index.js +104 -0
- package/dist/addon-themes/manager.js +97 -0
- package/dist/addon-themes/postinstall.js +33 -0
- package/dist/addon-themes/preview.d.ts +6 -0
- package/dist/addon-themes/preview.js +8 -0
- package/dist/addon-vitest/constants.d.ts +132 -0
- package/dist/addon-vitest/constants.js +66 -0
- package/dist/addon-vitest/index.d.ts +4 -0
- package/dist/addon-vitest/index.js +8 -0
- package/dist/addon-vitest/manager.js +665 -0
- package/dist/addon-vitest/node/coverage-reporter.js +1284 -0
- package/dist/addon-vitest/node/vitest.js +674 -0
- package/dist/addon-vitest/postinstall.js +24 -0
- package/dist/addon-vitest/preset.js +943 -0
- package/dist/addon-vitest/vitest-plugin/global-setup.js +162 -0
- package/dist/addon-vitest/vitest-plugin/index.d.ts +56 -0
- package/dist/addon-vitest/vitest-plugin/index.js +463 -0
- package/dist/addon-vitest/vitest-plugin/setup-file-with-project-annotations.js +9 -0
- package/dist/addon-vitest/vitest-plugin/setup-file.browser.4.js +20 -0
- package/dist/addon-vitest/vitest-plugin/setup-file.js +50 -0
- package/dist/addon-vitest/vitest-plugin/test-utils.js +128 -0
- package/dist/babel/index.d.ts +2301 -0
- package/dist/babel/index.js +61 -0
- package/dist/backgrounds/index.d.ts +6 -0
- package/dist/backgrounds/index.js +15 -0
- package/dist/bin/core.js +1705 -0
- package/dist/bin/dispatcher.js +43 -0
- package/dist/bin/loader.js +115 -0
- package/dist/builder-vite/index.d.ts +50 -0
- package/dist/builder-vite/index.js +245 -0
- package/dist/builder-vite/preset.js +27 -0
- package/dist/channels/index.d.ts +2 -0
- package/dist/channels/index.js +352 -0
- package/dist/chunk-B2t1tGRh.d.ts +284 -0
- package/dist/chunk-BCoJQE-f.d.ts +602 -0
- package/dist/chunk-BGkgZp-H.d.ts +214 -0
- package/dist/chunk-BTVrWliM.d.ts +115 -0
- package/dist/chunk-BXLImeLy.d.ts +197 -0
- package/dist/chunk-BfBzpgct.d.ts +916 -0
- package/dist/chunk-Bpi2tz-6.d.ts +511 -0
- package/dist/chunk-BxWufQms.d.ts +142 -0
- package/dist/chunk-C-bavsOH.d.ts +34 -0
- package/dist/chunk-C2p5r3Vt.d.ts +13001 -0
- package/dist/chunk-C6PAgHLT.d.ts +12 -0
- package/dist/chunk-CMeX4WRe.d.ts +179 -0
- package/dist/chunk-Ct9xd6IM.d.ts +65 -0
- package/dist/chunk-CwQKNaYL.d.ts +15 -0
- package/dist/chunk-D7DwV41f.d.ts +3622 -0
- package/dist/chunk-DEVFdzxR.d.ts +253 -0
- package/dist/chunk-DaVb55-_.d.ts +124 -0
- package/dist/chunk-DgRNfmj_.d.ts +40 -0
- package/dist/chunk-DoIGKY33.d.ts +666 -0
- package/dist/chunk-Dr3R0DXk.d.ts +40 -0
- package/dist/chunk-DtHByo32.d.ts +55 -0
- package/dist/chunk-Dw1z1Pki.d.ts +933 -0
- package/dist/chunk-DzuY9DXg.d.ts +79 -0
- package/dist/chunk-FjDVzZTj.d.ts +62 -0
- package/dist/chunk-Kt1tW-D1.d.ts +59 -0
- package/dist/chunk-XP8oHzpE.d.ts +6 -0
- package/dist/chunk-gCX81nOr.d.ts +61 -0
- package/dist/chunk-pcFXCimE.d.ts +741 -0
- package/dist/cli/index.d.ts +1174 -0
- package/dist/cli/index.js +5613 -0
- package/dist/cli/skills/content/index.d.ts +72 -0
- package/dist/cli/skills/content/index.js +335 -0
- package/dist/cli/tools/sdk/child-host.d.ts +61 -0
- package/dist/cli/tools/sdk/child-host.js +131 -0
- package/dist/cli/tools/sdk/index.d.ts +137 -0
- package/dist/cli/tools/sdk/index.js +44 -0
- package/dist/cli-commands/bin/index.js +25 -0
- package/dist/client-logger/index.d.ts +31 -0
- package/dist/client-logger/index.js +63 -0
- package/dist/common/index.d.ts +1103 -0
- package/dist/common/index.js +364 -0
- package/dist/components/index.d.ts +1924 -0
- package/dist/components/index.js +13759 -0
- package/dist/core-events/index.d.ts +155 -0
- package/dist/core-events/index.js +136 -0
- package/dist/core-server/index.d.ts +2200 -0
- package/dist/core-server/index.js +4165 -0
- package/dist/core-server/presets/common-manager.css +170 -0
- package/dist/core-server/presets/common-manager.js +4168 -0
- package/dist/core-server/presets/common-override-preset.js +81 -0
- package/dist/core-server/presets/common-preset.js +2187 -0
- package/dist/create/bin/index.js +23 -0
- package/dist/create/index.js +25 -0
- package/dist/csf/csf-utils.d.ts +2 -0
- package/dist/csf/csf-utils.js +19 -0
- package/dist/csf/index.d.ts +7 -0
- package/dist/csf/index.js +2142 -0
- package/dist/csf-tools/index.d.ts +1157 -0
- package/dist/csf-tools/index.js +736 -0
- package/dist/docs-tools/index.d.ts +197 -0
- package/dist/docs-tools/index.js +61 -0
- package/dist/highlight/index.d.ts +10 -0
- package/dist/highlight/index.js +15 -0
- package/dist/instrumenter/index.d.ts +113 -0
- package/dist/instrumenter/index.js +2595 -0
- package/dist/manager/_manager-chunks/globals-runtime-8HkdnU2F.js +6144 -0
- package/dist/manager/_manager-chunks/globals-runtime-BIKBO23x.js +3389 -0
- package/dist/manager/_manager-chunks/globals-runtime-BdGkqNEt.js +45 -0
- package/dist/manager/_manager-chunks/globals-runtime-BmphMP6z.js +1190 -0
- package/dist/manager/_manager-chunks/globals-runtime-BvM-NY2g.js +13307 -0
- package/dist/manager/_manager-chunks/globals-runtime-C02fvgcd.js +9243 -0
- package/dist/manager/_manager-chunks/globals-runtime-DkAPXCvc.js +9766 -0
- package/dist/manager/_manager-chunks/globals-runtime-DpNYC-qi.js +5564 -0
- package/dist/manager/_manager-chunks/globals-runtime-DtcOnYHR.js +5357 -0
- package/dist/manager/_manager-chunks/globals-runtime-DwFqpqya.js +722 -0
- package/dist/manager/_manager-chunks/globals-runtime-FC201B7s.js +6837 -0
- package/dist/manager/_manager-chunks/globals-runtime-Rp_zjGnh.js +121 -0
- package/dist/manager/_manager-chunks/globals-runtime-ZHrQFa3-.js +10463 -0
- package/dist/manager/_manager-chunks/globals-runtime-eLPTIfX-.js +7759 -0
- package/dist/manager/_manager-chunks/globals-runtime-qKvCZHFY.js +4468 -0
- package/dist/manager/_manager-chunks/globals-runtime-sGpNlIJ1.js +5102 -0
- package/dist/manager/_manager-chunks/runtime-B1L9TH89.js +452 -0
- package/dist/manager/_manager-chunks/runtime-BK0zF7FN.js +22 -0
- package/dist/manager/_manager-chunks/runtime-BhkT2CXl.js +1408 -0
- package/dist/manager/_manager-chunks/runtime-Bly6WJLN.js +998 -0
- package/dist/manager/_manager-chunks/runtime-D0UOWx0U.js +979 -0
- package/dist/manager/_manager-chunks/runtime-D94Vq3oR.js +4014 -0
- package/dist/manager/_manager-chunks/runtime-DMig8mT7.js +77 -0
- package/dist/manager/_manager-chunks/runtime-EITvVbkG.js +46 -0
- package/dist/manager/_manager-chunks/runtime-cp5pazY2.js +8936 -0
- package/dist/manager/_manager-chunks/runtime-eDVAYF7N.js +6860 -0
- package/dist/manager/_manager-chunks/runtime-i-PDAHLR.js +2493 -0
- package/dist/manager/globals-runtime.js +2 -0
- package/dist/manager/globals.d.ts +23 -0
- package/dist/manager/globals.js +26 -0
- package/dist/manager/manager-stores.d.ts +2 -0
- package/dist/manager/manager-stores.js +19 -0
- package/dist/manager/runtime.js +2 -0
- package/dist/manager-api/index.d.ts +2 -0
- package/dist/manager-api/index.js +3257 -0
- package/dist/manager-errors.d.ts +89 -0
- package/dist/manager-errors.js +20 -0
- package/dist/mcp/index.d.ts +270 -0
- package/dist/mcp/index.js +305 -0
- package/dist/mocking-utils/index.d.ts +689 -0
- package/dist/mocking-utils/index.js +521 -0
- package/dist/mocking-utils/mocker-runtime.js +1254 -0
- package/dist/nextjs-vite/config/preview.js +3 -0
- package/dist/nextjs-vite/export-mocks/cache/index.d.ts +25 -0
- package/dist/nextjs-vite/export-mocks/cache/index.js +29 -0
- package/dist/nextjs-vite/export-mocks/headers/index.d.ts +37 -0
- package/dist/nextjs-vite/export-mocks/headers/index.js +54 -0
- package/dist/nextjs-vite/export-mocks/link/index.d.ts +9 -0
- package/dist/nextjs-vite/export-mocks/link/index.js +59 -0
- package/dist/nextjs-vite/export-mocks/navigation/index.d.ts +28 -0
- package/dist/nextjs-vite/export-mocks/navigation/index.js +58 -0
- package/dist/nextjs-vite/export-mocks/router/index.d.ts +34 -0
- package/dist/nextjs-vite/export-mocks/router/index.js +63 -0
- package/dist/nextjs-vite/index.d.ts +92 -0
- package/dist/nextjs-vite/index.js +58 -0
- package/dist/nextjs-vite/node/index.d.ts +6 -0
- package/dist/nextjs-vite/node/index.js +20 -0
- package/dist/nextjs-vite/preset.js +648 -0
- package/dist/nextjs-vite/preview.d.ts +20 -0
- package/dist/nextjs-vite/preview.js +11 -0
- package/dist/nextjs-vite/vite-plugin/index.d.ts +6 -0
- package/dist/nextjs-vite/vite-plugin/index.js +19 -0
- package/dist/nextjs-vite-plugin/index.d.ts +28 -0
- package/dist/nextjs-vite-plugin/index.js +923 -0
- package/dist/nextjs-vite-plugin/mocks/storybook.global.js +29 -0
- package/dist/nextjs-vite-plugin/plugins/next-image/alias/image-context.js +8 -0
- package/dist/nextjs-vite-plugin/plugins/next-image/alias/image-default-loader.js +23 -0
- package/dist/nextjs-vite-plugin/plugins/next-image/alias/next-image.js +28 -0
- package/dist/nextjs-vite-plugin/plugins/next-image/alias/next-legacy-image.js +17 -0
- package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/cache/index.js +29 -0
- package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/dynamic/index.js +40 -0
- package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/headers/index.js +55 -0
- package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/link/index.js +63 -0
- package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/navigation/index.js +71 -0
- package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/router/index.js +74 -0
- package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/rsc/server-only.js +7 -0
- package/dist/nextjs-vite-plugin/plugins/next-mocks/alias/safe-stable-stringify/index.js +13 -0
- package/dist/nextjs-vite-plugin/plugins/next-mocks/compatibility/draft-mode.compat.js +7 -0
- package/dist/node-logger/index.d.ts +495 -0
- package/dist/node-logger/index.js +42 -0
- package/dist/oxc-parser/index.d.ts +99 -0
- package/dist/oxc-parser/index.js +275 -0
- package/dist/oxc-parser/worker.js +37 -0
- package/dist/preview/_chunks/runtime-BIzIdDbb.js +10263 -0
- package/dist/preview/_chunks/runtime-BTPtVY1p.js +1102 -0
- package/dist/preview/_chunks/runtime-BZSnICCg.js +8484 -0
- package/dist/preview/_chunks/runtime-BdGkqNEt.js +45 -0
- package/dist/preview/_chunks/runtime-BwSxqk3t.js +63 -0
- package/dist/preview/_chunks/runtime-CqHxptiK.js +6143 -0
- package/dist/preview/_chunks/runtime-CsV4HZPV.js +5064 -0
- package/dist/preview/_chunks/runtime-CxZK_Ln3.js +284 -0
- package/dist/preview/_chunks/runtime-DZToXfvO.js +9767 -0
- package/dist/preview/_chunks/runtime-DrTjJkPY.js +3872 -0
- package/dist/preview/_chunks/runtime-DuHdxMFA.js +387 -0
- package/dist/preview/_chunks/runtime-iXdo8CR8.js +3635 -0
- package/dist/preview/_chunks/runtime-q3wt0e_N.js +6838 -0
- package/dist/preview/globals.d.ts +16 -0
- package/dist/preview/globals.js +20 -0
- package/dist/preview/runtime.js +6 -0
- package/dist/preview-api/index.d.ts +4 -0
- package/dist/preview-api/index.js +147 -0
- package/dist/preview-errors.d.ts +186 -0
- package/dist/preview-errors.js +56 -0
- package/dist/react/docgen/docgen-worker.js +38 -0
- package/dist/react/entry-preview-argtypes.js +9 -0
- package/dist/react/entry-preview-docs.js +12 -0
- package/dist/react/entry-preview-rsc.js +11 -0
- package/dist/react/entry-preview.js +21 -0
- package/dist/react/index.d.ts +119 -0
- package/dist/react/index.js +26 -0
- package/dist/react/preset.js +301 -0
- package/dist/react/preview.d.ts +2 -0
- package/dist/react/preview.js +11 -0
- package/dist/react-native/bin/get-stories.js +34 -0
- package/dist/react-native/index.d.ts +160 -0
- package/dist/react-native/index.js +1547 -0
- package/dist/react-native/metro/node.d.ts +83 -0
- package/dist/react-native/metro/node.js +21 -0
- package/dist/react-native/metro/withStorybook.d.ts +2269 -0
- package/dist/react-native/metro/withStorybook.js +138 -0
- package/dist/react-native/preview.d.ts +6 -0
- package/dist/react-native/preview.js +20 -0
- package/dist/react-native/scripts/generate.d.ts +22 -0
- package/dist/react-native/scripts/generate.js +18 -0
- package/dist/react-native/stub.js +20 -0
- package/dist/react-native-theming/index.d.ts +175 -0
- package/dist/react-native-theming/index.js +2591 -0
- package/dist/react-native-ui/index.d.ts +130 -0
- package/dist/react-native-ui/index.js +1448 -0
- package/dist/react-native-ui-common/index.d.ts +230 -0
- package/dist/react-native-ui-common/index.js +514 -0
- package/dist/react-vite/index.d.ts +4 -0
- package/dist/react-vite/index.js +8 -0
- package/dist/react-vite/node/index.d.ts +6 -0
- package/dist/react-vite/node/index.js +20 -0
- package/dist/react-vite/preset.d.ts +6 -0
- package/dist/react-vite/preset.js +21 -0
- package/dist/router/index.d.ts +141 -0
- package/dist/router/index.js +1217 -0
- package/dist/server-errors.d.ts +2 -0
- package/dist/server-errors.js +149 -0
- package/dist/shared/open-service/index.d.ts +3 -0
- package/dist/shared/open-service/index.js +115 -0
- package/dist/shared/open-service/services/docgen/worker/docgen-worker.js +75 -0
- package/dist/shared/open-service/toolsets/docs/public.d.ts +1296 -0
- package/dist/shared/open-service/toolsets/docs/public.js +991 -0
- package/dist/telemetry/index.d.ts +314 -0
- package/dist/telemetry/index.js +103 -0
- package/dist/test/index.d.ts +158 -0
- package/dist/test/index.js +19421 -0
- package/dist/theming/create.d.ts +15 -0
- package/dist/theming/create.js +11 -0
- package/dist/theming/index.d.ts +54 -0
- package/dist/theming/index.js +511 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +48 -0
- package/dist/viewport/index.d.ts +275 -0
- package/dist/viewport/index.js +21 -0
- package/package.json +1054 -4
- package/template/nextjs-vite/cli/.eslintrc.json +6 -0
- package/template/nextjs-vite/cli/js/Button.jsx +42 -0
- package/template/nextjs-vite/cli/js/Button.stories.js +49 -0
- package/template/nextjs-vite/cli/js/Configure.mdx +470 -0
- package/template/nextjs-vite/cli/js/Header.jsx +58 -0
- package/template/nextjs-vite/cli/js/Header.stories.js +30 -0
- package/template/nextjs-vite/cli/js/Page.jsx +68 -0
- package/template/nextjs-vite/cli/js/Page.stories.js +28 -0
- package/template/nextjs-vite/cli/ts/Button.stories.ts +54 -0
- package/template/nextjs-vite/cli/ts/Button.tsx +39 -0
- package/template/nextjs-vite/cli/ts/Configure.mdx +446 -0
- package/template/nextjs-vite/cli/ts/Header.stories.ts +34 -0
- package/template/nextjs-vite/cli/ts/Header.tsx +54 -0
- package/template/nextjs-vite/cli/ts/Page.stories.ts +33 -0
- package/template/nextjs-vite/cli/ts/Page.tsx +73 -0
- package/template/react/cli/.eslintrc.json +5 -0
- package/template/react/cli/js/Button.jsx +39 -0
- package/template/react/cli/js/Button.stories.js +49 -0
- package/template/react/cli/js/Header.jsx +56 -0
- package/template/react/cli/js/Header.stories.js +29 -0
- package/template/react/cli/js/Page.jsx +69 -0
- package/template/react/cli/js/Page.stories.js +28 -0
- package/template/react/cli/ts/Button.stories.ts +54 -0
- package/template/react/cli/ts/Button.tsx +37 -0
- package/template/react/cli/ts/Header.stories.ts +34 -0
- package/template/react/cli/ts/Header.tsx +56 -0
- package/template/react/cli/ts/Page.stories.ts +33 -0
- package/template/react/cli/ts/Page.tsx +73 -0
- package/template/react-vite/cli/.eslintrc.json +5 -0
- package/template/react-vite/cli/js/Button.jsx +39 -0
- package/template/react-vite/cli/js/Button.stories.js +49 -0
- package/template/react-vite/cli/js/Header.jsx +56 -0
- package/template/react-vite/cli/js/Header.stories.js +29 -0
- package/template/react-vite/cli/js/Page.jsx +69 -0
- package/template/react-vite/cli/js/Page.stories.js +28 -0
- package/template/react-vite/cli/ts/Button.stories.ts +54 -0
- package/template/react-vite/cli/ts/Button.tsx +37 -0
- package/template/react-vite/cli/ts/Header.stories.ts +34 -0
- package/template/react-vite/cli/ts/Header.tsx +56 -0
- package/template/react-vite/cli/ts/Page.stories.ts +33 -0
- package/template/react-vite/cli/ts/Page.tsx +73 -0
|
@@ -0,0 +1,1133 @@
|
|
|
1
|
+
import CJS_COMPAT_NODE_URL_ro17f80mg6k from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_ro17f80mg6k from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_ro17f80mg6k from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_ro17f80mg6k.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_ro17f80mg6k.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_ro17f80mg6k.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Forkbook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import {
|
|
13
|
+
createCsfObject,
|
|
14
|
+
pathForNode,
|
|
15
|
+
unwrapExpression
|
|
16
|
+
} from "./chunk-YZFWBA5L.js";
|
|
17
|
+
import {
|
|
18
|
+
invariant
|
|
19
|
+
} from "./chunk-34EO2PUT.js";
|
|
20
|
+
|
|
21
|
+
// src/csf-tools/ConfigFile.ts
|
|
22
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
23
|
+
import {
|
|
24
|
+
babelParse,
|
|
25
|
+
generate,
|
|
26
|
+
recast,
|
|
27
|
+
types as t2,
|
|
28
|
+
traverse as traverse2
|
|
29
|
+
} from "@aussieljk/forkbook/internal/babel";
|
|
30
|
+
import { logger } from "@aussieljk/forkbook/internal/node-logger";
|
|
31
|
+
import { dedent } from "ts-dedent";
|
|
32
|
+
|
|
33
|
+
// src/csf-tools/ConfigObject.ts
|
|
34
|
+
import { traverse, types as t } from "@aussieljk/forkbook/internal/babel";
|
|
35
|
+
var isConfigFactory = (callee) => {
|
|
36
|
+
if (!callee.isIdentifier())
|
|
37
|
+
return !1;
|
|
38
|
+
let binding = callee.scope.getBinding(callee.node.name), name = binding?.path.isImportSpecifier() ? binding.path.node.imported : binding ? void 0 : callee.node;
|
|
39
|
+
return t.isIdentifier(name) && ["defineMain", "definePreview", "defineConfig"].includes(name.name);
|
|
40
|
+
}, isExportReference = (reference) => {
|
|
41
|
+
let parent = reference.parentPath;
|
|
42
|
+
return parent ? parent.isTSAsExpression() || parent.isTSSatisfiesExpression() || parent.isTSNonNullExpression() ? isExportReference(parent) : reference.isExportNamedDeclaration() || parent.isExportDefaultDeclaration() || parent.isExportSpecifier() || parent.isAssignmentExpression() && t.isMemberExpression(parent.node.left) && t.isIdentifier(parent.node.left.object, { name: "module" }) && t.isIdentifier(parent.node.left.property, { name: "exports" }) : !1;
|
|
43
|
+
};
|
|
44
|
+
function createConfigObject(config, mode, report, markChanged) {
|
|
45
|
+
let result = {
|
|
46
|
+
ok: !1,
|
|
47
|
+
diagnostic: {
|
|
48
|
+
code: "unsupported-initializer",
|
|
49
|
+
target: { kind: "config" },
|
|
50
|
+
path: [],
|
|
51
|
+
message: "Cannot find a mutable config root"
|
|
52
|
+
}
|
|
53
|
+
}, reject = (node, code, message) => {
|
|
54
|
+
result = {
|
|
55
|
+
ok: !1,
|
|
56
|
+
diagnostic: {
|
|
57
|
+
code,
|
|
58
|
+
target: { kind: "config" },
|
|
59
|
+
path: [],
|
|
60
|
+
message,
|
|
61
|
+
...node.loc ? { loc: node.loc } : {}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
return traverse(config._ast, {
|
|
66
|
+
Program(program) {
|
|
67
|
+
program.stop();
|
|
68
|
+
let assignments = [];
|
|
69
|
+
program.traverse({
|
|
70
|
+
AssignmentExpression(path) {
|
|
71
|
+
let { left } = path.node;
|
|
72
|
+
t.isMemberExpression(left) && (t.isIdentifier(left.object, { name: "module" }) && (t.isIdentifier(left.property, { name: "exports" }) || t.isStringLiteral(left.property, { value: "exports" })) || t.isIdentifier(left.object, { name: "exports" })) && assignments.push(path);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
let root = pathForNode(program, config._exportsObject);
|
|
76
|
+
if (root) {
|
|
77
|
+
let declaration = root.findParent((parent) => parent.isVariableDeclarator());
|
|
78
|
+
if (mode === "mutate" && Object.values(config._exportDecls).some((exported) => exported !== declaration?.node)) {
|
|
79
|
+
reject(
|
|
80
|
+
root.node,
|
|
81
|
+
"ambiguous-binding",
|
|
82
|
+
"Cannot mutate mixed default and named config exports"
|
|
83
|
+
);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
for (let parent = root.parentPath; parent && !parent.isProgram(); parent = parent.parentPath) {
|
|
87
|
+
if (!parent.isCallExpression())
|
|
88
|
+
continue;
|
|
89
|
+
let callee = parent.get("callee");
|
|
90
|
+
if (!(callee.isMemberExpression() && !callee.node.computed && t.isIdentifier(callee.node.property, { name: "type" }) && parent.node.arguments.length === 0) && !(isConfigFactory(callee) && parent.node.arguments.length === 1)) {
|
|
91
|
+
reject(
|
|
92
|
+
parent.node,
|
|
93
|
+
"unsupported-initializer",
|
|
94
|
+
"Cannot mutate an arbitrary config factory call"
|
|
95
|
+
);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
let statement = root.getStatementParent();
|
|
100
|
+
if (statement?.isExpressionStatement() && (!t.isAssignmentExpression(statement.node.expression) || !t.isMemberExpression(statement.node.expression.left) || !t.isIdentifier(statement.node.expression.left.object, { name: "module" }) || !t.isIdentifier(statement.node.expression.left.property, { name: "exports" }))) {
|
|
101
|
+
reject(
|
|
102
|
+
root.node,
|
|
103
|
+
"ambiguous-binding",
|
|
104
|
+
"Cannot mutate a config that is not directly exported"
|
|
105
|
+
);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!statement?.parentPath.isProgram() && !statement?.parentPath.isExportNamedDeclaration()) {
|
|
109
|
+
reject(
|
|
110
|
+
root.node,
|
|
111
|
+
"unsupported-initializer",
|
|
112
|
+
"Cannot mutate a config declared inside a function or conditional"
|
|
113
|
+
);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (declaration?.isVariableDeclarator() && t.isIdentifier(declaration.node.id)) {
|
|
117
|
+
let binding = declaration.scope.getBinding(declaration.node.id.name);
|
|
118
|
+
if (!binding?.constant || binding.referencePaths.length !== 1 || !binding.referencePaths.every(isExportReference)) {
|
|
119
|
+
reject(
|
|
120
|
+
declaration.node,
|
|
121
|
+
"ambiguous-binding",
|
|
122
|
+
"Cannot mutate a shared or reassigned config binding"
|
|
123
|
+
);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (assignments.length > 1 || assignments.some(
|
|
128
|
+
(assignment) => assignment.scope.hasBinding("module") || t.isMemberExpression(assignment.node.left) && assignment.node.left.computed || !assignment.parentPath.parentPath?.isProgram()
|
|
129
|
+
)) {
|
|
130
|
+
reject(
|
|
131
|
+
root.node,
|
|
132
|
+
"ambiguous-binding",
|
|
133
|
+
"Cannot mutate conditional, repeated, or shadowed module.exports"
|
|
134
|
+
);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
result = {
|
|
138
|
+
ok: !0,
|
|
139
|
+
object: createCsfObject({ kind: "config" }, root, [], report, markChanged)
|
|
140
|
+
};
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (config.hasDefaultExport || assignments.length > 0) {
|
|
144
|
+
reject(
|
|
145
|
+
config._ast.program,
|
|
146
|
+
"unsupported-initializer",
|
|
147
|
+
"Cannot mutate a config without a static object initializer"
|
|
148
|
+
);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
let named = /* @__PURE__ */ new Map(), virtualRoot = t.objectExpression([]), seen = /* @__PURE__ */ new Set();
|
|
152
|
+
for (let statement of program.get("body"))
|
|
153
|
+
if (!(statement.isExportNamedDeclaration() && statement.node.exportKind === "type")) {
|
|
154
|
+
if (statement.isExportAllDeclaration() || statement.isExportNamedDeclaration() && statement.node.source) {
|
|
155
|
+
reject(
|
|
156
|
+
statement.node,
|
|
157
|
+
"unsupported-initializer",
|
|
158
|
+
"Cannot mutate re-exported config fields"
|
|
159
|
+
);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (statement.isExportNamedDeclaration())
|
|
163
|
+
for (let specifier of statement.get("specifiers")) {
|
|
164
|
+
if (!specifier.isExportSpecifier() || specifier.node.exportKind === "type")
|
|
165
|
+
continue;
|
|
166
|
+
let name = t.isIdentifier(specifier.node.exported) ? specifier.node.exported.name : specifier.node.exported.value;
|
|
167
|
+
if (!Object.hasOwn(config._exportDecls, name)) {
|
|
168
|
+
reject(
|
|
169
|
+
specifier.node,
|
|
170
|
+
"unsupported-initializer",
|
|
171
|
+
`Cannot mutate the unresolved ${name} export`
|
|
172
|
+
);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
for (let [name, node] of Object.entries(config._exportDecls)) {
|
|
178
|
+
let declaration = pathForNode(program, node);
|
|
179
|
+
if (!(declaration?.isVariableDeclarator() || declaration?.isFunctionDeclaration()) || !t.isIdentifier(declaration.node.id)) {
|
|
180
|
+
reject(
|
|
181
|
+
node,
|
|
182
|
+
"unsupported-initializer",
|
|
183
|
+
`Cannot mutate the ${name} export without an expression initializer`
|
|
184
|
+
);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
let binding = declaration.scope.getBinding(declaration.node.id.name);
|
|
188
|
+
if (!binding?.constant || seen.has(node) || mode === "mutate" && !binding.referencePaths.every(isExportReference)) {
|
|
189
|
+
reject(
|
|
190
|
+
node,
|
|
191
|
+
"ambiguous-binding",
|
|
192
|
+
`Cannot mutate the shared or reassigned ${name} export`
|
|
193
|
+
);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
seen.add(node);
|
|
197
|
+
let specifier = binding.referencePaths.find(
|
|
198
|
+
(path) => path.parentPath?.isExportSpecifier()
|
|
199
|
+
)?.parentPath, value = declaration.isFunctionDeclaration() ? t.toExpression(t.cloneNode(declaration.node)) : declaration.node.init;
|
|
200
|
+
if (!t.isExpression(value)) {
|
|
201
|
+
reject(
|
|
202
|
+
node,
|
|
203
|
+
"unsupported-initializer",
|
|
204
|
+
`Cannot mutate the ${name} export without an expression initializer`
|
|
205
|
+
);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
let property = t.objectProperty(t.stringLiteral(name), value);
|
|
209
|
+
virtualRoot.properties.push(property), named.set(property, {
|
|
210
|
+
declaration,
|
|
211
|
+
...specifier?.isExportSpecifier() ? { specifier } : {}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
let syncExports = () => {
|
|
215
|
+
for (let [property, entry] of named)
|
|
216
|
+
virtualRoot.properties.includes(property) || (entry.specifier ? entry.specifier.remove() : entry.declaration.remove(), named.delete(property));
|
|
217
|
+
for (let property of virtualRoot.properties) {
|
|
218
|
+
if (!t.isObjectProperty(property) || !t.isExpression(property.value))
|
|
219
|
+
continue;
|
|
220
|
+
let name = t.isIdentifier(property.key) ? property.key.name : t.isStringLiteral(property.key) ? property.key.value : void 0;
|
|
221
|
+
if (name === void 0)
|
|
222
|
+
continue;
|
|
223
|
+
let entry = named.get(property);
|
|
224
|
+
if (entry) {
|
|
225
|
+
if (entry.declaration.isFunctionDeclaration())
|
|
226
|
+
if (t.isFunctionExpression(property.value) && (!property.value.id || property.value.id.name === entry.declaration.node.id?.name)) {
|
|
227
|
+
let { params, body, async, generator, returnType, typeParameters } = property.value;
|
|
228
|
+
Object.assign(entry.declaration.node, {
|
|
229
|
+
params,
|
|
230
|
+
body,
|
|
231
|
+
async,
|
|
232
|
+
generator,
|
|
233
|
+
returnType,
|
|
234
|
+
typeParameters
|
|
235
|
+
});
|
|
236
|
+
} else {
|
|
237
|
+
let id2 = entry.declaration.node.id;
|
|
238
|
+
if (!id2)
|
|
239
|
+
continue;
|
|
240
|
+
let variable2 = t.variableDeclarator(id2, property.value);
|
|
241
|
+
entry.declaration.replaceWith(t.variableDeclaration("const", [variable2]));
|
|
242
|
+
let path = pathForNode(program, variable2);
|
|
243
|
+
path && (entry.declaration = path);
|
|
244
|
+
}
|
|
245
|
+
else entry.declaration.isVariableDeclarator() && (entry.declaration.node.init = property.value);
|
|
246
|
+
if (entry.specifier) {
|
|
247
|
+
entry.specifier.node.exported = t.isValidIdentifier(name) ? t.identifier(name) : t.stringLiteral(name);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (t.isValidIdentifier(name) && (t.isIdentifier(entry.declaration.node.id, { name }) || !program.scope.hasBinding(name))) {
|
|
251
|
+
entry.declaration.node.id = t.identifier(name);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
entry.declaration.remove();
|
|
255
|
+
}
|
|
256
|
+
let id = t.isValidIdentifier(name) && !program.scope.hasBinding(name) ? t.identifier(name) : program.scope.generateUidIdentifier(name), declaration = t.variableDeclarator(id, property.value), variable = t.variableDeclaration("const", [declaration]);
|
|
257
|
+
if (id.name === name)
|
|
258
|
+
program.pushContainer("body", t.exportNamedDeclaration(variable));
|
|
259
|
+
else {
|
|
260
|
+
let specifier = t.exportSpecifier(
|
|
261
|
+
id,
|
|
262
|
+
t.isValidIdentifier(name) ? t.identifier(name) : t.stringLiteral(name)
|
|
263
|
+
);
|
|
264
|
+
program.pushContainer("body", [variable, t.exportNamedDeclaration(null, [specifier])]);
|
|
265
|
+
}
|
|
266
|
+
let declarationPath = pathForNode(program, declaration);
|
|
267
|
+
if (declarationPath) {
|
|
268
|
+
let specifierPath = program.get("body").flatMap(
|
|
269
|
+
(statement) => statement.isExportNamedDeclaration() ? statement.get("specifiers") : []
|
|
270
|
+
).find((specifier) => specifier.isExportSpecifier() && specifier.node.local === id);
|
|
271
|
+
named.set(property, {
|
|
272
|
+
declaration: declarationPath,
|
|
273
|
+
...specifierPath?.isExportSpecifier() ? { specifier: specifierPath } : {}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
program.scope.crawl(), markChanged();
|
|
278
|
+
};
|
|
279
|
+
result = {
|
|
280
|
+
ok: !0,
|
|
281
|
+
object: createCsfObject(
|
|
282
|
+
{ kind: "config" },
|
|
283
|
+
{
|
|
284
|
+
node: virtualRoot,
|
|
285
|
+
detached: !0,
|
|
286
|
+
scope: program.scope,
|
|
287
|
+
buildCodeFrameError: program.buildCodeFrameError.bind(program)
|
|
288
|
+
},
|
|
289
|
+
[],
|
|
290
|
+
report,
|
|
291
|
+
syncExports
|
|
292
|
+
)
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}), result;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// src/csf-tools/ConfigFile.ts
|
|
299
|
+
var getCsfParsingErrorMessage = ({
|
|
300
|
+
fileName,
|
|
301
|
+
expectedType,
|
|
302
|
+
foundType,
|
|
303
|
+
node
|
|
304
|
+
}) => dedent`
|
|
305
|
+
CSF Parsing error in ${fileName ?? "a config file"}: Expected '${expectedType}' but found '${foundType}' instead in '${node?.type}'.
|
|
306
|
+
`, propKey = (p) => t2.isIdentifier(p.key) ? p.key.name : t2.isStringLiteral(p.key) ? p.key.value : null, _getPath = (path, node) => {
|
|
307
|
+
if (path.length === 0)
|
|
308
|
+
return node;
|
|
309
|
+
if (t2.isObjectExpression(node)) {
|
|
310
|
+
let [first, ...rest] = path, field = node.properties.find((p) => propKey(p) === first);
|
|
311
|
+
if (field)
|
|
312
|
+
return _getPath(rest, field.value);
|
|
313
|
+
}
|
|
314
|
+
}, _getPathProperties = (path, node) => {
|
|
315
|
+
if (path.length === 0) {
|
|
316
|
+
if (t2.isObjectExpression(node))
|
|
317
|
+
return node.properties;
|
|
318
|
+
throw new Error("Expected object expression");
|
|
319
|
+
}
|
|
320
|
+
if (t2.isObjectExpression(node)) {
|
|
321
|
+
let [first, ...rest] = path, field = node.properties.find((p) => propKey(p) === first);
|
|
322
|
+
if (field)
|
|
323
|
+
return rest.length === 0 ? node.properties : _getPathProperties(rest, field.value);
|
|
324
|
+
}
|
|
325
|
+
}, _findVarDeclarator = (identifier, program) => {
|
|
326
|
+
let declarator = null, declarations = null;
|
|
327
|
+
return program.body.find((node) => (t2.isVariableDeclaration(node) ? declarations = node.declarations : t2.isExportNamedDeclaration(node) && t2.isVariableDeclaration(node.declaration) && (declarations = node.declaration.declarations), declarations && declarations.find((decl) => t2.isVariableDeclarator(decl) && t2.isIdentifier(decl.id) && decl.id.name === identifier ? (declarator = decl, !0) : !1))), declarator;
|
|
328
|
+
}, _findVarInitialization = (identifier, program) => _findVarDeclarator(identifier, program)?.init, NEXT_LINE_DIRECTIVE = /^\s*(@ts-(expect-error|ignore)|[a-z]+-disable-next-line|prettier-ignore|biome-ignore)\b/, getHeaderComments = (statement) => {
|
|
329
|
+
let leading = (statement?.comments ?? []).filter((comment) => comment.leading), directive = leading.findIndex(({ value }) => NEXT_LINE_DIRECTIVE.test(value));
|
|
330
|
+
return directive === -1 ? leading : leading.slice(0, directive);
|
|
331
|
+
}, prependStatement = (program, statement) => {
|
|
332
|
+
let first = program.body[0], header = getHeaderComments(first);
|
|
333
|
+
if (!first || !header.length) {
|
|
334
|
+
program.body.unshift(statement);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
let firstNonImport = program.body.findIndex((node) => !t2.isImportDeclaration(node)), index = firstNonImport === -1 ? program.body.length : firstNonImport;
|
|
338
|
+
if (index === 0) {
|
|
339
|
+
let notHeader = (comment) => !header.includes(comment);
|
|
340
|
+
first.comments = first.comments?.filter(notHeader), first.leadingComments = first.leadingComments?.filter(notHeader), Object.assign(statement, { comments: header, leadingComments: header });
|
|
341
|
+
}
|
|
342
|
+
program.body.splice(index, 0, statement);
|
|
343
|
+
}, ConfigFile = class {
|
|
344
|
+
constructor(ast, code, fileName) {
|
|
345
|
+
/**
|
|
346
|
+
* Identify the config, meta, story, annotation, or call argument this editor represents.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* const object = loadConfig('export default {};').parse();
|
|
351
|
+
* object.target; // { kind: 'config' }
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
this.target = { kind: "config" };
|
|
355
|
+
// No member may be private: core resolves this class from both src and dist, and any private
|
|
356
|
+
// member makes the emitted class type nominal, so the two identities stop being assignable.
|
|
357
|
+
this._changed = !1;
|
|
358
|
+
this._mutationDiagnostics = [];
|
|
359
|
+
this._exports = {};
|
|
360
|
+
// FIXME: this is a hack. this is only used in the case where the user is
|
|
361
|
+
// modifying a named export that's a scalar. The _exports map is not suitable
|
|
362
|
+
// for that. But rather than refactor the whole thing, we just use this as a stopgap.
|
|
363
|
+
this._exportDecls = {};
|
|
364
|
+
this.hasDefaultExport = !1;
|
|
365
|
+
/** Unwraps TS assertions/satisfies from a node, to get the underlying node. */
|
|
366
|
+
this._unwrap = (node) => t2.isTSAsExpression(node) || t2.isTSSatisfiesExpression(node) ? this._unwrap(node.expression) : node;
|
|
367
|
+
/**
|
|
368
|
+
* Resolve a declaration node by unwrapping TS assertions/satisfies and following identifiers to
|
|
369
|
+
* resolve the correct node in case it's an identifier.
|
|
370
|
+
*/
|
|
371
|
+
this._resolveDeclaration = (node, parent = this._ast.program) => {
|
|
372
|
+
let decl = this._unwrap(node);
|
|
373
|
+
if (t2.isIdentifier(decl) && t2.isProgram(parent)) {
|
|
374
|
+
let initialization = _findVarInitialization(decl.name, parent);
|
|
375
|
+
return initialization ? this._unwrap(initialization) : decl;
|
|
376
|
+
}
|
|
377
|
+
return decl;
|
|
378
|
+
};
|
|
379
|
+
this._ast = ast, this._code = code, this.fileName = fileName;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Report whether this editor has applied a mutation. Reads and no-op edits leave it unchanged.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* const object = loadConfig('export default {};').parse();
|
|
387
|
+
* object.changed; // false
|
|
388
|
+
* object.set(['tags'], ['autodocs']);
|
|
389
|
+
* object.changed; // true
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
get changed() {
|
|
393
|
+
return this._changed;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Read diagnostics from unsupported discovery, reads, or mutations. `writeConfig` refuses to
|
|
397
|
+
* write a config with diagnostics, even if another edit succeeded.
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ```ts
|
|
401
|
+
* const config = loadConfig('export default { old: 1, current: 2 };').parse();
|
|
402
|
+
* config.rename(['old'], 'current');
|
|
403
|
+
* config.mutationDiagnostics.map(({ code }) => code); // ['occupied-destination']
|
|
404
|
+
* config.changed; // false
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
get mutationDiagnostics() {
|
|
408
|
+
return [...this._mutationDiagnostics];
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Read a copy of the Babel expression at a property path. Missing fields return `undefined`.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* ```ts
|
|
415
|
+
* const object = loadConfig("export default { tags: ['docs'] };").parse();
|
|
416
|
+
* object.get(['tags'])?.type; // 'ArrayExpression'
|
|
417
|
+
* object.get(['missing']); // undefined
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
get(path) {
|
|
421
|
+
let editor = this._editor("read");
|
|
422
|
+
return editor.ok ? editor.object.get(path) : void 0;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Read plain values without executing code. Missing fields return `undefined`; unresolved
|
|
426
|
+
* expressions also return `undefined` and add a mutation diagnostic.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```ts
|
|
430
|
+
* const object = loadConfig("export default { tags: ['docs'], enabled: true };").parse();
|
|
431
|
+
* object.getValue(['tags']); // ['docs']
|
|
432
|
+
* object.getValue(['enabled']); // true
|
|
433
|
+
* object.getValue(['missing']); // undefined
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
getValue(path) {
|
|
437
|
+
let editor = this._editor("read");
|
|
438
|
+
return editor.ok ? editor.object.getValue(path) : void 0;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Set a plain value or Babel expression, creating missing parents. Accepts nested arrays and
|
|
442
|
+
* objects; top-level expression-shaped objects are interpreted as AST nodes.
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```ts
|
|
446
|
+
* const object = loadConfig('export default {};').parse();
|
|
447
|
+
* object.set(['parameters', 'a11y'], { test: 'todo', enabled: true });
|
|
448
|
+
* // { ok: true, changed: true }
|
|
449
|
+
* object.getValue(['parameters']); // { a11y: { test: 'todo', enabled: true } }
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
set(path, value) {
|
|
453
|
+
return this._mutate((object) => object.set(path, value));
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Replace a value using its live Babel expression. Reused nodes preserve their source formatting.
|
|
457
|
+
* Return a new node, or `undefined` to leave the value unchanged. Do not mutate or retain the input
|
|
458
|
+
* node: such changes bypass change tracking and diagnostics.
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ```ts
|
|
462
|
+
* const object = loadConfig("export default { tags: ['docs'] };").parse();
|
|
463
|
+
* object.transform(['tags'], (value) =>
|
|
464
|
+
* t.arrayExpression([t.spreadElement(value), t.stringLiteral('autodocs')])
|
|
465
|
+
* ); // { ok: true, changed: true }
|
|
466
|
+
* object.getValue(['tags']); // ['docs', 'autodocs']
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
transform(path, derive) {
|
|
470
|
+
return this._mutate((object) => object.transform(path, derive));
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Remove a property and recursively clean up empty parents. Missing fields are a no-op.
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```ts
|
|
477
|
+
* const object = loadConfig('export default { parameters: { a11y: { disable: true } } };').parse();
|
|
478
|
+
* object.remove(['parameters', 'a11y', 'disable']); // { ok: true, changed: true }
|
|
479
|
+
* object.getValue(['parameters']); // undefined
|
|
480
|
+
* object.remove(['parameters']); // { ok: true, changed: false }
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
remove(path) {
|
|
484
|
+
return this._mutate((object) => object.remove(path));
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Rename a property within its parent. An occupied destination produces a diagnostic
|
|
488
|
+
* and leaves the source unchanged.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```ts
|
|
492
|
+
* const object = loadConfig("export default { a11y: { element: '#root' } };").parse();
|
|
493
|
+
* object.rename(['a11y', 'element'], 'context'); // { ok: true, changed: true }
|
|
494
|
+
* object.getValue(['a11y']); // { context: '#root' }
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
rename(path, name) {
|
|
498
|
+
return this._mutate((object) => object.rename(path, name));
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Move a property to another path, creating missing destination parents and cleaning up
|
|
502
|
+
* empty source parents. Rejects occupied destinations. Use `group` when nesting siblings must
|
|
503
|
+
* preserve expression evaluation order.
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```ts
|
|
507
|
+
* const object = loadConfig("export default { globals: { theme: 'dark' } };").parse();
|
|
508
|
+
* object.move(['globals'], ['initialGlobals']); // { ok: true, changed: true }
|
|
509
|
+
* object.getValue(['initialGlobals']); // { theme: 'dark' }
|
|
510
|
+
* object.getValue(['globals']); // undefined
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
move(from, to) {
|
|
514
|
+
return this._mutate((object) => object.move(from, to));
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Nest named sibling properties under a destination, retaining their source order. Rejects
|
|
518
|
+
* conflicts and relocations that could change evaluation order. Missing source fields are ignored.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```ts
|
|
522
|
+
* const object = loadConfig('export default { showNav: false, showPanel: true };').parse();
|
|
523
|
+
* object.group(['layout'], ['showNav', 'showPanel']); // { ok: true, changed: true }
|
|
524
|
+
* object.getValue(['layout']); // { showNav: false, showPanel: true }
|
|
525
|
+
* object.getValue(['showNav']); // undefined
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
group(path, names) {
|
|
529
|
+
return this._mutate((object) => object.group(path, names));
|
|
530
|
+
}
|
|
531
|
+
_mutate(operation) {
|
|
532
|
+
let editor = this._editor("mutate");
|
|
533
|
+
return editor.ok === !0 ? operation(editor.object) : { ok: !1, changed: !1, diagnostic: editor.diagnostic };
|
|
534
|
+
}
|
|
535
|
+
_editor(mode) {
|
|
536
|
+
let editor = createConfigObject(
|
|
537
|
+
this,
|
|
538
|
+
mode,
|
|
539
|
+
(diagnostic) => this._mutationDiagnostics.push(diagnostic),
|
|
540
|
+
() => {
|
|
541
|
+
this._changed = !0, this._exports = {}, this._exportDecls = {}, this.parse();
|
|
542
|
+
}
|
|
543
|
+
);
|
|
544
|
+
return editor.ok === !1 && this._mutationDiagnostics.push(editor.diagnostic), editor;
|
|
545
|
+
}
|
|
546
|
+
_parseExportsObject(exportsObject) {
|
|
547
|
+
this._exportsObject = exportsObject, exportsObject.properties.forEach((p) => {
|
|
548
|
+
let exportName = propKey(p);
|
|
549
|
+
if (exportName) {
|
|
550
|
+
let exportVal = this._resolveDeclaration(p.value);
|
|
551
|
+
this._exports[exportName] = exportVal;
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
parse() {
|
|
556
|
+
this._inferQuotes();
|
|
557
|
+
let self = this;
|
|
558
|
+
return traverse2(this._ast, {
|
|
559
|
+
ExportDefaultDeclaration: {
|
|
560
|
+
enter({ node, parent }) {
|
|
561
|
+
self.hasDefaultExport = !0;
|
|
562
|
+
let decl = self._resolveDeclaration(node.declaration, parent);
|
|
563
|
+
for (; t2.isCallExpression(decl); )
|
|
564
|
+
if (t2.isObjectExpression(decl.arguments[0])) {
|
|
565
|
+
decl = decl.arguments[0];
|
|
566
|
+
break;
|
|
567
|
+
} else if (t2.isMemberExpression(decl.callee) && t2.isCallExpression(decl.callee.object))
|
|
568
|
+
decl = decl.callee.object;
|
|
569
|
+
else
|
|
570
|
+
break;
|
|
571
|
+
t2.isObjectExpression(decl) ? self._parseExportsObject(decl) : logger.debug(
|
|
572
|
+
getCsfParsingErrorMessage({
|
|
573
|
+
fileName: self.fileName,
|
|
574
|
+
expectedType: "ObjectExpression",
|
|
575
|
+
foundType: decl?.type,
|
|
576
|
+
node: decl || node.declaration
|
|
577
|
+
})
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
ExportNamedDeclaration: {
|
|
582
|
+
enter({ node, parent }) {
|
|
583
|
+
if (t2.isVariableDeclaration(node.declaration))
|
|
584
|
+
node.declaration.declarations.forEach((decl) => {
|
|
585
|
+
if (t2.isVariableDeclarator(decl) && t2.isIdentifier(decl.id)) {
|
|
586
|
+
let { name: exportName } = decl.id, exportVal = self._resolveDeclaration(decl.init, parent);
|
|
587
|
+
self._exports[exportName] = exportVal, self._exportDecls[exportName] = decl;
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
else if (t2.isFunctionDeclaration(node.declaration)) {
|
|
591
|
+
let decl = node.declaration;
|
|
592
|
+
if (t2.isIdentifier(decl.id)) {
|
|
593
|
+
let { name: exportName } = decl.id;
|
|
594
|
+
self._exportDecls[exportName] = decl, self._exports[exportName] = t2.toExpression(t2.cloneNode(decl));
|
|
595
|
+
}
|
|
596
|
+
} else node.specifiers ? node.specifiers.forEach((spec) => {
|
|
597
|
+
if (t2.isExportSpecifier(spec) && t2.isIdentifier(spec.local) && (t2.isIdentifier(spec.exported) || t2.isStringLiteral(spec.exported))) {
|
|
598
|
+
let { name: localName } = spec.local, exportName = t2.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value, decl = _findVarDeclarator(localName, self._ast.program) ?? self._ast.program.body.find(
|
|
599
|
+
(statement) => t2.isFunctionDeclaration(statement) && statement.id?.name === localName
|
|
600
|
+
);
|
|
601
|
+
if (decl) {
|
|
602
|
+
let value = t2.isFunctionDeclaration(decl) ? t2.toExpression(t2.cloneNode(decl)) : decl.init ? self._resolveDeclaration(decl.init, parent) : void 0;
|
|
603
|
+
if (exportName === "default" && t2.isObjectExpression(value)) {
|
|
604
|
+
self.hasDefaultExport = !0, self._parseExportsObject(value);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
self._exports[exportName] = value, self._exportDecls[exportName] = decl;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}) : logger.debug(
|
|
611
|
+
getCsfParsingErrorMessage({
|
|
612
|
+
fileName: self.fileName,
|
|
613
|
+
expectedType: "VariableDeclaration",
|
|
614
|
+
foundType: node.declaration?.type,
|
|
615
|
+
node: node.declaration
|
|
616
|
+
})
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
ExpressionStatement: {
|
|
621
|
+
enter({ node, parent }) {
|
|
622
|
+
if (t2.isAssignmentExpression(node.expression) && node.expression.operator === "=") {
|
|
623
|
+
let { left, right } = node.expression;
|
|
624
|
+
if (t2.isMemberExpression(left) && t2.isIdentifier(left.object) && left.object.name === "module" && t2.isIdentifier(left.property) && left.property.name === "exports") {
|
|
625
|
+
let exportObject = right;
|
|
626
|
+
exportObject = self._resolveDeclaration(exportObject, parent), t2.isObjectExpression(exportObject) ? (self._exportsObject = exportObject, exportObject.properties.forEach((p) => {
|
|
627
|
+
let exportName = propKey(p);
|
|
628
|
+
if (exportName) {
|
|
629
|
+
let exportVal = self._resolveDeclaration(p.value, parent);
|
|
630
|
+
self._exports[exportName] = exportVal;
|
|
631
|
+
}
|
|
632
|
+
})) : logger.debug(
|
|
633
|
+
getCsfParsingErrorMessage({
|
|
634
|
+
fileName: self.fileName,
|
|
635
|
+
expectedType: "ObjectExpression",
|
|
636
|
+
foundType: exportObject?.type,
|
|
637
|
+
node: exportObject
|
|
638
|
+
})
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
CallExpression: {
|
|
645
|
+
enter: ({ node }) => {
|
|
646
|
+
t2.isIdentifier(node.callee) && node.callee.name === "definePreview" && node.arguments.length === 1 && t2.isObjectExpression(node.arguments[0]) && self._parseExportsObject(node.arguments[0]);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}), self;
|
|
650
|
+
}
|
|
651
|
+
getFieldNode(path) {
|
|
652
|
+
let [root, ...rest] = path, exported = this._exports[root];
|
|
653
|
+
if (exported)
|
|
654
|
+
return _getPath(rest, exported);
|
|
655
|
+
}
|
|
656
|
+
getFieldProperties(path) {
|
|
657
|
+
let [root, ...rest] = path, exported = this._exports[root];
|
|
658
|
+
if (exported)
|
|
659
|
+
return _getPathProperties(rest, exported);
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* @example
|
|
663
|
+
*
|
|
664
|
+
* ```ts
|
|
665
|
+
* // 1. { framework: 'framework-name' }
|
|
666
|
+
* // 2. { framework: { name: 'framework-name', options: {} }
|
|
667
|
+
* getNameFromPath(['framework']); // => 'framework-name'
|
|
668
|
+
* ```
|
|
669
|
+
*
|
|
670
|
+
* @returns The name of a node in a given path, supporting the following formats:
|
|
671
|
+
*/
|
|
672
|
+
getNameFromPath(path) {
|
|
673
|
+
let node = this.getFieldNode(path);
|
|
674
|
+
if (node)
|
|
675
|
+
return this._getPresetValue(node, "name");
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Returns an array of names of a node in a given path, supporting the following formats:
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
*
|
|
682
|
+
* ```ts
|
|
683
|
+
* const config = {
|
|
684
|
+
* addons: ['first-addon', { name: 'second-addon', options: {} }],
|
|
685
|
+
* };
|
|
686
|
+
* // => ['first-addon', 'second-addon']
|
|
687
|
+
* getNamesFromPath(['addons']);
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
getNamesFromPath(path) {
|
|
691
|
+
let node = this.getFieldNode(path);
|
|
692
|
+
if (!node)
|
|
693
|
+
return;
|
|
694
|
+
let pathNames = [];
|
|
695
|
+
return t2.isArrayExpression(node) && node.elements.forEach((element) => {
|
|
696
|
+
pathNames.push(this._getPresetValue(element, "name"));
|
|
697
|
+
}), pathNames;
|
|
698
|
+
}
|
|
699
|
+
_getWrappedValue(node) {
|
|
700
|
+
if (t2.isCallExpression(node)) {
|
|
701
|
+
let arg = node.arguments[0];
|
|
702
|
+
if (t2.isStringLiteral(arg))
|
|
703
|
+
return arg.value;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Given a node and a fallback property, returns a **non-evaluated** string value of the node.
|
|
708
|
+
*
|
|
709
|
+
* 1. `{ node: 'value' }`
|
|
710
|
+
* 2. `{ node: { fallbackProperty: 'value' } }`
|
|
711
|
+
*/
|
|
712
|
+
_getPresetValue(node, fallbackProperty) {
|
|
713
|
+
let value;
|
|
714
|
+
if (t2.isStringLiteral(node) ? value = node.value : t2.isObjectExpression(node) ? node.properties.forEach((prop) => {
|
|
715
|
+
t2.isObjectProperty(prop) && t2.isIdentifier(prop.key) && prop.key.name === fallbackProperty && (t2.isStringLiteral(prop.value) ? value = prop.value.value : value = this._getWrappedValue(prop.value)), t2.isObjectProperty(prop) && t2.isStringLiteral(prop.key) && prop.key.value === "name" && t2.isStringLiteral(prop.value) && (value = prop.value.value);
|
|
716
|
+
}) : t2.isCallExpression(node) && (value = this._getWrappedValue(node)), !value)
|
|
717
|
+
throw new Error(
|
|
718
|
+
`The given node must be a string literal or an object expression with a "${fallbackProperty}" property that is a string literal.`
|
|
719
|
+
);
|
|
720
|
+
return value;
|
|
721
|
+
}
|
|
722
|
+
removeField(path) {
|
|
723
|
+
let removeProperty = (properties2, prop) => {
|
|
724
|
+
let index = properties2.findIndex(
|
|
725
|
+
(p) => t2.isIdentifier(p.key) && p.key.name === prop || t2.isStringLiteral(p.key) && p.key.value === prop
|
|
726
|
+
);
|
|
727
|
+
index >= 0 && properties2.splice(index, 1);
|
|
728
|
+
};
|
|
729
|
+
if (path.length === 1) {
|
|
730
|
+
let removedRootProperty = !1;
|
|
731
|
+
if (this._ast.program.body.forEach((node) => {
|
|
732
|
+
if (t2.isExportNamedDeclaration(node) && t2.isVariableDeclaration(node.declaration)) {
|
|
733
|
+
let decl = node.declaration.declarations[0];
|
|
734
|
+
t2.isIdentifier(decl.id) && decl.id.name === path[0] && (this._ast.program.body.splice(this._ast.program.body.indexOf(node), 1), removedRootProperty = !0);
|
|
735
|
+
}
|
|
736
|
+
if (t2.isExportDefaultDeclaration(node)) {
|
|
737
|
+
let resolved = this._resolveDeclaration(node.declaration);
|
|
738
|
+
if (t2.isObjectExpression(resolved)) {
|
|
739
|
+
let properties2 = resolved.properties;
|
|
740
|
+
removeProperty(properties2, path[0]), removedRootProperty = !0;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
if (t2.isExpressionStatement(node) && t2.isAssignmentExpression(node.expression) && t2.isMemberExpression(node.expression.left) && t2.isIdentifier(node.expression.left.object) && node.expression.left.object.name === "module" && t2.isIdentifier(node.expression.left.property) && node.expression.left.property.name === "exports" && t2.isObjectExpression(node.expression.right)) {
|
|
744
|
+
let properties2 = node.expression.right.properties;
|
|
745
|
+
removeProperty(properties2, path[0]), removedRootProperty = !0;
|
|
746
|
+
}
|
|
747
|
+
}), removedRootProperty)
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
let properties = this.getFieldProperties(path);
|
|
751
|
+
if (properties) {
|
|
752
|
+
let lastPath = path.at(-1);
|
|
753
|
+
removeProperty(properties, lastPath);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
appendValueToArray(path, value) {
|
|
757
|
+
let node = this.valueToNode(value);
|
|
758
|
+
node && this.appendNodeToArray(path, node);
|
|
759
|
+
}
|
|
760
|
+
appendNodeToArray(path, node) {
|
|
761
|
+
let current = this.getFieldNode(path);
|
|
762
|
+
if (!current)
|
|
763
|
+
this.set(path, t2.arrayExpression([node]));
|
|
764
|
+
else if (t2.isArrayExpression(current))
|
|
765
|
+
current.elements.push(node);
|
|
766
|
+
else
|
|
767
|
+
throw new Error(`Expected array at '${path.join(".")}', got '${current.type}'`);
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Specialized helper to remove addons or other array entries that can either be strings or
|
|
771
|
+
* objects with a name property.
|
|
772
|
+
*/
|
|
773
|
+
removeEntryFromArray(path, value) {
|
|
774
|
+
let current = this.getFieldNode(path);
|
|
775
|
+
if (current)
|
|
776
|
+
if (t2.isArrayExpression(current)) {
|
|
777
|
+
let index = current.elements.findIndex((element) => t2.isStringLiteral(element) ? element.value === value : t2.isObjectExpression(element) ? this._getPresetValue(element, "name") === value : this._getWrappedValue(element) === value);
|
|
778
|
+
if (index >= 0)
|
|
779
|
+
current.elements.splice(index, 1);
|
|
780
|
+
else
|
|
781
|
+
throw new Error(`Could not find '${value}' in array at '${path.join(".")}'`);
|
|
782
|
+
} else
|
|
783
|
+
throw new Error(`Expected array at '${path.join(".")}', got '${current.type}'`);
|
|
784
|
+
}
|
|
785
|
+
_inferQuotes() {
|
|
786
|
+
if (!this._quotes) {
|
|
787
|
+
let occurrences = { "'": 0, '"': 0 }, countQuotes = ({ node }) => {
|
|
788
|
+
let raw = node.extra?.raw;
|
|
789
|
+
typeof raw == "string" && (raw[0] === "'" || raw[0] === '"') && (occurrences[raw[0]] += 1);
|
|
790
|
+
};
|
|
791
|
+
traverse2(this._ast, {
|
|
792
|
+
StringLiteral: { enter: countQuotes },
|
|
793
|
+
DirectiveLiteral: { enter: countQuotes }
|
|
794
|
+
}), this._quotes = occurrences["'"] > occurrences['"'] ? "single" : "double";
|
|
795
|
+
}
|
|
796
|
+
return this._quotes;
|
|
797
|
+
}
|
|
798
|
+
valueToNode(value) {
|
|
799
|
+
let quotes = this._inferQuotes(), valueNode;
|
|
800
|
+
if (quotes === "single") {
|
|
801
|
+
let { code } = generate(t2.valueToNode(value), { jsescOption: { quotes } }), program = babelParse(`const __x = ${code}`);
|
|
802
|
+
traverse2(program, {
|
|
803
|
+
VariableDeclaration: {
|
|
804
|
+
enter({ node }) {
|
|
805
|
+
node.declarations.length === 1 && t2.isVariableDeclarator(node.declarations[0]) && t2.isIdentifier(node.declarations[0].id) && node.declarations[0].id.name === "__x" && (valueNode = node.declarations[0].init);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
} else
|
|
810
|
+
valueNode = t2.valueToNode(value);
|
|
811
|
+
return valueNode;
|
|
812
|
+
}
|
|
813
|
+
getBodyDeclarations() {
|
|
814
|
+
return this._ast.program.body;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Edit the first object argument of method calls on a named import, including CommonJS aliases.
|
|
818
|
+
* Unsupported arguments add mutation diagnostics; calls without arguments are ignored.
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```ts
|
|
822
|
+
* const manager = loadConfig(`
|
|
823
|
+
* import { addons } from '@aussieljk/forkbook/manager-api';
|
|
824
|
+
* addons.setConfig({ showNav: false });
|
|
825
|
+
* `).parse();
|
|
826
|
+
* const [object] = manager.callArguments({
|
|
827
|
+
* importedName: 'addons',
|
|
828
|
+
* methodName: 'setConfig',
|
|
829
|
+
* moduleNames: ['@aussieljk/forkbook/manager-api'],
|
|
830
|
+
* });
|
|
831
|
+
* object.group(['layout'], ['showNav']);
|
|
832
|
+
* object.getValue(['layout']); // { showNav: false }
|
|
833
|
+
* manager.changed; // true
|
|
834
|
+
* ```
|
|
835
|
+
*/
|
|
836
|
+
callArguments({
|
|
837
|
+
importedName,
|
|
838
|
+
methodName,
|
|
839
|
+
moduleNames
|
|
840
|
+
}) {
|
|
841
|
+
let modules = new Set(moduleNames), imports = /* @__PURE__ */ new Map();
|
|
842
|
+
traverse2(this._ast, {
|
|
843
|
+
ImportDeclaration(path) {
|
|
844
|
+
if (!(!modules.has(path.node.source.value) || path.node.importKind === "type")) {
|
|
845
|
+
for (let specifier of path.node.specifiers)
|
|
846
|
+
if (t2.isImportSpecifier(specifier) && specifier.importKind !== "type" && t2.isIdentifier(specifier.imported, { name: importedName })) {
|
|
847
|
+
let bindingNodes = imports.get(specifier.local.name) ?? /* @__PURE__ */ new Set();
|
|
848
|
+
bindingNodes.add(specifier), imports.set(specifier.local.name, bindingNodes);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
VariableDeclarator(path) {
|
|
853
|
+
let { id, init } = path.node;
|
|
854
|
+
if (!(!t2.isObjectPattern(id) || !t2.isCallExpression(init) || !t2.isIdentifier(init.callee, { name: "require" }) || path.scope.getBinding("require") !== void 0 || init.arguments.length !== 1 || !t2.isStringLiteral(init.arguments[0]) || !modules.has(init.arguments[0].value))) {
|
|
855
|
+
for (let property of id.properties)
|
|
856
|
+
if (t2.isObjectProperty(property) && !property.computed && (t2.isIdentifier(property.key) && property.key.name === importedName || t2.isStringLiteral(property.key) && property.key.value === importedName) && t2.isIdentifier(property.value)) {
|
|
857
|
+
let bindingNodes = imports.get(property.value.name) ?? /* @__PURE__ */ new Set();
|
|
858
|
+
bindingNodes.add(path.node), imports.set(property.value.name, bindingNodes);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
let objects = [], report = (diagnostic) => this._mutationDiagnostics.push(diagnostic), markChanged = () => {
|
|
864
|
+
this._changed = !0;
|
|
865
|
+
};
|
|
866
|
+
return traverse2(this._ast, {
|
|
867
|
+
CallExpression(path) {
|
|
868
|
+
let { callee } = path.node;
|
|
869
|
+
if (!t2.isMemberExpression(callee) || !t2.isIdentifier(callee.object) || !(t2.isIdentifier(callee.property) && !callee.computed && callee.property.name === methodName || t2.isStringLiteral(callee.property) && callee.property.value === methodName))
|
|
870
|
+
return;
|
|
871
|
+
let bindingNode = path.scope.getBinding(callee.object.name)?.path.node;
|
|
872
|
+
if (bindingNode && imports.get(callee.object.name)?.has(bindingNode)) {
|
|
873
|
+
let argument = path.node.arguments[0];
|
|
874
|
+
if (!argument)
|
|
875
|
+
return;
|
|
876
|
+
let value = unwrapExpression(argument), target = { kind: "call-argument", importedName, methodName }, binding = path.scope.getBinding(callee.object.name);
|
|
877
|
+
if (!binding?.constant || !t2.isObjectExpression(value)) {
|
|
878
|
+
report({
|
|
879
|
+
code: binding?.constant ? "unsupported-initializer" : "ambiguous-binding",
|
|
880
|
+
target,
|
|
881
|
+
path: [],
|
|
882
|
+
message: binding?.constant ? "the call argument is not an object literal" : "the imported binding is reassigned",
|
|
883
|
+
...argument.loc ? { loc: argument.loc } : {}
|
|
884
|
+
});
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
objects.push(
|
|
888
|
+
createCsfObject(
|
|
889
|
+
target,
|
|
890
|
+
{
|
|
891
|
+
node: value,
|
|
892
|
+
scope: path.scope,
|
|
893
|
+
buildCodeFrameError: path.buildCodeFrameError.bind(path)
|
|
894
|
+
},
|
|
895
|
+
[],
|
|
896
|
+
report,
|
|
897
|
+
markChanged
|
|
898
|
+
)
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}), objects;
|
|
903
|
+
}
|
|
904
|
+
setBodyDeclaration(declaration) {
|
|
905
|
+
this._ast.program.body.push(declaration);
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Import specifiers for a specific require import
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
*
|
|
912
|
+
* ```ts
|
|
913
|
+
* // const { foo } = require('bar');
|
|
914
|
+
* setRequireImport(['foo'], 'bar');
|
|
915
|
+
*
|
|
916
|
+
* // const foo = require('bar');
|
|
917
|
+
* setRequireImport('foo', 'bar');
|
|
918
|
+
* ```
|
|
919
|
+
*
|
|
920
|
+
* @param importSpecifiers - The import specifiers to set. If a string is passed in, a default
|
|
921
|
+
* import will be set. Otherwise, an array of named imports will be set
|
|
922
|
+
* @param fromImport - The module to import from
|
|
923
|
+
*/
|
|
924
|
+
setRequireImport(importSpecifier, fromImport) {
|
|
925
|
+
let requireDeclaration = this._ast.program.body.find((node) => {
|
|
926
|
+
let hasDeclaration = t2.isVariableDeclaration(node) && node.declarations.length === 1 && t2.isVariableDeclarator(node.declarations[0]) && t2.isCallExpression(node.declarations[0].init) && t2.isIdentifier(node.declarations[0].init.callee) && node.declarations[0].init.callee.name === "require" && t2.isStringLiteral(node.declarations[0].init.arguments[0]) && (node.declarations[0].init.arguments[0].value === fromImport || node.declarations[0].init.arguments[0].value === fromImport.split("node:")[1]);
|
|
927
|
+
return hasDeclaration && (fromImport = node.declarations[0].init.arguments[0].value), hasDeclaration;
|
|
928
|
+
}), hasRequireSpecifier = (name) => t2.isObjectPattern(requireDeclaration?.declarations[0].id) && requireDeclaration?.declarations[0].id.properties.find(
|
|
929
|
+
(specifier) => t2.isObjectProperty(specifier) && t2.isIdentifier(specifier.key) && specifier.key.name === name
|
|
930
|
+
), hasDefaultRequireSpecifier = (declaration, name) => declaration.declarations.length === 1 && t2.isVariableDeclarator(declaration.declarations[0]) && t2.isIdentifier(declaration.declarations[0].id) && declaration.declarations[0].id.name === name;
|
|
931
|
+
if (typeof importSpecifier == "string") {
|
|
932
|
+
let addDefaultRequireSpecifier = () => {
|
|
933
|
+
prependStatement(
|
|
934
|
+
this._ast.program,
|
|
935
|
+
t2.variableDeclaration("const", [
|
|
936
|
+
t2.variableDeclarator(
|
|
937
|
+
t2.identifier(importSpecifier),
|
|
938
|
+
t2.callExpression(t2.identifier("require"), [t2.stringLiteral(fromImport)])
|
|
939
|
+
)
|
|
940
|
+
])
|
|
941
|
+
);
|
|
942
|
+
};
|
|
943
|
+
requireDeclaration && hasDefaultRequireSpecifier(requireDeclaration, importSpecifier) || addDefaultRequireSpecifier();
|
|
944
|
+
} else requireDeclaration ? importSpecifier.forEach((specifier) => {
|
|
945
|
+
hasRequireSpecifier(specifier) || requireDeclaration.declarations[0].id.properties.push(
|
|
946
|
+
t2.objectProperty(t2.identifier(specifier), t2.identifier(specifier), void 0, !0)
|
|
947
|
+
);
|
|
948
|
+
}) : prependStatement(
|
|
949
|
+
this._ast.program,
|
|
950
|
+
t2.variableDeclaration("const", [
|
|
951
|
+
t2.variableDeclarator(
|
|
952
|
+
t2.objectPattern(
|
|
953
|
+
importSpecifier.map(
|
|
954
|
+
(specifier) => t2.objectProperty(t2.identifier(specifier), t2.identifier(specifier), void 0, !0)
|
|
955
|
+
)
|
|
956
|
+
),
|
|
957
|
+
t2.callExpression(t2.identifier("require"), [t2.stringLiteral(fromImport)])
|
|
958
|
+
)
|
|
959
|
+
])
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Set import specifiers for a given import statement.
|
|
964
|
+
*
|
|
965
|
+
* Does not support setting type imports (yet)
|
|
966
|
+
*
|
|
967
|
+
* @example
|
|
968
|
+
*
|
|
969
|
+
* ```ts
|
|
970
|
+
* // import { foo } from 'bar';
|
|
971
|
+
* setImport(['foo'], 'bar');
|
|
972
|
+
*
|
|
973
|
+
* // import foo from 'bar';
|
|
974
|
+
* setImport('foo', 'bar');
|
|
975
|
+
*
|
|
976
|
+
* // import * as foo from 'bar';
|
|
977
|
+
* setImport({ namespace: 'foo' }, 'bar');
|
|
978
|
+
*
|
|
979
|
+
* // import 'bar';
|
|
980
|
+
* setImport(null, 'bar');
|
|
981
|
+
* ```
|
|
982
|
+
*
|
|
983
|
+
* @param importSpecifiers - The import specifiers to set. If a string is passed in, a default
|
|
984
|
+
* import will be set. Otherwise, an array of named imports will be set
|
|
985
|
+
* @param fromImport - The module to import from
|
|
986
|
+
*/
|
|
987
|
+
setImport(importSpecifier, fromImport) {
|
|
988
|
+
let importDeclaration = this._ast.program.body.find((node) => {
|
|
989
|
+
let hasDeclaration = t2.isImportDeclaration(node) && (node.source.value === fromImport || node.source.value === fromImport.split("node:")[1]);
|
|
990
|
+
return hasDeclaration && (fromImport = node.source.value), hasDeclaration;
|
|
991
|
+
}), getNewImportSpecifier = (specifier) => t2.importSpecifier(t2.identifier(specifier), t2.identifier(specifier)), hasImportSpecifier = (declaration, name) => declaration.specifiers.find(
|
|
992
|
+
(specifier) => t2.isImportSpecifier(specifier) && t2.isIdentifier(specifier.imported) && specifier.imported.name === name
|
|
993
|
+
), hasNamespaceImportSpecifier = (declaration, name) => declaration.specifiers.find(
|
|
994
|
+
(specifier) => t2.isImportNamespaceSpecifier(specifier) && t2.isIdentifier(specifier.local) && specifier.local.name === name
|
|
995
|
+
);
|
|
996
|
+
importSpecifier === null ? importDeclaration || prependStatement(this._ast.program, t2.importDeclaration([], t2.stringLiteral(fromImport))) : typeof importSpecifier == "string" ? importDeclaration ? ((declaration, name) => declaration.specifiers.find(
|
|
997
|
+
(specifier) => t2.isImportDefaultSpecifier(specifier) && t2.isIdentifier(specifier.local) && specifier.local.name === name
|
|
998
|
+
))(importDeclaration, importSpecifier) || importDeclaration.specifiers.push(
|
|
999
|
+
t2.importDefaultSpecifier(t2.identifier(importSpecifier))
|
|
1000
|
+
) : prependStatement(
|
|
1001
|
+
this._ast.program,
|
|
1002
|
+
t2.importDeclaration(
|
|
1003
|
+
[t2.importDefaultSpecifier(t2.identifier(importSpecifier))],
|
|
1004
|
+
t2.stringLiteral(fromImport)
|
|
1005
|
+
)
|
|
1006
|
+
) : Array.isArray(importSpecifier) ? importDeclaration ? importSpecifier.forEach((specifier) => {
|
|
1007
|
+
hasImportSpecifier(importDeclaration, specifier) || importDeclaration.specifiers.push(getNewImportSpecifier(specifier));
|
|
1008
|
+
}) : prependStatement(
|
|
1009
|
+
this._ast.program,
|
|
1010
|
+
t2.importDeclaration(
|
|
1011
|
+
importSpecifier.map(getNewImportSpecifier),
|
|
1012
|
+
t2.stringLiteral(fromImport)
|
|
1013
|
+
)
|
|
1014
|
+
) : importSpecifier.namespace && (importDeclaration ? hasNamespaceImportSpecifier(importDeclaration, importSpecifier.namespace) || importDeclaration.specifiers.push(
|
|
1015
|
+
t2.importNamespaceSpecifier(t2.identifier(importSpecifier.namespace))
|
|
1016
|
+
) : prependStatement(
|
|
1017
|
+
this._ast.program,
|
|
1018
|
+
t2.importDeclaration(
|
|
1019
|
+
[t2.importNamespaceSpecifier(t2.identifier(importSpecifier.namespace))],
|
|
1020
|
+
t2.stringLiteral(fromImport)
|
|
1021
|
+
)
|
|
1022
|
+
));
|
|
1023
|
+
}
|
|
1024
|
+
_removeRequireImport(importSpecifier, fromImport) {
|
|
1025
|
+
let requireDeclarationIndex = this._ast.program.body.findIndex((node) => t2.isVariableDeclaration(node) && node.declarations.length === 1 && t2.isVariableDeclarator(node.declarations[0]) && t2.isCallExpression(node.declarations[0].init) && t2.isIdentifier(node.declarations[0].init.callee) && node.declarations[0].init.callee.name === "require" && t2.isStringLiteral(node.declarations[0].init.arguments[0]) && (node.declarations[0].init.arguments[0].value === fromImport || node.declarations[0].init.arguments[0].value === fromImport.split("node:")[1]));
|
|
1026
|
+
if (requireDeclarationIndex === -1)
|
|
1027
|
+
return;
|
|
1028
|
+
let declarator = this._ast.program.body[requireDeclarationIndex].declarations[0];
|
|
1029
|
+
if (importSpecifier !== null) {
|
|
1030
|
+
if (typeof importSpecifier == "string") {
|
|
1031
|
+
t2.isIdentifier(declarator.id) && declarator.id.name === importSpecifier && this._ast.program.body.splice(requireDeclarationIndex, 1);
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
if (!(typeof importSpecifier == "object" && "namespace" in importSpecifier) && Array.isArray(importSpecifier) && t2.isObjectPattern(declarator.id)) {
|
|
1035
|
+
let objectPattern = declarator.id;
|
|
1036
|
+
importSpecifier.forEach((specifier) => {
|
|
1037
|
+
let index = objectPattern.properties.findIndex(
|
|
1038
|
+
(prop) => t2.isObjectProperty(prop) && t2.isIdentifier(prop.key) && prop.key.name === specifier
|
|
1039
|
+
);
|
|
1040
|
+
index !== -1 && objectPattern.properties.splice(index, 1);
|
|
1041
|
+
}), objectPattern.properties.length === 0 && this._ast.program.body.splice(requireDeclarationIndex, 1);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
_removeImport(importSpecifier, fromImport) {
|
|
1046
|
+
let importDeclarationIndex = this._ast.program.body.findIndex(
|
|
1047
|
+
(node) => t2.isImportDeclaration(node) && (node.source.value === fromImport || node.source.value === fromImport.split("node:")[1])
|
|
1048
|
+
);
|
|
1049
|
+
if (importDeclarationIndex === -1)
|
|
1050
|
+
return;
|
|
1051
|
+
let importDeclaration = this._ast.program.body[importDeclarationIndex];
|
|
1052
|
+
if (importSpecifier === null) {
|
|
1053
|
+
importDeclaration.specifiers.length === 0 && this._ast.program.body.splice(importDeclarationIndex, 1);
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
if (typeof importSpecifier == "object" && "namespace" in importSpecifier) {
|
|
1057
|
+
let index = importDeclaration.specifiers.findIndex(
|
|
1058
|
+
(specifier) => t2.isImportNamespaceSpecifier(specifier) && t2.isIdentifier(specifier.local) && specifier.local.name === importSpecifier.namespace
|
|
1059
|
+
);
|
|
1060
|
+
index !== -1 && importDeclaration.specifiers.splice(index, 1);
|
|
1061
|
+
}
|
|
1062
|
+
if (typeof importSpecifier == "string") {
|
|
1063
|
+
let index = importDeclaration.specifiers.findIndex(
|
|
1064
|
+
(specifier) => t2.isImportDefaultSpecifier(specifier) && t2.isIdentifier(specifier.local) && specifier.local.name === importSpecifier
|
|
1065
|
+
);
|
|
1066
|
+
index !== -1 && importDeclaration.specifiers.splice(index, 1);
|
|
1067
|
+
}
|
|
1068
|
+
Array.isArray(importSpecifier) && importSpecifier.forEach((specifier) => {
|
|
1069
|
+
let index = importDeclaration.specifiers.findIndex(
|
|
1070
|
+
(current) => t2.isImportSpecifier(current) && t2.isIdentifier(current.imported) && current.imported.name === specifier
|
|
1071
|
+
);
|
|
1072
|
+
index !== -1 && importDeclaration.specifiers.splice(index, 1);
|
|
1073
|
+
}), importDeclaration.specifiers.length === 0 && this._ast.program.body.splice(importDeclarationIndex, 1);
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Remove import specifiers for a given import statement.
|
|
1077
|
+
*
|
|
1078
|
+
* Does not support removing type imports (yet)
|
|
1079
|
+
*
|
|
1080
|
+
* @example
|
|
1081
|
+
*
|
|
1082
|
+
* ```ts
|
|
1083
|
+
* // import { foo } from 'bar';
|
|
1084
|
+
* setImport(['foo'], 'bar');
|
|
1085
|
+
*
|
|
1086
|
+
* // import foo from 'bar';
|
|
1087
|
+
* setImport('foo', 'bar');
|
|
1088
|
+
*
|
|
1089
|
+
* // import * as foo from 'bar';
|
|
1090
|
+
* setImport({ namespace: 'foo' }, 'bar');
|
|
1091
|
+
*
|
|
1092
|
+
* // import 'bar';
|
|
1093
|
+
* setImport(null, 'bar');
|
|
1094
|
+
* ```
|
|
1095
|
+
*
|
|
1096
|
+
* @param importSpecifiers - The import specifiers to remove. If a string is passed in, will only
|
|
1097
|
+
* remove the default import. Otherwise, named imports matching the array will be removed.
|
|
1098
|
+
* @param fromImport - The module to import from
|
|
1099
|
+
*/
|
|
1100
|
+
removeImport(importSpecifier, fromImport) {
|
|
1101
|
+
this._removeRequireImport(importSpecifier, fromImport), this._removeImport(importSpecifier, fromImport);
|
|
1102
|
+
}
|
|
1103
|
+
}, loadConfig = (code, fileName) => {
|
|
1104
|
+
let ast = babelParse(code);
|
|
1105
|
+
return new ConfigFile(ast, code, fileName);
|
|
1106
|
+
}, formatConfig = (config) => printConfig(config).code, printConfig = (config, options = {}) => recast.print(config._ast, {
|
|
1107
|
+
quote: config._inferQuotes(),
|
|
1108
|
+
// Recast defaults this to `os.EOL`, which would carriage-return printed files on Windows.
|
|
1109
|
+
lineTerminator: `
|
|
1110
|
+
`,
|
|
1111
|
+
...options
|
|
1112
|
+
}), readConfig = async (fileName) => {
|
|
1113
|
+
let code = (await readFile(fileName, "utf-8")).toString();
|
|
1114
|
+
return loadConfig(code, fileName).parse();
|
|
1115
|
+
}, writeConfig = async (config, fileName) => {
|
|
1116
|
+
let [diagnostic] = config.mutationDiagnostics;
|
|
1117
|
+
invariant(!diagnostic, diagnostic?.message);
|
|
1118
|
+
let fname = fileName || config.fileName;
|
|
1119
|
+
if (!fname)
|
|
1120
|
+
throw new Error("Please specify a fileName for writeConfig");
|
|
1121
|
+
await writeFile(fname, formatConfig(config));
|
|
1122
|
+
}, isCsfFactoryPreview = (previewConfig) => !!previewConfig._ast.program.body.find((node) => t2.isImportDeclaration(node) && (node.source.value.includes("storybook") || node.source.value.includes("forkbook")) && node.specifiers.some((specifier) => t2.isImportSpecifier(specifier) && t2.isIdentifier(specifier.imported) && specifier.imported.name === "definePreview"));
|
|
1123
|
+
|
|
1124
|
+
export {
|
|
1125
|
+
getHeaderComments,
|
|
1126
|
+
ConfigFile,
|
|
1127
|
+
loadConfig,
|
|
1128
|
+
formatConfig,
|
|
1129
|
+
printConfig,
|
|
1130
|
+
readConfig,
|
|
1131
|
+
writeConfig,
|
|
1132
|
+
isCsfFactoryPreview
|
|
1133
|
+
};
|