-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): refactor sandpack provider (#342)
- Loading branch information
Showing
48 changed files
with
3,171 additions
and
2,580 deletions.
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.