astro 2.2.3 → 2.3.1
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/dist/assets/consts.d.ts +3 -2
- package/dist/assets/consts.js +4 -1
- package/dist/assets/services/service.js +3 -3
- package/dist/assets/types.d.ts +1 -1
- package/dist/content/runtime-assets.d.ts +1 -1
- package/dist/content/runtime-assets.js +1 -1
- package/dist/content/types-generator.js +6 -1
- package/dist/content/utils.d.ts +1 -1
- package/dist/content/utils.js +6 -2
- package/dist/content/vite-plugin-content-imports.js +6 -1
- package/dist/core/app/index.js +3 -2
- package/dist/core/app/types.d.ts +1 -0
- package/dist/core/build/generate.js +2 -2
- package/dist/core/build/plugins/plugin-ssr.js +2 -1
- package/dist/core/build/static-build.js +4 -1
- package/dist/core/config/schema.d.ts +5 -5
- package/dist/core/config/vite-load.js +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/core.js +1 -1
- package/dist/core/sync/index.js +1 -1
- package/dist/core/util.js +5 -1
- package/dist/vite-plugin-config-alias/index.d.ts +2 -7
- package/dist/vite-plugin-config-alias/index.js +59 -34
- package/package.json +6 -6
package/dist/assets/consts.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export declare const VIRTUAL_MODULE_ID = "astro:assets";
|
|
2
2
|
export declare const VIRTUAL_SERVICE_ID = "virtual:image-service";
|
|
3
|
+
export declare const VALID_INPUT_FORMATS: readonly ["jpeg", "jpg", "png", "tiff", "webp", "gif", "svg"];
|
|
3
4
|
/**
|
|
4
5
|
* Valid formats for optimizations in our base services.
|
|
5
|
-
* Certain formats can be imported (namely SVGs) but not
|
|
6
|
+
* Certain formats can be imported (namely SVGs) but not processed, so they are excluded from this list.
|
|
6
7
|
*/
|
|
7
|
-
export declare const
|
|
8
|
+
export declare const VALID_OPTIMIZABLE_FORMATS: readonly ["jpeg", "jpg", "png", "tiff", "webp", "gif"];
|
|
8
9
|
export declare const VALID_OUTPUT_FORMATS: readonly ["avif", "png", "webp", "jpeg", "jpg"];
|
package/dist/assets/consts.js
CHANGED
|
@@ -14,11 +14,14 @@ const VALID_INPUT_FORMATS = [
|
|
|
14
14
|
"png",
|
|
15
15
|
"tiff",
|
|
16
16
|
"webp",
|
|
17
|
-
"gif"
|
|
17
|
+
"gif",
|
|
18
|
+
"svg"
|
|
18
19
|
];
|
|
20
|
+
const VALID_OPTIMIZABLE_FORMATS = ["jpeg", "jpg", "png", "tiff", "webp", "gif"];
|
|
19
21
|
const VALID_OUTPUT_FORMATS = ["avif", "png", "webp", "jpeg", "jpg"];
|
|
20
22
|
export {
|
|
21
23
|
VALID_INPUT_FORMATS,
|
|
24
|
+
VALID_OPTIMIZABLE_FORMATS,
|
|
22
25
|
VALID_OUTPUT_FORMATS,
|
|
23
26
|
VIRTUAL_MODULE_ID,
|
|
24
27
|
VIRTUAL_SERVICE_ID
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { VALID_OPTIMIZABLE_FORMATS } from "../consts.js";
|
|
3
3
|
import { isESMImportedImage } from "../internal.js";
|
|
4
4
|
function isLocalService(service) {
|
|
5
5
|
if (!service) {
|
|
@@ -38,13 +38,13 @@ const baseService = {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
} else {
|
|
41
|
-
if (!
|
|
41
|
+
if (!VALID_OPTIMIZABLE_FORMATS.includes(options.src.format)) {
|
|
42
42
|
throw new AstroError({
|
|
43
43
|
...AstroErrorData.UnsupportedImageFormat,
|
|
44
44
|
message: AstroErrorData.UnsupportedImageFormat.message(
|
|
45
45
|
options.src.format,
|
|
46
46
|
options.src.src,
|
|
47
|
-
|
|
47
|
+
VALID_OPTIMIZABLE_FORMATS
|
|
48
48
|
)
|
|
49
49
|
});
|
|
50
50
|
}
|
package/dist/assets/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { VALID_INPUT_FORMATS, VALID_OUTPUT_FORMATS } from './consts.js';
|
|
|
2
2
|
import type { ImageService } from './services/service.js';
|
|
3
3
|
export type ImageQualityPreset = 'low' | 'mid' | 'high' | 'max' | (string & {});
|
|
4
4
|
export type ImageQuality = ImageQualityPreset | number;
|
|
5
|
-
export type ImageInputFormat = (typeof VALID_INPUT_FORMATS)[number]
|
|
5
|
+
export type ImageInputFormat = (typeof VALID_INPUT_FORMATS)[number];
|
|
6
6
|
export type ImageOutputFormat = (typeof VALID_OUTPUT_FORMATS)[number] | (string & {});
|
|
7
7
|
declare global {
|
|
8
8
|
var astroAsset: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PluginContext } from 'rollup';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import type { AstroSettings } from '../@types/astro.js';
|
|
4
|
-
export declare function createImage(settings: AstroSettings, pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata, string>;
|
|
4
|
+
export declare function createImage(settings: AstroSettings, pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata | z.ZodNever, string>;
|
|
@@ -80,7 +80,12 @@ async function createContentTypesGenerator({
|
|
|
80
80
|
}
|
|
81
81
|
return { shouldGenerateTypes: true };
|
|
82
82
|
}
|
|
83
|
-
const fileType = getEntryType(
|
|
83
|
+
const fileType = getEntryType(
|
|
84
|
+
fileURLToPath(event.entry),
|
|
85
|
+
contentPaths,
|
|
86
|
+
contentEntryExts,
|
|
87
|
+
settings.config.experimental.assets
|
|
88
|
+
);
|
|
84
89
|
if (fileType === "ignored") {
|
|
85
90
|
return { shouldGenerateTypes: false };
|
|
86
91
|
}
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ export declare function getEntryInfo(params: Pick<ContentPaths, 'contentDir'> &
|
|
|
63
63
|
entry: URL;
|
|
64
64
|
allowFilesOutsideCollection?: true;
|
|
65
65
|
}): EntryInfo;
|
|
66
|
-
export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'>, contentFileExts: string[]): 'content' | 'config' | 'ignored' | 'unsupported';
|
|
66
|
+
export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'>, contentFileExts: string[], experimentalAssets: boolean): 'content' | 'config' | 'ignored' | 'unsupported';
|
|
67
67
|
/**
|
|
68
68
|
* Match YAML exception handling from Astro core errors
|
|
69
69
|
* @see 'astro/src/core/errors.ts'
|
package/dist/content/utils.js
CHANGED
|
@@ -5,6 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
6
|
import { normalizePath } from "vite";
|
|
7
7
|
import { z } from "zod";
|
|
8
|
+
import { VALID_INPUT_FORMATS } from "../assets/consts.js";
|
|
8
9
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
9
10
|
import { CONTENT_TYPES_FILE } from "./consts.js";
|
|
10
11
|
import { errorMap } from "./error-map.js";
|
|
@@ -113,10 +114,10 @@ function getEntryInfo({
|
|
|
113
114
|
};
|
|
114
115
|
return res;
|
|
115
116
|
}
|
|
116
|
-
function getEntryType(entryPath, paths, contentFileExts) {
|
|
117
|
+
function getEntryType(entryPath, paths, contentFileExts, experimentalAssets) {
|
|
117
118
|
const { ext, base } = path.parse(entryPath);
|
|
118
119
|
const fileUrl = pathToFileURL(entryPath);
|
|
119
|
-
if (hasUnderscoreBelowContentDirectoryPath(fileUrl, paths.contentDir) || isOnIgnoreList(base)) {
|
|
120
|
+
if (hasUnderscoreBelowContentDirectoryPath(fileUrl, paths.contentDir) || isOnIgnoreList(base) || experimentalAssets && isImageAsset(ext)) {
|
|
120
121
|
return "ignored";
|
|
121
122
|
} else if (contentFileExts.includes(ext)) {
|
|
122
123
|
return "content";
|
|
@@ -129,6 +130,9 @@ function getEntryType(entryPath, paths, contentFileExts) {
|
|
|
129
130
|
function isOnIgnoreList(fileName) {
|
|
130
131
|
return [".DS_Store"].includes(fileName);
|
|
131
132
|
}
|
|
133
|
+
function isImageAsset(fileExt) {
|
|
134
|
+
return VALID_INPUT_FORMATS.includes(fileExt.slice(1));
|
|
135
|
+
}
|
|
132
136
|
function hasUnderscoreBelowContentDirectoryPath(fileUrl, contentDir) {
|
|
133
137
|
const parts = fileUrl.pathname.replace(contentDir.pathname, "").split("/");
|
|
134
138
|
for (const part of parts) {
|
|
@@ -68,7 +68,12 @@ function astroContentImportPlugin({
|
|
|
68
68
|
},
|
|
69
69
|
configureServer(viteServer) {
|
|
70
70
|
viteServer.watcher.on("all", async (event, entry) => {
|
|
71
|
-
if (CHOKIDAR_MODIFIED_EVENTS.includes(event) && getEntryType(
|
|
71
|
+
if (CHOKIDAR_MODIFIED_EVENTS.includes(event) && getEntryType(
|
|
72
|
+
entry,
|
|
73
|
+
contentPaths,
|
|
74
|
+
contentEntryExts,
|
|
75
|
+
settings.config.experimental.assets
|
|
76
|
+
) === "config") {
|
|
72
77
|
for (const modUrl of viteServer.moduleGraph.urlToModuleMap.keys()) {
|
|
73
78
|
if (isContentFlagImport(modUrl) || Boolean(getContentRendererByViteId(modUrl, settings))) {
|
|
74
79
|
const mod = await viteServer.moduleGraph.getModuleByUrl(modUrl);
|
package/dist/core/app/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { attachToResponse, getSetCookiesFromResponse } from "../cookies/index.js
|
|
|
3
3
|
import { call as callEndpoint } from "../endpoint/index.js";
|
|
4
4
|
import { consoleLogDestination } from "../logger/console.js";
|
|
5
5
|
import { error } from "../logger/core.js";
|
|
6
|
-
import {
|
|
6
|
+
import { removeTrailingForwardSlash } from "../path.js";
|
|
7
7
|
import {
|
|
8
8
|
createEnvironment,
|
|
9
9
|
createRenderContext,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "../render/index.js";
|
|
12
12
|
import { RouteCache } from "../render/route-cache.js";
|
|
13
13
|
import {
|
|
14
|
+
createAssetLink,
|
|
14
15
|
createLinkStylesheetElementSet,
|
|
15
16
|
createModuleScriptElement
|
|
16
17
|
} from "../render/ssr-element.js";
|
|
@@ -54,7 +55,7 @@ class App {
|
|
|
54
55
|
return bundlePath;
|
|
55
56
|
}
|
|
56
57
|
default: {
|
|
57
|
-
return
|
|
58
|
+
return createAssetLink(bundlePath, manifest.base, manifest.assetsPrefix);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
},
|
package/dist/core/app/types.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ async function generatePages(opts, internals) {
|
|
|
64
64
|
const ssr = opts.settings.config.output === "server";
|
|
65
65
|
const serverEntry = opts.buildConfig.serverEntry;
|
|
66
66
|
const outFolder = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir);
|
|
67
|
-
if (
|
|
67
|
+
if (ssr && !hasPrerenderedPages(internals))
|
|
68
68
|
return;
|
|
69
69
|
const verb = ssr ? "prerendering" : "generating";
|
|
70
70
|
info(opts.logging, null, `
|
|
@@ -72,7 +72,7 @@ ${bgGreen(black(` ${verb} static routes `))}`);
|
|
|
72
72
|
const ssrEntryURL = new URL("./" + serverEntry + `?time=${Date.now()}`, outFolder);
|
|
73
73
|
const ssrEntry = await import(ssrEntryURL.toString());
|
|
74
74
|
const builtPaths = /* @__PURE__ */ new Set();
|
|
75
|
-
if (
|
|
75
|
+
if (ssr) {
|
|
76
76
|
for (const pageData of eachPrerenderedPageData(internals)) {
|
|
77
77
|
await generatePage(opts, internals, pageData, ssrEntry, builtPaths);
|
|
78
78
|
}
|
|
@@ -19,7 +19,7 @@ function vitePluginSSR(internals, adapter) {
|
|
|
19
19
|
options(opts) {
|
|
20
20
|
return addRollupInput(opts, [virtualModuleId]);
|
|
21
21
|
},
|
|
22
|
-
resolveId(id
|
|
22
|
+
resolveId(id) {
|
|
23
23
|
if (id === virtualModuleId) {
|
|
24
24
|
return resolvedVirtualModuleId;
|
|
25
25
|
}
|
|
@@ -171,6 +171,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
171
171
|
routes,
|
|
172
172
|
site: settings.config.site,
|
|
173
173
|
base: settings.config.base,
|
|
174
|
+
assetsPrefix: settings.config.build.assetsPrefix,
|
|
174
175
|
markdown: settings.config.markdown,
|
|
175
176
|
pageMap: null,
|
|
176
177
|
componentMetadata: Array.from(internals.componentMetadata),
|
|
@@ -3,6 +3,7 @@ import * as eslexer from "es-module-lexer";
|
|
|
3
3
|
import glob from "fast-glob";
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import { bgGreen, bgMagenta, black, dim } from "kleur/colors";
|
|
6
|
+
import path from "path";
|
|
6
7
|
import { fileURLToPath } from "url";
|
|
7
8
|
import * as vite from "vite";
|
|
8
9
|
import {
|
|
@@ -292,11 +293,13 @@ async function ssrMoveAssets(opts) {
|
|
|
292
293
|
cwd: fileURLToPath(serverAssets)
|
|
293
294
|
});
|
|
294
295
|
if (files.length > 0) {
|
|
295
|
-
await fs.promises.mkdir(clientAssets, { recursive: true });
|
|
296
296
|
await Promise.all(
|
|
297
297
|
files.map(async (filename) => {
|
|
298
298
|
const currentUrl = new URL(filename, appendForwardSlash(serverAssets.toString()));
|
|
299
299
|
const clientUrl = new URL(filename, appendForwardSlash(clientAssets.toString()));
|
|
300
|
+
const dir = new URL(path.parse(clientUrl.href).dir);
|
|
301
|
+
if (!fs.existsSync(dir))
|
|
302
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
300
303
|
return fs.promises.rename(currentUrl, clientUrl);
|
|
301
304
|
})
|
|
302
305
|
);
|
|
@@ -52,10 +52,10 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
52
52
|
serverEntry: string;
|
|
53
53
|
}, {
|
|
54
54
|
assets?: string | undefined;
|
|
55
|
+
assetsPrefix?: string | undefined;
|
|
55
56
|
server?: string | undefined;
|
|
56
57
|
format?: "file" | "directory" | undefined;
|
|
57
58
|
client?: string | undefined;
|
|
58
|
-
assetsPrefix?: string | undefined;
|
|
59
59
|
serverEntry?: string | undefined;
|
|
60
60
|
}>>>;
|
|
61
61
|
server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
@@ -227,10 +227,10 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
227
227
|
integrations?: unknown;
|
|
228
228
|
build?: {
|
|
229
229
|
assets?: string | undefined;
|
|
230
|
+
assetsPrefix?: string | undefined;
|
|
230
231
|
server?: string | undefined;
|
|
231
232
|
format?: "file" | "directory" | undefined;
|
|
232
233
|
client?: string | undefined;
|
|
233
|
-
assetsPrefix?: string | undefined;
|
|
234
234
|
serverEntry?: string | undefined;
|
|
235
235
|
} | undefined;
|
|
236
236
|
image?: {
|
|
@@ -354,10 +354,10 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
354
354
|
serverEntry: string;
|
|
355
355
|
}, {
|
|
356
356
|
assets?: string | undefined;
|
|
357
|
+
assetsPrefix?: string | undefined;
|
|
357
358
|
server?: string | undefined;
|
|
358
359
|
format?: "file" | "directory" | undefined;
|
|
359
360
|
client?: string | undefined;
|
|
360
|
-
assetsPrefix?: string | undefined;
|
|
361
361
|
serverEntry?: string | undefined;
|
|
362
362
|
}>>>;
|
|
363
363
|
server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
@@ -470,10 +470,10 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
470
470
|
integrations?: unknown;
|
|
471
471
|
build?: {
|
|
472
472
|
assets?: string | undefined;
|
|
473
|
+
assetsPrefix?: string | undefined;
|
|
473
474
|
server?: string | undefined;
|
|
474
475
|
format?: "file" | "directory" | undefined;
|
|
475
476
|
client?: string | undefined;
|
|
476
|
-
assetsPrefix?: string | undefined;
|
|
477
477
|
serverEntry?: string | undefined;
|
|
478
478
|
} | undefined;
|
|
479
479
|
image?: {
|
|
@@ -569,10 +569,10 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
569
569
|
integrations?: unknown;
|
|
570
570
|
build?: {
|
|
571
571
|
assets?: string | undefined;
|
|
572
|
+
assetsPrefix?: string | undefined;
|
|
572
573
|
server?: string | undefined;
|
|
573
574
|
format?: "file" | "directory" | undefined;
|
|
574
575
|
client?: string | undefined;
|
|
575
|
-
assetsPrefix?: string | undefined;
|
|
576
576
|
serverEntry?: string | undefined;
|
|
577
577
|
} | undefined;
|
|
578
578
|
image?: {
|
|
@@ -4,7 +4,7 @@ import loadFallbackPlugin from "../../vite-plugin-load-fallback/index.js";
|
|
|
4
4
|
async function createViteLoader(root, fs) {
|
|
5
5
|
const viteServer = await vite.createServer({
|
|
6
6
|
server: { middlewareMode: true, hmr: false },
|
|
7
|
-
optimizeDeps: {
|
|
7
|
+
optimizeDeps: { disabled: true },
|
|
8
8
|
clearScreen: false,
|
|
9
9
|
appType: "custom",
|
|
10
10
|
ssr: {
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -53,7 +53,7 @@ async function dev(settings, options) {
|
|
|
53
53
|
isRestart: options.isRestart
|
|
54
54
|
})
|
|
55
55
|
);
|
|
56
|
-
const currentVersion = "2.
|
|
56
|
+
const currentVersion = "2.3.1";
|
|
57
57
|
if (currentVersion.includes("-")) {
|
|
58
58
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
59
59
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
base,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "2.
|
|
50
|
+
const version = "2.3.1";
|
|
51
51
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
52
52
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
53
53
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -233,7 +233,7 @@ function printHelp({
|
|
|
233
233
|
message.push(
|
|
234
234
|
linebreak(),
|
|
235
235
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
236
|
-
`v${"2.
|
|
236
|
+
`v${"2.3.1"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
package/dist/core/render/core.js
CHANGED
|
@@ -14,7 +14,7 @@ async function getParamsAndProps(opts) {
|
|
|
14
14
|
let pageProps;
|
|
15
15
|
if (route && !route.pathname) {
|
|
16
16
|
if (route.params.length) {
|
|
17
|
-
const paramsMatch = route.pattern.exec(pathname);
|
|
17
|
+
const paramsMatch = route.pattern.exec(decodeURIComponent(pathname));
|
|
18
18
|
if (paramsMatch) {
|
|
19
19
|
params = getParams(route.params)(paramsMatch);
|
|
20
20
|
if (route.type === "endpoint" && mod.getStaticPaths) {
|
package/dist/core/sync/index.js
CHANGED
package/dist/core/util.js
CHANGED
|
@@ -121,7 +121,11 @@ function rootRelativePath(root, idOrUrl) {
|
|
|
121
121
|
} else {
|
|
122
122
|
id = idOrUrl;
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
const normalizedRoot = normalizePath(fileURLToPath(root));
|
|
125
|
+
if (id.startsWith(normalizedRoot)) {
|
|
126
|
+
id = id.slice(normalizedRoot.length);
|
|
127
|
+
}
|
|
128
|
+
return prependForwardSlash(id);
|
|
125
129
|
}
|
|
126
130
|
function emoji(char, fallback) {
|
|
127
131
|
return process.platform !== "win32" ? char : fallback;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
+
import { type Plugin as VitePlugin } from 'vite';
|
|
1
2
|
import type { AstroSettings } from '../@types/astro';
|
|
2
|
-
import type * as vite from 'vite';
|
|
3
|
-
/** Result of successfully parsed tsconfig.json or jsconfig.json. */
|
|
4
|
-
export declare interface Alias {
|
|
5
|
-
find: RegExp;
|
|
6
|
-
replacement: string;
|
|
7
|
-
}
|
|
8
3
|
/** Returns a Vite plugin used to alias paths from tsconfig.json and jsconfig.json. */
|
|
9
4
|
export default function configAliasVitePlugin({ settings, }: {
|
|
10
5
|
settings: AstroSettings;
|
|
11
|
-
}):
|
|
6
|
+
}): VitePlugin | null;
|
|
@@ -1,66 +1,91 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { normalizePath } from "vite";
|
|
3
3
|
const getConfigAlias = (settings) => {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
if (!config || !configPath)
|
|
4
|
+
const { tsConfig, tsConfigPath } = settings;
|
|
5
|
+
if (!tsConfig || !tsConfigPath || !tsConfig.compilerOptions)
|
|
7
6
|
return null;
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
7
|
+
const { baseUrl, paths } = tsConfig.compilerOptions;
|
|
8
|
+
if (!baseUrl || !paths)
|
|
10
9
|
return null;
|
|
11
|
-
const
|
|
12
|
-
path.posix.dirname(normalize(configPath).replace(/^\/?/, "/")),
|
|
13
|
-
normalize(compilerOptions.baseUrl)
|
|
14
|
-
);
|
|
10
|
+
const resolvedBaseUrl = path.resolve(path.dirname(tsConfigPath), baseUrl);
|
|
15
11
|
const aliases = [];
|
|
16
|
-
for (
|
|
17
|
-
Object(compilerOptions.paths)
|
|
18
|
-
)) {
|
|
19
|
-
values = [].concat(values);
|
|
12
|
+
for (const [alias, values] of Object.entries(paths)) {
|
|
20
13
|
const find = new RegExp(
|
|
21
14
|
`^${[...alias].map(
|
|
22
15
|
(segment) => segment === "*" ? "(.+)" : segment.replace(/[\\^$*+?.()|[\]{}]/, "\\$&")
|
|
23
16
|
).join("")}$`
|
|
24
17
|
);
|
|
25
18
|
let matchId = 0;
|
|
26
|
-
for (
|
|
27
|
-
const replacement = [...path.
|
|
19
|
+
for (const value of values) {
|
|
20
|
+
const replacement = [...normalizePath(path.resolve(resolvedBaseUrl, value))].map((segment) => segment === "*" ? `$${++matchId}` : segment === "$" ? "$$" : segment).join("");
|
|
28
21
|
aliases.push({ find, replacement });
|
|
29
22
|
}
|
|
30
23
|
}
|
|
31
24
|
aliases.push({
|
|
32
|
-
find: /^(
|
|
33
|
-
replacement: `${[...
|
|
25
|
+
find: /^(?!\.*\/|\w:)(.+)$/,
|
|
26
|
+
replacement: `${[...normalizePath(resolvedBaseUrl)].map((segment) => segment === "$" ? "$$" : segment).join("")}/$1`
|
|
34
27
|
});
|
|
35
28
|
return aliases;
|
|
36
29
|
};
|
|
37
30
|
function configAliasVitePlugin({
|
|
38
31
|
settings
|
|
39
32
|
}) {
|
|
40
|
-
const { config } = settings;
|
|
41
33
|
const configAlias = getConfigAlias(settings);
|
|
42
34
|
if (!configAlias)
|
|
43
|
-
return
|
|
44
|
-
|
|
35
|
+
return null;
|
|
36
|
+
const plugin = {
|
|
45
37
|
name: "astro:tsconfig-alias",
|
|
46
38
|
enforce: "pre",
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
configResolved(config) {
|
|
40
|
+
patchCreateResolver(config, plugin);
|
|
41
|
+
},
|
|
42
|
+
async resolveId(id, importer, options) {
|
|
43
|
+
if (isVirtualId(id))
|
|
44
|
+
return;
|
|
51
45
|
for (const alias of configAlias) {
|
|
52
|
-
if (alias.find.test(
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
if (resolvedAliasedId)
|
|
59
|
-
return resolvedAliasedId;
|
|
46
|
+
if (alias.find.test(id)) {
|
|
47
|
+
const updatedId = id.replace(alias.find, alias.replacement);
|
|
48
|
+
const resolved = await this.resolve(updatedId, importer, { skipSelf: true, ...options });
|
|
49
|
+
if (resolved)
|
|
50
|
+
return resolved;
|
|
60
51
|
}
|
|
61
52
|
}
|
|
62
53
|
}
|
|
63
54
|
};
|
|
55
|
+
return plugin;
|
|
56
|
+
}
|
|
57
|
+
function patchCreateResolver(config, prePlugin) {
|
|
58
|
+
const _createResolver = config.createResolver;
|
|
59
|
+
config.createResolver = function(...args1) {
|
|
60
|
+
const resolver = _createResolver.apply(config, args1);
|
|
61
|
+
return async function(...args2) {
|
|
62
|
+
const id = args2[0];
|
|
63
|
+
const importer = args2[1];
|
|
64
|
+
const ssr = args2[3];
|
|
65
|
+
if (importer == null ? void 0 : importer.includes("node_modules")) {
|
|
66
|
+
return resolver.apply(_createResolver, args2);
|
|
67
|
+
}
|
|
68
|
+
const fakePluginContext = {
|
|
69
|
+
resolve: (_id, _importer) => resolver(_id, _importer, false, ssr)
|
|
70
|
+
};
|
|
71
|
+
const fakeResolveIdOpts = {
|
|
72
|
+
assertions: {},
|
|
73
|
+
isEntry: false,
|
|
74
|
+
ssr
|
|
75
|
+
};
|
|
76
|
+
const resolved = await prePlugin.resolveId.apply(fakePluginContext, [
|
|
77
|
+
id,
|
|
78
|
+
importer,
|
|
79
|
+
fakeResolveIdOpts
|
|
80
|
+
]);
|
|
81
|
+
if (resolved)
|
|
82
|
+
return resolved;
|
|
83
|
+
return resolver.apply(_createResolver, args2);
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function isVirtualId(id) {
|
|
88
|
+
return id.includes("\0") || id.startsWith("virtual:") || id.startsWith("astro:");
|
|
64
89
|
}
|
|
65
90
|
export {
|
|
66
91
|
configAliasVitePlugin as default
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
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",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"dependencies": {
|
|
96
96
|
"@astrojs/compiler": "^1.3.1",
|
|
97
97
|
"@astrojs/language-server": "^0.28.3",
|
|
98
|
-
"@astrojs/markdown-remark": "^2.1.
|
|
98
|
+
"@astrojs/markdown-remark": "^2.1.4",
|
|
99
99
|
"@astrojs/telemetry": "^2.1.0",
|
|
100
100
|
"@astrojs/webapi": "^2.1.0",
|
|
101
101
|
"@babel/core": "^7.18.2",
|
|
@@ -142,10 +142,10 @@
|
|
|
142
142
|
"typescript": "*",
|
|
143
143
|
"unist-util-visit": "^4.1.0",
|
|
144
144
|
"vfile": "^5.3.2",
|
|
145
|
-
"vite": "^4.
|
|
145
|
+
"vite": "^4.3.1",
|
|
146
146
|
"vitefu": "^0.2.4",
|
|
147
147
|
"yargs-parser": "^21.0.1",
|
|
148
|
-
"zod": "^3.
|
|
148
|
+
"zod": "^3.20.6"
|
|
149
149
|
},
|
|
150
150
|
"devDependencies": {
|
|
151
151
|
"@playwright/test": "^1.29.2",
|
|
@@ -170,7 +170,6 @@
|
|
|
170
170
|
"@types/server-destroy": "^1.0.1",
|
|
171
171
|
"@types/sharp": "^0.31.1",
|
|
172
172
|
"@types/unist": "^2.0.6",
|
|
173
|
-
"astro-scripts": "0.0.14",
|
|
174
173
|
"chai": "^4.3.6",
|
|
175
174
|
"cheerio": "^1.0.0-rc.11",
|
|
176
175
|
"eol": "^0.9.1",
|
|
@@ -186,7 +185,8 @@
|
|
|
186
185
|
"sharp": "^0.31.3",
|
|
187
186
|
"srcset-parse": "^1.1.0",
|
|
188
187
|
"undici": "^5.20.0",
|
|
189
|
-
"unified": "^10.1.2"
|
|
188
|
+
"unified": "^10.1.2",
|
|
189
|
+
"astro-scripts": "0.0.14"
|
|
190
190
|
},
|
|
191
191
|
"peerDependencies": {
|
|
192
192
|
"sharp": "^0.31.3"
|