Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: support astro add without npm installing #3183

Merged
merged 8 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.