astro 1.2.4 → 1.2.5

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.
@@ -3,6 +3,7 @@
3
3
  import type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig } from '@astrojs/markdown-remark';
4
4
  import type * as babel from '@babel/core';
5
5
  import type { AddressInfo } from 'net';
6
+ import type { TsConfigJson } from 'tsconfig-resolver';
6
7
  import type * as vite from 'vite';
7
8
  import { z } from 'zod';
8
9
  import type { SerializedSSRManifest } from '../core/app/types';
@@ -803,6 +804,8 @@ export interface InjectedRoute {
803
804
  export interface AstroConfig extends z.output<typeof AstroConfigSchema> {
804
805
  integrations: AstroIntegration[];
805
806
  _ctx: {
807
+ tsConfig: TsConfigJson | undefined;
808
+ tsConfigPath: string | undefined;
806
809
  pageExtensions: string[];
807
810
  injectedRoutes: InjectedRoute[];
808
811
  adapter: AstroAdapter | undefined;
@@ -156,7 +156,15 @@ renderPage_fn = async function(request, routeData, mod, status = 200) {
156
156
  throw new Error(`Unable to resolve [${specifier}]`);
157
157
  }
158
158
  const bundlePath = manifest.entryModules[specifier];
159
- return bundlePath.startsWith("data:") ? bundlePath : prependForwardSlash(joinPaths(manifest.base, bundlePath));
159
+ switch (true) {
160
+ case bundlePath.startsWith("data:"):
161
+ case bundlePath.length === 0: {
162
+ return bundlePath;
163
+ }
164
+ default: {
165
+ return prependForwardSlash(joinPaths(manifest.base, bundlePath));
166
+ }
167
+ }
160
168
  },
161
169
  route: routeData,
162
170
  routeCache: __privateGet(this, _routeCache),
@@ -246,7 +246,7 @@ async function generatePath(pathname, opts, gopts) {
246
246
  const hashedFilePath = internals.entrySpecifierToBundleMap.get(specifier);
247
247
  if (typeof hashedFilePath !== "string") {
248
248
  if (specifier === BEFORE_HYDRATION_SCRIPT_ID) {
249
- return "data:text/javascript;charset=utf-8,//[no before-hydration script]";
249
+ return "";
250
250
  }
251
251
  throw new Error(`Cannot find the built path for ${specifier}`);
252
252
  }
@@ -119,7 +119,7 @@ function buildManifest(opts, internals, staticFiles) {
119
119
  });
120
120
  }
121
121
  if (!(BEFORE_HYDRATION_SCRIPT_ID in entryModules)) {
122
- entryModules[BEFORE_HYDRATION_SCRIPT_ID] = "data:text/javascript;charset=utf-8,//[no before-hydration script]";
122
+ entryModules[BEFORE_HYDRATION_SCRIPT_ID] = "";
123
123
  }
124
124
  const ssrManifest = {
125
125
  adapterName: opts.astroConfig._ctx.adapter.name,
@@ -5,6 +5,7 @@ import * as colors from "kleur/colors";
5
5
  import path from "path";
6
6
  import postcssrc from "postcss-load-config";
7
7
  import { BUNDLED_THEMES } from "shiki";
8
+ import * as tsr from "tsconfig-resolver";
8
9
  import { fileURLToPath, pathToFileURL } from "url";
9
10
  import * as vite from "vite";
10
11
  import { mergeConfig as mergeViteConfig } from "vite";
@@ -203,10 +204,13 @@ See https://astro.build/config for more information.`
203
204
  )
204
205
  }).optional().default({})
205
206
  });
207
+ const tsconfig = loadTSConfig(root);
206
208
  const result = {
207
209
  ...await AstroConfigRelativeSchema.parseAsync(userConfig),
208
210
  _ctx: {
209
211
  pageExtensions: [".astro", ".md", ".html"],
212
+ tsConfig: tsconfig == null ? void 0 : tsconfig.config,
213
+ tsConfigPath: tsconfig == null ? void 0 : tsconfig.path,
210
214
  scripts: [],
211
215
  renderers: [jsxRenderer],
212
216
  injectedRoutes: [],
@@ -346,6 +350,15 @@ async function tryLoadConfig(configOptions, flags, root) {
346
350
  await finallyCleanup();
347
351
  }
348
352
  }
353
+ function loadTSConfig(cwd) {
354
+ for (const searchName of ["tsconfig.json", "jsconfig.json"]) {
355
+ const config = tsr.tsconfigResolverSync({ cwd, searchName });
356
+ if (config.exists) {
357
+ return config;
358
+ }
359
+ }
360
+ return void 0;
361
+ }
349
362
  async function loadConfig(configOptions) {
350
363
  const root = resolveRoot(configOptions.cwd);
351
364
  const flags = resolveFlags(configOptions.flags || {});
@@ -48,7 +48,7 @@ async function dev(config, options) {
48
48
  isRestart
49
49
  })
50
50
  );
51
- const currentVersion = "1.2.4";
51
+ const currentVersion = "1.2.5";
52
52
  if (currentVersion.includes("-")) {
53
53
  warn(options.logging, null, msg.prerelease({ currentVersion }));
54
54
  }
@@ -47,7 +47,7 @@ function devStart({
47
47
  site,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "1.2.4";
50
+ const version = "1.2.5";
51
51
  const rootPath = site ? site.pathname : "/";
52
52
  const localPrefix = `${dim("\u2503")} Local `;
53
53
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -226,7 +226,7 @@ function printHelp({
226
226
  message.push(
227
227
  linebreak(),
228
228
  ` ${bgGreen(black(` ${commandName} `))} ${green(
229
- `v${"1.2.4"}`
229
+ `v${"1.2.5"}`
230
230
  )} ${headline}`
231
231
  );
232
232
  }
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.2.4";
8
+ const ASTRO_VERSION = "1.2.5";
9
9
  function isObject(value) {
10
10
  return typeof value === "object" && value != null;
11
11
  }
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "1.2.4";
1
+ const ASTRO_VERSION = "1.2.5";
2
2
  function createDeprecatedFetchContentFn() {
3
3
  return () => {
4
4
  throw new Error("Deprecated: Astro.fetchContent() has been replaced with Astro.glob().");
@@ -63,7 +63,10 @@ var _a;
63
63
  }
64
64
  async childrenConnectedCallback() {
65
65
  window.addEventListener("astro:hydrate", this.hydrate);
66
- await import(this.getAttribute("before-hydration-url"));
66
+ let beforeHydrationUrl = this.getAttribute("before-hydration-url");
67
+ if (beforeHydrationUrl) {
68
+ await import(beforeHydrationUrl);
69
+ }
67
70
  this.start();
68
71
  }
69
72
  start() {
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "var l;{const c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t)},o=(t,i)=>{if(t===\"\"||!Array.isArray(i))return i;const[e,n]=i;return e in c?c[e](n):void 0};customElements.get(\"astro-island\")||customElements.define(\"astro-island\",(l=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement&&this.parentElement.closest(\"astro-island[ssr]\"))return;const i=this.querySelectorAll(\"astro-slot\"),e={},n=this.querySelectorAll(\"template[data-astro-template]\");for(const s of n){const r=s.closest(this.tagName);!r||!r.isSameNode(this)||(e[s.getAttribute(\"data-astro-template\")||\"default\"]=s.innerHTML,s.remove())}for(const s of i){const r=s.closest(this.tagName);!r||!r.isSameNode(this)||(e[s.getAttribute(\"name\")||\"default\"]=s.innerHTML)}const a=this.hasAttribute(\"props\")?JSON.parse(this.getAttribute(\"props\"),o):{};this.hydrator(this)(this.Component,a,e,{client:this.getAttribute(\"client\")}),this.removeAttribute(\"ssr\"),window.removeEventListener(\"astro:hydrate\",this.hydrate),window.dispatchEvent(new CustomEvent(\"astro:hydrate\"))}}connectedCallback(){!this.hasAttribute(\"await-children\")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((i,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener(\"astro:hydrate\",this.hydrate),await import(this.getAttribute(\"before-hydration-url\")),this.start()}start(){const i=JSON.parse(this.getAttribute(\"opts\")),e=this.getAttribute(\"client\");if(Astro[e]===void 0){window.addEventListener(`astro:${e}`,()=>this.start(),{once:!0});return}Astro[e](async()=>{const n=this.getAttribute(\"renderer-url\"),[a,{default:s}]=await Promise.all([import(this.getAttribute(\"component-url\")),n?import(n):()=>()=>{}]),r=this.getAttribute(\"component-export\")||\"default\";if(!r.includes(\".\"))this.Component=a[r];else{this.Component=a;for(const d of r.split(\".\"))this.Component=this.Component[d]}return this.hydrator=s,this.hydrate},i,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},l.observedAttributes=[\"props\"],l))}";
6
+ declare const _default: "var l;{const c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t)},o=(t,s)=>{if(t===\"\"||!Array.isArray(s))return s;const[e,n]=s;return e in c?c[e](n):void 0};customElements.get(\"astro-island\")||customElements.define(\"astro-island\",(l=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement&&this.parentElement.closest(\"astro-island[ssr]\"))return;const s=this.querySelectorAll(\"astro-slot\"),e={},n=this.querySelectorAll(\"template[data-astro-template]\");for(const r of n){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute(\"data-astro-template\")||\"default\"]=r.innerHTML,r.remove())}for(const r of s){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute(\"name\")||\"default\"]=r.innerHTML)}const a=this.hasAttribute(\"props\")?JSON.parse(this.getAttribute(\"props\"),o):{};this.hydrator(this)(this.Component,a,e,{client:this.getAttribute(\"client\")}),this.removeAttribute(\"ssr\"),window.removeEventListener(\"astro:hydrate\",this.hydrate),window.dispatchEvent(new CustomEvent(\"astro:hydrate\"))}}connectedCallback(){!this.hasAttribute(\"await-children\")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((s,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener(\"astro:hydrate\",this.hydrate);let s=this.getAttribute(\"before-hydration-url\");s&&await import(s),this.start()}start(){const s=JSON.parse(this.getAttribute(\"opts\")),e=this.getAttribute(\"client\");if(Astro[e]===void 0){window.addEventListener(`astro:${e}`,()=>this.start(),{once:!0});return}Astro[e](async()=>{const n=this.getAttribute(\"renderer-url\"),[a,{default:r}]=await Promise.all([import(this.getAttribute(\"component-url\")),n?import(n):()=>()=>{}]),i=this.getAttribute(\"component-export\")||\"default\";if(!i.includes(\".\"))this.Component=a[i];else{this.Component=a;for(const d of i.split(\".\"))this.Component=this.Component[d]}return this.hydrator=r,this.hydrate},s,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},l.observedAttributes=[\"props\"],l))}";
7
7
  export default _default;
@@ -1,4 +1,4 @@
1
- var astro_island_prebuilt_default = `var l;{const c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t)},o=(t,i)=>{if(t===""||!Array.isArray(i))return i;const[e,n]=i;return e in c?c[e](n):void 0};customElements.get("astro-island")||customElements.define("astro-island",(l=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement&&this.parentElement.closest("astro-island[ssr]"))return;const i=this.querySelectorAll("astro-slot"),e={},n=this.querySelectorAll("template[data-astro-template]");for(const s of n){const r=s.closest(this.tagName);!r||!r.isSameNode(this)||(e[s.getAttribute("data-astro-template")||"default"]=s.innerHTML,s.remove())}for(const s of i){const r=s.closest(this.tagName);!r||!r.isSameNode(this)||(e[s.getAttribute("name")||"default"]=s.innerHTML)}const a=this.hasAttribute("props")?JSON.parse(this.getAttribute("props"),o):{};this.hydrator(this)(this.Component,a,e,{client:this.getAttribute("client")}),this.removeAttribute("ssr"),window.removeEventListener("astro:hydrate",this.hydrate),window.dispatchEvent(new CustomEvent("astro:hydrate"))}}connectedCallback(){!this.hasAttribute("await-children")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((i,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener("astro:hydrate",this.hydrate),await import(this.getAttribute("before-hydration-url")),this.start()}start(){const i=JSON.parse(this.getAttribute("opts")),e=this.getAttribute("client");if(Astro[e]===void 0){window.addEventListener(\`astro:\${e}\`,()=>this.start(),{once:!0});return}Astro[e](async()=>{const n=this.getAttribute("renderer-url"),[a,{default:s}]=await Promise.all([import(this.getAttribute("component-url")),n?import(n):()=>()=>{}]),r=this.getAttribute("component-export")||"default";if(!r.includes("."))this.Component=a[r];else{this.Component=a;for(const d of r.split("."))this.Component=this.Component[d]}return this.hydrator=s,this.hydrate},i,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},l.observedAttributes=["props"],l))}`;
1
+ var astro_island_prebuilt_default = `var l;{const c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t)},o=(t,s)=>{if(t===""||!Array.isArray(s))return s;const[e,n]=s;return e in c?c[e](n):void 0};customElements.get("astro-island")||customElements.define("astro-island",(l=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement&&this.parentElement.closest("astro-island[ssr]"))return;const s=this.querySelectorAll("astro-slot"),e={},n=this.querySelectorAll("template[data-astro-template]");for(const r of n){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute("data-astro-template")||"default"]=r.innerHTML,r.remove())}for(const r of s){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute("name")||"default"]=r.innerHTML)}const a=this.hasAttribute("props")?JSON.parse(this.getAttribute("props"),o):{};this.hydrator(this)(this.Component,a,e,{client:this.getAttribute("client")}),this.removeAttribute("ssr"),window.removeEventListener("astro:hydrate",this.hydrate),window.dispatchEvent(new CustomEvent("astro:hydrate"))}}connectedCallback(){!this.hasAttribute("await-children")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((s,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener("astro:hydrate",this.hydrate);let s=this.getAttribute("before-hydration-url");s&&await import(s),this.start()}start(){const s=JSON.parse(this.getAttribute("opts")),e=this.getAttribute("client");if(Astro[e]===void 0){window.addEventListener(\`astro:\${e}\`,()=>this.start(),{once:!0});return}Astro[e](async()=>{const n=this.getAttribute("renderer-url"),[a,{default:r}]=await Promise.all([import(this.getAttribute("component-url")),n?import(n):()=>()=>{}]),i=this.getAttribute("component-export")||"default";if(!i.includes("."))this.Component=a[i];else{this.Component=a;for(const d of i.split("."))this.Component=this.Component[d]}return this.hydrator=r,this.hydrate},s,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},l.observedAttributes=["props"],l))}`;
2
2
  export {
3
3
  astro_island_prebuilt_default as default
4
4
  };
@@ -93,7 +93,10 @@ async function generateHydrateScript(scriptOptions, metadata) {
93
93
  }
94
94
  island.props["ssr"] = "";
95
95
  island.props["client"] = hydrate;
96
- island.props["before-hydration-url"] = await result.resolve("astro:scripts/before-hydration.js");
96
+ let beforeHydrationUrl = await result.resolve("astro:scripts/before-hydration.js");
97
+ if (beforeHydrationUrl.length) {
98
+ island.props["before-hydration-url"] = beforeHydrationUrl;
99
+ }
97
100
  island.props["opts"] = escapeHTML(
98
101
  JSON.stringify({
99
102
  name: metadata.displayName,
@@ -1,20 +1,15 @@
1
1
  import * as path from "path";
2
- import * as tsr from "tsconfig-resolver";
3
- import * as url from "url";
4
2
  const normalize = (pathname) => String(pathname).split(path.sep).join(path.posix.sep);
5
- const getExistingConfig = (searchName, cwd) => {
6
- const config = tsr.tsconfigResolverSync({ cwd, searchName });
7
- return config.exists ? config : null;
8
- };
9
- const getConfigAlias = (cwd) => {
10
- const config = getExistingConfig("tsconfig.json", cwd) || getExistingConfig("jsconfig.json", cwd);
11
- if (!config)
3
+ const getConfigAlias = (astroConfig) => {
4
+ const config = astroConfig._ctx.tsConfig;
5
+ const configPath = astroConfig._ctx.tsConfigPath;
6
+ if (!config || !configPath)
12
7
  return null;
13
- const compilerOptions = Object(config.config.compilerOptions);
8
+ const compilerOptions = Object(config.compilerOptions);
14
9
  if (!compilerOptions.baseUrl)
15
10
  return null;
16
11
  const baseUrl = path.posix.resolve(
17
- path.posix.dirname(normalize(config.path).replace(/^\/?/, "/")),
12
+ path.posix.dirname(normalize(configPath).replace(/^\/?/, "/")),
18
13
  normalize(compilerOptions.baseUrl)
19
14
  );
20
15
  const aliases = [];
@@ -42,7 +37,7 @@ const getConfigAlias = (cwd) => {
42
37
  function configAliasVitePlugin({
43
38
  config: astroConfig
44
39
  }) {
45
- const configAlias = getConfigAlias(astroConfig.root && url.fileURLToPath(astroConfig.root));
40
+ const configAlias = getConfigAlias(astroConfig);
46
41
  if (!configAlias)
47
42
  return {};
48
43
  return {
@@ -124,6 +124,7 @@ function jsx({ config, logging }) {
124
124
  defaultJSXRendererEntry = [...jsxRenderersIntegrationOnly.entries()][0];
125
125
  },
126
126
  async transform(code, id, opts) {
127
+ var _a;
127
128
  const ssr = Boolean(opts == null ? void 0 : opts.ssr);
128
129
  if (!JSX_EXTENSIONS.has(path.extname(id))) {
129
130
  return null;
@@ -163,6 +164,10 @@ function jsx({ config, logging }) {
163
164
  if (!importSource && IMPORT_KEYWORD_REGEX.test(code)) {
164
165
  importSource = await detectImportSourceFromImports(code, id, jsxRenderers);
165
166
  }
167
+ if (!importSource) {
168
+ const compilerOptions = (_a = config._ctx.tsConfig) == null ? void 0 : _a.compilerOptions;
169
+ importSource = compilerOptions == null ? void 0 : compilerOptions.jsxImportSource;
170
+ }
166
171
  if (!importSource && defaultJSXRendererEntry) {
167
172
  const [defaultRendererName] = defaultJSXRendererEntry;
168
173
  error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
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",