fix: tolerate static file imports in config files (brillout/docpress#86)#3123
Merged
fix: tolerate static file imports in config files (brillout/docpress#86)#3123
Conversation
d59db8e to
7c3697d
Compare
…lation
Non-JS imports (e.g. .svg, .css) are now resolved to
'STATIC_FILE_NOT_AVAILABLE:/path/to/file' instead of being
treated as pointer imports, enabling files with
`env: { config: true, client: true }` to be loaded in Node.js.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 82a19ffcde861d0e97f6b3a0d2d4bb007b82b643.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… not stubs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use a cached esbuild sub-call to enumerate a file's exports, so that named imports from runtime-tagged or non-script files all resolve to the STATIC_FILE_NOT_AVAILABLE stub string. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Instead of a sub-build to enumerate exports, reuse the existing
Babel-based pointer import transform: mark with{type:'runtime'}
imports as 'static' in the pointerImports map so that
transformPointerImports replaces each specifier with
STATIC_FILE_NOT_AVAILABLE:<path>.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Convert STATIC_FILE_NOT_AVAILABLE:path strings to import statements during config value serialization, just like pointer import strings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Multiple config values with the same STATIC_FILE_NOT_AVAILABLE (or pointer import) path were generating redundant import bindings. Use a WeakMap keyed on the importStatements array to reuse existing import names for same path+export pairs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit b3964dea5a2b4336dade2468257c145653e34027.
Store Vite-compatible paths in STATIC_FILE_NOT_AVAILABLE strings: - vike-static-file onLoad: convert abs path to root-relative (/@fs/ fallback) - isStaticStub onResolve: store Vite path (npm name or root-relative) in pointerImports dict; update pointerImports.ts to use it as the path Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…m paths" This reverts commit 0384f63c48c372b1e269b6a14326afeef2cc4f14.
- with{type:'runtime'} script files: treat as regular pointer imports
(import:path:exportName format) instead of static stubs, so export
names are correctly encoded and the pointer import mechanism handles
serialization.
- Remove 'static' type from pointerImports map; remove isStaticStub
logic from pointerImports.ts.
- vike-static-file onLoad: convert abs filesystem path to Vite-compatible
root-relative path (/@fs/ fallback) so the STATIC_FILE_NOT_AVAILABLE
string contains the correct import path.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add pluginStripRuntimeImportAttribute Vite plugin that removes
`with { type: 'runtime' }` attributes from import statements when
files are transpiled for client/server runtime. These attributes are
config-time only; leaving them in runtime code breaks bundlers and
runtimes that don't support unknown import attributes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…e bundles" This reverts commit 354198e.
…lues Config values loaded at config-time that contain STATIC_FILE_NOT_AVAILABLE strings should not be converted to runtime imports. The serializer should not be involved; the vike-static-file stub is only for preventing Node.js crashes when config files import non-script files at config-time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Non-plain-script value files (+docpress.tsx, +Component.vue, etc.) are runtime-only files. Even when env.config=true, they should remain as plus-file pointer imports rather than being evaluated at config-time. This is consistent with the existing pointer-import logic in transpileAndExecuteFile.ts: // .jsx, .vue, .svg, ... => obviously not config code => pointer import Previously, the vike-static-file stub allowed these files to load successfully at config-time (bypassing SVG/CSS import failures), causing them to be serialized as 'js-serialized' instead of 'plus-file'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…files" This reverts commit a2169cb.
…e:runtime}" This reverts commit 1d44d75.
When a +{configName}.js value file also runs in client or server
environments (env.client or env.server), its value must remain a
pointer import rather than being inlined as 'js-serialized' JSON.
This prevents value files like +docpress.tsx (env: { config, client,
server }) from being evaluated and inlined at config-time. Their imports
(SVG files, icon packages, etc.) should only be resolved by Vite at
runtime, not at config-time by esbuild.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…me bundles" This reverts commit 9d2cef2.
…pe:runtime}" This reverts commit 57d3e2059c2cd4ed905804b0fd51df4e573ca470.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7c3697d to
0767293
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See also:
dist/externalizable brillout/docpress#85+docpressat build time (meta.env.config === true) brillout/docpress#86+docpressat build time (meta.env.config === true) (closes #86) brillout/docpress#88with { type: 'vike-pointer' }(closes #1500) #3126