diff --git a/lib/index.js b/lib/index.js index f4f7bd9..7ae8831 100644 --- a/lib/index.js +++ b/lib/index.js @@ -8,12 +8,19 @@ const { copyFilesRecursive, output, colors, - debug + debug, } = require('./util'); const path = require('path'); const { replaceTscAliasPaths } = require('tsc-alias'); const chokidar = require('chokidar'); +function getRelativeDir(rootDir, filePathDir) { + if (!filePathDir) { + return filePathDir; + } + return path.relative(rootDir, filePathDir); +} + function run() { const [runCmd, tscArgs, runArgs, isCleanDirectory] = parseArgs(process.argv); const cwd = process.cwd(); @@ -52,10 +59,10 @@ function run() { } if (tsconfig.options) { - outDir = tsconfig.options.outDir; + outDir = getRelativeDir(cwd, tsconfig.options.outDir); // 解析出来的 tsconfig.json 中的 allowJs 优先级更高 allowJs = tsconfig.options.allowJs; - sourceDir = tsconfig.options.rootDir || sourceDir; + sourceDir = getRelativeDir(cwd, tsconfig.options.rootDir) || sourceDir; // 判断是否需要启动 tsc-alias hasPaths = !!( tsconfig.options.paths && Object.keys(tsconfig.options.paths).length > 0 diff --git a/package.json b/package.json index 88e5732..1fea2e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mwtsc", - "version": "1.7.0", + "version": "1.7.1-beta.1", "description": "tsc wrapper for midway development", "main": "lib/index.js", "bin": { @@ -14,9 +14,9 @@ }, "devDependencies": { "execa": "^5.1.1", - "jest": "^29.4.1", + "jest": "^29.7.0", "mwts": "^1.3.0", - "typescript": "~4.9.0" + "typescript": "~4.9.5" }, "engines": { "node": ">=12.0.0" diff --git a/test/__snapshots__/util.test.js.snap b/test/__snapshots__/util.test.js.snap deleted file mode 100644 index d3ee3a7..0000000 --- a/test/__snapshots__/util.test.js.snap +++ /dev/null @@ -1,155 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`test/util.test.js should test read tsconfig file 1`] = ` -{ - "compileOnSave": true, - "errors": [ - { - "category": 1, - "code": 18003, - "file": undefined, - "length": undefined, - "messageText": "No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '["dist","node_modules","test"]'.", - "reportsDeprecated": undefined, - "reportsUnnecessary": undefined, - "start": undefined, - }, - ], - "fileNames": [], - "options": { - "configFilePath": undefined, - "module": 1, - "moduleResolution": 2, - "target": 5, - }, - "projectReferences": undefined, - "raw": { - "compileOnSave": true, - "compilerOptions": { - "module": "commonjs", - "moduleResolution": "node", - "target": "es2018", - }, - "exclude": [ - "dist", - "node_modules", - "test", - ], - }, - "typeAcquisition": { - "enable": false, - "exclude": [], - "include": [], - }, - "watchOptions": undefined, - "wildcardDirectories": { - "/users/harry/project/mtsc/test/fixtures/ts_config": 1, - }, -} -`; - -exports[`test/util.test.js should test read tsconfig file with extends 1`] = ` -{ - "compileOnSave": false, - "errors": [ - { - "category": 1, - "code": 18003, - "file": undefined, - "length": undefined, - "messageText": "No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["src/**/*.ts"]' and 'exclude' paths were '["asset","app/public","app/views","dist","node_modules*","**/*.d.ts","**/*.spec.ts"]'.", - "reportsDeprecated": undefined, - "reportsUnnecessary": undefined, - "start": undefined, - }, - ], - "fileNames": [], - "options": { - "baseUrl": "/Users/harry/project/mtsc/test/fixtures/ts_config", - "configFilePath": undefined, - "declaration": true, - "declarationMap": true, - "emitDecoratorMetadata": true, - "esModuleInterop": true, - "exactOptionalPropertyTypes": true, - "experimentalDecorators": true, - "forceConsistentCasingInFileNames": true, - "incremental": true, - "module": 199, - "moduleResolution": 99, - "newLine": 1, - "noFallthroughCasesInSwitch": true, - "noImplicitOverride": true, - "noPropertyAccessFromIndexSignature": true, - "noUncheckedIndexedAccess": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "outDir": "/Users/harry/project/mtsc/test/fixtures/ts_config/dist", - "paths": { - "##/*": [ - "src/*", - ], - "#@/*": [ - "test/*", - ], - "#a/*": [ - "src/app/*", - ], - }, - "pathsBasePath": "/Users/harry/project/mtsc/test/fixtures/ts_config", - "preserveConstEnums": true, - "pretty": true, - "resolveJsonModule": true, - "skipLibCheck": true, - "sourceMap": true, - "strict": true, - "strictPropertyInitialization": false, - "stripInternal": true, - "target": 9, - "tsBuildInfoFile": "/Users/harry/project/mtsc/test/fixtures/ts_config/.tsbuildinfo", - "types": [ - "mocha", - "node", - ], - }, - "projectReferences": undefined, - "raw": { - "compileOnSave": false, - "compilerOptions": { - "paths": { - "##/*": [ - "src/*", - ], - "#@/*": [ - "test/*", - ], - "#a/*": [ - "src/app/*", - ], - }, - }, - "exclude": [ - "asset", - "app/public", - "app/views", - "dist", - "node_modules*", - "**/*.d.ts", - "**/*.spec.ts", - ], - "extends": "./tsconfig.base.json", - "include": [ - "src/**/*.ts", - ], - }, - "typeAcquisition": { - "enable": false, - "exclude": [], - "include": [], - }, - "watchOptions": undefined, - "wildcardDirectories": { - "/users/harry/project/mtsc/test/fixtures/ts_config/src": 1, - }, -} -`; diff --git a/test/fixtures/ts_config/tsconfig_extend.json b/test/fixtures/ts_config/tsconfig_extend.json index 9350232..320b868 100644 --- a/test/fixtures/ts_config/tsconfig_extend.json +++ b/test/fixtures/ts_config/tsconfig_extend.json @@ -1,10 +1,5 @@ { "extends": "./tsconfig.base.json", "compilerOptions": { - "paths": { - "##/*": ["src/*"], - "#a/*": ["src/app/*"], - "#@/*": ["test/*"] - }, } } diff --git a/test/util.test.js b/test/util.test.js index 9cedff6..6935b34 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -78,12 +78,16 @@ describe('test/util.test.js', () => { it('should test read tsconfig file', () => { const data = readJSONCFile(path.join(__dirname, 'fixtures/ts_config/tsconfig.json')); - expect(data).toMatchSnapshot(); + expect(data.options).toBeDefined(); + expect(data.raw).toBeDefined(); }); it('should test read tsconfig file with extends', () => { const data = readJSONCFile(path.join(__dirname, 'fixtures/ts_config/tsconfig_extend.json')); - expect(data).toMatchSnapshot(); + expect(data.options).toBeDefined(); + expect(data.options.paths).toBeDefined(); + expect(data.raw).toBeDefined(); + expect(data.raw.paths).not.toBeDefined(); }); });