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

Building includes declarations from sibling test directory -- use 2 tsconfigs #132

Closed
badeball opened this issue Jan 13, 2019 · 2 comments
Closed
Labels
kind: support Asking for support with something or a specific use case

Comments

@badeball
Copy link

badeball commented Jan 13, 2019

What happens and why it is wrong

I'm running the following, simple example, but the generated declarations include declarations from the test directory and create the following tree.

$ tree dist/
dist/
├── foo.js
├── lib
│   └── foo.d.ts
└── test
    └── foo-spec.d.ts

If I however rename the test file to remove the ts-extension (mv test/foo-spec.ts test/foo-spec.js), I get the the following tree, which is more aligned with my expectations.

$ tree dist/
dist/
├── foo.d.ts
└── foo.js

How is one supposed to test (while still using typescript), but not let it affect the build output?

Environment

Versions

  • typescript: 3.2.2
  • rollup: 1.1.0
  • rollup-plugin-typescript2: 3.2.2

rollup.config.js

import typescript from "rollup-plugin-typescript2";

export default {
  input: "lib/foo.ts",
  output: [
    {
      file: "dist/foo.js",
      format: "cjs"
    }
  ],
  plugins: [
    typescript(),
  ],
};

tsconfig.json

{
  "compilerOptions": {
    "declaration": true
  }
}

package.json

{
  "scripts": {
    "build": "rollup --config"
  },
  "dependencies": {
    "rollup": "^1.1.0",
    "rollup-plugin-typescript2": "^0.18.1",
    "typescript": "^3.2.2"
  }
}

plugin output with verbosity 3

$ npm run build

> @ build /home/jonas/projects/example
> rollup --config


lib/foo.ts → dist/foo.js...
rpt2: typescript version: 3.2.2
rpt2: tslib version: 1.9.3
rpt2: rollup-plugin-typescript2 version: 0.18.1
rpt2: plugin options:
{
    "verbosity": 3,
    "check": true,
    "clean": false,
    "cacheRoot": "/home/jonas/projects/example/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "typescript": "version 3.2.2",
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {},
    "transformers": [],
    "tsconfigDefaults": {},
    "objectHashIgnoreUnknownHack": false
}
rpt2: rollup config:
{
    "experimentalCacheExpiry": 10,
    "external": [
        "",
        ""
    ],
    "inlineDynamicImports": false,
    "input": "lib/foo.ts",
    "chunkGroupingSize": 5000,
    "perf": false,
    "plugins": [
        {
            "name": "rpt2"
        }
    ]
}
rpt2: built-in options overrides: {
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "inlineSourceMap": false,
    "outDir": "/home/jonas/projects/example/.rpt2_cache/placeholder",
    "moduleResolution": 2,
    "allowNonTsExtensions": true,
    "declarationDir": "/home/jonas/projects/example",
    "sourceRoot": null
}
rpt2: parsed tsconfig: {
    "options": {
        "module": 5,
        "declaration": true,
        "configFilePath": "/home/jonas/projects/example/tsconfig.json",
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "noEmit": false,
        "inlineSourceMap": false,
        "outDir": "/home/jonas/projects/example/.rpt2_cache/placeholder",
        "moduleResolution": 2,
        "allowNonTsExtensions": true,
        "declarationDir": "/home/jonas/projects/example",
        "sourceRoot": null
    },
    "fileNames": [
        "/home/jonas/projects/example/lib/foo.ts",
        "/home/jonas/projects/example/test/foo-spec.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {
            "module": "ES2015",
            "declaration": true
        },
        "compileOnSave": false
    },
    "errors": [],
    "wildcardDirectories": {
        "/home/jonas/projects/example": 1
    },
    "compileOnSave": false,
    "configFileSpecs": {
        "includeSpecs": [
            "**/*"
        ],
        "validatedIncludeSpecs": [
            "**/*"
        ],
        "wildcardDirectories": {
            "/home/jonas/projects/example": 1
        }
    }
}
rpt2: included:
'[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]'
rpt2: excluded:
'[
    "*.d.ts",
    "**/*.d.ts"
]'
rpt2: Ambient types:
rpt2:     /home/jonas/projects/example/node_modules/@types/estree/index.d.ts
rpt2:     /home/jonas/projects/example/node_modules/@types/node/index.d.ts
rpt2: transpiling '/home/jonas/projects/example/lib/foo.ts'
rpt2:     cache: '/home/jonas/projects/example/.rpt2_cache/rpt2_75ff5961aeedcee767d6c7041f1eb1648cb1bbc1/code/cache/b3ed268311cacea225a5f9897812420c926c3d10'
rpt2:     cache hit
rpt2:     cache: '/home/jonas/projects/example/.rpt2_cache/rpt2_75ff5961aeedcee767d6c7041f1eb1648cb1bbc1/syntacticDiagnostics/cache/b3ed268311cacea225a5f9897812420c926c3d10'
rpt2:     cache hit
rpt2:     cache: '/home/jonas/projects/example/.rpt2_cache/rpt2_75ff5961aeedcee767d6c7041f1eb1648cb1bbc1/semanticDiagnostics/cache/b3ed268311cacea225a5f9897812420c926c3d10'
rpt2:     cache hit
rpt2: generated declarations for '/home/jonas/projects/example/lib/foo.ts'
rpt2: generating target 1
rpt2: rolling caches
rpt2: generating missed declarations for '/home/jonas/projects/example/test/foo-spec.ts'
rpt2: writing declarations for '/home/jonas/projects/example/lib/foo.ts' to '/home/jonas/projects/example/dist/lib/foo.d.ts'
rpt2: writing declarations for '/home/jonas/projects/example/test/foo-spec.ts' to '/home/jonas/projects/example/dist/test/foo-spec.d.ts'
(!) rpt2 plugin: The ongenerate hook used by plugin rpt2 is deprecated. The generateBundle hook should be used instead.
(!) rpt2 plugin: The onwrite hook used by plugin rpt2 is deprecated. The generateBundle hook should be used instead.
created dist/foo.js in 924ms
@ezolenko
Copy link
Owner

ezolenko commented Jan 14, 2019

Declarations are generated for all ts files that are captured in tsconfig.json, if you don't specify relevant files in tsconfig, the default is all files in the same folder and in all subdirectories I believe.

In your case try creating 2 tsconfigs -- one for source that will get published and one for test that uses built source and runs tests. See files and include/exclude options in tsconfig-json.

@badeball
Copy link
Author

I see. Thanks for the quick response!

@agilgur5 agilgur5 changed the title Building includes declerations from sibling test directory Building includes declarations from sibling test directory -- use 2 tsconfigs May 21, 2022
@agilgur5 agilgur5 added the kind: support Asking for support with something or a specific use case label May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: support Asking for support with something or a specific use case
Projects
None yet
Development

No branches or pull requests

3 participants