@rollup/plugin-typescript
Advanced tools
Comparing version 11.0.0 to 11.1.0
@@ -853,17 +853,24 @@ 'use strict'; | ||
const code = getEmittedFile(id, emittedFiles, tsCache); | ||
let baseDir = outputOptions.dir || | ||
(parsedOptions.options.declaration | ||
? parsedOptions.options.declarationDir || parsedOptions.options.outDir | ||
: null); | ||
const cwd = normalizePath(process.cwd()); | ||
if (parsedOptions.options.declaration && | ||
parsedOptions.options.declarationDir && | ||
(baseDir === null || baseDir === void 0 ? void 0 : baseDir.startsWith(cwd))) { | ||
const declarationDir = baseDir.slice(cwd.length + 1); | ||
baseDir = baseDir.slice(0, -1 * declarationDir.length); | ||
if (!code || !parsedOptions.options.declaration) { | ||
return; | ||
} | ||
if (!baseDir && tsconfig) { | ||
baseDir = tsconfig.substring(0, tsconfig.lastIndexOf('/')); | ||
let baseDir; | ||
if (outputOptions.dir) { | ||
baseDir = outputOptions.dir; | ||
} | ||
if (!code || !baseDir) | ||
else if (outputOptions.file) { | ||
// find common path of output.file and configured declation output | ||
const outputDir = path__namespace.dirname(outputOptions.file); | ||
const configured = path__namespace.resolve(parsedOptions.options.declarationDir || | ||
parsedOptions.options.outDir || | ||
tsconfig || | ||
process.cwd()); | ||
const backwards = path__namespace | ||
.relative(outputDir, configured) | ||
.split(path__namespace.sep) | ||
.filter((v) => v === '..') | ||
.join(path__namespace.sep); | ||
baseDir = path__namespace.normalize(`${outputDir}/${backwards}`); | ||
} | ||
if (!baseDir) | ||
return; | ||
@@ -870,0 +877,0 @@ this.emitFile({ |
@@ -831,17 +831,24 @@ import * as path from 'path'; | ||
const code = getEmittedFile(id, emittedFiles, tsCache); | ||
let baseDir = outputOptions.dir || | ||
(parsedOptions.options.declaration | ||
? parsedOptions.options.declarationDir || parsedOptions.options.outDir | ||
: null); | ||
const cwd = normalizePath(process.cwd()); | ||
if (parsedOptions.options.declaration && | ||
parsedOptions.options.declarationDir && | ||
(baseDir === null || baseDir === void 0 ? void 0 : baseDir.startsWith(cwd))) { | ||
const declarationDir = baseDir.slice(cwd.length + 1); | ||
baseDir = baseDir.slice(0, -1 * declarationDir.length); | ||
if (!code || !parsedOptions.options.declaration) { | ||
return; | ||
} | ||
if (!baseDir && tsconfig) { | ||
baseDir = tsconfig.substring(0, tsconfig.lastIndexOf('/')); | ||
let baseDir; | ||
if (outputOptions.dir) { | ||
baseDir = outputOptions.dir; | ||
} | ||
if (!code || !baseDir) | ||
else if (outputOptions.file) { | ||
// find common path of output.file and configured declation output | ||
const outputDir = path.dirname(outputOptions.file); | ||
const configured = path.resolve(parsedOptions.options.declarationDir || | ||
parsedOptions.options.outDir || | ||
tsconfig || | ||
process.cwd()); | ||
const backwards = path | ||
.relative(outputDir, configured) | ||
.split(path.sep) | ||
.filter((v) => v === '..') | ||
.join(path.sep); | ||
baseDir = path.normalize(`${outputDir}/${backwards}`); | ||
} | ||
if (!baseDir) | ||
return; | ||
@@ -848,0 +855,0 @@ this.emitFile({ |
{ | ||
"name": "@rollup/plugin-typescript", | ||
"version": "11.0.0", | ||
"version": "11.1.0", | ||
"publishConfig": { | ||
@@ -74,2 +74,3 @@ "access": "public" | ||
"@types/node": "^14.18.30", | ||
"@types/resolve": "^1.20.2", | ||
"buble": "^0.20.0", | ||
@@ -76,0 +77,0 @@ "rollup": "^3.2.3", |
@@ -303,50 +303,2 @@ [npm]: https://img.shields.io/npm/v/@rollup/plugin-typescript | ||
### Declaration Output With `output.file` | ||
When instructing Rollup to output a specific file name via the `output.file` Rollup configuration, and TypeScript to output declaration files, users may encounter a situation where the declarations are nested improperly. And additionally when attempting to fix the improper nesting via use of `outDir` or `declarationDir` result in further TypeScript errors. | ||
Consider the following `rollup.config.js` file: | ||
```js | ||
import typescript from '@rollup/plugin-typescript'; | ||
export default { | ||
input: 'src/index.ts', | ||
output: { | ||
file: 'dist/index.mjs' | ||
}, | ||
plugins: [typescript()] | ||
}; | ||
``` | ||
And accompanying `tsconfig.json` file: | ||
```json | ||
{ | ||
"include": ["*"], | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"declaration": true | ||
} | ||
} | ||
``` | ||
This setup will produce `dist/index.mjs` and `dist/src/index.d.ts`. To correctly place the declaration file, add an `exclude` setting in `tsconfig` and modify the `declarationDir` setting in `compilerOptions` to resemble: | ||
```json | ||
{ | ||
"include": ["*"], | ||
"exclude": ["dist"], | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"declaration": true, | ||
"declarationDir": "." | ||
} | ||
} | ||
``` | ||
This will result in the correct output of `dist/index.mjs` and `dist/index.d.ts`. | ||
_For reference, please see the workaround this section is based on [here](https://github.com/microsoft/bistring/commit/7e57116c812ae2c01f383c234f3b447f733b5d0c)_ | ||
## Meta | ||
@@ -353,0 +305,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1833
91883
7
308