Skip to content

Commit

Permalink
fix: Export Project as named export to match declaration file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Oct 1, 2018
1 parent 295ea4a commit f529801
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/_script-templates/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Project, { FunctionDeclaration, ClassDeclaration, Node, SourceFile, MethodDeclaration, TypeGuards, Decorator,
import { Project, FunctionDeclaration, ClassDeclaration, Node, SourceFile, MethodDeclaration, TypeGuards, Decorator,
EnumDeclaration, EnumMember, ExportDeclaration, ExportSpecifier, ImportDeclaration, ImportSpecifier,
InterfaceDeclaration, ShorthandPropertyAssignment, SpreadAssignment, ObjectLiteralExpression, ParameterDeclaration,
Type, Symbol, Signature, TypeFormatFlags, NamespaceDeclaration, Directory, Diagnostic, DiagnosticMessageChain,
Expand Down
2 changes: 1 addition & 1 deletion docs/details/exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export interface Interface2 {}
The following code:

```ts
import Project, {TypeGuards} from "ts-simple-ast";
import { Project, TypeGuards } from "ts-simple-ast";

const project = new Project();
project.addExistingSourceFiles("**/*.ts");
Expand Down
2 changes: 1 addition & 1 deletion docs/details/source-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Use the `sourceFile.isSaved()` method that will tell you if the file is saved to
The `sourceFile.delete()` method will queue up deletions to the file system. When done call `project.save()`. For example:

```ts
import Project from "ts-simple-ast";
import { Project } from "ts-simple-ast";

// queue up all the source files to be deleted
const project = new Project();
Expand Down
2 changes: 1 addition & 1 deletion docs/details/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Add or insert variable statements to a source file, namespace, or function like
`insertVariableStatement()`, or `insertVariableStatements()`.

```ts
import Project, {VariableDeclarationKind} from "ts-simple-ast";
import { Project, VariableDeclarationKind } from "ts-simple-ast";

const variableStatement = sourceFile.addVariableStatement({
declarationKind: VariableDeclarationKind.Const, // defaults to "let"
Expand Down
2 changes: 1 addition & 1 deletion docs/manipulation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Most information about manipulation can be found in the [Details](../details) se
All moves, copies, and deletes won't be propagated to the underlying file system until `save()` is called on the main `project` object.

```ts
import Project from "ts-simple-ast";
import { Project } from "ts-simple-ast";

const project = new Project();

Expand Down
2 changes: 1 addition & 1 deletion docs/manipulation/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ It won't be updated when manipulation happens again. Note that after doing this,
It's possible to make sure all created nodes within a block are forgotten:

```ts
import Project, {NamespaceDeclaration, InterfaceDeclaration, ClassDeclaration} from "ts-simple-ast";
import { Project, NamespaceDeclaration, InterfaceDeclaration, ClassDeclaration } from "ts-simple-ast";

const project = new Project();
const text = "namespace Namespace { interface Interface {} class Class {} }";
Expand Down
2 changes: 1 addition & 1 deletion docs/manipulation/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: Manipulation Settings
The manipulation settings can be set when creating the main AST object:

```ts
import Project, {QuoteKind, NewLineKind, IndentationText} from "ts-simple-ast";
import { Project, QuoteKind, NewLineKind, IndentationText } from "ts-simple-ast";

const project = new Project({
// these are the defaults
Expand Down
2 changes: 1 addition & 1 deletion docs/navigation/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default Person;
And setup:

```ts
import Project from "ts-simple-ast";
import { Project } from "ts-simple-ast";

const project = new Project();
project.addExistingSourceFiles("**/*.ts");
Expand Down
2 changes: 1 addition & 1 deletion docs/setup/adding-source-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You will need to populate the `project` object with source files.
Source files will be added when instantiating with a `tsConfigFilePath`:

```ts
import Project from "ts-simple-ast";
import { Project } from "ts-simple-ast";

const project = new Project({
tsConfigFilePath: "path/to/tsconfig.json"
Expand Down
8 changes: 4 additions & 4 deletions docs/setup/file-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ by useful in some scenarios (for example, using a virtual file system is useful
### Current File System Object

```ts
import Project from "ts-simple-ast";
import { Project } from "ts-simple-ast";
const project = new Project();

const fs = project.getFileSystem(); // returns: FileSystemHost
Expand All @@ -24,7 +24,7 @@ here (ex. `writeFile(filePath: string, fileText: string): Promise<void>`, `readF
If you want to use a virtual file system that is stored in memory, specify that when creating an `Ast` object:

```ts
import Project from "ts-simple-ast";
import { Project } from "ts-simple-ast";

const project = new Project({ useVirtualFileSystem: true });
const fs = project.getFileSystem();
Expand All @@ -45,7 +45,7 @@ you won't be able to resolve the types they define.
If you need this information, you will have to write them to the virtual file system manually using a method that works well in your environment:

```ts ignore-error: 1109
import Project, {FileSystemHost} from "ts-simple-ast";
import { Project, FileSystemHost } from "ts-simple-ast";

function loadDtsFiles(fs: FileSystemHost) {
// Example that loads every single lib file. You most likely don't need all of these.
Expand Down Expand Up @@ -78,7 +78,7 @@ When using a non-default file system, the library will search for these files in
It's possible to use your own custom file system by implementing the `FileSystemHost` interface then passing in an instance of this when creating a new `Ast` object:

```ts ignore-error: 2420, 2345
import Project, {FileSystemHost} from "ts-simple-ast";
import { Project, FileSystemHost } from "ts-simple-ast";

class MyCustomFileSystem implements FileSystemHost {
// implement it
Expand Down
4 changes: 2 additions & 2 deletions docs/setup/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ title: Instantiating
Use the default export from `"ts-simple-ast"`:

```ts
import Project from "ts-simple-ast";
import { Project } from "ts-simple-ast";

const project = new Project();
```

### Compiler options

```ts
import Project, {ScriptTarget} from "ts-simple-ast";
import { Project, ScriptTarget } from "ts-simple-ast";

const project = new Project({
compilerOptions: {
Expand Down
5 changes: 3 additions & 2 deletions lib/ts-simple-ast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,6 @@ export declare class Project {
forgetNodesCreatedInBlock(block: (remember: (...node: Node[]) => void) => Promise<void>): void;
}

export default Project;

export interface SourceFileCreateOptions {
overwrite?: boolean;
}
Expand Down Expand Up @@ -9984,3 +9982,6 @@ interface TypeParameterDeclarationSpecificStructure {

export * from "./typescript/typescript";
export * from "./codeBlockWriter/code-block-writer";

/** @deprecated Use the named export "Project" */
export default Project;
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Work in progress: https://dsherret.github.io/ts-simple-ast/
## Example

```ts
import Project from "ts-simple-ast";
import { Project } from "ts-simple-ast";

// initialize
const project = new Project();
Expand Down
5 changes: 4 additions & 1 deletion scripts/generation/flattenDeclarationFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function flattenDeclarationFiles(project: Project, mainFile: SourceFile)
const compilerApiFile = project.getSourceFileOrThrow("dist/typescript/typescript.d.ts");
const codeBlockWriterFile = project.getSourceFileOrThrow("dist/codeBlockWriter/code-block-writer.d.ts");
const exportedDeclarations = mainFile.getExportedDeclarations();

mainFile.removeText();

for (let declaration of exportedDeclarations) {
Expand All @@ -37,9 +38,11 @@ export function flattenDeclarationFiles(project: Project, mainFile: SourceFile)

mainFile.addExportDeclaration({ moduleSpecifier: mainFile.getRelativePathAsModuleSpecifierTo(compilerApiFile) });
mainFile.addExportDeclaration({ moduleSpecifier: mainFile.getRelativePathAsModuleSpecifierTo(codeBlockWriterFile) });
// todo: no JSDoc? seems like TypeScript declaration file says no, but the compiler parses it anyway
const defaultExport = mainFile.addExportAssignment({ expression: "Project", isExportEquals: false });
mainFile.insertText(defaultExport.getStart(), writer => writer.write(`/** @deprecated Use the named export "Project" */`).newLine());

// update the main.d.ts file
mainFile.getClassOrThrow("Project").setIsDefaultExport(true);
mainFile.replaceWithText(mainFile.getFullText().replace(/compiler\.([A-Za-z]+)/g, "$1"));

definitionFiles.filter(f => f !== mainFile).forEach(f => f.delete());
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export * from "./compiler";
export * from "./errors/classes";
export { Directory, DirectoryAddOptions, DirectoryCopyOptions, DirectoryEmitResult, DirectoryMoveOptions, FileSystemHost } from "./fileSystem";
export * from "./options";
export { Options, Project as default, SourceFileCreateOptions } from "./Project";
export { Options, Project, SourceFileCreateOptions } from "./Project";
export { Project as default } from "./Project";
export * from "./structures";
export { Constructor, WriterFunction } from "./types";
export * from "./typescript";
Expand Down
2 changes: 1 addition & 1 deletion src/tests/compiler/module/exportSpecifierTests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { ExportDeclaration, ExportSpecifier } from "../../../compiler";
import Project from "../../../main";
import { Project } from "../../../Project";
import { ExportSpecifierStructure } from "../../../structures";
import { SyntaxKind } from "../../../typescript";
import { ArrayUtils } from "../../../utils";
Expand Down
2 changes: 1 addition & 1 deletion src/tests/manipulation/textChecks/isBlankLineAtPosTests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import Project from "../../../main";
import { Project } from "../../../Project";
import { isBlankLineAtPos } from "../../../manipulation/textChecks";

describe(nameof(isBlankLineAtPos), () => {
Expand Down

0 comments on commit f529801

Please sign in to comment.