vite-plugin-neon-new 0.8.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 +178 -0
- package/README.md +146 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# vite-plugin-neon-new
|
|
2
|
+
|
|
3
|
+
This Vite plugin instantly provisions a Postgres instance (via Neon) and injects the connection string into your `.env` file, so you can start developing immediately.
|
|
4
|
+
|
|
5
|
+
> **Note:** This package was previously named `vite-plugin-db`. The old package is now deprecated. If you're upgrading, simply replace it with `vite-plugin-neon-new` in your imports and package.json.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
- On first `vite dev`, the plugin checks for a `DATABASE_URL` (or your configured key) in your `.env`.
|
|
10
|
+
- If not found, it creates a claimable Neon database and writes the connection string to your `.env`.
|
|
11
|
+
- The plugin is a noop in production builds.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
| Package Manager | Command |
|
|
16
|
+
| --------------- | -------------------------------------- |
|
|
17
|
+
| **npm** | `npm add -D vite-plugin-neon-new` |
|
|
18
|
+
| **pnpm** | `pnpm add -D vite-plugin-neon-new` |
|
|
19
|
+
| **yarn** | `yarn add -D vite-plugin-neon-new` |
|
|
20
|
+
| **bun** | `bun add -D vite-plugin-neon-new` |
|
|
21
|
+
| **deno** | `deno add -D npm:vite-plugin-neon-new` |
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
> **BREAKING CHANGE in v3.0.0**: The `referrer` option is now **required**.
|
|
26
|
+
|
|
27
|
+
Add the plugin as the first entry in your Vite config:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { postgres } from "vite-plugin-neon-new";
|
|
31
|
+
import react from "@vitejs/plugin-react";
|
|
32
|
+
import { defineConfig } from "vite";
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
plugins: [
|
|
36
|
+
postgres({
|
|
37
|
+
referrer: "github:username/repo-name", // REQUIRED
|
|
38
|
+
}),
|
|
39
|
+
react(),
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Configuration
|
|
45
|
+
|
|
46
|
+
You can pass an options object to customize the `.env` file path, the environment variable name, and database seeding:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
postgres({
|
|
50
|
+
referrer: "your-app-name", // REQUIRED - for tracking and affiliates
|
|
51
|
+
env: ".env.local", // Path to your .env file (default: ".env")
|
|
52
|
+
envKey: "DATABASE_URL", // Name of the env variable (default: "DATABASE_URL")
|
|
53
|
+
envPrefix: "VITE_", // Prefix for public env vars (default: "VITE_")
|
|
54
|
+
settings: {
|
|
55
|
+
logicalReplication: false, // Enable logical replication (default: false)
|
|
56
|
+
},
|
|
57
|
+
seed: {
|
|
58
|
+
type: "sql-script",
|
|
59
|
+
path: "./schema.sql", // Path to SQL file to execute after database creation
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
| Option | Type | Description | Required | Default |
|
|
65
|
+
| ----------- | ------ | --------------------------------------- | -------- | -------------- |
|
|
66
|
+
| `referrer` | string | Referrer identifier for tracking | Yes | - |
|
|
67
|
+
| `env` | string | Path to the `.env` file | No | `.env` |
|
|
68
|
+
| `envKey` | string | Name of the environment variable | No | `DATABASE_URL` |
|
|
69
|
+
| `envPrefix` | string | Prefix for public environment variables | No | `VITE_` |
|
|
70
|
+
| `settings` | object | Database configuration settings | No | - |
|
|
71
|
+
| `seed` | object | Configuration for seeding the database | No | - |
|
|
72
|
+
|
|
73
|
+
### settings Options
|
|
74
|
+
|
|
75
|
+
| Property | Type | Description | Default |
|
|
76
|
+
| -------------------- | ------- | -------------------------- | ------- |
|
|
77
|
+
| `logicalReplication` | boolean | Enable logical replication | `false` |
|
|
78
|
+
|
|
79
|
+
### seed Options
|
|
80
|
+
|
|
81
|
+
| Property | Type | Description | Default |
|
|
82
|
+
| -------- | ------ | ----------------------------------------------- | ------- |
|
|
83
|
+
| `type` | string | Type of seeding (currently only `"sql-script"`) | - |
|
|
84
|
+
| `path` | string | Path to SQL file to execute after creation | - |
|
|
85
|
+
|
|
86
|
+
## What gets written
|
|
87
|
+
|
|
88
|
+
The plugin writes the following environment variables to your `.env`:
|
|
89
|
+
|
|
90
|
+
| Variable | Description |
|
|
91
|
+
| ------------------------------- | ---------------------------------------------------------- |
|
|
92
|
+
| `DATABASE_URL` | The **pooler** connection string (default connection) |
|
|
93
|
+
| `DATABASE_URL_DIRECT` | The direct connection string |
|
|
94
|
+
| `{envPrefix}POSTGRES_CLAIM_URL` | Claim URL (valid for 72 hours) to take ownership of the DB |
|
|
95
|
+
|
|
96
|
+
> **Note:** The pooler connection is now the default for `DATABASE_URL` (as of the latest version). The pooler provides connection pooling and is recommended for most use cases, especially serverless environments.
|
|
97
|
+
|
|
98
|
+
If `seed` is configured, the specified SQL script will be executed after database creation.
|
|
99
|
+
|
|
100
|
+
## Type Definitions
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
interface PostgresPluginOptions {
|
|
104
|
+
referrer: string; // Required - Referrer identifier for tracking
|
|
105
|
+
env?: string; // Path to the .env file
|
|
106
|
+
envKey?: string; // Name of the environment variable
|
|
107
|
+
envPrefix?: string; // Prefix for public environment variables
|
|
108
|
+
settings?: {
|
|
109
|
+
logicalReplication?: boolean; // Enable logical replication (default: false)
|
|
110
|
+
};
|
|
111
|
+
seed?: {
|
|
112
|
+
type: "sql-script";
|
|
113
|
+
path: string;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## FAQ
|
|
121
|
+
|
|
122
|
+
<details>
|
|
123
|
+
<summary>What if I already have a <code>DATABASE_URL</code> env var?</summary>
|
|
124
|
+
|
|
125
|
+
The plugin will not overwrite it. Remove the variable if you want to generate a new Neon database.
|
|
126
|
+
|
|
127
|
+
</details>
|
|
128
|
+
|
|
129
|
+
<details>
|
|
130
|
+
<summary>Is this safe to run on CI when building for production?</summary>
|
|
131
|
+
|
|
132
|
+
The plugin is a noop in production mode (`vite build`), so it won't create databases or modify your `.env` in CI.
|
|
133
|
+
|
|
134
|
+
</details>
|
|
135
|
+
|
|
136
|
+
<details>
|
|
137
|
+
<summary>Can I use this with other frameworks?</summary>
|
|
138
|
+
|
|
139
|
+
Yes, this plugin is framework-agnostic. The example uses React, but you can use it with any Vite-compatible framework.
|
|
140
|
+
</sumamry>
|
|
141
|
+
|
|
142
|
+
## Advanced
|
|
143
|
+
|
|
144
|
+
If you want to generate claimable databases outside of Vite, use the [`neon-new`](https://github.com/neondatabase/neon-pkgs/tree/main/packages/neon-new) library directly.
|
|
145
|
+
|
|
146
|
+
> See [documentation on Neon](https://neon.com/docs/reference/neon-launchpad) for more.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type PostgresPluginOptions = {
|
|
5
|
+
referrer: string;
|
|
6
|
+
dotEnvFile?: string;
|
|
7
|
+
dotEnvKey?: string;
|
|
8
|
+
seed?: {
|
|
9
|
+
type: "sql-script";
|
|
10
|
+
path: string;
|
|
11
|
+
};
|
|
12
|
+
envPrefix?: string;
|
|
13
|
+
settings?: {
|
|
14
|
+
logicalReplication?: boolean;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare function postgresPlugin(options: PostgresPluginOptions): Plugin;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { postgresPlugin as default, postgresPlugin as postgres };
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;KAeK,qBAAA;;EAAA,UAAA,CAAA,EAAA,MAAA;EAgBI,SAAA,CAAA,EAAA,MAAc;EAAA,IAAA,CAAA,EAAA;IAAU,IAAA,EAAA,YAAA;IAAwB,IAAA,EAAA,MAAA;EAAM,CAAA;;;;;;iBAAtD,cAAA,UAAwB,wBAAwB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { intro, log, outro } from "@clack/prompts";
|
|
3
|
+
import { instantPostgres } from "neon-new";
|
|
4
|
+
import { loadEnv } from "vite";
|
|
5
|
+
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
const DEFAULTS = {
|
|
8
|
+
dotEnvFile: ".env",
|
|
9
|
+
dotEnvKey: "DATABASE_URL",
|
|
10
|
+
seed: void 0,
|
|
11
|
+
envPrefix: "VITE_",
|
|
12
|
+
settings: { logicalReplication: false }
|
|
13
|
+
};
|
|
14
|
+
let claimProcessStarted = false;
|
|
15
|
+
function postgresPlugin(options) {
|
|
16
|
+
if (!options?.referrer || options.referrer.trim() === "") throw new Error("vite-plugin-neon-new: 'referrer' option is required.\n\nThe referrer helps track usage for the Open Source Program.\n\nUsage:\n postgres({ referrer: 'your-app-name' })\n\nExamples:\n postgres({ referrer: 'github:username/repo-name' })\n postgres({ referrer: 'my-vite-app' })\n\nFor more information, visit: https://neon.com/docs/reference/instagres");
|
|
17
|
+
const { dotEnvFile: envPath, dotEnvKey: envKey, referrer, seed, envPrefix, settings } = {
|
|
18
|
+
...DEFAULTS,
|
|
19
|
+
...options,
|
|
20
|
+
settings: {
|
|
21
|
+
...DEFAULTS.settings,
|
|
22
|
+
...options.settings
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
name: "vite-plugin-neon-new",
|
|
27
|
+
enforce: "pre",
|
|
28
|
+
async config({ root, envDir }, { mode }) {
|
|
29
|
+
if (mode === "production" || claimProcessStarted) return;
|
|
30
|
+
const resolvedRoot = resolve(root ?? process.cwd());
|
|
31
|
+
envDir = envDir ? resolve(resolvedRoot, envDir) : resolvedRoot;
|
|
32
|
+
const resolvedEnvPath = resolve(envDir, envPath || DEFAULTS.dotEnvFile);
|
|
33
|
+
const envVars = loadEnv(mode, envDir, envKey);
|
|
34
|
+
if (Object.keys(envVars).length > 0) if (!envVars[envKey]) log.info(`Environment variable ${envKey} not found in ${resolvedEnvPath}. We will create one for you.`);
|
|
35
|
+
else {
|
|
36
|
+
log.info(`Environment variable ${envKey} found in ${resolvedEnvPath}. If you wish to create a new Neon database, please remove the existing variable.`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
claimProcessStarted = true;
|
|
40
|
+
intro("Setting up your project with a Neon database.");
|
|
41
|
+
await instantPostgres({
|
|
42
|
+
dotEnvFile: envPath,
|
|
43
|
+
dotEnvKey: envKey,
|
|
44
|
+
referrer: `npm:vite-plugin-neon-new|${referrer}`,
|
|
45
|
+
seed,
|
|
46
|
+
envPrefix,
|
|
47
|
+
settings
|
|
48
|
+
});
|
|
49
|
+
outro("Neon database created successfully.");
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { postgresPlugin as default, postgresPlugin as postgres };
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport { intro, log, outro } from \"@clack/prompts\";\nimport { instantPostgres } from \"neon-new\";\nimport { loadEnv, type Plugin } from \"vite\";\n\nconst DEFAULTS = {\n\tdotEnvFile: \".env\",\n\tdotEnvKey: \"DATABASE_URL\",\n\tseed: undefined,\n\tenvPrefix: \"VITE_\",\n\tsettings: {\n\t\tlogicalReplication: false,\n\t},\n};\n\ntype PostgresPluginOptions = {\n\treferrer: string;\n\tdotEnvFile?: string;\n\tdotEnvKey?: string;\n\tseed?: {\n\t\ttype: \"sql-script\";\n\t\tpath: string;\n\t};\n\tenvPrefix?: string;\n\tsettings?: {\n\t\tlogicalReplication?: boolean;\n\t};\n};\n\nlet claimProcessStarted = false;\n\nfunction postgresPlugin(options: PostgresPluginOptions): Plugin {\n\tif (!options?.referrer || options.referrer.trim() === \"\") {\n\t\tthrow new Error(\n\t\t\t\"vite-plugin-neon-new: 'referrer' option is required.\\n\\n\" +\n\t\t\t\t\"The referrer helps track usage for the Open Source Program.\\n\\n\" +\n\t\t\t\t\"Usage:\\n\" +\n\t\t\t\t\" postgres({ referrer: 'your-app-name' })\\n\\n\" +\n\t\t\t\t\"Examples:\\n\" +\n\t\t\t\t\" postgres({ referrer: 'github:username/repo-name' })\\n\" +\n\t\t\t\t\" postgres({ referrer: 'my-vite-app' })\\n\\n\" +\n\t\t\t\t\"For more information, visit: https://neon.com/docs/reference/instagres\",\n\t\t);\n\t}\n\n\tconst {\n\t\tdotEnvFile: envPath,\n\t\tdotEnvKey: envKey,\n\t\treferrer,\n\t\tseed,\n\t\tenvPrefix,\n\t\tsettings,\n\t} = {\n\t\t...DEFAULTS,\n\t\t...options,\n\t\tsettings: {\n\t\t\t...DEFAULTS.settings,\n\t\t\t...options.settings,\n\t\t},\n\t};\n\treturn {\n\t\tname: \"vite-plugin-neon-new\",\n\t\tenforce: \"pre\",\n\n\t\tasync config({ root, envDir }, { mode }) {\n\t\t\t// Don't run in production to prevent accidental creation of a Neon database on CI\n\t\t\tif (mode === \"production\" || claimProcessStarted) return;\n\n\t\t\tconst resolvedRoot = resolve(root ?? process.cwd());\n\t\t\tenvDir = envDir ? resolve(resolvedRoot, envDir) : resolvedRoot;\n\t\t\tconst resolvedEnvPath = resolve(\n\t\t\t\tenvDir,\n\t\t\t\tenvPath || DEFAULTS.dotEnvFile,\n\t\t\t);\n\n\t\t\tconst envVars = loadEnv(mode, envDir, envKey);\n\n\t\t\tif (Object.keys(envVars).length > 0) {\n\t\t\t\tconst envVar = envVars[envKey];\n\t\t\t\tif (!envVar) {\n\t\t\t\t\tlog.info(\n\t\t\t\t\t\t`Environment variable ${envKey} not found in ${resolvedEnvPath}. We will create one for you.`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tlog.info(\n\t\t\t\t\t\t`Environment variable ${envKey} found in ${resolvedEnvPath}. If you wish to create a new Neon database, please remove the existing variable.`,\n\t\t\t\t\t);\n\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tclaimProcessStarted = true;\n\n\t\t\tintro(\"Setting up your project with a Neon database.\");\n\t\t\tawait instantPostgres({\n\t\t\t\tdotEnvFile: envPath,\n\t\t\t\tdotEnvKey: envKey,\n\t\t\t\treferrer: `npm:vite-plugin-neon-new|${referrer}`,\n\t\t\t\tseed,\n\t\t\t\tenvPrefix,\n\t\t\t\tsettings,\n\t\t\t});\n\t\t\toutro(\"Neon database created successfully.\");\n\t\t},\n\t};\n}\n\nexport { postgresPlugin as postgres };\nexport default postgresPlugin;\n"],"mappings":";;;;;;AAKA,MAAM,WAAW;CAChB,YAAY;CACZ,WAAW;CACX,MAAM;CACN,WAAW;CACX,UAAU,EACT,oBAAoB,OACpB;CACD;AAgBD,IAAI,sBAAsB;AAE1B,SAAS,eAAe,SAAwC;AAC/D,KAAI,CAAC,SAAS,YAAY,QAAQ,SAAS,MAAM,KAAK,GACrD,OAAM,IAAI,MACT,kWAQA;CAGF,MAAM,EACL,YAAY,SACZ,WAAW,QACX,UACA,MACA,WACA,aACG;EACH,GAAG;EACH,GAAG;EACH,UAAU;GACT,GAAG,SAAS;GACZ,GAAG,QAAQ;GACX;EACD;AACD,QAAO;EACN,MAAM;EACN,SAAS;EAET,MAAM,OAAO,EAAE,MAAM,UAAU,EAAE,QAAQ;AAExC,OAAI,SAAS,gBAAgB,oBAAqB;GAElD,MAAM,eAAe,QAAQ,QAAQ,QAAQ,KAAK,CAAC;AACnD,YAAS,SAAS,QAAQ,cAAc,OAAO,GAAG;GAClD,MAAM,kBAAkB,QACvB,QACA,WAAW,SAAS,WACpB;GAED,MAAM,UAAU,QAAQ,MAAM,QAAQ,OAAO;AAE7C,OAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,EAEjC,KAAI,CADW,QAAQ,QAEtB,KAAI,KACH,wBAAwB,OAAO,gBAAgB,gBAAgB,+BAC/D;QACK;AACN,QAAI,KACH,wBAAwB,OAAO,YAAY,gBAAgB,mFAC3D;AAED;;AAGF,yBAAsB;AAEtB,SAAM,gDAAgD;AACtD,SAAM,gBAAgB;IACrB,YAAY;IACZ,WAAW;IACX,UAAU,4BAA4B;IACtC;IACA;IACA;IACA,CAAC;AACF,SAAM,sCAAsC;;EAE7C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-neon-new",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"neon",
|
|
6
|
+
"database",
|
|
7
|
+
"postgres",
|
|
8
|
+
"vite",
|
|
9
|
+
"neon-new"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"README.md",
|
|
17
|
+
"dist/",
|
|
18
|
+
"package.json"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^20.19.0",
|
|
22
|
+
"@vitest/coverage-v8": "3.0.9",
|
|
23
|
+
"tsdown": "^0.14.1",
|
|
24
|
+
"typescript": "^5.8.2",
|
|
25
|
+
"vite": "^6.4.1",
|
|
26
|
+
"vitest": "^3.0.9"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"vite": "^6.0.0 || ^7.0.0"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@clack/prompts": "0.10.1",
|
|
36
|
+
"neon-new": "0.14.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc --noEmit && tsdown",
|
|
40
|
+
"test": "vitest --passWithNoTests",
|
|
41
|
+
"test:ci": "vitest run --passWithNoTests",
|
|
42
|
+
"tsc": "tsc",
|
|
43
|
+
"dry:run": "pnpm build && node dist/cli.js --yes",
|
|
44
|
+
"dry:run:prompt": "pnpm build && node dist/cli.js"
|
|
45
|
+
}
|
|
46
|
+
}
|