Description
What happens and why it is wrong
When building a project with files that only have type declarations, the declarations don't get generated for those files. Using tsc
generated the declarations and declaration maps as expected.
Versions
- typescript: 3.0.1
- rollup: 0.64.1
- rollup-plugin-typescript2: 0.16.1
rollup.config.js
import { dirname, join } from 'path';
import commonjs from 'rollup-plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import resolve from 'rollup-plugin-node-resolve';
const root = process.cwd();
const { main, module, types, dependencies = {}, peerDependencies = {} } = require(join(root, 'package.json'));
export default {
input: join(root, 'src/index.ts'),
output: [
{
file: join(root, main),
format: 'cjs',
sourcemap: true
},
{
file: join(root, module),
format: 'es',
sourcemap: true
}
],
external: [
...Object.keys(dependencies),
...Object.keys(peerDependencies)
],
plugins: [
resolve(),
typescript({
clean: true,
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
rootDir: join(root, 'src'),
declarationDir: join(root, dirname(types))
}
}
}),
commonjs()
]
};
tsconfig.json
{
"compilerOptions": {
"module": "esnext",
"target": "es5",
"lib": [
"es6",
"dom"
],
"jsx": "react",
"moduleResolution": "node",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"strict": true,
"allowSyntheticDefaultImports": true
},
"include": [
"src/"
]
}
package.json
{
"scripts": {
"prebuild": "lerna exec -- rimraf lib",
"build": "lerna exec --parallel -- rollup --config \\$LERNA_ROOT_PATH/rollup.config.js"
},
"devDependencies": {
"lerna": "^3.1.2",
"rimraf": "^2.6.2",
"rollup": "^0.64.1",
"rollup-plugin-commonjs": "^9.1.5",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-typescript2": "^0.16.1",
"typescript": "^3.0.1"
}
}
plugin output with verbosity 3
Log
lerna notice cli v3.1.4
lerna info exec in 1 package: "rollup --config $LERNA_ROOT_PATH/rollup.config.js"
@: <path>/src/index.ts → lib/index.js, lib/index.es.js...
@: rpt2: typescript version: 3.0.1
@: rpt2: tslib version: 1.9.3
@: rpt2: rollup-plugin-typescript2 version: 0.16.1
@: rpt2: plugin options:
@: {
@: "verbosity": 3,
@: "clean": true,
@: "useTsconfigDeclarationDir": true,
@: "tsconfigOverride": {
@: "compilerOptions": {
@: "rootDir": "<path>/src",
@: "declarationDir": "<path>/lib"
@: }
@: },
@: "check": true,
@: "cacheRoot": "<path>/.rpt2_cache",
@: "include": [
@: "*.ts+(|x)",
@: "**/*.ts+(|x)"
@: ],
@: "exclude": [
@: "*.d.ts",
@: "**/*.d.ts"
@: ],
@: "abortOnError": true,
@: "rollupCommonJSResolveHack": false,
@: "typescript": "version 3.0.1",
@: "transformers": [],
@: "tsconfigDefaults": {}
@: }
@: rpt2: rollup config:
@: {
@: "external": [
@: "react",
@: "",
@: ""
@: ],
@: "inlineDynamicImports": false,
@: "input": "<path>/src/index.ts",
@: "chunkGroupingSize": 5000,
@: "perf": false,
@: "plugins": [
@: {
@: "name": "node-resolve"
@: },
@: {
@: "name": "rpt2"
@: },
@: {
@: "name": "commonjs"
@: }
@: ],
@: "entry": "<path>/src/index.ts"
@: }
@: rpt2: built-in options overrides: {
@: "noEmitHelpers": false,
@: "importHelpers": true,
@: "noResolve": false,
@: "noEmit": false,
@: "inlineSourceMap": false,
@: "outDir": "<path>/.rpt2_cache/placeholder",
@: "moduleResolution": 2
@: }
@: rpt2: parsed tsconfig: {
@: "options": {
@: "module": 6,
@: "target": 1,
@: "lib": [
@: "lib.es2015.d.ts",
@: "lib.dom.d.ts"
@: ],
@: "jsx": 2,
@: "moduleResolution": 2,
@: "declaration": true,
@: "declarationMap": true,
@: "sourceMap": true,
@: "strict": true,
@: "allowSyntheticDefaultImports": true,
@: "rootDir": "<path>/src",
@: "declarationDir": "<path>/lib",
@: "configFilePath": "<path>/tsconfig.json",
@: "noEmitHelpers": false,
@: "importHelpers": true,
@: "noResolve": false,
@: "noEmit": false,
@: "inlineSourceMap": false,
@: "outDir": "<path>/.rpt2_cache/placeholder"
@: },
@: "fileNames": [],
@: "typeAcquisition": {
@: "enable": false,
@: "include": [],
@: "exclude": []
@: },
@: "raw": {
@: "compilerOptions": {
@: "module": "esnext",
@: "target": "es5",
@: "lib": [
@: "es6",
@: "dom"
@: ],
@: "jsx": "react",
@: "moduleResolution": "node",
@: "declaration": true,
@: "declarationMap": true,
@: "sourceMap": true,
@: "strict": true,
@: "allowSyntheticDefaultImports": true,
@: "rootDir": "<path>/src",
@: "declarationDir": "<path>/lib"
@: },
@: "include": [
@: "src/"
@: ],
@: "compileOnSave": false
@: },
@: "errors": [
@: {
@: "messageText": "No inputs were found in config file '<path>/tsconfig.json'. Specified 'include' paths were '[\"src/\"]' and 'exclude' paths were '[\"<path>/lib\"]'.",
@: "category": 1,
@: "code": 18003
@: }
@: ],
@: "wildcardDirectories": {
@: "<path>/src/": 1
@: },
@: "compileOnSave": false,
@: "configFileSpecs": {
@: "includeSpecs": [
@: "src/"
@: ],
@: "excludeSpecs": [
@: "<path>/lib"
@: ],
@: "validatedIncludeSpecs": [
@: "src/"
@: ],
@: "validatedExcludeSpecs": [
@: "<path>/lib"
@: ],
@: "wildcardDirectories": {
@: "<path>/src/": 1
@: }
@: }
@: }
@: rpt2: included:
@: '[
@: "*.ts+(|x)",
@: "**/*.ts+(|x)"
@: ]'
@: rpt2: excluded:
@: '[
@: "*.d.ts",
@: "**/*.d.ts"
@: ]'
@: rpt2: Ambient types:
@: rpt2: <path>/node_modules/@types/estree/index.d.ts
@: rpt2: <path>/node_modules/@types/node/index.d.ts
@: rpt2: <path>/node_modules/@types/prop-types/index.d.ts
@: rpt2: <path>/node_modules/@types/react/index.d.ts
@: rpt2: ambient types changed, redoing all semantic diagnostics
@: rpt2: transpiling '<path>/src/index.ts'
@: rpt2: cache: 'cb5a72ce1d9ca58fa672e942573d3ba70cc6e65e'
@: rpt2: cache miss
@: rpt2: cache: 'cb5a72ce1d9ca58fa672e942573d3ba70cc6e65e'
@: rpt2: cache miss
@: rpt2: cache: 'cb5a72ce1d9ca58fa672e942573d3ba70cc6e65e'
@: rpt2: cache miss
@: rpt2: generated declarations for '<path>/src/index.ts'
@: rpt2: dependency '<path>/src/constants.ts'
@: rpt2: imported by '<path>/src/index.ts'
@: rpt2: resolving './constants'
@: rpt2: to '<path>/src/constants.ts'
@: rpt2: transpiling '<path>/src/constants.ts'
@: rpt2: cache: 'c0821b0be34b449d7f93ba52a5b0708ea09e39f7'
@: rpt2: cache miss
@: rpt2: cache: 'c0821b0be34b449d7f93ba52a5b0708ea09e39f7'
@: rpt2: cache miss
@: rpt2: cache: 'c0821b0be34b449d7f93ba52a5b0708ea09e39f7'
@: rpt2: cache miss
@: rpt2: generated declarations for '<path>/src/constants.ts'
@: rpt2: generating target 1
@: rpt2: rolling caches
@: rpt2: writing declarations for '<path>/src/index.ts' to '<path>/lib/index.d.ts'
@: rpt2: writing declarations for '<path>/src/index.ts' to '<path>/lib/index.d.ts.map'
@: rpt2: writing declarations for '<path>/src/constants.ts' to '<path>/lib/constants.d.ts'
@: rpt2: writing declarations for '<path>/src/constants.ts' to '<path>/lib/constants.d.ts.map'
@: rpt2: generating target 2
@: rpt2: rolling caches
@: rpt2: writing declarations for '<path>/src/index.ts' to '<path>/lib/index.d.ts'
@: rpt2: writing declarations for '<path>/src/index.ts' to '<path>/lib/index.d.ts.map'
@: rpt2: writing declarations for '<path>/src/constants.ts' to '<path>/lib/constants.d.ts'
@: rpt2: writing declarations for '<path>/src/constants.ts' to '<path>/lib/constants.d.ts.map'
@: created lib/index.js, lib/index.es.js in 1.2s