repopo 0.7.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +217 -6
- package/THIRD-PARTY-LICENSES.txt +152 -5
- package/esm/adapters/fluidFramework.d.ts +103 -0
- package/esm/adapters/fluidFramework.d.ts.map +1 -0
- package/esm/adapters/fluidFramework.js +124 -0
- package/esm/adapters/fluidFramework.js.map +1 -0
- package/esm/baseCommand.d.ts +1 -0
- package/esm/baseCommand.d.ts.map +1 -1
- package/esm/baseCommand.js +2 -0
- package/esm/baseCommand.js.map +1 -1
- package/esm/commands/check.d.ts.map +1 -1
- package/esm/commands/check.js +76 -50
- package/esm/commands/check.js.map +1 -1
- package/esm/commands/list.d.ts.map +1 -1
- package/esm/commands/list.js +3 -1
- package/esm/commands/list.js.map +1 -1
- package/esm/generators.d.ts +30 -2
- package/esm/generators.d.ts.map +1 -1
- package/esm/generators.js +31 -1
- package/esm/generators.js.map +1 -1
- package/esm/index.d.ts +14 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +13 -2
- package/esm/index.js.map +1 -1
- package/esm/makePolicy.d.ts +31 -2
- package/esm/makePolicy.d.ts.map +1 -1
- package/esm/makePolicy.js +27 -13
- package/esm/makePolicy.js.map +1 -1
- package/esm/perf.d.ts +6 -2
- package/esm/perf.d.ts.map +1 -1
- package/esm/perf.js +5 -4
- package/esm/perf.js.map +1 -1
- package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
- package/esm/policies/HtmlFileHeaders.js +11 -7
- package/esm/policies/HtmlFileHeaders.js.map +1 -1
- package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
- package/esm/policies/JsTsFileHeaders.js +11 -7
- package/esm/policies/JsTsFileHeaders.js.map +1 -1
- package/esm/policies/LicenseFileExists.d.ts.map +1 -1
- package/esm/policies/LicenseFileExists.js +22 -16
- package/esm/policies/LicenseFileExists.js.map +1 -1
- package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
- package/esm/policies/NoJsFileExtensions.js +16 -9
- package/esm/policies/NoJsFileExtensions.js.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.d.ts.map +1 -1
- package/esm/policies/NoLargeBinaryFiles.js +35 -29
- package/esm/policies/NoLargeBinaryFiles.js.map +1 -1
- package/esm/policies/NoPrivateWorkspaceDependencies.d.ts +37 -0
- package/esm/policies/NoPrivateWorkspaceDependencies.d.ts.map +1 -0
- package/esm/policies/NoPrivateWorkspaceDependencies.js +145 -0
- package/esm/policies/NoPrivateWorkspaceDependencies.js.map +1 -0
- package/esm/policies/PackageAllowedScopes.d.ts +88 -0
- package/esm/policies/PackageAllowedScopes.d.ts.map +1 -0
- package/esm/policies/PackageAllowedScopes.js +118 -0
- package/esm/policies/PackageAllowedScopes.js.map +1 -0
- package/esm/policies/PackageEsmType.d.ts +100 -0
- package/esm/policies/PackageEsmType.d.ts.map +1 -0
- package/esm/policies/PackageEsmType.js +261 -0
- package/esm/policies/PackageEsmType.js.map +1 -0
- package/esm/policies/PackageFolderName.d.ts +97 -0
- package/esm/policies/PackageFolderName.d.ts.map +1 -0
- package/esm/policies/PackageFolderName.js +108 -0
- package/esm/policies/PackageFolderName.js.map +1 -0
- package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
- package/esm/policies/PackageJsonProperties.js +36 -30
- package/esm/policies/PackageJsonProperties.js.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
- package/esm/policies/PackageJsonRepoDirectoryProperty.js +41 -37
- package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
- package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
- package/esm/policies/PackageJsonSorted.js +40 -28
- package/esm/policies/PackageJsonSorted.js.map +1 -1
- package/esm/policies/PackageLicense.d.ts +61 -0
- package/esm/policies/PackageLicense.d.ts.map +1 -0
- package/esm/policies/PackageLicense.js +135 -0
- package/esm/policies/PackageLicense.js.map +1 -0
- package/esm/policies/PackagePrivateField.d.ts +124 -0
- package/esm/policies/PackagePrivateField.d.ts.map +1 -0
- package/esm/policies/PackagePrivateField.js +159 -0
- package/esm/policies/PackagePrivateField.js.map +1 -0
- package/esm/policies/PackageReadme.d.ts +77 -0
- package/esm/policies/PackageReadme.d.ts.map +1 -0
- package/esm/policies/PackageReadme.js +213 -0
- package/esm/policies/PackageReadme.js.map +1 -0
- package/esm/policies/PackageScripts.d.ts +180 -2
- package/esm/policies/PackageScripts.d.ts.map +1 -1
- package/esm/policies/PackageScripts.js +358 -34
- package/esm/policies/PackageScripts.js.map +1 -1
- package/esm/policies/PackageTestScripts.d.ts +100 -0
- package/esm/policies/PackageTestScripts.d.ts.map +1 -0
- package/esm/policies/PackageTestScripts.js +155 -0
- package/esm/policies/PackageTestScripts.js.map +1 -0
- package/esm/policies/RequiredGitignorePatterns.d.ts.map +1 -1
- package/esm/policies/RequiredGitignorePatterns.js +30 -19
- package/esm/policies/RequiredGitignorePatterns.js.map +1 -1
- package/esm/policies.d.ts +9 -1
- package/esm/policies.d.ts.map +1 -1
- package/esm/policies.js +10 -1
- package/esm/policies.js.map +1 -1
- package/esm/policy.d.ts +37 -8
- package/esm/policy.d.ts.map +1 -1
- package/esm/policy.js +18 -9
- package/esm/policy.js.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +43 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
- package/esm/policyDefiners/defineFileHeaderPolicy.js +18 -5
- package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
- package/esm/policyDefiners/definePackagePolicy.d.ts +43 -2
- package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -1
- package/esm/policyDefiners/definePackagePolicy.js +41 -5
- package/esm/policyDefiners/definePackagePolicy.js.map +1 -1
- package/esm/tsdoc-metadata.json +1 -1
- package/esm/utils/indentation.d.ts +73 -0
- package/esm/utils/indentation.d.ts.map +1 -0
- package/esm/utils/indentation.js +97 -0
- package/esm/utils/indentation.js.map +1 -0
- package/esm/utils/packageName.d.ts +71 -0
- package/esm/utils/packageName.d.ts.map +1 -0
- package/esm/utils/packageName.js +79 -0
- package/esm/utils/packageName.js.map +1 -0
- package/oclif.manifest.json +1 -1
- package/package.json +33 -16
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
/**
|
|
3
|
+
* Regex to match leading whitespace at the start of a line.
|
|
4
|
+
*/
|
|
5
|
+
const LEADING_WHITESPACE_REGEX = /^(\s+)/;
|
|
6
|
+
/**
|
|
7
|
+
* Default indentation style used when detection fails or no indentation is found.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_INDENTATION = "\t";
|
|
12
|
+
/**
|
|
13
|
+
* Detect the indentation style used in a file.
|
|
14
|
+
*
|
|
15
|
+
* Analyzes the file content to determine whether tabs or spaces are used
|
|
16
|
+
* for indentation. This is useful when writing files to preserve
|
|
17
|
+
* the existing formatting style.
|
|
18
|
+
*
|
|
19
|
+
* @param filePath - Path to the file
|
|
20
|
+
* @param defaultIndentation - Indentation to use if detection fails (default: tab)
|
|
21
|
+
* @returns The detected indentation (tab character or number of spaces)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const indent = await detectIndentation("/path/to/package.json");
|
|
26
|
+
* // Returns "\t" for tabs, or a number like 2 or 4 for spaces
|
|
27
|
+
*
|
|
28
|
+
* // With custom default
|
|
29
|
+
* const indent = await detectIndentation("/path/to/file.yaml", 2);
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @alpha
|
|
33
|
+
*/
|
|
34
|
+
export async function detectIndentation(filePath, defaultIndentation = DEFAULT_INDENTATION) {
|
|
35
|
+
try {
|
|
36
|
+
const content = await readFile(filePath, "utf-8");
|
|
37
|
+
return detectIndentationFromContent(content, defaultIndentation);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// If we can't read the file, use default
|
|
41
|
+
return defaultIndentation;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Detect the indentation style used in text content.
|
|
46
|
+
*
|
|
47
|
+
* Analyzes the content string to determine whether tabs or spaces are used
|
|
48
|
+
* for indentation. This is a pure function useful for testing and for
|
|
49
|
+
* cases where the content is already in memory.
|
|
50
|
+
*
|
|
51
|
+
* The detection algorithm:
|
|
52
|
+
* 1. Splits content into lines
|
|
53
|
+
* 2. Finds the first line that starts with whitespace
|
|
54
|
+
* 3. If it starts with a tab, returns tab
|
|
55
|
+
* 4. If it starts with spaces, returns the count of leading spaces
|
|
56
|
+
* 5. If no indented lines found, returns the default
|
|
57
|
+
*
|
|
58
|
+
* @param content - The file content as a string
|
|
59
|
+
* @param defaultIndentation - Indentation to use if no indented lines found (default: tab)
|
|
60
|
+
* @returns The detected indentation (tab character or number of spaces)
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // JSON with 2-space indentation
|
|
65
|
+
* const json = '{\n "name": "test"\n}';
|
|
66
|
+
* detectIndentationFromContent(json); // Returns 2
|
|
67
|
+
*
|
|
68
|
+
* // YAML with tab indentation
|
|
69
|
+
* const yaml = 'root:\n\tchild: value';
|
|
70
|
+
* detectIndentationFromContent(yaml); // Returns "\t"
|
|
71
|
+
*
|
|
72
|
+
* // No indentation found - uses default
|
|
73
|
+
* detectIndentationFromContent('no indent'); // Returns "\t"
|
|
74
|
+
* detectIndentationFromContent('no indent', 4); // Returns 4
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @alpha
|
|
78
|
+
*/
|
|
79
|
+
export function detectIndentationFromContent(content, defaultIndentation = DEFAULT_INDENTATION) {
|
|
80
|
+
const lines = content.split("\n");
|
|
81
|
+
// Look for the first indented line to detect the pattern
|
|
82
|
+
for (const line of lines) {
|
|
83
|
+
const match = LEADING_WHITESPACE_REGEX.exec(line);
|
|
84
|
+
if (match?.[1]) {
|
|
85
|
+
const indent = match[1];
|
|
86
|
+
// Check if it's tabs
|
|
87
|
+
if (indent.startsWith("\t")) {
|
|
88
|
+
return "\t";
|
|
89
|
+
}
|
|
90
|
+
// Count spaces
|
|
91
|
+
return indent.length;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// No indented lines found, use default
|
|
95
|
+
return defaultIndentation;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=indentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indentation.js","sourceRoot":"","sources":["../../src/utils/indentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;GAEG;AACH,MAAM,wBAAwB,GAAG,QAAQ,CAAC;AAU1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAqB,IAAI,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,QAAgB,EAChB,qBAAuC,mBAAmB;IAE1D,IAAI,CAAC;QACJ,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAClD,OAAO,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAClE,CAAC;IAAC,MAAM,CAAC;QACR,yCAAyC;QACzC,OAAO,kBAAkB,CAAC;IAC3B,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,4BAA4B,CAC3C,OAAe,EACf,qBAAuC,mBAAmB;IAE1D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAElC,yDAAyD;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAChB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACxB,qBAAqB;YACrB,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7B,OAAO,IAAI,CAAC;YACb,CAAC;YACD,eAAe;YACf,OAAO,MAAM,CAAC,MAAM,CAAC;QACtB,CAAC;IACF,CAAC;IAED,uCAAuC;IACvC,OAAO,kBAAkB,CAAC;AAC3B,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\n\n/**\n * Regex to match leading whitespace at the start of a line.\n */\nconst LEADING_WHITESPACE_REGEX = /^(\\s+)/;\n\n/**\n * Represents detected indentation style.\n *\n * - `\"\\t\"` - Tab character\n * - `number` - Number of spaces (e.g., 2, 4)\n */\nexport type IndentationStyle = \"\\t\" | number;\n\n/**\n * Default indentation style used when detection fails or no indentation is found.\n *\n * @alpha\n */\nexport const DEFAULT_INDENTATION: IndentationStyle = \"\\t\";\n\n/**\n * Detect the indentation style used in a file.\n *\n * Analyzes the file content to determine whether tabs or spaces are used\n * for indentation. This is useful when writing files to preserve\n * the existing formatting style.\n *\n * @param filePath - Path to the file\n * @param defaultIndentation - Indentation to use if detection fails (default: tab)\n * @returns The detected indentation (tab character or number of spaces)\n *\n * @example\n * ```typescript\n * const indent = await detectIndentation(\"/path/to/package.json\");\n * // Returns \"\\t\" for tabs, or a number like 2 or 4 for spaces\n *\n * // With custom default\n * const indent = await detectIndentation(\"/path/to/file.yaml\", 2);\n * ```\n *\n * @alpha\n */\nexport async function detectIndentation(\n\tfilePath: string,\n\tdefaultIndentation: IndentationStyle = DEFAULT_INDENTATION,\n): Promise<IndentationStyle> {\n\ttry {\n\t\tconst content = await readFile(filePath, \"utf-8\");\n\t\treturn detectIndentationFromContent(content, defaultIndentation);\n\t} catch {\n\t\t// If we can't read the file, use default\n\t\treturn defaultIndentation;\n\t}\n}\n\n/**\n * Detect the indentation style used in text content.\n *\n * Analyzes the content string to determine whether tabs or spaces are used\n * for indentation. This is a pure function useful for testing and for\n * cases where the content is already in memory.\n *\n * The detection algorithm:\n * 1. Splits content into lines\n * 2. Finds the first line that starts with whitespace\n * 3. If it starts with a tab, returns tab\n * 4. If it starts with spaces, returns the count of leading spaces\n * 5. If no indented lines found, returns the default\n *\n * @param content - The file content as a string\n * @param defaultIndentation - Indentation to use if no indented lines found (default: tab)\n * @returns The detected indentation (tab character or number of spaces)\n *\n * @example\n * ```typescript\n * // JSON with 2-space indentation\n * const json = '{\\n \"name\": \"test\"\\n}';\n * detectIndentationFromContent(json); // Returns 2\n *\n * // YAML with tab indentation\n * const yaml = 'root:\\n\\tchild: value';\n * detectIndentationFromContent(yaml); // Returns \"\\t\"\n *\n * // No indentation found - uses default\n * detectIndentationFromContent('no indent'); // Returns \"\\t\"\n * detectIndentationFromContent('no indent', 4); // Returns 4\n * ```\n *\n * @alpha\n */\nexport function detectIndentationFromContent(\n\tcontent: string,\n\tdefaultIndentation: IndentationStyle = DEFAULT_INDENTATION,\n): IndentationStyle {\n\tconst lines = content.split(\"\\n\");\n\n\t// Look for the first indented line to detect the pattern\n\tfor (const line of lines) {\n\t\tconst match = LEADING_WHITESPACE_REGEX.exec(line);\n\t\tif (match?.[1]) {\n\t\t\tconst indent = match[1];\n\t\t\t// Check if it's tabs\n\t\t\tif (indent.startsWith(\"\\t\")) {\n\t\t\t\treturn \"\\t\";\n\t\t\t}\n\t\t\t// Count spaces\n\t\t\treturn indent.length;\n\t\t}\n\t}\n\n\t// No indented lines found, use default\n\treturn defaultIndentation;\n}\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for working with npm package names.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Result of parsing a package name into its components.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
export interface ParsedPackageName {
|
|
12
|
+
/**
|
|
13
|
+
* The full original package name.
|
|
14
|
+
*/
|
|
15
|
+
name: string;
|
|
16
|
+
/**
|
|
17
|
+
* The scope portion of the name (e.g., `@myorg`), or `undefined` if unscoped.
|
|
18
|
+
*/
|
|
19
|
+
scope: string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The name portion without the scope (e.g., `my-package`).
|
|
22
|
+
* For unscoped packages, this is the same as `name`.
|
|
23
|
+
*/
|
|
24
|
+
unscopedName: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parse a package name into its scope and unscoped name components.
|
|
28
|
+
*
|
|
29
|
+
* @param packageName - The package name to parse (e.g., `@myorg/my-package` or `my-package`)
|
|
30
|
+
* @returns An object containing the parsed components
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* parsePackageName("@myorg/my-package")
|
|
35
|
+
* // Returns: { name: "@myorg/my-package", scope: "@myorg", unscopedName: "my-package" }
|
|
36
|
+
*
|
|
37
|
+
* parsePackageName("my-package")
|
|
38
|
+
* // Returns: { name: "my-package", scope: undefined, unscopedName: "my-package" }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @alpha
|
|
42
|
+
*/
|
|
43
|
+
export declare function parsePackageName(packageName: string): ParsedPackageName;
|
|
44
|
+
/**
|
|
45
|
+
* Extract just the scope from a package name.
|
|
46
|
+
*
|
|
47
|
+
* @param packageName - The package name (e.g., `@myorg/foo` or `unscoped-pkg`)
|
|
48
|
+
* @returns The scope (e.g., `@myorg`) or `undefined` if unscoped
|
|
49
|
+
*
|
|
50
|
+
* @alpha
|
|
51
|
+
*/
|
|
52
|
+
export declare function getPackageScope(packageName: string): string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Extract the unscoped portion of a package name.
|
|
55
|
+
*
|
|
56
|
+
* @param packageName - The package name (e.g., `@myorg/my-package` or `my-package`)
|
|
57
|
+
* @returns The unscoped name (e.g., `my-package`)
|
|
58
|
+
*
|
|
59
|
+
* @alpha
|
|
60
|
+
*/
|
|
61
|
+
export declare function getUnscopedName(packageName: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Check if a package name is scoped.
|
|
64
|
+
*
|
|
65
|
+
* @param packageName - The package name to check
|
|
66
|
+
* @returns `true` if the package is scoped (starts with `@` and contains `/`)
|
|
67
|
+
*
|
|
68
|
+
* @alpha
|
|
69
|
+
*/
|
|
70
|
+
export declare function isScoped(packageName: string): boolean;
|
|
71
|
+
//# sourceMappingURL=packageName.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageName.d.ts","sourceRoot":"","sources":["../../src/utils/packageName.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1B;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,iBAAiB,CAwBvE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEvE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAErD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for working with npm package names.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Parse a package name into its scope and unscoped name components.
|
|
8
|
+
*
|
|
9
|
+
* @param packageName - The package name to parse (e.g., `@myorg/my-package` or `my-package`)
|
|
10
|
+
* @returns An object containing the parsed components
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* parsePackageName("@myorg/my-package")
|
|
15
|
+
* // Returns: { name: "@myorg/my-package", scope: "@myorg", unscopedName: "my-package" }
|
|
16
|
+
*
|
|
17
|
+
* parsePackageName("my-package")
|
|
18
|
+
* // Returns: { name: "my-package", scope: undefined, unscopedName: "my-package" }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @alpha
|
|
22
|
+
*/
|
|
23
|
+
export function parsePackageName(packageName) {
|
|
24
|
+
if (!packageName.startsWith("@")) {
|
|
25
|
+
return {
|
|
26
|
+
name: packageName,
|
|
27
|
+
scope: undefined,
|
|
28
|
+
unscopedName: packageName,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const slashIndex = packageName.indexOf("/");
|
|
32
|
+
if (slashIndex === -1) {
|
|
33
|
+
// Malformed scoped name without a slash - treat as unscoped
|
|
34
|
+
return {
|
|
35
|
+
name: packageName,
|
|
36
|
+
scope: undefined,
|
|
37
|
+
unscopedName: packageName,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
name: packageName,
|
|
42
|
+
scope: packageName.slice(0, slashIndex),
|
|
43
|
+
unscopedName: packageName.slice(slashIndex + 1),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Extract just the scope from a package name.
|
|
48
|
+
*
|
|
49
|
+
* @param packageName - The package name (e.g., `@myorg/foo` or `unscoped-pkg`)
|
|
50
|
+
* @returns The scope (e.g., `@myorg`) or `undefined` if unscoped
|
|
51
|
+
*
|
|
52
|
+
* @alpha
|
|
53
|
+
*/
|
|
54
|
+
export function getPackageScope(packageName) {
|
|
55
|
+
return parsePackageName(packageName).scope;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Extract the unscoped portion of a package name.
|
|
59
|
+
*
|
|
60
|
+
* @param packageName - The package name (e.g., `@myorg/my-package` or `my-package`)
|
|
61
|
+
* @returns The unscoped name (e.g., `my-package`)
|
|
62
|
+
*
|
|
63
|
+
* @alpha
|
|
64
|
+
*/
|
|
65
|
+
export function getUnscopedName(packageName) {
|
|
66
|
+
return parsePackageName(packageName).unscopedName;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if a package name is scoped.
|
|
70
|
+
*
|
|
71
|
+
* @param packageName - The package name to check
|
|
72
|
+
* @returns `true` if the package is scoped (starts with `@` and contains `/`)
|
|
73
|
+
*
|
|
74
|
+
* @alpha
|
|
75
|
+
*/
|
|
76
|
+
export function isScoped(packageName) {
|
|
77
|
+
return parsePackageName(packageName).scope !== undefined;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=packageName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageName.js","sourceRoot":"","sources":["../../src/utils/packageName.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAyBH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAmB;IACnD,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,OAAO;YACN,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,SAAS;YAChB,YAAY,EAAE,WAAW;SACzB,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;QACvB,4DAA4D;QAC5D,OAAO;YACN,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,SAAS;YAChB,YAAY,EAAE,WAAW;SACzB,CAAC;IACH,CAAC;IAED,OAAO;QACN,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC;QACvC,YAAY,EAAE,WAAW,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC;KAC/C,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,WAAmB;IAClD,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC;AAC5C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,WAAmB;IAClD,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,WAAmB;IAC3C,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * Utility functions for working with npm package names.\n *\n * @packageDocumentation\n */\n\n/**\n * Result of parsing a package name into its components.\n *\n * @alpha\n */\nexport interface ParsedPackageName {\n\t/**\n\t * The full original package name.\n\t */\n\tname: string;\n\n\t/**\n\t * The scope portion of the name (e.g., `@myorg`), or `undefined` if unscoped.\n\t */\n\tscope: string | undefined;\n\n\t/**\n\t * The name portion without the scope (e.g., `my-package`).\n\t * For unscoped packages, this is the same as `name`.\n\t */\n\tunscopedName: string;\n}\n\n/**\n * Parse a package name into its scope and unscoped name components.\n *\n * @param packageName - The package name to parse (e.g., `@myorg/my-package` or `my-package`)\n * @returns An object containing the parsed components\n *\n * @example\n * ```typescript\n * parsePackageName(\"@myorg/my-package\")\n * // Returns: { name: \"@myorg/my-package\", scope: \"@myorg\", unscopedName: \"my-package\" }\n *\n * parsePackageName(\"my-package\")\n * // Returns: { name: \"my-package\", scope: undefined, unscopedName: \"my-package\" }\n * ```\n *\n * @alpha\n */\nexport function parsePackageName(packageName: string): ParsedPackageName {\n\tif (!packageName.startsWith(\"@\")) {\n\t\treturn {\n\t\t\tname: packageName,\n\t\t\tscope: undefined,\n\t\t\tunscopedName: packageName,\n\t\t};\n\t}\n\n\tconst slashIndex = packageName.indexOf(\"/\");\n\tif (slashIndex === -1) {\n\t\t// Malformed scoped name without a slash - treat as unscoped\n\t\treturn {\n\t\t\tname: packageName,\n\t\t\tscope: undefined,\n\t\t\tunscopedName: packageName,\n\t\t};\n\t}\n\n\treturn {\n\t\tname: packageName,\n\t\tscope: packageName.slice(0, slashIndex),\n\t\tunscopedName: packageName.slice(slashIndex + 1),\n\t};\n}\n\n/**\n * Extract just the scope from a package name.\n *\n * @param packageName - The package name (e.g., `@myorg/foo` or `unscoped-pkg`)\n * @returns The scope (e.g., `@myorg`) or `undefined` if unscoped\n *\n * @alpha\n */\nexport function getPackageScope(packageName: string): string | undefined {\n\treturn parsePackageName(packageName).scope;\n}\n\n/**\n * Extract the unscoped portion of a package name.\n *\n * @param packageName - The package name (e.g., `@myorg/my-package` or `my-package`)\n * @returns The unscoped name (e.g., `my-package`)\n *\n * @alpha\n */\nexport function getUnscopedName(packageName: string): string {\n\treturn parsePackageName(packageName).unscopedName;\n}\n\n/**\n * Check if a package name is scoped.\n *\n * @param packageName - The package name to check\n * @returns `true` if the package is scoped (starts with `@` and contains `/`)\n *\n * @alpha\n */\nexport function isScoped(packageName: string): boolean {\n\treturn parsePackageName(packageName).scope !== undefined;\n}\n"]}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repopo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Enforce policies on all or some of the files in a git repository.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"policy",
|
|
@@ -42,46 +42,61 @@
|
|
|
42
42
|
"/THIRD-PARTY-LICENSES.txt"
|
|
43
43
|
],
|
|
44
44
|
"oclif": {
|
|
45
|
+
"additionalHelpFlags": [
|
|
46
|
+
"-h"
|
|
47
|
+
],
|
|
48
|
+
"additionalVersionFlags": [
|
|
49
|
+
"-V"
|
|
50
|
+
],
|
|
45
51
|
"bin": "repopo",
|
|
46
52
|
"commands": {
|
|
47
53
|
"strategy": "pattern",
|
|
48
54
|
"target": "./esm/commands"
|
|
49
55
|
},
|
|
50
|
-
"devPlugins": [
|
|
56
|
+
"devPlugins": [
|
|
57
|
+
"@oclif/plugin-command-snapshot"
|
|
58
|
+
],
|
|
51
59
|
"dirname": "repopo",
|
|
52
60
|
"plugins": [],
|
|
53
61
|
"repositoryPrefix": "<%- repo %>/blob/main/packages/repopo/<%- commandPath %>"
|
|
54
62
|
},
|
|
55
63
|
"dependencies": {
|
|
56
|
-
"@fluid-tools/build-infrastructure": "~0.
|
|
64
|
+
"@fluid-tools/build-infrastructure": "~0.63.0",
|
|
57
65
|
"@oclif/core": "^4.8.0",
|
|
58
|
-
"@oclif/plugin-help": "^6.2.
|
|
59
|
-
"@rushstack/node-core-library": "^5.
|
|
66
|
+
"@oclif/plugin-help": "^6.2.36",
|
|
67
|
+
"@rushstack/node-core-library": "^5.19.0",
|
|
68
|
+
"consola": "^3.4.0",
|
|
60
69
|
"defu": "^6.1.4",
|
|
70
|
+
"effection": "^4.0.0",
|
|
61
71
|
"jsonfile": "^6.2.0",
|
|
62
72
|
"microdiff": "^1.5.0",
|
|
63
73
|
"pathe": "^2.0.3",
|
|
64
74
|
"picocolors": "^1.1.1",
|
|
75
|
+
"picomatch": "^4.0.3",
|
|
76
|
+
"resolve-workspace-root": "^2.0.0",
|
|
65
77
|
"simple-git": "^3.30.0",
|
|
66
|
-
"
|
|
78
|
+
"tinyglobby": "^0.2.15",
|
|
79
|
+
"@tylerbu/cli-api": "^0.10.1",
|
|
67
80
|
"@tylerbu/fundamentals": "^0.3.0"
|
|
68
81
|
},
|
|
69
82
|
"devDependencies": {
|
|
70
|
-
"@biomejs/biome": "2.
|
|
71
|
-
"@microsoft/api-extractor": "^7.
|
|
83
|
+
"@biomejs/biome": "2.3.8",
|
|
84
|
+
"@microsoft/api-extractor": "^7.56.0",
|
|
72
85
|
"@oclif/plugin-command-snapshot": "^5.3.8",
|
|
73
|
-
"@oclif/test": "^4.1.
|
|
86
|
+
"@oclif/test": "^4.1.15",
|
|
74
87
|
"@types/jsonfile": "^6.1.4",
|
|
75
|
-
"@types/node": "^20.19.
|
|
88
|
+
"@types/node": "^20.19.25",
|
|
89
|
+
"@types/picomatch": "^4.0.2",
|
|
76
90
|
"@types/tmp": "^0.2.6",
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
91
|
+
"@vitest/coverage-v8": "^4.0.17",
|
|
92
|
+
"generate-license-file": "^4.1.1",
|
|
93
|
+
"oclif": "^4.22.50",
|
|
94
|
+
"rimraf": "^6.1.2",
|
|
80
95
|
"tmp-promise": "^3.0.3",
|
|
81
96
|
"ts-node": "^10.9.2",
|
|
82
|
-
"type-fest": "^5.
|
|
97
|
+
"type-fest": "^5.4.1",
|
|
83
98
|
"typescript": "~5.9.3",
|
|
84
|
-
"vitest": "^
|
|
99
|
+
"vitest": "^4.0.17"
|
|
85
100
|
},
|
|
86
101
|
"peerDependencies": {
|
|
87
102
|
"sort-package-json": "*"
|
|
@@ -120,6 +135,8 @@
|
|
|
120
135
|
"readme:main": "oclif readme --no-aliases",
|
|
121
136
|
"release:license": "generate-license-file -c ../../.generatelicensefile.cjs",
|
|
122
137
|
"test": "vitest run",
|
|
123
|
-
"test:
|
|
138
|
+
"test:coverage": "vitest run --coverage",
|
|
139
|
+
"test:snapshots": "./bin/dev.js snapshot:compare --filepath test/commands/__snapshots__/commands.json",
|
|
140
|
+
"test:watch": "vitest"
|
|
124
141
|
}
|
|
125
142
|
}
|