Skip to content

Commit

Permalink
Merge branch 'main' into chore/update-storybook-to-v8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel3108 authored Nov 14, 2024
2 parents 3a3776c + 9da497f commit 51c65c3
Show file tree
Hide file tree
Showing 33 changed files with 1,533 additions and 1,675 deletions.
38 changes: 17 additions & 21 deletions community-adder-template/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@ export const options = defineAdderOptions({

export default defineAdder({
id: 'community-addon',
environments: { kit: true, svelte: true },
options,
packages: [],
files: [
{
name: () => 'adder-template-demo.txt',
content: ({ content, options }) => {
if (options.demo) {
return 'This is a text file made by the Community Adder Template demo!';
}
return content;
setup: ({ kit, unsupported }) => {
if (!kit) unsupported('Requires SvelteKit');
},
run: ({ sv, options, typescript }) => {
sv.file('adder-template-demo.txt', (content) => {
if (options.demo) {
return 'This is a text file made by the Community Adder Template demo!';
}
},
{
name: () => 'src/DemoComponent.svelte',
content: ({ content, options, typescript }) => {
if (!options.demo) return content;
const { script, generateCode } = parseSvelte(content, { typescript });
imports.addDefault(script.ast, '../adder-template-demo.txt?raw', 'demo');
return generateCode({ script: script.generateCode(), template: '{demo}' });
}
}
]
return content;
});

sv.file('src/DemoComponent.svelte', (content) => {
if (!options.demo) return content;
const { script, generateCode } = parseSvelte(content, { typescript });
imports.addDefault(script.ast, '../adder-template-demo.txt?raw', 'demo');
return generateCode({ script: script.generateCode(), template: '{demo}' });
});
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"prettier": "^3.3.3",
"prettier-plugin-packagejson": "^2.5.3",
"prettier-plugin-svelte": "^3.2.6",
"rollup": "^4.21.2",
"rollup": "^4.22.4",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-preserve-shebangs": "^0.2.0",
"sv": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/adders/_config/official.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const officialAdders = [
mdsvex,
paraglide,
storybook
];
] as AdderWithoutExplicitArgs[];

export function getAdderDetails(id: string): AdderWithoutExplicitArgs {
const details = officialAdders.find((a) => a.id === id);
Expand Down
30 changes: 30 additions & 0 deletions packages/adders/_tests/all-addons/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import process from 'node:process';
import { expect } from '@playwright/test';
import { setupTest } from '../_setup/suite.ts';
import { officialAdders } from '../../index.ts';
import type { AddonMap, OptionMap } from 'sv';

const windowsCI = process.env.CI && process.platform === 'win32';
const addons = officialAdders.reduce<AddonMap>((addonMap, addon) => {
if (addon.id === 'storybook' && windowsCI) return addonMap;
addonMap[addon.id] = addon;
return addonMap;
}, {});

const defaultOptions = officialAdders.reduce<OptionMap<typeof addons>>((options, addon) => {
options[addon.id] = {};
return options;
}, {});

const { test, variants, prepareServer } = setupTest(addons);

const kitOnly = variants.filter((v) => v.startsWith('kit'));
test.concurrent.for(kitOnly)('run all addons - %s', async (variant, { page, ...ctx }) => {
const cwd = await ctx.run(variant, defaultOptions);

const { close } = await prepareServer({ cwd, page });
// kill server process when we're done
ctx.onTestFinished(async () => await close());

expect(true).toBe(true);
});
12 changes: 11 additions & 1 deletion packages/adders/_tests/eslint/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import fs from 'node:fs';
import path from 'node:path';
import { execSync } from 'node:child_process';
import { expect } from '@playwright/test';
import { setupTest } from '../_setup/suite.ts';
import eslint from '../../eslint/index.ts';
Expand All @@ -11,5 +14,12 @@ test.concurrent.for(variants)('core - %s', async (variant, { page, ...ctx }) =>
// kill server process when we're done
ctx.onTestFinished(async () => await close());

expect(true).toBe(true);
const unlintedFile = 'let foo = "";\nif (Boolean(foo)) {\n//\n}';
fs.writeFileSync(path.resolve(cwd, 'foo.js'), unlintedFile, 'utf8');

expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).toThrowError();

expect(() => execSync('pnpm eslint --fix .', { cwd, stdio: 'pipe' })).not.toThrowError();

expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).not.toThrowError();
});
12 changes: 11 additions & 1 deletion packages/adders/_tests/prettier/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import fs from 'node:fs';
import path from 'node:path';
import { execSync } from 'node:child_process';
import { expect } from '@playwright/test';
import { setupTest } from '../_setup/suite.ts';
import prettier from '../../prettier/index.ts';
Expand All @@ -11,5 +14,12 @@ test.concurrent.for(variants)('core - %s', async (variant, { page, ...ctx }) =>
// kill server process when we're done
ctx.onTestFinished(async () => await close());

expect(true).toBe(true);
const unformattedFile = 'const foo = "bar"';
fs.writeFileSync(path.resolve(cwd, 'foo.js'), unformattedFile, 'utf8');

expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).toThrowError();

expect(() => execSync('pnpm format', { cwd, stdio: 'pipe' })).not.toThrowError();

expect(() => execSync('pnpm lint', { cwd, stdio: 'pipe' })).not.toThrowError();
});
5 changes: 3 additions & 2 deletions packages/adders/_tests/storybook/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const { test, variants, prepareServer } = setupTest({ storybook });

let port = 6006;

const skip = process.env.CI && process.platform === 'win32';
test.skipIf(skip).concurrent.for(variants)(
const windowsCI = process.env.CI && process.platform === 'win32';
test.for(variants)(
'storybook loaded - %s',
{ concurrent: !windowsCI },
async (variant, { page, ...ctx }) => {
const cwd = await ctx.run(variant, { storybook: {} });

Expand Down
8 changes: 2 additions & 6 deletions packages/adders/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { imports, exports, common } from '@sveltejs/cli-core/js';
import { type Question, type FileEditor } from '@sveltejs/cli-core';
import { parseScript, parseSvelte } from '@sveltejs/cli-core/parsers';

export function addEslintConfigPrettier({ content }: FileEditor<Record<string, Question>>): string {
export function addEslintConfigPrettier(content: string): string {
const { ast, generateCode } = parseScript(content);

// if a default import for `eslint-plugin-svelte` already exists, then we'll use their specifier's name instead
Expand Down Expand Up @@ -65,10 +64,7 @@ export function addEslintConfigPrettier({ content }: FileEditor<Record<string, Q
return generateCode();
}

export function addToDemoPage(
{ content }: FileEditor<Record<string, Question>>,
path: string
): string {
export function addToDemoPage(content: string, path: string): string {
const { template, generateCode } = parseSvelte(content);

for (const node of template.ast.childNodes) {
Expand Down
Loading

0 comments on commit 51c65c3

Please sign in to comment.