Skip to content

Commit

Permalink
Remove system config #69
Browse files Browse the repository at this point in the history
  • Loading branch information
qrac committed Oct 15, 2022
1 parent 2e63535 commit 79a8976
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 79 deletions.
4 changes: 0 additions & 4 deletions packages/minista/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import type { ResolvedMainConfig } from "./main.js"
import type { ResolvedSubConfig } from "./sub.js"
import type { ResolvedMdxConfig } from "./mdx.js"
import type { ResolvedViteConfig } from "./vite.js"
import type { SystemConfig } from "./system.js"
import { resolveUserConfig } from "./user.js"
import { resolveMainConfig } from "./main.js"
import { resolveSubConfig } from "./sub.js"
import { resolveMdxConfig } from "./mdx.js"
import { resolveViteConfig } from "./vite.js"
import { systemConfig } from "./system.js"

export type InlineConfig = UserConfig & {
configFile?: string | false
Expand All @@ -20,7 +18,6 @@ export type ResolvedConfig = {
sub: ResolvedSubConfig
mdx: ResolvedMdxConfig
vite: ResolvedViteConfig
system: SystemConfig
}

export async function resolveConfig(
Expand All @@ -41,7 +38,6 @@ export async function resolveConfig(
sub: resolvedSubConfig,
mdx: resolvedMdxConfig,
vite: resolvedViteConfig,
system: systemConfig,
}
return resolvedConfig
}
11 changes: 11 additions & 0 deletions packages/minista/src/config/sub.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "node:path"
import fs from "fs-extra"
import { normalizePath } from "vite"

import type { ResolvedMainConfig } from "./main.js"
Expand All @@ -11,6 +12,7 @@ export type ResolvedSubConfig = {
resolvedRoot: string
resolvedEntry: ResolvedEntry
resolvedAlias: ResolvedAlias
tempDir: string
}

export async function resolveSubConfig(
Expand All @@ -29,9 +31,18 @@ export async function resolveSubConfig(
const viteConfigAlias = mainConfig.vite.resolve?.alias || {}
const resolvedAlias = await resolveAlias(configAlias, viteConfigAlias)

let tempDir = ""

if (await fs.pathExists(path.join(resolvedRoot, "node_modules"))) {
tempDir = path.join(resolvedRoot, "node_modules", ".minista")
} else {
tempDir = path.join(process.cwd(), "node_modules", ".minista")
}

return {
resolvedRoot,
resolvedEntry,
resolvedAlias,
tempDir,
}
}
65 changes: 0 additions & 65 deletions packages/minista/src/config/system.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/minista/src/config/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { ResolvedMainConfig } from "./main.js"
import type { ResolvedSubConfig } from "./sub.js"
import type { ResolvedMdxConfig } from "./mdx.js"
import type { ResolvedEntry } from "./entry.js"
import { systemConfig } from "./system.js"
import { pluginSvgr } from "../plugins/svgr.js"

const __filename = fileURLToPath(import.meta.url)
Expand Down Expand Up @@ -109,7 +108,7 @@ export async function resolveViteConfig(
allow: [
searchForWorkspaceRoot(process.cwd()),
path.resolve(__dirname + "/../../"),
path.resolve(systemConfig.temp.icons.outDir),
path.resolve(subConfig.tempDir),
],
},
},
Expand All @@ -125,7 +124,7 @@ export async function resolveViteConfig(
},
{
find: "/@minista-temp",
replacement: path.resolve(systemConfig.temp.out),
replacement: path.resolve(subConfig.tempDir),
},
],
},
Expand Down
13 changes: 6 additions & 7 deletions packages/minista/src/generate/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import path from "node:path"
import fs from "fs-extra"
import pc from "picocolors"
import beautify from "js-beautify"
import { fetch } from "undici"

import type { ResolvedConfig } from "../config/index.js"
import type { BuildResult } from "../cli/build.js"
import type { GatherPages } from "../gather/pages.js"

export { fetch }

export async function generatePages({
config,
items,
Expand All @@ -27,7 +30,7 @@ export async function generatePages({
return
}
let fileName = item.fileName
fileName = "__minista_gather_pages.mjs"
fileName = "pages.mjs"

let data = ""
item.source && (data = item.source)
Expand All @@ -36,11 +39,8 @@ export async function generatePages({
if (!data) {
return
}
gatherPagesPath = path.join(
config.sub.resolvedRoot,
config.main.out,
fileName
)
gatherPagesPath = path.join(config.sub.tempDir, fileName)

return await fs
.outputFile(gatherPagesPath, data)
.then(() => {
Expand Down Expand Up @@ -108,5 +108,4 @@ export async function generatePages({
})
})
)
await fs.remove(gatherPagesPath)
}

0 comments on commit 79a8976

Please sign in to comment.