-
Notifications
You must be signed in to change notification settings - Fork 922
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
support TypeScript-format config #1253
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
33c2f62
support TypeScript-format config
g-plane 7e7fa8b
update docs
g-plane d42f274
fix lint error
g-plane 6a15653
re-implement importing TS-format config
g-plane 0b7e5a5
add compat usage
g-plane f90b0dd
build TS-format config file with "esbuild"
g-plane 61156f2
add error message when failed to load config
g-plane 49acf4e
update snapshot
g-plane d3d99ac
Update 10-reference.md
FredKSchott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`snowpack build config-ts-format: allFiles 1`] = ` | ||
Array [ | ||
"__snowpack__/env.js", | ||
"_dist_/index.js", | ||
] | ||
`; | ||
|
||
exports[`snowpack build config-ts-format: build/__snowpack__/env.js 1`] = `"export default {\\"MODE\\":\\"production\\",\\"NODE_ENV\\":\\"production\\"};"`; | ||
|
||
exports[`snowpack build config-ts-format: build/_dist_/index.js 1`] = `"console.log('fooey');"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default '/_dist_'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"private": true, | ||
"version": "1.0.1", | ||
"name": "@snowpack/test-config-ts-format", | ||
"description": "Test for TypeScript-format config file.", | ||
"scripts": { | ||
"testbuild": "snowpack build" | ||
}, | ||
"devDependencies": { | ||
"snowpack": "^2.12.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type {SnowpackConfig} from '../../../snowpack/src'; | ||
import dist from './export'; | ||
|
||
const config: Partial<SnowpackConfig> = { | ||
mount: { | ||
'./src': dist, | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('fooey'); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strong +1 on this feature request, but I think this implementation will break any relative imports (
../
out of the temp dir is going to point somewhere else).I'm not sure of a better way to do this though. We could create the '.snowpack.config.cjs' file alongside
snowpack.config.ts
temporarily, and then delete it when we're done. It sounds like cosmicconfig does some caching, which means this wouldn't have to happen every time. That's the best I can come up with right nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outdated. Please read next comment.
I've re-implemented this part (see latest commit). The new way is using Node.js built-invm
module and execute it. Because the code is wrapped in a function, variables created in the config file won't be leaked into outer scope. And, there won't be filesystem operations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the config file will be bundled by esbuild. That means any imports will be bundled into a single file, so placing the compiled file in temp directory should be safe now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's clever! It's definitely a solution to the relative imports problem but introduces a lot of extra effort with potential for slow down and bugs. I wouldn't feel comfortable unless this also came with a
console.warn("TypeScript config support is still experimental")
.tbh I still prefer the temporary single-file method outlined in https://github.com/pikapkg/snowpack/pull/1253/files#r501834625 to bundling the entire config. A light touch for a workaround like this is valuable. And, since cosmicconfig does caching, the users should rarely notice it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we can put the temporary file into current working directory, I think bundling is necessary, because this allows to import other TS files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @FredKSchott
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still thinking about this. St the very least, we want to get the current release that's on master out first, and then revisit this post-release. Hopefully getting that out tonight/tomorrow.