-
-
Notifications
You must be signed in to change notification settings - Fork 4
Added Base Package.json Page #61
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
Open
AlexanderKaran
wants to merge
10
commits into
main
Choose a base branch
from
package-json-scan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+523
−17
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4563f3f
Added Base Package.json Page
AlexanderKaran 9f8c3c5
Merge branch 'main' into package-json-scan
AlexanderKaran 1fbca4b
Revert
AlexanderKaran f872486
Update src/routes/package-json/+page.server.ts
AlexanderKaran 339b01f
Update src/routes/package-json/+page.server.ts
AlexanderKaran fae05dd
Improved success message
AlexanderKaran 4b9b434
Wording fix
AlexanderKaran cd6da71
Changed FilterInput name to ModuleInput to make it more generic
AlexanderKaran c50d67e
Moved to remote functions for file selection
AlexanderKaran 2e53cc2
Updated filter
AlexanderKaran 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 hidden or 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,27 @@ | ||
| <script lang="ts"> | ||
| import type { HTMLButtonAttributes } from 'svelte/elements'; | ||
|
|
||
| type Props = HTMLButtonAttributes; | ||
|
|
||
| let { ...rest }: Props = $props(); | ||
| </script> | ||
|
|
||
| <button {...rest} type="submit">→</button> | ||
|
|
||
| <style> | ||
| button { | ||
| background: none; | ||
| border: none; | ||
| color: var(--accent); | ||
| font-family: inherit; | ||
| font-size: 1.125rem; | ||
| padding: 0.625rem 0.75rem; | ||
| cursor: pointer; | ||
| flex-shrink: 0; | ||
| line-height: 1; | ||
| } | ||
|
|
||
| button:hover { | ||
| color: var(--accent-hover); | ||
| } | ||
| </style> |
This file contains hidden or 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 hidden or 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,67 @@ | ||
| import { fail } from '@sveltejs/kit'; | ||
| import type { Actions } from './$types'; | ||
| import { all } from 'module-replacements'; | ||
| export const prerender = false; | ||
|
|
||
| function is_record(value: unknown): value is Record<string, unknown> { | ||
| return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
| } | ||
|
|
||
| export const actions = { | ||
| default: async ({ request }) => { | ||
| const data = await request.formData(); | ||
| const package_json = data.get('package_json'); | ||
|
|
||
| if (!package_json) { | ||
| return fail(400, { package_json, error: 'Paste a package.json file to scan.' }); | ||
| } | ||
|
|
||
| let parsed_json: unknown; | ||
| try { | ||
| parsed_json = JSON.parse(package_json.toString()); | ||
| } catch { | ||
| return fail(400, { package_json, error: 'File was not valid JSON.' }); | ||
| } | ||
|
|
||
| if (!is_record(parsed_json)) { | ||
| return fail(400, { | ||
| package_json, | ||
| error: 'File was an invalid format (not an object).' | ||
| }); | ||
| } | ||
|
|
||
| if (!parsed_json['devDependencies'] && !parsed_json['dependencies']) { | ||
| return fail(400, { | ||
| package_json, | ||
| error: 'No dependencies or devDependencies found.' | ||
| }); | ||
| } | ||
|
|
||
| const dev_deps = parsed_json['devDependencies'] ?? {}; | ||
| const prod_deps = parsed_json['dependencies'] ?? {}; | ||
|
|
||
| if (!is_record(dev_deps) || !is_record(prod_deps)) { | ||
| return fail(400, { | ||
| package_json, | ||
| error: 'dependencies and devDependencies must be objects.' | ||
| }); | ||
| } | ||
|
|
||
| const replacements = []; | ||
| for (const mapping of Object.keys(all.mappings)) { | ||
| const match = dev_deps[mapping] ?? prod_deps[mapping]; | ||
| if (match) { | ||
| replacements.push({ | ||
| dep: mapping, | ||
| replacement: all.mappings[mapping] | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| success: true, | ||
| checked: Object.keys(dev_deps).length + Object.keys(prod_deps).length, | ||
| replacements | ||
| }; | ||
| } | ||
| } satisfies Actions; | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.