Skip to content
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

Verify the package names in desktop/bin/dump_artifacts.ts #398

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/desktop/bin/dump_artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ async function copyStreamlitAppDirectory(options: CopyHomeDirectoryOptions) {
return fsExtra.copy(options.sourceDir, options.copyTo);
}

// Original: packages/sharing-editor/bin/gen-sample-app-manifests-json.ts
// TODO: Be DRY
async function readRequirements(
requirementsTxtPath: string
): Promise<string[]> {
Expand All @@ -161,6 +163,27 @@ async function readRequirements(
}
}

// Original: kernel/src/requirements.ts
// TODO: Be DRY
function verifyRequirements(requirements: string[]) {
requirements.forEach((req) => {
let url: URL;
try {
url = new URL(req);
} catch {
// `req` is not a URL -> OK
return;
}

// Ref: The scheme checker in the micropip implementation is https://github.com/pyodide/micropip/blob/v0.1.0/micropip/_compat_in_pyodide.py#L23-L26
if (url.protocol === "emfs:" || url.protocol === "file:") {
throw new Error(
`"emfs:" and "file:" protocols are not allowed for the requirement (${req})`
);
}
});
}

yargs(hideBin(process.argv))
.command(
"* <appHomeDirSource> [packages..]",
Expand Down Expand Up @@ -218,6 +241,7 @@ yargs(hideBin(process.argv))
await readRequirements(requirementTxtFilePath)
);
}
verifyRequirements(requirements);

await copyBuildDirectory({ copyTo: destDir, override: args.force });
await createSitePackagesSnapshot({
Expand Down