@astryxdesign/cli 0.7.16 → 0.7.17-canary.g335a172
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/README.md +76 -86
- package/api/build/_adapter.d.mts +12 -0
- package/api/build/_adapter.mjs +51 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +4 -3
- package/api/build/build.type.d.mts +2 -2
- package/api/build/build.type.mjs +3 -3
- package/api/build/kit/kind.d.mts +2 -1
- package/api/build/kit/kind.mjs +199 -10
- package/api/build/kit/kit.mjs +6 -4
- package/api/build/kit/rank.mjs +69 -16
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +12 -8
- package/api/build/kit/weights.d.mts +16 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +251 -35
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +48 -0
- package/api/build/kit/words.mjs +90 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +1 -1
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +26 -2
- package/api/docs/_adapter.mjs +219 -6
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +83 -10
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/icon/_records.mjs +2 -1
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/integration/_adapter.d.mts +44 -0
- package/api/integration/_adapter.mjs +77 -1
- package/api/integration/authoring-checks.mjs +6 -6
- package/api/integration/example-scope.d.mts +14 -0
- package/api/integration/example-scope.mjs +44 -0
- package/api/integration/example-scope.type.d.mts +29 -0
- package/api/integration/example-scope.type.mjs +25 -0
- package/api/integration/integrationExampleScope.doc.d.mts +11 -0
- package/api/integration/integrationExampleScope.doc.mjs +59 -0
- package/api/integration/validate-integration.mjs +19 -1
- package/api/integration/validate-integration.type.d.mts +9 -0
- package/api/integration/validate-integration.type.mjs +1 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/render/_adapter.mjs +591 -195
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +52 -0
- package/api/render/render.type.mjs +31 -1
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_gather-components.d.mts +3 -2
- package/api/search/_gather-components.mjs +12 -3
- package/api/search/_lexical.d.mts +5 -0
- package/api/search/_lexical.mjs +8 -2
- package/api/search/_result.d.mts +11 -9
- package/api/search/_result.mjs +4 -4
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search-index.mjs +7 -1
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +12 -1
- package/api/theme/build/build.d.mts +60 -0
- package/api/theme/build/build.mjs +210 -54
- package/api/theme/build/font-warning.d.mts +8 -0
- package/api/theme/build/font-warning.mjs +19 -0
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +55 -0
- package/api/theme-edit/_adapter.mjs +673 -42
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1858 -312
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +49 -1
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.mjs +60 -3
- package/api/theme-edit/_css.mjs +21 -1
- package/api/theme-edit/_edit.d.mts +22 -0
- package/api/theme-edit/_edit.mjs +1533 -92
- package/api/theme-edit/_how-commands.d.mts +57 -0
- package/api/theme-edit/_how-commands.mjs +587 -1
- package/api/theme-edit/_how-question.d.mts +78 -0
- package/api/theme-edit/_how-question.mjs +4716 -235
- package/api/theme-edit/_how.mjs +134 -8
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_normal.d.mts +219 -0
- package/api/theme-edit/_normal.mjs +1041 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +8 -0
- package/api/theme-edit/_parts.mjs +103 -2
- package/api/theme-edit/_playwright-picture.d.mts +4 -0
- package/api/theme-edit/_playwright-picture.mjs +34 -0
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +394 -74
- package/api/theme-edit/_preview.d.mts +69 -8
- package/api/theme-edit/_preview.mjs +531 -108
- package/api/theme-edit/_settings.d.mts +243 -6
- package/api/theme-edit/_settings.mjs +2415 -147
- package/api/theme-edit/_tables.d.mts +6 -0
- package/api/theme-edit/_tables.mjs +44 -1
- package/api/theme-edit/_vet.d.mts +18 -0
- package/api/theme-edit/_vet.mjs +32 -0
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
- package/api/upgrade/run/run.mjs +4 -3
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/run-codemod.mjs +87 -7
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/component-list.generated.json +1 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +44 -3
- package/assets/docs/tree/single-component.doc.mjs +4 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +6 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/component/categories.d.mts +37 -0
- package/authoring/doctypes/component/categories.mjs +54 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/authoring/example/example.doc.d.mts +12 -0
- package/authoring/example/example.doc.mjs +69 -0
- package/authoring/example/preview.d.mts +92 -0
- package/authoring/example/preview.mjs +994 -0
- package/authoring/example/type.ts +102 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +3 -1
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +22 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +32 -14
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +145 -16
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +183 -6
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/cli-error.mjs +2 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/lib/json-shim.mjs +77 -21
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +56 -8
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/copied-passages.mjs +2 -1
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +22 -8
- package/foundation/discovery/icon-definition-discovery.mjs +2 -1
- package/foundation/discovery/icon-set-checks.mjs +2 -1
- package/foundation/discovery/icon-set-discovery.mjs +2 -1
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/prop-drift.mjs +9 -9
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/stored-component-list.d.mts +43 -0
- package/foundation/discovery/stored-component-list.mjs +90 -0
- package/foundation/discovery/stored-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +38 -18
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +3 -2
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/discovery/theming-targets.mjs +3 -2
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +31 -0
- package/foundation/fonts/font-stylesheet.mjs +115 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/file-protection.mjs +4 -3
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +164 -55
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/listing-cache.d.mts +7 -0
- package/foundation/fs/listing-cache.mjs +10 -0
- package/foundation/fs/module-loader.d.mts +24 -2
- package/foundation/fs/module-loader.mjs +94 -21
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/integrations/contribution-inventory.mjs +4 -3
- package/foundation/integrations/example-code.d.mts +63 -0
- package/foundation/integrations/example-code.mjs +416 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/validate-contributions.mjs +17 -45
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +39 -7
- package/foundation/render/embedded-imports.mjs +66 -27
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +121 -13
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +35 -3
- package/foundation/render/render-page.mjs +316 -42
- package/foundation/render/source-block.d.mts +85 -6
- package/foundation/render/source-block.mjs +211 -20
- package/foundation/render/ts-paths.d.mts +69 -6
- package/foundation/render/ts-paths.mjs +326 -40
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +2 -2
- package/foundation/text/compare-text.d.mts +14 -0
- package/foundation/text/compare-text.mjs +68 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +18 -4
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +15 -1
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The scope a package's component examples are read against, and
|
|
5
|
+
* Doctor's check that each example runs on its own unless it is
|
|
6
|
+
* `kind: 'setup'`, judged by the rule a live preview uses.
|
|
7
|
+
* @input A loaded integration: its components root, package directory and
|
|
8
|
+
* package.json, and the Core and React installed beside it.
|
|
9
|
+
* @output `exampleScopeFor`: the ExampleScope as JSON, which
|
|
10
|
+
* `integrationExampleScope` returns. `exampleCodeCheck`: a note for each
|
|
11
|
+
* example `previewableExample` refuses, with its fix, and the examples it
|
|
12
|
+
* could not judge.
|
|
13
|
+
* @position foundation/integrations, beside the other contribution
|
|
14
|
+
* validators; run by `astryx doctor integration validate` (and so by
|
|
15
|
+
* `integration check`) through api/integration/validate-integration.mjs,
|
|
16
|
+
* which marks the notes `next`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import * as fs from 'node:fs';
|
|
20
|
+
import * as path from 'node:path';
|
|
21
|
+
import {createRequire} from 'node:module';
|
|
22
|
+
import {
|
|
23
|
+
packagesInstalledWith,
|
|
24
|
+
previewableExample,
|
|
25
|
+
} from '../../authoring/example/preview.mjs';
|
|
26
|
+
import {findProjectCoreDir} from '../fs/paths.mjs';
|
|
27
|
+
import {
|
|
28
|
+
CORE_PACKAGE,
|
|
29
|
+
discoverComponents,
|
|
30
|
+
discoverIntegrationComponents,
|
|
31
|
+
resolveIntegrationImportPath,
|
|
32
|
+
} from '../discovery/component-discovery.mjs';
|
|
33
|
+
import {discoverHooks} from '../discovery/hook-discovery.mjs';
|
|
34
|
+
import {loadComponentDoc} from '../discovery/component-loader.mjs';
|
|
35
|
+
import {babelParse} from '../runtime/lazy-dependencies.mjs';
|
|
36
|
+
import {declaredTargets, readImports, subpathFor} from './public-imports.mjs';
|
|
37
|
+
import {allTargets, isRecord, subpathDeclaration} from './exports-subpaths.mjs';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {{code: string, message: string}} ExampleCodeNote
|
|
41
|
+
* @typedef {{file: string, example: string, reason: string}} ExampleCodeUnchecked
|
|
42
|
+
* @typedef {import('../../authoring/example/type.ts').ExampleScope} ExampleScope
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/** @param {string} from @param {string} to */
|
|
46
|
+
function rel(from, to) {
|
|
47
|
+
return path.relative(from, to).split(path.sep).join('/');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {string} packageDir
|
|
52
|
+
* @returns {Record<string, unknown> | null}
|
|
53
|
+
*/
|
|
54
|
+
function readManifest(packageDir) {
|
|
55
|
+
try {
|
|
56
|
+
const parsed = JSON.parse(
|
|
57
|
+
fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8'),
|
|
58
|
+
);
|
|
59
|
+
return isRecord(parsed) ? parsed : null;
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* React's named exports, as the package resolves React.
|
|
67
|
+
* @param {string} packageDir
|
|
68
|
+
* @returns {string[] | null} null when React cannot be loaded
|
|
69
|
+
*/
|
|
70
|
+
function reactExports(packageDir) {
|
|
71
|
+
try {
|
|
72
|
+
const require = createRequire(path.join(packageDir, 'package.json'));
|
|
73
|
+
return Object.keys(require('react'));
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Each component and hook Core documents, from the Core installed beside the
|
|
81
|
+
* package.
|
|
82
|
+
* @param {string} packageDir
|
|
83
|
+
* @returns {Array<{name: string, import: string}> | null} null when no Core
|
|
84
|
+
* is installed, or its docs cannot be read
|
|
85
|
+
*/
|
|
86
|
+
function coreNames(packageDir) {
|
|
87
|
+
const coreDir = findProjectCoreDir(packageDir);
|
|
88
|
+
if (!coreDir) return null;
|
|
89
|
+
try {
|
|
90
|
+
const names = [
|
|
91
|
+
...Object.values(discoverComponents(coreDir)).flat(),
|
|
92
|
+
...Object.values(discoverHooks(coreDir)).flat(),
|
|
93
|
+
];
|
|
94
|
+
return [...new Set(names)].map(name => ({name, import: CORE_PACKAGE}));
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Whether a module imports `server-only`, the marker of code that runs only
|
|
102
|
+
* on a server. A file that cannot be read imports nothing.
|
|
103
|
+
* @param {string} file
|
|
104
|
+
*/
|
|
105
|
+
function importsServerOnly(file) {
|
|
106
|
+
try {
|
|
107
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
108
|
+
return (
|
|
109
|
+
text.includes('server-only') &&
|
|
110
|
+
readImports(text).some(
|
|
111
|
+
statement => statement.source === 'server-only' && !statement.typeOnly,
|
|
112
|
+
)
|
|
113
|
+
);
|
|
114
|
+
} catch {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** How many files a wildcard `exports` target may be matched against. */
|
|
120
|
+
const WILDCARD_FILE_LIMIT = 5_000;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The files under a folder, `node_modules` aside, up to a limit.
|
|
124
|
+
* @param {string} dir
|
|
125
|
+
* @param {string[]} [out]
|
|
126
|
+
* @returns {string[]}
|
|
127
|
+
*/
|
|
128
|
+
function filesUnder(dir, out = []) {
|
|
129
|
+
/** @type {fs.Dirent[]} */
|
|
130
|
+
let entries;
|
|
131
|
+
try {
|
|
132
|
+
entries = fs.readdirSync(dir, {withFileTypes: true});
|
|
133
|
+
} catch {
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
for (const entry of entries) {
|
|
137
|
+
if (out.length >= WILDCARD_FILE_LIMIT) break;
|
|
138
|
+
if (entry.name === 'node_modules') continue;
|
|
139
|
+
const full = path.join(dir, entry.name);
|
|
140
|
+
if (entry.isDirectory()) filesUnder(full, out);
|
|
141
|
+
else if (entry.isFile()) out.push(full);
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The package's own import specifiers whose module imports `server-only`:
|
|
148
|
+
* each subpath its `exports` declares, and for a wildcard subpath, each file
|
|
149
|
+
* its target pattern can name, by the subpath that exports that file. A
|
|
150
|
+
* package with no `exports` names none, as no subpath of it is declared.
|
|
151
|
+
* @param {string} packageDir
|
|
152
|
+
* @param {string} packageName
|
|
153
|
+
* @param {unknown} exportsField
|
|
154
|
+
* @returns {string[]}
|
|
155
|
+
*/
|
|
156
|
+
function serverOnlyModules(packageDir, packageName, exportsField) {
|
|
157
|
+
if (exportsField == null) return [];
|
|
158
|
+
/** @type {Set<string>} */
|
|
159
|
+
const found = new Set();
|
|
160
|
+
/** @param {string} subpath */
|
|
161
|
+
const targets = subpath =>
|
|
162
|
+
declaredTargets(packageDir, subpathDeclaration(exportsField, subpath))
|
|
163
|
+
.files;
|
|
164
|
+
/** @param {string} subpath `.` or `./…` */
|
|
165
|
+
const add = subpath =>
|
|
166
|
+
found.add(
|
|
167
|
+
subpath === '.' ? packageName : `${packageName}${subpath.slice(1)}`,
|
|
168
|
+
);
|
|
169
|
+
const keys = isRecord(exportsField) ? Object.keys(exportsField) : [];
|
|
170
|
+
if (keys.length === 0 || !keys.every(key => key.startsWith('.'))) {
|
|
171
|
+
if (targets('.').some(importsServerOnly)) add('.');
|
|
172
|
+
return [...found];
|
|
173
|
+
}
|
|
174
|
+
const map = /** @type {Record<string, unknown>} */ (exportsField);
|
|
175
|
+
const root = path.resolve(packageDir);
|
|
176
|
+
for (const key of keys) {
|
|
177
|
+
if (!key.includes('*')) {
|
|
178
|
+
if (targets(key).some(importsServerOnly)) add(key);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
for (const target of allTargets(map[key])) {
|
|
182
|
+
const star = target.indexOf('*');
|
|
183
|
+
if (!target.startsWith('./') || star === -1) continue;
|
|
184
|
+
const folder = path.resolve(
|
|
185
|
+
root,
|
|
186
|
+
target.slice(0, target.lastIndexOf('/', star) + 1),
|
|
187
|
+
);
|
|
188
|
+
if (folder !== root && !folder.startsWith(root + path.sep)) continue;
|
|
189
|
+
for (const file of filesUnder(folder)) {
|
|
190
|
+
if (!importsServerOnly(file)) continue;
|
|
191
|
+
// This key's own subpath for the file: an earlier key that also
|
|
192
|
+
// names it is a second specifier for the same module.
|
|
193
|
+
const subpath = subpathFor({[key]: map[key]}, packageDir, file);
|
|
194
|
+
if (subpath != null && targets(subpath).includes(file)) add(subpath);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return [...found].sort();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The documented components whose source declares them as async functions:
|
|
203
|
+
* server components, which only a server can render. A source that cannot be
|
|
204
|
+
* read or parsed names none.
|
|
205
|
+
* @param {Array<{name: string, sourcePath: string | null}>} records
|
|
206
|
+
* @returns {string[]}
|
|
207
|
+
*/
|
|
208
|
+
function asyncComponents(records) {
|
|
209
|
+
/** @type {Map<string, Set<string>>} source file → its async function names */
|
|
210
|
+
const bySource = new Map();
|
|
211
|
+
/** @type {string[]} */
|
|
212
|
+
const found = [];
|
|
213
|
+
for (const {name, sourcePath} of records) {
|
|
214
|
+
if (!sourcePath) continue;
|
|
215
|
+
let names = bySource.get(sourcePath);
|
|
216
|
+
if (!names) {
|
|
217
|
+
names = asyncFunctionNames(sourcePath);
|
|
218
|
+
bySource.set(sourcePath, names);
|
|
219
|
+
}
|
|
220
|
+
if (names.has(name)) found.push(name);
|
|
221
|
+
}
|
|
222
|
+
return found;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The top-level async functions a module declares, exported or not.
|
|
227
|
+
* @param {string} file
|
|
228
|
+
* @returns {Set<string>}
|
|
229
|
+
*/
|
|
230
|
+
function asyncFunctionNames(file) {
|
|
231
|
+
/** @type {Set<string>} */
|
|
232
|
+
const names = new Set();
|
|
233
|
+
/** @type {any} */
|
|
234
|
+
let ast;
|
|
235
|
+
try {
|
|
236
|
+
ast = babelParse(fs.readFileSync(file, 'utf8'), {
|
|
237
|
+
sourceType: 'module',
|
|
238
|
+
plugins: ['jsx', 'typescript'],
|
|
239
|
+
});
|
|
240
|
+
} catch {
|
|
241
|
+
return names; // an unreadable source names no server component
|
|
242
|
+
}
|
|
243
|
+
for (const statement of ast.program.body) {
|
|
244
|
+
const node =
|
|
245
|
+
statement.type === 'ExportNamedDeclaration' ||
|
|
246
|
+
statement.type === 'ExportDefaultDeclaration'
|
|
247
|
+
? statement.declaration
|
|
248
|
+
: statement;
|
|
249
|
+
if (node?.type === 'FunctionDeclaration' && node.async && node.id) {
|
|
250
|
+
names.add(node.id.name);
|
|
251
|
+
}
|
|
252
|
+
if (node?.type !== 'VariableDeclaration') continue;
|
|
253
|
+
for (const declarator of node.declarations) {
|
|
254
|
+
const init = declarator.init;
|
|
255
|
+
if (
|
|
256
|
+
declarator.id.type === 'Identifier' &&
|
|
257
|
+
(init?.type === 'ArrowFunctionExpression' ||
|
|
258
|
+
init?.type === 'FunctionExpression') &&
|
|
259
|
+
init.async
|
|
260
|
+
) {
|
|
261
|
+
names.add(declarator.id.name);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return names;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @typedef {object} ExampleScopeRead
|
|
270
|
+
* @property {ExampleScope | null} scope null when there is nothing to read
|
|
271
|
+
* examples against: no package.json with a name
|
|
272
|
+
* @property {string} [reason] why `scope` is null
|
|
273
|
+
* @property {string} [incomplete] why names Core or React give could not be
|
|
274
|
+
* read: the scope then lists none of them, so a name it does not list may
|
|
275
|
+
* still be defined
|
|
276
|
+
* @property {Map<string, any>} docs each component doc that loaded, by path
|
|
277
|
+
*/
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* The scope a package's component examples are read against, as JSON: the
|
|
281
|
+
* components the package documents with the import an app uses for each,
|
|
282
|
+
* the components and hooks the Core installed beside it documents, the
|
|
283
|
+
* React it resolves, the packages it declares, and its server-only modules
|
|
284
|
+
* and async components.
|
|
285
|
+
* @param {any} integration a loaded integration
|
|
286
|
+
* @returns {Promise<ExampleScopeRead>}
|
|
287
|
+
*/
|
|
288
|
+
export async function exampleScopeFor(integration) {
|
|
289
|
+
/** @type {Map<string, any>} */
|
|
290
|
+
const docs = new Map();
|
|
291
|
+
const packageDir = integration?.__packageDir;
|
|
292
|
+
const manifest = packageDir ? readManifest(packageDir) : null;
|
|
293
|
+
const packageName = typeof manifest?.name === 'string' ? manifest.name : null;
|
|
294
|
+
if (!packageDir || !manifest || !packageName) {
|
|
295
|
+
return {scope: null, reason: 'package.json has no name', docs};
|
|
296
|
+
}
|
|
297
|
+
/** @type {ReturnType<typeof discoverIntegrationComponents>} */
|
|
298
|
+
let records = [];
|
|
299
|
+
try {
|
|
300
|
+
records = discoverIntegrationComponents(integration);
|
|
301
|
+
} catch {
|
|
302
|
+
// An unreadable root is reported by the root validators.
|
|
303
|
+
}
|
|
304
|
+
for (const record of records) {
|
|
305
|
+
if (docs.has(record.docPath)) continue;
|
|
306
|
+
try {
|
|
307
|
+
const doc = await loadComponentDoc(record.docPath);
|
|
308
|
+
if (isRecord(doc)) docs.set(record.docPath, doc);
|
|
309
|
+
} catch {
|
|
310
|
+
// A doc that does not load is reported by the doc validators.
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const exportsField = manifest.exports ?? null;
|
|
314
|
+
const react = reactExports(packageDir);
|
|
315
|
+
const core = coreNames(packageDir);
|
|
316
|
+
/** @type {ExampleScope} */
|
|
317
|
+
const scope = {
|
|
318
|
+
packageName,
|
|
319
|
+
packageNames: records.map(record => ({
|
|
320
|
+
name: record.name,
|
|
321
|
+
import: resolveIntegrationImportPath(
|
|
322
|
+
{
|
|
323
|
+
exportsMap: /** @type {any} */ (exportsField),
|
|
324
|
+
packageDir,
|
|
325
|
+
docPath: record.docPath,
|
|
326
|
+
packageName,
|
|
327
|
+
},
|
|
328
|
+
record.name,
|
|
329
|
+
typeof docs.get(record.docPath)?.import === 'string'
|
|
330
|
+
? docs.get(record.docPath).import
|
|
331
|
+
: null,
|
|
332
|
+
),
|
|
333
|
+
})),
|
|
334
|
+
coreNames: core ?? [],
|
|
335
|
+
reactNames: react ?? [],
|
|
336
|
+
dependencies: packagesInstalledWith(manifest),
|
|
337
|
+
serverOnlyModules: serverOnlyModules(packageDir, packageName, exportsField),
|
|
338
|
+
serverComponents: asyncComponents(records),
|
|
339
|
+
};
|
|
340
|
+
// Without Core or React, a name either provides cannot be told from an
|
|
341
|
+
// undefined one.
|
|
342
|
+
const incomplete =
|
|
343
|
+
core == null
|
|
344
|
+
? "Core's docs cannot be read beside the package"
|
|
345
|
+
: react == null
|
|
346
|
+
? 'React cannot be loaded from the package'
|
|
347
|
+
: null;
|
|
348
|
+
return {scope, ...(incomplete ? {incomplete} : {}), docs};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Check every example of every component doc the package ships.
|
|
353
|
+
* @param {any} integration a loaded integration
|
|
354
|
+
* @returns {Promise<{notes: ExampleCodeNote[], unchecked: ExampleCodeUnchecked[]}>}
|
|
355
|
+
*/
|
|
356
|
+
export async function exampleCodeCheck(integration) {
|
|
357
|
+
/** @type {ExampleCodeNote[]} */
|
|
358
|
+
const notes = [];
|
|
359
|
+
/** @type {ExampleCodeUnchecked[]} */
|
|
360
|
+
const unchecked = [];
|
|
361
|
+
const {scope, incomplete: missing, docs} = await exampleScopeFor(integration);
|
|
362
|
+
if (!scope) return {notes, unchecked};
|
|
363
|
+
const packageDir = integration.__packageDir;
|
|
364
|
+
for (const [docPath, doc] of docs) {
|
|
365
|
+
const shownDoc = rel(packageDir, docPath);
|
|
366
|
+
const entries = [
|
|
367
|
+
doc,
|
|
368
|
+
...(Array.isArray(doc.components) ? doc.components : []),
|
|
369
|
+
].filter(isRecord);
|
|
370
|
+
for (const entry of entries) {
|
|
371
|
+
const examples = Array.isArray(entry.examples) ? entry.examples : [];
|
|
372
|
+
for (const [index, example] of examples.entries()) {
|
|
373
|
+
if (!isRecord(example) || typeof example.code !== 'string') continue;
|
|
374
|
+
const label =
|
|
375
|
+
typeof example.label === 'string'
|
|
376
|
+
? `"${example.label}"`
|
|
377
|
+
: `#${index + 1}`;
|
|
378
|
+
const shown =
|
|
379
|
+
entry === doc || typeof entry.name !== 'string'
|
|
380
|
+
? `example ${label}`
|
|
381
|
+
: `${entry.name} example ${label}`;
|
|
382
|
+
/** @type {import('../../authoring/example/type.ts').PreviewableExample} */
|
|
383
|
+
let read;
|
|
384
|
+
try {
|
|
385
|
+
read = previewableExample(
|
|
386
|
+
{code: example.code, kind: example.kind},
|
|
387
|
+
scope,
|
|
388
|
+
);
|
|
389
|
+
} catch (error) {
|
|
390
|
+
unchecked.push({
|
|
391
|
+
file: shownDoc,
|
|
392
|
+
example: label,
|
|
393
|
+
reason: `it could not be read: ${error instanceof Error ? error.message : String(error)}`,
|
|
394
|
+
});
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (read.previewable || read.setup) continue;
|
|
398
|
+
for (const problem of read.problems) {
|
|
399
|
+
if (problem.code === 'example_undefined_name' && missing) {
|
|
400
|
+
unchecked.push({
|
|
401
|
+
file: shownDoc,
|
|
402
|
+
example: label,
|
|
403
|
+
reason: `${missing}, so its names ${(problem.names ?? []).join(', ')} cannot be judged`,
|
|
404
|
+
});
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
notes.push({
|
|
408
|
+
code: problem.code,
|
|
409
|
+
message: `Component doc "${shownDoc}" ${shown} ${problem.message}. Fix: ${problem.fix}`,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return {notes, unchecked};
|
|
416
|
+
}
|
|
@@ -18,6 +18,15 @@ export function splitSpecifier(specifier: string): {
|
|
|
18
18
|
* @returns {ImportStatement[]}
|
|
19
19
|
*/
|
|
20
20
|
export function readImports(text: string): ImportStatement[];
|
|
21
|
+
/**
|
|
22
|
+
* A declared subpath of the package whose target is `file`, if any: an exact
|
|
23
|
+
* key, or a wildcard key whose target pattern matches the file.
|
|
24
|
+
* @param {unknown} exportsField
|
|
25
|
+
* @param {string} packageDir
|
|
26
|
+
* @param {string} file
|
|
27
|
+
* @returns {string | null}
|
|
28
|
+
*/
|
|
29
|
+
export function subpathFor(exportsField: unknown, packageDir: string, file: string): string | null;
|
|
21
30
|
/**
|
|
22
31
|
* Every name (runtime or type) a module exports, and whether the list is
|
|
23
32
|
* complete: an `export *` from another package, `export =`, or a module that
|
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
isRecord,
|
|
46
46
|
subpathDeclaration,
|
|
47
47
|
} from './exports-subpaths.mjs';
|
|
48
|
+
import {compareText} from '../text/compare-text.mjs';
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
51
|
* @typedef {import('./issue').AstryxIntegrationIssue} Issue
|
|
@@ -283,7 +284,7 @@ function declarationIn(exportsField, packageDir, subpath) {
|
|
|
283
284
|
* @param {string} file
|
|
284
285
|
* @returns {string | null}
|
|
285
286
|
*/
|
|
286
|
-
function subpathFor(exportsField, packageDir, file) {
|
|
287
|
+
export function subpathFor(exportsField, packageDir, file) {
|
|
287
288
|
if (!isRecord(exportsField)) return null;
|
|
288
289
|
const wanted = `./${rel(packageDir, file)}`;
|
|
289
290
|
for (const [key, value] of Object.entries(exportsField)) {
|
|
@@ -786,7 +787,7 @@ function augmentationReason(ctx) {
|
|
|
786
787
|
} catch {
|
|
787
788
|
continue;
|
|
788
789
|
}
|
|
789
|
-
entries.sort((x, y) => x.name
|
|
790
|
+
entries.sort((x, y) => compareText(x.name, y.name));
|
|
790
791
|
for (const entry of entries) {
|
|
791
792
|
if (++seen > AUGMENTATION_WALK_LIMIT) {
|
|
792
793
|
reason = `the package has more than ${AUGMENTATION_WALK_LIMIT} files to search for a \`declare module\` block, which can add names to its modules, so the names it imports were not checked`;
|
|
@@ -24,10 +24,16 @@
|
|
|
24
24
|
import * as fs from 'node:fs';
|
|
25
25
|
import * as path from 'node:path';
|
|
26
26
|
import {spawnSync} from 'node:child_process';
|
|
27
|
-
import {
|
|
27
|
+
import {createRequire} from 'node:module';
|
|
28
28
|
import {isValidSemver} from '../env/semver.mjs';
|
|
29
29
|
import {findProjectCoreDir} from '../fs/paths.mjs';
|
|
30
30
|
import {KNOWN_INTEGRATION_KEYS} from '../../authoring/integration/schema.mjs';
|
|
31
|
+
import {
|
|
32
|
+
isNodeEnvRead,
|
|
33
|
+
isProcessEnv,
|
|
34
|
+
isServerOnlyImport,
|
|
35
|
+
packagesInstalledWith,
|
|
36
|
+
} from '../../authoring/example/preview.mjs';
|
|
31
37
|
import {
|
|
32
38
|
contributionFiles,
|
|
33
39
|
findSourceOnlyCandidates,
|
|
@@ -1049,10 +1055,6 @@ export async function blockComponentsCheck(integration) {
|
|
|
1049
1055
|
// `A/B Testing`).
|
|
1050
1056
|
const PATH_CATEGORY = /^[a-z0-9][\w.-]*(?:\/[\w.-]+)+$/u;
|
|
1051
1057
|
|
|
1052
|
-
/** Imports a browser cannot load, which a showcase must not make. */
|
|
1053
|
-
const SERVER_ONLY_IMPORTS =
|
|
1054
|
-
/^(?:server-only|next\/headers|next\/server|next\/cache|node:.+)$/u;
|
|
1055
|
-
|
|
1056
1058
|
/**
|
|
1057
1059
|
* Every spelling a glob's `{a,b}` braces stand for, nested braces included.
|
|
1058
1060
|
* @param {string} pattern
|
|
@@ -1341,10 +1343,10 @@ function literalPath(node) {
|
|
|
1341
1343
|
* (which bundlers replace). `assets` are the relative paths it loads with `new URL('./x', import.meta.url)`. A module
|
|
1342
1344
|
* that does not parse reports nothing; the template check owns that.
|
|
1343
1345
|
* @param {string} source
|
|
1344
|
-
* @param {
|
|
1346
|
+
* @param {ReadonlyArray<string>} dependencies the packages the package declares
|
|
1345
1347
|
* @returns {{server: string[], assets: string[]}}
|
|
1346
1348
|
*/
|
|
1347
|
-
function readModule(source,
|
|
1349
|
+
function readModule(source, dependencies) {
|
|
1348
1350
|
/** @type {any} */
|
|
1349
1351
|
let ast;
|
|
1350
1352
|
try {
|
|
@@ -1362,10 +1364,7 @@ function readModule(source, builtins) {
|
|
|
1362
1364
|
const found = [];
|
|
1363
1365
|
/** @param {unknown} spec */
|
|
1364
1366
|
const checkSpec = spec => {
|
|
1365
|
-
if (
|
|
1366
|
-
typeof spec === 'string' &&
|
|
1367
|
-
(SERVER_ONLY_IMPORTS.test(spec) || builtins.has(spec))
|
|
1368
|
-
) {
|
|
1367
|
+
if (typeof spec === 'string' && isServerOnlyImport(spec, dependencies)) {
|
|
1369
1368
|
found.push(`imports '${spec}'`);
|
|
1370
1369
|
}
|
|
1371
1370
|
};
|
|
@@ -1431,30 +1430,13 @@ function readModule(source, builtins) {
|
|
|
1431
1430
|
}
|
|
1432
1431
|
break;
|
|
1433
1432
|
}
|
|
1434
|
-
case 'MemberExpression':
|
|
1435
|
-
|
|
1436
|
-
if (
|
|
1437
|
-
object.type === 'Identifier' &&
|
|
1438
|
-
object.name === 'process' &&
|
|
1439
|
-
!node.computed &&
|
|
1440
|
-
node.property.name === 'env'
|
|
1441
|
-
) {
|
|
1442
|
-
found.push('reads process.env');
|
|
1443
|
-
return;
|
|
1444
|
-
}
|
|
1445
|
-
if (
|
|
1446
|
-
object.type === 'MemberExpression' &&
|
|
1447
|
-
object.object.type === 'Identifier' &&
|
|
1448
|
-
object.object.name === 'process' &&
|
|
1449
|
-
!object.computed &&
|
|
1450
|
-
object.property.name === 'env'
|
|
1451
|
-
) {
|
|
1452
|
-
if (!node.computed && node.property.name === 'NODE_ENV') return;
|
|
1433
|
+
case 'MemberExpression':
|
|
1434
|
+
if (isNodeEnvRead(node)) return;
|
|
1435
|
+
if (isProcessEnv(node) || isProcessEnv(node.object)) {
|
|
1453
1436
|
found.push('reads process.env');
|
|
1454
1437
|
return;
|
|
1455
1438
|
}
|
|
1456
1439
|
break;
|
|
1457
|
-
}
|
|
1458
1440
|
default:
|
|
1459
1441
|
break;
|
|
1460
1442
|
}
|
|
@@ -1560,21 +1542,14 @@ export async function componentExamplesCheck(integration) {
|
|
|
1560
1542
|
const rel = (/** @type {string} */ file) => slash(path.relative(base, file));
|
|
1561
1543
|
/** @type {unknown} */
|
|
1562
1544
|
let packedFiles;
|
|
1563
|
-
/** @type {
|
|
1564
|
-
|
|
1545
|
+
/** @type {string[]} the packages an app installs with this one */
|
|
1546
|
+
let dependencies = [];
|
|
1565
1547
|
try {
|
|
1566
1548
|
const pkg = JSON.parse(
|
|
1567
1549
|
fs.readFileSync(path.join(base, 'package.json'), 'utf8'),
|
|
1568
1550
|
);
|
|
1569
1551
|
packedFiles = pkg.files;
|
|
1570
|
-
|
|
1571
|
-
'dependencies',
|
|
1572
|
-
'peerDependencies',
|
|
1573
|
-
'optionalDependencies',
|
|
1574
|
-
'devDependencies',
|
|
1575
|
-
]) {
|
|
1576
|
-
for (const name of Object.keys(pkg[field] ?? {})) declared.add(name);
|
|
1577
|
-
}
|
|
1552
|
+
dependencies = packagesInstalledWith(pkg);
|
|
1578
1553
|
} catch {
|
|
1579
1554
|
packedFiles = undefined;
|
|
1580
1555
|
}
|
|
@@ -1582,9 +1557,6 @@ export async function componentExamplesCheck(integration) {
|
|
|
1582
1557
|
const npm = {};
|
|
1583
1558
|
/** @type {Array<{file: string, asset: string, reason: string}>} */
|
|
1584
1559
|
const unchecked = [];
|
|
1585
|
-
// A bare builtin name the package installs from npm (`buffer`, `events`)
|
|
1586
|
-
// is that package, which bundlers ship to the browser.
|
|
1587
|
-
const builtins = new Set(builtinModules.filter(name => !declared.has(name)));
|
|
1588
1560
|
/** @type {Set<string>} */
|
|
1589
1561
|
const shown = new Set();
|
|
1590
1562
|
for (const template of templates) {
|
|
@@ -1616,7 +1588,7 @@ export async function componentExamplesCheck(integration) {
|
|
|
1616
1588
|
} catch {
|
|
1617
1589
|
continue;
|
|
1618
1590
|
}
|
|
1619
|
-
const parsed = readModule(source,
|
|
1591
|
+
const parsed = readModule(source, dependencies);
|
|
1620
1592
|
// A block is a showcase when it says so, or when it shows components
|
|
1621
1593
|
// through `alsoShowcaseFor`, which counts them as shown above.
|
|
1622
1594
|
const showcase =
|
|
@@ -26,3 +26,9 @@ export function embeddedPathProblem(p: string, options?: {
|
|
|
26
26
|
} | null;
|
|
27
27
|
/** The file extensions a page module may have. */
|
|
28
28
|
export const PAGE_EXTENSIONS: string[];
|
|
29
|
+
/**
|
|
30
|
+
* The file extensions of a module a render carries: a page module's, and the
|
|
31
|
+
* module kinds a page module may import that hold no JSX (`.mts`, `.cts`,
|
|
32
|
+
* `.cjs`).
|
|
33
|
+
*/
|
|
34
|
+
export const MODULE_EXTENSIONS: string[];
|
|
@@ -18,12 +18,32 @@ import {isAssetPath} from './assets.mjs';
|
|
|
18
18
|
/** The file extensions a page module may have. */
|
|
19
19
|
export const PAGE_EXTENSIONS = ['.tsx', '.jsx', '.ts', '.js', '.mjs'];
|
|
20
20
|
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* The file extensions of a module a render carries: a page module's, and the
|
|
23
|
+
* module kinds a page module may import that hold no JSX (`.mts`, `.cts`,
|
|
24
|
+
* `.cjs`).
|
|
25
|
+
*/
|
|
26
|
+
export const MODULE_EXTENSIONS = [...PAGE_EXTENSIONS, '.mts', '.cts', '.cjs'];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* JSON files that configure a project or a tool rather than hold page data,
|
|
30
|
+
* by the names tools read: a manifest or a tool's own file (`package.json`,
|
|
31
|
+
* `turbo.json`, `project.json`, ...), a TypeScript or JavaScript project
|
|
32
|
+
* (`tsconfig.json`, `tsconfig.app.json`, `jsconfig.json`), a `*.config.json`,
|
|
33
|
+
* and a lockfile. Page data may have any other name (`config.json`,
|
|
34
|
+
* `chart-config.json`). An rc file a tool reads is a dotfile, which no render
|
|
35
|
+
* carries.
|
|
36
|
+
*/
|
|
22
37
|
const CONFIG_JSON =
|
|
23
|
-
/^(package|package-lock|composer|deno|turbo|vercel|nx|lerna|app|bower|now|netlify|firebase|renovate|project|workspace|angular|biome|components)\.jsonc
|
|
38
|
+
/^(package|package-lock|composer|deno|turbo|vercel|nx|lerna|app|bower|now|netlify|firebase|renovate|project|workspace|angular|biome|components)\.jsonc?$|^(ts|js)config(\.[^.]+)*\.jsonc?$|\.config\.jsonc?$|(^|[._-])lock\.jsonc?$/i;
|
|
24
39
|
|
|
25
|
-
/**
|
|
26
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Tool configuration modules, by the names tools read: `vite.config.ts`,
|
|
42
|
+
* `astryx.config.mjs`, `next.config.js`. A module named `config.ts` or
|
|
43
|
+
* `arc.ts` is the page's own; an rc module a tool reads (`.eslintrc.js`) is
|
|
44
|
+
* a dotfile, which no render carries.
|
|
45
|
+
*/
|
|
46
|
+
const CONFIG_MODULE = /\.config\.[cm]?[jt]sx?$/i;
|
|
27
47
|
|
|
28
48
|
/** Any script module. */
|
|
29
49
|
const SCRIPT = /\.(c|m)?[jt]sx?$/i;
|
|
@@ -103,6 +123,6 @@ export function embeddedPathProblem(p, options = {}) {
|
|
|
103
123
|
if (((ext === '.json' || ext === '.jsonc') && CONFIG_JSON.test(base)) || CONFIG_MODULE.test(base)) {
|
|
104
124
|
return {code: 'ERR_RENDER_SOURCE_DAMAGED', reason: `a project or tool configuration file (${p})`};
|
|
105
125
|
}
|
|
106
|
-
if (
|
|
126
|
+
if (MODULE_EXTENSIONS.includes(ext) || ext === '.css' || ext === '.json' || isAssetPath(p)) return null;
|
|
107
127
|
return {code: 'ERR_RENDER_SOURCE_DAMAGED', reason: `a kind of file a render never embeds (${p})`};
|
|
108
128
|
}
|