Skip to content

Commit

Permalink
Verify the package names in desktop/bin/dump_artifacts.ts (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitphx authored Nov 10, 2022
1 parent bfa315f commit 485d379
Showing 1 changed file with 24 additions and 0 deletions.
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

0 comments on commit 485d379

Please sign in to comment.