From 902b2c538345d3290aa683d715f204e92bd9766a Mon Sep 17 00:00:00 2001 From: Manuel Serret Date: Fri, 27 Sep 2024 16:57:24 +0200 Subject: [PATCH 1/7] feat: add support for `create` api --- packages/cli/bin.ts | 11 +++++++++++ packages/cli/index.ts | 12 ++---------- packages/cli/package.json | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 packages/cli/bin.ts diff --git a/packages/cli/bin.ts b/packages/cli/bin.ts new file mode 100644 index 000000000..115adc849 --- /dev/null +++ b/packages/cli/bin.ts @@ -0,0 +1,11 @@ +#!/usr/bin/env node + +import pkg from './package.json'; +import { program } from 'commander'; +import { add } from './commands/add.js'; +import { create } from './commands/create.js'; +import { helpConfig } from './common.js'; + +program.name(pkg.name).version(pkg.version, '-v').configureHelp(helpConfig); +program.addCommand(create).addCommand(add); +program.parse(); diff --git a/packages/cli/index.ts b/packages/cli/index.ts index 115adc849..b5c7b91ec 100644 --- a/packages/cli/index.ts +++ b/packages/cli/index.ts @@ -1,11 +1,3 @@ -#!/usr/bin/env node +import { create } from '@svelte-cli/create'; -import pkg from './package.json'; -import { program } from 'commander'; -import { add } from './commands/add.js'; -import { create } from './commands/create.js'; -import { helpConfig } from './common.js'; - -program.name(pkg.name).version(pkg.version, '-v').configureHelp(helpConfig); -program.addCommand(create).addCommand(add); -program.parse(); +export { create }; diff --git a/packages/cli/package.json b/packages/cli/package.json index 897e879fd..a7f2727fc 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -19,7 +19,7 @@ }, "license": "MIT", "homepage": "https://kit.svelte.dev", - "bin": "./dist/index.js", + "bin": "./dist/bin.js", "main": "./dist/index.js", "dependencies": { "@svelte-cli/core": "workspace:*" From 138c917eb94d41b595df069823a7ae4384bd03a0 Mon Sep 17 00:00:00 2001 From: Manuel Serret Date: Fri, 27 Sep 2024 17:17:50 +0200 Subject: [PATCH 2/7] add rollup config --- rollup.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/rollup.config.js b/rollup.config.js index f98eface9..f6f8fe9c6 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -23,6 +23,7 @@ function getConfig(project) { const outDir = `./packages/${project}/dist`; if (project === 'core') inputs.push(`./packages/${project}/internal.ts`); + if (project === 'cli') inputs.push(`./packages/${project}/bin.ts`); const projectRoot = path.resolve(path.join(outDir, '..')); fs.rmSync(outDir, { force: true, recursive: true }); From aeab315bceeb5685e978d38b4ff25400c98b9dfc Mon Sep 17 00:00:00 2001 From: AdrianGonz97 <31664583+AdrianGonz97@users.noreply.github.com> Date: Sun, 29 Sep 2024 12:17:40 -0400 Subject: [PATCH 3/7] fix library export --- packages/cli/package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index a7f2727fc..0a03ec4fe 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -20,7 +20,12 @@ "license": "MIT", "homepage": "https://kit.svelte.dev", "bin": "./dist/bin.js", - "main": "./dist/index.js", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, "dependencies": { "@svelte-cli/core": "workspace:*" }, From e5c1de9ffe907a9be8d75f7f60e8c83869af0623 Mon Sep 17 00:00:00 2001 From: AdrianGonz97 <31664583+AdrianGonz97@users.noreply.github.com> Date: Sun, 29 Sep 2024 12:17:46 -0400 Subject: [PATCH 4/7] tweak --- packages/cli/common.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cli/common.ts b/packages/cli/common.ts index cebf21672..e7b340bdb 100644 --- a/packages/cli/common.ts +++ b/packages/cli/common.ts @@ -4,7 +4,7 @@ import { exec } from 'tinyexec'; import * as p from '@svelte-cli/clack-prompts'; import { detect, AGENTS, type AgentName } from 'package-manager-detector'; import { COMMANDS, constructCommand } from 'package-manager-detector/commands'; -import type { AdderWithoutExplicitArgs } from '@svelte-cli/core'; +import type { AdderWithoutExplicitArgs, Precondition } from '@svelte-cli/core'; import type { Argument, HelpConfiguration, Option } from 'commander'; export const helpConfig: HelpConfiguration = { @@ -114,11 +114,12 @@ async function installDependencies(command: string, args: string[], cwd: string) } } +type PreconditionCheck = { name: string; preconditions: Precondition[] }; export function getGlobalPreconditions( cwd: string, projectType: 'svelte' | 'kit', adders: AdderWithoutExplicitArgs[] -) { +): PreconditionCheck { return { name: 'global checks', preconditions: [ From f7df5cc6ddf49d3652bcbca15d2a044993f87bb5 Mon Sep 17 00:00:00 2001 From: AdrianGonz97 <31664583+AdrianGonz97@users.noreply.github.com> Date: Sun, 29 Sep 2024 12:19:12 -0400 Subject: [PATCH 5/7] generate dts for library api --- packages/cli/tsconfig.json | 10 ++++++++++ rollup.config.js | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 packages/cli/tsconfig.json diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json new file mode 100644 index 000000000..6f8003492 --- /dev/null +++ b/packages/cli/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "checkJs": false, + "isolatedDeclarations": true, + "declaration": true + }, + // we'll only want to enforce `isolatedDeclarations` on the library portion of the CLI + "include": ["index.ts"] +} diff --git a/rollup.config.js b/rollup.config.js index d189e29f2..c0f847a2c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -35,7 +35,7 @@ function getConfig(project) { js: `${projectRoot}/tooling/js/index.ts` }; } else if (project === 'cli') { - inputs = [`${projectRoot}/bin.ts`]; + inputs = [`${projectRoot}/index.ts`, `${projectRoot}/bin.ts`]; } else { inputs = [`${projectRoot}/index.ts`]; } @@ -107,7 +107,7 @@ function getConfig(project) { external, plugins: [ preserveShebangs(), - 'exports' in pkg && dts(), + 'exports' in pkg && dts({ include: project === 'cli' ? [inputs[0]] : undefined }), esbuild(), nodeResolve({ preferBuiltins: true, rootDir: projectRoot }), commonjs(), From 80b4f5c7dd97b5ae65fc144d5793cd135425acbc Mon Sep 17 00:00:00 2001 From: AdrianGonz97 <31664583+AdrianGonz97@users.noreply.github.com> Date: Sun, 29 Sep 2024 16:51:00 -0400 Subject: [PATCH 6/7] pls fix? --- eslint.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eslint.config.js b/eslint.config.js index 6a350144c..7268c861a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -12,7 +12,8 @@ export default [ { languageOptions: { parserOptions: { - project: true + project: true, + tsconfigRootDir: import.meta.dirname } }, rules: { From 4ea2b87da3652f30892e2b8e81316c5e1b5a4688 Mon Sep 17 00:00:00 2001 From: AdrianGonz97 <31664583+AdrianGonz97@users.noreply.github.com> Date: Sun, 29 Sep 2024 17:19:10 -0400 Subject: [PATCH 7/7] gotcha you little bugger --- eslint.config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 7268c861a..c6f1bbf07 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -12,8 +12,8 @@ export default [ { languageOptions: { parserOptions: { - project: true, - tsconfigRootDir: import.meta.dirname + // use the nearest tsconfig from the source or fallback to the root + project: ['packages/**/tsconfig.json', 'tsconfig.json'] } }, rules: { @@ -27,7 +27,7 @@ export default [ 'packages/create/shared/**/*', 'packages/create/scripts/**/*', 'packages/create/templates/**/*', - 'temp/**/*', + '**/temp/*', '.test-tmp/**/*', '**/dist/*', 'packages/**/tests/**/{output,input}.ts',