npm-init2 3.0.22 → 3.0.23

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 CHANGED
@@ -3,6 +3,59 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.0.23](https://github.com/bluelovers/ws-yarn-workspaces/compare/npm-init2@3.0.22...npm-init2@3.0.23) (2026-10-12)
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * **fix-all:** 引入共用靜態檔案控制邏輯並優化多套件支援
12
+
13
+
14
+
15
+ ### 🐛 Bug Fixes
16
+
17
+ * **npm-init2:** 暫時停用 Workspaces 專案的 node_modules 連結功能 ([c559749](https://github.com/bluelovers/ws-yarn-workspaces/commit/c559749a9c8e67dc59f2823a2db2d441390ea780))
18
+
19
+
20
+ ### ✨ Features
21
+
22
+ * **fix-all:** 引入共用靜態檔案控制邏輯並優化多套件支援 ([e447590](https://github.com/bluelovers/ws-yarn-workspaces/commit/e447590f2dfd34a83f028db773a2f4c60e30dec2))
23
+
24
+
25
+ ### 📦 Code Refactoring
26
+
27
+ * **core:** 統一靜態檔案控制邏輯並更新 package.json 腳本規範 ([12f5a56](https://github.com/bluelovers/ws-yarn-workspaces/commit/12f5a5623a6f19e33616a326c86a094c548a0436))
28
+
29
+
30
+ ### 📚 Documentation
31
+
32
+ * add jsdoc ([9cb9b13](https://github.com/bluelovers/ws-yarn-workspaces/commit/9cb9b13eda8c357221ad1b754458aa9916eada22))
33
+
34
+
35
+ ### 🚨 Tests
36
+
37
+ * **test:** 將測試框架從 jest 遷移至 node:test ([3af9774](https://github.com/bluelovers/ws-yarn-workspaces/commit/3af9774964abc48083ec60b2021c1cec08874803))
38
+
39
+
40
+ ### 🛠 Build System
41
+
42
+ * update build ([3186340](https://github.com/bluelovers/ws-yarn-workspaces/commit/3186340758172427cb1e9b8955f6fd677abac625))
43
+ * **deps:** 更新測試腳本與依賴以支援 node:test ([f9c71c7](https://github.com/bluelovers/ws-yarn-workspaces/commit/f9c71c795c792c5c7ed9d613ce7e9c3c726c39d5))
44
+
45
+
46
+ ### ♻️ Chores
47
+
48
+ * **deps:** 更新依賴版本並清理 npm-init2 腳本 ([82bf1e5](https://github.com/bluelovers/ws-yarn-workspaces/commit/82bf1e5d229759aa285205d81cf0651e4d3d9792))
49
+ * **deps:** 更新各套件依賴版本 ([569f075](https://github.com/bluelovers/ws-yarn-workspaces/commit/569f0756189cdadf69955d8e388ac0a6a8988056))
50
+ * **workspace:** 更新測試指令路徑與新增工作區搜尋選項 ([a80039d](https://github.com/bluelovers/ws-yarn-workspaces/commit/a80039dd8c691e047466966ffc8f8a4e2e31c03f))
51
+
52
+
53
+ ### 🔖 Miscellaneous
54
+
55
+ * . ([e5788f8](https://github.com/bluelovers/ws-yarn-workspaces/commit/e5788f84551b870490a96d0a5d67d8d542481373))
56
+
57
+
58
+
6
59
  ## [3.0.22](https://github.com/bluelovers/ws-yarn-workspaces/compare/npm-init2@3.0.21...npm-init2@3.0.22) (2026-09-10)
7
60
 
8
61
  **Note:** Version bump only for package npm-init2
package/README.md CHANGED
@@ -8,7 +8,17 @@
8
8
 
9
9
  `npm-init2` simplifies the process of creating new Node.js packages, allowing you to run `npx npm-init2 xxx` instead of `mkdir xxx && cd xxx && npm init`.
10
10
 
11
- ## 安裝與使用 / Installation & Usage
11
+ ## Features / 功能特性
12
+
13
+ - ⚡ **一鍵初始化** - 簡化 `mkdir && cd && npm init` 流程
14
+ - 🏢 **Workspaces 支援** - 自動偵測並整合 Monorepo 環境
15
+ - 📝 **智能設定** - 自動填充 repository、bugs、homepage 等欄位
16
+ - 🔧 **腳本範本** - 提供常見的 npm scripts 預設值
17
+ - 📦 **依賴管理** - 自動添加 tslib 等常用依賴
18
+ - 🧪 **Jest 整合** - 偵測到 Jest 時自動設定測試腳本
19
+ - 📚 **README 生成** - 自動生成基礎 README.md
20
+
21
+ ## Installation / 安裝
12
22
 
13
23
  ```bash
14
24
  # 快速初始化新套件 / Quickly initialize a new package
@@ -21,30 +31,7 @@ npx npm-init2 my-package --npmClient yarn
21
31
  npx npm-init2 --cwd ./my-project
22
32
  ```
23
33
 
24
- ## 命令列選項 / CLI Options
25
-
26
- | 選項 / Option | 說明 / Description |
27
- |--------------|-------------------|
28
- | `--npmClient` | 指定套件管理器 (`yarn`, `npm`, `pnpm`) / Specify package manager |
29
- | `--cwd` | 設定工作目錄 / Set working directory |
30
- | `--name` | 指定套件名稱 / Specify package name |
31
- | `--skipCheckWorkspace` | 跳過 Workspaces 檢查 / Skip workspace detection |
32
- | `--sort` | 對 package.json 進行排序 / Sort package.json |
33
- | `--yes` / `-y` | 使用預設值 / Use default values |
34
- | `--tsdx` | 啟用 TSDX 設定 / Enable TSDX configuration |
35
- | `--private` / `-p` | 設定為私有套件 / Set as private package |
36
-
37
- ## 功能特性 / Features
38
-
39
- - ⚡ **一鍵初始化** - 簡化 `mkdir && cd && npm init` 流程
40
- - 🏢 **Workspaces 支援** - 自動偵測並整合 Monorepo 環境
41
- - 📝 **智能設定** - 自動填充 repository、bugs、homepage 等欄位
42
- - 🔧 **腳本範本** - 提供常見的 npm scripts 預設值
43
- - 📦 **依賴管理** - 自動添加 tslib 等常用依賴
44
- - 🧪 **Jest 整合** - 偵測到 Jest 時自動設定測試腳本
45
- - 📚 **README 生成** - 自動生成基礎 README.md
46
-
47
- ## 使用範例 / Examples
34
+ ## Usage / 使用方式
48
35
 
49
36
  ### 基本使用 / Basic Usage
50
37
 
@@ -74,7 +61,75 @@ npx npm-init2 my-package --skipCheckWorkspace
74
61
  npx npm-init2 my-ts-lib --tsdx
75
62
  ```
76
63
 
77
- ## 對應指令 / Command Mapping
64
+ ## API Documentation / API 文件
65
+
66
+ ### `initWithPreserveDeps(options)`
67
+
68
+ 執行 npm/yarn 初始化指令,並在完成後把舊 `package.json` 的依賴項 (Dependencies) 還原回去。
69
+ Runs the npm/yarn init command and restores the dependencies from the old `package.json` afterwards.
70
+
71
+ ```typescript
72
+ import { initWithPreserveDeps } from 'npm-init2/lib/initWithPreserveDeps';
73
+
74
+ const { cp } = initWithPreserveDeps({
75
+ npmClient: 'npm',
76
+ cwd: '/path/to/target',
77
+ args: ['init', '-y'],
78
+ old_pkg, // 舊 package.json 內容 / previous package.json
79
+ pkg_file_path: '/path/to/target/package.json',
80
+ });
81
+ ```
82
+
83
+ **Parameters / 參數:**
84
+
85
+ | 參數 / Parameter | 說明 / Description |
86
+ | --- | --- |
87
+ | `npmClient` | 執行的套件管理器,例如 `npm`、`yarn` / Package manager to run |
88
+ | `cwd` | 執行目錄 / Working directory of the child process |
89
+ | `args` | 傳給套件管理器的參數,例如 `['init', '-y']` / Arguments passed to the package manager |
90
+ | `old_pkg` | 初始化前的 package.json,用於還原依賴 / The previous package.json, used to restore dependencies |
91
+ | `pkg_file_path` | 目標 package.json 路徑 / Path of the target package.json |
92
+
93
+ **Returns / 回傳:**
94
+
95
+ - `{ cp }` - 子行程 (Child Process) 的執行結果;`cp.error` 存在代表初始化失敗 / The child process result; a truthy `cp.error` means initialization failed
96
+
97
+ > 子行程以 `stdio: inherit` 執行並強制關閉顏色輸出(`FORCE_COLOR=0`、`NO_COLOR=1`),避免終端控制碼干擾後續輸出。
98
+ > The child process runs with `stdio: inherit` and colors disabled (`FORCE_COLOR=0`, `NO_COLOR=1`) so escape sequences do not corrupt later output.
99
+
100
+ ### `setupToYargs(yargs)`
101
+
102
+ 註冊 `npm-init2` 的命令列選項,並繼承 `@yarn-tool/fix-all` 的共用選項 (Shared Options)。
103
+ Registers the CLI options of `npm-init2` and inherits the shared options from `@yarn-tool/fix-all`.
104
+
105
+ ```typescript
106
+ import yargs from 'yargs';
107
+ import { setupToYargs } from 'npm-init2/lib/yargs-setting';
108
+
109
+ const cli = setupToYargs(yargs);
110
+ const argv = cli.argv;
111
+ ```
112
+
113
+ ## Configuration / 設定
114
+
115
+ ### CLI Options / 命令列選項
116
+
117
+ | 選項 / Option | 說明 / Description |
118
+ |--------------|-------------------|
119
+ | `--npmClient` | 指定套件管理器 (`yarn`, `npm`, `pnpm`) / Specify package manager |
120
+ | `--cwd` | 設定工作目錄 / Set working directory |
121
+ | `--name` | 指定套件名稱 / Specify package name |
122
+ | `--skipCheckWorkspace` | 跳過 Workspaces 檢查 / Skip workspace detection |
123
+ | `--sort` | 對 package.json 進行排序 / Sort package.json |
124
+ | `--yes` / `-y` | 使用預設值 / Use default values |
125
+ | `--tsdx` | 啟用 TSDX 設定 / Enable TSDX configuration |
126
+ | `--private` / `-p` | 設定為私有套件 / Set as private package |
127
+ | `--createModule` / `-m` | 傳給 `npm init` 的模組建立參數 / Module creation flag forwarded to `npm init` |
128
+
129
+ > `--cwd` 只在 `defaultDescription` 顯示 `process.cwd()`,未實際傳入時由主流程以 `cli.argv.cwd || process.cwd()` 決定,因此可以區分「使用者明確指定」與「使用預設值」。
130
+ > `--cwd` only shows `process.cwd()` as its `defaultDescription`; when it is not passed, the main flow decides via `cli.argv.cwd || process.cwd()`, which distinguishes an explicit path from the default.
131
+
132
+ ## Command Mapping / 對應指令
78
133
 
79
134
  | npm-init2 指令 | 等效指令 |
80
135
  |---------------|---------|
@@ -82,7 +137,7 @@ npx npm-init2 my-ts-lib --tsdx
82
137
  | `npx npm-init2 --npmClient yarn` | `yarn init` |
83
138
  | `npx npm-init2 my-pkg` | `mkdir my-pkg && cd my-pkg && npm init` |
84
139
 
85
- ## 預設腳本 / Default Scripts
140
+ ## Default Scripts / 預設腳本
86
141
 
87
142
  初始化後的 package.json 會包含以下腳本:
88
143
 
@@ -98,7 +153,7 @@ The initialized package.json will include these scripts:
98
153
  }
99
154
  ```
100
155
 
101
- ## 相關專案 / Related Projects
156
+ ## Related Projects / 相關專案
102
157
 
103
158
  - [create-yarn-workspaces](https://www.npmjs.com/package/create-yarn-workspaces) - 初始化 Workspaces 根專案 / Initialize workspace root project
104
159
  - [find-pkg-ws](https://www.npmjs.com/package/find-pkg-ws) - 尋找 Workspace Package / Find workspace packages
package/bin/npm-init2.js CHANGED
@@ -1,5 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ /**
5
+ * CLI 入口:僅載入主模組以執行初始化流程,
6
+ * 實際邏輯全部在 index.ts,此檔對應 package.json 的 bin 欄位
7
+ *
8
+ * CLI entry: only loads the main module to run the init flow; all logic lives in index.ts and
9
+ * this file is what the package.json `bin` field points at
10
+ */
4
11
  require("..");
5
12
  //# sourceMappingURL=npm-init2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"npm-init2.js","sourceRoot":"","sources":["npm-init2.ts"],"names":[],"mappings":";;;AAEA,cAAY","sourcesContent":["#!/usr/bin/env node\n\nimport '..';\n\n\n"]}
1
+ {"version":3,"file":"npm-init2.js","sourceRoot":"","sources":["npm-init2.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AACH,cAAY","sourcesContent":["#!/usr/bin/env node\n\n/**\n * CLI 入口:僅載入主模組以執行初始化流程,\n * 實際邏輯全部在 index.ts,此檔對應 package.json 的 bin 欄位\n *\n * CLI entry: only loads the main module to run the init flow; all logic lives in index.ts and\n * this file is what the package.json `bin` field points at\n */\nimport '..';\n\n\n"]}
package/index.js CHANGED
@@ -48,7 +48,10 @@ const pkg_scripts_1 = require("@yarn-tool/pkg-entry-util/lib/preset/scripts/pkg-
48
48
  const write_package_json_1 = require("@yarn-tool/write-package-json");
49
49
  const getRootCopyStaticFiles_1 = require("@yarn-tool/static-file/lib/root/getRootCopyStaticFiles");
50
50
  const scripts_1 = require("@yarn-tool/pkg-entry-util/lib/field/scripts");
51
- // 更新通知器(已停用)/ Update notifier (disabled)
51
+ const staticFiles_1 = require("@yarn-tool/fix-all/lib/file/staticFiles");
52
+ /**
53
+ * 更新通知器(已停用)/ Update notifier (disabled)
54
+ */
52
55
  //updateNotifier(__dirname);
53
56
  /**
54
57
  * 避免 IDE 緩衝區問題的權宜之計
@@ -65,7 +68,9 @@ let cli = (0, yargs_setting_1.setupToYargs)(yargs_1.default);
65
68
  * Get command line positional arguments
66
69
  */
67
70
  let argv = cli.argv._;
68
- // 除錯輸出(已停用)/ Debug output (disabled)
71
+ /**
72
+ * 除錯輸出(已停用)/ Debug output (disabled)
73
+ */
69
74
  //console.dir(cli.argv);
70
75
  /**
71
76
  * 解析工作目錄
@@ -101,7 +106,9 @@ let wsProject;
101
106
  */
102
107
  if (rootData === null || rootData === void 0 ? void 0 : rootData.hasWorkspace) {
103
108
  workspacesConfig = (0, workspaces_config_1.parseStaticPackagesPaths)((0, workspaces_config_1.getConfig)(rootData.ws));
104
- // 取得第一個前綴作為預設前綴 / Get first prefix as default prefix
109
+ /**
110
+ * 取得第一個前綴作為預設前綴 / Take the first prefix as the default prefix
111
+ */
105
112
  if (workspacesConfig.prefix.length) {
106
113
  workspacePrefix = workspacesConfig.prefix[0];
107
114
  }
@@ -131,10 +138,16 @@ let { targetDir, targetName, scopedPackagePattern } = (0, init_path_1.getTargetD
131
138
  */
132
139
  let flags = Object.keys(cli.argv)
133
140
  .reduce(function (a, f) {
134
- // 跳過特定選項 / Skip specific options
141
+ /**
142
+ * 跳過特定選項:這些選項不參與 npm init 的旗標組字
143
+ * Skip specific options: these are not folded into the npm init flag string
144
+ */
135
145
  if (f === 'silent' || f === 'y' || f === 'yes') {
136
146
  }
137
- // 收集單字母標誌 / Collect single-letter flags
147
+ /**
148
+ * 收集單字母標誌:只有單一小寫字母且值為真時才加入
149
+ * Collect single-letter flags: only a single lowercase letter with a truthy value is added
150
+ */
138
151
  else if (/^[a-z]$/.test(f) && cli.argv[f]) {
139
152
  a.push(f);
140
153
  }
@@ -151,7 +164,9 @@ let args = [
151
164
  cli.argv.createModule,
152
165
  cli.argv.yes && '-y',
153
166
  ].filter(v => v);
154
- // 輸出命令參數(已停用)/ Output command arguments (disabled)
167
+ /**
168
+ * 輸出命令參數(已停用)/ Output command arguments (disabled)
169
+ */
155
170
  //console.log(args);
156
171
  /**
157
172
  * Package.json 檔案路徑
@@ -212,7 +227,13 @@ else if (!targetName) {
212
227
  old_pkg_name = old_pkg.name;
213
228
  }
214
229
  catch (e) {
215
- // 忽略讀取錯誤 / Ignore read errors
230
+ /**
231
+ * 讀取失敗時忽略(例如檔案不存在或 JSON 無效),
232
+ * 讓後續流程改以全新 package.json 處理
233
+ *
234
+ * Ignore read failures (e.g. missing file or invalid JSON) so the rest of the flow
235
+ * treats the target as a brand-new package.json
236
+ */
216
237
  }
217
238
  }
218
239
  /**
@@ -334,8 +355,10 @@ if (!cp.error) {
334
355
  * Merge corresponding script templates based on project type
335
356
  */
336
357
  if (rootData.hasWorkspace) {
337
- // Workspaces 專案不添加額外根腳本
338
- // Workspace projects don't add extra root scripts
358
+ /**
359
+ * Workspaces 專案不添加額外根腳本:根專案的腳本由 workspaces 設定管理
360
+ * Workspace projects get no extra root scripts: root scripts are managed by the workspace setup
361
+ */
339
362
  }
340
363
  else if (rootData.isRoot) {
341
364
  sharedScript = {
@@ -347,7 +370,7 @@ if (!cp.error) {
347
370
  * 組合 Pre-version 腳本
348
371
  * Compose pre-version scripts
349
372
  */
350
- preScripts.push("yarn run test" /* EnumScriptsEntry.preversion */);
373
+ preScripts.push("pnpm run test" /* EnumScriptsEntry.preversion */);
351
374
  sharedScript.preversion = preScripts.join(' && ');
352
375
  /**
353
376
  * 初始化 scripts 欄位(如果不存在)
@@ -453,7 +476,10 @@ if (!cp.error) {
453
476
  var _a, _b, _c;
454
477
  return ((_a = cpkg.dependencies) === null || _a === void 0 ? void 0 : _a[name]) || ((_b = cpkg.devDependencies) === null || _b === void 0 ? void 0 : _b[name]) || ((_c = cpkg.peerDependencies) === null || _c === void 0 ? void 0 : _c[name]) || "*";
455
478
  };
456
- // 初始化依賴項欄位 / Initialize dependency fields
479
+ /**
480
+ * 初始化依賴項欄位:沿用既有內容,缺漏時才建立空物件
481
+ * Initialize dependency fields: keep existing entries and only create empty objects when missing
482
+ */
457
483
  pkg.data.dependencies = pkg.data.dependencies || {};
458
484
  pkg.data.devDependencies = pkg.data.devDependencies || {};
459
485
  pkg.data.peerDependencies = pkg.data.peerDependencies || {};
@@ -465,7 +491,10 @@ if (!cp.error) {
465
491
  pkg.data.devDependencies['@bluelovers/tsconfig'] = findVersion('@bluelovers/tsconfig');
466
492
  pkg.data.devDependencies['@types/node'] = findVersion('@types/node');
467
493
  }
468
- // 添加 tslib 作為執行時依賴 / Add tslib as runtime dependency
494
+ /**
495
+ * 添加 tslib 作為執行時依賴:多數工具鏈會假設 tslib 存在
496
+ * Add tslib as a runtime dependency: most toolchains assume tslib is present
497
+ */
469
498
  pkg.data.dependencies['tslib'] = findVersion('tslib');
470
499
  }
471
500
  /**
@@ -551,11 +580,16 @@ if (!cp.error) {
551
580
  /**
552
581
  * 複製靜態範本檔案
553
582
  * Copy static template files
583
+ *
584
+ * 此呼叫點 addStaticFiles 預設為 true,可用 --noStaticFiles 關閉
585
+ * addStaticFiles defaults to true at this call site; disable it with --noStaticFiles
554
586
  */
555
- (0, static_file_1.copyStaticFiles)({
556
- cwd: targetDir,
557
- file_map,
558
- });
587
+ if ((0, staticFiles_1._isAddStaticFilesWithReset)(cli.argv, true)) {
588
+ (0, static_file_1.copyStaticFiles)({
589
+ cwd: targetDir,
590
+ file_map,
591
+ });
592
+ }
559
593
  /**
560
594
  * 生成 README.md(如果需要)
561
595
  * Generate README.md if needed
@@ -569,8 +603,14 @@ if (!cp.error) {
569
603
  /**
570
604
  * 將 Package 連結到 node_modules(Workspaces 專案)
571
605
  * Link package to node_modules (for workspace projects)
606
+ *
607
+ * 注意:條件以 `false &&` 開頭,永遠不會成立,此區塊目前已完全停用,
608
+ * 程式碼保留以便日後恢復
609
+ *
610
+ * Note: the guard starts with `false &&` and never holds, so this block is fully
611
+ * disabled; the code is kept for a possible re-enable later
572
612
  */
573
- if (wsProject && !rootData.isWorkspace) {
613
+ if (false && wsProject && !rootData.isWorkspace) {
574
614
  (0, node_modules_link_1.linkToNodeModules)({
575
615
  cwd: targetDir,
576
616
  sourcePackagePath: targetDir,
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;GAeG;;;;;AAEH,0DAA0B;AAC1B,uCAAyD;AACzD,mCAAwD;AACxD,yDAAwE;AACxE,qEAA4D;AAE5D,uDAAmD;AACnD,oDAAgD;AAChD,2BAAgC;AAChC,2EAAwE;AACxE,yEAAmE;AACnE,sEAAkE;AAClE,+CAA0C;AAC1C,oEAAiE;AACjE,oDAAoD;AACpD,+BAAgC;AAChC,oEAA+D;AAC/D,qEAAkE;AAGlE,wDAAyD;AACzD,gDAA+D;AAC/D,mFAAgF;AAChF,gEAA+D;AAC/D,6EAAuF;AACvF,8EAAsF;AACtF,4FAA+F;AAC/F,0FAAkG;AAClG,sEAAsE;AACtE,mGAAoG;AACpG,yEAA8G;AAE9G,yCAAyC;AACzC,4BAA4B;AAE5B;;;GAGG;AACH,sBAAO,CAAC,MAAM,CAAC;AAEf;;;GAGG;AACH,IAAI,GAAG,GAAG,IAAA,4BAAY,EAAC,eAAK,CAAC,CAAC;AAE9B;;;GAGG;AACH,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAEtB,qCAAqC;AACrC,wBAAwB;AAExB;;;GAGG;AACH,IAAI,GAAG,GAAG,IAAA,gBAAO,EAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAEjD;;;GAGG;AACH,IAAI,QAAQ,GAAG,IAAA,oBAAQ,EAAC;IACvB,GAAG;IACH,kBAAkB,EAAE,GAAG,CAAC,IAAI,CAAC,kBAAkB;CAC/C,CAAC,CAAC;AAEH;;;GAGG;AACH,IAAI,eAAuB,CAAC;AAE5B;;;GAGG;AACH,IAAI,gBAA6D,CAAA;AAEjE;;;GAGG;AACH,IAAI,SAA4B,CAAC;AAEjC;;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,CAAC;QACZ,CAAC;QAED;;;WAGG;QACH,GAAG,CAAC,mBAAmB,EAAE,CAAC;QAE1B;;;WAGG;QACH,IAAA,6BAAe,EAAC;YACf,GAAG,EAAE,SAAS;YACd,QAAQ;SACR,CAAC,CAAA;QAEF;;;WAGG;QACH,IAAI,YAAY,EAChB,CAAC;YACA,IAAA,yBAAW,EAAC;gBACX,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,GAAG,CAAC,IAAI;aAClB,CAAC,CAAA;QACH,CAAC;QAED;;;WAGG;QACH,IAAI,SAAS,IAAI,CAAC,QAAQ,CAAC,WAAW,EACtC,CAAC;YACA,IAAA,qCAAiB,EAAC;gBACjB,GAAG,EAAE,SAAS;gBACd,iBAAiB,EAAE,SAAS;gBAC5B,SAAS,EAAE,IAAI;aACf,CAAC,CAAA;QACH,CAAC;IAEF,CAAC;AACF,CAAC;KAED,CAAC;IACA;;;OAGG;IACH,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACtB,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,SAAS,CAAC,GAAiB,EAAE,IAAY;;IAEjD,GAAG,aAAH,GAAG,cAAH,GAAG,IAAH,GAAG,GAAK,EAAE,EAAC;IACX,OAAO,MAAA,MAAA,GAAG,CAAC,YAAY,0CAAG,IAAI,CAAC,mCAAI,MAAA,GAAG,CAAC,eAAe,0CAAG,IAAI,CAAC,CAAA;AAC/D,CAAC","sourcesContent":["#!/usr/bin/env node\n\n/**\n * NPM/Yarn 專案初始化 CLI 工具\n * NPM/Yarn Project Initialization CLI Tool\n *\n * 提供互動式命令列介面來初始化新的 Node.js 專案,支援:\n * - 一般專案與 Monorepo Workspaces 專案\n * - 自動設定 package.json 欄位與腳本\n * - 整合 TypeScript、Jest、TSDX 等開發工具\n * - 自動生成 README.md 與配置檔案\n *\n * Provides interactive CLI for initializing new Node.js projects, supporting:\n * - Regular projects and Monorepo Workspaces projects\n * - Automatic package.json field and script configuration\n * - Integration with TypeScript, Jest, TSDX and other dev tools\n * - Auto-generation of README.md and configuration files\n */\n\nimport yargs from 'yargs';\nimport { ensureDirSync, pathExistsSync } from 'fs-extra';\nimport { join, parse, relative, resolve } from 'upath2';\nimport { getConfig, parseStaticPackagesPaths } from 'workspaces-config';\nimport { PackageJsonLoader } from 'npm-package-json-loader';\nimport { IPackageJson } from '@ts-type/package-dts';\nimport { setupToYargs } from './lib/yargs-setting';\nimport { findRoot } from '@yarn-tool/find-root';\nimport { existsSync } from 'fs';\nimport { writeReadme } from '@yarn-tool/pkg-readme-tpl/lib/writeReadme';\nimport { sortPackageJsonScripts } from 'sort-package-json-scripts';\nimport { WorkspacesProject } from '@yarn-tool/workspaces-project';\nimport { pathIsSame } from 'path-is-same';\nimport { linkToNodeModules } from '@yarn-tool/node-modules-link';\nimport { getTargetDir } from '@yarn-tool/init-path';\nimport { basename } from 'path';\nimport { isBuiltinModule } from '@yarn-tool/is-builtin-module';\nimport { initWithPreserveDeps } from './lib/initWithPreserveDeps';\nimport { IStaticFilesMapArray } from '@yarn-tool/static-file/lib/types';\nimport { defaultCopyStaticFiles, defaultCopyStaticFilesRootOnly } from '@yarn-tool/static-file/lib/const';\nimport { copyStaticFiles } from '@yarn-tool/static-file';\nimport { consoleLogger as console } from 'debug-color2/logger';\nimport { nameExistsInWorkspaces } from 'ws-pkg-list/lib/nameExistsInWorkspaces';\nimport { fillPkgHostedInfo } from '@yarn-tool/pkg-hosted-info';\nimport { setup as setupTsdx } from '@yarn-tool/setup-module-env/lib/preset/tsdx/index';\nimport { fillDummyScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/dummy';\nimport { defaultRootScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/root-scripts';\nimport { defaultPkgNotOldExists } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/pkg-scripts';\nimport { outputPackageJSONSync } from '@yarn-tool/write-package-json';\nimport { getRootCopyStaticFilesAuto } from '@yarn-tool/static-file/lib/root/getRootCopyStaticFiles';\nimport { EnumScriptsEntry, scriptsEntryIsNoTestSpecified } from '@yarn-tool/pkg-entry-util/lib/field/scripts';\n\n// 更新通知器(已停用)/ Update notifier (disabled)\n//updateNotifier(__dirname);\n\n/**\n * 避免 IDE 緩衝區問題的權宜之計\n * Workaround to avoid IDE buffer issues\n */\nconsole.length;\n\n/**\n * 設定 Yargs CLI 實例\n * Setup Yargs CLI instance\n */\nlet cli = setupToYargs(yargs);\n\n/**\n * 取得命令列位置參數\n * Get command line positional arguments\n */\nlet argv = cli.argv._;\n\n// 除錯輸出(已停用)/ Debug output (disabled)\n//console.dir(cli.argv);\n\n/**\n * 解析工作目錄\n * Resolve working directory\n */\nlet cwd = resolve(cli.argv.cwd || process.cwd());\n\n/**\n * 尋找專案根目錄資訊\n * Find project root information\n */\nlet rootData = findRoot({\n\tcwd,\n\tskipCheckWorkspace: cli.argv.skipCheckWorkspace,\n});\n\n/**\n * Workspaces 前綴路徑\n * Workspace prefix path\n */\nlet workspacePrefix: string;\n\n/**\n * Workspaces 配置物件\n * Workspaces configuration object\n */\nlet workspacesConfig: ReturnType<typeof parseStaticPackagesPaths>\n\n/**\n * Workspaces 專案實例\n * Workspaces project instance\n */\nlet wsProject: WorkspacesProject;\n\n/**\n * 如果有 Workspaces,解析配置並建立專案實例\n * If workspaces exist, parse configuration and create project instance\n */\nif (rootData?.hasWorkspace)\n{\n\tworkspacesConfig = parseStaticPackagesPaths(getConfig(rootData.ws));\n\n\t// 取得第一個前綴作為預設前綴 / Get first prefix as default prefix\n\tif (workspacesConfig.prefix.length)\n\t{\n\t\tworkspacePrefix = workspacesConfig.prefix[0];\n\t}\n\n\twsProject = new WorkspacesProject(rootData.ws)\n}\n\n/**\n * 取得目標目錄與名稱資訊\n * Get target directory and name information\n */\nlet { targetDir, targetName, scopedPackagePattern } = getTargetDir({\n\t// @ts-ignore\n\tinputName: argv.length && argv[0],\n\tcwd,\n\ttargetName: cli.argv.name || null,\n\thasWorkspace: rootData?.ws,\n\tworkspacePrefix,\n\tworkspacesConfig,\n});\n\n/**\n * 確保目標目錄存在\n * Ensure target directory exists\n */\nensureDirSync(targetDir);\n\n/**\n * 收集命令列標誌參數(單字母選項)\n * Collect command line flag arguments (single-letter options)\n */\nlet flags = Object.keys(cli.argv)\n\t.reduce(function (a, f)\n\t{\n\t\t// 跳過特定選項 / Skip specific options\n\t\tif (f === 'silent' || f === 'y' || f === 'yes')\n\t\t{\n\n\t\t}\n\t\t// 收集單字母標誌 / Collect single-letter flags\n\t\telse if (/^[a-z]$/.test(f) && cli.argv[f])\n\t\t{\n\t\t\ta.push(f);\n\t\t}\n\n\t\treturn a;\n\t}, [])\n\t.join('')\n;\n\n/**\n * 建構 npm init 命令參數\n * Build npm init command arguments\n */\nlet args = [\n\t'init',\n\t(flags && '-' + flags),\n\tcli.argv.createModule,\n\tcli.argv.yes && '-y',\n].filter(v => v);\n\n// 輸出命令參數(已停用)/ Output command arguments (disabled)\n//console.log(args);\n\n/**\n * Package.json 檔案路徑\n * Package.json file path\n */\nconst pkg_file_path = join(targetDir, 'package.json');\n\n/**\n * 舊 Package 名稱(用於保留原名稱)\n * Old package name (for preserving original name)\n */\nlet old_pkg_name: string;\n\n/**\n * 標記 Package.json 是否已存在\n * Flag indicating if package.json already exists\n */\nconst oldExists = existsSync(pkg_file_path);\n\n/**\n * 舊 Package.json 內容\n * Old package.json content\n */\nlet old_pkg: IPackageJson;\n\n/**\n * 驗證:已存在的 Package 不能指定新名稱\n * Validation: Existing packages cannot specify a new name\n */\nif (oldExists && targetName?.length)\n{\n\tconsole.error(`對於已存在的 Package 而言,禁止同時指定名稱`, targetName);\n\tconsole.error(pkg_file_path);\n\tprocess.exit(1);\n}\n\n/**\n * 驗證:檢查名稱是否已在 Workspaces 中存在\n * Validation: Check if name already exists in workspaces\n */\nif (!oldExists && rootData?.hasWorkspace)\n{\n\tif (nameExistsInWorkspaces(targetName))\n\t{\n\t\tconsole.error(`root:`, rootData.root)\n\t\tconsole.error(`目標名稱已存在於 Workspaces 內,請更換名稱:`, targetName);\n\t\tprocess.exit(1);\n\t}\n}\n\n/**\n * 處理內建模組名稱的特殊情況\n * Handle special case for builtin module names\n */\nif (!oldExists && targetName && scopedPackagePattern && isBuiltinModule(basename(targetDir)))\n{\n\toutputPackageJSONSync(pkg_file_path, {\n\t\tname: targetName,\n\t})\n}\nelse if (!targetName)\n{\n\t/**\n\t * 嘗試讀取現有的 package.json\n\t * Try to read existing package.json\n\t */\n\ttry\n\t{\n\t\told_pkg = new PackageJsonLoader(pkg_file_path)?.data;\n\n\t\told_pkg_name = old_pkg.name\n\t}\n\tcatch (e)\n\t{\n\t\t// 忽略讀取錯誤 / Ignore read errors\n\t}\n}\n\n/**\n * 執行初始化並保留現有依賴項\n * Execute initialization while preserving existing dependencies\n */\nlet { cp } = initWithPreserveDeps({\n\tnpmClient: cli.argv.npmClient,\n\targs,\n\tcwd: targetDir,\n\told_pkg,\n\tpkg_file_path,\n});\n\n/**\n * 如果初始化成功,繼續後續設定\n * If initialization succeeded, continue with further configuration\n */\nif (!cp.error)\n{\n\t/**\n\t * 重新尋找根目錄(因為可能已建立新結構)\n\t * Re-find root directory (as new structure may have been created)\n\t */\n\trootData = findRoot({\n\t\tcwd: targetDir,\n\t\tskipCheckWorkspace: cli.argv.skipCheckWorkspace,\n\t});\n\n\t/**\n\t * 驗證根目錄是否正確\n\t * Validate root directory\n\t */\n\tif (!rootData?.root)\n\t{\n\t\tconsole.error(`發生錯誤,初始化失敗`, targetName);\n\t\tconsole.error(targetDir);\n\t\tprocess.exit(1);\n\t}\n\n\t/**\n\t * 載入 package.json\n\t * Load package.json\n\t */\n\tlet pkg = new PackageJsonLoader(pkg_file_path);\n\n\t/**\n\t * 如果 package.json 存在,進行詳細設定\n\t * If package.json exists, perform detailed configuration\n\t */\n\tif (pkg.exists())\n\t{\n\t\t/**\n\t\t * 設定 private 標誌(非 yarn 時)\n\t\t * Set private flag (when not using yarn)\n\t\t */\n\t\tif (cli.argv['p'] && cli.argv.npmClient !== 'yarn')\n\t\t{\n\t\t\tpkg.data.private = true;\n\t\t}\n\n\t\t/**\n\t\t * 防止 node- 前綴被 npm 移除的處理\n\t\t * Handle preservation of node- prefix that npm might remove\n\t\t */\n\t\tif (!cli.argv.yes && old_pkg_name && /^node-/.test(old_pkg_name) && ('node-' + pkg.data.name) === old_pkg_name)\n\t\t{\n\t\t\tpkg.data.name = old_pkg_name;\n\t\t}\n\t\telse if (cli.argv.yes && old_pkg_name && pkg.data.name !== old_pkg_name)\n\t\t{\n\t\t\tpkg.data.name = old_pkg_name;\n\t\t}\n\t\telse if (targetName && pkg.data.name !== targetName)\n\t\t{\n\t\t\tpkg.data.name = targetName;\n\t\t}\n\n\t\t/**\n\t\t * 檢查 Scoped Package 的發布配置\n\t\t * Check publish configuration for scoped packages\n\t\t */\n\t\tif (pkg.data.name && /^@/.test(pkg.data.name) && !pkg.data.publishConfig)\n\t\t{\n\t\t\t//pkg.data.publishConfig = {};\n\t\t}\n\n\t\t/**\n\t\t * 初始化 scripts 欄位\n\t\t * Initialize scripts field\n\t\t */\n\t\tif (!pkg.data.scripts)\n\t\t{\n\t\t\tpkg.data.scripts = {};\n\t\t}\n\n\t\t/**\n\t\t * 填充 Package 託管資訊(repository、bugs、homepage 等)\n\t\t * Fill package hosting info (repository, bugs, homepage, etc.)\n\t\t */\n\t\tfillPkgHostedInfo(pkg.data, {\n\t\t\ttargetDir,\n\t\t\trootData,\n\t\t});\n\n\t\t/**\n\t\t * 設定 Package Manager(預設 Yarn)\n\t\t * Set Package Manager (default to Yarn)\n\t\t */\n\t\t// pkg.data.packageManager ??= \"yarn@1.22.19\";\n\n\t\t/**\n\t\t * 共享腳本範本\n\t\t * Shared script templates\n\t\t */\n\t\tlet sharedScript: IPackageJson['scripts'] = {\n\t\t\t\"test\": `echo \"Error: no test specified\"`,\n\t\t};\n\n\t\t/**\n\t\t * 填充虛擬佔位腳本\n\t\t * Fill dummy placeholder scripts\n\t\t */\n\t\tfillDummyScripts(sharedScript);\n\n\t\t/**\n\t\t * Pre-version 腳本序列\n\t\t * Pre-version script sequence\n\t\t */\n\t\tlet preScripts: string[] = [\"echo preversion\"];\n\n\t\t/**\n\t\t * 設定 Root 專用的 prepublishOnly 腳本\n\t\t * Set prepublishOnly script for root projects\n\t\t */\n\t\tif (rootData.isRoot && !rootData.isWorkspace)\n\t\t{\n\t\t\tsharedScript.prepublishOnly = \"yarn run preversion\"\n\t\t}\n\n\t\t/**\n\t\t * 根據專案類型合併對應的腳本範本\n\t\t * Merge corresponding script templates based on project type\n\t\t */\n\t\tif (rootData.hasWorkspace)\n\t\t{\n\t\t\t// Workspaces 專案不添加額外根腳本\n\t\t\t// Workspace projects don't add extra root scripts\n\t\t}\n\t\telse if (rootData.isRoot)\n\t\t{\n\t\t\tsharedScript = {\n\t\t\t\t...sharedScript,\n\t\t\t\t...defaultRootScripts(),\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * 組合 Pre-version 腳本\n\t\t * Compose pre-version scripts\n\t\t */\n\t\tpreScripts.push(EnumScriptsEntry.preversion);\n\t\tsharedScript.preversion = preScripts.join(' && ')\n\n\t\t/**\n\t\t * 初始化 scripts 欄位(如果不存在)\n\t\t * Initialize scripts field if not exists\n\t\t */\n\t\tpkg.data.scripts ??= {};\n\n\t\t/**\n\t\t * 處理新建立的 Package 腳本\n\t\t * Handle scripts for newly created packages\n\t\t */\n\t\tif (!oldExists)\n\t\t{\n\t\t\t/**\n\t\t\t * 如果現有腳本是預設的無測試提示,且我們有測試腳本,則刪除舊的\n\t\t\t * If existing script is default no-test message and we have a test script, remove old one\n\t\t\t */\n\t\t\tif (scriptsEntryIsNoTestSpecified(pkg.data.scripts?.test) && sharedScript.test?.length > 0)\n\t\t\t{\n\t\t\t\tdelete pkg.data.scripts!.test\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * 如果根專案使用 Jest,設定對應的測試腳本\n\t\t\t * If root project uses Jest, set corresponding test script\n\t\t\t */\n\t\t\tif (_findDeps(wsProject?.manifest, '@types/jest') || _findDeps(wsProject?.manifest, 'jest') || _findDeps(wsProject?.manifest, 'ts-jest'))\n\t\t\t{\n\t\t\t\tsharedScript.test = EnumScriptsEntry.JEST_TEST;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * 合併預設腳本到新 Package\n\t\t\t * Merge default scripts to new package\n\t\t\t */\n\t\t\tObject\n\t\t\t\t.entries({\n\t\t\t\t\t...defaultPkgNotOldExists(),\n\t\t\t\t\t...sharedScript,\n\t\t\t\t})\n\t\t\t\t.forEach(([k, v]) =>\n\t\t\t\t{\n\t\t\t\t\tpkg.data.scripts[k] ??= v;\n\t\t\t\t})\n\t\t\t;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/**\n\t\t\t * 處理已存在的 Package 腳本\n\t\t\t * Handle scripts for existing packages\n\t\t\t */\n\t\t\tObject\n\t\t\t\t.entries(sharedScript)\n\t\t\t\t.forEach(([k, v]) =>\n\t\t\t\t{\n\t\t\t\t\t/**\n\t\t\t\t\t * 跳過尾隨底線標記的重複腳本\n\t\t\t\t\t * Skip duplicate scripts marked with trailing underscores\n\t\t\t\t\t */\n\t\t\t\t\tif (k.endsWith('_') && pkg.data.scripts[k.replace(/_+$/, '')] === v)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tpkg.data.scripts[k] ??= v;\n\t\t\t\t})\n\t\t\t;\n\n\t\t\t/**\n\t\t\t * 處理 TypeScript 型別定義路徑\n\t\t\t * Handle TypeScript type definitions path\n\t\t\t */\n\t\t\tif (!pkg.data.types || !pkg.data.typings)\n\t\t\t{\n\t\t\t\tpkg.data.types = pkg.data.types || pkg.data.typings;\n\n\t\t\t\t/**\n\t\t\t\t * 自動偵測型別定義檔案位置\n\t\t\t\t * Auto-detect type definition file location\n\t\t\t\t */\n\t\t\t\tif (pkg.data.main && !pkg.data.types)\n\t\t\t\t{\n\t\t\t\t\tlet file = join(targetDir, pkg.data.main)\n\t\t\t\t\tlet parsed = parse(file);\n\n\t\t\t\t\tif (!pathIsSame(targetDir, parsed.dir) && pathExistsSync(join(parsed.dir, parsed.name + '.d.ts')))\n\t\t\t\t\t{\n\t\t\t\t\t\tpkg.data.types = relative(targetDir, parsed.dir).replace(/^\\.\\//, '') + '/' + parsed.name + '.d.ts'\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tpkg.data.typings = pkg.data.types;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * 保留舊 Package.json 中未被覆蓋的欄位\n\t\t\t * Preserve fields from old package.json that weren't overwritten\n\t\t\t */\n\t\t\tif (old_pkg)\n\t\t\t{\n\t\t\t\tObject.keys(old_pkg)\n\t\t\t\t\t.forEach(key =>\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!(key in pkg.data))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpkg.data[key] = old_pkg[key];\n\t\t\t\t\t\t}\n\n\t\t\t\t\t})\n\t\t\t\t;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * 為新 Package 添加預設依賴項\n\t\t * Add default dependencies for new packages\n\t\t */\n\t\tif (!oldExists)\n\t\t{\n\t\t\tconst cpkg = require('./package.json') as IPackageJson;\n\n\t\t\t/**\n\t\t\t * 尋找依賴項版本的輔助函式\n\t\t\t * Helper function to find dependency version\n\t\t\t */\n\t\t\tconst findVersion = (name: string) =>\n\t\t\t{\n\t\t\t\treturn cpkg.dependencies?.[name] || cpkg.devDependencies?.[name] || cpkg.peerDependencies?.[name] || \"*\"\n\t\t\t};\n\n\t\t\t// 初始化依賴項欄位 / Initialize dependency fields\n\t\t\tpkg.data.dependencies = pkg.data.dependencies || {};\n\t\t\tpkg.data.devDependencies = pkg.data.devDependencies || {};\n\t\t\tpkg.data.peerDependencies = pkg.data.peerDependencies || {};\n\n\t\t\t/**\n\t\t\t * 為 Root 專案添加開發依賴項\n\t\t\t * Add dev dependencies for root projects\n\t\t\t */\n\t\t\tif (rootData.isRoot)\n\t\t\t{\n\t\t\t\tpkg.data.devDependencies['@bluelovers/tsconfig'] = findVersion('@bluelovers/tsconfig');\n\t\t\t\tpkg.data.devDependencies['@types/node'] = findVersion('@types/node');\n\t\t\t}\n\n\t\t\t// 添加 tslib 作為執行時依賴 / Add tslib as runtime dependency\n\t\t\tpkg.data.dependencies['tslib'] = findVersion('tslib');\n\t\t}\n\n\t\t/**\n\t\t * 繼承 Root 專案的關鍵字\n\t\t * Inherit keywords from root project\n\t\t */\n\t\tif (wsProject && !rootData.isWorkspace)\n\t\t{\n\t\t\tconst rootKeywords = wsProject.manifest.toJSON().keywords;\n\n\t\t\tif (!pkg.data.keywords?.length && rootKeywords?.length)\n\t\t\t{\n\t\t\t\tpkg.data.keywords = rootKeywords.slice()\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * 添加工具標記關鍵字\n\t\t * Add tool marker keyword\n\t\t */\n\t\tpkg.data.keywords ??= [];\n\t\tpkg.data.keywords.push('create-by-yarn-tool');\n\n\t\t/**\n\t\t * 取得要複製的靜態檔案映射\n\t\t * Get static file mappings to copy\n\t\t */\n\t\tlet file_map = getRootCopyStaticFilesAuto({\n\t\t\thasWorkspace: !!wsProject,\n\t\t\tisRoot: !wsProject,\n\t\t});\n\n\t\t/**\n\t\t * README.md 檔案路徑\n\t\t * README.md file path\n\t\t */\n\t\tconst mdFile = join(targetDir, 'README.md');\n\n\t\t/**\n\t\t * 判斷是否需要生成 README\n\t\t * Determine if README needs to be generated\n\t\t */\n\t\tlet existsReadme = !oldExists || !existsSync(mdFile);\n\n\t\t/**\n\t\t * 如果啟用 TSDX,執行 TSDX 設定\n\t\t * If TSDX is enabled, execute TSDX setup\n\t\t */\n\t\tif (cli.argv.tsdx)\n\t\t{\n\t\t\t({\n\t\t\t\tfile_map,\n\t\t\t\texistsReadme,\n\t\t\t} = setupTsdx({\n\t\t\t\ttargetDir,\n\t\t\t\trootData,\n\t\t\t\tpkg: pkg.data,\n\t\t\t\tfile_map,\n\t\t\t\tmdFile,\n\t\t\t\texistsReadme,\n\t\t\t\toldExists,\n\t\t\t}));\n\t\t}\n\n\t\t/**\n\t\t * 排序 package.json 中的腳本\n\t\t * Sort scripts in package.json\n\t\t */\n\t\tpkg.data.scripts = sortPackageJsonScripts(pkg.data.scripts);\n\n\t\t/**\n\t\t * 設定 sideEffects 為 false(優化 Tree Shaking)\n\t\t * Set sideEffects to false (optimize Tree Shaking)\n\t\t * @see https://juejin.cn/post/6844903640533041159\n\t\t */\n\t\tpkg.data.sideEffects ??= false;\n\n\t\t/**\n\t\t * 自動修復 package.json 常見問題\n\t\t * Auto-fix common package.json issues\n\t\t */\n\t\tpkg.autofix();\n\n\t\t/**\n\t\t * 如果需要,對 package.json 進行排序\n\t\t * Sort package.json if requested\n\t\t */\n\t\tif (cli.argv.sort)\n\t\t{\n\t\t\tpkg.sort();\n\t\t}\n\n\t\t/**\n\t\t * 只在有載入資料時寫入檔案\n\t\t * Only write file when data was loaded\n\t\t */\n\t\tpkg.writeOnlyWhenLoaded();\n\n\t\t/**\n\t\t * 複製靜態範本檔案\n\t\t * Copy static template files\n\t\t */\n\t\tcopyStaticFiles({\n\t\t\tcwd: targetDir,\n\t\t\tfile_map,\n\t\t})\n\n\t\t/**\n\t\t * 生成 README.md(如果需要)\n\t\t * Generate README.md if needed\n\t\t */\n\t\tif (existsReadme)\n\t\t{\n\t\t\twriteReadme({\n\t\t\t\tfile: mdFile,\n\t\t\t\tvariable: pkg.data,\n\t\t\t})\n\t\t}\n\n\t\t/**\n\t\t * 將 Package 連結到 node_modules(Workspaces 專案)\n\t\t * Link package to node_modules (for workspace projects)\n\t\t */\n\t\tif (wsProject && !rootData.isWorkspace)\n\t\t{\n\t\t\tlinkToNodeModules({\n\t\t\t\tcwd: targetDir,\n\t\t\t\tsourcePackagePath: targetDir,\n\t\t\t\toverwrite: true,\n\t\t\t})\n\t\t}\n\n\t}\n}\nelse\n{\n\t/**\n\t * 初始化失敗,設定錯誤退出碼\n\t * Initialization failed, set error exit code\n\t */\n\tprocess.exitCode = 1;\n}\n\n/**\n * 在 Package 中尋找指定依賴項\n * Find specified dependency in package\n *\n * @param pkg - Package.json 物件 / Package.json object\n * @param name - 依賴項名稱 / Dependency name\n * @returns 是否找到 / Whether found\n */\nfunction _findDeps(pkg: IPackageJson, name: string)\n{\n\tpkg ??= {};\n\treturn pkg.dependencies?.[name] ?? pkg.devDependencies?.[name]\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;GAeG;;;;;AAEH,0DAA0B;AAC1B,uCAAyD;AACzD,mCAAwD;AACxD,yDAAwE;AACxE,qEAA4D;AAE5D,uDAAmD;AACnD,oDAAgD;AAChD,2BAAgC;AAChC,2EAAwE;AACxE,yEAAmE;AACnE,sEAAkE;AAClE,+CAA0C;AAC1C,oEAAiE;AACjE,oDAAoD;AACpD,+BAAgC;AAChC,oEAA+D;AAC/D,qEAAkE;AAGlE,wDAAyD;AACzD,gDAA+D;AAC/D,mFAAgF;AAChF,gEAA+D;AAC/D,6EAAuF;AACvF,8EAAsF;AACtF,4FAA+F;AAC/F,0FAAkG;AAClG,sEAAsE;AACtE,mGAAoG;AACpG,yEAA8G;AAC9G,yEAAqF;AAErF;;GAEG;AACH,4BAA4B;AAE5B;;;GAGG;AACH,sBAAO,CAAC,MAAM,CAAC;AAEf;;;GAGG;AACH,IAAI,GAAG,GAAG,IAAA,4BAAY,EAAC,eAAK,CAAC,CAAC;AAE9B;;;GAGG;AACH,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAEtB;;GAEG;AACH,wBAAwB;AAExB;;;GAGG;AACH,IAAI,GAAG,GAAG,IAAA,gBAAO,EAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAEjD;;;GAGG;AACH,IAAI,QAAQ,GAAG,IAAA,oBAAQ,EAAC;IACvB,GAAG;IACH,kBAAkB,EAAE,G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ialization CLI Tool\n *\n * 提供互動式命令列介面來初始化新的 Node.js 專案,支援:\n * - 一般專案與 Monorepo Workspaces 專案\n * - 自動設定 package.json 欄位與腳本\n * - 整合 TypeScript、Jest、TSDX 等開發工具\n * - 自動生成 README.md 與配置檔案\n *\n * Provides interactive CLI for initializing new Node.js projects, supporting:\n * - Regular projects and Monorepo Workspaces projects\n * - Automatic package.json field and script configuration\n * - Integration with TypeScript, Jest, TSDX and other dev tools\n * - Auto-generation of README.md and configuration files\n */\n\nimport yargs from 'yargs';\nimport { ensureDirSync, pathExistsSync } from 'fs-extra';\nimport { join, parse, relative, resolve } from 'upath2';\nimport { getConfig, parseStaticPackagesPaths } from 'workspaces-config';\nimport { PackageJsonLoader } from 'npm-package-json-loader';\nimport { IPackageJson } from '@ts-type/package-dts';\nimport { setupToYargs } from './lib/yargs-setting';\nimport { findRoot } from '@yarn-tool/find-root';\nimport { existsSync } from 'fs';\nimport { writeReadme } from '@yarn-tool/pkg-readme-tpl/lib/writeReadme';\nimport { sortPackageJsonScripts } from 'sort-package-json-scripts';\nimport { WorkspacesProject } from '@yarn-tool/workspaces-project';\nimport { pathIsSame } from 'path-is-same';\nimport { linkToNodeModules } from '@yarn-tool/node-modules-link';\nimport { getTargetDir } from '@yarn-tool/init-path';\nimport { basename } from 'path';\nimport { isBuiltinModule } from '@yarn-tool/is-builtin-module';\nimport { initWithPreserveDeps } from './lib/initWithPreserveDeps';\nimport { IStaticFilesMapArray } from '@yarn-tool/static-file/lib/types';\nimport { defaultCopyStaticFiles, defaultCopyStaticFilesRootOnly } from '@yarn-tool/static-file/lib/const';\nimport { copyStaticFiles } from '@yarn-tool/static-file';\nimport { consoleLogger as console } from 'debug-color2/logger';\nimport { nameExistsInWorkspaces } from 'ws-pkg-list/lib/nameExistsInWorkspaces';\nimport { fillPkgHostedInfo } from '@yarn-tool/pkg-hosted-info';\nimport { setup as setupTsdx } from '@yarn-tool/setup-module-env/lib/preset/tsdx/index';\nimport { fillDummyScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/dummy';\nimport { defaultRootScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/root-scripts';\nimport { defaultPkgNotOldExists } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/pkg-scripts';\nimport { outputPackageJSONSync } from '@yarn-tool/write-package-json';\nimport { getRootCopyStaticFilesAuto } from '@yarn-tool/static-file/lib/root/getRootCopyStaticFiles';\nimport { EnumScriptsEntry, scriptsEntryIsNoTestSpecified } from '@yarn-tool/pkg-entry-util/lib/field/scripts';\nimport { _isAddStaticFilesWithReset } from '@yarn-tool/fix-all/lib/file/staticFiles';\n\n/**\n * 更新通知器(已停用)/ Update notifier (disabled)\n */\n//updateNotifier(__dirname);\n\n/**\n * 避免 IDE 緩衝區問題的權宜之計\n * Workaround to avoid IDE buffer issues\n */\nconsole.length;\n\n/**\n * 設定 Yargs CLI 實例\n * Setup Yargs CLI instance\n */\nlet cli = setupToYargs(yargs);\n\n/**\n * 取得命令列位置參數\n * Get command line positional arguments\n */\nlet argv = cli.argv._;\n\n/**\n * 除錯輸出(已停用)/ Debug output (disabled)\n */\n//console.dir(cli.argv);\n\n/**\n * 解析工作目錄\n * Resolve working directory\n */\nlet cwd = resolve(cli.argv.cwd || process.cwd());\n\n/**\n * 尋找專案根目錄資訊\n * Find project root information\n */\nlet rootData = findRoot({\n\tcwd,\n\tskipCheckWorkspace: cli.argv.skipCheckWorkspace,\n});\n\n/**\n * Workspaces 前綴路徑\n * Workspace prefix path\n */\nlet workspacePrefix: string;\n\n/**\n * Workspaces 配置物件\n * Workspaces configuration object\n */\nlet workspacesConfig: ReturnType<typeof parseStaticPackagesPaths>\n\n/**\n * Workspaces 專案實例\n * Workspaces project instance\n */\nlet wsProject: WorkspacesProject;\n\n/**\n * 如果有 Workspaces,解析配置並建立專案實例\n * If workspaces exist, parse configuration and create project instance\n */\nif (rootData?.hasWorkspace)\n{\n\tworkspacesConfig = parseStaticPackagesPaths(getConfig(rootData.ws));\n\n\t/**\n\t * 取得第一個前綴作為預設前綴 / Take the first prefix as the default prefix\n\t */\n\tif (workspacesConfig.prefix.length)\n\t{\n\t\tworkspacePrefix = workspacesConfig.prefix[0];\n\t}\n\n\twsProject = new WorkspacesProject(rootData.ws)\n}\n\n/**\n * 取得目標目錄與名稱資訊\n * Get target directory and name information\n */\nlet { targetDir, targetName, scopedPackagePattern } = getTargetDir({\n\t// @ts-ignore\n\tinputName: argv.length && argv[0],\n\tcwd,\n\ttargetName: cli.argv.name || null,\n\thasWorkspace: rootData?.ws,\n\tworkspacePrefix,\n\tworkspacesConfig,\n});\n\n/**\n * 確保目標目錄存在\n * Ensure target directory exists\n */\nensureDirSync(targetDir);\n\n/**\n * 收集命令列標誌參數(單字母選項)\n * Collect command line flag arguments (single-letter options)\n */\nlet flags = Object.keys(cli.argv)\n\t.reduce(function (a, f)\n\t{\n\t\t/**\n\t\t * 跳過特定選項:這些選項不參與 npm init 的旗標組字\n\t\t * Skip specific options: these are not folded into the npm init flag string\n\t\t */\n\t\tif (f === 'silent' || f === 'y' || f === 'yes')\n\t\t{\n\n\t\t}\n\t\t/**\n\t\t * 收集單字母標誌:只有單一小寫字母且值為真時才加入\n\t\t * Collect single-letter flags: only a single lowercase letter with a truthy value is added\n\t\t */\n\t\telse if (/^[a-z]$/.test(f) && cli.argv[f])\n\t\t{\n\t\t\ta.push(f);\n\t\t}\n\n\t\treturn a;\n\t}, [])\n\t.join('')\n;\n\n/**\n * 建構 npm init 命令參數\n * Build npm init command arguments\n */\nlet args = [\n\t'init',\n\t(flags && '-' + flags),\n\tcli.argv.createModule,\n\tcli.argv.yes && '-y',\n].filter(v => v);\n\n/**\n * 輸出命令參數(已停用)/ Output command arguments (disabled)\n */\n//console.log(args);\n\n/**\n * Package.json 檔案路徑\n * Package.json file path\n */\nconst pkg_file_path = join(targetDir, 'package.json');\n\n/**\n * 舊 Package 名稱(用於保留原名稱)\n * Old package name (for preserving original name)\n */\nlet old_pkg_name: string;\n\n/**\n * 標記 Package.json 是否已存在\n * Flag indicating if package.json already exists\n */\nconst oldExists = existsSync(pkg_file_path);\n\n/**\n * 舊 Package.json 內容\n * Old package.json content\n */\nlet old_pkg: IPackageJson;\n\n/**\n * 驗證:已存在的 Package 不能指定新名稱\n * Validation: Existing packages cannot specify a new name\n */\nif (oldExists && targetName?.length)\n{\n\tconsole.error(`對於已存在的 Package 而言,禁止同時指定名稱`, targetName);\n\tconsole.error(pkg_file_path);\n\tprocess.exit(1);\n}\n\n/**\n * 驗證:檢查名稱是否已在 Workspaces 中存在\n * Validation: Check if name already exists in workspaces\n */\nif (!oldExists && rootData?.hasWorkspace)\n{\n\tif (nameExistsInWorkspaces(targetName))\n\t{\n\t\tconsole.error(`root:`, rootData.root)\n\t\tconsole.error(`目標名稱已存在於 Workspaces 內,請更換名稱:`, targetName);\n\t\tprocess.exit(1);\n\t}\n}\n\n/**\n * 處理內建模組名稱的特殊情況\n * Handle special case for builtin module names\n */\nif (!oldExists && targetName && scopedPackagePattern && isBuiltinModule(basename(targetDir)))\n{\n\toutputPackageJSONSync(pkg_file_path, {\n\t\tname: targetName,\n\t})\n}\nelse if (!targetName)\n{\n\t/**\n\t * 嘗試讀取現有的 package.json\n\t * Try to read existing package.json\n\t */\n\ttry\n\t{\n\t\told_pkg = new PackageJsonLoader(pkg_file_path)?.data;\n\n\t\told_pkg_name = old_pkg.name\n\t}\n\tcatch (e)\n\t{\n\t\t/**\n\t\t * 讀取失敗時忽略(例如檔案不存在或 JSON 無效),\n\t\t * 讓後續流程改以全新 package.json 處理\n\t\t *\n\t\t * Ignore read failures (e.g. missing file or invalid JSON) so the rest of the flow\n\t\t * treats the target as a brand-new package.json\n\t\t */\n\t}\n}\n\n/**\n * 執行初始化並保留現有依賴項\n * Execute initialization while preserving existing dependencies\n */\nlet { cp } = initWithPreserveDeps({\n\tnpmClient: cli.argv.npmClient,\n\targs,\n\tcwd: targetDir,\n\told_pkg,\n\tpkg_file_path,\n});\n\n/**\n * 如果初始化成功,繼續後續設定\n * If initialization succeeded, continue with further configuration\n */\nif (!cp.error)\n{\n\t/**\n\t * 重新尋找根目錄(因為可能已建立新結構)\n\t * Re-find root directory (as new structure may have been created)\n\t */\n\trootData = findRoot({\n\t\tcwd: targetDir,\n\t\tskipCheckWorkspace: cli.argv.skipCheckWorkspace,\n\t});\n\n\t/**\n\t * 驗證根目錄是否正確\n\t * Validate root directory\n\t */\n\tif (!rootData?.root)\n\t{\n\t\tconsole.error(`發生錯誤,初始化失敗`, targetName);\n\t\tconsole.error(targetDir);\n\t\tprocess.exit(1);\n\t}\n\n\t/**\n\t * 載入 package.json\n\t * Load package.json\n\t */\n\tlet pkg = new PackageJsonLoader(pkg_file_path);\n\n\t/**\n\t * 如果 package.json 存在,進行詳細設定\n\t * If package.json exists, perform detailed configuration\n\t */\n\tif (pkg.exists())\n\t{\n\t\t/**\n\t\t * 設定 private 標誌(非 yarn 時)\n\t\t * Set private flag (when not using yarn)\n\t\t */\n\t\tif (cli.argv['p'] && cli.argv.npmClient !== 'yarn')\n\t\t{\n\t\t\tpkg.data.private = true;\n\t\t}\n\n\t\t/**\n\t\t * 防止 node- 前綴被 npm 移除的處理\n\t\t * Handle preservation of node- prefix that npm might remove\n\t\t */\n\t\tif (!cli.argv.yes && old_pkg_name && /^node-/.test(old_pkg_name) && ('node-' + pkg.data.name) === old_pkg_name)\n\t\t{\n\t\t\tpkg.data.name = old_pkg_name;\n\t\t}\n\t\telse if (cli.argv.yes && old_pkg_name && pkg.data.name !== old_pkg_name)\n\t\t{\n\t\t\tpkg.data.name = old_pkg_name;\n\t\t}\n\t\telse if (targetName && pkg.data.name !== targetName)\n\t\t{\n\t\t\tpkg.data.name = targetName;\n\t\t}\n\n\t\t/**\n\t\t * 檢查 Scoped Package 的發布配置\n\t\t * Check publish configuration for scoped packages\n\t\t */\n\t\tif (pkg.data.name && /^@/.test(pkg.data.name) && !pkg.data.publishConfig)\n\t\t{\n\t\t\t//pkg.data.publishConfig = {};\n\t\t}\n\n\t\t/**\n\t\t * 初始化 scripts 欄位\n\t\t * Initialize scripts field\n\t\t */\n\t\tif (!pkg.data.scripts)\n\t\t{\n\t\t\tpkg.data.scripts = {};\n\t\t}\n\n\t\t/**\n\t\t * 填充 Package 託管資訊(repository、bugs、homepage 等)\n\t\t * Fill package hosting info (repository, bugs, homepage, etc.)\n\t\t */\n\t\tfillPkgHostedInfo(pkg.data, {\n\t\t\ttargetDir,\n\t\t\trootData,\n\t\t});\n\n\t\t/**\n\t\t * 設定 Package Manager(預設 Yarn)\n\t\t * Set Package Manager (default to Yarn)\n\t\t */\n\t\t// pkg.data.packageManager ??= \"yarn@1.22.19\";\n\n\t\t/**\n\t\t * 共享腳本範本\n\t\t * Shared script templates\n\t\t */\n\t\tlet sharedScript: IPackageJson['scripts'] = {\n\t\t\t\"test\": `echo \"Error: no test specified\"`,\n\t\t};\n\n\t\t/**\n\t\t * 填充虛擬佔位腳本\n\t\t * Fill dummy placeholder scripts\n\t\t */\n\t\tfillDummyScripts(sharedScript);\n\n\t\t/**\n\t\t * Pre-version 腳本序列\n\t\t * Pre-version script sequence\n\t\t */\n\t\tlet preScripts: string[] = [\"echo preversion\"];\n\n\t\t/**\n\t\t * 設定 Root 專用的 prepublishOnly 腳本\n\t\t * Set prepublishOnly script for root projects\n\t\t */\n\t\tif (rootData.isRoot && !rootData.isWorkspace)\n\t\t{\n\t\t\tsharedScript.prepublishOnly = \"yarn run preversion\"\n\t\t}\n\n\t\t/**\n\t\t * 根據專案類型合併對應的腳本範本\n\t\t * Merge corresponding script templates based on project type\n\t\t */\n\t\tif (rootData.hasWorkspace)\n\t\t{\n\t\t\t/**\n\t\t\t * Workspaces 專案不添加額外根腳本:根專案的腳本由 workspaces 設定管理\n\t\t\t * Workspace projects get no extra root scripts: root scripts are managed by the workspace setup\n\t\t\t */\n\t\t}\n\t\telse if (rootData.isRoot)\n\t\t{\n\t\t\tsharedScript = {\n\t\t\t\t...sharedScript,\n\t\t\t\t...defaultRootScripts(),\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * 組合 Pre-version 腳本\n\t\t * Compose pre-version scripts\n\t\t */\n\t\tpreScripts.push(EnumScriptsEntry.preversion);\n\t\tsharedScript.preversion = preScripts.join(' && ')\n\n\t\t/**\n\t\t * 初始化 scripts 欄位(如果不存在)\n\t\t * Initialize scripts field if not exists\n\t\t */\n\t\tpkg.data.scripts ??= {};\n\n\t\t/**\n\t\t * 處理新建立的 Package 腳本\n\t\t * Handle scripts for newly created packages\n\t\t */\n\t\tif (!oldExists)\n\t\t{\n\t\t\t/**\n\t\t\t * 如果現有腳本是預設的無測試提示,且我們有測試腳本,則刪除舊的\n\t\t\t * If existing script is default no-test message and we have a test script, remove old one\n\t\t\t */\n\t\t\tif (scriptsEntryIsNoTestSpecified(pkg.data.scripts?.test) && sharedScript.test?.length > 0)\n\t\t\t{\n\t\t\t\tdelete pkg.data.scripts!.test\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * 如果根專案使用 Jest,設定對應的測試腳本\n\t\t\t * If root project uses Jest, set corresponding test script\n\t\t\t */\n\t\t\tif (_findDeps(wsProject?.manifest, '@types/jest') || _findDeps(wsProject?.manifest, 'jest') || _findDeps(wsProject?.manifest, 'ts-jest'))\n\t\t\t{\n\t\t\t\tsharedScript.test = EnumScriptsEntry.JEST_TEST;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * 合併預設腳本到新 Package\n\t\t\t * Merge default scripts to new package\n\t\t\t */\n\t\t\tObject\n\t\t\t\t.entries({\n\t\t\t\t\t...defaultPkgNotOldExists(),\n\t\t\t\t\t...sharedScript,\n\t\t\t\t})\n\t\t\t\t.forEach(([k, v]) =>\n\t\t\t\t{\n\t\t\t\t\tpkg.data.scripts[k] ??= v;\n\t\t\t\t})\n\t\t\t;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/**\n\t\t\t * 處理已存在的 Package 腳本\n\t\t\t * Handle scripts for existing packages\n\t\t\t */\n\t\t\tObject\n\t\t\t\t.entries(sharedScript)\n\t\t\t\t.forEach(([k, v]) =>\n\t\t\t\t{\n\t\t\t\t\t/**\n\t\t\t\t\t * 跳過尾隨底線標記的重複腳本\n\t\t\t\t\t * Skip duplicate scripts marked with trailing underscores\n\t\t\t\t\t */\n\t\t\t\t\tif (k.endsWith('_') && pkg.data.scripts[k.replace(/_+$/, '')] === v)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tpkg.data.scripts[k] ??= v;\n\t\t\t\t})\n\t\t\t;\n\n\t\t\t/**\n\t\t\t * 處理 TypeScript 型別定義路徑\n\t\t\t * Handle TypeScript type definitions path\n\t\t\t */\n\t\t\tif (!pkg.data.types || !pkg.data.typings)\n\t\t\t{\n\t\t\t\tpkg.data.types = pkg.data.types || pkg.data.typings;\n\n\t\t\t\t/**\n\t\t\t\t * 自動偵測型別定義檔案位置\n\t\t\t\t * Auto-detect type definition file location\n\t\t\t\t */\n\t\t\t\tif (pkg.data.main && !pkg.data.types)\n\t\t\t\t{\n\t\t\t\t\tlet file = join(targetDir, pkg.data.main)\n\t\t\t\t\tlet parsed = parse(file);\n\n\t\t\t\t\tif (!pathIsSame(targetDir, parsed.dir) && pathExistsSync(join(parsed.dir, parsed.name + '.d.ts')))\n\t\t\t\t\t{\n\t\t\t\t\t\tpkg.data.types = relative(targetDir, parsed.dir).replace(/^\\.\\//, '') + '/' + parsed.name + '.d.ts'\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tpkg.data.typings = pkg.data.types;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * 保留舊 Package.json 中未被覆蓋的欄位\n\t\t\t * Preserve fields from old package.json that weren't overwritten\n\t\t\t */\n\t\t\tif (old_pkg)\n\t\t\t{\n\t\t\t\tObject.keys(old_pkg)\n\t\t\t\t\t.forEach(key =>\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!(key in pkg.data))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpkg.data[key] = old_pkg[key];\n\t\t\t\t\t\t}\n\n\t\t\t\t\t})\n\t\t\t\t;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * 為新 Package 添加預設依賴項\n\t\t * Add default dependencies for new packages\n\t\t */\n\t\tif (!oldExists)\n\t\t{\n\t\t\tconst cpkg = require('./package.json') as IPackageJson;\n\n\t\t\t/**\n\t\t\t * 尋找依賴項版本的輔助函式\n\t\t\t * Helper function to find dependency version\n\t\t\t */\n\t\t\tconst findVersion = (name: string) =>\n\t\t\t{\n\t\t\t\treturn cpkg.dependencies?.[name] || cpkg.devDependencies?.[name] || cpkg.peerDependencies?.[name] || \"*\"\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * 初始化依賴項欄位:沿用既有內容,缺漏時才建立空物件\n\t\t\t * Initialize dependency fields: keep existing entries and only create empty objects when missing\n\t\t\t */\n\t\t\tpkg.data.dependencies = pkg.data.dependencies || {};\n\t\t\tpkg.data.devDependencies = pkg.data.devDependencies || {};\n\t\t\tpkg.data.peerDependencies = pkg.data.peerDependencies || {};\n\n\t\t\t/**\n\t\t\t * 為 Root 專案添加開發依賴項\n\t\t\t * Add dev dependencies for root projects\n\t\t\t */\n\t\t\tif (rootData.isRoot)\n\t\t\t{\n\t\t\t\tpkg.data.devDependencies['@bluelovers/tsconfig'] = findVersion('@bluelovers/tsconfig');\n\t\t\t\tpkg.data.devDependencies['@types/node'] = findVersion('@types/node');\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * 添加 tslib 作為執行時依賴:多數工具鏈會假設 tslib 存在\n\t\t\t * Add tslib as a runtime dependency: most toolchains assume tslib is present\n\t\t\t */\n\t\t\tpkg.data.dependencies['tslib'] = findVersion('tslib');\n\t\t}\n\n\t\t/**\n\t\t * 繼承 Root 專案的關鍵字\n\t\t * Inherit keywords from root project\n\t\t */\n\t\tif (wsProject && !rootData.isWorkspace)\n\t\t{\n\t\t\tconst rootKeywords = wsProject.manifest.toJSON().keywords;\n\n\t\t\tif (!pkg.data.keywords?.length && rootKeywords?.length)\n\t\t\t{\n\t\t\t\tpkg.data.keywords = rootKeywords.slice()\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * 添加工具標記關鍵字\n\t\t * Add tool marker keyword\n\t\t */\n\t\tpkg.data.keywords ??= [];\n\t\tpkg.data.keywords.push('create-by-yarn-tool');\n\n\t\t/**\n\t\t * 取得要複製的靜態檔案映射\n\t\t * Get static file mappings to copy\n\t\t */\n\t\tlet file_map = getRootCopyStaticFilesAuto({\n\t\t\thasWorkspace: !!wsProject,\n\t\t\tisRoot: !wsProject,\n\t\t});\n\n\t\t/**\n\t\t * README.md 檔案路徑\n\t\t * README.md file path\n\t\t */\n\t\tconst mdFile = join(targetDir, 'README.md');\n\n\t\t/**\n\t\t * 判斷是否需要生成 README\n\t\t * Determine if README needs to be generated\n\t\t */\n\t\tlet existsReadme = !oldExists || !existsSync(mdFile);\n\n\t\t/**\n\t\t * 如果啟用 TSDX,執行 TSDX 設定\n\t\t * If TSDX is enabled, execute TSDX setup\n\t\t */\n\t\tif (cli.argv.tsdx)\n\t\t{\n\t\t\t({\n\t\t\t\tfile_map,\n\t\t\t\texistsReadme,\n\t\t\t} = setupTsdx({\n\t\t\t\ttargetDir,\n\t\t\t\trootData,\n\t\t\t\tpkg: pkg.data,\n\t\t\t\tfile_map,\n\t\t\t\tmdFile,\n\t\t\t\texistsReadme,\n\t\t\t\toldExists,\n\t\t\t}));\n\t\t}\n\n\t\t/**\n\t\t * 排序 package.json 中的腳本\n\t\t * Sort scripts in package.json\n\t\t */\n\t\tpkg.data.scripts = sortPackageJsonScripts(pkg.data.scripts);\n\n\t\t/**\n\t\t * 設定 sideEffects 為 false(優化 Tree Shaking)\n\t\t * Set sideEffects to false (optimize Tree Shaking)\n\t\t * @see https://juejin.cn/post/6844903640533041159\n\t\t */\n\t\tpkg.data.sideEffects ??= false;\n\n\t\t/**\n\t\t * 自動修復 package.json 常見問題\n\t\t * Auto-fix common package.json issues\n\t\t */\n\t\tpkg.autofix();\n\n\t\t/**\n\t\t * 如果需要,對 package.json 進行排序\n\t\t * Sort package.json if requested\n\t\t */\n\t\tif (cli.argv.sort)\n\t\t{\n\t\t\tpkg.sort();\n\t\t}\n\n\t\t/**\n\t\t * 只在有載入資料時寫入檔案\n\t\t * Only write file when data was loaded\n\t\t */\n\t\tpkg.writeOnlyWhenLoaded();\n\n\t\t/**\n\t\t * 複製靜態範本檔案\n\t\t * Copy static template files\n\t\t *\n\t\t * 此呼叫點 addStaticFiles 預設為 true,可用 --noStaticFiles 關閉\n\t\t * addStaticFiles defaults to true at this call site; disable it with --noStaticFiles\n\t\t */\n\t\tif (_isAddStaticFilesWithReset(cli.argv, true))\n\t\t{\n\t\t\tcopyStaticFiles({\n\t\t\t\tcwd: targetDir,\n\t\t\t\tfile_map,\n\t\t\t})\n\t\t}\n\n\t\t/**\n\t\t * 生成 README.md(如果需要)\n\t\t * Generate README.md if needed\n\t\t */\n\t\tif (existsReadme)\n\t\t{\n\t\t\twriteReadme({\n\t\t\t\tfile: mdFile,\n\t\t\t\tvariable: pkg.data,\n\t\t\t})\n\t\t}\n\n\t\t/**\n\t\t * 將 Package 連結到 node_modules(Workspaces 專案)\n\t\t * Link package to node_modules (for workspace projects)\n\t\t *\n\t\t * 注意:條件以 `false &&` 開頭,永遠不會成立,此區塊目前已完全停用,\n\t\t * 程式碼保留以便日後恢復\n\t\t *\n\t\t * Note: the guard starts with `false &&` and never holds, so this block is fully\n\t\t * disabled; the code is kept for a possible re-enable later\n\t\t */\n\t\tif (false && wsProject && !rootData.isWorkspace)\n\t\t{\n\t\t\tlinkToNodeModules({\n\t\t\t\tcwd: targetDir,\n\t\t\t\tsourcePackagePath: targetDir,\n\t\t\t\toverwrite: true,\n\t\t\t})\n\t\t}\n\n\t}\n}\nelse\n{\n\t/**\n\t * 初始化失敗,設定錯誤退出碼\n\t * Initialization failed, set error exit code\n\t */\n\tprocess.exitCode = 1;\n}\n\n/**\n * 在 Package 中尋找指定依賴項\n * Find specified dependency in package\n *\n * @param pkg - Package.json 物件 / Package.json object\n * @param name - 依賴項名稱 / Dependency name\n * @returns 是否找到 / Whether found\n */\nfunction _findDeps(pkg: IPackageJson, name: string)\n{\n\tpkg ??= {};\n\treturn pkg.dependencies?.[name] ?? pkg.devDependencies?.[name]\n}\n"]}
@@ -1,4 +1,44 @@
1
+ /**
2
+ * @fileoverview Initialization helper that keeps existing dependencies
3
+ * @description 初始化套件並保留既有依賴項的輔助模組
4
+ *
5
+ * 本模組負責呼叫套件管理器執行 init,並在成功後把舊的依賴欄位寫回新建的 package.json。
6
+ * This module runs the package manager's init and writes the old dependency fields back into
7
+ * the freshly created package.json afterwards.
8
+ *
9
+ * @module npm-init2/lib/initWithPreserveDeps
10
+ */
1
11
  import { IPackageJson } from '@ts-type/package-dts';
12
+ /**
13
+ * 執行 npm/yarn 初始化並保留舊專案的依賴項
14
+ * Run npm/yarn init while preserving the previous project's dependencies
15
+ *
16
+ * 初始化指令會重建 package.json 並清掉依賴欄位,因此在子行程成功後,
17
+ * 再把 old_pkg 的 dependencies / devDependencies 寫回,避免既有依賴遺失。
18
+ *
19
+ * The init command rebuilds package.json and drops its dependency fields, so once the child
20
+ * process succeeds the `dependencies` / `devDependencies` of `old_pkg` are written back to
21
+ * avoid losing existing dependencies.
22
+ *
23
+ * @param {object} options - 初始化選項 / initialization options
24
+ *
25
+ * @param {string} options.npmClient - 執行的套件管理器 / package manager to run
26
+ * @param {string} options.cwd - 執行目錄 / working directory of the child process
27
+ * @param {string[]} options.args - 傳給套件管理器的參數 / arguments passed to the package manager
28
+ * @param {IPackageJson} options.old_pkg - 初始化前的 package.json / the previous package.json
29
+ * @param {string} options.pkg_file_path - 目標 package.json 路徑 / path of the target package.json
30
+ *
31
+ * @returns {{ cp }} 子行程結果;cp.error 存在代表失敗 / child process result; a truthy `cp.error` means failure
32
+ *
33
+ * @example
34
+ * const { cp } = initWithPreserveDeps({
35
+ * npmClient: 'npm',
36
+ * cwd: targetDir,
37
+ * args: ['init', '-y'],
38
+ * old_pkg,
39
+ * pkg_file_path: join(targetDir, 'package.json'),
40
+ * });
41
+ */
2
42
  export declare function initWithPreserveDeps({ npmClient, cwd, args, old_pkg, pkg_file_path }: {
3
43
  npmClient: string;
4
44
  cwd: string;
@@ -8,4 +48,8 @@ export declare function initWithPreserveDeps({ npmClient, cwd, args, old_pkg, pk
8
48
  }): {
9
49
  cp: import("cross-spawn-extra").SpawnSyncReturns<Buffer<ArrayBufferLike>>;
10
50
  };
51
+ /**
52
+ * 預設匯出 initWithPreserveDeps,讓 `import initWithPreserveDeps from '...'` 可直接使用
53
+ * Default-export initWithPreserveDeps so `import initWithPreserveDeps from '...'` works directly
54
+ */
11
55
  export default initWithPreserveDeps;
@@ -1,9 +1,56 @@
1
1
  "use strict";
2
+ /**
3
+ * @fileoverview Initialization helper that keeps existing dependencies
4
+ * @description 初始化套件並保留既有依賴項的輔助模組
5
+ *
6
+ * 本模組負責呼叫套件管理器執行 init,並在成功後把舊的依賴欄位寫回新建的 package.json。
7
+ * This module runs the package manager's init and writes the old dependency fields back into
8
+ * the freshly created package.json afterwards.
9
+ *
10
+ * @module npm-init2/lib/initWithPreserveDeps
11
+ */
2
12
  Object.defineProperty(exports, "__esModule", { value: true });
3
13
  exports.initWithPreserveDeps = initWithPreserveDeps;
4
14
  const cross_spawn_extra_1 = require("cross-spawn-extra");
5
15
  const npm_package_json_loader_1 = require("npm-package-json-loader");
16
+ /**
17
+ * 執行 npm/yarn 初始化並保留舊專案的依賴項
18
+ * Run npm/yarn init while preserving the previous project's dependencies
19
+ *
20
+ * 初始化指令會重建 package.json 並清掉依賴欄位,因此在子行程成功後,
21
+ * 再把 old_pkg 的 dependencies / devDependencies 寫回,避免既有依賴遺失。
22
+ *
23
+ * The init command rebuilds package.json and drops its dependency fields, so once the child
24
+ * process succeeds the `dependencies` / `devDependencies` of `old_pkg` are written back to
25
+ * avoid losing existing dependencies.
26
+ *
27
+ * @param {object} options - 初始化選項 / initialization options
28
+ *
29
+ * @param {string} options.npmClient - 執行的套件管理器 / package manager to run
30
+ * @param {string} options.cwd - 執行目錄 / working directory of the child process
31
+ * @param {string[]} options.args - 傳給套件管理器的參數 / arguments passed to the package manager
32
+ * @param {IPackageJson} options.old_pkg - 初始化前的 package.json / the previous package.json
33
+ * @param {string} options.pkg_file_path - 目標 package.json 路徑 / path of the target package.json
34
+ *
35
+ * @returns {{ cp }} 子行程結果;cp.error 存在代表失敗 / child process result; a truthy `cp.error` means failure
36
+ *
37
+ * @example
38
+ * const { cp } = initWithPreserveDeps({
39
+ * npmClient: 'npm',
40
+ * cwd: targetDir,
41
+ * args: ['init', '-y'],
42
+ * old_pkg,
43
+ * pkg_file_path: join(targetDir, 'package.json'),
44
+ * });
45
+ */
6
46
  function initWithPreserveDeps({ npmClient, cwd, args, old_pkg, pkg_file_path }) {
47
+ /**
48
+ * 以 stdio: inherit 讓子行程直接沿用目前終端的輸入輸出;
49
+ * 關閉顏色(FORCE_COLOR=0、NO_COLOR=1)避免控制碼污染後續輸出
50
+ *
51
+ * `stdio: inherit` lets the child reuse the current terminal's input/output; colors are
52
+ * disabled (FORCE_COLOR=0, NO_COLOR=1) so escape sequences do not pollute later output
53
+ */
7
54
  const cp = (0, cross_spawn_extra_1.sync)(npmClient, args, {
8
55
  stdio: 'inherit',
9
56
  cwd,
@@ -12,9 +59,25 @@ function initWithPreserveDeps({ npmClient, cwd, args, old_pkg, pkg_file_path })
12
59
  NO_COLOR: "1",
13
60
  }
14
61
  });
62
+ /**
63
+ * 只有初始化成功且有舊資料時才還原依賴;
64
+ * 失敗時不碰 package.json,讓呼叫端能取得原始錯誤狀態
65
+ *
66
+ * Restore dependencies only when init succeeded and old data exists; the package.json is
67
+ * left untouched on failure so the caller sees the original error state
68
+ */
15
69
  if (!cp.error && old_pkg) {
16
70
  let pkg = new npm_package_json_loader_1.PackageJsonLoader(pkg_file_path);
71
+ /**
72
+ * 檔案確實存在才寫入,避免初始化失敗時憑空建立 package.json
73
+ * Write only when the file exists, so a failed init does not conjure up a package.json
74
+ */
17
75
  if (pkg.exists()) {
76
+ /**
77
+ * 只還原依賴欄位;其餘舊欄位由呼叫端(index.ts)另行合併
78
+ * Only the dependency fields are restored here; the caller (index.ts) merges the
79
+ * other legacy fields separately
80
+ */
18
81
  pkg.data.dependencies = old_pkg.dependencies;
19
82
  pkg.data.devDependencies = old_pkg.devDependencies;
20
83
  pkg.writeOnlyWhenLoaded();
@@ -22,5 +85,9 @@ function initWithPreserveDeps({ npmClient, cwd, args, old_pkg, pkg_file_path })
22
85
  }
23
86
  return { cp };
24
87
  }
88
+ /**
89
+ * 預設匯出 initWithPreserveDeps,讓 `import initWithPreserveDeps from '...'` 可直接使用
90
+ * Default-export initWithPreserveDeps so `import initWithPreserveDeps from '...'` works directly
91
+ */
25
92
  exports.default = initWithPreserveDeps;
26
93
  //# sourceMappingURL=initWithPreserveDeps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"initWithPreserveDeps.js","sourceRoot":"","sources":["initWithPreserveDeps.ts"],"names":[],"mappings":";;AAIA,oDAqCC;AAzCD,yDAAyC;AAEzC,qEAA4D;AAE5D,SAAgB,oBAAoB,CAAC,EACpC,SAAS,EACT,GAAG,EACH,IAAI,EACJ,OAAO,EACP,aAAa,EAOb;IAEA,MAAM,EAAE,GAAG,IAAA,wBAAI,EAAC,SAAS,EAAE,IAAI,EAAE;QAChC,KAAK,EAAE,SAAS;QAChB,GAAG;QACH,GAAG,EAAE;YACJ,WAAW,EAAE,GAAG;YAChB,QAAQ,EAAE,GAAG;SACb;KACD,CAAC,CAAC;IAEH,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,OAAO,EACxB,CAAC;QACA,IAAI,GAAG,GAAG,IAAI,2CAAiB,CAAC,aAAa,CAAC,CAAC;QAE/C,IAAI,GAAG,CAAC,MAAM,EAAE,EAChB,CAAC;YACA,GAAG,CAAC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;YAC7C,GAAG,CAAC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;YAEnD,GAAG,CAAC,mBAAmB,EAAE,CAAC;QAC3B,CAAC;IACF,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,CAAA;AACd,CAAC;AAED,kBAAe,oBAAoB,CAAA","sourcesContent":["import { sync } from 'cross-spawn-extra';\nimport { IPackageJson } from '@ts-type/package-dts';\nimport { PackageJsonLoader } from 'npm-package-json-loader';\n\nexport function initWithPreserveDeps({\n\tnpmClient,\n\tcwd,\n\targs,\n\told_pkg,\n\tpkg_file_path\n}: {\n\tnpmClient: string,\n\tcwd: string,\n\targs: string[],\n\told_pkg: IPackageJson,\n\tpkg_file_path: string,\n})\n{\n\tconst cp = sync(npmClient, args, {\n\t\tstdio: 'inherit',\n\t\tcwd,\n\t\tenv: {\n\t\t\tFORCE_COLOR: \"0\",\n\t\t\tNO_COLOR: \"1\",\n\t\t}\n\t});\n\n\tif (!cp.error && old_pkg)\n\t{\n\t\tlet pkg = new PackageJsonLoader(pkg_file_path);\n\n\t\tif (pkg.exists())\n\t\t{\n\t\t\tpkg.data.dependencies = old_pkg.dependencies;\n\t\t\tpkg.data.devDependencies = old_pkg.devDependencies;\n\n\t\t\tpkg.writeOnlyWhenLoaded();\n\t\t}\n\t}\n\n\treturn { cp }\n}\n\nexport default initWithPreserveDeps\n"]}
1
+ {"version":3,"file":"initWithPreserveDeps.js","sourceRoot":"","sources":["initWithPreserveDeps.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAoCH,oDA4DC;AA9FD,yDAAyC;AAEzC,qEAA4D;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAgB,oBAAoB,CAAC,EACpC,SAAS,EACT,GAAG,EACH,IAAI,EACJ,OAAO,EACP,aAAa,EAOb;IAEA;;;;;;OAMG;IACH,MAAM,EAAE,GAAG,IAAA,wBAAI,EAAC,SAAS,EAAE,IAAI,EAAE;QAChC,KAAK,EAAE,SAAS;QAChB,GAAG;QACH,GAAG,EAAE;YACJ,WAAW,EAAE,GAAG;YAChB,QAAQ,EAAE,GAAG;SACb;KACD,CAAC,CAAC;IAEH;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,OAAO,EACxB,CAAC;QACA,IAAI,GAAG,GAAG,IAAI,2CAAiB,CAAC,aAAa,CAAC,CAAC;QAE/C;;;WAGG;QACH,IAAI,GAAG,CAAC,MAAM,EAAE,EAChB,CAAC;YACA;;;;eAIG;YACH,GAAG,CAAC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;YAC7C,GAAG,CAAC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;YAEnD,GAAG,CAAC,mBAAmB,EAAE,CAAC;QAC3B,CAAC;IACF,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,CAAA;AACd,CAAC;AAED;;;GAGG;AACH,kBAAe,oBAAoB,CAAA","sourcesContent":["/**\n * @fileoverview Initialization helper that keeps existing dependencies\n * @description 初始化套件並保留既有依賴項的輔助模組\n *\n * 本模組負責呼叫套件管理器執行 init,並在成功後把舊的依賴欄位寫回新建的 package.json。\n * This module runs the package manager's init and writes the old dependency fields back into\n * the freshly created package.json afterwards.\n *\n * @module npm-init2/lib/initWithPreserveDeps\n */\n\nimport { sync } from 'cross-spawn-extra';\nimport { IPackageJson } from '@ts-type/package-dts';\nimport { PackageJsonLoader } from 'npm-package-json-loader';\n\n/**\n * 執行 npm/yarn 初始化並保留舊專案的依賴項\n * Run npm/yarn init while preserving the previous project's dependencies\n *\n * 初始化指令會重建 package.json 並清掉依賴欄位,因此在子行程成功後,\n * 再把 old_pkg 的 dependencies / devDependencies 寫回,避免既有依賴遺失。\n *\n * The init command rebuilds package.json and drops its dependency fields, so once the child\n * process succeeds the `dependencies` / `devDependencies` of `old_pkg` are written back to\n * avoid losing existing dependencies.\n *\n * @param {object} options - 初始化選項 / initialization options\n *\n * @param {string} options.npmClient - 執行的套件管理器 / package manager to run\n * @param {string} options.cwd - 執行目錄 / working directory of the child process\n * @param {string[]} options.args - 傳給套件管理器的參數 / arguments passed to the package manager\n * @param {IPackageJson} options.old_pkg - 初始化前的 package.json / the previous package.json\n * @param {string} options.pkg_file_path - 目標 package.json 路徑 / path of the target package.json\n *\n * @returns {{ cp }} 子行程結果;cp.error 存在代表失敗 / child process result; a truthy `cp.error` means failure\n *\n * @example\n * const { cp } = initWithPreserveDeps({\n * npmClient: 'npm',\n * cwd: targetDir,\n * args: ['init', '-y'],\n * old_pkg,\n * pkg_file_path: join(targetDir, 'package.json'),\n * });\n */\nexport function initWithPreserveDeps({\n\tnpmClient,\n\tcwd,\n\targs,\n\told_pkg,\n\tpkg_file_path\n}: {\n\tnpmClient: string,\n\tcwd: string,\n\targs: string[],\n\told_pkg: IPackageJson,\n\tpkg_file_path: string,\n})\n{\n\t/**\n\t * 以 stdio: inherit 讓子行程直接沿用目前終端的輸入輸出;\n\t * 關閉顏色(FORCE_COLOR=0、NO_COLOR=1)避免控制碼污染後續輸出\n\t *\n\t * `stdio: inherit` lets the child reuse the current terminal's input/output; colors are\n\t * disabled (FORCE_COLOR=0, NO_COLOR=1) so escape sequences do not pollute later output\n\t */\n\tconst cp = sync(npmClient, args, {\n\t\tstdio: 'inherit',\n\t\tcwd,\n\t\tenv: {\n\t\t\tFORCE_COLOR: \"0\",\n\t\t\tNO_COLOR: \"1\",\n\t\t}\n\t});\n\n\t/**\n\t * 只有初始化成功且有舊資料時才還原依賴;\n\t * 失敗時不碰 package.json,讓呼叫端能取得原始錯誤狀態\n\t *\n\t * Restore dependencies only when init succeeded and old data exists; the package.json is\n\t * left untouched on failure so the caller sees the original error state\n\t */\n\tif (!cp.error && old_pkg)\n\t{\n\t\tlet pkg = new PackageJsonLoader(pkg_file_path);\n\n\t\t/**\n\t\t * 檔案確實存在才寫入,避免初始化失敗時憑空建立 package.json\n\t\t * Write only when the file exists, so a failed init does not conjure up a package.json\n\t\t */\n\t\tif (pkg.exists())\n\t\t{\n\t\t\t/**\n\t\t\t * 只還原依賴欄位;其餘舊欄位由呼叫端(index.ts)另行合併\n\t\t\t * Only the dependency fields are restored here; the caller (index.ts) merges the\n\t\t\t * other legacy fields separately\n\t\t\t */\n\t\t\tpkg.data.dependencies = old_pkg.dependencies;\n\t\t\tpkg.data.devDependencies = old_pkg.devDependencies;\n\n\t\t\tpkg.writeOnlyWhenLoaded();\n\t\t}\n\t}\n\n\treturn { cp }\n}\n\n/**\n * 預設匯出 initWithPreserveDeps,讓 `import initWithPreserveDeps from '...'` 可直接使用\n * Default-export initWithPreserveDeps so `import initWithPreserveDeps from '...'` works directly\n */\nexport default initWithPreserveDeps\n"]}
@@ -1,10 +1,31 @@
1
1
  /**
2
2
  * Created by user on 2019/5/16.
3
3
  */
4
+ /**
5
+ * @fileoverview CLI option definitions for npm-init2
6
+ * @description npm-init2 的命令列選項定義
7
+ *
8
+ * 選項集中在這裡註冊,主流程(index.ts)只讀取解析後的 argv,
9
+ * 如此可單獨替換選項定義而不影響初始化邏輯。
10
+ * Options are registered here while the main flow (index.ts) only reads the parsed argv, so the
11
+ * option definitions can change without touching the initialization logic.
12
+ *
13
+ * @module npm-init2/lib/yargs-setting
14
+ */
4
15
  import yargs from 'yargs';
5
16
  import { Argv } from 'yargs';
6
- import { IYargsSync } from '@yarn-tool/types';
7
- export declare function setupToYargs<T>(yargs: Argv<T>): IYargsSync<yargs.Argv<yargs.Omit<T, never> & {
17
+ /**
18
+ * 設定 Yargs CLI 選項
19
+ * Setup Yargs CLI options
20
+ *
21
+ * 繼承 @yarn-tool/fix-all 的共用選項
22
+ * (overwriteHostedGitInfo / branch / resetStaticFiles / addStaticFiles / noStaticFiles)
23
+ * Inherits shared options from @yarn-tool/fix-all
24
+ * (overwriteHostedGitInfo / branch / resetStaticFiles / addStaticFiles / noStaticFiles)
25
+ *
26
+ * @param yargs - Yargs 實例 / Yargs instance
27
+ */
28
+ export declare function setupToYargs<T>(yargs: Argv<T>): import("@yarn-tool/types").IYargsSync<yargs.Argv<yargs.Omit<T, never> & {
8
29
  npmClient: string;
9
30
  } & {
10
31
  yes: boolean;
@@ -26,5 +47,19 @@ export declare function setupToYargs<T>(yargs: Argv<T>): IYargsSync<yargs.Argv<y
26
47
  copyStatic: boolean;
27
48
  } & {
28
49
  tsdx: boolean;
50
+ } & {
51
+ overwriteHostedGitInfo: boolean;
52
+ } & {
53
+ branch: string;
54
+ } & {
55
+ resetStaticFiles: boolean;
56
+ } & {
57
+ addStaticFiles: boolean;
58
+ } & {
59
+ noStaticFiles: boolean;
29
60
  }>>;
61
+ /**
62
+ * 預設匯出 setupToYargs,讓 `import setupToYargs from '...'` 可直接使用
63
+ * Default-export setupToYargs so `import setupToYargs from '...'` works directly
64
+ */
30
65
  export default setupToYargs;
@@ -4,7 +4,23 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.setupToYargs = setupToYargs;
7
+ const yargs_setting_1 = require("@yarn-tool/fix-all/lib/util/yargs-setting");
8
+ /**
9
+ * 設定 Yargs CLI 選項
10
+ * Setup Yargs CLI options
11
+ *
12
+ * 繼承 @yarn-tool/fix-all 的共用選項
13
+ * (overwriteHostedGitInfo / branch / resetStaticFiles / addStaticFiles / noStaticFiles)
14
+ * Inherits shared options from @yarn-tool/fix-all
15
+ * (overwriteHostedGitInfo / branch / resetStaticFiles / addStaticFiles / noStaticFiles)
16
+ *
17
+ * @param yargs - Yargs 實例 / Yargs instance
18
+ */
7
19
  function setupToYargs(yargs) {
20
+ /**
21
+ * 註冊 npm-init2 的命令列選項,完成後再交給 @yarn-tool/fix-all 補上共用選項
22
+ * Register npm-init2's CLI options, then let @yarn-tool/fix-all append the shared options
23
+ */
8
24
  const _return = yargs
9
25
  .default({
10
26
  //input: process.cwd(),
@@ -23,6 +39,13 @@ function setupToYargs(yargs) {
23
39
  // default: 'npm',
24
40
  type: 'boolean',
25
41
  })
42
+ /**
43
+ * 只設定 defaultDescription 而未設定 default:
44
+ * 未傳入時 argv.cwd 保持 undefined,主流程得以區分「使用者明確指定」與「使用預設值」
45
+ *
46
+ * Only `defaultDescription` is set instead of `default`, so `argv.cwd` stays undefined
47
+ * when not passed and the main flow can distinguish an explicit path from the default
48
+ */
26
49
  .option('cwd', {
27
50
  alias: ['C'],
28
51
  requiresArg: true,
@@ -39,6 +62,10 @@ function setupToYargs(yargs) {
39
62
  alias: ['f'],
40
63
  type: 'boolean',
41
64
  })
65
+ /**
66
+ * 預設排序;yargs 會為布林選項自動產生 --noSort 反向旗標
67
+ * Sorted by default; yargs auto-generates the `--noSort` negation flag for boolean options
68
+ */
42
69
  .option('sort', {
43
70
  type: 'boolean',
44
71
  default: true,
@@ -60,7 +87,15 @@ function setupToYargs(yargs) {
60
87
  .option('tsdx', {
61
88
  type: 'boolean',
62
89
  });
63
- return _return;
90
+ /**
91
+ * 繼承 @yarn-tool/fix-all 的共用靜態檔案選項
92
+ * Inherit shared static file options from @yarn-tool/fix-all
93
+ */
94
+ return (0, yargs_setting_1.setupToYargs)(_return);
64
95
  }
96
+ /**
97
+ * 預設匯出 setupToYargs,讓 `import setupToYargs from '...'` 可直接使用
98
+ * Default-export setupToYargs so `import setupToYargs from '...'` works directly
99
+ */
65
100
  exports.default = setupToYargs;
66
101
  //# sourceMappingURL=yargs-setting.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"yargs-setting.js","sourceRoot":"","sources":["yargs-setting.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAMH,oCA4DC;AA5DD,SAAgB,YAAY,CAAI,KAAc;IAE7C,MAAM,OAAO,GAAG,KAAK;SACnB,OAAO,CAAC;IACR,uBAAuB;KACvB,CAAC;SACD,MAAM,CAAC,WAAW,EAAE;QACpB,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,WAAW,EAAE,IAAI;QACjB,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,mBAAmB;QAChC,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,QAAQ;KACd,CAAC;SACD,MAAM,CAAC,KAAK,EAAE;QACd,KAAK,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC;QACzB,sBAAsB;QACtB,mBAAmB;QAChB,IAAI,EAAE,SAAS;KACf,CAAC;SACD,MAAM,CAAC,KAAK,EAAE;QACd,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,WAAW,EAAE,IAAI;QACjB,SAAS,EAAE,IAAI;QAClB,2BAA2B;QACxB,kBAAkB,EAAE,OAAO,CAAC,GAAG,EAAE;QACjC,IAAI,EAAE,QAAQ;KACd,CAAC;SACD,MAAM,CAAC,oBAAoB,EAAE;QAC7B,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,IAAI,EAAE,SAAS;KACf,CAAC;SACD,MAAM,CAAC,OAAO,EAAE;QAChB,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,IAAI,EAAE,SAAS;KACf,CAAC;SACD,MAAM,CAAC,MAAM,EAAE;QACf,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,IAAI;KACb,CAAC;SACD,MAAM,CAAC,SAAS,EAAE;QAClB,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,IAAI,EAAE,SAAS;KACf,CAAC;SACD,MAAM,CAAC,cAAc,EAAE;QACvB,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,IAAI,EAAE,QAAQ;KACd,CAAC;SACD,MAAM,CAAC,MAAM,EAAE;QACf,IAAI,EAAE,QAAQ;KACd,CAAC;SACD,MAAM,CAAC,YAAY,EAAE;QACrB,IAAI,EAAE,SAAS;KACf,CAAC;SACD,MAAM,CAAC,MAAM,EAAE;QACf,IAAI,EAAE,SAAS;KACf,CAAC,CACF;IAED,OAAO,OAA4C,CAAA;AACpD,CAAC;AAED,kBAAe,YAAY,CAAA","sourcesContent":["/**\n * Created by user on 2019/5/16.\n */\n\nimport yargs, { Arguments } from 'yargs';\nimport { Argv, Omit } from 'yargs';\nimport { IYargsSync, IYargsUnPackArgv } from '@yarn-tool/types';\n\nexport function setupToYargs<T>(yargs: Argv<T>)\n{\n\tconst _return = yargs\n\t\t.default({\n\t\t\t//input: process.cwd(),\n\t\t})\n\t\t.option('npmClient', {\n\t\t\talias: ['N'],\n\t\t\trequiresArg: true,\n\t\t\tnormalize: true,\n\t\t\tdescription: 'npm, yarn, ...etc',\n\t\t\tdefault: 'npm',\n\t\t\ttype: 'string',\n\t\t})\n\t\t.option('yes', {\n\t\t\talias: ['y', 'silent'],\n//\t\trequiresArg: true,\n//\t\tdefault: 'npm',\n\t\t\ttype: 'boolean',\n\t\t})\n\t\t.option('cwd', {\n\t\t\talias: ['C'],\n\t\t\trequiresArg: true,\n\t\t\tnormalize: true,\n//\t\tdefault: process.cwd(),\n\t\t\tdefaultDescription: process.cwd(),\n\t\t\ttype: 'string',\n\t\t})\n\t\t.option('skipCheckWorkspace', {\n\t\t\talias: ['W'],\n\t\t\ttype: 'boolean',\n\t\t})\n\t\t.option('force', {\n\t\t\talias: ['f'],\n\t\t\ttype: 'boolean',\n\t\t})\n\t\t.option('sort', {\n\t\t\ttype: 'boolean',\n\t\t\tdefault: true,\n\t\t})\n\t\t.option('private', {\n\t\t\talias: ['p'],\n\t\t\ttype: 'boolean',\n\t\t})\n\t\t.option('createModule', {\n\t\t\talias: ['m'],\n\t\t\ttype: 'string',\n\t\t})\n\t\t.option('name', {\n\t\t\ttype: 'string',\n\t\t})\n\t\t.option('copyStatic', {\n\t\t\ttype: 'boolean',\n\t\t})\n\t\t.option('tsdx', {\n\t\t\ttype: 'boolean',\n\t\t})\n\t;\n\n\treturn _return as any as IYargsSync<typeof _return>\n}\n\nexport default setupToYargs\n"]}
1
+ {"version":3,"file":"yargs-setting.js","sourceRoot":"","sources":["yargs-setting.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA6BH,oCA+EC;AA5FD,6EAA+F;AAE/F;;;;;;;;;;GAUG;AACH,SAAgB,YAAY,CAAI,KAAc;IAE7C;;;OAGG;IACH,MAAM,OAAO,GAAG,KAAK;SACnB,OAAO,C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,CAAC,MAAM,EAAE;QACf,IAAI,EAAE,SAAS;KACf,CAAC,CACF;IAED;;;OAGG;IACH,OAAO,IAAA,4BAAkB,EAAC,OAAO,CAAC,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,kBAAe,YAAY,CAAA","sourcesContent":["/**\n * Created by user on 2019/5/16.\n */\n\n/**\n * @fileoverview CLI option definitions for npm-init2\n * @description npm-init2 的命令列選項定義\n *\n * 選項集中在這裡註冊,主流程(index.ts)只讀取解析後的 argv,\n * 如此可單獨替換選項定義而不影響初始化邏輯。\n * Options are registered here while the main flow (index.ts) only reads the parsed argv, so the\n * option definitions can change without touching the initialization logic.\n *\n * @module npm-init2/lib/yargs-setting\n */\n\nimport yargs, { Arguments } from 'yargs';\nimport { Argv, Omit } from 'yargs';\nimport { setupToYargs as setupFixAllToYargs } from '@yarn-tool/fix-all/lib/util/yargs-setting';\n\n/**\n * 設定 Yargs CLI 選項\n * Setup Yargs CLI options\n *\n * 繼承 @yarn-tool/fix-all 的共用選項\n * (overwriteHostedGitInfo / branch / resetStaticFiles / addStaticFiles / noStaticFiles)\n * Inherits shared options from @yarn-tool/fix-all\n * (overwriteHostedGitInfo / branch / resetStaticFiles / addStaticFiles / noStaticFiles)\n *\n * @param yargs - Yargs 實例 / Yargs instance\n */\nexport function setupToYargs<T>(yargs: Argv<T>)\n{\n\t/**\n\t * 註冊 npm-init2 的命令列選項,完成後再交給 @yarn-tool/fix-all 補上共用選項\n\t * Register npm-init2's CLI options, then let @yarn-tool/fix-all append the shared options\n\t */\n\tconst _return = yargs\n\t\t.default({\n\t\t\t//input: process.cwd(),\n\t\t})\n\t\t.option('npmClient', {\n\t\t\talias: ['N'],\n\t\t\trequiresArg: true,\n\t\t\tnormalize: true,\n\t\t\tdescription: 'npm, yarn, ...etc',\n\t\t\tdefault: 'npm',\n\t\t\ttype: 'string',\n\t\t})\n\t\t.option('yes', {\n\t\t\talias: ['y', 'silent'],\n//\t\trequiresArg: true,\n//\t\tdefault: 'npm',\n\t\t\ttype: 'boolean',\n\t\t})\n\t\t/**\n\t\t * 只設定 defaultDescription 而未設定 default:\n\t\t * 未傳入時 argv.cwd 保持 undefined,主流程得以區分「使用者明確指定」與「使用預設值」\n\t\t *\n\t\t * Only `defaultDescription` is set instead of `default`, so `argv.cwd` stays undefined\n\t\t * when not passed and the main flow can distinguish an explicit path from the default\n\t\t */\n\t\t.option('cwd', {\n\t\t\talias: ['C'],\n\t\t\trequiresArg: true,\n\t\t\tnormalize: true,\n//\t\tdefault: process.cwd(),\n\t\t\tdefaultDescription: process.cwd(),\n\t\t\ttype: 'string',\n\t\t})\n\t\t.option('skipCheckWorkspace', {\n\t\t\talias: ['W'],\n\t\t\ttype: 'boolean',\n\t\t})\n\t\t.option('force', {\n\t\t\talias: ['f'],\n\t\t\ttype: 'boolean',\n\t\t})\n\t\t/**\n\t\t * 預設排序;yargs 會為布林選項自動產生 --noSort 反向旗標\n\t\t * Sorted by default; yargs auto-generates the `--noSort` negation flag for boolean options\n\t\t */\n\t\t.option('sort', {\n\t\t\ttype: 'boolean',\n\t\t\tdefault: true,\n\t\t})\n\t\t.option('private', {\n\t\t\talias: ['p'],\n\t\t\ttype: 'boolean',\n\t\t})\n\t\t.option('createModule', {\n\t\t\talias: ['m'],\n\t\t\ttype: 'string',\n\t\t})\n\t\t.option('name', {\n\t\t\ttype: 'string',\n\t\t})\n\t\t.option('copyStatic', {\n\t\t\ttype: 'boolean',\n\t\t})\n\t\t.option('tsdx', {\n\t\t\ttype: 'boolean',\n\t\t})\n\t;\n\n\t/**\n\t * 繼承 @yarn-tool/fix-all 的共用靜態檔案選項\n\t * Inherit shared static file options from @yarn-tool/fix-all\n\t */\n\treturn setupFixAllToYargs(_return);\n}\n\n/**\n * 預設匯出 setupToYargs,讓 `import setupToYargs from '...'` 可直接使用\n * Default-export setupToYargs so `import setupToYargs from '...'` works directly\n */\nexport default setupToYargs\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-init2",
3
- "version": "3.0.22",
3
+ "version": "3.0.23",
4
4
  "private": false,
5
5
  "description": "a lazy npm init for create new package, support yarn workspace. make we without use `mkdir xxx && cd xxx && [npm|yarn] init` with `npx npm-init2 xxx`",
6
6
  "keywords": [
@@ -35,66 +35,61 @@
35
35
  "lib": "lib"
36
36
  },
37
37
  "scripts": {
38
+ "bin:self": "tsx bin/npm-init2.ts",
38
39
  "coverage": "pnpm run test -- --coverage",
39
- "test": "node --run test:jest --",
40
+ "test": "node --run test:node",
40
41
  "test:jest": "jest --passWithNoTests",
41
42
  "test:jest:coverage": "pnpm run test:jest -- --coverage",
42
43
  "test:jest:snapshot": "pnpm run test:jest -- -u",
44
+ "test:node": "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts",
43
45
  "test:snapshot": "pnpm run test -u",
46
+ "test:tsc": "tsc --noEmit & echo typescript check done",
44
47
  "test:tsd": "ynpx tsd",
45
- "prebuild:lockfile": "npx sync-lockfile .",
46
48
  "npm:publish": "npm publish",
47
49
  "preversion": "pnpm run test",
48
- "prepublish:lockfile": "npx sync-lockfile .",
49
- "prepublishOnly": "echo prepublishOnly",
50
- "prepublishOnly_": "pnpm run ncu && pnpm run sort-package-json && pnpm run test",
51
- "postpublish_": "git commit -m \"chore(release): publish\" . & git push & echo postpublish",
52
- "ncu": "npx yarn-tool ncu -u",
53
- "sort-package-json": "npx yarn-tool sort",
54
- "tsc:showConfig": "ynpx get-current-tsconfig -p"
50
+ "prepublishOnly": "echo prepublishOnly"
55
51
  },
56
52
  "config": {},
57
53
  "dependencies": {
58
- "@ts-type/package-dts": "^3.0.9",
59
- "@yarn-tool/find-root": "^2.0.25",
60
- "@yarn-tool/init-path": "^2.0.10",
61
- "@yarn-tool/is-builtin-module": "^1.0.28",
62
- "@yarn-tool/node-modules-link": "^3.0.12",
63
- "@yarn-tool/pkg-entry-util": "^3.0.14",
64
- "@yarn-tool/pkg-git-info": "^2.0.8",
65
- "@yarn-tool/pkg-hosted-info": "^3.0.11",
66
- "@yarn-tool/pkg-readme-tpl": "^1.0.9",
67
- "@yarn-tool/setup-module-env": "^3.0.16",
68
- "@yarn-tool/static-file": "^3.0.19",
69
- "@yarn-tool/types": "^1.0.21",
70
- "@yarn-tool/update-notifier": "^1.0.48",
71
- "@yarn-tool/workspaces-project": "^3.0.14",
72
- "@yarn-tool/write-package-json": "^1.0.17",
54
+ "@ts-type/package-dts": "^3.0.14",
55
+ "@yarn-tool/find-root": "^2.0.26",
56
+ "@yarn-tool/init-path": "^2.0.11",
57
+ "@yarn-tool/is-builtin-module": "^1.0.29",
58
+ "@yarn-tool/node-modules-link": "^3.0.13",
59
+ "@yarn-tool/pkg-entry-util": "^3.0.15",
60
+ "@yarn-tool/pkg-git-info": "^2.0.9",
61
+ "@yarn-tool/pkg-hosted-info": "^3.0.12",
62
+ "@yarn-tool/pkg-readme-tpl": "^1.0.10",
63
+ "@yarn-tool/setup-module-env": "^3.0.17",
64
+ "@yarn-tool/static-file": "^3.0.20",
65
+ "@yarn-tool/types": "^1.0.22",
66
+ "@yarn-tool/update-notifier": "^1.0.49",
67
+ "@yarn-tool/workspaces-project": "^3.0.15",
68
+ "@yarn-tool/write-package-json": "^1.0.18",
73
69
  "cross-spawn-extra": "^3.0.3",
74
70
  "debug-color2": "^1.3.2",
75
- "find-yarn-workspace-root2": "^1.2.55",
76
- "fs-extra": "^11.4.0",
71
+ "find-yarn-workspace-root2": "^1.2.56",
72
+ "fs-extra": "^11.4.1",
77
73
  "json5": "^2.2.3",
78
74
  "lodash": "^4.18.1",
79
75
  "micromatch": "^4.0.8",
80
- "npm-package-json-loader": "^3.0.15",
76
+ "npm-package-json-loader": "^3.0.16",
81
77
  "path-is-same": "^1.0.29",
82
- "sort-package-json-scripts": "^1.1.34",
78
+ "sort-package-json-scripts": "^1.1.35",
83
79
  "tslib": ">=2.8.1",
84
80
  "upath2": "^3.1.25",
85
81
  "validate-npm-package-name": "^8.0.0",
86
- "workspaces-config": "^2.0.11",
87
- "ws-pkg-list": "^3.0.11",
82
+ "workspaces-config": "^2.0.12",
83
+ "ws-pkg-list": "^3.0.12",
88
84
  "yargs": "<18 >=17.7.2"
89
85
  },
90
86
  "devDependencies": {
91
87
  "@bluelovers/tsconfig": "^2.0.3",
92
- "@types/node": "^26.4.1",
93
- "@yarn-tool/require-resolve": "^4.0.9",
94
- "@yarn-tool/ws-find-up-paths": "^1.0.22"
88
+ "@types/node": "^26.6.5",
89
+ "@yarn-tool/require-resolve": "^4.0.10",
90
+ "@yarn-tool/ws-find-up-paths": "^1.0.23"
95
91
  },
96
- "bundleDependencies": [],
97
92
  "preferGlobal": true,
98
93
  "publishConfig": {},
99
- "gitHead": "74c07cfa7748b838e039b289590ba5d720fcef44"
94
+ "gitHead": "471c63ee11851f0ac3487f23d1c472936f99b460"
100
95
  }