-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into setup-husky-pre-commit
- Loading branch information
Showing
13 changed files
with
239 additions
and
52 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...ges/bundler-plugin-core/src/bundle-analysis/__tests__/bundleAnalysisPluginFactory.test.ts
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,42 @@ | ||
import { bundleAnalysisPluginFactory } from "../bundleAnalysisPluginFactory"; | ||
|
||
describe("bundleAnalysisPluginFactory", () => { | ||
it("returns a build start function", () => { | ||
const plugin = bundleAnalysisPluginFactory({ | ||
userOptions: {}, | ||
bundleAnalysisUploadPlugin: () => ({ | ||
version: "1", | ||
name: "plugin-name", | ||
pluginVersion: "1.0.0", | ||
}), | ||
}); | ||
|
||
expect(plugin.buildStart).toEqual(expect.any(Function)); | ||
}); | ||
|
||
it("returns a build end function", () => { | ||
const plugin = bundleAnalysisPluginFactory({ | ||
userOptions: {}, | ||
bundleAnalysisUploadPlugin: () => ({ | ||
version: "1", | ||
name: "plugin-name", | ||
pluginVersion: "1.0.0", | ||
}), | ||
}); | ||
|
||
expect(plugin.buildEnd).toEqual(expect.any(Function)); | ||
}); | ||
|
||
it("returns a write bundle function", () => { | ||
const plugin = bundleAnalysisPluginFactory({ | ||
userOptions: {}, | ||
bundleAnalysisUploadPlugin: () => ({ | ||
version: "1", | ||
name: "plugin-name", | ||
pluginVersion: "1.0.0", | ||
}), | ||
}); | ||
|
||
expect(plugin.writeBundle).toEqual(expect.any(Function)); | ||
}); | ||
}); |
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,5 @@ | ||
export class InvalidSlugError extends Error { | ||
constructor(msg: string) { | ||
super(msg); | ||
} | ||
} |
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,5 @@ | ||
export class NoCommitShaError extends Error { | ||
constructor(msg: string) { | ||
super(msg); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import childprocess from "child_process"; | ||
|
||
export function isProgramInstalled(programName: string): boolean { | ||
return !childprocess.spawnSync(programName).error; | ||
return !childprocess?.spawnSync(programName)?.error; | ||
} |
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 |
---|---|---|
@@ -1,11 +1,35 @@ | ||
import { InvalidSlugError } from "../errors/InvalidSlugError"; | ||
import { OWNER_SLUG_JOIN, REPO_SLUG_JOIN } from "./constants"; | ||
import { red } from "./logging"; | ||
|
||
export const preProcessBody = ( | ||
body: Record<string, string | null | undefined>, | ||
) => { | ||
for (const [key, value] of Object.entries(body)) { | ||
if (key === "slug" && typeof value === "string") { | ||
body[key] = encodeSlug(value); | ||
} | ||
|
||
if (!value || value === "") { | ||
body[key] = null; | ||
} | ||
} | ||
|
||
return body; | ||
}; | ||
|
||
export const encodeSlug = (slug: string): string => { | ||
const repoIndex = slug.lastIndexOf("/") + 1; | ||
const owner = slug.substring(0, repoIndex).trimEnd(); | ||
const repo = slug.substring(repoIndex, slug.length); | ||
|
||
if (owner === "" || repo === "") { | ||
red("Invalid owner and/or repo"); | ||
throw new InvalidSlugError("Invalid owner and/or repo"); | ||
} | ||
|
||
const encodedOwner = owner?.split("/").join(OWNER_SLUG_JOIN).slice(0, -3); | ||
const encodedSlug = [encodedOwner, repo].join(REPO_SLUG_JOIN); | ||
|
||
return encodedSlug; | ||
}; |
Oops, something went wrong.