-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow loading ts compiler from cwd (#169)
test case under node 8 Co-authored-by: dengruoqi <[email protected]>
- Loading branch information
Showing
7 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/fixtures/example-ts-custom-compiler/config/config.default.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
export const key = '12345'; |
8 changes: 8 additions & 0 deletions
8
test/fixtures/example-ts-custom-compiler/node_modules/egg/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test/fixtures/example-ts-custom-compiler/node_modules/egg/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "example-ts-custom-compiler" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,9 @@ const coffee = require('coffee'); | |
const mm = require('mm'); | ||
const fs = require('fs'); | ||
const rimraf = require('mz-modules/rimraf'); | ||
const exec = require('mz/child_process').exec; | ||
const os = require('os'); | ||
const assert = require('assert'); | ||
|
||
describe('test/ts.test.js', () => { | ||
const eggBin = require.resolve('../bin/egg-bin'); | ||
|
@@ -149,6 +151,17 @@ describe('test/ts.test.js', () => { | |
}); | ||
|
||
describe('egg.typescript = true', () => { | ||
const tempNodeModules = path.join(__dirname, './fixtures/node_modules'); | ||
const tempPackageJson = path.join(__dirname, './fixtures/package.json'); | ||
afterEach(async () => { | ||
if (fs.existsSync(tempNodeModules)) { | ||
await rimraf(tempNodeModules); | ||
} | ||
if (fs.existsSync(tempPackageJson)) { | ||
await rimraf(tempPackageJson); | ||
} | ||
}); | ||
|
||
if (process.env.EGG_VERSION && process.env.EGG_VERSION === '1') { | ||
console.log('skip egg@1'); | ||
return; | ||
|
@@ -192,6 +205,19 @@ describe('test/ts.test.js', () => { | |
.end(); | ||
}); | ||
|
||
it('should load custom ts compiler', async () => { | ||
const cwd = path.join(__dirname, './fixtures/example-ts-custom-compiler'); | ||
|
||
// install custom ts-node | ||
await exec('npx cnpm install [email protected]', { cwd: path.join(__dirname, './fixtures') }); | ||
|
||
const { stderr, code } = await coffee.fork(eggBin, [ 'dev', '--ts' ], { cwd, env: { DEBUG: 'egg-bin' } }) | ||
.debug() | ||
.end(); | ||
assert(/ts-node@8\.10\.2/.test(stderr)); | ||
assert.equal(code, 0); | ||
}); | ||
|
||
it('should start app with other tscompiler without error', () => { | ||
return coffee.fork(eggBin, [ 'dev', '--ts', '--tscompiler=esbuild-register' ], { | ||
cwd: path.join(__dirname, './fixtures/example-ts'), | ||
|