@niche-works/dev 0.3.0 → 0.4.2

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.
Files changed (208) hide show
  1. package/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/addExports/addExports.cjs +61 -0
  3. package/addExports/addExports.cjs.map +1 -0
  4. package/addExports/addExports.d.cts +11 -0
  5. package/addExports/addExports.d.mts +12 -0
  6. package/addExports/addExports.mjs +59 -0
  7. package/addExports/addExports.mjs.map +1 -0
  8. package/addExports/index.cjs +3 -0
  9. package/addExports/index.d.cts +3 -0
  10. package/addExports/index.d.mts +3 -0
  11. package/addExports/index.mjs +3 -0
  12. package/addExports/types.cjs +0 -0
  13. package/{src/addExports/types.ts → addExports/types.d.cts} +33 -33
  14. package/addExports/types.d.mts +33 -0
  15. package/addExports/types.mjs +1 -0
  16. package/addJsExtensions/addJsExtensions.cjs +31 -0
  17. package/addJsExtensions/addJsExtensions.cjs.map +1 -0
  18. package/addJsExtensions/addJsExtensions.d.cts +8 -0
  19. package/addJsExtensions/addJsExtensions.d.mts +9 -0
  20. package/addJsExtensions/addJsExtensions.mjs +28 -0
  21. package/addJsExtensions/addJsExtensions.mjs.map +1 -0
  22. package/addJsExtensions/index.cjs +3 -0
  23. package/addJsExtensions/index.d.cts +2 -0
  24. package/addJsExtensions/index.d.mts +2 -0
  25. package/addJsExtensions/index.mjs +3 -0
  26. package/checkExistence/checkExistence.cjs +23 -0
  27. package/checkExistence/checkExistence.cjs.map +1 -0
  28. package/checkExistence/checkExistence.d.cts +9 -0
  29. package/checkExistence/checkExistence.d.mts +10 -0
  30. package/checkExistence/checkExistence.mjs +21 -0
  31. package/checkExistence/checkExistence.mjs.map +1 -0
  32. package/checkExistence/index.cjs +3 -0
  33. package/checkExistence/index.d.cts +2 -0
  34. package/checkExistence/index.d.mts +2 -0
  35. package/checkExistence/index.mjs +3 -0
  36. package/createExternalOptionFunction/createExternalOptionFunction.cjs +25 -0
  37. package/createExternalOptionFunction/createExternalOptionFunction.cjs.map +1 -0
  38. package/createExternalOptionFunction/createExternalOptionFunction.d.cts +10 -0
  39. package/createExternalOptionFunction/createExternalOptionFunction.d.mts +11 -0
  40. package/createExternalOptionFunction/createExternalOptionFunction.mjs +25 -0
  41. package/createExternalOptionFunction/createExternalOptionFunction.mjs.map +1 -0
  42. package/createExternalOptionFunction/index.cjs +3 -0
  43. package/createExternalOptionFunction/index.d.cts +2 -0
  44. package/createExternalOptionFunction/index.d.mts +2 -0
  45. package/createExternalOptionFunction/index.mjs +3 -0
  46. package/createExternalOptionFunction/types.cjs +0 -0
  47. package/createExternalOptionFunction/types.d.cts +31 -0
  48. package/createExternalOptionFunction/types.d.mts +31 -0
  49. package/createExternalOptionFunction/types.mjs +1 -0
  50. package/editJsonFile/editJsonFile.cjs +29 -0
  51. package/editJsonFile/editJsonFile.cjs.map +1 -0
  52. package/editJsonFile/editJsonFile.d.cts +9 -0
  53. package/editJsonFile/editJsonFile.d.mts +10 -0
  54. package/editJsonFile/editJsonFile.mjs +26 -0
  55. package/editJsonFile/editJsonFile.mjs.map +1 -0
  56. package/editJsonFile/index.cjs +3 -0
  57. package/editJsonFile/index.d.cts +2 -0
  58. package/editJsonFile/index.d.mts +2 -0
  59. package/editJsonFile/index.mjs +3 -0
  60. package/generatePublishPackageJson/generatePublishPackageJson.cjs +46 -0
  61. package/generatePublishPackageJson/generatePublishPackageJson.cjs.map +1 -0
  62. package/generatePublishPackageJson/generatePublishPackageJson.d.cts +6 -0
  63. package/generatePublishPackageJson/generatePublishPackageJson.d.mts +7 -0
  64. package/generatePublishPackageJson/generatePublishPackageJson.mjs +44 -0
  65. package/generatePublishPackageJson/generatePublishPackageJson.mjs.map +1 -0
  66. package/generatePublishPackageJson/index.cjs +3 -0
  67. package/generatePublishPackageJson/index.d.cts +3 -0
  68. package/generatePublishPackageJson/index.d.mts +3 -0
  69. package/generatePublishPackageJson/index.mjs +3 -0
  70. package/generatePublishPackageJson/types.cjs +0 -0
  71. package/{src/generatePublishPackageJson/types.ts → generatePublishPackageJson/types.d.cts} +60 -61
  72. package/generatePublishPackageJson/types.d.mts +60 -0
  73. package/generatePublishPackageJson/types.mjs +1 -0
  74. package/index.cjs +38 -0
  75. package/index.d.cts +13 -0
  76. package/index.d.mts +13 -0
  77. package/index.mjs +26 -0
  78. package/indexes/constants.cjs +123 -0
  79. package/indexes/constants.cjs.map +1 -0
  80. package/indexes/constants.d.cts +66 -0
  81. package/indexes/constants.d.mts +66 -0
  82. package/indexes/constants.mjs +106 -0
  83. package/indexes/constants.mjs.map +1 -0
  84. package/indexes/index.cjs +3 -0
  85. package/indexes/index.d.cts +3 -0
  86. package/indexes/index.d.mts +3 -0
  87. package/indexes/index.mjs +3 -0
  88. package/indexes/indexes.cjs +125 -0
  89. package/indexes/indexes.cjs.map +1 -0
  90. package/indexes/indexes.d.cts +11 -0
  91. package/indexes/indexes.d.mts +12 -0
  92. package/indexes/indexes.mjs +123 -0
  93. package/indexes/indexes.mjs.map +1 -0
  94. package/indexes/types.cjs +0 -0
  95. package/{src/indexes/types.ts → indexes/types.d.cts} +81 -87
  96. package/indexes/types.d.mts +81 -0
  97. package/indexes/types.mjs +1 -0
  98. package/installFromLocal/index.cjs +3 -0
  99. package/installFromLocal/index.d.cts +3 -0
  100. package/installFromLocal/index.d.mts +3 -0
  101. package/installFromLocal/index.mjs +3 -0
  102. package/installFromLocal/installFromLocal.cjs +46 -0
  103. package/installFromLocal/installFromLocal.cjs.map +1 -0
  104. package/installFromLocal/installFromLocal.d.cts +11 -0
  105. package/installFromLocal/installFromLocal.d.mts +12 -0
  106. package/installFromLocal/installFromLocal.mjs +43 -0
  107. package/installFromLocal/installFromLocal.mjs.map +1 -0
  108. package/installFromLocal/types.cjs +0 -0
  109. package/{src/installFromLocal/types.ts → installFromLocal/types.d.cts} +21 -19
  110. package/installFromLocal/types.d.mts +21 -0
  111. package/installFromLocal/types.mjs +1 -0
  112. package/isMatchingPath/index.cjs +3 -0
  113. package/isMatchingPath/index.d.cts +3 -0
  114. package/isMatchingPath/index.d.mts +3 -0
  115. package/isMatchingPath/index.mjs +3 -0
  116. package/isMatchingPath/isMatchingPath.cjs +52 -0
  117. package/isMatchingPath/isMatchingPath.cjs.map +1 -0
  118. package/isMatchingPath/isMatchingPath.d.cts +13 -0
  119. package/isMatchingPath/isMatchingPath.d.mts +14 -0
  120. package/isMatchingPath/isMatchingPath.mjs +50 -0
  121. package/isMatchingPath/isMatchingPath.mjs.map +1 -0
  122. package/isMatchingPath/types.cjs +0 -0
  123. package/isMatchingPath/types.d.cts +72 -0
  124. package/isMatchingPath/types.d.mts +72 -0
  125. package/isMatchingPath/types.mjs +1 -0
  126. package/isTargetPath/index.cjs +3 -0
  127. package/isTargetPath/index.d.cts +3 -0
  128. package/isTargetPath/index.d.mts +3 -0
  129. package/isTargetPath/index.mjs +3 -0
  130. package/isTargetPath/isTargetPath.cjs +21 -0
  131. package/isTargetPath/isTargetPath.cjs.map +1 -0
  132. package/isTargetPath/isTargetPath.d.cts +7 -0
  133. package/isTargetPath/isTargetPath.d.mts +8 -0
  134. package/isTargetPath/isTargetPath.mjs +19 -0
  135. package/isTargetPath/isTargetPath.mjs.map +1 -0
  136. package/isTargetPath/types.cjs +0 -0
  137. package/isTargetPath/types.d.cts +33 -0
  138. package/isTargetPath/types.d.mts +33 -0
  139. package/isTargetPath/types.mjs +1 -0
  140. package/moveFilesToSubdir/index.cjs +3 -0
  141. package/moveFilesToSubdir/index.d.cts +3 -0
  142. package/moveFilesToSubdir/index.d.mts +3 -0
  143. package/moveFilesToSubdir/index.mjs +3 -0
  144. package/moveFilesToSubdir/moveFilesToSubdir.cjs +32 -0
  145. package/moveFilesToSubdir/moveFilesToSubdir.cjs.map +1 -0
  146. package/moveFilesToSubdir/moveFilesToSubdir.d.cts +10 -0
  147. package/moveFilesToSubdir/moveFilesToSubdir.d.mts +11 -0
  148. package/moveFilesToSubdir/moveFilesToSubdir.mjs +29 -0
  149. package/moveFilesToSubdir/moveFilesToSubdir.mjs.map +1 -0
  150. package/moveFilesToSubdir/types.cjs +0 -0
  151. package/moveFilesToSubdir/types.d.cts +18 -0
  152. package/moveFilesToSubdir/types.d.mts +18 -0
  153. package/moveFilesToSubdir/types.mjs +1 -0
  154. package/package.json +20 -30
  155. package/removeFiles/index.cjs +3 -0
  156. package/removeFiles/index.d.cts +2 -0
  157. package/removeFiles/index.d.mts +2 -0
  158. package/removeFiles/index.mjs +3 -0
  159. package/removeFiles/removeFiles.cjs +15 -0
  160. package/removeFiles/removeFiles.cjs.map +1 -0
  161. package/removeFiles/removeFiles.d.cts +6 -0
  162. package/removeFiles/removeFiles.d.mts +7 -0
  163. package/removeFiles/removeFiles.mjs +12 -0
  164. package/removeFiles/removeFiles.mjs.map +1 -0
  165. package/removeFiles/types.cjs +0 -0
  166. package/removeFiles/types.d.cts +9 -0
  167. package/removeFiles/types.d.mts +9 -0
  168. package/removeFiles/types.mjs +1 -0
  169. package/ver/index.cjs +3 -0
  170. package/ver/index.d.cts +3 -0
  171. package/ver/index.d.mts +3 -0
  172. package/ver/index.mjs +3 -0
  173. package/ver/types.cjs +0 -0
  174. package/{src/ver/types.ts → ver/types.d.cts} +16 -13
  175. package/ver/types.d.mts +16 -0
  176. package/ver/types.mjs +1 -0
  177. package/ver/ver.cjs +34 -0
  178. package/ver/ver.cjs.map +1 -0
  179. package/ver/ver.d.cts +11 -0
  180. package/ver/ver.d.mts +12 -0
  181. package/ver/ver.mjs +31 -0
  182. package/ver/ver.mjs.map +1 -0
  183. package/src/addExports/addExports.ts +0 -98
  184. package/src/addExports/index.ts +0 -2
  185. package/src/addJsExtensions/addJsExtensions.ts +0 -31
  186. package/src/addJsExtensions/index.ts +0 -1
  187. package/src/checkExistence/checkExistence.ts +0 -16
  188. package/src/checkExistence/index.ts +0 -1
  189. package/src/editJsonFile/editJsonFile.ts +0 -30
  190. package/src/editJsonFile/index.ts +0 -1
  191. package/src/generatePublishPackageJson/generatePublishPackageJson.ts +0 -55
  192. package/src/generatePublishPackageJson/index.ts +0 -2
  193. package/src/index.ts +0 -10
  194. package/src/indexes/constants.ts +0 -135
  195. package/src/indexes/index.ts +0 -2
  196. package/src/indexes/indexes.ts +0 -194
  197. package/src/installFromLocal/index.ts +0 -2
  198. package/src/installFromLocal/installFromLocal.ts +0 -63
  199. package/src/isMatchingPath/_types.ts +0 -65
  200. package/src/isMatchingPath/index.ts +0 -2
  201. package/src/isMatchingPath/isMatchingPath.ts +0 -88
  202. package/src/isMatchingPath/types.ts +0 -21
  203. package/src/moveFilesToSubdir/index.ts +0 -1
  204. package/src/moveFilesToSubdir/moveFilesToSubdir.ts +0 -23
  205. package/src/ver/index.ts +0 -2
  206. package/src/ver/ver.ts +0 -38
  207. package/tsconfig.json +0 -46
  208. package/tsup.config.ts +0 -36
@@ -0,0 +1,123 @@
1
+ import isMatchingPath from "../isMatchingPath/isMatchingPath.mjs";
2
+ import "../isMatchingPath/index.mjs";
3
+ import { DEFAULT_EXCLUDE, DEFAULT_EXPORT_ALL, DEFAULT_EXPORT_ALL_AS, DEFAULT_EXPORT_DEFAULT, DEFAULT_EXPORT_TYPE_ALL, DEFAULT_INCLUDE } from "./constants.mjs";
4
+ import fs from "fs-extra";
5
+ import { posix } from "path";
6
+
7
+ //#region src/indexes/indexes.ts
8
+ const EXPORTS = {
9
+ exportAll: {
10
+ type: "named",
11
+ generate: (name) => `export * from './${name}';`
12
+ },
13
+ exportAllAs: {
14
+ type: "named",
15
+ generate: (name) => `export * as ${name} from './${name}';`
16
+ },
17
+ exportDefault: {
18
+ type: "default",
19
+ generate: (name) => `export { default } from './${name}';`
20
+ },
21
+ exportDefaultAs: {
22
+ type: "named",
23
+ generate: (name) => `export { default as ${name} } from './${name}';`
24
+ },
25
+ exportTypeAll: {
26
+ type: "type",
27
+ generate: (name) => `export type * from './${name}';`
28
+ }
29
+ };
30
+ /**
31
+ * 対象のディレクトリ配下のindexファイルを作成する\
32
+ * 対象ファイルで出力形式が特に指定されていない場合は下記の形式で出力\
33
+ * `export { default as ${name} } from './${name}';`
34
+ */
35
+ function indexes(options = {}) {
36
+ const { srcPath = "src", indexFileName = "index.ts", include = DEFAULT_INCLUDE, exclude = DEFAULT_EXCLUDE, exportAll = DEFAULT_EXPORT_ALL, exportAllAs = DEFAULT_EXPORT_ALL_AS, exportDefault = DEFAULT_EXPORT_DEFAULT, exportTypeAll = DEFAULT_EXPORT_TYPE_ALL, ...rest } = options;
37
+ _indexes(srcPath, _createRegex(indexFileName), {
38
+ indexFileName,
39
+ include,
40
+ exclude,
41
+ exportAll,
42
+ exportAllAs,
43
+ exportDefault,
44
+ exportTypeAll,
45
+ ...rest
46
+ });
47
+ }
48
+ function _indexes(targetPath, indexRegex, options) {
49
+ const { indexFileName = "index.ts", include, exclude, includeNamedWithDefault, exportAll, exportAllAs, exportDefault, exportDefaultAs, exportTypeAll, dryRun } = options;
50
+ const exportTargets = {
51
+ exportAll,
52
+ exportAllAs,
53
+ exportDefault,
54
+ exportDefaultAs,
55
+ exportTypeAll
56
+ };
57
+ if (!fs.statSync(targetPath).isDirectory()) console.error(`"${targetPath}" is not directory.`);
58
+ const items = fs.readdirSync(targetPath);
59
+ items.sort((a, b) => a.toLowerCase() > b.toLowerCase() ? 1 : -1);
60
+ const exportCodes = [];
61
+ let hasDefaultExport = false;
62
+ let hasNamedExport = false;
63
+ for (const item of items) {
64
+ const itemPath = posix.join(targetPath, item);
65
+ const { name } = posix.parse(itemPath);
66
+ const stat = fs.statSync(itemPath);
67
+ let children;
68
+ if (stat.isDirectory()) children = _indexes(itemPath, indexRegex, options);
69
+ const isMatchingPathOptions = { conditionOptions: {
70
+ indexRegex,
71
+ children
72
+ } };
73
+ if (!indexRegex.test(item) && isMatchingPath(itemPath, include, isMatchingPathOptions) && !isMatchingPath(itemPath, exclude, isMatchingPathOptions)) {
74
+ let isExported = false;
75
+ for (const type in EXPORTS) {
76
+ const exportType = type;
77
+ const exportTarget = exportTargets[exportType];
78
+ if (exportTarget && isMatchingPath(itemPath, exportTarget, isMatchingPathOptions)) {
79
+ const EXPORT = EXPORTS[exportType];
80
+ exportCodes.push({
81
+ type: EXPORT.type,
82
+ code: EXPORT.generate(name)
83
+ });
84
+ if (EXPORT.type === "named") hasNamedExport = true;
85
+ else if (EXPORT.type === "default") hasDefaultExport = true;
86
+ isExported = true;
87
+ break;
88
+ }
89
+ }
90
+ if (!isExported) {
91
+ exportCodes.push({
92
+ type: EXPORTS.exportDefaultAs.type,
93
+ code: EXPORTS.exportDefaultAs.generate(name)
94
+ });
95
+ hasNamedExport = true;
96
+ }
97
+ }
98
+ }
99
+ if (exportCodes.length) {
100
+ let index;
101
+ if (hasDefaultExport && hasNamedExport && !includeNamedWithDefault) index = exportCodes.reduce((result, exportCode) => {
102
+ if (exportCode.type !== "named") result.push(exportCode.code);
103
+ return result;
104
+ }, []);
105
+ else index = exportCodes.map((exportCode) => exportCode.code);
106
+ const indexPath = posix.join(targetPath, indexFileName);
107
+ if (!dryRun) {
108
+ fs.writeFileSync(indexPath, index.join("\r\n") + "\r\n", { encoding: "utf8" });
109
+ console.info(indexPath);
110
+ } else {
111
+ console.info(indexPath + "-------------------------------------");
112
+ console.info(index.join("\r\n") + "\r\n");
113
+ }
114
+ }
115
+ return items;
116
+ }
117
+ function _createRegex(str) {
118
+ return new RegExp(`^${str.replace(/[.*+?^=!:${}()|\[\]\/\\]/g, "\\$&")}$`, "i");
119
+ }
120
+
121
+ //#endregion
122
+ export { indexes as default };
123
+ //# sourceMappingURL=indexes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexes.mjs","names":["path"],"sources":["../../src/indexes/indexes.ts"],"sourcesContent":["import fs from 'fs-extra';\r\nimport { posix as path } from 'path';\r\nimport isMatchingPath from '../isMatchingPath';\r\nimport {\r\n DEFAULT_EXCLUDE,\r\n DEFAULT_EXPORT_ALL,\r\n DEFAULT_EXPORT_ALL_AS,\r\n DEFAULT_EXPORT_DEFAULT,\r\n DEFAULT_EXPORT_TYPE_ALL,\r\n DEFAULT_INCLUDE,\r\n} from './constants';\r\nimport type { IndexesOptions } from './types';\r\n\r\nconst EXPORTS = {\r\n exportAll: {\r\n type: 'named',\r\n generate: (name: string) => `export * from './${name}';`,\r\n },\r\n exportAllAs: {\r\n type: 'named',\r\n generate: (name: string) => `export * as ${name} from './${name}';`,\r\n },\r\n exportDefault: {\r\n type: 'default',\r\n generate: (name: string) => `export { default } from './${name}';`,\r\n },\r\n exportDefaultAs: {\r\n type: 'named',\r\n generate: (name: string) =>\r\n `export { default as ${name} } from './${name}';`,\r\n },\r\n exportTypeAll: {\r\n type: 'type',\r\n generate: (name: string) => `export type * from './${name}';`,\r\n },\r\n} as const;\r\n\r\n/**\r\n * 対象のディレクトリ配下のindexファイルを作成する\\\r\n * 対象ファイルで出力形式が特に指定されていない場合は下記の形式で出力\\\r\n * `export { default as ${name} } from './${name}';`\r\n */\r\nexport default function indexes(options: IndexesOptions = {}) {\r\n const {\r\n srcPath = 'src',\r\n indexFileName = 'index.ts',\r\n include = DEFAULT_INCLUDE,\r\n exclude = DEFAULT_EXCLUDE,\r\n exportAll = DEFAULT_EXPORT_ALL,\r\n exportAllAs = DEFAULT_EXPORT_ALL_AS,\r\n exportDefault = DEFAULT_EXPORT_DEFAULT,\r\n exportTypeAll = DEFAULT_EXPORT_TYPE_ALL,\r\n ...rest\r\n } = options;\r\n const indexRegex = _createRegex(indexFileName);\r\n\r\n // indexファイルの作成処理を実行\r\n _indexes(srcPath, indexRegex, {\r\n indexFileName,\r\n include,\r\n exclude,\r\n exportAll,\r\n exportAllAs,\r\n exportDefault,\r\n exportTypeAll,\r\n ...rest,\r\n });\r\n}\r\n\r\nfunction _indexes(\r\n targetPath: string,\r\n indexRegex: RegExp,\r\n options: IndexesOptions,\r\n) {\r\n const {\r\n indexFileName = 'index.ts',\r\n include,\r\n exclude,\r\n includeNamedWithDefault,\r\n exportAll,\r\n exportAllAs,\r\n exportDefault,\r\n exportDefaultAs,\r\n exportTypeAll,\r\n dryRun,\r\n } = options;\r\n const exportTargets = {\r\n exportAll,\r\n exportAllAs,\r\n exportDefault,\r\n exportDefaultAs,\r\n exportTypeAll,\r\n };\r\n const stat = fs.statSync(targetPath);\r\n if (!stat.isDirectory()) {\r\n console.error(`\"${targetPath}\" is not directory.`);\r\n }\r\n const items = fs.readdirSync(targetPath);\r\n items.sort((a, b) => (a.toLowerCase() > b.toLowerCase() ? 1 : -1));\r\n const exportCodes = [];\r\n let hasDefaultExport = false;\r\n let hasNamedExport = false;\r\n\r\n for (const item of items) {\r\n const itemPath = path.join(targetPath, item);\r\n const { name } = path.parse(itemPath);\r\n const stat = fs.statSync(itemPath);\r\n\r\n let children;\r\n if (stat.isDirectory()) {\r\n // ディレクトリの場合は先に子要素を処理\r\n children = _indexes(itemPath, indexRegex, options);\r\n }\r\n const isMatchingPathOptions = {\r\n conditionOptions: { indexRegex, children },\r\n };\r\n\r\n if (\r\n !indexRegex.test(item) &&\r\n isMatchingPath(itemPath, include, isMatchingPathOptions) &&\r\n !isMatchingPath(itemPath, exclude, isMatchingPathOptions)\r\n ) {\r\n // indexではない場合\r\n let isExported = false;\r\n for (const type in EXPORTS) {\r\n const exportType = type as keyof typeof EXPORTS;\r\n const exportTarget = exportTargets[exportType];\r\n if (\r\n exportTarget &&\r\n isMatchingPath(itemPath, exportTarget, isMatchingPathOptions)\r\n ) {\r\n // 条件に一致した場合はexportのコードを生成\r\n const EXPORT = EXPORTS[exportType];\r\n exportCodes.push({\r\n type: EXPORT.type,\r\n code: EXPORT.generate(name),\r\n });\r\n // exportの種類に応じたフラグを立てる\r\n if (EXPORT.type === 'named') {\r\n hasNamedExport = true;\r\n } else if (EXPORT.type === 'default') {\r\n hasDefaultExport = true;\r\n }\r\n isExported = true;\r\n break;\r\n }\r\n }\r\n if (!isExported) {\r\n // 未指定の場合はexportDefaultAs\r\n exportCodes.push({\r\n type: EXPORTS.exportDefaultAs.type,\r\n code: EXPORTS.exportDefaultAs.generate(name),\r\n });\r\n hasNamedExport = true;\r\n }\r\n }\r\n }\r\n\r\n if (exportCodes.length) {\r\n let index;\r\n if (hasDefaultExport && hasNamedExport && !includeNamedWithDefault) {\r\n // デフォルトエクスポートと名前付きエクスポートの混在を許さない場合は名前付きエクスポートを除外\r\n index = exportCodes.reduce<string[]>((result, exportCode) => {\r\n if (exportCode.type !== 'named') {\r\n result.push(exportCode.code);\r\n }\r\n return result;\r\n }, []);\r\n } else {\r\n index = exportCodes.map((exportCode) => exportCode.code);\r\n }\r\n\r\n const indexPath = path.join(targetPath, indexFileName);\r\n if (!dryRun) {\r\n // indexファイルの出力\r\n fs.writeFileSync(indexPath, index.join('\\r\\n') + '\\r\\n', {\r\n encoding: 'utf8',\r\n });\r\n console.info(indexPath);\r\n } else {\r\n console.info(indexPath + '-------------------------------------');\r\n console.info(index.join('\\r\\n') + '\\r\\n');\r\n }\r\n }\r\n\r\n return items;\r\n}\r\n\r\nfunction _createRegex(str: string) {\r\n return new RegExp(\r\n `^${str.replace(/[.*+?^=!:${}()|\\[\\]\\/\\\\]/g, '\\\\$&')}$`,\r\n 'i',\r\n );\r\n}\r\n"],"mappings":"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"}
File without changes
@@ -1,87 +1,81 @@
1
- import type { IsMatchingPathCondition } from '../isMatchingPath';
2
-
3
- export type IndexesOptions = {
4
- /**
5
- * 処理対象のパス\
6
- * @default `src`
7
- */
8
- srcPath?: string;
9
-
10
- /**
11
- * indexのファイル名\
12
- * @default `index.ts`
13
- */
14
- indexFileName?: string;
15
-
16
- /**
17
- * indexファイルを作る対象\
18
- * 未指定の場合は下記の条件がデフォルトで適用される
19
- *
20
- * - ファイル名が`_`で始まらず拡張子が`.ts`,`.tsx`,`.js`,`.jsx`のもの
21
- * - ディレクトリ名が`_`で始まらないもの
22
- */
23
- include?: IsMatchingPathCondition[];
24
-
25
- /**
26
- * indexファイルを作る対象から除外するもの
27
- */
28
- exclude?: IsMatchingPathCondition[];
29
-
30
- /**
31
- * 同じindexファイル内にデフォルトエクスポートがある場合でも名前付きエクスポートをする\
32
- * デフォルトエクスポートしたモジュールをcjsへ変換したものへアクセスする際に、\
33
- * defaultという名前付きでアクセスしても問題ない場合はtrue
34
- */
35
- includeNamedWithDefault?: boolean;
36
-
37
- /**
38
- * exportの形式を下記にしたいもの
39
- *
40
- * ```
41
- * export * from './abc';
42
- * ```
43
- */
44
- exportAll?: IsMatchingPathCondition[];
45
-
46
- /**
47
- * exportの形式を下記にしたいもの
48
- *
49
- * ```
50
- * export * as abc from './abc';
51
- * ```
52
- */
53
- exportAllAs?: IsMatchingPathCondition[];
54
-
55
- /**
56
- * exportの形式を下記にしたいもの
57
- *
58
- * ```
59
- * export { default } from './abc';
60
- * ```
61
- */
62
- exportDefault?: IsMatchingPathCondition[];
63
-
64
- /**
65
- * exportの形式を下記にしたいもの
66
- *
67
- * ```
68
- * export { default as abc } from './abc';
69
- * ```
70
- */
71
- exportDefaultAs?: IsMatchingPathCondition[];
72
-
73
- /**
74
- * exportの形式を下記にしたいもの
75
- *
76
- * ```
77
- * export type * from './abc';
78
- * ```
79
- */
80
- exportTypeAll?: IsMatchingPathCondition[];
81
-
82
- /**
83
- * お試し\
84
- * ファイルの操作は行わない
85
- */
86
- dryRun?: boolean;
87
- };
1
+ import { IsMatchingPathCondition } from "../isMatchingPath/types.cjs";
2
+
3
+ //#region src/indexes/types.d.ts
4
+ type IndexesOptions = {
5
+ /**
6
+ * 処理対象のパス\
7
+ * @default `src`
8
+ */
9
+ srcPath?: string;
10
+ /**
11
+ * indexのファイル名\
12
+ * @default `index.ts`
13
+ */
14
+ indexFileName?: string;
15
+ /**
16
+ * indexファイルを作る対象\
17
+ * 未指定の場合は下記の条件がデフォルトで適用される
18
+ *
19
+ * - ファイル名が`_`で始まらず拡張子が`.ts`,`.tsx`,`.js`,`.jsx`のもの
20
+ * - ディレクトリ名が`_`で始まらないもの
21
+ */
22
+ include?: IsMatchingPathCondition[];
23
+ /**
24
+ * indexファイルを作る対象から除外するもの
25
+ */
26
+ exclude?: IsMatchingPathCondition[];
27
+ /**
28
+ * 同じindexファイル内にデフォルトエクスポートがある場合でも名前付きエクスポートをする\
29
+ * デフォルトエクスポートしたモジュールをcjsへ変換したものへアクセスする際に、\
30
+ * defaultという名前付きでアクセスしても問題ない場合はtrue
31
+ */
32
+ includeNamedWithDefault?: boolean;
33
+ /**
34
+ * exportの形式を下記にしたいもの
35
+ *
36
+ * ```
37
+ * export * from './abc';
38
+ * ```
39
+ */
40
+ exportAll?: IsMatchingPathCondition[];
41
+ /**
42
+ * exportの形式を下記にしたいもの
43
+ *
44
+ * ```
45
+ * export * as abc from './abc';
46
+ * ```
47
+ */
48
+ exportAllAs?: IsMatchingPathCondition[];
49
+ /**
50
+ * exportの形式を下記にしたいもの
51
+ *
52
+ * ```
53
+ * export { default } from './abc';
54
+ * ```
55
+ */
56
+ exportDefault?: IsMatchingPathCondition[];
57
+ /**
58
+ * exportの形式を下記にしたいもの
59
+ *
60
+ * ```
61
+ * export { default as abc } from './abc';
62
+ * ```
63
+ */
64
+ exportDefaultAs?: IsMatchingPathCondition[];
65
+ /**
66
+ * exportの形式を下記にしたいもの
67
+ *
68
+ * ```
69
+ * export type * from './abc';
70
+ * ```
71
+ */
72
+ exportTypeAll?: IsMatchingPathCondition[];
73
+ /**
74
+ * お試し\
75
+ * ファイルの操作は行わない
76
+ */
77
+ dryRun?: boolean;
78
+ };
79
+ //#endregion
80
+ export { IndexesOptions };
81
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1,81 @@
1
+ import { IsMatchingPathCondition } from "../isMatchingPath/types.mjs";
2
+
3
+ //#region src/indexes/types.d.ts
4
+ type IndexesOptions = {
5
+ /**
6
+ * 処理対象のパス\
7
+ * @default `src`
8
+ */
9
+ srcPath?: string;
10
+ /**
11
+ * indexのファイル名\
12
+ * @default `index.ts`
13
+ */
14
+ indexFileName?: string;
15
+ /**
16
+ * indexファイルを作る対象\
17
+ * 未指定の場合は下記の条件がデフォルトで適用される
18
+ *
19
+ * - ファイル名が`_`で始まらず拡張子が`.ts`,`.tsx`,`.js`,`.jsx`のもの
20
+ * - ディレクトリ名が`_`で始まらないもの
21
+ */
22
+ include?: IsMatchingPathCondition[];
23
+ /**
24
+ * indexファイルを作る対象から除外するもの
25
+ */
26
+ exclude?: IsMatchingPathCondition[];
27
+ /**
28
+ * 同じindexファイル内にデフォルトエクスポートがある場合でも名前付きエクスポートをする\
29
+ * デフォルトエクスポートしたモジュールをcjsへ変換したものへアクセスする際に、\
30
+ * defaultという名前付きでアクセスしても問題ない場合はtrue
31
+ */
32
+ includeNamedWithDefault?: boolean;
33
+ /**
34
+ * exportの形式を下記にしたいもの
35
+ *
36
+ * ```
37
+ * export * from './abc';
38
+ * ```
39
+ */
40
+ exportAll?: IsMatchingPathCondition[];
41
+ /**
42
+ * exportの形式を下記にしたいもの
43
+ *
44
+ * ```
45
+ * export * as abc from './abc';
46
+ * ```
47
+ */
48
+ exportAllAs?: IsMatchingPathCondition[];
49
+ /**
50
+ * exportの形式を下記にしたいもの
51
+ *
52
+ * ```
53
+ * export { default } from './abc';
54
+ * ```
55
+ */
56
+ exportDefault?: IsMatchingPathCondition[];
57
+ /**
58
+ * exportの形式を下記にしたいもの
59
+ *
60
+ * ```
61
+ * export { default as abc } from './abc';
62
+ * ```
63
+ */
64
+ exportDefaultAs?: IsMatchingPathCondition[];
65
+ /**
66
+ * exportの形式を下記にしたいもの
67
+ *
68
+ * ```
69
+ * export type * from './abc';
70
+ * ```
71
+ */
72
+ exportTypeAll?: IsMatchingPathCondition[];
73
+ /**
74
+ * お試し\
75
+ * ファイルの操作は行わない
76
+ */
77
+ dryRun?: boolean;
78
+ };
79
+ //#endregion
80
+ export { IndexesOptions };
81
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,3 @@
1
+ const require_installFromLocal_installFromLocal = require('./installFromLocal.cjs');
2
+
3
+ module.exports = require_installFromLocal_installFromLocal;
@@ -0,0 +1,3 @@
1
+ import { InstallFromLocalOptions } from "./types.cjs";
2
+ import installFromLocal from "./installFromLocal.cjs";
3
+ export { InstallFromLocalOptions, installFromLocal as default };
@@ -0,0 +1,3 @@
1
+ import { InstallFromLocalOptions } from "./types.mjs";
2
+ import installFromLocal from "./installFromLocal.mjs";
3
+ export { InstallFromLocalOptions, installFromLocal as default };
@@ -0,0 +1,3 @@
1
+ import installFromLocal from "./installFromLocal.mjs";
2
+
3
+ export { installFromLocal as default };
@@ -0,0 +1,46 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_checkExistence_checkExistence = require('../checkExistence/checkExistence.cjs');
3
+ require('../checkExistence/index.cjs');
4
+ let fs_extra = require("fs-extra");
5
+ fs_extra = require_runtime.__toESM(fs_extra, 1);
6
+ let path = require("path");
7
+ path = require_runtime.__toESM(path, 1);
8
+ let remeda = require("remeda");
9
+
10
+ //#region src/installFromLocal/installFromLocal.ts
11
+ /**
12
+ * ローカルに配置されたパッケージを差し替える
13
+ * @param localNodeModulesPath ローカルのnode_modulesディレクトリのパス
14
+ * @param options オプション
15
+ */
16
+ function installFromLocal(localNodeModulesPath, options = {}) {
17
+ const { packageJsonPath = "./package.json", nodeModulesPath = "./node_modules", dryRun } = options;
18
+ const resolvedLocalNodeModulesPath = path.default.resolve(localNodeModulesPath);
19
+ const resolvedPackageJsonPath = path.default.resolve(packageJsonPath);
20
+ if (!require_checkExistence_checkExistence(resolvedLocalNodeModulesPath, resolvedPackageJsonPath)) return;
21
+ console.info(`${localNodeModulesPath} -> ${nodeModulesPath}`);
22
+ const packageJson = fs_extra.default.readJSONSync(resolvedPackageJsonPath);
23
+ const localPackages = (0, remeda.reduce)({
24
+ ...packageJson.dependencies,
25
+ ...packageJson.devDependencies
26
+ }, (result, value, key) => {
27
+ if (value.startsWith(localNodeModulesPath)) result[key] = value;
28
+ else if (value.startsWith(`file:${localNodeModulesPath}`)) result[key] = value.substring(5);
29
+ return result;
30
+ }, {});
31
+ for (const packageName in localPackages) {
32
+ const localPackagePath = path.default.resolve(localPackages[packageName]);
33
+ if (fs_extra.default.existsSync(localPackagePath)) {
34
+ const installedPackagePath = path.default.resolve(nodeModulesPath, packageName);
35
+ if (!dryRun) {
36
+ if (fs_extra.default.existsSync(installedPackagePath)) fs_extra.default.removeSync(installedPackagePath);
37
+ fs_extra.default.copySync(localPackagePath, installedPackagePath);
38
+ }
39
+ console.info(`${packageName} is being copied...`);
40
+ }
41
+ }
42
+ }
43
+
44
+ //#endregion
45
+ module.exports = installFromLocal;
46
+ //# sourceMappingURL=installFromLocal.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installFromLocal.cjs","names":["checkExistence","fs"],"sources":["../../src/installFromLocal/installFromLocal.ts"],"sourcesContent":["import fs from 'fs-extra';\r\nimport path from 'path';\r\nimport { reduce } from 'remeda';\r\nimport checkExistence from '../checkExistence';\r\nimport type { InstallFromLocalOptions } from './types';\r\n\r\n/**\r\n * ローカルに配置されたパッケージを差し替える\r\n * @param localNodeModulesPath ローカルのnode_modulesディレクトリのパス\r\n * @param options オプション\r\n */\r\nexport default function installFromLocal(\r\n localNodeModulesPath: string,\r\n options: InstallFromLocalOptions = {},\r\n) {\r\n const {\r\n packageJsonPath = './package.json',\r\n nodeModulesPath = './node_modules',\r\n dryRun,\r\n } = options;\r\n const resolvedLocalNodeModulesPath = path.resolve(localNodeModulesPath);\r\n const resolvedPackageJsonPath = path.resolve(packageJsonPath);\r\n\r\n if (!checkExistence(resolvedLocalNodeModulesPath, resolvedPackageJsonPath)) {\r\n return;\r\n }\r\n\r\n console.info(`${localNodeModulesPath} -> ${nodeModulesPath}`);\r\n\r\n // package.jsonからローカルのnode_modulesにあるパッケージを取得\r\n const packageJson = fs.readJSONSync(resolvedPackageJsonPath);\r\n const localPackages = reduce(\r\n { ...packageJson.dependencies, ...packageJson.devDependencies },\r\n (result: Record<string, string>, value: string, key) => {\r\n if (value.startsWith(localNodeModulesPath)) {\r\n result[key] = value;\r\n } else if (value.startsWith(`file:${localNodeModulesPath}`)) {\r\n result[key] = value.substring(5);\r\n }\r\n return result;\r\n },\r\n {},\r\n );\r\n\r\n for (const packageName in localPackages) {\r\n // ローカルパッケージの確認\r\n const localPackagePath = path.resolve(localPackages[packageName]);\r\n if (fs.existsSync(localPackagePath)) {\r\n // ローカルパッケージがある場合のみ処理\r\n const installedPackagePath = path.resolve(nodeModulesPath, packageName);\r\n if (!dryRun) {\r\n // コピーを行う\r\n if (fs.existsSync(installedPackagePath)) {\r\n // 古いパッケージは削除\r\n fs.removeSync(installedPackagePath);\r\n }\r\n // パッケージをコピー\r\n fs.copySync(localPackagePath, installedPackagePath);\r\n }\r\n console.info(`${packageName} is being copied...`);\r\n }\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;AAWA,SAAwB,iBACtB,sBACA,UAAmC,EAAE,EACrC;CACA,MAAM,EACJ,kBAAkB,kBAClB,kBAAkB,kBAClB,WACE;CACJ,MAAM,+BAA+B,aAAK,QAAQ,qBAAqB;CACvE,MAAM,0BAA0B,aAAK,QAAQ,gBAAgB;AAE7D,KAAI,CAACA,sCAAe,8BAA8B,wBAAwB,CACxE;AAGF,SAAQ,KAAK,GAAG,qBAAqB,MAAM,kBAAkB;CAG7D,MAAM,cAAcC,iBAAG,aAAa,wBAAwB;CAC5D,MAAM,mCACJ;EAAE,GAAG,YAAY;EAAc,GAAG,YAAY;EAAiB,GAC9D,QAAgC,OAAe,QAAQ;AACtD,MAAI,MAAM,WAAW,qBAAqB,CACxC,QAAO,OAAO;WACL,MAAM,WAAW,QAAQ,uBAAuB,CACzD,QAAO,OAAO,MAAM,UAAU,EAAE;AAElC,SAAO;IAET,EAAE,CACH;AAED,MAAK,MAAM,eAAe,eAAe;EAEvC,MAAM,mBAAmB,aAAK,QAAQ,cAAc,aAAa;AACjE,MAAIA,iBAAG,WAAW,iBAAiB,EAAE;GAEnC,MAAM,uBAAuB,aAAK,QAAQ,iBAAiB,YAAY;AACvE,OAAI,CAAC,QAAQ;AAEX,QAAIA,iBAAG,WAAW,qBAAqB,CAErC,kBAAG,WAAW,qBAAqB;AAGrC,qBAAG,SAAS,kBAAkB,qBAAqB;;AAErD,WAAQ,KAAK,GAAG,YAAY,qBAAqB"}
@@ -0,0 +1,11 @@
1
+ import { InstallFromLocalOptions } from "./types.cjs";
2
+
3
+ //#region src/installFromLocal/installFromLocal.d.ts
4
+ /**
5
+ * ローカルに配置されたパッケージを差し替える
6
+ * @param localNodeModulesPath ローカルのnode_modulesディレクトリのパス
7
+ * @param options オプション
8
+ */
9
+ declare function installFromLocal(localNodeModulesPath: string, options?: InstallFromLocalOptions): void;
10
+ export = installFromLocal;
11
+ //# sourceMappingURL=installFromLocal.d.cts.map
@@ -0,0 +1,12 @@
1
+ import { InstallFromLocalOptions } from "./types.mjs";
2
+
3
+ //#region src/installFromLocal/installFromLocal.d.ts
4
+ /**
5
+ * ローカルに配置されたパッケージを差し替える
6
+ * @param localNodeModulesPath ローカルのnode_modulesディレクトリのパス
7
+ * @param options オプション
8
+ */
9
+ declare function installFromLocal(localNodeModulesPath: string, options?: InstallFromLocalOptions): void;
10
+ //#endregion
11
+ export { installFromLocal as default };
12
+ //# sourceMappingURL=installFromLocal.d.mts.map
@@ -0,0 +1,43 @@
1
+ import checkExistence from "../checkExistence/checkExistence.mjs";
2
+ import "../checkExistence/index.mjs";
3
+ import fs from "fs-extra";
4
+ import path from "path";
5
+ import { reduce } from "remeda";
6
+
7
+ //#region src/installFromLocal/installFromLocal.ts
8
+ /**
9
+ * ローカルに配置されたパッケージを差し替える
10
+ * @param localNodeModulesPath ローカルのnode_modulesディレクトリのパス
11
+ * @param options オプション
12
+ */
13
+ function installFromLocal(localNodeModulesPath, options = {}) {
14
+ const { packageJsonPath = "./package.json", nodeModulesPath = "./node_modules", dryRun } = options;
15
+ const resolvedLocalNodeModulesPath = path.resolve(localNodeModulesPath);
16
+ const resolvedPackageJsonPath = path.resolve(packageJsonPath);
17
+ if (!checkExistence(resolvedLocalNodeModulesPath, resolvedPackageJsonPath)) return;
18
+ console.info(`${localNodeModulesPath} -> ${nodeModulesPath}`);
19
+ const packageJson = fs.readJSONSync(resolvedPackageJsonPath);
20
+ const localPackages = reduce({
21
+ ...packageJson.dependencies,
22
+ ...packageJson.devDependencies
23
+ }, (result, value, key) => {
24
+ if (value.startsWith(localNodeModulesPath)) result[key] = value;
25
+ else if (value.startsWith(`file:${localNodeModulesPath}`)) result[key] = value.substring(5);
26
+ return result;
27
+ }, {});
28
+ for (const packageName in localPackages) {
29
+ const localPackagePath = path.resolve(localPackages[packageName]);
30
+ if (fs.existsSync(localPackagePath)) {
31
+ const installedPackagePath = path.resolve(nodeModulesPath, packageName);
32
+ if (!dryRun) {
33
+ if (fs.existsSync(installedPackagePath)) fs.removeSync(installedPackagePath);
34
+ fs.copySync(localPackagePath, installedPackagePath);
35
+ }
36
+ console.info(`${packageName} is being copied...`);
37
+ }
38
+ }
39
+ }
40
+
41
+ //#endregion
42
+ export { installFromLocal as default };
43
+ //# sourceMappingURL=installFromLocal.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installFromLocal.mjs","names":[],"sources":["../../src/installFromLocal/installFromLocal.ts"],"sourcesContent":["import fs from 'fs-extra';\r\nimport path from 'path';\r\nimport { reduce } from 'remeda';\r\nimport checkExistence from '../checkExistence';\r\nimport type { InstallFromLocalOptions } from './types';\r\n\r\n/**\r\n * ローカルに配置されたパッケージを差し替える\r\n * @param localNodeModulesPath ローカルのnode_modulesディレクトリのパス\r\n * @param options オプション\r\n */\r\nexport default function installFromLocal(\r\n localNodeModulesPath: string,\r\n options: InstallFromLocalOptions = {},\r\n) {\r\n const {\r\n packageJsonPath = './package.json',\r\n nodeModulesPath = './node_modules',\r\n dryRun,\r\n } = options;\r\n const resolvedLocalNodeModulesPath = path.resolve(localNodeModulesPath);\r\n const resolvedPackageJsonPath = path.resolve(packageJsonPath);\r\n\r\n if (!checkExistence(resolvedLocalNodeModulesPath, resolvedPackageJsonPath)) {\r\n return;\r\n }\r\n\r\n console.info(`${localNodeModulesPath} -> ${nodeModulesPath}`);\r\n\r\n // package.jsonからローカルのnode_modulesにあるパッケージを取得\r\n const packageJson = fs.readJSONSync(resolvedPackageJsonPath);\r\n const localPackages = reduce(\r\n { ...packageJson.dependencies, ...packageJson.devDependencies },\r\n (result: Record<string, string>, value: string, key) => {\r\n if (value.startsWith(localNodeModulesPath)) {\r\n result[key] = value;\r\n } else if (value.startsWith(`file:${localNodeModulesPath}`)) {\r\n result[key] = value.substring(5);\r\n }\r\n return result;\r\n },\r\n {},\r\n );\r\n\r\n for (const packageName in localPackages) {\r\n // ローカルパッケージの確認\r\n const localPackagePath = path.resolve(localPackages[packageName]);\r\n if (fs.existsSync(localPackagePath)) {\r\n // ローカルパッケージがある場合のみ処理\r\n const installedPackagePath = path.resolve(nodeModulesPath, packageName);\r\n if (!dryRun) {\r\n // コピーを行う\r\n if (fs.existsSync(installedPackagePath)) {\r\n // 古いパッケージは削除\r\n fs.removeSync(installedPackagePath);\r\n }\r\n // パッケージをコピー\r\n fs.copySync(localPackagePath, installedPackagePath);\r\n }\r\n console.info(`${packageName} is being copied...`);\r\n }\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;AAWA,SAAwB,iBACtB,sBACA,UAAmC,EAAE,EACrC;CACA,MAAM,EACJ,kBAAkB,kBAClB,kBAAkB,kBAClB,WACE;CACJ,MAAM,+BAA+B,KAAK,QAAQ,qBAAqB;CACvE,MAAM,0BAA0B,KAAK,QAAQ,gBAAgB;AAE7D,KAAI,CAAC,eAAe,8BAA8B,wBAAwB,CACxE;AAGF,SAAQ,KAAK,GAAG,qBAAqB,MAAM,kBAAkB;CAG7D,MAAM,cAAc,GAAG,aAAa,wBAAwB;CAC5D,MAAM,gBAAgB,OACpB;EAAE,GAAG,YAAY;EAAc,GAAG,YAAY;EAAiB,GAC9D,QAAgC,OAAe,QAAQ;AACtD,MAAI,MAAM,WAAW,qBAAqB,CACxC,QAAO,OAAO;WACL,MAAM,WAAW,QAAQ,uBAAuB,CACzD,QAAO,OAAO,MAAM,UAAU,EAAE;AAElC,SAAO;IAET,EAAE,CACH;AAED,MAAK,MAAM,eAAe,eAAe;EAEvC,MAAM,mBAAmB,KAAK,QAAQ,cAAc,aAAa;AACjE,MAAI,GAAG,WAAW,iBAAiB,EAAE;GAEnC,MAAM,uBAAuB,KAAK,QAAQ,iBAAiB,YAAY;AACvE,OAAI,CAAC,QAAQ;AAEX,QAAI,GAAG,WAAW,qBAAqB,CAErC,IAAG,WAAW,qBAAqB;AAGrC,OAAG,SAAS,kBAAkB,qBAAqB;;AAErD,WAAQ,KAAK,GAAG,YAAY,qBAAqB"}
File without changes
@@ -1,19 +1,21 @@
1
- export type InstallFromLocalOptions = {
2
- /**
3
- * package.jsonのパス
4
- * @default './package.json'
5
- */
6
- packageJsonPath?: string;
7
-
8
- /**
9
- * node_modulesのパス
10
- * @default './node_modules'
11
- */
12
- nodeModulesPath?: string;
13
-
14
- /**
15
- * お試し
16
- * ファイルの操作は行わない
17
- */
18
- dryRun?: boolean;
19
- };
1
+ //#region src/installFromLocal/types.d.ts
2
+ type InstallFromLocalOptions = {
3
+ /**
4
+ * package.jsonのパス
5
+ * @default './package.json'
6
+ */
7
+ packageJsonPath?: string;
8
+ /**
9
+ * node_modulesのパス
10
+ * @default './node_modules'
11
+ */
12
+ nodeModulesPath?: string;
13
+ /**
14
+ * お試し
15
+ * ファイルの操作は行わない
16
+ */
17
+ dryRun?: boolean;
18
+ };
19
+ //#endregion
20
+ export { InstallFromLocalOptions };
21
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1,21 @@
1
+ //#region src/installFromLocal/types.d.ts
2
+ type InstallFromLocalOptions = {
3
+ /**
4
+ * package.jsonのパス
5
+ * @default './package.json'
6
+ */
7
+ packageJsonPath?: string;
8
+ /**
9
+ * node_modulesのパス
10
+ * @default './node_modules'
11
+ */
12
+ nodeModulesPath?: string;
13
+ /**
14
+ * お試し
15
+ * ファイルの操作は行わない
16
+ */
17
+ dryRun?: boolean;
18
+ };
19
+ //#endregion
20
+ export { InstallFromLocalOptions };
21
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,3 @@
1
+ const require_isMatchingPath_isMatchingPath = require('./isMatchingPath.cjs');
2
+
3
+ module.exports = require_isMatchingPath_isMatchingPath;
@@ -0,0 +1,3 @@
1
+ import { ConditionConfig, ConditionFn, ConditionFnOptions, ConditionValues, IsMatchingPathCondition, IsMatchingPathOptions } from "./types.cjs";
2
+ import isMatchingPath from "./isMatchingPath.cjs";
3
+ export { ConditionConfig, ConditionFn, ConditionFnOptions, ConditionValues, IsMatchingPathCondition, IsMatchingPathOptions, isMatchingPath as default };
@@ -0,0 +1,3 @@
1
+ import { ConditionConfig, ConditionFn, ConditionFnOptions, ConditionValues, IsMatchingPathCondition, IsMatchingPathOptions } from "./types.mjs";
2
+ import isMatchingPath from "./isMatchingPath.mjs";
3
+ export { ConditionConfig, ConditionFn, ConditionFnOptions, ConditionValues, IsMatchingPathCondition, IsMatchingPathOptions, isMatchingPath as default };
@@ -0,0 +1,3 @@
1
+ import isMatchingPath from "./isMatchingPath.mjs";
2
+
3
+ export { isMatchingPath as default };