@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.
- package/_virtual/_rolldown/runtime.cjs +29 -0
- package/addExports/addExports.cjs +61 -0
- package/addExports/addExports.cjs.map +1 -0
- package/addExports/addExports.d.cts +11 -0
- package/addExports/addExports.d.mts +12 -0
- package/addExports/addExports.mjs +59 -0
- package/addExports/addExports.mjs.map +1 -0
- package/addExports/index.cjs +3 -0
- package/addExports/index.d.cts +3 -0
- package/addExports/index.d.mts +3 -0
- package/addExports/index.mjs +3 -0
- package/addExports/types.cjs +0 -0
- package/{src/addExports/types.ts → addExports/types.d.cts} +33 -33
- package/addExports/types.d.mts +33 -0
- package/addExports/types.mjs +1 -0
- package/addJsExtensions/addJsExtensions.cjs +31 -0
- package/addJsExtensions/addJsExtensions.cjs.map +1 -0
- package/addJsExtensions/addJsExtensions.d.cts +8 -0
- package/addJsExtensions/addJsExtensions.d.mts +9 -0
- package/addJsExtensions/addJsExtensions.mjs +28 -0
- package/addJsExtensions/addJsExtensions.mjs.map +1 -0
- package/addJsExtensions/index.cjs +3 -0
- package/addJsExtensions/index.d.cts +2 -0
- package/addJsExtensions/index.d.mts +2 -0
- package/addJsExtensions/index.mjs +3 -0
- package/checkExistence/checkExistence.cjs +23 -0
- package/checkExistence/checkExistence.cjs.map +1 -0
- package/checkExistence/checkExistence.d.cts +9 -0
- package/checkExistence/checkExistence.d.mts +10 -0
- package/checkExistence/checkExistence.mjs +21 -0
- package/checkExistence/checkExistence.mjs.map +1 -0
- package/checkExistence/index.cjs +3 -0
- package/checkExistence/index.d.cts +2 -0
- package/checkExistence/index.d.mts +2 -0
- package/checkExistence/index.mjs +3 -0
- package/createExternalOptionFunction/createExternalOptionFunction.cjs +25 -0
- package/createExternalOptionFunction/createExternalOptionFunction.cjs.map +1 -0
- package/createExternalOptionFunction/createExternalOptionFunction.d.cts +10 -0
- package/createExternalOptionFunction/createExternalOptionFunction.d.mts +11 -0
- package/createExternalOptionFunction/createExternalOptionFunction.mjs +25 -0
- package/createExternalOptionFunction/createExternalOptionFunction.mjs.map +1 -0
- package/createExternalOptionFunction/index.cjs +3 -0
- package/createExternalOptionFunction/index.d.cts +2 -0
- package/createExternalOptionFunction/index.d.mts +2 -0
- package/createExternalOptionFunction/index.mjs +3 -0
- package/createExternalOptionFunction/types.cjs +0 -0
- package/createExternalOptionFunction/types.d.cts +31 -0
- package/createExternalOptionFunction/types.d.mts +31 -0
- package/createExternalOptionFunction/types.mjs +1 -0
- package/editJsonFile/editJsonFile.cjs +29 -0
- package/editJsonFile/editJsonFile.cjs.map +1 -0
- package/editJsonFile/editJsonFile.d.cts +9 -0
- package/editJsonFile/editJsonFile.d.mts +10 -0
- package/editJsonFile/editJsonFile.mjs +26 -0
- package/editJsonFile/editJsonFile.mjs.map +1 -0
- package/editJsonFile/index.cjs +3 -0
- package/editJsonFile/index.d.cts +2 -0
- package/editJsonFile/index.d.mts +2 -0
- package/editJsonFile/index.mjs +3 -0
- package/generatePublishPackageJson/generatePublishPackageJson.cjs +46 -0
- package/generatePublishPackageJson/generatePublishPackageJson.cjs.map +1 -0
- package/generatePublishPackageJson/generatePublishPackageJson.d.cts +6 -0
- package/generatePublishPackageJson/generatePublishPackageJson.d.mts +7 -0
- package/generatePublishPackageJson/generatePublishPackageJson.mjs +44 -0
- package/generatePublishPackageJson/generatePublishPackageJson.mjs.map +1 -0
- package/generatePublishPackageJson/index.cjs +3 -0
- package/generatePublishPackageJson/index.d.cts +3 -0
- package/generatePublishPackageJson/index.d.mts +3 -0
- package/generatePublishPackageJson/index.mjs +3 -0
- package/generatePublishPackageJson/types.cjs +0 -0
- package/{src/generatePublishPackageJson/types.ts → generatePublishPackageJson/types.d.cts} +60 -61
- package/generatePublishPackageJson/types.d.mts +60 -0
- package/generatePublishPackageJson/types.mjs +1 -0
- package/index.cjs +38 -0
- package/index.d.cts +13 -0
- package/index.d.mts +13 -0
- package/index.mjs +26 -0
- package/indexes/constants.cjs +123 -0
- package/indexes/constants.cjs.map +1 -0
- package/indexes/constants.d.cts +66 -0
- package/indexes/constants.d.mts +66 -0
- package/indexes/constants.mjs +106 -0
- package/indexes/constants.mjs.map +1 -0
- package/indexes/index.cjs +3 -0
- package/indexes/index.d.cts +3 -0
- package/indexes/index.d.mts +3 -0
- package/indexes/index.mjs +3 -0
- package/indexes/indexes.cjs +125 -0
- package/indexes/indexes.cjs.map +1 -0
- package/indexes/indexes.d.cts +11 -0
- package/indexes/indexes.d.mts +12 -0
- package/indexes/indexes.mjs +123 -0
- package/indexes/indexes.mjs.map +1 -0
- package/indexes/types.cjs +0 -0
- package/{src/indexes/types.ts → indexes/types.d.cts} +81 -87
- package/indexes/types.d.mts +81 -0
- package/indexes/types.mjs +1 -0
- package/installFromLocal/index.cjs +3 -0
- package/installFromLocal/index.d.cts +3 -0
- package/installFromLocal/index.d.mts +3 -0
- package/installFromLocal/index.mjs +3 -0
- package/installFromLocal/installFromLocal.cjs +46 -0
- package/installFromLocal/installFromLocal.cjs.map +1 -0
- package/installFromLocal/installFromLocal.d.cts +11 -0
- package/installFromLocal/installFromLocal.d.mts +12 -0
- package/installFromLocal/installFromLocal.mjs +43 -0
- package/installFromLocal/installFromLocal.mjs.map +1 -0
- package/installFromLocal/types.cjs +0 -0
- package/{src/installFromLocal/types.ts → installFromLocal/types.d.cts} +21 -19
- package/installFromLocal/types.d.mts +21 -0
- package/installFromLocal/types.mjs +1 -0
- package/isMatchingPath/index.cjs +3 -0
- package/isMatchingPath/index.d.cts +3 -0
- package/isMatchingPath/index.d.mts +3 -0
- package/isMatchingPath/index.mjs +3 -0
- package/isMatchingPath/isMatchingPath.cjs +52 -0
- package/isMatchingPath/isMatchingPath.cjs.map +1 -0
- package/isMatchingPath/isMatchingPath.d.cts +13 -0
- package/isMatchingPath/isMatchingPath.d.mts +14 -0
- package/isMatchingPath/isMatchingPath.mjs +50 -0
- package/isMatchingPath/isMatchingPath.mjs.map +1 -0
- package/isMatchingPath/types.cjs +0 -0
- package/isMatchingPath/types.d.cts +72 -0
- package/isMatchingPath/types.d.mts +72 -0
- package/isMatchingPath/types.mjs +1 -0
- package/isTargetPath/index.cjs +3 -0
- package/isTargetPath/index.d.cts +3 -0
- package/isTargetPath/index.d.mts +3 -0
- package/isTargetPath/index.mjs +3 -0
- package/isTargetPath/isTargetPath.cjs +21 -0
- package/isTargetPath/isTargetPath.cjs.map +1 -0
- package/isTargetPath/isTargetPath.d.cts +7 -0
- package/isTargetPath/isTargetPath.d.mts +8 -0
- package/isTargetPath/isTargetPath.mjs +19 -0
- package/isTargetPath/isTargetPath.mjs.map +1 -0
- package/isTargetPath/types.cjs +0 -0
- package/isTargetPath/types.d.cts +33 -0
- package/isTargetPath/types.d.mts +33 -0
- package/isTargetPath/types.mjs +1 -0
- package/moveFilesToSubdir/index.cjs +3 -0
- package/moveFilesToSubdir/index.d.cts +3 -0
- package/moveFilesToSubdir/index.d.mts +3 -0
- package/moveFilesToSubdir/index.mjs +3 -0
- package/moveFilesToSubdir/moveFilesToSubdir.cjs +32 -0
- package/moveFilesToSubdir/moveFilesToSubdir.cjs.map +1 -0
- package/moveFilesToSubdir/moveFilesToSubdir.d.cts +10 -0
- package/moveFilesToSubdir/moveFilesToSubdir.d.mts +11 -0
- package/moveFilesToSubdir/moveFilesToSubdir.mjs +29 -0
- package/moveFilesToSubdir/moveFilesToSubdir.mjs.map +1 -0
- package/moveFilesToSubdir/types.cjs +0 -0
- package/moveFilesToSubdir/types.d.cts +18 -0
- package/moveFilesToSubdir/types.d.mts +18 -0
- package/moveFilesToSubdir/types.mjs +1 -0
- package/package.json +20 -30
- package/removeFiles/index.cjs +3 -0
- package/removeFiles/index.d.cts +2 -0
- package/removeFiles/index.d.mts +2 -0
- package/removeFiles/index.mjs +3 -0
- package/removeFiles/removeFiles.cjs +15 -0
- package/removeFiles/removeFiles.cjs.map +1 -0
- package/removeFiles/removeFiles.d.cts +6 -0
- package/removeFiles/removeFiles.d.mts +7 -0
- package/removeFiles/removeFiles.mjs +12 -0
- package/removeFiles/removeFiles.mjs.map +1 -0
- package/removeFiles/types.cjs +0 -0
- package/removeFiles/types.d.cts +9 -0
- package/removeFiles/types.d.mts +9 -0
- package/removeFiles/types.mjs +1 -0
- package/ver/index.cjs +3 -0
- package/ver/index.d.cts +3 -0
- package/ver/index.d.mts +3 -0
- package/ver/index.mjs +3 -0
- package/ver/types.cjs +0 -0
- package/{src/ver/types.ts → ver/types.d.cts} +16 -13
- package/ver/types.d.mts +16 -0
- package/ver/types.mjs +1 -0
- package/ver/ver.cjs +34 -0
- package/ver/ver.cjs.map +1 -0
- package/ver/ver.d.cts +11 -0
- package/ver/ver.d.mts +12 -0
- package/ver/ver.mjs +31 -0
- package/ver/ver.mjs.map +1 -0
- package/src/addExports/addExports.ts +0 -98
- package/src/addExports/index.ts +0 -2
- package/src/addJsExtensions/addJsExtensions.ts +0 -31
- package/src/addJsExtensions/index.ts +0 -1
- package/src/checkExistence/checkExistence.ts +0 -16
- package/src/checkExistence/index.ts +0 -1
- package/src/editJsonFile/editJsonFile.ts +0 -30
- package/src/editJsonFile/index.ts +0 -1
- package/src/generatePublishPackageJson/generatePublishPackageJson.ts +0 -55
- package/src/generatePublishPackageJson/index.ts +0 -2
- package/src/index.ts +0 -10
- package/src/indexes/constants.ts +0 -135
- package/src/indexes/index.ts +0 -2
- package/src/indexes/indexes.ts +0 -194
- package/src/installFromLocal/index.ts +0 -2
- package/src/installFromLocal/installFromLocal.ts +0 -63
- package/src/isMatchingPath/_types.ts +0 -65
- package/src/isMatchingPath/index.ts +0 -2
- package/src/isMatchingPath/isMatchingPath.ts +0 -88
- package/src/isMatchingPath/types.ts +0 -21
- package/src/moveFilesToSubdir/index.ts +0 -1
- package/src/moveFilesToSubdir/moveFilesToSubdir.ts +0 -23
- package/src/ver/index.ts +0 -2
- package/src/ver/ver.ts +0 -38
- package/tsconfig.json +0 -46
- 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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* indexのファイル名\
|
|
12
|
-
* @default `index.ts`
|
|
13
|
-
*/
|
|
14
|
-
indexFileName?: string;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* -
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* export
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* ```
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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,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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* node_modulesのパス
|
|
10
|
-
* @default './node_modules'
|
|
11
|
-
*/
|
|
12
|
-
nodeModulesPath?: string;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
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 };
|