midwayjs / midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
https://www.midwayjs.org/
MIT License
7.4k stars 577 forks source link

mindway-bin build设置outDir合tsconfig中的outDir不同,构建完成不能正常删除.mwcc-cache #1716

Open tyouzu1 opened 2 years ago

tyouzu1 commented 2 years ago

需要拷贝一些文件,看了源码,copyFile 的targetDir是outDir,所以通过 outDir设置,mindway-bin build 设置outDir后 midway-bin build --outDir=dist/node/src/server

构建完成不能正常删除.mwcc-cache, 如图,

image

看起来应该是 【cli-plugin-buildmwcc 】两边文件对于 outdir 取值不一致的问题

如果可以改的话麻烦看下pr https://github.com/midwayjs/cli/pull/264

package.json

{
  "dependencies": {
    "@midwayjs/bootstrap": "^2.14.6",
    "@midwayjs/core": "^2.14.6",
    "@midwayjs/decorator": "^2.14.0",
    "@midwayjs/koa": "^2.14.6",
    "@types/react": "^17.0.39",
    "@types/react-dom": "^17.0.11",
    "koa-bodyparser": "^4.3.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "devDependencies": {
    "@midwayjs/cli": "^1.2.99",
  },
  "engines": {
    "node": ">=14.0.0"
  },
  "scripts": {
    ***//这里
    "build:server": "cross-env NODE_ENV=production midway-bin build -c --srcDir=src/server --tsConfig=src/server/tsconfig.json --outDir=dist/node/src/server"
  },
  "midway-bin-clean": [
    ".vscode/.tsbuildinfo",
    "dist/node"
  ],
  "midway-luckyeye": {
    "packages": [
      "midway_v2"
    ]
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "author": "anonymous",
  "license": "MIT"
}
{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "inlineSourceMap": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "stripInternal": true,
    "skipLibCheck": true,
    "pretty": true,
    "declaration": true,
    "allowJs": false,
    "rootDir": ".",
    "typeRoots": [
      "./typings",
      "./node_modules/@types"
    ],
    "outDir": "dist/node",  // 这里目录改了后,没法构建
    "composite": true,
    "baseUrl": "./",
    "paths": {
      "@/*": ["./*"],
      "~/*": ["../*"]
    }
  },
  "exclude": [
    "**/**/*.tsx",
    "**/test/*"
  ],
  "references": [{
      "path": "../common"
    },
    {
      "path": "../browser"
    }
  ],
  "ts-node": {
    "compilerOptions": {
      "module": "commonjs",
      "require": ["tsconfig-paths/register"]
    }
  }
}

cli-plugin-build/src/index.ts#L219

if (!this.options.buildCache) {
            const { cwd } = this.core;
            const outDir = this.getOutDir();
            const cacheList = [
                (0, path_1.join)(cwd, outDir, '.mwcc-cache'),
                (0, path_1.join)(cwd, outDir, 'midway.build.json'),
            ];
            for (const cacheFile of cacheList) {
                if ((0, fs_extra_1.existsSync)(cacheFile)) {
                    await (0, fs_extra_1.remove)(cacheFile);
                }
            }
        }

@midwayjs/mwcc/src/compiler-host.ts#L16

 this.derivedOutputDir = config.compilerOptions?.outDir ?? 'dist';
czy88840616 commented 2 years ago

额,我有时候是自己 build 里 rm -rf .mwcc..

tyouzu1 commented 2 years ago

额,我有时候是自己 build 里 rm -rf .mwcc..

😂 反正现在看着只能自己删了

waitingsong commented 2 years ago

试试在 package.json scripts 中添加一个


afterbuild:server: "rm -rf .mwcc"
tyouzu1 commented 2 years ago

试试在 package.json scripts 中添加一个


afterbuild:server: "rm -rf .mwcc"

@waitingsong 这个我知道,就是想的能自动一点,能和mwcc那边保持一致,所以提了个pr。

czy88840616 commented 2 years ago

mwcc 其实我们想逐步去掉了。。。直接用上 tsc,但是受限于历史原因,暂时还得用。