screw-up 0.9.1 → 0.10.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.
@@ -1,119 +0,0 @@
1
- "use strict";
2
- const fs = require("fs");
3
- const promises = require("fs/promises");
4
- const path = require("path");
5
- const flattenObject = (obj, prefix, map) => {
6
- for (const [key, value] of Object.entries(obj)) {
7
- if (!value)
8
- continue;
9
- const fullKey = prefix ? `${prefix}.${key}` : key;
10
- if (typeof value === "string") {
11
- map[fullKey] = value;
12
- } else if (Array.isArray(value)) {
13
- map[fullKey] = value.map((v) => String(v)).join(",");
14
- } else if (typeof value === "object") {
15
- flattenObject(value, fullKey, map);
16
- } else {
17
- map[fullKey] = String(value);
18
- }
19
- }
20
- };
21
- const readPackageMetadata = async (packagePath) => {
22
- try {
23
- const content = await promises.readFile(packagePath, "utf-8");
24
- const json = JSON.parse(content);
25
- const map = {};
26
- flattenObject(json, "", map);
27
- return map;
28
- } catch (error) {
29
- console.warn(`Failed to read package.json from ${packagePath}:`, error);
30
- return {};
31
- }
32
- };
33
- const findWorkspaceRoot = async (startPath) => {
34
- let currentPath = startPath;
35
- while (currentPath !== path.dirname(currentPath)) {
36
- const packageJsonPath = path.join(currentPath, "package.json");
37
- if (fs.existsSync(packageJsonPath)) {
38
- try {
39
- const content = await promises.readFile(packageJsonPath, "utf-8");
40
- const packageJson = JSON.parse(content);
41
- if (packageJson.workspaces || fs.existsSync(path.join(currentPath, "pnpm-workspace.yaml")) || fs.existsSync(path.join(currentPath, "lerna.json"))) {
42
- return currentPath;
43
- }
44
- } catch (error) {
45
- console.warn(`Failed to parse package.json at ${packageJsonPath}:`, error);
46
- }
47
- }
48
- currentPath = path.dirname(currentPath);
49
- }
50
- return void 0;
51
- };
52
- const mergePackageMetadata = (parentMetadata, childMetadata) => {
53
- const merged = {};
54
- for (const key in parentMetadata) {
55
- const value = parentMetadata[key];
56
- if (value !== void 0) {
57
- merged[key] = value;
58
- }
59
- }
60
- for (const key in childMetadata) {
61
- const value = childMetadata[key];
62
- if (value !== void 0) {
63
- merged[key] = value;
64
- }
65
- }
66
- return merged;
67
- };
68
- const resolvePackageMetadataT = async (projectRoot, readPackageMetadataFn, mergePackageMetadataFn) => {
69
- const workspaceRoot = await findWorkspaceRoot(projectRoot);
70
- if (!workspaceRoot) {
71
- const localPackagePath = path.join(projectRoot, "package.json");
72
- return await readPackageMetadataFn(localPackagePath);
73
- }
74
- const projectPackagePath = path.join(projectRoot, "package.json");
75
- const rootPackagePath = path.join(workspaceRoot, "package.json");
76
- const metadata = await readPackageMetadataFn(rootPackagePath);
77
- if (projectPackagePath !== rootPackagePath && fs.existsSync(projectPackagePath)) {
78
- const projectMetadata = await readPackageMetadataFn(projectPackagePath);
79
- return mergePackageMetadataFn(metadata, projectMetadata);
80
- } else {
81
- return metadata;
82
- }
83
- };
84
- const readRawPackageJson = async (packagePath) => {
85
- try {
86
- const content = await promises.readFile(packagePath, "utf-8");
87
- return JSON.parse(content);
88
- } catch (error) {
89
- console.error(`Failed to read package.json from ${packagePath}:`, error);
90
- throw error;
91
- }
92
- };
93
- const mergeRawPackageJson = (parentPackage, childPackage) => {
94
- const inheritableFields = [
95
- "version",
96
- "description",
97
- "author",
98
- "license",
99
- "repository",
100
- "keywords",
101
- "homepage",
102
- "bugs"
103
- ];
104
- const merged = { ...childPackage };
105
- for (const field of inheritableFields) {
106
- if (parentPackage[field] && !merged[field]) {
107
- merged[field] = parentPackage[field];
108
- }
109
- }
110
- return merged;
111
- };
112
- const resolvePackageMetadata = (projectRoot) => {
113
- return resolvePackageMetadataT(projectRoot, readPackageMetadata, mergePackageMetadata);
114
- };
115
- const resolveRawPackageJson = (projectRoot) => {
116
- return resolvePackageMetadataT(projectRoot, readRawPackageJson, mergeRawPackageJson);
117
- };
118
- exports.resolvePackageMetadata = resolvePackageMetadata;
119
- exports.resolveRawPackageJson = resolveRawPackageJson;
@@ -1,120 +0,0 @@
1
- import { existsSync } from "fs";
2
- import { readFile } from "fs/promises";
3
- import { join, dirname } from "path";
4
- const flattenObject = (obj, prefix, map) => {
5
- for (const [key, value] of Object.entries(obj)) {
6
- if (!value)
7
- continue;
8
- const fullKey = prefix ? `${prefix}.${key}` : key;
9
- if (typeof value === "string") {
10
- map[fullKey] = value;
11
- } else if (Array.isArray(value)) {
12
- map[fullKey] = value.map((v) => String(v)).join(",");
13
- } else if (typeof value === "object") {
14
- flattenObject(value, fullKey, map);
15
- } else {
16
- map[fullKey] = String(value);
17
- }
18
- }
19
- };
20
- const readPackageMetadata = async (packagePath) => {
21
- try {
22
- const content = await readFile(packagePath, "utf-8");
23
- const json = JSON.parse(content);
24
- const map = {};
25
- flattenObject(json, "", map);
26
- return map;
27
- } catch (error) {
28
- console.warn(`Failed to read package.json from ${packagePath}:`, error);
29
- return {};
30
- }
31
- };
32
- const findWorkspaceRoot = async (startPath) => {
33
- let currentPath = startPath;
34
- while (currentPath !== dirname(currentPath)) {
35
- const packageJsonPath = join(currentPath, "package.json");
36
- if (existsSync(packageJsonPath)) {
37
- try {
38
- const content = await readFile(packageJsonPath, "utf-8");
39
- const packageJson = JSON.parse(content);
40
- if (packageJson.workspaces || existsSync(join(currentPath, "pnpm-workspace.yaml")) || existsSync(join(currentPath, "lerna.json"))) {
41
- return currentPath;
42
- }
43
- } catch (error) {
44
- console.warn(`Failed to parse package.json at ${packageJsonPath}:`, error);
45
- }
46
- }
47
- currentPath = dirname(currentPath);
48
- }
49
- return void 0;
50
- };
51
- const mergePackageMetadata = (parentMetadata, childMetadata) => {
52
- const merged = {};
53
- for (const key in parentMetadata) {
54
- const value = parentMetadata[key];
55
- if (value !== void 0) {
56
- merged[key] = value;
57
- }
58
- }
59
- for (const key in childMetadata) {
60
- const value = childMetadata[key];
61
- if (value !== void 0) {
62
- merged[key] = value;
63
- }
64
- }
65
- return merged;
66
- };
67
- const resolvePackageMetadataT = async (projectRoot, readPackageMetadataFn, mergePackageMetadataFn) => {
68
- const workspaceRoot = await findWorkspaceRoot(projectRoot);
69
- if (!workspaceRoot) {
70
- const localPackagePath = join(projectRoot, "package.json");
71
- return await readPackageMetadataFn(localPackagePath);
72
- }
73
- const projectPackagePath = join(projectRoot, "package.json");
74
- const rootPackagePath = join(workspaceRoot, "package.json");
75
- const metadata = await readPackageMetadataFn(rootPackagePath);
76
- if (projectPackagePath !== rootPackagePath && existsSync(projectPackagePath)) {
77
- const projectMetadata = await readPackageMetadataFn(projectPackagePath);
78
- return mergePackageMetadataFn(metadata, projectMetadata);
79
- } else {
80
- return metadata;
81
- }
82
- };
83
- const readRawPackageJson = async (packagePath) => {
84
- try {
85
- const content = await readFile(packagePath, "utf-8");
86
- return JSON.parse(content);
87
- } catch (error) {
88
- console.error(`Failed to read package.json from ${packagePath}:`, error);
89
- throw error;
90
- }
91
- };
92
- const mergeRawPackageJson = (parentPackage, childPackage) => {
93
- const inheritableFields = [
94
- "version",
95
- "description",
96
- "author",
97
- "license",
98
- "repository",
99
- "keywords",
100
- "homepage",
101
- "bugs"
102
- ];
103
- const merged = { ...childPackage };
104
- for (const field of inheritableFields) {
105
- if (parentPackage[field] && !merged[field]) {
106
- merged[field] = parentPackage[field];
107
- }
108
- }
109
- return merged;
110
- };
111
- const resolvePackageMetadata = (projectRoot) => {
112
- return resolvePackageMetadataT(projectRoot, readPackageMetadata, mergePackageMetadata);
113
- };
114
- const resolveRawPackageJson = (projectRoot) => {
115
- return resolvePackageMetadataT(projectRoot, readRawPackageJson, mergeRawPackageJson);
116
- };
117
- export {
118
- resolveRawPackageJson as a,
119
- resolvePackageMetadata as r
120
- };