create-yarn-workspaces 3.0.35 → 3.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +34 -11
- package/bin/yarn-ws-init.js +18 -16
- package/bin/yarn-ws-init.js.map +1 -1
- package/index.d.ts +22 -82
- package/index.js +43 -303
- package/index.js.map +1 -1
- package/lib/check-env.d.ts +42 -0
- package/lib/check-env.js +87 -0
- package/lib/check-env.js.map +1 -0
- package/lib/core.d.ts +85 -0
- package/lib/core.js +273 -0
- package/lib/core.js.map +1 -0
- package/lib/index.d.ts +4 -5
- package/lib/index.js +15 -18
- package/lib/index.js.map +1 -1
- package/lib/package.demo.json +1 -1
- package/lib/util.d.ts +4 -5
- package/lib/util.js +10 -9
- package/lib/util.js.map +1 -1
- package/package.json +12 -6
- package/yargs-setting.d.ts +3 -10
- package/yargs-setting.js +11 -14
- package/yargs-setting.js.map +1 -1
package/lib/core.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._precheckYarnWorkspaces = _precheckYarnWorkspaces;
|
|
4
|
+
exports._createYarnWorkspaces = _createYarnWorkspaces;
|
|
5
|
+
exports.createDirByPackages = createDirByPackages;
|
|
6
|
+
const upath2_1 = require("upath2");
|
|
7
|
+
const fs_extra_1 = require("fs-extra");
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
const util_1 = require("./util");
|
|
10
|
+
const find_root_1 = require("@yarn-tool/find-root");
|
|
11
|
+
const staticFiles_1 = require("@yarn-tool/fix-all/lib/file/staticFiles");
|
|
12
|
+
const static_file_1 = require("@yarn-tool/static-file");
|
|
13
|
+
const sort_package_json3_1 = require("sort-package-json3");
|
|
14
|
+
const logger_1 = require("debug-color2/logger");
|
|
15
|
+
const wsCopyStaticFiles_1 = require("@yarn-tool/static-file/lib/ws/wsCopyStaticFiles");
|
|
16
|
+
/**
|
|
17
|
+
* 創建 Workspaces 的核心前置檢查邏輯
|
|
18
|
+
*
|
|
19
|
+
* 處理參數正規化、尋找專案根目錄,並檢查:
|
|
20
|
+
* - 是否已存在 Package
|
|
21
|
+
* - 是否已存在(父層)Workspaces
|
|
22
|
+
*
|
|
23
|
+
* @param cwd - 工作目錄路徑;也可直接傳入 IOptions
|
|
24
|
+
* @param options - 配置選項
|
|
25
|
+
* @returns 前置檢查結果;`ok` 為 false 時不應繼續創建
|
|
26
|
+
*/
|
|
27
|
+
function _precheckYarnWorkspaces(cwd, options = {}) {
|
|
28
|
+
var _a;
|
|
29
|
+
/** 處理第一個參數可能是選項物件的情況 */
|
|
30
|
+
if (cwd && typeof cwd != 'string') {
|
|
31
|
+
options = cwd;
|
|
32
|
+
cwd = options.cwd;
|
|
33
|
+
}
|
|
34
|
+
/** 預設使用當前工作目錄 */
|
|
35
|
+
cwd !== null && cwd !== void 0 ? cwd : (cwd = process.cwd());
|
|
36
|
+
/** 尋找專案根目錄資訊 */
|
|
37
|
+
const rootData = (0, find_root_1.findRootLazy)({
|
|
38
|
+
cwd,
|
|
39
|
+
});
|
|
40
|
+
/** 標準化路徑 */
|
|
41
|
+
cwd = (0, upath2_1.normalize)((_a = rootData === null || rootData === void 0 ? void 0 : rootData.cwd) !== null && _a !== void 0 ? _a : cwd);
|
|
42
|
+
/** 取得 Package 根目錄與 Workspaces 路徑 */
|
|
43
|
+
let root = rootData === null || rootData === void 0 ? void 0 : rootData.pkg;
|
|
44
|
+
let ws = rootData === null || rootData === void 0 ? void 0 : rootData.ws;
|
|
45
|
+
/** 實際要初始化的目標路徑:優先採用既有 package 根目錄,否則退回 cwd。 */
|
|
46
|
+
let targetPath = (0, upath2_1.resolve)(root || cwd);
|
|
47
|
+
/** 除錯輸出 */
|
|
48
|
+
options.debug && logger_1.consoleLogger.debug({
|
|
49
|
+
targetPath,
|
|
50
|
+
ws,
|
|
51
|
+
options,
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* 檢查是否已存在 Package
|
|
55
|
+
*/
|
|
56
|
+
if (!options.ignoreExistsPackage && root) {
|
|
57
|
+
logger_1.consoleLogger.error(`already have package at "${root}", or use ignoreExistsPackage for overwrite it`);
|
|
58
|
+
return { ok: false, targetPath, options };
|
|
59
|
+
}
|
|
60
|
+
else if (root) {
|
|
61
|
+
/** 忽略已存在的 Package */
|
|
62
|
+
logger_1.consoleLogger.warn(`ignore exists package "${root}"`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 檢查是否已存在 Workspaces
|
|
66
|
+
*/
|
|
67
|
+
if (ws) {
|
|
68
|
+
/** 檢查目標路徑是否與現有 Workspace 相同 */
|
|
69
|
+
let bool = !(0, util_1.isSamePath)(targetPath, ws);
|
|
70
|
+
logger_1.consoleLogger.warn(`detect exists workspace "${ws}"`);
|
|
71
|
+
if (bool) {
|
|
72
|
+
/** 根據選項決定是否忽略父層 Workspaces */
|
|
73
|
+
if (options.ignoreParentWorkspaces) {
|
|
74
|
+
logger_1.consoleLogger.warn(`ignoreParentWorkspaces = true`);
|
|
75
|
+
bool = false;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
logger_1.consoleLogger.error(`target path already is workspace`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (bool) {
|
|
82
|
+
return { ok: false, targetPath, options };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return { ok: true, targetPath, options };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 內部創建 Workspaces 實作函式
|
|
89
|
+
*
|
|
90
|
+
* 執行實際的 Workspaces 初始化工作,包含:
|
|
91
|
+
* - 讀取並更新 Lerna 配置
|
|
92
|
+
* - 創建或更新 package.json
|
|
93
|
+
* - 複製靜態範本檔案
|
|
94
|
+
* - 創建 packages 目錄
|
|
95
|
+
*
|
|
96
|
+
* @param targetPath - 目標路徑
|
|
97
|
+
* @param options - 配置選項
|
|
98
|
+
* @returns 是否成功
|
|
99
|
+
*/
|
|
100
|
+
function _createYarnWorkspaces(targetPath, options = {}) {
|
|
101
|
+
var _a;
|
|
102
|
+
logger_1.consoleLogger.info(`create in target path "${targetPath}"`);
|
|
103
|
+
let pkg;
|
|
104
|
+
let lerna;
|
|
105
|
+
/**
|
|
106
|
+
* 嘗試讀取現有的 lerna.json 配置
|
|
107
|
+
*/
|
|
108
|
+
{
|
|
109
|
+
let file = (0, upath2_1.join)(targetPath, 'lerna.json');
|
|
110
|
+
if ((0, fs_extra_1.existsSync)(file)) {
|
|
111
|
+
let json = JSON.parse((0, fs_extra_1.readFileSync)(file).toString());
|
|
112
|
+
/**
|
|
113
|
+
* 清理空的 packages 陣列
|
|
114
|
+
*/
|
|
115
|
+
if (json.packages && !Object.keys(json.packages).length) {
|
|
116
|
+
json.packages = undefined;
|
|
117
|
+
}
|
|
118
|
+
lerna = json;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 預設 packages 目錄模式
|
|
123
|
+
*/
|
|
124
|
+
let packages = lerna && lerna.packages || [
|
|
125
|
+
"packages/*",
|
|
126
|
+
];
|
|
127
|
+
let file = (0, upath2_1.join)(targetPath, 'package.json');
|
|
128
|
+
/**
|
|
129
|
+
* 處理 package.json 不存在的情況
|
|
130
|
+
*/
|
|
131
|
+
if (!(0, fs_extra_1.existsSync)(file)) {
|
|
132
|
+
/** 使用目錄名作為預設 Package 名稱 */
|
|
133
|
+
let name = (0, upath2_1.basename)(targetPath);
|
|
134
|
+
/** 創建目標目錄(如果不存在) */
|
|
135
|
+
if (!(0, fs_extra_1.existsSync)(targetPath)) {
|
|
136
|
+
(0, fs_extra_1.mkdirSync)(targetPath);
|
|
137
|
+
}
|
|
138
|
+
/** 合併預設配置與基本資訊 */
|
|
139
|
+
pkg = Object.assign((0, index_1.getDefaultPackageJson)(name), {
|
|
140
|
+
name,
|
|
141
|
+
workspaces: packages,
|
|
142
|
+
});
|
|
143
|
+
/**
|
|
144
|
+
* 執行自定義初始化回呼
|
|
145
|
+
*/
|
|
146
|
+
if (options.initPackageJson) {
|
|
147
|
+
let ret = options.initPackageJson(pkg);
|
|
148
|
+
if (ret) {
|
|
149
|
+
pkg = ret;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
/**
|
|
155
|
+
* 處理已存在的 package.json
|
|
156
|
+
*/
|
|
157
|
+
let json = JSON.parse((0, fs_extra_1.readFileSync)(file).toString());
|
|
158
|
+
let workspaces;
|
|
159
|
+
/**
|
|
160
|
+
* 解析現有的 workspaces 配置
|
|
161
|
+
*/
|
|
162
|
+
if (json.workspaces && Object.keys(json.workspaces).length) {
|
|
163
|
+
workspaces = json.workspaces;
|
|
164
|
+
/**
|
|
165
|
+
* 支援 nohoist 配置格式
|
|
166
|
+
* @see https://yarnpkg.com/blog/2018/02/15/nohoist/
|
|
167
|
+
*/
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
packages = workspaces.packages || workspaces;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
workspaces = packages;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 更新 Package.json 內容
|
|
176
|
+
*/
|
|
177
|
+
pkg = Object.assign(json, {
|
|
178
|
+
"private": true,
|
|
179
|
+
"workspaces": workspaces,
|
|
180
|
+
});
|
|
181
|
+
/**
|
|
182
|
+
* 合併預設腳本與欄位
|
|
183
|
+
*/
|
|
184
|
+
Object.entries((0, index_1.getDefaultPackageJson)(json.name))
|
|
185
|
+
.forEach(([field, value]) => {
|
|
186
|
+
var _a, _b;
|
|
187
|
+
/**
|
|
188
|
+
* 特殊處理 scripts 欄位:合併而非覆蓋
|
|
189
|
+
*/
|
|
190
|
+
if (field === 'scripts') {
|
|
191
|
+
(_a = pkg.scripts) !== null && _a !== void 0 ? _a : (pkg.scripts = {});
|
|
192
|
+
pkg.scripts = {
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
...value,
|
|
195
|
+
...pkg.scripts,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
/** 使用空值合併運算子設置預設值 */
|
|
200
|
+
(_b = pkg[field]) !== null && _b !== void 0 ? _b : (pkg[field] = value);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* 寫入格式化後的 package.json
|
|
206
|
+
*/
|
|
207
|
+
let s = JSON.stringify((0, sort_package_json3_1.sortPackageJson)(pkg), null, 2);
|
|
208
|
+
(0, fs_extra_1.writeFileSync)(file, s);
|
|
209
|
+
logger_1.consoleLogger.success(`create workspace package.json`);
|
|
210
|
+
/**
|
|
211
|
+
* 更新 Lerna 配置(如果存在且需要更新)
|
|
212
|
+
*/
|
|
213
|
+
if (lerna && (packages != lerna.packages || lerna.npmClient !== 'yarn' || lerna['useWorkspaces'] !== true)) {
|
|
214
|
+
let file = (0, upath2_1.join)(targetPath, 'lerna.json');
|
|
215
|
+
/** 更新 Workspaces 模式 */
|
|
216
|
+
lerna.packages = packages;
|
|
217
|
+
(_a = lerna.npmClient) !== null && _a !== void 0 ? _a : (lerna.npmClient = 'pnpm');
|
|
218
|
+
// lerna['useWorkspaces'] = true;
|
|
219
|
+
let s = JSON.stringify((0, sort_package_json3_1.sortPackageJson)(lerna), null, 2);
|
|
220
|
+
(0, fs_extra_1.writeFileSync)(file, s);
|
|
221
|
+
logger_1.consoleLogger.info(`update lerna.json`);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 複製靜態範本檔案
|
|
225
|
+
*/
|
|
226
|
+
const file_map = (0, wsCopyStaticFiles_1.getWsCopyStaticFiles)();
|
|
227
|
+
/**
|
|
228
|
+
* 複製靜態範本檔案
|
|
229
|
+
*
|
|
230
|
+
* 此呼叫點 addStaticFiles 預設為 true,可用 noStaticFiles 關閉
|
|
231
|
+
*/
|
|
232
|
+
if ((0, staticFiles_1._isAddStaticFilesOrReset)(options, true)) {
|
|
233
|
+
(0, static_file_1.copyStaticFiles)({
|
|
234
|
+
cwd: targetPath,
|
|
235
|
+
file_map,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* 根據 packages 模式創建目錄
|
|
240
|
+
*/
|
|
241
|
+
createDirByPackages(targetPath, packages);
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* 根據 packages 模式創建目錄
|
|
246
|
+
*
|
|
247
|
+
* 解析 packages 陣列中的目錄模式(如 "packages/*"),
|
|
248
|
+
* 並創建對應的實體目錄。
|
|
249
|
+
*
|
|
250
|
+
* @param cwd - 當前工作目錄
|
|
251
|
+
* @param packages - packages 模式陣列
|
|
252
|
+
* @returns 是否有創建任何目錄
|
|
253
|
+
*/
|
|
254
|
+
function createDirByPackages(cwd, packages) {
|
|
255
|
+
return packages.some(function (value) {
|
|
256
|
+
let bool;
|
|
257
|
+
/** 提取路徑的第一個部分(目錄名稱) */
|
|
258
|
+
let s = value.split(/[\/\\]/)[0];
|
|
259
|
+
/**
|
|
260
|
+
* 只處理不包含 glob 模式的純目錄路徑
|
|
261
|
+
*/
|
|
262
|
+
if (!/[!?\*{}\[\]]/.test(s)) {
|
|
263
|
+
let dir = (0, upath2_1.join)(cwd, s);
|
|
264
|
+
/** 目錄不存在時創建 */
|
|
265
|
+
if (!(0, fs_extra_1.existsSync)(dir)) {
|
|
266
|
+
(0, fs_extra_1.mkdirSync)(dir);
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
return bool;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=core.js.map
|
package/lib/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["core.ts"],"names":[],"mappings":";;AAkFA,0DAgFC;AAeD,sDA4LC;AAYD,kDA2BC;AAjZD,mCAA6E;AAC7E,uCAA8E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,CAAC,CAAC;QAEjC;;WAEG;QACH,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAC3B,CAAC;YACA,IAAI,GAAG,GAAG,IAAA,aAAI,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAEvB,eAAe;YACf,IAAI,CAAC,IAAA,qBAAU,EAAC,GAAG,CAAC,EACpB,CAAC;gBACA,IAAA,oBAAS,EAAC,GAAG,CAAC,CAAC;YAChB,CAAC;YAED,OAAO,IAAI,CAAC;QACb,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { INpmAutoFixAll } from '@yarn-tool/fix-all';\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { ILernaJson } from '@ts-type/package-dts/lerna-json';\nimport { basename, join, normalize as pathNormalize, resolve } from 'upath2';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs-extra';\nimport { getDefaultPackageJson } from './index';\nimport { isSamePath } from './util';\nimport { findRootLazy } from '@yarn-tool/find-root';\nimport { _isAddStaticFilesOrReset } from '@yarn-tool/fix-all/lib/file/staticFiles';\nimport { copyStaticFiles } from '@yarn-tool/static-file';\nimport { sortPackageJson } from 'sort-package-json3';\nimport { consoleLogger as console } from 'debug-color2/logger';\nimport { getWsCopyStaticFiles } from '@yarn-tool/static-file/lib/ws/wsCopyStaticFiles';\n\n/**\n * 創建 Workspaces 的選項介面\n */\nexport interface IOptions extends Pick<INpmAutoFixAll, 'addStaticFiles' | 'noStaticFiles'>\n{\n\t/**\n\t * 工作目錄路徑\n\t */\n\tcwd?: string,\n\n\t/**\n\t * 忽略父層 Workspaces\n\t */\n\tignoreParentWorkspaces?: boolean,\n\n\t/**\n\t * 忽略已存在的 Package\n\t */\n\tignoreExistsPackage?: boolean,\n\n\t/**\n\t * 初始化 Package.json 的回呼函式\n\t * @template T - 擴展屬性類型\n\t * @param current - 當前的 package.json\n\t * @returns 修改後的 package.json\n\t */\n\tinitPackageJson?<T extends Record<string, any> = {}>(current: IPackageJson): IPackageJson & T,\n\n\t/**\n\t * 啟用除錯模式\n\t */\n\tdebug?: boolean,\n\n\t/**\n\t * 啟用互動介面\n\t *\n\t * 僅 `createYarnWorkspacesAsync` 支援,sync 版本會忽略此選項;\n\t * 需環境具備 TTY,且在 `_checkEnv` 判定疑似錯誤路徑時才會詢問是否繼續。\n\t */\n\tinteractive?: boolean,\n}\n\n/**\n * `createYarnWorkspaces` 的前置檢查結果\n */\nexport interface IPrecheckResult\n{\n\t/** 是否可繼續執行創建流程 */\n\tok: boolean,\n\n\t/** 實際要初始化的目標路徑:優先採用既有 package 根目錄,否則退回 cwd。 */\n\ttargetPath: string,\n\n\t/** 經參數正規化後的配置選項(第一個參數可能直接傳入選項物件) */\n\toptions: IOptions,\n}\n\n/**\n * 創建 Workspaces 的核心前置檢查邏輯\n *\n * 處理參數正規化、尋找專案根目錄,並檢查:\n * - 是否已存在 Package\n * - 是否已存在(父層)Workspaces\n *\n * @param cwd - 工作目錄路徑;也可直接傳入 IOptions\n * @param options - 配置選項\n * @returns 前置檢查結果;`ok` 為 false 時不應繼續創建\n */\nexport function _precheckYarnWorkspaces(cwd?: string, options: IOptions = {}): IPrecheckResult\n{\n\t/** 處理第一個參數可能是選項物件的情況 */\n\tif (cwd && typeof cwd != 'string')\n\t{\n\t\toptions = cwd;\n\t\tcwd = options.cwd;\n\t}\n\n\t/** 預設使用當前工作目錄 */\n\tcwd ??= process.cwd();\n\n\t/** 尋找專案根目錄資訊 */\n\tconst rootData = findRootLazy({\n\t\tcwd,\n\t});\n\n\t/** 標準化路徑 */\n\tcwd = pathNormalize(rootData?.cwd ?? cwd);\n\n\t/** 取得 Package 根目錄與 Workspaces 路徑 */\n\tlet root: string = rootData?.pkg;\n\tlet ws: string = rootData?.ws;\n\n\t/** 實際要初始化的目標路徑:優先採用既有 package 根目錄,否則退回 cwd。 */\n\tlet targetPath = resolve(root || cwd);\n\n\t/** 除錯輸出 */\n\toptions.debug && console.debug({\n\t\ttargetPath,\n\t\tws,\n\t\toptions,\n\t});\n\n\t/**\n\t * 檢查是否已存在 Package\n\t */\n\tif (!options.ignoreExistsPackage && root)\n\t{\n\t\tconsole.error(`already have package at \"${root}\", or use ignoreExistsPackage for overwrite it`);\n\n\t\treturn { ok: false, targetPath, options };\n\t}\n\telse if (root)\n\t{\n\t\t/** 忽略已存在的 Package */\n\t\tconsole.warn(`ignore exists package \"${root}\"`);\n\t}\n\n\t/**\n\t * 檢查是否已存在 Workspaces\n\t */\n\tif (ws)\n\t{\n\t\t/** 檢查目標路徑是否與現有 Workspace 相同 */\n\t\tlet bool: boolean = !isSamePath(targetPath, ws);\n\n\t\tconsole.warn(`detect exists workspace \"${ws}\"`);\n\n\t\tif (bool)\n\t\t{\n\t\t\t/** 根據選項決定是否忽略父層 Workspaces */\n\t\t\tif (options.ignoreParentWorkspaces)\n\t\t\t{\n\t\t\t\tconsole.warn(`ignoreParentWorkspaces = true`);\n\t\t\t\tbool = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tconsole.error(`target path already is workspace`);\n\t\t\t}\n\t\t}\n\n\t\tif (bool)\n\t\t{\n\t\t\treturn { ok: false, targetPath, options };\n\t\t}\n\t}\n\n\treturn { ok: true, targetPath, options };\n}\n\n/**\n * 內部創建 Workspaces 實作函式\n *\n * 執行實際的 Workspaces 初始化工作,包含:\n * - 讀取並更新 Lerna 配置\n * - 創建或更新 package.json\n * - 複製靜態範本檔案\n * - 創建 packages 目錄\n *\n * @param targetPath - 目標路徑\n * @param options - 配置選項\n * @returns 是否成功\n */\nexport function _createYarnWorkspaces(targetPath: string, options: IOptions = {})\n{\n\tconsole.info(`create in target path \"${targetPath}\"`);\n\n\tlet pkg: IPackageJson;\n\n\tlet lerna: ILernaJson;\n\n\t/**\n\t * 嘗試讀取現有的 lerna.json 配置\n\t */\n\t{\n\t\tlet file = join(targetPath, 'lerna.json');\n\n\t\tif (existsSync(file))\n\t\t{\n\t\t\tlet json: ILernaJson = JSON.parse(readFileSync(file).toString());\n\n\t\t\t/**\n\t\t\t * 清理空的 packages 陣列\n\t\t\t */\n\t\t\tif (json.packages && !Object.keys(json.packages).length)\n\t\t\t{\n\t\t\t\tjson.packages = undefined;\n\t\t\t}\n\n\t\t\tlerna = json;\n\t\t}\n\t}\n\n\t/**\n\t * 預設 packages 目錄模式\n\t */\n\tlet packages = lerna && lerna.packages || [\n\t\t\"packages/*\",\n\t];\n\n\tlet file = join(targetPath, 'package.json');\n\n\t/**\n\t * 處理 package.json 不存在的情況\n\t */\n\tif (!existsSync(file))\n\t{\n\t\t/** 使用目錄名作為預設 Package 名稱 */\n\t\tlet name = basename(targetPath);\n\n\t\t/** 創建目標目錄(如果不存在) */\n\t\tif (!existsSync(targetPath))\n\t\t{\n\t\t\tmkdirSync(targetPath);\n\t\t}\n\n\t\t/** 合併預設配置與基本資訊 */\n\t\tpkg = Object.assign(getDefaultPackageJson(name), {\n\t\t\tname,\n\t\t\tworkspaces: packages,\n\t\t});\n\n\t\t/**\n\t\t * 執行自定義初始化回呼\n\t\t */\n\t\tif (options.initPackageJson)\n\t\t{\n\t\t\tlet ret = options.initPackageJson(pkg);\n\n\t\t\tif (ret)\n\t\t\t{\n\t\t\t\tpkg = ret;\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\t/**\n\t\t * 處理已存在的 package.json\n\t\t */\n\t\tlet json: IPackageJson = JSON.parse(readFileSync(file).toString());\n\n\t\tlet workspaces: ILernaJson['packages'];\n\n\t\t/**\n\t\t * 解析現有的 workspaces 配置\n\t\t */\n\t\tif (json.workspaces && Object.keys(json.workspaces).length)\n\t\t{\n\t\t\tworkspaces = json.workspaces;\n\n\t\t\t/**\n\t\t\t * 支援 nohoist 配置格式\n\t\t\t * @see https://yarnpkg.com/blog/2018/02/15/nohoist/\n\t\t\t */\n\t\t\t// @ts-ignore\n\t\t\tpackages = workspaces.packages || workspaces;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tworkspaces = packages;\n\t\t}\n\n\t\t/**\n\t\t * 更新 Package.json 內容\n\t\t */\n\t\tpkg = Object.assign(json, {\n\t\t\t\"private\": true,\n\t\t\t\"workspaces\": workspaces,\n\t\t});\n\n\t\t/**\n\t\t * 合併預設腳本與欄位\n\t\t */\n\t\tObject.entries(getDefaultPackageJson(json.name))\n\t\t\t.forEach(([field, value]) =>\n\t\t\t{\n\n\t\t\t\t/**\n\t\t\t\t * 特殊處理 scripts 欄位:合併而非覆蓋\n\t\t\t\t */\n\t\t\t\tif (field === 'scripts')\n\t\t\t\t{\n\t\t\t\t\tpkg.scripts ??= {};\n\t\t\t\t\tpkg.scripts = {\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\t...pkg.scripts,\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/** 使用空值合併運算子設置預設值 */\n\t\t\t\t\tpkg[field] ??= value\n\t\t\t\t}\n\n\t\t\t})\n\t\t;\n\n\t}\n\n\t/**\n\t * 寫入格式化後的 package.json\n\t */\n\tlet s = JSON.stringify(sortPackageJson(pkg), null, 2);\n\twriteFileSync(file, s);\n\n\tconsole.success(`create workspace package.json`);\n\n\t/**\n\t * 更新 Lerna 配置(如果存在且需要更新)\n\t */\n\tif (lerna && (packages != lerna.packages || lerna.npmClient !== 'yarn' || lerna['useWorkspaces'] !== true))\n\t{\n\t\tlet file = join(targetPath, 'lerna.json');\n\n\t\t/** 更新 Workspaces 模式 */\n\t\tlerna.packages = packages;\n\t\tlerna.npmClient ??= 'pnpm';\n\t\t// lerna['useWorkspaces'] = true;\n\n\t\tlet s = JSON.stringify(sortPackageJson(lerna), null, 2);\n\t\twriteFileSync(file, s);\n\n\t\tconsole.info(`update lerna.json`);\n\t}\n\n\t/**\n\t * 複製靜態範本檔案\n\t */\n\tconst file_map = getWsCopyStaticFiles();\n\n\t/**\n\t * 複製靜態範本檔案\n\t *\n\t * 此呼叫點 addStaticFiles 預設為 true,可用 noStaticFiles 關閉\n\t */\n\tif (_isAddStaticFilesOrReset(options, true))\n\t{\n\t\tcopyStaticFiles({\n\t\t\tcwd: targetPath,\n\t\t\tfile_map,\n\t\t});\n\t}\n\n\t/**\n\t * 根據 packages 模式創建目錄\n\t */\n\tcreateDirByPackages(targetPath, packages);\n\n\treturn true;\n}\n\n/**\n * 根據 packages 模式創建目錄\n *\n * 解析 packages 陣列中的目錄模式(如 \"packages/*\"),\n * 並創建對應的實體目錄。\n *\n * @param cwd - 當前工作目錄\n * @param packages - packages 模式陣列\n * @returns 是否有創建任何目錄\n */\nexport function createDirByPackages(cwd: string, packages: string[])\n{\n\treturn packages.some(function (value)\n\t{\n\t\tlet bool: boolean;\n\n\t\t/** 提取路徑的第一個部分(目錄名稱) */\n\t\tlet s = value.split(/[\\/\\\\]/)[0];\n\n\t\t/**\n\t\t * 只處理不包含 glob 模式的純目錄路徑\n\t\t */\n\t\tif (!/[!?\\*{}\\[\\]]/.test(s))\n\t\t{\n\t\t\tlet dir = join(cwd, s);\n\n\t\t\t/** 目錄不存在時創建 */\n\t\t\tif (!existsSync(dir))\n\t\t\t{\n\t\t\t\tmkdirSync(dir);\n\t\t\t}\n\n\t\t\treturn true;\n\t\t}\n\n\t\treturn bool;\n\t})\n}"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { IPackageJson } from '@ts-type/package-dts/package-json';
|
|
2
2
|
/**
|
|
3
3
|
* 取得新專案根目錄的預設 package.json 內容。
|
|
4
|
-
* Build the default root `package.json` content for a new project.
|
|
5
4
|
*
|
|
6
|
-
* @param name 套件名稱;未提供時保留 undefined 交由呼叫端補上。
|
|
7
|
-
* @returns 含預設 scripts 與依賴的 package.json 物件。
|
|
5
|
+
* @param name 套件名稱;未提供時保留 undefined 交由呼叫端補上。
|
|
6
|
+
* @returns 含預設 scripts 與依賴的 package.json 物件。
|
|
8
7
|
*/
|
|
9
8
|
export declare function getDefaultPackageJson(name?: string): IPackageJson;
|
|
10
9
|
/**
|
|
11
10
|
* 取得新專案根目錄的預設 tsconfig 內容。
|
|
12
|
-
* Build the default root `tsconfig` content for a new project.
|
|
13
11
|
*
|
|
14
|
-
* @returns 繼承 @bluelovers/tsconfig 的 tsconfig 物件。
|
|
12
|
+
* @returns 繼承 @bluelovers/tsconfig 的 tsconfig 物件。
|
|
13
|
+
* @deprecated
|
|
15
14
|
*/
|
|
16
15
|
export declare function getDefaultTsconfig(): {
|
|
17
16
|
extends: string;
|
package/lib/index.js
CHANGED
|
@@ -5,14 +5,14 @@ exports.getDefaultTsconfig = getDefaultTsconfig;
|
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const ws_root_scripts_1 = require("@yarn-tool/pkg-entry-util/lib/preset/scripts/ws-root-scripts");
|
|
7
7
|
const dummy_1 = require("@yarn-tool/pkg-entry-util/lib/preset/scripts/dummy");
|
|
8
|
+
// @ts-ignore
|
|
8
9
|
const package_demo_json_1 = require("./package.demo.json");
|
|
9
10
|
const package_json_1 = tslib_1.__importDefault(require("../package.json"));
|
|
10
11
|
/**
|
|
11
12
|
* 取得新專案根目錄的預設 package.json 內容。
|
|
12
|
-
* Build the default root `package.json` content for a new project.
|
|
13
13
|
*
|
|
14
|
-
* @param name 套件名稱;未提供時保留 undefined 交由呼叫端補上。
|
|
15
|
-
* @returns 含預設 scripts 與依賴的 package.json 物件。
|
|
14
|
+
* @param name 套件名稱;未提供時保留 undefined 交由呼叫端補上。
|
|
15
|
+
* @returns 含預設 scripts 與依賴的 package.json 物件。
|
|
16
16
|
*/
|
|
17
17
|
function getDefaultPackageJson(name) {
|
|
18
18
|
let json = {
|
|
@@ -23,8 +23,7 @@ function getDefaultPackageJson(name) {
|
|
|
23
23
|
"workspaces": [
|
|
24
24
|
"packages/*",
|
|
25
25
|
],
|
|
26
|
-
|
|
27
|
-
// Mark the origin by default so the project can later be recognized as created by yarn-tool.
|
|
26
|
+
/** 預設標記建立來源,方便日後辨識此專案由 yarn-tool 產生。 */
|
|
28
27
|
keywords: [
|
|
29
28
|
"create-by-yarn-tool",
|
|
30
29
|
],
|
|
@@ -34,39 +33,37 @@ function getDefaultPackageJson(name) {
|
|
|
34
33
|
peerDependencies: package_demo_json_1.peerDependencies,
|
|
35
34
|
// "resolutions": {},
|
|
36
35
|
};
|
|
37
|
-
|
|
38
|
-
// Override the template versions with this package's own dependency versions so the generated project matches the toolchain.
|
|
36
|
+
/** 以本套件自身的依賴版本覆寫範本版本,確保產生的專案與工具列版本一致。 */
|
|
39
37
|
for (const deps of ['dependencies', 'devDependencies', 'peerDependencies']) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
if (!json[deps]) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const keys = Object.keys(json[deps]);
|
|
42
|
+
/** 範本沒有該依賴欄位、或本套件也未宣告時略過,避免憑空新增空的依賴區塊。 */
|
|
43
43
|
if (!keys.length || !package_json_1.default[deps]) {
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
// Copy before mutating so we do not edit the imported template object (a shared instance in the module cache).
|
|
46
|
+
/** 複製一份再改寫,避免直接動到匯入的範本物件(其為模組快取中的共享實例)。 */
|
|
48
47
|
json[deps] = {
|
|
49
48
|
...json[deps],
|
|
50
49
|
};
|
|
51
50
|
keys
|
|
52
51
|
.forEach(function (key) {
|
|
53
|
-
|
|
54
|
-
// Only overwrite keys also declared by this package; keep template defaults for the rest.
|
|
52
|
+
/** 只覆寫本套件也宣告了的鍵,其餘保留範本預設版本。 */
|
|
55
53
|
if (package_json_1.default[deps][key]) {
|
|
56
54
|
json[deps][key] = package_json_1.default[deps][key];
|
|
57
55
|
}
|
|
58
56
|
});
|
|
59
57
|
}
|
|
60
|
-
|
|
61
|
-
// Fill in workspace-specific default scripts (existing scripts are not overwritten).
|
|
58
|
+
/** 補上 workspaces 專用的預設腳本(已存在的腳本不會被覆蓋)。 */
|
|
62
59
|
(0, dummy_1.fillDummyScripts)(json.scripts, 'workspaces');
|
|
63
60
|
return json;
|
|
64
61
|
}
|
|
65
62
|
/**
|
|
66
63
|
* 取得新專案根目錄的預設 tsconfig 內容。
|
|
67
|
-
* Build the default root `tsconfig` content for a new project.
|
|
68
64
|
*
|
|
69
|
-
* @returns 繼承 @bluelovers/tsconfig 的 tsconfig 物件。
|
|
65
|
+
* @returns 繼承 @bluelovers/tsconfig 的 tsconfig 物件。
|
|
66
|
+
* @deprecated
|
|
70
67
|
*/
|
|
71
68
|
function getDefaultTsconfig() {
|
|
72
69
|
return {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAaA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAaA,sDAyDC;AAQD,gDAKC;;AAlFD,kGAA2G;AAC3G,8EAAsF;AACtF,aAAa;AACb,2DAAsF;AACtF,2EAAmC;AAEnC;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,IAAa;IAElD,IAAI,IAAI,GAAiB;QACxB,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,OAAO;QAClB,SAAS,EAAE,IAAI;QACf,oCAAoC;QACpC,YAAY,EAAE;YACb,YAAY;SACZ;QACD,wCAAwC;QACxC,QAAQ,EAAE;YACT,qBAAqB;SACrB;QACD,SAAS,EAAE,IAAA,6CAA2B,GAAE;QACxC,YAAY,EAAZ,gCAAY;QACZ,eAAe,EAAf,mCAAe;QACf,gBAAgB,EAAhB,oCAAgB;QAChB,qBAAqB;KACd,CAAC;IAET,yCAAyC;IACzC,KAAK,MAAM,IAAI,IAAI,CAAC,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,CAAU,EACnF,CAAC;QACA,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EACf,CAAC;YACA,SAAS;QACV,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAErC,0CAA0C;QAC1C,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,sBAAI,CAAC,IAAI,CAAC,EAC/B,CAAC;YACA,SAAS;QACV,CAAC;QAED,2CAA2C;QAC3C,IAAI,CAAC,IAAI,CAAC,GAAG;YACZ,GAAG,IAAI,CAAC,IAAI,CAAC;SACb,CAAC;QAEF,IAAI;aACF,OAAO,CAAC,UAAU,GAAG;YAErB,+BAA+B;YAC/B,IAAI,sBAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EACnB,CAAC;gBACA,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,sBAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACnC,CAAC;QACF,CAAC,CAAC,CACF;IACF,CAAC;IAED,0CAA0C;IAC1C,IAAA,wBAAgB,EAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAE7C,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB;IAEjC,OAAO;QACN,OAAO,EAAE,uCAAuC;KAChD,CAAA;AACF,CAAC","sourcesContent":["import { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { defaultWorkspaceRootScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/ws-root-scripts';\nimport { fillDummyScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/dummy';\n// @ts-ignore\nimport { dependencies, devDependencies, peerDependencies } from './package.demo.json';\nimport _pkg from '../package.json';\n\n/**\n * 取得新專案根目錄的預設 package.json 內容。\n *\n * @param name 套件名稱;未提供時保留 undefined 交由呼叫端補上。\n * @returns 含預設 scripts 與依賴的 package.json 物件。\n */\nexport function getDefaultPackageJson(name?: string): IPackageJson\n{\n\tlet json: IPackageJson = {\n\t\t\"name\": name,\n\t\t\"version\": \"1.0.0\",\n\t\t\"private\": true,\n\t\t// \"packageManager\": \"yarn@1.22.19\",\n\t\t\"workspaces\": [\n\t\t\t\"packages/*\",\n\t\t],\n\t\t/** 預設標記建立來源,方便日後辨識此專案由 yarn-tool 產生。 */\n\t\tkeywords: [\n\t\t\t\"create-by-yarn-tool\",\n\t\t],\n\t\t\"scripts\": defaultWorkspaceRootScripts(),\n\t\tdependencies,\n\t\tdevDependencies,\n\t\tpeerDependencies,\n\t\t// \"resolutions\": {},\n\t} as any;\n\n\t/** 以本套件自身的依賴版本覆寫範本版本,確保產生的專案與工具列版本一致。 */\n\tfor (const deps of ['dependencies', 'devDependencies', 'peerDependencies'] as const)\n\t{\n\t\tif (!json[deps])\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tconst keys = Object.keys(json[deps]);\n\n\t\t/** 範本沒有該依賴欄位、或本套件也未宣告時略過,避免憑空新增空的依賴區塊。 */\n\t\tif (!keys.length || !_pkg[deps])\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\t/** 複製一份再改寫,避免直接動到匯入的範本物件(其為模組快取中的共享實例)。 */\n\t\tjson[deps] = {\n\t\t\t...json[deps],\n\t\t};\n\n\t\tkeys\n\t\t\t.forEach(function (key)\n\t\t\t{\n\t\t\t\t/** 只覆寫本套件也宣告了的鍵,其餘保留範本預設版本。 */\n\t\t\t\tif (_pkg[deps][key])\n\t\t\t\t{\n\t\t\t\t\tjson[deps][key] = _pkg[deps][key];\n\t\t\t\t}\n\t\t\t})\n\t\t;\n\t}\n\n\t/** 補上 workspaces 專用的預設腳本(已存在的腳本不會被覆蓋)。 */\n\tfillDummyScripts(json.scripts, 'workspaces');\n\n\treturn json;\n}\n\n/**\n * 取得新專案根目錄的預設 tsconfig 內容。\n *\n * @returns 繼承 @bluelovers/tsconfig 的 tsconfig 物件。\n * @deprecated\n */\nexport function getDefaultTsconfig()\n{\n\treturn {\n\t\textends: \"@bluelovers/tsconfig/esm/mapfile.json\",\n\t}\n}\n"]}
|
package/lib/package.demo.json
CHANGED
package/lib/util.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Check whether two paths point to the same location (marked `@deprecated`; use `path-is-same` instead).
|
|
2
|
+
* 判斷兩個路徑是否為同一位置
|
|
4
3
|
*
|
|
5
|
-
* @param p1 第一個路徑。
|
|
6
|
-
* @param p2 第二個路徑。
|
|
7
|
-
* @returns 兩路徑相同時為 true;任一為空則直接 false
|
|
4
|
+
* @param p1 第一個路徑。
|
|
5
|
+
* @param p2 第二個路徑。
|
|
6
|
+
* @returns 兩路徑相同時為 true;任一為空則直接 false。
|
|
8
7
|
*/
|
|
9
8
|
export declare function isSamePath(p1: string, p2: string): boolean;
|
package/lib/util.js
CHANGED
|
@@ -4,24 +4,25 @@ exports.isSamePath = isSamePath;
|
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const path_is_same_1 = require("path-is-same");
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* Check whether two paths point to the same location (marked `@deprecated`; use `path-is-same` instead).
|
|
7
|
+
* 判斷兩個路徑是否為同一位置
|
|
9
8
|
*
|
|
10
|
-
* @param p1 第一個路徑。
|
|
11
|
-
* @param p2 第二個路徑。
|
|
12
|
-
* @returns 兩路徑相同時為 true;任一為空則直接 false
|
|
9
|
+
* @param p1 第一個路徑。
|
|
10
|
+
* @param p2 第二個路徑。
|
|
11
|
+
* @returns 兩路徑相同時為 true;任一為空則直接 false。
|
|
13
12
|
*/
|
|
14
13
|
function isSamePath(p1, p2) {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/**
|
|
15
|
+
* 任一輸入為空時無法比較,直接回傳 false 以免 relative() 產生誤判。
|
|
16
|
+
*/
|
|
17
17
|
if (!p1 || !p2) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
else if ((0, path_is_same_1.pathIsSame)(p1, p2)) {
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* 字面不相同時再以 relative 判斷,涵蓋結尾斜線或 '.' 等等價寫法。
|
|
25
|
+
*/
|
|
25
26
|
let s = (0, path_1.relative)(p1, p2);
|
|
26
27
|
return (s === '.' || s === '');
|
|
27
28
|
}
|
package/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["util.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["util.ts"],"names":[],"mappings":";;AAUA,gCAmBC;AA7BD,+BAAgC;AAChC,+CAA0C;AAE1C;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,EAAU,EAAE,EAAU;IAEhD;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,EACd,CAAC;QACA,OAAO,KAAK,CAAC;IACd,CAAC;SACI,IAAI,IAAA,yBAAU,EAAC,EAAE,EAAE,EAAE,CAAC,EAC3B,CAAC;QACA,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,GAAG,IAAA,eAAQ,EAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACzB,OAAO,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { relative } from \"path\";\nimport { pathIsSame } from 'path-is-same';\n\n/**\n * 判斷兩個路徑是否為同一位置\n *\n * @param p1 第一個路徑。\n * @param p2 第二個路徑。\n * @returns 兩路徑相同時為 true;任一為空則直接 false。\n */\nexport function isSamePath(p1: string, p2: string)\n{\n\t/**\n\t * 任一輸入為空時無法比較,直接回傳 false 以免 relative() 產生誤判。\n\t */\n\tif (!p1 || !p2)\n\t{\n\t\treturn false;\n\t}\n\telse if (pathIsSame(p1, p2))\n\t{\n\t\treturn true;\n\t}\n\n\t/**\n\t * 字面不相同時再以 relative 判斷,涵蓋結尾斜線或 '.' 等等價寫法。\n\t */\n\tlet s = relative(p1, p2);\n\treturn (s === '.' || s === '');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-yarn-workspaces",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"description": "Quickly initialize
|
|
3
|
+
"version": "3.0.37",
|
|
4
|
+
"description": "Quickly initialize a Workspaces project structure compatible with both Yarn and pnpm And Lerna",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"create",
|
|
7
7
|
"yarn-workspaces",
|
|
8
8
|
"cli",
|
|
9
9
|
"init",
|
|
10
|
+
"lerna",
|
|
11
|
+
"monorepo",
|
|
10
12
|
"npm",
|
|
13
|
+
"pnpm",
|
|
11
14
|
"workspace",
|
|
12
15
|
"workspaces",
|
|
13
16
|
"ws",
|
|
@@ -46,6 +49,7 @@
|
|
|
46
49
|
"test:node:bin:coverage": "node --run test:node:bin -- --experimental-test-coverage --",
|
|
47
50
|
"test:snapshot": "pnpm run test -u",
|
|
48
51
|
"test:tsc": "tsc --noEmit & echo typescript check done",
|
|
52
|
+
"test:tsc:all": "node --run test:tsc && node --run test:tsc:sub",
|
|
49
53
|
"test:tsc:sub": "cd test && tsc --noEmit & echo Type checking completed (test)",
|
|
50
54
|
"test:tsd": "ynpx tsd",
|
|
51
55
|
"npm:publish": "npm publish",
|
|
@@ -60,16 +64,18 @@
|
|
|
60
64
|
},
|
|
61
65
|
"dependencies": {
|
|
62
66
|
"@bluelovers/tsconfig": "^2.0.3",
|
|
67
|
+
"@clack/prompts": "^1.8.1",
|
|
63
68
|
"@ts-type/package-dts": "^3.0.14",
|
|
64
69
|
"@types/jest": "^30.0.0",
|
|
65
70
|
"@types/node": "^26.6.5",
|
|
66
71
|
"@yarn-tool/find-root": "^2.0.29",
|
|
67
|
-
"@yarn-tool/fix-all": "^3.0.
|
|
68
|
-
"@yarn-tool/pkg-entry-util": "^3.0.
|
|
72
|
+
"@yarn-tool/fix-all": "^3.0.31",
|
|
73
|
+
"@yarn-tool/pkg-entry-util": "^3.0.26",
|
|
69
74
|
"@yarn-tool/require-resolve": "^4.0.16",
|
|
70
|
-
"@yarn-tool/static-file": "^3.0.
|
|
75
|
+
"@yarn-tool/static-file": "^3.0.31",
|
|
71
76
|
"@yarn-tool/ws-find-up-paths": "^1.0.27",
|
|
72
77
|
"debug-color2": "^1.3.2",
|
|
78
|
+
"fast-glob": "^3.3.3",
|
|
73
79
|
"find-yarn-workspace-root2": "^1.2.59",
|
|
74
80
|
"fs-extra": "^11.4.1",
|
|
75
81
|
"path-is-same": "^1.0.29",
|
|
@@ -84,5 +90,5 @@
|
|
|
84
90
|
"@yarn-tool/ncu": "^3.0.19",
|
|
85
91
|
"@yarn-tool/write-package-json": "^1.0.22"
|
|
86
92
|
},
|
|
87
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "491c2429f96718eca2e628c00a8cd0cf5ade31c2"
|
|
88
94
|
}
|
package/yargs-setting.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Yargs 命令列參數設定模組
|
|
3
|
-
* Yargs Command Line Arguments Configuration Module
|
|
4
3
|
*
|
|
5
4
|
* 提供 Workspaces 初始化相關的命令列參數設定與驗證
|
|
6
|
-
* Provides command line argument configuration and validation for
|
|
7
|
-
* workspace initialization
|
|
8
5
|
*
|
|
9
6
|
* @author user
|
|
10
7
|
* @since 2019/5/16
|
|
@@ -13,19 +10,13 @@ import yargs from 'yargs';
|
|
|
13
10
|
import { Argv } from 'yargs';
|
|
14
11
|
/**
|
|
15
12
|
* 設定 Workspaces 初始化相關的 Yargs 選項
|
|
16
|
-
* Setup Yargs options for workspaces initialization
|
|
17
13
|
*
|
|
18
14
|
* 配置命令列參數,包含:
|
|
19
15
|
* - name: Package 名稱
|
|
20
16
|
* - ignoreExistsPackage: 忽略已存在的 Package
|
|
21
17
|
* - ignoreParentWorkspaces: 忽略父層 Workspaces
|
|
22
18
|
* - debug: 啟用除錯模式
|
|
23
|
-
*
|
|
24
|
-
* Configures command line arguments including:
|
|
25
|
-
* - name: Package name
|
|
26
|
-
* - ignoreExistsPackage: Ignore existing package
|
|
27
|
-
* - ignoreParentWorkspaces: Ignore parent workspaces
|
|
28
|
-
* - debug: Enable debug mode
|
|
19
|
+
* - interactive: 啟用互動介面
|
|
29
20
|
*
|
|
30
21
|
* @template T - Yargs 參數類型 / Yargs argument type
|
|
31
22
|
* @param yargs - Yargs 實例 / Yargs instance
|
|
@@ -51,6 +42,8 @@ export declare function setupWorkspacesInitToYargs<T extends any>(yargs: Argv<T>
|
|
|
51
42
|
ignoreParentWorkspaces: boolean;
|
|
52
43
|
} & {
|
|
53
44
|
debug: boolean;
|
|
45
|
+
} & {
|
|
46
|
+
interactive: boolean;
|
|
54
47
|
}>;
|
|
55
48
|
/**
|
|
56
49
|
* 預設導出設定函式
|