Skip to content

Commit 19f0c85

Browse files
committed
Merge branch 'main' of github.com:sveltejs/cli into pnpmBuildDependency
2 parents a311c0a + 916f9b7 commit 19f0c85

9 files changed

Lines changed: 65 additions & 27 deletions

File tree

.changeset/some-rings-appear.md

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

packages/sv-utils/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @sveltejs/sv-utils
22

3+
## 0.1.0
4+
### Minor Changes
5+
6+
7+
- feat: community add-ons are now **experimental** ([#1020](https://github.com/sveltejs/cli/pull/1020))
8+
39
## 0.0.5
410
### Patch Changes
511

packages/sv-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sveltejs/sv-utils",
3-
"version": "0.0.5",
3+
"version": "0.1.0",
44
"type": "module",
55
"description": "Utility functions for sv",
66
"license": "MIT",

packages/sv/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# sv
22

3+
## 0.14.0
4+
### Minor Changes
5+
6+
7+
- feat: community add-ons are now **experimental** ([#1020](https://github.com/sveltejs/cli/pull/1020))
8+
9+
10+
### Patch Changes
11+
12+
- Updated dependencies [[`c0e5831`](https://github.com/sveltejs/cli/commit/c0e583126279afe7aff8cebb03c5b3928d73b521)]:
13+
- @sveltejs/sv-utils@0.1.0
14+
315
## 0.13.2
416
### Patch Changes
517

packages/sv/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sv",
3-
"version": "0.13.2",
3+
"version": "0.14.0",
44
"type": "module",
55
"description": "A command line interface (CLI) for creating and maintaining Svelte applications",
66
"license": "MIT",

packages/sv/src/cli/create.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,25 @@ async function createProject(cwd: ProjectPath, options: Options) {
258258
const projectPath = path.resolve(directory);
259259
const basename = path.basename(projectPath);
260260
const parentDirName = path.basename(path.dirname(projectPath));
261-
const projectName = parentDirName.startsWith('@') ? `${parentDirName}/${basename}` : basename;
261+
let projectName = parentDirName.startsWith('@') ? `${parentDirName}/${basename}` : basename;
262262

263263
if (template === 'addon' && !projectName.startsWith('@')) {
264264
// At this stage, we don't support un-scoped add-ons
265265
// FYI: a demo exists for `npx sv add my-cool-addon`
266-
common.errorAndExit(
267-
`Community add-ons must be published under an npm org (e.g. ${color.command('@my-org/sv')}). Unscoped package names are not supported at this stage.`
268-
);
266+
const org = await p.text({
267+
message: `Community add-ons must be published under an npm org. Enter the name of your npm org:`,
268+
placeholder: ' @my-org',
269+
validate: (value) => {
270+
if (!value) return 'Organization name is required';
271+
if (!value.startsWith('@')) return 'Must start with @';
272+
if (value.includes('/')) return 'Just the org, not the full package name';
273+
}
274+
});
275+
if (p.isCancel(org)) {
276+
p.cancel('Operation cancelled.');
277+
process.exit(0);
278+
}
279+
projectName = `${org}/${basename}`;
269280
}
270281

271282
if (template === 'addon' && options.add.length > 0) {

packages/sv/src/cli/tests/snapshots/@my-org/sv/tests/addon.test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const browser = false;
1010
const { test, prepareServer, testCases } = setupTest(
1111
{ addon },
1212
{
13-
kinds: [{ type: 'default', options: { addon: { who: 'you' } } }],
13+
kinds: [{ type: 'default', options: { [addon.id]: { who: 'you' } } }],
1414
filter: (testCase) => testCase.variant.includes('kit'),
1515
browser
1616
}
@@ -21,15 +21,18 @@ test.concurrent.for(testCases)(
2121
async (testCase, { page, ...ctx }) => {
2222
const cwd = ctx.cwd(testCase);
2323

24-
const msg =
25-
"This is a text file made by the Community Addon Template demo for the add-on: '@my-org/sv'!";
24+
const msg = "Community Addon Template demo for the add-on: '@my-org/sv'!";
2625

2726
const contentPath = path.resolve(cwd, `src/lib/@my-org/sv/content.txt`);
2827
const contentContent = fs.readFileSync(contentPath, 'utf8');
29-
3028
// Check if we have the imports
3129
expect(contentContent).toContain(msg);
3230

31+
const helloPath = path.resolve(cwd, `src/lib/@my-org/sv/HelloComponent.svelte`);
32+
const helloContent = fs.readFileSync(helloPath, 'utf8');
33+
// Check if we have the imports
34+
expect(helloContent).toContain('you');
35+
3336
// For browser testing
3437
if (browser) {
3538
const { close } = await prepareServer({ cwd, page });

packages/sv/src/create/templates/addon/tests/addon.test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const browser = false;
1010
const { test, prepareServer, testCases } = setupTest(
1111
{ addon },
1212
{
13-
kinds: [{ type: 'default', options: { addon: { who: 'you' } } }],
13+
kinds: [{ type: 'default', options: { [addon.id]: { who: 'you' } } }],
1414
filter: (testCase) => testCase.variant.includes('kit'),
1515
browser
1616
}
@@ -21,15 +21,18 @@ test.concurrent.for(testCases)(
2121
async (testCase, { page, ...ctx }) => {
2222
const cwd = ctx.cwd(testCase);
2323

24-
const msg =
25-
"This is a text file made by the Community Addon Template demo for the add-on: '~SV-NAME-TODO~'!";
24+
const msg = "Community Addon Template demo for the add-on: '~SV-NAME-TODO~'!";
2625

2726
const contentPath = path.resolve(cwd, `src/lib/~SV-NAME-TODO~/content.txt`);
2827
const contentContent = fs.readFileSync(contentPath, 'utf8');
29-
3028
// Check if we have the imports
3129
expect(contentContent).toContain(msg);
3230

31+
const helloPath = path.resolve(cwd, `src/lib/~SV-NAME-TODO~/HelloComponent.svelte`);
32+
const helloContent = fs.readFileSync(helloPath, 'utf8');
33+
// Check if we have the imports
34+
expect(helloContent).toContain('you');
35+
3336
// For browser testing
3437
if (browser) {
3538
const { close } = await prepareServer({ cwd, page });

packages/sv/src/testing.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,17 @@ export async function prepareServer({
239239
return { url, close };
240240
}
241241

242+
export type PlaywrightContext = Pick<typeof import('@playwright/test'), 'chromium'>;
243+
242244
export type VitestContext = Pick<
243245
typeof import('vitest'),
244246
'inject' | 'test' | 'beforeAll' | 'beforeEach'
245247
>;
246248

247-
export function createSetupTest(vitest: VitestContext): <Addons extends AddonMap>(
249+
export function createSetupTest(
250+
vitest: VitestContext,
251+
playwright?: PlaywrightContext
252+
): <Addons extends AddonMap>(
248253
addons: Addons,
249254
options?: SetupTestOptions<Addons>
250255
) => {
@@ -272,12 +277,16 @@ export function createSetupTest(vitest: VitestContext): <Addons extends AddonMap
272277
if (withBrowser) {
273278
beforeAll(async () => {
274279
let chromium: Awaited<typeof import('@playwright/test')>['chromium'];
275-
try {
276-
({ chromium } = await import('@playwright/test'));
277-
} catch {
278-
throw new Error(
279-
'Browser testing requires @playwright/test. Install it with: pnpm add -D @playwright/test'
280-
);
280+
if (playwright) {
281+
chromium = playwright.chromium;
282+
} else {
283+
try {
284+
({ chromium } = await import('@playwright/test'));
285+
} catch {
286+
throw new Error(
287+
'Browser testing requires @playwright/test. Install it with: pnpm add -D @playwright/test'
288+
);
289+
}
281290
}
282291
browser = await chromium.launch();
283292
return async () => {

0 commit comments

Comments
 (0)