Skip to content

Commit 8142704

Browse files
authored
Use user's typescript first, fallback to bundled (#741)
* use process.cwd()'s typescript * use process.argv[1]'s instead of process.cwd()'s typescript * Handle situation that argv1 is empty * changeset * Require "typescript" from cwd i.o. argv1
1 parent 360511b commit 8142704

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

.changeset/silver-guests-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'microbundle': minor
3+
---
4+
5+
Use user's typescript first, fallback to bundled

package-lock.json

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"lodash.merge": "^4.6.2",
105105
"module-details-from-path": "^1.0.3",
106106
"pretty-bytes": "^5.3.0",
107+
"resolve-from": "^4.0.0",
107108
"rollup": "^1.32.1",
108109
"rollup-plugin-bundle-size": "^1.0.1",
109110
"rollup-plugin-es3": "^1.1.0",

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import autoprefixer from 'autoprefixer';
99
import cssnano from 'cssnano';
1010
import { rollup, watch } from 'rollup';
1111
import builtinModules from 'builtin-modules';
12+
import resolveFrom from 'resolve-from';
1213
import commonjs from '@rollup/plugin-commonjs';
1314
import babel from '@rollup/plugin-babel';
1415
import customBabel from './lib/babel-custom';
@@ -486,7 +487,10 @@ function createConfig(options, entry, format, writeMeta) {
486487
},
487488
useTypescript &&
488489
typescript({
489-
typescript: require('typescript'),
490+
typescript: require(resolveFrom.silent(
491+
options.cwd,
492+
'typescript',
493+
) || 'typescript'),
490494
cacheRoot: `./node_modules/.cache/.rts2_cache_${format}`,
491495
useTsconfigDeclarationDir: true,
492496
tsconfigDefaults: {

0 commit comments

Comments
 (0)