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

Get strict about type only imports #1584

Merged
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
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
project: './tsconfig.json',
},
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
Expand Down Expand Up @@ -57,5 +58,11 @@ module.exports = {
'import/no-extraneous-dependencies': 'off',
},
},
{
files: ['tests/**/*'],
rules: {
'node/no-missing-require': 'off',
},
},
],
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"compile": "tsc",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint:eslint": "eslint . --cache",
"lint:eslint:fix": "eslint . --fix",
"lint:eslint": "eslint . --cache --report-unused-disable-directives",
"lint:eslint:fix": "eslint . --fix --report-unused-disable-directives",
"lint:prettier": "prettier . -c",
"lint:prettier:fix": "prettier . -w",
"lint:router-types": "cd packages/router && pnpm lint:types",
Expand Down
3 changes: 2 additions & 1 deletion packages/addon-dev/src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { default as hbs } from './rollup-hbs-plugin';
import { default as gjs } from './rollup-gjs-plugin';
import { default as publicEntrypoints } from './rollup-public-entrypoints';
import { default as appReexports } from './rollup-app-reexports';
import { default as clean, Options as DelOptions } from 'rollup-plugin-delete';
import type { Options as DelOptions } from 'rollup-plugin-delete';
import { default as clean } from 'rollup-plugin-delete';
import { default as keepAssets } from './rollup-keep-assets';
import { default as dependencies } from './rollup-addon-dependencies';
import { default as publicAssets } from './rollup-public-assets';
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/add-to-tree.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Node } from 'broccoli-node-api';
import type { Node } from 'broccoli-node-api';
import { Funnel } from 'broccoli-funnel';

export default class AddToTree extends Funnel {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PackageRules } from '..';
import type { PackageRules } from '..';

let rulesForV1: PackageRules = {
package: 'ember-basic-dropdown',
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/addon-dependency-rules/ember-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PackageRules } from '..';
import type { PackageRules } from '..';

let rules: PackageRules[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PackageRules } from '..';
import type { PackageRules } from '..';

let rules: PackageRules = {
package: 'ember-element-helper',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PackageRules } from '..';
import type { PackageRules } from '..';

const rules: PackageRules[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PackageRules } from '..';
import type { PackageRules } from '..';

let rules: PackageRules = {
package: 'ember-power-select-typeahead',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PackageRules } from '..';
import type { PackageRules } from '..';

const rules: PackageRules[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PackageRules } from '..';
import type { PackageRules } from '..';

let rules: PackageRules = {
package: 'ember-power-select',
Expand Down
3 changes: 2 additions & 1 deletion packages/compat/src/audit-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import { readFileSync, readJSONSync, writeFileSync } from 'fs-extra';
import { resolve } from 'path';
import yargs from 'yargs/yargs';
import { Audit, AuditResults, Finding, isBuildError } from './audit';
import type { Finding } from './audit';
import { Audit, AuditResults, isBuildError } from './audit';

// slightly wacky because yargs types don't cover this, but you can't access the
// other documented place to find `hideBin` on node < 12.17
Expand Down
21 changes: 4 additions & 17 deletions packages/compat/src/audit.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import { readFileSync, readJSONSync } from 'fs-extra';
import { dirname, join, resolve as resolvePath } from 'path';
import {
AppMeta,
explicitRelative,
hbsToJS,
locateEmbroiderWorkingDir,
Resolver,
ResolverOptions,
RewrittenPackageCache,
} from '@embroider/core';
import type { AppMeta, ResolverOptions } from '@embroider/core';
import { explicitRelative, hbsToJS, locateEmbroiderWorkingDir, Resolver, RewrittenPackageCache } from '@embroider/core';
import { Memoize } from 'typescript-memoize';
import chalk from 'chalk';
import jsdom from 'jsdom';
import groupBy from 'lodash/groupBy';
import fromPairs from 'lodash/fromPairs';
import {
auditJS,
CodeFrameStorage,
ExportAll,
InternalImport,
isNamespaceMarker,
NamespaceMarker,
} from './audit/babel-visitor';
import type { ExportAll, InternalImport, NamespaceMarker } from './audit/babel-visitor';
import { auditJS, CodeFrameStorage, isNamespaceMarker } from './audit/babel-visitor';
import { AuditBuildOptions, AuditOptions } from './audit/options';
import { buildApp, BuildError, isBuildError } from './audit/build';

Expand Down
9 changes: 6 additions & 3 deletions packages/compat/src/audit/babel-visitor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import traverse, { NodePath, Node } from '@babel/traverse';
import { TransformOptions, transformSync, types as t } from '@babel/core';
import { codeFrameColumns, SourceLocation } from '@babel/code-frame';
import type { NodePath, Node } from '@babel/traverse';
import traverse from '@babel/traverse';
import type { TransformOptions } from '@babel/core';
import { transformSync, types as t } from '@babel/core';
import type { SourceLocation } from '@babel/code-frame';
import { codeFrameColumns } from '@babel/code-frame';

export class VisitorState {}

Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/audit/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk';
import { AuditBuildOptions } from '../audit';
import type { AuditBuildOptions } from '../audit';
import { spawn } from 'child_process';

export async function buildApp(options: AuditBuildOptions): Promise<void> {
Expand Down
8 changes: 5 additions & 3 deletions packages/compat/src/babel-plugin-adjust-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import type * as Babel from '@babel/core';
import type { types as t } from '@babel/core';
import { ImportUtil } from 'babel-import-util';
import { readJSONSync } from 'fs-extra';
import { CompatResolverOptions } from './resolver-transform';
import { locateEmbroiderWorkingDir, Package, packageName, Resolver, unrelativize } from '@embroider/core';
import type { CompatResolverOptions } from './resolver-transform';
import type { Package } from '@embroider/core';
import { locateEmbroiderWorkingDir, packageName, Resolver, unrelativize } from '@embroider/core';
import { snippetToDasherizedName } from './dasherize-component-name';
import { ActivePackageRules, appTreeRulesDir, ComponentRules, ModuleRules, TemplateRules } from './dependency-rules';
import type { ActivePackageRules, ComponentRules, ModuleRules, TemplateRules } from './dependency-rules';
import { appTreeRulesDir } from './dependency-rules';

export type Options = { appRoot: string };

Expand Down
6 changes: 3 additions & 3 deletions packages/compat/src/build-compat-addon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import V1InstanceCache from './v1-instance-cache';
import { Package } from '@embroider/core';
import type V1InstanceCache from './v1-instance-cache';
import type { Package } from '@embroider/core';
import SmooshPackageJSON from './smoosh-package-json';
import broccoliMergeTrees from 'broccoli-merge-trees';
import { Node } from 'broccoli-node-api';
import type { Node } from 'broccoli-node-api';
import EmptyPackageTree from './empty-package-tree';

export default function buildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): Node {
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/compat-adapters/@ember-data/debug.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddonMeta } from '@embroider/core';
import type { AddonMeta } from '@embroider/core';
import V1Addon from '../../v1-addon';
import semver from 'semver';

Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/compat-adapters/@ember-data/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddonMeta } from '@embroider/core';
import type { AddonMeta } from '@embroider/core';
import { EmberDataBase } from '../ember-data';

export default class EmberDataStore extends EmberDataBase {
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/compat-adapters/ember-cli-fastboot.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import V1Addon from '../v1-addon';
import Plugin from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import type { Node } from 'broccoli-node-api';
import { readJSONSync, outputJSONSync } from 'fs-extra';
import { join } from 'path';
import writeFile from 'broccoli-file-creator';
import { Memoize } from 'typescript-memoize';
import bind from 'bind-decorator';
import { AddonMeta } from '@embroider/core';
import type { AddonMeta } from '@embroider/core';

export default class EmberCliFastboot extends V1Addon {
customizes(...trees: string[]): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/compat-adapters/ember-cli-mirage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import V1Addon from '../v1-addon';
import buildFunnel from 'broccoli-funnel';
import { AddonMeta } from '@embroider/core';
import type { AddonMeta } from '@embroider/core';

export default class extends V1Addon {
get packageMeta(): Partial<AddonMeta> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import V1Addon from '../v1-addon';
import { join } from 'path';
import { Node } from 'broccoli-node-api';
import type { Node } from 'broccoli-node-api';
import { readdirSync, writeFileSync, readFileSync } from 'fs';
import { pathExistsSync, removeSync } from 'fs-extra';
import { Funnel } from 'broccoli-funnel';
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/compat-adapters/ember-data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import V1Addon from '../v1-addon';
import { join } from 'path';
import { Memoize } from 'typescript-memoize';
import { Node } from 'broccoli-node-api';
import type { Node } from 'broccoli-node-api';
import { sync as resolveSync } from 'resolve';
import semver from 'semver';

Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/compat-adapters/ember-engines.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import V1Addon from '../v1-addon';
import Filter from 'broccoli-persistent-filter';
import { AddonMeta } from '@embroider/core';
import type { AddonMeta } from '@embroider/core';

class Awk extends Filter {
search: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/compat-adapters/ember-inflector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import V1Addon from '../v1-addon';
import AddToTree from '../add-to-tree';
import { Node } from 'broccoli-node-api';
import type { Node } from 'broccoli-node-api';
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import { removeSync } from 'fs-extra';
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/compat-adapters/ember-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { transform } from '@babel/core';
import type * as Babel from '@babel/core';
import type { NodePath } from '@babel/traverse';
import Plugin from 'broccoli-plugin';
import { Node } from 'broccoli-node-api';
import type { Node } from 'broccoli-node-api';

export default class extends V1Addon {
get v2Tree() {
Expand Down
7 changes: 4 additions & 3 deletions packages/compat/src/compat-addons.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Node } from 'broccoli-node-api';
import type { Node } from 'broccoli-node-api';
import { resolve } from 'path';
import { locateEmbroiderWorkingDir, RewrittenPackageCache, Stage, WaitForTrees } from '@embroider/core';
import type { Stage } from '@embroider/core';
import { locateEmbroiderWorkingDir, RewrittenPackageCache, WaitForTrees } from '@embroider/core';
import TreeSync from 'tree-sync';
import CompatApp from './compat-app';
import type CompatApp from './compat-app';
import { convertLegacyAddons } from './standalone-addon-build';

// This build stage expects to be run with broccoli memoization enabled in order
Expand Down
31 changes: 18 additions & 13 deletions packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Node as BroccoliNode } from 'broccoli-node-api';
import {
import type { Node as BroccoliNode } from 'broccoli-node-api';
import type {
OutputPaths,
Asset,
EmberAsset,
AddonPackage,
Engine,
AppMeta,
TemplateColocationPluginOptions,
} from '@embroider/core';
import {
explicitRelative,
extensionsPattern,
TemplateColocationPluginOptions,
debug,
warn,
jsHandlebarsCompile,
Expand All @@ -20,10 +22,11 @@ import {
} from '@embroider/core';
import walkSync from 'walk-sync';
import { resolve as resolvePath, posix } from 'path';
import { JSDOM } from 'jsdom';
import Options from './options';
import { CompatResolverOptions } from './resolver-transform';
import { activePackageRules, PackageRules } from './dependency-rules';
import type { JSDOM } from 'jsdom';
import type Options from './options';
import type { CompatResolverOptions } from './resolver-transform';
import type { PackageRules } from './dependency-rules';
import { activePackageRules } from './dependency-rules';
import flatMap from 'lodash/flatMap';
import sortBy from 'lodash/sortBy';
import flatten from 'lodash/flatten';
Expand All @@ -37,18 +40,20 @@ import type { Options as EtcOptions } from 'babel-plugin-ember-template-compilat
import type { Options as ResolverTransformOptions } from './resolver-transform';
import type { Options as AdjustImportsOptions } from './babel-plugin-adjust-imports';
import { PreparedEmberHTML } from '@embroider/core/src/ember-html';
import { InMemoryAsset, OnDiskAsset, ImplicitAssetPaths } from '@embroider/core/src/asset';
import type { InMemoryAsset, OnDiskAsset, ImplicitAssetPaths } from '@embroider/core/src/asset';
import { makePortable } from '@embroider/core/src/portable-babel-config';
import { AppFiles, RouteFiles } from '@embroider/core/src/app-files';
import { PortableHint, maybeNodeModuleVersion } from '@embroider/core/src/portable';
import type { RouteFiles } from '@embroider/core/src/app-files';
import { AppFiles } from '@embroider/core/src/app-files';
import type { PortableHint } from '@embroider/core/src/portable';
import { maybeNodeModuleVersion } from '@embroider/core/src/portable';
import assertNever from 'assert-never';
import { Memoize } from 'typescript-memoize';
import { join, dirname } from 'path';
import resolve from 'resolve';
import { V1Config } from './v1-config';
import { AddonMeta, Package, PackageInfo } from '@embroider/core';
import type { V1Config } from './v1-config';
import type { AddonMeta, Package, PackageInfo } from '@embroider/core';
import { ensureDirSync, copySync, readdirSync, pathExistsSync } from 'fs-extra';
import { TransformOptions } from '@babel/core';
import type { TransformOptions } from '@babel/core';
import { MacrosConfig } from '@embroider/macros/src/node';
import SourceMapConcat from 'fast-sourcemap-concat';
import escapeRegExp from 'escape-string-regexp';
Expand Down
25 changes: 13 additions & 12 deletions packages/compat/src/compat-app.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { Node as BroccoliNode } from 'broccoli-node-api';
import {
PackageCache,
WaitForTrees,
Stage,
RewrittenPackageCache,
Package,
locateEmbroiderWorkingDir,
} from '@embroider/core';
import Options, { optionsWithDefaults } from './options';
import type { Node as BroccoliNode } from 'broccoli-node-api';
import type { Stage, Package } from '@embroider/core';
import { PackageCache, WaitForTrees, RewrittenPackageCache, locateEmbroiderWorkingDir } from '@embroider/core';
import type Options from './options';
import { optionsWithDefaults } from './options';
import { Memoize } from 'typescript-memoize';
import { sync as pkgUpSync } from 'pkg-up';
import { join, dirname, isAbsolute, sep } from 'path';
Expand All @@ -17,11 +12,17 @@ import { WatchedDir } from 'broccoli-source';
import resolve from 'resolve';
import { V1Config, WriteV1Config } from './v1-config';
import { WriteV1AppBoot, ReadV1AppBoot } from './v1-appboot';
import { AddonMeta, EmberAppInstance, OutputFileToInputFileMap, PackageInfo, AddonInstance } from '@embroider/core';
import type {
AddonMeta,
EmberAppInstance,
OutputFileToInputFileMap,
PackageInfo,
AddonInstance,
} from '@embroider/core';
import { writeJSONSync, ensureDirSync, copySync, readdirSync, pathExistsSync, existsSync } from 'fs-extra';
import AddToTree from './add-to-tree';
import DummyPackage from './dummy-package';
import { TransformOptions } from '@babel/core';
import type { TransformOptions } from '@babel/core';
import { isEmbroiderMacrosPlugin, MacrosConfig } from '@embroider/macros/src/node';
import resolvePackagePath from 'resolve-package-path';
import Concat from 'broccoli-concat';
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/src/compat-utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import cloneDeep from 'lodash/cloneDeep';
import { AddonMeta, PackageInfo } from '@embroider/core';
import type { AddonMeta, PackageInfo } from '@embroider/core';
import resolve from 'resolve';
import { resolve as pathResolve } from 'path';
import { PluginItem } from '@babel/core';
import type { PluginItem } from '@babel/core';

export function addPeerDependency(packageJSON: PackageInfo, packageName: string, version = '*') {
let pkg = cloneDeep(packageJSON);
Expand Down
8 changes: 5 additions & 3 deletions packages/compat/src/default-pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { App, Addons as CompatAddons, Options } from '.';
import { toBroccoliPlugin, PackagerConstructor, Variant, EmberAppInstance } from '@embroider/core';
import type { Options } from '.';
import { App, Addons as CompatAddons } from '.';
import type { PackagerConstructor, Variant, EmberAppInstance } from '@embroider/core';
import { toBroccoliPlugin } from '@embroider/core';
import { tmpdir } from '@embroider/core';
import { Node } from 'broccoli-node-api';
import type { Node } from 'broccoli-node-api';
import writeFile from 'broccoli-file-creator';
import mergeTrees from 'broccoli-merge-trees';
import { createHash } from 'crypto';
Expand Down
Loading