Skip to content

Commit

Permalink
fix: Use verbatim types. (#254)
Browse files Browse the repository at this point in the history
* First pass.

* Second pass.

* Third pass.

* Fix tests.
  • Loading branch information
milesj authored May 22, 2024
1 parent a443f15 commit 6dd029e
Show file tree
Hide file tree
Showing 54 changed files with 95 additions and 116 deletions.
4 changes: 0 additions & 4 deletions .moon/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@ tasks:
command: 'vitest run --config ../../vitest.config.ts'
deps:
- '^:build'

typecheck:
deps:
- '^:build'
2 changes: 1 addition & 1 deletion packages/babel-plugin-cjs-esm-interop/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable complexity */

import paths from 'node:path';
import { NodePath, PluginObj, PluginPass, types as t } from '@babel/core';
import { NodePath, type PluginObj, type PluginPass, types as t } from '@babel/core';
// @ts-expect-error Not typed
import { addDefault } from '@babel/helper-module-imports';

Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-cjs-esm-interop/tests/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import { transformAsync, TransformOptions } from '@babel/core';
import cjsEsmInterop, { CjsEsmInteropOptions } from '../src';
import { transformAsync, type TransformOptions } from '@babel/core';
import cjsEsmInterop, { type CjsEsmInteropOptions } from '../src';

async function transform(
code: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-conditional-invariant/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePath, PluginObj, types as t } from '@babel/core';
import { NodePath, type PluginObj, types as t } from '@babel/core';

function isWrappedWithConditional(path: NodePath<t.ExpressionStatement>): boolean {
let currentPath: NodePath<t.Node> | null = path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { transformAsync, TransformOptions } from '@babel/core';
import { transformAsync, type TransformOptions } from '@babel/core';
import conditionalInvariantPlugin from '../src';

async function transform(code: string, options?: TransformOptions): Promise<string> {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-env-constants/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './types';
import { NodePath, PluginObj, types as t } from '@babel/core';
import { NodePath, type PluginObj, types as t } from '@babel/core';

const exprs = {
DEV: ['!==', 'production'],
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-env-constants/tests/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { transformAsync, TransformOptions } from '@babel/core';
import { transformAsync, type TransformOptions } from '@babel/core';
import envConstantsPlugin from '../src';

async function transform(code: string, options?: TransformOptions): Promise<string> {
Expand Down
3 changes: 2 additions & 1 deletion packages/packemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
"spdx-license-list": "^6.9.0"
},
"devDependencies": {
"@typescript-eslint/types": "^6.21.0"
"@typescript-eslint/types": "^6.21.0",
"typescript": "*"
},
"peerDependencies": {
"chokidar": "^3.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/Artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { execa } from 'execa';
import { rollup } from 'rollup';
import { applyStyle } from '@boost/cli';
import { Path, toArray, VirtualPath } from '@boost/common';
import { createDebugger, Debugger } from '@boost/debug';
import { createDebugger, type Debugger } from '@boost/debug';
import { convertCjsTypes } from './helpers/compat/convertCjsTypes';
import { removeSourcePath } from './helpers/removeSourcePath';
import type { Package } from './Package';
Expand Down
4 changes: 2 additions & 2 deletions packages/packemon/src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Blueprint, Schemas } from '@boost/common';
import type { Blueprint, Schemas } from '@boost/common';
import { Configuration } from '@boost/config';
import { BuildParams, ConfigFile, ConfigMutator, ConfigMutatorWithBuild } from './types';
import type { BuildParams, ConfigFile, ConfigMutator, ConfigMutatorWithBuild } from './types';

export class Config extends Configuration<ConfigFile> {
blueprint({ bool, func }: Schemas): Blueprint<ConfigFile> {
Expand Down
8 changes: 4 additions & 4 deletions packages/packemon/src/Package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import glob from 'fast-glob';
import semver from 'semver';
import { isObject, Memoize, PackageStructure, Path, toArray } from '@boost/common';
import { isObject, Memoize, type PackageStructure, Path, toArray } from '@boost/common';
import { optimal } from '@boost/common/optimal';
import { createDebugger, Debugger } from '@boost/debug';
import { createDebugger, type Debugger } from '@boost/debug';
import { Artifact } from './Artifact';
import {
DEFAULT_FORMATS,
Expand All @@ -18,14 +18,14 @@ import {
NODE_SUPPORTED_VERSIONS,
SUPPORT_PRIORITY,
} from './constants';
import { FileSystem, nodeFileSystem } from './FileSystem';
import { type FileSystem, nodeFileSystem } from './FileSystem';
import { injectDefaultCondition } from './helpers/injectDefaultCondition';
import { loadTsconfigJson } from './helpers/loadTsconfigJson';
import { matchesPattern } from './helpers/matchesPattern';
import { mergeExports } from './helpers/mergeExports';
import { sortExports } from './helpers/sortExports';
import { packemonBlueprint } from './schemas';
import {
import type {
ApiType,
BuildOptions,
ConfigFile,
Expand Down
6 changes: 3 additions & 3 deletions packages/packemon/src/PackageValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { execa } from 'execa';
import semver from 'semver';
import spdxLicenses from 'spdx-license-list';
import {
DependencyMap,
type DependencyMap,
isModuleName,
isObject,
PeopleSetting,
type PeopleSetting,
Project,
toArray,
} from '@boost/common';
import { Package } from './Package';
import { ValidateOptions } from './types';
import type { ValidateOptions } from './types';

export class PackageValidator {
static entryPoints: string[] = ['main', 'module', 'browser', 'types', 'typings', 'bin', 'man'];
Expand Down
6 changes: 3 additions & 3 deletions packages/packemon/src/Packemon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Path, PortablePath, Project } from '@boost/common';
import { Path, type PortablePath, Project } from '@boost/common';
import { optimal } from '@boost/common/optimal';
import { createDebugger, Debugger } from '@boost/debug';
import { createDebugger, type Debugger } from '@boost/debug';
import { Config } from './Config';
import { FileSystem, nodeFileSystem } from './FileSystem';
import { type FileSystem, nodeFileSystem } from './FileSystem';
import { matchesPattern } from './helpers/matchesPattern';
import { Package } from './Package';
import { PackageValidator } from './PackageValidator';
Expand Down
12 changes: 6 additions & 6 deletions packages/packemon/src/babel.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { TransformOptions as ConfigStructure } from '@babel/core';
import type { TransformOptions as ConfigStructure } from '@babel/core';
import { Path, toArray } from '@boost/common';
import { FeatureFlags } from './types';
import type { FeatureFlags } from './types';
import {
Artifact,
DEFAULT_SUPPORT,
Format,
type Format,
getBabelInputConfig,
getBabelOutputConfig,
Package,
Packemon,
PackemonPackage,
Platform,
Support,
type PackemonPackage,
type Platform,
type Support,
} from '.';

const format = (process.env.PACKEMON_FORMAT ?? 'lib') as Format;
Expand Down
4 changes: 2 additions & 2 deletions packages/packemon/src/babel/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PluginItem, TransformOptions as ConfigStructure } from '@babel/core';
import type { PluginItem, TransformOptions as ConfigStructure } from '@babel/core';
import { Artifact } from '../Artifact';
import {
BROWSER_TARGETS,
Expand All @@ -7,7 +7,7 @@ import {
NODE_SUPPORTED_VERSIONS,
} from '../constants';
import { shouldKeepDynamicImport } from '../helpers/shouldKeepDynamicImport';
import {
import type {
ConfigFile,
FeatureFlags,
Format,
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/commands/Base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applyStyle, Arg, Command, GlobalOptions, PrimitiveType } from '@boost/cli';
import { applyStyle, Arg, Command, type GlobalOptions, type PrimitiveType } from '@boost/cli';
import { figures } from '@boost/terminal';
import { PackageValidator } from '../PackageValidator';
import { Packemon } from '../Packemon';
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/commands/Build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { formatMs } from '@boost/common';
import { figures } from '@boost/terminal';
import { STATE_COLORS } from '../constants';
import { Package } from '../Package';
import { BuildOptions } from '../types';
import type { BuildOptions } from '../types';
import { BaseCommand } from './Base';

@Config('build', 'Build a standardized package for distribution')
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/commands/Init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Arg, Config } from '@boost/cli';
import { DEFAULT_INPUT, DEFAULT_SUPPORT } from '../constants';
import { Package } from '../Package';
import { PackemonPackageConfig } from '../types';
import type { PackemonPackageConfig } from '../types';
import { BaseCommand } from './Base';

export interface InitOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/commands/Scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import glob from 'fast-glob';
import { Arg, Command, Config } from '@boost/cli';
import { json } from '@boost/common';
import { nodeFileSystem } from '../FileSystem';
import { InfraType, ScaffoldParams, TemplateType } from '../types';
import type { InfraType, ScaffoldParams, TemplateType } from '../types';

@Config('scaffold', 'Scaffold projects and packages with ease')
export class ScaffoldCommand extends Command {
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/commands/Validate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Arg, Config } from '@boost/cli';
import { ValidateOptions } from '../types';
import type { ValidateOptions } from '../types';
import { BaseCommand } from './Base';

@Config('validate', 'Validate package metadata and configuration')
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/components/Files/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useMemo } from 'react';
import { Box, Text } from 'ink';
import { StyleType } from '@boost/cli';
import type { StyleType } from '@boost/cli';
import { Style } from '@boost/cli/react';
import { Symbol } from './Symbol';
import { TreeContext, useTree } from './TreeContext';
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/components/Files/TreeContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useContext } from 'react';
import { StyleType } from '@boost/cli';
import type { StyleType } from '@boost/cli';

interface TreeContextType {
folderStyle?: StyleType;
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/components/Files/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Box, Static } from 'ink';
import { Header } from '@boost/cli/react';
import { List } from './List';
import { FileTree, Tree } from './Tree';
import { type FileTree, Tree } from './Tree';

export type FileFormat = 'list' | 'tree';

Expand Down
4 changes: 2 additions & 2 deletions packages/packemon/src/components/Init/PackageForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { applyStyle } from '@boost/cli';
import { Input, MultiSelect, Select, SelectOptionLike } from '@boost/cli/react';
import { Input, MultiSelect, Select, type SelectOptionLike } from '@boost/cli/react';
import { toArray } from '@boost/common';
import {
BROWSER_TARGETS,
Expand All @@ -11,7 +11,7 @@ import {
NATIVE_TARGETS,
NODE_SUPPORTED_VERSIONS,
} from '../../constants';
import { Format, PackemonPackageConfig, Platform, Support } from '../../types';
import type { Format, PackemonPackageConfig, Platform, Support } from '../../types';

export interface PackageFormProps {
onSubmit: (config: PackemonPackageConfig) => void;
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/components/Init/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useCallback } from 'react';
import { Box, Text } from 'ink';
import { Header, Style, useProgram } from '@boost/cli/react';
import { PackemonPackageConfig } from '../../types';
import type { PackemonPackageConfig } from '../../types';
import { PackageForm } from './PackageForm';

export type InitPackageConfigs = Record<string, PackemonPackageConfig>;
Expand Down
4 changes: 2 additions & 2 deletions packages/packemon/src/components/Scaffold/TemplateSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useMemo } from 'react';
import { Select, SelectOptionLike } from '@boost/cli/react';
import { TemplateType } from '../../types';
import { Select, type SelectOptionLike } from '@boost/cli/react';
import type { TemplateType } from '../../types';

export interface TemplateSelectProps {
defaultTemplate?: TemplateType;
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/components/Scaffold/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCallback, useEffect, useState } from 'react';
import { Box, Text } from 'ink';
import { Input, useProgram } from '@boost/cli/react';
import { isModuleName } from '@boost/common';
import { ScaffoldParams, TemplateType } from '../../types';
import type { ScaffoldParams, TemplateType } from '../../types';
import { TemplateSelect } from './TemplateSelect';

export interface ScaffoldProps {
Expand Down
4 changes: 2 additions & 2 deletions packages/packemon/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StyleType } from '@boost/cli';
import {
import type { StyleType } from '@boost/cli';
import type {
ArtifactState,
BrowserFormat,
Format,
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/helpers/compat/convertCjsTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import glob from 'fast-glob';
import { Path } from '@boost/common';
import { FileSystem } from '../../FileSystem';
import type { FileSystem } from '../../FileSystem';

export async function convertCjsTypes(cjsDir: Path, fs: FileSystem) {
const dtsFiles = await glob(['**/*.d.ts', '**/*.d.ts.map'], {
Expand Down
4 changes: 2 additions & 2 deletions packages/packemon/src/helpers/getVersion.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { PackageStructure } from '@boost/common';
import { FileSystem } from '../FileSystem';
import type { PackageStructure } from '@boost/common';
import type { FileSystem } from '../FileSystem';

const PKG_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), '../../package.json');

Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/helpers/injectDefaultCondition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-param-reassign */

import { PackageExportConditions, PackageExports } from '../types';
import type { PackageExportConditions, PackageExports } from '../types';

export function injectDefaultCondition(exportMap: PackageExports) {
Object.entries(exportMap).forEach(([path, conditions]) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/packemon/src/helpers/loadTsconfigJson.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Path, PortablePath } from '@boost/common';
import { FileSystem } from '../FileSystem';
import { TSConfigStructure } from '../types';
import { Path, type PortablePath } from '@boost/common';
import type { FileSystem } from '../FileSystem';
import type { TSConfigStructure } from '../types';
import { loadModule } from './loadModule';

const CACHE = new Map<Path, TSConfigStructure>();
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/helpers/mergeExports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-param-reassign */

import { PackageExportConditions, PackageExportPaths } from '../types';
import type { PackageExportConditions, PackageExportPaths } from '../types';

export function mergeExports(
prev: PackageExportPaths | string,
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/helpers/shouldKeepDynamicImport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Format, Platform } from '../types';
import type { Format, Platform } from '../types';

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
export function shouldKeepDynamicImport(platform: Platform, format: Format): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/helpers/sortExportConditions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PackageExportPaths } from '../types';
import type { PackageExportPaths } from '../types';

// https://nodejs.org/api/packages.html#conditional-exports
const WEIGHTS = {
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/helpers/sortExports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PackageExports } from '../types';
import type { PackageExports } from '../types';
import { sortExportConditions } from './sortExportConditions';

const WEIGHTS: Record<string, number> = {
Expand Down
4 changes: 2 additions & 2 deletions packages/packemon/src/rollup/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ModuleFormat, OutputOptions, Plugin, RollupOptions } from 'rollup';
import type { ModuleFormat, OutputOptions, Plugin, RollupOptions } from 'rollup';
import { nodeExternals } from 'rollup-plugin-node-externals';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import { getBabelInputPlugin, getBabelOutputPlugin } from '@rollup/plugin-babel';
Expand All @@ -9,7 +9,7 @@ import type { Artifact } from '../Artifact';
import { getBabelInputConfig, getBabelOutputConfig } from '../babel/config';
import { EXCLUDE, EXCLUDE_RUST, EXTENSIONS } from '../constants';
import { getSwcInputConfig, getSwcOutputConfig } from '../swc/config';
import { ConfigFile, FeatureFlags, Format } from '../types';
import type { ConfigFile, FeatureFlags, Format } from '../types';
import { addBinShebang } from './plugins/addBinShebang';
import { addMjsWrapperForCjs } from './plugins/addMjsWrapperForCjs';
import { copyAndRefAssets } from './plugins/copyAndRefAssets';
Expand Down
2 changes: 1 addition & 1 deletion packages/packemon/src/rollup/plugins/addBinShebang.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */

import { OutputPlugin } from 'rollup';
import type { OutputPlugin } from 'rollup';

export function addBinShebang(): OutputPlugin {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/packemon/src/rollup/plugins/addMjsWrapperForCjs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'node:path';
import { GetModuleInfo, Plugin } from 'rollup';
import type { GetModuleInfo, Plugin } from 'rollup';
import { Path } from '@boost/common';
import type { TSESTree } from '@typescript-eslint/types';
import { InputMap } from '../../types';
import type { InputMap } from '../../types';

export interface AddMjsWrapperOptions {
inputs: InputMap;
Expand Down
Loading

0 comments on commit 6dd029e

Please sign in to comment.