@icebreakers/monorepo-templates 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/assets/Dockerfile +5 -14
  2. package/assets/commitlint.config.ts +3 -1
  3. package/assets/eslint.config.js +14 -2
  4. package/assets/lint-staged.config.js +3 -1
  5. package/assets/package.json +6 -7
  6. package/assets/repoctl.config.ts +3 -30
  7. package/assets/stylelint.config.js +3 -1
  8. package/assets/vitest.config.ts +3 -1
  9. package/assets-data.mjs +0 -1
  10. package/dist/index.mjs +12 -5
  11. package/package.json +1 -1
  12. package/templates/cli/bin/index.js +1 -1
  13. package/templates/cli/package.json +5 -2
  14. package/templates/cli/{tsup.config.ts → tsdown.config.ts} +3 -2
  15. package/templates/client/eslint.config.js +2 -4
  16. package/templates/client/gitignore +0 -1
  17. package/templates/client/package.json +8 -8
  18. package/templates/client/worker-configuration.d.ts +13557 -0
  19. package/templates/client/wrangler.jsonc +3 -0
  20. package/templates/server/eslint.config.js +8 -0
  21. package/templates/server/gitignore +0 -1
  22. package/templates/server/package.json +8 -7
  23. package/templates/server/{tsup.config.ts → tsdown.config.ts} +2 -1
  24. package/templates/server/vitest.config.ts +3 -2
  25. package/templates/server/worker-configuration.d.ts +13557 -0
  26. package/templates/server/wrangler.jsonc +3 -0
  27. package/templates/tsdown/vitest.config.ts +3 -2
  28. package/templates/vitepress/monorepo/commands.md +12 -2
  29. package/templates/vitepress/monorepo/troubleshooting.md +20 -1
  30. package/templates/vitepress/package.json +1 -1
  31. package/templates/vitepress/why/examples/3.npm-basic-package/package-lock.json +605 -2770
  32. package/templates/vitepress/why/examples/3.npm-basic-package/package.json +5 -6
  33. package/templates/vitepress/why/examples/3.npm-basic-package/tsdown.config.ts +16 -0
  34. package/templates/vitepress/why/modern/bundlers.md +11 -0
  35. package/templates/vue-lib/eslint.config.js +1 -3
  36. package/templates/vue-lib/package.json +7 -7
  37. package/templates/vue-lib/test-d/index.test-d.ts +1 -1
  38. package/templates/vue-lib/vitest.config.ts +1 -3
  39. package/assets/tooling/ensure-tooling-built.mjs +0 -24
  40. package/assets/tooling/load-tooling-module.mjs +0 -71
  41. package/templates/vitepress/why/examples/3.npm-basic-package/build.config.ts +0 -24
  42. package/templates/vitepress/why/examples/3.npm-basic-package/tsup.config.ts +0 -16
@@ -19,14 +19,13 @@
19
19
  "dist"
20
20
  ],
21
21
  "scripts": {
22
- "dev": "unbuild --stub",
23
- "build:watch": "tsup --watch --sourcemap",
24
- "build": "tsup"
22
+ "dev": "tsdown --watch --sourcemap",
23
+ "build:watch": "tsdown --watch --sourcemap",
24
+ "build": "tsdown"
25
25
  },
26
26
  "devDependencies": {
27
- "tsup": "^8.5.0",
27
+ "tsdown": "0.21.10",
28
28
  "tsx": "^4.19.4",
29
- "typescript": "^5.8.3",
30
- "unbuild": "^3.5.0"
29
+ "typescript": "^5.8.3"
31
30
  }
32
31
  }
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'tsdown'
2
+
3
+ export default defineConfig({
4
+ entry: ['src/index.ts'],
5
+ shims: true,
6
+ format: ['esm', 'cjs'],
7
+ clean: true,
8
+ dts: true,
9
+ target: 'node18',
10
+ cjsInterop: true,
11
+ outExtensions({ format }) {
12
+ return {
13
+ js: format === 'esm' ? '.mjs' : '.cjs',
14
+ }
15
+ },
16
+ })
@@ -12,6 +12,17 @@
12
12
 
13
13
  当前这个仓库已经把通用类库模板收敛到 `tsdown`,组件库则继续使用 `vite` 库模式。
14
14
 
15
+ ## 过时的方案
16
+
17
+ :::warning 不推荐继续使用
18
+ `tsup` 和 `unbuild` 在这个模板仓库里已经被标记为过时方案,不再作为新项目的推荐构建工具。
19
+ :::
20
+
21
+ - `tsup` 曾经用于部分 TypeScript 包和服务模板,但现在这些模板已经迁移到 `tsdown`。如果旧项目里还有 `tsup.config.ts`,建议改成 `tsdown.config.ts`,并把 `build` / `dev` 脚本切到 `tsdown`。
22
+ - `unbuild` 曾经用于库包开发时的 stub 流程,但这里的新模板已经统一使用 `tsdown --watch` 处理开发构建。新项目不要继续引入 `unbuild`。
23
+
24
+ 新建 TypeScript 类库优先使用 `tsdown` 模板;Vue 组件库继续使用 `vite` 库模式。
25
+
15
26
  ## tsdown
16
27
 
17
28
  本项目当前的通用类库模板是 [tsdown](https://github.com/sonofmagic/monorepo-template/tree/main/templates/tsdown)
@@ -1,6 +1,4 @@
1
- import { loadRepoctlToolingModule } from '../../tooling/load-tooling-module.mjs'
2
-
3
- const { defineEslintConfig } = await loadRepoctlToolingModule()
1
+ import { defineEslintConfig } from 'repoctl/tooling'
4
2
 
5
3
  export default await defineEslintConfig({
6
4
  options: {
@@ -17,11 +17,11 @@
17
17
  "sideEffects": false,
18
18
  "exports": {
19
19
  ".": {
20
- "types": "./dist/src/index.d.ts",
20
+ "types": "./dist/index.d.ts",
21
21
  "default": "./src/index.ts"
22
22
  }
23
23
  },
24
- "types": "./dist/src/index.d.ts",
24
+ "types": "./dist/index.d.ts",
25
25
  "files": [
26
26
  "dist"
27
27
  ],
@@ -33,12 +33,12 @@
33
33
  "lint": "eslint .",
34
34
  "lint:fix": "eslint . --fix",
35
35
  "typecheck": "vue-tsc -b",
36
- "tsd": "pnpm build && tsd --typings dist/src/index.d.ts --files test-d/**/*.test-d.ts"
36
+ "tsd": "pnpm build && tsd --typings dist/index.d.ts --files test-d/**/*.test-d.ts"
37
37
  },
38
38
  "publishConfig": {
39
39
  "exports": {
40
40
  ".": {
41
- "types": "./dist/src/index.d.ts",
41
+ "types": "./dist/index.d.ts",
42
42
  "import": "./dist/index.js",
43
43
  "require": "./dist/index.umd.cjs"
44
44
  },
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "main": "./dist/index.umd.cjs",
48
48
  "module": "./dist/index.js",
49
- "types": "./dist/src/index.d.ts"
49
+ "types": "./dist/index.d.ts"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@vitejs/plugin-vue": "^6.0.6",
@@ -55,7 +55,7 @@
55
55
  "jsdom": "^29.1.1",
56
56
  "vite": "^8.0.10",
57
57
  "vite-plugin-dts": "^5.0.0",
58
- "vue": "^3.5.33",
59
- "vue-tsc": "^3.2.7"
58
+ "vue": "^3.5.34",
59
+ "vue-tsc": "^3.2.8"
60
60
  }
61
61
  }
@@ -1,6 +1,6 @@
1
1
  import type { Component } from 'vue'
2
2
  import { expectAssignable } from 'tsd'
3
3
  // eslint-disable-next-line antfu/no-import-dist
4
- import { HelloWorld } from '../dist/src/index'
4
+ import { HelloWorld } from '../dist/index'
5
5
 
6
6
  expectAssignable<Component>(HelloWorld)
@@ -1,10 +1,8 @@
1
1
  import Vue from '@vitejs/plugin-vue'
2
+ import { defineVitestProjectConfig } from 'repoctl/tooling'
2
3
  import { mergeConfig } from 'vitest/config'
3
- import { loadRepoctlToolingModule } from '../../tooling/load-tooling-module.mjs'
4
4
  import { sharedConfig } from './vite.shared.config'
5
5
 
6
- const { defineVitestProjectConfig } = await loadRepoctlToolingModule()
7
-
8
6
  export default mergeConfig(sharedConfig, {
9
7
  ...await defineVitestProjectConfig({
10
8
  options: {
@@ -1,24 +0,0 @@
1
- import { execSync } from 'node:child_process'
2
- import { existsSync } from 'node:fs'
3
- import path from 'node:path'
4
- import { fileURLToPath } from 'node:url'
5
-
6
- const toolingMarkerPaths = [
7
- ['packages', 'monorepo', 'dist', 'tooling-entry.mjs'],
8
- ['packages', 'repoctl', 'dist', 'tooling-entry.mjs'],
9
- ]
10
-
11
- const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
12
-
13
- export async function ensureToolingBuilt() {
14
- const missingBuildOutput = toolingMarkerPaths.some(segments => !existsSync(path.join(rootDir, ...segments)))
15
-
16
- if (!missingBuildOutput) {
17
- return
18
- }
19
-
20
- execSync('pnpm tooling:build', {
21
- cwd: rootDir,
22
- stdio: 'inherit',
23
- })
24
- }
@@ -1,71 +0,0 @@
1
- import path from 'node:path'
2
- import { fileURLToPath, pathToFileURL } from 'node:url'
3
- import { ensureToolingBuilt } from './ensure-tooling-built.mjs'
4
-
5
- const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
6
-
7
- const toolingEntryPaths = {
8
- monorepo: path.join(rootDir, 'packages', 'monorepo', 'dist', 'tooling-entry.mjs'),
9
- repoctl: path.join(rootDir, 'packages', 'repoctl', 'dist', 'tooling-entry.mjs'),
10
- }
11
-
12
- function getToolingImportSpecifier(entryPath, cacheBust = false) {
13
- const fileUrl = pathToFileURL(entryPath)
14
- return cacheBust ? `${fileUrl.href}?t=${Date.now()}` : fileUrl.href
15
- }
16
-
17
- export function isRecoverableToolingLoadError(error) {
18
- if (!(error instanceof Error)) {
19
- return false
20
- }
21
-
22
- const nodeError = /** @type {NodeJS.ErrnoException} */ (error)
23
- return nodeError.code === 'ERR_MODULE_NOT_FOUND'
24
- || nodeError.code === 'ENOENT'
25
- || error.message.includes('Cannot find module')
26
- || error.message.includes('No such file or directory')
27
- }
28
-
29
- async function importToolingEntry(entryPath, cacheBust = false) {
30
- const specifier = getToolingImportSpecifier(entryPath, cacheBust)
31
- return import(specifier)
32
- }
33
-
34
- export function createToolingModuleLoader({
35
- ensureBuilt = ensureToolingBuilt,
36
- importModule = importToolingEntry,
37
- } = {}) {
38
- return async function loadToolingModule(entryPath) {
39
- await ensureBuilt()
40
-
41
- try {
42
- return await importModule(entryPath)
43
- }
44
- catch (error) {
45
- if (!isRecoverableToolingLoadError(error)) {
46
- throw error
47
- }
48
-
49
- await ensureBuilt()
50
- return importModule(entryPath, true)
51
- }
52
- }
53
- }
54
-
55
- const loadToolingModule = createToolingModuleLoader()
56
-
57
- export function loadMonorepoToolingModule() {
58
- return loadToolingModule(toolingEntryPaths.monorepo)
59
- }
60
-
61
- export async function loadRepoctlToolingModule() {
62
- try {
63
- return await loadToolingModule(toolingEntryPaths.repoctl)
64
- }
65
- catch (error) {
66
- if (!isRecoverableToolingLoadError(error)) {
67
- throw error
68
- }
69
- return loadToolingModule(toolingEntryPaths.monorepo)
70
- }
71
- }
@@ -1,24 +0,0 @@
1
- import path from 'node:path'
2
- import { defineBuildConfig } from 'unbuild'
3
-
4
- export default defineBuildConfig({
5
- // entries: ['./src/index', './src/cli'],
6
- rollup: {
7
- // 内联,相当于 nodeResolve
8
- inlineDependencies: true,
9
- // cjs
10
- emitCJS: true,
11
- // 添加 cjs 注入
12
- cjsBridge: true,
13
- dts: {
14
- // https://github.com/unjs/unbuild/issues/135
15
- respectExternal: false,
16
- },
17
- },
18
- alias: {
19
- // 别名
20
- '@': path.resolve(__dirname, './src'),
21
- },
22
- // dts
23
- declaration: true,
24
- })
@@ -1,16 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- export default defineConfig({
4
- entry: ['src/index.ts'],
5
- shims: true,
6
- format: ['cjs', 'esm'],
7
- clean: true,
8
- dts: true,
9
- cjsInterop: true,
10
- splitting: true,
11
- outExtension({ format }) {
12
- return {
13
- js: `.${format === 'esm' ? 'mjs' : 'cjs'}`,
14
- }
15
- },
16
- })