-
Notifications
You must be signed in to change notification settings - Fork 354
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
feat(api): refactor sandpack provider #342
Merged
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
da197c5
initial version
danilowoz 483f9f8
template refactor
danilowoz be81322
match apis
danilowoz 67c8be4
revert some changes
danilowoz 106e1ef
redo tests
danilowoz e59872f
cover files tests
danilowoz a1cbf9d
deprecate customSetup.files
danilowoz 1eea9b1
tests, tests, tests...
danilowoz cdc9b6a
initial state
danilowoz 7c5a58c
remove sandbox id feature
danilowoz f594a5e
remove customSetup.main
danilowoz 6fe9f09
error messages
danilowoz dac3a1f
tests
danilowoz dc448df
ci: deploy workflows
danilowoz 23c1083
update websites
danilowoz e551e73
fixes
danilowoz 3b47ccf
conflict: merge from master
danilowoz df14e1c
add showRefreshButton api
danilowoz 1f05358
feat(type safe): custom setup (#361)
danilowoz 0a5a9ef
merge
danilowoz 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,80 @@ | ||
import { addPackageJSONIfNeeded } from "./utils"; | ||
|
||
const files = { | ||
"/package.json": { | ||
code: `{ | ||
"name": "custom-package", | ||
"main": "old-entry.js", | ||
"dependencies": { "baz": "*" }, | ||
"devDependencies": { "baz": "*" } | ||
}`, | ||
}, | ||
}; | ||
|
||
describe(addPackageJSONIfNeeded, () => { | ||
test("it merges the package.json - dependencies", () => { | ||
const output = addPackageJSONIfNeeded(files, { foo: "*" }); | ||
|
||
expect(JSON.parse(output["/package.json"].code).dependencies).toEqual({ | ||
baz: "*", | ||
foo: "*", | ||
}); | ||
}); | ||
|
||
test("it merges the package.json - dev-dependencies", () => { | ||
const output = addPackageJSONIfNeeded(files, undefined, { foo: "*" }); | ||
|
||
expect(JSON.parse(output["/package.json"].code).devDependencies).toEqual({ | ||
baz: "*", | ||
foo: "*", | ||
}); | ||
}); | ||
|
||
test("it merges the package.json - entry", () => { | ||
const output = addPackageJSONIfNeeded( | ||
files, | ||
undefined, | ||
undefined, | ||
"new-entry.js" | ||
); | ||
|
||
expect(JSON.parse(output["/package.json"].code).main).toEqual( | ||
"new-entry.js" | ||
); | ||
}); | ||
|
||
test("it returns an error when there is not dependencies at all", () => { | ||
try { | ||
addPackageJSONIfNeeded({ "/package.json": { code: `{}` } }); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} catch (err: any) { | ||
expect(err.message).toBe( | ||
'[sandpack-client]: "dependencies" was not specified - provide either a package.json or a "dependencies" value' | ||
); | ||
} | ||
}); | ||
|
||
test("it supports package.json without leading slash", () => { | ||
const output = addPackageJSONIfNeeded( | ||
{ | ||
"package.json": { | ||
code: `{ | ||
"main": "old-entry.js", | ||
"dependencies": { "baz": "*" }, | ||
"devDependencies": { "baz": "*" } | ||
}`, | ||
}, | ||
}, | ||
{ foo: "*" }, | ||
{ foo: "*" }, | ||
"new-entry.ts" | ||
); | ||
|
||
expect(JSON.parse(output["package.json"].code)).toEqual({ | ||
main: "new-entry.ts", | ||
dependencies: { baz: "*", foo: "*" }, | ||
devDependencies: { baz: "*", foo: "*" }, | ||
}); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.
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.
Should we normalise these paths at some point? Just a note for potential future improvements
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.
Yes, indeed we need to address it. I noted this problem when I was trying to implement a new feature, which fetches sandboxes from CodeSandbox, and I faced a ton of issues (see
resolveFile
for instance).Here's the task: #353