@yarn-tool/setup-module-env 3.0.23 → 3.0.25
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 +18 -0
- package/lib/preset/tsdx/index.js +2 -2
- package/lib/preset/tsdx/index.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
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.25](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/setup-module-env@3.0.24...@yarn-tool/setup-module-env@3.0.25) (2026-11-03)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @yarn-tool/setup-module-env
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [3.0.24](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/setup-module-env@3.0.23...@yarn-tool/setup-module-env@3.0.24) (2026-11-03)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### ✨ Features
|
|
19
|
+
|
|
20
|
+
* **pkg:** 更新測試腳本與類型定義 ([e82f671](https://github.com/bluelovers/ws-yarn-workspaces/commit/e82f671a516c744c6109375121b3bf3dfd112c4a))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
## [3.0.23](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/setup-module-env@3.0.21...@yarn-tool/setup-module-env@3.0.23) (2026-10-24)
|
|
7
25
|
|
|
8
26
|
|
package/lib/preset/tsdx/index.js
CHANGED
|
@@ -60,8 +60,8 @@ function updatePackageJson(pkg, config) {
|
|
|
60
60
|
if ((0, scripts_1.scriptsEntryIsNoTestSpecified)(pkg.scripts["test"])) {
|
|
61
61
|
pkg.scripts["test"] = void 0;
|
|
62
62
|
}
|
|
63
|
-
(_b = (_r = pkg.scripts)["test"]) !== null && _b !== void 0 ? _b : (_r["test"] = "
|
|
64
|
-
(_c = (_s = pkg.scripts)["test:node"]) !== null && _c !== void 0 ? _c : (_s["test:node"] = "
|
|
63
|
+
(_b = (_r = pkg.scripts)["test"]) !== null && _b !== void 0 ? _b : (_r["test"] = "node --run test:node:bin -- **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts" /* EnumScriptsEntry.NODE_TEST */);
|
|
64
|
+
(_c = (_s = pkg.scripts)["test:node"]) !== null && _c !== void 0 ? _c : (_s["test:node"] = "node --run test:node:bin -- **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts" /* EnumScriptsEntry.NODE_TEST */);
|
|
65
65
|
/**
|
|
66
66
|
* 設定 posttest 腳本,在測試後執行 build
|
|
67
67
|
* Set posttest script to run build after tests
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAoCH,8CAkJC;AAoDD,sBAwCC;AA7QD,sEAAmF;AACnF,yEAA8G;AAG9G,+BAAuC;AACvC,uCAAyC;AACzC,+BAA+B;AAE/B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,iBAAiB,CAAyB,GAAM,EAAE,MAA6B;;;IAE9F;;;OAGG;IACH,MAAA,GAAG,CAAC,OAAO,oCAAX,GAAG,CAAC,OAAO,GAAK,EAAE,EAAC;IAEnB;;;;;;;;OAQG;IACH,IAAI,IAAA,uCAA6B,EAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EACtD,CAAC;QACA,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,YAAA,GAAG,CAAC,OAAO,EAAC,MAAM,wCAAN,MAAM,yIAAiC;IAEnD,YAAA,GAAG,CAAC,OAAO,EAAC,W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C;IAC7C,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,sBAAsB,CAAC;IACjD,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,GAAG,kBAAkB,CAAC;IAE9C;;;;;;OAMG;IACH,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IAEnC;;;OAGG;IACH,YAAA,GAAG,CAAC,OAAO,EAAC,gBAAgB,wCAAhB,gBAAgB,IAAM,gBAAgB,EAAC;IAEnD;;;OAGG;IACH,MAAA,GAAG,CAAC,QAAQ,oCAAZ,GAAG,CAAC,QAAQ,GAAK,EAAE,EAAC;IAEpB;;;;;;OAMG;IACH,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,yCAAkB,EAC5C,CAAC;QACA,GAAG,CAAC,QAAQ,CAAC,IAAI,yCAAkB,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,IAAA,oBAAc,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAA;AACX,CAAC;AAgCD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,KAAK,CAAyB,MAA4B;IAEzE,IAAI,EACH,GAAG,EACH,QAAQ,EACR,SAAS,GACT,GAAG,MAAM,CAAC;IAEX;;;OAGG;IACH,GAAG,GAAG,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAErC;;;;;;OAMG;IACH,QAAQ,GAAG;QACR,GAAG,uCAA0B;QAC/B,GAAG,QAAQ;KACX,CAAC;IAEF;;;;;;OAMG;IACH,IAAA,wBAAa,EAAC,IAAA,cAAO,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAEzC,OAAO;QACN,GAAG,MAAM;QACT,GAAG;QACH,QAAQ;KACR,CAAA;AACF,CAAC","sourcesContent":["/**\n * tsdx 專案設定模組\n * tsdx project setup module\n *\n * 此模組提供設定 tsdx 專案的核心功能,包括更新 package.json、\n * 設定靜態檔案映射以及主要設定函式。\n * This module provides core functionality for setting up tsdx projects,\n * including updating package.json, configuring static file mappings,\n * and the main setup function.\n */\n\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { IFindRootReturnType } from '@yarn-tool/find-root';\nimport { _Key, IStaticFilesMapArray } from '@yarn-tool/static-file/lib/types';\nimport { defaultCopyStaticFilesTsdx } from '@yarn-tool/static-file/lib/const-tsdx';\nimport { EnumScriptsEntry, scriptsEntryIsNoTestSpecified } from '@yarn-tool/pkg-entry-util/lib/field/scripts';\nimport { deleteValue } from 'dot-values2';\nimport { EnumTsdx } from './const';\nimport { fixTsdxPackage } from './fix';\nimport { ensureDirSync } from 'fs-extra';\nimport { resolve } from 'path';\n\n/**\n * 更新 package.json 以符合 tsdx 專案標準\n * Update package.json to conform to tsdx project standards\n *\n * 此函式會設定以下內容:\n * This function configures the following:\n *\n * - scripts: test, posttest, build, build:dts:bundle, build:tsdx 等\n * scripts: test, posttest, build, build:dts:bundle, build:tsdx, etc.\n *\n * - main/module/types: 設定輸出檔案路徑\n * main/module/types: configure output file paths\n *\n * - exports: 設定模組匯出映射\n * exports: configure module export mappings\n *\n * - keywords: 添加 tsdx 標識關鍵字\n * keywords: add tsdx identifier keyword\n *\n * @param pkg - 要更新的 package.json 物件 / package.json object to update\n * @param config - 設定選項 (可選) / configuration options (optional)\n * @returns 更新後的 package.json 物件 / Updated package.json object\n */\nexport function updatePackageJson<P extends IPackageJson>(pkg: P, config?: ISetupTsdxOptions<P>)\n{\n\t/**\n\t * 確保 scripts 欄位存在\n\t * Ensure scripts field exists\n\t */\n\tpkg.scripts ??= {};\n\n\t/**\n\t * 如果 test 腳本未指定或為空,清除並設定預設值\n\t * If test script is not specified or empty, clear and set default\n\t *\n\t * 先設為 undefined 才能讓下一行的 ??= 生效,\n\t * 因為 \"no test specified\" 這類佔位字串並非 nullish\n\t * Setting it to undefined first lets the following ??= take effect,\n\t * because placeholder strings like \"no test specified\" are not nullish\n\t */\n\tif (scriptsEntryIsNoTestSpecified(pkg.scripts[\"test\"]))\n\t{\n\t\tpkg.scripts[\"test\"] = void 0;\n\t}\n\n\tpkg.scripts[\"test\"] ??= EnumScriptsEntry.NODE_TEST;\n\n\tpkg.scripts[\"test:node\"] ??= EnumScriptsEntry.NODE_TEST;\n\n\t/**\n\t * 設定 posttest 腳本,在測試後執行 build\n\t * Set posttest script to run build after tests\n\t */\n\tpkg.scripts[\"posttest\"] ??= \"pnpm run build\";\n\n\t/**\n\t * 如果 build 腳本不包含 tsdx build,則設定新的 build 腳本\n\t * If build script doesn't include tsdx build, set new build script\n\t *\n\t * 以 includes 檢查而非直接覆寫,避免破壞已含 tsdx build 的自訂腳本\n\t * Checks with includes instead of overwriting directly, so custom scripts already invoking tsdx build are preserved\n\t */\n\tif (!pkg.scripts[\"build\"]?.includes('run build:tsdx'))\n\t{\n\t\tpkg.scripts[\"build\"] = EnumScriptsEntry.BUILD_TSDX_AND_DTS;\n\t}\n\n\t/**\n\t * 設定 TypeScript 宣告檔案打包腳本\n\t * Set TypeScript declaration file bundling script\n\t */\n\tpkg.scripts[\"build:dts:bundle\"] ??= EnumScriptsEntry.BUILD_DTS_BUNDLE;\n\n\t/**\n\t * 設定 tsdx build 腳本,目標為 node 環境\n\t * Set tsdx build script targeting node environment\n\t */\n\tpkg.scripts[\"build:tsdx\"] ??= EnumScriptsEntry.BUILD_TSDX;\n\n\t/**\n\t * 設定複製宣告檔案的腳本 (Windows 語法)\n\t * Set declaration file copy script (Windows syntax)\n\t */\n\tpkg.scripts[\"build:dts:copy\"] ??= EnumScriptsEntry.BUILD_DTS_COPY;\n\n\t/**\n\t * 設定 TypeScript 宣告檔案輸出腳本\n\t * Set TypeScript declaration file emit script\n\t */\n\tpkg.scripts[\"build:dts:tsc:emit\"] ??= EnumScriptsEntry.BUILD_DTS_TSC_EMIT;\n\n\t/**\n\t * 設定完整的 dts 建置腳本\n\t * Set complete dts build script\n\t */\n\tpkg.scripts[\"build:dts:tsc\"] ??= EnumScriptsEntry.BUILD_DTS_TSC;\n\n\t/**\n\t * 設定模組入口點\n\t * Set module entry points\n\t *\n\t * 這裡刻意直接賦值而非 ??=,確保與 tsdx 的實際輸出檔名保持一致\n\t * Assigned directly instead of via ??= to stay in sync with tsdx's actual output file names\n\t */\n\tpkg.main = \"dist/index.cjs\";\n\tpkg.module = \"dist/index.esm.mjs\";\n\tpkg.types = pkg.typings = \"dist/index.d.ts\";\n\n\t/**\n\t * 設定 unpkg CDN 入口點\n\t * Set unpkg CDN entry point\n\t */\n\tpkg.unpkg ??= \"dist/index.umd.production.min.cjs\";\n\n\t/**\n\t * 設定 exports 欄位,定義模組匯出映射\n\t * Set exports field, defining module export mappings\n\t *\n\t * types/import/require 一律覆寫,因為必須與 main/module/types 的輸出檔名完全對應,\n\t * 否則 Node.js 的條件匯出會指向過期的舊檔\n\t * types/import/require are always overwritten because they must match the output names of\n\t * main/module/types exactly, otherwise Node.js conditional exports would point at stale files\n\t */\n\tpkg.exports ??= {};\n\tpkg.exports['.'] ??= {};\n\tpkg.exports['.'].types = \"./dist/index.d.ts\";\n\tpkg.exports['.'].import = \"./dist/index.esm.mjs\";\n\tpkg.exports['.'].require = \"./dist/index.cjs\";\n\n\t/**\n\t * 允許直接存取 src 目錄下的檔案\n\t * Allow direct access to files under src directory\n\t *\n\t * 直接覆寫而非 ??=,確保 wildcard 匯出格式始終一致\n\t * Overwritten rather than via ??= so the wildcard export format always stays consistent\n\t */\n\tpkg.exports['./src/*'] = './src/*';\n\n\t/**\n\t * 匯出 package.json 本身\n\t * Export package.json itself\n\t */\n\tpkg.exports['./package.json'] ??= './package.json';\n\n\t/**\n\t * 確保 keywords 欄位存在\n\t * Ensure keywords field exists\n\t */\n\tpkg.keywords ??= [];\n\n\t/**\n\t * 添加 tsdx 標識關鍵字(如果尚未存在)\n\t * Add tsdx identifier keyword if not already present\n\t *\n\t * 重複的 keywords 會讓 isTsdxPackage 的判斷失去意義,故先檢查再加入\n\t * Duplicate keywords would undermine the check in isTsdxPackage, so it is added only when absent\n\t */\n\tif (!pkg.keywords.includes(EnumTsdx.keyword))\n\t{\n\t\tpkg.keywords.push(EnumTsdx.keyword);\n\t}\n\n\t/**\n\t * 呼叫 fixTsdxPackage 進行額外的修復\n\t * Call fixTsdxPackage for additional fixes\n\t */\n\tfixTsdxPackage(pkg, config);\n\n\treturn pkg\n}\n\n/**\n * tsdx 設定選項介面\n * tsdx setup options interface\n *\n * @template P - package.json 類型 / package.json type\n */\nexport interface ISetupTsdxOptions<P extends IPackageJson>\n{\n\t/** 目標目錄路徑 / Target directory path */\n\ttargetDir: string,\n\n\t/** package.json 物件 / package.json object */\n\tpkg: P,\n\n\t/** 工作區根目錄資訊 / Workspace root directory information */\n\trootData: IFindRootReturnType,\n\n\t/** 靜態檔案映射表 / Static file mapping table */\n\tfile_map: IStaticFilesMapArray<string>,\n\n\t/** README 檔案名稱 / README file name */\n\tmdFile: string,\n\n\t/** 是否存在 README 檔案 / Whether README file exists */\n\texistsReadme: boolean,\n\n\t/** 是否為已存在的專案 / Whether it's an existing project */\n\toldExists: boolean,\n}\n\n/**\n * 設定 tsdx 專案的主要函式\n * Main function for setting up tsdx project\n *\n * 此函式執行以下操作:\n * This function performs the following operations:\n *\n * 1. 更新 package.json 設定\n * Update package.json configuration\n *\n * 2. 合併預設與自訂的靜態檔案映射\n * Merge default and custom static file mappings\n *\n * 3. 確保 src 目錄存在\n * Ensure src directory exists\n *\n * @template P - package.json 類型 / package.json type\n * @param config - 設定選項 / Configuration options\n * @returns 包含更新後設定的物件 / Object containing updated configuration\n */\nexport function setup<P extends IPackageJson>(config: ISetupTsdxOptions<P>)\n{\n\tlet {\n\t\tpkg,\n\t\tfile_map,\n\t\ttargetDir,\n\t} = config;\n\n\t/**\n\t * 更新 package.json\n\t * Update package.json\n\t */\n\tpkg = updatePackageJson(pkg, config);\n\n\t/**\n\t * 合併預設與自訂的靜態檔案映射\n\t * Merge default and custom static file mappings\n\t *\n\t * 預設項排在前方,自訂項排在後方,讓呼叫端可用相同目標路徑覆寫預設值\n\t * Default entries come first and custom entries follow, so callers can override a default via the same target path\n\t */\n\tfile_map = [\n ...defaultCopyStaticFilesTsdx,\n\t\t...file_map,\n\t];\n\n\t/**\n\t * 確保 src 目錄存在\n\t * Ensure src directory exists\n\t *\n\t * tsdx 假定來源碼位於 src/,新專案若缺少此目錄會導致後續 build 失敗\n\t * tsdx assumes sources live under src/; a new project missing this directory would fail the subsequent build\n\t */\n\tensureDirSync(resolve(targetDir, 'src'));\n\n\treturn {\n\t\t...config,\n\t\tpkg,\n\t\tfile_map,\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAoCH,8CAkJC;AAoDD,sBAwCC;AA7QD,sEAAmF;AACnF,yEAA8G;AAG9G,+BAAuC;AACvC,uCAAyC;AACzC,+BAA+B;AAE/B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,iBAAiB,CAAyB,GAAM,EAAE,MAA6B;;;IAE9F;;;OAGG;IACH,MAAA,GAAG,CAAC,OAAO,oCAAX,GAAG,CAAC,OAAO,GAAK,EAAE,EAAC;IAEnB;;;;;;;;OAQG;IACH,IAAI,IAAA,uCAA6B,EAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EACtD,CAAC;QACA,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,YAAA,GAAG,CAAC,OAAO,EAAC,MAAM,wCAAN,MAAM,kIAAiC;IAEnD,YAAA,GAAG,CAAC,OAAO,EAAC,WAAW,wCAAX,WAAW,kIAAiC;IAExD;;;OAGG;IACH,YAAA,GAAG,CAAC,OAAO,EAAC,UAAU,wCAAV,UAAU,IAAM,gBAAgB,EAAC;IAE7C;;;;;;OAMG;IACH,IAAI,CAAC,CAAA,MAAA,GAAG,CAAC,OAAO,CAAC,O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OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IAEnC;;;OAGG;IACH,YAAA,GAAG,CAAC,OAAO,EAAC,gBAAgB,wCAAhB,gBAAgB,IAAM,gBAAgB,EAAC;IAEnD;;;OAGG;IACH,MAAA,GAAG,CAAC,QAAQ,oCAAZ,GAAG,CAAC,QAAQ,GAAK,EAAE,EAAC;IAEpB;;;;;;OAMG;IACH,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,yCAAkB,EAC5C,CAAC;QACA,GAAG,CAAC,QAAQ,CAAC,IAAI,yCAAkB,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,IAAA,oBAAc,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAA;AACX,CAAC;AAgCD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,KAAK,CAAyB,MAA4B;IAEzE,IAAI,EACH,GAAG,EACH,QAAQ,EACR,SAAS,GACT,GAAG,MAAM,CAAC;IAEX;;;OAGG;IACH,GAAG,GAAG,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAErC;;;;;;OAMG;IACH,QAAQ,GAAG;QACR,GAAG,uCAA0B;QAC/B,GAAG,QAAQ;KACX,CAAC;IAEF;;;;;;OAMG;IACH,IAAA,wBAAa,EAAC,IAAA,cAAO,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAEzC,OAAO;QACN,GAAG,MAAM;QACT,GAAG;QACH,QAAQ;KACR,CAAA;AACF,CAAC","sourcesContent":["/**\n * tsdx 專案設定模組\n * tsdx project setup module\n *\n * 此模組提供設定 tsdx 專案的核心功能,包括更新 package.json、\n * 設定靜態檔案映射以及主要設定函式。\n * This module provides core functionality for setting up tsdx projects,\n * including updating package.json, configuring static file mappings,\n * and the main setup function.\n */\n\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { IFindRootReturnType } from '@yarn-tool/find-root';\nimport { _Key, IStaticFilesMapArray } from '@yarn-tool/static-file/lib/types';\nimport { defaultCopyStaticFilesTsdx } from '@yarn-tool/static-file/lib/const-tsdx';\nimport { EnumScriptsEntry, scriptsEntryIsNoTestSpecified } from '@yarn-tool/pkg-entry-util/lib/field/scripts';\nimport { deleteValue } from 'dot-values2';\nimport { EnumTsdx } from './const';\nimport { fixTsdxPackage } from './fix';\nimport { ensureDirSync } from 'fs-extra';\nimport { resolve } from 'path';\n\n/**\n * 更新 package.json 以符合 tsdx 專案標準\n * Update package.json to conform to tsdx project standards\n *\n * 此函式會設定以下內容:\n * This function configures the following:\n *\n * - scripts: test, posttest, build, build:dts:bundle, build:tsdx 等\n * scripts: test, posttest, build, build:dts:bundle, build:tsdx, etc.\n *\n * - main/module/types: 設定輸出檔案路徑\n * main/module/types: configure output file paths\n *\n * - exports: 設定模組匯出映射\n * exports: configure module export mappings\n *\n * - keywords: 添加 tsdx 標識關鍵字\n * keywords: add tsdx identifier keyword\n *\n * @param pkg - 要更新的 package.json 物件 / package.json object to update\n * @param config - 設定選項 (可選) / configuration options (optional)\n * @returns 更新後的 package.json 物件 / Updated package.json object\n */\nexport function updatePackageJson<P extends IPackageJson>(pkg: P, config?: ISetupTsdxOptions<P>)\n{\n\t/**\n\t * 確保 scripts 欄位存在\n\t * Ensure scripts field exists\n\t */\n\tpkg.scripts ??= {};\n\n\t/**\n\t * 如果 test 腳本未指定或為空,清除並設定預設值\n\t * If test script is not specified or empty, clear and set default\n\t *\n\t * 先設為 undefined 才能讓下一行的 ??= 生效,\n\t * 因為 \"no test specified\" 這類佔位字串並非 nullish\n\t * Setting it to undefined first lets the following ??= take effect,\n\t * because placeholder strings like \"no test specified\" are not nullish\n\t */\n\tif (scriptsEntryIsNoTestSpecified(pkg.scripts[\"test\"]))\n\t{\n\t\tpkg.scripts[\"test\"] = void 0;\n\t}\n\n\tpkg.scripts[\"test\"] ??= EnumScriptsEntry.NODE_TEST;\n\n\tpkg.scripts[\"test:node\"] ??= EnumScriptsEntry.NODE_TEST;\n\n\t/**\n\t * 設定 posttest 腳本,在測試後執行 build\n\t * Set posttest script to run build after tests\n\t */\n\tpkg.scripts[\"posttest\"] ??= \"pnpm run build\";\n\n\t/**\n\t * 如果 build 腳本不包含 tsdx build,則設定新的 build 腳本\n\t * If build script doesn't include tsdx build, set new build script\n\t *\n\t * 以 includes 檢查而非直接覆寫,避免破壞已含 tsdx build 的自訂腳本\n\t * Checks with includes instead of overwriting directly, so custom scripts already invoking tsdx build are preserved\n\t */\n\tif (!pkg.scripts[\"build\"]?.includes('run build:tsdx'))\n\t{\n\t\tpkg.scripts[\"build\"] = EnumScriptsEntry.BUILD_TSDX_AND_DTS;\n\t}\n\n\t/**\n\t * 設定 TypeScript 宣告檔案打包腳本\n\t * Set TypeScript declaration file bundling script\n\t */\n\tpkg.scripts[\"build:dts:bundle\"] ??= EnumScriptsEntry.BUILD_DTS_BUNDLE;\n\n\t/**\n\t * 設定 tsdx build 腳本,目標為 node 環境\n\t * Set tsdx build script targeting node environment\n\t */\n\tpkg.scripts[\"build:tsdx\"] ??= EnumScriptsEntry.BUILD_TSDX;\n\n\t/**\n\t * 設定複製宣告檔案的腳本 (Windows 語法)\n\t * Set declaration file copy script (Windows syntax)\n\t */\n\tpkg.scripts[\"build:dts:copy\"] ??= EnumScriptsEntry.BUILD_DTS_COPY;\n\n\t/**\n\t * 設定 TypeScript 宣告檔案輸出腳本\n\t * Set TypeScript declaration file emit script\n\t */\n\tpkg.scripts[\"build:dts:tsc:emit\"] ??= EnumScriptsEntry.BUILD_DTS_TSC_EMIT;\n\n\t/**\n\t * 設定完整的 dts 建置腳本\n\t * Set complete dts build script\n\t */\n\tpkg.scripts[\"build:dts:tsc\"] ??= EnumScriptsEntry.BUILD_DTS_TSC;\n\n\t/**\n\t * 設定模組入口點\n\t * Set module entry points\n\t *\n\t * 這裡刻意直接賦值而非 ??=,確保與 tsdx 的實際輸出檔名保持一致\n\t * Assigned directly instead of via ??= to stay in sync with tsdx's actual output file names\n\t */\n\tpkg.main = \"dist/index.cjs\";\n\tpkg.module = \"dist/index.esm.mjs\";\n\tpkg.types = pkg.typings = \"dist/index.d.ts\";\n\n\t/**\n\t * 設定 unpkg CDN 入口點\n\t * Set unpkg CDN entry point\n\t */\n\tpkg.unpkg ??= \"dist/index.umd.production.min.cjs\";\n\n\t/**\n\t * 設定 exports 欄位,定義模組匯出映射\n\t * Set exports field, defining module export mappings\n\t *\n\t * types/import/require 一律覆寫,因為必須與 main/module/types 的輸出檔名完全對應,\n\t * 否則 Node.js 的條件匯出會指向過期的舊檔\n\t * types/import/require are always overwritten because they must match the output names of\n\t * main/module/types exactly, otherwise Node.js conditional exports would point at stale files\n\t */\n\tpkg.exports ??= {};\n\tpkg.exports['.'] ??= {};\n\tpkg.exports['.'].types = \"./dist/index.d.ts\";\n\tpkg.exports['.'].import = \"./dist/index.esm.mjs\";\n\tpkg.exports['.'].require = \"./dist/index.cjs\";\n\n\t/**\n\t * 允許直接存取 src 目錄下的檔案\n\t * Allow direct access to files under src directory\n\t *\n\t * 直接覆寫而非 ??=,確保 wildcard 匯出格式始終一致\n\t * Overwritten rather than via ??= so the wildcard export format always stays consistent\n\t */\n\tpkg.exports['./src/*'] = './src/*';\n\n\t/**\n\t * 匯出 package.json 本身\n\t * Export package.json itself\n\t */\n\tpkg.exports['./package.json'] ??= './package.json';\n\n\t/**\n\t * 確保 keywords 欄位存在\n\t * Ensure keywords field exists\n\t */\n\tpkg.keywords ??= [];\n\n\t/**\n\t * 添加 tsdx 標識關鍵字(如果尚未存在)\n\t * Add tsdx identifier keyword if not already present\n\t *\n\t * 重複的 keywords 會讓 isTsdxPackage 的判斷失去意義,故先檢查再加入\n\t * Duplicate keywords would undermine the check in isTsdxPackage, so it is added only when absent\n\t */\n\tif (!pkg.keywords.includes(EnumTsdx.keyword))\n\t{\n\t\tpkg.keywords.push(EnumTsdx.keyword);\n\t}\n\n\t/**\n\t * 呼叫 fixTsdxPackage 進行額外的修復\n\t * Call fixTsdxPackage for additional fixes\n\t */\n\tfixTsdxPackage(pkg, config);\n\n\treturn pkg\n}\n\n/**\n * tsdx 設定選項介面\n * tsdx setup options interface\n *\n * @template P - package.json 類型 / package.json type\n */\nexport interface ISetupTsdxOptions<P extends IPackageJson>\n{\n\t/** 目標目錄路徑 / Target directory path */\n\ttargetDir: string,\n\n\t/** package.json 物件 / package.json object */\n\tpkg: P,\n\n\t/** 工作區根目錄資訊 / Workspace root directory information */\n\trootData: IFindRootReturnType,\n\n\t/** 靜態檔案映射表 / Static file mapping table */\n\tfile_map: IStaticFilesMapArray<string>,\n\n\t/** README 檔案名稱 / README file name */\n\tmdFile: string,\n\n\t/** 是否存在 README 檔案 / Whether README file exists */\n\texistsReadme: boolean,\n\n\t/** 是否為已存在的專案 / Whether it's an existing project */\n\toldExists: boolean,\n}\n\n/**\n * 設定 tsdx 專案的主要函式\n * Main function for setting up tsdx project\n *\n * 此函式執行以下操作:\n * This function performs the following operations:\n *\n * 1. 更新 package.json 設定\n * Update package.json configuration\n *\n * 2. 合併預設與自訂的靜態檔案映射\n * Merge default and custom static file mappings\n *\n * 3. 確保 src 目錄存在\n * Ensure src directory exists\n *\n * @template P - package.json 類型 / package.json type\n * @param config - 設定選項 / Configuration options\n * @returns 包含更新後設定的物件 / Object containing updated configuration\n */\nexport function setup<P extends IPackageJson>(config: ISetupTsdxOptions<P>)\n{\n\tlet {\n\t\tpkg,\n\t\tfile_map,\n\t\ttargetDir,\n\t} = config;\n\n\t/**\n\t * 更新 package.json\n\t * Update package.json\n\t */\n\tpkg = updatePackageJson(pkg, config);\n\n\t/**\n\t * 合併預設與自訂的靜態檔案映射\n\t * Merge default and custom static file mappings\n\t *\n\t * 預設項排在前方,自訂項排在後方,讓呼叫端可用相同目標路徑覆寫預設值\n\t * Default entries come first and custom entries follow, so callers can override a default via the same target path\n\t */\n\tfile_map = [\n ...defaultCopyStaticFilesTsdx,\n\t\t...file_map,\n\t];\n\n\t/**\n\t * 確保 src 目錄存在\n\t * Ensure src directory exists\n\t *\n\t * tsdx 假定來源碼位於 src/,新專案若缺少此目錄會導致後續 build 失敗\n\t * tsdx assumes sources live under src/; a new project missing this directory would fail the subsequent build\n\t */\n\tensureDirSync(resolve(targetDir, 'src'));\n\n\treturn {\n\t\t...config,\n\t\tpkg,\n\t\tfile_map,\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarn-tool/setup-module-env",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.25",
|
|
4
4
|
"description": "用於設定 tsdx 專案環境的工具,自動配置 package.json 與靜態檔案 (Tool for setting up tsdx project environment, auto-configuring package.json and static files)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tsdx",
|
|
@@ -65,14 +65,14 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@ts-type/package-dts": "^3.0.14",
|
|
68
|
-
"@yarn-tool/find-root": "^2.0.
|
|
69
|
-
"@yarn-tool/pkg-entry-util": "^3.0.
|
|
70
|
-
"@yarn-tool/static-file": "^3.0.
|
|
68
|
+
"@yarn-tool/find-root": "^2.0.29",
|
|
69
|
+
"@yarn-tool/pkg-entry-util": "^3.0.22",
|
|
70
|
+
"@yarn-tool/static-file": "^3.0.27",
|
|
71
71
|
"dot-values2": "^2.0.7",
|
|
72
72
|
"tslib": ">=2.8.1"
|
|
73
73
|
},
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"access": "public"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "799385bf39d7db26d0a2ee91c0c4ee9002f1035d"
|
|
78
78
|
}
|