astro 1.5.3 → 1.6.0
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/client-base.d.ts +98 -11
- package/dist/@types/astro.d.ts +8 -4
- package/dist/cli/index.js +2 -0
- package/dist/core/config/config.js +3 -0
- package/dist/core/config/settings.js +2 -1
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +11 -2
- package/dist/core/create-vite.js +22 -84
- package/dist/core/dev/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/preview/index.js +3 -1
- package/dist/core/render/dev/vite.js +2 -1
- package/dist/core/routing/manifest/create.js +6 -1
- package/dist/core/util.d.ts +5 -0
- package/dist/core/util.js +17 -0
- package/dist/vite-plugin-astro-postprocess/index.js +2 -1
- package/dist/vite-plugin-jsx/index.js +2 -2
- package/dist/vite-plugin-markdown/index.js +3 -2
- package/dist/vite-plugin-markdown-legacy/index.js +5 -4
- package/package.json +3 -1
package/client-base.d.ts
CHANGED
|
@@ -1,19 +1,106 @@
|
|
|
1
1
|
/// <reference path="./import-meta.d.ts" />
|
|
2
2
|
|
|
3
|
+
type MD = import('./dist/@types/astro').MarkdownInstance<Record<string, any>>;
|
|
4
|
+
interface ExportedMarkdownModuleEntities {
|
|
5
|
+
frontmatter: MD['frontmatter'];
|
|
6
|
+
file: MD['file'];
|
|
7
|
+
url: MD['url'];
|
|
8
|
+
getHeadings: MD['getHeadings'];
|
|
9
|
+
/** @deprecated Renamed to `getHeadings()` */
|
|
10
|
+
getHeaders: () => void;
|
|
11
|
+
Content: MD['Content'];
|
|
12
|
+
rawContent: MD['rawContent'];
|
|
13
|
+
compiledContent: MD['compiledContent'];
|
|
14
|
+
load: MD['default'];
|
|
15
|
+
}
|
|
16
|
+
|
|
3
17
|
declare module '*.md' {
|
|
4
|
-
|
|
18
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
19
|
+
export const {
|
|
20
|
+
frontmatter,
|
|
21
|
+
file,
|
|
22
|
+
url,
|
|
23
|
+
getHeadings,
|
|
24
|
+
getHeaders,
|
|
25
|
+
Content,
|
|
26
|
+
rawContent,
|
|
27
|
+
compiledContent,
|
|
28
|
+
}: ExportedMarkdownModuleEntities;
|
|
29
|
+
export default load;
|
|
30
|
+
}
|
|
5
31
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
32
|
+
declare module '*.markdown' {
|
|
33
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
34
|
+
export const {
|
|
35
|
+
frontmatter,
|
|
36
|
+
file,
|
|
37
|
+
url,
|
|
38
|
+
getHeadings,
|
|
39
|
+
getHeaders,
|
|
40
|
+
Content,
|
|
41
|
+
rawContent,
|
|
42
|
+
compiledContent,
|
|
43
|
+
}: ExportedMarkdownModuleEntities;
|
|
44
|
+
export default load;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare module '*.mkdn' {
|
|
48
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
49
|
+
export const {
|
|
50
|
+
frontmatter,
|
|
51
|
+
file,
|
|
52
|
+
url,
|
|
53
|
+
getHeadings,
|
|
54
|
+
getHeaders,
|
|
55
|
+
Content,
|
|
56
|
+
rawContent,
|
|
57
|
+
compiledContent,
|
|
58
|
+
}: ExportedMarkdownModuleEntities;
|
|
59
|
+
export default load;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare module '*.mkd' {
|
|
63
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
64
|
+
export const {
|
|
65
|
+
frontmatter,
|
|
66
|
+
file,
|
|
67
|
+
url,
|
|
68
|
+
getHeadings,
|
|
69
|
+
getHeaders,
|
|
70
|
+
Content,
|
|
71
|
+
rawContent,
|
|
72
|
+
compiledContent,
|
|
73
|
+
}: ExportedMarkdownModuleEntities;
|
|
74
|
+
export default load;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare module '*.mdwn' {
|
|
78
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
79
|
+
export const {
|
|
80
|
+
frontmatter,
|
|
81
|
+
file,
|
|
82
|
+
url,
|
|
83
|
+
getHeadings,
|
|
84
|
+
getHeaders,
|
|
85
|
+
Content,
|
|
86
|
+
rawContent,
|
|
87
|
+
compiledContent,
|
|
88
|
+
}: ExportedMarkdownModuleEntities;
|
|
89
|
+
export default load;
|
|
90
|
+
}
|
|
15
91
|
|
|
16
|
-
|
|
92
|
+
declare module '*.mdown' {
|
|
93
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
94
|
+
export const {
|
|
95
|
+
frontmatter,
|
|
96
|
+
file,
|
|
97
|
+
url,
|
|
98
|
+
getHeadings,
|
|
99
|
+
getHeaders,
|
|
100
|
+
Content,
|
|
101
|
+
rawContent,
|
|
102
|
+
compiledContent,
|
|
103
|
+
}: ExportedMarkdownModuleEntities;
|
|
17
104
|
export default load;
|
|
18
105
|
}
|
|
19
106
|
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { PageBuildData } from '../core/build/types';
|
|
|
11
11
|
import type { AstroConfigSchema } from '../core/config';
|
|
12
12
|
import type { AstroCookies } from '../core/cookies';
|
|
13
13
|
import type { AstroComponentFactory } from '../runtime/server';
|
|
14
|
+
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
|
|
14
15
|
export type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, ShikiConfig, } from '@astrojs/markdown-remark';
|
|
15
16
|
export type { SSRManifest } from '../core/app/types';
|
|
16
17
|
export interface AstroBuiltinProps {
|
|
@@ -54,6 +55,7 @@ export interface AstroComponentMetadata {
|
|
|
54
55
|
export interface CLIFlags {
|
|
55
56
|
root?: string;
|
|
56
57
|
site?: string;
|
|
58
|
+
base?: string;
|
|
57
59
|
host?: string | boolean;
|
|
58
60
|
port?: number;
|
|
59
61
|
config?: string;
|
|
@@ -219,6 +221,8 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
|
|
|
219
221
|
render(slotName: string, args?: any[]): Promise<string>;
|
|
220
222
|
};
|
|
221
223
|
}
|
|
224
|
+
/** Union type of supported markdown file extensions */
|
|
225
|
+
declare type MarkdowFileExtension = typeof SUPPORTED_MARKDOWN_FILE_EXTENSIONS[number];
|
|
222
226
|
export interface AstroGlobalPartial {
|
|
223
227
|
/**
|
|
224
228
|
* @deprecated since version 0.24. See the {@link https://astro.build/deprecated/resolve upgrade guide} for more details.
|
|
@@ -237,7 +241,7 @@ export interface AstroGlobalPartial {
|
|
|
237
241
|
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroglob)
|
|
238
242
|
*/
|
|
239
243
|
glob(globStr: `${any}.astro`): Promise<AstroInstance[]>;
|
|
240
|
-
glob<T extends Record<string, any>>(globStr: `${any}
|
|
244
|
+
glob<T extends Record<string, any>>(globStr: `${any}${MarkdowFileExtension}`): Promise<MarkdownInstance<T>[]>;
|
|
241
245
|
glob<T extends Record<string, any>>(globStr: `${any}.mdx`): Promise<MDXInstance<T>[]>;
|
|
242
246
|
glob<T extends Record<string, any>>(globStr: string): Promise<T[]>;
|
|
243
247
|
/**
|
|
@@ -675,7 +679,7 @@ export interface AstroUserConfig {
|
|
|
675
679
|
* Pass [remark plugins](https://github.com/remarkjs/remark) to customize how your Markdown is built. You can import and apply the plugin function (recommended), or pass the plugin name as a string.
|
|
676
680
|
*
|
|
677
681
|
* :::caution
|
|
678
|
-
* Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the `extendDefaultPlugins` flag.
|
|
682
|
+
* Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the [`extendDefaultPlugins`](#markdownextenddefaultplugins) flag.
|
|
679
683
|
* :::
|
|
680
684
|
*
|
|
681
685
|
* ```js
|
|
@@ -696,7 +700,7 @@ export interface AstroUserConfig {
|
|
|
696
700
|
* Pass [rehype plugins](https://github.com/remarkjs/remark-rehype) to customize how your Markdown's output HTML is processed. You can import and apply the plugin function (recommended), or pass the plugin name as a string.
|
|
697
701
|
*
|
|
698
702
|
* :::caution
|
|
699
|
-
* Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the `extendDefaultPlugins` flag.
|
|
703
|
+
* Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the [`extendDefaultPlugins`](#markdownextenddefaultplugins) flag.
|
|
700
704
|
* :::
|
|
701
705
|
*
|
|
702
706
|
* ```js
|
|
@@ -816,7 +820,7 @@ export interface AstroUserConfig {
|
|
|
816
820
|
* @default `false`
|
|
817
821
|
* @version 1.0.0-rc.1
|
|
818
822
|
* @description
|
|
819
|
-
* Enable Astro's pre-v1.0 support for components and JSX expressions in `.md` Markdown files.
|
|
823
|
+
* Enable Astro's pre-v1.0 support for components and JSX expressions in `.md` (and alternative extensions for markdown files like ".markdown") Markdown files.
|
|
820
824
|
* In Astro `1.0.0-rc`, this original behavior was removed as the default, in favor of our new [MDX integration](/en/guides/integrations-guide/mdx/).
|
|
821
825
|
*
|
|
822
826
|
* To enable this behavior, set `legacy.astroFlavoredMarkdown` to `true` in your [`astro.config.mjs` configuration file](/en/guides/configuring-astro/#the-astro-config-file).
|
package/dist/cli/index.js
CHANGED
|
@@ -44,6 +44,8 @@ function printAstroHelp() {
|
|
|
44
44
|
"Global Flags": [
|
|
45
45
|
["--config <path>", "Specify your config file."],
|
|
46
46
|
["--root <path>", "Specify your project root folder."],
|
|
47
|
+
["--site <url>", "Specify your project site."],
|
|
48
|
+
["--base <pathname>", "Specify your project base."],
|
|
47
49
|
["--verbose", "Enable verbose logging."],
|
|
48
50
|
["--silent", "Disable all logging."],
|
|
49
51
|
["--version", "Show the version number and exit."],
|
|
@@ -72,6 +72,7 @@ function resolveFlags(flags) {
|
|
|
72
72
|
return {
|
|
73
73
|
root: typeof flags.root === "string" ? flags.root : void 0,
|
|
74
74
|
site: typeof flags.site === "string" ? flags.site : void 0,
|
|
75
|
+
base: typeof flags.base === "string" ? flags.base : void 0,
|
|
75
76
|
port: typeof flags.port === "number" ? flags.port : void 0,
|
|
76
77
|
config: typeof flags.config === "string" ? flags.config : void 0,
|
|
77
78
|
host: typeof flags.host === "string" || typeof flags.host === "boolean" ? flags.host : void 0,
|
|
@@ -86,6 +87,8 @@ function mergeCLIFlags(astroConfig, flags, cmd) {
|
|
|
86
87
|
astroConfig.markdown = astroConfig.markdown || {};
|
|
87
88
|
if (typeof flags.site === "string")
|
|
88
89
|
astroConfig.site = flags.site;
|
|
90
|
+
if (typeof flags.base === "string")
|
|
91
|
+
astroConfig.base = flags.base;
|
|
89
92
|
if (typeof flags.drafts === "boolean")
|
|
90
93
|
astroConfig.markdown.drafts = flags.drafts;
|
|
91
94
|
if (typeof flags.port === "number") {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./../constants.js";
|
|
1
2
|
import jsxRenderer from "../../jsx/renderer.js";
|
|
2
3
|
import { loadTSConfig } from "./tsconfig.js";
|
|
3
4
|
function createSettings(config, cwd) {
|
|
@@ -8,7 +9,7 @@ function createSettings(config, cwd) {
|
|
|
8
9
|
tsConfigPath: tsconfig == null ? void 0 : tsconfig.path,
|
|
9
10
|
adapter: void 0,
|
|
10
11
|
injectedRoutes: [],
|
|
11
|
-
pageExtensions: [".astro", ".
|
|
12
|
+
pageExtensions: [".astro", ".html", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
|
|
12
13
|
renderers: [jsxRenderer],
|
|
13
14
|
scripts: [],
|
|
14
15
|
watchFiles: (tsconfig == null ? void 0 : tsconfig.exists) ? [tsconfig.path, ...tsconfig.extendedPaths] : []
|
package/dist/core/constants.d.ts
CHANGED
package/dist/core/constants.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
const ASTRO_VERSION = "1.
|
|
1
|
+
const ASTRO_VERSION = "1.6.0";
|
|
2
|
+
const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
|
|
3
|
+
".markdown",
|
|
4
|
+
".mdown",
|
|
5
|
+
".mkdn",
|
|
6
|
+
".mkd",
|
|
7
|
+
".mdwn",
|
|
8
|
+
".md"
|
|
9
|
+
];
|
|
2
10
|
export {
|
|
3
|
-
ASTRO_VERSION
|
|
11
|
+
ASTRO_VERSION,
|
|
12
|
+
SUPPORTED_MARKDOWN_FILE_EXTENSIONS
|
|
4
13
|
};
|
package/dist/core/create-vite.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import { createRequire } from "module";
|
|
3
|
-
import path from "path";
|
|
4
1
|
import { fileURLToPath } from "url";
|
|
5
2
|
import * as vite from "vite";
|
|
3
|
+
import { crawlFrameworkPkgs } from "vitefu";
|
|
6
4
|
import astroPostprocessVitePlugin from "../vite-plugin-astro-postprocess/index.js";
|
|
7
5
|
import astroViteServerPlugin from "../vite-plugin-astro-server/index.js";
|
|
8
6
|
import astroVitePlugin from "../vite-plugin-astro/index.js";
|
|
@@ -35,7 +33,22 @@ function getSsrNoExternalDeps(projectRoot) {
|
|
|
35
33
|
return noExternalDeps;
|
|
36
34
|
}
|
|
37
35
|
async function createVite(commandConfig, { settings, logging, mode }) {
|
|
38
|
-
const
|
|
36
|
+
const astroPkgsConfig = await crawlFrameworkPkgs({
|
|
37
|
+
root: fileURLToPath(settings.config.root),
|
|
38
|
+
isBuild: mode === "build",
|
|
39
|
+
isFrameworkPkgByJson(pkgJson) {
|
|
40
|
+
var _a, _b, _c, _d;
|
|
41
|
+
return ((_a = pkgJson.peerDependencies) == null ? void 0 : _a.astro) || ((_b = pkgJson.dependencies) == null ? void 0 : _b.astro) || ((_c = pkgJson.keywords) == null ? void 0 : _c.includes("astro")) || ((_d = pkgJson.keywords) == null ? void 0 : _d.includes("astro-component")) || /^(@[^\/]+\/)?astro\-/.test(pkgJson.name);
|
|
42
|
+
},
|
|
43
|
+
isFrameworkPkgByName(pkgName) {
|
|
44
|
+
const isNotAstroPkg = isCommonNotAstro(pkgName);
|
|
45
|
+
if (isNotAstroPkg) {
|
|
46
|
+
return false;
|
|
47
|
+
} else {
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
39
52
|
const commonConfig = {
|
|
40
53
|
cacheDir: fileURLToPath(new URL("./node_modules/.vite/", settings.config.root)),
|
|
41
54
|
clearScreen: false,
|
|
@@ -88,8 +101,11 @@ async function createVite(commandConfig, { settings, logging, mode }) {
|
|
|
88
101
|
conditions: ["astro"]
|
|
89
102
|
},
|
|
90
103
|
ssr: {
|
|
91
|
-
noExternal: [
|
|
92
|
-
|
|
104
|
+
noExternal: [
|
|
105
|
+
...getSsrNoExternalDeps(settings.config.root),
|
|
106
|
+
...astroPkgsConfig.ssr.noExternal
|
|
107
|
+
],
|
|
108
|
+
external: [...mode === "dev" ? ["shiki"] : [], ...astroPkgsConfig.ssr.external]
|
|
93
109
|
}
|
|
94
110
|
};
|
|
95
111
|
let result = commonConfig;
|
|
@@ -118,84 +134,6 @@ function sortPlugins(pluginOptions) {
|
|
|
118
134
|
pluginOptions.splice(mdxPluginIndex, 1);
|
|
119
135
|
pluginOptions.splice(jsxPluginIndex, 0, mdxPlugin);
|
|
120
136
|
}
|
|
121
|
-
async function getAstroPackages(settings) {
|
|
122
|
-
const { astroPackages } = new DependencyWalker(settings.config.root);
|
|
123
|
-
return astroPackages;
|
|
124
|
-
}
|
|
125
|
-
class DependencyWalker {
|
|
126
|
-
constructor(root) {
|
|
127
|
-
this.astroDeps = /* @__PURE__ */ new Set();
|
|
128
|
-
this.nonAstroDeps = /* @__PURE__ */ new Set();
|
|
129
|
-
const pkgUrl = new URL("./package.json", root);
|
|
130
|
-
this.require = createRequire(pkgUrl);
|
|
131
|
-
const pkgPath = fileURLToPath(pkgUrl);
|
|
132
|
-
if (!fs.existsSync(pkgPath))
|
|
133
|
-
return;
|
|
134
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
135
|
-
const deps = [
|
|
136
|
-
...Object.keys(pkg.dependencies || {}),
|
|
137
|
-
...Object.keys(pkg.devDependencies || {})
|
|
138
|
-
];
|
|
139
|
-
this.scanDependencies(deps);
|
|
140
|
-
}
|
|
141
|
-
get astroPackages() {
|
|
142
|
-
return Array.from(this.astroDeps);
|
|
143
|
-
}
|
|
144
|
-
seen(dep) {
|
|
145
|
-
return this.astroDeps.has(dep) || this.nonAstroDeps.has(dep);
|
|
146
|
-
}
|
|
147
|
-
readPkgJSON(dir) {
|
|
148
|
-
try {
|
|
149
|
-
const filePath = path.join(dir, "package.json");
|
|
150
|
-
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
151
|
-
} catch (e) {
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
resolvePkgJSON(dep) {
|
|
155
|
-
try {
|
|
156
|
-
const pkgJson = this.require(dep + "/package.json");
|
|
157
|
-
return pkgJson;
|
|
158
|
-
} catch (e) {
|
|
159
|
-
try {
|
|
160
|
-
let dir = path.dirname(this.require.resolve(dep));
|
|
161
|
-
while (dir) {
|
|
162
|
-
const pkgJSON = this.readPkgJSON(dir);
|
|
163
|
-
if (pkgJSON && pkgJSON.name === dep)
|
|
164
|
-
return pkgJSON;
|
|
165
|
-
const parentDir = path.dirname(dir);
|
|
166
|
-
if (parentDir === dir)
|
|
167
|
-
break;
|
|
168
|
-
dir = parentDir;
|
|
169
|
-
}
|
|
170
|
-
} catch {
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
scanDependencies(deps) {
|
|
175
|
-
const newDeps = [];
|
|
176
|
-
for (const dep of deps) {
|
|
177
|
-
if (isCommonNotAstro(dep)) {
|
|
178
|
-
this.nonAstroDeps.add(dep);
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
const pkgJson = this.resolvePkgJSON(dep);
|
|
182
|
-
if (!pkgJson) {
|
|
183
|
-
this.nonAstroDeps.add(dep);
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
const { dependencies = {}, peerDependencies = {}, keywords = [] } = pkgJson;
|
|
187
|
-
if (peerDependencies.astro || dependencies.astro || keywords.includes("astro") || keywords.includes("astro-component") || /^(@[^\/]+\/)?astro\-/.test(dep)) {
|
|
188
|
-
this.astroDeps.add(dep);
|
|
189
|
-
const unknownDependencies = Object.keys(dependencies).filter((d) => !this.seen(d));
|
|
190
|
-
newDeps.push(...unknownDependencies);
|
|
191
|
-
} else {
|
|
192
|
-
this.nonAstroDeps.add(dep);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (newDeps.length)
|
|
196
|
-
this.scanDependencies(newDeps);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
137
|
const COMMON_DEPENDENCIES_NOT_ASTRO = [
|
|
200
138
|
"autoprefixer",
|
|
201
139
|
"react",
|
package/dist/core/dev/index.js
CHANGED
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.
|
|
50
|
+
const version = "1.6.0";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -250,7 +250,7 @@ function printHelp({
|
|
|
250
250
|
message.push(
|
|
251
251
|
linebreak(),
|
|
252
252
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
253
|
-
`v${"1.
|
|
253
|
+
`v${"1.6.0"}`
|
|
254
254
|
)} ${headline}`
|
|
255
255
|
);
|
|
256
256
|
}
|
|
@@ -19,7 +19,9 @@ async function preview(_settings, { logging }) {
|
|
|
19
19
|
throw new Error(`[preview] No adapter found.`);
|
|
20
20
|
}
|
|
21
21
|
if (!settings.adapter.previewEntrypoint) {
|
|
22
|
-
throw new Error(
|
|
22
|
+
throw new Error(
|
|
23
|
+
`[preview] The ${settings.adapter.name} adapter does not support the preview command.`
|
|
24
|
+
);
|
|
23
25
|
}
|
|
24
26
|
const require2 = createRequire(settings.config.root);
|
|
25
27
|
const previewEntrypoint = require2.resolve(settings.adapter.previewEntrypoint);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import npath from "path";
|
|
2
|
+
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
|
|
2
3
|
import { unwrapId } from "../../util.js";
|
|
3
4
|
import { STYLE_EXTENSIONS } from "../util.js";
|
|
4
|
-
const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro",
|
|
5
|
+
const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS]);
|
|
5
6
|
const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
|
|
6
7
|
async function* crawlGraph(viteServer, _id, isRootFile, scanned = /* @__PURE__ */ new Set()) {
|
|
7
8
|
const id = unwrapId(_id);
|
|
@@ -3,6 +3,7 @@ import { createRequire } from "module";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import slash from "slash";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
|
+
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
|
|
6
7
|
import { warn } from "../../logger/core.js";
|
|
7
8
|
import { removeLeadingForwardSlash } from "../../path.js";
|
|
8
9
|
import { resolvePages } from "../../util.js";
|
|
@@ -135,7 +136,11 @@ function createRouteManifest({ settings, cwd }, logging) {
|
|
|
135
136
|
var _a;
|
|
136
137
|
const components = [];
|
|
137
138
|
const routes = [];
|
|
138
|
-
const validPageExtensions = /* @__PURE__ */ new Set([
|
|
139
|
+
const validPageExtensions = /* @__PURE__ */ new Set([
|
|
140
|
+
".astro",
|
|
141
|
+
...SUPPORTED_MARKDOWN_FILE_EXTENSIONS,
|
|
142
|
+
...settings.pageExtensions
|
|
143
|
+
]);
|
|
139
144
|
const validEndpointExtensions = /* @__PURE__ */ new Set([".js", ".ts"]);
|
|
140
145
|
function walk(dir, parentSegments, parentParams) {
|
|
141
146
|
let items = [];
|
package/dist/core/util.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro';
|
|
|
4
4
|
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
5
5
|
/** Cross-realm compatible URL */
|
|
6
6
|
export declare function isURL(value: unknown): value is URL;
|
|
7
|
+
/** Check if a file is a markdown file based on its extension */
|
|
8
|
+
export declare function isMarkdownFile(fileId: string, option: {
|
|
9
|
+
criteria: 'endsWith' | 'includes';
|
|
10
|
+
suffix?: string;
|
|
11
|
+
}): boolean;
|
|
7
12
|
/** Wraps an object in an array. If an array is passed, ignore it. */
|
|
8
13
|
export declare function arraify<T>(target: T | T[]): T[];
|
|
9
14
|
export declare function padMultilineString(source: string, n?: number): string;
|
package/dist/core/util.js
CHANGED
|
@@ -5,6 +5,7 @@ import resolve from "resolve";
|
|
|
5
5
|
import slash from "slash";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
7
|
import { normalizePath } from "vite";
|
|
8
|
+
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./constants.js";
|
|
8
9
|
import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
|
|
9
10
|
function isObject(value) {
|
|
10
11
|
return typeof value === "object" && value != null;
|
|
@@ -12,6 +13,21 @@ function isObject(value) {
|
|
|
12
13
|
function isURL(value) {
|
|
13
14
|
return Object.prototype.toString.call(value) === "[object URL]";
|
|
14
15
|
}
|
|
16
|
+
function isMarkdownFile(fileId, option) {
|
|
17
|
+
const _suffix = option.suffix ?? "";
|
|
18
|
+
if (option.criteria === "endsWith") {
|
|
19
|
+
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
|
|
20
|
+
if (fileId.endsWith(`${markdownFileExtension}${_suffix}`))
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
|
|
26
|
+
if (fileId.includes(`${markdownFileExtension}${_suffix}`))
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
15
31
|
function arraify(target) {
|
|
16
32
|
return Array.isArray(target) ? target : [target];
|
|
17
33
|
}
|
|
@@ -194,6 +210,7 @@ export {
|
|
|
194
210
|
emoji,
|
|
195
211
|
getLocalAddress,
|
|
196
212
|
getOutputFilename,
|
|
213
|
+
isMarkdownFile,
|
|
197
214
|
isModeServerWithNoAdapter,
|
|
198
215
|
isObject,
|
|
199
216
|
isPage,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { parse as babelParser } from "@babel/parser";
|
|
2
2
|
import { parse, print, types, visit } from "recast";
|
|
3
|
+
import { isMarkdownFile } from "../core/util.js";
|
|
3
4
|
const ASTRO_GLOB_REGEX = /Astro2?\s*\.\s*glob\s*\(/;
|
|
4
5
|
function astro(_opts) {
|
|
5
6
|
return {
|
|
6
7
|
name: "astro:postprocess",
|
|
7
8
|
async transform(code, id) {
|
|
8
|
-
if (!id.endsWith(".astro") && !id
|
|
9
|
+
if (!id.endsWith(".astro") && !isMarkdownFile(id, { criteria: "endsWith" })) {
|
|
9
10
|
return null;
|
|
10
11
|
}
|
|
11
12
|
if (!ASTRO_GLOB_REGEX.test(code)) {
|
|
@@ -4,7 +4,7 @@ import esbuild from "esbuild";
|
|
|
4
4
|
import * as colors from "kleur/colors";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import { error } from "../core/logger/core.js";
|
|
7
|
-
import { parseNpmName } from "../core/util.js";
|
|
7
|
+
import { isMarkdownFile, parseNpmName } from "../core/util.js";
|
|
8
8
|
import tagExportsPlugin from "./tag.js";
|
|
9
9
|
const JSX_EXTENSIONS = /* @__PURE__ */ new Set([".jsx", ".tsx", ".mdx"]);
|
|
10
10
|
const IMPORT_STATEMENTS = {
|
|
@@ -131,7 +131,7 @@ function jsx({ settings, logging }) {
|
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
133
|
const { mode } = viteConfig;
|
|
134
|
-
if (id.includes(".mdx") || id
|
|
134
|
+
if (id.includes(".mdx") || isMarkdownFile(id, { criteria: "includes" })) {
|
|
135
135
|
const { code: jsxCode2 } = await esbuild.transform(code, {
|
|
136
136
|
loader: getEsbuildLoader(path.extname(id)),
|
|
137
137
|
jsx: "preserve",
|
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { normalizePath } from "vite";
|
|
6
6
|
import { collectErrorMetadata } from "../core/errors.js";
|
|
7
7
|
import { warn } from "../core/logger/core.js";
|
|
8
|
+
import { isMarkdownFile } from "../core/util.js";
|
|
8
9
|
import { getFileInfo, safelyGetAstroData } from "../vite-plugin-utils/index.js";
|
|
9
10
|
function safeMatter(source, id) {
|
|
10
11
|
try {
|
|
@@ -22,7 +23,7 @@ function markdown({ settings, logging }) {
|
|
|
22
23
|
enforce: "pre",
|
|
23
24
|
name: "astro:markdown",
|
|
24
25
|
async load(id) {
|
|
25
|
-
if (id
|
|
26
|
+
if (isMarkdownFile(id, { criteria: "endsWith" })) {
|
|
26
27
|
const { fileId, fileUrl } = getFileInfo(id, settings.config);
|
|
27
28
|
const rawFile = await fs.promises.readFile(fileId, "utf-8");
|
|
28
29
|
const raw = safeMatter(rawFile, id);
|
|
@@ -43,7 +44,7 @@ function markdown({ settings, logging }) {
|
|
|
43
44
|
warn(
|
|
44
45
|
logging,
|
|
45
46
|
"markdown",
|
|
46
|
-
`[${id}] Astro now supports MDX! Support for components in ".md" files using the "setup" frontmatter is no longer enabled by default. Migrate this file to MDX or add the "legacy.astroFlavoredMarkdown" config flag to re-enable support.`
|
|
47
|
+
`[${id}] Astro now supports MDX! Support for components in ".md" (or alternative extensions like ".markdown") files using the "setup" frontmatter is no longer enabled by default. Migrate this file to MDX or add the "legacy.astroFlavoredMarkdown" config flag to re-enable support.`
|
|
47
48
|
);
|
|
48
49
|
}
|
|
49
50
|
const code = escapeViteEnvReferences(`
|
|
@@ -7,6 +7,7 @@ import { fileURLToPath } from "url";
|
|
|
7
7
|
import { pagesVirtualModuleId } from "../core/app/index.js";
|
|
8
8
|
import { cachedCompilation } from "../core/compile/index.js";
|
|
9
9
|
import { collectErrorMetadata } from "../core/errors.js";
|
|
10
|
+
import { isMarkdownFile } from "../core/util.js";
|
|
10
11
|
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
|
11
12
|
import {
|
|
12
13
|
createTransformStyles,
|
|
@@ -57,11 +58,11 @@ function markdown({ settings }) {
|
|
|
57
58
|
styleTransformer.viteDevServer = server;
|
|
58
59
|
},
|
|
59
60
|
async resolveId(id, importer, options) {
|
|
60
|
-
if (id
|
|
61
|
+
if (isMarkdownFile(id, { criteria: "endsWith", suffix: MARKDOWN_CONTENT_FLAG })) {
|
|
61
62
|
const resolvedId = await this.resolve(id, importer, { skipSelf: true, ...options });
|
|
62
63
|
return resolvedId == null ? void 0 : resolvedId.id.replace(MARKDOWN_CONTENT_FLAG, "");
|
|
63
64
|
}
|
|
64
|
-
if (id
|
|
65
|
+
if (isMarkdownFile(id, { criteria: "endsWith" }) && !isRootImport(importer)) {
|
|
65
66
|
const resolvedId = await this.resolve(id, importer, { skipSelf: true, ...options });
|
|
66
67
|
if (resolvedId) {
|
|
67
68
|
return resolvedId.id + MARKDOWN_IMPORT_FLAG;
|
|
@@ -70,7 +71,7 @@ function markdown({ settings }) {
|
|
|
70
71
|
return void 0;
|
|
71
72
|
},
|
|
72
73
|
async load(id, opts) {
|
|
73
|
-
if (id
|
|
74
|
+
if (isMarkdownFile(id, { criteria: "endsWith", suffix: MARKDOWN_IMPORT_FLAG })) {
|
|
74
75
|
const { fileId, fileUrl } = getFileInfo(id, config);
|
|
75
76
|
const source = await fs.promises.readFile(fileId, "utf8");
|
|
76
77
|
const { data: frontmatter, content: rawContent } = safeMatter(source, fileId);
|
|
@@ -105,7 +106,7 @@ function markdown({ settings }) {
|
|
|
105
106
|
map: null
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
|
-
if (id
|
|
109
|
+
if (isMarkdownFile(id, { criteria: "endsWith" })) {
|
|
109
110
|
const filename = normalizeFilename(id);
|
|
110
111
|
const source = await fs.promises.readFile(filename, "utf8");
|
|
111
112
|
const renderOpts = config.markdown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "withastro",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"default": "./astro.js"
|
|
30
30
|
},
|
|
31
31
|
"./env": "./env.d.ts",
|
|
32
|
+
"./types": "./types.d.ts",
|
|
32
33
|
"./client": "./client.d.ts",
|
|
33
34
|
"./client-base": "./client-base.d.ts",
|
|
34
35
|
"./import-meta": "./import-meta.d.ts",
|
|
@@ -144,6 +145,7 @@
|
|
|
144
145
|
"unist-util-visit": "^4.1.0",
|
|
145
146
|
"vfile": "^5.3.2",
|
|
146
147
|
"vite": "~3.1.3",
|
|
148
|
+
"vitefu": "^0.1.0",
|
|
147
149
|
"yargs-parser": "^21.0.1",
|
|
148
150
|
"zod": "^3.17.3"
|
|
149
151
|
},
|