@kurone-kito/vite-lib-config 0.20.0-alpha.3

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Kuroné Kito (黒音キト)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # ⚡️ `@kurone-kito/vite-lib-config`
2
+
3
+ Vite configuration for CLI and library projects
4
+
5
+ ## System Requirements
6
+
7
+ - Node.js: Any of the following versions
8
+ - Iron LTS (`^20.11.x`)
9
+ - Jod LTS (`^22.x.x`)
10
+ - Latest (`>=24.x.x`)
11
+
12
+ ## Usage
13
+
14
+ ```ts
15
+ import config from '@kurone-kito/vite-lib-config';
16
+ console.log(config); // => {}
17
+ ```
18
+
19
+ ## LICENSE
20
+
21
+ MIT
@@ -0,0 +1,4 @@
1
+ export type { ViteConfigOptions } from './vite.mjs';
2
+ export { viteConfig } from './vite.mjs';
3
+ export { vitestConfig } from './vitest.mjs';
4
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.mjs ADDED
@@ -0,0 +1,55 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import castArray from "lodash-es/castArray.js";
4
+ import shebangRegex from "shebang-regex";
5
+ import { mergeConfig } from "vite";
6
+ import dts from "vite-plugin-dts";
7
+ import { mergeConfig as mergeConfig$1 } from "vitest/config";
8
+ const out = "[name].mjs";
9
+ const staticConfig$1 = {
10
+ build: {
11
+ rollupOptions: {
12
+ output: {
13
+ chunkFileNames: out,
14
+ entryFileNames: out,
15
+ format: "es",
16
+ importAttributesKey: "with"
17
+ }
18
+ },
19
+ sourcemap: true,
20
+ ssr: true,
21
+ target: "node20.11"
22
+ }
23
+ };
24
+ const innerCreateConfig = (entries) => {
25
+ const entry = entries.filter((f) => existsSync(f));
26
+ if (!entry.length) {
27
+ return {};
28
+ }
29
+ const bin = entry.every((f) => shebangRegex.test(readFileSync(f, "utf8")));
30
+ return mergeConfig(staticConfig$1, {
31
+ build: {
32
+ rollupOptions: { input: entry },
33
+ ...bin ? {} : { lib: { entry, formats: ["es"] } }
34
+ },
35
+ plugins: bin ? [] : [dts({ exclude: ["**/*.spec.mts"] })]
36
+ });
37
+ };
38
+ const viteConfig = (overrides = {}, options = {}) => {
39
+ const {
40
+ cwd = process.cwd(),
41
+ entries = "index.mts",
42
+ srcDir = "src"
43
+ } = options;
44
+ const files = castArray(entries).map((e) => resolve(cwd, srcDir, e));
45
+ return mergeConfig(innerCreateConfig(files), overrides);
46
+ };
47
+ const staticConfig = {
48
+ test: { environment: "node" }
49
+ };
50
+ const vitestConfig = (overrides = {}, options = {}) => mergeConfig$1(staticConfig, viteConfig(overrides, options));
51
+ export {
52
+ viteConfig,
53
+ vitestConfig
54
+ };
55
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/vite.mts","../src/vitest.mts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport castArray from 'lodash-es/castArray.js';\nimport shebangRegex from 'shebang-regex';\nimport type { Arrayable } from 'type-fest';\nimport type { UserConfig } from 'vite';\nimport { mergeConfig } from 'vite';\nimport dts from 'vite-plugin-dts';\n\n/**\n * Type definition for options used when creating a Vite configuration.\n * @see {@link viteConfig}\n */\nexport interface ViteConfigOptions {\n /**\n * Base directory of the target project.\n * @default process.cwd()\n */\n readonly cwd?: string | undefined;\n\n /**\n * Entry files relative to {@link srcDir}.\n * @default ['index.mts']\n */\n readonly entries?: Readonly<Arrayable<string>> | undefined;\n\n /**\n * Directory where the source files are located.\n * @default 'src'\n */\n readonly srcDir?: string | undefined;\n}\n\n/** The name of the output file. */\nconst out = '[name].mjs';\n\n/** Static configuration for Vite builds. */\nconst staticConfig = {\n build: {\n rollupOptions: {\n output: {\n chunkFileNames: out,\n entryFileNames: out,\n format: 'es',\n importAttributesKey: 'with',\n },\n },\n sourcemap: true,\n ssr: true,\n target: 'node20.11',\n },\n} as const satisfies UserConfig;\n\n/**\n * Creates a Vite configuration based on the provided entry point.\n *\n * The entry point is `src/index.mts` under the provided working directory.\n * If the file starts with a shebang(`#!...`), the build uses library mode;\n * otherwise it performs an SSR build.\n * @param entries Entry point files for the Vite configuration.\n * @return A Vite {@link UserConfig} object with the configuration\n */\nconst innerCreateConfig = (entries: readonly string[]): UserConfig => {\n const entry = entries.filter((f) => existsSync(f));\n if (!entry.length) {\n return {};\n }\n const bin = entry.every((f) => shebangRegex.test(readFileSync(f, 'utf8')));\n return mergeConfig<UserConfig, UserConfig>(staticConfig, {\n build: {\n rollupOptions: { input: entry },\n ...(bin ? {} : { lib: { entry, formats: ['es'] } }),\n },\n plugins: bin ? [] : [dts({ exclude: ['**/*.spec.mts'] })],\n });\n};\n\n/**\n * Create a Vite configuration for the current project.\n *\n * The entry point is `src/index.mts` under the provided working directory.\n * If the file starts with a shebang(`#!...`), the build uses library mode;\n * otherwise it performs an SSR build. Additional settings can override\n * these defaults via {@link mergeConfig}.\n * @param overrides Additional configuration options to merge with the base\n * config.\n * @param options Options for creating the config, including the working\n * directory.\n * @return A Vite {@link UserConfig} object with the merged configuration.\n */\nexport const viteConfig = (\n overrides: UserConfig = {},\n options: ViteConfigOptions = {},\n): UserConfig => {\n const {\n cwd = process.cwd(),\n entries = 'index.mts',\n srcDir = 'src',\n } = options;\n const files = castArray(entries).map((e) => resolve(cwd, srcDir, e));\n return mergeConfig(innerCreateConfig(files), overrides);\n};\n","import type { ViteUserConfig } from 'vitest/config';\nimport { mergeConfig } from 'vitest/config';\nimport type { ViteConfigOptions } from './vite.mjs';\nimport { viteConfig } from './vite.mjs';\n\n/** Static configuration for Vitest tests. */\nconst staticConfig = {\n test: { environment: 'node' },\n} as const satisfies ViteUserConfig;\n\n/**\n * Create a Vitest configuration for the current project.\n *\n * The entry point is `src/index.mts` under the provided working directory.\n * If the file starts with a shebang(`#!...`), the build uses library mode;\n * otherwise it performs an SSR build. Additional settings can override\n * these defaults via {@link mergeConfig}.\n * @param overrides Additional configuration options to merge with the base\n * config.\n * @param options Options for creating the config, including the working\n * directory.\n * @return A Vitest {@link ViteUserConfig} object with the merged\n * configuration.\n */\nexport const vitestConfig = (\n overrides: ViteUserConfig = {},\n options: ViteConfigOptions = {},\n): ViteUserConfig => mergeConfig(staticConfig, viteConfig(overrides, options));\n"],"names":["staticConfig","mergeConfig"],"mappings":";;;;;;;AAkCA,MAAM,MAAM;AAGZ,MAAMA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+1,38 @@
1
+ import { Arrayable } from 'type-fest';
2
+ import { UserConfig } from 'vite';
3
+ /**
4
+ * Type definition for options used when creating a Vite configuration.
5
+ * @see {@link viteConfig}
6
+ */
7
+ export interface ViteConfigOptions {
8
+ /**
9
+ * Base directory of the target project.
10
+ * @default process.cwd()
11
+ */
12
+ readonly cwd?: string | undefined;
13
+ /**
14
+ * Entry files relative to {@link srcDir}.
15
+ * @default ['index.mts']
16
+ */
17
+ readonly entries?: Readonly<Arrayable<string>> | undefined;
18
+ /**
19
+ * Directory where the source files are located.
20
+ * @default 'src'
21
+ */
22
+ readonly srcDir?: string | undefined;
23
+ }
24
+ /**
25
+ * Create a Vite configuration for the current project.
26
+ *
27
+ * The entry point is `src/index.mts` under the provided working directory.
28
+ * If the file starts with a shebang(`#!...`), the build uses library mode;
29
+ * otherwise it performs an SSR build. Additional settings can override
30
+ * these defaults via {@link mergeConfig}.
31
+ * @param overrides Additional configuration options to merge with the base
32
+ * config.
33
+ * @param options Options for creating the config, including the working
34
+ * directory.
35
+ * @return A Vite {@link UserConfig} object with the merged configuration.
36
+ */
37
+ export declare const viteConfig: (overrides?: UserConfig, options?: ViteConfigOptions) => UserConfig;
38
+ //# sourceMappingURL=vite.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.mts","sourceRoot":"","sources":["../src/vite.mts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIvC;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAElC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;IAE3D;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AA8CD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GACrB,YAAW,UAAe,EAC1B,UAAS,iBAAsB,KAC9B,UAQF,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { ViteUserConfig } from 'vitest/config';
2
+ import { ViteConfigOptions } from './vite.mjs';
3
+ /**
4
+ * Create a Vitest configuration for the current project.
5
+ *
6
+ * The entry point is `src/index.mts` under the provided working directory.
7
+ * If the file starts with a shebang(`#!...`), the build uses library mode;
8
+ * otherwise it performs an SSR build. Additional settings can override
9
+ * these defaults via {@link mergeConfig}.
10
+ * @param overrides Additional configuration options to merge with the base
11
+ * config.
12
+ * @param options Options for creating the config, including the working
13
+ * directory.
14
+ * @return A Vitest {@link ViteUserConfig} object with the merged
15
+ * configuration.
16
+ */
17
+ export declare const vitestConfig: (overrides?: ViteUserConfig, options?: ViteConfigOptions) => ViteUserConfig;
18
+ //# sourceMappingURL=vitest.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest.d.mts","sourceRoot":"","sources":["../src/vitest.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAQpD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GACvB,YAAW,cAAmB,EAC9B,UAAS,iBAAsB,KAC9B,cAA2E,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@kurone-kito/vite-lib-config",
3
+ "version": "0.20.0-alpha.3",
4
+ "description": "The vite configuration package for the workspaces",
5
+ "keywords": [
6
+ "cli",
7
+ "config",
8
+ "vite"
9
+ ],
10
+ "homepage": "https://github.com/kurone-kito/builder-config#readme",
11
+ "bugs": "https://github.com/kurone-kito/builder-config/issues",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/kurone-kito/builder-config.git",
15
+ "directory": "packages/vite-lib-config"
16
+ },
17
+ "license": "MIT",
18
+ "author": "kurone-kito <krone@kit.black> (https://kit.black/)",
19
+ "type": "module",
20
+ "exports": "./dist/index.mjs",
21
+ "types": "./dist/index.d.mts",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {
26
+ "lodash-es": "^4.17.21",
27
+ "shebang-regex": "^4.0.0",
28
+ "vite": "^7.0.0",
29
+ "vite-plugin-dts": "^4.5.4"
30
+ },
31
+ "devDependencies": {
32
+ "@types/lodash-es": "^4.17.12",
33
+ "@types/node": "^24.0.4",
34
+ "@vitest/coverage-v8": "^3.2.4",
35
+ "cpy-cli": "^5.0.0",
36
+ "rimraf": "^6.0.1",
37
+ "type-fest": "^4.41.0",
38
+ "typescript": "~5.8.3",
39
+ "vitest": "^3.2.4",
40
+ "@kurone-kito/typescript-config": "^0.20.0-alpha.3"
41
+ },
42
+ "engines": {
43
+ "node": "^20.11 || ^22 || >=24"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "scripts": {
49
+ "build": "vite build",
50
+ "clean": "rimraf -g \"*.tgz\" \"*.tsbuildinfo\" coverage dist LICENSE node_modules/.cache",
51
+ "dev": "vite build --watch",
52
+ "prebuild": "cpy --flat ../../LICENSE .",
53
+ "test": "vitest run --coverage"
54
+ }
55
+ }