@zthun/janitor-vite 21.1.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.md +20 -0
- package/README.md +90 -0
- package/dist/extensions/extension-dev-server.d.mts +37 -0
- package/dist/extensions/extension-externalize.d.mts +29 -0
- package/dist/extensions/extension-library.d.mts +26 -0
- package/dist/helpful/get-all-node-builtins.d.mts +1 -0
- package/dist/helpful/get-all-package-dependencies.d.mts +2 -0
- package/dist/helpful/resolve-cwd.d.mts +2 -0
- package/dist/index.cjs +343 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.js +308 -0
- package/dist/index.js.map +1 -0
- package/dist/projects/project-cli.d.mts +8 -0
- package/dist/projects/project-dom.d.mts +14 -0
- package/dist/projects/project-monorepo.d.mts +14 -0
- package/dist/projects/project-nestjs.d.mts +9 -0
- package/dist/projects/project-node.d.mts +12 -0
- package/dist/projects/project-react.d.mts +14 -0
- package/dist/projects/project.d.mts +14 -0
- package/package.json +57 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Anthony Bonta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
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, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Janitor Vite
|
|
2
|
+
|
|
3
|
+
This is a set of common plugins for vite that simplifies build setup.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
# NPM
|
|
9
|
+
npm install @zthun/janitor-vite --save-dev
|
|
10
|
+
# Yarn
|
|
11
|
+
yarn add @zthun/janitor-vite --dev
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Projects
|
|
15
|
+
|
|
16
|
+
The first step is to pick your project type. What are you building?
|
|
17
|
+
|
|
18
|
+
| Type | Description |
|
|
19
|
+
| -------- | ------------------------------------------------------- |
|
|
20
|
+
| Node | Basic node command line app. |
|
|
21
|
+
| CLI | Same as node. Here for semantics. |
|
|
22
|
+
| NestJS | Same as node. Here for semantics. |
|
|
23
|
+
| DOM | A browser based application. |
|
|
24
|
+
| React | A DOM application that uses react as the framework. |
|
|
25
|
+
| Monorepo | You're building multiple things in the packages folder. |
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// vite.config.ts
|
|
29
|
+
import { defineConfig } from "vite";
|
|
30
|
+
import { projectMonorepo } from "@zthun/janitor-vite";
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
plugins: [projectMonorepo()],
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Extensions
|
|
38
|
+
|
|
39
|
+
After you have the type of project you're building, you can use available
|
|
40
|
+
extensions to modify the project with extra features.
|
|
41
|
+
|
|
42
|
+
| Type | Description |
|
|
43
|
+
| ----------- | ----------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| Library | Turns your project into an npm library. Usually only used with the base project or a dom project. |
|
|
45
|
+
| Externalize | Externalizes your dependencies so they are not bundled. If you build a library, you get this automatically. |
|
|
46
|
+
| DevServer | Adds a dev server. Usually paired with a dom project. |
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
// vite.config.ts
|
|
50
|
+
import { defineConfig } from "vite";
|
|
51
|
+
import { project, extensionLibrary } from "@zthun/janitor-vite";
|
|
52
|
+
|
|
53
|
+
// Basic library for browsers and node.
|
|
54
|
+
export default defineConfig({
|
|
55
|
+
plugins: [project(), extensionLibrary()],
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// vite.config.ts
|
|
61
|
+
import { defineConfig } from "vite";
|
|
62
|
+
import { projectReact, extensionLibrary } from "@zthun/janitor-vite";
|
|
63
|
+
|
|
64
|
+
// Builds a react library.
|
|
65
|
+
export default defineConfig({
|
|
66
|
+
plugins: [projectReact(), extensionLibrary()],
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
// vite.config.ts
|
|
72
|
+
import { defineConfig } from "vite";
|
|
73
|
+
import { projectCli, extensionExternalize } from "@zthun/janitor-vite";
|
|
74
|
+
|
|
75
|
+
// Builds a cli that does not bundle dependencies.
|
|
76
|
+
export default defineConfig({
|
|
77
|
+
plugins: [projectCli(), extensionExternalize()],
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
// vite.config.ts
|
|
83
|
+
import { defineConfig } from "vite";
|
|
84
|
+
import { projectReact, extensionDevServer } from "@zthun/janitor-vite";
|
|
85
|
+
|
|
86
|
+
// Basic react application
|
|
87
|
+
export default defineConfig({
|
|
88
|
+
plugins: [projectReact(), extensionDevServer()],
|
|
89
|
+
});
|
|
90
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the dev server.
|
|
4
|
+
*
|
|
5
|
+
* The expectation for almost every repository in this instance
|
|
6
|
+
* is that it is running the backend and frontend in a docker
|
|
7
|
+
* compose environment, so it assumes it will be running in a docker
|
|
8
|
+
* network.
|
|
9
|
+
*
|
|
10
|
+
* If this isn't true, then these options will be useful.
|
|
11
|
+
*/
|
|
12
|
+
export interface ExtensionDevServerOptions {
|
|
13
|
+
/**
|
|
14
|
+
* The port to run on.
|
|
15
|
+
*
|
|
16
|
+
* @default 5173
|
|
17
|
+
*/
|
|
18
|
+
port?: number;
|
|
19
|
+
/**
|
|
20
|
+
* The binding host.
|
|
21
|
+
*
|
|
22
|
+
* @default "0.0.0.0"
|
|
23
|
+
*/
|
|
24
|
+
host?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Adds a dev server to your vite build.
|
|
28
|
+
*
|
|
29
|
+
* This is usually paired with a dom based project and
|
|
30
|
+
* is only used for debugging. AllowedHosts in this plugin
|
|
31
|
+
* is set to true to allow for local manipulation of the
|
|
32
|
+
* OS host file to simulate true domains.
|
|
33
|
+
*
|
|
34
|
+
* @returns
|
|
35
|
+
* A list of plugins that add the dev server option.
|
|
36
|
+
*/
|
|
37
|
+
export declare function extensionDevServer(options?: ExtensionDevServerOptions): Plugin[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PathLike } from 'node:fs';
|
|
2
|
+
import { Plugin } from 'vite';
|
|
3
|
+
/**
|
|
4
|
+
* Options for externalizing dependencies.
|
|
5
|
+
*/
|
|
6
|
+
export interface ExternalizeOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The path to the package json file that contains dependencies
|
|
9
|
+
* to externalize or false to only externalize node builtins.
|
|
10
|
+
*
|
|
11
|
+
* If this is undefined, then the package.json in the current
|
|
12
|
+
* working directory will be used.
|
|
13
|
+
*/
|
|
14
|
+
packageJson?: PathLike | false;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* An externalize extension tells a project to not bundle the dependencies together.
|
|
18
|
+
*
|
|
19
|
+
* This is mostly used for libraries and if you use extensionLibrary(), or projectNode()
|
|
20
|
+
* you do not need to include this extension as it will be included for you already.
|
|
21
|
+
*
|
|
22
|
+
* @param options -
|
|
23
|
+
* Optional options for how to externalize dependency values.
|
|
24
|
+
*
|
|
25
|
+
* @returns
|
|
26
|
+
* A list of plugins that will stop vite from bundling packages
|
|
27
|
+
* from the node_modules directory and node builtins.
|
|
28
|
+
*/
|
|
29
|
+
export declare const extensionExternalize: (options?: ExternalizeOptions) => Plugin[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Turns any project into a shared library.
|
|
4
|
+
*
|
|
5
|
+
* A library does not actually run any code, it simply contains shared
|
|
6
|
+
* code that makes up other projects.
|
|
7
|
+
*
|
|
8
|
+
* A library is expected to have an index.mts file under the src directory
|
|
9
|
+
* that is a long list of exports that the library will provide to consumers.
|
|
10
|
+
* Only one barrel export should be used for a library. It's better to have
|
|
11
|
+
* multiple libraries than to complicate a library with subpaths in the
|
|
12
|
+
* exports of package.json. This keeps the expectations that when you npm
|
|
13
|
+
* library "foo", you can do import { something } from 'foo' and not need to
|
|
14
|
+
* have the brain overload of hunting down available paths from within.
|
|
15
|
+
*
|
|
16
|
+
* When you classify something as a library, source maps are turned on,
|
|
17
|
+
* and none of your code for it will be minified. This is to help with
|
|
18
|
+
* debugging library code outside of the library development environment.
|
|
19
|
+
* Module libraries in the janitor system are not expected to be deployed
|
|
20
|
+
* to a system by themselves. They are bundled with the overarching parent
|
|
21
|
+
* application.
|
|
22
|
+
*
|
|
23
|
+
* @returns
|
|
24
|
+
* The list of plugins that turn any project into a library.
|
|
25
|
+
*/
|
|
26
|
+
export declare function extensionLibrary(): Plugin[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getAllNodeBuiltins(): RegExp[];
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let node_path = require("node:path");
|
|
25
|
+
let node_module = require("node:module");
|
|
26
|
+
let node_fs = require("node:fs");
|
|
27
|
+
let lodash_es = require("lodash-es");
|
|
28
|
+
let unplugin_dts_vite = require("unplugin-dts/vite");
|
|
29
|
+
unplugin_dts_vite = __toESM(unplugin_dts_vite, 1);
|
|
30
|
+
let unplugin_swc = require("unplugin-swc");
|
|
31
|
+
unplugin_swc = __toESM(unplugin_swc, 1);
|
|
32
|
+
require("vitest/config");
|
|
33
|
+
let _vitejs_plugin_react_swc = require("@vitejs/plugin-react-swc");
|
|
34
|
+
_vitejs_plugin_react_swc = __toESM(_vitejs_plugin_react_swc, 1);
|
|
35
|
+
//#region src/extensions/extension-dev-server.mts
|
|
36
|
+
/**
|
|
37
|
+
* Adds a dev server to your vite build.
|
|
38
|
+
*
|
|
39
|
+
* This is usually paired with a dom based project and
|
|
40
|
+
* is only used for debugging. AllowedHosts in this plugin
|
|
41
|
+
* is set to true to allow for local manipulation of the
|
|
42
|
+
* OS host file to simulate true domains.
|
|
43
|
+
*
|
|
44
|
+
* @returns
|
|
45
|
+
* A list of plugins that add the dev server option.
|
|
46
|
+
*/ function extensionDevServer(options = {}) {
|
|
47
|
+
const { port = 5173, host = "0.0.0.0" } = options;
|
|
48
|
+
return [{
|
|
49
|
+
name: "janitor:extension-dev-server",
|
|
50
|
+
config: () => {
|
|
51
|
+
return { server: {
|
|
52
|
+
allowedHosts: true,
|
|
53
|
+
strictPort: true,
|
|
54
|
+
host,
|
|
55
|
+
port
|
|
56
|
+
} };
|
|
57
|
+
}
|
|
58
|
+
}];
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/helpful/get-all-node-builtins.mts
|
|
62
|
+
function getAllNodeBuiltins() {
|
|
63
|
+
return node_module.builtinModules.map((m) => new RegExp(`^(?:node:)?${m}$`));
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/helpful/get-all-package-dependencies.mts
|
|
67
|
+
function getAllPackageDependencies(pkg) {
|
|
68
|
+
try {
|
|
69
|
+
const externals = /* @__PURE__ */ new Set();
|
|
70
|
+
const contents = (0, node_fs.readFileSync)(pkg).toString();
|
|
71
|
+
const { dependencies = [], devDependencies = [], optionalDependencies = [], peerDependencies = [] } = JSON.parse(contents);
|
|
72
|
+
const push = externals.add.bind(externals);
|
|
73
|
+
Object.keys(dependencies).concat(Object.keys(devDependencies)).concat(Object.keys(optionalDependencies)).concat(Object.keys(peerDependencies)).map((dep) => new RegExp(`^${dep}(?:/.+)?$`)).forEach(push);
|
|
74
|
+
return Array.from(externals);
|
|
75
|
+
} catch {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/helpful/resolve-cwd.mts
|
|
81
|
+
function resolveCwd(current) {
|
|
82
|
+
return current?.root || process.cwd();
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/extensions/extension-externalize.mts
|
|
86
|
+
/**
|
|
87
|
+
* An externalize extension tells a project to not bundle the dependencies together.
|
|
88
|
+
*
|
|
89
|
+
* This is mostly used for libraries and if you use extensionLibrary(), or projectNode()
|
|
90
|
+
* you do not need to include this extension as it will be included for you already.
|
|
91
|
+
*
|
|
92
|
+
* @param options -
|
|
93
|
+
* Optional options for how to externalize dependency values.
|
|
94
|
+
*
|
|
95
|
+
* @returns
|
|
96
|
+
* A list of plugins that will stop vite from bundling packages
|
|
97
|
+
* from the node_modules directory and node builtins.
|
|
98
|
+
*/ var extensionExternalize = (options = {}) => {
|
|
99
|
+
return [{
|
|
100
|
+
name: "janitor:extension-externalize",
|
|
101
|
+
config: (current) => {
|
|
102
|
+
const cwd = resolveCwd(current);
|
|
103
|
+
const fallback = (0, node_path.resolve)(cwd, "package.json");
|
|
104
|
+
const { packageJson = fallback } = options;
|
|
105
|
+
const externalDeps = new Set(getAllNodeBuiltins());
|
|
106
|
+
if (packageJson !== false) getAllPackageDependencies(packageJson).forEach((p) => externalDeps.add(p));
|
|
107
|
+
const depMatchers = Array.from(externalDeps);
|
|
108
|
+
return { build: { rolldownOptions: { external: (source) => {
|
|
109
|
+
return depMatchers.some((depMatcher) => depMatcher.test(source));
|
|
110
|
+
} } } };
|
|
111
|
+
}
|
|
112
|
+
}];
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/extensions/extension-library.mts
|
|
116
|
+
/**
|
|
117
|
+
* Turns any project into a shared library.
|
|
118
|
+
*
|
|
119
|
+
* A library does not actually run any code, it simply contains shared
|
|
120
|
+
* code that makes up other projects.
|
|
121
|
+
*
|
|
122
|
+
* A library is expected to have an index.mts file under the src directory
|
|
123
|
+
* that is a long list of exports that the library will provide to consumers.
|
|
124
|
+
* Only one barrel export should be used for a library. It's better to have
|
|
125
|
+
* multiple libraries than to complicate a library with subpaths in the
|
|
126
|
+
* exports of package.json. This keeps the expectations that when you npm
|
|
127
|
+
* library "foo", you can do import { something } from 'foo' and not need to
|
|
128
|
+
* have the brain overload of hunting down available paths from within.
|
|
129
|
+
*
|
|
130
|
+
* When you classify something as a library, source maps are turned on,
|
|
131
|
+
* and none of your code for it will be minified. This is to help with
|
|
132
|
+
* debugging library code outside of the library development environment.
|
|
133
|
+
* Module libraries in the janitor system are not expected to be deployed
|
|
134
|
+
* to a system by themselves. They are bundled with the overarching parent
|
|
135
|
+
* application.
|
|
136
|
+
*
|
|
137
|
+
* @returns
|
|
138
|
+
* The list of plugins that turn any project into a library.
|
|
139
|
+
*/ function extensionLibrary() {
|
|
140
|
+
return [
|
|
141
|
+
...extensionExternalize(),
|
|
142
|
+
...(0, lodash_es.castArray)((0, unplugin_dts_vite.default)({
|
|
143
|
+
compilerOptions: { paths: {} },
|
|
144
|
+
include: ["src/**/*.{js,mjs,cjs,ts,mts,jsx,tsx}"],
|
|
145
|
+
exclude: ["**/*.{spec,test}.{js,mjs,cjs,ts,mts,jsx,tsx}"]
|
|
146
|
+
})),
|
|
147
|
+
{
|
|
148
|
+
name: "janitor:extension-library",
|
|
149
|
+
config: (current) => {
|
|
150
|
+
const cwd = resolveCwd(current);
|
|
151
|
+
return { build: {
|
|
152
|
+
minify: false,
|
|
153
|
+
sourcemap: true,
|
|
154
|
+
lib: {
|
|
155
|
+
entry: { index: (0, node_path.resolve)(cwd, "./src/index.mts") },
|
|
156
|
+
formats: ["cjs", "es"]
|
|
157
|
+
}
|
|
158
|
+
} };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/projects/project.mts
|
|
165
|
+
/**
|
|
166
|
+
* The base plugin for all project types.
|
|
167
|
+
*
|
|
168
|
+
* This will be included with every project. The default build engine for all projects
|
|
169
|
+
* is swc. While esbuild and oxc outperform swc, swc has the closest and most accurate
|
|
170
|
+
* implementation of the latest ECMAScript features which gives us one unified build engine.
|
|
171
|
+
*
|
|
172
|
+
* A vite build should only include one project type and as many extensions as it wants.
|
|
173
|
+
*
|
|
174
|
+
* @returns
|
|
175
|
+
* A list of plugins that all project types will provide.
|
|
176
|
+
*/ function project() {
|
|
177
|
+
return [unplugin_swc.default.vite({ jsc: { transform: { react: { runtime: "automatic" } } } }), {
|
|
178
|
+
name: "janitor:project",
|
|
179
|
+
config: () => {
|
|
180
|
+
return {
|
|
181
|
+
oxc: false,
|
|
182
|
+
resolve: { tsconfigPaths: true },
|
|
183
|
+
build: {
|
|
184
|
+
chunkSizeWarningLimit: 8e3,
|
|
185
|
+
minify: true,
|
|
186
|
+
sourcemap: false,
|
|
187
|
+
rolldownOptions: { checks: { pluginTimings: false } }
|
|
188
|
+
},
|
|
189
|
+
test: {
|
|
190
|
+
globals: true,
|
|
191
|
+
testTimeout: 2e4,
|
|
192
|
+
maxConcurrency: 10
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}];
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/projects/project-node.mts
|
|
200
|
+
/**
|
|
201
|
+
* A plugin that marks a project as a node application.
|
|
202
|
+
*
|
|
203
|
+
* Node applications expect an entry point of main.mts under the
|
|
204
|
+
* src directory.
|
|
205
|
+
*
|
|
206
|
+
* @returns
|
|
207
|
+
* A list of plugins that turn a project into a node base cli
|
|
208
|
+
* project.
|
|
209
|
+
*/ function projectNode() {
|
|
210
|
+
return [
|
|
211
|
+
...project(),
|
|
212
|
+
...extensionExternalize({ packageJson: false }),
|
|
213
|
+
{
|
|
214
|
+
name: "janitor:project-node",
|
|
215
|
+
config: (current) => {
|
|
216
|
+
const cwd = resolveCwd(current);
|
|
217
|
+
return {
|
|
218
|
+
resolve: {
|
|
219
|
+
conditions: [
|
|
220
|
+
"module",
|
|
221
|
+
"node",
|
|
222
|
+
"development|production"
|
|
223
|
+
],
|
|
224
|
+
mainFields: [
|
|
225
|
+
"module",
|
|
226
|
+
"jsnext:main",
|
|
227
|
+
"jsnext"
|
|
228
|
+
]
|
|
229
|
+
},
|
|
230
|
+
build: { lib: {
|
|
231
|
+
entry: { main: (0, node_path.resolve)(cwd, "./src/main.mts") },
|
|
232
|
+
formats: ["es"]
|
|
233
|
+
} }
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/projects/project-cli.mts
|
|
241
|
+
/**
|
|
242
|
+
* Currently the same as {@link projectNode}.
|
|
243
|
+
*
|
|
244
|
+
* @returns
|
|
245
|
+
* A list of plugins that turn your project into a cli.
|
|
246
|
+
*/ function projectCli() {
|
|
247
|
+
return [...projectNode(), { name: "janitor:project-cli" }];
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/projects/project-dom.mts
|
|
251
|
+
/**
|
|
252
|
+
* A project for the DOM is a frontend application built with
|
|
253
|
+
* basic web components, html, and css.
|
|
254
|
+
*
|
|
255
|
+
* Frontend projects with frameworks will automatically have this plugin.
|
|
256
|
+
*
|
|
257
|
+
* This will set the testing environment to happy-dom.
|
|
258
|
+
*
|
|
259
|
+
* @returns
|
|
260
|
+
* A list of plugins that setup a vite build as a project for
|
|
261
|
+
* a frontend.
|
|
262
|
+
*/ function projectDom() {
|
|
263
|
+
return [...project(), {
|
|
264
|
+
name: "janitor:project-dom",
|
|
265
|
+
config: () => {
|
|
266
|
+
return { test: {
|
|
267
|
+
environment: "happy-dom",
|
|
268
|
+
pool: "vmThreads",
|
|
269
|
+
environmentOptions: { happyDOM: { settings: { handleDisabledFileLoadingAsSuccess: true } } }
|
|
270
|
+
} };
|
|
271
|
+
}
|
|
272
|
+
}];
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/projects/project-monorepo.mts
|
|
276
|
+
/**
|
|
277
|
+
* A special project type for the root vite config or vitest config where
|
|
278
|
+
* the repository is a monorepo of packages that use more than one config entry
|
|
279
|
+
* for each package.
|
|
280
|
+
*
|
|
281
|
+
* This should only be set in a monorepo where the root just specifies which
|
|
282
|
+
* packages the monorepo outputs. It sets up vitest to look for vite.config
|
|
283
|
+
* files under each package.
|
|
284
|
+
*
|
|
285
|
+
* @returns
|
|
286
|
+
* The list of plugins to use for the root monorepo.
|
|
287
|
+
*/ function projectMonorepo() {
|
|
288
|
+
return [...project(), {
|
|
289
|
+
name: "janitor:project-monorepo",
|
|
290
|
+
config: (current) => {
|
|
291
|
+
return { test: { projects: [`${resolveCwd(current)}/packages/*/{vite,vitest}.config.{js,cjs,mjs,ts,mts}`] } };
|
|
292
|
+
}
|
|
293
|
+
}];
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/projects/project-nestjs.mts
|
|
297
|
+
/**
|
|
298
|
+
* Currently the same as {@link projectNode}.
|
|
299
|
+
*
|
|
300
|
+
* @returns
|
|
301
|
+
* A list of plugins that turn your project into an app that
|
|
302
|
+
* runs a NestJS backend.
|
|
303
|
+
*/ function projectNestJs() {
|
|
304
|
+
return [...projectNode(), { name: "janitor:project-nestjs" }];
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/projects/project-react.mts
|
|
308
|
+
/**
|
|
309
|
+
* A project that builds out a react website.
|
|
310
|
+
*
|
|
311
|
+
* A react website is just a dom project that has the
|
|
312
|
+
* react swc plugin enabled.
|
|
313
|
+
*
|
|
314
|
+
* This should normally be coupled with the server extension
|
|
315
|
+
* for full debugging support.
|
|
316
|
+
*
|
|
317
|
+
* @returns
|
|
318
|
+
* A list of plugins that builds a react website.
|
|
319
|
+
*/ function projectReact() {
|
|
320
|
+
return [
|
|
321
|
+
...projectDom(),
|
|
322
|
+
...(0, _vitejs_plugin_react_swc.default)(),
|
|
323
|
+
{
|
|
324
|
+
name: "janitor:project-react",
|
|
325
|
+
config: () => {
|
|
326
|
+
return { oxc: false };
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
];
|
|
330
|
+
}
|
|
331
|
+
//#endregion
|
|
332
|
+
exports.extensionDevServer = extensionDevServer;
|
|
333
|
+
exports.extensionExternalize = extensionExternalize;
|
|
334
|
+
exports.extensionLibrary = extensionLibrary;
|
|
335
|
+
exports.project = project;
|
|
336
|
+
exports.projectCli = projectCli;
|
|
337
|
+
exports.projectDom = projectDom;
|
|
338
|
+
exports.projectMonorepo = projectMonorepo;
|
|
339
|
+
exports.projectNestJs = projectNestJs;
|
|
340
|
+
exports.projectNode = projectNode;
|
|
341
|
+
exports.projectReact = projectReact;
|
|
342
|
+
|
|
343
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["extensionDevServer","options","port","host","name","config","server","allowedHosts","strictPort","builtinModules","modules","getAllNodeBuiltins","map","m","RegExp","readFileSync","getAllPackageDependencies","pkg","externals","Set","contents","toString","dependencies","devDependencies","optionalDependencies","peerDependencies","JSON","parse","push","add","bind","Object","keys","concat","map","dep","RegExp","forEach","Array","from","resolveCwd","current","root","process","cwd","resolve","getAllNodeBuiltins","getAllPackageDependencies","resolveCwd","extensionExternalize","options","name","config","current","cwd","fallback","packageJson","externalDeps","Set","forEach","p","add","depMatchers","Array","from","build","rolldownOptions","external","source","some","depMatcher","test","resolve","castArray","dts","resolveCwd","extensionExternalize","extensionLibrary","compilerOptions","paths","include","exclude","name","config","current","cwd","build","minify","sourcemap","lib","entry","index","formats","swc","project","vite","jsc","transform","react","runtime","name","config","oxc","resolve","tsconfigPaths","build","chunkSizeWarningLimit","minify","sourcemap","rolldownOptions","checks","pluginTimings","test","globals","testTimeout","maxConcurrency","resolve","extensionExternalize","resolveCwd","project","projectNode","packageJson","name","config","current","cwd","conditions","mainFields","build","lib","entry","main","formats","projectNode","projectCli","name","project","projectDom","name","config","test","environment","pool","environmentOptions","happyDOM","settings","handleDisabledFileLoadingAsSuccess","resolveCwd","project","projectMonorepo","name","config","current","cwd","test","projects","projectNode","projectNestJs","name","react","projectDom","projectReact","name","config","oxc"],"sources":["../src/extensions/extension-dev-server.mts","../src/helpful/get-all-node-builtins.mts","../src/helpful/get-all-package-dependencies.mts","../src/helpful/resolve-cwd.mts","../src/extensions/extension-externalize.mts","../src/extensions/extension-library.mts","../src/projects/project.mts","../src/projects/project-node.mts","../src/projects/project-cli.mts","../src/projects/project-dom.mts","../src/projects/project-monorepo.mts","../src/projects/project-nestjs.mts","../src/projects/project-react.mts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\n/**\n * Options for the dev server.\n *\n * The expectation for almost every repository in this instance\n * is that it is running the backend and frontend in a docker\n * compose environment, so it assumes it will be running in a docker\n * network. \n *\n * If this isn't true, then these options will be useful.\n */\nexport interface ExtensionDevServerOptions {\n /**\n * The port to run on. \n *\n * @default 5173\n */\n port?: number;\n\n /**\n * The binding host.\n *\n * @default \"0.0.0.0\"\n */\n host?: string;\n}\n\n/**\n * Adds a dev server to your vite build.\n *\n * This is usually paired with a dom based project and\n * is only used for debugging. AllowedHosts in this plugin\n * is set to true to allow for local manipulation of the\n * OS host file to simulate true domains.\n *\n * @returns\n * A list of plugins that add the dev server option.\n */\nexport function extensionDevServer(\n options: ExtensionDevServerOptions = {},\n): Plugin[] {\n const { port = 5173, host = \"0.0.0.0\" } = options;\n\n return [\n {\n name: \"janitor:extension-dev-server\",\n config: () => {\n return {\n server: {\n allowedHosts: true,\n strictPort: true,\n host,\n port,\n },\n };\n },\n },\n ];\n}\n","import { builtinModules as modules } from \"node:module\";\n\nexport function getAllNodeBuiltins(): RegExp[] {\n return modules.map((m) => new RegExp(`^(?:node:)?${m}$`));\n}\n","import { type PathLike, readFileSync } from \"node:fs\";\n\nexport function getAllPackageDependencies(pkg: PathLike): RegExp[] {\n try {\n const externals = new Set<RegExp>();\n\n const contents = readFileSync(pkg).toString();\n const {\n dependencies = [],\n devDependencies = [],\n optionalDependencies = [],\n peerDependencies = [],\n } = JSON.parse(contents) as Record<string, Record<string, string>>;\n\n const push = externals.add.bind(externals);\n\n Object.keys(dependencies)\n .concat(Object.keys(devDependencies))\n .concat(Object.keys(optionalDependencies))\n .concat(Object.keys(peerDependencies))\n .map((dep) => new RegExp(`^${dep}(?:/.+)?$`))\n .forEach(push);\n\n return Array.from(externals);\n } catch {\n return [];\n }\n}\n","import type { UserConfig } from \"vite\";\n\nexport function resolveCwd(current?: UserConfig): string {\n return current?.root || process.cwd();\n}\n","import type { PathLike } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport type { Plugin, UserConfig } from \"vite\";\n\nimport { getAllNodeBuiltins } from \"../helpful/get-all-node-builtins.mjs\";\nimport { getAllPackageDependencies } from \"../helpful/get-all-package-dependencies.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\n\n/**\n * Options for externalizing dependencies.\n */\nexport interface ExternalizeOptions {\n /**\n * The path to the package json file that contains dependencies\n * to externalize or false to only externalize node builtins.\n *\n * If this is undefined, then the package.json in the current\n * working directory will be used.\n */\n packageJson?: PathLike | false;\n}\n\n/**\n * An externalize extension tells a project to not bundle the dependencies together. \n *\n * This is mostly used for libraries and if you use extensionLibrary(), or projectNode()\n * you do not need to include this extension as it will be included for you already.\n *\n * @param options -\n * Optional options for how to externalize dependency values.\n *\n * @returns\n * A list of plugins that will stop vite from bundling packages\n * from the node_modules directory and node builtins.\n */\nexport const extensionExternalize = (\n options: ExternalizeOptions = {},\n): Plugin[] => {\n return [\n {\n name: \"janitor:extension-externalize\",\n config: (current) => {\n const cwd = resolveCwd(current);\n const fallback = resolve(cwd, \"package.json\");\n const { packageJson = fallback } = options;\n const externalDeps = new Set<RegExp>(getAllNodeBuiltins());\n\n if (packageJson !== false) {\n getAllPackageDependencies(packageJson).forEach((p) =>\n externalDeps.add(p),\n );\n }\n\n const depMatchers = Array.from(externalDeps);\n\n return {\n build: {\n rolldownOptions: {\n external: (source) => {\n return depMatchers.some((depMatcher) =>\n depMatcher.test(source),\n );\n },\n },\n },\n } satisfies UserConfig;\n },\n },\n ];\n};\n","import { resolve } from \"node:path\";\n\nimport { castArray } from \"lodash-es\";\nimport dts from \"unplugin-dts/vite\";\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { extensionExternalize } from \"./extension-externalize.mjs\";\n\n/**\n * Turns any project into a shared library.\n *\n * A library does not actually run any code, it simply contains shared\n * code that makes up other projects.\n *\n * A library is expected to have an index.mts file under the src directory\n * that is a long list of exports that the library will provide to consumers.\n * Only one barrel export should be used for a library. It's better to have\n * multiple libraries than to complicate a library with subpaths in the\n * exports of package.json. This keeps the expectations that when you npm\n * library \"foo\", you can do import { something } from 'foo' and not need to\n * have the brain overload of hunting down available paths from within.\n *\n * When you classify something as a library, source maps are turned on,\n * and none of your code for it will be minified. This is to help with\n * debugging library code outside of the library development environment.\n * Module libraries in the janitor system are not expected to be deployed\n * to a system by themselves. They are bundled with the overarching parent\n * application.\n *\n * @returns\n * The list of plugins that turn any project into a library.\n */\nexport function extensionLibrary(): Plugin[] {\n return [\n ...extensionExternalize(),\n ...castArray(\n dts({\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 // We only want to include output source files, not any config files outside\n // of our source code directory.\n include: [\"src/**/*.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n // Make sure to exclude spec and test files as well, these don't need to\n // be included (and shouldn't be).\n exclude: [\"**/*.{spec,test}.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n }),\n ),\n {\n name: \"janitor:extension-library\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n build: {\n minify: false,\n sourcemap: true,\n lib: {\n entry: {\n index: resolve(cwd, \"./src/index.mts\"),\n },\n formats: [\"cjs\", \"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import swc from \"unplugin-swc\";\nimport type { Plugin } from \"vite\";\n\n/**\n * The base plugin for all project types.\n *\n * This will be included with every project. The default build engine for all projects\n * is swc. While esbuild and oxc outperform swc, swc has the closest and most accurate\n * implementation of the latest ECMAScript features which gives us one unified build engine.\n *\n * A vite build should only include one project type and as many extensions as it wants.\n *\n * @returns\n * A list of plugins that all project types will provide.\n */\nexport function project(): Plugin[] {\n return [\n swc.vite({\n jsc: {\n transform: {\n react: {\n runtime: \"automatic\",\n },\n },\n },\n }),\n {\n name: \"janitor:project\",\n config: () => {\n return {\n oxc: false,\n resolve: {\n tsconfigPaths: true,\n },\n build: {\n chunkSizeWarningLimit: 8000,\n minify: true,\n sourcemap: false,\n rolldownOptions: {\n checks: {\n pluginTimings: false,\n },\n },\n },\n test: {\n globals: true,\n testTimeout: 20000,\n maxConcurrency: 10,\n },\n };\n },\n },\n ];\n}\n","import { resolve } from \"node:path\";\n\nimport type { Plugin } from \"vite\";\n\nimport { extensionExternalize } from \"../extensions/extension-externalize.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A plugin that marks a project as a node application.\n *\n * Node applications expect an entry point of main.mts under the\n * src directory.\n *\n * @returns\n * A list of plugins that turn a project into a node base cli\n * project.\n */\nexport function projectNode(): Plugin[] {\n return [\n ...project(),\n ...extensionExternalize({ packageJson: false }),\n {\n name: \"janitor:project-node\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n resolve: {\n conditions: [\"module\", \"node\", \"development|production\"],\n mainFields: [\"module\", \"jsnext:main\", \"jsnext\"],\n },\n build: {\n lib: {\n entry: {\n main: resolve(cwd, \"./src/main.mts\"),\n },\n formats: [\"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into a cli.\n */\nexport function projectCli(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-cli\",\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { project } from \"./project.mjs\";\n\n/**\n * A project for the DOM is a frontend application built with\n * basic web components, html, and css.\n *\n * Frontend projects with frameworks will automatically have this plugin.\n *\n * This will set the testing environment to happy-dom.\n *\n * @returns\n * A list of plugins that setup a vite build as a project for\n * a frontend.\n */\nexport function projectDom(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-dom\",\n config: () => {\n return {\n test: {\n environment: \"happy-dom\",\n pool: \"vmThreads\",\n environmentOptions: {\n happyDOM: {\n settings: {\n // This is to shut up happy-dom yelling about not being able\n // to download some injected css files.\n handleDisabledFileLoadingAsSuccess: true,\n },\n },\n },\n },\n };\n },\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A special project type for the root vite config or vitest config where\n * the repository is a monorepo of packages that use more than one config entry\n * for each package.\n *\n * This should only be set in a monorepo where the root just specifies which\n * packages the monorepo outputs. It sets up vitest to look for vite.config\n * files under each package.\n *\n * @returns\n * The list of plugins to use for the root monorepo.\n */\nexport function projectMonorepo(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-monorepo\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n test: {\n projects: [\n `${cwd}/packages/*/{vite,vitest}.config.{js,cjs,mjs,ts,mts}`,\n ],\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into an app that\n * runs a NestJS backend.\n */\nexport function projectNestJs(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-nestjs\",\n },\n ];\n}\n","import react from \"@vitejs/plugin-react-swc\";\nimport type { Plugin } from \"vite\";\n\nimport { projectDom } from \"./project-dom.mjs\";\n\n/**\n * A project that builds out a react website.\n *\n * A react website is just a dom project that has the\n * react swc plugin enabled.\n *\n * This should normally be coupled with the server extension\n * for full debugging support.\n *\n * @returns\n * A list of plugins that builds a react website.\n */\nexport function projectReact(): Plugin[] {\n return [\n ...projectDom(),\n ...react(),\n {\n name: \"janitor:project-react\",\n config: () => {\n return {\n oxc: false,\n };\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCA,SAAgBA,mBACdC,UAAqC,CAAC,GAAC;CAEvC,MAAM,EAAEC,OAAO,MAAMC,OAAO,cAAcF;CAE1C,OAAO,CACL;EACEG,MAAM;EACNC,cAAQ;GACN,OAAO,EACLC,QAAQ;IACNC,cAAc;IACdC,YAAY;IACZL;IACAD;GACF,EACF;EACF;CACF,CACD;AACH;;;ACzDA,SAAgBS,qBAAAA;CACd,OAAOD,YAAAA,eAAQE,KAAKC,MAAM,IAAIC,OAAO,cAAcD,EAAE,EAAE,CAAA;AACzD;;;ACFA,SAAgBG,0BAA0BC,KAAa;CACrD,IAAI;EACF,MAAMC,4BAAY,IAAIC,IAAAA;EAEtB,MAAMC,YAAAA,GAAWL,QAAAA,aAAAA,CAAaE,GAAAA,CAAAA,CAAKI,SAAQ;EAC3C,MAAM,EACJC,eAAe,CAAA,GACfC,kBAAkB,CAAA,GAClBC,uBAAuB,CAAA,GACvBC,mBAAmB,CAAA,MACjBC,KAAKC,MAAMP,QA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;KACjB,EACF;IACF;GACF;EACF;CACD;AACH;;;;;;;;GClCA,SAAgBE,aAAAA;CACd,OAAO,CACFD,GAAAA,YAAAA,GACH,EACEE,MAAM,sBACR,CACD;AACH;;;;;;;;;;;;;;GCCA,SAAgBE,aAAAA;CACd,OAAO,CACFD,GAAAA,QAAAA,GACH;EACEE,MAAM;EACNC,cAAQ;GACN,OAAO,EACLC,MAAM;IACJC,aAAa;IACbC,MAAM;IACNC,oBAAoB,EAClBC,UAAU,EACRC,UAAU,EAGRC,oCAAoC,KACtC,EACF,EACF;GACF,EACF;EACF;CACF,CACD;AACH;;;;;;;;;;;;;;GCvBA,SAAgBG,kBAAAA;CACd,OAAO,CACFD,GAAAA,QAAAA,GACH;EACEE,MAAM;EACNC,SAASC,YAAAA;GAGP,OAAO,EACLE,MAAM,EACJC,UAAU,CACR,GALMR,WAAWK,OAKdC,EAAI,qDACR,EACH,EACF;EACF;CACF,CACD;AACH;;;;;;;;;GC1BA,SAAgBI,gBAAAA;CACd,OAAO,CACFD,GAAAA,YAAAA,GACH,EACEE,MAAM,yBACR,CACD;AACH;;;;;;;;;;;;;;GCDA,SAAgBG,eAAAA;CACd,OAAO;EACFD,GAAAA,WAAAA;EACAD,IAAAA,GAAAA,yBAAAA,QAAAA,CAAAA;EACH;GACEG,MAAM;GACNC,cAAQ;IACN,OAAO,EACLC,KAAK,MACP;GACF;EACF;CACD;AACH"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './extensions/extension-dev-server.mjs';
|
|
2
|
+
export * from './extensions/extension-externalize.mjs';
|
|
3
|
+
export * from './extensions/extension-library.mjs';
|
|
4
|
+
export * from './projects/project.mjs';
|
|
5
|
+
export * from './projects/project-cli.mjs';
|
|
6
|
+
export * from './projects/project-dom.mjs';
|
|
7
|
+
export * from './projects/project-monorepo.mjs';
|
|
8
|
+
export * from './projects/project-nestjs.mjs';
|
|
9
|
+
export * from './projects/project-node.mjs';
|
|
10
|
+
export * from './projects/project-react.mjs';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { builtinModules } from "node:module";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { castArray } from "lodash-es";
|
|
5
|
+
import dts from "unplugin-dts/vite";
|
|
6
|
+
import swc from "unplugin-swc";
|
|
7
|
+
import "vitest/config";
|
|
8
|
+
import react from "@vitejs/plugin-react-swc";
|
|
9
|
+
//#region src/extensions/extension-dev-server.mts
|
|
10
|
+
/**
|
|
11
|
+
* Adds a dev server to your vite build.
|
|
12
|
+
*
|
|
13
|
+
* This is usually paired with a dom based project and
|
|
14
|
+
* is only used for debugging. AllowedHosts in this plugin
|
|
15
|
+
* is set to true to allow for local manipulation of the
|
|
16
|
+
* OS host file to simulate true domains.
|
|
17
|
+
*
|
|
18
|
+
* @returns
|
|
19
|
+
* A list of plugins that add the dev server option.
|
|
20
|
+
*/ function extensionDevServer(options = {}) {
|
|
21
|
+
const { port = 5173, host = "0.0.0.0" } = options;
|
|
22
|
+
return [{
|
|
23
|
+
name: "janitor:extension-dev-server",
|
|
24
|
+
config: () => {
|
|
25
|
+
return { server: {
|
|
26
|
+
allowedHosts: true,
|
|
27
|
+
strictPort: true,
|
|
28
|
+
host,
|
|
29
|
+
port
|
|
30
|
+
} };
|
|
31
|
+
}
|
|
32
|
+
}];
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/helpful/get-all-node-builtins.mts
|
|
36
|
+
function getAllNodeBuiltins() {
|
|
37
|
+
return builtinModules.map((m) => new RegExp(`^(?:node:)?${m}$`));
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/helpful/get-all-package-dependencies.mts
|
|
41
|
+
function getAllPackageDependencies(pkg) {
|
|
42
|
+
try {
|
|
43
|
+
const externals = /* @__PURE__ */ new Set();
|
|
44
|
+
const contents = readFileSync(pkg).toString();
|
|
45
|
+
const { dependencies = [], devDependencies = [], optionalDependencies = [], peerDependencies = [] } = JSON.parse(contents);
|
|
46
|
+
const push = externals.add.bind(externals);
|
|
47
|
+
Object.keys(dependencies).concat(Object.keys(devDependencies)).concat(Object.keys(optionalDependencies)).concat(Object.keys(peerDependencies)).map((dep) => new RegExp(`^${dep}(?:/.+)?$`)).forEach(push);
|
|
48
|
+
return Array.from(externals);
|
|
49
|
+
} catch {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/helpful/resolve-cwd.mts
|
|
55
|
+
function resolveCwd(current) {
|
|
56
|
+
return current?.root || process.cwd();
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/extensions/extension-externalize.mts
|
|
60
|
+
/**
|
|
61
|
+
* An externalize extension tells a project to not bundle the dependencies together.
|
|
62
|
+
*
|
|
63
|
+
* This is mostly used for libraries and if you use extensionLibrary(), or projectNode()
|
|
64
|
+
* you do not need to include this extension as it will be included for you already.
|
|
65
|
+
*
|
|
66
|
+
* @param options -
|
|
67
|
+
* Optional options for how to externalize dependency values.
|
|
68
|
+
*
|
|
69
|
+
* @returns
|
|
70
|
+
* A list of plugins that will stop vite from bundling packages
|
|
71
|
+
* from the node_modules directory and node builtins.
|
|
72
|
+
*/ var extensionExternalize = (options = {}) => {
|
|
73
|
+
return [{
|
|
74
|
+
name: "janitor:extension-externalize",
|
|
75
|
+
config: (current) => {
|
|
76
|
+
const cwd = resolveCwd(current);
|
|
77
|
+
const fallback = resolve(cwd, "package.json");
|
|
78
|
+
const { packageJson = fallback } = options;
|
|
79
|
+
const externalDeps = new Set(getAllNodeBuiltins());
|
|
80
|
+
if (packageJson !== false) getAllPackageDependencies(packageJson).forEach((p) => externalDeps.add(p));
|
|
81
|
+
const depMatchers = Array.from(externalDeps);
|
|
82
|
+
return { build: { rolldownOptions: { external: (source) => {
|
|
83
|
+
return depMatchers.some((depMatcher) => depMatcher.test(source));
|
|
84
|
+
} } } };
|
|
85
|
+
}
|
|
86
|
+
}];
|
|
87
|
+
};
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/extensions/extension-library.mts
|
|
90
|
+
/**
|
|
91
|
+
* Turns any project into a shared library.
|
|
92
|
+
*
|
|
93
|
+
* A library does not actually run any code, it simply contains shared
|
|
94
|
+
* code that makes up other projects.
|
|
95
|
+
*
|
|
96
|
+
* A library is expected to have an index.mts file under the src directory
|
|
97
|
+
* that is a long list of exports that the library will provide to consumers.
|
|
98
|
+
* Only one barrel export should be used for a library. It's better to have
|
|
99
|
+
* multiple libraries than to complicate a library with subpaths in the
|
|
100
|
+
* exports of package.json. This keeps the expectations that when you npm
|
|
101
|
+
* library "foo", you can do import { something } from 'foo' and not need to
|
|
102
|
+
* have the brain overload of hunting down available paths from within.
|
|
103
|
+
*
|
|
104
|
+
* When you classify something as a library, source maps are turned on,
|
|
105
|
+
* and none of your code for it will be minified. This is to help with
|
|
106
|
+
* debugging library code outside of the library development environment.
|
|
107
|
+
* Module libraries in the janitor system are not expected to be deployed
|
|
108
|
+
* to a system by themselves. They are bundled with the overarching parent
|
|
109
|
+
* application.
|
|
110
|
+
*
|
|
111
|
+
* @returns
|
|
112
|
+
* The list of plugins that turn any project into a library.
|
|
113
|
+
*/ function extensionLibrary() {
|
|
114
|
+
return [
|
|
115
|
+
...extensionExternalize(),
|
|
116
|
+
...castArray(dts({
|
|
117
|
+
compilerOptions: { paths: {} },
|
|
118
|
+
include: ["src/**/*.{js,mjs,cjs,ts,mts,jsx,tsx}"],
|
|
119
|
+
exclude: ["**/*.{spec,test}.{js,mjs,cjs,ts,mts,jsx,tsx}"]
|
|
120
|
+
})),
|
|
121
|
+
{
|
|
122
|
+
name: "janitor:extension-library",
|
|
123
|
+
config: (current) => {
|
|
124
|
+
const cwd = resolveCwd(current);
|
|
125
|
+
return { build: {
|
|
126
|
+
minify: false,
|
|
127
|
+
sourcemap: true,
|
|
128
|
+
lib: {
|
|
129
|
+
entry: { index: resolve(cwd, "./src/index.mts") },
|
|
130
|
+
formats: ["cjs", "es"]
|
|
131
|
+
}
|
|
132
|
+
} };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/projects/project.mts
|
|
139
|
+
/**
|
|
140
|
+
* The base plugin for all project types.
|
|
141
|
+
*
|
|
142
|
+
* This will be included with every project. The default build engine for all projects
|
|
143
|
+
* is swc. While esbuild and oxc outperform swc, swc has the closest and most accurate
|
|
144
|
+
* implementation of the latest ECMAScript features which gives us one unified build engine.
|
|
145
|
+
*
|
|
146
|
+
* A vite build should only include one project type and as many extensions as it wants.
|
|
147
|
+
*
|
|
148
|
+
* @returns
|
|
149
|
+
* A list of plugins that all project types will provide.
|
|
150
|
+
*/ function project() {
|
|
151
|
+
return [swc.vite({ jsc: { transform: { react: { runtime: "automatic" } } } }), {
|
|
152
|
+
name: "janitor:project",
|
|
153
|
+
config: () => {
|
|
154
|
+
return {
|
|
155
|
+
oxc: false,
|
|
156
|
+
resolve: { tsconfigPaths: true },
|
|
157
|
+
build: {
|
|
158
|
+
chunkSizeWarningLimit: 8e3,
|
|
159
|
+
minify: true,
|
|
160
|
+
sourcemap: false,
|
|
161
|
+
rolldownOptions: { checks: { pluginTimings: false } }
|
|
162
|
+
},
|
|
163
|
+
test: {
|
|
164
|
+
globals: true,
|
|
165
|
+
testTimeout: 2e4,
|
|
166
|
+
maxConcurrency: 10
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}];
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/projects/project-node.mts
|
|
174
|
+
/**
|
|
175
|
+
* A plugin that marks a project as a node application.
|
|
176
|
+
*
|
|
177
|
+
* Node applications expect an entry point of main.mts under the
|
|
178
|
+
* src directory.
|
|
179
|
+
*
|
|
180
|
+
* @returns
|
|
181
|
+
* A list of plugins that turn a project into a node base cli
|
|
182
|
+
* project.
|
|
183
|
+
*/ function projectNode() {
|
|
184
|
+
return [
|
|
185
|
+
...project(),
|
|
186
|
+
...extensionExternalize({ packageJson: false }),
|
|
187
|
+
{
|
|
188
|
+
name: "janitor:project-node",
|
|
189
|
+
config: (current) => {
|
|
190
|
+
const cwd = resolveCwd(current);
|
|
191
|
+
return {
|
|
192
|
+
resolve: {
|
|
193
|
+
conditions: [
|
|
194
|
+
"module",
|
|
195
|
+
"node",
|
|
196
|
+
"development|production"
|
|
197
|
+
],
|
|
198
|
+
mainFields: [
|
|
199
|
+
"module",
|
|
200
|
+
"jsnext:main",
|
|
201
|
+
"jsnext"
|
|
202
|
+
]
|
|
203
|
+
},
|
|
204
|
+
build: { lib: {
|
|
205
|
+
entry: { main: resolve(cwd, "./src/main.mts") },
|
|
206
|
+
formats: ["es"]
|
|
207
|
+
} }
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
];
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/projects/project-cli.mts
|
|
215
|
+
/**
|
|
216
|
+
* Currently the same as {@link projectNode}.
|
|
217
|
+
*
|
|
218
|
+
* @returns
|
|
219
|
+
* A list of plugins that turn your project into a cli.
|
|
220
|
+
*/ function projectCli() {
|
|
221
|
+
return [...projectNode(), { name: "janitor:project-cli" }];
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/projects/project-dom.mts
|
|
225
|
+
/**
|
|
226
|
+
* A project for the DOM is a frontend application built with
|
|
227
|
+
* basic web components, html, and css.
|
|
228
|
+
*
|
|
229
|
+
* Frontend projects with frameworks will automatically have this plugin.
|
|
230
|
+
*
|
|
231
|
+
* This will set the testing environment to happy-dom.
|
|
232
|
+
*
|
|
233
|
+
* @returns
|
|
234
|
+
* A list of plugins that setup a vite build as a project for
|
|
235
|
+
* a frontend.
|
|
236
|
+
*/ function projectDom() {
|
|
237
|
+
return [...project(), {
|
|
238
|
+
name: "janitor:project-dom",
|
|
239
|
+
config: () => {
|
|
240
|
+
return { test: {
|
|
241
|
+
environment: "happy-dom",
|
|
242
|
+
pool: "vmThreads",
|
|
243
|
+
environmentOptions: { happyDOM: { settings: { handleDisabledFileLoadingAsSuccess: true } } }
|
|
244
|
+
} };
|
|
245
|
+
}
|
|
246
|
+
}];
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/projects/project-monorepo.mts
|
|
250
|
+
/**
|
|
251
|
+
* A special project type for the root vite config or vitest config where
|
|
252
|
+
* the repository is a monorepo of packages that use more than one config entry
|
|
253
|
+
* for each package.
|
|
254
|
+
*
|
|
255
|
+
* This should only be set in a monorepo where the root just specifies which
|
|
256
|
+
* packages the monorepo outputs. It sets up vitest to look for vite.config
|
|
257
|
+
* files under each package.
|
|
258
|
+
*
|
|
259
|
+
* @returns
|
|
260
|
+
* The list of plugins to use for the root monorepo.
|
|
261
|
+
*/ function projectMonorepo() {
|
|
262
|
+
return [...project(), {
|
|
263
|
+
name: "janitor:project-monorepo",
|
|
264
|
+
config: (current) => {
|
|
265
|
+
return { test: { projects: [`${resolveCwd(current)}/packages/*/{vite,vitest}.config.{js,cjs,mjs,ts,mts}`] } };
|
|
266
|
+
}
|
|
267
|
+
}];
|
|
268
|
+
}
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/projects/project-nestjs.mts
|
|
271
|
+
/**
|
|
272
|
+
* Currently the same as {@link projectNode}.
|
|
273
|
+
*
|
|
274
|
+
* @returns
|
|
275
|
+
* A list of plugins that turn your project into an app that
|
|
276
|
+
* runs a NestJS backend.
|
|
277
|
+
*/ function projectNestJs() {
|
|
278
|
+
return [...projectNode(), { name: "janitor:project-nestjs" }];
|
|
279
|
+
}
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/projects/project-react.mts
|
|
282
|
+
/**
|
|
283
|
+
* A project that builds out a react website.
|
|
284
|
+
*
|
|
285
|
+
* A react website is just a dom project that has the
|
|
286
|
+
* react swc plugin enabled.
|
|
287
|
+
*
|
|
288
|
+
* This should normally be coupled with the server extension
|
|
289
|
+
* for full debugging support.
|
|
290
|
+
*
|
|
291
|
+
* @returns
|
|
292
|
+
* A list of plugins that builds a react website.
|
|
293
|
+
*/ function projectReact() {
|
|
294
|
+
return [
|
|
295
|
+
...projectDom(),
|
|
296
|
+
...react(),
|
|
297
|
+
{
|
|
298
|
+
name: "janitor:project-react",
|
|
299
|
+
config: () => {
|
|
300
|
+
return { oxc: false };
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
];
|
|
304
|
+
}
|
|
305
|
+
//#endregion
|
|
306
|
+
export { extensionDevServer, extensionExternalize, extensionLibrary, project, projectCli, projectDom, projectMonorepo, projectNestJs, projectNode, projectReact };
|
|
307
|
+
|
|
308
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["extensionDevServer","options","port","host","name","config","server","allowedHosts","strictPort","builtinModules","modules","getAllNodeBuiltins","map","m","RegExp","readFileSync","getAllPackageDependencies","pkg","externals","Set","contents","toString","dependencies","devDependencies","optionalDependencies","peerDependencies","JSON","parse","push","add","bind","Object","keys","concat","map","dep","RegExp","forEach","Array","from","resolveCwd","current","root","process","cwd","resolve","getAllNodeBuiltins","getAllPackageDependencies","resolveCwd","extensionExternalize","options","name","config","current","cwd","fallback","packageJson","externalDeps","Set","forEach","p","add","depMatchers","Array","from","build","rolldownOptions","external","source","some","depMatcher","test","resolve","castArray","dts","resolveCwd","extensionExternalize","extensionLibrary","compilerOptions","paths","include","exclude","name","config","current","cwd","build","minify","sourcemap","lib","entry","index","formats","swc","project","vite","jsc","transform","react","runtime","name","config","oxc","resolve","tsconfigPaths","build","chunkSizeWarningLimit","minify","sourcemap","rolldownOptions","checks","pluginTimings","test","globals","testTimeout","maxConcurrency","resolve","extensionExternalize","resolveCwd","project","projectNode","packageJson","name","config","current","cwd","conditions","mainFields","build","lib","entry","main","formats","projectNode","projectCli","name","project","projectDom","name","config","test","environment","pool","environmentOptions","happyDOM","settings","handleDisabledFileLoadingAsSuccess","resolveCwd","project","projectMonorepo","name","config","current","cwd","test","projects","projectNode","projectNestJs","name","react","projectDom","projectReact","name","config","oxc"],"sources":["../src/extensions/extension-dev-server.mts","../src/helpful/get-all-node-builtins.mts","../src/helpful/get-all-package-dependencies.mts","../src/helpful/resolve-cwd.mts","../src/extensions/extension-externalize.mts","../src/extensions/extension-library.mts","../src/projects/project.mts","../src/projects/project-node.mts","../src/projects/project-cli.mts","../src/projects/project-dom.mts","../src/projects/project-monorepo.mts","../src/projects/project-nestjs.mts","../src/projects/project-react.mts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\n/**\n * Options for the dev server.\n *\n * The expectation for almost every repository in this instance\n * is that it is running the backend and frontend in a docker\n * compose environment, so it assumes it will be running in a docker\n * network. \n *\n * If this isn't true, then these options will be useful.\n */\nexport interface ExtensionDevServerOptions {\n /**\n * The port to run on. \n *\n * @default 5173\n */\n port?: number;\n\n /**\n * The binding host.\n *\n * @default \"0.0.0.0\"\n */\n host?: string;\n}\n\n/**\n * Adds a dev server to your vite build.\n *\n * This is usually paired with a dom based project and\n * is only used for debugging. AllowedHosts in this plugin\n * is set to true to allow for local manipulation of the\n * OS host file to simulate true domains.\n *\n * @returns\n * A list of plugins that add the dev server option.\n */\nexport function extensionDevServer(\n options: ExtensionDevServerOptions = {},\n): Plugin[] {\n const { port = 5173, host = \"0.0.0.0\" } = options;\n\n return [\n {\n name: \"janitor:extension-dev-server\",\n config: () => {\n return {\n server: {\n allowedHosts: true,\n strictPort: true,\n host,\n port,\n },\n };\n },\n },\n ];\n}\n","import { builtinModules as modules } from \"node:module\";\n\nexport function getAllNodeBuiltins(): RegExp[] {\n return modules.map((m) => new RegExp(`^(?:node:)?${m}$`));\n}\n","import { type PathLike, readFileSync } from \"node:fs\";\n\nexport function getAllPackageDependencies(pkg: PathLike): RegExp[] {\n try {\n const externals = new Set<RegExp>();\n\n const contents = readFileSync(pkg).toString();\n const {\n dependencies = [],\n devDependencies = [],\n optionalDependencies = [],\n peerDependencies = [],\n } = JSON.parse(contents) as Record<string, Record<string, string>>;\n\n const push = externals.add.bind(externals);\n\n Object.keys(dependencies)\n .concat(Object.keys(devDependencies))\n .concat(Object.keys(optionalDependencies))\n .concat(Object.keys(peerDependencies))\n .map((dep) => new RegExp(`^${dep}(?:/.+)?$`))\n .forEach(push);\n\n return Array.from(externals);\n } catch {\n return [];\n }\n}\n","import type { UserConfig } from \"vite\";\n\nexport function resolveCwd(current?: UserConfig): string {\n return current?.root || process.cwd();\n}\n","import type { PathLike } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport type { Plugin, UserConfig } from \"vite\";\n\nimport { getAllNodeBuiltins } from \"../helpful/get-all-node-builtins.mjs\";\nimport { getAllPackageDependencies } from \"../helpful/get-all-package-dependencies.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\n\n/**\n * Options for externalizing dependencies.\n */\nexport interface ExternalizeOptions {\n /**\n * The path to the package json file that contains dependencies\n * to externalize or false to only externalize node builtins.\n *\n * If this is undefined, then the package.json in the current\n * working directory will be used.\n */\n packageJson?: PathLike | false;\n}\n\n/**\n * An externalize extension tells a project to not bundle the dependencies together. \n *\n * This is mostly used for libraries and if you use extensionLibrary(), or projectNode()\n * you do not need to include this extension as it will be included for you already.\n *\n * @param options -\n * Optional options for how to externalize dependency values.\n *\n * @returns\n * A list of plugins that will stop vite from bundling packages\n * from the node_modules directory and node builtins.\n */\nexport const extensionExternalize = (\n options: ExternalizeOptions = {},\n): Plugin[] => {\n return [\n {\n name: \"janitor:extension-externalize\",\n config: (current) => {\n const cwd = resolveCwd(current);\n const fallback = resolve(cwd, \"package.json\");\n const { packageJson = fallback } = options;\n const externalDeps = new Set<RegExp>(getAllNodeBuiltins());\n\n if (packageJson !== false) {\n getAllPackageDependencies(packageJson).forEach((p) =>\n externalDeps.add(p),\n );\n }\n\n const depMatchers = Array.from(externalDeps);\n\n return {\n build: {\n rolldownOptions: {\n external: (source) => {\n return depMatchers.some((depMatcher) =>\n depMatcher.test(source),\n );\n },\n },\n },\n } satisfies UserConfig;\n },\n },\n ];\n};\n","import { resolve } from \"node:path\";\n\nimport { castArray } from \"lodash-es\";\nimport dts from \"unplugin-dts/vite\";\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { extensionExternalize } from \"./extension-externalize.mjs\";\n\n/**\n * Turns any project into a shared library.\n *\n * A library does not actually run any code, it simply contains shared\n * code that makes up other projects.\n *\n * A library is expected to have an index.mts file under the src directory\n * that is a long list of exports that the library will provide to consumers.\n * Only one barrel export should be used for a library. It's better to have\n * multiple libraries than to complicate a library with subpaths in the\n * exports of package.json. This keeps the expectations that when you npm\n * library \"foo\", you can do import { something } from 'foo' and not need to\n * have the brain overload of hunting down available paths from within.\n *\n * When you classify something as a library, source maps are turned on,\n * and none of your code for it will be minified. This is to help with\n * debugging library code outside of the library development environment.\n * Module libraries in the janitor system are not expected to be deployed\n * to a system by themselves. They are bundled with the overarching parent\n * application.\n *\n * @returns\n * The list of plugins that turn any project into a library.\n */\nexport function extensionLibrary(): Plugin[] {\n return [\n ...extensionExternalize(),\n ...castArray(\n dts({\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 // We only want to include output source files, not any config files outside\n // of our source code directory.\n include: [\"src/**/*.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n // Make sure to exclude spec and test files as well, these don't need to\n // be included (and shouldn't be).\n exclude: [\"**/*.{spec,test}.{js,mjs,cjs,ts,mts,jsx,tsx}\"],\n }),\n ),\n {\n name: \"janitor:extension-library\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n build: {\n minify: false,\n sourcemap: true,\n lib: {\n entry: {\n index: resolve(cwd, \"./src/index.mts\"),\n },\n formats: [\"cjs\", \"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import swc from \"unplugin-swc\";\nimport type { Plugin } from \"vite\";\n\n/**\n * The base plugin for all project types.\n *\n * This will be included with every project. The default build engine for all projects\n * is swc. While esbuild and oxc outperform swc, swc has the closest and most accurate\n * implementation of the latest ECMAScript features which gives us one unified build engine.\n *\n * A vite build should only include one project type and as many extensions as it wants.\n *\n * @returns\n * A list of plugins that all project types will provide.\n */\nexport function project(): Plugin[] {\n return [\n swc.vite({\n jsc: {\n transform: {\n react: {\n runtime: \"automatic\",\n },\n },\n },\n }),\n {\n name: \"janitor:project\",\n config: () => {\n return {\n oxc: false,\n resolve: {\n tsconfigPaths: true,\n },\n build: {\n chunkSizeWarningLimit: 8000,\n minify: true,\n sourcemap: false,\n rolldownOptions: {\n checks: {\n pluginTimings: false,\n },\n },\n },\n test: {\n globals: true,\n testTimeout: 20000,\n maxConcurrency: 10,\n },\n };\n },\n },\n ];\n}\n","import { resolve } from \"node:path\";\n\nimport type { Plugin } from \"vite\";\n\nimport { extensionExternalize } from \"../extensions/extension-externalize.mjs\";\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A plugin that marks a project as a node application.\n *\n * Node applications expect an entry point of main.mts under the\n * src directory.\n *\n * @returns\n * A list of plugins that turn a project into a node base cli\n * project.\n */\nexport function projectNode(): Plugin[] {\n return [\n ...project(),\n ...extensionExternalize({ packageJson: false }),\n {\n name: \"janitor:project-node\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n resolve: {\n conditions: [\"module\", \"node\", \"development|production\"],\n mainFields: [\"module\", \"jsnext:main\", \"jsnext\"],\n },\n build: {\n lib: {\n entry: {\n main: resolve(cwd, \"./src/main.mts\"),\n },\n formats: [\"es\"],\n },\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into a cli.\n */\nexport function projectCli(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-cli\",\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { project } from \"./project.mjs\";\n\n/**\n * A project for the DOM is a frontend application built with\n * basic web components, html, and css.\n *\n * Frontend projects with frameworks will automatically have this plugin.\n *\n * This will set the testing environment to happy-dom.\n *\n * @returns\n * A list of plugins that setup a vite build as a project for\n * a frontend.\n */\nexport function projectDom(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-dom\",\n config: () => {\n return {\n test: {\n environment: \"happy-dom\",\n pool: \"vmThreads\",\n environmentOptions: {\n happyDOM: {\n settings: {\n // This is to shut up happy-dom yelling about not being able\n // to download some injected css files.\n handleDisabledFileLoadingAsSuccess: true,\n },\n },\n },\n },\n };\n },\n },\n ];\n}\n","import \"vitest/config\";\n\nimport type { Plugin } from \"vite\";\n\nimport { resolveCwd } from \"../helpful/resolve-cwd.mjs\";\nimport { project } from \"./project.mjs\";\n\n/**\n * A special project type for the root vite config or vitest config where\n * the repository is a monorepo of packages that use more than one config entry\n * for each package.\n *\n * This should only be set in a monorepo where the root just specifies which\n * packages the monorepo outputs. It sets up vitest to look for vite.config\n * files under each package.\n *\n * @returns\n * The list of plugins to use for the root monorepo.\n */\nexport function projectMonorepo(): Plugin[] {\n return [\n ...project(),\n {\n name: \"janitor:project-monorepo\",\n config: (current) => {\n const cwd = resolveCwd(current);\n\n return {\n test: {\n projects: [\n `${cwd}/packages/*/{vite,vitest}.config.{js,cjs,mjs,ts,mts}`,\n ],\n },\n };\n },\n },\n ];\n}\n","import type { Plugin } from \"vite\";\n\nimport { projectNode } from \"./project-node.mjs\";\n\n/**\n * Currently the same as {@link projectNode}.\n *\n * @returns\n * A list of plugins that turn your project into an app that\n * runs a NestJS backend.\n */\nexport function projectNestJs(): Plugin[] {\n return [\n ...projectNode(),\n {\n name: \"janitor:project-nestjs\",\n },\n ];\n}\n","import react from \"@vitejs/plugin-react-swc\";\nimport type { Plugin } from \"vite\";\n\nimport { projectDom } from \"./project-dom.mjs\";\n\n/**\n * A project that builds out a react website.\n *\n * A react website is just a dom project that has the\n * react swc plugin enabled.\n *\n * This should normally be coupled with the server extension\n * for full debugging support.\n *\n * @returns\n * A list of plugins that builds a react website.\n */\nexport function projectReact(): Plugin[] {\n return [\n ...projectDom(),\n ...react(),\n {\n name: \"janitor:project-react\",\n config: () => {\n return {\n oxc: false,\n };\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;GAuCA,SAAgBA,mBACdC,UAAqC,CAAC,GAAC;CAEvC,MAAM,EAAEC,OAAO,MAAMC,OAAO,cAAcF;CAE1C,OAAO,CACL;EACEG,MAAM;EACNC,cAAQ;GACN,OAAO,EACLC,QAAQ;IACNC,cAAc;IACdC,YAAY;IACZL;IACAD;GACF,EACF;EACF;CACF,CACD;AACH;;;ACzDA,SAAgBS,qBAAAA;CACd,OAAOD,eAAQE,KAAKC,MAAM,IAAIC,OAAO,cAAcD,EAAE,EAAE,CAAA;AACzD;;;ACFA,SAAgBG,0BAA0BC,KAAa;CACrD,IAAI;EACF,MAAMC,4BAAY,IAAIC,IAAAA;EAEtB,MAAMC,WAAWL,aAAaE,GAAAA,CAAAA,CAAKI,SAAQ;EAC3C,MAAM,EACJC,eAAe,CAAA,GACfC,kBAAkB,CAAA,GAClBC,uBAAuB,CAAA,GACvBC,mBAAmB,CAAA,MACjBC,KAAKC,MAAMP,QAAAA;EAEf,MAAMQ,OAAOV,UAAUW,IAAIC,KAAKZ,SAAAA;EAEhCa,OAAOC,KAAKV,YAAAA,CAAAA,CACTW,OAAOF,OAAOC,KAAKT,eAAAA,CAAAA,CAAAA,CACnBU,OAAOF,OAAOC,KAAKR,oBAAAA,CAAAA,CAAAA,CACnBS,OAAOF,OAAOC,KAAKP,gBAAAA,CAAAA,CAAAA,CACnBS,KAAKC,QAAQ,IAAIC,OAAO,IAAID,IAAI,UAAU,CAAA,CAAA,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FD,GAAAA,QAAAA,GACH;EACEE,MAAM;EACNC,SAASC,YAAAA;GAGP,OAAO,EACLE,MAAM,EACJC,UAAU,CACR,GALMR,WAAWK,OAKdC,EAAI,qDACR,EACH,EACF;EACF;CACF,CACD;AACH;;;;;;;;;GC1BA,SAAgBI,gBAAAA;CACd,OAAO,CACFD,GAAAA,YAAAA,GACH,EACEE,MAAM,yBACR,CACD;AACH;;;;;;;;;;;;;;GCDA,SAAgBG,eAAAA;CACd,OAAO;EACFD,GAAAA,WAAAA;EACAD,GAAAA,MAAAA;EACH;GACEG,MAAM;GACNC,cAAQ;IACN,OAAO,EACLC,KAAK,MACP;GACF;EACF;CACD;AACH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* A project for the DOM is a frontend application built with
|
|
4
|
+
* basic web components, html, and css.
|
|
5
|
+
*
|
|
6
|
+
* Frontend projects with frameworks will automatically have this plugin.
|
|
7
|
+
*
|
|
8
|
+
* This will set the testing environment to happy-dom.
|
|
9
|
+
*
|
|
10
|
+
* @returns
|
|
11
|
+
* A list of plugins that setup a vite build as a project for
|
|
12
|
+
* a frontend.
|
|
13
|
+
*/
|
|
14
|
+
export declare function projectDom(): Plugin[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* A special project type for the root vite config or vitest config where
|
|
4
|
+
* the repository is a monorepo of packages that use more than one config entry
|
|
5
|
+
* for each package.
|
|
6
|
+
*
|
|
7
|
+
* This should only be set in a monorepo where the root just specifies which
|
|
8
|
+
* packages the monorepo outputs. It sets up vitest to look for vite.config
|
|
9
|
+
* files under each package.
|
|
10
|
+
*
|
|
11
|
+
* @returns
|
|
12
|
+
* The list of plugins to use for the root monorepo.
|
|
13
|
+
*/
|
|
14
|
+
export declare function projectMonorepo(): Plugin[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* A plugin that marks a project as a node application.
|
|
4
|
+
*
|
|
5
|
+
* Node applications expect an entry point of main.mts under the
|
|
6
|
+
* src directory.
|
|
7
|
+
*
|
|
8
|
+
* @returns
|
|
9
|
+
* A list of plugins that turn a project into a node base cli
|
|
10
|
+
* project.
|
|
11
|
+
*/
|
|
12
|
+
export declare function projectNode(): Plugin[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* A project that builds out a react website.
|
|
4
|
+
*
|
|
5
|
+
* A react website is just a dom project that has the
|
|
6
|
+
* react swc plugin enabled.
|
|
7
|
+
*
|
|
8
|
+
* This should normally be coupled with the server extension
|
|
9
|
+
* for full debugging support.
|
|
10
|
+
*
|
|
11
|
+
* @returns
|
|
12
|
+
* A list of plugins that builds a react website.
|
|
13
|
+
*/
|
|
14
|
+
export declare function projectReact(): Plugin[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* The base plugin for all project types.
|
|
4
|
+
*
|
|
5
|
+
* This will be included with every project. The default build engine for all projects
|
|
6
|
+
* is swc. While esbuild and oxc outperform swc, swc has the closest and most accurate
|
|
7
|
+
* implementation of the latest ECMAScript features which gives us one unified build engine.
|
|
8
|
+
*
|
|
9
|
+
* A vite build should only include one project type and as many extensions as it wants.
|
|
10
|
+
*
|
|
11
|
+
* @returns
|
|
12
|
+
* A list of plugins that all project types will provide.
|
|
13
|
+
*/
|
|
14
|
+
export declare function project(): Plugin[];
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zthun/janitor-vite",
|
|
3
|
+
"version": "21.1.0",
|
|
4
|
+
"description": "A shared set of plugins for vite that use conventions over configuration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.mts",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=24"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "vite build"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/zthun/janitor",
|
|
24
|
+
"directory": "packages/janitor-vite"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@swc/core": "^1.16.0",
|
|
31
|
+
"@vitejs/plugin-react-swc": "^4.3.3",
|
|
32
|
+
"happy-dom": "^20.11.2",
|
|
33
|
+
"lodash-es": "^4.18.1",
|
|
34
|
+
"unplugin-dts": "^1.0.3",
|
|
35
|
+
"unplugin-swc": "^1.5.11",
|
|
36
|
+
"vite": "^8.2.1",
|
|
37
|
+
"vitest": "^4.1.11"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"typescript": "^6.0.3"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"happy-dom": "^20.11.2",
|
|
44
|
+
"vite": "^8.2.1",
|
|
45
|
+
"vitest": "^4.1.11"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"happy-dom": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"author": "Anthony Bonta",
|
|
56
|
+
"gitHead": "1541f1775452c766b016e1e8e830a717a4bb8eca"
|
|
57
|
+
}
|