screw-up 1.27.0 → 1.29.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/dist/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.27.0
3
+ * version: 1.29.0
4
4
  * description: Simply package metadata inserter on Vite plugin
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/screw-up.git
8
- * git.commit.hash: eb1634007fc12b0ddd13928d7688758bdfe32624
8
+ * git.commit.hash: 3833f6ef842d9e5a0b4f7277ca3b118f26fd4a6b
9
9
  */
10
- import { i as getFetchGitMetadata, l as resolvePackageMetadata, n as generateMetadataFileContent, o as createConsoleLogger, r as writeFileIfChanged, t as ensureMetadataGitignore } from "./metadata-file-Djz8vanJ.js";
11
- import { i as version, n as name, t as git_commit_hash } from "./packageMetadata-B3dAY9Pw.js";
10
+ import { i as getFetchGitMetadata, l as resolvePackageMetadata, n as generateMetadataFileContent, o as createConsoleLogger, r as writeFileIfChanged, t as ensureMetadataGitignore } from "./metadata-file-CyQ2yue9.js";
11
+ import { i as version, n as name, t as git_commit_hash } from "./packageMetadata-DnXbVLQ5.js";
12
12
  import { readFile, readdir, writeFile } from "fs/promises";
13
13
  import { existsSync } from "fs";
14
14
  import { dirname, extname, join } from "path";
package/dist/main.cjs CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  /*!
3
3
  * name: screw-up
4
- * version: 1.27.0
4
+ * version: 1.29.0
5
5
  * description: Simply package metadata inserter on Vite plugin
6
6
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
7
7
  * license: MIT
8
8
  * repository.url: https://github.com/kekyo/screw-up.git
9
- * git.commit.hash: eb1634007fc12b0ddd13928d7688758bdfe32624
9
+ * git.commit.hash: 3833f6ef842d9e5a0b4f7277ca3b118f26fd4a6b
10
10
  */
11
11
  //#region \0rolldown/runtime.js
12
12
  var __create = Object.create;
@@ -31,7 +31,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
31
  enumerable: true
32
32
  }) : target, mod));
33
33
  //#endregion
34
- const require_packageMetadata = require("./packageMetadata-BwJnVnNu.cjs");
34
+ const require_packageMetadata = require("./packageMetadata-K_w0Knb7.cjs");
35
35
  let path = require("path");
36
36
  let fs = require("fs");
37
37
  let fs_promises = require("fs/promises");
@@ -2815,12 +2815,81 @@ var getRelatedBranches = async (repositoryPath, commitHash) => {
2815
2815
  * @param repositoryPath - Local Git repository directory
2816
2816
  * @returns Modified files
2817
2817
  */
2818
+ var isModifiedFile = ([, head, workdir, stage]) => {
2819
+ return workdir === 2 || stage === 2 || stage === 3 || head === 1 && workdir === 0 || head === 0 && workdir === 1;
2820
+ };
2821
+ var getStatusRow = async (filepath, entries) => {
2822
+ const [head, workdir, stage] = entries;
2823
+ const [headType, workdirType, stageType] = await Promise.all([
2824
+ head ? head.type() : void 0,
2825
+ workdir ? workdir.type() : void 0,
2826
+ stage ? stage.type() : void 0
2827
+ ]);
2828
+ const isBlob = [
2829
+ headType,
2830
+ workdirType,
2831
+ stageType
2832
+ ].includes("blob");
2833
+ if ((headType === "tree" || headType === "special") && !isBlob) return;
2834
+ if (headType === "commit") return;
2835
+ if ((workdirType === "tree" || workdirType === "special") && !isBlob) return;
2836
+ if (stageType === "commit") return;
2837
+ if ((stageType === "tree" || stageType === "special") && !isBlob) return;
2838
+ const headOid = headType === "blob" ? await head.oid() : void 0;
2839
+ const stageOid = stageType === "blob" ? await stage.oid() : void 0;
2840
+ let workdirOid;
2841
+ if (headType !== "blob" && workdirType === "blob" && stageType !== "blob") workdirOid = "42";
2842
+ else if (workdirType === "blob") workdirOid = await workdir.oid();
2843
+ const entry = [
2844
+ void 0,
2845
+ headOid,
2846
+ workdirOid,
2847
+ stageOid
2848
+ ];
2849
+ const statusValues = entry.map((value) => entry.indexOf(value));
2850
+ return [
2851
+ filepath,
2852
+ statusValues[1],
2853
+ statusValues[2],
2854
+ statusValues[3]
2855
+ ];
2856
+ };
2857
+ var reduceModifiedFiles = async (parent, children) => {
2858
+ const modifiedFiles = parent ? [parent] : [];
2859
+ for (const child of children) modifiedFiles.push(...child);
2860
+ return modifiedFiles;
2861
+ };
2862
+ var iterateSequentially = async (walk, children) => {
2863
+ const results = [];
2864
+ for (const child of children) results.push(await walk(child));
2865
+ return results;
2866
+ };
2818
2867
  var getModifiedFiles = async (repositoryPath) => {
2819
2868
  try {
2820
- return (await isomorphic_git.statusMatrix({
2869
+ return await isomorphic_git.walk({
2821
2870
  fs: fs_promises.default,
2822
- dir: repositoryPath
2823
- })).filter(([, head, workdir, stage]) => workdir === 2 || stage === 2 || stage === 3 || head === 1 && workdir === 0 || head === 0 && workdir === 1);
2871
+ dir: repositoryPath,
2872
+ trees: [
2873
+ isomorphic_git.TREE({ ref: "HEAD" }),
2874
+ isomorphic_git.WORKDIR(),
2875
+ isomorphic_git.STAGE()
2876
+ ],
2877
+ map: async (filepath, entries) => {
2878
+ const [head, workdir, stage] = entries;
2879
+ if (!head && !stage && workdir) {
2880
+ if (await isomorphic_git.isIgnored({
2881
+ fs: fs_promises.default,
2882
+ dir: repositoryPath,
2883
+ filepath
2884
+ })) return null;
2885
+ }
2886
+ const statusRow = await getStatusRow(filepath, entries);
2887
+ if (!statusRow || !isModifiedFile(statusRow)) return;
2888
+ return statusRow;
2889
+ },
2890
+ reduce: reduceModifiedFiles,
2891
+ iterate: iterateSequentially
2892
+ });
2824
2893
  } catch (_unused5) {
2825
2894
  return [];
2826
2895
  }
@@ -3007,6 +3076,62 @@ var mergeResolvedPackageJson = (packedPackageJson, resolvedPackageJson) => {
3007
3076
  }
3008
3077
  return mergedPackageJson;
3009
3078
  };
3079
+ var workspaceProtocolPrefix = "workspace:";
3080
+ var inferVersionPrefix = (dependencySpec) => {
3081
+ if (dependencySpec.startsWith("^")) return "^";
3082
+ if (dependencySpec.startsWith("~")) return "~";
3083
+ return "";
3084
+ };
3085
+ var looksLikeWorkspaceProtocolAlias = (rawSpecifier) => {
3086
+ if (!rawSpecifier) return false;
3087
+ if (rawSpecifier === "*" || rawSpecifier === "^" || rawSpecifier === "~" || rawSpecifier.startsWith("^") || rawSpecifier.startsWith("~") || /^[0-9]/.test(rawSpecifier)) return false;
3088
+ return true;
3089
+ };
3090
+ var parseWorkspaceProtocolDependencyReference = (dependencyName, workspaceProtocolSpecifier) => {
3091
+ if (!workspaceProtocolSpecifier.startsWith(workspaceProtocolPrefix)) return;
3092
+ const rawSpecifier = workspaceProtocolSpecifier.slice(10).trim();
3093
+ if (!looksLikeWorkspaceProtocolAlias(rawSpecifier)) return {
3094
+ targetPackageName: dependencyName,
3095
+ alias: false
3096
+ };
3097
+ if (rawSpecifier.startsWith("@")) {
3098
+ const secondAt = rawSpecifier.indexOf("@", 1);
3099
+ const targetPackageName = secondAt >= 0 ? rawSpecifier.slice(0, secondAt) : rawSpecifier;
3100
+ return {
3101
+ targetPackageName,
3102
+ alias: targetPackageName !== dependencyName
3103
+ };
3104
+ }
3105
+ const atIndex = rawSpecifier.indexOf("@");
3106
+ const targetPackageName = atIndex >= 0 ? rawSpecifier.slice(0, atIndex) : rawSpecifier;
3107
+ return {
3108
+ targetPackageName,
3109
+ alias: targetPackageName !== dependencyName
3110
+ };
3111
+ };
3112
+ var formatResolvedWorkspaceDependency = (packedDependencySpecifier, reference, sibling) => {
3113
+ const aliasPrefix = `npm:${reference.targetPackageName}@`;
3114
+ if (packedDependencySpecifier.startsWith(aliasPrefix)) return `${aliasPrefix}${inferVersionPrefix(packedDependencySpecifier.slice(aliasPrefix.length))}${sibling.version}`;
3115
+ return `${inferVersionPrefix(packedDependencySpecifier)}${sibling.version}`;
3116
+ };
3117
+ var replaceWorkspaceProtocolDependencies = (packageJson, resolvedPackageJson, siblings) => {
3118
+ const modifiedPackageJson = clonePackageJson(packageJson);
3119
+ for (const sectionKey of dependencySectionKeys) {
3120
+ const modifiedSection = modifiedPackageJson[sectionKey];
3121
+ const resolvedSection = resolvedPackageJson === null || resolvedPackageJson === void 0 ? void 0 : resolvedPackageJson[sectionKey];
3122
+ if (!modifiedSection || typeof modifiedSection !== "object" || !resolvedSection || typeof resolvedSection !== "object") continue;
3123
+ for (const [dependencyName, dependencySpecifier] of Object.entries(resolvedSection)) {
3124
+ if (typeof dependencySpecifier !== "string") continue;
3125
+ const reference = parseWorkspaceProtocolDependencyReference(dependencyName, dependencySpecifier);
3126
+ if (!reference) continue;
3127
+ const sibling = siblings.get(reference.targetPackageName);
3128
+ const packedDependencySpecifier = modifiedSection[dependencyName];
3129
+ if (!sibling || typeof packedDependencySpecifier !== "string") continue;
3130
+ modifiedSection[dependencyName] = formatResolvedWorkspaceDependency(packedDependencySpecifier, reference, sibling);
3131
+ }
3132
+ }
3133
+ return modifiedPackageJson;
3134
+ };
3010
3135
  var getFilesArray = (packageJson) => {
3011
3136
  if (!packageJson || !Array.isArray(packageJson.files)) return;
3012
3137
  const entries = packageJson.files.filter((entry) => typeof entry === "string");
@@ -3179,7 +3304,7 @@ var packAssets = async (targetDir, outputDir, checkWorkingDirectoryStatus, alway
3179
3304
  }
3180
3305
  delete resolvedPackageJson.readme;
3181
3306
  }
3182
- const workspaceRoot = replacePeerDepsWildcards ? await findWorkspaceRoot(targetDir, logger) : void 0;
3307
+ const workspaceRoot = replacePeerDepsWildcards || packageManager === "pnpm" ? await findWorkspaceRoot(targetDir, logger) : void 0;
3183
3308
  const workspaceSiblings = workspaceRoot ? await collectWorkspaceSiblings(workspaceRoot, fetchGitMetadata, alwaysOverrideVersionFromGit, inheritableFields, logger) : void 0;
3184
3309
  const filesMergeEnabled = mergeFiles && inheritableFields.has("files");
3185
3310
  const workspaceFilesMerge = filesMergeEnabled ? await resolveWorkspaceFilesMerge(targetDir, logger) : void 0;
@@ -3206,6 +3331,7 @@ var packAssets = async (targetDir, outputDir, checkWorkingDirectoryStatus, alway
3206
3331
  let finalPackageJson = resolvedPackageJson;
3207
3332
  if ((0, fs.existsSync)(packageJsonPath)) {
3208
3333
  finalPackageJson = mergeResolvedPackageJson(await readPackageJsonFile(packageJsonPath), resolvedPackageJson);
3334
+ if (packageManager === "pnpm" && (workspaceSiblings === null || workspaceSiblings === void 0 ? void 0 : workspaceSiblings.size)) finalPackageJson = replaceWorkspaceProtocolDependencies(finalPackageJson, resolvedPackageJson, workspaceSiblings);
3209
3335
  if (workspaceSiblings && workspaceSiblings.size > 0) finalPackageJson = replacePeerDependenciesWildcards(finalPackageJson, workspaceSiblings, peerDepsVersionPrefix);
3210
3336
  if (packageJsonReadme) delete finalPackageJson.readme;
3211
3337
  await (0, fs_promises.writeFile)(packageJsonPath, JSON.stringify(finalPackageJson, null, 2));
@@ -3787,7 +3913,7 @@ var publishCommand = async (args, logger) => {
3787
3913
  }
3788
3914
  };
3789
3915
  var showHelp = async () => {
3790
- const { author, license, repository_url, version, git_commit_hash } = await Promise.resolve().then(() => require("./packageMetadata-BZlXZqjz.cjs"));
3916
+ const { author, license, repository_url, version, git_commit_hash } = await Promise.resolve().then(() => require("./packageMetadata-CpakAG0S.cjs"));
3791
3917
  console.info(`screw-up [${version}-${git_commit_hash}]
3792
3918
  Easy package metadata inserter CLI
3793
3919
  Copyright (c) ${author}