Open Ddupasquier opened 1 year ago
@Ddupasquier I think I found the issue with this - the store in your lib
folder is importing from routes
. So I think that's confusing the packager. Delete that and it should compile.
https://github.com/Ddupasquier/mysvelte_ui/blob/main/src/lib/stores/componentStore.ts#L3-L5
Thanks for narrowing it down sean. It seems the types gain additional nesting inside the output folder if you have imports from somewhere outside the input folder.
Minimal repro here: https://github.com/gtm-nayan/lib-extrainput-dts-repro and I think this needs to be fixed within svelte2tsx somewhere.
I'm baffled as to why the path just silently changes when adding the imports,
the options passed to ts.createCompilerHost
are
{
"paths": {
"$lib": [
"../src/lib"
],
"$lib/*": [
"../src/lib/*"
]
},
"rootDirs": [
"/home/ciri/sveltejs/lib-extrainput-dts-repro",
"/home/ciri/sveltejs/lib-extrainput-dts-repro/.svelte-kit/types"
],
"importsNotUsedAsValues": 2,
"isolatedModules": true,
"preserveValueImports": true,
"lib": [
"lib.esnext.d.ts",
"lib.dom.d.ts",
"lib.dom.iterable.d.ts"
],
"moduleResolution": 2,
"module": 99,
"target": 99,
"pathsBasePath": "/home/ciri/sveltejs/lib-extrainput-dts-repro/.svelte-kit",
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": false,
"strict": true,
"configFilePath": "/home/ciri/sveltejs/lib-extrainput-dts-repro/tsconfig.json",
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true,
"declarationDir": "dist/__package_types_tmp__",
"allowNonTsExtensions": true
}
nowhere does it mention the input folder so I'd expect the declarations to end up in dist/__package_types_tmp__/src/lib
in either case with this config 🤔
@gtm-nayan No worries. If it helps, I don't think this is an issue in svelte2tsx specifically. It's how TS compiles. I've seen this in node apps where they import "above" src, the output is always then weirdly nested because of that external import.
Perhaps a solution would be to do a check in the packager / svelte2tsx when it's complete and see if the output folder is in fact the one expected? I imagine it would be difficult to figure out which imports are "external" before running tsc
.
Ahh, turns out this absurdity is documented thankfully, and the way to get the output path consistent is to set rootDir.
Although, I'm trying that out and while the lib files are working as intended, it's now generating adjacent .d.ts
files for the files outside of input instead of ignoring/throwing on those imports.
wat 😕
So if I move 'stores' to be sibling to 'lib' this should ideally fix the issue?
@gtm-nayan we set declarationDir
for this in typescript.js
My idea for this:
libRoot
when invoking emitDts
<dist>/__package_types_tmp__/src/lib
and move it to <dist>
pick output that's within
/package_types_tmp/src/lib and move it to
that'd work, but cherry picking the output that way feels fragile for a few reasons:
src/lib/test.ts:1:21 - error TS6059: File '/home/ciri/sveltejs/huh/src/routes/test2.ts' is not under 'rootDir' '/home/ciri/sveltejs/huh/src/lib'. 'rootDir' is expected to contain all source files.
@Ddupasquier I think I found the issue with this - the store in your
lib
folder is importing fromroutes
. So I think that's confusing the packager. Delete that and it should compile.https://github.com/Ddupasquier/mysvelte_ui/blob/main/src/lib/stores/componentStore.ts#L3-L5
Moving the store to be sibling to lib has not fixed the issue.
New update:
I've moved everything from lib that does not have to do with the library I intend to publish to a new folder which is sibling to lib and routes. Now the index.d.ts file is being created in the dist directory BUT I'm getting a new error.
Errors:
1. pkg.exports["."].types is ./dist/index.d.ts but the file is not published. Is it specified in pkg.files?
2. pkg.types is ./dist/index.d.ts but the file is not published. Is it specified in pkg.files?
My package.json is the same as in my initial explanation of this issue, so you can refer to that. I will like this reply in the original issue as well.
New update:
I've moved everything from lib that does not have to do with the library I intend to publish to a new folder which is sibling to lib and routes. Now the index.d.ts file is being created in the dist directory BUT I'm getting a new error.
Errors: 1. pkg.exports["."].types is ./dist/index.d.ts but the file is not published. Is it specified in pkg.files? 2. pkg.types is ./dist/index.d.ts but the file is not published. Is it specified in pkg.files?
My package.json is the same as in my initial explanation of this issue, so you can refer to that. I will like this reply in the original issue as well.
Added, "dist/*" to pkg.files and it fixed the issue! I am now able to publish and I'm getting my types from the published library!
Updates:
index.d.ts now being created/newError
Describe the bug
When running "npm run package", I get this error:
For some reason the package script isn't generating my ts properly and I'm having an impossible time debugging it.
Here is what my package.json looks like:
Not entirely sure how relevant it is, but I've also included some pictures of my current file structure, as well as my dist content.
Here is the link to my repo. https://github.com/Ddupasquier/mysvelte_ui
This error can easily be reproduced by running the build script.
Reproduction
Unfortunately I cannot think of a way to reproduce this on a smaller scale. You'll see the error at the end of the build script. https://github.com/Ddupasquier/mysvelte_ui/tree/4438db330a094619d33c0d927638eab19572e49c
Logs
This is what I get in the logs while running npm publish:
System Info
Severity
serious, but I can work around it
Additional Information
Sorry if this is lacking any crucial information. I'll be readily available to provide anything else needed.