Coder Social home page Coder Social logo

project-references-demo's Introduction

TypeScript Project References Demo

Files in this repository

The structure of this repo is as follows:

Source Code Folders

/core                  Base library for this application
  /tsconfig.json         Config file for 'core' project
  /utilities.ts          Submodule that exposes two utility functions
/animals               Depends on 'core'
  /tsconfig.json         Config file for 'animal' project
  /animal.ts             Defines the 'animal' type
  /dog.ts                Defines the 'dog' type
  /index.ts              Entry point module that re-exposes types from animal.ts and dog.ts
/zoo                   Depends on 'animals' (directly) and 'core' (indirectly)
  /tsconfig.json         Config file for 'zoo' project
  /zoo.ts                Creates a zoo with some dogs in it (OK it's a weird zoo)
/tsconfig.json           Solution file for the application

Build and Build Configuration

/core                  Base library for this application
/lib                   Output folder (not checked in)
/tsconfig-base.json    Shared configuration file for common compiler options

The Usual Suspects

/README.md             You're reading it
/.gitignore            For excluding build outputs and node_modules
/package.json          NPM package definition file
/package-lock.json     NPM package lock file
/node_modules          NPM modules

Branches You Can Try

The following branches are provided for demo/exploration purposes

master

This branch shows the normal layout

> git checkout master
>yarn build
yarn run v1.15.2
$ tsc -b -v
[11:02:33 AM] Projects in this build:
    * core/tsconfig.json
    * animals/tsconfig.json
    * zoo/tsconfig.json
    * tsconfig.json

[11:02:33 AM] Project 'core/tsconfig.json' is out of date because output file 'lib/core/utilities.js' does not exist

[11:02:33 AM] Building project 'c:/github/project-references-demo/core/tsconfig.json'...

[11:02:35 AM] Project 'animals/tsconfig.json' is out of date because output file 'lib/animals/animal.js' does not exist

[11:02:35 AM] Building project 'c:/github/project-references-demo/animals/tsconfig.json'...

[11:02:35 AM] Project 'zoo/tsconfig.json' is out of date because output file 'lib/zoo/zoo.js' does not exist

[11:02:35 AM] Building project 'c:/github/project-references-demo/zoo/tsconfig.json'...

Done in 2.66s.

>

circular

This branch introduces a circular dependency by editing the core project's tsconfig.json to add a dependency to zoo. Attempting to build any project will cause an error:

> git checkout circular
> yarn build
yarn run v1.15.2
$ tsc -b -v
[11:52:04 AM] Projects in this build:
    * animals/tsconfig.json
    * zoo/tsconfig.json
    * core/tsconfig.json
    * tsconfig.json

error TS6202: Project references may not form a circular graph. Cycle detected: c:/github/project-references-demo/tsconfig.json
c:/github/project-references-demo/core/tsconfig.json
c:/github/project-references-demo/zoo/tsconfig.json
c:/github/project-references-demo/animals/tsconfig.json


Found 1 error.

error Command failed with exit code 4.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

>

bad-ref

This branch introduces an illegal reference in the source code by adding an import targeting a file outside the project folder. Attempting to build core will cause an error:

> git checkout bad-ref
>yarn build
yarn run v1.15.2
$ tsc -b -v
[1:40:34 PM] Projects in this build:
    * core/tsconfig.json
    * animals/tsconfig.json
    * zoo/tsconfig.json
    * tsconfig.json

[1:40:34 PM] Project 'core/tsconfig.json' is out of date because output file 'lib/core/utilities.js' does not exist

[1:40:34 PM] Building project 'c:/github/project-references-demo/core/tsconfig.json'...

animals/index.ts:1:20 - error TS6059: File 'c:/github/project-references-demo/animals/animal.ts' is not under 'rootDir' 'c:/github/project-references-demo/core'. 'rootDir' is expected to contain all source files.

1 import Animal from './animal';
                     ~~~~~~~~~~

animals/index.ts:1:20 - error TS6307: File 'c:/github/project-references-demo/animals/animal.ts' is not listed within the file list of project 'c:/github/project-references-demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.

1 import Animal from './animal';
                     ~~~~~~~~~~

animals/index.ts:4:32 - error TS6059: File 'c:/github/project-references-demo/animals/dog.ts' is not under 'rootDir' 'c:/github/project-references-demo/core'. 'rootDir' is expected to contain all source files.

4 import { createDog, Dog } from './dog';
                                 ~~~~~~~

animals/index.ts:4:32 - error TS6307: File 'c:/github/project-references-demo/animals/dog.ts' is not listed within the file list of project 'c:/github/project-references-demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.

4 import { createDog, Dog } from './dog';
                                 ~~~~~~~

core/utilities.ts:1:1 - error TS6133: 'A' is declared but its value is never read.

1 import * as A from '../animals';
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

core/utilities.ts:1:20 - error TS6059: File 'c:/github/project-references-demo/animals/index.ts' is not under 'rootDir' 'c:/github/project-references-demo/core'. 'rootDir' is expected to contain all source files.

1 import * as A from '../animals';
                     ~~~~~~~~~~~~

core/utilities.ts:1:20 - error TS6307: File 'c:/github/project-references-demo/animals/index.ts' is not listed within the file list of project 'c:/github/project-references-demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.

1 import * as A from '../animals';
                     ~~~~~~~~~~~~

[1:40:35 PM] Project 'animals/tsconfig.json' can't be built because its dependency 'core' has errors

[1:40:35 PM] Skipping build of project 'c:/github/project-references-demo/animals/tsconfig.json' because its dependency 'c:/github/project-references-demo/core' has errors

[1:40:35 PM] Project 'zoo/tsconfig.json' can't be built because its dependency 'animals' was not built

[1:40:35 PM] Skipping build of project 'c:/github/project-references-demo/zoo/tsconfig.json' because its dependency 'c:/github/project-references-demo/animals' was not built


Found 7 errors.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

>

empty-sleeves

Nothing up my sleeves ๐Ÿ‡๐ŸŽฉ! This branch deletes the core and animals source files. The zoo project can still be built because it only consumes the output files.

> gulp clean
[...]
> gulp core animals
[...]
> git checkout empty-sleeves
> gulp zoo
[07:35:22] Using gulpfile C:\github\project-references-demo\gulpfile.js
[07:35:22] Starting 'zoo'...
[07:35:24] Finished 'zoo' after 2.15 s

project-references-demo's People

Contributors

ryancavanaugh avatar sheetalkamat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

project-references-demo's Issues

Just a question

Is it better to use outdir or outfile when using new project reference?
Thanks Ryan

Is there anyway to get the auto import feature from VS Code to work with project reference?

Currently, it looks like the auto-import will work for any files are already referenced, so if i add a bark function to dog.ts, you can immediately import that in zoo.ts

However, let's say I add a new file, cat.ts, and a meow function in it. There's no way to auto-import that function into zoo.ts.

I tried this with tsc -b -w running and the declarations are being created, but VS code still doesn't pick that up

Referencing core/utilities.makeRandomName() from zoo TOO?

I hope I'm not missing something small, but I'm having trouble with a similar setup in my own project, although the specifics and the exact error are different.

Why can't I add a direct project reference from zoo to core without it breaking the build?

image

In case it is relevant: In my own project, I'm trying to use pnpm workspaces which does some linking of projects into packages' node_modules - so the error is that it can't find the definitions once the node_modules are populated by the first build? This bug seems relevant, but I can't understand exactly how to relate to it. If I can get past understanding this simple case of zoo -> core, zoo -> animal & animal -> core, then I figure the next step will be to somehow suppress the pnpm linking of node_modules of projects in the monorepo, and let typescript handle that calculation instead??

Need to add files: [] to tsproject and create baseconfig with compiler options to extend from

From microsoft/TypeScript#28875

danielrentz commented 29 days ago
TypeScript Version: 3.2.1

I have tried https://github.com/RyanCavanaugh/project-references-demo

and tsc -b tsproject.json emits the output files into the /lib directory as expected, but additionally generates (some of) these files again next to the *.ts source files which seems unexpected.

Example session:

> git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean

> tsc --build tsproject.json

> git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        animals/animal.d.ts
        animals/animal.js
        animals/dog.d.ts
        animals/dog.js
        zoo/zoo.d.ts
        zoo/zoo.js
nothing added to commit but untracked files present (use "git add" to track)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.