@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.
- package/assets/Dockerfile +5 -14
- package/assets/commitlint.config.ts +3 -1
- package/assets/eslint.config.js +14 -2
- package/assets/lint-staged.config.js +3 -1
- package/assets/package.json +6 -7
- package/assets/repoctl.config.ts +3 -30
- package/assets/stylelint.config.js +3 -1
- package/assets/vitest.config.ts +3 -1
- package/assets-data.mjs +0 -1
- package/dist/index.mjs +12 -5
- package/package.json +1 -1
- package/templates/cli/bin/index.js +1 -1
- package/templates/cli/package.json +5 -2
- package/templates/cli/{tsup.config.ts → tsdown.config.ts} +3 -2
- package/templates/client/eslint.config.js +2 -4
- package/templates/client/gitignore +0 -1
- package/templates/client/package.json +8 -8
- package/templates/client/worker-configuration.d.ts +13557 -0
- package/templates/client/wrangler.jsonc +3 -0
- package/templates/server/eslint.config.js +8 -0
- package/templates/server/gitignore +0 -1
- package/templates/server/package.json +8 -7
- package/templates/server/{tsup.config.ts → tsdown.config.ts} +2 -1
- package/templates/server/vitest.config.ts +3 -2
- package/templates/server/worker-configuration.d.ts +13557 -0
- package/templates/server/wrangler.jsonc +3 -0
- package/templates/tsdown/vitest.config.ts +3 -2
- package/templates/vitepress/monorepo/commands.md +12 -2
- package/templates/vitepress/monorepo/troubleshooting.md +20 -1
- package/templates/vitepress/package.json +1 -1
- package/templates/vitepress/why/examples/3.npm-basic-package/package-lock.json +605 -2770
- package/templates/vitepress/why/examples/3.npm-basic-package/package.json +5 -6
- package/templates/vitepress/why/examples/3.npm-basic-package/tsdown.config.ts +16 -0
- package/templates/vitepress/why/modern/bundlers.md +11 -0
- package/templates/vue-lib/eslint.config.js +1 -3
- package/templates/vue-lib/package.json +7 -7
- package/templates/vue-lib/test-d/index.test-d.ts +1 -1
- package/templates/vue-lib/vitest.config.ts +1 -3
- package/assets/tooling/ensure-tooling-built.mjs +0 -24
- package/assets/tooling/load-tooling-module.mjs +0 -71
- package/templates/vitepress/why/examples/3.npm-basic-package/build.config.ts +0 -24
- 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": "
|
|
23
|
-
"build:watch": "
|
|
24
|
-
"build": "
|
|
22
|
+
"dev": "tsdown --watch --sourcemap",
|
|
23
|
+
"build:watch": "tsdown --watch --sourcemap",
|
|
24
|
+
"build": "tsdown"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"
|
|
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)
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"types": "./dist/
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
21
|
"default": "./src/index.ts"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
"types": "./dist/
|
|
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/
|
|
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/
|
|
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/
|
|
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.
|
|
59
|
-
"vue-tsc": "^3.2.
|
|
58
|
+
"vue": "^3.5.34",
|
|
59
|
+
"vue-tsc": "^3.2.8"
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -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
|
-
})
|