@budsbox/builder_vite 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Konstantin Kutsyllo
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 @@
1
+ # @budsbox/builder_vite
@@ -0,0 +1,4 @@
1
+ export { createBaseConfig, formatVarName, formatFileName } from './lib.js';
2
+ export { usePlainConfig } from './plain.js';
3
+ export { useReactConfig } from './react.js';
4
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { createBaseConfig, formatVarName, formatFileName } from './lib.js';
2
+ export { usePlainConfig } from './plain.js';
3
+ export { useReactConfig } from './react.js';
4
+ //# sourceMappingURL=index.js.map
package/dist/lib.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { type LibraryOptions, type UserConfigExport, type UserConfigFnPromise } from 'vite';
2
+ /**
3
+ * Creates a base configuration function that merges a provided base configuration
4
+ * with a custom configuration. The result is a function that resolves and merges
5
+ * both configurations based on the given environment.
6
+ *
7
+ * @param base - The base configuration, which can either be a `UserConfigExport` object
8
+ * or a function that resolves to a `UserConfigExport` object based on the provided environment.
9
+ * @returns A function that accepts a custom configuration of type `UserConfigExport`
10
+ * and returns a promise-based configuration function (`UserConfigFnPromise`) that resolves
11
+ * to a merged configuration.
12
+ */
13
+ export declare function createBaseConfig(base: UserConfigExport): (custom?: UserConfigExport) => UserConfigFnPromise;
14
+ /**
15
+ * Formats a package name into a standardized string format, suitable for use as a variable name.
16
+ *
17
+ * @param packageName - The full package name to be formatted. This can have an optional scope
18
+ * and a package name separated by a forward slash.
19
+ * @returns A formatted variable name string composed of the camelCase scope (if present),
20
+ * the processed package name segments using camelCase, separated by a dollar sign ('$').
21
+ */
22
+ export declare const formatVarName: (packageName: string) => string;
23
+ /**
24
+ * Generates a formatted file name based on the provided library format.
25
+ *
26
+ * @param format - The library format to generate the file name for. It determines the file extension.
27
+ * @param entryName - The name of the entry point file, used to generate the file name.
28
+ * @returns The generated file name in the format `{format}.{extension}`,
29
+ * where the extension is either `mjs` for `es` format or `cjs` for other formats.
30
+ */
31
+ export declare const formatFileName: Exclude<LibraryOptions['fileName'], string | undefined>;
32
+ //# sourceMappingURL=lib.d.ts.map
package/dist/lib.js ADDED
@@ -0,0 +1,49 @@
1
+ import { mergeConfig, } from 'vite';
2
+ import { isFunction, isNotNil } from '@budsbox/lib-es/guards';
3
+ import { fif } from '@budsbox/lib-es/logical';
4
+ import { camelCase, parsePackageName } from '@budsbox/lib-es/string';
5
+ /**
6
+ * Creates a base configuration function that merges a provided base configuration
7
+ * with a custom configuration. The result is a function that resolves and merges
8
+ * both configurations based on the given environment.
9
+ *
10
+ * @param base - The base configuration, which can either be a `UserConfigExport` object
11
+ * or a function that resolves to a `UserConfigExport` object based on the provided environment.
12
+ * @returns A function that accepts a custom configuration of type `UserConfigExport`
13
+ * and returns a promise-based configuration function (`UserConfigFnPromise`) that resolves
14
+ * to a merged configuration.
15
+ */
16
+ export function createBaseConfig(base) {
17
+ return (custom) => async (env) => {
18
+ const resolvedBase = await fif(await base, isFunction, (baseFn) => baseFn(env), (baseObj) => baseObj);
19
+ const resolvedCustom = await fif(await custom, isFunction, (customFn) => customFn(env), (customObj) => customObj);
20
+ return mergeConfig(resolvedBase, resolvedCustom ?? {});
21
+ };
22
+ }
23
+ /**
24
+ * Formats a package name into a standardized string format, suitable for use as a variable name.
25
+ *
26
+ * @param packageName - The full package name to be formatted. This can have an optional scope
27
+ * and a package name separated by a forward slash.
28
+ * @returns A formatted variable name string composed of the camelCase scope (if present),
29
+ * the processed package name segments using camelCase, separated by a dollar sign ('$').
30
+ */
31
+ export const formatVarName = (packageName) => {
32
+ const { scope, name } = parsePackageName(packageName, true);
33
+ return [
34
+ isNotNil(scope) ? camelCase(scope) : null,
35
+ name.split('_').map(camelCase).join('_'),
36
+ ]
37
+ .filter(isNotNil)
38
+ .join('$');
39
+ };
40
+ /**
41
+ * Generates a formatted file name based on the provided library format.
42
+ *
43
+ * @param format - The library format to generate the file name for. It determines the file extension.
44
+ * @param entryName - The name of the entry point file, used to generate the file name.
45
+ * @returns The generated file name in the format `{format}.{extension}`,
46
+ * where the extension is either `mjs` for `es` format or `cjs` for other formats.
47
+ */
48
+ export const formatFileName = (format, entryName) => `${entryName}.${format === 'es' ? 'mjs' : 'cjs'}`;
49
+ //# sourceMappingURL=lib.js.map
@@ -0,0 +1,2 @@
1
+ export declare const usePlainConfig: (custom?: import("vite").UserConfigExport) => import("vite").UserConfigFnPromise;
2
+ //# sourceMappingURL=plain.d.ts.map
package/dist/plain.js ADDED
@@ -0,0 +1,21 @@
1
+ import { NodePackageImporter } from 'sass-embedded';
2
+ import { createBaseConfig } from './lib.js';
3
+ export const usePlainConfig = createBaseConfig(({ mode }) => ({
4
+ root: 'src',
5
+ build: {
6
+ outDir: '../dist',
7
+ emptyOutDir: true,
8
+ },
9
+ css: {
10
+ modules: {
11
+ localsConvention: 'camelCaseOnly',
12
+ generateScopedName: mode === 'production' ? '[hash:hex]' : '[path][name]__[local]',
13
+ },
14
+ preprocessorOptions: {
15
+ scss: {
16
+ importers: [new NodePackageImporter()],
17
+ },
18
+ },
19
+ },
20
+ }));
21
+ //# sourceMappingURL=plain.js.map
@@ -0,0 +1,2 @@
1
+ export declare const useReactConfig: (custom?: import("vite").UserConfigExport) => import("vite").UserConfigFnPromise;
2
+ //# sourceMappingURL=react.d.ts.map
package/dist/react.js ADDED
@@ -0,0 +1,13 @@
1
+ import react from '@vitejs/plugin-react';
2
+ import { createBaseConfig } from './lib.js';
3
+ import { usePlainConfig } from './plain.js';
4
+ export const useReactConfig = createBaseConfig(usePlainConfig(() => ({
5
+ plugins: [
6
+ react({
7
+ babel: {
8
+ plugins: ['babel-plugin-react-compiler'],
9
+ },
10
+ }),
11
+ ],
12
+ })));
13
+ //# sourceMappingURL=react.js.map
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@budsbox/builder_vite",
3
+ "version": "1.0.0",
4
+ "homepage": "https://gitlab.com/budsbox/fe/seed",
5
+ "bugs": {
6
+ "url": "https://gitlab.com/budsbox/fe/seed/-/issues"
7
+ },
8
+ "repository": "gitlab:budsbox/fe/seed",
9
+ "license": "MIT",
10
+ "author": "Konstantin Kutsyllo <trikadin@pm.me>",
11
+ "type": "module",
12
+ "imports": {
13
+ "#package.json": "./package.json"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "types": "./dist/index.d.ts"
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "files": [
23
+ "dist/**/*.js",
24
+ "dist/**/*.d.ts"
25
+ ],
26
+ "scripts": {
27
+ "name": "echo $npm_package_name",
28
+ "prepack": "yarn p:ts:prepack"
29
+ },
30
+ "dependencies": {
31
+ "@budsbox/lib-es": "^2.2.0",
32
+ "tslib": "^2.8.1"
33
+ },
34
+ "devDependencies": {
35
+ "@budsbox/eslint": "^1.2.0",
36
+ "@budsbox/eslint_presets-node-lib": "^1.0.3",
37
+ "@budsbox/eslint_presets-tools": "^1.0.3",
38
+ "@budsbox/lib-types": "^1.1.0",
39
+ "@budsbox/tsconfigs": "^4.3.0",
40
+ "@types/eslint": "^9.6.1",
41
+ "@types/node": "^22.15.2",
42
+ "@vitejs/plugin-react": "^5.0.3",
43
+ "babel-plugin-react-compiler": "^19.1.0-rc.3",
44
+ "eslint": "^9.26.0",
45
+ "sass-embedded": "^1.92.1",
46
+ "type-fest": "^4.32.0",
47
+ "typescript": "^5.8.3",
48
+ "vite": "^7.1.5"
49
+ },
50
+ "peerDependencies": {
51
+ "@vitejs/plugin-react": "^5.0.3",
52
+ "babel-plugin-react-compiler": "^19.1.0-rc.3",
53
+ "sass-embedded": "^1.92.1",
54
+ "vite": "^7.1.5"
55
+ },
56
+ "packageManager": "yarn@4.9.2"
57
+ }