Skip to content

Commit fa62849

Browse files
authored
Merge pull request #44 from solidjs-community/dev-dependencies
Add `installsDev` option
2 parents 62abe9d + f00a9d3 commit fa62849

5 files changed

Lines changed: 58 additions & 36 deletions

File tree

packages/commands/src/handlers/add.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ const handleAutocompleteAdd = async () => {
4343
{ label: t.NO, value: false },
4444
{ label: t.YES_FORCE, value: [true, "force"] },
4545
],
46-
message: `${t.CONFIRM_INSTALL(a.length)} \n${color.red(S_BAR)} \n${color.red(S_BAR)} ${
47-
" " + color.yellow(a.map((opt) => opt.label).join(" ")) + " "
48-
} \n${color.red(S_BAR)} `,
46+
message: `${t.CONFIRM_INSTALL(a.length)} \n${color.red(S_BAR)} \n${color.red(S_BAR)} ${" " + color.yellow(a.map((opt) => opt.label).join(" ")) + " "
47+
} \n${color.red(S_BAR)} `,
4948
}),
5049
);
5150

@@ -114,16 +113,19 @@ export const handleAdd = async (packages?: string[], forceTransform: boolean = f
114113

115114
for (let i = 0; i < configs.length; i++) {
116115
const config = configs[i];
117-
config.installs.forEach((p) => queueUpdate({ type: "package", name: p }));
116+
config.installs.forEach((p) => queueUpdate({ type: "package", name: p, dev: false }));
117+
config.installsDev?.forEach((p) => queueUpdate({ type: "package", name: p, dev: true }));
118118
}
119119
// Queue primitives
120120
for (const primitive of await transformPrimitives(possiblePrimitives)) {
121-
queueUpdate({ type: "package", name: primitive.value });
121+
queueUpdate({ type: "package", name: primitive.value, dev: false });
122122
}
123123

124124
if (!configs.length) return;
125-
126-
await spinnerify({
125+
const pluginOptions = configs.map((c) => c.pluginOptions).filter(Boolean) as PluginOptions[];
126+
if (pluginOptions.length) {
127+
const appConfig = await getAppConfig();
128+
await spinnerify({
127129
startText: "Processing config",
128130
finishText: "Config processed",
129131
fn: async () => {
@@ -136,6 +138,7 @@ export const handleAdd = async (packages?: string[], forceTransform: boolean = f
136138
await writeFile(appConfig, code);
137139
},
138140
});
141+
}
139142

140143
p.log.info("Preparing post install steps for integrations");
141144

@@ -174,8 +177,7 @@ export const handleAdd = async (packages?: string[], forceTransform: boolean = f
174177
if (fileUpdates.length) p.log.message([`${color.cyan("Modify")}`, ...fileUpdates.map((f) => ` - ${f}`)].join("\n"));
175178

176179
if (packageUpdates.length)
177-
p.log.message([`${color.cyan("Install")}`, ...packageUpdates.map((p) => ` - ${p}`)].join("\n"));
178-
180+
p.log.message([`${color.cyan("Install")}`, ...packageUpdates.map((p) => ` - ${p.name}` + (p.dev ? " (dev)" : ""))].join("\n"));
179181
if (commandUpdates.length)
180182
p.log.message([`${color.cyan("Run commands")}`, ...commandUpdates.map((p) => ` - ${p}`)].join("\n"));
181183

@@ -192,8 +194,7 @@ export const handleAdd = async (packages?: string[], forceTransform: boolean = f
192194
if (postInstalls.length === 0) return;
193195

194196
p.log.message(
195-
`${postInstalls.length} ${
196-
postInstalls.length === 1 ? "package has" : "packages have"
197+
`${postInstalls.length} ${postInstalls.length === 1 ? "package has" : "packages have"
197198
} post install steps that need to run.`,
198199
);
199200

packages/commands/src/lib/integrations.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import { createSignal } from "@solid-cli/reactivity";
77
import * as p from "@clack/prompts";
88
import color from "picocolors";
99
import { cancelable } from "@solid-cli/ui";
10-
import { PluginOptions } from "@chialab/esbuild-plugin-meta-url";
1110
import { flushQueue } from "@solid-cli/utils/updates";
11+
import { PluginOptions } from "@solid-cli/utils/transform";
1212

1313
// All the integrations/packages that we support
1414
export type Supported = keyof typeof integrations;
1515

1616
export type IntegrationsValue = {
1717
pluginOptions?: PluginOptions;
1818
installs: string[];
19+
installsDev?: string[];
1920
additionalConfig?: () => Promise<void>;
2021
postInstall?: () => Promise<void>;
2122
};
@@ -24,7 +25,7 @@ export type Integrations = Record<Supported, IntegrationsValue>;
2425

2526
export const [rootFile, setRootFile] = createSignal<string | undefined>(undefined);
2627

27-
export const integrations = {
28+
export const integrations: Record<string, IntegrationsValue> = {
2829
"tailwind": {
2930
installs: ["tailwindcss", "postcss", "autoprefixer"],
3031
postInstall: async () => {
@@ -79,7 +80,8 @@ export const integrations = {
7980
isDefault: true,
8081
options: {},
8182
},
82-
installs: ["unocss"],
83+
installs: [""],
84+
installsDev: ["unocss"],
8385
additionalConfig: async () => {
8486
const path = rootFile();
8587
if (!path) return;
@@ -110,7 +112,8 @@ export const integrations = {
110112
},
111113
},
112114
"vitest": {
113-
installs: [
115+
installs: [],
116+
installsDev: [
114117
"vitest",
115118
"jsdom",
116119
"@solidjs/testing-library",
@@ -119,7 +122,7 @@ export const integrations = {
119122
],
120123
additionalConfig: async () => {
121124
try {
122-
p.log.info("Adding test script to package.json");
125+
p.log.info("Adding test script to package.json");
123126
const packageJsonString = await readFile("package.json", "utf8");
124127
const packageJson = JSON.parse(packageJsonString);
125128
if (!/\bvitest\b/.test(packageJson.scripts.test || "")) {
@@ -128,7 +131,7 @@ export const integrations = {
128131
}
129132
const hasTs = fileExists("tsconfig.json");
130133
if (hasTs) {
131-
p.log.info("Adding testing types to tsconfig.json");
134+
p.log.info("Adding testing types to tsconfig.json");
132135
const tsConfigString = await readFile("tsconfig.json", "utf8");
133136
const tsConfig = JSON.parse(tsConfigString);
134137
if (!tsConfig.compilerOptions) {
@@ -145,8 +148,8 @@ export const integrations = {
145148
(suffix) => !fileExists(`vite.config.${suffix}`) && !fileExists(`vitest.config.${suffix}`),
146149
)
147150
) {
148-
const suffix = hasTs ? "ts" : "mjs";
149-
p.log.info(`Adding vitest.config.${suffix}`);
151+
const suffix = hasTs ? "ts" : "mjs";
152+
p.log.info(`Adding vitest.config.${suffix}`);
150153
await writeFile(
151154
`vitest.config.${suffix}`,
152155
`import solid from "vite-plugin-solid";

packages/commands/src/lib/utils/helpers.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ export function validateFilePath(path: string, lookingFor: string): string | und
2727
export function validateFilePath(path: string, lookingFor: string[]): string | undefined;
2828
export function validateFilePath(path: string, lookingFor: string | string[]): string | undefined {
2929
path = resolve(path);
30-
const isDir = lstatSync(path).isDirectory();
30+
let isDir: boolean;
31+
try {
32+
console.log(path)
33+
isDir = lstatSync(path).isDirectory();
34+
}
35+
catch (e) { return undefined }
3136
if (isDir) {
3237
const files = readdirSync(path, { withFileTypes: true });
3338

@@ -58,9 +63,11 @@ export async function findFiles(
5863
let { depth = Infinity, ignoreDirs = ["node_modules", "."], startsWith = true } = opts;
5964

6065
startPath = resolve(startPath);
61-
62-
const isDir = lstatSync(startPath).isDirectory();
63-
66+
let isDir: boolean;
67+
try {
68+
isDir = lstatSync(startPath).isDirectory();
69+
}
70+
catch (e) { return [] };
6471
if (!isDir) {
6572
startPath = resolve(startPath.slice(0, startPath.lastIndexOf("/")));
6673
}

packages/core/src/index.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,23 @@ const main = async () => {
9595
version,
9696
});
9797
const args = process.argv.slice(2);
98+
try {
9899

99-
if (args.length === 0) {
100-
await provideSuggestions();
101-
return;
102-
}
100+
if (args.length === 0) {
101+
await provideSuggestions();
102+
return;
103+
}
103104

104-
if (args.length === 1 && args[0] === "start") {
105-
await provideStartSuggestions();
106-
return;
107-
}
105+
if (args.length === 1 && args[0] === "start") {
106+
await provideStartSuggestions();
107+
return;
108+
}
108109

109-
await run(cli, args);
110+
await run(cli, args);
111+
}
112+
catch (e) {
113+
console.error(e);
114+
process.exit(1);
115+
}
110116
};
111117
main();

packages/utils/src/updates/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ declare global {
77
// Batch all updates here, so we can confirm with the user then flush
88
export const UPDATESQUEUE: Update[] = globalThis.UPDATESQUEUE ?? [];
99
globalThis.UPDATESQUEUE = UPDATESQUEUE;
10-
type PackageUpdate = { type: "package"; name: string };
10+
type PackageUpdate = { type: "package"; name: string; dev: boolean };
1111
type CommandUpdate = { type: "command"; name: string };
1212
type FileUpdate = { type: "file"; name: string; contents: string; checked: boolean };
1313
// Don't bother explicitly handling plugin updates, since they're just a file update
1414
export type Update = PackageUpdate | CommandUpdate | FileUpdate;
1515
type UpdateSummary = {
16-
packageUpdates: string[];
16+
packageUpdates: PackageUpdate[];
1717
commandUpdates: string[];
1818
fileUpdates: string[];
1919
};
@@ -23,7 +23,7 @@ export const clearQueue = () => {
2323
};
2424
export const summarizeUpdates = (): UpdateSummary => {
2525
const fileUpdates = UPDATESQUEUE.filter((u) => u.type === "file").map((s) => s.name);
26-
const packageUpdates = UPDATESQUEUE.filter((u) => u.type === "package").map((s) => s.name);
26+
const packageUpdates = UPDATESQUEUE.filter((u) => u.type === "package") as PackageUpdate[];
2727
const commandUpdates = UPDATESQUEUE.filter((u) => u.type === "command").map((s) => s.name);
2828
return { packageUpdates, commandUpdates, fileUpdates };
2929
};
@@ -64,7 +64,12 @@ export const flushPackageUpdates = async () => {
6464
const pM = detectPackageManager();
6565
const instlCmd = getInstallCommand(pM);
6666
for (const update of packageUpdates) {
67-
await $`${pM.name} ${instlCmd} ${update.name}`;
67+
if (update.dev) {
68+
await $`${pM.name} ${instlCmd} -D ${update.name}`;
69+
}
70+
else {
71+
await $`${pM.name} ${instlCmd} ${update.name}`;
72+
}
6873
}
6974
};
7075
export const flushCommandUpdates = async () => {

0 commit comments

Comments
 (0)