astro 1.1.7 → 1.1.8

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.
@@ -843,7 +843,7 @@ export interface MarkdownInstance<T extends Record<string, any>> {
843
843
  getHeaders(): void;
844
844
  default: AstroComponentFactory;
845
845
  }
846
- export interface MDXInstance<T> extends Omit<MarkdownInstance<T>, 'rawContent' | 'compiledContent'> {
846
+ export interface MDXInstance<T extends Record<string, any>> extends Omit<MarkdownInstance<T>, 'rawContent' | 'compiledContent'> {
847
847
  /** MDX does not support rawContent! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins */
848
848
  rawContent: never;
849
849
  /** MDX does not support compiledContent! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins */
@@ -860,7 +860,7 @@ export interface MarkdownLayoutProps<T extends Record<string, any>> {
860
860
  rawContent: MarkdownInstance<T>['rawContent'];
861
861
  compiledContent: MarkdownInstance<T>['compiledContent'];
862
862
  }
863
- export declare type MDXLayoutProps<T> = Omit<MarkdownLayoutProps<T>, 'rawContent' | 'compiledContent'>;
863
+ export declare type MDXLayoutProps<T extends Record<string, any>> = Omit<MarkdownLayoutProps<T>, 'rawContent' | 'compiledContent'>;
864
864
  export declare type GetHydrateCallback = () => Promise<() => void | Promise<void>>;
865
865
  /**
866
866
  * getStaticPaths() options
@@ -459,11 +459,11 @@ async function getInstallIntegrationsCommand({
459
459
  ).sort();
460
460
  switch (pm.name) {
461
461
  case "npm":
462
- return { pm: "npm", command: "install", flags: ["--save-dev"], dependencies };
462
+ return { pm: "npm", command: "install", flags: [], dependencies };
463
463
  case "yarn":
464
- return { pm: "yarn", command: "add", flags: ["--dev"], dependencies };
464
+ return { pm: "yarn", command: "add", flags: [], dependencies };
465
465
  case "pnpm":
466
- return { pm: "pnpm", command: "install", flags: ["--save-dev"], dependencies };
466
+ return { pm: "pnpm", command: "install", flags: [], dependencies };
467
467
  default:
468
468
  return null;
469
469
  }
@@ -478,7 +478,10 @@ async function tryToInstallIntegrations({
478
478
  if (installCommand === null) {
479
479
  return 0 /* none */;
480
480
  } else {
481
- const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command} ${installCommand.flags.join(" ")} ${cyan(installCommand.dependencies.join(" "))}`;
481
+ const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command}${[
482
+ "",
483
+ ...installCommand.flags
484
+ ].join(" ")} ${cyan(installCommand.dependencies.join(" "))}`;
482
485
  const message = `
483
486
  ${boxen(coloredOutput, {
484
487
  margin: 0.5,
@@ -1,8 +1,6 @@
1
1
  import type { TransformResult } from '@astrojs/compiler';
2
- import type { PluginContext } from 'rollup';
3
- import type { ViteDevServer } from 'vite';
4
- import type { AstroConfig } from '../@types/astro';
5
- import type { TransformStyleWithVite } from './styles';
2
+ import type { AstroConfig } from '../../@types/astro';
3
+ import type { TransformStyle } from './types';
6
4
  declare type CompileResult = TransformResult & {
7
5
  cssDeps: Set<string>;
8
6
  source: string;
@@ -12,10 +10,7 @@ export interface CompileProps {
12
10
  filename: string;
13
11
  moduleId: string;
14
12
  source: string;
15
- ssr: boolean;
16
- transformStyleWithVite: TransformStyleWithVite;
17
- viteDevServer?: ViteDevServer;
18
- pluginContext: PluginContext;
13
+ transformStyle: TransformStyle;
19
14
  }
20
15
  export declare function isCached(config: AstroConfig, filename: string): boolean;
21
16
  export declare function getCachedSource(config: AstroConfig, filename: string): string | null;
@@ -1,35 +1,19 @@
1
1
  import { transform } from "@astrojs/compiler";
2
- import { fileURLToPath } from "url";
3
- import { AstroErrorCodes } from "../core/errors.js";
4
- import { prependForwardSlash } from "../core/path.js";
5
- import { viteID } from "../core/util.js";
2
+ import { AstroErrorCodes } from "../errors.js";
3
+ import { prependForwardSlash } from "../path.js";
4
+ import { AggregateError, viteID } from "../util.js";
5
+ import { createStylePreprocessor } from "./style.js";
6
6
  const configCache = /* @__PURE__ */ new WeakMap();
7
- function getNormalizedID(filename) {
8
- try {
9
- const filenameURL = new URL(`file://${filename}`);
10
- return fileURLToPath(filenameURL);
11
- } catch (err) {
12
- return filename;
13
- }
14
- }
15
7
  async function compile({
16
8
  config,
17
9
  filename,
18
10
  moduleId,
19
11
  source,
20
- ssr,
21
- transformStyleWithVite,
22
- viteDevServer,
23
- pluginContext
12
+ transformStyle
24
13
  }) {
25
14
  var _a;
26
- const normalizedID = getNormalizedID(filename);
27
15
  let cssDeps = /* @__PURE__ */ new Set();
28
- let cssTransformError;
29
- if (!pluginContext.addWatchFile) {
30
- pluginContext.addWatchFile = () => {
31
- };
32
- }
16
+ let cssTransformErrors = [];
33
17
  const transformResult = await transform(source, {
34
18
  pathname: `/@fs${prependForwardSlash(moduleId)}`,
35
19
  projectRoot: config.root.toString(),
@@ -37,47 +21,30 @@ async function compile({
37
21
  sourcefile: filename,
38
22
  sourcemap: "both",
39
23
  internalURL: `/@fs${prependForwardSlash(
40
- viteID(new URL("../runtime/server/index.js", import.meta.url))
24
+ viteID(new URL("../../runtime/server/index.js", import.meta.url))
41
25
  )}`,
42
26
  experimentalStaticExtraction: true,
43
- preprocessStyle: async (value, attrs) => {
44
- const lang = `.${(attrs == null ? void 0 : attrs.lang) || "css"}`.toLowerCase();
45
- try {
46
- const result = await transformStyleWithVite.call(pluginContext, {
47
- id: normalizedID,
48
- source: value,
49
- lang,
50
- ssr,
51
- viteDevServer
52
- });
53
- if (!result)
54
- return null;
55
- for (const dep of result.deps) {
56
- cssDeps.add(dep);
57
- }
58
- let map;
59
- if (result.map) {
60
- if (typeof result.map === "string") {
61
- map = result.map;
62
- } else if (result.map.mappings) {
63
- map = result.map.toString();
64
- }
65
- }
66
- return { code: result.code, map };
67
- } catch (err) {
68
- cssTransformError = err;
69
- return null;
70
- }
71
- }
27
+ preprocessStyle: createStylePreprocessor(transformStyle, cssDeps, cssTransformErrors)
72
28
  }).catch((err) => {
73
29
  err.code = err.code || AstroErrorCodes.UnknownCompilerError;
74
30
  throw err;
75
31
  }).then((result) => {
76
- if (cssTransformError) {
77
- cssTransformError.code = cssTransformError.code || AstroErrorCodes.UnknownCompilerCSSError;
78
- throw cssTransformError;
32
+ switch (cssTransformErrors.length) {
33
+ case 0:
34
+ return result;
35
+ case 1: {
36
+ let error = cssTransformErrors[0];
37
+ if (!error.code) {
38
+ error.code = AstroErrorCodes.UnknownCompilerCSSError;
39
+ }
40
+ throw cssTransformErrors[0];
41
+ }
42
+ default: {
43
+ const aggregateError = new AggregateError(cssTransformErrors);
44
+ aggregateError.code = AstroErrorCodes.UnknownCompilerCSSError;
45
+ throw aggregateError;
46
+ }
79
47
  }
80
- return result;
81
48
  });
82
49
  const compileResult = Object.create(transformResult, {
83
50
  cssDeps: {
@@ -0,0 +1,3 @@
1
+ export type { CompileProps } from './compile';
2
+ export { cachedCompilation, getCachedSource, invalidateCompilation, isCached } from './compile.js';
3
+ export type { TransformStyle } from './types';
@@ -0,0 +1,7 @@
1
+ import { cachedCompilation, getCachedSource, invalidateCompilation, isCached } from "./compile.js";
2
+ export {
3
+ cachedCompilation,
4
+ getCachedSource,
5
+ invalidateCompilation,
6
+ isCached
7
+ };
@@ -0,0 +1,5 @@
1
+ import type { TransformOptions } from '@astrojs/compiler';
2
+ import type { TransformStyle } from './types';
3
+ declare type PreprocessStyle = TransformOptions['preprocessStyle'];
4
+ export declare function createStylePreprocessor(transformStyle: TransformStyle, cssDeps: Set<string>, errors: Error[]): PreprocessStyle;
5
+ export {};
@@ -0,0 +1,31 @@
1
+ function createStylePreprocessor(transformStyle, cssDeps, errors) {
2
+ const preprocessStyle = async (value, attrs) => {
3
+ const lang = `.${(attrs == null ? void 0 : attrs.lang) || "css"}`.toLowerCase();
4
+ try {
5
+ const result = await transformStyle(value, lang);
6
+ if (!result)
7
+ return null;
8
+ for (const dep of result.deps) {
9
+ cssDeps.add(dep);
10
+ }
11
+ let map;
12
+ if (result.map) {
13
+ if (typeof result.map === "string") {
14
+ map = result.map;
15
+ } else if (result.map.mappings) {
16
+ map = result.map.toString();
17
+ }
18
+ }
19
+ return { code: result.code, map };
20
+ } catch (err) {
21
+ errors.push(err);
22
+ return {
23
+ error: err + ""
24
+ };
25
+ }
26
+ };
27
+ return preprocessStyle;
28
+ }
29
+ export {
30
+ createStylePreprocessor
31
+ };
@@ -0,0 +1,7 @@
1
+ import type { SourceMap } from 'rollup';
2
+ export declare type TransformStyleResult = null | {
3
+ code: string;
4
+ map: SourceMap | null;
5
+ deps: Set<string>;
6
+ };
7
+ export declare type TransformStyle = (source: string, lang: string) => TransformStyleResult | Promise<TransformStyleResult>;
File without changes
@@ -46,7 +46,7 @@ async function dev(config, options) {
46
46
  https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
47
47
  })
48
48
  );
49
- const currentVersion = "1.1.7";
49
+ const currentVersion = "1.1.8";
50
50
  if (currentVersion.includes("-")) {
51
51
  warn(options.logging, null, msg.prerelease({ currentVersion }));
52
52
  }
@@ -46,7 +46,7 @@ function devStart({
46
46
  https,
47
47
  site
48
48
  }) {
49
- const version = "1.1.7";
49
+ const version = "1.1.8";
50
50
  const rootPath = site ? site.pathname : "/";
51
51
  const localPrefix = `${dim("\u2503")} Local `;
52
52
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -225,7 +225,7 @@ function printHelp({
225
225
  message.push(
226
226
  linebreak(),
227
227
  ` ${bgGreen(black(` ${commandName} `))} ${green(
228
- `v${"1.1.7"}`
228
+ `v${"1.1.8"}`
229
229
  )} ${headline}`
230
230
  );
231
231
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { ErrorPayload, ViteDevServer } from 'vite';
2
3
  import type { AstroConfig, RouteType } from '../@types/astro';
3
4
  export declare const ASTRO_VERSION: string;
@@ -46,3 +47,15 @@ export declare function getLocalAddress(serverAddress: string, host: string | bo
46
47
  * through a script tag or a dynamic import as-is.
47
48
  */
48
49
  export declare function resolveIdToUrl(viteServer: ViteDevServer, id: string): Promise<string>;
50
+ export declare const AggregateError: AggregateErrorConstructor | {
51
+ new (errors: Iterable<any>, message?: string | undefined): {
52
+ errors: Array<any>;
53
+ name: string;
54
+ message: string;
55
+ stack?: string | undefined;
56
+ cause?: Error | undefined;
57
+ };
58
+ captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
59
+ prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
60
+ stackTraceLimit: number;
61
+ };
package/dist/core/util.js CHANGED
@@ -5,7 +5,7 @@ import resolve from "resolve";
5
5
  import slash from "slash";
6
6
  import { fileURLToPath, pathToFileURL } from "url";
7
7
  import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
8
- const ASTRO_VERSION = "1.1.7";
8
+ const ASTRO_VERSION = "1.1.8";
9
9
  function isObject(value) {
10
10
  return typeof value === "object" && value != null;
11
11
  }
@@ -87,7 +87,7 @@ function resolveDependency(dep, projectRoot) {
87
87
  return pathToFileURL(resolved).toString();
88
88
  }
89
89
  function viteID(filePath) {
90
- return slash(fileURLToPath(filePath));
90
+ return slash(fileURLToPath(filePath) + filePath.search);
91
91
  }
92
92
  const VALID_ID_PREFIX = `/@id/`;
93
93
  function unwrapId(id) {
@@ -170,8 +170,16 @@ async function resolveIdToUrl(viteServer, id) {
170
170
  }
171
171
  return VALID_ID_PREFIX + result.id;
172
172
  }
173
+ const AggregateError = typeof globalThis.AggregateError !== "undefined" ? globalThis.AggregateError : class extends Error {
174
+ constructor(errors, message) {
175
+ super(message);
176
+ this.errors = [];
177
+ this.errors = Array.from(errors);
178
+ }
179
+ };
173
180
  export {
174
181
  ASTRO_VERSION,
182
+ AggregateError,
175
183
  VALID_ID_PREFIX,
176
184
  arraify,
177
185
  codeFrame,
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "1.1.7";
1
+ const ASTRO_VERSION = "1.1.8";
2
2
  function createDeprecatedFetchContentFn() {
3
3
  return () => {
4
4
  throw new Error("Deprecated: Astro.fetchContent() has been replaced with Astro.glob().");
@@ -56,7 +56,7 @@ async function renderPage(result, componentFactory, props, children, streaming)
56
56
  controller.enqueue(encoder.encode("<!DOCTYPE html>\n"));
57
57
  }
58
58
  }
59
- controller.enqueue(encoder.encode(html));
59
+ controller.enqueue(encoder.encode(String(html)));
60
60
  i++;
61
61
  }
62
62
  controller.close();
@@ -8,23 +8,35 @@ const PROP_TYPE = {
8
8
  BigInt: 6,
9
9
  URL: 7
10
10
  };
11
- function serializeArray(value, metadata) {
12
- return value.map((v) => convertToSerializedForm(v, metadata));
11
+ function serializeArray(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
12
+ if (parents.has(value)) {
13
+ throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
14
+
15
+ Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
16
+ }
17
+ parents.add(value);
18
+ const serialized = value.map((v) => {
19
+ return convertToSerializedForm(v, metadata, parents);
20
+ });
21
+ parents.delete(value);
22
+ return serialized;
13
23
  }
14
- function serializeObject(value, metadata) {
15
- if (cyclicRefs.has(value)) {
24
+ function serializeObject(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
25
+ if (parents.has(value)) {
16
26
  throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
17
27
 
18
28
  Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
19
29
  }
20
- cyclicRefs.add(value);
21
- return Object.fromEntries(
30
+ parents.add(value);
31
+ const serialized = Object.fromEntries(
22
32
  Object.entries(value).map(([k, v]) => {
23
- return [k, convertToSerializedForm(v, metadata)];
33
+ return [k, convertToSerializedForm(v, metadata, parents)];
24
34
  })
25
35
  );
36
+ parents.delete(value);
37
+ return serialized;
26
38
  }
27
- function convertToSerializedForm(value, metadata) {
39
+ function convertToSerializedForm(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
28
40
  const tag = Object.prototype.toString.call(value);
29
41
  switch (tag) {
30
42
  case "[object Date]": {
@@ -36,13 +48,13 @@ function convertToSerializedForm(value, metadata) {
36
48
  case "[object Map]": {
37
49
  return [
38
50
  PROP_TYPE.Map,
39
- JSON.stringify(serializeArray(Array.from(value), metadata))
51
+ JSON.stringify(serializeArray(Array.from(value), metadata, parents))
40
52
  ];
41
53
  }
42
54
  case "[object Set]": {
43
55
  return [
44
56
  PROP_TYPE.Set,
45
- JSON.stringify(serializeArray(Array.from(value), metadata))
57
+ JSON.stringify(serializeArray(Array.from(value), metadata, parents))
46
58
  ];
47
59
  }
48
60
  case "[object BigInt]": {
@@ -52,21 +64,19 @@ function convertToSerializedForm(value, metadata) {
52
64
  return [PROP_TYPE.URL, value.toString()];
53
65
  }
54
66
  case "[object Array]": {
55
- return [PROP_TYPE.JSON, JSON.stringify(serializeArray(value, metadata))];
67
+ return [PROP_TYPE.JSON, JSON.stringify(serializeArray(value, metadata, parents))];
56
68
  }
57
69
  default: {
58
70
  if (value !== null && typeof value === "object") {
59
- return [PROP_TYPE.Value, serializeObject(value, metadata)];
71
+ return [PROP_TYPE.Value, serializeObject(value, metadata, parents)];
60
72
  } else {
61
73
  return [PROP_TYPE.Value, value];
62
74
  }
63
75
  }
64
76
  }
65
77
  }
66
- let cyclicRefs = /* @__PURE__ */ new WeakSet();
67
78
  function serializeProps(props, metadata) {
68
79
  const serialized = JSON.stringify(serializeObject(props, metadata));
69
- cyclicRefs = /* @__PURE__ */ new WeakSet();
70
80
  return serialized;
71
81
  }
72
82
  export {
@@ -1,7 +1,7 @@
1
1
  import type { HmrContext, ModuleNode } from 'vite';
2
2
  import type { AstroConfig } from '../@types/astro';
3
+ import { cachedCompilation } from '../core/compile/index.js';
3
4
  import type { LogOptions } from '../core/logger/core.js';
4
- import { cachedCompilation } from './compile.js';
5
5
  export interface HandleHotUpdateOptions {
6
6
  config: AstroConfig;
7
7
  logging: LogOptions;
@@ -1,7 +1,7 @@
1
1
  import { fileURLToPath } from "node:url";
2
+ import { invalidateCompilation, isCached } from "../core/compile/index.js";
2
3
  import { info } from "../core/logger/core.js";
3
4
  import * as msg from "../core/messages.js";
4
- import { invalidateCompilation, isCached } from "./compile.js";
5
5
  import { isAstroScript } from "./query.js";
6
6
  const PKG_PREFIX = new URL("../../", import.meta.url);
7
7
  const isPkgFile = (id) => {
@@ -2,12 +2,16 @@ import ancestor from "common-ancestor-path";
2
2
  import esbuild from "esbuild";
3
3
  import slash from "slash";
4
4
  import { fileURLToPath } from "url";
5
- import { isRelativePath, startsWithForwardSlash } from "../core/path.js";
5
+ import { cachedCompilation, getCachedSource } from "../core/compile/index.js";
6
+ import { isRelativePath, prependForwardSlash, startsWithForwardSlash } from "../core/path.js";
7
+ import { viteID } from "../core/util.js";
6
8
  import { getFileInfo } from "../vite-plugin-utils/index.js";
7
- import { cachedCompilation, getCachedSource } from "./compile.js";
9
+ import {
10
+ createTransformStyles,
11
+ createViteStyleTransformer
12
+ } from "../vite-style-transform/index.js";
8
13
  import { handleHotUpdate } from "./hmr.js";
9
14
  import { parseAstroRequest } from "./query.js";
10
- import { createTransformStyleWithViteFn } from "./styles.js";
11
15
  const FRONTMATTER_PARSE_REGEXP = /^\-\-\-(.*)^\-\-\-/ms;
12
16
  function astro({ config, logging }) {
13
17
  function normalizeFilename(filename) {
@@ -24,10 +28,11 @@ function astro({ config, logging }) {
24
28
  return slash(fileURLToPath(url)) + url.search;
25
29
  }
26
30
  let resolvedConfig;
27
- let transformStyleWithVite;
31
+ let styleTransformer;
28
32
  let viteDevServer;
29
33
  const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
30
34
  const isBrowserPath = (path) => path.startsWith(srcRootWeb);
35
+ const isFullFilePath = (path) => path.startsWith(prependForwardSlash(slash(fileURLToPath(config.root))));
31
36
  function resolveRelativeFromAstroParent(id, parsedFrom) {
32
37
  const filename = normalizeFilename(parsedFrom.filename);
33
38
  const resolvedURL = new URL(id, `file://${filename}`);
@@ -42,10 +47,11 @@ function astro({ config, logging }) {
42
47
  enforce: "pre",
43
48
  configResolved(_resolvedConfig) {
44
49
  resolvedConfig = _resolvedConfig;
45
- transformStyleWithVite = createTransformStyleWithViteFn(_resolvedConfig);
50
+ styleTransformer = createViteStyleTransformer(_resolvedConfig);
46
51
  },
47
52
  configureServer(server) {
48
53
  viteDevServer = server;
54
+ styleTransformer.viteDevServer = server;
49
55
  },
50
56
  async resolveId(id, from, opts) {
51
57
  if (from) {
@@ -63,6 +69,9 @@ function astro({ config, logging }) {
63
69
  if (query.type === "style" && isBrowserPath(id)) {
64
70
  return relativeToRoot(id);
65
71
  }
72
+ if (isFullFilePath(id)) {
73
+ return viteID(new URL("file://" + id));
74
+ }
66
75
  return id;
67
76
  }
68
77
  },
@@ -86,10 +95,7 @@ function astro({ config, logging }) {
86
95
  filename,
87
96
  moduleId: id,
88
97
  source,
89
- ssr: Boolean(opts == null ? void 0 : opts.ssr),
90
- transformStyleWithVite,
91
- viteDevServer,
92
- pluginContext: this
98
+ transformStyle: createTransformStyles(styleTransformer, filename, Boolean(opts == null ? void 0 : opts.ssr), this)
93
99
  };
94
100
  switch (query.type) {
95
101
  case "style": {
@@ -163,7 +169,7 @@ File: ${filename}`
163
169
  }
164
170
  },
165
171
  async transform(source, id, opts) {
166
- var _a, _b;
172
+ var _a;
167
173
  const parsedId = parseAstroRequest(id);
168
174
  const query = parsedId.query;
169
175
  if (!id.endsWith(".astro") || query.astro) {
@@ -178,10 +184,7 @@ File: ${filename}`
178
184
  filename,
179
185
  moduleId: id,
180
186
  source,
181
- ssr: Boolean(opts == null ? void 0 : opts.ssr),
182
- transformStyleWithVite,
183
- viteDevServer,
184
- pluginContext: this
187
+ transformStyle: createTransformStyles(styleTransformer, filename, Boolean(opts == null ? void 0 : opts.ssr), this)
185
188
  };
186
189
  try {
187
190
  const transformResult = await cachedCompilation(compileProps);
@@ -203,16 +206,8 @@ const $$url = ${JSON.stringify(
203
206
  )};export { $$file as file, $$url as url };
204
207
  `;
205
208
  if (!resolvedConfig.isProduction) {
206
- const metadata = transformResult.code.split("$$createMetadata(")[1].split("});\n")[0];
207
- const pattern = /specifier:\s*'([^']*)'/g;
208
- const deps = /* @__PURE__ */ new Set();
209
- let match;
210
- while (match = (_b = pattern.exec(metadata)) == null ? void 0 : _b[1]) {
211
- deps.add(match);
212
- }
213
209
  let i = 0;
214
210
  while (i < transformResult.scripts.length) {
215
- deps.add(`${id}?astro&type=script&index=${i}&lang.ts`);
216
211
  SUFFIX += `import "${id}?astro&type=script&index=${i}&lang.ts";`;
217
212
  i++;
218
213
  }
@@ -288,10 +283,7 @@ ${source}
288
283
  filename: context.file,
289
284
  moduleId: context.file,
290
285
  source: await context.read(),
291
- ssr: true,
292
- transformStyleWithVite,
293
- viteDevServer,
294
- pluginContext: this
286
+ transformStyle: createTransformStyles(styleTransformer, context.file, true, this)
295
287
  };
296
288
  const compile = () => cachedCompilation(compileProps);
297
289
  return handleHotUpdate.call(this, context, {
@@ -5,12 +5,13 @@ import fs from "fs";
5
5
  import matter from "gray-matter";
6
6
  import { fileURLToPath } from "url";
7
7
  import { pagesVirtualModuleId } from "../core/app/index.js";
8
+ import { cachedCompilation } from "../core/compile/index.js";
8
9
  import { collectErrorMetadata } from "../core/errors.js";
9
- import { cachedCompilation } from "../vite-plugin-astro/compile.js";
10
- import {
11
- createTransformStyleWithViteFn
12
- } from "../vite-plugin-astro/styles.js";
13
10
  import { getFileInfo } from "../vite-plugin-utils/index.js";
11
+ import {
12
+ createTransformStyles,
13
+ createViteStyleTransformer
14
+ } from "../vite-style-transform/index.js";
14
15
  const MARKDOWN_IMPORT_FLAG = "?mdImport";
15
16
  const MARKDOWN_CONTENT_FLAG = "?content";
16
17
  function safeMatter(source, id) {
@@ -43,13 +44,16 @@ function markdown({ config, logging }) {
43
44
  }
44
45
  return false;
45
46
  }
46
- let transformStyleWithVite;
47
+ let styleTransformer;
47
48
  let viteDevServer;
48
49
  return {
49
50
  name: "astro:markdown",
50
51
  enforce: "pre",
51
52
  configResolved(_resolvedConfig) {
52
- transformStyleWithVite = createTransformStyleWithViteFn(_resolvedConfig);
53
+ styleTransformer = createViteStyleTransformer(_resolvedConfig);
54
+ },
55
+ configureServer(server) {
56
+ styleTransformer.viteDevServer = server;
53
57
  },
54
58
  async resolveId(id, importer, options) {
55
59
  if (id.endsWith(`.md${MARKDOWN_CONTENT_FLAG}`)) {
@@ -161,10 +165,12 @@ ${astroResult}
161
165
  filename,
162
166
  moduleId: id,
163
167
  source: astroResult,
164
- ssr: Boolean(opts == null ? void 0 : opts.ssr),
165
- transformStyleWithVite,
166
- viteDevServer,
167
- pluginContext: this
168
+ transformStyle: createTransformStyles(
169
+ styleTransformer,
170
+ filename,
171
+ Boolean(opts == null ? void 0 : opts.ssr),
172
+ this
173
+ )
168
174
  };
169
175
  let transformResult = await cachedCompilation(compileProps);
170
176
  let { code: tsResult } = transformResult;
@@ -0,0 +1,2 @@
1
+ export type { ViteStyleTransformer } from './style-transform';
2
+ export { createTransformStyles, createViteStyleTransformer } from './style-transform.js';
@@ -0,0 +1,5 @@
1
+ import { createTransformStyles, createViteStyleTransformer } from "./style-transform.js";
2
+ export {
3
+ createTransformStyles,
4
+ createViteStyleTransformer
5
+ };
@@ -0,0 +1,10 @@
1
+ import type { PluginContext } from 'rollup';
2
+ import type { TransformStyle } from '../core/compile/index';
3
+ import { TransformStyleWithVite } from './transform-with-vite.js';
4
+ import type * as vite from 'vite';
5
+ export declare type ViteStyleTransformer = {
6
+ viteDevServer?: vite.ViteDevServer;
7
+ transformStyleWithVite: TransformStyleWithVite;
8
+ };
9
+ export declare function createViteStyleTransformer(viteConfig: vite.ResolvedConfig): ViteStyleTransformer;
10
+ export declare function createTransformStyles(viteStyleTransformer: ViteStyleTransformer, filename: string, ssr: boolean, pluginContext: PluginContext): TransformStyle;
@@ -0,0 +1,36 @@
1
+ import { fileURLToPath } from "url";
2
+ import { createTransformStyleWithViteFn } from "./transform-with-vite.js";
3
+ function createViteStyleTransformer(viteConfig) {
4
+ return {
5
+ transformStyleWithVite: createTransformStyleWithViteFn(viteConfig)
6
+ };
7
+ }
8
+ function getNormalizedIDForPostCSS(filename) {
9
+ try {
10
+ const filenameURL = new URL(`file://${filename}`);
11
+ return fileURLToPath(filenameURL);
12
+ } catch (err) {
13
+ return filename;
14
+ }
15
+ }
16
+ function createTransformStyles(viteStyleTransformer, filename, ssr, pluginContext) {
17
+ if (!pluginContext.addWatchFile) {
18
+ pluginContext.addWatchFile = () => {
19
+ };
20
+ }
21
+ const normalizedID = getNormalizedIDForPostCSS(filename);
22
+ return async function(styleSource, lang) {
23
+ const result = await viteStyleTransformer.transformStyleWithVite.call(pluginContext, {
24
+ id: normalizedID,
25
+ source: styleSource,
26
+ lang,
27
+ ssr,
28
+ viteDevServer: viteStyleTransformer.viteDevServer
29
+ });
30
+ return result;
31
+ };
32
+ }
33
+ export {
34
+ createTransformStyles,
35
+ createViteStyleTransformer
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
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",
@@ -82,7 +82,7 @@
82
82
  "vendor"
83
83
  ],
84
84
  "dependencies": {
85
- "@astrojs/compiler": "^0.23.5",
85
+ "@astrojs/compiler": "^0.24.0",
86
86
  "@astrojs/language-server": "^0.23.0",
87
87
  "@astrojs/markdown-remark": "^1.1.1",
88
88
  "@astrojs/telemetry": "^1.0.0",
@@ -95,6 +95,9 @@
95
95
  "@babel/types": "^7.18.4",
96
96
  "@proload/core": "^0.3.2",
97
97
  "@proload/plugin-tsm": "^0.2.1",
98
+ "@types/babel__core": "^7.1.19",
99
+ "@types/html-escaper": "^3.0.0",
100
+ "@types/yargs-parser": "^21.0.0",
98
101
  "boxen": "^6.2.1",
99
102
  "ci-info": "^3.3.1",
100
103
  "common-ancestor-path": "^1.0.1",
@@ -139,7 +142,6 @@
139
142
  },
140
143
  "devDependencies": {
141
144
  "@playwright/test": "^1.22.2",
142
- "@types/babel__core": "^7.1.19",
143
145
  "@types/babel__generator": "^7.6.4",
144
146
  "@types/babel__traverse": "^7.17.1",
145
147
  "@types/chai": "^4.3.1",
@@ -148,7 +150,6 @@
148
150
  "@types/debug": "^4.1.7",
149
151
  "@types/diff": "^5.0.2",
150
152
  "@types/estree": "^0.0.51",
151
- "@types/html-escaper": "^3.0.0",
152
153
  "@types/mime": "^2.0.3",
153
154
  "@types/mocha": "^9.1.1",
154
155
  "@types/parse5": "^6.0.3",
@@ -158,7 +159,6 @@
158
159
  "@types/rimraf": "^3.0.2",
159
160
  "@types/send": "^0.17.1",
160
161
  "@types/unist": "^2.0.6",
161
- "@types/yargs-parser": "^21.0.0",
162
162
  "ast-types": "^0.14.2",
163
163
  "astro-scripts": "0.0.7",
164
164
  "chai": "^4.3.6",
@@ -178,7 +178,8 @@
178
178
  "dev": "astro-scripts dev --prebuild \"src/runtime/server/astro-island.ts\" --prebuild \"src/runtime/client/{idle,load,media,only,visible}.ts\" \"src/**/*.ts\"",
179
179
  "postbuild": "astro-scripts copy \"src/**/*.astro\"",
180
180
  "benchmark": "node test/benchmark/dev.bench.js && node test/benchmark/build.bench.js",
181
- "test": "mocha --exit --timeout 20000 --ignore **/lit-element.test.js && mocha --timeout 20000 **/lit-element.test.js",
181
+ "test:unit": "mocha --exit --timeout 2000 ./test/units/**/*.test.js",
182
+ "test": "pnpm run test:unit && mocha --exit --timeout 20000 --ignore **/lit-element.test.js && mocha --timeout 20000 **/lit-element.test.js",
182
183
  "test:match": "mocha --timeout 20000 -g",
183
184
  "test:e2e": "playwright test",
184
185
  "test:e2e:match": "playwright test -g"