astro 5.16.13 → 5.16.15
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/components/Font.astro +4 -4
- package/dist/assets/fonts/config.d.ts +19 -236
- package/dist/assets/fonts/config.js +7 -23
- package/dist/assets/fonts/constants.d.ts +0 -1
- package/dist/assets/fonts/constants.js +0 -2
- package/dist/assets/fonts/core/collect-component-data.d.ts +9 -0
- package/dist/assets/fonts/core/collect-component-data.js +47 -0
- package/dist/assets/fonts/core/collect-font-assets-from-faces.d.ts +17 -0
- package/dist/assets/fonts/core/collect-font-assets-from-faces.js +71 -0
- package/dist/assets/fonts/core/collect-font-data.d.ts +4 -0
- package/dist/assets/fonts/core/collect-font-data.js +23 -0
- package/dist/assets/fonts/core/compute-font-families-assets.d.ts +20 -0
- package/dist/assets/fonts/core/compute-font-families-assets.js +67 -0
- package/dist/assets/fonts/core/filter-and-transform-font-faces.d.ts +20 -0
- package/dist/assets/fonts/core/filter-and-transform-font-faces.js +39 -0
- package/dist/assets/fonts/core/get-or-create-font-family-assets.d.ts +8 -0
- package/dist/assets/fonts/core/get-or-create-font-family-assets.js +34 -0
- package/dist/assets/fonts/core/optimize-fallbacks.d.ts +2 -3
- package/dist/assets/fonts/core/optimize-fallbacks.js +2 -3
- package/dist/assets/fonts/core/resolve-family.d.ts +6 -0
- package/dist/assets/fonts/core/resolve-family.js +23 -0
- package/dist/assets/fonts/definitions.d.ts +6 -28
- package/dist/assets/fonts/infra/build-font-file-id-generator.d.ts +13 -0
- package/dist/assets/fonts/infra/{build-url-proxy-hash-resolver.js → build-font-file-id-generator.js} +3 -6
- package/dist/assets/fonts/infra/build-url-resolver.d.ts +1 -1
- package/dist/assets/fonts/infra/build-url-resolver.js +4 -4
- package/dist/assets/fonts/infra/cached-font-fetcher.d.ts +1 -1
- package/dist/assets/fonts/infra/cached-font-fetcher.js +11 -3
- package/dist/assets/fonts/infra/capsize-font-metrics-resolver.d.ts +2 -2
- package/dist/assets/fonts/infra/dev-font-file-id-generator.d.ts +16 -0
- package/dist/assets/fonts/infra/{dev-url-proxy-hash-resolver.js → dev-font-file-id-generator.js} +8 -8
- package/dist/assets/fonts/infra/dev-url-resolver.d.ts +1 -1
- package/dist/assets/fonts/infra/dev-url-resolver.js +2 -2
- package/dist/assets/fonts/infra/fs-font-file-content-resolver.d.ts +10 -0
- package/dist/assets/fonts/infra/fs-font-file-content-resolver.js +21 -0
- package/dist/assets/fonts/infra/minifiable-css-renderer.d.ts +2 -1
- package/dist/assets/fonts/infra/{font-type-extractor.d.ts → node-font-type-extractor.d.ts} +1 -1
- package/dist/assets/fonts/infra/{font-type-extractor.js → node-font-type-extractor.js} +2 -2
- package/dist/assets/fonts/infra/unifont-font-resolver.d.ts +5 -3
- package/dist/assets/fonts/infra/unifont-font-resolver.js +14 -17
- package/dist/assets/fonts/providers/index.d.ts +6 -1
- package/dist/assets/fonts/providers/index.js +9 -1
- package/dist/assets/fonts/providers/local.d.ts +41 -8
- package/dist/assets/fonts/providers/local.js +65 -48
- package/dist/assets/fonts/runtime/client.d.ts +1 -1
- package/dist/assets/fonts/runtime/client.js +1 -1
- package/dist/assets/fonts/runtime/server.d.ts +1 -1
- package/dist/assets/fonts/runtime/server.js +1 -1
- package/dist/assets/fonts/types.d.ts +61 -110
- package/dist/assets/fonts/utils.d.ts +1 -7
- package/dist/assets/fonts/utils.js +1 -15
- package/dist/assets/fonts/vite-plugin-fonts.js +149 -141
- package/dist/cli/add/index.js +39 -0
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/config/index.d.ts +1 -2
- package/dist/content/content-layer.js +3 -3
- package/dist/core/config/schemas/base.d.ts +58 -429
- package/dist/core/config/schemas/base.js +2 -2
- package/dist/core/config/schemas/relative.d.ts +76 -541
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +1 -1
- package/dist/core/errors/errors-data.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/types/public/config.d.ts +3 -4
- package/package.json +5 -5
- package/dist/assets/fonts/core/normalize-remote-font-faces.d.ts +0 -7
- package/dist/assets/fonts/core/normalize-remote-font-faces.js +0 -41
- package/dist/assets/fonts/core/resolve-families.d.ts +0 -16
- package/dist/assets/fonts/core/resolve-families.js +0 -63
- package/dist/assets/fonts/infra/build-url-proxy-hash-resolver.d.ts +0 -15
- package/dist/assets/fonts/infra/data-collector.d.ts +0 -10
- package/dist/assets/fonts/infra/data-collector.js +0 -35
- package/dist/assets/fonts/infra/dev-url-proxy-hash-resolver.d.ts +0 -15
- package/dist/assets/fonts/infra/local-url-proxy-content-resolver.d.ts +0 -4
- package/dist/assets/fonts/infra/local-url-proxy-content-resolver.js +0 -14
- package/dist/assets/fonts/infra/remote-url-proxy-content-resolver.d.ts +0 -4
- package/dist/assets/fonts/infra/remote-url-proxy-content-resolver.js +0 -9
- package/dist/assets/fonts/infra/require-local-provider-url-resolver.d.ts +0 -9
- package/dist/assets/fonts/infra/require-local-provider-url-resolver.js +0 -30
- package/dist/assets/fonts/infra/url-proxy.d.ts +0 -16
- package/dist/assets/fonts/infra/url-proxy.js +0 -50
- package/dist/assets/fonts/orchestrate.d.ts +0 -42
- package/dist/assets/fonts/orchestrate.js +0 -173
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { isAbsolute } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
4
|
import colors from "piccolore";
|
|
6
5
|
import { getAlgorithm, shouldTrackCspHashes } from "../../core/csp/common.js";
|
|
7
6
|
import { generateCspDigest } from "../../core/encryption.js";
|
|
@@ -21,26 +20,28 @@ import {
|
|
|
21
20
|
RUNTIME_VIRTUAL_MODULE_ID,
|
|
22
21
|
VIRTUAL_MODULE_ID
|
|
23
22
|
} from "./constants.js";
|
|
24
|
-
import {
|
|
23
|
+
import { collectComponentData } from "./core/collect-component-data.js";
|
|
24
|
+
import { collectFontAssetsFromFaces } from "./core/collect-font-assets-from-faces.js";
|
|
25
|
+
import { collectFontData } from "./core/collect-font-data.js";
|
|
26
|
+
import { computeFontFamiliesAssets } from "./core/compute-font-families-assets.js";
|
|
27
|
+
import { filterAndTransformFontFaces } from "./core/filter-and-transform-font-faces.js";
|
|
28
|
+
import { getOrCreateFontFamilyAssets } from "./core/get-or-create-font-family-assets.js";
|
|
29
|
+
import { optimizeFallbacks } from "./core/optimize-fallbacks.js";
|
|
30
|
+
import { resolveFamily } from "./core/resolve-family.js";
|
|
31
|
+
import { BuildFontFileIdGenerator } from "./infra/build-font-file-id-generator.js";
|
|
25
32
|
import { BuildUrlResolver } from "./infra/build-url-resolver.js";
|
|
26
33
|
import { CachedFontFetcher } from "./infra/cached-font-fetcher.js";
|
|
27
34
|
import { CapsizeFontMetricsResolver } from "./infra/capsize-font-metrics-resolver.js";
|
|
28
|
-
import {
|
|
29
|
-
import { DevUrlProxyHashResolver } from "./infra/dev-url-proxy-hash-resolver.js";
|
|
35
|
+
import { DevFontFileIdGenerator } from "./infra/dev-font-file-id-generator.js";
|
|
30
36
|
import { DevUrlResolver } from "./infra/dev-url-resolver.js";
|
|
31
|
-
import {
|
|
32
|
-
import { FontaceFontFileReader } from "./infra/fontace-font-file-reader.js";
|
|
37
|
+
import { FsFontFileContentResolver } from "./infra/fs-font-file-content-resolver.js";
|
|
33
38
|
import { LevenshteinStringMatcher } from "./infra/levenshtein-string-matcher.js";
|
|
34
|
-
import { LocalUrlProxyContentResolver } from "./infra/local-url-proxy-content-resolver.js";
|
|
35
39
|
import { MinifiableCssRenderer } from "./infra/minifiable-css-renderer.js";
|
|
36
|
-
import {
|
|
37
|
-
import { RequireLocalProviderUrlResolver } from "./infra/require-local-provider-url-resolver.js";
|
|
40
|
+
import { NodeFontTypeExtractor } from "./infra/node-font-type-extractor.js";
|
|
38
41
|
import { RealSystemFallbacksProvider } from "./infra/system-fallbacks-provider.js";
|
|
39
42
|
import { UnifontFontResolver } from "./infra/unifont-font-resolver.js";
|
|
40
43
|
import { UnstorageFsStorage } from "./infra/unstorage-fs-storage.js";
|
|
41
|
-
import { RealUrlProxy } from "./infra/url-proxy.js";
|
|
42
44
|
import { XxhashHasher } from "./infra/xxhash-hasher.js";
|
|
43
|
-
import { orchestrate } from "./orchestrate.js";
|
|
44
45
|
function fontsPlugin({ settings, sync, logger }) {
|
|
45
46
|
if (!settings.config.experimental.fonts) {
|
|
46
47
|
return {
|
|
@@ -69,137 +70,134 @@ function fontsPlugin({ settings, sync, logger }) {
|
|
|
69
70
|
appendForwardSlash(joinPaths(settings.config.build.assets, ASSETS_DIR))
|
|
70
71
|
);
|
|
71
72
|
const baseUrl = joinPaths(settings.config.base, assetsDir);
|
|
72
|
-
let
|
|
73
|
-
let
|
|
74
|
-
let
|
|
73
|
+
let fontFileById = null;
|
|
74
|
+
let componentDataByCssVariable = null;
|
|
75
|
+
let fontDataByCssVariable = null;
|
|
75
76
|
let isBuild;
|
|
76
77
|
let fontFetcher = null;
|
|
77
78
|
let fontTypeExtractor = null;
|
|
78
79
|
const cleanup = () => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
componentDataByCssVariable = null;
|
|
81
|
+
fontDataByCssVariable = null;
|
|
82
|
+
fontFileById = null;
|
|
82
83
|
fontFetcher = null;
|
|
83
84
|
};
|
|
84
|
-
async function initialize({
|
|
85
|
-
cacheDir,
|
|
86
|
-
cssRenderer,
|
|
87
|
-
urlResolver,
|
|
88
|
-
createHashResolver
|
|
89
|
-
}) {
|
|
90
|
-
const { root } = settings.config;
|
|
91
|
-
const hasher = await XxhashHasher.create();
|
|
92
|
-
const pathsToWarn = /* @__PURE__ */ new Set();
|
|
93
|
-
const localProviderUrlResolver = new RequireLocalProviderUrlResolver({
|
|
94
|
-
root,
|
|
95
|
-
intercept: (path) => {
|
|
96
|
-
if (path.startsWith(fileURLToPath(settings.config.publicDir))) {
|
|
97
|
-
if (pathsToWarn.has(path)) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
pathsToWarn.add(path);
|
|
101
|
-
logger.warn(
|
|
102
|
-
"assets",
|
|
103
|
-
`Found a local font file ${JSON.stringify(path)} in the \`public/\` folder. To avoid duplicated files in the build output, move this file into \`src/\``
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
const storage = new UnstorageFsStorage({ base: cacheDir });
|
|
109
|
-
const systemFallbacksProvider = new RealSystemFallbacksProvider();
|
|
110
|
-
fontFetcher = new CachedFontFetcher({ storage, fetch, readFile });
|
|
111
|
-
const fontMetricsResolver = new CapsizeFontMetricsResolver({ fontFetcher, cssRenderer });
|
|
112
|
-
fontTypeExtractor = new RealFontTypeExtractor();
|
|
113
|
-
const fontFileReader = new FontaceFontFileReader();
|
|
114
|
-
const stringMatcher = new LevenshteinStringMatcher();
|
|
115
|
-
const res = await orchestrate({
|
|
116
|
-
families: settings.config.experimental.fonts,
|
|
117
|
-
hasher,
|
|
118
|
-
localProviderUrlResolver,
|
|
119
|
-
createFontResolver: async ({ families }) => await UnifontFontResolver.create({
|
|
120
|
-
families,
|
|
121
|
-
hasher,
|
|
122
|
-
storage
|
|
123
|
-
}),
|
|
124
|
-
cssRenderer,
|
|
125
|
-
systemFallbacksProvider,
|
|
126
|
-
fontMetricsResolver,
|
|
127
|
-
fontTypeExtractor,
|
|
128
|
-
fontFileReader,
|
|
129
|
-
logger,
|
|
130
|
-
createUrlProxy: ({ local, cssVariable, ...params }) => {
|
|
131
|
-
const dataCollector = new RealDataCollector(params);
|
|
132
|
-
const contentResolver = local ? new LocalUrlProxyContentResolver() : new RemoteUrlProxyContentResolver();
|
|
133
|
-
return new RealUrlProxy({
|
|
134
|
-
urlResolver,
|
|
135
|
-
hashResolver: createHashResolver({ hasher, contentResolver }),
|
|
136
|
-
dataCollector,
|
|
137
|
-
cssVariable
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
defaults: DEFAULTS,
|
|
141
|
-
bold: colors.bold,
|
|
142
|
-
stringMatcher
|
|
143
|
-
});
|
|
144
|
-
fontFileDataMap = res.fontFileDataMap;
|
|
145
|
-
internalConsumableMap = res.internalConsumableMap;
|
|
146
|
-
fontData = res.fontData;
|
|
147
|
-
if (shouldTrackCspHashes(settings.config.experimental.csp)) {
|
|
148
|
-
const algorithm = getAlgorithm(settings.config.experimental.csp);
|
|
149
|
-
for (const { css } of internalConsumableMap.values()) {
|
|
150
|
-
settings.injectedCsp.styleHashes.push(await generateCspDigest(css, algorithm));
|
|
151
|
-
}
|
|
152
|
-
for (const resource of urlResolver.cspResources) {
|
|
153
|
-
settings.injectedCsp.fontResources.add(resource);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
85
|
return {
|
|
158
86
|
name: "astro:fonts",
|
|
159
87
|
config(_, { command }) {
|
|
160
88
|
isBuild = command === "build";
|
|
161
89
|
},
|
|
162
90
|
async buildStart() {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
91
|
+
const { root } = settings.config;
|
|
92
|
+
const hasher = await XxhashHasher.create();
|
|
93
|
+
const storage = new UnstorageFsStorage({
|
|
94
|
+
// In dev, we cache fonts data in .astro so it can be easily inspected and cleared
|
|
95
|
+
base: new URL(CACHE_DIR, isBuild ? settings.config.cacheDir : settings.dotAstroDir)
|
|
96
|
+
});
|
|
97
|
+
const systemFallbacksProvider = new RealSystemFallbacksProvider();
|
|
98
|
+
fontFetcher = new CachedFontFetcher({ storage, fetch, readFile });
|
|
99
|
+
const cssRenderer = new MinifiableCssRenderer({ minify: isBuild });
|
|
100
|
+
const fontMetricsResolver = new CapsizeFontMetricsResolver({ fontFetcher, cssRenderer });
|
|
101
|
+
fontTypeExtractor = new NodeFontTypeExtractor();
|
|
102
|
+
const stringMatcher = new LevenshteinStringMatcher();
|
|
103
|
+
const urlResolver = isBuild ? new BuildUrlResolver({
|
|
104
|
+
base: baseUrl,
|
|
105
|
+
assetsPrefix: settings.config.build.assetsPrefix,
|
|
106
|
+
searchParams: settings.adapter?.client?.assetQueryParams ?? new URLSearchParams()
|
|
107
|
+
}) : new DevUrlResolver({
|
|
108
|
+
base: baseUrl,
|
|
109
|
+
searchParams: settings.adapter?.client?.assetQueryParams ?? new URLSearchParams()
|
|
110
|
+
});
|
|
111
|
+
const contentResolver = new FsFontFileContentResolver({
|
|
112
|
+
readFileSync: (path) => readFileSync(path, "utf-8")
|
|
113
|
+
});
|
|
114
|
+
const fontFileIdGenerator = isBuild ? new BuildFontFileIdGenerator({
|
|
115
|
+
hasher,
|
|
116
|
+
contentResolver
|
|
117
|
+
}) : new DevFontFileIdGenerator({
|
|
118
|
+
hasher,
|
|
119
|
+
contentResolver
|
|
120
|
+
});
|
|
121
|
+
const { bold } = colors;
|
|
122
|
+
const defaults = DEFAULTS;
|
|
123
|
+
const resolvedFamilies = settings.config.experimental.fonts.map(
|
|
124
|
+
(family) => resolveFamily({ family, hasher })
|
|
125
|
+
);
|
|
126
|
+
const { fontFamilyAssets, fontFileById: _fontFileById } = await computeFontFamiliesAssets({
|
|
127
|
+
resolvedFamilies,
|
|
128
|
+
defaults,
|
|
129
|
+
bold,
|
|
130
|
+
logger,
|
|
131
|
+
stringMatcher,
|
|
132
|
+
fontResolver: await UnifontFontResolver.create({
|
|
133
|
+
families: resolvedFamilies,
|
|
134
|
+
hasher,
|
|
135
|
+
storage,
|
|
136
|
+
root
|
|
137
|
+
}),
|
|
138
|
+
getOrCreateFontFamilyAssets: ({ family, fontFamilyAssetsByUniqueKey }) => getOrCreateFontFamilyAssets({
|
|
139
|
+
family,
|
|
140
|
+
fontFamilyAssetsByUniqueKey,
|
|
141
|
+
bold,
|
|
142
|
+
logger
|
|
143
|
+
}),
|
|
144
|
+
filterAndTransformFontFaces: ({ family, fonts }) => filterAndTransformFontFaces({
|
|
145
|
+
family,
|
|
146
|
+
fonts,
|
|
147
|
+
fontFileIdGenerator,
|
|
148
|
+
fontTypeExtractor,
|
|
149
|
+
urlResolver
|
|
150
|
+
}),
|
|
151
|
+
collectFontAssetsFromFaces: ({ collectedFontsIds, family, fontFilesIds, fonts }) => collectFontAssetsFromFaces({
|
|
152
|
+
collectedFontsIds,
|
|
153
|
+
family,
|
|
154
|
+
fontFilesIds,
|
|
155
|
+
fonts,
|
|
156
|
+
fontFileIdGenerator,
|
|
157
|
+
hasher,
|
|
158
|
+
defaults
|
|
159
|
+
})
|
|
160
|
+
});
|
|
161
|
+
fontDataByCssVariable = collectFontData(fontFamilyAssets);
|
|
162
|
+
componentDataByCssVariable = await collectComponentData({
|
|
163
|
+
cssRenderer,
|
|
164
|
+
defaults,
|
|
165
|
+
fontFamilyAssets,
|
|
166
|
+
optimizeFallbacks: ({ collectedFonts, fallbacks, family }) => optimizeFallbacks({
|
|
167
|
+
collectedFonts,
|
|
168
|
+
fallbacks,
|
|
169
|
+
family,
|
|
170
|
+
fontMetricsResolver,
|
|
171
|
+
systemFallbacksProvider
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
fontFileById = _fontFileById;
|
|
175
|
+
if (shouldTrackCspHashes(settings.config.experimental.csp)) {
|
|
176
|
+
const algorithm = getAlgorithm(settings.config.experimental.csp);
|
|
177
|
+
for (const { css } of componentDataByCssVariable.values()) {
|
|
178
|
+
settings.injectedCsp.styleHashes.push(await generateCspDigest(css, algorithm));
|
|
179
|
+
}
|
|
180
|
+
for (const resource of urlResolver.cspResources) {
|
|
181
|
+
settings.injectedCsp.fontResources.add(resource);
|
|
182
|
+
}
|
|
185
183
|
}
|
|
186
184
|
},
|
|
187
185
|
async configureServer(server) {
|
|
188
186
|
server.watcher.on("change", (path) => {
|
|
189
|
-
if (!
|
|
187
|
+
if (!fontFileById) {
|
|
190
188
|
return;
|
|
191
189
|
}
|
|
192
|
-
const localPaths = [...
|
|
190
|
+
const localPaths = [...fontFileById.values()].filter(({ url }) => isAbsolute(url)).map((v) => v.url);
|
|
193
191
|
if (localPaths.includes(path)) {
|
|
194
192
|
logger.info("assets", "Font file updated");
|
|
195
193
|
server.restart();
|
|
196
194
|
}
|
|
197
195
|
});
|
|
198
196
|
server.watcher.on("unlink", (path) => {
|
|
199
|
-
if (!
|
|
197
|
+
if (!fontFileById) {
|
|
200
198
|
return;
|
|
201
199
|
}
|
|
202
|
-
const localPaths = [...
|
|
200
|
+
const localPaths = [...fontFileById.values()].filter(({ url }) => isAbsolute(url)).map((v) => v.url);
|
|
203
201
|
if (localPaths.includes(path)) {
|
|
204
202
|
logger.warn(
|
|
205
203
|
"assets",
|
|
@@ -208,21 +206,28 @@ function fontsPlugin({ settings, sync, logger }) {
|
|
|
208
206
|
}
|
|
209
207
|
});
|
|
210
208
|
server.middlewares.use(assetsDir, async (req, res, next) => {
|
|
209
|
+
if (!fontFetcher || !fontTypeExtractor) {
|
|
210
|
+
logger.debug(
|
|
211
|
+
"assets",
|
|
212
|
+
"Fonts dependencies should be initialized by now, skipping dev middleware."
|
|
213
|
+
);
|
|
214
|
+
return next();
|
|
215
|
+
}
|
|
211
216
|
if (!req.url) {
|
|
212
217
|
return next();
|
|
213
218
|
}
|
|
214
|
-
const
|
|
215
|
-
const
|
|
216
|
-
if (!
|
|
219
|
+
const fontId = req.url.slice(1);
|
|
220
|
+
const fontData = fontFileById?.get(fontId);
|
|
221
|
+
if (!fontData) {
|
|
217
222
|
return next();
|
|
218
223
|
}
|
|
219
224
|
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
|
|
220
225
|
res.setHeader("Pragma", "no-cache");
|
|
221
226
|
res.setHeader("Expires", 0);
|
|
222
227
|
try {
|
|
223
|
-
const buffer = await fontFetcher.fetch({
|
|
224
|
-
res.setHeader("Content-Length", buffer.
|
|
225
|
-
res.setHeader("Content-Type", `font/${fontTypeExtractor.extract(
|
|
228
|
+
const buffer = await fontFetcher.fetch({ id: fontId, ...fontData });
|
|
229
|
+
res.setHeader("Content-Length", buffer.length);
|
|
230
|
+
res.setHeader("Content-Type", `font/${fontTypeExtractor.extract(fontId)}`);
|
|
226
231
|
res.end(buffer);
|
|
227
232
|
} catch (err) {
|
|
228
233
|
logger.error("assets", "Cannot download font file");
|
|
@@ -252,9 +257,9 @@ function fontsPlugin({ settings, sync, logger }) {
|
|
|
252
257
|
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
253
258
|
return {
|
|
254
259
|
code: `
|
|
255
|
-
export const
|
|
256
|
-
export const
|
|
257
|
-
export const bufferImports = {${[...
|
|
260
|
+
export const componentDataByCssVariable = new Map(${JSON.stringify(Array.from(componentDataByCssVariable?.entries() ?? []))});
|
|
261
|
+
export const fontDataByCssVariable = ${JSON.stringify(fontDataByCssVariable ?? {})}
|
|
262
|
+
export const bufferImports = {${[...fontFileById?.keys() ?? []].map((key) => `"${key}": () => import("${BUFFER_VIRTUAL_MODULE_ID_PREFIX}${key}")`).join(",")}};
|
|
258
263
|
`
|
|
259
264
|
};
|
|
260
265
|
}
|
|
@@ -269,15 +274,20 @@ function fontsPlugin({ settings, sync, logger }) {
|
|
|
269
274
|
};
|
|
270
275
|
}
|
|
271
276
|
if (id.startsWith(RESOLVED_BUFFER_VIRTUAL_MODULE_ID_PREFIX)) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
};
|
|
277
|
+
if (!fontFetcher) {
|
|
278
|
+
logger.debug(
|
|
279
|
+
"assets",
|
|
280
|
+
"Fonts dependencies should be initialized by now, skipping dev middleware."
|
|
281
|
+
);
|
|
282
|
+
return { code: `export default null;` };
|
|
283
|
+
}
|
|
284
|
+
const fontId = id.slice(RESOLVED_BUFFER_VIRTUAL_MODULE_ID_PREFIX.length);
|
|
285
|
+
const fontData = fontFileById?.get(fontId);
|
|
286
|
+
if (!fontData) {
|
|
287
|
+
return { code: `export default null;` };
|
|
278
288
|
}
|
|
279
289
|
try {
|
|
280
|
-
const buffer = await fontFetcher.fetch({
|
|
290
|
+
const buffer = await fontFetcher.fetch({ id: fontId, ...fontData });
|
|
281
291
|
const bytes = Array.from(buffer);
|
|
282
292
|
return {
|
|
283
293
|
code: `export default Uint8Array.from(${JSON.stringify(bytes)});`
|
|
@@ -290,9 +300,7 @@ function fontsPlugin({ settings, sync, logger }) {
|
|
|
290
300
|
formatErrorMessage(collectErrorMetadata(err), logger.level() === "debug")
|
|
291
301
|
);
|
|
292
302
|
}
|
|
293
|
-
return {
|
|
294
|
-
code: `export default null;`
|
|
295
|
-
};
|
|
303
|
+
return { code: `export default null;` };
|
|
296
304
|
}
|
|
297
305
|
}
|
|
298
306
|
},
|
|
@@ -309,16 +317,16 @@ function fontsPlugin({ settings, sync, logger }) {
|
|
|
309
317
|
} catch (cause) {
|
|
310
318
|
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause });
|
|
311
319
|
}
|
|
312
|
-
if (
|
|
320
|
+
if (fontFileById) {
|
|
313
321
|
logger.info(
|
|
314
322
|
"assets",
|
|
315
|
-
`Copying fonts (${
|
|
323
|
+
`Copying fonts (${fontFileById.size} file${fontFileById.size === 1 ? "" : "s"})...`
|
|
316
324
|
);
|
|
317
325
|
await Promise.all(
|
|
318
|
-
Array.from(
|
|
319
|
-
const data = await fontFetcher.fetch({
|
|
326
|
+
Array.from(fontFileById.entries()).map(async ([id, associatedData]) => {
|
|
327
|
+
const data = await fontFetcher.fetch({ id, ...associatedData });
|
|
320
328
|
try {
|
|
321
|
-
writeFileSync(new URL(
|
|
329
|
+
writeFileSync(new URL(id, fontsDir), data);
|
|
322
330
|
} catch (cause) {
|
|
323
331
|
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause });
|
|
324
332
|
}
|
package/dist/cli/add/index.js
CHANGED
|
@@ -289,6 +289,45 @@ async function add(names, { flags }) {
|
|
|
289
289
|
defaultConfigContent: STUBS.LIT_NPMRC
|
|
290
290
|
});
|
|
291
291
|
}
|
|
292
|
+
if (integrations.find((integration) => integration.id === "vercel")) {
|
|
293
|
+
const gitignorePath = new URL("./.gitignore", root);
|
|
294
|
+
const gitignoreEntry = ".vercel";
|
|
295
|
+
if (existsSync(gitignorePath)) {
|
|
296
|
+
const content = await fs.readFile(fileURLToPath(gitignorePath), { encoding: "utf-8" });
|
|
297
|
+
if (!content.includes(gitignoreEntry)) {
|
|
298
|
+
logger.info(
|
|
299
|
+
"SKIP_FORMAT",
|
|
300
|
+
`
|
|
301
|
+
${magenta(`Astro will add ${green(".vercel")} to ${green(".gitignore")}.`)}
|
|
302
|
+
`
|
|
303
|
+
);
|
|
304
|
+
if (await askToContinue({ flags, logger })) {
|
|
305
|
+
const newContent = content.endsWith("\n") ? `${content}${gitignoreEntry}
|
|
306
|
+
` : `${content}
|
|
307
|
+
${gitignoreEntry}
|
|
308
|
+
`;
|
|
309
|
+
await fs.writeFile(fileURLToPath(gitignorePath), newContent, { encoding: "utf-8" });
|
|
310
|
+
logger.debug("add", "Updated .gitignore with .vercel");
|
|
311
|
+
}
|
|
312
|
+
} else {
|
|
313
|
+
logger.debug("add", ".vercel already in .gitignore");
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
logger.info(
|
|
317
|
+
"SKIP_FORMAT",
|
|
318
|
+
`
|
|
319
|
+
${magenta(`Astro will create ${green(".gitignore")} with ${green(".vercel")}.`)}
|
|
320
|
+
`
|
|
321
|
+
);
|
|
322
|
+
if (await askToContinue({ flags, logger })) {
|
|
323
|
+
await fs.writeFile(fileURLToPath(gitignorePath), `${gitignoreEntry}
|
|
324
|
+
`, {
|
|
325
|
+
encoding: "utf-8"
|
|
326
|
+
});
|
|
327
|
+
logger.debug("add", "Created .gitignore with .vercel");
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
292
331
|
break;
|
|
293
332
|
}
|
|
294
333
|
case 2 /* cancelled */: {
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { UserConfig as ViteUserConfig, UserConfigFn as ViteUserConfigFn } from 'vite';
|
|
2
|
-
import type { LOCAL_PROVIDER_NAME } from '../assets/fonts/constants.js';
|
|
3
2
|
import type { FontProvider } from '../assets/fonts/types.js';
|
|
4
3
|
import type { AstroInlineConfig, AstroUserConfig, Locales, SessionDriverName } from '../types/public/config.js';
|
|
5
4
|
/**
|
|
6
5
|
* See the full Astro Configuration API Documentation
|
|
7
6
|
* https://astro.build/config
|
|
8
7
|
*/
|
|
9
|
-
export declare function defineConfig<const TLocales extends Locales = never, const TDriver extends SessionDriverName = never, const TFontProviders extends Array<FontProvider
|
|
8
|
+
export declare function defineConfig<const TLocales extends Locales = never, const TDriver extends SessionDriverName = never, const TFontProviders extends Array<FontProvider> = never>(config: AstroUserConfig<TLocales, TDriver, TFontProviders>): AstroUserConfig<TLocales, TDriver, TFontProviders>;
|
|
10
9
|
/**
|
|
11
10
|
* Use Astro to generate a fully resolved Vite config
|
|
12
11
|
*/
|
|
@@ -164,7 +164,7 @@ ${contentConfig.error.message}`);
|
|
|
164
164
|
logger.info("Content config changed");
|
|
165
165
|
shouldClear = true;
|
|
166
166
|
}
|
|
167
|
-
if (previousAstroVersion && previousAstroVersion !== "5.16.
|
|
167
|
+
if (previousAstroVersion && previousAstroVersion !== "5.16.15") {
|
|
168
168
|
logger.info("Astro version changed");
|
|
169
169
|
shouldClear = true;
|
|
170
170
|
}
|
|
@@ -172,8 +172,8 @@ ${contentConfig.error.message}`);
|
|
|
172
172
|
logger.info("Clearing content store");
|
|
173
173
|
this.#store.clearAll();
|
|
174
174
|
}
|
|
175
|
-
if ("5.16.
|
|
176
|
-
await this.#store.metaStore().set("astro-version", "5.16.
|
|
175
|
+
if ("5.16.15") {
|
|
176
|
+
await this.#store.metaStore().set("astro-version", "5.16.15");
|
|
177
177
|
}
|
|
178
178
|
if (currentConfigDigest) {
|
|
179
179
|
await this.#store.metaStore().set("content-config-digest", currentConfigDigest);
|