@universal-deploy/auto 0.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/README.md +43 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/vite.d.ts +13 -0
- package/dist/vite.js +57 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
## @universal-deploy/auto
|
|
2
|
+
|
|
3
|
+
Automatically enables the Node.js adapter if no other deployment target (Vercel, Cloudflare, Netlify) is detected in the Vite configuration.
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @universal-deploy/auto
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Usage
|
|
12
|
+
|
|
13
|
+
Add the `auto` plugin to your `vite.config.ts`:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { auto } from "@universal-deploy/auto/vite";
|
|
17
|
+
import { defineConfig } from "vite";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [
|
|
21
|
+
auto(),
|
|
22
|
+
// ... other plugins
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### How it works
|
|
28
|
+
|
|
29
|
+
The `auto()` plugin detects the presence of other deployment adapters in your Vite configuration. If any of the following plugins are found, it automatically disables its own Node.js adapter injection:
|
|
30
|
+
|
|
31
|
+
- `vite-plugin-vercel`
|
|
32
|
+
- `@cloudflare/vite-plugin`
|
|
33
|
+
- `@netlify/vite-plugin` (also requires `@universal-deploy/netlify` for compatibility)
|
|
34
|
+
|
|
35
|
+
If none of these are present, it enables `@universal-deploy/node` to provide a default Node.js-compatible server build.
|
|
36
|
+
|
|
37
|
+
### Options
|
|
38
|
+
|
|
39
|
+
The `auto()` plugin accepts the following options:
|
|
40
|
+
|
|
41
|
+
- `node`: Same options as the `@universal-deploy/node` adapter:
|
|
42
|
+
- `static`: (string | boolean) The directory containing static assets. Defaults to the client output directory.
|
|
43
|
+
- `importer`: (string) The importer to use when resolving the server entry.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { node } from "@universal-deploy/node/vite";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/vite.d.ts
|
|
5
|
+
type NodePluginOptions = Parameters<typeof node>[0];
|
|
6
|
+
/**
|
|
7
|
+
* Automatically enables the node adapter if no other deployment target (Vercel, Cloudflare, Netlify) is detected.
|
|
8
|
+
*/
|
|
9
|
+
declare function auto(options?: {
|
|
10
|
+
node?: NodePluginOptions;
|
|
11
|
+
}): Plugin[];
|
|
12
|
+
//#endregion
|
|
13
|
+
export { auto };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { node } from "@universal-deploy/node/vite";
|
|
2
|
+
import { catchAll, devServer } from "@universal-deploy/store/vite";
|
|
3
|
+
|
|
4
|
+
//#region src/vite.ts
|
|
5
|
+
const INSTANCE = Symbol("auto-instance");
|
|
6
|
+
/**
|
|
7
|
+
* Automatically enables the node adapter if no other deployment target (Vercel, Cloudflare, Netlify) is detected.
|
|
8
|
+
*/
|
|
9
|
+
function auto(options) {
|
|
10
|
+
const instance = Symbol("instance");
|
|
11
|
+
return [
|
|
12
|
+
catchAll(),
|
|
13
|
+
devServer(),
|
|
14
|
+
...node(options?.node).map((p) => {
|
|
15
|
+
p[INSTANCE] = instance;
|
|
16
|
+
return enablePluginIf((config) => noDeploymentTargetFound(p, config), p);
|
|
17
|
+
})
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Enables a plugin based on a specified condition callback which will be executed in the `config` hook.
|
|
22
|
+
*/
|
|
23
|
+
function enablePluginIf(condition, originalPlugin) {
|
|
24
|
+
const originalConfig = originalPlugin.config;
|
|
25
|
+
originalPlugin.config = {
|
|
26
|
+
order: originalConfig && "order" in originalConfig ? originalConfig.order : "pre",
|
|
27
|
+
async handler(c, e) {
|
|
28
|
+
if (!await condition.call(this, c, e)) {
|
|
29
|
+
const keysToDelete = Object.keys(originalPlugin).filter((k) => k !== "name");
|
|
30
|
+
originalPlugin.name += ":disabled";
|
|
31
|
+
for (const key of keysToDelete) delete originalPlugin[key];
|
|
32
|
+
} else if (originalConfig) {
|
|
33
|
+
if (typeof originalConfig === "function") return originalConfig.call(this, c, e);
|
|
34
|
+
return originalConfig.handler.call(this, c, e);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return originalPlugin;
|
|
39
|
+
}
|
|
40
|
+
async function noDeploymentTargetFound(thisNodePlugin, c) {
|
|
41
|
+
const plugins = (await asyncFlatten(c.plugins ?? [])).filter((p) => Boolean(p));
|
|
42
|
+
const vitePluginVercel = plugins.some((p) => p.name.match(/^vite-plugin-vercel/));
|
|
43
|
+
const cloudflareVitePlugin = plugins.some((p) => p.name.match(/^vite-plugin-cloudflare/));
|
|
44
|
+
const netlifyVitePlugin = plugins.some((p) => p.name.match(/^ud:netlify/));
|
|
45
|
+
const otherNodePlugin = plugins.some((p) => p.name.startsWith("ud:node:emit") && p[INSTANCE] !== thisNodePlugin?.[INSTANCE]);
|
|
46
|
+
return !vitePluginVercel && !cloudflareVitePlugin && !netlifyVitePlugin && !otherNodePlugin;
|
|
47
|
+
}
|
|
48
|
+
async function asyncFlatten(arr) {
|
|
49
|
+
const flattened = [];
|
|
50
|
+
for (const item of arr) if (Array.isArray(item)) flattened.push(...await asyncFlatten(item));
|
|
51
|
+
else if (item instanceof Promise) flattened.push(...await asyncFlatten([await item]));
|
|
52
|
+
else if (item) flattened.push(item);
|
|
53
|
+
return flattened;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { auto };
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@universal-deploy/auto",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js",
|
|
9
|
+
"./vite": "./dist/vite.js"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@universal-deploy/node": "^0.1.2",
|
|
13
|
+
"@universal-deploy/store": "^0.1.4"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"tsdown": "^0.20.3",
|
|
17
|
+
"typescript": "^5.9.3",
|
|
18
|
+
"vite": "^8.0.0-beta.13",
|
|
19
|
+
"vitest": "^3.0.7"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"vite": ">=7.1"
|
|
23
|
+
},
|
|
24
|
+
"peerDependenciesMeta": {
|
|
25
|
+
"vite": {
|
|
26
|
+
"optional": true
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/"
|
|
31
|
+
],
|
|
32
|
+
"repository": "github:photon-js/universal-deploy",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"scripts": {
|
|
35
|
+
"dev": "tsdown --watch",
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:types": "tsc --noEmit"
|
|
39
|
+
}
|
|
40
|
+
}
|