Skip to content

Commit abef027

Browse files
authored
chore: enable isolatedDeclarations for libraries for faster dts transformations (#7)
1 parent 4830305 commit abef027

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+693
-471
lines changed

.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
3+
}

.vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"eslint.useFlatConfig": true,
3+
"typescript.tsdk": "./node_modules/typescript/lib"
4+
}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"private": true,
66
"type": "module",
77
"scripts": {
8-
"check": "tsc --noEmit",
8+
"check": "pnpm -r check",
99
"lint": "pnpm -r lint && eslint --cache --cache-location node_modules/.eslintcache",
1010
"format": "pnpm -r format",
1111
"changeset:version": "changeset version && pnpm -r generate:version && git add --all",
@@ -27,11 +27,11 @@
2727
"prettier": "^3.1.1",
2828
"prettier-plugin-svelte": "^3.2.6",
2929
"rollup": "^4.20.0",
30-
"rollup-plugin-dts": "^6.1.1",
3130
"rollup-plugin-esbuild": "^6.1.1",
3231
"rollup-plugin-preserve-shebangs": "^0.2.0",
3332
"typescript": "^5.3.3",
34-
"typescript-eslint": "^8.0.0"
33+
"typescript-eslint": "^8.0.0",
34+
"unplugin-isolated-decl": "^0.4.5"
3535
},
3636
"packageManager": "[email protected]",
3737
"engines": {

packages/adders/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { AdderConfig, AdderWithoutExplicitArgs } from '@svelte-cli/core/adder/config';
2-
import type { Question } from '@svelte-cli/core/adder/options';
1+
import type { AdderConfig, AdderWithoutExplicitArgs, Question } from '@svelte-cli/core';
32

43
export async function getAdderDetails(name: string) {
54
const adder: { default: AdderWithoutExplicitArgs } = await import(`./${name}/index.ts`);

packages/adders/mdsvex/config/tests.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { defineAdderTests } from '@svelte-cli/core';
1+
import {
2+
defineAdderTests,
3+
type SvelteFileEditorArgs,
4+
type TextFileEditorArgs,
5+
type OptionDefinition
6+
} from '@svelte-cli/core';
27
import { options } from './options';
3-
import type {
4-
SvelteFileEditorArgs,
5-
TextFileEditorArgs
6-
} from '@svelte-cli/core/files/processors.js';
7-
import type { OptionDefinition } from '@svelte-cli/core/adder/options.js';
88

99
export const tests = defineAdderTests({
1010
files: [

packages/adders/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"type": "module",
66
"scripts": {
77
"lint": "prettier --check . --config ../../.prettierrc --ignore-path ../../.gitignore --ignore-path .gitignore",
8-
"format": "pnpm lint --write"
8+
"format": "pnpm lint --write",
9+
"check": "tsc"
910
},
1011
"exports": {
1112
".": {

packages/adders/tailwindcss/config/tests.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { defineAdderTests } from '@svelte-cli/core';
1+
import {
2+
defineAdderTests,
3+
type OptionDefinition,
4+
type SvelteFileEditorArgs
5+
} from '@svelte-cli/core';
26
import { options } from './options';
3-
import type { OptionDefinition } from '@svelte-cli/core/adder/options.js';
4-
import type { SvelteFileEditorArgs } from '@svelte-cli/core/files/processors.js';
57

68
const divId = 'myDiv';
79
const typographyDivId = 'myTypographyDiv';

packages/ast-manipulation/css/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type CssAstEditor = {
1616
addImports: typeof addImports;
1717
};
1818

19-
export function getCssAstEditor(ast: CssAst) {
19+
export function getCssAstEditor(ast: CssAst): CssAstEditor {
2020
const editor: CssAstEditor = {
2121
ast,
2222
addRule,
@@ -42,7 +42,7 @@ export function addRule(ast: CssAst, selector: string): Rule {
4242
return rule;
4343
}
4444

45-
export function addDeclaration(ast: Rule | CssAst, property: string, value: string) {
45+
export function addDeclaration(ast: Rule | CssAst, property: string, value: string): void {
4646
const declarations = ast.nodes.filter((x): x is Declaration => x.type == 'decl');
4747
let declaration = declarations.find((x) => x.prop == property);
4848

@@ -54,7 +54,7 @@ export function addDeclaration(ast: Rule | CssAst, property: string, value: stri
5454
}
5555
}
5656

57-
export function addImports(ast: Rule | CssAst, imports: string[]) {
57+
export function addImports(ast: Rule | CssAst, imports: string[]): CssChildNode[] {
5858
let prev: CssChildNode | undefined;
5959
const nodes = imports.map((param) => {
6060
const found = ast.nodes.find(
@@ -91,7 +91,7 @@ export function addAtRule(ast: CssAst, name: string, params: string, append = fa
9191
return atRule;
9292
}
9393

94-
export function addComment(ast: CssAst, commentValue: string) {
94+
export function addComment(ast: CssAst, commentValue: string): void {
9595
const comment = new Comment({ text: commentValue });
9696
ast.append(comment);
9797
}

packages/ast-manipulation/html/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type HtmlAstEditor = {
1515
appendElement: typeof appendElement;
1616
};
1717

18-
export function getHtmlAstEditor(document: HtmlDocument) {
18+
export function getHtmlAstEditor(document: HtmlDocument): HtmlAstEditor {
1919
const editor: HtmlAstEditor = {
2020
ast: document,
2121
div,
@@ -27,25 +27,25 @@ export function getHtmlAstEditor(document: HtmlDocument) {
2727
return editor;
2828
}
2929

30-
function div(attributes: Record<string, string> = {}) {
30+
function div(attributes: Record<string, string> = {}): HtmlElement {
3131
return element('div', attributes);
3232
}
3333

34-
function element(tagName: string, attributes: Record<string, string> = {}) {
34+
function element(tagName: string, attributes: Record<string, string> = {}): HtmlElement {
3535
const element = new HtmlElement(tagName, {}, undefined, HtmlElementType.Tag);
3636
element.attribs = attributes;
3737
return element;
3838
}
3939

40-
function insertElement(childNodes: HtmlChildNode[], elementToInsert: HtmlChildNode) {
40+
function insertElement(childNodes: HtmlChildNode[], elementToInsert: HtmlChildNode): void {
4141
childNodes.splice(0, 0, elementToInsert);
4242
}
4343

44-
function appendElement(childNodes: HtmlChildNode[], elementToAppend: HtmlChildNode) {
44+
function appendElement(childNodes: HtmlChildNode[], elementToAppend: HtmlChildNode): void {
4545
childNodes.push(elementToAppend);
4646
}
4747

48-
function addFromRawHtml(childNodes: HtmlChildNode[], html: string) {
48+
function addFromRawHtml(childNodes: HtmlChildNode[], html: string): void {
4949
const document = parseHtml(html);
5050
for (const childNode of document.childNodes) {
5151
childNodes.push(childNode);

packages/ast-manipulation/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { getCssAstEditor, type CssAstEditor } from './css/index.js';
2-
import { getHtmlAstEditor, type HtmlAstEditor } from './html/index.js';
3-
import { getJsAstEditor, type JsAstEditor } from './js/index.js';
1+
import { getCssAstEditor, type CssAstEditor } from './css/index';
2+
import { getHtmlAstEditor, type HtmlAstEditor } from './html/index';
3+
import { getJsAstEditor, type JsAstEditor } from './js/index';
44

55
export {
66
getCssAstEditor,

packages/ast-manipulation/js/array.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { areNodesEqual } from './common.js';
1+
import { areNodesEqual } from './common';
22
import type { AstKinds, AstTypes } from '@svelte-cli/ast-tooling';
33

4-
export function createEmpty() {
4+
export function createEmpty(): AstTypes.ArrayExpression {
55
const arrayExpression: AstTypes.ArrayExpression = {
66
type: 'ArrayExpression',
77
elements: []
@@ -12,7 +12,7 @@ export function createEmpty() {
1212
export function push(
1313
ast: AstTypes.ArrayExpression,
1414
data: string | AstKinds.ExpressionKind | AstKinds.SpreadElementKind
15-
) {
15+
): void {
1616
if (typeof data === 'string') {
1717
const existingLiterals = ast.elements.filter(
1818
(x): x is AstTypes.StringLiteral => x?.type == 'StringLiteral'

packages/ast-manipulation/js/common.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import decircular from 'decircular';
1010
import dedent from 'dedent';
1111

12-
export function addJsDocTypeComment(node: AstTypes.Node, type: string) {
12+
export function addJsDocTypeComment(node: AstTypes.Node, type: string): void {
1313
const comment: AstTypes.CommentBlock = {
1414
type: 'CommentBlock',
1515
value: `* @type {${type}} `,
@@ -22,7 +22,10 @@ export function addJsDocTypeComment(node: AstTypes.Node, type: string) {
2222
if (!found) node.comments.push(comment);
2323
}
2424

25-
export function typeAnnotateExpression(node: AstKinds.ExpressionKind, type: string) {
25+
export function typeAnnotateExpression(
26+
node: AstKinds.ExpressionKind,
27+
type: string
28+
): AstTypes.TSAsExpression {
2629
const expression: AstTypes.TSAsExpression = {
2730
type: 'TSAsExpression',
2831
expression: node,
@@ -39,7 +42,7 @@ export function createSpreadElement(expression: AstKinds.ExpressionKind): AstTyp
3942
};
4043
}
4144

42-
export function createLiteral(value: string | null = null) {
45+
export function createLiteral(value: string | null = null): AstTypes.Literal {
4346
const literal: AstTypes.Literal = {
4447
type: 'Literal',
4548
value
@@ -48,7 +51,7 @@ export function createLiteral(value: string | null = null) {
4851
return literal;
4952
}
5053

51-
export function areNodesEqual(ast1: AstTypes.ASTNode, ast2: AstTypes.ASTNode) {
54+
export function areNodesEqual(ast1: AstTypes.ASTNode, ast2: AstTypes.ASTNode): boolean {
5255
// We're deep cloning these trees so that we can strip the locations off of them for comparisons.
5356
// Without this, we'd be getting false negatives due to slight differences in formatting style.
5457
// These ASTs are also filled to the brim with circular references, which prevents
@@ -60,23 +63,28 @@ export function areNodesEqual(ast1: AstTypes.ASTNode, ast2: AstTypes.ASTNode) {
6063
);
6164
}
6265

63-
export function blockStatement() {
66+
export function blockStatement(): AstTypes.BlockStatement {
6467
const statement: AstTypes.BlockStatement = {
6568
type: 'BlockStatement',
6669
body: []
6770
};
6871
return statement;
6972
}
7073

71-
export function expressionStatement(expression: AstKinds.ExpressionKind) {
74+
export function expressionStatement(
75+
expression: AstKinds.ExpressionKind
76+
): AstTypes.ExpressionStatement {
7277
const statement: AstTypes.ExpressionStatement = {
7378
type: 'ExpressionStatement',
7479
expression
7580
};
7681
return statement;
7782
}
7883

79-
export function addFromString(ast: AstTypes.BlockStatement | AstTypes.Program, value: string) {
84+
export function addFromString(
85+
ast: AstTypes.BlockStatement | AstTypes.Program,
86+
value: string
87+
): void {
8088
const program = parseScript(dedent(value));
8189

8290
for (const childNode of program.body) {
@@ -105,7 +113,7 @@ export function statementFromString(value: string): AstKinds.StatementKind {
105113
export function addStatement(
106114
ast: AstTypes.BlockStatement | AstTypes.Program,
107115
statement: AstKinds.StatementKind
108-
) {
116+
): void {
109117
if (!hasNode(ast, statement)) ast.body.push(statement);
110118
}
111119

packages/ast-manipulation/js/exports.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function namedExport(
5757
ast: AstTypes.Program,
5858
name: string,
5959
fallback: AstTypes.VariableDeclaration
60-
) {
60+
): AstTypes.ExportNamedDeclaration | undefined {
6161
const namedExports = ast.body.filter(
6262
(x): x is AstTypes.ExportNamedDeclaration => x.type == 'ExportNamedDeclaration'
6363
);

packages/ast-manipulation/js/function.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { AstKinds, AstTypes } from '@svelte-cli/ast-tooling';
22

3-
export function call(name: string, args: string[]) {
3+
export function call(name: string, args: string[]): AstTypes.CallExpression {
44
const callExpression: AstTypes.CallExpression = {
55
type: 'CallExpression',
66
callee: {
@@ -20,7 +20,7 @@ export function call(name: string, args: string[]) {
2020
return callExpression;
2121
}
2222

23-
export function callByIdentifier(name: string, args: string[]) {
23+
export function callByIdentifier(name: string, args: string[]): AstTypes.CallExpression {
2424
const callExpression: AstTypes.CallExpression = {
2525
type: 'CallExpression',
2626
callee: {
@@ -44,7 +44,7 @@ export function callByIdentifier(name: string, args: string[]) {
4444
export function arrowFunction(
4545
async: boolean,
4646
body: AstKinds.ExpressionKind | AstTypes.BlockStatement
47-
) {
47+
): AstTypes.ArrowFunctionExpression {
4848
const arrowFunction: AstTypes.ArrowFunctionExpression = {
4949
type: 'ArrowFunctionExpression',
5050
async,
@@ -59,7 +59,7 @@ export function argumentByIndex<T extends AstKinds.ExpressionKind>(
5959
ast: AstTypes.CallExpression,
6060
i: number,
6161
fallback: T
62-
) {
62+
): T {
6363
if (i < ast.arguments.length) {
6464
return ast.arguments[i] as T;
6565
}

packages/ast-manipulation/js/imports.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { AstTypes } from '@svelte-cli/ast-tooling';
2-
import { areNodesEqual } from './common.js';
2+
import { areNodesEqual } from './common';
33

4-
export function addEmpty(ast: AstTypes.Program, importFrom: string) {
4+
export function addEmpty(ast: AstTypes.Program, importFrom: string): void {
55
const expectedImportDeclaration: AstTypes.ImportDeclaration = {
66
type: 'ImportDeclaration',
77
source: {
@@ -14,7 +14,7 @@ export function addEmpty(ast: AstTypes.Program, importFrom: string) {
1414
addImportIfNecessary(ast, expectedImportDeclaration);
1515
}
1616

17-
export function addDefault(ast: AstTypes.Program, importFrom: string, importAs: string) {
17+
export function addDefault(ast: AstTypes.Program, importFrom: string, importAs: string): void {
1818
const expectedImportDeclaration: AstTypes.ImportDeclaration = {
1919
type: 'ImportDeclaration',
2020
source: {
@@ -40,7 +40,7 @@ export function addNamed(
4040
importFrom: string,
4141
exportedAsImportAs: Record<string, string>,
4242
isType = false
43-
) {
43+
): void {
4444
const specifiers = Object.entries(exportedAsImportAs).map(([key, value]) => {
4545
const specifier: AstTypes.ImportSpecifier = {
4646
type: 'ImportSpecifier',

packages/ast-manipulation/js/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as ArrayUtils from './array.js';
2-
import * as ObjectUtils from './object.js';
3-
import * as CommonUtils from './common.js';
4-
import * as FunctionUtils from './function.js';
5-
import * as ImportUtils from './imports.js';
6-
import * as VariableUtils from './variables.js';
7-
import * as ExportUtils from './exports.js';
1+
import * as ArrayUtils from './array';
2+
import * as ObjectUtils from './object';
3+
import * as CommonUtils from './common';
4+
import * as FunctionUtils from './function';
5+
import * as ImportUtils from './imports';
6+
import * as VariableUtils from './variables';
7+
import * as ExportUtils from './exports';
88
import type { AstTypes } from '@svelte-cli/ast-tooling';
99

1010
export type JsAstEditor = {
@@ -18,7 +18,7 @@ export type JsAstEditor = {
1818
exports: typeof ExportUtils;
1919
};
2020

21-
export function getJsAstEditor(ast: AstTypes.Program) {
21+
export function getJsAstEditor(ast: AstTypes.Program): JsAstEditor {
2222
const astEditor: JsAstEditor = {
2323
ast,
2424
object: ObjectUtils,

0 commit comments

Comments
 (0)