@kurone-kito/vite-lib-config 0.21.0 → 0.22.0-alpha.2

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/dist/index.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
+ import { builtinModules } from "node:module";
2
3
  import { resolve } from "node:path";
4
+ import { nodeResolve } from "@rollup/plugin-node-resolve";
3
5
  import castArray from "lodash-es/castArray.js";
4
6
  import shebangRegex from "shebang-regex";
5
7
  import { mergeConfig } from "vite";
@@ -21,6 +23,21 @@ const staticConfig$1 = {
21
23
  target: "node20.11"
22
24
  }
23
25
  };
26
+ const staticSeaConfig = {
27
+ build: {
28
+ rollupOptions: {
29
+ external: [...builtinModules, ...builtinModules.map((m) => `node:${m}`)],
30
+ output: {
31
+ entryFileNames: "index.cjs",
32
+ format: "cjs",
33
+ inlineDynamicImports: true,
34
+ manualChunks: void 0
35
+ },
36
+ plugins: [nodeResolve({ preferBuiltins: true })]
37
+ }
38
+ },
39
+ ssr: { noExternal: true }
40
+ };
24
41
  const innerCreateConfig = (entries) => {
25
42
  const entry = entries.filter((f) => existsSync(f));
26
43
  if (!entry.length) {
@@ -39,10 +56,15 @@ const viteConfig = (overrides = {}, options = {}) => {
39
56
  const {
40
57
  cwd = process.cwd(),
41
58
  entries = "index.mts",
59
+ sea,
42
60
  srcDir = "src"
43
61
  } = options;
44
62
  const files = castArray(entries).map((e) => resolve(cwd, srcDir, e));
45
- return mergeConfig(innerCreateConfig(files), overrides);
63
+ const seaConfig = sea ? staticSeaConfig : {};
64
+ return mergeConfig(
65
+ innerCreateConfig(files),
66
+ mergeConfig(seaConfig, overrides)
67
+ );
46
68
  };
47
69
  const staticConfig = {
48
70
  test: { environment: "node" }
@@ -1 +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,iBAAe;AAAA,EACnB,OAAO;AAAA,IACL,eAAe;AAAA,MACb,QAAQ;AAAA,QACN,gBAAgB;AAAA,QAChB,gBAAgB;AAAA,QAChB,QAAQ;AAAA,QACR,qBAAqB;AAAA,MAAA;AAAA,IACvB;AAAA,IAEF,WAAW;AAAA,IACX,KAAK;AAAA,IACL,QAAQ;AAAA,EAAA;AAEZ;AAWA,MAAM,oBAAoB,CAAC,YAA2C;AACpE,QAAM,QAAQ,QAAQ,OAAO,CAAC,MAAM,WAAW,CAAC,CAAC;AACjD,MAAI,CAAC,MAAM,QAAQ;AACjB,WAAO,CAAA;AAAA,EACT;AACA,QAAM,MAAM,MAAM,MAAM,CAAC,MAAM,aAAa,KAAK,aAAa,GAAG,MAAM,CAAC,CAAC;AACzE,SAAO,YAAoCA,gBAAc;AAAA,IACvD,OAAO;AAAA,MACL,eAAe,EAAE,OAAO,MAAA;AAAA,MACxB,GAAI,MAAM,CAAA,IAAK,EAAE,KAAK,EAAE,OAAO,SAAS,CAAC,IAAI,EAAA,EAAE;AAAA,IAAE;AAAA,IAEnD,SAAS,MAAM,CAAA,IAAK,CAAC,IAAI,EAAE,SAAS,CAAC,eAAe,GAAG,CAAC;AAAA,EAAA,CACzD;AACH;AAeO,MAAM,aAAa,CACxB,YAAwB,IACxB,UAA6B,CAAA,MACd;AACf,QAAM;AAAA,IACJ,MAAM,QAAQ,IAAA;AAAA,IACd,UAAU;AAAA,IACV,SAAS;AAAA,EAAA,IACP;AACJ,QAAM,QAAQ,UAAU,OAAO,EAAE,IAAI,CAAC,MAAM,QAAQ,KAAK,QAAQ,CAAC,CAAC;AACnE,SAAO,YAAY,kBAAkB,KAAK,GAAG,SAAS;AACxD;AC/FA,MAAM,eAAe;AAAA,EACnB,MAAM,EAAE,aAAa,OAAA;AACvB;AAgBO,MAAM,eAAe,CAC1B,YAA4B,CAAA,GAC5B,UAA6B,CAAA,MACVC,cAAY,cAAc,WAAW,WAAW,OAAO,CAAC;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/vite.mts","../src/vitest.mts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { builtinModules } from 'node:module';\nimport { resolve } from 'node:path';\nimport { nodeResolve } from '@rollup/plugin-node-resolve';\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 * Enable that builds for SEA (Single Executable Application).\n *\n * If enabled, the build will bundle all dependencies into a single file.\n * @default false\n */\n readonly sea?: boolean | 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/** Static configuration for SEA builds. */\nconst staticSeaConfig = {\n build: {\n rollupOptions: {\n external: [...builtinModules, ...builtinModules.map((m) => `node:${m}`)],\n output: {\n entryFileNames: 'index.cjs',\n format: 'cjs',\n inlineDynamicImports: true,\n manualChunks: undefined,\n },\n plugins: [nodeResolve({ preferBuiltins: true })],\n },\n },\n ssr: { noExternal: true },\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 sea,\n srcDir = 'src',\n } = options;\n const files = castArray(entries).map((e) => resolve(cwd, srcDir, e));\n const seaConfig = sea ? staticSeaConfig : {};\n return mergeConfig(\n innerCreateConfig(files),\n mergeConfig(seaConfig, overrides),\n );\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":";;;;;;;;;AA4CA,MAAM,MAAM;AAGZ,MAAMA,iBAAe;AAAA,EACnB,OAAO;AAAA,IACL,eAAe;AAAA,MACb,QAAQ;AAAA,QACN,gBAAgB;AAAA,QAChB,gBAAgB;AAAA,QAChB,QAAQ;AAAA,QAC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AAM,QAAQ,KAAK,QAAQ,CAAC,CAAC;AACnE,QAAM,YAAY,MAAM,kBAAkB,CAAA;AAC1C,SAAO;AAAA,IACL,kBAAkB,KAAK;AAAA,IACvB,YAAY,WAAW,SAAS;AAAA,EAAA;AAEpC;AC/HA,MAAM,eAAe;AAAA,EACnB,MAAM,EAAE,aAAa,OAAA;AACvB;AAgBO,MAAM,eAAe,CAC1B,YAA4B,CAAA,GAC5B,UAA6B,CAAA,MACVC,cAAY,cAAc,WAAW,WAAW,OAAO,CAAC;"}
package/dist/vite.d.mts CHANGED
@@ -15,6 +15,13 @@ export interface ViteConfigOptions {
15
15
  * @default ['index.mts']
16
16
  */
17
17
  readonly entries?: Readonly<Arrayable<string>> | undefined;
18
+ /**
19
+ * Enable that builds for SEA (Single Executable Application).
20
+ *
21
+ * If enabled, the build will bundle all dependencies into a single file.
22
+ * @default false
23
+ */
24
+ readonly sea?: boolean | undefined;
18
25
  /**
19
26
  * Directory where the source files are located.
20
27
  * @default 'src'
@@ -1 +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"}
1
+ {"version":3,"file":"vite.d.mts","sourceRoot":"","sources":["../src/vite.mts"],"names":[],"mappings":"AAMA,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;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAEnC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AA+DD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GACrB,YAAW,UAAe,EAC1B,UAAS,iBAAsB,KAC9B,UAaF,CAAC"}
@@ -42,6 +42,22 @@ Entry files relative to [srcDir](#srcdir).
42
42
 
43
43
  ***
44
44
 
45
+ ### sea?
46
+
47
+ > `readonly` `optional` **sea**: `boolean`
48
+
49
+ Enable that builds for SEA (Single Executable Application).
50
+
51
+ If enabled, the build will bundle all dependencies into a single file.
52
+
53
+ #### Default
54
+
55
+ ```ts
56
+ false
57
+ ```
58
+
59
+ ***
60
+
45
61
  ### srcDir?
46
62
 
47
63
  > `readonly` `optional` **srcDir**: `string`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kurone-kito/vite-lib-config",
3
- "version": "0.21.0",
3
+ "version": "0.22.0-alpha.2",
4
4
  "description": "The vite configuration package for the workspaces",
5
5
  "keywords": [
6
6
  "cli",
@@ -26,21 +26,22 @@
26
26
  "dependencies": {
27
27
  "lodash-es": "^4.17.21",
28
28
  "shebang-regex": "^4.0.0",
29
- "type-fest": "^5.0.1",
29
+ "type-fest": "^5.2.0",
30
30
  "vite": "^7.1.9",
31
31
  "vite-plugin-dts": "^4.5.4"
32
32
  },
33
33
  "devDependencies": {
34
+ "@rollup/plugin-node-resolve": "^16.0.3",
34
35
  "@types/lodash-es": "^4.17.12",
35
- "@types/node": "^24.6.2",
36
- "@vitest/coverage-v8": "^3.2.4",
36
+ "@types/node": "^24.10.0",
37
+ "@vitest/coverage-v8": "^4.0.6",
37
38
  "cpy-cli": "^6.0.0",
38
- "rimraf": "^6.0.1",
39
- "typedoc": "^0.28.13",
39
+ "rimraf": "^6.1.0",
40
+ "typedoc": "^0.28.14",
40
41
  "typedoc-plugin-markdown": "^4.9.0",
41
42
  "typescript": "~5.9.3",
42
- "vitest": "^3.2.4",
43
- "@kurone-kito/typescript-config": "^0.21.0"
43
+ "vitest": "^4.0.6",
44
+ "@kurone-kito/typescript-config": "^0.22.0-alpha.2"
44
45
  },
45
46
  "engines": {
46
47
  "node": "^20.11 || ^22 || >=24"
@@ -55,6 +56,8 @@
55
56
  "clean": "rimraf -g \"*.tgz\" \"*.tsbuildinfo\" coverage dist LICENSE node_modules/.cache",
56
57
  "dev": "vite build --watch",
57
58
  "prebuild": "cpy --flat ../../LICENSE .",
58
- "test": "vitest run --coverage"
59
+ "test": "pnpm run \"/test:.+/\"",
60
+ "test:ts": "tsc -p tsconfig.test.json --noEmit",
61
+ "test:vitest": "vitest run --coverage"
59
62
  }
60
63
  }