Skip to content

Commit 6f88993

Browse files
committed
Merge branch 'main' into feat/addons-as-args
2 parents 16ba7a2 + 30c09ac commit 6f88993

38 files changed

+217
-1992
lines changed

CONTRIBUTING.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# SV Contributing Guide
2+
3+
## Workflow
4+
5+
We follow the standard fork-based workflow:
6+
7+
1. **Fork** this repository to your GitHub account.
8+
2. **Clone** your fork locally.
9+
3. **Create a new branch** for your change:
10+
`git checkout -b your-feature-name`
11+
4. **Commit and push** your changes to your branch.
12+
5. **Open a pull request** from your branch to the `main` branch of this repository.
13+
14+
Please keep your pull requests focused to feature or issue. Focused smaller changes are easier to review and faster to merge.
15+
16+
## Preparing
17+
This is a monorepo, meaning the repo holds multiple packages. It requires the use of [pnpm](https://pnpm.io/). You can [install pnpm](https://pnpm.io/installation) with:
18+
19+
```bash
20+
npm i -g pnpm
21+
```
22+
23+
For running certain packages and tests locally you will need to install [docker](https://docs.docker.com/get-started/get-docker).
24+
Linux users, you will have to ensure 'sudo' is not required. See [docker post install](https://docs.docker.com/engine/install/linux-postinstall/)
25+
26+
`pnpm` commands run in the project's root directory will run on all sub-projects. You can checkout the code and install the dependencies with:
27+
28+
```bash
29+
cd cli
30+
pnpm install
31+
```
32+
33+
## Build and run
34+
To build the project and all packages. Run the 'build' script:
35+
36+
```bash
37+
# from root of project
38+
pnpm build
39+
```
40+
This outputs into /packages/PACKAGE/dist/.
41+
42+
Run the 'cli' package:
43+
```bash
44+
pnpm sv
45+
```
46+
47+
Run build with watch mode:
48+
```bash
49+
pnpm dev
50+
```
51+
52+
## Testing
53+
54+
For each add-on we have integration tests setup. These install the deps, build the app, run the dev server and then run a few small snippets against the add-on to see if the changes introduced by the add-on are working as expected.
55+
56+
Run all tests:
57+
```bash
58+
# from root of project
59+
pnpm test
60+
```
61+
62+
Run tests with vitest ui:
63+
```bash
64+
# from root of project
65+
pnpm test:ui
66+
```
67+
68+
Run package specific tests by specifying a project flag to the package and running the test command. Eg:
69+
```bash
70+
pnpm test --project core # addons / create / migrate / etc.
71+
```
72+
73+
To run a individual test. `cd` into the package. Run the local `test` script to that package, with a path arg to the individual peice you want tested. Eg:
74+
```bash
75+
pnpm test [path-to-test]
76+
```
77+
78+
To debug a failing test. A good starting point is to `cd` into the failing tests dir. Proceed to `build` it. Then `preview` it. From here you will have increased information to help in the debug process. Eg:
79+
```bash
80+
# Each test is a standalone app
81+
cd .test-output/addons/[addon-test]/[test-id]
82+
pnpm build
83+
pnpm preview
84+
```
85+
86+
## Style Guide
87+
88+
### Coding style
89+
90+
There are a few guidelines we follow:
91+
92+
- Ensure `pnpm lint` and `pnpm check` pass. You can run `pnpm format` to format the code
93+
- linting
94+
```bash
95+
# from root of project
96+
pnpm lint
97+
```
98+
- formatting
99+
```bash
100+
# from root of project
101+
pnpm format
102+
```
103+
- type checking
104+
```bash
105+
# from root of project
106+
pnpm check
107+
```
108+
109+
## svelte-migrate
110+
To run svelte-migrate locally:
111+
```bash
112+
# from root of project
113+
node ./packages/migrate/bin.js
114+
```
115+
116+
## Generating changelogs
117+
Only publish a change set if it is in 'sv' or 'svelte-migrate' as all other packages are bundled.
118+
For changes to be reflected in package changelogs:
119+
```bash
120+
# from root of project
121+
pnpm changeset:publish
122+
```

packages/addons/_tests/drizzle/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test.concurrent.for(testCases)(
4343

4444
const ts = variant === 'kit-ts';
4545
const drizzleConfig = path.resolve(cwd, `drizzle.config.${ts ? 'ts' : 'js'}`);
46-
const content = fs.readFileSync(drizzleConfig, 'utf8').replace('strict: true,', '');
46+
const content = fs.readFileSync(drizzleConfig, 'utf8').replace(/strict: true[,\s]/, '');
4747
fs.writeFileSync(drizzleConfig, content, 'utf8');
4848

4949
const routes = path.resolve(cwd, 'src', 'routes');

packages/addons/drizzle/index.ts

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
13
import { common, exports, functions, imports, object, variables } from '@sveltejs/cli-core/js';
24
import { defineAddon, defineAddonOptions, dedent, type OptionValues } from '@sveltejs/cli-core';
35
import { parseJson, parseScript } from '@sveltejs/cli-core/parsers';
@@ -69,8 +71,21 @@ export default defineAddon({
6971
shortDescription: 'database orm',
7072
homepage: 'https://orm.drizzle.team',
7173
options,
72-
setup: ({ kit, unsupported }) => {
74+
setup: ({ kit, unsupported, cwd, typescript }) => {
75+
const ext = typescript ? 'ts' : 'js';
7376
if (!kit) unsupported('Requires SvelteKit');
77+
78+
const baseDBPath = path.resolve(kit!.libDirectory, 'server', 'db');
79+
const paths = {
80+
'drizzle config': path.relative(cwd, path.resolve(cwd, `drizzle.config.${ext}`)),
81+
'database schema': path.relative(cwd, path.resolve(baseDBPath, `schema.${ext}`)),
82+
database: path.relative(cwd, path.resolve(baseDBPath, `index.${ext}`))
83+
};
84+
for (const [fileType, filePath] of Object.entries(paths)) {
85+
if (fs.existsSync(filePath)) {
86+
unsupported(`Preexisting ${fileType} file at '${filePath}'`);
87+
}
88+
}
7489
},
7590
run: ({ sv, typescript, options, kit }) => {
7691
const ext = typescript ? 'ts' : 'js';
@@ -178,41 +193,27 @@ export default defineAddon({
178193

179194
imports.addNamed(ast, 'drizzle-kit', { defineConfig: 'defineConfig' });
180195

181-
const envCheckStatement = common.statementFromString(
182-
"if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');"
196+
common.addStatement(
197+
ast,
198+
common.statementFromString(
199+
"if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');"
200+
)
183201
);
184-
common.addStatement(ast, envCheckStatement);
185-
186-
const fallback = common.expressionFromString('defineConfig({})');
187-
const { value: exportDefault } = exports.defaultExport(ast, fallback);
188-
if (exportDefault.type !== 'CallExpression') return content;
189-
190-
const objExpression = exportDefault.arguments?.[0];
191-
if (!objExpression || objExpression.type !== 'ObjectExpression') return content;
192-
193-
const authToken =
194-
options.sqlite === 'turso'
195-
? common.expressionFromString('process.env.DATABASE_AUTH_TOKEN')
196-
: undefined;
197-
198-
object.properties(objExpression, {
199-
schema: common.createLiteral(`./src/lib/server/db/schema.${typescript ? 'ts' : 'js'}`),
200-
dbCredentials: object.create({
201-
url: common.expressionFromString('process.env.DATABASE_URL'),
202-
authToken
203-
}),
204-
verbose: { type: 'Literal', value: true },
205-
strict: { type: 'Literal', value: true }
206-
});
207-
208-
const dialect = options.sqlite === 'turso' ? 'turso' : options.database;
209-
object.overrideProperties(objExpression, {
210-
dialect: common.createLiteral(dialect)
211-
});
212202

213-
// The `driver` property is only required for _some_ sqlite DBs.
214-
// We'll need to remove it if it's anything but sqlite
215-
if (options.database !== 'sqlite') object.removeProperty(objExpression, 'driver');
203+
exports.defaultExport(
204+
ast,
205+
common.expressionFromString(`
206+
defineConfig({
207+
schema: "./src/lib/server/db/schema.${typescript ? 'ts' : 'js'}",
208+
dialect: "${options.sqlite === 'turso' ? 'turso' : options.database}",
209+
dbCredentials: {
210+
${options.sqlite === 'turso' ? 'authToken: process.env.DATABASE_AUTH_TOKEN,' : ''}
211+
url: process.env.DATABASE_URL
212+
},
213+
verbose: true,
214+
strict: true
215+
})`)
216+
);
216217

217218
return generateCode();
218219
});

packages/clack-core/LICENSE

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/clack-core/README.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/clack-core/index.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/clack-core/package.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

packages/clack-core/src/prompts/confirm.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)