astro 4.5.16 → 4.5.17
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/astro-jsx.d.ts +2 -0
- package/dist/@types/astro.d.ts +2 -2
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/core/build/generate.js +1 -1
- package/dist/core/build/plugins/plugin-prerender.js +3 -1
- package/dist/core/build/plugins/plugin-scripts.js +12 -3
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/jsx/renderer.d.ts +2 -8
- package/dist/jsx/renderer.js +2 -11
- package/dist/jsx/transform-options.d.ts +2 -0
- package/dist/jsx/transform-options.js +14 -0
- package/dist/runtime/client/dev-toolbar/entrypoint.js +3 -3
- package/dist/runtime/client/dev-toolbar/toolbar.js +7 -1
- package/dist/vite-plugin-mdx/index.d.ts +1 -9
- package/dist/vite-plugin-mdx/index.js +3 -65
- package/dist/vite-plugin-mdx/tag.d.ts +1 -4
- package/dist/vite-plugin-mdx/tag.js +93 -97
- package/dist/vite-plugin-mdx/transform-jsx.d.ts +2 -0
- package/dist/vite-plugin-mdx/transform-jsx.js +50 -0
- package/package.json +1 -1
package/astro-jsx.d.ts
CHANGED
|
@@ -873,6 +873,8 @@ declare namespace astroHTML.JSX {
|
|
|
873
873
|
playsinline?: boolean | string | undefined | null;
|
|
874
874
|
preload?: string | undefined | null;
|
|
875
875
|
src?: string | undefined | null;
|
|
876
|
+
// https://www.w3.org/TR/remote-playback/#the-disableremoteplayback-attribute
|
|
877
|
+
disableRemotePlayback?: boolean | string | undefined | null;
|
|
876
878
|
}
|
|
877
879
|
|
|
878
880
|
interface MetaHTMLAttributes extends HTMLAttributes {
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -2330,9 +2330,9 @@ export interface AstroRenderer {
|
|
|
2330
2330
|
clientEntrypoint?: string;
|
|
2331
2331
|
/** Import entrypoint for the server/build/ssr renderer. */
|
|
2332
2332
|
serverEntrypoint: string;
|
|
2333
|
-
/**
|
|
2333
|
+
/** @deprecated Vite plugins should transform the JSX instead */
|
|
2334
2334
|
jsxImportSource?: string;
|
|
2335
|
-
/**
|
|
2335
|
+
/** @deprecated Vite plugins should transform the JSX instead */
|
|
2336
2336
|
jsxTransformOptions?: JSXTransformFn;
|
|
2337
2337
|
}
|
|
2338
2338
|
export interface SSRLoadedRenderer extends AstroRenderer {
|
package/dist/cli/add/babel.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const visit: {
|
|
|
11
11
|
node: (node: traverse.Node, opts: traverse.TraverseOptions<traverse.Node>, scope?: traverse.Scope | undefined, state?: any, path?: traverse.NodePath<traverse.Node> | undefined, skipKeys?: Record<string, boolean> | undefined) => void;
|
|
12
12
|
clearNode: (node: traverse.Node, opts?: traverse.RemovePropertiesOptions | undefined) => void;
|
|
13
13
|
removeProperties: (tree: traverse.Node, opts?: traverse.RemovePropertiesOptions | undefined) => traverse.Node;
|
|
14
|
-
hasType: (tree: traverse.Node, type: "CatchClause" | "ClassBody" | "Identifier" | "Program" | "SpreadElement" | "Super" | "SwitchCase" | "TemplateElement" | "VariableDeclarator" | "ArrayExpression" | "ArrowFunctionExpression" | "AssignmentExpression" | "AwaitExpression" | "BinaryExpression" | "CallExpression" | "ClassExpression" | "ConditionalExpression" | "FunctionExpression" | "ImportExpression" | "LogicalExpression" | "MemberExpression" | "MetaProperty" | "NewExpression" | "ObjectExpression" | "SequenceExpression" | "TaggedTemplateExpression" | "TemplateLiteral" | "ThisExpression" | "UnaryExpression" | "UpdateExpression" | "YieldExpression" | "ClassDeclaration" | "FunctionDeclaration" | "ImportDeclaration" | "ExportNamedDeclaration" | "ExportDefaultDeclaration" | "ExportAllDeclaration" | "ImportSpecifier" | "ImportDefaultSpecifier" | "ImportNamespaceSpecifier" | "ExportSpecifier" | "ObjectPattern" | "ArrayPattern" | "RestElement" | "AssignmentPattern" | "ExpressionStatement" | "BlockStatement" | "StaticBlock" | "EmptyStatement" | "DebuggerStatement" | "WithStatement" | "ReturnStatement" | "LabeledStatement" | "BreakStatement" | "ContinueStatement" | "IfStatement" | "SwitchStatement" | "ThrowStatement" | "TryStatement" | "WhileStatement" | "DoWhileStatement" | "ForStatement" | "ForInStatement" | "ForOfStatement" | "VariableDeclaration" | "File" | "AnyTypeAnnotation" | "ArgumentPlaceholder" | "ArrayTypeAnnotation" | "BigIntLiteral" | "BindExpression" | "BooleanLiteral" | "BooleanLiteralTypeAnnotation" | "BooleanTypeAnnotation" | "ClassAccessorProperty" | "ClassImplements" | "ClassMethod" | "ClassPrivateMethod" | "ClassPrivateProperty" | "ClassProperty" | "DecimalLiteral" | "DeclareClass" | "DeclareExportAllDeclaration" | "DeclareExportDeclaration" | "DeclareFunction" | "DeclareInterface" | "DeclareModule" | "DeclareModuleExports" | "DeclareOpaqueType" | "DeclareTypeAlias" | "DeclareVariable" | "DeclaredPredicate" | "Decorator" | "Directive" | "DirectiveLiteral" | "DoExpression" | "EmptyTypeAnnotation" | "EnumBooleanBody" | "EnumBooleanMember" | "EnumDeclaration" | "EnumDefaultedMember" | "EnumNumberBody" | "EnumNumberMember" | "EnumStringBody" | "EnumStringMember" | "EnumSymbolBody" | "ExistsTypeAnnotation" | "ExportDefaultSpecifier" | "ExportNamespaceSpecifier" | "FunctionTypeAnnotation" | "FunctionTypeParam" | "GenericTypeAnnotation" | "Import" | "ImportAttribute" | "IndexedAccessType" | "InferredPredicate" | "InterfaceDeclaration" | "InterfaceExtends" | "InterfaceTypeAnnotation" | "InterpreterDirective" | "IntersectionTypeAnnotation" | "
|
|
14
|
+
hasType: (tree: traverse.Node, type: "CatchClause" | "ClassBody" | "Identifier" | "Program" | "SpreadElement" | "Super" | "SwitchCase" | "TemplateElement" | "VariableDeclarator" | "ArrayExpression" | "ArrowFunctionExpression" | "AssignmentExpression" | "AwaitExpression" | "BinaryExpression" | "CallExpression" | "ClassExpression" | "ConditionalExpression" | "FunctionExpression" | "ImportExpression" | "LogicalExpression" | "MemberExpression" | "MetaProperty" | "NewExpression" | "ObjectExpression" | "SequenceExpression" | "TaggedTemplateExpression" | "TemplateLiteral" | "ThisExpression" | "UnaryExpression" | "UpdateExpression" | "YieldExpression" | "ClassDeclaration" | "FunctionDeclaration" | "ImportDeclaration" | "ExportNamedDeclaration" | "ExportDefaultDeclaration" | "ExportAllDeclaration" | "ImportSpecifier" | "ImportDefaultSpecifier" | "ImportNamespaceSpecifier" | "ExportSpecifier" | "ObjectPattern" | "ArrayPattern" | "RestElement" | "AssignmentPattern" | "ExpressionStatement" | "BlockStatement" | "StaticBlock" | "EmptyStatement" | "DebuggerStatement" | "WithStatement" | "ReturnStatement" | "LabeledStatement" | "BreakStatement" | "ContinueStatement" | "IfStatement" | "SwitchStatement" | "ThrowStatement" | "TryStatement" | "WhileStatement" | "DoWhileStatement" | "ForStatement" | "ForInStatement" | "ForOfStatement" | "VariableDeclaration" | "File" | "JSXAttribute" | "JSXSpreadAttribute" | "JSXIdentifier" | "JSXNamespacedName" | "JSXElement" | "JSXOpeningElement" | "JSXMemberExpression" | "AnyTypeAnnotation" | "ArgumentPlaceholder" | "ArrayTypeAnnotation" | "BigIntLiteral" | "BindExpression" | "BooleanLiteral" | "BooleanLiteralTypeAnnotation" | "BooleanTypeAnnotation" | "ClassAccessorProperty" | "ClassImplements" | "ClassMethod" | "ClassPrivateMethod" | "ClassPrivateProperty" | "ClassProperty" | "DecimalLiteral" | "DeclareClass" | "DeclareExportAllDeclaration" | "DeclareExportDeclaration" | "DeclareFunction" | "DeclareInterface" | "DeclareModule" | "DeclareModuleExports" | "DeclareOpaqueType" | "DeclareTypeAlias" | "DeclareVariable" | "DeclaredPredicate" | "Decorator" | "Directive" | "DirectiveLiteral" | "DoExpression" | "EmptyTypeAnnotation" | "EnumBooleanBody" | "EnumBooleanMember" | "EnumDeclaration" | "EnumDefaultedMember" | "EnumNumberBody" | "EnumNumberMember" | "EnumStringBody" | "EnumStringMember" | "EnumSymbolBody" | "ExistsTypeAnnotation" | "ExportDefaultSpecifier" | "ExportNamespaceSpecifier" | "FunctionTypeAnnotation" | "FunctionTypeParam" | "GenericTypeAnnotation" | "Import" | "ImportAttribute" | "IndexedAccessType" | "InferredPredicate" | "InterfaceDeclaration" | "InterfaceExtends" | "InterfaceTypeAnnotation" | "InterpreterDirective" | "IntersectionTypeAnnotation" | "JSXClosingElement" | "JSXClosingFragment" | "JSXEmptyExpression" | "JSXExpressionContainer" | "JSXFragment" | "JSXOpeningFragment" | "JSXSpreadChild" | "JSXText" | "MixedTypeAnnotation" | "ModuleExpression" | "Noop" | "NullLiteral" | "NullLiteralTypeAnnotation" | "NullableTypeAnnotation" | "NumberLiteral" | "NumberLiteralTypeAnnotation" | "NumberTypeAnnotation" | "NumericLiteral" | "ObjectMethod" | "ObjectProperty" | "ObjectTypeAnnotation" | "ObjectTypeCallProperty" | "ObjectTypeIndexer" | "ObjectTypeInternalSlot" | "ObjectTypeProperty" | "ObjectTypeSpreadProperty" | "OpaqueType" | "OptionalCallExpression" | "OptionalIndexedAccessType" | "OptionalMemberExpression" | "ParenthesizedExpression" | "PipelineBareFunction" | "PipelinePrimaryTopicReference" | "PipelineTopicExpression" | "Placeholder" | "PrivateName" | "QualifiedTypeIdentifier" | "RecordExpression" | "RegExpLiteral" | "RegexLiteral" | "RestProperty" | "SpreadProperty" | "StringLiteral" | "StringLiteralTypeAnnotation" | "StringTypeAnnotation" | "SymbolTypeAnnotation" | "TSAnyKeyword" | "TSArrayType" | "TSAsExpression" | "TSBigIntKeyword" | "TSBooleanKeyword" | "TSCallSignatureDeclaration" | "TSConditionalType" | "TSConstructSignatureDeclaration" | "TSConstructorType" | "TSDeclareFunction" | "TSDeclareMethod" | "TSEnumDeclaration" | "TSEnumMember" | "TSExportAssignment" | "TSExpressionWithTypeArguments" | "TSExternalModuleReference" | "TSFunctionType" | "TSImportEqualsDeclaration" | "TSImportType" | "TSIndexSignature" | "TSIndexedAccessType" | "TSInferType" | "TSInstantiationExpression" | "TSInterfaceBody" | "TSInterfaceDeclaration" | "TSIntersectionType" | "TSIntrinsicKeyword" | "TSLiteralType" | "TSMappedType" | "TSMethodSignature" | "TSModuleBlock" | "TSModuleDeclaration" | "TSNamedTupleMember" | "TSNamespaceExportDeclaration" | "TSNeverKeyword" | "TSNonNullExpression" | "TSNullKeyword" | "TSNumberKeyword" | "TSObjectKeyword" | "TSOptionalType" | "TSParameterProperty" | "TSParenthesizedType" | "TSPropertySignature" | "TSQualifiedName" | "TSRestType" | "TSSatisfiesExpression" | "TSStringKeyword" | "TSSymbolKeyword" | "TSThisType" | "TSTupleType" | "TSTypeAliasDeclaration" | "TSTypeAnnotation" | "TSTypeAssertion" | "TSTypeLiteral" | "TSTypeOperator" | "TSTypeParameter" | "TSTypeParameterDeclaration" | "TSTypeParameterInstantiation" | "TSTypePredicate" | "TSTypeQuery" | "TSTypeReference" | "TSUndefinedKeyword" | "TSUnionType" | "TSUnknownKeyword" | "TSVoidKeyword" | "ThisTypeAnnotation" | "TopicReference" | "TupleExpression" | "TupleTypeAnnotation" | "TypeAlias" | "TypeAnnotation" | "TypeCastExpression" | "TypeParameter" | "TypeParameterDeclaration" | "TypeParameterInstantiation" | "TypeofTypeAnnotation" | "UnionTypeAnnotation" | "V8IntrinsicIdentifier" | "Variance" | "VoidTypeAnnotation", denylistTypes?: string[] | undefined) => boolean;
|
|
15
15
|
cache: typeof traverse.cache;
|
|
16
16
|
};
|
|
17
17
|
export { t };
|
|
@@ -250,7 +250,7 @@ async function getPathsForRoute(route, mod, pipeline, builtPaths) {
|
|
|
250
250
|
logger,
|
|
251
251
|
ssr: serverLike
|
|
252
252
|
}).catch((err) => {
|
|
253
|
-
logger.
|
|
253
|
+
logger.error("build", `Failed to call getStaticPaths for ${route.component}`);
|
|
254
254
|
throw err;
|
|
255
255
|
});
|
|
256
256
|
const label = staticPaths.length === 1 ? "page" : "pages";
|
|
@@ -40,7 +40,6 @@ function vitePluginPrerender(opts, internals) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
opts.allPages;
|
|
44
43
|
pageInfo.hasSharedModules = hasSharedModules;
|
|
45
44
|
pageInfo.route.prerender = true;
|
|
46
45
|
return "prerender";
|
|
@@ -54,6 +53,9 @@ function vitePluginPrerender(opts, internals) {
|
|
|
54
53
|
};
|
|
55
54
|
}
|
|
56
55
|
function pluginPrerender(opts, internals) {
|
|
56
|
+
if (opts.settings.config.output === "static") {
|
|
57
|
+
return { targets: ["server"] };
|
|
58
|
+
}
|
|
57
59
|
return {
|
|
58
60
|
targets: ["server"],
|
|
59
61
|
hooks: {
|
|
@@ -7,10 +7,19 @@ function vitePluginScripts(internals) {
|
|
|
7
7
|
assetInlineLimit = config.build.assetsInlineLimit;
|
|
8
8
|
},
|
|
9
9
|
async generateBundle(_options, bundle) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const outputs = Object.values(bundle);
|
|
11
|
+
const importedIds = /* @__PURE__ */ new Set();
|
|
12
|
+
for (const output of outputs) {
|
|
13
|
+
if (output.type === "chunk") {
|
|
14
|
+
for (const id of output.imports) {
|
|
15
|
+
importedIds.add(id);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
for (const output of outputs) {
|
|
20
|
+
if (output.type === "chunk" && output.facadeModuleId && internals.discoveredScripts.has(output.facadeModuleId) && !importedIds.has(output.fileName) && output.imports.length === 0 && output.dynamicImports.length === 0 && shouldInlineAsset(output.code, output.fileName, assetInlineLimit)) {
|
|
12
21
|
internals.inlinedScripts.set(output.facadeModuleId, output.code.trim());
|
|
13
|
-
delete bundle[
|
|
22
|
+
delete bundle[output.fileName];
|
|
14
23
|
}
|
|
15
24
|
}
|
|
16
25
|
}
|
package/dist/core/constants.js
CHANGED
package/dist/core/create-vite.js
CHANGED
|
@@ -112,7 +112,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
|
|
|
112
112
|
envVitePlugin({ settings }),
|
|
113
113
|
markdownVitePlugin({ settings, logger }),
|
|
114
114
|
htmlVitePlugin(),
|
|
115
|
-
mdxVitePlugin(
|
|
115
|
+
mdxVitePlugin(),
|
|
116
116
|
astroPostprocessVitePlugin(),
|
|
117
117
|
astroIntegrationsContainerPlugin({ settings, logger }),
|
|
118
118
|
astroScriptsPageSSRPlugin({ settings }),
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -23,7 +23,7 @@ async function dev(inlineConfig) {
|
|
|
23
23
|
base: restart.container.settings.config.base
|
|
24
24
|
})
|
|
25
25
|
);
|
|
26
|
-
const currentVersion = "4.5.
|
|
26
|
+
const currentVersion = "4.5.17";
|
|
27
27
|
if (currentVersion.includes("-")) {
|
|
28
28
|
logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
|
|
29
29
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -36,7 +36,7 @@ function serverStart({
|
|
|
36
36
|
host,
|
|
37
37
|
base
|
|
38
38
|
}) {
|
|
39
|
-
const version = "4.5.
|
|
39
|
+
const version = "4.5.17";
|
|
40
40
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
41
41
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
42
42
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -261,7 +261,7 @@ function printHelp({
|
|
|
261
261
|
message.push(
|
|
262
262
|
linebreak(),
|
|
263
263
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
264
|
-
`v${"4.5.
|
|
264
|
+
`v${"4.5.17"}`
|
|
265
265
|
)} ${headline}`
|
|
266
266
|
);
|
|
267
267
|
}
|
package/dist/jsx/renderer.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
serverEntrypoint: string;
|
|
4
|
-
jsxImportSource: string;
|
|
5
|
-
jsxTransformOptions: () => Promise<{
|
|
6
|
-
plugins: any[];
|
|
7
|
-
}>;
|
|
8
|
-
};
|
|
1
|
+
import type { AstroRenderer } from '../@types/astro.js';
|
|
2
|
+
declare const renderer: AstroRenderer;
|
|
9
3
|
export default renderer;
|
package/dist/jsx/renderer.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
+
import { jsxTransformOptions } from "./transform-options.js";
|
|
1
2
|
const renderer = {
|
|
2
3
|
name: "astro:jsx",
|
|
3
4
|
serverEntrypoint: "astro/jsx/server.js",
|
|
4
5
|
jsxImportSource: "astro",
|
|
5
|
-
jsxTransformOptions
|
|
6
|
-
const plugin = await import("@babel/plugin-transform-react-jsx");
|
|
7
|
-
const jsx = plugin.default?.default ?? plugin.default;
|
|
8
|
-
const { default: astroJSX } = await import("./babel.js");
|
|
9
|
-
return {
|
|
10
|
-
plugins: [
|
|
11
|
-
astroJSX(),
|
|
12
|
-
jsx({}, { throwIfNamespace: false, runtime: "automatic", importSource: "astro" })
|
|
13
|
-
]
|
|
14
|
-
};
|
|
15
|
-
}
|
|
6
|
+
jsxTransformOptions
|
|
16
7
|
};
|
|
17
8
|
var renderer_default = renderer;
|
|
18
9
|
export {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
async function jsxTransformOptions() {
|
|
2
|
+
const plugin = await import("@babel/plugin-transform-react-jsx");
|
|
3
|
+
const jsx = plugin.default?.default ?? plugin.default;
|
|
4
|
+
const { default: astroJSX } = await import("./babel.js");
|
|
5
|
+
return {
|
|
6
|
+
plugins: [
|
|
7
|
+
astroJSX(),
|
|
8
|
+
jsx({}, { throwIfNamespace: false, runtime: "automatic", importSource: "astro" })
|
|
9
|
+
]
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
jsxTransformOptions
|
|
14
|
+
};
|
|
@@ -53,9 +53,9 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
53
53
|
overlay = document.createElement("astro-dev-toolbar");
|
|
54
54
|
const notificationLevels = ["error", "warning", "info"];
|
|
55
55
|
const notificationSVGs = {
|
|
56
|
-
error: '<svg viewBox="0 0 10 10"><rect width="9" height="9" x=".5" y=".5" fill="
|
|
57
|
-
warning: '<svg
|
|
58
|
-
info: '<svg viewBox="0 0 10 10"><rect width="9" height="9" x=".5" y=".5" fill="
|
|
56
|
+
error: '<svg viewBox="0 0 10 10" style="--fill:var(--fill-default);--fill-default:#B33E66;--fill-hover:#E3AFC1;"><rect width="9" height="9" x=".5" y=".5" fill="var(--fill)" stroke="#13151A" stroke-width="2" rx="4.5"/></svg>',
|
|
57
|
+
warning: '<svg width="12" height="10" fill="none" style="--fill:var(--fill-default);--fill-default:#B58A2D;--fill-hover:#D5B776;"><path fill="var(--fill)" stroke="#13151A" stroke-width="2" d="M7.29904 1.25c-.57735-1-2.02073-1-2.59808 0l-3.4641 6C.65951 8.25 1.3812 9.5 2.5359 9.5h6.9282c1.1547 0 1.8764-1.25 1.299-2.25l-3.46406-6Z"/></svg>',
|
|
58
|
+
info: '<svg viewBox="0 0 10 10" style="--fill:var(--fill-default);--fill-default:#3645D9;--fill-hover:#BDC3FF;"><rect width="9" height="9" x=".5" y=".5" fill="var(--fill)" stroke="#13151A" stroke-width="2" rx="1.5"/></svg>'
|
|
59
59
|
};
|
|
60
60
|
const prepareApp = (appDefinition, builtIn) => {
|
|
61
61
|
const eventTarget = new EventTarget();
|
|
@@ -171,8 +171,14 @@ class AstroDevToolbar extends HTMLElement {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
#dev-bar #bar-container .item:hover .notification rect, #dev-bar #bar-container .item:hover .notification path {
|
|
175
|
+
stroke: #38393D;
|
|
176
|
+
--fill: var(--fill-hover);
|
|
177
|
+
}
|
|
178
|
+
|
|
174
179
|
#dev-bar #bar-container .item.active .notification rect, #dev-bar #bar-container .item.active .notification path {
|
|
175
|
-
stroke:
|
|
180
|
+
stroke: #454C5C;
|
|
181
|
+
--fill: var(--fill-hover);
|
|
176
182
|
}
|
|
177
183
|
|
|
178
184
|
#dev-bar .item .icon {
|
|
@@ -1,10 +1,2 @@
|
|
|
1
1
|
import { type Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
import type { Logger } from '../core/logger/core.js';
|
|
4
|
-
interface AstroPluginJSXOptions {
|
|
5
|
-
settings: AstroSettings;
|
|
6
|
-
logger: Logger;
|
|
7
|
-
}
|
|
8
|
-
/** Use Astro config to allow for alternate or multiple JSX renderers (by default Vite will assume React) */
|
|
9
|
-
export default function mdxVitePlugin({ settings }: AstroPluginJSXOptions): Plugin;
|
|
10
|
-
export {};
|
|
2
|
+
export default function mdxVitePlugin(): Plugin;
|
|
@@ -1,71 +1,16 @@
|
|
|
1
1
|
import { transformWithEsbuild } from "vite";
|
|
2
|
-
import babel from "@babel/core";
|
|
3
2
|
import { CONTENT_FLAG, PROPAGATED_ASSET_FLAG } from "../content/index.js";
|
|
4
3
|
import { astroEntryPrefix } from "../core/build/plugins/plugin-component-entry.js";
|
|
5
4
|
import { removeQueryString } from "../core/path.js";
|
|
6
|
-
import
|
|
7
|
-
async function transformJSX({
|
|
8
|
-
code,
|
|
9
|
-
mode,
|
|
10
|
-
id,
|
|
11
|
-
ssr,
|
|
12
|
-
renderer,
|
|
13
|
-
root
|
|
14
|
-
}) {
|
|
15
|
-
const { jsxTransformOptions } = renderer;
|
|
16
|
-
const options = await jsxTransformOptions({ mode, ssr });
|
|
17
|
-
const plugins = [...options.plugins || []];
|
|
18
|
-
if (ssr) {
|
|
19
|
-
plugins.push(await tagExportsPlugin({ rendererName: renderer.name, root }));
|
|
20
|
-
}
|
|
21
|
-
const result = await babel.transformAsync(code, {
|
|
22
|
-
presets: options.presets,
|
|
23
|
-
plugins,
|
|
24
|
-
cwd: process.cwd(),
|
|
25
|
-
filename: id,
|
|
26
|
-
ast: false,
|
|
27
|
-
compact: false,
|
|
28
|
-
sourceMaps: true,
|
|
29
|
-
configFile: false,
|
|
30
|
-
babelrc: false,
|
|
31
|
-
inputSourceMap: options.inputSourceMap
|
|
32
|
-
});
|
|
33
|
-
if (!result)
|
|
34
|
-
return null;
|
|
35
|
-
if (renderer.name === "astro:jsx") {
|
|
36
|
-
const { astro } = result.metadata;
|
|
37
|
-
return {
|
|
38
|
-
code: result.code || "",
|
|
39
|
-
map: result.map,
|
|
40
|
-
meta: {
|
|
41
|
-
astro,
|
|
42
|
-
vite: {
|
|
43
|
-
// Setting this vite metadata to `ts` causes Vite to resolve .js
|
|
44
|
-
// extensions to .ts files.
|
|
45
|
-
lang: "ts"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
code: result.code || "",
|
|
52
|
-
map: result.map
|
|
53
|
-
};
|
|
54
|
-
}
|
|
5
|
+
import { transformJSX } from "./transform-jsx.js";
|
|
55
6
|
const SPECIAL_QUERY_REGEX = new RegExp(
|
|
56
7
|
`[?&](?:worker|sharedworker|raw|url|${CONTENT_FLAG}|${PROPAGATED_ASSET_FLAG})\\b`
|
|
57
8
|
);
|
|
58
|
-
function mdxVitePlugin(
|
|
59
|
-
let viteConfig;
|
|
60
|
-
let astroJSXRenderer;
|
|
9
|
+
function mdxVitePlugin() {
|
|
61
10
|
return {
|
|
62
11
|
name: "astro:jsx",
|
|
63
12
|
enforce: "pre",
|
|
64
13
|
// run transforms before other plugins
|
|
65
|
-
async configResolved(resolvedConfig) {
|
|
66
|
-
viteConfig = resolvedConfig;
|
|
67
|
-
astroJSXRenderer = settings.renderers.find((r) => r.jsxImportSource === "astro");
|
|
68
|
-
},
|
|
69
14
|
async transform(code, id, opts) {
|
|
70
15
|
if (SPECIAL_QUERY_REGEX.test(id) || id.startsWith(astroEntryPrefix)) {
|
|
71
16
|
return null;
|
|
@@ -86,14 +31,7 @@ function mdxVitePlugin({ settings }) {
|
|
|
86
31
|
}
|
|
87
32
|
}
|
|
88
33
|
});
|
|
89
|
-
return transformJSX(
|
|
90
|
-
code: jsxCode,
|
|
91
|
-
id,
|
|
92
|
-
renderer: astroJSXRenderer,
|
|
93
|
-
mode: viteConfig.mode,
|
|
94
|
-
ssr: Boolean(opts?.ssr),
|
|
95
|
-
root: settings.config.root
|
|
96
|
-
});
|
|
34
|
+
return await transformJSX(jsxCode, id, opts?.ssr);
|
|
97
35
|
}
|
|
98
36
|
};
|
|
99
37
|
}
|
|
@@ -7,7 +7,4 @@ import type { PluginObj } from '@babel/core';
|
|
|
7
7
|
* This plugin crawls each export in the file and "tags" each export with a given `rendererName`.
|
|
8
8
|
* This allows us to automatically match a component to a renderer and skip the usual `check()` calls.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
11
|
-
rendererName: string;
|
|
12
|
-
root: URL;
|
|
13
|
-
}): Promise<PluginObj>;
|
|
10
|
+
export declare const tagExportsPlugin: PluginObj;
|
|
@@ -1,107 +1,103 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
t.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
);
|
|
23
|
-
},
|
|
24
|
-
// For each export we found, inject `__astro_tag_component__(exportName, rendererName)`
|
|
25
|
-
exit(path, state) {
|
|
26
|
-
const exportedIds = state.get("astro:tags");
|
|
27
|
-
if (exportedIds) {
|
|
28
|
-
for (const id of exportedIds) {
|
|
29
|
-
path.node.body.push(
|
|
30
|
-
t.expressionStatement(
|
|
31
|
-
t.callExpression(t.identifier("__astro_tag_component__"), [
|
|
32
|
-
t.identifier(id),
|
|
33
|
-
t.stringLiteral(rendererName)
|
|
34
|
-
])
|
|
35
|
-
)
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
2
|
+
import astroJsxRenderer from "../jsx/renderer.js";
|
|
3
|
+
const rendererName = astroJsxRenderer.name;
|
|
4
|
+
const tagExportsPlugin = {
|
|
5
|
+
visitor: {
|
|
6
|
+
Program: {
|
|
7
|
+
// Inject `import { __astro_tag_component__ } from 'astro/runtime/server/index.js'`
|
|
8
|
+
enter(path) {
|
|
9
|
+
path.node.body.splice(
|
|
10
|
+
0,
|
|
11
|
+
0,
|
|
12
|
+
t.importDeclaration(
|
|
13
|
+
[
|
|
14
|
+
t.importSpecifier(
|
|
15
|
+
t.identifier("__astro_tag_component__"),
|
|
16
|
+
t.identifier("__astro_tag_component__")
|
|
17
|
+
)
|
|
18
|
+
],
|
|
19
|
+
t.stringLiteral("astro/runtime/server/index.js")
|
|
20
|
+
)
|
|
21
|
+
);
|
|
40
22
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const uidIdentifier = path.scope.generateUidIdentifier(varName);
|
|
54
|
-
path.insertBefore(
|
|
55
|
-
t.variableDeclaration("const", [
|
|
56
|
-
t.variableDeclarator(uidIdentifier, node.declaration)
|
|
57
|
-
])
|
|
23
|
+
// For each export we found, inject `__astro_tag_component__(exportName, rendererName)`
|
|
24
|
+
exit(path, state) {
|
|
25
|
+
const exportedIds = state.get("astro:tags");
|
|
26
|
+
if (exportedIds) {
|
|
27
|
+
for (const id of exportedIds) {
|
|
28
|
+
path.node.body.push(
|
|
29
|
+
t.expressionStatement(
|
|
30
|
+
t.callExpression(t.identifier("__astro_tag_component__"), [
|
|
31
|
+
t.identifier(id),
|
|
32
|
+
t.stringLiteral(rendererName)
|
|
33
|
+
])
|
|
34
|
+
)
|
|
58
35
|
);
|
|
59
|
-
node.declaration = uidIdentifier;
|
|
60
|
-
} else if (t.isFunctionDeclaration(node.declaration) && !node.declaration.id?.name) {
|
|
61
|
-
const uidIdentifier = path.scope.generateUidIdentifier("_function");
|
|
62
|
-
node.declaration.id = uidIdentifier;
|
|
63
36
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
ExportDeclaration: {
|
|
41
|
+
/**
|
|
42
|
+
* For default anonymous function export, we need to give them a unique name
|
|
43
|
+
* @param path
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
enter(path) {
|
|
47
|
+
const node = path.node;
|
|
48
|
+
if (!t.isExportDefaultDeclaration(node))
|
|
49
|
+
return;
|
|
50
|
+
if (t.isArrowFunctionExpression(node.declaration) || t.isCallExpression(node.declaration)) {
|
|
51
|
+
const varName = t.isArrowFunctionExpression(node.declaration) ? "_arrow_function" : "_hoc_function";
|
|
52
|
+
const uidIdentifier = path.scope.generateUidIdentifier(varName);
|
|
53
|
+
path.insertBefore(
|
|
54
|
+
t.variableDeclaration("const", [t.variableDeclarator(uidIdentifier, node.declaration)])
|
|
55
|
+
);
|
|
56
|
+
node.declaration = uidIdentifier;
|
|
57
|
+
} else if (t.isFunctionDeclaration(node.declaration) && !node.declaration.id?.name) {
|
|
58
|
+
const uidIdentifier = path.scope.generateUidIdentifier("_function");
|
|
59
|
+
node.declaration.id = uidIdentifier;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
exit(path, state) {
|
|
63
|
+
const node = path.node;
|
|
64
|
+
if (node.exportKind === "type")
|
|
65
|
+
return;
|
|
66
|
+
if (t.isExportAllDeclaration(node))
|
|
67
|
+
return;
|
|
68
|
+
const addTag = (id) => {
|
|
69
|
+
const tags = state.get("astro:tags") ?? [];
|
|
70
|
+
state.set("astro:tags", [...tags, id]);
|
|
71
|
+
};
|
|
72
|
+
if (t.isExportNamedDeclaration(node) || t.isExportDefaultDeclaration(node)) {
|
|
73
|
+
if (t.isIdentifier(node.declaration)) {
|
|
74
|
+
addTag(node.declaration.name);
|
|
75
|
+
} else if (t.isFunctionDeclaration(node.declaration) && node.declaration.id?.name) {
|
|
76
|
+
addTag(node.declaration.id.name);
|
|
77
|
+
} else if (t.isVariableDeclaration(node.declaration)) {
|
|
78
|
+
node.declaration.declarations?.forEach((declaration) => {
|
|
79
|
+
if (t.isArrowFunctionExpression(declaration.init) && t.isIdentifier(declaration.id)) {
|
|
80
|
+
addTag(declaration.id.name);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
} else if (t.isObjectExpression(node.declaration)) {
|
|
84
|
+
node.declaration.properties?.forEach((property) => {
|
|
85
|
+
if (t.isProperty(property) && t.isIdentifier(property.key)) {
|
|
86
|
+
addTag(property.key.name);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
} else if (t.isExportNamedDeclaration(node) && !node.source) {
|
|
90
|
+
node.specifiers.forEach((specifier) => {
|
|
91
|
+
if (t.isExportSpecifier(specifier) && t.isIdentifier(specifier.exported)) {
|
|
92
|
+
addTag(specifier.local.name);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
99
95
|
}
|
|
100
96
|
}
|
|
101
97
|
}
|
|
102
98
|
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
105
101
|
export {
|
|
106
|
-
|
|
102
|
+
tagExportsPlugin
|
|
107
103
|
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import babel from "@babel/core";
|
|
2
|
+
import { jsxTransformOptions } from "../jsx/transform-options.js";
|
|
3
|
+
import { tagExportsPlugin } from "./tag.js";
|
|
4
|
+
async function transformJSX(code, id, ssr) {
|
|
5
|
+
const options = await getJsxTransformOptions();
|
|
6
|
+
const plugins = ssr ? [...options.plugins ?? [], tagExportsPlugin] : options.plugins;
|
|
7
|
+
const result = await babel.transformAsync(code, {
|
|
8
|
+
presets: options.presets,
|
|
9
|
+
plugins,
|
|
10
|
+
cwd: process.cwd(),
|
|
11
|
+
filename: id,
|
|
12
|
+
ast: false,
|
|
13
|
+
compact: false,
|
|
14
|
+
sourceMaps: true,
|
|
15
|
+
configFile: false,
|
|
16
|
+
babelrc: false,
|
|
17
|
+
browserslistConfigFile: false,
|
|
18
|
+
inputSourceMap: options.inputSourceMap
|
|
19
|
+
});
|
|
20
|
+
if (!result)
|
|
21
|
+
return null;
|
|
22
|
+
const { astro } = result.metadata;
|
|
23
|
+
return {
|
|
24
|
+
code: result.code || "",
|
|
25
|
+
map: result.map,
|
|
26
|
+
meta: {
|
|
27
|
+
astro,
|
|
28
|
+
vite: {
|
|
29
|
+
// Setting this vite metadata to `ts` causes Vite to resolve .js
|
|
30
|
+
// extensions to .ts files.
|
|
31
|
+
lang: "ts"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
let cachedJsxTransformOptions;
|
|
37
|
+
async function getJsxTransformOptions() {
|
|
38
|
+
if (cachedJsxTransformOptions) {
|
|
39
|
+
return cachedJsxTransformOptions;
|
|
40
|
+
}
|
|
41
|
+
const options = jsxTransformOptions();
|
|
42
|
+
cachedJsxTransformOptions = options;
|
|
43
|
+
options.then((resolvedOptions) => {
|
|
44
|
+
cachedJsxTransformOptions = resolvedOptions;
|
|
45
|
+
});
|
|
46
|
+
return options;
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
transformJSX
|
|
50
|
+
};
|