Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify imports #243

Merged
merged 9 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
},
"license": "MIT",
"type": "module",
"imports": {
"#tests/*": {
"development": "./tests/*.ts"
},
"#*": {
"development": "./src/*.ts",
"default": "./dist/*.js"
}
},
"exports": {
".": {
"types": "./dist/index.d.ts",
Expand All @@ -44,7 +35,7 @@
"README.md"
],
"scripts": {
"build": "svelte-package --input ./src --types",
"build": "svelte-package --types",
"build-storybook": "storybook build",
"check": "svelte-check",
"chromatic": "chromatic --exit-zero-on-changes",
Expand All @@ -54,7 +45,7 @@
"lint": "eslint --cache --cache-location=.cache/eslint --ext .js,.json,.html,.svelte,.ts --report-unused-disable-directives",
"prepublish": "pnpm run clean && pnpm run build",
"release": "pnpm run build && auto shipit",
"start": "concurrently \"pnpm run storybook --quiet\" \"pnpm run build --watch\"",
"start": "pnpm run build && concurrently \"pnpm run build --watch\" \"pnpm run storybook --quiet\"",
"storybook": "storybook dev --port 6006 --no-open",
"test": "vitest run",
"test:watch": "vitest watch"
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import MagicString from 'magic-string';
import { preprocess } from 'svelte/compiler';
import type { Plugin } from 'vite';

import { codemodLegacyNodes } from '#compiler/pre-transform/index';
import { transformStoriesCode } from '#compiler/post-transform/index';
import { getSvelteAST } from '#parser/ast';
import { extractCompiledASTNodes } from '#parser/extract/compiled/nodes';
import { extractSvelteASTNodes } from '#parser/extract/svelte/nodes';
import { codemodLegacyNodes } from '$lib/compiler/pre-transform/index.js';
import { transformStoriesCode } from '$lib/compiler/post-transform/index.js';
import { getSvelteAST } from '$lib/parser/ast.js';
import { extractCompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';
import { extractSvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';

export async function preTransformPlugin(): Promise<Plugin> {
const [{ createFilter }, { print }] = await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { print } from 'esrap';
import { describe, it } from 'vitest';

import { createExportDefaultMeta } from './create-export-default';
import { createExportDefaultMeta } from './create-export-default.js';

import type { ESTreeAST } from '#parser/ast';
import type { ESTreeAST } from '$lib/parser/ast.js';

describe(createExportDefaultMeta.name, () => {
it('creates a new export default correctly', ({ expect }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/post-transform/appendix/create-export-default.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { getMetaIdentifier } from '#parser/analyse/define-meta/meta-identifier';
import type { ESTreeAST } from '#parser/ast';
import type { getMetaIdentifier } from '$lib/parser/analyse/define-meta/meta-identifier.js';
import type { ESTreeAST } from '$lib/parser/ast.js';

interface Params {
metaIdentifier: ReturnType<typeof getMetaIdentifier>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { print } from 'esrap';
import { describe, it } from 'vitest';

import { createExportOrderVariable } from './create-export-order';
import { createExportOrderVariable } from './create-export-order.js';

describe(createExportOrderVariable.name, () => {
it('correctly creates a variable with named exports order', ({ expect }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/post-transform/appendix/create-export-order.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { getStoriesIdentifiers } from '#parser/analyse/story/attributes/identifiers';
import type { ESTreeAST } from '#parser/ast';
import type { getStoriesIdentifiers } from '$lib/parser/analyse/story/attributes/identifiers.js';
import type { ESTreeAST } from '$lib/parser/ast.js';

interface Params {
storyIdentifiers: ReturnType<typeof getStoriesIdentifiers>;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/post-transform/appendix/create-import.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { print } from 'esrap';
import { describe, it } from 'vitest';

import { createRuntimeStoriesImport } from './create-import';
import { createRuntimeStoriesImport } from './create-import.js';

describe(createRuntimeStoriesImport.name, () => {
it('creates import correctly', ({ expect }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/post-transform/appendix/create-import.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pkg from '@storybook/addon-svelte-csf/package.json' with { type: 'json' };

import type { ESTreeAST } from '#parser/ast';
import type { ESTreeAST } from '$lib/parser/ast.js';

/**
* The export is defined in the `package.json` export map
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { print } from 'esrap';
import { describe, it } from 'vitest';

import { createNamedExportStory } from './create-named-export-story';
import { createVariableFromRuntimeStoriesCall } from './create-variable-from-runtime-stories-call';
import { createNamedExportStory } from './create-named-export-story.js';
import { createVariableFromRuntimeStoriesCall } from './create-variable-from-runtime-stories-call.js';

import type { ESTreeAST } from '#parser/ast';
import type { ESTreeAST } from '$lib/parser/ast.js';

describe(createNamedExportStory.name, () => {
it('correctly creates a variable with named exports order', ({ expect }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { createVariableFromRuntimeStoriesCall } from './create-variable-from-runtime-stories-call';
import type { createVariableFromRuntimeStoriesCall } from './create-variable-from-runtime-stories-call.js';

import type { ESTreeAST } from '#parser/ast';
import type { ESTreeAST } from '$lib/parser/ast.js';

interface Params {
exportName: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { print } from 'esrap';
import { describe, it } from 'vitest';

import { createVariableFromRuntimeStoriesCall } from './create-variable-from-runtime-stories-call';
import { createVariableFromRuntimeStoriesCall } from './create-variable-from-runtime-stories-call.js';

describe(createVariableFromRuntimeStoriesCall.name, () => {
it('creates a variable correctly', ({ expect }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { getMetaIdentifier } from '#parser/analyse/define-meta/meta-identifier';
import type { ESTreeAST } from '#parser/ast';
import type { getMetaIdentifier } from '$lib/parser/analyse/define-meta/meta-identifier.js';
import type { ESTreeAST } from '$lib/parser/ast.js';

interface Params {
storiesFunctionDeclaration: ESTreeAST.FunctionDeclaration;
Expand Down
18 changes: 9 additions & 9 deletions src/compiler/post-transform/create-appendix.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { print } from 'esrap';
import MagicString from 'magic-string';

import { createExportDefaultMeta } from './appendix/create-export-default';
import { createExportOrderVariable } from './appendix/create-export-order';
import { createRuntimeStoriesImport } from './appendix/create-import';
import { createVariableFromRuntimeStoriesCall } from './appendix/create-variable-from-runtime-stories-call';
import { createNamedExportStory } from './appendix/create-named-export-story';
import { createExportDefaultMeta } from './appendix/create-export-default.js';
import { createExportOrderVariable } from './appendix/create-export-order.js';
import { createRuntimeStoriesImport } from './appendix/create-import.js';
import { createVariableFromRuntimeStoriesCall } from './appendix/create-variable-from-runtime-stories-call.js';
import { createNamedExportStory } from './appendix/create-named-export-story.js';

import { getMetaIdentifier } from '#parser/analyse/define-meta/meta-identifier';
import type { CompiledASTNodes } from '#parser/extract/compiled/nodes';
import type { SvelteASTNodes } from '#parser/extract/svelte/nodes';
import { getStoriesIdentifiers } from '#parser/analyse/story/attributes/identifiers';
import { getMetaIdentifier } from '$lib/parser/analyse/define-meta/meta-identifier.js';
import type { CompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';
import type { SvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';
import { getStoriesIdentifiers } from '$lib/parser/analyse/story/attributes/identifiers.js';

interface Params {
code: MagicString;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/post-transform/define-meta/destructure-meta.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CompiledASTNodes } from '#parser/extract/compiled/nodes';
import { NoDestructuredDefineMetaCallError } from '#utils/error/parser/analyse/define-meta';
import type { CompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';
import { NoDestructuredDefineMetaCallError } from '$lib/utils/error/parser/analyse/define-meta.js';

interface Params {
nodes: CompiledASTNodes;
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/post-transform/define-meta/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { describe, it } from 'vitest';

import { transformDefineMeta } from '.';

import { getSvelteAST } from '#parser/ast';
import { extractSvelteASTNodes } from '#parser/extract/svelte/nodes';
import { extractCompiledASTNodes } from '#parser/extract/compiled/nodes';
import { getSvelteAST } from '$lib/parser/ast.js';
import { extractSvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';
import { extractCompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/post-transform/define-meta/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { print } from 'esrap';
import type MagicString from 'magic-string';

import { destructureMetaFromDefineMeta } from './destructure-meta';
import { insertDefineMetaJSDocCommentAsDescription } from './insert-description';
import { destructureMetaFromDefineMeta } from './destructure-meta.js';
import { insertDefineMetaJSDocCommentAsDescription } from './insert-description.js';

import type { CompiledASTNodes } from '#parser/extract/compiled/nodes';
import type { SvelteASTNodes } from '#parser/extract/svelte/nodes';
import type { CompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';
import type { SvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';

interface Params {
code: MagicString;
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/post-transform/define-meta/insert-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
getDescriptionPropertyValue,
getDocsPropertyValue,
getParametersPropertyValue,
} from '#compiler/post-transform/shared/description';
import { createASTObjectExpression, createASTProperty, type ESTreeAST } from '#parser/ast';
import type { SvelteASTNodes } from '#parser/extract/svelte/nodes';
import type { CompiledASTNodes } from '#parser/extract/compiled/nodes';
import { getDefineMetaFirstArgumentObjectExpression } from '#parser/extract/svelte/define-meta';
} from '$lib/compiler/post-transform/shared/description.js';
import { createASTObjectExpression, createASTProperty, type ESTreeAST } from '$lib/parser/ast.js';
import type { SvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';
import type { CompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';
import { getDefineMetaFirstArgumentObjectExpression } from '$lib/parser/extract/svelte/define-meta.js';

interface Params {
nodes: {
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/post-transform/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { describe, it } from 'vitest';

import { transformStoriesCode } from '.';

import { getSvelteAST } from '#parser/ast';
import { extractSvelteASTNodes } from '#parser/extract/svelte/nodes';
import { extractCompiledASTNodes } from '#parser/extract/compiled/nodes';
import { getSvelteAST } from '$lib/parser/ast.js';
import { extractSvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';
import { extractCompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

Expand Down
14 changes: 7 additions & 7 deletions src/compiler/post-transform/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type MagicString from 'magic-string';

import { transformStory } from './story';
import { transformDefineMeta } from './define-meta';
import { removeExportDefault } from './remove-export-default';
import { createAppendix } from './create-appendix';
import { transformStory } from './story/index.js';
import { transformDefineMeta } from './define-meta/index.js';
import { removeExportDefault } from './remove-export-default.js';
import { createAppendix } from './create-appendix.js';

import type { CompiledASTNodes } from '#parser/extract/compiled/nodes';
import { extractStoriesNodesFromExportDefaultFn } from '#parser/extract/compiled/stories';
import type { SvelteASTNodes } from '#parser/extract/svelte/nodes';
import type { CompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';
import { extractStoriesNodesFromExportDefaultFn } from '$lib/parser/extract/compiled/stories.js';
import type { SvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';

interface Params {
code: MagicString;
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/post-transform/remove-export-default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import MagicString from 'magic-string';
import { parseAst } from 'rollup/parseAst';
import { describe, it } from 'vitest';

import { removeExportDefault } from './remove-export-default';
import { removeExportDefault } from './remove-export-default.js';

import { extractCompiledASTNodes } from '#parser/extract/compiled/nodes';
import { StorybookSvelteCSFError } from '#utils/error';
import { extractCompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';
import { StorybookSvelteCSFError } from '$lib/utils/error.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/post-transform/remove-export-default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { print } from 'esrap';
import type MagicString from 'magic-string';

import type { CompiledASTNodes } from '#parser/extract/compiled/nodes';
import type { CompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';

interface Params {
code: MagicString;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/post-transform/shared/description.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { logger } from '@storybook/node-logger';
import dedent from 'dedent';

import type { ESTreeAST, SvelteAST } from '#parser/ast';
import type { ESTreeAST, SvelteAST } from '$lib/parser/ast.js';

import { createASTObjectExpression } from '#parser/ast';
import { createASTObjectExpression } from '$lib/parser/ast.js';

interface FindPropertyOptions {
name: string;
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/post-transform/story/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { describe, it } from 'vitest';

import { transformStory } from '.';

import { getSvelteAST } from '#parser/ast';
import { extractSvelteASTNodes } from '#parser/extract/svelte/nodes';
import { extractCompiledASTNodes } from '#parser/extract/compiled/nodes';
import { extractStoriesNodesFromExportDefaultFn } from '#parser/extract/compiled/stories';
import { getSvelteAST } from '$lib/parser/ast.js';
import { extractSvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';
import { extractCompiledASTNodes } from '$lib/parser/extract/compiled/nodes.js';
import { extractStoriesNodesFromExportDefaultFn } from '$lib/parser/extract/compiled/stories.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/post-transform/story/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { print } from 'esrap';
import type MagicString from 'magic-string';

import { insertStoryHTMLCommentAsDescription } from './insert-description';
import { insertSvelteCSFToStoryParameters } from './insert-svelte-csf';
import { insertStoryHTMLCommentAsDescription } from './insert-description.js';
import { insertSvelteCSFToStoryParameters } from './insert-svelte-csf.js';

import type { extractStoriesNodesFromExportDefaultFn } from '#parser/extract/compiled/stories';
import type { SvelteASTNodes } from '#parser/extract/svelte/nodes';
import type { extractStoriesNodesFromExportDefaultFn } from '$lib/parser/extract/compiled/stories.js';
import type { SvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';

interface Params {
code: MagicString;
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/post-transform/story/insert-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {
getParametersPropertyValue,
getDocsPropertyValue,
getDescriptionPropertyValue,
} from '#compiler/post-transform/shared/description';
import { createASTObjectExpression, createASTProperty } from '#parser/ast';
} from '$lib/compiler/post-transform/shared/description.js';
import { createASTObjectExpression, createASTProperty } from '$lib/parser/ast.js';

import type { ESTreeAST } from '#parser/ast';
import type { extractStoriesNodesFromExportDefaultFn } from '#parser/extract/compiled/stories';
import { getStoryPropsObjectExpression } from '#parser/extract/compiled/story';
import type { SvelteASTNodes } from '#parser/extract/svelte/nodes';
import type { ESTreeAST } from '$lib/parser/ast.js';
import type { extractStoriesNodesFromExportDefaultFn } from '$lib/parser/extract/compiled/stories.js';
import { getStoryPropsObjectExpression } from '$lib/parser/extract/compiled/story.js';
import type { SvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';

interface Params {
nodes: {
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/post-transform/story/insert-svelte-csf.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
findPropertyParametersIndex,
getParametersPropertyValue,
} from '#compiler/post-transform/shared/description';
} from '$lib/compiler/post-transform/shared/description.js';

import type { extractStoriesNodesFromExportDefaultFn } from '#parser/extract/compiled/stories';
import { getStoryPropsObjectExpression } from '#parser/extract/compiled/story';
import type { SvelteASTNodes, extractSvelteASTNodes } from '#parser/extract/svelte/nodes';
import { getStoryChildrenRawCode } from '#parser/analyse/story/children';
import { createASTObjectExpression, createASTProperty } from '#parser/ast';
import type { extractStoriesNodesFromExportDefaultFn } from '$lib/parser/extract/compiled/stories.js';
import { getStoryPropsObjectExpression } from '$lib/parser/extract/compiled/story.js';
import type { SvelteASTNodes, extractSvelteASTNodes } from '$lib/parser/extract/svelte/nodes.js';
import { getStoryChildrenRawCode } from '$lib/parser/analyse/story/children.js';
import { createASTObjectExpression, createASTProperty } from '$lib/parser/ast.js';

interface Params {
nodes: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { print } from 'svelte-ast-print';
import { describe, it } from 'vitest';

import { transformComponentMetaToDefineMeta } from './component-meta-to-define-meta';
import { transformComponentMetaToDefineMeta } from './component-meta-to-define-meta.js';

import type { SvelteAST } from '#parser/ast';
import { parseAndExtractSvelteNode } from '#tests/extractor';
import type { SvelteAST } from '$lib/parser/ast.js';
import { parseAndExtractSvelteNode } from '../../../../tests/extractor.js';

describe(transformComponentMetaToDefineMeta.name, () => {
it('works with a simple example', async ({ expect }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
createASTExpressionTag,
type ESTreeAST,
type SvelteAST,
} from '#parser/ast';
} from '$lib/parser/ast.js';

interface Params {
component: SvelteAST.Component;
Expand Down
Loading
Loading