Adds astro cli dynamic imports (#5292)
* change add, build, preview, devServer and telemtryHandler imports to dynamic * update changelog for astro cli imports change
This commit is contained in:
parent
b4f77a6122
commit
97e2b6ad7a
2 changed files with 15 additions and 5 deletions
5
.changeset/friendly-beds-explode.md
Normal file
5
.changeset/friendly-beds-explode.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Changes slow astro cli imports to dynamic
|
|
@ -4,8 +4,6 @@ import { pathToFileURL } from 'url';
|
||||||
import type { Arguments as Flags } from 'yargs-parser';
|
import type { Arguments as Flags } from 'yargs-parser';
|
||||||
import yargs from 'yargs-parser';
|
import yargs from 'yargs-parser';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import add from '../core/add/index.js';
|
|
||||||
import build from '../core/build/index.js';
|
|
||||||
import {
|
import {
|
||||||
createSettings,
|
createSettings,
|
||||||
openConfig,
|
openConfig,
|
||||||
|
@ -13,18 +11,15 @@ import {
|
||||||
resolveFlags,
|
resolveFlags,
|
||||||
} from '../core/config/index.js';
|
} from '../core/config/index.js';
|
||||||
import { ASTRO_VERSION } from '../core/constants.js';
|
import { ASTRO_VERSION } from '../core/constants.js';
|
||||||
import devServer from '../core/dev/index.js';
|
|
||||||
import { collectErrorMetadata } from '../core/errors/dev/index.js';
|
import { collectErrorMetadata } from '../core/errors/dev/index.js';
|
||||||
import { createSafeError } from '../core/errors/index.js';
|
import { createSafeError } from '../core/errors/index.js';
|
||||||
import { debug, error, info, LogOptions } from '../core/logger/core.js';
|
import { debug, error, info, LogOptions } from '../core/logger/core.js';
|
||||||
import { enableVerboseLogging, nodeLogDestination } from '../core/logger/node.js';
|
import { enableVerboseLogging, nodeLogDestination } from '../core/logger/node.js';
|
||||||
import { formatConfigErrorMessage, formatErrorMessage, printHelp } from '../core/messages.js';
|
import { formatConfigErrorMessage, formatErrorMessage, printHelp } from '../core/messages.js';
|
||||||
import preview from '../core/preview/index.js';
|
|
||||||
import * as event from '../events/index.js';
|
import * as event from '../events/index.js';
|
||||||
import { eventConfigError, eventError, telemetry } from '../events/index.js';
|
import { eventConfigError, eventError, telemetry } from '../events/index.js';
|
||||||
import { check } from './check/index.js';
|
import { check } from './check/index.js';
|
||||||
import { openInBrowser } from './open.js';
|
import { openInBrowser } from './open.js';
|
||||||
import * as telemetryHandler from './telemetry.js';
|
|
||||||
|
|
||||||
type Arguments = yargs.Arguments;
|
type Arguments = yargs.Arguments;
|
||||||
type CLICommand =
|
type CLICommand =
|
||||||
|
@ -140,6 +135,8 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
|
||||||
//
|
//
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case 'add': {
|
case 'add': {
|
||||||
|
const { default: add } = await import('../core/add/index.js');
|
||||||
|
|
||||||
telemetry.record(event.eventCliSession(cmd));
|
telemetry.record(event.eventCliSession(cmd));
|
||||||
const packages = flags._.slice(3) as string[];
|
const packages = flags._.slice(3) as string[];
|
||||||
return await add(packages, { cwd: root, flags, logging, telemetry });
|
return await add(packages, { cwd: root, flags, logging, telemetry });
|
||||||
|
@ -149,6 +146,8 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
|
||||||
return await openInBrowser('https://docs.astro.build/');
|
return await openInBrowser('https://docs.astro.build/');
|
||||||
}
|
}
|
||||||
case 'telemetry': {
|
case 'telemetry': {
|
||||||
|
const telemetryHandler = await import('./telemetry.js');
|
||||||
|
|
||||||
// Do not track session start, since the user may be trying to enable,
|
// Do not track session start, since the user may be trying to enable,
|
||||||
// disable, or modify telemetry settings.
|
// disable, or modify telemetry settings.
|
||||||
const subcommand = flags._[3]?.toString();
|
const subcommand = flags._[3]?.toString();
|
||||||
|
@ -174,6 +173,8 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
|
||||||
// by the end of this switch statement.
|
// by the end of this switch statement.
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case 'dev': {
|
case 'dev': {
|
||||||
|
const { default: devServer } = await import('../core/dev/index.js');
|
||||||
|
|
||||||
const configFlag = resolveFlags(flags).config;
|
const configFlag = resolveFlags(flags).config;
|
||||||
const configFlagPath = configFlag ? await resolveConfigPath({ cwd: root, flags }) : undefined;
|
const configFlagPath = configFlag ? await resolveConfigPath({ cwd: root, flags }) : undefined;
|
||||||
|
|
||||||
|
@ -191,6 +192,8 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'build': {
|
case 'build': {
|
||||||
|
const { default: build } = await import('../core/build/index.js');
|
||||||
|
|
||||||
return await build(settings, { ...flags, logging, telemetry });
|
return await build(settings, { ...flags, logging, telemetry });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,6 +203,8 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'preview': {
|
case 'preview': {
|
||||||
|
const { default: preview } = await import('../core/preview/index.js');
|
||||||
|
|
||||||
const server = await preview(settings, { logging, telemetry });
|
const server = await preview(settings, { logging, telemetry });
|
||||||
return await server.closed(); // keep alive until the server is closed
|
return await server.closed(); // keep alive until the server is closed
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue