Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

co-located test types included in dist (tsconfig exclude vs plugin exclude) #280

Closed
Soviut opened this issue Sep 4, 2021 · 11 comments · Fixed by #347
Closed

co-located test types included in dist (tsconfig exclude vs plugin exclude) #280

Soviut opened this issue Sep 4, 2021 · 11 comments · Fixed by #347
Assignees
Labels
kind: bug Something isn't working properly kind: regression Specific type of bug -- past behavior that worked is now broken solution: duplicate This issue or pull request already exists solution: workaround available There is a workaround available for this issue

Comments

@Soviut
Copy link

Soviut commented Sep 4, 2021

What happens and why it is wrong

I'm building a Vue component library with vue-sfc-rollup. I've put each component in its own sub-directory to make it easy to group Jest tests, Storybook stories, etc. The tests are written in typescript and follow a ComponentName.spec.ts naming convention.

Since the tests are not imported anywhere, I would expect them to not be included in the build. However, after running a build, the test setup in my /tests directory and the test files that sit next to each component are having their type definitions included in the /dist output directory.

I tried adding an exclude config to the typescript plugin based on this StackOverflow answer https://stackoverflow.com/a/68687006/46914

This didn't seem to help; the excludes were not being respected. Finally, I wound up trying one of the other suggestion the same StackOverflow post and put the excludes in the tsconfig.json. This worked; the types the test setup and the test themselves were both excluded. However, this also removes proper type checking for these test files, something I want to keep.

Environment

Versions
    rollup: ^2.52.8 => 2.56.3 
    rollup-plugin-typescript2: ^0.30.0 => 0.30.0 
    typescript: ^4.3.5 => 4.3.5 

rollup.config.js

`rollup.config.js`:

// rollup.config.js
import fs from 'fs';
import path from 'path';
import vue from 'rollup-plugin-vue';
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import ttypescript from 'ttypescript';
import typescript from 'rollup-plugin-typescript2';
import minimist from 'minimist';

// Get browserslist config and remove ie from es build targets
const esbrowserslist = fs.readFileSync('./.browserslistrc')
.toString()
.split('\n')
.filter((entry) => entry && entry.substring(0, 2) !== 'ie');

// Extract babel preset-env config, to combine with esbrowserslist
const babelPresetEnvConfig = require('../babel.config')
.presets.filter((entry) => entry[0] === '@babel/preset-env')[0][1];

const argv = minimist(process.argv.slice(2));

const projectRoot = path.resolve(__dirname, '..');

const baseConfig = {
input: 'src/entry.ts',
plugins: {
preVue: [
alias({
entries: [
{
find: '@',
replacement: ${path.resolve(projectRoot, 'src')},
},
],
}),
],
replace: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
vue: {
css: true,
template: {
isProduction: true,
},
},
postVue: [
resolve({
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
}),
commonjs(),
],
babel: {
exclude: 'node_modules/**',
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
babelHelpers: 'bundled',
},
},
};

// ESM/UMD/IIFE shared settings: externals
// Refer to https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
const external = [
// list external dependencies, exactly the way it is written in the import statement.
// eg. 'jquery'
'vue',
'@vue/composition-api',
];

// UMD/IIFE shared settings: output.globals
// Refer to https://rollupjs.org/guide/en#output-globals for details
const globals = {
// Provide global variable names to replace your external imports
// eg. jquery: '$'
vue: 'Vue',
};

// Customize configs for individual targets
const buildFormats = [];
if (!argv.format || argv.format === 'es') {
const esConfig = {
...baseConfig,
input: 'src/entry.esm.ts',
external,
output: {
file: 'dist/arternal-components.esm.js',
format: 'esm',
exports: 'named',
},
plugins: [
replace(baseConfig.plugins.replace),
...baseConfig.plugins.preVue,
vue(baseConfig.plugins.vue),
...baseConfig.plugins.postVue,
// Only use typescript for declarations - babel will
// do actual js transformations
typescript({
typescript: ttypescript,
useTsconfigDeclarationDir: true,
emitDeclarationOnly: true,
// TODO: for some reason these do not exclude unless set in tsconfig.json
exclude: [
"/tests",
"
/tests",
"**/*.spec.ts",
],
}),
babel({
...baseConfig.plugins.babel,
presets: [
[
'@babel/preset-env',
{
...babelPresetEnvConfig,
targets: esbrowserslist,
},
],
],
}),
],
};
buildFormats.push(esConfig);
}

if (!argv.format || argv.format === 'cjs') {
const umdConfig = {
...baseConfig,
external,
output: {
compact: true,
file: 'dist/arternal-components.ssr.js',
format: 'cjs',
name: 'ArternalComponents',
exports: 'auto',
globals,
},
plugins: [
replace(baseConfig.plugins.replace),
...baseConfig.plugins.preVue,
vue({
...baseConfig.plugins.vue,
template: {
...baseConfig.plugins.vue.template,
optimizeSSR: true,
},
}),
...baseConfig.plugins.postVue,
babel(baseConfig.plugins.babel),
],
};
buildFormats.push(umdConfig);
}

if (!argv.format || argv.format === 'iife') {
const unpkgConfig = {
...baseConfig,
external,
output: {
compact: true,
file: 'dist/arternal-components.min.js',
format: 'iife',
name: 'ArternalComponents',
exports: 'auto',
globals,
},
plugins: [
replace(baseConfig.plugins.replace),
...baseConfig.plugins.preVue,
vue(baseConfig.plugins.vue),
...baseConfig.plugins.postVue,
babel(baseConfig.plugins.babel),
terser({
output: {
ecma: 5,
},
}),
],
};
buildFormats.push(unpkgConfig);
}

// Export config
export default buildFormats;

tsconfig.json

`tsconfig.json`:

{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"declaration": true,
"declarationDir": "dist/types",
"noUnusedLocals": true,
"noUnusedParameters": true,
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"newLine": "lf",
"types": [
"node",
"vue",
"jest"
],
"paths": {
"@/": [
"src/
"
]
},
"plugins": [
{
"transform": "@zerollup/ts-transform-paths",
"exclude": [
"*"
]
}
],
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"exclude": [
"node_modules",
"dist"
]
}

package.json

`package.json`:

{
"name": "@arternal/components",
"version": "0.1.1",
"description": "",
"scripts": {
"serve": "vue-cli-service serve dev/serve.ts",
"build": "cross-env NODE_ENV=production rollup --config build/rollup.config.js",
"test:unit": "vue-cli-service test:unit",
"build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es",
"build:ssr": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format cjs",
"build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife",
"postbuild": "rimraf ./dist/types/dev ./dist/types/src/entry.d.ts",
"prebuild": "rimraf ./dist",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"main": "dist/arternal-components.ssr.js",
"module": "dist/arternal-components.esm.js",
"browser": "dist/arternal-components.esm.js",
"unpkg": "dist/arternal-components.min.js",
"files": [
"dist/",
"src/**/
.vue"
],
"dependencies": {
"@vue/composition-api": "^1.1.3"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@babel/preset-typescript": "^7.14.5",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.4.2",
"@storybook/addon-actions": "^6.3.7",
"@storybook/addon-essentials": "^6.3.7",
"@storybook/addon-links": "^6.3.7",
"@storybook/vue": "^6.3.7",
"@types/jest": "^24.0.19",
"@vue/cli-plugin-babel": "^4.5.13",
"@vue/cli-plugin-typescript": "^4.5.13",
"@vue/cli-plugin-unit-jest": "~4.5.0",
"@vue/cli-service": "^4.5.13",
"@vue/test-utils": "^1.0.3",
"@zerollup/ts-transform-paths": "^1.7.18",
"autoprefixer": "^9.8.6",
"babel-loader": "^8.2.2",
"cross-env": "^7.0.3",
"minimist": "^1.2.5",
"postcss": "^7.0.36",
"regenerator-runtime": "^0.13.9",
"rimraf": "^3.0.2",
"rollup": "^2.52.8",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.30.0",
"rollup-plugin-vue": "^5.1.9",
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.9",
"ttypescript": "^1.5.12",
"typescript": "^4.3.5",
"vue": "^2.6.14",
"vue-loader": "^15.9.8",
"vue-template-compiler": "^2.6.14"
},
"peerDependencies": {
"vue": "^2.6.14"
},
"engines": {
"node": ">=12"
},
"sideEffects": false,
"types": "dist/types/src/entry.esm.d.ts"
}

plugin output with verbosity 3

plugin output with verbosity 3:

src/entry.esm.ts → dist/arternal-components.esm.js...
rpt2: built-in options overrides: {
"noEmitHelpers": false,
"importHelpers": true,
"noResolve": false,
"noEmit": false,
"inlineSourceMap": false,
"outDir": "/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/placeholder",
"moduleResolution": 2,
"allowNonTsExtensions": true
}
rpt2: parsed tsconfig: {
"options": {
"target": 99,
"module": 99,
"strict": true,
"declaration": true,
"declarationDir": "/home/soviut/projects/arternal/shared-components/dist/types",
"noUnusedLocals": true,
"noUnusedParameters": true,
"importHelpers": true,
"moduleResolution": 2,
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": "/home/soviut/projects/arternal/shared-components",
"newLine": 1,
"types": [
"node",
"vue",
"jest"
],
"paths": {
"@/": [
"src/
"
]
},
"plugins": [
{
"transform": "@zerollup/ts-transform-paths",
"exclude": [
""
]
}
],
"lib": [
"lib.esnext.d.ts",
"lib.dom.d.ts",
"lib.dom.iterable.d.ts",
"lib.scripthost.d.ts"
],
"configFilePath": "/home/soviut/projects/arternal/shared-components/tsconfig.json",
"pathsBasePath": "/home/soviut/projects/arternal/shared-components",
"noEmitHelpers": false,
"noResolve": false,
"noEmit": false,
"inlineSourceMap": false,
"outDir": "/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/placeholder",
"allowNonTsExtensions": true
},
"fileNames": [
"/home/soviut/projects/arternal/shared-components/shims-tsx.d.ts",
"/home/soviut/projects/arternal/shared-components/shims-vue.d.ts",
"/home/soviut/projects/arternal/shared-components/dev/serve.ts",
"/home/soviut/projects/arternal/shared-components/src/entry.esm.ts",
"/home/soviut/projects/arternal/shared-components/src/entry.ts",
"/home/soviut/projects/arternal/shared-components/src/lib-components/index.ts",
"/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/AvatarPill.spec.ts",
"/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/index.ts",
"/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/LinearChart.spec.ts",
"/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/index.ts",
"/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/RingChart.spec.ts",
"/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/index.ts",
"/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/Toggle.spec.ts",
"/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/index.ts",
"/home/soviut/projects/arternal/shared-components/tests/unit/setup.ts"
],
"typeAcquisition": {
"enable": false,
"include": [],
"exclude": []
},
"raw": {
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"declaration": true,
"declarationDir": "dist/types",
"noUnusedLocals": true,
"noUnusedParameters": true,
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"newLine": "lf",
"types": [
"node",
"vue",
"jest"
],
"paths": {
"@/
": [
"src/"
]
},
"plugins": [
{
"transform": "@zerollup/ts-transform-paths",
"exclude": [
"
"
]
}
],
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"exclude": [
"node_modules",
"dist"
],
"compileOnSave": false
},
"errors": [],
"wildcardDirectories": {
"/home/soviut/projects/arternal/shared-components": 1
},
"compileOnSave": false
}
rpt2: typescript version: 4.3.5
rpt2: tslib version: 2.1.0
rpt2: rollup version: 2.56.3
rpt2: rollup-plugin-typescript2 version: 0.30.0
rpt2: plugin options:
{
"typescript": "version 4.3.5",
"useTsconfigDeclarationDir": true,
"emitDeclarationOnly": true,
"verbosity": 3,
"check": true,
"clean": false,
"cacheRoot": "/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2",
"include": [
".ts+(|x)",
"**/
.ts+(|x)"
],
"exclude": [
".d.ts",
"**/
.d.ts"
],
"abortOnError": true,
"rollupCommonJSResolveHack": false,
"tsconfigOverride": {},
"transformers": [],
"tsconfigDefaults": {},
"objectHashIgnoreUnknownHack": false,
"cwd": "/home/soviut/projects/arternal/shared-components"
}
rpt2: rollup config:
{
"external": [
"vue",
"@vue/composition-api"
],
"input": "src/entry.esm.ts",
"plugins": [
{
"name": "replace"
},
{
"name": "alias"
},
{
"name": "VuePlugin"
},
{
"name": "node-resolve"
},
{
"name": "commonjs"
},
{
"name": "rpt2"
},
{
"name": "babel"
},
{
"name": "stdin"
}
],
"output": [
{
"exports": "named",
"file": "dist/arternal-components.esm.js",
"format": "esm",
"plugins": []
}
]
}
rpt2: tsconfig path: /home/soviut/projects/arternal/shared-components/tsconfig.json
rpt2: included:
[
".ts+(|x)",
"**/
.ts+(|x)"
]
rpt2: excluded:
[
".d.ts",
"**/
.d.ts"
]
(node:1418) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /home/soviut/projects/arternal/shared-components/node_modules/tslib/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use node --trace-deprecation ... to show where the warning was created)
rpt2: Ambient types:
rpt2: /home/soviut/projects/arternal/shared-components/shims-tsx.d.ts
rpt2: /home/soviut/projects/arternal/shared-components/shims-vue.d.ts
rpt2: /home/soviut/projects/arternal/shared-components/node_modules/@types/node/index.d.ts
rpt2: /home/soviut/projects/arternal/shared-components/node_modules/@types/jest/index.d.ts
rpt2: ambient types changed, redoing all semantic diagnostics
rpt2: transpiling '/home/soviut/projects/arternal/shared-components/src/entry.esm.ts'
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/code/cache/d23588596eb6d0649c602de7386d61877186ccff'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/syntacticDiagnostics/cache/d23588596eb6d0649c602de7386d61877186ccff'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/semanticDiagnostics/cache/d23588596eb6d0649c602de7386d61877186ccff'
rpt2: cache miss
rpt2: generated declarations for '/home/soviut/projects/arternal/shared-components/src/entry.esm.ts'
rpt2: transpiling '/home/soviut/projects/arternal/shared-components/src/lib-components/index.ts'
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/code/cache/48e0bbe76d94190d44edcc4fe102bd89b59d8de0'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/syntacticDiagnostics/cache/48e0bbe76d94190d44edcc4fe102bd89b59d8de0'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/semanticDiagnostics/cache/48e0bbe76d94190d44edcc4fe102bd89b59d8de0'
rpt2: cache miss
rpt2: generated declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/index.ts'
rpt2: transpiling '/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/index.ts'
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/code/cache/e17ad1cb70b06bb62a0aec98d95e0449fc5ef7ec'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/syntacticDiagnostics/cache/e17ad1cb70b06bb62a0aec98d95e0449fc5ef7ec'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/semanticDiagnostics/cache/e17ad1cb70b06bb62a0aec98d95e0449fc5ef7ec'
rpt2: cache miss
rpt2: generated declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/index.ts'
rpt2: transpiling '/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/index.ts'
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/code/cache/ec83024138360c1637ba5d324a15a3395559254e'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/syntacticDiagnostics/cache/ec83024138360c1637ba5d324a15a3395559254e'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/semanticDiagnostics/cache/ec83024138360c1637ba5d324a15a3395559254e'
rpt2: cache miss
rpt2: generated declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/index.ts'
rpt2: transpiling '/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/index.ts'
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/code/cache/0b1f3b293dfdc58aa6ee7dcf49e802ee4a77d810'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/syntacticDiagnostics/cache/0b1f3b293dfdc58aa6ee7dcf49e802ee4a77d810'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/semanticDiagnostics/cache/0b1f3b293dfdc58aa6ee7dcf49e802ee4a77d810'
rpt2: cache miss
rpt2: generated declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/index.ts'
rpt2: transpiling '/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/index.ts'
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/code/cache/6ba43b99645dcf89d1636a3049140db96bcce432'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/syntacticDiagnostics/cache/6ba43b99645dcf89d1636a3049140db96bcce432'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/semanticDiagnostics/cache/6ba43b99645dcf89d1636a3049140db96bcce432'
rpt2: cache miss
rpt2: generated declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/index.ts'
rpt2: transpiling '/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/AvatarPill.vue?rollup-plugin-vue=script.ts'
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/code/cache/5385fedc1bcf7f2133755af70fb708fccf2554f4'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/syntacticDiagnostics/cache/5385fedc1bcf7f2133755af70fb708fccf2554f4'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/semanticDiagnostics/cache/5385fedc1bcf7f2133755af70fb708fccf2554f4'
rpt2: cache miss
rpt2: generated declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/AvatarPill.vue?rollup-plugin-vue=script.ts'
rpt2: transpiling '/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/LinearChart.vue?rollup-plugin-vue=script.ts'
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/code/cache/2eda56c72ff92e8ab8166f6e26252bcdb248557b'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/syntacticDiagnostics/cache/2eda56c72ff92e8ab8166f6e26252bcdb248557b'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/semanticDiagnostics/cache/2eda56c72ff92e8ab8166f6e26252bcdb248557b'
rpt2: cache miss
rpt2: generated declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/LinearChart.vue?rollup-plugin-vue=script.ts'
rpt2: transpiling '/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/RingChart.vue?rollup-plugin-vue=script.ts'
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/code/cache/b8bb598e1797b13f1406777c08107cddab8af7d0'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/syntacticDiagnostics/cache/b8bb598e1797b13f1406777c08107cddab8af7d0'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/semanticDiagnostics/cache/b8bb598e1797b13f1406777c08107cddab8af7d0'
rpt2: cache miss
rpt2: generated declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/RingChart.vue?rollup-plugin-vue=script.ts'
rpt2: transpiling '/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/Toggle.vue?rollup-plugin-vue=script.ts'
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/code/cache/6fd65492c1e2d90e63bb6e0ab580e481f216c1f5'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/syntacticDiagnostics/cache/6fd65492c1e2d90e63bb6e0ab580e481f216c1f5'
rpt2: cache miss
rpt2: cache: '/home/soviut/projects/arternal/shared-components/node_modules/.cache/rollup-plugin-typescript2/rpt2_df69ec664174241979228bef6d9df36f2966eacb/semanticDiagnostics/cache/6fd65492c1e2d90e63bb6e0ab580e481f216c1f5'
rpt2: cache miss
rpt2: generated declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/Toggle.vue?rollup-plugin-vue=script.ts'
rpt2: generating target 1
rpt2: rolling caches
rpt2: generating missed declarations for '/home/soviut/projects/arternal/shared-components/shims-tsx.d.ts'
rpt2: generating missed declarations for '/home/soviut/projects/arternal/shared-components/shims-vue.d.ts'
rpt2: generating missed declarations for '/home/soviut/projects/arternal/shared-components/dev/serve.ts'
rpt2: generating missed declarations for '/home/soviut/projects/arternal/shared-components/src/entry.ts'
rpt2: generating missed declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/AvatarPill.spec.ts'
rpt2: generating missed declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/LinearChart.spec.ts'
rpt2: generating missed declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/RingChart.spec.ts'
rpt2: generating missed declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/Toggle.spec.ts'
rpt2: generating missed declarations for '/home/soviut/projects/arternal/shared-components/tests/unit/setup.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/entry.esm.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/entry.esm.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/index.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/index.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/index.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/AvatarPill/index.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/index.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/LinearChart/index.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/index.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/RingChart/index.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/index.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/Toggle/index.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/AvatarPill.vue?rollup-plugin-vue=script.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/AvatarPill/AvatarPill.vue.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/LinearChart.vue?rollup-plugin-vue=script.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/LinearChart/LinearChart.vue.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/RingChart.vue?rollup-plugin-vue=script.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/RingChart/RingChart.vue.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/Toggle.vue?rollup-plugin-vue=script.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/Toggle/Toggle.vue.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/dev/serve.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/dev/serve.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/entry.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/entry.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/AvatarPill.spec.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/AvatarPill/AvatarPill.spec.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/LinearChart.spec.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/LinearChart/LinearChart.spec.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/RingChart.spec.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/RingChart/RingChart.spec.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/Toggle.spec.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/src/lib-components/Toggle/Toggle.spec.d.ts'
rpt2: emitting declarations for '/home/soviut/projects/arternal/shared-components/tests/unit/setup.ts' to '/home/soviut/projects/arternal/shared-components/dist/types/tests/unit/setup.d.ts'
(!) Plugin replace: @rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to true, as the next major version will default this option to true.
created dist/arternal-components.esm.js in 3.5s

src/entry.ts → dist/arternal-components.ssr.js...
(!) Plugin replace: @rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to true, as the next major version will default this option to true.
created dist/arternal-components.ssr.js in 766ms

src/entry.ts → dist/arternal-components.min.js...
(!) Plugin replace: @rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to true, as the next major version will default this option to true.
(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
@vue/composition-api (guessing 'compositionApi')
created dist/arternal-components.min.js in 990ms

@ezolenko
Copy link
Owner

ezolenko commented Sep 9, 2021

You can make separate build targets for tests and actual code. Either play with input parameter in rollup config, or make a separate rollup config for tests (see how this plugin itself is being built).

@Soviut
Copy link
Author

Soviut commented Sep 9, 2021

@ezolenko Thanks, I'll have a look at the input parameter. To clarify, I don't want the tests included at all; they're only useful at development time.

@ezolenko
Copy link
Owner

ezolenko commented Sep 9, 2021

Yeah, usually tests are setup as a separate artifact that gets built and executed during every build, but excluded from the published package.

@Soviut
Copy link
Author

Soviut commented Sep 9, 2021

@ezolenko So after doing some more research on typescript exclude, I wound up making a tsconfig.compile.json that extends my tsconfig.json.

tsconfig.json*

  ...
  "exclude": [
    "node_modules",
    "dist",
  ]

tsconfig.compile.json

{
  "extends": "./tsconfig.json",
  "exclude": [
    "node_modules",
    "dist",

    "**/tests",
    "**/__tests__",
    "**/*.spec.ts"
  ]
}

Then I configured the plugin to use this typescript file

      typescript({
        typescript: ttypescript,
        useTsconfigDeclarationDir: true,
        emitDeclarationOnly: true,
        tsconfig: path.resolve(projectRoot, 'tsconfig.compile.json'), // <--
        verbosity: 3,
      }),

This works; the test files are being ignored and I don't have any .d.ts files for them showing up in dist.

BEFORE in verbosity 3 rpt2: parsed tsconfig:

    "fileNames": [
        "/home/soviut/projects/arternal/shared-components/shims-tsx.d.ts",
        "/home/soviut/projects/arternal/shared-components/shims-vue.d.ts",
        "/home/soviut/projects/arternal/shared-components/dev/serve.ts",
        "/home/soviut/projects/arternal/shared-components/src/entry.esm.ts",
        "/home/soviut/projects/arternal/shared-components/src/entry.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/index.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/AvatarPill.spec.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/index.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/LinearChart.spec.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/index.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/RingChart.spec.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/index.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/Toggle.spec.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/index.ts",
        "/home/soviut/projects/arternal/shared-components/tests/unit/setup.ts"
    ],

AFTER:

    "fileNames": [
        "/home/soviut/projects/arternal/shared-components/shims-tsx.d.ts",
        "/home/soviut/projects/arternal/shared-components/shims-vue.d.ts",
        "/home/soviut/projects/arternal/shared-components/dev/serve.ts",
        "/home/soviut/projects/arternal/shared-components/src/entry.esm.ts",
        "/home/soviut/projects/arternal/shared-components/src/entry.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/index.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/AvatarPill/index.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/LinearChart/index.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/RingChart/index.ts",
        "/home/soviut/projects/arternal/shared-components/src/lib-components/Toggle/index.ts"
    ],

This leaves me with only one question; what exactly is the typescript plugin exclude option doing? It seems to be happening after the tsconfig is parsed and the source files have already been accumulated.

@ezolenko
Copy link
Owner

ezolenko commented Sep 9, 2021

rollup (and its plugins) generates a stream of files and each plugin decides to process them or not based on plugin-level include/exclude options. If you exclude something on plugin level, it will not be transpiled into js. If you exclude something on tsconfig level, but rollup finds it in other ways (from input in rollup config for example), then it will be transpiled.

The problem with types and some ts files is that rollup doesn't see them if typescript doesn't generate import statement in generated js (if you import a ts file, but only use type only information which gets stripped from js for example). This will normally result in missing types (ts file not showing up in rollup stream, no d.ts file made for it). That's why the plugin takes all files found by typescript through tsconfig and just makes types for them, since it is better to make more than to miss something.

If you want to make a PR that would go through import chain for each transpiled file and flag them for type generation, I wouldn't complain (look for allImportedFiles in index.ts, right now it gets filled with tsconfig files and everything rollup serves up).

@Soviut
Copy link
Author

Soviut commented Sep 9, 2021

I'm still not sure I understand what exclude in the plugin does.

What I original expected was that having the following plugin config would strip any matched files from the list of filenames that the compiled tsconfig generates. Then definitions wouldn't be generated for excludes.

typescript({
  typescript: ttypescript,
  useTsconfigDeclarationDir: true,
  emitDeclarationOnly: true,

  exclude: [
    "**/tests",
    "**/__tests__",
    "**/*.spec.ts",
  ],
}),

Instead, it generating definitions for all my test (spec.ts) files, seemingly ignoring the exclude config.

@ezolenko
Copy link
Owner

ezolenko commented Sep 9, 2021

Yep. like I said, types are different due to that workaround.

@Soviut
Copy link
Author

Soviut commented Sep 9, 2021

Okay, thanks for letting my talk through this. Perhaps before attempting the allImportedFiles flagging, I could do a small docs update that explains this behaviour and how to work around it.

@Soviut Soviut closed this as completed Sep 9, 2021
@agilgur5 agilgur5 changed the title plugin excludes not working causing test types to be included in dist co-located test types included in dist Apr 23, 2022
@agilgur5 agilgur5 added solution: tsc behavior This is tsc's behavior as well, so this is not a bug with this plugin kind: support Asking for support with something or a specific use case labels Apr 23, 2022
@agilgur5 agilgur5 changed the title co-located test types included in dist co-located test types included in dist, have to use tsconfig exclude instead of plugin exclude Apr 23, 2022
@agilgur5 agilgur5 added the solution: intended behavior This is not a bug and is expected behavior label Apr 23, 2022
@agilgur5 agilgur5 added solution: duplicate This issue or pull request already exists kind: bug Something isn't working properly solution: workaround available There is a workaround available for this issue and removed solution: intended behavior This is not a bug and is expected behavior solution: tsc behavior This is tsc's behavior as well, so this is not a bug with this plugin kind: support Asking for support with something or a specific use case labels May 3, 2022
@agilgur5
Copy link
Collaborator

agilgur5 commented May 3, 2022

Looks like this duplicated #225 albeit with different wording. The thread here is very useful to understanding why this happens (differences between tsconfig exclude and Rollup/plugin filter exclude)

Running the filter function on allImportedFiles I think would work for the majority of cases like these. May need to play with the file extensions a bit though.

I might be able to get a PR for that out soon actually as it's relatively simple (vs. the whole import chain), but there's some rigorous testing needed for it, especially since all declaration files are part of the default plugin exclude

@agilgur5 agilgur5 added solution: unresolved Issue has been closed by OP but root cause has not necessarily been resolved and removed solution: unresolved Issue has been closed by OP but root cause has not necessarily been resolved labels Jun 4, 2022
@agilgur5 agilgur5 self-assigned this Jun 5, 2022
@agilgur5 agilgur5 changed the title co-located test types included in dist, have to use tsconfig exclude instead of plugin exclude co-located test types included in dist -- use tsconfig exclude instead of plugin exclude Jun 5, 2022
@agilgur5 agilgur5 changed the title co-located test types included in dist -- use tsconfig exclude instead of plugin exclude co-located test types included in dist (tsconfig exclude vs plugin exclude) Jun 5, 2022
@agilgur5
Copy link
Collaborator

agilgur5 commented Jun 5, 2022

So the specific case and confusion around plugin exclude vs. tsconfig exclude should be fixed by #347 .
Once that's merged and released, the workaround of using separate tsconfig excludes should no longer be necessary.

The more proper fix to go through the import chain (in allImportedFiles etc) will be handled separately by fixes to #211 / #7. Notably, for the case listed here -- which does not involve type-only files -- #347 's fix should completely handle it.

@agilgur5 agilgur5 added the kind: regression Specific type of bug -- past behavior that worked is now broken label Jun 23, 2022
@agilgur5
Copy link
Collaborator

#347 has been released in 0.33.0

Repository owner locked as resolved and limited conversation to collaborators Jul 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: bug Something isn't working properly kind: regression Specific type of bug -- past behavior that worked is now broken solution: duplicate This issue or pull request already exists solution: workaround available There is a workaround available for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants