@_tc/template-core 0.3.0 → 0.3.1

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.
@@ -27,6 +27,7 @@ This workspace is the TemplateCore npm package repository (`@_tc/template-core`)
27
27
  3. Generate the smallest working slice first: config, entry, controller, router, model.
28
28
  4. Keep keys stable. Array merge and project overrides depend on `key`.
29
29
  5. Prefer CommonJS `.js` for generated consumer examples unless the existing consumer app already uses TypeScript.
30
+ 6. If the existing consumer app declares `"type": "module"`, do not generate `.js` backend convention files with `module.exports` under that scope. Use `.ts` convention files, or add a local `package.json` with `{ "type": "commonjs" }` under `app/`, `config/`, or `models/` before generating CommonJS `.js` files.
30
31
 
31
32
  ## TemplateCore Conventions
32
33
 
package/AGENT_README.md CHANGED
@@ -124,6 +124,20 @@ models/**/*.(js|ts) -> 内置 project service 读取的项目模
124
124
  ssr/apps/**/*.entry.(js|jsx|ts|tsx) -> SSR 页面入口,可选
125
125
  ```
126
126
 
127
+ ### 3.1 后端约定文件的模块格式
128
+
129
+ `@_tc/template-core` 包本身提供 ESM/CJS 入口,使用方项目可以用 `import` 引入包。但 `config/`、`app/`、`models/` 里的后端约定文件由 loader 扫描真实文件路径后同步加载,当前按 `require()` 语义处理,并只扫描 `.js` / `.ts`。
130
+
131
+ 后端约定文件需要满足 CommonJS 加载语义:
132
+
133
+ - 普通 CommonJS 项目可以使用 `.js` + `module.exports`。
134
+ - TypeScript 项目可以使用 `.ts` + `export default`,loader 会把 `.ts` 按 CommonJS 方式转译后加载。
135
+ - 如果业务项目声明了 `"type": "module"`,不要把 `.js` 后端约定文件写成原生 ESM 作为稳定用法,也不要在该作用域下使用 `.js` + `module.exports`。
136
+ - `"type": "module"` 项目如需保留 `.js` 后端约定文件,请在 `app/`、`config/` 或 `models/` 下增加局部 `package.json`:`{ "type": "commonjs" }`。
137
+ - `.mjs`、顶层 `await`、依赖原生 ESM 语义的后端约定文件当前不作为支持约定。
138
+
139
+ 推荐分层:启动脚本、构建脚本和前端代码可以使用 ESM;`config/`、`app/`、`models/` 里的后端约定文件保持 CommonJS 加载语义。
140
+
127
141
  常用后端类型:
128
142
 
129
143
  | 类型 | 使用场景 |
package/README.md CHANGED
@@ -656,6 +656,20 @@ config/config.{env}.(js|ts) -> app.config
656
656
  models/**/*.(js|ts) -> 内置 project service 按需读取的项目模型配置
657
657
  ```
658
658
 
659
+ ### 后端约定文件的模块格式
660
+
661
+ TemplateCore 包本身提供 ESM/CJS 入口,业务项目可以用 `import` 引入包。但上面这些后端约定文件是由 loader 扫描真实文件路径后同步加载的,当前按 `require()` 语义处理,并只扫描 `.js` / `.ts`。
662
+
663
+ 因此后端约定文件需要满足 CommonJS 加载语义:
664
+
665
+ - 普通 CommonJS 项目可以使用 `.js` + `module.exports`。
666
+ - TypeScript 项目可以使用 `.ts` + `export default`,loader 会把 `.ts` 按 CommonJS 方式转译后加载。
667
+ - 如果业务项目声明了 `"type": "module"`,不要把 `.js` 后端约定文件写成原生 ESM 作为稳定用法,也不要在该作用域下使用 `.js` + `module.exports`。
668
+ - `"type": "module"` 项目如需保留 `.js` 后端约定文件,请在 `app/`、`config/` 或 `models/` 下增加局部 `package.json`:`{ "type": "commonjs" }`。
669
+ - `.mjs`、顶层 `await`、依赖原生 ESM 语义的后端约定文件当前不作为支持约定。
670
+
671
+ 推荐分层:启动脚本、构建脚本和前端代码可以使用 ESM;`config/`、`app/`、`models/` 里的后端约定文件保持 CommonJS 加载语义。
672
+
659
673
  内置扩展:
660
674
 
661
675
  - `app.extends.$fetch`:Node 侧基于 `fetch` 的 axios 风格请求实例,支持 `get/post/put/patch/delete` 和 `create(config)`。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_tc/template-core",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A full-stack TypeScript admin framework package powered by Koa, React, and Vite",
5
5
  "types": "./types/index.d.ts",
6
6
  "exports": {