Skip to content

Commit

Permalink
feat: make options optional
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve committed Oct 31, 2023
1 parent 4b99b98 commit ff099b3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ $ pnpm add -D unplugin-vue-complex-types
import VueComplexTypes from "unplugin-vue-complex-types/vite";

export default defineConfig({
plugins: [VueComplexTypes({})],
plugins: [
VueComplexTypes({
/* Options */
}),
],
});
```

Expand All @@ -44,7 +48,7 @@ import VueComplexTypes from "unplugin-vue-complex-types/rollup";
export default {
plugins: [
VueComplexTypes({
tsconfigPath: "tsconfig.json", // Path to your tsconfig.json
/* Options */
}),
// other plugins
],
Expand All @@ -62,7 +66,7 @@ module.exports = {
/* ... */
plugins: [
require("unplugin-vue-complex-types/webpack")({
tsconfigPath: "tsconfig.json", // Path to your tsconfig.json
/* Options */
}),
],
};
Expand All @@ -78,7 +82,7 @@ module.exports = {
export default defineNuxtConfig({
modules: ["unplugin-vue-complex-types/nuxt"],
complexTypes: {
tsconfigPath: "tsconfig.json", // Path to your tsconfig.json
/* Options */
},
});
```
Expand All @@ -94,7 +98,7 @@ module.exports = {
configureWebpack: {
plugins: [
require("unplugin-vue-complex-types/webpack")({
tsconfigPath: "tsconfig.json", // Path to your tsconfig.json
/* Options */
}),
],
},
Expand All @@ -113,7 +117,7 @@ module.exports = {
[
"unplugin-vue-complex-types/vite",
{
tsconfigPath: "tsconfig.json", // Path to your tsconfig.json
/* Options */
},
],
],
Expand All @@ -129,7 +133,7 @@ module.exports = {
chainWebpack(chain) {
chain.plugin("unplugin-vue-complex-types").use(
VueComplexTypesPlugin({
tsconfigPath: "tsconfig.json", // Path to your tsconfig.json
/* Options */
}),
);
},
Expand All @@ -150,7 +154,7 @@ build({
/* ... */
plugins: [
require("unplugin-vue-complex-types/esbuild")({
tsconfigPath: "tsconfig.json", // Path to your tsconfig.json
/* Options */
}),
],
});
Expand All @@ -168,14 +172,21 @@ import VueComplexTypes from "unplugin-vue-complex-types/astro";
export default defineConfig({
integrations: [
VueComplexTypes({
tsconfigPath: "tsconfig.json", // Path to your tsconfig.json
/* Options */
}),
],
});
```

<br></details>

## 📚 Options

### `tsconfigPath`

- Type: `string`
- Default: `path.join(process.cwd(), "tsconfig.json")`

## 📝 License

[MIT](./LICENSE). Made with ❤️ by [Ray](https://github.com/so1ve)
6 changes: 4 additions & 2 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { createUnplugin } from "unplugin";
import { ensureLanguage } from "./language";
import { transform } from "./transform";
import type { Options } from "./types";
import { resolveOptions } from "./utils";

export { ensureLanguage, getLanguage } from "./language";

export default createUnplugin<Options>((options) => ({
export default createUnplugin<Options | undefined>((options = {}) => ({
name: "unplugin-vue-complex-types",
buildStart() {
ensureLanguage(options.tsconfigPath);
const resolvedOptions = resolveOptions(options);
ensureLanguage(resolvedOptions.tsconfigPath);
},
transform(code, id) {
if (!id.endsWith(".vue")) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface Options {
tsconfigPath: string;
tsconfigPath?: string;
}
8 changes: 8 additions & 0 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
import { join } from "node:path";

import type { Options } from "./types";

const windowsPathReg = /\\/g;
export const normalizePath = (id: string) => id.replace(windowsPathReg, "/");

export const resolveOptions = (rawOptions: Options): Required<Options> => ({
tsconfigPath: rawOptions.tsconfigPath ?? join(process.cwd(), "tsconfig.json"),
});

0 comments on commit ff099b3

Please sign in to comment.