Skip to content

Commit

Permalink
Feat: support astro add without npm installing (#3183)
Browse files Browse the repository at this point in the history
* deps: update to latest proload

* feat: avoid parsing config on resolveConfigUrl

* chore: changeset

* fix: bump proload

* fix: bump proload

* fix: bump proload

* fix: bump proload

* fix: bump proload

Co-authored-by: Nate Moore <nate@skypack.dev>
  • Loading branch information
bholmesdev and Nate Moore committed Apr 26, 2022
1 parent e4bb276 commit 7a61977
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .changeset/giant-impalas-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/tailwind': patch
---

Support "astro add" before installing project dependencies
4 changes: 2 additions & 2 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
"@babel/generator": "^7.17.9",
"@babel/parser": "^7.17.9",
"@babel/traverse": "^7.17.9",
"@proload/core": "^0.2.2",
"@proload/plugin-tsm": "^0.1.1",
"@proload/core": "^0.3.2-next.4",
"@proload/plugin-tsm": "^0.2.1-next.0",
"ast-types": "^0.14.2",
"boxen": "^6.2.1",
"ci-info": "^3.3.0",
Expand Down
13 changes: 4 additions & 9 deletions packages/astro/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,6 @@ export async function cli(args: string[]) {
logging.level = 'silent';
}

let config: AstroConfig;
try {
// Note: ideally, `loadConfig` would return the config AND its filePath
// For now, `add` has to resolve the config again internally
config = await loadConfig({ cwd: root, flags, cmd });
} catch (err) {
return throwAndExit(err);
}

switch (cmd) {
case 'add': {
try {
Expand All @@ -124,6 +115,7 @@ export async function cli(args: string[]) {
}
case 'dev': {
try {
const config = await loadConfig({ cwd: root, flags, cmd });
await devServer(config, { logging });
return await new Promise(() => {}); // lives forever
} catch (err) {
Expand All @@ -133,19 +125,22 @@ export async function cli(args: string[]) {

case 'build': {
try {
const config = await loadConfig({ cwd: root, flags, cmd });
return await build(config, { logging });
} catch (err) {
return throwAndExit(err);
}
}

case 'check': {
const config = await loadConfig({ cwd: root, flags, cmd });
const ret = await check(config);
return process.exit(ret);
}

case 'preview': {
try {
const config = await loadConfig({ cwd: root, flags, cmd });
const server = await preview(config, { logging });
return await server.closed(); // keep alive until the server is closed
} catch (err) {
Expand Down
14 changes: 9 additions & 5 deletions packages/astro/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { pathToFileURL, fileURLToPath } from 'url';
import { mergeConfig as mergeViteConfig } from 'vite';
import { BUNDLED_THEMES } from 'shiki';
import { z } from 'zod';
import load, { ProloadError } from '@proload/core';
import load, { resolve, ProloadError } from '@proload/core';
import loadTypeScript from '@proload/plugin-tsm';
import postcssrc from 'postcss-load-config';
import { arraify, isObject } from './util.js';
Expand Down Expand Up @@ -385,11 +385,15 @@ export async function resolveConfigURL(
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
userConfigPath = fileURLToPath(new URL(userConfigPath, `file://${root}/`));
}
// Automatically load config file using Proload
// Resolve config file path using Proload
// If `userConfigPath` is `undefined`, Proload will search for `astro.config.[cm]?[jt]s`
const config = await load('astro', { mustExist: false, cwd: root, filePath: userConfigPath });
if (config) {
return pathToFileURL(config.filePath);
const configPath = await resolve('astro', {
mustExist: false,
cwd: root,
filePath: userConfigPath,
});
if (configPath) {
return pathToFileURL(configPath);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/tailwind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dev": "astro-scripts dev \"src/**/*.ts\""
},
"dependencies": {
"@proload/core": "^0.2.2",
"@proload/core": "^0.3.1",
"autoprefixer": "^10.4.4",
"postcss": "^8.4.12",
"tailwindcss": "^3.0.24"
Expand Down
40 changes: 27 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a61977

Please sign in to comment.