Skip to content

Commit

Permalink
Rollback styleEntrypoint option
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Sep 20, 2024
1 parent 8900979 commit 5d77c5e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-pugs-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chialab/plasma': minor
---

Rollback `styleEntrypoint` option: importing the css module in the svelte file can cause problems with vite preprocessor. The css module should be imported manually.
7 changes: 0 additions & 7 deletions docs/guide/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ The custom elements manifest path to use to generate the wrappers. If not specif
The original module entrypoint to use to import component implementation and types.
If the entrypoint is the main module of the package, it matches the name of NPM module.

## Style entrypoint

- `--style`
- Type: `string`

The original module entrypoint to use to import component styles.

## Outdir

- `--outdir`, `-o`
Expand Down
3 changes: 0 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ program

.argument('[input]', 'custom elements manifest path')
.option('-e, --entrypoint <path>', 'module entrypoint')
.option('--style <path>', 'style module entrypoint')
.option('-o, --outdir <outdir>', 'output directory')
.option('-f, --frameworks <frameworks...>', 'the framework to convert to')
.option('-y, --yes', 'convert all candidates to all available frameworks')
Expand All @@ -50,7 +49,6 @@ program
sourceDir,
options: {
entrypoint?: string;
style?: string;
outdir?: string;
frameworks?: Frameworks[];
yes?: boolean;
Expand Down Expand Up @@ -160,7 +158,6 @@ program
);
const outFile = await transform(entry, framework, {
entrypoint: entrypoint as string,
styleEntrypoint: options.style,
outdir: outDir,
});
task.title = `Converted ${chalk.whiteBright(component)} to ${colorFramework(
Expand Down
20 changes: 7 additions & 13 deletions src/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ export interface SvelteTransformOptions {
* The output directory to write the converted components to.
*/
outdir: string;

/**
* The style entrypoint.
*/
styleEntrypoint?: string;
}

function getAttributes(tagName: string) {
Expand Down Expand Up @@ -203,12 +198,7 @@ export function generateSvelteComponent(entry: Entry, options: SvelteTransformOp
>${slots.join('')}</${definition.extend ?? definition.name}>`;

return `<script>
import '${options.entrypoint}';${
options.styleEntrypoint
? `
import '${options.styleEntrypoint}';`
: ''
}
import '${options.entrypoint}';
function __sync(node, props) {
const state = {};
Expand All @@ -232,9 +222,13 @@ export function generateSvelteComponent(entry: Entry, options: SvelteTransformOp
let __element;
export function getElement() {
return __element;
}
}${
props.length
? `
${props.map((propName) => `export let ${propName} = undefined;`).join('\n ')}
${props.map((propName) => `export let ${propName} = undefined;`).join('\n ')}`
: ''
}
</script>
${markup}`;
Expand Down
9 changes: 6 additions & 3 deletions test/src/svelte/TestElement.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
function __sync(node, props) {
const state = {};
const assign = (node, props) => {
for (const key in props)
if (props[key] !== undefined || state[key] !== undefined)
node[key] = state[key] = props[key];
node.assign(Object.entries(props).reduce((acc, [key, value]) => {
if (props[key] !== undefined || state[key] !== undefined) {
acc[key] = state[key] = props[key];
}
return acc;
}, {}));
};
assign(node, props);
Expand Down
9 changes: 6 additions & 3 deletions test/src/svelte/TestLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
function __sync(node, props) {
const state = {};
const assign = (node, props) => {
for (const key in props)
if (props[key] !== undefined || state[key] !== undefined)
node[key] = state[key] = props[key];
node.assign(Object.entries(props).reduce((acc, [key, value]) => {
if (props[key] !== undefined || state[key] !== undefined) {
acc[key] = state[key] = props[key];
}
return acc;
}, {}));
};
assign(node, props);
Expand Down

0 comments on commit 5d77c5e

Please sign in to comment.