From b1ac1403d2599af52f41d9a21bb7649b4e1a5fa4 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 13 Feb 2023 16:57:56 -0500 Subject: [PATCH 1/5] refactor: move sync to core --- packages/astro/src/cli/check/index.ts | 2 +- packages/astro/src/cli/index.ts | 2 +- packages/astro/src/core/build/index.ts | 2 +- packages/astro/src/{cli => core}/sync/index.ts | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) rename packages/astro/src/{cli => core}/sync/index.ts (87%) diff --git a/packages/astro/src/cli/check/index.ts b/packages/astro/src/cli/check/index.ts index 037525a5b2ee..fc27b62a39e7 100644 --- a/packages/astro/src/cli/check/index.ts +++ b/packages/astro/src/cli/check/index.ts @@ -21,7 +21,7 @@ interface Result { export async function check(settings: AstroSettings, { logging }: { logging: LogOptions }) { console.log(bold('astro check')); - const { sync } = await import('../sync/index.js'); + const { sync } = await import('../../core/sync/index.js'); const syncRet = await sync(settings, { logging, fs }); // early exit on sync failure if (syncRet === 1) return syncRet; diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 27c2a323cbb8..7c894fa09a19 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -212,7 +212,7 @@ async function runCommand(cmd: string, flags: yargs.Arguments) { } case 'sync': { - const { sync } = await import('./sync/index.js'); + const { sync } = await import('../core/sync/index.js'); const ret = await sync(settings, { logging, fs }); return process.exit(ret); diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index a2baa460958c..638d78d105b9 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -81,7 +81,7 @@ class AstroBuilder { ); await runHookConfigDone({ settings: this.settings, logging }); - const { sync } = await import('../../cli/sync/index.js'); + const { sync } = await import('../sync/index.js'); const syncRet = await sync(this.settings, { logging, fs }); if (syncRet !== 0) { return process.exit(syncRet); diff --git a/packages/astro/src/cli/sync/index.ts b/packages/astro/src/core/sync/index.ts similarity index 87% rename from packages/astro/src/cli/sync/index.ts rename to packages/astro/src/core/sync/index.ts index f321b8b0ba02..5b37f1441ae6 100644 --- a/packages/astro/src/cli/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -5,10 +5,10 @@ import { createServer } from 'vite'; import type { AstroSettings } from '../../@types/astro'; import { createContentTypesGenerator } from '../../content/index.js'; import { globalContentConfigObserver } from '../../content/utils.js'; -import { getTimeStat } from '../../core/build/util.js'; -import { createVite } from '../../core/create-vite.js'; -import { AstroError, AstroErrorData } from '../../core/errors/index.js'; -import { info, LogOptions } from '../../core/logger/core.js'; +import { getTimeStat } from '../build/util.js'; +import { createVite } from '../create-vite.js'; +import { AstroError, AstroErrorData } from '../errors/index.js'; +import { info, LogOptions } from '../logger/core.js'; import { setUpEnvTs } from '../../vite-plugin-inject-env-ts/index.js'; export async function sync( From 2514c01543b82c616e80330a3ed6c4af958a1401 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 13 Feb 2023 17:05:33 -0500 Subject: [PATCH 2/5] fix: runHookConfigSetup in CLI --- packages/astro/src/cli/index.ts | 4 ++-- packages/astro/src/core/sync/index.ts | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 7c894fa09a19..0cec490bd1ef 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -212,9 +212,9 @@ async function runCommand(cmd: string, flags: yargs.Arguments) { } case 'sync': { - const { sync } = await import('../core/sync/index.js'); + const { syncCli } = await import('../core/sync/index.js'); - const ret = await sync(settings, { logging, fs }); + const ret = await syncCli(settings, { logging, fs }); return process.exit(ret); } diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index 5b37f1441ae6..f849ff6cf232 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -7,14 +7,29 @@ import { createContentTypesGenerator } from '../../content/index.js'; import { globalContentConfigObserver } from '../../content/utils.js'; import { getTimeStat } from '../build/util.js'; import { createVite } from '../create-vite.js'; +import { runHookConfigSetup } from '../../integrations/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import { info, LogOptions } from '../logger/core.js'; import { setUpEnvTs } from '../../vite-plugin-inject-env-ts/index.js'; +type ProcessExit = 0 | 1; + +export async function syncCli( + settings: AstroSettings, + { logging, fs }: { logging: LogOptions; fs: typeof fsMod } +): Promise { + const resolvedSettings = await runHookConfigSetup({ + settings, + logging, + command: 'build', + }); + return sync(resolvedSettings, { logging, fs }); +} + export async function sync( settings: AstroSettings, { logging, fs }: { logging: LogOptions; fs: typeof fsMod } -): Promise<0 | 1> { +): Promise { const timerStart = performance.now(); // Needed to load content config const tempViteServer = await createServer( From f81ea60486919ef55a1a624dc156ee98daf53912 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 13 Feb 2023 17:07:45 -0500 Subject: [PATCH 3/5] chore: changeset --- .changeset/cold-spoons-battle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cold-spoons-battle.md diff --git a/.changeset/cold-spoons-battle.md b/.changeset/cold-spoons-battle.md new file mode 100644 index 000000000000..1245d2a26206 --- /dev/null +++ b/.changeset/cold-spoons-battle.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix: run integration setup hooks during `astro sync` From 7f137914f09e8dcc2adecc4b7999bc2b8ca5d144 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 13 Feb 2023 17:14:50 -0500 Subject: [PATCH 4/5] fix: sync import on test-utils --- packages/astro/test/test-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index 856c0b09fe88..bb06f90e429a 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -5,7 +5,7 @@ import fs from 'fs'; import os from 'os'; import stripAnsi from 'strip-ansi'; import { fileURLToPath } from 'url'; -import { sync } from '../dist/cli/sync/index.js'; +import { sync } from '../dist/core/sync/index.js'; import build from '../dist/core/build/index.js'; import { openConfig } from '../dist/core/config/config.js'; import { createSettings } from '../dist/core/config/index.js'; From f005efc1c19bb005d09a17908d740a0baa588447 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 13 Feb 2023 17:37:23 -0500 Subject: [PATCH 5/5] fix: use syncCli in check --- packages/astro/src/cli/check/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/cli/check/index.ts b/packages/astro/src/cli/check/index.ts index fc27b62a39e7..069ce343c81b 100644 --- a/packages/astro/src/cli/check/index.ts +++ b/packages/astro/src/cli/check/index.ts @@ -21,8 +21,8 @@ interface Result { export async function check(settings: AstroSettings, { logging }: { logging: LogOptions }) { console.log(bold('astro check')); - const { sync } = await import('../../core/sync/index.js'); - const syncRet = await sync(settings, { logging, fs }); + const { syncCli } = await import('../../core/sync/index.js'); + const syncRet = await syncCli(settings, { logging, fs }); // early exit on sync failure if (syncRet === 1) return syncRet;