pax_global_header00006660000000000000000000000064146113202140014504gustar00rootroot0000000000000052 comment=c69ff0d1c585b96f093ee6323bbc5a74cc1eda58 timocov-dts-bundle-generator-c69ff0d/000077500000000000000000000000001461132021400177125ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/.eslintignore000066400000000000000000000001621461132021400224140ustar00rootroot00000000000000*.js /dist/** /dts-out/** **/node_modules /tests/e2e/test-cases/*/**/*.ts !/tests/e2e/test-cases/**/*.spec.js timocov-dts-bundle-generator-c69ff0d/.eslintrc.js000066400000000000000000000362441461132021400221620ustar00rootroot00000000000000module.exports = { root: true, plugins: [ '@typescript-eslint', 'eslint-plugin-deprecation', 'eslint-plugin-import', 'eslint-plugin-unicorn', ], extends: [ 'eslint:recommended', ], env: { browser: false, es6: true, node: true, }, parserOptions: { ecmaVersion: 2020, sourceType: 'module', }, overrides: [ { // rules specific for js files only files: ['**/*.js'], rules: { // enforces no braces where they can be omitted // http://eslint.org/docs/rules/arrow-body-style 'arrow-body-style': ['error', 'as-needed'], // enforce one true brace style 'brace-style': ['error', '1tbs', { allowSingleLine: true }], // require camel case names camelcase: 'error', // encourages use of dot notation whenever possible 'dot-notation': ['error', { allowKeywords: true }], // this option sets a specific tab width for your code // https://github.com/eslint/eslint/blob/master/docs/rules/indent.md indent: ['error', 'tab', { SwitchCase: 1, VariableDeclarator: 1 }], // disallow creation of functions within loops 'no-loop-func': 'error', // disallow variable declarations from shadowing variables declared in the outer scope 'no-shadow': 'error', // disallow use of undeclared variables unless mentioned in a /*global */ block 'no-undef': 'error', // disallow usage of expressions in statement position 'no-unused-expressions': 'error', // disallow declaration of variables that are not used in the code 'no-unused-vars': ['error', { vars: 'local', args: 'none', ignoreRestSiblings: true }], // specify whether double or single quotes should be used quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }], // require or disallow use of semicolons instead of ASI semi: ['error', 'always'], }, }, { files: ['**/*.ts'], extends: [ 'plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking', 'plugin:import/typescript', ], parser: '@typescript-eslint/parser', parserOptions: { project: 'tsconfig.options.json', sourceType: 'module', }, rules: { '@typescript-eslint/array-type': [ 'error', { default: 'array', }, ], '@typescript-eslint/brace-style': ['error', '1tbs', { allowSingleLine: true }], '@typescript-eslint/consistent-type-assertions': [ 'error', { assertionStyle: 'as', objectLiteralTypeAssertions: 'never', }, ], '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], '@typescript-eslint/dot-notation': 'error', '@typescript-eslint/explicit-member-accessibility': [ 'error', { accessibility: 'explicit', overrides: { accessors: 'explicit', constructors: 'explicit', }, }, ], '@typescript-eslint/indent': ['error', 'tab'], '@typescript-eslint/member-delimiter-style': 'error', '@typescript-eslint/member-ordering': [ 'error', { default: [ 'signature', 'public-static-field', 'protected-static-field', 'private-static-field', 'public-instance-field', 'protected-instance-field', 'private-instance-field', 'constructor', 'public-instance-method', 'public-static-method', 'protected-instance-method', 'protected-static-method', 'private-instance-method', 'private-static-method', ], }, ], '@typescript-eslint/naming-convention': [ 'error', { selector: 'default', format: ['camelCase'], leadingUnderscore: 'forbid', trailingUnderscore: 'forbid' }, { selector: 'typeLike', format: ['PascalCase'] }, { selector: 'enumMember', format: ['PascalCase'] }, ], '@typescript-eslint/no-empty-interface': 'off', '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/no-extraneous-class': 'error', '@typescript-eslint/no-inferrable-types': [ 'error', { ignoreParameters: true, ignoreProperties: true, }, ], '@typescript-eslint/no-invalid-void-type': 'error', '@typescript-eslint/no-loop-func': 'error', '@typescript-eslint/no-namespace': 'off', '@typescript-eslint/no-non-null-assertion': 'error', '@typescript-eslint/no-require-imports': 'off', '@typescript-eslint/no-shadow': 'error', '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'off', '@typescript-eslint/no-unnecessary-qualifier': 'error', '@typescript-eslint/no-unnecessary-type-arguments': 'off', '@typescript-eslint/no-unsafe-assignment': 'off', '@typescript-eslint/no-unused-expressions': 'error', '@typescript-eslint/no-unused-vars': 'off', '@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/parameter-properties': ['error', { prefer: 'class-property' }], '@typescript-eslint/prefer-for-of': 'off', '@typescript-eslint/prefer-function-type': 'error', '@typescript-eslint/prefer-readonly': 'off', // TODO '@typescript-eslint/promise-function-async': 'off', '@typescript-eslint/quotes': ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }], '@typescript-eslint/restrict-plus-operands': 'off', '@typescript-eslint/restrict-template-expressions': 'off', '@typescript-eslint/semi': [ 'error', 'always', ], '@typescript-eslint/strict-boolean-expressions': 'off', '@typescript-eslint/triple-slash-reference': [ 'off', { path: 'never', types: 'prefer-import', lib: 'never', }, ], '@typescript-eslint/type-annotation-spacing': 'error', '@typescript-eslint/typedef': [ 'error', { parameter: true, propertyDeclaration: true, memberVariableDeclaration: true, }, ], '@typescript-eslint/unbound-method': 'off', 'deprecation/deprecation': 'error', }, }, ], rules: { // enforces return statements in callbacks of array's methods // http://eslint.org/docs/rules/array-callback-return 'array-callback-return': 'error', 'arrow-parens': ['error', 'as-needed'], // enforce a maximum cyclomatic complexity allowed in a program complexity: ['error', { max: 13 }], // specify curly brace conventions for all control statements curly: ['error', 'all'], // require the use of === and !== eqeqeq: ['error', 'smart'], // require `for-in` loops to include an `if` statement 'guard-for-in': 'error', // enforce a maximum number of classes per file 'max-classes-per-file': ['error', 5], // disallow the use of alert, confirm, and prompt 'no-alert': 'warn', // disallow use of arguments.caller or arguments.callee 'no-caller': 'error', // disallow Unnecessary Labels // http://eslint.org/docs/rules/no-extra-label 'no-extra-label': 'error', // disallow use of eval() 'no-eval': 'error', // disallow adding to native types 'no-extend-native': 'error', // disallow unnecessary function binding 'no-extra-bind': 'error', // disallow the use of leading or trailing decimal points in numeric literals 'no-floating-decimal': 'error', // disallow use of eval()-like methods 'no-implied-eval': 'error', // disallow usage of __iterator__ property 'no-iterator': 'error', // disallow use of labels for anything other then loops and switches 'no-labels': ['error', { allowLoop: false, allowSwitch: false }], // disallow unnecessary nested blocks 'no-lone-blocks': 'error', // disallow use of multiple spaces 'no-multi-spaces': 'error', // disallow use of multiline strings 'no-multi-str': 'error', // disallow use of new operator when not part of the assignment or comparison 'no-new': 'error', // disallow use of new operator for Function object 'no-new-func': 'error', // disallows creating new instances of String, Number, and Boolean 'no-new-wrappers': 'error', // disallow use of octal escape sequences in string literals, such as // var foo = 'Copyright \251'; 'no-octal-escape': 'error', // disallow usage of __proto__ property 'no-proto': 'error', // disallow use of assignment in return statement 'no-return-assign': 'error', // disallow unnecessary `return await` 'no-return-await': 'error', // disallow use of `javascript:` urls. 'no-script-url': 'error', // disallow comparisons where both sides are exactly the same 'no-self-compare': 'error', // disallow use of comma operator 'no-sequences': 'error', // restrict what can be thrown as an exception 'no-throw-literal': 'error', // requires to declare all vars on top of their containing scope // 'vars-on-top': 2, // require immediate function invocation to be wrapped in parentheses // http://eslint.org/docs/rules/wrap-iife.html 'wrap-iife': ['error', 'inside'], // errors // disallow assignment in conditional expressions 'no-cond-assign': ['error', 'always'], // disallow use of console 'no-console': 'error', // disallow unnecessary parentheses 'no-extra-parens': ['error', 'functions'], // disallow template literal placeholder syntax in regular strings 'no-template-curly-in-string': 'error', // Avoid code that looks like two expressions but is actually one 'no-unexpected-multiline': 'off', // es6 // require space before/after arrow function's arrow // https://github.com/eslint/eslint/blob/master/docs/rules/arrow-spacing.md 'arrow-spacing': ['error', { before: true, after: true }], // require trailing commas in multiline object literals 'comma-dangle': ['error', { arrays: 'always-multiline', objects: 'always-multiline', imports: 'always-multiline', exports: 'always-multiline', functions: 'never', }], // disallow duplicate module imports 'no-duplicate-imports': 'error', // require let or const instead of var 'no-var': 'error', // disallow unnecessary constructor // http://eslint.org/docs/rules/no-useless-constructor 'no-useless-constructor': 'error', // require method and property shorthand syntax for object literals // https://github.com/eslint/eslint/blob/master/docs/rules/object-shorthand.md 'object-shorthand': 'off', // suggest using arrow functions as callbacks 'prefer-arrow-callback': 'error', // suggest using of const declaration for variables that are never modified after declared 'prefer-const': 'error', // require rest parameters instead of `arguments` 'prefer-rest-params': 'error', // require template literals instead of string concatenation 'prefer-template': 'off', // TODO // enforce usage of spacing in template strings // http://eslint.org/docs/rules/template-curly-spacing 'template-curly-spacing': 'error', // enforce spacing around the * in yield* expressions // http://eslint.org/docs/rules/yield-star-spacing 'yield-star-spacing': ['error', 'after'], // strict strict: 'off', // vars // disallow initializing variables to `undefined` 'no-undef-init': 'error', // style // enforce spacing inside array brackets 'array-bracket-spacing': ['error', 'never'], // enforce spacing before and after comma 'comma-spacing': ['error', { before: false, after: true }], // enforce one true comma style 'comma-style': ['error', 'last'], // disallow padding inside computed properties 'computed-property-spacing': ['error', 'never'], // enforce newline at the end of file, with no multiple empty lines 'eol-last': 'error', // specify whether double or single quotes should be used in JSX attributes // http://eslint.org/docs/rules/jsx-quotes 'jsx-quotes': ['error', 'prefer-double'], // enforces spacing between keys and values in object literal properties 'key-spacing': ['error', { beforeColon: false, afterColon: true }], // require a space before & after certain keywords 'keyword-spacing': ['error', { before: true, after: true, overrides: { return: { after: true }, throw: { after: true }, case: { after: true }, }, }], // enforce a maximum number of parameters in function definitions 'max-params': ['error', { max: 6 }], // require a capital letter for constructors 'new-cap': ['error', { newIsCap: true, capIsNew: false }], // enforce or disallow parentheses when invoking a constructor with no arguments 'new-parens': ['error', 'always'], // disallow use of the Array constructor 'no-array-constructor': 'error', // disallow mixed spaces and tabs for indentation 'no-mixed-spaces-and-tabs': 'error', // disallow multiple empty lines and only one newline at the end 'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 1 }], // disallow nested ternary expressions // 'no-nested-ternary': 2, // disallow use of the Object constructor 'no-new-object': 'error', // disallow specified syntax 'no-restricted-syntax': ['error', 'ForInStatement', `BinaryExpression[operator='in']`], // disallow space between function identifier and application 'no-spaced-func': 'error', // disallow trailing whitespace at the end of lines 'no-trailing-spaces': 'error', // disallow the use of Boolean literals in conditional expressions // also, prefer `a || b` over `a ? a : b` // http://eslint.org/docs/rules/no-unneeded-ternary 'no-unneeded-ternary': ['error', { defaultAssignment: false }], // disallow whitespace before properties // http://eslint.org/docs/rules/no-whitespace-before-property 'no-whitespace-before-property': 'error', // require padding inside curly braces 'object-curly-spacing': ['error', 'always'], // allow just one var statement per function 'one-var': ['error', 'never'], // require a newline around variable declaration // http://eslint.org/docs/rules/one-var-declaration-per-line 'one-var-declaration-per-line': ['error', 'always'], // enforce padding within blocks 'padded-blocks': ['error', 'never'], // disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead. 'prefer-object-spread': 'error', // require quotes around object literal property names // http://eslint.org/docs/rules/quote-props.html 'quote-props': ['error', 'as-needed', { keywords: false, unnecessary: true, numbers: false }], // enforce spacing before and after semicolons 'semi-spacing': ['error', { before: false, after: true }], // require or disallow space before blocks 'space-before-blocks': 'error', // require or disallow space before function opening parenthesis // https://github.com/eslint/eslint/blob/master/docs/rules/space-before-function-paren.md 'space-before-function-paren': ['error', { anonymous: 'never', named: 'never' }], // require or disallow spaces inside parentheses 'space-in-parens': ['error', 'never'], // require spaces around operators 'space-infix-ops': 'error', // require or disallow a space immediately following the // or /* in a comment 'spaced-comment': ['error', 'always', { exceptions: ['-', '+'], markers: ['=', '!', '/'], // space here to support sprockets directives }], 'import/no-default-export': 'error', 'unicorn/empty-brace-spaces': ['error'], 'unicorn/filename-case': ['error', { case: 'kebabCase' }], 'unicorn/no-array-push-push': ['error'], 'unicorn/prefer-date-now': ['error'], }, }; timocov-dts-bundle-generator-c69ff0d/.gitattributes000066400000000000000000000000411461132021400226000ustar00rootroot00000000000000*.ts linguist-language=TypeScripttimocov-dts-bundle-generator-c69ff0d/.github/000077500000000000000000000000001461132021400212525ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/.github/FUNDING.yml000066400000000000000000000003471461132021400230730ustar00rootroot00000000000000github: timocov # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] patreon: # Replace with a single Patreon username open_collective: dts-bundle-generator # Replace with a single Open Collective username timocov-dts-bundle-generator-c69ff0d/.github/ISSUE_TEMPLATE/000077500000000000000000000000001461132021400234355ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/.github/ISSUE_TEMPLATE/bug_report.md000066400000000000000000000005151461132021400261300ustar00rootroot00000000000000--- name: Bug report about: Create a report to help us improve --- **Bug report** **Input code** ```ts // place your code here ``` **Expected output** ```ts // place your code here ``` **Actual output** ```ts // place your code here ``` **Additional context** Add any other context about the problem here (CLI options, etc) timocov-dts-bundle-generator-c69ff0d/.github/ISSUE_TEMPLATE/other.md000066400000000000000000000001011461132021400250700ustar00rootroot00000000000000--- name: Other about: Any other issues/improves/features --- timocov-dts-bundle-generator-c69ff0d/.github/logo.svg000066400000000000000000000127131461132021400227370ustar00rootroot00000000000000 .d.ts foo.ts bar.ts baz.ts main.ts timocov-dts-bundle-generator-c69ff0d/.github/workflows/000077500000000000000000000000001461132021400233075ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/.github/workflows/ci.yml000066400000000000000000000023131461132021400244240ustar00rootroot00000000000000name: CI Test on: push: branches: - master schedule: # https://crontab.guru/#0_10_*_*_0 - cron: '0 10 * * 0' pull_request: jobs: lint: name: Lint files runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 16 - run: npm install - run: npm run lint ts-min: name: Minimal TS runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 14 - run: npm install - run: npm install typescript@5.0.2 - run: npm run tsc ts-current: name: Current TS runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 14 - run: npm install - run: npm run tsc - run: npm run test - run: npm run bundle-dts ts-next: name: The next TS runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 14 - run: npm install - run: npm install typescript@next - run: npm run tsc - run: npm run test - run: npm run bundle-dts timocov-dts-bundle-generator-c69ff0d/.github/workflows/release.yml000066400000000000000000000006621461132021400254560ustar00rootroot00000000000000name: Publish new version on: push: tags: - v* jobs: publish: name: Publish runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 14 registry-url: 'https://registry.npmjs.org' - run: npm install - run: npm run prepare-release - run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}} timocov-dts-bundle-generator-c69ff0d/.gitignore000066400000000000000000000001511461132021400216770ustar00rootroot00000000000000/dist/ /dts-out/ node_modules/ package-lock.json package-lock.json.* *.tsbuildinfo config-schema.d.ts timocov-dts-bundle-generator-c69ff0d/.mailmap000066400000000000000000000000451461132021400213320ustar00rootroot00000000000000Evgeniy Timokhov timocov-dts-bundle-generator-c69ff0d/.mocharc.js000066400000000000000000000006771461132021400217540ustar00rootroot00000000000000const path = require('path'); // override tsconfig for tests process.env.TS_NODE_PROJECT = path.resolve(__dirname, './tsconfig.options.json'); // just transpile in tests process.env.TS_NODE_TRANSPILE_ONLY = 'true'; const config = { require: [ 'ts-node/register', ], extension: ['.spec.ts', '.spec.js'], ignore: '**/.tsc-out/**', checkLeaks: true, recursive: true, diff: true, timeout: 10000, slow: 5000, }; module.exports = config; timocov-dts-bundle-generator-c69ff0d/.npmrc000066400000000000000000000000231461132021400210250ustar00rootroot00000000000000package-lock=false timocov-dts-bundle-generator-c69ff0d/.vscode/000077500000000000000000000000001461132021400212535ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/.vscode/launch.json000066400000000000000000000014301461132021400234160ustar00rootroot00000000000000{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Run e2e test", "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", "args": [ "tests/e2e/test-cases/${input:testCaseName}/index.spec.js" ], "internalConsoleOptions": "openOnSessionStart" }, { "type": "node", "request": "attach", "name": "Attach debugger", "skipFiles": [ "/**" ] }, ], "inputs": [ { "type": "promptString", "id": "testCaseName", "description": "Please enter a test case name (a folder name)" } ] } timocov-dts-bundle-generator-c69ff0d/.vscode/settings.json000066400000000000000000000004521461132021400240070ustar00rootroot00000000000000{ "files.exclude": { "**/*.tsbuildinfo": true, "config-schema.d.ts": true, "dist/**": true, "dts-out/**": true, "tests/e2e/.tsc-out/**": true, "tests/unittests/.tsc-out/**": true, }, "typescript.tsdk": "./node_modules/ts-compiler/lib", } timocov-dts-bundle-generator-c69ff0d/LICENSE000066400000000000000000000020611461132021400207160ustar00rootroot00000000000000MIT License Copyright (c) 2017 Evgeniy Timokhov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. timocov-dts-bundle-generator-c69ff0d/README.md000066400000000000000000000163621461132021400212010ustar00rootroot00000000000000
# DTS Bundle Generator [![GH Actions][ci-img]][ci-link] [![npm version][npm-version-img]][npm-link] [![Downloads][npm-downloads-img]][npm-link] Small tool to generate a dts bundle from your ts code. For example: ```ts // a.ts export class A {} ``` ```ts // b.ts export class B {} ``` ```ts // entry.ts import { A } from './a'; import { B } from './b'; declare function makeA(): A; export function makeB(): B { makeA(); return new B(); } ``` When you run `dts-bundle-generator -o my.d.ts entry.ts` in `my.d.ts` you will get the following: ```ts declare class B { } export declare function makeB(): B; ``` ## Installation 1. Install the package from `npm`: ```bash npm install --save-dev dts-bundle-generator ``` or ```bash npm install -g dts-bundle-generator ``` 1. Enable `declaration` compiler option in `tsconfig.json` ## Usage ``` Usage: dts-bundle-generator [options] Options: --help Show help [boolean] --out-file, -o File name of generated d.ts [string] --verbose Enable verbose logging [boolean] [default: false] --silent Disable any logging except errors [boolean] [default: false] --no-check Skip validation of generated d.ts file [boolean] [default: false] --fail-on-class Fail if generated dts contains class declaration [boolean] [default: false] --external-inlines Array of package names from node_modules to inline typings from. Used types will be inlined into the output file [array] --external-imports Array of package names from node_modules to import typings from. Used types will be imported using "import { First, Second } from 'library-name';". By default all libraries will be imported (except inlined libraries and libraries from @types) [array] --external-types Array of package names from @types to import typings from via the triple-slash reference directive. By default all packages are allowed and will be used according to their usages [array] --umd-module-name Name of the UMD module. If specified then `export as namespace ModuleName;` will be emitted [string] --project Path to the tsconfig.json file that will be used for the compilation [string] --sort Sort output nodes [boolean] [default: false] --inline-declare-global Enables inlining of `declare global` statements contained in files which should be inlined (all local files and packages from `--external-inlines`) [boolean] [default: false] --inline-declare-externals Enables inlining of `declare module` statements of the global modules (e.g. `declare module 'external-module' {}`, but NOT `declare module './internal-module' {}`) contained in files which should be inlined (all local files and packages from inlined libraries) [boolean] [default: false] --disable-symlinks-following (EXPERIMENTAL) Disables resolving of symlinks to the original path. See https://github.com/timocov/dts-bundle-generator/issues/39 for more information [boolean] [default: false] --respect-preserve-const-enum Enables stripping the `const` keyword from every direct-exported (or re-exported) from entry file `const enum`. See https://github.com/timocov/dts-bundle-generator/issues/110 for more information [boolean] [default: false] --export-referenced-types By default all interfaces, types and const enums are marked as exported even if they aren't exported directly. This option allows you to disable this behavior so a node will be exported if it is exported from root source file only. [boolean] [default: true] --config File path to the generator config file [string] --no-banner Allows remove "Generated by dts-bundle-generator" comment from the output [boolean] [default: false] --version Show version number [boolean] ``` Examples: ```bash ./node_modules/.bin/dts-bundle-generator -o my.d.ts path/to/your/entry-file.ts ``` ```bash ./node_modules/.bin/dts-bundle-generator path/to/your/entry-file.ts path/to/your/entry-file-2.ts ``` ```bash ./node_modules/.bin/dts-bundle-generator --external-inlines=@mycompany/internal-project --external-imports=@angular/core rxjs path/to/your/entry-file.ts ``` ```bash ./node_modules/.bin/dts-bundle-generator --external-types=jquery path/to/your/entry-file.ts ``` ## Config file It is unnecessary, but you can use config file for the tool. See [config documentation](src/config-file/README.md) for more information. ## Why If you have modules then you can create definitions by default using `tsc`, but `tsc` generates them for each module separately. Yeah, you can use `outFile` (for `amd` and `system`), but generated code looks like this: ```ts declare module "a" { export class A { } } declare module "b" { export class B { } } declare module "entry" { import { B } from "b"; export function makeB(): B; } ``` but: 1. `A` is not used at all and most probably you do not want to export it. 1. If you bundle your code in a way when all modules are merged (like when using Webpack or Rollup) then there should be no such modules as `a` or `b` (actually `entry` too) in the resulting file. [ci-img]: https://github.com/timocov/dts-bundle-generator/workflows/CI%20Test/badge.svg?branch=master [ci-link]: https://github.com/timocov/dts-bundle-generator/actions?query=branch%3Amaster [npm-version-img]: https://badge.fury.io/js/dts-bundle-generator.svg [npm-downloads-img]: https://img.shields.io/npm/dm/dts-bundle-generator.svg [npm-link]: https://www.npmjs.com/package/dts-bundle-generator timocov-dts-bundle-generator-c69ff0d/dts-config.js000066400000000000000000000006571461132021400223150ustar00rootroot00000000000000// @ts-check /** @type import('./src/config-file/load-config-file').BundlerConfig */ const config = { compilationOptions: { preferredConfigPath: './tsconfig.options.json', }, entries: [ { filePath: './dts-out/bundle-generator.d.ts', outFile: './dist/bundle-generator.d.ts', }, { filePath: './dts-out/config-file/load-config-file.d.ts', outFile: './config-schema.d.ts', }, ], }; module.exports = config; timocov-dts-bundle-generator-c69ff0d/package.json000066400000000000000000000036441461132021400222070ustar00rootroot00000000000000{ "private": true, "name": "dts-bundle-generator", "version": "9.5.1", "description": "DTS Bundle Generator", "main": "dist/bundle-generator.js", "typings": "dist/bundle-generator.d.ts", "bin": "dist/bin/dts-bundle-generator.js", "files": [ "config-schema.d.ts", "dist/**/*.d.ts", "dist/**/*.js" ], "author": "Evgeniy Timokhov", "bugs": { "url": "https://github.com/timocov/dts-bundle-generator/issues" }, "homepage": "https://github.com/timocov/dts-bundle-generator", "dependencies": { "typescript": ">=5.0.2", "yargs": "^17.6.0" }, "devDependencies": { "@types/mocha": "~10.0.0", "@types/node": "~14.18.26", "@types/yargs": "~17.0.13", "@typescript-eslint/eslint-plugin": "~7.4.0", "@typescript-eslint/parser": "~7.4.0", "eslint": "~8.57.0", "eslint-plugin-deprecation": "~2.0.0", "eslint-plugin-import": "~2.29.0", "eslint-plugin-unicorn": "~51.0.1", "mocha": "~10.4.0", "npm-run-all": "~4.1.5", "rimraf": "~5.0.1", "ts-compiler": "npm:typescript@5.4.3", "ts-node": "~10.9.1" }, "license": "MIT", "readme": "README.md", "repository": { "type": "git", "url": "git+https://github.com/timocov/dts-bundle-generator.git" }, "engines": { "node": ">=14.0.0" }, "scripts": { "clean": "rimraf dist/ dts-out/", "lint": "eslint --format=unix ./", "check-dts-config": "node ./node_modules/ts-compiler/bin/tsc -p tsconfig.dts-config.json", "bundle-dts": "npm run check-dts-config && node ./dist/bin/dts-bundle-generator.js --config dts-config.js --silent", "tsc": "node ./node_modules/ts-compiler/bin/tsc --version && node ./node_modules/ts-compiler/bin/tsc -b ./tsconfig.json", "verify": "npm-run-all clean tsc -p bundle-dts lint -s test", "prepare-release": "npm-run-all clean tsc bundle-dts && node scripts/clean-package-json.js", "test": "mocha --recursive -p --reporter list tests/" } } timocov-dts-bundle-generator-c69ff0d/scripts/000077500000000000000000000000001461132021400214015ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/scripts/clean-package-json.js000077500000000000000000000012561461132021400253700ustar00rootroot00000000000000#!/usr/bin/env node /** * This script does something like https://github.com/shashkovdanil/clean-publish does * but it seems that clean-publish isn't supported anymore and we can't use it in CI */ const path = require('path'); const fs = require('fs'); function main() { const packageJsonPath = path.resolve(__dirname, '..', 'package.json'); const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf-8' })); delete packageJson.private; delete packageJson.devDependencies; delete packageJson.scripts; fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', { encoding: 'utf-8' }); } if (require.main === module) { main(); } timocov-dts-bundle-generator-c69ff0d/src/000077500000000000000000000000001461132021400205015ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/src/bin/000077500000000000000000000000001461132021400212515ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/src/bin/dts-bundle-generator.ts000066400000000000000000000226471461132021400256610ustar00rootroot00000000000000#!/usr/bin/env node import * as path from 'path'; import * as ts from 'typescript'; import * as yargs from 'yargs'; import { loadConfigFile, BundlerConfig, ConfigEntryPoint } from '../config-file/load-config-file'; import { generateDtsBundle } from '../bundle-generator'; import { checkProgramDiagnosticsErrors } from '../helpers/check-diagnostics-errors'; import { getCompilerOptions } from '../get-compiler-options'; import { fixPath } from '../helpers/fix-path'; import { measureTime } from '../helpers/measure-time'; import { enableNormalLog, enableVerbose, errorLog, normalLog, verboseLog, warnLog, } from '../logger'; function toStringsArray(data: unknown): string[] | undefined { if (data === undefined) { return data; } if (!Array.isArray(data)) { throw new Error(`${data} is not a array`); } return data.map(String); } /* eslint-disable @typescript-eslint/naming-convention */ interface ParsedArgs extends yargs.Arguments { sort: boolean; silent: boolean; verbose: boolean; 'no-check': boolean; 'fail-on-class': boolean; 'inline-declare-global': boolean; 'inline-declare-externals': boolean; 'disable-symlinks-following': boolean; 'no-banner': boolean; 'respect-preserve-const-enum': boolean; 'export-referenced-types': boolean; 'out-file': string | undefined; 'umd-module-name': string | undefined; project: string | undefined; config: string | undefined; 'external-inlines': string[] | undefined; 'external-imports': string[] | undefined; 'external-types': string[] | undefined; } /* eslint-enable @typescript-eslint/naming-convention */ function parseArgs(): ParsedArgs { return yargs .parserConfiguration({ /* eslint-disable @typescript-eslint/naming-convention */ 'boolean-negation': false, 'camel-case-expansion': false, 'dot-notation': false, 'short-option-groups': false, /* eslint-enable @typescript-eslint/naming-convention */ }) .usage('Usage: $0 [options] ') .demandCommand(0) .option('out-file', { alias: 'o', type: 'string', description: 'File name of generated d.ts', }) .option('verbose', { type: 'boolean', default: false, description: 'Enable verbose logging', }) .option('silent', { type: 'boolean', default: false, description: 'Disable any logging except errors', }) .option('no-check', { type: 'boolean', default: false, description: 'Skip validation of generated d.ts file', }) .option('fail-on-class', { type: 'boolean', default: false, description: 'Fail if generated dts contains class declaration', }) .option('external-inlines', { type: 'array', description: 'Array of package names from node_modules to inline typings from.\n' + 'Used types will be inlined into the output file', coerce: toStringsArray, }) .option('external-imports', { type: 'array', description: 'Array of package names from node_modules to import typings from.\n' + 'Used types will be imported using "import { First, Second } from \'library-name\';".\n' + 'By default all libraries will be imported (except inlined libraries and libraries from @types)', coerce: toStringsArray, }) .option('external-types', { type: 'array', description: 'Array of package names from @types to import typings from via the triple-slash reference directive.\n' + 'By default all packages are allowed and will be used according to their usages', coerce: toStringsArray, }) .option('umd-module-name', { type: 'string', description: 'Name of the UMD module. If specified then `export as namespace ModuleName;` will be emitted', }) .option('project', { type: 'string', description: 'Path to the tsconfig.json file that will be used for the compilation', }) .option('sort', { type: 'boolean', default: false, description: 'Sort output nodes', }) .option('inline-declare-global', { type: 'boolean', default: false, description: 'Enables inlining of `declare global` statements contained in files which should be inlined (all local files and packages from `--external-inlines`)', }) .option('inline-declare-externals', { type: 'boolean', default: false, description: 'Enables inlining of `declare module` statements of the global modules (e.g. `declare module \'external-module\' {}`, but NOT `declare module \'./internal-module\' {}`) contained in files which should be inlined (all local files and packages from inlined libraries)', }) .option('disable-symlinks-following', { type: 'boolean', default: false, description: '(EXPERIMENTAL) Disables resolving of symlinks to the original path. See https://github.com/timocov/dts-bundle-generator/issues/39 for more information', }) .option('respect-preserve-const-enum', { type: 'boolean', default: false, description: 'Enables stripping the `const` keyword from every direct-exported (or re-exported) from entry file `const enum`. See https://github.com/timocov/dts-bundle-generator/issues/110 for more information', }) .option('export-referenced-types', { type: 'boolean', default: true, description: 'By default all interfaces, types and const enums are marked as exported even if they aren\'t exported directly. This option allows you to disable this behavior so a node will be exported if it is exported from root source file only.', }) .option('config', { type: 'string', description: 'File path to the generator config file', }) .option('no-banner', { type: 'boolean', default: false, description: 'Allows remove "Generated by dts-bundle-generator" comment from the output', }) .version() .strict() .example('$0 path/to/your/entry-file.ts', '') .example('$0 path/to/your/entry-file.ts path/to/your/entry-file-2.ts', '') .example('$0 --external-types jquery react -- entry-file.ts', '') .wrap(Math.min(100, yargs.terminalWidth())) .argv as ParsedArgs; } function generateOutFileName(inputFilePath: string): string { const inputFileName = path.parse(inputFilePath).name; return fixPath(path.join(inputFilePath, '..', inputFileName + '.d.ts')); } // eslint-disable-next-line complexity function main(): void { const args = parseArgs(); if (args.silent && args.verbose) { throw new Error('Cannot use both silent and verbose options at the same time'); } else if (args.verbose) { enableVerbose(); } else if (!args.silent) { enableNormalLog(); } let bundlerConfig: BundlerConfig; if (args.config !== undefined) { verboseLog(`Trying to load config from ${args.config} file...`); bundlerConfig = loadConfigFile(args.config); } else { if (args._.length < 1) { throw new Error('No input files specified'); } if (args._.length > 1 && args['out-file']) { throw new Error('Cannot use outFile with multiple entries'); } bundlerConfig = { entries: args._.map((entryPath: string | number) => { return { filePath: String(entryPath), outFile: args['out-file'], noCheck: args['no-check'], libraries: { allowedTypesLibraries: args['external-types'], importedLibraries: args['external-imports'], inlinedLibraries: args['external-inlines'], }, output: { inlineDeclareExternals: args['inline-declare-externals'], inlineDeclareGlobals: args['inline-declare-global'], umdModuleName: args['umd-module-name'], sortNodes: args.sort, noBanner: args['no-banner'], respectPreserveConstEnum: args['respect-preserve-const-enum'], exportReferencedTypes: args['export-referenced-types'], }, failOnClass: args['fail-on-class'], }; }), compilationOptions: { preferredConfigPath: args.project, followSymlinks: !args['disable-symlinks-following'], }, }; } verboseLog(`Total entries count=${bundlerConfig.entries.length}`); const generatedDts = generateDtsBundle(bundlerConfig.entries, bundlerConfig.compilationOptions); const outFilesToCheck: string[] = []; for (let i = 0; i < bundlerConfig.entries.length; ++i) { const entry = bundlerConfig.entries[i]; const outFile = entry.outFile !== undefined ? entry.outFile : generateOutFileName(entry.filePath); normalLog(`Writing ${entry.filePath} -> ${outFile}`); ts.sys.writeFile(outFile, generatedDts[i]); if (!entry.noCheck) { outFilesToCheck.push(outFile); } } if (outFilesToCheck.length === 0) { normalLog('File checking is skipped (due nothing to check)'); return; } normalLog('Checking generated files...'); const preferredConfigFile = bundlerConfig.compilationOptions !== undefined ? bundlerConfig.compilationOptions.preferredConfigPath : undefined; const compilerOptions = getCompilerOptions(outFilesToCheck, preferredConfigFile); if (compilerOptions.skipLibCheck) { compilerOptions.skipLibCheck = false; warnLog('Compiler option "skipLibCheck" is disabled to properly check generated output'); } // we want to turn this option on because in this case the compile will generate declaration diagnostics out of the box compilerOptions.declaration = true; let checkFailed = false; for (const outputFile of outFilesToCheck) { const program = ts.createProgram([outputFile], compilerOptions); try { checkProgramDiagnosticsErrors(program); } catch (e) { checkFailed = true; } } if (checkFailed) { throw new Error('Failed to check some of generated bundles, check error messages above'); } } try { const executionTime = measureTime(main); normalLog(`Done in ${(executionTime / 1000).toFixed(2)}s`); } catch (ex) { normalLog(''); errorLog(`Error: ${(ex as Error).message}`); process.exit(1); } timocov-dts-bundle-generator-c69ff0d/src/bundle-generator.ts000066400000000000000000001550051461132021400243140ustar00rootroot00000000000000import * as ts from 'typescript'; import { compileDts } from './compile-dts'; import { TypesUsageEvaluator } from './types-usage-evaluator'; import { ExportType, getActualSymbol, getClosestModuleLikeNode, getClosestSourceFileLikeNode, getDeclarationsForExportedValues, getDeclarationsForSymbol, getImportExportReferencedSymbol, getExportsForSourceFile, getExportsForStatement, getImportModuleName, getNodeName, getNodeOwnSymbol, getNodeSymbol, getRootSourceFile, getSymbolExportStarDeclarations, hasNodeModifier, isAmbientModule, isDeclareGlobalStatement, isDeclareModule, isNodeNamedDeclaration, SourceFileExport, splitTransientSymbol, } from './helpers/typescript'; import { getFileModuleInfo, getModuleLikeModuleInfo, getReferencedModuleInfo, ModuleCriteria, ModuleInfo, ModuleType, } from './module-info'; import { generateOutput, ModuleImportsSet, OutputInputData, StatementSettings } from './generate-output'; import { normalLog, verboseLog, warnLog, } from './logger'; import { CollisionsResolver } from './collisions-resolver'; export interface CompilationOptions { /** * EXPERIMENTAL! * Allows disable resolving of symlinks to the original path. * By default following is enabled. * @see https://github.com/timocov/dts-bundle-generator/issues/39 */ followSymlinks?: boolean; /** * Path to the tsconfig file that will be used for the compilation. */ preferredConfigPath?: string; } export interface OutputOptions { /** * Sort output nodes in ascendant order. */ sortNodes?: boolean; /** * Name of the UMD module. * If specified then `export as namespace ModuleName;` will be emitted. */ umdModuleName?: string; /** * Enables inlining of `declare global` statements contained in files which should be inlined (all local files and packages from inlined libraries). */ inlineDeclareGlobals?: boolean; /** * Enables inlining of `declare module` statements of the global modules * (e.g. `declare module 'external-module' {}`, but NOT `declare module './internal-module' {}`) * contained in files which should be inlined (all local files and packages from inlined libraries) */ inlineDeclareExternals?: boolean; /** * Allows remove "Generated by dts-bundle-generator" comment from the output */ noBanner?: boolean; /** * Enables stripping the `const` keyword from every direct-exported (or re-exported) from entry file `const enum`. * This allows you "avoid" the issue described in https://github.com/microsoft/TypeScript/issues/37774. */ respectPreserveConstEnum?: boolean; /** * By default all interfaces, types and const enums are marked as exported even if they aren't exported directly. * This option allows you to disable this behavior so a node will be exported if it is exported from root source file only. */ exportReferencedTypes?: boolean; } export interface LibrariesOptions { /** * Array of package names from node_modules to inline typings from. * Used types will be inlined into the output file. */ inlinedLibraries?: string[]; /** * Array of package names from node_modules to import typings from. * Used types will be imported using `import { First, Second } from 'library-name';`. * By default all libraries will be imported (except inlined libraries and libraries from @types). */ importedLibraries?: string[]; /** * Array of package names from @types to import typings from via the triple-slash reference directive. * By default all packages are allowed and will be used according to their usages. */ allowedTypesLibraries?: string[]; } export interface EntryPointConfig { /** * Path to input file. */ filePath: string; libraries?: LibrariesOptions; /** * Fail if generated dts contains class declaration. */ failOnClass?: boolean; output?: OutputOptions; } export function generateDtsBundle(entries: readonly EntryPointConfig[], options: CompilationOptions = {}): string[] { normalLog('Compiling input files...'); const { program, rootFilesRemapping } = compileDts(entries.map((entry: EntryPointConfig) => entry.filePath), options.preferredConfigPath, options.followSymlinks); const typeChecker = program.getTypeChecker(); const typeRoots = ts.getEffectiveTypeRoots(program.getCompilerOptions(), {}); const sourceFiles = program.getSourceFiles().filter((file: ts.SourceFile) => { return !program.isSourceFileDefaultLibrary(file); }); const typesUsageEvaluator = new TypesUsageEvaluator(sourceFiles, typeChecker); // eslint-disable-next-line complexity return entries.map((entryConfig: EntryPointConfig) => { normalLog(`Processing ${entryConfig.filePath}`); const newRootFilePath = rootFilesRemapping.get(entryConfig.filePath); if (newRootFilePath === undefined) { throw new Error(`Cannot remap root source file ${entryConfig.filePath}`); } const rootSourceFile = getRootSourceFile(program, newRootFilePath); const rootSourceFileSymbol = typeChecker.getSymbolAtLocation(rootSourceFile); if (rootSourceFileSymbol === undefined) { throw new Error(`Symbol for root source file ${newRootFilePath} not found`); } const librariesOptions: LibrariesOptions = entryConfig.libraries || {}; const criteria: ModuleCriteria = { allowedTypesLibraries: librariesOptions.allowedTypesLibraries, importedLibraries: librariesOptions.importedLibraries, inlinedLibraries: librariesOptions.inlinedLibraries || [], typeRoots, }; const rootFileExports = getExportsForSourceFile(typeChecker, rootSourceFileSymbol); const rootFileExportSymbols = rootFileExports.map((exp: SourceFileExport) => exp.symbol); interface CollectingResult extends Omit { statements: ts.Statement[]; } const collectionResult: CollectingResult = { typesReferences: new Set(), imports: new Map(), statements: [], renamedExports: new Map(), wrappedNamespaces: new Map(), }; const outputOptions: OutputOptions = entryConfig.output || {}; const inlineDeclareGlobals = Boolean(outputOptions.inlineDeclareGlobals); const inlineDeclareExternals = Boolean(outputOptions.inlineDeclareExternals); const collisionsResolver = new CollisionsResolver(typeChecker); function updateResultForAnyModule(statements: readonly ts.Statement[], currentModule: ModuleInfo): void { // contains a set of modules that were visited already // can be used to prevent infinite recursion in updating results in re-exports const visitedModules = new Set(); function updateResultForExternalExport(exportAssignment: ts.ExportAssignment | ts.ExportDeclaration): void { // if we have `export =` or `export * from` somewhere so we can decide that every declaration of exported symbol in this way // is "part of the exported module" and we need to update result according every member of each declaration // but treat they as current module (we do not need to update module info) for (const declaration of getDeclarationsForExportedValues(exportAssignment, typeChecker)) { if (ts.isVariableDeclaration(declaration)) { // variables will be processed separately anyway so no need to process them again here continue; } let exportedDeclarations: readonly ts.Statement[] = []; if (ts.isExportDeclaration(exportAssignment) && ts.isSourceFile(declaration)) { const referencedModule = getReferencedModuleInfo(exportAssignment, criteria, typeChecker); if (referencedModule !== null) { if (visitedModules.has(referencedModule.fileName)) { continue; } visitedModules.add(referencedModule.fileName); } exportedDeclarations = declaration.statements; } else if (ts.isModuleDeclaration(declaration)) { if (declaration.body !== undefined && ts.isModuleBlock(declaration.body)) { const referencedModule = getReferencedModuleInfo(declaration, criteria, typeChecker); if (referencedModule !== null) { if (visitedModules.has(referencedModule.fileName)) { continue; } visitedModules.add(referencedModule.fileName); } exportedDeclarations = declaration.body.statements; } } else { exportedDeclarations = [declaration as unknown as ts.Statement]; } updateResultImpl(exportedDeclarations); } } // eslint-disable-next-line complexity function updateResultImpl(statementsToProcess: readonly ts.Statement[]): void { for (const statement of statementsToProcess) { // we should skip import statements if (statement.kind === ts.SyntaxKind.ImportDeclaration || statement.kind === ts.SyntaxKind.ImportEqualsDeclaration) { continue; } if (isDeclareModule(statement)) { updateResultForModuleDeclaration(statement, currentModule); // if a statement is `declare module "module" {}` then don't process it below // as it is handled already in `updateResultForModuleDeclaration` // but if it is `declare module Module {}` then it can be used in types and imports // so in this case it needs to be checked for "usages" below if (ts.isStringLiteral(statement.name)) { continue; } } if (currentModule.type === ModuleType.ShouldBeUsedForModulesOnly) { continue; } if (isDeclareGlobalStatement(statement) && inlineDeclareGlobals && currentModule.type === ModuleType.ShouldBeInlined) { collectionResult.statements.push(statement); continue; } if (ts.isExportDeclaration(statement)) { if (currentModule.type === ModuleType.ShouldBeInlined) { continue; } // `export * from` if (statement.exportClause === undefined) { updateResultForExternalExport(statement); continue; } // `export { val }` if (ts.isNamedExports(statement.exportClause) && currentModule.type === ModuleType.ShouldBeImported) { updateImportsForStatement(statement); continue; } } if (ts.isExportAssignment(statement) && statement.isExportEquals && currentModule.type !== ModuleType.ShouldBeInlined) { updateResultForExternalExport(statement); continue; } if (!isNodeUsed(statement)) { continue; } switch (currentModule.type) { case ModuleType.ShouldBeReferencedAsTypes: // while a node might be "used" somewhere via transitive nodes // we need to add types reference only if a node is treated as "should be imported" // because otherwise we might have lots of false-positive references forEachNodeThatShouldBeImported(statement, () => addTypesReference(currentModule.typesLibraryName)); break; case ModuleType.ShouldBeImported: updateImportsForStatement(statement); break; case ModuleType.ShouldBeInlined: if (ts.isVariableStatement(statement)) { for (const variableDeclaration of statement.declarationList.declarations) { if (ts.isIdentifier(variableDeclaration.name)) { collisionsResolver.addTopLevelIdentifier(variableDeclaration.name); continue; } for (const element of variableDeclaration.name.elements) { if (!ts.isOmittedExpression(element) && ts.isIdentifier(element.name)) { collisionsResolver.addTopLevelIdentifier(element.name); } } } } else if (isNodeNamedDeclaration(statement)) { const statementName = getNodeName(statement); if (statementName !== undefined) { collisionsResolver.addTopLevelIdentifier(statementName as ts.Identifier | ts.DefaultKeyword); } } collectionResult.statements.push(statement); break; } } } updateResultImpl(statements); } function isReferencedModuleImportable(statement: ts.ExportDeclaration | ts.ImportDeclaration): boolean { return getReferencedModuleInfo(statement, criteria, typeChecker)?.type === ModuleType.ShouldBeImported; } function handleExportDeclarationFromRootModule(exportDeclaration: ts.ExportDeclaration): void { function handleExportStarStatement(exportStarStatement: ts.ExportDeclaration, visitedSymbols: Set = new Set()): void { if (exportStarStatement.moduleSpecifier === undefined || exportStarStatement.exportClause !== undefined) { throw new Error(`Invalid export-star declaration statement provided, ${exportStarStatement.getText()}`); } const importModuleSpecifier = getImportModuleName(exportStarStatement); if (importModuleSpecifier === null) { return; } const referencedModuleInfo = getReferencedModuleInfo(exportStarStatement, criteria, typeChecker); if (referencedModuleInfo === null) { return; } switch (referencedModuleInfo.type) { case ModuleType.ShouldBeInlined: { // `export * from './inlined-module'` const referencedModuleSymbol = getNodeOwnSymbol(exportStarStatement.moduleSpecifier, typeChecker); const referencedSourceFileExportStarSymbol = referencedModuleSymbol.exports?.get(ts.InternalSymbolName.ExportStar); if (referencedSourceFileExportStarSymbol !== undefined) { if (visitedSymbols.has(referencedSourceFileExportStarSymbol)) { return; } visitedSymbols.add(referencedSourceFileExportStarSymbol); // we need to go recursive for all `export * from` statements and add all that are from imported modules for (const exportDecl of getSymbolExportStarDeclarations(referencedSourceFileExportStarSymbol)) { handleExportStarStatement(exportDecl, visitedSymbols); } } break; } case ModuleType.ShouldBeImported: { // `export * from 'importable-package'` collectionResult.statements.push(exportStarStatement); break; } } } interface ExportingExportStarExport { exportStarDeclaration: ts.ExportDeclaration; exportedNodeSymbol: ts.Symbol; } /** * This function returns an export-star object that exports given {@link nodeSymbol} symbol. * If an exporting export declaration object is not from an importable module then `null` is returned. * Also if the symbol is exported explicitly (i.e. via `export { Name }` or specifying `export` keyword next to the node) then `null` is returned as well. */ function findExportingExportStarExportFromImportableModule(referencedModuleSymbol: ts.Symbol, nodeSymbol: ts.Symbol): ExportingExportStarExport | null { function findResultRecursively(referencedModuleSym: ts.Symbol, exportedNodeSym: ts.Symbol, visitedSymbols: Set): ExportingExportStarExport | null { // prevent infinite recursion if (visitedSymbols.has(referencedModuleSym)) { return null; } visitedSymbols.add(referencedModuleSym); // `export * from` exports always have less priority over explicit exports so it should go last const exportStarExport = referencedModuleSym.exports?.get(ts.InternalSymbolName.ExportStar); if (exportStarExport === undefined) { return null; } for (const exportStarDeclaration of getDeclarationsForSymbol(exportStarExport).filter(ts.isExportDeclaration)) { if (exportStarDeclaration.moduleSpecifier === undefined) { // this seems impossible, but to make the compiler/types happy continue; } const exportStarModuleSymbol = getNodeOwnSymbol(exportStarDeclaration.moduleSpecifier, typeChecker); if (exportStarModuleSymbol.exports === undefined) { continue; } if (isReferencedModuleImportable(exportStarDeclaration)) { // for "importable" modules we don't need to go deeper or even check "explicit" exports // as it doesn't matter how its done internally and we care about "public" interface only // so we can just check whether it exports a symbol or not (irregardless of how it is exported exactly internally) const referencedModuleExports = typeChecker.getExportsOfModule(exportStarModuleSymbol); const exportedNodeSymbol = referencedModuleExports.find((exp: ts.Symbol) => getActualSymbol(exp, typeChecker) === nodeSymbol); if (exportedNodeSymbol !== undefined) { return { exportStarDeclaration, exportedNodeSymbol }; } continue; } const result = findResultRecursively(exportStarModuleSymbol, exportedNodeSym, visitedSymbols); if (result !== null) { return result; } } return null; } if (referencedModuleSymbol.exports === undefined) { throw new Error(`No exports found for "${referencedModuleSymbol.getName()}" symbol`); } const hasExplicitExportOfSymbol = Array.from(referencedModuleSymbol.exports.values()).some((exp: ts.Symbol) => { if (exp.escapedName === ts.InternalSymbolName.ExportStar) { return false; } return getActualSymbol(exp, typeChecker) === nodeSymbol; }); if (hasExplicitExportOfSymbol) { // symbol is exported explicitly ¯\_(ツ)_/¯ return null; } return findResultRecursively(referencedModuleSymbol, nodeSymbol, new Set()); } // `export * from 'module'` if (exportDeclaration.exportClause === undefined) { handleExportStarStatement(exportDeclaration); return; } if (exportDeclaration.exportClause !== undefined && ts.isNamedExports(exportDeclaration.exportClause)) { // `export { val, val2 }` if (exportDeclaration.moduleSpecifier === undefined) { for (const exportElement of exportDeclaration.exportClause.elements) { const exportElementSymbol = getImportExportReferencedSymbol(exportElement, typeChecker); const namespaceImportFromImportableModule = getDeclarationsForSymbol(exportElementSymbol).find((importDecl: ts.Declaration): importDecl is ts.NamespaceImport => { // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion return ts.isNamespaceImport(importDecl) && isReferencedModuleImportable(importDecl.parent.parent as ts.ImportDeclaration); }); if (namespaceImportFromImportableModule !== undefined) { // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion const importModuleSpecifier = getImportModuleName(namespaceImportFromImportableModule.parent.parent as ts.ImportDeclaration); if (importModuleSpecifier === null) { throw new Error(`Cannot get import module name from '${namespaceImportFromImportableModule.parent.parent.getText()}'`); } addNsImport( getImportItem(importModuleSpecifier), namespaceImportFromImportableModule.name ); } } return; } // `export { val, val2 } from 'module'` if (exportDeclaration.moduleSpecifier !== undefined) { const referencedModuleSymbol = getNodeOwnSymbol(exportDeclaration.moduleSpecifier, typeChecker); // in this case we want to find all elements that we re-exported via `export * from` exports as they aren't handled elsewhere for (const exportElement of exportDeclaration.exportClause.elements) { const exportedNodeSymbol = getActualSymbol(getImportExportReferencedSymbol(exportElement, typeChecker), typeChecker); const exportingExportStarResult = findExportingExportStarExportFromImportableModule( referencedModuleSymbol, exportedNodeSymbol ); if (exportingExportStarResult === null) { continue; } const importModuleSpecifier = getImportModuleName(exportingExportStarResult.exportStarDeclaration); if (importModuleSpecifier === null) { throw new Error(`Cannot get import module name from '${exportingExportStarResult.exportStarDeclaration.getText()}'`); } // technically we could use named imports and then add re-exports // but this solution affects names scope (re-exports don't affect it) // and also it is slightly complicated to find a name declaration (identifier) that needs to be imported // so it feels better to go this way, but happy to change in the future if there would be any issues addReExport( getImportItem(importModuleSpecifier), exportingExportStarResult.exportedNodeSymbol.getName(), exportElement.name.text ); } return; } } } function updateResultForRootModule(statements: readonly ts.Statement[], currentModule: ModuleInfo): void { updateResultForAnyModule(statements, currentModule); // add skipped by `updateResult` exports for (const statement of statements) { if (ts.isExportDeclaration(statement)) { handleExportDeclarationFromRootModule(statement); continue; } if (ts.isExportAssignment(statement)) { // `"export ="` or `export default 123` or `export default "str"` if (statement.isExportEquals || !ts.isIdentifier(statement.expression)) { collectionResult.statements.push(statement); } continue; } } } function updateResultForModuleDeclaration(moduleDecl: ts.ModuleDeclaration, currentModule: ModuleInfo): void { if (moduleDecl.body === undefined || !ts.isModuleBlock(moduleDecl.body)) { return; } const referencedModuleInfo = getModuleLikeModuleInfo(moduleDecl, criteria, typeChecker); if (referencedModuleInfo === null) { return; } // if we have declaration of external module inside internal one if (!currentModule.isExternal && referencedModuleInfo.isExternal) { // if it's allowed - we need to just add it to result without any processing if (inlineDeclareExternals) { collectionResult.statements.push(moduleDecl); } return; } updateResultForAnyModule(moduleDecl.body.statements, referencedModuleInfo); } function addTypesReference(library: string): void { if (!collectionResult.typesReferences.has(library)) { normalLog(`Library "${library}" will be added via reference directive`); collectionResult.typesReferences.add(library); } } function forEachNodeThatShouldBeImported(statement: ts.Statement | ts.SourceFile | ts.ExportSpecifier, callback: (st: ts.DeclarationStatement) => void): void { const statementsToImport = ts.isVariableStatement(statement) ? statement.declarationList.declarations : ts.isExportDeclaration(statement) && statement.exportClause !== undefined ? ts.isNamespaceExport(statement.exportClause) ? [statement.exportClause] : statement.exportClause.elements : [statement]; for (const statementToImport of statementsToImport) { if (shouldNodeBeImported(statementToImport as ts.DeclarationStatement)) { callback(statementToImport as ts.DeclarationStatement); } } } function updateImportsForStatement(statement: ts.Statement | ts.SourceFile | ts.ExportSpecifier): void { forEachNodeThatShouldBeImported(statement, (statementToImport: ts.DeclarationStatement) => { addImport(statementToImport); // if we're going to add import of any statement in the bundle // we should check whether the library of that statement // could be referenced via triple-slash reference-types directive // because the project which will use bundled declaration file // can have `types: []` in the tsconfig and it'll fail // this is especially related to the types packages // which declares different modules in their declarations // e.g. @types/node has declaration for "packages" events, fs, path and so on const sourceFile = statementToImport.getSourceFile(); const moduleInfo = getFileModuleInfo(sourceFile.fileName, criteria); if (moduleInfo.type === ModuleType.ShouldBeReferencedAsTypes) { addTypesReference(moduleInfo.typesLibraryName); } }); } function getDeclarationUsagesSourceFiles(declaration: ts.NamedDeclaration): Set { return new Set( getExportedSymbolsUsingStatement(declaration) .map((symbol: ts.Symbol) => getDeclarationsForSymbol(symbol)) .reduce((acc: ts.Declaration[], val: ts.Declaration[]) => acc.concat(val), []) .map(getClosestModuleLikeNode) ); } function getImportItem(importModuleSpecifier: string): ModuleImportsSet { let importItem = collectionResult.imports.get(importModuleSpecifier); if (importItem === undefined) { importItem = { defaultImports: new Set(), namedImports: new Map(), nsImport: null, requireImports: new Set(), reExports: new Map(), }; collectionResult.imports.set(importModuleSpecifier, importItem); } return importItem; } function addRequireImport(importItem: ModuleImportsSet, preferredLocalName: ts.Identifier): void { importItem.requireImports.add(collisionsResolver.addTopLevelIdentifier(preferredLocalName)); } function addNamedImport(importItem: ModuleImportsSet, preferredLocalName: ts.Identifier, importedIdentifier: ts.Identifier): void { const newLocalName = collisionsResolver.addTopLevelIdentifier(preferredLocalName); const importedName = importedIdentifier.text; importItem.namedImports.set(newLocalName, importedName); } function addReExport(importItem: ModuleImportsSet, moduleExportedName: string, reExportedName: string): void { // re-exports don't affect local names scope so we don't need to register them in collisions resolver importItem.reExports.set(reExportedName, moduleExportedName); } function addNsImport(importItem: ModuleImportsSet, preferredLocalName: ts.Identifier): void { if (importItem.nsImport === null) { importItem.nsImport = collisionsResolver.addTopLevelIdentifier(preferredLocalName); } } function addDefaultImport(importItem: ModuleImportsSet, preferredLocalName: ts.Identifier): void { importItem.defaultImports.add(collisionsResolver.addTopLevelIdentifier(preferredLocalName)); } function addImport(statement: ts.DeclarationStatement | ts.SourceFile): void { forEachImportOfStatement(statement, (imp: ImportOfStatement, referencedModuleInfo: ModuleInfo, importModuleSpecifier: string) => { // if a referenced module should be inlined we can just ignore it if (referencedModuleInfo.type !== ModuleType.ShouldBeImported) { return; } const importItem = getImportItem(importModuleSpecifier); if (ts.isImportEqualsDeclaration(imp)) { // import x = require("mod"); addRequireImport(importItem, imp.name); return; } if (ts.isExportSpecifier(imp)) { // export { El1, El2 as ExportedName } from 'module'; addNamedImport(importItem, imp.name, imp.propertyName || imp.name); return; } if (ts.isNamespaceExport(imp)) { // export * as name from 'module'; addNsImport(importItem, imp.name); return; } if (ts.isImportClause(imp) && imp.name !== undefined) { // import name from 'module'; addDefaultImport(importItem, imp.name); return; } if (ts.isImportSpecifier(imp)) { // import { El1, El2 as ImportedName } from 'module'; addNamedImport(importItem, imp.name, imp.propertyName || imp.name); return; } if (ts.isNamespaceImport(imp)) { // import * as name from 'module'; addNsImport(importItem, imp.name); return; } }); } type ImportOfStatement = ts.ImportEqualsDeclaration | ts.ExportSpecifier | ts.NamespaceExport | ts.ImportClause | ts.ImportSpecifier | ts.NamespaceImport; function forEachImportOfStatement(statement: ts.DeclarationStatement | ts.SourceFile, callback: (imp: ImportOfStatement, referencedModuleInfo: ModuleInfo, importModuleSpecifier: string) => void): void { if (!ts.isSourceFile(statement) && statement.name === undefined) { throw new Error(`Import/usage unnamed declaration: ${statement.getText()}`); } getDeclarationUsagesSourceFiles(statement).forEach((sourceFile: ts.SourceFile | ts.ModuleDeclaration) => { if (getModuleLikeModuleInfo(sourceFile, criteria, typeChecker).type !== ModuleType.ShouldBeInlined) { // we should ignore source files that aren't inlined return; } const sourceFileStatements: readonly ts.Statement[] = ts.isSourceFile(sourceFile) ? sourceFile.statements : sourceFile.body !== undefined && ts.isModuleBlock(sourceFile.body) ? sourceFile.body.statements : [] ; // eslint-disable-next-line complexity sourceFileStatements.forEach((st: ts.Statement) => { if (!ts.isImportEqualsDeclaration(st) && !ts.isImportDeclaration(st) && !ts.isExportDeclaration(st)) { return; } const importModuleSpecifier = getImportModuleName(st); if (importModuleSpecifier === null) { return; } const referencedModuleInfo = getReferencedModuleInfo(st, criteria, typeChecker); // if a referenced module should be inlined we can just ignore it if (referencedModuleInfo === null) { return; } if (ts.isImportEqualsDeclaration(st)) { if (areDeclarationSame(statement, st)) { callback(st, referencedModuleInfo, importModuleSpecifier); } return; } if (ts.isExportDeclaration(st) && st.exportClause !== undefined) { if (ts.isNamedExports(st.exportClause)) { // export { El1, El2 as ExportedName } from 'module'; st.exportClause.elements .filter(areDeclarationSame.bind(null, statement)) .forEach((specifier: ts.ExportSpecifier) => { callback(specifier, referencedModuleInfo, importModuleSpecifier); }); } else { // export * as name from 'module'; if (isNodeUsed(st.exportClause)) { callback(st.exportClause, referencedModuleInfo, importModuleSpecifier); } } } else if (ts.isImportDeclaration(st) && st.importClause !== undefined) { if (st.importClause.name !== undefined && areDeclarationSame(statement, st.importClause)) { // import name from 'module'; callback(st.importClause, referencedModuleInfo, importModuleSpecifier); } if (st.importClause.namedBindings !== undefined) { if (ts.isNamedImports(st.importClause.namedBindings)) { // import { El1, El2 as ImportedName } from 'module'; st.importClause.namedBindings.elements .filter(areDeclarationSame.bind(null, statement)) .forEach((specifier: ts.ImportSpecifier) => { callback(specifier, referencedModuleInfo, importModuleSpecifier); }); } else { // import * as name from 'module'; if (isNodeUsed(st.importClause)) { callback(st.importClause.namedBindings, referencedModuleInfo, importModuleSpecifier); } } } } }); }); } function getInlinedSymbolsUsingSymbol(symbol: ts.Symbol, predicate: (usedInSymbol: ts.Symbol) => boolean): ts.Symbol[] { return Array.from(typesUsageEvaluator.getSymbolsUsingSymbol(symbol) ?? []).filter((usedInSymbol: ts.Symbol) => { if (!predicate(usedInSymbol)) { return false; } return getDeclarationsForSymbol(usedInSymbol).some((decl: ts.Declaration) => { const closestModuleLike = getClosestSourceFileLikeNode(decl); const moduleInfo = getModuleLikeModuleInfo(closestModuleLike, criteria, typeChecker); return moduleInfo.type === ModuleType.ShouldBeInlined; }); }); } function isSymbolUsedByInlinedSymbols(symbol: ts.Symbol, predicate: (usedInSymbol: ts.Symbol) => boolean, visitedSymbols: Set = new Set()): boolean { if (visitedSymbols.has(symbol)) { return false; } visitedSymbols.add(symbol); return Array.from(typesUsageEvaluator.getSymbolsUsingSymbol(symbol) ?? []).some((usedInSymbol: ts.Symbol) => { if (!predicate(usedInSymbol)) { return isSymbolUsedByInlinedSymbols(usedInSymbol, predicate, visitedSymbols); } const usedByThisSymbol = getDeclarationsForSymbol(usedInSymbol).some((decl: ts.Declaration) => { const closestModuleLike = getClosestSourceFileLikeNode(decl); const moduleInfo = getModuleLikeModuleInfo(closestModuleLike, criteria, typeChecker); return moduleInfo.type === ModuleType.ShouldBeInlined; }); if (usedByThisSymbol) { return true; } return isSymbolUsedByInlinedSymbols(usedInSymbol, predicate, visitedSymbols); }); } function isSymbolUsedByRootFileExports(symbol: ts.Symbol): boolean { return rootFileExportSymbols.some((rootSymbol: ts.Symbol) => typesUsageEvaluator.isSymbolUsedBySymbol(symbol, rootSymbol)); } function isSymbolForGlobalDeclaration(symbol: ts.Symbol): boolean { return symbol.escapedName === ts.InternalSymbolName.Global; } function isSymbolForDeclareModuleDeclaration(symbol: ts.Symbol): boolean { return getDeclarationsForSymbol(symbol).some(isDeclareModule); } // eslint-disable-next-line complexity function isNodeUsed(node: ts.Node): boolean { if (isNodeNamedDeclaration(node) || ts.isSourceFile(node)) { const nodeSymbol = getNodeSymbol(node, typeChecker); if (nodeSymbol === null) { return false; } // note we don't need a function similar to `isSymbolUsedByGlobalSymbols` or `isSymbolUsedByGlobalSymbols` // because `TypesUsageEvaluator.isSymbolUsedBySymbol` already handles recursive checks const nodeUsedByDirectExports = isSymbolUsedByRootFileExports(nodeSymbol); if (nodeUsedByDirectExports) { return true; } if (inlineDeclareGlobals && isSymbolUsedByInlinedSymbols(nodeSymbol, isSymbolForGlobalDeclaration)) { return true; } if (inlineDeclareExternals && isSymbolUsedByInlinedSymbols(nodeSymbol, isSymbolForDeclareModuleDeclaration)) { return true; } return false; } if (ts.isVariableStatement(node)) { return node.declarationList.declarations.some((declaration: ts.VariableDeclaration) => { if (ts.isObjectBindingPattern(declaration.name) || ts.isArrayBindingPattern(declaration.name)) { return declaration.name.elements.some(isNodeUsed); } return isNodeUsed(declaration); }); } if (ts.isExportDeclaration(node) && node.exportClause !== undefined && ts.isNamespaceExport(node.exportClause)) { return isNodeUsed(node.exportClause); } if (ts.isImportClause(node) && node.namedBindings !== undefined) { return isNodeUsed(node.namedBindings); } return false; } function shouldNodeBeImported(node: ts.NamedDeclaration): boolean { const nodeSymbol = getNodeSymbol(node, typeChecker); if (nodeSymbol === null) { return false; } return shouldSymbolBeImported(nodeSymbol); } function shouldSymbolBeImported(nodeSymbol: ts.Symbol): boolean { const isSymbolDeclaredInDefaultLibrary = getDeclarationsForSymbol(nodeSymbol).some( (declaration: ts.Declaration) => program.isSourceFileDefaultLibrary(declaration.getSourceFile()) ); if (isSymbolDeclaredInDefaultLibrary) { // we shouldn't import a node declared in the default library (such dom, es2015) // yeah, actually we should check that node is declared only in the default lib // but it seems we can check that at least one declaration is from default lib // to treat the node as un-importable // because we can't re-export declared somewhere else node with declaration merging // also, if some lib file will not be added to the project // for example like it is described in the react declaration file (e.g. React Native) // then here we still have a bug with "importing global declaration from a package" // (see https://github.com/timocov/dts-bundle-generator/issues/71) // but I don't think it is a big problem for now // and it's possible that it will be fixed in https://github.com/timocov/dts-bundle-generator/issues/59 return false; } const symbolsDeclarations = getDeclarationsForSymbol(nodeSymbol); // if all declarations of the symbol are in modules that should be inlined then this symbol must be inlined, not imported const shouldSymbolBeInlined = symbolsDeclarations.every( (decl: ts.Declaration) => getModuleLikeModuleInfo( getClosestSourceFileLikeNode(decl), criteria, typeChecker ).type === ModuleType.ShouldBeInlined ); if (shouldSymbolBeInlined) { return false; } return getExportedSymbolsUsingSymbol(nodeSymbol).length !== 0; } function getExportedSymbolsUsingStatement(node: ts.NamedDeclaration): readonly ts.Symbol[] { const nodeSymbol = getNodeSymbol(node, typeChecker); if (nodeSymbol === null) { return []; } return getExportedSymbolsUsingSymbol(nodeSymbol); } function getExportedSymbolsUsingSymbol(nodeSymbol: ts.Symbol): readonly ts.Symbol[] { const symbolsUsingNode = typesUsageEvaluator.getSymbolsUsingSymbol(nodeSymbol); if (symbolsUsingNode === null) { throw new Error(`Something went wrong - getSymbolsUsingSymbol returned null but expected to be a set of symbols (symbol=${nodeSymbol.name})`); } return [ ...(rootFileExportSymbols.includes(nodeSymbol) ? [nodeSymbol] : []), // symbols which are used in types directly ...getInlinedSymbolsUsingSymbol(nodeSymbol, isSymbolUsedByRootFileExports), // symbols which are used in global types i.e. in `declare global`s ...(inlineDeclareGlobals ? getInlinedSymbolsUsingSymbol(nodeSymbol, isSymbolForGlobalDeclaration) : []), // symbols which are used in "declare module" types ...(inlineDeclareExternals ? getInlinedSymbolsUsingSymbol(nodeSymbol, isSymbolForDeclareModuleDeclaration) : []), ]; } function areDeclarationSame(left: ts.NamedDeclaration, right: ts.NamedDeclaration): boolean { const leftSymbols = splitTransientSymbol(getNodeSymbol(left, typeChecker) as ts.Symbol, typeChecker); const rightSymbols = splitTransientSymbol(getNodeSymbol(right, typeChecker) as ts.Symbol, typeChecker); for (const leftSymbol of leftSymbols) { if (rightSymbols.has(leftSymbol)) { return true; } } return false; } function createNamespaceForExports(exports: ts.SymbolTable, namespaceSymbol: ts.Symbol): string | null { function addSymbolToNamespaceExports(namespaceExports: Map, symbol: ts.Symbol): void { // if a symbol isn't used by the namespace symbol it might mean that it shouldn't be included into the bundle because of tree-shaking // in this case we shouldn't even try to add such symbol to the namespace if (!typesUsageEvaluator.isSymbolUsedBySymbol(symbol, namespaceSymbol)) { return; } const symbolKnownNames = collisionsResolver.namesForSymbol(symbol); if (symbolKnownNames.size === 0) { throw new Error(`Cannot get local names for symbol '${symbol.getName()}' while generating namespaced export`); } namespaceExports.set(symbol.getName(), Array.from(symbolKnownNames)[0]); } function handleNamespacedImportOrExport(namespacedImportOrExport: ts.ExportDeclaration | ts.ImportDeclaration, namespaceExports: Map, symbol: ts.Symbol): void { if (namespacedImportOrExport.moduleSpecifier === undefined) { return; } if (isReferencedModuleImportable(namespacedImportOrExport)) { // in case of an external export statement we should copy it as is // here we assume that a namespace import will be added in other places // so here we can just add re-export addSymbolToNamespaceExports(namespaceExports, symbol); return; } const referencedSourceFileSymbol = getNodeOwnSymbol(namespacedImportOrExport.moduleSpecifier, typeChecker); if (referencedSourceFileSymbol.exports === undefined) { return; } if (ts.isImportDeclaration(namespacedImportOrExport) && referencedSourceFileSymbol.exports.has(ts.InternalSymbolName.ExportEquals)) { // in case of handling `import * as Ns` statements with `export =` export in a module we need to ignore it // as that import will be renamed later return; } const localNamespaceName = createNamespaceForExports(referencedSourceFileSymbol.exports, symbol); if (localNamespaceName !== null) { namespaceExports.set(symbol.getName(), localNamespaceName); } } function processExportSymbol(namespaceExports: Map, symbol: ts.Symbol): void { if (symbol.escapedName === ts.InternalSymbolName.ExportStar) { // this means that an export contains `export * from 'module'` statement for (const exportStarDeclaration of getSymbolExportStarDeclarations(symbol)) { if (exportStarDeclaration.moduleSpecifier === undefined) { throw new Error(`Export star declaration does not have a module specifier '${exportStarDeclaration.getText()}'`); } if (isReferencedModuleImportable(exportStarDeclaration)) { // in case of re-exporting from other modules directly we should import everything and re-export manually // but it is not supported yet so lets just fail for now throw new Error(`Having a re-export from an importable module as a part of namespaced export is not supported yet.`); } const referencedSourceFileSymbol = getNodeOwnSymbol(exportStarDeclaration.moduleSpecifier, typeChecker); referencedSourceFileSymbol.exports?.forEach( processExportSymbol.bind(null, namespaceExports) ); } return; } symbol.declarations?.forEach((decl: ts.Declaration) => { if (ts.isNamespaceExport(decl) && decl.parent.moduleSpecifier !== undefined) { handleNamespacedImportOrExport(decl.parent, namespaceExports, symbol); return; } if (ts.isExportSpecifier(decl)) { const exportElementSymbol = getImportExportReferencedSymbol(decl, typeChecker); const namespaceImport = getDeclarationsForSymbol(exportElementSymbol).find(ts.isNamespaceImport); if (namespaceImport !== undefined) { // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion handleNamespacedImportOrExport(namespaceImport.parent.parent as ts.ImportDeclaration, namespaceExports, symbol); } return; } }); addSymbolToNamespaceExports(namespaceExports, symbol); } // eslint-disable-next-line complexity function getIdentifierOfNamespaceImportFromInlinedModule(nsSymbol: ts.Symbol): ts.Identifier | null { // handling namespaced re-exports/imports // e.g. `export * as NS from './local-module';` or `import * as NS from './local-module'; export { NS }` for (const decl of getDeclarationsForSymbol(nsSymbol)) { if (!ts.isNamespaceExport(decl) && !ts.isExportSpecifier(decl) && !ts.isNamespaceImport(decl)) { continue; } // if it is namespace export then it should be from a inlined module (e.g. `export * as NS from './local-module';`) if (ts.isNamespaceExport(decl) && !isReferencedModuleImportable(decl.parent)) { return decl.name; } // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion if (ts.isNamespaceImport(decl) && !isReferencedModuleImportable(decl.parent.parent as ts.ImportDeclaration)) { return decl.name; } if (ts.isExportSpecifier(decl)) { // if it is export specifier then it should exporting a local symbol i.e. without a module specifier (e.g. `export { NS };` or `export { NS as NewNsName };`) if (decl.parent.parent.moduleSpecifier !== undefined) { // this means that namespace symbol is created somewhere else in the import/export chain if (isReferencedModuleImportable(decl.parent.parent)) { continue; } // in case of a chain of imports/exports we need to keep searching recursively if (getIdentifierOfNamespaceImportFromInlinedModule(getImportExportReferencedSymbol(decl, typeChecker))) { return decl.name; } } // but also that local symbol should be a namespace imported from inlined module // i.e. `import * as NS from './local-module'` const result = getDeclarationsForSymbol(getImportExportReferencedSymbol(decl, typeChecker)).some((importDecl: ts.Declaration) => { if (ts.isNamespaceImport(importDecl)) { // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion return !isReferencedModuleImportable(importDecl.parent.parent as ts.ImportDeclaration); } if (ts.isImportSpecifier(importDecl)) { // this means that namespace symbol is created somewhere else in the import/export chain return getIdentifierOfNamespaceImportFromInlinedModule(getImportExportReferencedSymbol(importDecl, typeChecker)); } return false; }); if (result) { return decl.name; } } } return null; } const namespaceNameIdentifier = getIdentifierOfNamespaceImportFromInlinedModule(namespaceSymbol); if (namespaceNameIdentifier === null) { return null; } const namespaceExports = new Map(); exports.forEach( processExportSymbol.bind(null, namespaceExports) ); if (namespaceExports.size !== 0) { const namespaceLocalName = collisionsResolver.addTopLevelIdentifier(namespaceNameIdentifier); collectionResult.wrappedNamespaces.set(namespaceLocalName, namespaceExports); return namespaceLocalName; } return null; } function syncExports(): void { for (const exp of rootFileExports) { if (exp.type === ExportType.CommonJS) { // commonjs will be handled separately where we handle root source files // as the only way of adding it is to add an explicit export statement in the root source file continue; } // if resolved symbol is a "synthetic" symbol already (i.e. not namespace module) // then we should create a namespace for its exports // otherwise most likely it will be inlined as is anyway so we don't need to do anything const namespaceLocalName = exp.symbol.flags & ts.SymbolFlags.ValueModule && exp.symbol.exports !== undefined ? createNamespaceForExports(exp.symbol.exports, exp.originalSymbol) : null ; if (namespaceLocalName !== null) { collectionResult.renamedExports.set(exp.exportedName, namespaceLocalName); } const symbolKnownNames = collisionsResolver.namesForSymbol(exp.symbol); if (symbolKnownNames.size === 0) { // that's fine if a symbol doesn't exists in collisions resolver because it operates on top-level symbols only // in some cases a symbol can be exported but not added to the top-level scope // for instance in case of re-export from a library `export { Foo } from 'bar'` // in this case we'll add this re-export differently continue; } if (symbolKnownNames.has(exp.exportedName)) { // an exported symbol is already known with its "exported" name so nothing to do at this point // but if it is re-exported from imported library then we assume it was previously imported so we should re-export it anyway if (shouldSymbolBeImported(exp.symbol)) { collectionResult.renamedExports.set(exp.exportedName, exp.exportedName); } continue; } // in case if this symbol isn't known yet we need to add it via renamed export // we assume that all known names are equal so we can use any (first) // usually all "local" names should have only one known name // but having multiple names is possible with imports - you can import the same node with different names // and we want to preserve the source input as much as we can that's why we re-use them collectionResult.renamedExports.set(exp.exportedName, Array.from(symbolKnownNames)[0]); } } for (const sourceFile of sourceFiles) { verboseLog(`======= Processing ${sourceFile.fileName} =======`); const updateFn = sourceFile === rootSourceFile ? updateResultForRootModule : updateResultForAnyModule; const currentModule = getFileModuleInfo(sourceFile.fileName, criteria); updateFn(sourceFile.statements, currentModule); // handle `import * as module` usage if it's used as whole module if (isNodeUsed(sourceFile)) { switch (currentModule.type) { case ModuleType.ShouldBeImported: { updateImportsForStatement(sourceFile); break; } case ModuleType.ShouldBeInlined: { const sourceFileSymbol = getNodeSymbol(sourceFile, typeChecker); if (sourceFileSymbol === null || sourceFileSymbol.exports === undefined) { throw new Error(`Cannot find symbol or exports for source file ${sourceFile.fileName}`); } let namespaceIdentifier: ts.Identifier | null = null; forEachImportOfStatement(sourceFile, (imp: ImportOfStatement) => { // here we want to handle creation of artificial namespace for a inlined module // so we don't care about other type of imports/exports - only these that create a "namespace" if (ts.isNamespaceExport(imp) || ts.isNamespaceImport(imp)) { namespaceIdentifier = imp.name; } }); if (namespaceIdentifier === null) { break; } createNamespaceForExports(sourceFileSymbol.exports, getNodeOwnSymbol(namespaceIdentifier, typeChecker)); break; } } } } if (entryConfig.failOnClass) { const classes = collectionResult.statements.filter(ts.isClassDeclaration); if (classes.length !== 0) { const classesNames = classes.map((c: ts.ClassDeclaration) => c.name === undefined ? 'anonymous class' : c.name.text); throw new Error(`${classes.length} class statement(s) are found in generated dts: ${classesNames.join(', ')}`); } } syncExports(); // by default this option should be enabled const exportReferencedTypes = outputOptions.exportReferencedTypes !== false; function isExportedWithLocalName(namedDeclaration: ts.NamedDeclaration, exportedName: string): boolean { const nodeName = getNodeName(namedDeclaration); if (nodeName === undefined) { throw new Error(`Cannot find node name ${namedDeclaration.getText()}`); } return collisionsResolver.resolveReferencedIdentifier(nodeName as ts.Identifier) === exportedName; } const renamedAndNotExplicitlyExportedTypes: ts.NamedDeclaration[] = []; const output = generateOutput( { ...collectionResult, resolveIdentifierName: (identifier: ts.Identifier | ts.QualifiedName | ts.PropertyAccessEntityNameExpression): string | null => { if (ts.isPropertyAccessOrQualifiedName(identifier)) { return collisionsResolver.resolveReferencedQualifiedName(identifier); } else { return collisionsResolver.resolveReferencedIdentifier(identifier); } }, // eslint-disable-next-line complexity getStatementSettings: (statement: ts.Statement): StatementSettings => { if (isAmbientModule(statement) || ts.isExportDeclaration(statement)) { return { shouldHaveExportKeyword: false, shouldHaveJSDoc: true }; } const statementExports = getExportsForStatement(rootFileExports, typeChecker, statement); // If true, then no direct export was found. That means that node might have // an export keyword (like interface, type, etc) otherwise, if there are // only re-exports with renaming (like export { foo as bar }) we don't need // to put export keyword for this statement because we'll re-export it in the way const isExplicitlyExportedWithOriginalName = statementExports.find((exp: SourceFileExport) => { if (ts.isVariableStatement(statement)) { for (const variableDeclaration of statement.declarationList.declarations) { if (ts.isIdentifier(variableDeclaration.name)) { const resolvedName = collisionsResolver.resolveReferencedIdentifier(variableDeclaration.name); if (exp.exportedName === resolvedName) { return true; } continue; } // it seems that the compiler doesn't produce anything else (e.g. binding elements) in declaration files // but it is still possible to write such code manually // this feels like quite rare case so no support for now warnLog(`Unhandled variable identifier type detected (${ts.SyntaxKind[variableDeclaration.name.kind]}). Please report this issue to https://github.com/timocov/dts-bundle-generator`); } return false; } return isNodeNamedDeclaration(statement) && isExportedWithLocalName(statement, exp.exportedName); }) !== undefined; // "direct export" means export from the root source file // e.g. classes/functions/etc must be exported from the root source file to have an "export" keyword // by default interfaces/types are exported even if they aren't directly exported (e.g. when they are referenced by other types) // but if `exportReferencedTypes` option is disabled we have to check direct export for them either const onlyExplicitlyExportedShouldBeExported = !exportReferencedTypes || ts.isClassDeclaration(statement) || (ts.isEnumDeclaration(statement) && !hasNodeModifier(statement, ts.SyntaxKind.ConstKeyword)) || ts.isFunctionDeclaration(statement) || ts.isVariableStatement(statement) || ts.isModuleDeclaration(statement); if (onlyExplicitlyExportedShouldBeExported) { // "valuable" statements must be re-exported from root source file // to having export keyword in declaration file return { shouldHaveExportKeyword: isExplicitlyExportedWithOriginalName, shouldHaveJSDoc: statementExports.length !== 0 }; } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion if (isNodeNamedDeclaration(statement) && !isExportedWithLocalName(statement, getNodeName(statement)!.getText())) { // if a type node was renamed because of name collisions it shouldn't be exported with its new name renamedAndNotExplicitlyExportedTypes.push(statement); return { shouldHaveExportKeyword: false, shouldHaveJSDoc: statementExports.length !== 0 }; } // at this point a statement of a type (interface, const enum, etc) will be exported 100% (it's just a matter of a name) // so it must have jsdoc comment return { shouldHaveExportKeyword: isExplicitlyExportedWithOriginalName || statementExports.length === 0, shouldHaveJSDoc: true }; }, needStripConstFromConstEnum: (constEnum: ts.EnumDeclaration) => { if (!program.getCompilerOptions().preserveConstEnums || !outputOptions.respectPreserveConstEnum) { return false; } const enumSymbol = getNodeSymbol(constEnum, typeChecker); if (enumSymbol === null) { return false; } return rootFileExportSymbols.includes(enumSymbol); }, needStripImportFromImportTypeNode: (node: ts.ImportTypeNode) => { if (node.qualifier === undefined) { return false; } if (!ts.isLiteralTypeNode(node.argument) || !ts.isStringLiteral(node.argument.literal)) { return false; } return getReferencedModuleInfo(node, criteria, typeChecker)?.type === ModuleType.ShouldBeInlined; }, }, { sortStatements: outputOptions.sortNodes, umdModuleName: outputOptions.umdModuleName, noBanner: outputOptions.noBanner, } ); if (renamedAndNotExplicitlyExportedTypes.length !== 0) { warnLog(`The following type nodes were renamed because of the name collisions and will not be exported from the generated bundle:\n- ${ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion renamedAndNotExplicitlyExportedTypes.map(node => `${getNodeName(node)!.getText()} (from ${node.getSourceFile().fileName})`).join('\n- ') }${ '\n' }This might lead to unpredictable and unexpected output, and possible breaking changes to your API.${ '\n' }Consider either (re-)exporting them explicitly from the entry point, or disable --export-referenced-types option ('output.exportReferencedTypes' in the config).`); } return output; }); } timocov-dts-bundle-generator-c69ff0d/src/collisions-resolver.ts000066400000000000000000000255361461132021400251010ustar00rootroot00000000000000import * as ts from 'typescript'; import { getActualSymbol, getClosestModuleLikeNode, getDeclarationNameSymbol, getDeclarationsForSymbol, resolveGlobalName, } from './helpers/typescript'; import { verboseLog } from './logger'; const renamingSupportedSymbols: readonly ts.SymbolFlags[] = [ ts.SymbolFlags.Alias, ts.SymbolFlags.Variable, ts.SymbolFlags.Class, ts.SymbolFlags.Enum, ts.SymbolFlags.Function, ts.SymbolFlags.Interface, ts.SymbolFlags.NamespaceModule, ts.SymbolFlags.TypeAlias, ts.SymbolFlags.ValueModule, ]; export interface ResolverIdentifier { name: string; identifier?: ts.Identifier; } /** * A class that holds information about top-level scoped names and allows to get collision-free names in one occurred. */ export class CollisionsResolver { private typeChecker: ts.TypeChecker; private collisionsMap: Map> = new Map(); private generatedNames: Map> = new Map(); public constructor(typeChecker: ts.TypeChecker) { this.typeChecker = typeChecker; } /** * Adds (or "registers") a top-level {@link identifier} (which takes a top-level scope name to use). */ public addTopLevelIdentifier(identifier: ts.Identifier | ts.DefaultKeyword): string { const symbol = getDeclarationNameSymbol(identifier, this.typeChecker); if (symbol === null) { throw new Error(`Something went wrong - cannot find a symbol for top-level identifier ${identifier.getText()} (from ${identifier.parent.parent.getText()})`); } const newLocalName = this.registerSymbol(symbol, identifier.getText()); if (newLocalName === null) { throw new Error(`Something went wrong - a symbol ${symbol.name} for top-level identifier ${identifier.getText()} cannot be renamed`); } return newLocalName; } /** * Returns a set of all already registered names for a given {@link symbol}. */ public namesForSymbol(symbol: ts.Symbol): Set { return this.generatedNames.get(getActualSymbol(symbol, this.typeChecker)) || new Set(); } /** * Resolves given {@link referencedIdentifier} to a name. * It assumes that a symbol for this identifier has been registered before by calling {@link addTopLevelIdentifier} method. * Otherwise it will return `null`. * * Note that a returned value might be of a different type of the identifier (e.g. {@link ts.QualifiedName} for a given {@link ts.Identifier}) */ public resolveReferencedIdentifier(referencedIdentifier: ts.Identifier): string | null { const identifierSymbol = getDeclarationNameSymbol(referencedIdentifier, this.typeChecker); if (identifierSymbol === null) { // that's fine if an identifier doesn't have a symbol // it could be in cases like for `prop` in `declare function func({ prop: prop3 }?: InterfaceName): TypeName;` return null; } const symbolScopePath = this.getSymbolScope(identifierSymbol); // this scope defines where the current identifier is located const currentIdentifierScope = this.getNodeScope(referencedIdentifier); if (symbolScopePath.length > 0 && currentIdentifierScope.length > 0 && symbolScopePath[0] === currentIdentifierScope[0]) { // if a referenced symbol is declared in the same scope where it is located // then just return its reference as is without any modification // also note that in this method we're working with identifiers only (i.e. it cannot be a qualified name) return referencedIdentifier.getText(); } const topLevelIdentifierSymbol = symbolScopePath.length === 0 ? identifierSymbol : symbolScopePath[0]; const namesForTopLevelSymbol = this.namesForSymbol(topLevelIdentifierSymbol); if (namesForTopLevelSymbol.size === 0) { return null; } let topLevelName = symbolScopePath.length === 0 ? referencedIdentifier.getText() : topLevelIdentifierSymbol.getName(); if (!namesForTopLevelSymbol.has(topLevelName)) { // if the set of already registered names does not contain the one that is requested const topLevelNamesArray = Array.from(namesForTopLevelSymbol); // lets find more suitable name for a top level symbol let suitableTopLevelName = topLevelNamesArray[0]; for (const name of topLevelNamesArray) { // attempt to find a generated name first to provide identifiers close to the original code as much as possible if (name.startsWith(`${topLevelName}$`)) { suitableTopLevelName = name; break; } } topLevelName = suitableTopLevelName; } const newIdentifierParts = [ ...symbolScopePath.map((symbol: ts.Symbol) => symbol.getName()), referencedIdentifier.getText(), ]; // we don't need to rename any symbol but top level only as only it can collide with other symbols newIdentifierParts[0] = topLevelName; return newIdentifierParts.join('.'); } /** * Similar to {@link resolveReferencedIdentifier}, but works with qualified names (Ns.Ns1.Interface). * The main point of this resolver is that it might change the first part of the qualifier only (as it drives uniqueness of a name). */ public resolveReferencedQualifiedName(referencedIdentifier: ts.QualifiedName | ts.PropertyAccessEntityNameExpression): string | null { let topLevelIdentifier: ts.Identifier | ts.QualifiedName | ts.PropertyAccessEntityNameExpression = referencedIdentifier; if (ts.isQualifiedName(topLevelIdentifier) || ts.isPropertyAccessExpression(topLevelIdentifier)) { let leftmostIdentifier = ts.isQualifiedName(topLevelIdentifier) ? topLevelIdentifier.left : topLevelIdentifier.expression; while (ts.isQualifiedName(leftmostIdentifier) || ts.isPropertyAccessExpression(leftmostIdentifier)) { leftmostIdentifier = ts.isQualifiedName(leftmostIdentifier) ? leftmostIdentifier.left : leftmostIdentifier.expression; } topLevelIdentifier = leftmostIdentifier; } const topLevelName = this.resolveReferencedIdentifier(topLevelIdentifier); if (topLevelName === null) { // that's fine if we don't have a name for this top-level symbol // it simply means that this symbol type might not be supported for renaming // at this point the top-level identifier isn't registered yet // but it is possible that the full qualified name is registered so we can use its replacement instead // it is possible in cases where you use `import * as nsName` for internal modules // so `nsName.Interface` will be resolved to `Interface` (or any other name that `Interface` was registered with) const identifierSymbol = getDeclarationNameSymbol(referencedIdentifier, this.typeChecker); if (identifierSymbol === null) { // that's fine if an identifier doesn't have a symbol // it could be in cases like for `prop` in `declare function func({ prop: prop3 }?: InterfaceName): TypeName;` return null; } const namesForSymbol = this.namesForSymbol(identifierSymbol); if (namesForSymbol.size !== 0) { // if the set of already registered names contains the one that is requested then lets use it return Array.from(namesForSymbol)[0]; } // if it is not registered - just skip it return null; } // for nodes that we have to import we need to add an imported value to the collisions map // so it will not overlap with other imports/inlined nodes const identifierParts = referencedIdentifier.getText().split('.'); // update top level part as it could get renamed above // note that `topLevelName` might be a qualified name (e.g. with `.` in the name) // but this is fine as we join with `.` below anyway // but it is worth it to mention here ¯\_(ツ)_/¯ identifierParts[0] = topLevelName; return identifierParts.join('.'); } private getSymbolScope(identifierSymbol: ts.Symbol): ts.Symbol[] { const identifierDeclarations = getDeclarationsForSymbol(identifierSymbol); // not all symbols have declarations, e.g. `globalThis` or `undefined` (not type but value e.g. in `typeof undefined`) // they are "fake" symbols that exist only at the compiler level (see checker.ts file in in the compiler or `globals.set()` calls) if (identifierDeclarations.length === 0) { return []; } // we assume that all symbols for a given identifier will be in the same scope (i.e. defined in the same namespaces-chain) // so we can use any declaration to find that scope as they all will have the same scope return this.getNodeScope(identifierDeclarations[0]); } /** * Returns a node's scope where it is located in terms of namespaces/modules. * E.g. A scope for `Opt` in `declare module foo { type Opt = number; }` is `[Symbol(foo)]` */ private getNodeScope(node: ts.Node): ts.Symbol[] { const scopeIdentifiersPath: ts.Symbol[] = []; let currentNode: ts.Node = getClosestModuleLikeNode(node); while (ts.isModuleDeclaration(currentNode) && ts.isIdentifier(currentNode.name)) { const nameSymbol = getDeclarationNameSymbol(currentNode.name, this.typeChecker); if (nameSymbol === null) { throw new Error(`Cannot find symbol for identifier '${currentNode.name.getText()}'`); } scopeIdentifiersPath.push(nameSymbol); currentNode = getClosestModuleLikeNode(currentNode.parent); } return scopeIdentifiersPath.reverse(); } private registerSymbol(identifierSymbol: ts.Symbol, preferredName: string): string | null { if (!renamingSupportedSymbols.some((flag: ts.SymbolFlags) => identifierSymbol.flags & flag)) { // if a symbol for something else that we don't support yet - skip verboseLog(`Symbol ${identifierSymbol.name} cannot be renamed because its flag (${identifierSymbol.flags}) isn't supported`); return null; } if (identifierSymbol.flags & ts.SymbolFlags.NamespaceModule && identifierSymbol.escapedName === ts.InternalSymbolName.Global) { // no need to rename `declare global` namespaces return null; } let symbolName = preferredName; if (symbolName === 'default') { // this is special case as an identifier cannot be named `default` because of es6 syntax // so lets fallback to some valid name symbolName = '_default'; } const collisionsKey = symbolName; let collisionSymbols = this.collisionsMap.get(collisionsKey); if (collisionSymbols === undefined) { collisionSymbols = new Map(); this.collisionsMap.set(collisionsKey, collisionSymbols); } const storedSymbolName = collisionSymbols.get(identifierSymbol); if (storedSymbolName !== undefined) { return storedSymbolName; } let nameIndex = collisionSymbols.size; let newName = collisionSymbols.size === 0 ? symbolName : `${symbolName}$${nameIndex}`; let resolvedGlobalSymbol = resolveGlobalName(this.typeChecker, newName); while (resolvedGlobalSymbol !== undefined && resolvedGlobalSymbol !== identifierSymbol) { nameIndex += 1; newName = `${symbolName}$${nameIndex}`; resolvedGlobalSymbol = resolveGlobalName(this.typeChecker, newName); } collisionSymbols.set(identifierSymbol, newName); let symbolNames = this.generatedNames.get(identifierSymbol); if (symbolNames === undefined) { symbolNames = new Set(); this.generatedNames.set(identifierSymbol, symbolNames); } symbolNames.add(newName); return newName; } } timocov-dts-bundle-generator-c69ff0d/src/compile-dts.ts000066400000000000000000000207441461132021400233000ustar00rootroot00000000000000import * as ts from 'typescript'; import { verboseLog, warnLog } from './logger'; import { getCompilerOptions } from './get-compiler-options'; import { checkProgramDiagnosticsErrors, checkDiagnosticsErrors } from './helpers/check-diagnostics-errors'; export interface CompileDtsResult { program: ts.Program; rootFilesRemapping: Map; } const declarationExtsRemapping: Partial> = { [ts.Extension.Js]: ts.Extension.Js, [ts.Extension.Jsx]: ts.Extension.Jsx, [ts.Extension.Json]: ts.Extension.Json, [ts.Extension.TsBuildInfo]: ts.Extension.TsBuildInfo, [ts.Extension.Mjs]: ts.Extension.Mjs, [ts.Extension.Cjs]: ts.Extension.Cjs, [ts.Extension.Ts]: ts.Extension.Dts, [ts.Extension.Tsx]: ts.Extension.Dts, [ts.Extension.Dts]: ts.Extension.Dts, [ts.Extension.Mts]: ts.Extension.Dmts, [ts.Extension.Dmts]: ts.Extension.Dmts, [ts.Extension.Cts]: ts.Extension.Dcts, [ts.Extension.Dcts]: ts.Extension.Dcts, } satisfies Record; export function compileDts(rootFiles: readonly string[], preferredConfigPath?: string, followSymlinks: boolean = true): CompileDtsResult { const compilerOptions = getCompilerOptions(rootFiles, preferredConfigPath); // currently we don't support these compiler options // and removing them shouldn't affect generated code // so let's just remove them for this run compilerOptions.outDir = undefined; compilerOptions.incremental = undefined; compilerOptions.tsBuildInfoFile = undefined; compilerOptions.declarationDir = undefined; // we want to turn this option on because in this case the compile will generate declaration diagnostics out of the box compilerOptions.declaration = true; if (compilerOptions.composite) { warnLog(`Composite projects aren't supported at the time. Prefer to use non-composite project to generate declarations instead or just ignore this message if everything works fine. See https://github.com/timocov/dts-bundle-generator/issues/93`); compilerOptions.composite = undefined; } const host = createCachingCompilerHost(compilerOptions); const dtsFiles = getDeclarationFiles(rootFiles, compilerOptions, host); if (!followSymlinks) { // note that this shouldn't affect the previous call as there we actually want to use actual path in order to compile files // and avoid issues like "you have .ts files in node_modules" host.realpath = (p: string) => p; } const moduleResolutionCache = ts.createModuleResolutionCache(host.getCurrentDirectory(), host.getCanonicalFileName, compilerOptions); host.resolveModuleNameLiterals = (moduleLiterals: readonly ts.StringLiteralLike[], containingFile: string): ts.ResolvedModuleWithFailedLookupLocations[] => { return moduleLiterals.map((moduleLiteral: ts.StringLiteralLike): ts.ResolvedModuleWithFailedLookupLocations => { const resolvedModule = ts.resolveModuleName(moduleLiteral.text, containingFile, compilerOptions, host, moduleResolutionCache).resolvedModule; if (resolvedModule && !resolvedModule.isExternalLibraryImport) { const newExt = declarationExtsRemapping[resolvedModule.extension]; if (newExt === undefined) { verboseLog(`Skipping module ${resolvedModule.resolvedFileName} because it has unsupported extension "${resolvedModule.extension}"`); return { resolvedModule }; } // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison if (newExt !== resolvedModule.extension) { verboseLog(`Changing module from ${resolvedModule.extension} to ${newExt} for ${resolvedModule.resolvedFileName}`); resolvedModule.extension = newExt; resolvedModule.resolvedFileName = changeExtensionToDts(resolvedModule.resolvedFileName); } } return { resolvedModule }; }); }; const originalGetSourceFile = host.getSourceFile; host.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void) => { const storedValue = dtsFiles.get(host.getCanonicalFileName(fileName)); if (storedValue !== undefined) { return ts.createSourceFile(fileName, storedValue, languageVersion); } return originalGetSourceFile(fileName, languageVersion, onError); }; const rootFilesRemapping = new Map(); const inputFiles = rootFiles.map((rootFile: string) => { const rootDtsFile = changeExtensionToDts(rootFile); rootFilesRemapping.set(rootFile, rootDtsFile); return rootDtsFile; }); const program = ts.createProgram(inputFiles, compilerOptions, host); checkProgramDiagnosticsErrors(program); warnAboutTypeScriptFilesInProgram(program); return { program, rootFilesRemapping }; } function createCachingCompilerHost(compilerOptions: ts.CompilerOptions): ts.CompilerHost { const host = ts.createIncrementalCompilerHost(compilerOptions); const sourceFilesCache = new Map(); const originalGetSourceFile = host.getSourceFile; host.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void): ts.SourceFile | undefined => { const key = host.getCanonicalFileName(fileName); let cacheValue = sourceFilesCache.get(key); if (cacheValue === undefined) { cacheValue = originalGetSourceFile(fileName, languageVersion, onError); sourceFilesCache.set(key, cacheValue); } return cacheValue; }; return host; } function changeExtensionToDts(fileName: string): string { let ext: ts.Extension | undefined; // `path.extname` doesn't handle `.d.ts` cases (it returns `.ts` instead of `.d.ts`) if (fileName.endsWith(ts.Extension.Dts)) { return fileName; } if (fileName.endsWith(ts.Extension.Cts)) { ext = ts.Extension.Cts; } else if (fileName.endsWith(ts.Extension.Mts)) { ext = ts.Extension.Mts; } else if (fileName.endsWith(ts.Extension.Ts)) { ext = ts.Extension.Ts; } else if (fileName.endsWith(ts.Extension.Tsx)) { ext = ts.Extension.Tsx; } if (ext === undefined) { return fileName; } return fileName.slice(0, -ext.length) + declarationExtsRemapping[ext]; } /** * @description Compiles source files into d.ts files and returns map of absolute path to file content */ function getDeclarationFiles(rootFiles: readonly string[], compilerOptions: ts.CompilerOptions, host: ts.CompilerHost): Map { // we must pass `declaration: true` and `noEmit: false` if we want to generate declaration files // see https://github.com/microsoft/TypeScript/issues/24002#issuecomment-550549393 // also, we don't want to generate anything apart from declarations so that's why `emitDeclarationOnly: true` is here // it allows to run the tool for projects with allowJs flag enabled to avoid errors like: // error TS5055: Cannot write file '' because it would overwrite input file. compilerOptions = { ...compilerOptions, noEmit: false, declaration: true, emitDeclarationOnly: true, }; // theoretically this could be dangerous because the compiler host is created with compiler options // so technically `compilerOptions` and ones that were used to create the host might be different (and most likely will be) // but apparently a compiler host doesn't use compiler options that much, just a few encoding/newLine oriented // so hopefully it should be fine const program = ts.createProgram(rootFiles, compilerOptions, host); const allFilesAreDeclarations = program.getSourceFiles().every((s: ts.SourceFile) => s.isDeclarationFile); const declarations = new Map(); if (allFilesAreDeclarations) { // if all files are declarations we don't need to compile the project twice // so let's just return empty map to speed up verboseLog('Skipping compiling the project to generate d.ts because all files in it are d.ts already'); return declarations; } checkProgramDiagnosticsErrors(program); const emitResult = program.emit( undefined, (fileName: string, data: string) => declarations.set(host.getCanonicalFileName(fileName), data), undefined, true ); checkDiagnosticsErrors(emitResult.diagnostics, 'Errors while emitting declarations'); return declarations; } function warnAboutTypeScriptFilesInProgram(program: ts.Program): void { const nonDeclarationFiles = program.getSourceFiles().filter((file: ts.SourceFile) => !file.isDeclarationFile); if (nonDeclarationFiles.length !== 0) { warnLog(`WARNING: It seems that some files in the compilation still are not declaration files. For more information see https://github.com/timocov/dts-bundle-generator/issues/53. If you think this is a mistake, feel free to open new issue or just ignore this warning. ${nonDeclarationFiles.map((file: ts.SourceFile) => file.fileName).join('\n ')} `); } } timocov-dts-bundle-generator-c69ff0d/src/config-file/000077500000000000000000000000001461132021400226635ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/src/config-file/README.md000066400000000000000000000152051461132021400241450ustar00rootroot00000000000000# Config file Config file might be either JSON file or JS file with CommonJS export of the config. ## Schema ```js { compilationOptions: { /** * EXPERIMENTAL! * Allows disable resolving of symlinks to the original path. * By default following is enabled. * @see https://github.com/timocov/dts-bundle-generator/issues/39 * Optional. Default value is `true`. */ followSymlinks: true, /** * Path to the tsconfig file that will be used for the compilation. * Must be set if entries count more than 1. */ preferredConfigPath: './tsconfig.json', }, // non-empty array of entries entries: [ { /** * Path to input file (absolute or relative to config file). * Required. */ filePath: './src/index.ts', /** * Path of generated d.ts. * If not specified - the path will be input file with replaced extension to `.d.ts`. */ outFile: './out/index.d.ts', /** * Fail if generated dts contains class declaration. * Optional. Default value is `false`. */ failOnClass: false, /** * Skip validation of generated d.ts file. * Optional. Default value is `false`. */ noCheck: false, libraries: { /** * Array of package names from @types to import typings from via the triple-slash reference directive. * By default all packages are allowed and will be used according to their usages. * Optional. Default value is `undefined`. */ allowedTypesLibraries: ['jquery', 'react'], /** * Array of package names from node_modules to import typings from. * Used types will be imported using `import { First, Second } from 'library-name';`. * By default all libraries will be imported (except inlined libraries and libraries from @types). * Optional. Default value is `undefined`. */ importedLibraries: ['rxjs', 'typescript'], /** * Array of package names from node_modules to inline typings from. * Used types will be inlined into the output file. * Optional. Default value is `[]`. */ inlinedLibraries: ['@my-company/package'], }, output: { /** * Enables inlining of `declare global` statements contained in files which should be inlined (all local files and packages from inlined libraries). * Optional. Default value is `false`. */ inlineDeclareGlobals: false, /** * Sort output nodes in ascendant order. * Optional. Default value is `false`. */ sortNodes: false, /** * Name of the UMD module. * If specified then `export as namespace ModuleName;` will be emitted. * Optional. Default value is `undefined`. */ umdModuleName: 'MyModuleName', /** * Enables inlining of `declare module` statements of the global modules * (e.g. `declare module 'external-module' {}`, but NOT `declare module './internal-module' {}`) * contained in files which should be inlined (all local files and packages from inlined libraries) */ inlineDeclareExternals: false, /** * Allows remove "Generated by dts-bundle-generator" comment from the output */ noBanner: false, /** * Enables stripping the `const` keyword from every direct-exported (or re-exported) from entry file `const enum`. * This allows you "avoid" the issue described in https://github.com/microsoft/TypeScript/issues/37774. */ respectPreserveConstEnum: false, /** * By default all interfaces, types and const enums are marked as exported even if they aren't exported directly. * This option allows you to disable this behavior so a node will be exported if it is exported from root source file only. */ exportReferencedTypes: true, }, }, ], } ``` ## Tips 1. You can use `@ts-check` for your JS config-file to check that your config has correct schema. 1. Also you can write your config in TS and before run dts-bundle-generator compile it in JS. ## Examples *JSON file*: ```json { "compilationOptions": { "preferredConfigPath": "./tsconfig.json" }, "entries": [ { "filePath": "./src/index.ts", "outFile": "./out/index.d.ts", "libraries": { "inlinedLibraries": ["@my-company/package"] }, "output": { "inlineDeclareGlobals": false, "sortNodes": true, "umdModuleName": "MyModuleName" } }, { "filePath": "./src/second.ts", "outFile": "./out/second.d.ts", "failOnClass": true, "libraries": { "allowedTypesLibraries": [], "importedLibraries": [], "inlinedLibraries": [] } }, { "filePath": "./src/third.ts" } ] } ``` *JS file*: ```js // @ts-check // If won't use `@ts-check` - just remove that comments (with `@type` JSDoc below). /** @type import('dts-bundle-generator/config-schema').OutputOptions */ const commonOutputParams = { inlineDeclareGlobals: false, sortNodes: true, }; /** @type import('dts-bundle-generator/config-schema').BundlerConfig */ const config = { compilationOptions: { preferredConfigPath: './tsconfig.json', }, entries: [ { filePath: './src/index.ts', outFile: './out/index.d.ts', noCheck: false, output: commonOutputParams, }, { filePath: './src/second.ts', outFile: './out/second.d.ts', failOnClass: true, libraries: { inlinedLibraries: ['@my-company/package'], }, output: commonOutputParams, }, ], }; module.exports = config; ``` timocov-dts-bundle-generator-c69ff0d/src/config-file/check-schema-match.ts000066400000000000000000000050241461132021400266410ustar00rootroot00000000000000export interface PrimitiveValues { boolean: false; requiredBoolean: true; string: ''; requiredString: 'REQUIRED'; } export type SchemeDescriptor = { [P in keyof T]-?: T[P] extends unknown[] ? [SchemeDescriptor] : SchemeDescriptor; }; export const schemaPrimitiveValues: Readonly = { boolean: false, requiredBoolean: true, string: '', requiredString: 'REQUIRED', }; const schemaRequiredValues = new Set([ schemaPrimitiveValues.requiredBoolean, schemaPrimitiveValues.requiredString, ]); export function checkSchemaMatch(value: unknown, schema: SchemeDescriptor, errors: string[]): value is T { if (value === undefined) { errors.push('Root value is undefined'); return false; } return checkSchemaMatchRecursively(value, schema, '', errors); } // eslint-disable-next-line complexity function checkSchemaMatchRecursively(value: unknown, schema: SchemeDescriptor | [SchemeDescriptor], prefix: string, errors: string[]): value is T { if (typeof schema === 'boolean' || typeof schema === 'string') { const schemeType = typeof schema; if (value === undefined && schemaRequiredValues.has(schema)) { errors.push(`Value for "${prefix}" is required and must have type "${schemeType}"`); return false; } const valueType = typeof value; if (value !== undefined && typeof schema !== valueType) { errors.push(`Type of values for "${prefix}" is not the same, expected=${schemeType}, actual=${valueType}`); return false; } return true; } if (value === undefined) { return true; } if (Array.isArray(schema)) { if (!Array.isArray(value)) { return false; } let result = true; for (let i = 0; i < value.length; ++i) { if (!checkSchemaMatchRecursively(value[i], schema[0], `${prefix}[${i}]`, errors)) { result = false; } } return result; } type SchemeKey = keyof SchemeDescriptor; type SchemeSubValue = SchemeDescriptor; let result = true; for (const valueKey of Object.keys(value as object)) { if (schema[valueKey as keyof T] === undefined) { errors.push(`Exceeded property "${valueKey}" found in ${prefix.length === 0 ? 'the root' : prefix}`); result = false; } } for (const schemaKey of Object.keys(schema)) { const isSubValueSchemeMatched = checkSchemaMatchRecursively( (value as Record)[schemaKey], schema[schemaKey as SchemeKey] as SchemeSubValue, prefix.length === 0 ? schemaKey : `${prefix}.${schemaKey}`, errors ); result = result && isSubValueSchemeMatched; } return result; } timocov-dts-bundle-generator-c69ff0d/src/config-file/load-config-file.ts000066400000000000000000000054471461132021400263440ustar00rootroot00000000000000import * as path from 'path'; import { errorLog } from '../logger'; import { EntryPointConfig, CompilationOptions } from '../bundle-generator'; import { getAbsolutePath } from '../helpers/get-absolute-path'; import { checkSchemaMatch, SchemeDescriptor, schemaPrimitiveValues } from './check-schema-match'; export interface ConfigEntryPoint extends EntryPointConfig { /** * Path of generated d.ts. * If not specified - the path will be input file with replaced extension to `.d.ts`. */ outFile?: string; /** * Skip validation of generated d.ts file */ noCheck?: boolean; } export interface BundlerConfig { entries: ConfigEntryPoint[]; compilationOptions?: CompilationOptions; } /** * @internal Do not output this function in generated dts for the npm package */ export function loadConfigFile(configPath: string): BundlerConfig { // eslint-disable-next-line @typescript-eslint/no-var-requires const possibleConfig = require(getAbsolutePath(configPath)); const errors: string[] = []; if (!checkSchemaMatch(possibleConfig, configScheme, errors)) { errorLog(errors.join('\n')); throw new Error('Cannot parse config file'); } if (!Array.isArray(possibleConfig.entries) || possibleConfig.entries.length === 0) { throw new Error('No entries found'); } const configFolder = path.dirname(configPath); possibleConfig.entries.forEach((entry: ConfigEntryPoint) => { entry.filePath = getAbsolutePath(entry.filePath, configFolder); if (entry.outFile !== undefined) { entry.outFile = getAbsolutePath(entry.outFile, configFolder); } }); if (possibleConfig.compilationOptions !== undefined && possibleConfig.compilationOptions.preferredConfigPath !== undefined) { possibleConfig.compilationOptions.preferredConfigPath = getAbsolutePath(possibleConfig.compilationOptions.preferredConfigPath, configFolder); } return possibleConfig; } const configScheme: SchemeDescriptor = { compilationOptions: { followSymlinks: schemaPrimitiveValues.boolean, preferredConfigPath: schemaPrimitiveValues.string, }, entries: [ { filePath: schemaPrimitiveValues.requiredString, outFile: schemaPrimitiveValues.string, failOnClass: schemaPrimitiveValues.boolean, noCheck: schemaPrimitiveValues.boolean, libraries: { allowedTypesLibraries: [schemaPrimitiveValues.string], importedLibraries: [schemaPrimitiveValues.string], inlinedLibraries: [schemaPrimitiveValues.string], }, output: { inlineDeclareGlobals: schemaPrimitiveValues.boolean, inlineDeclareExternals: schemaPrimitiveValues.boolean, sortNodes: schemaPrimitiveValues.boolean, umdModuleName: schemaPrimitiveValues.string, noBanner: schemaPrimitiveValues.boolean, respectPreserveConstEnum: schemaPrimitiveValues.boolean, exportReferencedTypes: schemaPrimitiveValues.boolean, }, }, ], }; timocov-dts-bundle-generator-c69ff0d/src/generate-output.ts000066400000000000000000000277661461132021400242230ustar00rootroot00000000000000import * as ts from 'typescript'; import { packageVersion } from './helpers/package-version'; import { getModifiers, getNodeName, modifiersToMap, recreateRootLevelNodeWithModifiers } from './helpers/typescript'; export interface ModuleImportsSet { defaultImports: Set; nsImport: string | null; namedImports: Map; requireImports: Set; reExports: Map; } export interface OutputInputData { typesReferences: Set; imports: Map; statements: readonly ts.Statement[]; renamedExports: Map; wrappedNamespaces: Map>; } export interface NeedStripDefaultKeywordResult { needStrip: boolean; newName?: string; } export interface StatementSettings { shouldHaveExportKeyword: boolean; shouldHaveJSDoc: boolean; } export interface OutputHelpers { getStatementSettings(statement: ts.Statement): StatementSettings; needStripConstFromConstEnum(constEnum: ts.EnumDeclaration): boolean; needStripImportFromImportTypeNode(importType: ts.ImportTypeNode): boolean; resolveIdentifierName(identifier: ts.Identifier | ts.QualifiedName | ts.PropertyAccessEntityNameExpression): string | null; } export type OutputParams = OutputHelpers & OutputInputData; export interface OutputOptions { umdModuleName?: string; sortStatements?: boolean; noBanner?: boolean; } export function generateOutput(params: OutputParams, options: OutputOptions = {}): string { const resultOutputParts: string[] = []; if (!options.noBanner) { resultOutputParts.push(`// Generated by dts-bundle-generator v${packageVersion()}`); } if (params.typesReferences.size !== 0) { const header = generateReferenceTypesDirective(Array.from(params.typesReferences)); resultOutputParts.push(header); } if (params.imports.size !== 0) { // we need to have sorted imports of libraries to have more "stable" output const sortedEntries = Array.from(params.imports.entries()).sort((firstEntry: [string, ModuleImportsSet], secondEntry: [string, ModuleImportsSet]) => { return firstEntry[0].localeCompare(secondEntry[0]); }); const importsArray: string[] = []; for (const [libraryName, libraryImports] of sortedEntries) { importsArray.push(...generateImports(libraryName, libraryImports)); } if (importsArray.length !== 0) { resultOutputParts.push(importsArray.join('\n')); } } const statements = params.statements.map((statement: ts.Statement) => getStatementText( statement, Boolean(options.sortStatements), params )); if (options.sortStatements) { statements.sort(compareStatementText); } if (statements.length !== 0) { resultOutputParts.push(statementsTextToString(statements)); } if (params.wrappedNamespaces.size !== 0) { resultOutputParts.push( Array.from(params.wrappedNamespaces.entries()) .map(([namespaceName, exportedNames]: [string, Map]) => { return `declare namespace ${namespaceName} {\n\texport { ${ Array.from(exportedNames.entries()) .map(([exportedName, localName]: [string, string]) => renamedExportValue(exportedName, localName)) .sort() .join(', ') } };\n}`; }) .join('\n') ); } if (params.renamedExports.size !== 0) { resultOutputParts.push(`export {\n\t${ Array.from(params.renamedExports.entries()) .map(([exportedName, localName]: [string, string]) => renamedExportValue(exportedName, localName)) .sort() .join(',\n\t') },\n};`); } if (options.umdModuleName !== undefined) { resultOutputParts.push(`export as namespace ${options.umdModuleName};`); } // this is used to prevent importing non-exported nodes // see https://stackoverflow.com/questions/52583603/intentional-that-export-shuts-off-automatic-export-of-all-symbols-from-a-ty resultOutputParts.push(`export {};\n`); return resultOutputParts.join('\n\n'); } interface StatementText { text: string; sortingValue: string; } function statementsTextToString(statements: StatementText[]): string { const statementsText = statements.map(statement => statement.text).join('\n'); return spacesToTabs(prettifyStatementsText(statementsText)); } function renamedExportValue(exportedName: string, localName: string): string { return exportedName !== localName ? `${localName} as ${exportedName}` : exportedName; } function renamedImportValue(importedName: string, localName: string): string { return importedName !== localName ? `${importedName} as ${localName}` : importedName; } function prettifyStatementsText(statementsText: string): string { const sourceFile = ts.createSourceFile('output.d.ts', statementsText, ts.ScriptTarget.Latest, false, ts.ScriptKind.TS); const printer = ts.createPrinter( { newLine: ts.NewLineKind.LineFeed, removeComments: false, } ); return printer.printFile(sourceFile).trim(); } function compareStatementText(a: StatementText, b: StatementText): number { if (a.sortingValue > b.sortingValue) { return 1; } else if (a.sortingValue < b.sortingValue) { return -1; } return 0; } function recreateEntityName(node: ts.EntityName, helpers: OutputHelpers): ts.EntityName { const resolvedName = helpers.resolveIdentifierName(node); if (resolvedName !== null && resolvedName !== node.getText()) { const identifiers = resolvedName.split('.'); let result: ts.EntityName = ts.factory.createIdentifier(identifiers[0]); for (let index = 1; index < identifiers.length; index += 1) { result = ts.factory.createQualifiedName( result, ts.factory.createIdentifier(identifiers[index]) ); } return result; } return node; } function getStatementText(statement: ts.Statement, includeSortingValue: boolean, helpers: OutputHelpers): StatementText { const { shouldHaveExportKeyword, shouldHaveJSDoc } = helpers.getStatementSettings(statement); // re-export statements do not contribute to top-level names scope so we don't need to resolve their identifiers const needResolveIdentifiers = !ts.isExportDeclaration(statement) || statement.moduleSpecifier === undefined; const printer = ts.createPrinter( { newLine: ts.NewLineKind.LineFeed, removeComments: false, }, { // eslint-disable-next-line complexity substituteNode: (hint: ts.EmitHint, node: ts.Node) => { if (node.parent === undefined) { return node; } if (needResolveIdentifiers) { if (ts.isPropertyAccessExpression(node)) { const resolvedName = helpers.resolveIdentifierName(node as ts.PropertyAccessEntityNameExpression); if (resolvedName !== null && resolvedName !== node.getText()) { const identifiers = resolvedName.split('.'); let result: ts.PropertyAccessExpression | ts.Identifier = ts.factory.createIdentifier(identifiers[0]); for (let index = 1; index < identifiers.length; index += 1) { result = ts.factory.createPropertyAccessExpression( result as ts.PropertyAccessExpression, ts.factory.createIdentifier(identifiers[index]) ); } return result; } return node; } if (ts.isIdentifier(node) || ts.isQualifiedName(node)) { // QualifiedName and PropertyAccessExpression are handled separately if (ts.isIdentifier(node) && (ts.isQualifiedName(node.parent) || ts.isPropertyAccessExpression(node.parent))) { return node; } if (ts.isIdentifier(node) && ts.isImportTypeNode(node.parent) && node.parent.qualifier === node) { // identifiers in dynamic imports should be ignored as they don't use local scope return node; } return recreateEntityName(node, helpers); } } // `import('module').Qualifier` or `typeof import('module').Qualifier` if (ts.isImportTypeNode(node) && node.qualifier !== undefined && helpers.needStripImportFromImportTypeNode(node)) { const newQualifier = recreateEntityName(node.qualifier, helpers); if (node.isTypeOf) { return ts.factory.createTypeQueryNode(newQualifier); } return ts.factory.createTypeReferenceNode(newQualifier, node.typeArguments); } if (node !== statement) { return node; } const modifiersMap = modifiersToMap(getModifiers(node)); if ( ts.isEnumDeclaration(node) && modifiersMap[ts.SyntaxKind.ConstKeyword] && helpers.needStripConstFromConstEnum(node) ) { modifiersMap[ts.SyntaxKind.ConstKeyword] = false; } const nodeName = getNodeName(node); const resolvedStatementName = nodeName !== undefined ? helpers.resolveIdentifierName(nodeName as ts.Identifier) || undefined : undefined; // strip the `default` keyword from node regardless if (modifiersMap[ts.SyntaxKind.DefaultKeyword]) { modifiersMap[ts.SyntaxKind.DefaultKeyword] = false; if (ts.isClassDeclaration(node)) { // for classes we need to replace `default` with `declare` instead otherwise it will produce an invalid syntax modifiersMap[ts.SyntaxKind.DeclareKeyword] = true; } } if (!shouldHaveExportKeyword) { modifiersMap[ts.SyntaxKind.ExportKeyword] = false; } else { modifiersMap[ts.SyntaxKind.ExportKeyword] = true; } // for some reason TypeScript allows to not write `declare` keyword for ClassDeclaration, FunctionDeclaration and VariableDeclaration // if it already has `export` keyword - so we need to add it // to avoid TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. if (!modifiersMap[ts.SyntaxKind.ExportKeyword] && (ts.isClassDeclaration(node) || ts.isFunctionDeclaration(node) || ts.isVariableStatement(node) || ts.isEnumDeclaration(node) || ts.isModuleDeclaration(node) ) ) { modifiersMap[ts.SyntaxKind.DeclareKeyword] = true; } return recreateRootLevelNodeWithModifiers(node, modifiersMap, resolvedStatementName, shouldHaveJSDoc); }, } ); const statementText = printer.printNode(ts.EmitHint.Unspecified, statement, statement.getSourceFile()).trim(); let sortingValue = ''; if (includeSortingValue) { // it looks like there is no way to get node's text without a comment at the same time as printing it // so to get the actual node text we have to parse it again // hopefully it shouldn't take too long (we don't need to do type check, just parse the AST) // also let's do it opt-in so if someone isn't using node sorting it won't affect them const tempSourceFile = ts.createSourceFile('temp.d.ts', statementText, ts.ScriptTarget.ESNext); // we certainly know that there should be 1 statement at the root level (the printed statement) sortingValue = tempSourceFile.getChildren()[0].getText(); } return { text: statementText, sortingValue }; } function generateImports(libraryName: string, imports: ModuleImportsSet): string[] { const fromEnding = `from '${libraryName}';`; const result: string[] = []; // sort to make output more "stable" if (imports.nsImport !== null) { result.push(`import * as ${imports.nsImport} ${fromEnding}`); } Array.from(imports.requireImports).sort().forEach((importName: string) => result.push(`import ${importName} = require('${libraryName}');`)); Array.from(imports.defaultImports).sort().forEach((importName: string) => result.push(`import ${importName} ${fromEnding}`)); if (imports.namedImports.size !== 0) { result.push(`import { ${ Array.from(imports.namedImports.entries()) .map(([localName, importedName]: [string, string]) => renamedImportValue(importedName, localName)) .sort() .join(', ') } } ${fromEnding}`); } if (imports.reExports.size !== 0) { result.push(`export { ${ Array.from(imports.reExports.entries()) .map(([localName, importedName]: [string, string]) => renamedImportValue(importedName, localName)) .sort() .join(', ') } } ${fromEnding}`); } return result; } function generateReferenceTypesDirective(libraries: string[]): string { return libraries.sort().map((library: string) => { return `/// `; }).join('\n'); } function spacesToTabs(text: string): string { // eslint-disable-next-line no-regex-spaces return text.replace(/^( )+/gm, (substring: string) => { return '\t'.repeat(substring.length / 4); }); } timocov-dts-bundle-generator-c69ff0d/src/get-compiler-options.ts000066400000000000000000000045201461132021400251320ustar00rootroot00000000000000import * as ts from 'typescript'; import * as path from 'path'; import { getAbsolutePath } from './helpers/get-absolute-path'; import { checkDiagnosticsErrors } from './helpers/check-diagnostics-errors'; import { verboseLog } from './logger'; const enum Constants { NoInputsWereFoundDiagnosticCode = 18003, } const parseConfigHost: ts.ParseConfigHost = { useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames, readDirectory: ts.sys.readDirectory, fileExists: ts.sys.fileExists, readFile: ts.sys.readFile, }; export function getCompilerOptions(inputFileNames: readonly string[], preferredConfigPath?: string): ts.CompilerOptions { const configFileName = preferredConfigPath !== undefined ? preferredConfigPath : findConfig(inputFileNames); verboseLog(`Using config: ${configFileName}`); const configParseResult = ts.readConfigFile(configFileName, ts.sys.readFile); checkDiagnosticsErrors(configParseResult.error !== undefined ? [configParseResult.error] : [], 'Error while processing tsconfig file'); const compilerOptionsParseResult = ts.parseJsonConfigFileContent( configParseResult.config, parseConfigHost, path.resolve(path.dirname(configFileName)), undefined, getAbsolutePath(configFileName) ); // we don't want to raise an error if no inputs found in a config file // because this error is mostly for CLI, but we'll pass an inputs in createProgram // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison const diagnostics = compilerOptionsParseResult.errors.filter((d: ts.Diagnostic) => d.code !== Constants.NoInputsWereFoundDiagnosticCode); checkDiagnosticsErrors(diagnostics, 'Error while processing tsconfig compiler options'); return compilerOptionsParseResult.options; } function findConfig(inputFiles: readonly string[]): string { if (inputFiles.length !== 1) { throw new Error('Cannot find tsconfig for multiple files. Please specify preferred tsconfig file'); } // input file could be a relative path to the current path // and desired config could be outside of current cwd folder // so we have to provide absolute path to find config until the root const searchPath = getAbsolutePath(inputFiles[0]); const configFileName = ts.findConfigFile(searchPath, ts.sys.fileExists); if (!configFileName) { throw new Error(`Cannot find config file for file ${searchPath}`); } return configFileName; } timocov-dts-bundle-generator-c69ff0d/src/helpers/000077500000000000000000000000001461132021400221435ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/src/helpers/check-diagnostics-errors.ts000066400000000000000000000016171461132021400274140ustar00rootroot00000000000000import * as ts from 'typescript'; import { errorLog } from '../logger'; const formatDiagnosticsHost: ts.FormatDiagnosticsHost = { getCanonicalFileName: (fileName: string) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(), getCurrentDirectory: ts.sys.getCurrentDirectory, getNewLine: () => ts.sys.newLine, }; export function checkProgramDiagnosticsErrors(program: ts.Program): void { if (!program.getCompilerOptions().declaration) { throw new Error(`Something went wrong - the program doesn't have declaration option enabled`); } checkDiagnosticsErrors(ts.getPreEmitDiagnostics(program), 'Compiled with errors'); } export function checkDiagnosticsErrors(diagnostics: readonly ts.Diagnostic[], failMessage: string): void { if (diagnostics.length === 0) { return; } errorLog(ts.formatDiagnostics(diagnostics, formatDiagnosticsHost).trim()); throw new Error(failMessage); } timocov-dts-bundle-generator-c69ff0d/src/helpers/fix-path.ts000066400000000000000000000001611461132021400242310ustar00rootroot00000000000000export function fixPath(path: string): string { // special case for windows return path.replace(/\\/g, '/'); } timocov-dts-bundle-generator-c69ff0d/src/helpers/get-absolute-path.ts000066400000000000000000000005031461132021400260360ustar00rootroot00000000000000import * as path from 'path'; import * as process from 'process'; import { fixPath } from './fix-path'; export function getAbsolutePath(fileName: string, cwd?: string): string { if (!path.isAbsolute(fileName)) { fileName = path.join(cwd !== undefined ? cwd : process.cwd(), fileName); } return fixPath(fileName); } timocov-dts-bundle-generator-c69ff0d/src/helpers/measure-time.ts000066400000000000000000000007111461132021400251070ustar00rootroot00000000000000/** * @param param function to execute * @returns execution time (in milliseconds) */ export function measureTime(func: () => void): number { const startAt = process.hrtime(); func(); const resultValue = process.hrtime(startAt); return secondsToMs(resultValue[0]) + nanosecondsToMs(resultValue[1]); } function secondsToMs(value: number): number { return value * 1000; } function nanosecondsToMs(value: number): number { return value / 1000000; } timocov-dts-bundle-generator-c69ff0d/src/helpers/node-modules.ts000066400000000000000000000014161461132021400251100ustar00rootroot00000000000000const nodeModulesFolderName = 'node_modules/'; const libraryNameRegex = /node_modules\/((?:(?=@)[^/]+\/[^/]+|[^/]+))\//; export function getLibraryName(fileName: string): string | null { const lastNodeModulesIndex = fileName.lastIndexOf(nodeModulesFolderName); if (lastNodeModulesIndex === -1) { return null; } const match = libraryNameRegex.exec(fileName.slice(lastNodeModulesIndex)); if (match === null) { return null; } return match[1]; } export function getTypesLibraryName(path: string): string | null { const libraryName = getLibraryName(path); if (libraryName === null) { return null; } const typesFolderPrefix = '@types/'; if (!libraryName.startsWith(typesFolderPrefix)) { return null; } return libraryName.substring(typesFolderPrefix.length); } timocov-dts-bundle-generator-c69ff0d/src/helpers/package-version.ts000066400000000000000000000010451461132021400255710ustar00rootroot00000000000000import * as fs from 'fs'; import * as path from 'path'; export function packageVersion(): string { let dirName = __dirname; while (dirName.length !== 0) { const packageJsonFilePath = path.join(dirName, 'package.json'); if (fs.existsSync(packageJsonFilePath)) { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-var-requires return require(packageJsonFilePath).version as string; } dirName = path.join(dirName, '..'); } throw new Error(`Cannot find up package.json in ${__dirname}`); } timocov-dts-bundle-generator-c69ff0d/src/helpers/typescript.ts000066400000000000000000000541011461132021400247220ustar00rootroot00000000000000import * as ts from 'typescript'; import { warnLog } from '../logger'; const namedDeclarationKinds = [ ts.SyntaxKind.InterfaceDeclaration, ts.SyntaxKind.ClassDeclaration, ts.SyntaxKind.EnumDeclaration, ts.SyntaxKind.TypeAliasDeclaration, ts.SyntaxKind.ModuleDeclaration, ts.SyntaxKind.FunctionDeclaration, ts.SyntaxKind.VariableDeclaration, ts.SyntaxKind.PropertySignature, ts.SyntaxKind.NamespaceExport, ts.SyntaxKind.NamespaceImport, ts.SyntaxKind.ExportSpecifier, ts.SyntaxKind.BindingElement, ]; export type NodeName = ts.DeclarationName | ts.DefaultKeyword | ts.QualifiedName | ts.PropertyAccessExpression | ts.BindingPattern; export function isNodeNamedDeclaration(node: ts.Node): node is ts.NamedDeclaration { return namedDeclarationKinds.indexOf(node.kind) !== -1; } export function hasNodeModifier(node: ts.Node, modifier: ts.SyntaxKind): boolean { const modifiers = getModifiers(node); return Boolean(modifiers && modifiers.some((nodeModifier: ts.Modifier) => nodeModifier.kind === modifier)); } export function getNodeName(node: ts.Node): NodeName | undefined { const nodeName = (node as unknown as ts.NamedDeclaration).name; if (nodeName === undefined) { const modifiers = getModifiers(node); const defaultModifier = modifiers?.find((mod: ts.Modifier) => mod.kind === ts.SyntaxKind.DefaultKeyword); if (defaultModifier !== undefined) { return defaultModifier as NodeName; } } return nodeName; } interface TypeCheckerCompat extends ts.TypeChecker { // this method will be added in the further typescript releases // see https://github.com/microsoft/TypeScript/pull/56193 getMergedSymbol(symbol: ts.Symbol): ts.Symbol; } export function getActualSymbol(symbol: ts.Symbol, typeChecker: ts.TypeChecker): ts.Symbol { if (symbol.flags & ts.SymbolFlags.Alias) { symbol = typeChecker.getAliasedSymbol(symbol); } return (typeChecker as TypeCheckerCompat).getMergedSymbol(symbol); } export function getDeclarationNameSymbol(name: NodeName, typeChecker: ts.TypeChecker): ts.Symbol | null { const symbol = typeChecker.getSymbolAtLocation(name); if (symbol === undefined) { return null; } return getActualSymbol(symbol, typeChecker); } export function splitTransientSymbol(symbol: ts.Symbol, typeChecker: ts.TypeChecker): Set { // actually I think we even don't need to operate/use "Transient" symbols anywhere // it's kind of aliased symbol, but just merged // but it's hard to refractor everything to use array of symbols instead of just symbol // so let's fix it for some places if ((symbol.flags & ts.SymbolFlags.Transient) === 0) { return new Set([symbol]); } // "Transient" symbol is kinda "merged" symbol // I don't really know is this way to "split" is correct // but it seems that it works for now ¯\_(ツ)_/¯ const declarations = getDeclarationsForSymbol(symbol); const result = new Set(); for (const declaration of declarations) { if (!isNodeNamedDeclaration(declaration) || declaration.name === undefined) { continue; } const sym = typeChecker.getSymbolAtLocation(declaration.name); if (sym === undefined) { continue; } result.add(getActualSymbol(sym, typeChecker)); } return result; } /** * @see https://github.com/Microsoft/TypeScript/blob/f7c4fefeb62416c311077a699cc15beb211c25c9/src/compiler/utilities.ts#L626-L628 */ function isGlobalScopeAugmentation(module: ts.ModuleDeclaration): boolean { return Boolean(module.flags & ts.NodeFlags.GlobalAugmentation); } /** * Returns whether node is ambient module declaration (declare module "name" or declare global) * @see https://github.com/Microsoft/TypeScript/blob/f7c4fefeb62416c311077a699cc15beb211c25c9/src/compiler/utilities.ts#L588-L590 */ export function isAmbientModule(node: ts.Node): boolean { return ts.isModuleDeclaration(node) && (node.name.kind === ts.SyntaxKind.StringLiteral || isGlobalScopeAugmentation(node)); } /** * Returns whether node is `declare module` ModuleDeclaration (not `declare global` or `namespace`) */ export function isDeclareModule(node: ts.Node): node is ts.ModuleDeclaration { // `declare module ""`, `declare global` and `namespace {}` are ModuleDeclaration // but here we need to check only `declare module` statements return ts.isModuleDeclaration(node) && !(node.flags & ts.NodeFlags.Namespace) && !isGlobalScopeAugmentation(node); } /** * Returns whether statement is `declare global` ModuleDeclaration */ export function isDeclareGlobalStatement(statement: ts.Statement): statement is ts.ModuleDeclaration { return ts.isModuleDeclaration(statement) && isGlobalScopeAugmentation(statement); } export function getDeclarationsForSymbol(symbol: ts.Symbol): ts.Declaration[] { const result: ts.Declaration[] = []; if (symbol.declarations !== undefined) { result.push(...symbol.declarations); } if (symbol.valueDeclaration !== undefined) { // push valueDeclaration might be already in declarations array // so let's check first to avoid duplication nodes if (!result.includes(symbol.valueDeclaration)) { result.push(symbol.valueDeclaration); } } return result; } export const enum ExportType { CommonJS, ES6Named, ES6Default, } export interface SourceFileExport { exportedName: string; symbol: ts.Symbol; originalSymbol: ts.Symbol; type: ExportType; } export function getExportsForSourceFile(typeChecker: ts.TypeChecker, sourceFileSymbol: ts.Symbol): SourceFileExport[] { if (sourceFileSymbol.exports !== undefined) { const commonJsExport = sourceFileSymbol.exports.get(ts.InternalSymbolName.ExportEquals); if (commonJsExport !== undefined) { const symbol = getActualSymbol(commonJsExport, typeChecker); return [ { symbol, originalSymbol: commonJsExport, type: ExportType.CommonJS, exportedName: '', }, ]; } } const result = typeChecker .getExportsOfModule(sourceFileSymbol) .map((symbol: ts.Symbol) => ({ symbol, originalSymbol: symbol, exportedName: symbol.name, type: ExportType.ES6Named })); if (sourceFileSymbol.exports !== undefined) { const defaultExportSymbol = sourceFileSymbol.exports.get(ts.InternalSymbolName.Default); if (defaultExportSymbol !== undefined) { const defaultExport = result.find((exp: SourceFileExport) => exp.symbol === defaultExportSymbol); if (defaultExport !== undefined) { defaultExport.type = ExportType.ES6Default; } else { // it seems that default export is always returned by getExportsOfModule // but let's add it to be sure add if there is no such export result.push({ symbol: defaultExportSymbol, originalSymbol: defaultExportSymbol, type: ExportType.ES6Default, exportedName: 'default', }); } } } const symbolsMergingResolvedExports: SourceFileExport[] = []; result.forEach((exp: SourceFileExport) => { exp.symbol = getActualSymbol(exp.symbol, typeChecker); const symbolsDeclarations = getDeclarationsForSymbol(exp.symbol); const importSpecifierDeclaration = symbolsDeclarations.find(ts.isImportSpecifier); if (symbolsDeclarations.length > 1 && importSpecifierDeclaration !== undefined) { // most likely this export is part of the symbol merging situation // where one of the declarations is the imported value but the other is declared locally // in this case we need to add an extra export to the exports list to make sure that it is marked as "exported" // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion const referencedModule = resolveReferencedModule(importSpecifierDeclaration.parent.parent.parent as ts.ImportDeclaration, typeChecker); if (referencedModule !== null) { const referencedModuleSymbol = getNodeSymbol(referencedModule, typeChecker); if (referencedModuleSymbol !== null) { const importedName = (importSpecifierDeclaration.propertyName ?? importSpecifierDeclaration.name).getText(); const exportedItemSymbol = typeChecker.getExportsOfModule(referencedModuleSymbol).find((exportSymbol: ts.Symbol) => exportSymbol.getName() === importedName); if (exportedItemSymbol !== undefined) { symbolsMergingResolvedExports.push({ ...exp, symbol: getActualSymbol(exportedItemSymbol, typeChecker), }); } } } } }); return [...result, ...symbolsMergingResolvedExports]; } export function resolveIdentifier(typeChecker: ts.TypeChecker, identifier: ts.Identifier): ts.NamedDeclaration | undefined { const symbol = getDeclarationNameSymbol(identifier, typeChecker); if (symbol === null) { return undefined; } return resolveDeclarationByIdentifierSymbol(symbol); } function resolveDeclarationByIdentifierSymbol(identifierSymbol: ts.Symbol): ts.NamedDeclaration | undefined { const declarations = getDeclarationsForSymbol(identifierSymbol); if (declarations.length === 0) { return undefined; } const decl = declarations[0]; if (!isNodeNamedDeclaration(decl)) { return undefined; } return decl; } export function getExportsForStatement( exportedSymbols: readonly SourceFileExport[], typeChecker: ts.TypeChecker, statement: ts.Statement | ts.NamedDeclaration ): SourceFileExport[] { if (ts.isVariableStatement(statement)) { if (statement.declarationList.declarations.length === 0) { return []; } const firstDeclarationExports = getExportsForName( exportedSymbols, typeChecker, statement.declarationList.declarations[0].name ); const allDeclarationsHaveSameExportType = statement.declarationList.declarations.every((variableDecl: ts.VariableDeclaration) => { // all declaration should have the same export type // TODO: for now it's not supported to have different type of exports return getExportsForName(exportedSymbols, typeChecker, variableDecl.name)[0]?.type === firstDeclarationExports[0]?.type; }); if (!allDeclarationsHaveSameExportType) { // log warn? return []; } return firstDeclarationExports; } const nodeName = getNodeName(statement); if (nodeName === undefined) { return []; } return getExportsForName(exportedSymbols, typeChecker, nodeName); } function getExportsForName( exportedSymbols: readonly SourceFileExport[], typeChecker: ts.TypeChecker, name: NodeName ): SourceFileExport[] { if (ts.isArrayBindingPattern(name) || ts.isObjectBindingPattern(name)) { // TODO: binding patterns in variable declarations are not supported for now // see https://github.com/microsoft/TypeScript/issues/30598 also return []; } const declarationSymbol = typeChecker.getSymbolAtLocation(name); return exportedSymbols.filter((rootExport: SourceFileExport) => rootExport.symbol === declarationSymbol); } export type ModifiersMap = Record; const modifiersPriority: Partial> = { [ts.SyntaxKind.ExportKeyword]: 4, [ts.SyntaxKind.DefaultKeyword]: 3, [ts.SyntaxKind.DeclareKeyword]: 2, [ts.SyntaxKind.AsyncKeyword]: 1, [ts.SyntaxKind.ConstKeyword]: 1, }; export function modifiersToMap(modifiers: (readonly ts.Modifier[]) | undefined | null): ModifiersMap { modifiers = modifiers || []; return modifiers.reduce( (result: ModifiersMap, modifier: ts.Modifier) => { result[modifier.kind] = true; return result; }, // eslint-disable-next-line @typescript-eslint/consistent-type-assertions {} as Record ); } export function modifiersMapToArray(modifiersMap: ModifiersMap): ts.Modifier[] { return Object.entries(modifiersMap) .filter(([kind, include]) => include) .map(([kind]) => { // we don't care about decorators here as it is not possible to have them in declaration files return ts.factory.createModifier(Number(kind)); }) .sort((a: ts.Modifier, b: ts.Modifier) => { // note `|| 0` is here as a fallback in the case if the compiler adds a new modifier // but the tool isn't updated yet const aValue = modifiersPriority[a.kind as ts.ModifierSyntaxKind] || 0; const bValue = modifiersPriority[b.kind as ts.ModifierSyntaxKind] || 0; return bValue - aValue; }); } export function recreateRootLevelNodeWithModifiers(node: ts.Node, modifiersMap: ModifiersMap, newName?: string, keepComments: boolean = true): ts.Node { const newNode = recreateRootLevelNodeWithModifiersImpl(node, modifiersMap, newName); if (keepComments) { ts.setCommentRange(newNode, ts.getCommentRange(node)); } return newNode; } // eslint-disable-next-line complexity function recreateRootLevelNodeWithModifiersImpl(node: ts.Node, modifiersMap: ModifiersMap, newName?: string): ts.Node { const modifiers = modifiersMapToArray(modifiersMap); if (ts.isArrowFunction(node)) { return ts.factory.createArrowFunction( modifiers, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body ); } if (ts.isClassDeclaration(node)) { return ts.factory.createClassDeclaration( modifiers, newName || node.name, node.typeParameters, node.heritageClauses, node.members ); } if (ts.isClassExpression(node)) { return ts.factory.createClassExpression( modifiers, newName || node.name, node.typeParameters, node.heritageClauses, node.members ); } if (ts.isEnumDeclaration(node)) { return ts.factory.createEnumDeclaration( modifiers, newName || node.name, node.members ); } if (ts.isExportAssignment(node)) { return ts.factory.createExportAssignment( modifiers, node.isExportEquals, node.expression ); } if (ts.isExportDeclaration(node)) { interface Ts53CompatExportDeclaration extends ts.ExportDeclaration { attributes?: ts.ExportDeclaration['assertClause']; } return ts.factory.createExportDeclaration( modifiers, node.isTypeOnly, node.exportClause, node.moduleSpecifier, // eslint-disable-next-line deprecation/deprecation (node as Ts53CompatExportDeclaration).attributes || node.assertClause ); } if (ts.isFunctionDeclaration(node)) { return ts.factory.createFunctionDeclaration( modifiers, node.asteriskToken, newName || node.name, node.typeParameters, node.parameters, node.type, node.body ); } if (ts.isFunctionExpression(node)) { return ts.factory.createFunctionExpression( modifiers, node.asteriskToken, newName || node.name, node.typeParameters, node.parameters, node.type, node.body ); } if (ts.isImportDeclaration(node)) { interface Ts53CompatImportDeclaration extends ts.ImportDeclaration { attributes?: ts.ImportDeclaration['assertClause']; } return ts.factory.createImportDeclaration( modifiers, node.importClause, node.moduleSpecifier, // eslint-disable-next-line deprecation/deprecation (node as Ts53CompatImportDeclaration).attributes || node.assertClause ); } if (ts.isImportEqualsDeclaration(node)) { return ts.factory.createImportEqualsDeclaration( modifiers, node.isTypeOnly, newName || node.name, node.moduleReference ); } if (ts.isInterfaceDeclaration(node)) { return ts.factory.createInterfaceDeclaration( modifiers, newName || node.name, node.typeParameters, node.heritageClauses, node.members ); } if (ts.isModuleDeclaration(node)) { return ts.factory.createModuleDeclaration( modifiers, node.name, node.body, node.flags ); } if (ts.isTypeAliasDeclaration(node)) { return ts.factory.createTypeAliasDeclaration( modifiers, newName || node.name, node.typeParameters, node.type ); } if (ts.isVariableStatement(node)) { return ts.factory.createVariableStatement( modifiers, node.declarationList ); } throw new Error(`Unknown top-level node kind (with modifiers): ${ts.SyntaxKind[node.kind]}. If you're seeing this error, please report a bug on https://github.com/timocov/dts-bundle-generator/issues`); } export function getModifiers(node: ts.Node): readonly ts.Modifier[] | undefined { if (!ts.canHaveModifiers(node)) { return undefined; } return ts.getModifiers(node); } export function getRootSourceFile(program: ts.Program, rootFileName: string): ts.SourceFile { if (program.getRootFileNames().indexOf(rootFileName) === -1) { throw new Error(`There is no such root file ${rootFileName}`); } const sourceFile = program.getSourceFile(rootFileName); if (sourceFile === undefined) { throw new Error(`Cannot get source file for root file ${rootFileName}`); } return sourceFile; } export function getNodeOwnSymbol(node: ts.Node, typeChecker: ts.TypeChecker): ts.Symbol { const nodeSymbol = typeChecker.getSymbolAtLocation(node); if (nodeSymbol === undefined) { throw new Error(`Cannot find symbol for node "${node.getText()}" in "${node.parent.getText()}" from "${node.getSourceFile().fileName}"`); } return nodeSymbol; } export function getNodeSymbol(node: ts.Node, typeChecker: ts.TypeChecker): ts.Symbol | null { if (ts.isSourceFile(node)) { const fileSymbol = typeChecker.getSymbolAtLocation(node); // a source file might not have a symbol in case of no exports in that file if (fileSymbol === undefined) { return null; } return getActualSymbol(fileSymbol, typeChecker); } const nodeName = getNodeName(node); if (nodeName === undefined) { return null; } return getDeclarationNameSymbol(nodeName, typeChecker); } export function getClosestModuleLikeNode(node: ts.Node): ts.SourceFile | ts.ModuleDeclaration { // we need to find a module block and return its module declaration // we don't need to handle empty modules/modules with jsdoc/etc while (!ts.isModuleBlock(node) && !ts.isSourceFile(node)) { node = node.parent; } return ts.isSourceFile(node) ? node : node.parent; } export function getClosestSourceFileLikeNode(node: ts.Node): ts.SourceFile | ts.ModuleDeclaration { // we need to find a module block and return its module declaration // we don't need to handle empty modules/modules with jsdoc/etc while (!(ts.isModuleBlock(node) && ts.isStringLiteral(node.parent.name)) && !ts.isSourceFile(node)) { node = node.parent; } return ts.isSourceFile(node) ? node : node.parent; } export type NodeWithReferencedModule = | ts.ExportDeclaration | ts.ImportDeclaration | ts.ImportEqualsDeclaration | ts.ImportTypeNode | ts.ModuleDeclaration ; export function resolveReferencedModule(node: NodeWithReferencedModule, typeChecker: ts.TypeChecker): ts.SourceFile | ts.ModuleDeclaration | null { let moduleName: ts.Expression | ts.LiteralTypeNode | undefined; if (ts.isExportDeclaration(node) || ts.isImportDeclaration(node)) { moduleName = node.moduleSpecifier; } else if (ts.isModuleDeclaration(node)) { moduleName = node.name; } else if (ts.isImportEqualsDeclaration(node)) { if (ts.isExternalModuleReference(node.moduleReference)) { moduleName = node.moduleReference.expression; } } else if (ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal)) { moduleName = node.argument.literal; } if (moduleName === undefined) { return null; } const moduleSymbol = typeChecker.getSymbolAtLocation(moduleName); if (moduleSymbol === undefined) { return null; } const symbol = getActualSymbol(moduleSymbol, typeChecker); if (symbol.valueDeclaration === undefined) { return null; } return ts.isSourceFile(symbol.valueDeclaration) || ts.isModuleDeclaration(symbol.valueDeclaration) ? symbol.valueDeclaration : null; } export function getImportModuleName(imp: ts.ImportEqualsDeclaration | ts.ImportDeclaration | ts.ExportDeclaration): string | null { if (ts.isImportDeclaration(imp)) { return imp.importClause === undefined ? null : (imp.moduleSpecifier as ts.StringLiteral).text ; } if (ts.isExportDeclaration(imp)) { return imp.moduleSpecifier === undefined ? null : (imp.moduleSpecifier as ts.StringLiteral).text ; } if (ts.isExternalModuleReference(imp.moduleReference)) { if (!ts.isStringLiteral(imp.moduleReference.expression)) { warnLog(`Cannot handle non string-literal-like import expression: ${imp.moduleReference.expression.getText()}`); return null; } return imp.moduleReference.expression.text; } return null; } /** * Returns a symbol that an {@link importExportSpecifier} node references to. * * For example, for given `export { Value }` it returns a declaration of `Value` whatever it is (import statement, interface declaration, etc). */ export function getImportExportReferencedSymbol(importExportSpecifier: ts.ExportSpecifier | ts.ImportSpecifier, typeChecker: ts.TypeChecker): ts.Symbol { return importExportSpecifier.propertyName !== undefined // eslint-disable-next-line @typescript-eslint/no-non-null-assertion ? typeChecker.getSymbolAtLocation(importExportSpecifier.propertyName)! // eslint-disable-next-line @typescript-eslint/no-non-null-assertion : typeChecker.getImmediateAliasedSymbol(typeChecker.getSymbolAtLocation(importExportSpecifier.name)!)! ; } export function getSymbolExportStarDeclarations(symbol: ts.Symbol): ts.ExportDeclaration[] { if (symbol.escapedName !== ts.InternalSymbolName.ExportStar) { throw new Error(`Only ExportStar symbol can have export star declaration, but got ${symbol.escapedName}`); } // this means that an export contains `export * from 'module'` statement return getDeclarationsForSymbol(symbol).filter((decl: ts.Declaration): decl is ts.ExportDeclaration => ts.isExportDeclaration(decl) && decl.moduleSpecifier !== undefined); } export function getDeclarationsForExportedValues(exp: ts.ExportAssignment | ts.ExportDeclaration, typeChecker: ts.TypeChecker): ts.Declaration[] { const nodeForSymbol = ts.isExportAssignment(exp) ? exp.expression : exp.moduleSpecifier; if (nodeForSymbol === undefined) { return []; } const symbolForExpression = typeChecker.getSymbolAtLocation(nodeForSymbol); if (symbolForExpression === undefined) { return []; } const symbol = getActualSymbol(symbolForExpression, typeChecker); return getDeclarationsForSymbol(symbol); } export function resolveGlobalName(typeChecker: ts.TypeChecker, name: string): ts.Symbol | undefined { interface Ts54CompatTypeChecker extends ts.TypeChecker { resolveName(name: string, location: ts.Node | undefined, meaning: ts.SymbolFlags, excludeGlobals: boolean): ts.Symbol | undefined; } // this value isn't available in all typescript versions so lets assign its value here instead const tsSymbolFlagsAll = /* ts.SymbolFlags.All */ -1 as ts.SymbolFlags; // see https://github.com/microsoft/TypeScript/pull/56932 return (typeChecker as Ts54CompatTypeChecker).resolveName(name, undefined, tsSymbolFlagsAll, false); } timocov-dts-bundle-generator-c69ff0d/src/logger.ts000066400000000000000000000022611461132021400223310ustar00rootroot00000000000000const enum LogLevel { Verbose, Normal, Warning, Error, } export function verboseLog(message: string): void { logMessage(message, LogLevel.Verbose); } export function normalLog(message: string): void { logMessage(message, LogLevel.Normal); } export function warnLog(message: string): void { logMessage(message, LogLevel.Warning); } export function errorLog(message: string): void { logMessage(message, LogLevel.Error); } let currentLogLevel = LogLevel.Error; export function enableVerbose(): void { currentLogLevel = LogLevel.Verbose; normalLog('Verbose log enabled'); } export function enableNormalLog(): void { currentLogLevel = LogLevel.Normal; } function logMessage(message: string, level: LogLevel = LogLevel.Verbose): void { if (level < currentLogLevel) { return; } switch (level) { case LogLevel.Error: // print red // eslint-disable-next-line no-console console.error(`\x1b[0;31m${message}\x1b[0m`); break; case LogLevel.Warning: // eslint-disable-next-line no-console console.warn(`\x1b[1;33m${message}\x1b[0m`); break; case LogLevel.Normal: case LogLevel.Verbose: // eslint-disable-next-line no-console console.log(message); } } timocov-dts-bundle-generator-c69ff0d/src/module-info.ts000066400000000000000000000133751461132021400233000ustar00rootroot00000000000000import * as path from 'path'; import * as ts from 'typescript'; import { getLibraryName, getTypesLibraryName, } from './helpers/node-modules'; import { fixPath } from './helpers/fix-path'; import { NodeWithReferencedModule, resolveReferencedModule } from './helpers/typescript'; export const enum ModuleType { ShouldBeInlined, ShouldBeImported, ShouldBeReferencedAsTypes, ShouldBeUsedForModulesOnly, } export interface UsedModuleInfoCommon { fileName: string; isExternal: boolean; } export interface InlinedModuleInfo extends UsedModuleInfoCommon { type: ModuleType.ShouldBeInlined; } export interface ImportedModuleInfo extends UsedModuleInfoCommon { type: ModuleType.ShouldBeImported; isExternal: true; } export interface ReferencedModuleInfo extends UsedModuleInfoCommon { type: ModuleType.ShouldBeReferencedAsTypes; typesLibraryName: string; isExternal: true; } export interface UsedForModulesModuleInfo extends UsedModuleInfoCommon { type: ModuleType.ShouldBeUsedForModulesOnly; isExternal: true; } export type ModuleInfo = InlinedModuleInfo | ImportedModuleInfo | ReferencedModuleInfo | UsedForModulesModuleInfo; export interface ModuleCriteria { inlinedLibraries: string[]; importedLibraries: string[] | undefined; allowedTypesLibraries: string[] | undefined; typeRoots?: string[]; } export function getFileModuleInfo(fileName: string, criteria: ModuleCriteria): ModuleInfo { return getModuleInfoImpl(fileName, fileName, criteria); } export function getReferencedModuleInfo(moduleDecl: NodeWithReferencedModule, criteria: ModuleCriteria, typeChecker: ts.TypeChecker): ModuleInfo | null { const referencedModule = resolveReferencedModule(moduleDecl, typeChecker); if (referencedModule === null) { return null; } const moduleFilePath = ts.isSourceFile(referencedModule) ? referencedModule.fileName : resolveModuleFileName(referencedModule.getSourceFile().fileName, referencedModule.name.text); return getFileModuleInfo(moduleFilePath, criteria); } export function getModuleLikeModuleInfo(moduleLike: ts.SourceFile | ts.ModuleDeclaration, criteria: ModuleCriteria, typeChecker: ts.TypeChecker): ModuleInfo { const resolvedModuleLike = ts.isSourceFile(moduleLike) ? moduleLike : resolveReferencedModule(moduleLike, typeChecker) ?? moduleLike; const fileName = ts.isSourceFile(resolvedModuleLike) ? resolvedModuleLike.fileName : resolveModuleFileName(resolvedModuleLike.getSourceFile().fileName, resolvedModuleLike.name.text); return getFileModuleInfo(fileName, criteria); } function resolveModuleFileName(currentFileName: string, moduleName: string): string { return moduleName.startsWith('.') ? fixPath(path.join(currentFileName, '..', moduleName)) : `node_modules/${moduleName}/`; } /** * @param currentFilePath Current file path - can be used to override actual path of module (e.g. with `typeRoots`) * @param originalFileName Original file name of the module * @param criteria Criteria of module info */ function getModuleInfoImpl(currentFilePath: string, originalFileName: string, criteria: ModuleCriteria): ModuleInfo { const npmLibraryName = getLibraryName(currentFilePath); if (npmLibraryName === null) { if (criteria.typeRoots !== undefined) { for (const root of criteria.typeRoots) { const relativePath = fixPath(path.relative(root, originalFileName)); if (!relativePath.startsWith('../')) { // relativePath is path relative to type root // so we should treat it as "library from node_modules/@types/" return getModuleInfoImpl(remapToTypesFromNodeModules(relativePath), originalFileName, criteria); } } } return { type: ModuleType.ShouldBeInlined, fileName: originalFileName, isExternal: false }; } const typesLibraryName = getTypesLibraryName(currentFilePath); if (shouldLibraryBeInlined(npmLibraryName, typesLibraryName, criteria.inlinedLibraries)) { return { type: ModuleType.ShouldBeInlined, fileName: originalFileName, isExternal: true }; } if (shouldLibraryBeImported(npmLibraryName, typesLibraryName, criteria.importedLibraries, criteria.allowedTypesLibraries)) { return { type: ModuleType.ShouldBeImported, fileName: originalFileName, isExternal: true }; } if (typesLibraryName !== null && isLibraryAllowed(typesLibraryName, criteria.allowedTypesLibraries)) { return { type: ModuleType.ShouldBeReferencedAsTypes, fileName: originalFileName, typesLibraryName, isExternal: true }; } return { type: ModuleType.ShouldBeUsedForModulesOnly, fileName: originalFileName, isExternal: true }; } function shouldLibraryBeInlined(npmLibraryName: string, typesLibraryName: string | null, inlinedLibraries: string[]): boolean { return isLibraryAllowed(npmLibraryName, inlinedLibraries) || typesLibraryName !== null && isLibraryAllowed(typesLibraryName, inlinedLibraries); } function shouldLibraryBeImported( npmLibraryName: string, typesLibraryName: string | null, importedLibraries: string[] | undefined, allowedTypesLibraries: string[] | undefined ): boolean { if (typesLibraryName === null) { return isLibraryAllowed(npmLibraryName, importedLibraries); } // to be imported a library from types shouldn't be allowed to be references as types // thus by default we treat all libraries as "should be imported" // but if it is a @types library then it should be imported only if it is not marked as "should be referenced as types" explicitly if (allowedTypesLibraries === undefined || !isLibraryAllowed(typesLibraryName, allowedTypesLibraries)) { return isLibraryAllowed(typesLibraryName, importedLibraries); } return false; } function isLibraryAllowed(libraryName: string, allowedArray?: string[]): boolean { return allowedArray === undefined || allowedArray.indexOf(libraryName) !== -1; } function remapToTypesFromNodeModules(pathRelativeToTypesRoot: string): string { return `node_modules/@types/${pathRelativeToTypesRoot}`; } timocov-dts-bundle-generator-c69ff0d/src/tsconfig.json000066400000000000000000000003071461132021400232100ustar00rootroot00000000000000{ "extends": "../tsconfig.options.json", "compilerOptions": { "composite": true, "declarationDir": "../dts-out", "incremental": true, "outDir": "../dist" }, "include": [ "**/*.ts" ] } timocov-dts-bundle-generator-c69ff0d/src/types-usage-evaluator.ts000066400000000000000000000301651461132021400253240ustar00rootroot00000000000000import * as ts from 'typescript'; import { getActualSymbol, getDeclarationsForExportedValues, getDeclarationsForSymbol, getImportExportReferencedSymbol, getNodeName, getNodeOwnSymbol, getSymbolExportStarDeclarations, isDeclareModule, isNodeNamedDeclaration, splitTransientSymbol, } from './helpers/typescript'; export class TypesUsageEvaluator { private readonly typeChecker: ts.TypeChecker; private readonly nodesParentsMap: Map> = new Map(); private readonly usageResultCache: Map> = new Map(); public constructor(files: ts.SourceFile[], typeChecker: ts.TypeChecker) { this.typeChecker = typeChecker; this.computeUsages(files); } public isSymbolUsedBySymbol(symbol: ts.Symbol, by: ts.Symbol): boolean { return this.isSymbolUsedBySymbolImpl(this.getActualSymbol(symbol), this.getActualSymbol(by), new Set()); } public getSymbolsUsingSymbol(symbol: ts.Symbol): Set | null { return this.nodesParentsMap.get(this.getActualSymbol(symbol)) || null; } private isSymbolUsedBySymbolImpl(fromSymbol: ts.Symbol, toSymbol: ts.Symbol, visitedSymbols: Set): boolean { if (fromSymbol === toSymbol) { return this.setUsageCacheValue(fromSymbol, toSymbol, true); } const cacheResult = this.usageResultCache.get(fromSymbol)?.get(toSymbol); if (cacheResult !== undefined) { return cacheResult; } const reachableNodes = this.nodesParentsMap.get(fromSymbol); if (reachableNodes !== undefined) { for (const symbol of reachableNodes) { if (visitedSymbols.has(symbol)) { continue; } visitedSymbols.add(symbol); if (this.isSymbolUsedBySymbolImpl(symbol, toSymbol, visitedSymbols)) { return this.setUsageCacheValue(fromSymbol, toSymbol, true); } } } visitedSymbols.add(fromSymbol); // note that we can't save negative result here because it might be not a final one // because we might ended up here because of `visitedSymbols.has(symbol)` check above // while actually checking that `symbol` symbol and we will store all its "children" as `false` // while in reality some of them might be `true` because of cross-references or using the same children symbols return false; } private setUsageCacheValue(fromSymbol: ts.Symbol, toSymbol: ts.Symbol, value: boolean): boolean { let fromSymbolCacheMap = this.usageResultCache.get(fromSymbol); if (fromSymbolCacheMap === undefined) { fromSymbolCacheMap = new Map(); this.usageResultCache.set(fromSymbol, fromSymbolCacheMap); } fromSymbolCacheMap.set(toSymbol, value); return value; } private computeUsages(files: ts.SourceFile[]): void { this.nodesParentsMap.clear(); for (const file of files) { ts.forEachChild(file, this.computeUsageForNode.bind(this)); } } // eslint-disable-next-line complexity private computeUsageForNode(node: ts.Node): void { if (isDeclareModule(node) && node.body !== undefined && ts.isModuleBlock(node.body)) { const moduleSymbol = this.getSymbol(node.name); for (const statement of node.body.statements) { this.computeUsageForNode(statement); if (isNodeNamedDeclaration(statement)) { const nodeName = getNodeName(statement); if (nodeName !== undefined) { // a node declared in `declare module` should adds "usage" to that module // so we can track its usage later if needed const statementSymbol = this.getSymbol(nodeName); this.addUsages(statementSymbol, moduleSymbol); } } } } if (isNodeNamedDeclaration(node)) { const nodeName = getNodeName(node); if (nodeName !== undefined) { if (ts.isObjectBindingPattern(nodeName) || ts.isArrayBindingPattern(nodeName)) { for (const element of nodeName.elements) { this.computeUsageForNode(element); } } else { const childSymbol = this.getSymbol(nodeName); if (childSymbol !== null) { this.computeUsagesRecursively(node, childSymbol); } } } } if (ts.isVariableStatement(node)) { for (const varDeclaration of node.declarationList.declarations) { this.computeUsageForNode(varDeclaration); } } // `export * as ns from 'mod'` if (ts.isExportDeclaration(node) && node.moduleSpecifier !== undefined && node.exportClause !== undefined && ts.isNamespaceExport(node.exportClause)) { this.addUsagesForNamespacedModule(node.exportClause, node.moduleSpecifier as ts.StringLiteral); } // `import * as ns from 'mod'` if (ts.isImportDeclaration(node) && node.moduleSpecifier !== undefined && node.importClause?.namedBindings !== undefined && ts.isNamespaceImport(node.importClause.namedBindings)) { // for namespaced imports we don't want to include module's exports into usage // because only exports actually "assign" all exports to a namespace node // namespaced imports affect only local scope (unless it is exported, but it handled elsewhere) this.addUsagesForNamespacedModule(node.importClause.namedBindings, node.moduleSpecifier as ts.StringLiteral, false); } // `export {}` or `export {} from 'mod'` if (ts.isExportDeclaration(node) && node.exportClause !== undefined && ts.isNamedExports(node.exportClause)) { for (const exportElement of node.exportClause.elements) { const exportElementSymbol = getImportExportReferencedSymbol(exportElement, this.typeChecker); // i.e. `import * as NS from './local-module'` const namespaceImportForElement = getDeclarationsForSymbol(exportElementSymbol).find(ts.isNamespaceImport); if (namespaceImportForElement !== undefined) { // the namespaced import itself doesn't add a "usage", but re-export of that imported namespace does // so here we're handling the case where previously imported namespace import has been re-exported from a module this.addUsagesForNamespacedModule(namespaceImportForElement, namespaceImportForElement.parent.parent.moduleSpecifier as ts.StringLiteral); } // "link" referenced symbol with its import const exportElementOwnSymbol = this.getNodeOwnSymbol(exportElement.name); this.addUsages(exportElementSymbol, exportElementOwnSymbol); this.addUsages(this.getActualSymbol(exportElementSymbol), exportElementOwnSymbol); } } // `export =` if (ts.isExportAssignment(node) && node.isExportEquals) { this.addUsagesForExportAssignment(node); } } private addUsagesForExportAssignment(exportAssignment: ts.ExportAssignment): void { for (const declaration of getDeclarationsForExportedValues(exportAssignment, this.typeChecker)) { // `declare module foobar {}` or `namespace foobar {}` if (ts.isModuleDeclaration(declaration) && ts.isIdentifier(declaration.name) && declaration.body !== undefined && ts.isModuleBlock(declaration.body)) { const moduleSymbol = this.getSymbol(declaration.name); for (const statement of declaration.body.statements) { if (isNodeNamedDeclaration(statement) && statement.name !== undefined) { const statementSymbol = this.getSymbol(statement.name); if (statementSymbol !== null) { // this feels counter-intuitive that we assign a statement as a parent of a module // but this is what happens when you have `export=` statements // you can import an interface declared in `export=` exported namespace // via named import statement // e.g. lets say you have `namespace foo { export interface Interface {} }; export = foo;` // then you can import it like `import { Interface } from 'module'` // in this case only `Interface` is used, but it is part of module `foo` // which means that `foo` is used via using `Interface` // if you're reading this - please stop using `export=` exports asap! this.addUsages(moduleSymbol, statementSymbol); } } } } } } private addUsagesForNamespacedModule(namespaceNode: ts.NamespaceImport | ts.NamespaceExport, moduleSpecifier: ts.StringLiteral, includeExports: boolean = true): void { // note that we shouldn't resolve the actual symbol for the namespace // as in some circumstances it will be resolved to the source file // i.e. namespaceSymbol would become referencedModuleSymbol so it would be no-op // but we want to add this module's usage to the map const namespaceSymbol = this.getNodeOwnSymbol(namespaceNode.name); const referencedSourceFileSymbol = this.getSymbol(moduleSpecifier); this.addUsages(referencedSourceFileSymbol, namespaceSymbol); // but in case it is not resolved to the source file we need to link them const resolvedNamespaceSymbol = this.getSymbol(namespaceNode.name); this.addUsages(resolvedNamespaceSymbol, namespaceSymbol); if (includeExports) { // if a referenced source file has any exports, they should be added "to the usage" as they all are re-exported/imported this.addExportsToSymbol(referencedSourceFileSymbol.exports, referencedSourceFileSymbol); } } private addExportsToSymbol(exports: ts.SymbolTable | undefined, parentSymbol: ts.Symbol, visitedSymbols: Set = new Set()): void { exports?.forEach((moduleExportedSymbol: ts.Symbol, name: ts.__String) => { if (name === ts.InternalSymbolName.ExportStar) { // this means that an export contains `export * from 'module'` statement for (const exportStarDeclaration of getSymbolExportStarDeclarations(moduleExportedSymbol)) { if (exportStarDeclaration.moduleSpecifier === undefined) { throw new Error(`Export star declaration does not have a module specifier '${exportStarDeclaration.getText()}'`); } const referencedSourceFileSymbol = this.getSymbol(exportStarDeclaration.moduleSpecifier); if (visitedSymbols.has(referencedSourceFileSymbol)) { continue; } visitedSymbols.add(referencedSourceFileSymbol); this.addExportsToSymbol(referencedSourceFileSymbol.exports, parentSymbol, visitedSymbols); } return; } this.addUsages(moduleExportedSymbol, parentSymbol); }); } private computeUsagesRecursively(parent: ts.Node, parentSymbol: ts.Symbol): void { ts.forEachChild(parent, (child: ts.Node) => { if (child.kind === ts.SyntaxKind.JSDoc) { return; } this.computeUsagesRecursively(child, parentSymbol); if (ts.isIdentifier(child) || child.kind === ts.SyntaxKind.DefaultKeyword) { // identifiers in labelled tuples don't have symbols for their labels // so let's just skip them from collecting if (ts.isNamedTupleMember(child.parent) && child.parent.name === child) { return; } // `{ propertyName: name }` - in this case we don't need to handle `propertyName` as it has no symbol if (ts.isBindingElement(child.parent) && child.parent.propertyName === child) { return; } this.addUsages(this.getSymbol(child), parentSymbol); if (!ts.isQualifiedName(child.parent)) { const childOwnSymbol = this.getNodeOwnSymbol(child); // i.e. `import * as NS from './local-module'` const namespaceImport = getDeclarationsForSymbol(childOwnSymbol).find(ts.isNamespaceImport); if (namespaceImport !== undefined) { // if a node is an identifier and not part of a qualified name // and it was created as part of namespaced import // then we need to assign all exports of referenced module into that namespace // because they might not be added previously while processing imports/exports this.addUsagesForNamespacedModule(namespaceImport, namespaceImport.parent.parent.moduleSpecifier as ts.StringLiteral, true); } } } }); } private addUsages(childSymbol: ts.Symbol, parentSymbol: ts.Symbol): void { const childSymbols = splitTransientSymbol(childSymbol, this.typeChecker); for (const childSplitSymbol of childSymbols) { let symbols = this.nodesParentsMap.get(childSplitSymbol); if (symbols === undefined) { symbols = new Set(); this.nodesParentsMap.set(childSplitSymbol, symbols); } // to avoid infinite recursion if (childSplitSymbol !== parentSymbol) { symbols.add(parentSymbol); } } } private getSymbol(node: ts.Node): ts.Symbol { return this.getActualSymbol(this.getNodeOwnSymbol(node)); } private getNodeOwnSymbol(node: ts.Node): ts.Symbol { return getNodeOwnSymbol(node, this.typeChecker); } private getActualSymbol(symbol: ts.Symbol): ts.Symbol { return getActualSymbol(symbol, this.typeChecker); } } timocov-dts-bundle-generator-c69ff0d/tests/000077500000000000000000000000001461132021400210545ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/000077500000000000000000000000001461132021400215275ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/.gitignore000066400000000000000000000000131461132021400235110ustar00rootroot00000000000000/.tsc-out/ timocov-dts-bundle-generator-c69ff0d/tests/e2e/README.md000066400000000000000000000014161461132021400230100ustar00rootroot00000000000000# e2e tests ## Create new test case To create new test case you need to create new folder in [test-cases](./test-cases) (as a sample you may use [test-case-sample](./test-case-sample) folder). New folder's name will be used as name of test case. Each test case must have at least 3 files: 1. `input.ts` or `input.d.ts` - the entry point of test case (this file will used to generate typings). 1. `output.d.ts` - file with expected output - it will be used to compare with just generated (actual) typings. 1. `config.ts` - file with test case config (e.g. generator options). It must export test case config (see [test-case-config.ts](./test-cases/test-case-config.ts) for type) via `export =`. ## Run tests ```bash # the command should be run in project root npm run test ``` timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-case-sample/000077500000000000000000000000001461132021400246765ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-case-sample/config.ts000066400000000000000000000002141461132021400265100ustar00rootroot00000000000000import { TestCaseConfig } from '../test-cases/test-case-config'; const config: TestCaseConfig = { failOnClass: true, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-case-sample/input.ts000066400000000000000000000000301461132021400263760ustar00rootroot00000000000000// place your code here timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-case-sample/output.d.ts000066400000000000000000000000361461132021400270270ustar00rootroot00000000000000// place expected output here timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases-validation.spec.ts000066400000000000000000000021601461132021400272320ustar00rootroot00000000000000import * as fs from 'fs'; import * as path from 'path'; import * as assert from 'assert'; const testCasesDir = path.resolve(__dirname, 'test-cases'); function isDirectory(filePath: string): boolean { return fs.lstatSync(path.resolve(testCasesDir, filePath)).isDirectory(); } function findTestCaseFolders(): string[] { return fs.readdirSync(testCasesDir) .filter((filePath: string) => isDirectory(filePath) && path.basename(filePath) !== 'node_modules') .map((directoryName: string) => path.resolve(testCasesDir, directoryName)); } describe(`e2e test cases validation`, () => { for (const testCaseFolder of findTestCaseFolders()) { it(path.basename(testCaseFolder), () => { const testCaseSpecFilePath = path.join(testCaseFolder, 'index.spec.js'); assert.strictEqual(fs.existsSync(testCaseSpecFilePath), true, `Spec file '${testCaseSpecFilePath}' should exist`); assert.strictEqual( fs.readFileSync(testCaseSpecFilePath, { encoding: 'utf-8' }).trim(), `require('../run-test-case').runTestCase(__dirname);`, 'Every test case spec file content should match expected value to run tests' ); }); } }); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/000077500000000000000000000000001461132021400236025ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/.gitignore000066400000000000000000000000441461132021400255700ustar00rootroot00000000000000!/**/output.d.ts !/**/node_modules/ timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-arbitrary-extensions/000077500000000000000000000000001461132021400311125ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-arbitrary-extensions/config.ts000066400000000000000000000001721461132021400327270ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-arbitrary-extensions/hello.d.json.ts000066400000000000000000000000761461132021400337620ustar00rootroot00000000000000declare const hello: Record; export default hello; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-arbitrary-extensions/hello.json000066400000000000000000000000171461132021400331060ustar00rootroot00000000000000{ "test": 1 }timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-arbitrary-extensions/index.spec.js000066400000000000000000000000641461132021400335100ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-arbitrary-extensions/input.d.ts000066400000000000000000000001111461132021400330340ustar00rootroot00000000000000import hello from './hello.json'; export function test(): typeof hello; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-arbitrary-extensions/output.d.ts000066400000000000000000000001311461132021400332370ustar00rootroot00000000000000declare const hello: Record; export function test(): typeof hello; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-arbitrary-extensions/tsconfig.json000066400000000000000000000002301461132021400336140ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "allowArbitraryExtensions": true, "esModuleInterop": true, "resolveJsonModule": true } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-js/000077500000000000000000000000001461132021400253325ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-js/config.ts000066400000000000000000000001721461132021400271470ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-js/hello.js000066400000000000000000000000551461132021400267730ustar00rootroot00000000000000const hello = { test: 1 }; export { hello } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-js/index.spec.js000066400000000000000000000000641461132021400277300ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-js/input.ts000066400000000000000000000001161461132021400270370ustar00rootroot00000000000000import { hello } from "./hello.js"; export function test() { return hello } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-js/output.d.ts000066400000000000000000000001001461132021400274530ustar00rootroot00000000000000export declare function test(): { test: number; }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/allow-js/tsconfig.json000066400000000000000000000001171461132021400300400ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "allowJs": true } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/ambient-redeclare-types/000077500000000000000000000000001461132021400303075ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/ambient-redeclare-types/config.ts000066400000000000000000000001541461132021400321240ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/ambient-redeclare-types/index.spec.js000066400000000000000000000000641461132021400327050ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/ambient-redeclare-types/input.d.ts000066400000000000000000000005631461132021400322440ustar00rootroot00000000000000// see https://github.com/dexie/Dexie.js/blob/f6a6f29183c7a05f732397524c48ce4c1236bd6e/src/public/index.d.ts#L34-L47 import { ExportedType, Type1, Type2 } from './type'; interface _Type1 extends Type1 {} interface _Type2 extends Type2 {} declare module ExportedType { interface Type1 extends _Type1 {} interface Type2 extends _Type2 {} } export { ExportedType }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/ambient-redeclare-types/output.d.ts000066400000000000000000000005651461132021400324470ustar00rootroot00000000000000export interface Type1 { } export interface Type2 { } export declare interface ExportedType { Type1: { prototype: Type1; }; Type2: { prototype: Type2; }; } export interface _Type1 extends Type1 { } export interface _Type2 extends Type2 { } export declare module ExportedType { interface Type1 extends _Type1 { } interface Type2 extends _Type2 { } } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/ambient-redeclare-types/type.d.ts000066400000000000000000000002331461132021400320600ustar00rootroot00000000000000export interface Type1 {} export interface Type2 {} export declare interface ExportedType { Type1: { prototype: Type1 }; Type2: { prototype: Type2 }; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/banner/000077500000000000000000000000001461132021400250475ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/banner/config.ts000066400000000000000000000002171461132021400266640ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { output: { noBanner: false, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/banner/index.spec.js000066400000000000000000000000641461132021400274450ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/banner/input.ts000066400000000000000000000000501461132021400265510ustar00rootroot00000000000000export type TypeName = string | number; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/banner/output.d.ts000066400000000000000000000001641461132021400272020ustar00rootroot00000000000000// Generated by dts-bundle-generator v$PACKAGE_CURRENT_VERSION export type TypeName = string | number; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/binding-patterns-without-initializer/000077500000000000000000000000001461132021400330745ustar00rootroot00000000000000array-const.d.ts000066400000000000000000000000551461132021400360510ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/binding-patterns-without-initializerexport const [ FOO = '321', BAR = 1337, ]; config.ts000066400000000000000000000001541461132021400346320ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/binding-patterns-without-initializerimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400354130ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/binding-patterns-without-initializerrequire('../run-test-case').runTestCase(__dirname); input.d.ts000066400000000000000000000003551461132021400347510ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/binding-patterns-without-initializerimport { BAR as ARR_BAR, FOO as ARR_FOO } from './array-const'; import { BAR as OBJ_BAR, FOO as OBJ_FOO } from './obj-const'; export type BarType = typeof ARR_BAR | typeof OBJ_BAR; export type FooType = typeof ARR_FOO | typeof OBJ_FOO; obj-const.d.ts000066400000000000000000000000611461132021400355020ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/binding-patterns-without-initializerexport declare const { FOO = 123, BAR = 42, }; output.d.ts000066400000000000000000000003041461132021400351440ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/binding-patterns-without-initializerdeclare const [FOO = "321", BAR = 1337,]; declare const { FOO$1 = 123, BAR$1 = 42, }; export type BarType = typeof BAR | typeof BAR$1; export type FooType = typeof FOO | typeof FOO$1; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/cts-extension/000077500000000000000000000000001461132021400264055ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/cts-extension/config.ts000066400000000000000000000001721461132021400302220ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/cts-extension/decl.d.cts000066400000000000000000000000331461132021400302450ustar00rootroot00000000000000export type Decl = string; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/cts-extension/file.cts000066400000000000000000000000361461132021400300360ustar00rootroot00000000000000export interface Interface {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/cts-extension/index.spec.js000066400000000000000000000000641461132021400310030ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/cts-extension/input.cts000066400000000000000000000002211461132021400302520ustar00rootroot00000000000000import { Interface } from './file.cjs'; import { Decl } from './decl.cjs'; export interface ExportedInterface extends Interface { foo: Decl; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/cts-extension/output.d.ts000066400000000000000000000002131461132021400305330ustar00rootroot00000000000000export interface Interface { } export type Decl = string; export interface ExportedInterface extends Interface { foo: Decl; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/custom-types-folder/000077500000000000000000000000001461132021400275275ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/custom-types-folder/config.ts000066400000000000000000000002521461132021400313430ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { importedLibraries: ['fake-types-lib-2'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/custom-types-folder/index.spec.js000066400000000000000000000000641461132021400321250ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/custom-types-folder/input.ts000066400000000000000000000001231461132021400312320ustar00rootroot00000000000000import { Data } from 'fake-types-lib-2/data'; export type MyData = Data | string; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/custom-types-folder/output.d.ts000066400000000000000000000001371461132021400316620ustar00rootroot00000000000000import { Data } from 'fake-types-lib-2/data'; export type MyData = Data | string; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/custom-types-folder/tsconfig.json000066400000000000000000000002321461132021400322330ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "types": ["fake-types-lib-2"], "typeRoots": [ "node_modules/@types", "./types" ] } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/custom-types-folder/types/000077500000000000000000000000001461132021400306735ustar00rootroot00000000000000fake-types-lib-2/000077500000000000000000000000001461132021400335675ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/custom-types-folder/typesindex.d.ts000066400000000000000000000001251461132021400354660ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/custom-types-folder/types/fake-types-lib-2declare module 'fake-types-lib-2/data' { export { Data } from 'fake-types-lib-2'; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-and-imports/000077500000000000000000000000001461132021400307175ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-and-imports/config.ts000066400000000000000000000002521461132021400325330ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = { output: { inlineDeclareExternals: true, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-and-imports/index.spec.js000066400000000000000000000000641461132021400333150ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-and-imports/input.d.ts000066400000000000000000000001561461132021400326520ustar00rootroot00000000000000import { Barfoo } from 'package-with-re-exports'; declare module 'fake-package' { export type A = Barfoo; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-and-imports/output.d.ts000066400000000000000000000001721461132021400330510ustar00rootroot00000000000000import { Barfoo } from 'package-with-re-exports'; declare module "fake-package" { export type A = Barfoo; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-in-internal-files/000077500000000000000000000000001461132021400320025ustar00rootroot00000000000000.gitignore000066400000000000000000000000421461132021400337070ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-in-internal-files!/ambient-module-declaration.d.ts ambient-module-declaration.d.ts000066400000000000000000000000441461132021400377000ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-in-internal-filesdeclare module 'ambient-module' { } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-in-internal-files/config.ts000066400000000000000000000002521461132021400336160ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = { output: { inlineDeclareExternals: true, }, }; export = config; index.spec.js000066400000000000000000000000641461132021400343210ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-in-internal-filesrequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-in-internal-files/input.ts000066400000000000000000000010161461132021400335070ustar00rootroot00000000000000// this test case comes from Dexie.js /// import { ModuleWithoutQuotes } from 'fake-package'; import { Interface, ExportedModule } from './interface'; export interface InterfaceInternal extends Interface {} declare module ModuleName { export interface Interface extends InterfaceInternal {} export type Bar = ExportedModule.Foo; export type Foo = ModuleWithoutQuotes.A; } declare var ModuleName: { prototype: Interface }; export { ModuleName }; interface.ts000066400000000000000000000001571461132021400342360ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-in-internal-filesexport interface Interface { field: Interface; } export module ExportedModule { export type Foo = string; } output.d.ts000066400000000000000000000007431461132021400340610ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-module-in-internal-filesimport { ModuleWithoutQuotes } from 'fake-package'; declare module "ambient-module" { } export interface Interface { field: Interface; } declare namespace ExportedModule { type Foo = string; } export interface InterfaceInternal extends Interface { } export declare namespace ModuleName { interface Interface extends InterfaceInternal { } type Bar = ExportedModule.Foo; type Foo = ModuleWithoutQuotes.A; } export declare var ModuleName: { prototype: Interface; }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-unknown-modules/000077500000000000000000000000001461132021400303445ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-unknown-modules/config.ts000066400000000000000000000002521461132021400321600ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = { output: { inlineDeclareExternals: true, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-unknown-modules/index.spec.js000066400000000000000000000000641461132021400327420ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-unknown-modules/input.d.ts000066400000000000000000000001041461132021400322700ustar00rootroot00000000000000/// export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-unknown-modules/modules.d.ts000066400000000000000000000001241461132021400326030ustar00rootroot00000000000000declare module '*.css' {} declare module 'module-that-does-not-exist-actually' { } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/declare-unknown-modules/output.d.ts000066400000000000000000000001401461132021400324710ustar00rootroot00000000000000declare module "*.css" { } declare module "module-that-does-not-exist-actually" { } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/default-export-of-default-export/000077500000000000000000000000001461132021400321105ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/default-export-of-default-export/class.ts000066400000000000000000000000401461132021400335570ustar00rootroot00000000000000export default class MyClass {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/default-export-of-default-export/config.ts000066400000000000000000000001721461132021400337250ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400344270ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/default-export-of-default-exportrequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/default-export-of-default-export/input.ts000066400000000000000000000000431461132021400336140ustar00rootroot00000000000000export { default } from './class'; output.d.ts000066400000000000000000000001101461132021400341530ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/default-export-of-default-exportdeclare class MyClass { } export { MyClass as default, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/different-default-export-names-in-project/000077500000000000000000000000001461132021400336625ustar00rootroot00000000000000config.ts000066400000000000000000000001721461132021400354200ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/different-default-export-names-in-projectimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400362010ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/different-default-export-names-in-projectrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000003271461132021400353140ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/different-default-export-names-in-projectimport DefaultClassOriginal from 'package-with-default-export'; import { ExportedInterface } from './my-file'; export interface ExportInterface { field1: typeof DefaultClassOriginal; field2: ExportedInterface; } my-file.ts000066400000000000000000000002321461132021400355120ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/different-default-export-names-in-projectimport DefaultClassRenamed from 'package-with-default-export'; export interface ExportedInterface {} export class FooBar extends DefaultClassRenamed {} output.d.ts000066400000000000000000000003331461132021400357340ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/different-default-export-names-in-projectimport DefaultClassOriginal from 'package-with-default-export'; export interface ExportedInterface { } export interface ExportInterface { field1: typeof DefaultClassOriginal; field2: ExportedInterface; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/disable-non-direct-exports/000077500000000000000000000000001461132021400307475ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/disable-non-direct-exports/config.ts000066400000000000000000000002521461132021400325630ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = { output: { exportReferencedTypes: false, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/disable-non-direct-exports/enums.d.ts000066400000000000000000000002121461132021400326630ustar00rootroot00000000000000// note it doesn't have `declare` keyword export const enum ConstEnum2 {} // note it doesn't have `declare` keyword export enum Enum2 {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/disable-non-direct-exports/index.spec.js000066400000000000000000000000641461132021400333450ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/disable-non-direct-exports/input.ts000066400000000000000000000005401461132021400324550ustar00rootroot00000000000000import { Class, ConstEnum, Enum, func, Interface, Type, variable, } from './module'; import { Enum2, ConstEnum2 } from './enums'; export interface ExportedInterface { class: Class; constEnum: ConstEnum; constEnum2: ConstEnum2; enum: Enum; enum2: Enum2; func: typeof func; interface: Interface; type: Type; variable: typeof variable; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/disable-non-direct-exports/module.ts000066400000000000000000000003111461132021400325770ustar00rootroot00000000000000export class Class {} export const enum ConstEnum {} export const variable: string = '123'; export enum Enum {} export function func(): void {} export interface Interface {} export type Type = string; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/disable-non-direct-exports/output.d.ts000066400000000000000000000007251461132021400331050ustar00rootroot00000000000000declare class Class { } declare const enum ConstEnum { } declare const variable: string; declare enum Enum { } declare function func(): void; interface Interface { } type Type = string; declare const enum ConstEnum2 { } declare enum Enum2 { } export interface ExportedInterface { class: Class; constEnum: ConstEnum; constEnum2: ConstEnum2; enum: Enum; enum2: Enum2; func: typeof func; interface: Interface; type: Type; variable: typeof variable; } export {}; dont-inline-declare-extenal-modules-in-internal-files/000077500000000000000000000000001461132021400357625ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases.gitignore000066400000000000000000000000421461132021400377460ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-extenal-modules-in-internal-files!/ambient-module-declaration.d.ts ambient-module-declaration.d.ts000066400000000000000000000000441461132021400437370ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-extenal-modules-in-internal-filesdeclare module 'ambient-module' { } config.ts000066400000000000000000000001721461132021400375770ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-extenal-modules-in-internal-filesimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400403600ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-extenal-modules-in-internal-filesrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000005501461132021400374710ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-extenal-modules-in-internal-files// this test case comes from Dexie.js /// import { Interface } from './interface'; export interface InterfaceInternal extends Interface {} declare module ModuleName { export interface Interface extends InterfaceInternal {} } declare var ModuleName: { prototype: Interface }; export { ModuleName }; interface.ts000066400000000000000000000000621461132021400402700ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-extenal-modules-in-internal-filesexport interface Interface { field: Interface; } output.d.ts000066400000000000000000000004161461132021400401150ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-extenal-modules-in-internal-filesexport interface Interface { field: Interface; } export interface InterfaceInternal extends Interface { } export declare namespace ModuleName { interface Interface extends InterfaceInternal { } } export declare var ModuleName: { prototype: Interface; }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-global/000077500000000000000000000000001461132021400306555ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-global/config.ts000066400000000000000000000002511461132021400324700ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = { output: { inlineDeclareGlobals: false, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-global/index.spec.js000066400000000000000000000000641461132021400332530ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-global/input.ts000066400000000000000000000001501461132021400323600ustar00rootroot00000000000000declare global { interface ArrayConstructor { field: string; } } export const field = Array.field; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/dont-inline-declare-global/output.d.ts000066400000000000000000000000601461132021400330030ustar00rootroot00000000000000export declare const field: string; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/double-re-export-from-node_modules/000077500000000000000000000000001461132021400324135ustar00rootroot00000000000000config.ts000066400000000000000000000001721461132021400341510ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/double-re-export-from-node_modulesimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400347320ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/double-re-export-from-node_modulesrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001121461132021400340350ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/double-re-export-from-node_modulesexport { DefaultClass, DefaultClass1, DefaultClass2 } from './re-export'; output.d.ts000066400000000000000000000003031461132021400344620ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/double-re-export-from-node_modulesimport { default as DefaultClass, default as DefaultClass1, default as DefaultClass2 } from 'package-with-default-export'; export { DefaultClass, DefaultClass1, DefaultClass2, }; export {}; re-export.ts000066400000000000000000000003041461132021400346260ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/double-re-export-from-node_modulesexport { default as DefaultClass, default as DefaultClass1 } from 'package-with-default-export'; import { default as DefaultClass2 } from 'package-with-default-export'; export { DefaultClass2 }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-declaration-merging/000077500000000000000000000000001461132021400310345ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-declaration-merging/bar.ts000066400000000000000000000000271461132021400321470ustar00rootroot00000000000000export const Bar = 12; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-declaration-merging/config.ts000066400000000000000000000002341461132021400326500ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { output: { exportReferencedTypes: false, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-declaration-merging/foo.ts000066400000000000000000000001311461132021400321620ustar00rootroot00000000000000import { Bar } from './bar'; export interface Foo {} interface Bar {} export { Bar }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-declaration-merging/index.spec.js000066400000000000000000000000641461132021400334320ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-declaration-merging/input.ts000066400000000000000000000001071461132021400325410ustar00rootroot00000000000000import { Foo, Bar } from './foo'; const Foo = 2; export { Foo, Bar }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-declaration-merging/output.d.ts000066400000000000000000000001731461132021400331670ustar00rootroot00000000000000export declare const Bar = 12; export interface Foo { } export interface Bar { } export declare const Foo = 2; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-exist-class/000077500000000000000000000000001461132021400310025ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-exist-class/config.ts000066400000000000000000000001721461132021400326170ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-exist-class/index.spec.js000066400000000000000000000000641461132021400334000ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-exist-class/input.ts000066400000000000000000000000761461132021400325140ustar00rootroot00000000000000export class MyAwesomeClass {} export default MyAwesomeClass; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-exist-class/output.d.ts000066400000000000000000000001351461132021400331330ustar00rootroot00000000000000export declare class MyAwesomeClass { } export { MyAwesomeClass as default, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-entry/000077500000000000000000000000001461132021400306455ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-entry/config.ts000066400000000000000000000001721461132021400324620ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-entry/index.spec.js000066400000000000000000000000641461132021400332430ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-entry/input.ts000066400000000000000000000002171461132021400323540ustar00rootroot00000000000000export interface MyInterface {} export type MyType = { [K in keyof T]: string; }; export default class NewClass implements MyInterface {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-entry/output.d.ts000066400000000000000000000002701461132021400327760ustar00rootroot00000000000000export interface MyInterface { } export type MyType = { [K in keyof T]: string; }; declare class NewClass implements MyInterface { } export { NewClass as default, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-non-entry/000077500000000000000000000000001461132021400314355ustar00rootroot00000000000000another-class.ts000066400000000000000000000000771461132021400344750ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-non-entryexport class MyAnotherClass {} export default MyAnotherClass; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-non-entry/class.ts000066400000000000000000000000401461132021400331040ustar00rootroot00000000000000export default class MyClass {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-non-entry/config.ts000066400000000000000000000001721461132021400332520ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400337540ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-non-entryrequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-non-entry/input.ts000066400000000000000000000003641461132021400331470ustar00rootroot00000000000000import MyInterface from './interface'; import MyClass from './class'; import MyAnotherClass from './another-class'; export default class MyNewClass extends MyClass implements MyInterface {} export class MyNewClass2 extends MyAnotherClass { } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-non-entry/interface.ts000066400000000000000000000000501461132021400337400ustar00rootroot00000000000000export default interface MyInterface {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-from-non-entry/output.d.ts000066400000000000000000000004151461132021400335670ustar00rootroot00000000000000export interface MyInterface { } declare class MyClass { } declare class MyAnotherClass { } declare class MyNewClass extends MyClass implements MyInterface { } export declare class MyNewClass2 extends MyAnotherClass { } export { MyNewClass as default, }; export {}; export-default-just-declared-class-from-entry/000077500000000000000000000000001461132021400344155ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000001721461132021400362320ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-just-declared-class-from-entryimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400370130ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-just-declared-class-from-entryrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000000511461132021400361200ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-just-declared-class-from-entryclass MyClass {} export default MyClass; output.d.ts000066400000000000000000000001101461132021400365370ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-just-declared-class-from-entrydeclare class MyClass { } export { MyClass as default, }; export {}; export-default-just-declared-fns-from-entry/000077500000000000000000000000001461132021400340765ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000001541461132021400357130ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-just-declared-fns-from-entryimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400364740ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-just-declared-fns-from-entryrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001151461132021400356020ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-just-declared-fns-from-entryimport fns, { fooBar as fooBaz } from './some-fns'; export { fns, fooBaz }; output.d.ts000066400000000000000000000002051461132021400362250ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-just-declared-fns-from-entrydeclare function name(a: number): number; declare function fooBar(): void; export { fooBar as fooBaz, name as fns, }; export {}; some-fns.ts000066400000000000000000000001511461132021400361720ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-just-declared-fns-from-entryexport default function name (a: number): number { return a + 1; }; export function fooBar(): void {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-no-export-referenced-types/000077500000000000000000000000001461132021400337405ustar00rootroot00000000000000config.ts000066400000000000000000000002341461132021400354750ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-no-export-referenced-typesimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { output: { exportReferencedTypes: false, }, }; export = config; index.spec.js000066400000000000000000000000641461132021400362570ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-no-export-referenced-typesrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000000501461132021400353630ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-no-export-referenced-typesconst foo = "bar"; export default foo; output.d.ts000066400000000000000000000001051461132021400360070ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-no-export-referenced-typesdeclare const foo = "bar"; export { foo as default, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statement/000077500000000000000000000000001461132021400321745ustar00rootroot00000000000000another-class.ts000066400000000000000000000000561461132021400352310ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statementexport default class { second: number = 1; } another-func.ts000066400000000000000000000000531461132021400350540ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statementexport default function(second: number) {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statement/class.ts000066400000000000000000000000551461132021400336510ustar00rootroot00000000000000export default class { first: number = 1; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statement/config.ts000066400000000000000000000001721461132021400340110ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statement/func.ts000066400000000000000000000000521461132021400334740ustar00rootroot00000000000000export default function(first: number) {} index.spec.js000066400000000000000000000000641461132021400345130ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statementrequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statement/input.ts000066400000000000000000000011401461132021400336770ustar00rootroot00000000000000export { default as myFunc1 } from './func'; export { default as myFunc2 } from './func'; export { default as myFunc3 } from './another-func'; export { default as myFunc4 } from './another-func'; export { default as myClass1 } from './class'; export { default as myClass2 } from './class'; export { default as myClass3 } from './another-class'; export { default as myClass4 } from './another-class'; export { default as number } from './number'; export { default as string } from './string'; export { default as object } from './object'; export { default as myClass5 } from 'package-with-default-export'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statement/number.ts000066400000000000000000000000221461132021400340260ustar00rootroot00000000000000export default 0; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statement/object.ts000066400000000000000000000000461461132021400340120ustar00rootroot00000000000000export default { type: 'object', }; output.d.ts000066400000000000000000000012241461132021400342460ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statementimport { default as myClass5 } from 'package-with-default-export'; declare function _default(first: number): void; declare function _default$1(second: number): void; declare class _default$2 { first: number; } declare class _default$3 { second: number; } declare const _default$4: 0; declare const _default$5: ""; declare const _default$6: { type: string; }; export { _default as myFunc1, _default as myFunc2, _default$1 as myFunc3, _default$1 as myFunc4, _default$2 as myClass1, _default$2 as myClass2, _default$3 as myClass3, _default$3 as myClass4, _default$4 as number, _default$5 as string, _default$6 as object, myClass5, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-default-unnamed-statement/string.ts000066400000000000000000000000231461132021400340450ustar00rootroot00000000000000export default ''; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-eq-from-entry/000077500000000000000000000000001461132021400276265ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-eq-from-entry/config.ts000066400000000000000000000001721461132021400314430ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-eq-from-entry/index.spec.js000066400000000000000000000000641461132021400322240ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-eq-from-entry/input.ts000066400000000000000000000000771461132021400313410ustar00rootroot00000000000000import { SomeClass } from './some-class'; export = SomeClass; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-eq-from-entry/output.d.ts000066400000000000000000000000741461132021400317610ustar00rootroot00000000000000declare class SomeClass { } export = SomeClass; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-eq-from-entry/some-class.ts000066400000000000000000000000321461132021400322370ustar00rootroot00000000000000export class SomeClass {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-keyof-typeof-var-type/000077500000000000000000000000001461132021400313075ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-keyof-typeof-var-type/config.ts000066400000000000000000000001541461132021400331240ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-keyof-typeof-var-type/index.spec.js000066400000000000000000000000641461132021400337050ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-keyof-typeof-var-type/input.ts000066400000000000000000000001471461132021400330200ustar00rootroot00000000000000const variableName = { a: 123, b: 'string', }; export type TypeOfConst = keyof typeof variableName; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-keyof-typeof-var-type/output.d.ts000066400000000000000000000001721461132021400334410ustar00rootroot00000000000000declare const variableName: { a: number; b: string; }; export type TypeOfConst = keyof typeof variableName; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-namespaces/000077500000000000000000000000001461132021400272405ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-namespaces/config.ts000066400000000000000000000001541461132021400310550ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-namespaces/index.spec.js000066400000000000000000000000641461132021400316360ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-namespaces/input.ts000066400000000000000000000003441461132021400307500ustar00rootroot00000000000000import { InternalModule, InternalNamespace, ExportedModule, ExportedNamespace } from './internals'; export type A = InternalModule.MType; export type B = InternalNamespace.NSType; export { ExportedModule, ExportedNamespace }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-namespaces/internals.ts000066400000000000000000000004111461132021400316030ustar00rootroot00000000000000export namespace InternalNamespace { export type NSType = string; } export module InternalModule { export type MType = number; } export namespace ExportedNamespace { export type ENSType = 1 | 2; } export module ExportedModule { export type EMType = 3 | 4; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-namespaces/output.d.ts000066400000000000000000000005361461132021400313760ustar00rootroot00000000000000declare namespace InternalNamespace { type NSType = string; } declare namespace InternalModule { type MType = number; } export declare namespace ExportedNamespace { type ENSType = 1 | 2; } export declare namespace ExportedModule { type EMType = 3 | 4; } export type A = InternalModule.MType; export type B = InternalNamespace.NSType; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-object-with-destructuring/000077500000000000000000000000001461132021400322405ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-object-with-destructuring/config.ts000066400000000000000000000001721461132021400340550ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400345570ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-object-with-destructuringrequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-object-with-destructuring/input.ts000066400000000000000000000002271461132021400337500ustar00rootroot00000000000000export const queryDict: Record = { param: '123', otherParam: '456', }; export const { param, otherParam, } = queryDict; output.d.ts000066400000000000000000000002321461132021400343100ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-object-with-destructuringexport declare const queryDict: Record; export declare const param: string | boolean, otherParam: string | boolean; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-variables-list/000077500000000000000000000000001461132021400300425ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-variables-list/config.ts000066400000000000000000000001541461132021400316570ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-variables-list/index.spec.js000066400000000000000000000000641461132021400324400ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-variables-list/input.ts000066400000000000000000000005671461132021400315610ustar00rootroot00000000000000// not supported for now - if variable declarations have different exports - then all aren't exported const defaultExportedString = 'str', justExportedNumber = 123; export default defaultExportedString; export { justExportedNumber }; const exportedString = 'str', nonExportedNum = 123; export { exportedString }; // fix unused expression error console.log(nonExportedNum); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-variables-list/output.d.ts000066400000000000000000000002601461132021400321720ustar00rootroot00000000000000declare const defaultExportedString = "str", justExportedNumber = 123; export declare const exportedString = "str"; export { defaultExportedString as default, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-variables-list/tsconfig.json000066400000000000000000000001211461132021400325430ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "types": ["node"] } } export-via-global-declaration-but-inlineDeclareGlobals-disabled/000077500000000000000000000000001461132021400377375ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000001721461132021400415540ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration-but-inlineDeclareGlobals-disabledimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400423350ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration-but-inlineDeclareGlobals-disabledrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000002731461132021400414500ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration-but-inlineDeclareGlobals-disabledimport { FooOptions } from './options'; import './other-global'; declare global { export namespace Cypress { export interface Chainable { foo(options?: FooOptions): void; } } } options.ts000066400000000000000000000000371461132021400420020ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration-but-inlineDeclareGlobals-disabledexport interface FooOptions {} other-global.ts000066400000000000000000000002431461132021400426650ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration-but-inlineDeclareGlobals-disabledimport { Interface } from 'fake-package'; declare global { export namespace Cypress { export interface Chainable { bar(options?: Interface): void; } } } output.d.ts000066400000000000000000000000131461132021400420630ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration-but-inlineDeclareGlobals-disabledexport {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration/000077500000000000000000000000001461132021400314215ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration/config.ts000066400000000000000000000002501461132021400332330ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = { output: { inlineDeclareGlobals: true, }, }; export = config; index.spec.js000066400000000000000000000000641461132021400337400ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declarationrequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration/input.ts000066400000000000000000000002731461132021400331320ustar00rootroot00000000000000import { FooOptions } from './options'; import './other-global'; declare global { export namespace Cypress { export interface Chainable { foo(options?: FooOptions): void; } } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration/options.ts000066400000000000000000000001241461132021400334610ustar00rootroot00000000000000export interface SubOptions {} export interface FooOptions { field: SubOptions; } other-global.ts000066400000000000000000000002431461132021400342700ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declarationimport { Interface } from 'fake-package'; declare global { export namespace Cypress { export interface Chainable { bar(options?: Interface): void; } } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-via-global-declaration/output.d.ts000066400000000000000000000005561461132021400335610ustar00rootroot00000000000000import { Interface } from 'fake-package'; export interface SubOptions { } export interface FooOptions { field: SubOptions; } declare global { export namespace Cypress { interface Chainable { bar(options?: Interface): void; } } } declare global { export namespace Cypress { interface Chainable { foo(options?: FooOptions): void; } } } export {}; export-wrapped-with-namespace-chain-but-via-imports/000077500000000000000000000000001461132021400355275ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000002341461132021400373430ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-but-via-importsimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { output: { exportReferencedTypes: false, }, }; export = config; first.ts000066400000000000000000000001171461132021400372250ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-but-via-importsimport * as FirstNamespaceName from './second'; export { FirstNamespaceName }; index.spec.js000066400000000000000000000000641461132021400401250ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-but-via-importsrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001121461132021400372300ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-but-via-importsimport * as TopNamespaceName from './first'; export { TopNamespaceName }; output.d.ts000066400000000000000000000005451461132021400376650ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-but-via-importsimport * as Ns from 'fake-package'; import * as Ns1 from 'package-with-export-eq'; type A = string; declare namespace SecondNamespaceName { export { A, Ns, Ns1 }; } declare namespace FirstNamespaceName { export { SecondNamespaceName }; } declare namespace TopNamespaceName { export { FirstNamespaceName }; } export { TopNamespaceName, }; export {}; second.ts000066400000000000000000000001201461132021400373430ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-but-via-importsimport * as SecondNamespaceName from './third'; export { SecondNamespaceName }; third.ts000066400000000000000000000003341461132021400372110ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-but-via-importsimport * as Ns1 from 'package-with-export-eq'; export type A = string; export * as Ns from 'fake-package'; export { Ns1 }; // this is not supported yet, uncomment once it is possible // export * from 'fake-package'; export-wrapped-with-namespace-chain-inline/000077500000000000000000000000001461132021400337435ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000003361461132021400355620ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-inlineimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { inlinedLibraries: ['package-with-export-eq'], }, output: { exportReferencedTypes: false, }, }; export = config; first.ts000066400000000000000000000000601461132021400354360ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-inlineexport * as FirstNamespaceName from './second'; index.spec.js000066400000000000000000000000641461132021400363410ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-inlinerequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000000551461132021400354520ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-inlineexport * as TopNamespaceName from './first'; output.d.ts000066400000000000000000000005421461132021400360760ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-inlineimport * as Ns from 'fake-package'; declare namespace MyModule { export interface SomeCoolInterface { field: string; field2: number; } } type A = string; declare namespace FirstNamespaceName { export { A, MyModule as Ns1, Ns }; } declare namespace TopNamespaceName { export { FirstNamespaceName }; } export { TopNamespaceName, }; export {}; second.ts000066400000000000000000000001761461132021400355720ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain-inlineimport * as Ns1 from 'package-with-export-eq'; export type A = string; export * as Ns from 'fake-package'; export { Ns1 }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chain/000077500000000000000000000000001461132021400325465ustar00rootroot00000000000000another-ns.ts000066400000000000000000000000461461132021400351150ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chainexport * as AnotherNs from './types'; config.ts000066400000000000000000000002341461132021400343030ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chainimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { output: { exportReferencedTypes: false, }, }; export = config; first.ts000066400000000000000000000000601461132021400341620ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chainexport * as FirstNamespaceName from './second'; index.spec.js000066400000000000000000000000641461132021400350650ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chainrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001561461132021400342000ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chainexport * as TopNamespaceName from './first'; export { AnotherNs as AnotherNsButRenamed } from './another-ns'; output.d.ts000066400000000000000000000007111461132021400346200ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chainimport * as Ns from 'fake-package'; import * as Ns1 from 'package-with-export-eq'; type A = string; type Str = string; declare namespace SecondNamespaceName { export { A, Ns, Ns1 }; } declare namespace FirstNamespaceName { export { SecondNamespaceName }; } declare namespace TopNamespaceName { export { FirstNamespaceName }; } declare namespace AnotherNsButRenamed { export { Str }; } export { AnotherNsButRenamed, TopNamespaceName, }; export {}; second.ts000066400000000000000000000000601461132021400343060ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chainexport * as SecondNamespaceName from './third'; third.ts000066400000000000000000000003341461132021400341510ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chainimport * as Ns1 from 'package-with-export-eq'; export type A = string; export * as Ns from 'fake-package'; export { Ns1 }; // this is not supported yet, uncomment once it is possible // export * from 'fake-package'; types.ts000066400000000000000000000000321461132021400341760ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-chainexport type Str = string; export-wrapped-with-namespace-export-eq-export/000077500000000000000000000000001461132021400346505ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000002341461132021400364640ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-export-eq-exportimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { output: { exportReferencedTypes: false, }, }; export = config; index.spec.js000066400000000000000000000000641461132021400372460ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-export-eq-exportrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000002111461132021400363510ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-export-eq-exportimport * as newName from 'package-with-export-eq'; import * as myLib from 'package-with-export-eq-variable'; export { newName, myLib }; output.d.ts000066400000000000000000000002301461132021400367750ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-export-eq-exportimport * as newName from 'package-with-export-eq'; import * as myLib from 'package-with-export-eq-variable'; export { myLib, newName, }; export {}; export-wrapped-with-namespace-export-eq-inline/000077500000000000000000000000001461132021400346055ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000004011461132021400364150ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-export-eq-inlineimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { inlinedLibraries: ['package-with-export-eq', 'package-with-export-eq-variable'], }, output: { exportReferencedTypes: false, }, }; export = config; index.spec.js000066400000000000000000000000641461132021400372030ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-export-eq-inlinerequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000002111461132021400363060ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-export-eq-inlineimport * as newName from 'package-with-export-eq'; import * as myLib from 'package-with-export-eq-variable'; export { newName, myLib }; output.d.ts000066400000000000000000000003471461132021400367430ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace-export-eq-inlinedeclare namespace MyModule { export interface SomeCoolInterface { field: string; field2: number; } } interface LibInterface { field: number; } export const myLib: LibInterface; export { MyModule as newName, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace/000077500000000000000000000000001461132021400314665ustar00rootroot00000000000000another-exports.ts000066400000000000000000000001761461132021400351250ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespaceexport type MyString = string; export interface MyInt {} export function func() {} export { Interface } from 'fake-package'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace/config.ts000066400000000000000000000002341461132021400333020ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { output: { exportReferencedTypes: false, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace/exports.ts000066400000000000000000000001761461132021400335460ustar00rootroot00000000000000export type MyString = string; export interface MyInt {} export function func() {} export { Interface } from 'fake-package'; index.spec.js000066400000000000000000000000641461132021400340050ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespacerequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace/input.ts000066400000000000000000000006521461132021400332000ustar00rootroot00000000000000export * as MyNamespace from './exports'; export * as MyNamespace1 from './another-exports'; export * as MyNamespace2 from './another-exports'; import * as SomeLocalNsName from './one-more-exports'; import * as MyNamespace4 from './one-more-exports'; import { MyInt } from './exports'; export interface MyNamespace2 { field: MyInt; } export type Type = MyInt; export { SomeLocalNsName as MyNamespace3, MyNamespace4, }; one-more-exports.ts000066400000000000000000000003221461132021400351770ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespaceexport type MyString = string; export interface MyInt {} export function func() {} export { Interface } from 'fake-package'; export * from './type'; export * from './type2'; export * as subNs from './type2'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace/output.d.ts000066400000000000000000000021561461132021400336240ustar00rootroot00000000000000import { Interface } from 'fake-package'; type MyString = string; interface MyInt { } declare function func(): void; type MyString$1 = string; interface MyInt$1 { } declare function func$1(): void; type MyType = string; type MyType2 = string; type MyString$2 = string; interface MyInt$2 { } declare function func$2(): void; interface MyNamespace2 { field: MyInt; } export type Type = MyInt; declare namespace MyNamespace4 { export { Interface, MyInt$2 as MyInt, MyString$2 as MyString, MyType, MyType2, func$2 as func, subNs }; } declare namespace subNs { export { MyType2 }; } declare namespace MyNamespace { export { Interface, MyInt, MyString, func }; } declare namespace MyNamespace1 { export { Interface, MyInt$1 as MyInt, MyString$1 as MyString, func$1 as func }; } declare namespace MyNamespace2 { export { Interface, MyInt$1 as MyInt, MyString$1 as MyString, func$1 as func }; } declare namespace MyNamespace3 { export { Interface, MyInt$2 as MyInt, MyString$2 as MyString, MyType, MyType2, func$2 as func, subNs }; } export { MyNamespace, MyNamespace1, MyNamespace2, MyNamespace3, MyNamespace4, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace/type.ts000066400000000000000000000000351461132021400330150ustar00rootroot00000000000000export type MyType = string; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/export-wrapped-with-namespace/type2.ts000066400000000000000000000000361461132021400331000ustar00rootroot00000000000000export type MyType2 = string; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module-complex/000077500000000000000000000000001461132021400311405ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module-complex/config.ts000066400000000000000000000001721461132021400327550ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; extendable-module.ts000066400000000000000000000001611461132021400350250ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module-complexexport function getRandom(): number { return 4; } export interface SomeInterface { field: typeof getRandom; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module-complex/extender.ts000066400000000000000000000002551461132021400333300ustar00rootroot00000000000000export function justFunction(input: boolean): void { // do nothing } declare module './extendable-module' { interface SomeInterface { field2: typeof justFunction; } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module-complex/index.spec.js000066400000000000000000000000641461132021400335360ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module-complex/input.ts000066400000000000000000000006041461132021400326470ustar00rootroot00000000000000// we need to add this to add `extender.d.ts` to list of files to bundle the types after compilation for dts /// /// import { SomeInterface } from './extendable-module'; import { justFunction } from './extender'; justFunction(true); export default SomeInterface; internal-extender/000077500000000000000000000000001461132021400345115ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module-complexextender.d.ts000066400000000000000000000002211461132021400371140ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module-complex/internal-extenderexport function justFunction2(): void; declare module '..\\extendable-module' { interface SomeInterface { field3: typeof justFunction2; } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module-complex/output.d.ts000066400000000000000000000005421461132021400332730ustar00rootroot00000000000000declare function justFunction(input: boolean): void; interface SomeInterface { field2: typeof justFunction; } declare function justFunction2(): void; interface SomeInterface { field3: typeof justFunction2; } declare function getRandom(): number; interface SomeInterface { field: typeof getRandom; } export { SomeInterface as default, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module/000077500000000000000000000000001461132021400274735ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module/config.ts000066400000000000000000000002521461132021400313070ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = { output: { inlineDeclareExternals: true, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module/extendable-module.ts000066400000000000000000000001611461132021400334370ustar00rootroot00000000000000export function getRandom(): number { return 4; } export interface SomeInterface { field: typeof getRandom; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module/index.spec.js000066400000000000000000000000641461132021400320710ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module/input.ts000066400000000000000000000005231461132021400312020ustar00rootroot00000000000000import { SomeInterface } from './extendable-module'; export function justFunction(input: SomeInterface): void { // do nothing } declare module './extendable-module' { interface SomeInterface { field2: typeof justFunction; } } declare module '@app/extendable-module' { interface SomeInterface { field3: typeof justFunction; } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module/output.d.ts000066400000000000000000000004631461132021400316300ustar00rootroot00000000000000declare function getRandom(): number; export interface SomeInterface { field: typeof getRandom; } export declare function justFunction(input: SomeInterface): void; export interface SomeInterface { field2: typeof justFunction; } export interface SomeInterface { field3: typeof justFunction; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/extend-other-module/tsconfig.json000066400000000000000000000001431461132021400322000ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "paths": { "@app/*": ["./*"] } } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/external-types/000077500000000000000000000000001461132021400265665ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/external-types/config.ts000066400000000000000000000002431461132021400304020ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { allowedTypesLibraries: ['mocha'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/external-types/index.spec.js000066400000000000000000000000641461132021400311640ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/external-types/input.ts000066400000000000000000000001111461132021400302660ustar00rootroot00000000000000import 'mocha'; export interface InterfaceName { prop: BrowserMocha; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/external-types/output.d.ts000066400000000000000000000001451461132021400307200ustar00rootroot00000000000000/// export interface InterfaceName { prop: BrowserMocha; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/globalThis/000077500000000000000000000000001461132021400256725ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/globalThis/config.ts000066400000000000000000000001541461132021400275070ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/globalThis/index.spec.js000066400000000000000000000000641461132021400302700ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/globalThis/input.ts000066400000000000000000000001561461132021400274030ustar00rootroot00000000000000export declare function getGlobal(): typeof globalThis; export declare function getUndef(): typeof undefined; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/globalThis/output.d.ts000066400000000000000000000001721461132021400300240ustar00rootroot00000000000000export declare function getGlobal(): typeof globalThis; export declare function getUndef(): typeof undefined; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/handle-export-eq-from-npm/000077500000000000000000000000001461132021400305105ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/handle-export-eq-from-npm/config.ts000066400000000000000000000002521461132021400323240ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = { libraries: { allowedTypesLibraries: [], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/handle-export-eq-from-npm/index.spec.js000066400000000000000000000000641461132021400331060ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/handle-export-eq-from-npm/input.ts000066400000000000000000000005331461132021400322200ustar00rootroot00000000000000import { SomeCoolInterface } from 'package-with-export-eq'; import { NamedDeclaration } from 'typescript'; import { EventEmitter } from 'events'; export class StoppableEventEmitter extends EventEmitter { public emitStoppableEvent(error: Error): this { return this; } } export type ExportType = SomeCoolInterface | NamedDeclaration | string; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/handle-export-eq-from-npm/output.d.ts000066400000000000000000000005241461132021400326430ustar00rootroot00000000000000import { EventEmitter } from 'events'; import { SomeCoolInterface } from 'package-with-export-eq'; import { NamedDeclaration } from 'typescript'; export declare class StoppableEventEmitter extends EventEmitter { emitStoppableEvent(error: Error): this; } export type ExportType = SomeCoolInterface | NamedDeclaration | string; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/handle-export-eq-from-npm/tsconfig.json000066400000000000000000000001211461132021400332110ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "types": ["node"] } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import()-type/000077500000000000000000000000001461132021400262145ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import()-type/config.ts000066400000000000000000000002451461132021400300320ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { inlinedLibraries: ['fake-package'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import()-type/custom-type.d.ts000066400000000000000000000002441461132021400312770ustar00rootroot00000000000000export interface CustomType { foo: number; bar: string; } export namespace Namespace { export const baz: number; } export declare type GenericType = {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import()-type/index.spec.js000066400000000000000000000000641461132021400306120ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import()-type/input.ts000066400000000000000000000002411461132021400277200ustar00rootroot00000000000000import { MyType } from './my-type'; import { NonDefaultInterface as DFI } from 'package-with-default-export'; export type MySecondType = MyType | number | DFI; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import()-type/my-type.d.ts000066400000000000000000000005711461132021400304150ustar00rootroot00000000000000export interface MyType { field: import('./custom-type').CustomType; field2: typeof import('./custom-type').Namespace; field3: import('ora').Options; field4: import('./custom-type').GenericType; field5: import('fake-package').Interface; field6: typeof import('./namespace').Namespace; field7: import('package-with-default-export').NonDefaultInterface; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import()-type/namespace.d.ts000066400000000000000000000000721461132021400307410ustar00rootroot00000000000000export namespace Namespace { export const baz: number; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import()-type/output.d.ts000066400000000000000000000012161461132021400303460ustar00rootroot00000000000000import { NonDefaultInterface as DFI } from 'package-with-default-export'; export interface CustomType { foo: number; bar: string; } declare namespace Namespace { export const baz: number; } export declare type GenericType = {}; export interface Interface { } declare namespace Namespace$1 { export const baz: number; } export interface MyType { field: CustomType; field2: typeof Namespace; field3: import("ora").Options; field4: GenericType; field5: Interface; field6: typeof Namespace$1; field7: import("package-with-default-export").NonDefaultInterface; } export type MySecondType = MyType | number | DFI; export {}; import-compound-type-from-npm-cause-unnecessary-import/000077500000000000000000000000001461132021400363325ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000001541461132021400401470ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-compound-type-from-npm-cause-unnecessary-importimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400407300ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-compound-type-from-npm-cause-unnecessary-importrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001461461132021400400420ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-compound-type-from-npm-cause-unnecessary-importimport { InterfaceWithFields } from 'fake-package'; export type MyType = InterfaceWithFields | null; output.d.ts000066400000000000000000000001621461132021400404630ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-compound-type-from-npm-cause-unnecessary-importimport { InterfaceWithFields } from 'fake-package'; export type MyType = InterfaceWithFields | null; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-default-from-node-modules/000077500000000000000000000000001461132021400320705ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-default-from-node-modules/config.ts000066400000000000000000000001721461132021400337050ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400344070ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-default-from-node-modulesrequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-default-from-node-modules/input.ts000066400000000000000000000001541461132021400335770ustar00rootroot00000000000000import DefaultClass from 'package-with-default-export'; export class MyCustomClass extends DefaultClass {} output.d.ts000066400000000000000000000002011461132021400341340ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-default-from-node-modulesimport DefaultClass from 'package-with-default-export'; export declare class MyCustomClass extends DefaultClass { } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq-with-interop/000077500000000000000000000000001461132021400301465ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq-with-interop/config.ts000066400000000000000000000001721461132021400317630ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq-with-interop/export-eq.ts000066400000000000000000000000501461132021400324350ustar00rootroot00000000000000class ClassName {} export = ClassName; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq-with-interop/index.spec.js000066400000000000000000000000641461132021400325440ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq-with-interop/input.ts000066400000000000000000000003441461132021400316560ustar00rootroot00000000000000import MyModule from 'package-with-export-eq'; import ClassName from './export-eq'; export class ExportedClass extends ClassName implements MyModule.SomeCoolInterface { public field: string = ''; public field2: number = 0; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq-with-interop/output.d.ts000066400000000000000000000003301461132021400322740ustar00rootroot00000000000000import MyModule from 'package-with-export-eq'; declare class ClassName { } export declare class ExportedClass extends ClassName implements MyModule.SomeCoolInterface { field: string; field2: number; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq-with-interop/tsconfig.json000066400000000000000000000001771461132021400326620ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "allowSyntheticDefaultImports": true, "esModuleInterop": true } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq/000077500000000000000000000000001461132021400255175ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq/config.ts000066400000000000000000000001721461132021400273340ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq/export-eq.ts000066400000000000000000000000501461132021400300060ustar00rootroot00000000000000class ClassName {} export = ClassName; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq/index.spec.js000066400000000000000000000000641461132021400301150ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq/input.ts000066400000000000000000000003601461132021400272250ustar00rootroot00000000000000import MyModule = require('package-with-export-eq'); import ClassName = require('./export-eq'); export class ExportedClass extends ClassName implements MyModule.SomeCoolInterface { public field: string = ''; public field2: number = 0; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-eq/output.d.ts000066400000000000000000000003361461132021400276530ustar00rootroot00000000000000import MyModule = require('package-with-export-eq'); declare class ClassName { } export declare class ExportedClass extends ClassName implements MyModule.SomeCoolInterface { field: string; field2: number; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-deps/000077500000000000000000000000001461132021400270065ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-deps/config.ts000066400000000000000000000002461461132021400306250ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { importedLibraries: ['fake-package'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-deps/index.spec.js000066400000000000000000000000641461132021400314040ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-deps/input.ts000066400000000000000000000001321461132021400305110ustar00rootroot00000000000000import { Interface, Type } from 'fake-package'; export type TestType = Interface | Type; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-deps/output.d.ts000066400000000000000000000001461461132021400311410ustar00rootroot00000000000000import { Interface, Type } from 'fake-package'; export type TestType = Interface | Type; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-interface-with-export-eq/000077500000000000000000000000001461132021400327065ustar00rootroot00000000000000config.ts000066400000000000000000000002431461132021400344430ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-interface-with-export-eqimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { importedLibraries: ['commander'], }, }; export = config; index.spec.js000066400000000000000000000000641461132021400352250ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-interface-with-export-eqrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001311461132021400343310ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-interface-with-export-eqimport { Command } from 'commander'; export function someFunction(program: Command) { } output.d.ts000066400000000000000000000001601461132021400347560ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-interface-with-export-eqimport { Command } from 'commander'; export declare function someFunction(program: Command): void; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-namespace-in-cjs/000077500000000000000000000000001461132021400311705ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-namespace-in-cjs/config.ts000066400000000000000000000002341461132021400330040ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { inlinedLibraries: ['ora'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-namespace-in-cjs/index.spec.js000066400000000000000000000000641461132021400335660ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-namespace-in-cjs/input.ts000066400000000000000000000001611461132021400326750ustar00rootroot00000000000000import { Options } from 'ora'; export declare const ExportedValue: Options; export type ExportedType = Options; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-namespace-in-cjs/output.d.ts000066400000000000000000000003151461132021400333210ustar00rootroot00000000000000declare namespace ora { interface Options { } } declare const ora: { (options: ora.Options): any; }; export declare const ExportedValue: ora.Options; export type ExportedType = ora.Options; export {}; import-from-non-relative-path-inferred-type/000077500000000000000000000000001461132021400341045ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000001721461132021400357210ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-non-relative-path-inferred-typeimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400365020ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-non-relative-path-inferred-typerequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001361461132021400356130ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-non-relative-path-inferred-typeimport { returnMyType } from "field/type"; export function test() { return returnMyType() } output.d.ts000066400000000000000000000001401461132021400362310ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-non-relative-path-inferred-typeexport interface MyType { field: string; } export declare function test(): MyType; export {}; src/000077500000000000000000000000001461132021400346735ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-non-relative-path-inferred-typefield/000077500000000000000000000000001461132021400357565ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-non-relative-path-inferred-type/srctype.ts000066400000000000000000000001651461132021400373110ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-non-relative-path-inferred-type/src/fieldexport interface MyType { field: string; } export function returnMyType(): MyType { return { field: "test" } } tsconfig.json000066400000000000000000000001221461132021400366060ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-non-relative-path-inferred-type{ "extends": "../tsconfig.json", "compilerOptions": { "baseUrl": "./src" } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types-cause-reference-types/000077500000000000000000000000001461132021400334135ustar00rootroot00000000000000config.ts000066400000000000000000000003551461132021400351540ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types-cause-reference-typesimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { allowedTypesLibraries: ['node', 'fake-types-lib-2'], importedLibraries: ['events', 'fake-types-lib-2.5'], }, }; export = config; extended-data.ts000066400000000000000000000002261461132021400364130ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types-cause-reference-types/// import { Data } from 'fake-types-lib-2.5'; export interface ExtendedData extends Data {} index.spec.js000066400000000000000000000000641461132021400357320ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types-cause-reference-typesrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000002761461132021400350500ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types-cause-reference-types/// import { EventEmitter } from 'events'; export class MyEventEmitter extends EventEmitter { } export { ExtendedData } from './extended-data'; output.d.ts000066400000000000000000000004261461132021400354700ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types-cause-reference-types/// /// import { EventEmitter } from 'events'; import { Data } from 'fake-types-lib-2.5'; export interface ExtendedData extends Data { } export declare class MyEventEmitter extends EventEmitter { } export {}; tsconfig.json000066400000000000000000000002111461132021400360350ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types-cause-reference-types{ "extends": "../tsconfig.json", "compilerOptions": { "types": [] }, "include": [ "inputs.ts" ], "exclude": [ "**/*.js" ] } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types/000077500000000000000000000000001461132021400272175ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types/config.ts000066400000000000000000000002561461132021400310370ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { importedLibraries: ['fs', 'fake-types-lib'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types/index.spec.js000066400000000000000000000000641461132021400316150ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types/input.ts000066400000000000000000000002551461132021400307300ustar00rootroot00000000000000import { InterfaceFromTypesPackage } from 'fake-types-lib'; import { Stats } from 'fs'; export interface InterfaceName { prop: Stats; field: InterfaceFromTypesPackage; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types/output.d.ts000066400000000000000000000003311461132021400313460ustar00rootroot00000000000000/// import { InterfaceFromTypesPackage } from 'fake-types-lib'; import { Stats } from 'fs'; export interface InterfaceName { prop: Stats; field: InterfaceFromTypesPackage; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-from-types/tsconfig.json000066400000000000000000000001211461132021400317200ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "types": ["node"] } } import-package-with-declaration-merging-with-default-lib/000077500000000000000000000000001461132021400364475ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000002521461132021400402630ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-package-with-declaration-merging-with-default-libimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { importedLibraries: ['fake-types-lib-3'], }, }; export = config; index.spec.js000066400000000000000000000000641461132021400410450ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-package-with-declaration-merging-with-default-librequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001301461132021400401500ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-package-with-declaration-merging-with-default-libimport { FooBar } from 'fake-types-lib-3'; export type Baz = FooBar; output.d.ts000066400000000000000000000001441461132021400406000ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-package-with-declaration-merging-with-default-libimport { FooBar } from 'fake-types-lib-3'; export type Baz = FooBar; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-star-from-local-module/000077500000000000000000000000001461132021400313775ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-star-from-local-module/config.ts000066400000000000000000000001721461132021400332140ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-star-from-local-module/func.ts000066400000000000000000000000401461132021400326740ustar00rootroot00000000000000export function func(): void {} index.spec.js000066400000000000000000000000641461132021400337160ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-star-from-local-modulerequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-star-from-local-module/input.ts000066400000000000000000000000671461132021400331110ustar00rootroot00000000000000import * as lib from './func'; export const Lib = lib; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-star-from-local-module/output.d.ts000066400000000000000000000001761461132021400335350ustar00rootroot00000000000000declare function func(): void; export declare const Lib: typeof lib; declare namespace lib { export { func }; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-type-from-deps/000077500000000000000000000000001461132021400277655ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-type-from-deps/config.ts000066400000000000000000000001551461132021400316030ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-type-from-deps/index.spec.js000066400000000000000000000000641461132021400323630ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-type-from-deps/input.ts000066400000000000000000000002601461132021400314720ustar00rootroot00000000000000import { InterfaceWithFields } from 'fake-package'; import { FakePackageType } from './module-with-import-type'; export type TestType = InterfaceWithFields | FakePackageType; module-with-import-type.d.ts000066400000000000000000000002501461132021400352220ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-type-from-deps// yes, these tabs are here on purpose import { type InterfaceWithFields } from 'fake-package'; export declare type FakePackageType = InterfaceWithFields | string; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-type-from-deps/output.d.ts000066400000000000000000000003031461132021400321130ustar00rootroot00000000000000import { InterfaceWithFields } from 'fake-package'; export declare type FakePackageType = InterfaceWithFields | string; export type TestType = InterfaceWithFields | FakePackageType; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-variables/000077500000000000000000000000001461132021400270625ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-variables/config.ts000066400000000000000000000001721461132021400306770ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-variables/index.spec.js000066400000000000000000000000641461132021400314600ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-variables/input.ts000066400000000000000000000003561461132021400305750ustar00rootroot00000000000000import { declaredVariable, declaredVariable2, variable, variable2 } from 'package-with-typings'; export const myVar: typeof variable | typeof variable2 = 1; export const myVar2: typeof declaredVariable | typeof declaredVariable2 = null; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-variables/output.d.ts000066400000000000000000000003771461132021400312230ustar00rootroot00000000000000import { declaredVariable, declaredVariable2, variable, variable2 } from 'package-with-typings'; export declare const myVar: typeof variable | typeof variable2; export declare const myVar2: typeof declaredVariable | typeof declaredVariable2; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-with-different-names/000077500000000000000000000000001461132021400311325ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-with-different-names/config.ts000066400000000000000000000003001461132021400327400ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { importedLibraries: ['fake-package', 'package-with-export-eq'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-with-different-names/index.spec.js000066400000000000000000000000641461132021400335300ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-with-different-names/input.ts000066400000000000000000000006051461132021400326420ustar00rootroot00000000000000import fakePackage1 from 'fake-package'; import * as fakePackage2 from 'fake-package'; import fakePackage3 = require('fake-package'); import { ExposedInterface } from './other-module'; export interface First extends fakePackage1.Interface {} export interface Second extends fakePackage2.Interface {} export interface Third extends fakePackage3.Interface {} export { ExposedInterface }; other-module.ts000066400000000000000000000005361461132021400340330ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-with-different-namesimport fakePackageDifferentNameThatShouldNotBeAddedToOutput = require('fake-package'); import PackageWithExportEq = require('package-with-export-eq'); export interface OtherInternalInterface extends fakePackageDifferentNameThatShouldNotBeAddedToOutput.Interface {} export interface ExposedInterface extends PackageWithExportEq.SomeCoolInterface {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-with-different-names/output.d.ts000066400000000000000000000007261461132021400332710ustar00rootroot00000000000000import * as fakePackage2 from 'fake-package'; import fakePackage3 = require('fake-package'); import fakePackage1 from 'fake-package'; import PackageWithExportEq = require('package-with-export-eq'); export interface ExposedInterface extends PackageWithExportEq.SomeCoolInterface { } export interface First extends fakePackage1.Interface { } export interface Second extends fakePackage2.Interface { } export interface Third extends fakePackage3.Interface { } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/import-with-different-names/tsconfig.json000066400000000000000000000001771461132021400336460ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "allowSyntheticDefaultImports": true, "esModuleInterop": true } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/include-exclude-in-tsconfig/000077500000000000000000000000001461132021400310725ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/include-exclude-in-tsconfig/config.ts000066400000000000000000000001541461132021400327070ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/include-exclude-in-tsconfig/index.spec.js000066400000000000000000000000641461132021400334700ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/include-exclude-in-tsconfig/input.ts000066400000000000000000000000351461132021400325770ustar00rootroot00000000000000export type FooBar = number; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/include-exclude-in-tsconfig/output.d.ts000066400000000000000000000000511461132021400332200ustar00rootroot00000000000000export type FooBar = number; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/include-exclude-in-tsconfig/tsconfig.json000066400000000000000000000002301461132021400335740ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "preserveConstEnums": true }, "include": [ "inputs.ts" ], "exclude": [ "**/*.js" ] } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-declare-global/000077500000000000000000000000001461132021400277135ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-declare-global/config.ts000066400000000000000000000002501461132021400315250ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = { output: { inlineDeclareGlobals: true, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-declare-global/index.spec.js000066400000000000000000000000641461132021400323110ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-declare-global/input.ts000066400000000000000000000003221461132021400314170ustar00rootroot00000000000000// this case comes from rxjs declare global { interface SymbolConstructor { readonly observable: symbol; } } export const observable = typeof Symbol === 'function' && Symbol.observable || '@@observable'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-declare-global/output.d.ts000066400000000000000000000002441461132021400320450ustar00rootroot00000000000000declare global { interface SymbolConstructor { readonly observable: symbol; } } export declare const observable: string | typeof Symbol.observable; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps-transitive/000077500000000000000000000000001461132021400311405ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps-transitive/config.ts000066400000000000000000000003211461132021400327510ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { inlinedLibraries: ['fake-package', 'fake-fs'], }, output: { sortNodes: true, } }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps-transitive/index.spec.js000066400000000000000000000000641461132021400335360ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps-transitive/input.ts000066400000000000000000000001241461132021400326440ustar00rootroot00000000000000export { InterfaceWithFields } from 'fake-package'; export { File } from 'fake-fs'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps-transitive/output.d.ts000066400000000000000000000005041461132021400332710ustar00rootroot00000000000000import { Path } from 'fake-path'; import { InterfaceFromTypesPackage } from 'fake-types-lib'; export interface File { path: Path; } export interface Interface { } export interface InterfaceWithFields { field: Type; field2: Interface; field3: InterfaceFromTypesPackage; } export type Type = number | string; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps-transitive/tsconfig.json000066400000000000000000000001261461132021400336460ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "types": ["fake-node"] } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps/000077500000000000000000000000001461132021400267525ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps/config.ts000066400000000000000000000002711461132021400305670ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { inlinedLibraries: ['fake-package', 'fake-types-lib-2'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps/index.spec.js000066400000000000000000000000641461132021400313500ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps/input.ts000066400000000000000000000005101461132021400304550ustar00rootroot00000000000000import { Interface, Type, ModuleWithoutQuotes } from 'fake-package'; import { Derived } from 'fake-types-lib-2'; import { SomeClass } from 'fake-package/some-class'; export type TestType = Interface | Type; export class MyClass extends SomeClass {} export type ReExportedTypes = Derived; export type T = ModuleWithoutQuotes.A; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-from-deps/output.d.ts000066400000000000000000000007301461132021400311040ustar00rootroot00000000000000export interface Interface { } export type Type = number | string; declare module ModuleWithoutQuotes { export type A = string; } export interface Base { id: string; } export interface Derived extends Base { name: string; } declare class SomeClass { private x; public constructor(); } export type TestType = Interface | Type; export declare class MyClass extends SomeClass { } export type ReExportedTypes = Derived; export type T = ModuleWithoutQuotes.A; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-package-with-namespaced-import/000077500000000000000000000000001461132021400330305ustar00rootroot00000000000000config.ts000066400000000000000000000002631461132021400345670ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-package-with-namespaced-importimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = { libraries: { inlinedLibraries: ['fake-package'], }, }; export = config; index.spec.js000066400000000000000000000000641461132021400353470ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-package-with-namespaced-importrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001311461132021400344530ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-package-with-namespaced-importimport { namespacedImportTypes } from 'fake-package'; export { namespacedImportTypes }; output.d.ts000066400000000000000000000001751461132021400351060ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/inline-package-with-namespaced-importimport * as namespacedImportTypes from 'package-with-namespaced-re-export'; export { namespacedImportTypes, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/labelled-tuples/000077500000000000000000000000001461132021400266605ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/labelled-tuples/config.ts000066400000000000000000000001541461132021400304750ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/labelled-tuples/index.spec.js000066400000000000000000000000641461132021400312560ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/labelled-tuples/input.ts000066400000000000000000000001441461132021400303660ustar00rootroot00000000000000interface Interface { foo: number; } export const a: [x: Interface, y: number] = [{ foo: 1 }, 2]; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/labelled-tuples/output.d.ts000066400000000000000000000001601461132021400310070ustar00rootroot00000000000000export interface Interface { foo: number; } export declare const a: [ x: Interface, y: number ]; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-namespaces/000077500000000000000000000000001461132021400271625ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-namespaces/config.ts000066400000000000000000000002531461132021400307770ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { inlinedLibraries: ['extensions-package'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-namespaces/index.spec.js000066400000000000000000000000641461132021400315600ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-namespaces/input.ts000066400000000000000000000004221461132021400306670ustar00rootroot00000000000000import { Ns1 as F1Ns1 } from './ns1'; import { Ns1 as F2Ns1 } from './ns2'; export { Ns1 as F1Ns1, Ns2 as F1Ns2, } from './ns1'; export { Ns1 as F2Ns1, Ns2 as F2Ns2, } from './ns2'; export interface Int { f1: F1Ns1.SubNs1.Interface1; f2: F2Ns1.SubNs1.Interface1; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-namespaces/ns1.ts000066400000000000000000000007531461132021400302400ustar00rootroot00000000000000export type FooBar = string; export namespace Ns1 { export namespace SubNs1 { export interface Interface1 { field1: FooBar; } } } export namespace Ns1 { export namespace SubNs1 { export interface Interface2 { field1: FooBar; } } } export module Ns2 { export module SubNs1 { export interface Interface1 { field1: Ns1.SubNs1.Interface1; } } } export module Ns2 { export module SubNs1 { export interface Interface2 { field1: Ns1.SubNs1.Interface2; } } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-namespaces/ns2.ts000066400000000000000000000007531461132021400302410ustar00rootroot00000000000000export type FooBar = number; export namespace Ns1 { export namespace SubNs1 { export interface Interface1 { field1: FooBar; } } } export namespace Ns1 { export namespace SubNs1 { export interface Interface2 { field1: FooBar; } } } export module Ns2 { export module SubNs1 { export interface Interface1 { field1: Ns1.SubNs1.Interface1; } } } export module Ns2 { export module SubNs1 { export interface Interface2 { field1: Ns1.SubNs1.Interface2; } } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-namespaces/output.d.ts000066400000000000000000000020651461132021400313170ustar00rootroot00000000000000export type FooBar = string; declare namespace Ns1 { namespace SubNs1 { interface Interface1 { field1: FooBar; } } } declare namespace Ns1 { namespace SubNs1 { interface Interface2 { field1: FooBar; } } } declare namespace Ns2 { namespace SubNs1 { interface Interface1 { field1: Ns1.SubNs1.Interface1; } } } declare namespace Ns2 { namespace SubNs1 { interface Interface2 { field1: Ns1.SubNs1.Interface2; } } } type FooBar$1 = number; declare namespace Ns1$1 { namespace SubNs1 { interface Interface1 { field1: FooBar$1; } } } declare namespace Ns1$1 { namespace SubNs1 { interface Interface2 { field1: FooBar$1; } } } declare namespace Ns2$1 { namespace SubNs1 { interface Interface1 { field1: Ns1$1.SubNs1.Interface1; } } } declare namespace Ns2$1 { namespace SubNs1 { interface Interface2 { field1: Ns1$1.SubNs1.Interface2; } } } export interface Int { f1: Ns1.SubNs1.Interface1; f2: Ns1$1.SubNs1.Interface1; } export { Ns1 as F1Ns1, Ns1$1 as F2Ns1, Ns2 as F1Ns2, Ns2$1 as F2Ns2, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-symbols/000077500000000000000000000000001461132021400265335ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-symbols/config.ts000066400000000000000000000002531461132021400303500ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { inlinedLibraries: ['extensions-package'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-symbols/index.spec.js000066400000000000000000000000641461132021400311310ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-symbols/input.ts000066400000000000000000000000441461132021400302400ustar00rootroot00000000000000export * from 'extensions-package'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/merged-symbols/output.d.ts000066400000000000000000000000131461132021400306570ustar00rootroot00000000000000export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mixed-imports/000077500000000000000000000000001461132021400264035ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mixed-imports/config.ts000066400000000000000000000001721461132021400302200ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mixed-imports/index.spec.js000066400000000000000000000000641461132021400310010ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mixed-imports/input.ts000066400000000000000000000015561461132021400301210ustar00rootroot00000000000000import DefaultClass, { NonDefaultInterface } from 'package-with-default-export'; import { default as RenamedDefaultClass, NonDefaultInterface as RenamedInterface } from 'package-with-default-export'; import * as wholePackage from 'package-with-default-export'; import defaultImportedNamespace from 'package-with-default-export/namespace'; import defaultImportedNamespace2, * as starImportNameModule from 'package-with-default-export/namespace'; import * as unusedStarImport from 'package-with-default-export/namespace'; console.log(typeof unusedStarImport); export interface ExportedInterface { field1: typeof DefaultClass; field2: NonDefaultInterface; field3: typeof RenamedDefaultClass; field4: RenamedInterface; field5: typeof wholePackage; field6: defaultImportedNamespace.Options; field7: defaultImportedNamespace2.Options; field8: typeof starImportNameModule; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mixed-imports/output.d.ts000066400000000000000000000014701461132021400305370ustar00rootroot00000000000000import * as wholePackage from 'package-with-default-export'; import DefaultClass from 'package-with-default-export'; import { NonDefaultInterface, NonDefaultInterface as RenamedInterface, default as RenamedDefaultClass } from 'package-with-default-export'; import * as starImportNameModule from 'package-with-default-export/namespace'; import defaultImportedNamespace from 'package-with-default-export/namespace'; import defaultImportedNamespace2 from 'package-with-default-export/namespace'; export interface ExportedInterface { field1: typeof DefaultClass; field2: NonDefaultInterface; field3: typeof RenamedDefaultClass; field4: RenamedInterface; field5: typeof wholePackage; field6: defaultImportedNamespace.Options; field7: defaultImportedNamespace2.Options; field8: typeof starImportNameModule; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mixed-imports/tsconfig.json000066400000000000000000000001211461132021400311040ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "types": ["node"] } } modules-in-internal-files-without-inline-declare-globals/000077500000000000000000000000001461132021400365045ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases.gitignore000066400000000000000000000000421461132021400404700ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/modules-in-internal-files-without-inline-declare-globals!/ambient-module-declaration.d.ts ambient-module-declaration.d.ts000066400000000000000000000000441461132021400444610ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/modules-in-internal-files-without-inline-declare-globalsdeclare module 'ambient-module' { } config.ts000066400000000000000000000001721461132021400403210ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/modules-in-internal-files-without-inline-declare-globalsimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400411020ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/modules-in-internal-files-without-inline-declare-globalsrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000006371461132021400402210ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/modules-in-internal-files-without-inline-declare-globals// this test case comes from Dexie.js /// import { Interface, ExportedModule } from './interface'; export interface InterfaceInternal extends Interface {} declare module ModuleName { export interface Interface extends InterfaceInternal {} export type Bar = ExportedModule.Foo; } declare var ModuleName: { prototype: Interface }; export { ModuleName }; interface.ts000066400000000000000000000001571461132021400410170ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/modules-in-internal-files-without-inline-declare-globalsexport interface Interface { field: Interface; } export module ExportedModule { export type Foo = string; } output.d.ts000066400000000000000000000005471461132021400406440ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/modules-in-internal-files-without-inline-declare-globalsexport interface Interface { field: Interface; } declare namespace ExportedModule { type Foo = string; } export interface InterfaceInternal extends Interface { } export declare namespace ModuleName { interface Interface extends InterfaceInternal { } type Bar = ExportedModule.Foo; } export declare var ModuleName: { prototype: Interface; }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mts-extension/000077500000000000000000000000001461132021400264175ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mts-extension/config.ts000066400000000000000000000001721461132021400302340ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mts-extension/decl.d.mts000066400000000000000000000000331461132021400302710ustar00rootroot00000000000000export type Decl = string; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mts-extension/file.mts000066400000000000000000000000361461132021400300620ustar00rootroot00000000000000export interface Interface {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mts-extension/index.spec.js000066400000000000000000000000641461132021400310150ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mts-extension/input.mts000066400000000000000000000002211461132021400302760ustar00rootroot00000000000000import { Interface } from './file.mjs'; import { Decl } from './decl.mjs'; export interface ExportedInterface extends Interface { foo: Decl; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/mts-extension/output.d.ts000066400000000000000000000002131461132021400305450ustar00rootroot00000000000000export interface Interface { } export type Decl = string; export interface ExportedInterface extends Interface { foo: Decl; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/000077500000000000000000000000001461132021400312665ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/config.ts000066400000000000000000000001551461132021400331040ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/export-eq.ts000066400000000000000000000013241461132021400335620ustar00rootroot00000000000000namespace ExportEqNs { export namespace InternalNs { export type NewType = string; } export type Bar = ExportEqNs.Foo; export type Foo = String; export namespace InternalNs2 { export type Type21 = InternalNs3.Type31; export type Type22 = InternalNs2.InternalNs3.Type31; export type Type23 = ExportEqNs.InternalNs2.InternalNs3.Type31; export namespace InternalNs3 { export type Type31 = InternalNs4.Type; export type Type32 = InternalNs3.InternalNs4.Type; export type Type33 = InternalNs2.InternalNs3.InternalNs4.Type; export type Type34 = ExportEqNs.InternalNs2.InternalNs3.InternalNs4.Type; export namespace InternalNs4 { export type Type = string; } } } } export = ExportEqNs; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/file1.ts000066400000000000000000000007371461132021400326450ustar00rootroot00000000000000const TEMPLATE = 'template1'; export default TEMPLATE; export const MergedSymbol = ''; export var Variable = 1; export interface MergedSymbol { test(): void }; export interface Interface { field1: number; } export function func(one: number) {} export type TypeName = Pick; export interface AnotherInterface { field1: number; } export function anotherFunc(one: NamespaceName.Local) {} export namespace NamespaceName { export interface Local {} } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/file2.ts000066400000000000000000000011241461132021400326350ustar00rootroot00000000000000const TEMPLATE = 'template2'; export default TEMPLATE; export const MergedSymbol = ''; export var Variable = ''; export interface MergedSymbol { test(): void }; export interface Interface { field2: number; } export function func(two: number) {} export type TypeName = Pick; /** Another interface doc string */ export interface AnotherInterface { field2: number; } /** Another func doc string */ export function anotherFunc(two: NamespaceName.Local) {} export namespace NamespaceName { export interface Local {} } export interface ExportedButNotUsedInterface {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/file3.ts000066400000000000000000000001231461132021400326340ustar00rootroot00000000000000interface DefaultInterface { field10: number; } export default DefaultInterface; import-star-1.ts000066400000000000000000000007541461132021400342040ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-filesimport * as fakePackage from 'fake-package'; import { Interface as FPI1, Interface } from 'fake-package'; import * as file1 from './file1'; import * as file1ButDifferent from './file1'; import { AnotherInterface as AiFromFile1 } from './file1'; import * as file2 from './file2'; export interface Inter { field: file1.Interface; field2: file2.AnotherInterface; field3: file1ButDifferent.TypeName; field4: AiFromFile1; field5: fakePackage.Interface; field6: FPI1; field7: Interface; } import-star-2.ts000066400000000000000000000010771461132021400342040ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-filesimport * as fakePackageButDifferent from 'fake-package'; import { Interface as FPI2, Interface } from 'fake-package'; import * as file1 from './file1'; import * as file1ButDifferent from './file1'; import { AnotherInterface as AiFromFile1 } from './file1'; import * as file2 from './file2'; import * as file3 from './file3'; export interface Inter2 { field: file1.Interface; field2: file2.AnotherInterface; field3: file1ButDifferent.TypeName; field4: AiFromFile1; field5: fakePackageButDifferent.Interface; field6: FPI2; field7: Interface; field8: file3.default; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/index.spec.js000066400000000000000000000000641461132021400336640ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/input.ts000066400000000000000000000014571461132021400330040ustar00rootroot00000000000000import { ExportEqNs } from './ns'; import { InternalNs } from './export-eq'; export type ExportedNsType = InternalNs.NewType; export { default as TEMPLATE1, MergedSymbol as MS1, Interface as I1, TypeName as T1, func as f1, NamespaceName as NS1, Variable as V1, // rename these to include them into import AnotherInterface as AI1, anotherFunc as af1, } from './file1'; export { default as TEMPLATE2, MergedSymbol as MS2, Interface as I2, TypeName as T2, func as f2, NamespaceName as NS2, Variable as V2, // yes, keep these without renaming so we can check that these aren't exported with wrong names AnotherInterface, anotherFunc, } from './file2'; export { Inter } from './import-star-1'; export { Inter2 } from './import-star-2'; export { MyType } from './type'; export { ExportEqNs }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/ns.ts000066400000000000000000000000411461132021400322510ustar00rootroot00000000000000export type ExportEqNs = string; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/output.d.ts000066400000000000000000000052561461132021400334300ustar00rootroot00000000000000import * as fakePackage from 'fake-package'; import { Interface as FPI1, Interface as FPI2, Interface as Interface$2 } from 'fake-package'; export type ExportEqNs = string; declare namespace ExportEqNs$1 { namespace InternalNs { type NewType = string; } type Bar = ExportEqNs$1.Foo; type Foo = String; namespace InternalNs2 { type Type21 = InternalNs3.Type31; type Type22 = InternalNs2.InternalNs3.Type31; type Type23 = ExportEqNs$1.InternalNs2.InternalNs3.Type31; namespace InternalNs3 { type Type31 = InternalNs4.Type; type Type32 = InternalNs3.InternalNs4.Type; type Type33 = InternalNs2.InternalNs3.InternalNs4.Type; type Type34 = ExportEqNs$1.InternalNs2.InternalNs3.InternalNs4.Type; namespace InternalNs4 { type Type = string; } } } } declare const TEMPLATE = "template1"; declare const MergedSymbol = ""; declare var Variable: number; interface MergedSymbol { test(): void; } interface Interface { field1: number; } declare function func(one: number): void; type TypeName = Pick; interface AnotherInterface { field1: number; } declare function anotherFunc(one: NamespaceName.Local): void; declare namespace NamespaceName { interface Local { } } declare const TEMPLATE$1 = "template2"; declare const MergedSymbol$1 = ""; declare var Variable$1: string; interface MergedSymbol$1 { test(): void; } interface Interface$1 { field2: number; } declare function func$1(two: number): void; type TypeName$1 = Pick; /** Another interface doc string */ interface AnotherInterface$1 { field2: number; } /** Another func doc string */ declare function anotherFunc$1(two: NamespaceName$1.Local): void; declare namespace NamespaceName$1 { interface Local { } } export interface Inter { field: Interface; field2: AnotherInterface$1; field3: TypeName; field4: AnotherInterface; field5: fakePackage.Interface; field6: FPI1; field7: Interface$2; } export interface DefaultInterface { field10: number; } export interface Inter2 { field: Interface; field2: AnotherInterface$1; field3: TypeName; field4: AnotherInterface; field5: fakePackage.Interface; field6: FPI2; field7: Interface$2; field8: DefaultInterface; } export type MyType = Interface$2; export type ExportedNsType = ExportEqNs$1.InternalNs.NewType; export { AnotherInterface as AI1, AnotherInterface$1 as AnotherInterface, Interface as I1, Interface$1 as I2, MergedSymbol as MS1, MergedSymbol$1 as MS2, NamespaceName as NS1, NamespaceName$1 as NS2, TEMPLATE as TEMPLATE1, TEMPLATE$1 as TEMPLATE2, TypeName as T1, TypeName$1 as T2, Variable as V1, Variable$1 as V2, anotherFunc as af1, anotherFunc$1 as anotherFunc, func as f1, func$1 as f2, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-across-files/type.ts000066400000000000000000000001131461132021400326120ustar00rootroot00000000000000import { Interface } from 'fake-package'; export type MyType = Interface; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-with-globals/000077500000000000000000000000001461132021400312705ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-with-globals/config.ts000066400000000000000000000001551461132021400331060ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-with-globals/index.spec.js000066400000000000000000000000641461132021400336660ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-with-globals/input.ts000066400000000000000000000002751461132021400330030ustar00rootroot00000000000000import { Date as LocalDate, Promise as LocalPromise } from './local-types'; export interface Int { localD: LocalDate; globalD: Date; localP: LocalPromise; globalP: Promise; } local-types.ts000066400000000000000000000003331461132021400340140ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-with-globalsdeclare global { // adding some global types to check that collisions mechanism works type Promise$1 = string; type Promise$2 = string; type Date$1 = string; } export interface Promise {} export interface Date {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/names-collision-with-globals/output.d.ts000066400000000000000000000002421461132021400334200ustar00rootroot00000000000000interface Promise$3 { } interface Date$2 { } export interface Int { localD: Date$2; globalD: Date; localP: Promise$3; globalP: Promise; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/namespaced-import/000077500000000000000000000000001461132021400272125ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/namespaced-import/config.ts000066400000000000000000000001721461132021400310270ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/namespaced-import/index.spec.js000066400000000000000000000000641461132021400316100ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/namespaced-import/input.ts000066400000000000000000000002461461132021400307230ustar00rootroot00000000000000import * as fakePackage from 'fake-package'; export declare class MyClass { static func(): fakePackage.InterfaceWithFields; static field: fakePackage.Interface; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/namespaced-import/output.d.ts000066400000000000000000000002621461132021400313440ustar00rootroot00000000000000import * as fakePackage from 'fake-package'; export declare class MyClass { static func(): fakePackage.InterfaceWithFields; static field: fakePackage.Interface; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/namespaced-import/tsconfig.json000066400000000000000000000001211461132021400317130ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "types": ["node"] } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/000077500000000000000000000000001461132021400262575ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/000077500000000000000000000000001461132021400275235ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/commander/000077500000000000000000000000001461132021400314705ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/commander/index.d.ts000066400000000000000000000005531461132021400333740ustar00rootroot00000000000000declare namespace commander { interface Option {} interface OptionConstructor { new(): Option; } interface Command {} interface CommandConstructor { new (): Command; } interface CommanderStatic extends Command { Command: CommandConstructor; Option: OptionConstructor; } } declare const commander: commander.CommanderStatic; export = commander; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/fake-node/000077500000000000000000000000001461132021400313545ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/fake-node/index.d.ts000066400000000000000000000002471461132021400332600ustar00rootroot00000000000000declare module 'fake-fs' { import { Path } from 'fake-path'; export interface File { path: Path; } } declare module 'fake-path' { export type Path = string; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/fake-types-lib-2/000077500000000000000000000000001461132021400324765ustar00rootroot00000000000000index.d.ts000066400000000000000000000005061461132021400343210ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/fake-types-lib-2declare module 'fake-types-lib-2' { export interface Data { field: number; method(): void; } export interface Base { id: string; } export interface Derived extends Base { name: string; } export function getData(): Data; } declare module 'fake-types-lib-2.5' { export interface Data { field: number; } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/fake-types-lib-3/000077500000000000000000000000001461132021400324775ustar00rootroot00000000000000global.d.ts000066400000000000000000000000361461132021400344510ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/fake-types-lib-3interface ArrayConstructor {} index.d.ts000066400000000000000000000002731461132021400343230ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/fake-types-lib-3/// declare namespace FakePackage3 { export interface FooBar {} } export = FakePackage3; export as namespace FakePackage3; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/fake-types-lib/000077500000000000000000000000001461132021400323375ustar00rootroot00000000000000index.d.ts000066400000000000000000000001521461132021400341570ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/fake-types-libexport interface InterfaceFromTypesPackage { field: string; field2: number; field3: string | number; } package-that-defines-other-packages/000077500000000000000000000000001461132021400363035ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@typesindex.d.ts000066400000000000000000000033151461132021400402060ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/package-that-defines-other-packagesdeclare module 're-export-via-eq-internal' { export interface FooBar {} export namespace FooBar { export type Type = number; } } declare module 're-export-via-eq' { import types = require('re-export-via-eq-internal'); export = types; } // ----------------------------------------------------------------------------- declare module 're-export-via-eq-v2-internal' { interface FooBar {} namespace FooBar { export type Type = number; } export = FooBar; } declare module 're-export-via-eq-v2' { import types = require('re-export-via-eq-v2-internal'); export = types; } // ----------------------------------------------------------------------------- declare module 're-export-via-star-internal' { export interface FooBar {} } declare module 're-export-via-star' { export * from 're-export-via-star-internal'; } // ----------------------------------------------------------------------------- declare module 're-export-via-star-with-rename-internal' { export interface FooBar {} } declare module 're-export-via-star-with-rename' { export * as NsName from 're-export-via-star-with-rename-internal'; } // ----------------------------------------------------------------------------- declare module 're-export-via-import-internal' { export interface FooBar {} } declare module 're-export-via-import' { import { FooBar } from 're-export-via-import-internal'; export { FooBar }; } // ----------------------------------------------------------------------------- declare module 're-export-cycle-dependency-1' { export interface FooBar {} export * from 're-export-cycle-dependency-2'; } declare module 're-export-cycle-dependency-2' { export interface BarFoo {} export * from 're-export-cycle-dependency-1'; } package-with-export-eq-variable/000077500000000000000000000000001461132021400355155ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@typesindex.d.ts000066400000000000000000000002161461132021400374150ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/@types/package-with-export-eq-variableinterface LibInterface { field: number; } declare module 'package-with-export-eq-variable' { const myLib: LibInterface; export = myLib; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/README.md000066400000000000000000000002451461132021400275370ustar00rootroot00000000000000# BEWARE Actually this folder is **not** node_modules from `npm` - it is just mock to use modules from "node_modules" without installing any additional package(s). timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/extensions-package/000077500000000000000000000000001461132021400320475ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/extensions-package/index.d.ts000066400000000000000000000000241461132021400337440ustar00rootroot00000000000000import './plugins'; node_modules/000077500000000000000000000000001461132021400344455ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/extensions-packageplugins-package/000077500000000000000000000000001461132021400375175ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/extensions-package/node_modulesindex.d.ts000066400000000000000000000002541461132021400414210ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/extensions-package/node_modules/plugins-packagedeclare const mergeName: mergeName.mergedName; declare namespace mergeName { export interface mergedName {} export interface OtherType {} } export { mergeName }; plugins.d.ts000066400000000000000000000003461461132021400342460ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/extensions-packageimport { mergeName } from 'plugins-package'; declare module 'plugins-package' { namespace mergeName { type A = string; } } declare module 'plugins-package/foobar' { export function foobar(val: mergeName.OtherType): void; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/fake-package/000077500000000000000000000000001461132021400305565ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/fake-package/index.d.ts000066400000000000000000000006371461132021400324650ustar00rootroot00000000000000import { InterfaceFromTypesPackage } from 'fake-types-lib'; import * as namespacedImportTypes from 'package-with-namespaced-re-export'; export interface Interface {} export type Type = number | string; export interface InterfaceWithFields { field: Type; field2: Interface; field3: InterfaceFromTypesPackage; } export module ModuleWithoutQuotes { export type A = string; } export { namespacedImportTypes }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/fake-package/some-class.d.ts000066400000000000000000000000761461132021400334210ustar00rootroot00000000000000export class SomeClass { private x; public constructor(); } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/ora/000077500000000000000000000000001461132021400270405ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/ora/index.d.ts000066400000000000000000000001671461132021400307450ustar00rootroot00000000000000declare namespace ora { interface Options { } } declare const ora: { (options: ora.Options): any; }; export = ora; package-with-cyclic-re-export-1/000077500000000000000000000000001461132021400340715ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modulesindex.d.ts000066400000000000000000000001301461132021400357640ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-cyclic-re-export-1export interface Package1Interface {} export * from 'package-with-cyclic-re-export-2'; package-with-cyclic-re-export-2/000077500000000000000000000000001461132021400340725ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modulesindex.d.ts000066400000000000000000000001301461132021400357650ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-cyclic-re-export-2export interface Package2Interface {} export * from 'package-with-cyclic-re-export-1'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-default-export/000077500000000000000000000000001461132021400335645ustar00rootroot00000000000000index.d.ts000066400000000000000000000001571461132021400354110ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-default-exportexport default class DefaultClass { } export interface NonDefaultInterface {} export type JustType = string; namespace.d.ts000066400000000000000000000001311461132021400362260ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-default-exportdeclare namespace NamespaceName { interface Options {} } export default NamespaceName; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-export-eq/000077500000000000000000000000001461132021400325455ustar00rootroot00000000000000index.d.ts000066400000000000000000000001771461132021400343740ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-export-eqdeclare namespace MyModule { export interface SomeCoolInterface { field: string; field2: number; } } export = MyModule; package-with-namespaced-import-export/000077500000000000000000000000001461132021400354715ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modulesindex.d.ts000066400000000000000000000001531461132021400373710ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-namespaced-import-exportimport * as fp1 from 'package-with-default-export'; export { fp1 }; export * as fp2 from 'fake-package'; package-with-namespaced-re-export/000077500000000000000000000000001461132021400345655ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modulesindex.d.ts000066400000000000000000000001301461132021400364600ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-namespaced-re-exportimport * as types from './types'; export { types }; export * as types2 from './types'; types.d.ts000066400000000000000000000000521461132021400365200ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-namespaced-re-exportexport interface Type { field: number; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-re-exports/000077500000000000000000000000001461132021400327315ustar00rootroot00000000000000content.d.ts000066400000000000000000000000331461132021400351120ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-re-exportsexport interface Foobar {} index.d.ts000066400000000000000000000002501461132021400345500ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-re-exportsexport * from './content'; export * as content from './content'; export { JustType as ReExportedName } from 'package-with-default-export'; export interface Barfoo {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-typings/000077500000000000000000000000001461132021400323165ustar00rootroot00000000000000index.d.ts000066400000000000000000000002751461132021400341440ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/node_modules/package-with-typingsexport const variable: number, variable2: string, variable3: string | number; export declare const declaredVariable: null, declaredVariable2: undefined, declaredVariable3: string | number; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/non-exported-abstract-class/000077500000000000000000000000001461132021400311305ustar00rootroot00000000000000abstract-class.d.ts000066400000000000000000000000501461132021400345440ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/non-exported-abstract-classexport abstract class AbstractClass { } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/non-exported-abstract-class/config.ts000066400000000000000000000001541461132021400327450ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/non-exported-abstract-class/index.spec.js000066400000000000000000000000641461132021400335260ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/non-exported-abstract-class/input.ts000066400000000000000000000001471461132021400326410ustar00rootroot00000000000000import { AbstractClass } from './abstract-class'; export class NormalClass extends AbstractClass { } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/non-exported-abstract-class/output.d.ts000066400000000000000000000001601461132021400332570ustar00rootroot00000000000000declare abstract class AbstractClass { } export declare class NormalClass extends AbstractClass { } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/primitive-generation/000077500000000000000000000000001461132021400277435ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/primitive-generation/config.ts000066400000000000000000000001541461132021400315600ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/primitive-generation/func.d.ts000066400000000000000000000002701461132021400314670ustar00rootroot00000000000000export type TypeName = string | number; export interface InterfaceName { prop: number; prop2: TypeName; } export declare function func2({ prop: prop3 }?: InterfaceName): TypeName; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/primitive-generation/index.spec.js000066400000000000000000000000641461132021400323410ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/primitive-generation/input.ts000066400000000000000000000003201461132021400314450ustar00rootroot00000000000000import { InterfaceName, TypeName, func2 } from './func'; export function func({ prop }: InterfaceName = { prop: 1, prop2: 1 }): TypeName { throw new Error('it does not matter' + prop); } export { func2 }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/primitive-generation/output.d.ts000066400000000000000000000004041461132021400320730ustar00rootroot00000000000000export type TypeName = string | number; export interface InterfaceName { prop: number; prop2: TypeName; } export declare function func2({ prop: prop3 }?: InterfaceName): TypeName; export declare function func({ prop }?: InterfaceName): TypeName; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-default-of-unnamed-class/000077500000000000000000000000001461132021400327045ustar00rootroot00000000000000class.ts000066400000000000000000000000301461132021400342730ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-default-of-unnamed-classexport default class {} config.ts000066400000000000000000000001721461132021400344420ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-default-of-unnamed-classimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400352230ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-default-of-unnamed-classrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000000431461132021400343310ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-default-of-unnamed-classexport { default } from './class'; output.d.ts000066400000000000000000000001121461132021400347510ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-default-of-unnamed-classdeclare class _default { } export { _default as default, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-named-and-default/000077500000000000000000000000001461132021400313745ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-named-and-default/config.ts000066400000000000000000000001541461132021400332110ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400337130ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-named-and-defaultrequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-named-and-default/input.ts000066400000000000000000000001031461132021400330750ustar00rootroot00000000000000export { default } from './lib'; export { sayHello } from './lib'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-named-and-default/lib.ts000066400000000000000000000001571461132021400325150ustar00rootroot00000000000000export const sayHello = (name: string) => { console.log(`Hello there, ${name}!`); } export default sayHello; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-named-and-default/output.d.ts000066400000000000000000000001461461132021400335270ustar00rootroot00000000000000export declare const sayHello: (name: string) => void; export { sayHello as default, }; export {}; tsconfig.json000066400000000000000000000001211461132021400340160ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-named-and-default{ "extends": "../tsconfig.json", "compilerOptions": { "types": ["node"] } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-namespace/000077500000000000000000000000001461132021400300625ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-namespace/config.ts000066400000000000000000000001541461132021400316770ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-namespace/index.spec.js000066400000000000000000000000641461132021400324600ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-namespace/input.ts000066400000000000000000000001011461132021400315610ustar00rootroot00000000000000export * as Foobar from 'package-with-namespaced-import-export'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-as-namespace/output.d.ts000066400000000000000000000001431461132021400322120ustar00rootroot00000000000000import * as Foobar from 'package-with-namespaced-import-export'; export { Foobar, }; export {}; re-export-default-export-as-default-export/000077500000000000000000000000001461132021400337535ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-casesconfig.ts000066400000000000000000000001541461132021400355700ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-as-default-exportimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400363510ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-as-default-exportrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000000451461132021400354610ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-as-default-exportexport { default } from './math.js'; math.ts000066400000000000000000000001231461132021400352500ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-as-default-exportconst subtract = (a: number, b: number): number => a - b; export default subtract; output.d.ts000066400000000000000000000001511461132021400361020ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-as-default-exportdeclare const subtract: (a: number, b: number) => number; export { subtract as default, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-name/000077500000000000000000000000001461132021400333025ustar00rootroot00000000000000class-names/000077500000000000000000000000001461132021400354315ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-nameclass-names.ts000066400000000000000000000001321461132021400402030ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-name/class-namesexport type ClassNamesFn = () => void; export const classNames: ClassNamesFn = () => { }; index.ts000066400000000000000000000001071461132021400371060ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-name/class-namesimport { classNames } from './class-names'; export default classNames; config.ts000066400000000000000000000001721461132021400350400ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-nameimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400356210ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-namerequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001541461132021400347320ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-nameexport { default as classNames } from './class-names'; export { default as isPromise } from './is-promise'; is-promise/000077500000000000000000000000001461132021400353125ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-nameindex.ts000066400000000000000000000001041461132021400367640ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-name/is-promiseimport { isPromise } from './is-promise'; export default isPromise; is-promise.ts000066400000000000000000000001171461132021400377500ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-name/is-promiseexport const isPromise: (value: unknown) => boolean = () => { return false; } output.d.ts000066400000000000000000000002371461132021400353570ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-default-export-with-same-nameexport type ClassNamesFn = () => void; export declare const classNames: ClassNamesFn; export declare const isPromise: (value: unknown) => boolean; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-importable-module/000077500000000000000000000000001461132021400321075ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-importable-module/class.ts000066400000000000000000000000401461132021400335560ustar00rootroot00000000000000export default class MyClass {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-importable-module/config.ts000066400000000000000000000001721461132021400337240ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400344260ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-importable-modulerequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-importable-module/input.ts000066400000000000000000000010001461132021400336050ustar00rootroot00000000000000export { Server } from 'http'; export * from 'fs'; export { SomeInterface } from './interface'; export { SomeInterface as Int1, AnotherInterface as Int2, default as DefInterface } from './interface'; export { constName as cName, letName as lName, funcName as fName, default as defFunction } from './variables'; export { default as MyClass } from './class'; export { default } from 'package-with-default-export'; import { NonDefaultInterface } from 'package-with-default-export'; export { NonDefaultInterface }; interface.ts000066400000000000000000000002521461132021400343370ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-importable-moduleexport interface SomeInterface { field: string; } export interface AnotherInterface { field: number; } export default interface DefaultInterface { field: boolean; } output.d.ts000066400000000000000000000013151461132021400341620ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-importable-moduleimport { Server } from 'http'; import { NonDefaultInterface, default as _default } from 'package-with-default-export'; export interface SomeInterface { field: string; } interface AnotherInterface { field: number; } interface DefaultInterface { field: boolean; } declare let letName: number; declare const constName = "const"; declare function funcName(): void; declare function defaultFunction(): void; export declare class MyClass { } export * from "fs"; export { AnotherInterface as Int2, DefaultInterface as DefInterface, NonDefaultInterface, Server, SomeInterface as Int1, _default as default, constName as cName, defaultFunction as defFunction, funcName as fName, letName as lName, }; export {}; tsconfig.json000066400000000000000000000001211461132021400345310ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-importable-module{ "extends": "../tsconfig.json", "compilerOptions": { "types": ["node"] } } variables.ts000066400000000000000000000002241461132021400343460ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-importable-moduleexport let letName = 123; export const constName = 'const'; export function funcName(): void {} export default function defaultFunction(): void {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-paths-module/000077500000000000000000000000001461132021400310705ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-paths-module/config.ts000066400000000000000000000001551461132021400327060ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-paths-module/index.spec.js000066400000000000000000000000641461132021400334660ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-paths-module/input.ts000066400000000000000000000000321461132021400325720ustar00rootroot00000000000000export * from '@/module'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-paths-module/module.ts000066400000000000000000000000421461132021400327210ustar00rootroot00000000000000export interface InterfaceName {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-paths-module/output.d.ts000066400000000000000000000000571461132021400332240ustar00rootroot00000000000000export interface InterfaceName { } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-from-paths-module/tsconfig.json000066400000000000000000000002251461132021400335760ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "paths": { "@/*": [ "./*" ], }, } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-modules/000077500000000000000000000000001461132021400276015ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-modules/config.ts000066400000000000000000000007241461132021400314210ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { allowedTypesLibraries: [], importedLibraries: [ 'package-with-cyclic-re-export-1', 'package-with-cyclic-re-export-2', 're-export-cycle-dependency-1', 're-export-cycle-dependency-2', 're-export-via-eq-v2', 're-export-via-eq', 're-export-via-import', 're-export-via-star-with-rename', 're-export-via-star', ], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-modules/index.spec.js000066400000000000000000000000641461132021400321770ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-modules/input.ts000066400000000000000000000013571461132021400313160ustar00rootroot00000000000000import { FooBar as EqFooBar } from 're-export-via-eq'; import { FooBar as ImportFooBar } from 're-export-via-import'; import { FooBar as StartFooBar } from 're-export-via-star'; import { NsName } from 're-export-via-star-with-rename'; import EqFooBarV2 from 're-export-via-eq-v2'; import { BarFoo } from 're-export-cycle-dependency-1'; import { FooBar } from 're-export-cycle-dependency-2'; import { Package2Interface } from 'package-with-cyclic-re-export-1'; import { Package1Interface } from 'package-with-cyclic-re-export-2'; export interface Interface { eq: EqFooBar; eqV2: EqFooBarV2; star: StartFooBar; ns: typeof NsName; cycle1: BarFoo; cycle2: FooBar; cycle3: Package2Interface; cycle4: Package1Interface; } export { ImportFooBar }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-modules/output.d.ts000066400000000000000000000013751461132021400317410ustar00rootroot00000000000000import { Package2Interface } from 'package-with-cyclic-re-export-1'; import { Package1Interface } from 'package-with-cyclic-re-export-2'; import { BarFoo } from 're-export-cycle-dependency-1'; import { FooBar } from 're-export-cycle-dependency-2'; import { FooBar as EqFooBar } from 're-export-via-eq'; import EqFooBarV2 from 're-export-via-eq-v2'; import { FooBar as ImportFooBar } from 're-export-via-import'; import { FooBar as StartFooBar } from 're-export-via-star'; import { NsName } from 're-export-via-star-with-rename'; export interface Interface { eq: EqFooBar; eqV2: EqFooBarV2; star: StartFooBar; ns: typeof NsName; cycle1: BarFoo; cycle2: FooBar; cycle3: Package2Interface; cycle4: Package1Interface; } export { ImportFooBar, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-modules/tsconfig.json000066400000000000000000000002131461132021400323040ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "esModuleInterop": true, "types": ["package-that-defines-other-packages"] } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-node_modules/000077500000000000000000000000001461132021400306065ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-node_modules/config.ts000066400000000000000000000002601461132021400324210ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { inlinedLibraries: ['package-with-re-exports'], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-node_modules/index.spec.js000066400000000000000000000000641461132021400332040ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-node_modules/input.ts000066400000000000000000000001701461132021400323130ustar00rootroot00000000000000import { Barfoo, Foobar, content } from 'package-with-re-exports'; export type Baz = Barfoo | Foobar | content.Foobar; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-in-node_modules/output.d.ts000066400000000000000000000002531461132021400327400ustar00rootroot00000000000000export interface Foobar { } export interface Barfoo { } export type Baz = Barfoo | Foobar | content.Foobar; declare namespace content { export { Foobar }; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star-with-selection/000077500000000000000000000000001461132021400314325ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star-with-selection/config.ts000066400000000000000000000001721461132021400332470ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400337510ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star-with-selectionrequire('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star-with-selection/input.ts000066400000000000000000000003331461132021400331400ustar00rootroot00000000000000export { Interface as Interface2, InterfaceWithFields, NonDefaultInterface, Type, Bar, ReExportedName as NewReExportedName } from './re-export'; export { NonDefaultInterface as Foo } from 'package-with-default-export'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star-with-selection/output.d.ts000066400000000000000000000006411461132021400335650ustar00rootroot00000000000000export { Interface as Interface2, InterfaceWithFields } from 'fake-package'; import { NonDefaultInterface, NonDefaultInterface as Foo, NonDefaultInterface as Type, NonDefaultInterface as Type2 } from 'package-with-default-export'; export { ReExportedName as NewReExportedName } from 'package-with-re-exports'; type Foo$1 = string; export type Bar = Foo$1; export { Foo, NonDefaultInterface, Type, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star-with-selection/re-export.ts000066400000000000000000000005271461132021400337330ustar00rootroot00000000000000export * from 'fake-package'; export { NonDefaultInterface } from 'package-with-default-export'; export { NonDefaultInterface as Type } from 'package-with-default-export'; export * from 'package-with-re-exports'; export * from 'package-with-cyclic-re-export-1'; export * from './re-export2'; export type Foo = string; export type Bar = Foo; re-export2.ts000066400000000000000000000001521461132021400337300ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star-with-selectionexport { NonDefaultInterface as Type2 } from 'package-with-default-export'; export * from 'fake-package'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star/000077500000000000000000000000001461132021400264765ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star/config.ts000066400000000000000000000001721461132021400303130ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star/index.spec.js000066400000000000000000000000641461132021400310740ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star/input.ts000066400000000000000000000000351461132021400302030ustar00rootroot00000000000000export * from './re-export'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star/output.d.ts000066400000000000000000000001271461132021400306300ustar00rootroot00000000000000export * from "fake-package"; export * from "package-with-default-export"; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-star/re-export.ts000066400000000000000000000001441461132021400307720ustar00rootroot00000000000000export * from 'fake-package'; export * from 'package-with-default-export'; export * from './input'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-with-paths/000077500000000000000000000000001461132021400276155ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-with-paths/config.ts000066400000000000000000000001541461132021400314320ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-with-paths/index.spec.js000066400000000000000000000000641461132021400322130ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-with-paths/input.ts000066400000000000000000000000651461132021400313250ustar00rootroot00000000000000export { DefaultClass } from '@test-case/re-export'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-with-paths/output.d.ts000066400000000000000000000001571461132021400317520ustar00rootroot00000000000000import { default as DefaultClass } from 'package-with-default-export'; export { DefaultClass, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-with-paths/re-export.ts000066400000000000000000000001071461132021400321100ustar00rootroot00000000000000export { default as DefaultClass } from 'package-with-default-export'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-with-paths/tsconfig.json000066400000000000000000000002051461132021400323210ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "paths": { "@test-case/re-export": [ "./re-export.ts" ] } } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-without-statements/000077500000000000000000000000001461132021400314155ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-without-statements/config.ts000066400000000000000000000001541461132021400332320ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-without-statements/index.spec.js000066400000000000000000000000641461132021400340130ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-without-statements/input.ts000066400000000000000000000000641461132021400331240ustar00rootroot00000000000000import * as FP from 'fake-package'; export { FP }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/re-export-without-statements/output.d.ts000066400000000000000000000001021461132021400335400ustar00rootroot00000000000000import * as FP from 'fake-package'; export { FP, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/recursive-types/000077500000000000000000000000001461132021400267535ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/recursive-types/config.ts000066400000000000000000000001721461132021400305700ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/recursive-types/index.spec.js000066400000000000000000000000641461132021400313510ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/recursive-types/input.ts000066400000000000000000000001161461132021400304600ustar00rootroot00000000000000import { FirstType } from './types'; export type MyType = FirstType; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/recursive-types/output.d.ts000066400000000000000000000003121461132021400311010ustar00rootroot00000000000000export type ThirdType = number; export type SecondType = T extends any ? V : FirstType; export type FirstType = SecondType; export type MyType = FirstType; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/recursive-types/types.ts000066400000000000000000000002121461132021400304620ustar00rootroot00000000000000type ThirdType = number; type SecondType = T extends any ? V : FirstType; export type FirstType = SecondType; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-imports/000077500000000000000000000000001461132021400265445ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-imports/config.ts000066400000000000000000000001721461132021400303610ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-imports/index.spec.js000066400000000000000000000000641461132021400311420ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-imports/input.ts000066400000000000000000000003131461132021400302500ustar00rootroot00000000000000import { InterfaceWithFields as FakePackageInterface } from 'fake-package'; export const myVar: FakePackageInterface = { field: 2, field2: {}, field3: { field: '', field2: 0, field3: 0, }, }; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-imports/output.d.ts000066400000000000000000000002131461132021400306720ustar00rootroot00000000000000import { InterfaceWithFields as FakePackageInterface } from 'fake-package'; export declare const myVar: FakePackageInterface; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-local-class/000077500000000000000000000000001461132021400272445ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-local-class/class-rename-1.ts000066400000000000000000000001661461132021400323270ustar00rootroot00000000000000import { OriginalClassName as LocalClassName1 } from './class'; export class ClassRename1 extends LocalClassName1 {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-local-class/class-rename-2.ts000066400000000000000000000001661461132021400323300ustar00rootroot00000000000000import { OriginalClassName as LocalClassName2 } from './class'; export class ClassRename2 extends LocalClassName2 {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-local-class/class.ts000066400000000000000000000000421461132021400307150ustar00rootroot00000000000000export class OriginalClassName {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-local-class/config.ts000066400000000000000000000001721461132021400310610ustar00rootroot00000000000000import { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-local-class/index.spec.js000066400000000000000000000000641461132021400316420ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-local-class/input.ts000066400000000000000000000001421461132021400307500ustar00rootroot00000000000000export { ClassRename1 } from './class-rename-1'; export { ClassRename2 } from './class-rename-2'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/rename-local-class/output.d.ts000066400000000000000000000002601461132021400313740ustar00rootroot00000000000000declare class OriginalClassName { } export declare class ClassRename1 extends OriginalClassName { } export declare class ClassRename2 extends OriginalClassName { } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/respect-preserve-const-enum/000077500000000000000000000000001461132021400311665ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/respect-preserve-const-enum/config.ts000066400000000000000000000002361461132021400330040ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { output: { respectPreserveConstEnum: true, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/respect-preserve-const-enum/const-enum.ts000066400000000000000000000001671461132021400336320ustar00rootroot00000000000000export const enum NonDirectlyExportedConstEnum { FooBar, } export const enum DirectlyReExportedConstEnum { BarFoo, } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/respect-preserve-const-enum/index.spec.js000066400000000000000000000000641461132021400335640ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/respect-preserve-const-enum/input.ts000066400000000000000000000004201461132021400326710ustar00rootroot00000000000000import { NonDirectlyExportedConstEnum } from './const-enum'; export const enum DirectlyExportedConstEnum { FirstItem = 'const enum', SecondItem = 1, } export const foo = NonDirectlyExportedConstEnum.FooBar; export { DirectlyReExportedConstEnum } from './const-enum'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/respect-preserve-const-enum/output.d.ts000066400000000000000000000004601461132021400333200ustar00rootroot00000000000000export declare const enum NonDirectlyExportedConstEnum { FooBar = 0 } export declare enum DirectlyReExportedConstEnum { BarFoo = 0 } export declare enum DirectlyExportedConstEnum { FirstItem = "const enum", SecondItem = 1 } export declare const foo = NonDirectlyExportedConstEnum.FooBar; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/respect-preserve-const-enum/tsconfig.json000066400000000000000000000001321461132021400336710ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "preserveConstEnums": true } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/run-test-case.ts000066400000000000000000000047401461132021400266510ustar00rootroot00000000000000import * as fs from 'fs'; import * as path from 'path'; import * as assert from 'assert'; import { generateDtsBundle } from '../../../src/bundle-generator'; import { TestCaseConfig } from './test-case-config'; interface TestCase { inputFileName: string; outputFileContent: string; config: TestCaseConfig; } // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access const currentPackageVersion = JSON.parse(fs.readFileSync(path.join(__dirname, '../../../package.json'), { encoding: 'utf-8' })).version as string; function prepareString(str: string): string { return str.replace(/\r\n/g, '\n'); } function findInputFile(testCaseDir: string): string { const tsFilePath = path.join(testCaseDir, 'input.ts'); if (fs.existsSync(tsFilePath)) { return tsFilePath; } const dtsFilePath = path.join(testCaseDir, 'input.d.ts'); if (fs.existsSync(dtsFilePath)) { return dtsFilePath; } const mtsFilePath = path.join(testCaseDir, 'input.mts'); if (fs.existsSync(mtsFilePath)) { return mtsFilePath; } const ctsFilePath = path.join(testCaseDir, 'input.cts'); if (fs.existsSync(ctsFilePath)) { return ctsFilePath; } throw new Error(`Cannot find input file in ${testCaseDir}`); } function getTestCaseConfig(testCaseDir: string): TestCase { const inputFileName = findInputFile(testCaseDir); const outputFileName = path.resolve(testCaseDir, 'output.d.ts'); assert(fs.existsSync(outputFileName), `Output file doesn't exist for ${testCaseDir}`); return { inputFileName, // eslint-disable-next-line @typescript-eslint/no-var-requires config: require(path.resolve(testCaseDir, 'config.ts')) as TestCaseConfig, outputFileContent: prepareString(fs.readFileSync(outputFileName, 'utf-8')).replace(/\$PACKAGE_CURRENT_VERSION/g, currentPackageVersion), }; } export function runTestCase(testCaseDirPath: string): void { const testCaseName = path.basename(testCaseDirPath); it(`e2e | ${testCaseName}`, () => { const testCase = getTestCaseConfig(testCaseDirPath); const outputOptions = testCase.config.output || {}; if (outputOptions.noBanner === undefined) { // hide banner by default for all tests except these who set it explicitly outputOptions.noBanner = true; } const dtsResult = generateDtsBundle( [ { ...testCase.config, output: outputOptions, filePath: testCase.inputFileName, }, ] )[0]; const result = prepareString(dtsResult); assert.strictEqual(result, testCase.outputFileContent, 'Output should be the same as expected'); }); } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/save-jsdoc/000077500000000000000000000000001461132021400256405ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/save-jsdoc/config.ts000066400000000000000000000001541461132021400274550ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/save-jsdoc/index.spec.js000066400000000000000000000000641461132021400302360ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/save-jsdoc/input.ts000066400000000000000000000007761461132021400273610ustar00rootroot00000000000000import { NonExportedClass } from './some-class'; /** * ExportedInterface JSDoc */ export interface ExportedInterface {} /** * ExportedType JSDoc */ export type ExportedType = string | number; /** * ExportedConstEnum JSDoc */ export const enum ExportedConstEnum { /** Item description */ Item, } /** * ExportedEnum JSDoc */ export enum ExportedEnum { Item } /** * const JSDoc */ export const constItem = 1; /** * ExportedClass JSDoc */ export class ExportedClass extends NonExportedClass {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/save-jsdoc/output.d.ts000066400000000000000000000014111461132021400277670ustar00rootroot00000000000000declare enum NonExportedEnum { First = 0 } /** * NonExportedConstEnum JSDoc */ export declare const enum NonExportedConstEnum { First = 0 } declare class NonExportedClass { method(): NonExportedEnum; /** Method description */ method2(): NonExportedConstEnum; } /** * ExportedInterface JSDoc */ export interface ExportedInterface { } /** * ExportedType JSDoc */ export type ExportedType = string | number; /** * ExportedConstEnum JSDoc */ export declare const enum ExportedConstEnum { /** Item description */ Item = 0 } /** * ExportedEnum JSDoc */ export declare enum ExportedEnum { Item = 0 } /** * const JSDoc */ export declare const constItem = 1; /** * ExportedClass JSDoc */ export declare class ExportedClass extends NonExportedClass { } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/save-jsdoc/some-class.ts000066400000000000000000000007351461132021400302630ustar00rootroot00000000000000/** * NonExportedEnum JSDoc must be removed from result dts */ export enum NonExportedEnum { First, } /** * NonExportedConstEnum JSDoc */ export const enum NonExportedConstEnum { First, } /** * NonExportedClass JSDoc must be removed from result dts */ export class NonExportedClass { public method(): NonExportedEnum { return NonExportedEnum.First; } /** Method description */ public method2(): NonExportedConstEnum { return NonExportedConstEnum.First; } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-default-from-one-package/000077500000000000000000000000001461132021400333065ustar00rootroot00000000000000config.ts000066400000000000000000000001721461132021400350440ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-default-from-one-packageimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400356250ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-default-from-one-packagerequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000005101461132021400347320ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-default-from-one-packageimport DefaultClass from 'package-with-default-export'; import DefaultClassRenamed from 'package-with-default-export'; import DefaultClassRenamed2 from 'package-with-default-export'; export interface ExportedInterface { field1: typeof DefaultClass; field2: typeof DefaultClassRenamed; field3: typeof DefaultClassRenamed2; } output.d.ts000066400000000000000000000005241461132021400353620ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-default-from-one-packageimport DefaultClass from 'package-with-default-export'; import DefaultClassRenamed from 'package-with-default-export'; import DefaultClassRenamed2 from 'package-with-default-export'; export interface ExportedInterface { field1: typeof DefaultClass; field2: typeof DefaultClassRenamed; field3: typeof DefaultClassRenamed2; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-star-from-one-package/000077500000000000000000000000001461132021400326335ustar00rootroot00000000000000config.ts000066400000000000000000000001721461132021400343710ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-star-from-one-packageimport { TestCaseConfig } from '../../test-cases/test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400351520ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-star-from-one-packagerequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000006341461132021400342660ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-star-from-one-packageimport * as firstImport from 'package-with-default-export'; import * as secondImport from 'package-with-default-export'; import * as thirdImportWholeModule from 'package-with-default-export'; import { ExportedType } from './module'; export interface ExportedInterface { field1: typeof firstImport.default; field2: typeof secondImport.default; field3: typeof thirdImportWholeModule; field4: ExportedType; } module.ts000066400000000000000000000002761461132021400344160ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-star-from-one-packageimport * as firstImportInModule from 'package-with-default-export'; export interface ExportedInterface { field1: typeof firstImportInModule; } export type ExportedType = string | number; output.d.ts000066400000000000000000000004321461132021400347050ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/several-import-star-from-one-packageimport * as firstImport from 'package-with-default-export'; export type ExportedType = string | number; export interface ExportedInterface { field1: typeof firstImport.default; field2: typeof firstImport.default; field3: typeof firstImport; field4: ExportedType; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/simple-tree-shaking/000077500000000000000000000000001461132021400274525ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/simple-tree-shaking/config.ts000066400000000000000000000001541461132021400312670ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/simple-tree-shaking/index.spec.js000066400000000000000000000000641461132021400320500ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/simple-tree-shaking/input.ts000066400000000000000000000001441461132021400311600ustar00rootroot00000000000000import { UsedInterface } from './input2'; export interface InterfaceName { prop: UsedInterface; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/simple-tree-shaking/input2.ts000066400000000000000000000001521461132021400312410ustar00rootroot00000000000000export interface NotUsedInterface { field: string; } export interface UsedInterface { field: number; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/simple-tree-shaking/output.d.ts000066400000000000000000000001701461132021400316020ustar00rootroot00000000000000export interface UsedInterface { field: number; } export interface InterfaceName { prop: UsedInterface; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/sort-nodes/000077500000000000000000000000001461132021400256775ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/sort-nodes/config.ts000066400000000000000000000002171461132021400275140ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { output: { sortNodes: true, }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/sort-nodes/index.spec.js000066400000000000000000000000641461132021400302750ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/sort-nodes/input.ts000066400000000000000000000003641461132021400274110ustar00rootroot00000000000000export interface CInterfaceName {} export interface BInterfaceName { prop: number; prop2: ATypeName; } export type BType = number; export type ATypeName = string | number; /** * Some description */ export type ZTypeName = string | null; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/sort-nodes/output.d.ts000066400000000000000000000003761461132021400300370ustar00rootroot00000000000000export interface BInterfaceName { prop: number; prop2: ATypeName; } export interface CInterfaceName { } export type ATypeName = string | number; export type BType = number; /** * Some description */ export type ZTypeName = string | null; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-class/000077500000000000000000000000001461132021400327465ustar00rootroot00000000000000config.ts000066400000000000000000000001541461132021400345040ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-classimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400352650ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-classrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001511461132021400343730ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-classimport { NonExportedClass } from './some-class'; export class ExportedClass extends NonExportedClass {} output.d.ts000066400000000000000000000002011461132021400350120ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-classdeclare class NonExportedClass { getThis(): this; } export declare class ExportedClass extends NonExportedClass { } export {}; some-class.ts000066400000000000000000000001161461132021400353030ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-classexport class NonExportedClass { public getThis(): this { return this; } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-enum/000077500000000000000000000000001461132021400326055ustar00rootroot00000000000000config.ts000066400000000000000000000001541461132021400343430ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-enumimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400351240ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-enumrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001511461132021400342320ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-enumimport { NonExportedClass } from './some-class'; export class ExportedClass extends NonExportedClass {} output.d.ts000066400000000000000000000004271461132021400346630ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-enumdeclare enum NonExportedEnum { First = 0 } export declare const enum NonExportedConstEnum { First = 0 } declare class NonExportedClass { method(): NonExportedEnum; method2(): NonExportedConstEnum; } export declare class ExportedClass extends NonExportedClass { } export {}; some-class.ts000066400000000000000000000004311461132021400351420ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-enumexport enum NonExportedEnum { First, } export const enum NonExportedConstEnum { First, } export class NonExportedClass { public method(): NonExportedEnum { return NonExportedEnum.First; } public method2(): NonExportedConstEnum { return NonExportedConstEnum.First; } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-function/000077500000000000000000000000001461132021400334665ustar00rootroot00000000000000config.ts000066400000000000000000000001541461132021400352240ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-functionimport { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; index.spec.js000066400000000000000000000000641461132021400360050ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-functionrequire('../run-test-case').runTestCase(__dirname); input.ts000066400000000000000000000001471461132021400351200ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-functionimport { getRandom } from './some-function'; export interface Interface { field: typeof getRandom; } output.d.ts000066400000000000000000000001531461132021400355400ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-functiondeclare function getRandom(): number; export interface Interface { field: typeof getRandom; } export {}; some-function.ts000066400000000000000000000000631461132021400365440ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/strip-export-from-non-exported-functionexport function getRandom(): number { return 4; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/test-case-config.ts000066400000000000000000000002401461132021400273010ustar00rootroot00000000000000import { EntryPointConfig } from '../../../src/bundle-generator'; export type TestCaseConfig = Pick; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/top-level-declarations/000077500000000000000000000000001461132021400301575ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/top-level-declarations/.gitignore000066400000000000000000000000341461132021400321440ustar00rootroot00000000000000!input.d.ts !library.d.ts timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/top-level-declarations/config.ts000066400000000000000000000001541461132021400317740ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/top-level-declarations/index.spec.js000066400000000000000000000000641461132021400325550ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/top-level-declarations/input.d.ts000066400000000000000000000003561461132021400321140ustar00rootroot00000000000000import { variable, SampleClass, ISample, SampleNS, functionName } from './library'; export namespace Sample { export { functionName }; export { variable }; export { SampleClass }; export { ISample }; export { SampleNS }; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/top-level-declarations/library.d.ts000066400000000000000000000002471461132021400324200ustar00rootroot00000000000000export function functionName(): void; export const variable: string; export class SampleClass {} export interface ISample {} export namespace SampleNS {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/top-level-declarations/output.d.ts000066400000000000000000000004751461132021400323170ustar00rootroot00000000000000declare function functionName(): void; declare const variable: string; declare class SampleClass { } export interface ISample { } declare namespace SampleNS { } export namespace Sample { export { functionName }; export { variable }; export { SampleClass }; export { ISample }; export { SampleNS }; } export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/tsconfig.json000066400000000000000000000003171461132021400263120ustar00rootroot00000000000000{ "extends": "../../../tsconfig.options.json", "compilerOptions": { // we especially set it to false to test that the tool set it to true inside and won't fail "declaration": false, "types": [] } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/umd-module-name/000077500000000000000000000000001461132021400265705ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/umd-module-name/config.ts000066400000000000000000000002341461132021400304040ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { output: { umdModuleName: 'MyUmdModule', }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/umd-module-name/index.spec.js000066400000000000000000000000641461132021400311660ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/umd-module-name/input.ts000066400000000000000000000000621461132021400302750ustar00rootroot00000000000000export interface InterfaceName { prop: number; } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/umd-module-name/output.d.ts000066400000000000000000000001401461132021400307150ustar00rootroot00000000000000export interface InterfaceName { prop: number; } export as namespace MyUmdModule; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/underscore-in-name/000077500000000000000000000000001461132021400272755ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/underscore-in-name/config.ts000066400000000000000000000001541461132021400311120ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = {}; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/underscore-in-name/func.ts000066400000000000000000000000431461132021400305750ustar00rootroot00000000000000export function __index(): void {} timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/underscore-in-name/index.spec.js000066400000000000000000000000641461132021400316730ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/underscore-in-name/input.ts000066400000000000000000000001751461132021400310070ustar00rootroot00000000000000export function __global(): void {} export { __index as __index, __index as ___index, __index as index, } from './func'; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/underscore-in-name/output.d.ts000066400000000000000000000002251461132021400314260ustar00rootroot00000000000000export declare function __index(): void; export declare function __global(): void; export { __index as ___index, __index as index, }; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/using-custom-types/000077500000000000000000000000001461132021400274015ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/using-custom-types/config.ts000066400000000000000000000002341461132021400312150ustar00rootroot00000000000000import { TestCaseConfig } from '../test-case-config'; const config: TestCaseConfig = { libraries: { allowedTypesLibraries: [], }, }; export = config; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/using-custom-types/custom-types/000077500000000000000000000000001461132021400320555ustar00rootroot00000000000000my-library/000077500000000000000000000000001461132021400340655ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/using-custom-types/custom-typesindex.d.ts000066400000000000000000000001501461132021400357620ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/using-custom-types/custom-types/my-librarydeclare module 'my-library' { export interface InterfaceName { field: string; field2: number; } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/using-custom-types/index.spec.js000066400000000000000000000000641461132021400317770ustar00rootroot00000000000000require('../run-test-case').runTestCase(__dirname); timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/using-custom-types/input.ts000066400000000000000000000001321461132021400311040ustar00rootroot00000000000000import { InterfaceName } from 'my-library'; export type MyType = InterfaceName | string; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/using-custom-types/output.d.ts000066400000000000000000000001461461132021400315340ustar00rootroot00000000000000import { InterfaceName } from 'my-library'; export type MyType = InterfaceName | string; export {}; timocov-dts-bundle-generator-c69ff0d/tests/e2e/test-cases/using-custom-types/tsconfig.json000066400000000000000000000001761461132021400321140ustar00rootroot00000000000000{ "extends": "../tsconfig.json", "compilerOptions": { "typeRoots": [ "node_modules/@types", "custom-types" ] } } timocov-dts-bundle-generator-c69ff0d/tests/e2e/tsconfig.json000066400000000000000000000005101461132021400242320ustar00rootroot00000000000000{ "extends": "../../tsconfig.options.json", "compilerOptions": { "composite": true, "incremental": true, "outDir": "./.tsc-out" }, "references": [ { "path": "../../src" }, ], "include": [ "./all-test-cases.ts", "./test-case-config.ts", "./test-cases/**/config.ts", "./test-cases/test-case-config.ts", ] } timocov-dts-bundle-generator-c69ff0d/tests/tsconfig.json000066400000000000000000000002401461132021400235570ustar00rootroot00000000000000{ "compilerOptions": { "composite": true, "incremental": true }, "references": [ { "path": "./e2e" }, { "path": "./unittests" } ], "include": [] } timocov-dts-bundle-generator-c69ff0d/tests/unittests/000077500000000000000000000000001461132021400231165ustar00rootroot00000000000000timocov-dts-bundle-generator-c69ff0d/tests/unittests/.gitignore000066400000000000000000000000131461132021400251000ustar00rootroot00000000000000/.tsc-out/ timocov-dts-bundle-generator-c69ff0d/tests/unittests/check-schema-match.spec.ts000066400000000000000000000103331461132021400300240ustar00rootroot00000000000000import * as assert from 'assert'; import { checkSchemaMatch, schemaPrimitiveValues, SchemeDescriptor } from '../../src/config-file/check-schema-match'; interface TestObj { foo: string; } interface TestInterface { booleanProp?: boolean; requiredBooleanProp: boolean; stringProp?: string; requiredStringProp: string; testArray?: TestObj[]; stringArray?: string[]; } const testSchema: SchemeDescriptor = { booleanProp: schemaPrimitiveValues.boolean, requiredBooleanProp: schemaPrimitiveValues.requiredBoolean, stringProp: schemaPrimitiveValues.string, requiredStringProp: schemaPrimitiveValues.requiredString, testArray: [{ foo: schemaPrimitiveValues.requiredString, }], stringArray: [schemaPrimitiveValues.string], }; function formatErrors(errors: string[]): string { return `errors: ${errors.join(' | ')}`; } describe('checkSchemaMatch', () => { it('should return true if object is fully matched', () => { const obj: TestInterface = { booleanProp: true, requiredBooleanProp: false, stringProp: 'test', requiredStringProp: 'test', }; const errors: string[] = []; assert.strictEqual(checkSchemaMatch(obj, testSchema, errors), true, formatErrors(errors)); }); it('should return true if object is matched partially', () => { const obj: TestInterface = { booleanProp: false, requiredBooleanProp: false, requiredStringProp: 'test', }; const errors: string[] = []; assert.strictEqual(checkSchemaMatch(obj, testSchema, errors), true, formatErrors(errors)); }); it('should return true if object contains only required values', () => { const obj: TestInterface = { requiredBooleanProp: false, requiredStringProp: 'test', }; const errors: string[] = []; assert.strictEqual(checkSchemaMatch(obj, testSchema, errors), true, formatErrors(errors)); }); it('should return false if object contains exceeded property', () => { const obj = { requiredBooleanProp: false, requiredStringProp: 'test', fooBar: 123, }; const errors: string[] = []; assert.strictEqual(checkSchemaMatch(obj, testSchema, errors), false, formatErrors(errors)); }); it('should return false if does not have required property', () => { const obj = { requiredBooleanProp: false, }; const errors: string[] = []; assert.strictEqual(checkSchemaMatch(obj, testSchema, errors), false, formatErrors(errors)); }); it('should return false if both does not have required property and have exceeded property', () => { const obj = { requiredBooleanProp: false, fooBar: 123, }; const errors: string[] = []; assert.strictEqual(checkSchemaMatch(obj, testSchema, errors), false, formatErrors(errors)); }); it('should return true for if value is empty array', () => { const obj: TestInterface = { requiredBooleanProp: false, requiredStringProp: 'test', stringArray: [], testArray: [], }; const errors: string[] = []; assert.strictEqual(checkSchemaMatch(obj, testSchema, errors), true, formatErrors(errors)); }); it('should return true if array contains only valid values', () => { const obj: TestInterface = { requiredBooleanProp: false, requiredStringProp: 'test', stringArray: ['string1', 'string2'], testArray: [ { foo: '3' }, { foo: '2' }, ], }; const errors: string[] = []; assert.strictEqual(checkSchemaMatch(obj, testSchema, errors), true, formatErrors(errors)); }); it('should return false if array contains invalid primitive values', () => { const obj = { requiredBooleanProp: false, requiredStringProp: 'test', stringArray: ['', false, 123], }; const errors: string[] = []; assert.strictEqual(checkSchemaMatch(obj, testSchema, errors), false, formatErrors(errors)); }); it('should return false if array contains invalid objects', () => { const obj = { requiredBooleanProp: false, requiredStringProp: 'test', testArray: [ { bar: '3' }, { foo: '2' }, { check: 123 }, ], }; const errors: string[] = []; assert.strictEqual(checkSchemaMatch(obj, testSchema, errors), false, formatErrors(errors)); }); it('should return false if root object is undefined', () => { const errors: string[] = []; assert.strictEqual(checkSchemaMatch(undefined, testSchema, errors), false, formatErrors(errors)); }); }); timocov-dts-bundle-generator-c69ff0d/tests/unittests/node-modules-helpres.spec.ts000066400000000000000000000034651461132021400304620ustar00rootroot00000000000000import * as assert from 'assert'; import { getTypesLibraryName, getLibraryName } from '../../src/helpers/node-modules'; describe('getLibraryName', () => { it('should return correct library name', () => { assert.strictEqual(getLibraryName('node_modules/typescript/index.js'), 'typescript'); assert.strictEqual(getLibraryName('./node_modules/typescript/index.js'), 'typescript'); assert.strictEqual(getLibraryName('./src/index.js'), null, 'Not node_modules folder'); assert.strictEqual(getLibraryName('node_modules/@types/fake-package/index.d.ts'), '@types/fake-package', 'fake-package package'); assert.strictEqual(getLibraryName('node_modules/some-package/node_modules/@types/fake-inside-package/index.d.ts'), '@types/fake-inside-package', 'node_modules inside other node_modules'); assert.strictEqual(getLibraryName('node_modules/@types/some-package/node_modules/not-types-package/index.d.ts'), 'not-types-package', 'node_modules inside node_modules/@types'); }); }); describe('getTypesLibraryName', () => { it('should return correct library types name', () => { assert.strictEqual(getTypesLibraryName('node_modules/typescript/index.js'), null); assert.strictEqual(getTypesLibraryName('./node_modules/typescript/index.js'), null); assert.strictEqual(getTypesLibraryName('./src/index.js'), null, 'Not node_modules folder'); assert.strictEqual(getTypesLibraryName('node_modules/@types/fake-package/index.d.ts'), 'fake-package', 'fake-package package'); assert.strictEqual(getTypesLibraryName('node_modules/some-package/node_modules/@types/fake-inside-package/index.d.ts'), 'fake-inside-package', 'node_modules inside other node_modules'); assert.strictEqual(getTypesLibraryName('node_modules/@types/some-package/node_modules/not-types-package/index.d.ts'), null, 'node_modules inside node_modules/@types'); }); }); timocov-dts-bundle-generator-c69ff0d/tests/unittests/tsconfig.json000066400000000000000000000003331461132021400256240ustar00rootroot00000000000000{ "extends": "../../tsconfig.options.json", "compilerOptions": { "composite": true, "incremental": true, "outDir": "./.tsc-out" }, "references": [ { "path": "../../src" }, ], "include": [ "**/*.ts" ] } timocov-dts-bundle-generator-c69ff0d/tsconfig.dts-config.json000066400000000000000000000002161461132021400244540ustar00rootroot00000000000000{ "extends": "./tsconfig.options.json", "compilerOptions": { "allowJs": true, "noEmit": true }, "include": [ "./dts-config.js" ] } timocov-dts-bundle-generator-c69ff0d/tsconfig.json000066400000000000000000000002341461132021400224200ustar00rootroot00000000000000{ "compilerOptions": { "composite": true, "incremental": true }, "references": [ { "path": "./src" }, { "path": "./tests" } ], "include": [] } timocov-dts-bundle-generator-c69ff0d/tsconfig.options.json000066400000000000000000000004521461132021400241140ustar00rootroot00000000000000{ "compilerOptions": { "declaration": true, "lib": ["es2020"], "module": "commonjs", "newLine": "LF", "noEmitOnError": true, "noFallthroughCasesInSwitch": true, "noImplicitReturns": true, "noUnusedLocals": true, "strict": true, "stripInternal": true, "target": "es2020" } }