Skip to content

Commit

Permalink
chore(exports): remove unused exports (#3415)
Browse files Browse the repository at this point in the history
resolve utility unused exports:

this commit resolves issues found in the `src/utils` directory related
to unused exports. 'ts-prune' seems to have issues when a file includes
a direct import and an aliased import to the same location:
```typescript
import { foo } from '../somewhere';
import * as Foo from '../somewhere';
```
doing so causes erroneous unused exports (or so it seems). the import of
`ParsePackageJsonResult` has been removed in favor of a simple
namespaced/aliased import (either would work here, this was an arbitrary
decision that minimizes code churn. we could have just as easily
directly imported everything from 'util').

cases where helper functions were never used have been removed.
otherwise, unnecessary export keywords were removed when a
property/function/etc. was used in the file in which it was defined

---
remove unused export TERMINAL_INFO

---
remove unused transpilerId const

this commit removes an unused constant from the `version.ts` file. in
addition to verifying that the identifier and its string contents are
not used in the codebase, the following was run to look for other
commits containing the string:
```
git log -S transpilerId --source --all
```
although commits were found containing 'transpilerId', no existing
usages of the string were found

---
remove unused host-config

this commit began by removing two unused exports from `host-config.ts`,
`generateHostConfig` and `DEFAULT_MODE`. from those two deletions,
additional functions and constants could be successively deleted, with
each deletion begetting another deletion, and another deletion, etc. by
the end, a single constant was left, `HOST_CONFIG_FILENAME`. that
constant is used in a single file, in a single place. as a result, the
filename was inlined
  • Loading branch information
rwaskiewicz authored Jul 8, 2022
1 parent c0aeac1 commit 23fd1f6
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 295 deletions.
2 changes: 0 additions & 2 deletions src/cli/telemetry/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export const tryFn = async <T extends (...args: any[]) => Promise<R>, R>(fn: T,
return null;
};

export declare const TERMINAL_INFO: d.TerminalInfo;

export const isInteractive = (sys: d.CompilerSystem, flags: ConfigFlags, object?: d.TerminalInfo): boolean => {
const terminalInfo =
object ||
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/config/validate-service-worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type * as d from '../../declarations';
import { HOST_CONFIG_FILENAME } from '../prerender/host-config';
import { isAbsolute, join } from 'path';
import { isString } from '@utils';

Expand Down Expand Up @@ -67,7 +66,7 @@ export const validateServiceWorker = (config: d.ValidatedConfig, outputTarget: d

const addGlobIgnores = (config: d.Config, globIgnores: string[]) => {
globIgnores.push(
`**/${HOST_CONFIG_FILENAME}`,
`**/host.config.json`, // the filename of the host configuration
`**/*.system.entry.js`,
`**/*.system.js`,
`**/${config.fsNamespace}.js`,
Expand Down
282 changes: 0 additions & 282 deletions src/compiler/prerender/host-config.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export const EMPTY_OBJ: any = {};
export const SVG_NS = 'http://www.w3.org/2000/svg';
export const HTML_NS = 'http://www.w3.org/1999/xhtml';
export const XLINK_NS = 'http://www.w3.org/1999/xlink';
export const XML_NS = 'http://www.w3.org/XML/1998/namespace';

/**
* File names and value
Expand Down
3 changes: 1 addition & 2 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ export const pluck = (obj: { [key: string]: any }, keys: string[]) => {
}, {} as { [key: string]: any });
};

const isDefined = (v: any): v is NonNullable<typeof v> => v !== null && v !== undefined;
export const isBoolean = (v: any): v is boolean => typeof v === 'boolean';
export const isDefined = (v: any): v is NonNullable<typeof v> => v !== null && v !== undefined;
export const isUndefined = (v: any): v is null | undefined => v === null || v === undefined;
export const isFunction = (v: any): v is Function => typeof v === 'function';
export const isNumber = (v: any): v is number => typeof v === 'number';
export const isObject = (val: Object): val is Object =>
Expand Down
9 changes: 4 additions & 5 deletions src/utils/test/util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type * as d from '../../declarations';
import { mockConfig, mockBuildCtx } from '@stencil/core/testing';
import * as util from '../util';
import * as util from '@utils';
import { stubDiagnostic } from '../../dev-server/test/Diagnostic.stub';
import { ParsePackageJsonResult } from '../util';

describe('util', () => {
describe('generatePreamble', () => {
Expand Down Expand Up @@ -167,7 +166,7 @@ describe('util', () => {
type: 'build',
});

expect(diagnostic).toEqual<ParsePackageJsonResult>({
expect(diagnostic).toEqual<util.ParsePackageJsonResult>({
diagnostic: expectedDiagnostic,
data: null,
filePath: mockPackageJsonPath,
Expand All @@ -185,7 +184,7 @@ describe('util', () => {
type: 'build',
});

expect(diagnostic).toEqual<ParsePackageJsonResult>({
expect(diagnostic).toEqual<util.ParsePackageJsonResult>({
diagnostic: expectedDiagnostic,
data: null,
filePath: undefined,
Expand All @@ -195,7 +194,7 @@ describe('util', () => {
it('returns the parsed data from the provided json', () => {
const diagnostic = util.parsePackageJson('{ "someJson": "value"}', mockPackageJsonPath);

expect(diagnostic).toEqual<ParsePackageJsonResult>({
expect(diagnostic).toEqual<util.ParsePackageJsonResult>({
diagnostic: null,
data: {
someJson: 'value',
Expand Down
1 change: 0 additions & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const parse5Version = '__VERSION:PARSE5__';
export const rollupVersion = '__VERSION:ROLLUP__';
export const sizzleVersion = '__VERSION:SIZZLE__';
export const terserVersion = '__VERSION:TERSER__';
export const transpilerId = '__BUILDID:TRANSPILE__';
export const typescriptVersion = '__VERSION:TYPESCRIPT__';
export const vermoji = '__VERMOJI__';
export const version = '__VERSION:STENCIL__';
Expand Down

0 comments on commit 23fd1f6

Please sign in to comment.