@zthun/janitor-build-config 19.1.4 → 19.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,6 +83,25 @@ export declare class ZViteConfigBuilder {
83
83
  * This object.
84
84
  */
85
85
  sourceMap(sourcemap?: boolean): this;
86
+ /**
87
+ * Adds an alias to the resolution options.
88
+ *
89
+ * @param key -
90
+ * The name of the package to alias
91
+ * @param value -
92
+ * The alias resolution
93
+ *
94
+ * @returns
95
+ * This object.
96
+ */
97
+ alias(key: string, value: string): this;
98
+ /**
99
+ * Adds an alias for lodash to lodash-es.
100
+ *
101
+ * @returns
102
+ * This object.
103
+ */
104
+ lodash: () => this;
86
105
  /**
87
106
  * Assigns the server options.
88
107
  *
package/dist/vite.cjs CHANGED
@@ -137,6 +137,7 @@ class ZViteConfigBuilder {
137
137
  * Initializes a new instance of this object.
138
138
  */
139
139
  constructor() {
140
+ this.lodash = this.alias.bind(this, "lodash", "lodash-es");
140
141
  this.config = {
141
142
  build: {
142
143
  minify: true,
@@ -194,6 +195,23 @@ class ZViteConfigBuilder {
194
195
  this.config.build = { ...this.config.build, sourcemap };
195
196
  return this;
196
197
  }
198
+ /**
199
+ * Adds an alias to the resolution options.
200
+ *
201
+ * @param key -
202
+ * The name of the package to alias
203
+ * @param value -
204
+ * The alias resolution
205
+ *
206
+ * @returns
207
+ * This object.
208
+ */
209
+ alias(key, value) {
210
+ this.config.resolve = this.config.resolve || {};
211
+ this.config.resolve.alias = this.config.resolve.alias || {};
212
+ this.config.resolve.alias[key] = value;
213
+ return this;
214
+ }
197
215
  /**
198
216
  * Assigns the server options.
199
217
  *
package/dist/vite.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vite.cjs","sources":["../src/vite/vite-library-builder.mts","../src/vite/vite-test-builder.mts","../src/vite/vite-config-builder.mts","../src/vite/vite-server-builder.mts"],"sourcesContent":["import { cloneDeep } from \"lodash-es\";\nimport type { LibraryOptions } from \"vite\";\n\n/**\n * A builder for Vite library configurations.\n */\nexport class ZViteLibraryBuilder {\n private library: LibraryOptions = {\n entry: {},\n formats: [\"es\", \"cjs\"],\n };\n\n /**\n * Adds an entry point to the library.\n *\n * @param name -\n * The name of the entry point.\n * @param path -\n * The path to the entry point file.\n *\n * @returns\n * This object.\n */\n public entry(name: string, path: string) {\n this.library.entry = {\n ...(this.library.entry as Record<string, string>),\n [name]: path,\n };\n return this;\n }\n\n /**\n * A shorthand for adding an entry point\n * named \"index\" that points to \"src/index.ts\"\n *\n * @returns\n * This object.\n */\n public index() {\n return this.entry(\"index\", \"./src/index.mts\");\n }\n\n /**\n * Returns the built library configuration.\n *\n * @returns\n * A deep clone of the library configuration.\n */\n public build() {\n return cloneDeep(this.library);\n }\n}\n","import { cloneDeep } from \"lodash-es\";\nimport type { InlineConfig, VitestEnvironment } from \"vitest/node\";\n\n/**\n * A builder for test configurations found in vite's defineConfig test field.\n */\nexport class ZViteTestBuilder {\n private test: InlineConfig;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this.test = {\n environment: \"node\",\n testTimeout: 30000,\n coverage: {\n all: false,\n provider: undefined,\n },\n };\n }\n\n /**\n * Sets the test environment.\n *\n * @param environment -\n * The test environment to use.\n *\n * @returns\n * This object.\n */\n public environment(environment: VitestEnvironment) {\n this.test.environment = environment;\n return this;\n }\n\n /**\n * Sets the test environment to \"node\".\n *\n * @returns\n * This object.\n */\n public node = this.environment.bind(this, \"node\");\n\n /**\n * Sets the test environment to \"happy-dom\".\n *\n * @returns\n * This object.\n */\n public browser = this.environment.bind(this, \"happy-dom\");\n\n /**\n * Sets the test coverage provider.\n *\n * @param provider -\n * The test coverage provider to use.\n *\n * @returns\n * This object.\n */\n public coverage(provider: \"v8\" | \"istanbul\") {\n this.test.coverage = { ...this.test.coverage, provider };\n return this;\n }\n\n /**\n * Sets the test coverage provider to \"v8\".\n *\n * @returns\n * This object.\n */\n public v8 = this.coverage.bind(this, \"v8\");\n\n /**\n * Sets the test coverage provider to \"istanbul\".\n *\n * @returns\n * This object.\n */\n public istanbul = this.coverage.bind(this, \"istanbul\");\n\n /**\n * Adds to the list of projects.\n *\n * @param project -\n * The list of projects.\n *\n * @returns\n * This object.\n */\n public project(project: string | string[] = []) {\n const projects = this.test.projects || [];\n this.test.projects = projects.concat(project);\n return this;\n }\n\n /**\n * Adds monorepo support to the test builder.\n *\n * @param packages -\n * The path to the package directory.\n *\n * @returns\n * This object.\n */\n public monorepo(packages = \"packages\") {\n return this.project(`${packages}/*/vitest.config.{js,cjs,mjs,ts,mts}`);\n }\n\n /**\n * Returns the built test configuration.\n *\n * @returns\n * A deep clone of the test configuration.\n */\n public build() {\n return cloneDeep(this.test);\n }\n}\n","import react from \"@vitejs/plugin-react\";\nimport { castArray, cloneDeep } from \"lodash-es\";\nimport swc from \"unplugin-swc\";\nimport type {\n LibraryOptions,\n PluginOption,\n ServerOptions,\n UserConfig,\n} from \"vite\";\nimport { checker } from \"vite-plugin-checker\";\nimport dtsPlugin from \"vite-plugin-dts\";\nimport { externalizeDeps } from \"vite-plugin-externalize-deps\";\nimport tsConfigPaths from \"vite-tsconfig-paths\";\nimport type { InlineConfig as TestConfig } from \"vitest/node.js\";\nimport { ZViteLibraryBuilder } from \"./vite-library-builder.mjs\";\nimport { ZViteTestBuilder } from \"./vite-test-builder.mjs\";\n\n/**\n * A config builder for the vite build system.\n *\n * This is helpful when building different types\n * of projects and keeping a standard.\n *\n * @example vite.config.ts\n *\n * ```ts\n * // Before Config Builder\n * export default defineConfig({\n * build: {\n * lib: {\n * entry: {\n * index: \"./src/index.ts\",\n * },\n * formats: [\"cjs\", \"es\"],\n * },\n * },\n * minify: false,\n * sourceMap: true,\n * plugins: [\n * swc.vite(),\n * tsConfigPaths(),\n * externalizeDeps(),\n * dtsPlugin({\n * compilerOptions: {\n * paths: {},\n * },\n * }),\n * ],\n * });\n * ```\n *\n * ```ts\n * // After config builder\n * const config = new ZViteConfigBuilder().library().build();\n * export default defineConfig(config);\n * ```\n */\nexport class ZViteConfigBuilder {\n private config: UserConfig;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this.config = {\n build: {\n minify: true,\n sourcemap: false,\n },\n plugins: [tsConfigPaths()],\n };\n }\n\n /**\n * Sets whether to minify the build output.\n *\n * @param minify -\n * The flag as to minify the output.\n *\n * @returns\n * This object.\n */\n public minify(minify = true) {\n this.config.build = { ...this.config.build, minify };\n return this;\n }\n\n /**\n * Adds a list of plugins.\n *\n * @param option -\n * The plugins to add.\n *\n * @returns\n * This object.\n */\n public plugin(option: PluginOption | PluginOption[] = []) {\n // See constructor - the config plugins are guaranteed to\n // be set. The swc and paths plugins are automatically added.\n const plugins = this.config.plugins!;\n this.config.plugins = plugins.concat(castArray(option));\n return this;\n }\n\n /**\n * Adds the swc plugin.\n *\n * This is mostly for nest projects as nest requires\n * swc to support decorators.\n */\n public swc() {\n return this.plugin(swc.vite());\n }\n\n /**\n * Sets whether to generate source maps.\n *\n * @param sourcemap -\n * True to generate a sourcemap, false for faster build.\n *\n * @returns\n * This object.\n */\n public sourceMap(sourcemap = true) {\n this.config.build = { ...this.config.build, sourcemap };\n return this;\n }\n\n /**\n * Assigns the server options.\n *\n * @param options -\n * The server options to assign.\n *\n * @returns\n * This object.\n */\n public server(options: ServerOptions) {\n this.config.server = cloneDeep(options);\n return this;\n }\n\n /**\n * Sets vite into library mode.\n *\n * @param lib -\n * The options for the library. You can set this to\n * nothing to use the default library which looks for\n * an entry point at the source directory called index.ts\n *\n * @see {@link ZViteLibraryBuilder} for more information.\n *\n * @returns\n * This object.\n */\n public library(\n lib: LibraryOptions = new ZViteLibraryBuilder().index().build(),\n ) {\n this.config.build = { ...this.config.build, lib };\n\n const dts = dtsPlugin({\n compilerOptions: {\n // Always turn off paths when building for production. You want to make\n // sure that your build is building in the correct order and that your\n // actual paths are correct.\n paths: {},\n },\n });\n const external = externalizeDeps();\n\n return this.minify(false).sourceMap().plugin(external).plugin(dts);\n }\n\n /**\n * Constructs the config to act as if it's compiling a node application.\n *\n * This is just an alias to {@link ZViteConfigBuilder.library} with two\n * entry points.\n *\n * 1. The file src/cli.ts is the main entry point of the application.\n * 1. The file, src/index.ts, is the api for importing\n *\n * @returns\n * This object.\n */\n public cli() {\n // A cli works similar to a library.\n const library = new ZViteLibraryBuilder()\n .entry(\"index\", \"src/index.mts\")\n .entry(\"cli\", \"src/cli.mts\")\n .build();\n return this.library(library);\n }\n\n /**\n * Constructs the config to act as if it's compiling a nest application.\n *\n * This is just an alias to {@link ZViteConfigBuilder.library} with a single\n * entry point.\n *\n * 1. The file, src/main.mts\n *\n * @returns\n * This object.\n */\n public nest() {\n const library = new ZViteLibraryBuilder()\n .entry(\"main\", \"src/main.mts\")\n .build();\n return this.library(library).swc();\n }\n\n /**\n * Constructs the config to act as if it's compiling a web application.\n *\n * @returns\n * This object.\n */\n public web() {\n return this.minify()\n .sourceMap(false)\n .plugin(checker({ typescript: true }));\n }\n\n /**\n * Constructs the config to compile a react application.\n *\n * @returns\n * This object.\n */\n public react() {\n return this.web().plugin(react());\n }\n\n /**\n * Constructs the config to be for testing.\n *\n * @param options -\n * The test config to use. If this is falsy,\n * then a test setup using a monorepo with an\n * istanbul provider in node is used.\n */\n public test(\n options: TestConfig = new ZViteTestBuilder()\n .node()\n .istanbul()\n .monorepo()\n .build(),\n ) {\n this.config.test = options;\n return this;\n }\n\n /**\n * Returns the currently built config.\n *\n * @returns\n * The currently built config.\n */\n public build() {\n return cloneDeep(this.config);\n }\n}\n","import { cloneDeep, isUndefined, omitBy } from \"lodash-es\";\nimport type { ServerOptions } from \"vite\";\n\nexport class ZViteServerBuilder {\n private options: ServerOptions = {};\n\n public allowedHost(name: string | string[] | true) {\n if (name === true) {\n this.options.allowedHosts = true;\n } else if (this.options.allowedHosts !== true) {\n const hosts = this.options.allowedHosts || [];\n this.options.allowedHosts = hosts.concat(name);\n }\n\n return this;\n }\n\n public denyAllHosts() {\n delete this.options.allowedHosts;\n return this;\n }\n\n public port(port?: number) {\n this.options.port = port;\n return this;\n }\n\n public strictPort() {\n this.options.strictPort = true;\n return this;\n }\n\n public host(ip: string) {\n this.options.host = ip;\n return this;\n }\n\n public localhost = this.host.bind(this, \"127.0.0.1\");\n\n public dev() {\n return this.strictPort().host(\"0.0.0.0\").allowedHost(true);\n }\n\n public build() {\n const clone = cloneDeep(this.options);\n return omitBy<ServerOptions>(clone, isUndefined) as ServerOptions;\n }\n}\n"],"names":["cloneDeep","castArray","externalizeDeps","checker","omitBy","isUndefined"],"mappings":";;;;;;;;;AAMO,MAAM,oBAAoB;AAAA,EAA1B,cAAA;AACL,SAAQ,UAA0B;AAAA,MAChC,OAAO,CAAC;AAAA,MACR,SAAS,CAAC,MAAM,KAAK;AAAA,IACvB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,MAAM,MAAc,MAAc;AACvC,SAAK,QAAQ,QAAQ;AAAA,MACnB,GAAI,KAAK,QAAQ;AAAA,MACjB,CAAC,IAAI,GAAG;AAAA,IACV;AACO,WAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUF,QAAQ;AACN,WAAA,KAAK,MAAM,SAAS,iBAAiB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASvC,QAAQ;AACN,WAAAA,SAAA,UAAU,KAAK,OAAO;AAAA,EAAA;AAEjC;AC7CO,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAMrB,cAAc;AA+BrB,SAAO,OAAO,KAAK,YAAY,KAAK,MAAM,MAAM;AAQhD,SAAO,UAAU,KAAK,YAAY,KAAK,MAAM,WAAW;AAsBxD,SAAO,KAAK,KAAK,SAAS,KAAK,MAAM,IAAI;AAQzC,SAAO,WAAW,KAAK,SAAS,KAAK,MAAM,UAAU;AApEnD,SAAK,OAAO;AAAA,MACV,aAAa;AAAA,MACb,aAA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MAAe;AACzB,SAAK,QAAQ,OAAO;AACb,WAAA;AAAA,EAAA;AAAA,EAGF,aAAa;AAClB,SAAK,QAAQ,aAAa;AACnB,WAAA;AAAA,EAAA;AAAA,EAGF,KAAK,IAAY;AACtB,SAAK,QAAQ,OAAO;AACb,WAAA;AAAA,EAAA;AAAA,EAKF,MAAM;AACX,WAAO,KAAK,aAAa,KAAK,SAAS,EAAE,YAAY,IAAI;AAAA,EAAA;AAAA,EAGpD,QAAQ;AACP,UAAA,QAAQA,SAAAA,UAAU,KAAK,OAAO;AAC7B,WAAAI,SAAA,OAAsB,OAAOC,oBAAW;AAAA,EAAA;AAEnD;;;;;"}
1
+ {"version":3,"file":"vite.cjs","sources":["../src/vite/vite-library-builder.mts","../src/vite/vite-test-builder.mts","../src/vite/vite-config-builder.mts","../src/vite/vite-server-builder.mts"],"sourcesContent":["import { cloneDeep } from \"lodash-es\";\nimport type { LibraryOptions } from \"vite\";\n\n/**\n * A builder for Vite library configurations.\n */\nexport class ZViteLibraryBuilder {\n private library: LibraryOptions = {\n entry: {},\n formats: [\"es\", \"cjs\"],\n };\n\n /**\n * Adds an entry point to the library.\n *\n * @param name -\n * The name of the entry point.\n * @param path -\n * The path to the entry point file.\n *\n * @returns\n * This object.\n */\n public entry(name: string, path: string) {\n this.library.entry = {\n ...(this.library.entry as Record<string, string>),\n [name]: path,\n };\n return this;\n }\n\n /**\n * A shorthand for adding an entry point\n * named \"index\" that points to \"src/index.ts\"\n *\n * @returns\n * This object.\n */\n public index() {\n return this.entry(\"index\", \"./src/index.mts\");\n }\n\n /**\n * Returns the built library configuration.\n *\n * @returns\n * A deep clone of the library configuration.\n */\n public build() {\n return cloneDeep(this.library);\n }\n}\n","import { cloneDeep } from \"lodash-es\";\nimport type { InlineConfig, VitestEnvironment } from \"vitest/node\";\n\n/**\n * A builder for test configurations found in vite's defineConfig test field.\n */\nexport class ZViteTestBuilder {\n private test: InlineConfig;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this.test = {\n environment: \"node\",\n testTimeout: 30000,\n coverage: {\n all: false,\n provider: undefined,\n },\n };\n }\n\n /**\n * Sets the test environment.\n *\n * @param environment -\n * The test environment to use.\n *\n * @returns\n * This object.\n */\n public environment(environment: VitestEnvironment) {\n this.test.environment = environment;\n return this;\n }\n\n /**\n * Sets the test environment to \"node\".\n *\n * @returns\n * This object.\n */\n public node = this.environment.bind(this, \"node\");\n\n /**\n * Sets the test environment to \"happy-dom\".\n *\n * @returns\n * This object.\n */\n public browser = this.environment.bind(this, \"happy-dom\");\n\n /**\n * Sets the test coverage provider.\n *\n * @param provider -\n * The test coverage provider to use.\n *\n * @returns\n * This object.\n */\n public coverage(provider: \"v8\" | \"istanbul\") {\n this.test.coverage = { ...this.test.coverage, provider };\n return this;\n }\n\n /**\n * Sets the test coverage provider to \"v8\".\n *\n * @returns\n * This object.\n */\n public v8 = this.coverage.bind(this, \"v8\");\n\n /**\n * Sets the test coverage provider to \"istanbul\".\n *\n * @returns\n * This object.\n */\n public istanbul = this.coverage.bind(this, \"istanbul\");\n\n /**\n * Adds to the list of projects.\n *\n * @param project -\n * The list of projects.\n *\n * @returns\n * This object.\n */\n public project(project: string | string[] = []) {\n const projects = this.test.projects || [];\n this.test.projects = projects.concat(project);\n return this;\n }\n\n /**\n * Adds monorepo support to the test builder.\n *\n * @param packages -\n * The path to the package directory.\n *\n * @returns\n * This object.\n */\n public monorepo(packages = \"packages\") {\n return this.project(`${packages}/*/vitest.config.{js,cjs,mjs,ts,mts}`);\n }\n\n /**\n * Returns the built test configuration.\n *\n * @returns\n * A deep clone of the test configuration.\n */\n public build() {\n return cloneDeep(this.test);\n }\n}\n","import react from \"@vitejs/plugin-react\";\nimport { castArray, cloneDeep } from \"lodash-es\";\nimport swc from \"unplugin-swc\";\nimport type {\n LibraryOptions,\n PluginOption,\n ServerOptions,\n UserConfig,\n} from \"vite\";\nimport { checker } from \"vite-plugin-checker\";\nimport dtsPlugin from \"vite-plugin-dts\";\nimport { externalizeDeps } from \"vite-plugin-externalize-deps\";\nimport tsConfigPaths from \"vite-tsconfig-paths\";\nimport type { InlineConfig as TestConfig } from \"vitest/node.js\";\nimport { ZViteLibraryBuilder } from \"./vite-library-builder.mjs\";\nimport { ZViteTestBuilder } from \"./vite-test-builder.mjs\";\n\n/**\n * A config builder for the vite build system.\n *\n * This is helpful when building different types\n * of projects and keeping a standard.\n *\n * @example vite.config.ts\n *\n * ```ts\n * // Before Config Builder\n * export default defineConfig({\n * build: {\n * lib: {\n * entry: {\n * index: \"./src/index.ts\",\n * },\n * formats: [\"cjs\", \"es\"],\n * },\n * },\n * minify: false,\n * sourceMap: true,\n * plugins: [\n * swc.vite(),\n * tsConfigPaths(),\n * externalizeDeps(),\n * dtsPlugin({\n * compilerOptions: {\n * paths: {},\n * },\n * }),\n * ],\n * });\n * ```\n *\n * ```ts\n * // After config builder\n * const config = new ZViteConfigBuilder().library().build();\n * export default defineConfig(config);\n * ```\n */\nexport class ZViteConfigBuilder {\n private config: UserConfig;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this.config = {\n build: {\n minify: true,\n sourcemap: false,\n },\n plugins: [tsConfigPaths()],\n };\n }\n\n /**\n * Sets whether to minify the build output.\n *\n * @param minify -\n * The flag as to minify the output.\n *\n * @returns\n * This object.\n */\n public minify(minify = true) {\n this.config.build = { ...this.config.build, minify };\n return this;\n }\n\n /**\n * Adds a list of plugins.\n *\n * @param option -\n * The plugins to add.\n *\n * @returns\n * This object.\n */\n public plugin(option: PluginOption | PluginOption[] = []) {\n // See constructor - the config plugins are guaranteed to\n // be set. The swc and paths plugins are automatically added.\n const plugins = this.config.plugins!;\n this.config.plugins = plugins.concat(castArray(option));\n return this;\n }\n\n /**\n * Adds the swc plugin.\n *\n * This is mostly for nest projects as nest requires\n * swc to support decorators.\n */\n public swc() {\n return this.plugin(swc.vite());\n }\n\n /**\n * Sets whether to generate source maps.\n *\n * @param sourcemap -\n * True to generate a sourcemap, false for faster build.\n *\n * @returns\n * This object.\n */\n public sourceMap(sourcemap = true) {\n this.config.build = { ...this.config.build, sourcemap };\n return this;\n }\n\n /**\n * Adds an alias to the resolution options.\n *\n * @param key -\n * The name of the package to alias\n * @param value -\n * The alias resolution\n *\n * @returns\n * This object.\n */\n public alias(key: string, value: string) {\n this.config.resolve = this.config.resolve || {};\n this.config.resolve.alias = this.config.resolve.alias || {};\n this.config.resolve.alias[key] = value;\n return this;\n }\n\n /**\n * Adds an alias for lodash to lodash-es.\n *\n * @returns\n * This object.\n */\n public lodash = this.alias.bind(this, \"lodash\", \"lodash-es\");\n\n /**\n * Assigns the server options.\n *\n * @param options -\n * The server options to assign.\n *\n * @returns\n * This object.\n */\n public server(options: ServerOptions) {\n this.config.server = cloneDeep(options);\n return this;\n }\n\n /**\n * Sets vite into library mode.\n *\n * @param lib -\n * The options for the library. You can set this to\n * nothing to use the default library which looks for\n * an entry point at the source directory called index.ts\n *\n * @see {@link ZViteLibraryBuilder} for more information.\n *\n * @returns\n * This object.\n */\n public library(\n lib: LibraryOptions = new ZViteLibraryBuilder().index().build(),\n ) {\n this.config.build = { ...this.config.build, lib };\n\n const dts = dtsPlugin({\n compilerOptions: {\n // Always turn off paths when building for production. You want to make\n // sure that your build is building in the correct order and that your\n // actual paths are correct.\n paths: {},\n },\n });\n const external = externalizeDeps();\n\n return this.minify(false).sourceMap().plugin(external).plugin(dts);\n }\n\n /**\n * Constructs the config to act as if it's compiling a node application.\n *\n * This is just an alias to {@link ZViteConfigBuilder.library} with two\n * entry points.\n *\n * 1. The file src/cli.ts is the main entry point of the application.\n * 1. The file, src/index.ts, is the api for importing\n *\n * @returns\n * This object.\n */\n public cli() {\n // A cli works similar to a library.\n const library = new ZViteLibraryBuilder()\n .entry(\"index\", \"src/index.mts\")\n .entry(\"cli\", \"src/cli.mts\")\n .build();\n return this.library(library);\n }\n\n /**\n * Constructs the config to act as if it's compiling a nest application.\n *\n * This is just an alias to {@link ZViteConfigBuilder.library} with a single\n * entry point.\n *\n * 1. The file, src/main.mts\n *\n * @returns\n * This object.\n */\n public nest() {\n const library = new ZViteLibraryBuilder()\n .entry(\"main\", \"src/main.mts\")\n .build();\n return this.library(library).swc();\n }\n\n /**\n * Constructs the config to act as if it's compiling a web application.\n *\n * @returns\n * This object.\n */\n public web() {\n return this.minify()\n .sourceMap(false)\n .plugin(checker({ typescript: true }));\n }\n\n /**\n * Constructs the config to compile a react application.\n *\n * @returns\n * This object.\n */\n public react() {\n return this.web().plugin(react());\n }\n\n /**\n * Constructs the config to be for testing.\n *\n * @param options -\n * The test config to use. If this is falsy,\n * then a test setup using a monorepo with an\n * istanbul provider in node is used.\n */\n public test(\n options: TestConfig = new ZViteTestBuilder()\n .node()\n .istanbul()\n .monorepo()\n .build(),\n ) {\n this.config.test = options;\n return this;\n }\n\n /**\n * Returns the currently built config.\n *\n * @returns\n * The currently built config.\n */\n public build() {\n return cloneDeep(this.config);\n }\n}\n","import { cloneDeep, isUndefined, omitBy } from \"lodash-es\";\nimport type { ServerOptions } from \"vite\";\n\nexport class ZViteServerBuilder {\n private options: ServerOptions = {};\n\n public allowedHost(name: string | string[] | true) {\n if (name === true) {\n this.options.allowedHosts = true;\n } else if (this.options.allowedHosts !== true) {\n const hosts = this.options.allowedHosts || [];\n this.options.allowedHosts = hosts.concat(name);\n }\n\n return this;\n }\n\n public denyAllHosts() {\n delete this.options.allowedHosts;\n return this;\n }\n\n public port(port?: number) {\n this.options.port = port;\n return this;\n }\n\n public strictPort() {\n this.options.strictPort = true;\n return this;\n }\n\n public host(ip: string) {\n this.options.host = ip;\n return this;\n }\n\n public localhost = this.host.bind(this, \"127.0.0.1\");\n\n public dev() {\n return this.strictPort().host(\"0.0.0.0\").allowedHost(true);\n }\n\n public build() {\n const clone = cloneDeep(this.options);\n return omitBy<ServerOptions>(clone, isUndefined) as ServerOptions;\n }\n}\n"],"names":["cloneDeep","castArray","externalizeDeps","checker","omitBy","isUndefined"],"mappings":";;;;;;;;;AAMO,MAAM,oBAAoB;AAAA,E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;AACb,WAAA;AAAA,EAAA;AAAA,EAGF,aAAa;AAClB,SAAK,QAAQ,aAAa;AACnB,WAAA;AAAA,EAAA;AAAA,EAGF,KAAK,IAAY;AACtB,SAAK,QAAQ,OAAO;AACb,WAAA;AAAA,EAAA;AAAA,EAKF,MAAM;AACX,WAAO,KAAK,aAAa,KAAK,SAAS,EAAE,YAAY,IAAI;AAAA,EAAA;AAAA,EAGpD,QAAQ;AACP,UAAA,QAAQA,SAAAA,UAAU,KAAK,OAAO;AAC7B,WAAAI,SAAA,OAAsB,OAAOC,oBAAW;AAAA,EAAA;AAEnD;;;;;"}
package/dist/vite.js CHANGED
@@ -135,6 +135,7 @@ class ZViteConfigBuilder {
135
135
  * Initializes a new instance of this object.
136
136
  */
137
137
  constructor() {
138
+ this.lodash = this.alias.bind(this, "lodash", "lodash-es");
138
139
  this.config = {
139
140
  build: {
140
141
  minify: true,
@@ -192,6 +193,23 @@ class ZViteConfigBuilder {
192
193
  this.config.build = { ...this.config.build, sourcemap };
193
194
  return this;
194
195
  }
196
+ /**
197
+ * Adds an alias to the resolution options.
198
+ *
199
+ * @param key -
200
+ * The name of the package to alias
201
+ * @param value -
202
+ * The alias resolution
203
+ *
204
+ * @returns
205
+ * This object.
206
+ */
207
+ alias(key, value) {
208
+ this.config.resolve = this.config.resolve || {};
209
+ this.config.resolve.alias = this.config.resolve.alias || {};
210
+ this.config.resolve.alias[key] = value;
211
+ return this;
212
+ }
195
213
  /**
196
214
  * Assigns the server options.
197
215
  *
package/dist/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vite.js","sources":["../src/vite/vite-library-builder.mts","../src/vite/vite-test-builder.mts","../src/vite/vite-config-builder.mts","../src/vite/vite-server-builder.mts"],"sourcesContent":["import { cloneDeep } from \"lodash-es\";\nimport type { LibraryOptions } from \"vite\";\n\n/**\n * A builder for Vite library configurations.\n */\nexport class ZViteLibraryBuilder {\n private library: LibraryOptions = {\n entry: {},\n formats: [\"es\", \"cjs\"],\n };\n\n /**\n * Adds an entry point to the library.\n *\n * @param name -\n * The name of the entry point.\n * @param path -\n * The path to the entry point file.\n *\n * @returns\n * This object.\n */\n public entry(name: string, path: string) {\n this.library.entry = {\n ...(this.library.entry as Record<string, string>),\n [name]: path,\n };\n return this;\n }\n\n /**\n * A shorthand for adding an entry point\n * named \"index\" that points to \"src/index.ts\"\n *\n * @returns\n * This object.\n */\n public index() {\n return this.entry(\"index\", \"./src/index.mts\");\n }\n\n /**\n * Returns the built library configuration.\n *\n * @returns\n * A deep clone of the library configuration.\n */\n public build() {\n return cloneDeep(this.library);\n }\n}\n","import { cloneDeep } from \"lodash-es\";\nimport type { InlineConfig, VitestEnvironment } from \"vitest/node\";\n\n/**\n * A builder for test configurations found in vite's defineConfig test field.\n */\nexport class ZViteTestBuilder {\n private test: InlineConfig;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this.test = {\n environment: \"node\",\n testTimeout: 30000,\n coverage: {\n all: false,\n provider: undefined,\n },\n };\n }\n\n /**\n * Sets the test environment.\n *\n * @param environment -\n * The test environment to use.\n *\n * @returns\n * This object.\n */\n public environment(environment: VitestEnvironment) {\n this.test.environment = environment;\n return this;\n }\n\n /**\n * Sets the test environment to \"node\".\n *\n * @returns\n * This object.\n */\n public node = this.environment.bind(this, \"node\");\n\n /**\n * Sets the test environment to \"happy-dom\".\n *\n * @returns\n * This object.\n */\n public browser = this.environment.bind(this, \"happy-dom\");\n\n /**\n * Sets the test coverage provider.\n *\n * @param provider -\n * The test coverage provider to use.\n *\n * @returns\n * This object.\n */\n public coverage(provider: \"v8\" | \"istanbul\") {\n this.test.coverage = { ...this.test.coverage, provider };\n return this;\n }\n\n /**\n * Sets the test coverage provider to \"v8\".\n *\n * @returns\n * This object.\n */\n public v8 = this.coverage.bind(this, \"v8\");\n\n /**\n * Sets the test coverage provider to \"istanbul\".\n *\n * @returns\n * This object.\n */\n public istanbul = this.coverage.bind(this, \"istanbul\");\n\n /**\n * Adds to the list of projects.\n *\n * @param project -\n * The list of projects.\n *\n * @returns\n * This object.\n */\n public project(project: string | string[] = []) {\n const projects = this.test.projects || [];\n this.test.projects = projects.concat(project);\n return this;\n }\n\n /**\n * Adds monorepo support to the test builder.\n *\n * @param packages -\n * The path to the package directory.\n *\n * @returns\n * This object.\n */\n public monorepo(packages = \"packages\") {\n return this.project(`${packages}/*/vitest.config.{js,cjs,mjs,ts,mts}`);\n }\n\n /**\n * Returns the built test configuration.\n *\n * @returns\n * A deep clone of the test configuration.\n */\n public build() {\n return cloneDeep(this.test);\n }\n}\n","import react from \"@vitejs/plugin-react\";\nimport { castArray, cloneDeep } from \"lodash-es\";\nimport swc from \"unplugin-swc\";\nimport type {\n LibraryOptions,\n PluginOption,\n ServerOptions,\n UserConfig,\n} from \"vite\";\nimport { checker } from \"vite-plugin-checker\";\nimport dtsPlugin from \"vite-plugin-dts\";\nimport { externalizeDeps } from \"vite-plugin-externalize-deps\";\nimport tsConfigPaths from \"vite-tsconfig-paths\";\nimport type { InlineConfig as TestConfig } from \"vitest/node.js\";\nimport { ZViteLibraryBuilder } from \"./vite-library-builder.mjs\";\nimport { ZViteTestBuilder } from \"./vite-test-builder.mjs\";\n\n/**\n * A config builder for the vite build system.\n *\n * This is helpful when building different types\n * of projects and keeping a standard.\n *\n * @example vite.config.ts\n *\n * ```ts\n * // Before Config Builder\n * export default defineConfig({\n * build: {\n * lib: {\n * entry: {\n * index: \"./src/index.ts\",\n * },\n * formats: [\"cjs\", \"es\"],\n * },\n * },\n * minify: false,\n * sourceMap: true,\n * plugins: [\n * swc.vite(),\n * tsConfigPaths(),\n * externalizeDeps(),\n * dtsPlugin({\n * compilerOptions: {\n * paths: {},\n * },\n * }),\n * ],\n * });\n * ```\n *\n * ```ts\n * // After config builder\n * const config = new ZViteConfigBuilder().library().build();\n * export default defineConfig(config);\n * ```\n */\nexport class ZViteConfigBuilder {\n private config: UserConfig;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this.config = {\n build: {\n minify: true,\n sourcemap: false,\n },\n plugins: [tsConfigPaths()],\n };\n }\n\n /**\n * Sets whether to minify the build output.\n *\n * @param minify -\n * The flag as to minify the output.\n *\n * @returns\n * This object.\n */\n public minify(minify = true) {\n this.config.build = { ...this.config.build, minify };\n return this;\n }\n\n /**\n * Adds a list of plugins.\n *\n * @param option -\n * The plugins to add.\n *\n * @returns\n * This object.\n */\n public plugin(option: PluginOption | PluginOption[] = []) {\n // See constructor - the config plugins are guaranteed to\n // be set. The swc and paths plugins are automatically added.\n const plugins = this.config.plugins!;\n this.config.plugins = plugins.concat(castArray(option));\n return this;\n }\n\n /**\n * Adds the swc plugin.\n *\n * This is mostly for nest projects as nest requires\n * swc to support decorators.\n */\n public swc() {\n return this.plugin(swc.vite());\n }\n\n /**\n * Sets whether to generate source maps.\n *\n * @param sourcemap -\n * True to generate a sourcemap, false for faster build.\n *\n * @returns\n * This object.\n */\n public sourceMap(sourcemap = true) {\n this.config.build = { ...this.config.build, sourcemap };\n return this;\n }\n\n /**\n * Assigns the server options.\n *\n * @param options -\n * The server options to assign.\n *\n * @returns\n * This object.\n */\n public server(options: ServerOptions) {\n this.config.server = cloneDeep(options);\n return this;\n }\n\n /**\n * Sets vite into library mode.\n *\n * @param lib -\n * The options for the library. You can set this to\n * nothing to use the default library which looks for\n * an entry point at the source directory called index.ts\n *\n * @see {@link ZViteLibraryBuilder} for more information.\n *\n * @returns\n * This object.\n */\n public library(\n lib: LibraryOptions = new ZViteLibraryBuilder().index().build(),\n ) {\n this.config.build = { ...this.config.build, lib };\n\n const dts = dtsPlugin({\n compilerOptions: {\n // Always turn off paths when building for production. You want to make\n // sure that your build is building in the correct order and that your\n // actual paths are correct.\n paths: {},\n },\n });\n const external = externalizeDeps();\n\n return this.minify(false).sourceMap().plugin(external).plugin(dts);\n }\n\n /**\n * Constructs the config to act as if it's compiling a node application.\n *\n * This is just an alias to {@link ZViteConfigBuilder.library} with two\n * entry points.\n *\n * 1. The file src/cli.ts is the main entry point of the application.\n * 1. The file, src/index.ts, is the api for importing\n *\n * @returns\n * This object.\n */\n public cli() {\n // A cli works similar to a library.\n const library = new ZViteLibraryBuilder()\n .entry(\"index\", \"src/index.mts\")\n .entry(\"cli\", \"src/cli.mts\")\n .build();\n return this.library(library);\n }\n\n /**\n * Constructs the config to act as if it's compiling a nest application.\n *\n * This is just an alias to {@link ZViteConfigBuilder.library} with a single\n * entry point.\n *\n * 1. The file, src/main.mts\n *\n * @returns\n * This object.\n */\n public nest() {\n const library = new ZViteLibraryBuilder()\n .entry(\"main\", \"src/main.mts\")\n .build();\n return this.library(library).swc();\n }\n\n /**\n * Constructs the config to act as if it's compiling a web application.\n *\n * @returns\n * This object.\n */\n public web() {\n return this.minify()\n .sourceMap(false)\n .plugin(checker({ typescript: true }));\n }\n\n /**\n * Constructs the config to compile a react application.\n *\n * @returns\n * This object.\n */\n public react() {\n return this.web().plugin(react());\n }\n\n /**\n * Constructs the config to be for testing.\n *\n * @param options -\n * The test config to use. If this is falsy,\n * then a test setup using a monorepo with an\n * istanbul provider in node is used.\n */\n public test(\n options: TestConfig = new ZViteTestBuilder()\n .node()\n .istanbul()\n .monorepo()\n .build(),\n ) {\n this.config.test = options;\n return this;\n }\n\n /**\n * Returns the currently built config.\n *\n * @returns\n * The currently built config.\n */\n public build() {\n return cloneDeep(this.config);\n }\n}\n","import { cloneDeep, isUndefined, omitBy } from \"lodash-es\";\nimport type { ServerOptions } from \"vite\";\n\nexport class ZViteServerBuilder {\n private options: ServerOptions = {};\n\n public allowedHost(name: string | string[] | true) {\n if (name === true) {\n this.options.allowedHosts = true;\n } else if (this.options.allowedHosts !== true) {\n const hosts = this.options.allowedHosts || [];\n this.options.allowedHosts = hosts.concat(name);\n }\n\n return this;\n }\n\n public denyAllHosts() {\n delete this.options.allowedHosts;\n return this;\n }\n\n public port(port?: number) {\n this.options.port = port;\n return this;\n }\n\n public strictPort() {\n this.options.strictPort = true;\n return this;\n }\n\n public host(ip: string) {\n this.options.host = ip;\n return this;\n }\n\n public localhost = this.host.bind(this, \"127.0.0.1\");\n\n public dev() {\n return this.strictPort().host(\"0.0.0.0\").allowedHost(true);\n }\n\n public build() {\n const clone = cloneDeep(this.options);\n return omitBy<ServerOptions>(clone, isUndefined) as ServerOptions;\n }\n}\n"],"names":[],"mappings":";;;;;;;AAMO,MAAM,oBAAoB;AAAA,EAA1B,cAAA;AACL,SAAQ,UAA0B;AAAA,MAChC,OAAO,CAAC;AAAA,MACR,SAAS,CAAC,MAAM,KAAK;AAAA,IACvB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,MAAM,MAAc,MAAc;AACvC,SAAK,QAAQ,QAAQ;AAAA,MACnB,GAAI,KAAK,QAAQ;AAAA,MACjB,CAAC,IAAI,GAAG;AAAA,IACV;AACO,WAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUF,QAAQ;AACN,WAAA,KAAK,MAAM,SAAS,iBAAiB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASvC,QAAQ;AACN,WAAA,UAAU,KAAK,OAAO;AAAA,EAAA;AAEjC;AC7CO,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAMrB,cAAc;AA+BrB,SAAO,OAAO,KAAK,YAAY,KAAK,MAAM,MAAM;AAQhD,SAAO,UAAU,KAAK,YAAY,KAAK,MAAM,WAAW;AAsBxD,SAAO,KAAK,KAAK,SAAS,KAAK,MAAM,IAAI;AAQzC,SAAO,WAAW,KAAK,SAAS,KAAK,MAAM,UAAU;AApEnD,SAAK,OAAO;AAAA,MACV,aAAa;AAAA,MACb,aAAa;AAAA,MACb,UAAU;AAAA,QACR,KAAK;AAAA,QACL,UAAU;AAAA,MAAA;AAAA,IAEd;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYK,YA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EAKF,MAAM;AACX,WAAO,KAAK,aAAa,KAAK,SAAS,EAAE,YAAY,IAAI;AAAA,EAAA;AAAA,EAGpD,QAAQ;AACP,UAAA,QAAQ,UAAU,KAAK,OAAO;AAC7B,WAAA,OAAsB,OAAO,WAAW;AAAA,EAAA;AAEnD;"}
1
+ {"version":3,"file":"vite.js","sources":["../src/vite/vite-library-builder.mts","../src/vite/vite-test-builder.mts","../src/vite/vite-config-builder.mts","../src/vite/vite-server-builder.mts"],"sourcesContent":["import { cloneDeep } from \"lodash-es\";\nimport type { LibraryOptions } from \"vite\";\n\n/**\n * A builder for Vite library configurations.\n */\nexport class ZViteLibraryBuilder {\n private library: LibraryOptions = {\n entry: {},\n formats: [\"es\", \"cjs\"],\n };\n\n /**\n * Adds an entry point to the library.\n *\n * @param name -\n * The name of the entry point.\n * @param path -\n * The path to the entry point file.\n *\n * @returns\n * This object.\n */\n public entry(name: string, path: string) {\n this.library.entry = {\n ...(this.library.entry as Record<string, string>),\n [name]: path,\n };\n return this;\n }\n\n /**\n * A shorthand for adding an entry point\n * named \"index\" that points to \"src/index.ts\"\n *\n * @returns\n * This object.\n */\n public index() {\n return this.entry(\"index\", \"./src/index.mts\");\n }\n\n /**\n * Returns the built library configuration.\n *\n * @returns\n * A deep clone of the library configuration.\n */\n public build() {\n return cloneDeep(this.library);\n }\n}\n","import { cloneDeep } from \"lodash-es\";\nimport type { InlineConfig, VitestEnvironment } from \"vitest/node\";\n\n/**\n * A builder for test configurations found in vite's defineConfig test field.\n */\nexport class ZViteTestBuilder {\n private test: InlineConfig;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this.test = {\n environment: \"node\",\n testTimeout: 30000,\n coverage: {\n all: false,\n provider: undefined,\n },\n };\n }\n\n /**\n * Sets the test environment.\n *\n * @param environment -\n * The test environment to use.\n *\n * @returns\n * This object.\n */\n public environment(environment: VitestEnvironment) {\n this.test.environment = environment;\n return this;\n }\n\n /**\n * Sets the test environment to \"node\".\n *\n * @returns\n * This object.\n */\n public node = this.environment.bind(this, \"node\");\n\n /**\n * Sets the test environment to \"happy-dom\".\n *\n * @returns\n * This object.\n */\n public browser = this.environment.bind(this, \"happy-dom\");\n\n /**\n * Sets the test coverage provider.\n *\n * @param provider -\n * The test coverage provider to use.\n *\n * @returns\n * This object.\n */\n public coverage(provider: \"v8\" | \"istanbul\") {\n this.test.coverage = { ...this.test.coverage, provider };\n return this;\n }\n\n /**\n * Sets the test coverage provider to \"v8\".\n *\n * @returns\n * This object.\n */\n public v8 = this.coverage.bind(this, \"v8\");\n\n /**\n * Sets the test coverage provider to \"istanbul\".\n *\n * @returns\n * This object.\n */\n public istanbul = this.coverage.bind(this, \"istanbul\");\n\n /**\n * Adds to the list of projects.\n *\n * @param project -\n * The list of projects.\n *\n * @returns\n * This object.\n */\n public project(project: string | string[] = []) {\n const projects = this.test.projects || [];\n this.test.projects = projects.concat(project);\n return this;\n }\n\n /**\n * Adds monorepo support to the test builder.\n *\n * @param packages -\n * The path to the package directory.\n *\n * @returns\n * This object.\n */\n public monorepo(packages = \"packages\") {\n return this.project(`${packages}/*/vitest.config.{js,cjs,mjs,ts,mts}`);\n }\n\n /**\n * Returns the built test configuration.\n *\n * @returns\n * A deep clone of the test configuration.\n */\n public build() {\n return cloneDeep(this.test);\n }\n}\n","import react from \"@vitejs/plugin-react\";\nimport { castArray, cloneDeep } from \"lodash-es\";\nimport swc from \"unplugin-swc\";\nimport type {\n LibraryOptions,\n PluginOption,\n ServerOptions,\n UserConfig,\n} from \"vite\";\nimport { checker } from \"vite-plugin-checker\";\nimport dtsPlugin from \"vite-plugin-dts\";\nimport { externalizeDeps } from \"vite-plugin-externalize-deps\";\nimport tsConfigPaths from \"vite-tsconfig-paths\";\nimport type { InlineConfig as TestConfig } from \"vitest/node.js\";\nimport { ZViteLibraryBuilder } from \"./vite-library-builder.mjs\";\nimport { ZViteTestBuilder } from \"./vite-test-builder.mjs\";\n\n/**\n * A config builder for the vite build system.\n *\n * This is helpful when building different types\n * of projects and keeping a standard.\n *\n * @example vite.config.ts\n *\n * ```ts\n * // Before Config Builder\n * export default defineConfig({\n * build: {\n * lib: {\n * entry: {\n * index: \"./src/index.ts\",\n * },\n * formats: [\"cjs\", \"es\"],\n * },\n * },\n * minify: false,\n * sourceMap: true,\n * plugins: [\n * swc.vite(),\n * tsConfigPaths(),\n * externalizeDeps(),\n * dtsPlugin({\n * compilerOptions: {\n * paths: {},\n * },\n * }),\n * ],\n * });\n * ```\n *\n * ```ts\n * // After config builder\n * const config = new ZViteConfigBuilder().library().build();\n * export default defineConfig(config);\n * ```\n */\nexport class ZViteConfigBuilder {\n private config: UserConfig;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this.config = {\n build: {\n minify: true,\n sourcemap: false,\n },\n plugins: [tsConfigPaths()],\n };\n }\n\n /**\n * Sets whether to minify the build output.\n *\n * @param minify -\n * The flag as to minify the output.\n *\n * @returns\n * This object.\n */\n public minify(minify = true) {\n this.config.build = { ...this.config.build, minify };\n return this;\n }\n\n /**\n * Adds a list of plugins.\n *\n * @param option -\n * The plugins to add.\n *\n * @returns\n * This object.\n */\n public plugin(option: PluginOption | PluginOption[] = []) {\n // See constructor - the config plugins are guaranteed to\n // be set. The swc and paths plugins are automatically added.\n const plugins = this.config.plugins!;\n this.config.plugins = plugins.concat(castArray(option));\n return this;\n }\n\n /**\n * Adds the swc plugin.\n *\n * This is mostly for nest projects as nest requires\n * swc to support decorators.\n */\n public swc() {\n return this.plugin(swc.vite());\n }\n\n /**\n * Sets whether to generate source maps.\n *\n * @param sourcemap -\n * True to generate a sourcemap, false for faster build.\n *\n * @returns\n * This object.\n */\n public sourceMap(sourcemap = true) {\n this.config.build = { ...this.config.build, sourcemap };\n return this;\n }\n\n /**\n * Adds an alias to the resolution options.\n *\n * @param key -\n * The name of the package to alias\n * @param value -\n * The alias resolution\n *\n * @returns\n * This object.\n */\n public alias(key: string, value: string) {\n this.config.resolve = this.config.resolve || {};\n this.config.resolve.alias = this.config.resolve.alias || {};\n this.config.resolve.alias[key] = value;\n return this;\n }\n\n /**\n * Adds an alias for lodash to lodash-es.\n *\n * @returns\n * This object.\n */\n public lodash = this.alias.bind(this, \"lodash\", \"lodash-es\");\n\n /**\n * Assigns the server options.\n *\n * @param options -\n * The server options to assign.\n *\n * @returns\n * This object.\n */\n public server(options: ServerOptions) {\n this.config.server = cloneDeep(options);\n return this;\n }\n\n /**\n * Sets vite into library mode.\n *\n * @param lib -\n * The options for the library. You can set this to\n * nothing to use the default library which looks for\n * an entry point at the source directory called index.ts\n *\n * @see {@link ZViteLibraryBuilder} for more information.\n *\n * @returns\n * This object.\n */\n public library(\n lib: LibraryOptions = new ZViteLibraryBuilder().index().build(),\n ) {\n this.config.build = { ...this.config.build, lib };\n\n const dts = dtsPlugin({\n compilerOptions: {\n // Always turn off paths when building for production. You want to make\n // sure that your build is building in the correct order and that your\n // actual paths are correct.\n paths: {},\n },\n });\n const external = externalizeDeps();\n\n return this.minify(false).sourceMap().plugin(external).plugin(dts);\n }\n\n /**\n * Constructs the config to act as if it's compiling a node application.\n *\n * This is just an alias to {@link ZViteConfigBuilder.library} with two\n * entry points.\n *\n * 1. The file src/cli.ts is the main entry point of the application.\n * 1. The file, src/index.ts, is the api for importing\n *\n * @returns\n * This object.\n */\n public cli() {\n // A cli works similar to a library.\n const library = new ZViteLibraryBuilder()\n .entry(\"index\", \"src/index.mts\")\n .entry(\"cli\", \"src/cli.mts\")\n .build();\n return this.library(library);\n }\n\n /**\n * Constructs the config to act as if it's compiling a nest application.\n *\n * This is just an alias to {@link ZViteConfigBuilder.library} with a single\n * entry point.\n *\n * 1. The file, src/main.mts\n *\n * @returns\n * This object.\n */\n public nest() {\n const library = new ZViteLibraryBuilder()\n .entry(\"main\", \"src/main.mts\")\n .build();\n return this.library(library).swc();\n }\n\n /**\n * Constructs the config to act as if it's compiling a web application.\n *\n * @returns\n * This object.\n */\n public web() {\n return this.minify()\n .sourceMap(false)\n .plugin(checker({ typescript: true }));\n }\n\n /**\n * Constructs the config to compile a react application.\n *\n * @returns\n * This object.\n */\n public react() {\n return this.web().plugin(react());\n }\n\n /**\n * Constructs the config to be for testing.\n *\n * @param options -\n * The test config to use. If this is falsy,\n * then a test setup using a monorepo with an\n * istanbul provider in node is used.\n */\n public test(\n options: TestConfig = new ZViteTestBuilder()\n .node()\n .istanbul()\n .monorepo()\n .build(),\n ) {\n this.config.test = options;\n return this;\n }\n\n /**\n * Returns the currently built config.\n *\n * @returns\n * The currently built config.\n */\n public build() {\n return cloneDeep(this.config);\n }\n}\n","import { cloneDeep, isUndefined, omitBy } from \"lodash-es\";\nimport type { ServerOptions } from \"vite\";\n\nexport class ZViteServerBuilder {\n private options: ServerOptions = {};\n\n public allowedHost(name: string | string[] | true) {\n if (name === true) {\n this.options.allowedHosts = true;\n } else if (this.options.allowedHosts !== true) {\n const hosts = this.options.allowedHosts || [];\n this.options.allowedHosts = hosts.concat(name);\n }\n\n return this;\n }\n\n public denyAllHosts() {\n delete this.options.allowedHosts;\n return this;\n }\n\n public port(port?: number) {\n this.options.port = port;\n return this;\n }\n\n public strictPort() {\n this.options.strictPort = true;\n return this;\n }\n\n public host(ip: string) {\n this.options.host = ip;\n return this;\n }\n\n public localhost = this.host.bind(this, \"127.0.0.1\");\n\n public dev() {\n return this.strictPort().host(\"0.0.0.0\").allowedHost(true);\n }\n\n public build() {\n const clone = cloneDeep(this.options);\n return omitBy<ServerOptions>(clone, isUndefined) as ServerOptions;\n }\n}\n"],"names":[],"mappings":";;;;;;;AAMO,MAAM,oBAAoB;AAAA,EAA1B,cAAA;AACL,SAAQ,UAA0B;AAAA,MAChC,OAAO,CAAC;AAAA,MACR,SAAS,CAAC,MAAM,KAAK;AAAA,IACvB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,MAAM,MAAc,MAAc;AACvC,SAAK,QAAQ,QAAQ;AAAA,MACnB,GAAI,KAAK,QAAQ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,OAAsB,OAAO,WAAW;AAAA,EAAA;AAEnD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zthun/janitor-build-config",
3
- "version": "19.1.4",
3
+ "version": "19.2.0",
4
4
  "description": "A shared configuration for builds that create websites, apis, and tests",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.mts",
@@ -31,8 +31,8 @@
31
31
  "dist"
32
32
  ],
33
33
  "dependencies": {
34
- "@swc/core": "^1.11.31",
35
- "@vitejs/plugin-react": "^4.5.1",
34
+ "@swc/core": "^1.12.0",
35
+ "@vitejs/plugin-react": "^4.5.2",
36
36
  "lodash-es": "^4.17.21",
37
37
  "typedoc": "^0.28.5",
38
38
  "unplugin-swc": "^1.5.4",
@@ -41,7 +41,7 @@
41
41
  "vite-plugin-dts": "^4.5.4",
42
42
  "vite-plugin-externalize-deps": "^0.9.0",
43
43
  "vite-tsconfig-paths": "^5.1.4",
44
- "vitest": "^3.2.2"
44
+ "vitest": "^3.2.3"
45
45
  },
46
46
  "devDependencies": {
47
47
  "typescript": "~5.8.3"
@@ -66,5 +66,5 @@
66
66
  "access": "public"
67
67
  },
68
68
  "author": "Anthony Bonta",
69
- "gitHead": "45d010afcb316c9a51ed9d4a8ab19d55ec9b6724"
69
+ "gitHead": "db77877e5b625c261b7d62f0d159b031fbda2e83"
70
70
  }